Skip to content

Commit

Permalink
rcu: fix implicit conversion in bit shift
Browse files Browse the repository at this point in the history
../lib/rcu/rte_rcu_qsbr.c(101): warning C4334: '<<': result of 32-bit
 shift implicitly converted to 64 bits (was 64-bit shift intended?)
../lib/rcu/rte_rcu_qsbr.c(107): warning C4334: '<<': result of 32-bit
 shift implicitly converted to 64 bits (was 64-bit shift intended?)
../lib/rcu/rte_rcu_qsbr.c(145): warning C4334: '<<': result of 32-bit
 shift implicitly converted to 64 bits (was 64-bit shift intended?)

These warnings are being issued by the MSVC compiler. Since the result is
being stored in a variable of type uint64_t, it makes sense to shift a
64-bit number instead of shifting a 32-bit number and then having the
compiler to convert the result implicitly to 64 bits.
UINT64_C was used in the fix as it is the portable way to define a 64-bit
constant (ULL suffix is architecture dependent).

From reading the code this is also a bugfix:
(1 << id), where id = thread_id & 0x3f, was wrong when thread_id > 0x1f.

Fixes: 64994b5 ("rcu: add RCU library supporting QSBR mechanism")
Cc: [email protected]

Signed-off-by: Andre Muezerie <[email protected]>
Reviewed-by: Honnappa Nagarahalli <[email protected]>
Reviewed-by: Morten Brørup <[email protected]>
  • Loading branch information
Andre Muezerie authored and tmonjalo committed Nov 19, 2024
1 parent 5d5dcd8 commit ffe827f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/rcu/rte_rcu_qsbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ rte_rcu_qsbr_thread_register(struct rte_rcu_qsbr *v, unsigned int thread_id)

/* Add the thread to the bitmap of registered threads */
old_bmap = rte_atomic_fetch_or_explicit(__RTE_QSBR_THRID_ARRAY_ELM(v, i),
(1UL << id), rte_memory_order_release);
RTE_BIT64(id), rte_memory_order_release);

/* Increment the number of threads registered only if the thread was not already
* registered
*/
if (!(old_bmap & (1UL << id)))
if (!(old_bmap & RTE_BIT64(id)))
rte_atomic_fetch_add_explicit(&v->num_threads, 1, rte_memory_order_relaxed);

return 0;
Expand Down Expand Up @@ -137,12 +137,12 @@ rte_rcu_qsbr_thread_unregister(struct rte_rcu_qsbr *v, unsigned int thread_id)
* reporting threads.
*/
old_bmap = rte_atomic_fetch_and_explicit(__RTE_QSBR_THRID_ARRAY_ELM(v, i),
~(1UL << id), rte_memory_order_release);
~RTE_BIT64(id), rte_memory_order_release);

/* Decrement the number of threads unregistered only if the thread was not already
* unregistered
*/
if (old_bmap & (1UL << id))
if (old_bmap & RTE_BIT64(id))
rte_atomic_fetch_sub_explicit(&v->num_threads, 1, rte_memory_order_relaxed);

return 0;
Expand Down Expand Up @@ -198,7 +198,7 @@ rte_rcu_qsbr_dump(FILE *f, struct rte_rcu_qsbr *v)
t = rte_ctz64(bmap);
fprintf(f, "%u ", id + t);

bmap &= ~(1UL << t);
bmap &= ~RTE_BIT64(t);
}
}

Expand All @@ -225,7 +225,7 @@ rte_rcu_qsbr_dump(FILE *f, struct rte_rcu_qsbr *v)
rte_atomic_load_explicit(
&v->qsbr_cnt[id + t].lock_cnt,
rte_memory_order_relaxed));
bmap &= ~(1UL << t);
bmap &= ~RTE_BIT64(t);
}
}

Expand Down

0 comments on commit ffe827f

Please sign in to comment.