* The atomic exchange test sets up a token in memory and * then spins up multiple lcores whose job is to generate * new tokens, exchange that new token for the old one held * in memory, and then verify that the old token is still * valid (i.e. the exchange did not corrupt the token). * * A token is made up of random data and 8 bits of crc * covering that random data. The following is an ex
| 397 | * +------------+------------+ |
| 398 | */ |
| 399 | static int |
| 400 | test_atomic_exchange(__rte_unused void *arg) |
| 401 | { |
| 402 | int i; |
| 403 | test16_t nt16, ot16; /* new token, old token */ |
| 404 | test32_t nt32, ot32; |
| 405 | test64_t nt64, ot64; |
| 406 | |
| 407 | /* Wait until all of the other threads have been dispatched */ |
| 408 | while (rte_atomic32_read(&synchro) == 0) |
| 409 | ; |
| 410 | |
| 411 | /* |
| 412 | * Let the battle begin! Every thread attempts to steal the current |
| 413 | * token with an atomic exchange operation and install its own newly |
| 414 | * generated token. If the old token is valid (i.e. it has the |
| 415 | * appropriate crc32 hash for the data) then the test iteration has |
| 416 | * passed. If the token is invalid, increment the counter. |
| 417 | */ |
| 418 | for (i = 0; i < N; i++) { |
| 419 | |
| 420 | /* Test 64bit Atomic Exchange */ |
| 421 | nt64.u64 = rte_rand(); |
| 422 | nt64.u8[7] = get_crc8(&nt64.u8[0], sizeof(nt64) - 1); |
| 423 | ot64.u64 = rte_atomic64_exchange(&token64, nt64.u64); |
| 424 | if (ot64.u8[7] != get_crc8(&ot64.u8[0], sizeof(ot64) - 1)) |
| 425 | rte_atomic64_inc(&count); |
| 426 | |
| 427 | /* Test 32bit Atomic Exchange */ |
| 428 | nt32.u32 = (uint32_t)rte_rand(); |
| 429 | nt32.u8[3] = get_crc8(&nt32.u8[0], sizeof(nt32) - 1); |
| 430 | ot32.u32 = rte_atomic32_exchange(&token32, nt32.u32); |
| 431 | if (ot32.u8[3] != get_crc8(&ot32.u8[0], sizeof(ot32) - 1)) |
| 432 | rte_atomic64_inc(&count); |
| 433 | |
| 434 | /* Test 16bit Atomic Exchange */ |
| 435 | nt16.u16 = (uint16_t)rte_rand(); |
| 436 | nt16.u8[1] = get_crc8(&nt16.u8[0], sizeof(nt16) - 1); |
| 437 | ot16.u16 = rte_atomic16_exchange(&token16, nt16.u16); |
| 438 | if (ot16.u8[1] != get_crc8(&ot16.u8[0], sizeof(ot16) - 1)) |
| 439 | rte_atomic64_inc(&count); |
| 440 | } |
| 441 | |
| 442 | return 0; |
| 443 | } |
| 444 | static int |
| 445 | test_atomic(void) |
| 446 | { |
nothing calls this directly
no test coverage detected