in bpf/xsk_fwd.c [981:1088]
int main(int argc, char **argv)
{
struct timespec time;
u64 ns0;
int i;
/* Parse args. */
memcpy(&bpool_params, &bpool_params_default,
sizeof(struct bpool_params));
memcpy(&umem_cfg, &umem_cfg_default,
sizeof(struct xsk_umem_config));
for (i = 0; i < MAX_PORTS; i++)
memcpy(&port_params[i], &port_params_default,
sizeof(struct port_params));
if (parse_args(argc, argv)) {
print_usage(argv[0]);
return -1;
}
/* Buffer pool initialization. */
bp = bpool_init(&bpool_params, &umem_cfg);
if (!bp) {
printf("Buffer pool initialization failed.\n");
return -1;
}
printf("Buffer pool created successfully.\n");
/* Ports initialization. */
for (i = 0; i < MAX_PORTS; i++)
port_params[i].bp = bp;
for (i = 0; i < n_ports; i++) {
ports[i] = port_init(&port_params[i]);
if (!ports[i]) {
printf("Port %d initialization failed.\n", i);
return -1;
}
print_port(i);
}
printf("All ports created successfully.\n");
/* Threads. */
for (i = 0; i < n_threads; i++) {
struct thread_data *t = &thread_data[i];
u32 n_ports_per_thread = n_ports / n_threads, j;
for (j = 0; j < n_ports_per_thread; j++) {
t->ports_rx[j] = ports[i * n_ports_per_thread + j];
t->ports_tx[j] = ports[i * n_ports_per_thread +
(j + 1) % n_ports_per_thread];
}
t->n_ports_rx = n_ports_per_thread;
print_thread(i);
}
for (i = 0; i < n_threads; i++) {
int status;
status = pthread_create(&threads[i],
NULL,
thread_func,
&thread_data[i]);
if (status) {
printf("Thread %d creation failed.\n", i);
return -1;
}
}
printf("All threads created successfully.\n");
/* Print statistics. */
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
signal(SIGABRT, signal_handler);
clock_gettime(CLOCK_MONOTONIC, &time);
ns0 = time.tv_sec * 1000000000UL + time.tv_nsec;
for ( ; !quit; ) {
u64 ns1, ns_diff;
sleep(1);
clock_gettime(CLOCK_MONOTONIC, &time);
ns1 = time.tv_sec * 1000000000UL + time.tv_nsec;
ns_diff = ns1 - ns0;
ns0 = ns1;
print_port_stats_all(ns_diff);
}
/* Threads completion. */
printf("Quit.\n");
for (i = 0; i < n_threads; i++)
thread_data[i].quit = 1;
for (i = 0; i < n_threads; i++)
pthread_join(threads[i], NULL);
for (i = 0; i < n_ports; i++)
port_free(ports[i]);
bpool_free(bp);
remove_xdp_program();
return 0;
}