#include<stdio.h>#include<string.h>#include<stdint.h>#include<errno.h>#include<sys/queue.h>#include<rte_memory.h>#include<rte_launch.h>#include<rte_eal.h>#include<rte_per_lcore.h>#include<rte_lcore.h>#include<rte_debug.h>staticintlcore_hello(__attribute__((unused))void*arg){unsignedlcore_id;lcore_id=rte_lcore_id();printf("hello from core %u\n",lcore_id);return0;}intmain(intargc,char**argv){intret;unsignedlcore_id;// 1. 初始化环境抽象层(EAL)
ret=rte_eal_init(argc,argv);if(ret<0)rte_panic("Cannot init EAL\n");/* call lcore_hello() on every slave lcore */// 2. 在每个可用的lcore上调用lcore_hello
RTE_LCORE_FOREACH_WORKER(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();return0;}
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2010-2014 Intel Corporation
# binary name
APP=helloworld# all source are stored in SRCS-y
SRCS-y:=main.cPKGCONF?=pkg-config# Build using pkg-config variables if possible
ifneq($(shell$(PKGCONF)--existslibdpdk&&echo0),0)$(error"no installation of DPDK found")endifall:shared.PHONY:sharedstaticshared:build/$(APP)-sharedln-sf$(APP)-sharedbuild/$(APP)static:build/$(APP)-staticln-sf$(APP)-staticbuild/$(APP)PC_FILE:=$(shell$(PKGCONF)--pathlibdpdk2>/dev/null)CFLAGS+=-O3$(shell$(PKGCONF)--cflagslibdpdk)LDFLAGS_SHARED=$(shell$(PKGCONF)--libslibdpdk)LDFLAGS_STATIC=$(shell$(PKGCONF)--static--libslibdpdk)ifeq($(MAKECMDGOALS),static)# check for broken pkg-config
ifeq($(shellecho$(LDFLAGS_STATIC)|grep'whole-archive.*l:lib.*no-whole-archive'),)$(warning"pkg-config output list does not contain drivers between 'whole-archive'/'no-whole-archive' flags.")$(error"Cannot generate statically-linked binaries with this version of pkg-config")endifendifCFLAGS+=-DALLOW_EXPERIMENTAL_APIbuild/$(APP)-shared:$(SRCS-y)Makefile$(PC_FILE)|build$(CC)$(CFLAGS)$(SRCS-y)-o$@$(LDFLAGS)$(LDFLAGS_SHARED)build/$(APP)-static:$(SRCS-y)Makefile$(PC_FILE)|build$(CC)$(CFLAGS)$(SRCS-y)-o$@$(LDFLAGS)$(LDFLAGS_STATIC)build:@mkdir-p$@.PHONY:cleanclean:rm-fbuild/$(APP)build/$(APP)-staticbuild/$(APP)-sharedtest-dbuild&&rmdir-pbuild||true