From 81bb4fdc9850ac21b042e424b7fcbbe0589def7c Mon Sep 17 00:00:00 2001 From: Denis Koreshkov Date: Tue, 1 Oct 2024 15:16:04 +0300 Subject: [PATCH] ensure CPU affinity is set on the 1st iteration --- src/urcu-call-rcu-impl.h | 12 ++++-------- src/workqueue.c | 7 ++++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/urcu-call-rcu-impl.h b/src/urcu-call-rcu-impl.h index c83bf297..0652c04b 100644 --- a/src/urcu-call-rcu-impl.h +++ b/src/urcu-call-rcu-impl.h @@ -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) { @@ -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; @@ -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. */ @@ -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; diff --git a/src/workqueue.c b/src/workqueue.c index b8ba4ae0..6cb1644f 100644 --- a/src/workqueue.c +++ b/src/workqueue.c @@ -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; @@ -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); @@ -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;