Skip to content

Comments

perf(agnocast_kmod): optimize exit worker and filter non-Agnocast PIDs#1083

Draft
k1832 wants to merge 3 commits intotier4:mainfrom
k1832:kmod/2.2-exit-worker-improvements
Draft

perf(agnocast_kmod): optimize exit worker and filter non-Agnocast PIDs#1083
k1832 wants to merge 3 commits intotier4:mainfrom
k1832:kmod/2.2-exit-worker-improvements

Conversation

@k1832
Copy link
Contributor

@k1832 k1832 commented Feb 19, 2026

Description

Three improvements to the process exit handling path:

Drain loop: The exit worker thread previously dequeued exactly one PID per wake-up cycle. When N processes exit simultaneously, this caused N separate sleep/wake context switches. Now all queued PIDs are drained in a single wake-up before going back to sleep.

RCU-based PID filtering: The kprobe on do_exit fires for every process exit system-wide. Previously, every exit triggered the full enqueue → wake → dequeue → rwsem pipeline before being discarded in process_exit_cleanup. Now an RCU-protected hash lookup in the kprobe handler skips non-Agnocast PIDs immediately (~50-100 ns) instead of going through the full pipeline (~6-14 us). This eliminates unnecessary rwsem acquisitions that contend with the publish/receive hot path.

EXIT_QUEUE_MASK: Replace inline (EXIT_QUEUE_SIZE - 1) with a named constant.

Related links

How was this PR tested?

  • Autoware (required)
  • bash scripts/e2e_test_1to1 (required)
  • bash scripts/e2e_test_2to2 (required)
  • kunit tests (required when modifying the kernel module)
  • sample application

Notes for reviewers

  • Each change is a separate commit
  • The RCU change adds rcu_head to process_info and uses hash_add_rcu/hash_del_rcu/kfree_rcu for proc_info_htable. This is a textbook RCU use case: a read-mostly hash table where writes are rare (process add/remove) and reads happen on every system-wide process exit.
  • find_process_info and process_exit_cleanup still use non-RCU hash iteration under global_htables_rwsem, which provides sufficient synchronization. Only the kprobe handler (which cannot sleep) uses RCU.

Version Update Label (Required)

need-patch-update

The exit worker thread previously dequeued exactly one PID per
wake-up cycle. When N processes exit simultaneously, this caused N
separate sleep/wake context switches. Change to an inner drain loop
that processes all queued PIDs before going back to sleep.

Signed-off-by: Keita Morisaki <keita.morisaki@tier4.jp>
The kprobe on do_exit fires for every process exit system-wide.
Previously, every exit — even unrelated processes — triggered the
full enqueue/wake/dequeue/rwsem pipeline before being discarded in
process_exit_cleanup.

Add an RCU-protected hash lookup in the kprobe handler to skip
non-Agnocast PIDs immediately (~50-100 ns) instead of going through
the full pipeline (~6-14 us). This eliminates unnecessary rwsem
acquisitions that contend with the publish/receive hot path.

Changes:
- Add rcu_head to process_info for deferred freeing
- Use hash_add_rcu/hash_del_rcu/kfree_rcu for proc_info_htable
- Use rcu_read_lock + hash_for_each_possible_rcu in kprobe handler
- synchronize_rcu in remove_all_process_info at module exit

Signed-off-by: Keita Morisaki <keita.morisaki@tier4.jp>
…apping

Replace inline (EXIT_QUEUE_SIZE - 1) with a named EXIT_QUEUE_MASK
constant. Remove the now-unnecessary comment about EXIT_QUEUE_SIZE
being a power of two, since the mask definition makes this self-evident.

Signed-off-by: Keita Morisaki <keita.morisaki@tier4.jp>
@sykwer
Copy link
Member

sykwer commented Feb 19, 2026

Great

@sykwer sykwer added the need-patch-update Bug fixes and other changes - requires PATCH version update label Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

need-patch-update Bug fixes and other changes - requires PATCH version update next-release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants