第一步:先切换到simple_mp目录下,在dpdk/examples/multi_process/simple_mp目录下
第二步:编译
make
第三步:运行
先启动primary进程,-l参数指定使用的逻辑核为core0和core1,–proc-type参数可以省略,默认第一个进程是primary进程,也可以指定值auto,表示自动检测进程的类型。
./simple_mp -l 0,1 --proc-type primary
secondary进程需要在primary进程之后启动,–proc-type参数必须指定(因为不指定该参数,将默认为primary进程,程序将初始化失败,因为已经存在了primary进程),值可以为secondary或auto:
./simple_mp -l 0,1 --proc-type secondary
secondary进程启动后,同样进入simple_mp命令行。
simple_mp使用dpdk cmd_line完成命令行功能,启动simple_mp程序后,输入?
可以查看支持的命令:
simple_mp >
send [Fixed STRING]: send a string to another process
quit [Fixed STRING]: close the application
help [Fixed STRING]: show help
也可以输入help
查看帮助:
simple_mp > help
Simple demo example of multi-process in RTE
This is a readline-like interface that can be used to
send commands to the simple app. Commands supported are:
- send [string]
- help
- quit
在primary进程的命令行中,输入:
simple_mp > send hello1
secondary进程将打印:
simple_mp > core 1: Received 'hello1'
在secondary进程执行send hello2,primary进程也将打印core 1: Received 'hello2'
main函数,将在primary进程创建两个ring队列
- 发送队列 PRI_2_SEC
- 接受队列 SEC_2_PRI
if (rte_eal_process_type() == RTE_PROC_PRIMARY){
send_ring = rte_ring_create(_PRI_2_SEC, ring_size, rte_socket_id(), flags);
recv_ring = rte_ring_create(_SEC_2_PRI, ring_size, rte_socket_id(), flags);
message_pool = rte_mempool_create(_MSG_POOL, pool_size,
string_size, pool_cache, priv_data_sz,
NULL, NULL, NULL, NULL,
rte_socket_id(), flags);
} else {
recv_ring = rte_ring_lookup(_PRI_2_SEC);
send_ring = rte_ring_lookup(_SEC_2_PRI);
message_pool = rte_mempool_lookup(_MSG_POOL);
}
对于secondary进程,查找发送和接受队列,顺序跟primary相反:
- 发送队列 SEC_2_PRI
- 接受队列 PRI_2_SEC
当在primary进程执行send hello1时,cmd_send_parsed函数执行入队PRI_2_SEC逻辑:
/* simple_mp/mp_commands.c */
static void cmd_send_parsed(void *parsed_result,
__attribute__((unused)) struct cmdline *cl,
__attribute__((unused)) void *data)
{
void *msg = NULL;
struct cmd_send_result *res = parsed_result;
if (rte_mempool_get(message_pool, &msg) < 0)
rte_panic("Failed to get message buffer\n");
snprintf((char *)msg, string_size, "%s", res->message);
if (rte_ring_enqueue(send_ring, msg) < 0) {
printf("Failed to send message - message discarded\n");
rte_mempool_put(message_pool, msg);
}
}
参考资料:
https://blog.csdn.net/yyywill/article/details/52967829