diff options
| author | Qiuwen Lu <[email protected]> | 2017-03-22 14:41:35 +0800 |
|---|---|---|
| committer | Qiuwen Lu <[email protected]> | 2017-03-22 14:41:35 +0800 |
| commit | 83de81b8f4b4fe4faabc23517efa791430f65ac2 (patch) | |
| tree | 38f628e646ab9067bcdaa66453ca0b3170fbc439 /examples | |
| parent | 6e1fe7e6803a50f9a432c489f4d1c3356fce8e9e (diff) | |
增加线程绑定功能。修正虚设备销毁部分实现。修正数据面处理流程的Bug。
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | examples/l2fwd.c | 41 |
2 files changed, 42 insertions, 1 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 481ded3..f471896 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -4,7 +4,7 @@ include_directories(${DPDK_INCLUDE_DIR}) add_definitions(${DPDK_C_PREDEFINED}) add_executable(mrtest-l2fwd l2fwd.c) -target_link_libraries(mrtest-l2fwd marsio) +target_link_libraries(mrtest-l2fwd marsio pthread) #add_executable(pag_rx_sample pag/rx_sample.c) #target_link_libraries(pag_rx_sample pag)
\ No newline at end of file diff --git a/examples/l2fwd.c b/examples/l2fwd.c index 6032ae5..0f9f385 100644 --- a/examples/l2fwd.c +++ b/examples/l2fwd.c @@ -15,6 +15,30 @@ unsigned int nr_thread; struct mr_instance * mr_instance = NULL; struct mr_vdev * dev_1_handler = NULL; struct mr_vdev * dev_2_handler = NULL; +struct mr_sendpath * to_dev_1_sendpath = NULL; +struct mr_sendpath * to_dev_2_sendpath = NULL; + +#define BURST_MAX 64 +unsigned int nr_burst = 32; + +void * l2fwd_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_1_handler, sid, rx_buff, nr_burst); + marsio_send_burst(to_dev_2_sendpath, sid, rx_buff, ret); + ret = marsio_recv_burst(dev_2_handler, sid, rx_buff, nr_burst); + marsio_send_burst(to_dev_1_sendpath, sid, rx_buff, ret); + } + + return (void *)NULL; +} int main(int argc, char * argv[]) { @@ -33,5 +57,22 @@ int main(int argc, char * argv[]) nr_thread = __builtin_popcountll(cpu_mask); dev_1_handler = marsio_open_device(mr_instance, dev_1_symbol, nr_thread, nr_thread); dev_2_handler = marsio_open_device(mr_instance, dev_2_symbol, nr_thread, nr_thread); + to_dev_1_sendpath = marsio_sendpath_create_by_vdev(dev_1_handler); + to_dev_2_sendpath = marsio_sendpath_create_by_vdev(dev_2_handler); + + fprintf(stdout, "Thread Count = %d\n", nr_thread); + pthread_t __tmp_pid[nr_thread]; + for (int i = 0; i < nr_thread; i++) + { + pthread_create(&__tmp_pid[i], NULL, l2fwd_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, "L2FWD is terminated. "); return 0; }
\ No newline at end of file |
