Chinaunix首页 | 论坛 | 博客
  • 博客访问: 228591
  • 博文数量: 31
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 296
  • 用 户 组: 普通用户
  • 注册时间: 2016-06-22 11:52
文章分类

全部博文(31)

文章存档

2018年(3)

2017年(11)

2016年(12)

2015年(5)

我的朋友

分类: C/C++

2016-11-30 19:23:04


点击(此处)折叠或打开

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdint.h>
  4. #include <errno.h>
  5. #include <sys/queue.h>

  6. #include <rte_memory.h>
  7. #include <rte_memzone.h>
  8. #include <rte_launch.h>
  9. #include <rte_eal.h>
  10. #include <rte_per_lcore.h>
  11. #include <rte_lcore.h>
  12. #include <rte_debug.h>

  13. static int lcore_hello(__attribute__((unused)) void *arg) /*要在多个cpu上运行的代码*/
  14. {
  15.     unsigned lcore_id;
  16.     lcore_id = rte_lcore_id();
  17. /* if(lcore_id == 2){ /*test code 1*/
  18. #include <unistd.h>
  19.         sleep (1);
  20.     } */
  21.     printf("hello from core %u\n", lcore_id);
  22.     return 0;
  23. }

  24. int main(int argc, char **argv)
  25. {
  26.     int ret;
  27.     unsigned lcore_id;

  28.     ret = rte_eal_init(argc, argv);
  29.     if (ret < 0)
  30.         rte_panic("Cannot init EAL\n");

  31.     /* call lcore_hello() on every slave lcore */
  32.     RTE_LCORE_FOREACH_SLAVE(lcore_id) {
  33.         rte_eal_remote_launch(lcore_hello, NULL, lcore_id);
  34.     }

  35.     /* call it on master lcore too */
  36.     lcore_hello(NULL);

  37.     rte_eal_mp_wait_lcore(); /*test point 1*/
  38.     return 0;
  39. }



这个例子比较简单,主要就是学习让代码运行在各个cpu上的接口rte_eal_remote_launch, 以及等待各个cpu运行完成再返回的接口rte_eal_mp_wait_lcore,。其实就跟绑定cpu 是一样的
添加了test code 1, 测试一下rte_eal_mp_wait_lcore的作用是否如自己理解的那样,等待所有cpu运行完成注册的函数lcore_hello才返回,当注释掉test point 1的时候,结果如下:

打开test point 1的注释结果如下:

结论,对rte_eal_mp_wait_lcore的理解正确
阅读(1835) | 评论(0) | 转发(0) |
0

上一篇:内存管理二

下一篇:udp connect 总结

给主人留下些什么吧!~~