2017-12-19 15:49:05 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
* Copyright(c) 2010-2017 Intel Corporation
|
2014-05-29 10:12:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
2015-04-23 13:03:50 +00:00
|
|
|
#include <rte_mempool.h>
|
2014-05-29 10:12:17 +00:00
|
|
|
#include <rte_cycles.h>
|
2015-04-23 13:03:50 +00:00
|
|
|
#include <rte_common.h>
|
|
|
|
#include <rte_mbuf.h>
|
2014-05-29 10:12:17 +00:00
|
|
|
#include <rte_distributor.h>
|
2017-06-05 08:58:43 +00:00
|
|
|
#include <rte_pause.h>
|
2014-05-29 10:12:17 +00:00
|
|
|
|
2017-03-20 10:08:34 +00:00
|
|
|
#define ITER_POWER_CL 25 /* log 2 of how many iterations for Cache Line test */
|
|
|
|
#define ITER_POWER 21 /* log 2 of how many iterations we do when timing. */
|
|
|
|
#define BURST 64
|
2014-05-29 10:12:17 +00:00
|
|
|
#define BIG_BATCH 1024
|
|
|
|
|
|
|
|
/* static vars - zero initialized by default */
|
|
|
|
static volatile int quit;
|
|
|
|
static volatile unsigned worker_idx;
|
|
|
|
|
|
|
|
struct worker_stats {
|
|
|
|
volatile unsigned handled_packets;
|
|
|
|
} __rte_cache_aligned;
|
2019-09-05 14:53:15 +00:00
|
|
|
static struct worker_stats worker_stats[RTE_MAX_LCORE];
|
2014-05-29 10:12:17 +00:00
|
|
|
|
2017-03-20 10:08:34 +00:00
|
|
|
/*
|
|
|
|
* worker thread used for testing the time to do a round-trip of a cache
|
2014-05-29 10:12:17 +00:00
|
|
|
* line between two cores and back again
|
|
|
|
*/
|
2018-05-10 01:25:38 +00:00
|
|
|
static int
|
2014-05-29 10:12:17 +00:00
|
|
|
flip_bit(volatile uint64_t *arg)
|
|
|
|
{
|
|
|
|
uint64_t old_val = 0;
|
|
|
|
while (old_val != 2) {
|
|
|
|
while (!*arg)
|
|
|
|
rte_pause();
|
|
|
|
old_val = *arg;
|
|
|
|
*arg = 0;
|
|
|
|
}
|
2018-05-10 01:25:38 +00:00
|
|
|
return 0;
|
2014-05-29 10:12:17 +00:00
|
|
|
}
|
|
|
|
|
2017-03-20 10:08:34 +00:00
|
|
|
/*
|
|
|
|
* test case to time the number of cycles to round-trip a cache line between
|
2014-05-29 10:12:17 +00:00
|
|
|
* two cores and back again.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
time_cache_line_switch(void)
|
|
|
|
{
|
|
|
|
/* allocate a full cache line for data, we use only first byte of it */
|
2014-11-19 12:26:06 +00:00
|
|
|
uint64_t data[RTE_CACHE_LINE_SIZE*3 / sizeof(uint64_t)];
|
2014-05-29 10:12:17 +00:00
|
|
|
|
2020-10-15 22:57:19 +00:00
|
|
|
unsigned int i, workerid = rte_get_next_lcore(rte_lcore_id(), 0, 0);
|
2014-05-29 10:12:17 +00:00
|
|
|
volatile uint64_t *pdata = &data[0];
|
|
|
|
*pdata = 1;
|
2020-10-15 22:57:19 +00:00
|
|
|
rte_eal_remote_launch((lcore_function_t *)flip_bit, &data[0], workerid);
|
2014-05-29 10:12:17 +00:00
|
|
|
while (*pdata)
|
|
|
|
rte_pause();
|
|
|
|
|
|
|
|
const uint64_t start_time = rte_rdtsc();
|
2017-03-20 10:08:34 +00:00
|
|
|
for (i = 0; i < (1 << ITER_POWER_CL); i++) {
|
2014-05-29 10:12:17 +00:00
|
|
|
while (*pdata)
|
|
|
|
rte_pause();
|
|
|
|
*pdata = 1;
|
|
|
|
}
|
|
|
|
const uint64_t end_time = rte_rdtsc();
|
|
|
|
|
|
|
|
while (*pdata)
|
|
|
|
rte_pause();
|
|
|
|
*pdata = 2;
|
2020-10-15 22:57:19 +00:00
|
|
|
rte_eal_wait_lcore(workerid);
|
2014-05-29 10:12:17 +00:00
|
|
|
printf("==== Cache line switch test ===\n");
|
2017-03-20 10:08:34 +00:00
|
|
|
printf("Time for %u iterations = %"PRIu64" ticks\n", (1<<ITER_POWER_CL),
|
2014-05-29 10:12:17 +00:00
|
|
|
end_time-start_time);
|
|
|
|
printf("Ticks per iteration = %"PRIu64"\n\n",
|
2017-03-20 10:08:34 +00:00
|
|
|
(end_time-start_time) >> ITER_POWER_CL);
|
2014-05-29 10:12:17 +00:00
|
|
|
}
|
|
|
|
|
2017-03-20 10:08:34 +00:00
|
|
|
/*
|
|
|
|
* returns the total count of the number of packets handled by the worker
|
2014-05-29 10:12:17 +00:00
|
|
|
* functions given below.
|
|
|
|
*/
|
|
|
|
static unsigned
|
|
|
|
total_packet_count(void)
|
|
|
|
{
|
|
|
|
unsigned i, count = 0;
|
|
|
|
for (i = 0; i < worker_idx; i++)
|
|
|
|
count += worker_stats[i].handled_packets;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* resets the packet counts for a new test */
|
|
|
|
static void
|
|
|
|
clear_packet_count(void)
|
|
|
|
{
|
|
|
|
memset(&worker_stats, 0, sizeof(worker_stats));
|
|
|
|
}
|
|
|
|
|
2017-03-20 10:08:34 +00:00
|
|
|
/*
|
|
|
|
* This is the basic worker function for performance tests.
|
2014-05-29 10:12:17 +00:00
|
|
|
* it does nothing but return packets and count them.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
handle_work(void *arg)
|
|
|
|
{
|
|
|
|
struct rte_distributor *d = arg;
|
2017-03-20 10:08:30 +00:00
|
|
|
unsigned int count = 0;
|
|
|
|
unsigned int num = 0;
|
|
|
|
int i;
|
2019-04-08 03:02:30 +00:00
|
|
|
unsigned int id = __atomic_fetch_add(&worker_idx, 1, __ATOMIC_RELAXED);
|
2017-03-20 10:08:30 +00:00
|
|
|
struct rte_mbuf *buf[8] __rte_cache_aligned;
|
2014-05-29 10:12:17 +00:00
|
|
|
|
2017-03-20 10:08:30 +00:00
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
buf[i] = NULL;
|
|
|
|
|
|
|
|
num = rte_distributor_get_pkt(d, id, buf, buf, num);
|
2014-05-29 10:12:17 +00:00
|
|
|
while (!quit) {
|
2017-03-20 10:08:30 +00:00
|
|
|
worker_stats[id].handled_packets += num;
|
|
|
|
count += num;
|
|
|
|
num = rte_distributor_get_pkt(d, id, buf, buf, num);
|
2014-05-29 10:12:17 +00:00
|
|
|
}
|
2017-03-20 10:08:30 +00:00
|
|
|
worker_stats[id].handled_packets += num;
|
|
|
|
count += num;
|
|
|
|
rte_distributor_return_pkt(d, id, buf, num);
|
2014-05-29 10:12:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-20 10:08:34 +00:00
|
|
|
/*
|
|
|
|
* This basic performance test just repeatedly sends in 32 packets at a time
|
2014-05-29 10:12:17 +00:00
|
|
|
* to the distributor and verifies at the end that we got them all in the worker
|
|
|
|
* threads and finally how long per packet the processing took.
|
|
|
|
*/
|
|
|
|
static inline int
|
|
|
|
perf_test(struct rte_distributor *d, struct rte_mempool *p)
|
|
|
|
{
|
2017-03-20 10:08:34 +00:00
|
|
|
unsigned int i;
|
2014-05-29 10:12:17 +00:00
|
|
|
uint64_t start, end;
|
|
|
|
struct rte_mbuf *bufs[BURST];
|
|
|
|
|
|
|
|
clear_packet_count();
|
|
|
|
if (rte_mempool_get_bulk(p, (void *)bufs, BURST) != 0) {
|
|
|
|
printf("Error getting mbufs from pool\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* ensure we have different hash value for each pkt */
|
|
|
|
for (i = 0; i < BURST; i++)
|
2014-11-10 12:52:46 +00:00
|
|
|
bufs[i]->hash.usr = i;
|
2014-05-29 10:12:17 +00:00
|
|
|
|
|
|
|
start = rte_rdtsc();
|
|
|
|
for (i = 0; i < (1<<ITER_POWER); i++)
|
|
|
|
rte_distributor_process(d, bufs, BURST);
|
|
|
|
end = rte_rdtsc();
|
|
|
|
|
|
|
|
do {
|
|
|
|
usleep(100);
|
|
|
|
rte_distributor_process(d, NULL, 0);
|
|
|
|
} while (total_packet_count() < (BURST << ITER_POWER));
|
|
|
|
|
2017-03-20 10:08:34 +00:00
|
|
|
rte_distributor_clear_returns(d);
|
|
|
|
|
2014-05-29 10:12:17 +00:00
|
|
|
printf("Time per burst: %"PRIu64"\n", (end - start) >> ITER_POWER);
|
|
|
|
printf("Time per packet: %"PRIu64"\n\n",
|
|
|
|
((end - start) >> ITER_POWER)/BURST);
|
|
|
|
rte_mempool_put_bulk(p, (void *)bufs, BURST);
|
|
|
|
|
|
|
|
for (i = 0; i < rte_lcore_count() - 1; i++)
|
|
|
|
printf("Worker %u handled %u packets\n", i,
|
|
|
|
worker_stats[i].handled_packets);
|
|
|
|
printf("Total packets: %u (%x)\n", total_packet_count(),
|
|
|
|
total_packet_count());
|
|
|
|
printf("=== Perf test done ===\n\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Useful function which ensures that all worker functions terminate */
|
|
|
|
static void
|
|
|
|
quit_workers(struct rte_distributor *d, struct rte_mempool *p)
|
|
|
|
{
|
2017-03-20 10:08:34 +00:00
|
|
|
const unsigned int num_workers = rte_lcore_count() - 1;
|
|
|
|
unsigned int i;
|
2014-05-29 10:12:17 +00:00
|
|
|
struct rte_mbuf *bufs[RTE_MAX_LCORE];
|
2017-03-20 10:08:34 +00:00
|
|
|
|
2014-05-29 10:12:17 +00:00
|
|
|
rte_mempool_get_bulk(p, (void *)bufs, num_workers);
|
|
|
|
|
|
|
|
quit = 1;
|
|
|
|
for (i = 0; i < num_workers; i++)
|
2014-11-10 12:52:46 +00:00
|
|
|
bufs[i]->hash.usr = i << 1;
|
2014-05-29 10:12:17 +00:00
|
|
|
rte_distributor_process(d, bufs, num_workers);
|
|
|
|
|
|
|
|
rte_mempool_put_bulk(p, (void *)bufs, num_workers);
|
|
|
|
|
|
|
|
rte_distributor_process(d, NULL, 0);
|
|
|
|
rte_eal_mp_wait_lcore();
|
|
|
|
quit = 0;
|
|
|
|
worker_idx = 0;
|
|
|
|
}
|
|
|
|
|
2014-08-18 11:29:23 +00:00
|
|
|
static int
|
2014-05-29 10:12:17 +00:00
|
|
|
test_distributor_perf(void)
|
|
|
|
{
|
2017-03-20 10:08:34 +00:00
|
|
|
static struct rte_distributor *ds;
|
|
|
|
static struct rte_distributor *db;
|
2014-05-29 10:12:17 +00:00
|
|
|
static struct rte_mempool *p;
|
|
|
|
|
|
|
|
if (rte_lcore_count() < 2) {
|
2019-06-15 06:42:30 +00:00
|
|
|
printf("Not enough cores for distributor_perf_autotest, expecting at least 2\n");
|
|
|
|
return TEST_SKIPPED;
|
2014-05-29 10:12:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* first time how long it takes to round-trip a cache line */
|
|
|
|
time_cache_line_switch();
|
|
|
|
|
2017-03-20 10:08:34 +00:00
|
|
|
if (ds == NULL) {
|
|
|
|
ds = rte_distributor_create("Test_perf", rte_socket_id(),
|
2017-03-20 10:08:30 +00:00
|
|
|
rte_lcore_count() - 1,
|
|
|
|
RTE_DIST_ALG_SINGLE);
|
2017-03-20 10:08:34 +00:00
|
|
|
if (ds == NULL) {
|
2014-05-29 10:12:17 +00:00
|
|
|
printf("Error creating distributor\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
2017-03-20 10:08:34 +00:00
|
|
|
rte_distributor_clear_returns(ds);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (db == NULL) {
|
|
|
|
db = rte_distributor_create("Test_burst", rte_socket_id(),
|
|
|
|
rte_lcore_count() - 1,
|
|
|
|
RTE_DIST_ALG_BURST);
|
|
|
|
if (db == NULL) {
|
|
|
|
printf("Error creating burst distributor\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rte_distributor_clear_returns(db);
|
2014-05-29 10:12:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned nb_bufs = (511 * rte_lcore_count()) < BIG_BATCH ?
|
|
|
|
(BIG_BATCH * 2) - 1 : (511 * rte_lcore_count());
|
|
|
|
if (p == NULL) {
|
2015-04-22 09:57:24 +00:00
|
|
|
p = rte_pktmbuf_pool_create("DPT_MBUF_POOL", nb_bufs, BURST,
|
2015-04-29 23:31:51 +00:00
|
|
|
0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
|
2014-05-29 10:12:17 +00:00
|
|
|
if (p == NULL) {
|
|
|
|
printf("Error creating mempool\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-20 10:08:34 +00:00
|
|
|
printf("=== Performance test of distributor (single mode) ===\n");
|
2020-10-15 22:57:19 +00:00
|
|
|
rte_eal_mp_remote_launch(handle_work, ds, SKIP_MAIN);
|
2017-03-20 10:08:34 +00:00
|
|
|
if (perf_test(ds, p) < 0)
|
|
|
|
return -1;
|
|
|
|
quit_workers(ds, p);
|
|
|
|
|
|
|
|
printf("=== Performance test of distributor (burst mode) ===\n");
|
2020-10-15 22:57:19 +00:00
|
|
|
rte_eal_mp_remote_launch(handle_work, db, SKIP_MAIN);
|
2017-03-20 10:08:34 +00:00
|
|
|
if (perf_test(db, p) < 0)
|
2014-05-29 10:12:17 +00:00
|
|
|
return -1;
|
2017-03-20 10:08:34 +00:00
|
|
|
quit_workers(db, p);
|
2014-05-29 10:12:17 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-13 12:38:13 +00:00
|
|
|
REGISTER_TEST_COMMAND(distributor_perf_autotest, test_distributor_perf);
|