Skip to content

Commit

Permalink
libublksrv: use sched_setaffinity() instead of pthread function
Browse files Browse the repository at this point in the history
pthread_setaffinity_np() is actually a wrapper around
sched_setaffinity(). For our usecase we are trying to set affinity
only of the current thread, so we can use sched_setaffinity() as a drop
in replacement. This makes code more portable (< glibc2.3.4, bionic)
and concise while keeping the functionality same.

Signed-off-by: Sandeep Dhavale <[email protected]>
  • Loading branch information
dhavale committed Nov 14, 2024
1 parent 4ba6a89 commit adc4b7f
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions lib/ublksrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,8 @@ static void ublksrv_set_sched_affinity(struct _ublksrv_dev *dev,
const struct ublksrv_ctrl_dev *cdev = dev->ctrl_dev;
unsigned dev_id = cdev->dev_info.dev_id;
cpu_set_t *cpuset = ublksrv_get_queue_affinity(cdev, q_id);
pthread_t thread = pthread_self();
int ret;

ret = pthread_setaffinity_np(thread, sizeof(cpu_set_t), cpuset);
if (ret)
if (sched_setaffinity(0, sizeof(cpu_set_t), cpuset) < 0)
ublk_err("ublk dev %u queue %u set affinity failed",
dev_id, q_id);
}
Expand Down

0 comments on commit adc4b7f

Please sign in to comment.