Skip to content

Commit

Permalink
ensure CPU affinity is set on the 1st iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Koreshkov committed Oct 1, 2024
1 parent 643c993 commit 81bb4fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
12 changes: 4 additions & 8 deletions src/urcu-call-rcu-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ static void alloc_cpu_call_rcu_data(void)
if (cpus_array_len <= 0) {
return;
}
p = malloc(cpus_array_len * sizeof(*per_cpu_call_rcu_data));
p = calloc(cpus_array_len, sizeof(*per_cpu_call_rcu_data));
if (p != NULL) {
memset(p, '\0', cpus_array_len * sizeof(*per_cpu_call_rcu_data));
rcu_set_pointer(&per_cpu_call_rcu_data, p);
} else {
if (!warned) {
Expand Down Expand Up @@ -198,7 +197,7 @@ int set_thread_cpu_affinity(struct call_rcu_data *crdp)

if (crdp->cpu_affinity < 0)
return 0;
if (++crdp->gp_count & SET_AFFINITY_CHECK_PERIOD_MASK)
if (crdp->gp_count++ & SET_AFFINITY_CHECK_PERIOD_MASK)
return 0;
if (urcu_sched_getcpu() == crdp->cpu_affinity)
return 0;
Expand Down Expand Up @@ -318,9 +317,6 @@ static void *call_rcu_thread(void *arg)
struct call_rcu_data *crdp = (struct call_rcu_data *) arg;
int rt = !!(uatomic_read(&crdp->flags) & URCU_CALL_RCU_RT);

if (set_thread_cpu_affinity(crdp))
urcu_die(errno);

/*
* If callbacks take a read-side lock, we need to be registered.
*/
Expand Down Expand Up @@ -428,10 +424,10 @@ static void call_rcu_data_init(struct call_rcu_data **crdpp,
int ret;
sigset_t newmask, oldmask;

crdp = malloc(sizeof(*crdp));
crdp = calloc(1, sizeof(*crdp));
if (crdp == NULL)
urcu_die(errno);
memset(crdp, '\0', sizeof(*crdp));

cds_wfcq_init(&crdp->cbs_head, &crdp->cbs_tail);
crdp->qlen = 0;
crdp->futex = 0;
Expand Down
7 changes: 4 additions & 3 deletions src/workqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static int set_thread_cpu_affinity(struct urcu_workqueue *workqueue)

if (workqueue->cpu_affinity < 0)
return 0;
if (++workqueue->loop_count & SET_AFFINITY_CHECK_PERIOD_MASK)
if (workqueue->loop_count++ & SET_AFFINITY_CHECK_PERIOD_MASK)
return 0;
if (urcu_sched_getcpu() == workqueue->cpu_affinity)
return 0;
Expand Down Expand Up @@ -163,6 +163,7 @@ static void *workqueue_thread(void *arg)
struct urcu_workqueue *workqueue = (struct urcu_workqueue *) arg;
int rt = !!(uatomic_read(&workqueue->flags) & URCU_WORKQUEUE_RT);

/* XXX needed? */
if (set_thread_cpu_affinity(workqueue))
urcu_die(errno);

Expand Down Expand Up @@ -275,10 +276,10 @@ struct urcu_workqueue *urcu_workqueue_create(unsigned long flags,
int ret;
sigset_t newmask, oldmask;

workqueue = malloc(sizeof(*workqueue));
workqueue = calloc(1, sizeof(*workqueue));
if (workqueue == NULL)
urcu_die(errno);
memset(workqueue, '\0', sizeof(*workqueue));

cds_wfcq_init(&workqueue->cbs_head, &workqueue->cbs_tail);
workqueue->qlen = 0;
workqueue->futex = 0;
Expand Down

0 comments on commit 81bb4fd

Please sign in to comment.