From: Phil Yang Date: Mon, 8 Apr 2019 03:02:30 +0000 (+0800) Subject: test/distributor: replace sync with atomic builtins X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=bb79646a47643c8802788ae2e9e99d81c1f9fcc0;p=dpdk.git test/distributor: replace sync with atomic builtins '__sync' built-in functions are deprecated, should use the '__atomic' built-in instead. the sync built-in functions are full barriers, while atomic built-in functions offer less restrictive one-way barriers, which help performance. Here is the example test result on TX2: sudo ./arm64-armv8a-linuxapp-gcc/app/test -l 112-139 \ -n 4 --socket-mem=1024,1024 -- -i RTE>>distributor_perf_autotest *** distributor_perf_autotest without this patch *** ==== Cache line switch test === Time for 33554432 iterations = 1519202730 ticks Ticks per iteration = 45 *** distributor_perf_autotest with this patch *** ==== Cache line switch test === Time for 33554432 iterations = 1251715496 ticks Ticks per iteration = 37 Less ticks needed for the cache line switch test. It got 17% of performance improvement. Signed-off-by: Phil Yang Reviewed-by: Gavin Hu Reviewed-by: Ruifeng Wang Reviewed-by: Joyce Kong Reviewed-by: Dharmik Thakkar Reviewed-by: Honnappa Nagarahalli --- diff --git a/app/test/test_distributor.c b/app/test/test_distributor.c index 8084c07943..928238f4c3 100644 --- a/app/test/test_distributor.c +++ b/app/test/test_distributor.c @@ -63,7 +63,7 @@ handle_work(void *arg) struct worker_params *wp = arg; struct rte_distributor *db = wp->dist; unsigned int count = 0, num = 0; - unsigned int id = __sync_fetch_and_add(&worker_idx, 1); + unsigned int id = __atomic_fetch_add(&worker_idx, 1, __ATOMIC_RELAXED); int i; for (i = 0; i < 8; i++) @@ -271,7 +271,7 @@ handle_work_with_free_mbufs(void *arg) unsigned int count = 0; unsigned int i; unsigned int num = 0; - unsigned int id = __sync_fetch_and_add(&worker_idx, 1); + unsigned int id = __atomic_fetch_add(&worker_idx, 1, __ATOMIC_RELAXED); for (i = 0; i < 8; i++) buf[i] = NULL; @@ -344,7 +344,8 @@ handle_work_for_shutdown_test(void *arg) unsigned int total = 0; unsigned int i; unsigned int returned = 0; - const unsigned int id = __sync_fetch_and_add(&worker_idx, 1); + const unsigned int id = __atomic_fetch_add(&worker_idx, 1, + __ATOMIC_RELAXED); num = rte_distributor_get_pkt(d, id, buf, buf, num); diff --git a/app/test/test_distributor_perf.c b/app/test/test_distributor_perf.c index f6f1139492..664530ff9e 100644 --- a/app/test/test_distributor_perf.c +++ b/app/test/test_distributor_perf.c @@ -111,7 +111,7 @@ handle_work(void *arg) unsigned int count = 0; unsigned int num = 0; int i; - unsigned int id = __sync_fetch_and_add(&worker_idx, 1); + unsigned int id = __atomic_fetch_add(&worker_idx, 1, __ATOMIC_RELAXED); struct rte_mbuf *buf[8] __rte_cache_aligned; for (i = 0; i < 8; i++)