selftests: ublk: make ublk_thread thread-local variable
authorMing Lei <ming.lei@redhat.com>
Sat, 1 Nov 2025 13:31:20 +0000 (21:31 +0800)
committerJens Axboe <axboe@kernel.dk>
Mon, 3 Nov 2025 15:34:59 +0000 (08:34 -0700)
commit3f5b1169d2ab20ed14271654799121232b9eb9d7
treeeb3b50573f8bd81e36ee435cd7dbbe619f03ba9d
parent0123bb91f464487cc1bbdcc515757dc723496a39
selftests: ublk: make ublk_thread thread-local variable

Refactor ublk_thread to be a thread-local variable instead of storing
it in ublk_dev:

- Remove pthread_t thread field from struct ublk_thread and move it to
  struct ublk_thread_info

- Remove struct ublk_thread array from struct ublk_dev, reducing memory
  footprint

- Define struct ublk_thread as local variable in __ublk_io_handler_fn()
  instead of accessing it from dev->threads[]

- Extract main IO handling logic into __ublk_io_handler_fn() which is
  marked as noinline

- Move CPU affinity setup to ublk_io_handler_fn() before calling
  __ublk_io_handler_fn()

- Update ublk_thread_set_sched_affinity() to take struct ublk_thread_info *
  instead of struct ublk_thread *, and use pthread_setaffinity_np()
  instead of sched_setaffinity()

- Reorder struct ublk_thread fields to group related state together

This change makes each thread's ublk_thread structure truly local to
the thread, improving cache locality and reducing memory usage.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
tools/testing/selftests/ublk/kublk.c
tools/testing/selftests/ublk/kublk.h