#include #include #include #include #include #include static char appsym[64] = "rxonly"; static char dev_symbol[64] = "meth0"; uint64_t cpu_mask = 0x3c; unsigned int nr_thread; struct mr_instance * mr_instance = NULL; struct mr_vdev * dev_handler = NULL; struct mr_sendpath * sendpath = NULL; #define BURST_MAX 64 unsigned int nr_burst = 32; unsigned int self_loop = 0; void * txonly_loop(void * arg) { uintptr_t sid = (uintptr_t)arg; marsio_buff_t * rx_buff[BURST_MAX]; unsigned int ret = 0; marsio_thread_init(mr_instance); for (;;) { ret = marsio_recv_burst(dev_handler, sid, rx_buff, nr_burst); if (!self_loop) { marsio_buff_free(mr_instance, rx_buff, ret, 0, 0); } else { marsio_send_burst(sendpath, sid, rx_buff, ret); } } return (void *)NULL; } int help() { return 0; } int main(int argc, char * argv[]) { int opt = 0; while ((opt = getopt(argc, argv, "s:t:a:c:b:d:h?rl")) != -1) { char * endptr = NULL; switch (opt) { case '?': case 'h': { help(); break; } case 'd': { snprintf(dev_symbol, sizeof(dev_symbol), "%s", optarg); break; } case 'a': { snprintf(appsym, sizeof(appsym), "%s", optarg); break; } case 'c': { cpu_mask = strtoull(optarg, &endptr, 0); if (cpu_mask == 0 && endptr == optarg) help(); break; } case 'b': { nr_burst = strtoull(optarg, &endptr, 0); if (nr_burst == 0 && endptr == optarg) help(); break; } case 'l': { self_loop = 1; break; } default: help(); break; } } mr_instance = marsio_create(); if (mr_instance == NULL) { fprintf(stderr, "Marsio instance create failed. "); abort(); } unsigned int opt_value = 1; marsio_option_set(mr_instance, MARSIO_OPT_EXIT_WHEN_ERR, &opt_value, sizeof(opt_value)); marsio_option_set(mr_instance, MARSIO_OPT_THREAD_MASK, &cpu_mask, sizeof(cpu_mask)); marsio_init(mr_instance, appsym); nr_thread = __builtin_popcountll(cpu_mask); dev_handler = marsio_open_device(mr_instance, dev_symbol, nr_thread, nr_thread); fprintf(stdout, "Thread Count = %d\n", nr_thread); if (self_loop) { sendpath = marsio_sendpath_create(mr_instance, MR_SENDPATH_VDEV, dev_handler); } pthread_t __tmp_pid[nr_thread]; for (int i = 0; i < nr_thread; i++) { pthread_create(&__tmp_pid[i], NULL, txonly_loop, (void *) (uintptr_t) i); } for (int i = 0; i < nr_thread; i++) { pthread_join(__tmp_pid[i], NULL); } marsio_destory(mr_instance); fprintf(stdout, "RXONLY is terminated. "); return 0; }