MCPcopy Create free account
hub / github.com/F-Stack/f-stack / test_atomic_exchange

Function test_atomic_exchange

dpdk/app/test/test_atomic.c:399–443  ·  view source on GitHub ↗

* 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

Source from the content-addressed store, hash-verified

397 * +------------+------------+
398 */
399static int
400test_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}
444static int
445test_atomic(void)
446{

Callers

nothing calls this directly

Calls 7

rte_atomic32_readFunction · 0.85
rte_randFunction · 0.85
get_crc8Function · 0.85
rte_atomic64_exchangeFunction · 0.50
rte_atomic64_incFunction · 0.50
rte_atomic32_exchangeFunction · 0.50
rte_atomic16_exchangeFunction · 0.50

Tested by

no test coverage detected