Skip to content

Commit 0883d73

Browse files
m-ronnblomdavid-marchand
authored andcommitted
bitops: support volatile pointers in new API
Have rte_bit_[test|set|clear|assign|flip]() and rte_bit_atomic_*() handle volatile-marked pointers. Bugzilla ID: 1385 Signed-off-by: Mattias Rönnblom <[email protected]> Acked-by: Morten Brørup <[email protected]> Acked-by: Jack Bond-Preston <[email protected]>
1 parent 35326b6 commit 0883d73

File tree

2 files changed

+86
-26
lines changed

2 files changed

+86
-26
lines changed

app/test/test_bitops.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
#include <rte_random.h>
1414
#include "test.h"
1515

16-
#define GEN_TEST_BIT_ACCESS(test_name, set_fun, clear_fun, assign_fun, flip_fun, test_fun, size) \
16+
#define GEN_TEST_BIT_ACCESS(test_name, set_fun, clear_fun, assign_fun, flip_fun, test_fun, size, \
17+
mod) \
1718
static int \
1819
test_name(void) \
1920
{ \
2021
uint ## size ## _t reference = (uint ## size ## _t)rte_rand(); \
2122
unsigned int bit_nr; \
22-
uint ## size ## _t word = (uint ## size ## _t)rte_rand(); \
23+
mod uint ## size ## _t word = (uint ## size ## _t)rte_rand(); \
2324
for (bit_nr = 0; bit_nr < size; bit_nr++) { \
2425
bool reference_bit = (reference >> bit_nr) & 1; \
2526
bool assign = rte_rand() & 1; \
@@ -37,7 +38,7 @@ test_name(void) \
3738
TEST_ASSERT(test_fun(&word, bit_nr) != reference_bit, \
3839
"Bit %d had unflipped value", bit_nr); \
3940
flip_fun(&word, bit_nr); \
40-
const uint ## size ## _t *const_ptr = &word; \
41+
const mod uint ## size ## _t *const_ptr = &word; \
4142
TEST_ASSERT(test_fun(const_ptr, bit_nr) == reference_bit, \
4243
"Bit %d had unexpected value", bit_nr); \
4344
} \
@@ -51,10 +52,16 @@ test_name(void) \
5152
}
5253

5354
GEN_TEST_BIT_ACCESS(test_bit_access32, rte_bit_set, rte_bit_clear, rte_bit_assign, rte_bit_flip,
54-
rte_bit_test, 32)
55+
rte_bit_test, 32,)
5556

5657
GEN_TEST_BIT_ACCESS(test_bit_access64, rte_bit_set, rte_bit_clear, rte_bit_assign, rte_bit_flip,
57-
rte_bit_test, 64)
58+
rte_bit_test, 64,)
59+
60+
GEN_TEST_BIT_ACCESS(test_bit_v_access32, rte_bit_set, rte_bit_clear, rte_bit_assign, rte_bit_flip,
61+
rte_bit_test, 32, volatile)
62+
63+
GEN_TEST_BIT_ACCESS(test_bit_v_access64, rte_bit_set, rte_bit_clear, rte_bit_assign, rte_bit_flip,
64+
rte_bit_test, 64, volatile)
5865

5966
#define bit_atomic_set(addr, nr) \
6067
rte_bit_atomic_set(addr, nr, rte_memory_order_relaxed)
@@ -72,10 +79,16 @@ GEN_TEST_BIT_ACCESS(test_bit_access64, rte_bit_set, rte_bit_clear, rte_bit_assig
7279
rte_bit_atomic_test(addr, nr, rte_memory_order_relaxed)
7380

7481
GEN_TEST_BIT_ACCESS(test_bit_atomic_access32, bit_atomic_set, bit_atomic_clear, bit_atomic_assign,
75-
bit_atomic_flip, bit_atomic_test, 32)
82+
bit_atomic_flip, bit_atomic_test, 32,)
7683

7784
GEN_TEST_BIT_ACCESS(test_bit_atomic_access64, bit_atomic_set, bit_atomic_clear, bit_atomic_assign,
78-
bit_atomic_flip, bit_atomic_test, 64)
85+
bit_atomic_flip, bit_atomic_test, 64,)
86+
87+
GEN_TEST_BIT_ACCESS(test_bit_atomic_v_access32, bit_atomic_set, bit_atomic_clear, bit_atomic_assign,
88+
bit_atomic_flip, bit_atomic_test, 32, volatile)
89+
90+
GEN_TEST_BIT_ACCESS(test_bit_atomic_v_access64, bit_atomic_set, bit_atomic_clear, bit_atomic_assign,
91+
bit_atomic_flip, bit_atomic_test, 64, volatile)
7992

8093
#define PARALLEL_TEST_RUNTIME 0.25
8194

@@ -389,8 +402,12 @@ static struct unit_test_suite test_suite = {
389402
TEST_CASE(test_bit_access64),
390403
TEST_CASE(test_bit_access32),
391404
TEST_CASE(test_bit_access64),
405+
TEST_CASE(test_bit_v_access32),
406+
TEST_CASE(test_bit_v_access64),
392407
TEST_CASE(test_bit_atomic_access32),
393408
TEST_CASE(test_bit_atomic_access64),
409+
TEST_CASE(test_bit_atomic_v_access32),
410+
TEST_CASE(test_bit_atomic_v_access64),
394411
TEST_CASE(test_bit_atomic_parallel_assign32),
395412
TEST_CASE(test_bit_atomic_parallel_assign64),
396413
TEST_CASE(test_bit_atomic_parallel_test_and_modify32),

lib/eal/include/rte_bitops.h

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,12 @@ extern "C" {
131131
_Generic((addr), \
132132
uint32_t *: __rte_bit_test32, \
133133
const uint32_t *: __rte_bit_test32, \
134+
volatile uint32_t *: __rte_bit_v_test32, \
135+
const volatile uint32_t *: __rte_bit_v_test32, \
134136
uint64_t *: __rte_bit_test64, \
135-
const uint64_t *: __rte_bit_test64) \
137+
const uint64_t *: __rte_bit_test64, \
138+
volatile uint64_t *: __rte_bit_v_test64, \
139+
const volatile uint64_t *: __rte_bit_v_test64) \
136140
(addr, nr)
137141

138142
/**
@@ -156,7 +160,9 @@ extern "C" {
156160
#define rte_bit_set(addr, nr) \
157161
_Generic((addr), \
158162
uint32_t *: __rte_bit_set32, \
159-
uint64_t *: __rte_bit_set64) \
163+
volatile uint32_t *: __rte_bit_v_set32, \
164+
uint64_t *: __rte_bit_set64, \
165+
volatile uint64_t *: __rte_bit_v_set64) \
160166
(addr, nr)
161167

162168
/**
@@ -180,7 +186,9 @@ extern "C" {
180186
#define rte_bit_clear(addr, nr) \
181187
_Generic((addr), \
182188
uint32_t *: __rte_bit_clear32, \
183-
uint64_t *: __rte_bit_clear64) \
189+
volatile uint32_t *: __rte_bit_v_clear32, \
190+
uint64_t *: __rte_bit_clear64, \
191+
volatile uint64_t *: __rte_bit_v_clear64) \
184192
(addr, nr)
185193

186194
/**
@@ -205,7 +213,9 @@ extern "C" {
205213
#define rte_bit_assign(addr, nr, value) \
206214
_Generic((addr), \
207215
uint32_t *: __rte_bit_assign32, \
208-
uint64_t *: __rte_bit_assign64) \
216+
volatile uint32_t *: __rte_bit_v_assign32, \
217+
uint64_t *: __rte_bit_assign64, \
218+
volatile uint64_t *: __rte_bit_v_assign64) \
209219
(addr, nr, value)
210220

211221
/**
@@ -229,7 +239,9 @@ extern "C" {
229239
#define rte_bit_flip(addr, nr) \
230240
_Generic((addr), \
231241
uint32_t *: __rte_bit_flip32, \
232-
uint64_t *: __rte_bit_flip64) \
242+
volatile uint32_t *: __rte_bit_v_flip32, \
243+
uint64_t *: __rte_bit_flip64, \
244+
volatile uint64_t *: __rte_bit_v_flip64) \
233245
(addr, nr)
234246

235247
/**
@@ -255,8 +267,12 @@ extern "C" {
255267
_Generic((addr), \
256268
uint32_t *: __rte_bit_atomic_test32, \
257269
const uint32_t *: __rte_bit_atomic_test32, \
270+
volatile uint32_t *: __rte_bit_atomic_v_test32, \
271+
const volatile uint32_t *: __rte_bit_atomic_v_test32, \
258272
uint64_t *: __rte_bit_atomic_test64, \
259-
const uint64_t *: __rte_bit_atomic_test64) \
273+
const uint64_t *: __rte_bit_atomic_test64, \
274+
volatile uint64_t *: __rte_bit_atomic_v_test64, \
275+
const volatile uint64_t *: __rte_bit_atomic_v_test64) \
260276
(addr, nr, memory_order)
261277

262278
/**
@@ -279,7 +295,9 @@ extern "C" {
279295
#define rte_bit_atomic_set(addr, nr, memory_order) \
280296
_Generic((addr), \
281297
uint32_t *: __rte_bit_atomic_set32, \
282-
uint64_t *: __rte_bit_atomic_set64) \
298+
volatile uint32_t *: __rte_bit_atomic_v_set32, \
299+
uint64_t *: __rte_bit_atomic_set64, \
300+
volatile uint64_t *: __rte_bit_atomic_v_set64) \
283301
(addr, nr, memory_order)
284302

285303
/**
@@ -302,7 +320,9 @@ extern "C" {
302320
#define rte_bit_atomic_clear(addr, nr, memory_order) \
303321
_Generic((addr), \
304322
uint32_t *: __rte_bit_atomic_clear32, \
305-
uint64_t *: __rte_bit_atomic_clear64) \
323+
volatile uint32_t *: __rte_bit_atomic_v_clear32, \
324+
uint64_t *: __rte_bit_atomic_clear64, \
325+
volatile uint64_t *: __rte_bit_atomic_v_clear64) \
306326
(addr, nr, memory_order)
307327

308328
/**
@@ -327,7 +347,9 @@ extern "C" {
327347
#define rte_bit_atomic_assign(addr, nr, value, memory_order) \
328348
_Generic((addr), \
329349
uint32_t *: __rte_bit_atomic_assign32, \
330-
uint64_t *: __rte_bit_atomic_assign64) \
350+
volatile uint32_t *: __rte_bit_atomic_v_assign32, \
351+
uint64_t *: __rte_bit_atomic_assign64, \
352+
volatile uint64_t *: __rte_bit_atomic_v_assign64) \
331353
(addr, nr, value, memory_order)
332354

333355
/**
@@ -351,7 +373,9 @@ extern "C" {
351373
#define rte_bit_atomic_flip(addr, nr, memory_order) \
352374
_Generic((addr), \
353375
uint32_t *: __rte_bit_atomic_flip32, \
354-
uint64_t *: __rte_bit_atomic_flip64) \
376+
volatile uint32_t *: __rte_bit_atomic_v_flip32, \
377+
uint64_t *: __rte_bit_atomic_flip64, \
378+
volatile uint64_t *: __rte_bit_atomic_v_flip64) \
355379
(addr, nr, memory_order)
356380

357381
/**
@@ -376,7 +400,9 @@ extern "C" {
376400
#define rte_bit_atomic_test_and_set(addr, nr, memory_order) \
377401
_Generic((addr), \
378402
uint32_t *: __rte_bit_atomic_test_and_set32, \
379-
uint64_t *: __rte_bit_atomic_test_and_set64) \
403+
volatile uint32_t *: __rte_bit_atomic_v_test_and_set32, \
404+
uint64_t *: __rte_bit_atomic_test_and_set64, \
405+
volatile uint64_t *: __rte_bit_atomic_v_test_and_set64) \
380406
(addr, nr, memory_order)
381407

382408
/**
@@ -401,7 +427,9 @@ extern "C" {
401427
#define rte_bit_atomic_test_and_clear(addr, nr, memory_order) \
402428
_Generic((addr), \
403429
uint32_t *: __rte_bit_atomic_test_and_clear32, \
404-
uint64_t *: __rte_bit_atomic_test_and_clear64) \
430+
volatile uint32_t *: __rte_bit_atomic_v_test_and_clear32, \
431+
uint64_t *: __rte_bit_atomic_test_and_clear64, \
432+
volatile uint64_t *: __rte_bit_atomic_v_test_and_clear64) \
405433
(addr, nr, memory_order)
406434

407435
/**
@@ -429,7 +457,9 @@ extern "C" {
429457
#define rte_bit_atomic_test_and_assign(addr, nr, value, memory_order) \
430458
_Generic((addr), \
431459
uint32_t *: __rte_bit_atomic_test_and_assign32, \
432-
uint64_t *: __rte_bit_atomic_test_and_assign64) \
460+
volatile uint32_t *: __rte_bit_atomic_v_test_and_assign32, \
461+
uint64_t *: __rte_bit_atomic_test_and_assign64, \
462+
volatile uint64_t *: __rte_bit_atomic_v_test_and_assign64) \
433463
(addr, nr, value, memory_order)
434464

435465
#define __RTE_GEN_BIT_TEST(variant, qualifier, size) \
@@ -492,7 +522,8 @@ __rte_bit_ ## variant ## flip ## size(qualifier uint ## size ## _t *addr, unsign
492522
__RTE_GEN_BIT_FLIP(v, qualifier, size)
493523

494524
#define __RTE_GEN_BIT_OPS_SIZE(size) \
495-
__RTE_GEN_BIT_OPS(,, size)
525+
__RTE_GEN_BIT_OPS(,, size) \
526+
__RTE_GEN_BIT_OPS(v_, volatile, size)
496527

497528
__RTE_GEN_BIT_OPS_SIZE(32)
498529
__RTE_GEN_BIT_OPS_SIZE(64)
@@ -617,7 +648,8 @@ __rte_bit_atomic_ ## variant ## test_and_assign ## size( \
617648
__RTE_GEN_BIT_ATOMIC_FLIP(variant, qualifier, size)
618649

619650
#define __RTE_GEN_BIT_ATOMIC_OPS_SIZE(size) \
620-
__RTE_GEN_BIT_ATOMIC_OPS(,, size)
651+
__RTE_GEN_BIT_ATOMIC_OPS(,, size) \
652+
__RTE_GEN_BIT_ATOMIC_OPS(v_, volatile, size)
621653

622654
__RTE_GEN_BIT_ATOMIC_OPS_SIZE(32)
623655
__RTE_GEN_BIT_ATOMIC_OPS_SIZE(64)
@@ -1334,7 +1366,8 @@ rte_bit_ ## family ## fun(qualifier uint ## size ## _t *addr, arg1_type arg1_nam
13341366
}
13351367

13361368
#define __RTE_BIT_OVERLOAD_SZ_2(family, fun, qualifier, size, arg1_type, arg1_name) \
1337-
__RTE_BIT_OVERLOAD_V_2(family,, fun, qualifier, size, arg1_type, arg1_name)
1369+
__RTE_BIT_OVERLOAD_V_2(family,, fun, qualifier, size, arg1_type, arg1_name) \
1370+
__RTE_BIT_OVERLOAD_V_2(family, v_, fun, qualifier volatile, size, arg1_type, arg1_name)
13381371

13391372
#define __RTE_BIT_OVERLOAD_2(family, fun, qualifier, arg1_type, arg1_name) \
13401373
__RTE_BIT_OVERLOAD_SZ_2(family, fun, qualifier, 32, arg1_type, arg1_name) \
@@ -1348,7 +1381,9 @@ rte_bit_ ## family ## fun(qualifier uint ## size ## _t *addr, arg1_type arg1_nam
13481381
}
13491382

13501383
#define __RTE_BIT_OVERLOAD_SZ_2R(family, fun, qualifier, size, ret_type, arg1_type, arg1_name) \
1351-
__RTE_BIT_OVERLOAD_V_2R(family,, fun, qualifier, size, ret_type, arg1_type, arg1_name)
1384+
__RTE_BIT_OVERLOAD_V_2R(family,, fun, qualifier, size, ret_type, arg1_type, arg1_name) \
1385+
__RTE_BIT_OVERLOAD_V_2R(family, v_, fun, qualifier volatile, size, ret_type, arg1_type, \
1386+
arg1_name)
13521387

13531388
#define __RTE_BIT_OVERLOAD_2R(family, fun, qualifier, ret_type, arg1_type, arg1_name) \
13541389
__RTE_BIT_OVERLOAD_SZ_2R(family, fun, qualifier, 32, ret_type, arg1_type, arg1_name) \
@@ -1366,6 +1401,8 @@ rte_bit_ ## family ## fun(qualifier uint ## size ## _t *addr, arg1_type arg1_nam
13661401
#define __RTE_BIT_OVERLOAD_SZ_3(family, fun, qualifier, size, arg1_type, arg1_name, \
13671402
arg2_type, arg2_name) \
13681403
__RTE_BIT_OVERLOAD_V_3(family,, fun, qualifier, size, arg1_type, arg1_name, \
1404+
arg2_type, arg2_name) \
1405+
__RTE_BIT_OVERLOAD_V_3(family, v_, fun, qualifier volatile, size, arg1_type, arg1_name, \
13691406
arg2_type, arg2_name)
13701407

13711408
#define __RTE_BIT_OVERLOAD_3(family, fun, qualifier, arg1_type, arg1_name, arg2_type, arg2_name) \
@@ -1386,7 +1423,9 @@ rte_bit_ ## family ## fun(qualifier uint ## size ## _t *addr, arg1_type arg1_nam
13861423
#define __RTE_BIT_OVERLOAD_SZ_3R(family, fun, qualifier, size, ret_type, arg1_type, arg1_name, \
13871424
arg2_type, arg2_name) \
13881425
__RTE_BIT_OVERLOAD_V_3R(family,, fun, qualifier, size, ret_type, arg1_type, arg1_name, \
1389-
arg2_type, arg2_name)
1426+
arg2_type, arg2_name) \
1427+
__RTE_BIT_OVERLOAD_V_3R(family, v_, fun, qualifier volatile, size, ret_type, \
1428+
arg1_type, arg1_name, arg2_type, arg2_name)
13901429

13911430
#define __RTE_BIT_OVERLOAD_3R(family, fun, qualifier, ret_type, arg1_type, arg1_name, \
13921431
arg2_type, arg2_name) \
@@ -1407,6 +1446,8 @@ rte_bit_ ## family ## fun(qualifier uint ## size ## _t *addr, arg1_type arg1_nam
14071446
#define __RTE_BIT_OVERLOAD_SZ_4(family, fun, qualifier, size, arg1_type, arg1_name, \
14081447
arg2_type, arg2_name, arg3_type, arg3_name) \
14091448
__RTE_BIT_OVERLOAD_V_4(family,, fun, qualifier, size, arg1_type, arg1_name, \
1449+
arg2_type, arg2_name, arg3_type, arg3_name) \
1450+
__RTE_BIT_OVERLOAD_V_4(family, v_, fun, qualifier volatile, size, arg1_type, arg1_name, \
14101451
arg2_type, arg2_name, arg3_type, arg3_name)
14111452

14121453
#define __RTE_BIT_OVERLOAD_4(family, fun, qualifier, arg1_type, arg1_name, arg2_type, arg2_name, \
@@ -1429,7 +1470,9 @@ rte_bit_ ## family ## fun(qualifier uint ## size ## _t *addr, arg1_type arg1_nam
14291470
#define __RTE_BIT_OVERLOAD_SZ_4R(family, fun, qualifier, size, ret_type, arg1_type, arg1_name, \
14301471
arg2_type, arg2_name, arg3_type, arg3_name) \
14311472
__RTE_BIT_OVERLOAD_V_4R(family,, fun, qualifier, size, ret_type, arg1_type, arg1_name, \
1432-
arg2_type, arg2_name, arg3_type, arg3_name)
1473+
arg2_type, arg2_name, arg3_type, arg3_name) \
1474+
__RTE_BIT_OVERLOAD_V_4R(family, v_, fun, qualifier volatile, size, ret_type, \
1475+
arg1_type, arg1_name, arg2_type, arg2_name, arg3_type, arg3_name)
14331476

14341477
#define __RTE_BIT_OVERLOAD_4R(family, fun, qualifier, ret_type, arg1_type, arg1_name, \
14351478
arg2_type, arg2_name, arg3_type, arg3_name) \

0 commit comments

Comments
 (0)