dpdk example——helloworld

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012570105/article/details/82385675
运行helloworld
  • 代码分析
static int manjingliu = 0;
static rte_rwlock_t sl;

static int
lcore_hello(__attribute__((unused)) void *arg)
{
    unsigned lcore_id;
    lcore_id = rte_lcore_id();
    printf("hello from core %u\n", lcore_id);

    rte_rwlock_write_lock(&sl);
    printf("Global write lock taken on core %u: %d\n", rte_lcore_id(), ++manjingliu);
    rte_rwlock_write_unlock(&sl);
    return 0;
}

int
main(int argc, char **argv)
{
 int ret;
 unsigned lcore_id;

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

 /* call lcore_hello() on every slave lcore */
 // 遍历逻辑核(除了主核)
 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
  // 在指定的逻辑核上运行指定的线程函数
  rte_eal_remote_launch(lcore_hello, NULL, lcore_id);
 }

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

 rte_eal_mp_wait_lcore();
 return 0;
}

result:
EAL: PCI memory mapped at 0x7ffff708c000
PMD: eth_em_dev_init(): port_id 3 vendorID=0x8086 deviceID=0x150c
hello from core 1
Global write lock taken on core 1: 1
hello from core 0
Global write lock taken on core 0: 2
hello from core 2
Global write lock taken on core 2: 3
hello from core 3
Global write lock taken on core 3: 4
  • 运行
    • ./helloworld –
    • 每个核上面工作了一个线程
    • 主核上又一个eal-intr-thread线程

猜你喜欢

转载自blog.csdn.net/u012570105/article/details/82385675