Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Review] Dpdk: add symmetric_mp test #3629

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
DPDK: add devname helper
  • Loading branch information
mcgov committed Feb 5, 2025
commit 08fa9d8a1b533036042ca4ad9fe1274b103a0aaf
51 changes: 51 additions & 0 deletions microsoft/testsuites/dpdk/devname/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2010-2014 Intel Corporation

# binary name
APP = devname

# all source are stored in SRCS-y
SRCS-y := main.c

PKGCONF ?= pkg-config

# Build using pkg-config variables if possible
ifneq ($(shell $(PKGCONF) --exists libdpdk && echo 0),0)
$(error "no installation of DPDK found")
endif

all: shared
.PHONY: shared static
shared: build/$(APP)-shared
ln -sf $(APP)-shared build/$(APP)
static: build/$(APP)-static
ln -sf $(APP)-static build/$(APP)

PC_FILE := $(shell $(PKGCONF) --path libdpdk 2>/dev/null)
CFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk)
LDFLAGS_SHARED = $(shell $(PKGCONF) --libs libdpdk)
LDFLAGS_STATIC = $(shell $(PKGCONF) --static --libs libdpdk)

ifeq ($(MAKECMDGOALS),static)
# check for broken pkg-config
ifeq ($(shell echo $(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")
endif
endif

CFLAGS += -DALLOW_EXPERIMENTAL_API

build/$(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: clean
clean:
rm -f build/$(APP) build/$(APP)-static build/$(APP)-shared
test -d build && rmdir -p build || true
33 changes: 33 additions & 0 deletions microsoft/testsuites/dpdk/devname/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# dpdk-devname

Print info about DPDK ports on a system.

## NOTE: This is a frozen copy from https://www.github.com/mcgov/devname

## build
clone into dpdk/examples
``` bash
git clone https://www.github.com/DPDK/dpdk.git
cd ./dpdk/examples
git clone https://github.com/mcgov/devname.git
cd ..
meson setup -Dexamples=devname [other options] build
cd build && ninja && ninja install
```

## usage:
```
$ ./build/examples/dpdk-devname
EAL: Detected CPU lcores: 32
EAL: Detected NUMA nodes: 1
EAL: Detected static linkage of DPDK
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: Selected IOVA mode 'PA'
EAL: Probe PCI driver: net_mana (1414:ba) device: 7870:00:00.0 (socket 0)
mana_init_once(): MP INIT PRIMARY
TELEMETRY: No legacy callbacks, legacy socket not created
dpdk-devname found port=0 driver=net_mana eth_dev_info_name=7870:00:00.0 get_name_by_port_name=7870:00:00.0_port3 owner_id=0x0000000000000002 owner_name=f8615163-0002-1000-2000-6045bda6bbc0 macaddr=60:45:bd:a6:bb:c0
dpdk-devname found port=1 driver=net_mana eth_dev_info_name=7870:00:00.0 get_name_by_port_name=7870:00:00.0_port2 owner_id=0x0000000000000001 owner_name=f8615163-0001-1000-2000-6045bda6bd76 macaddr=60:45:bd:a6:bd:76
dpdk-devname found port=2 driver=net_netvsc eth_dev_info_name=f8615163-0001-1000-2000-6045bda6bd76 get_name_by_port_name=f8615163-0001-1000-2000-6045bda6bd76 owner_id=0x0000000000000000 owner_name=null macaddr=60:45:bd:a6:bd:76
dpdk-devname found port=3 driver=net_netvsc eth_dev_info_name=f8615163-0002-1000-2000-6045bda6bbc0 get_name_by_port_name=f8615163-0002-1000-2000-6045bda6bbc0 owner_id=0x0000000000000000 owner_name=null macaddr=60:45:bd:a6:bb:c0
```
98 changes: 98 additions & 0 deletions microsoft/testsuites/dpdk/devname/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2010-2014 Intel Corporation
*/

#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>
#include <rte_ethdev.h>
#include <rte_dev.h>

const char usage_info[] = "usage: dpdk-devname\n";

/*a tiny application to print dpdk device and port id info */
int main(int argc, char **argv)
{
int ret;
/* Initialization of Environment Abstraction Layer (EAL). */
ret = rte_eal_init(argc, argv);
if (ret < 0)
rte_panic("Cannot init EAL\n");
/* >8 End of initialization of Environment Abstraction Layer */

struct rte_eth_dev_info device_info;
char device_name_by_port[RTE_ETH_NAME_MAX_LEN] = {0};
for (uint16_t portid = 0; portid < RTE_MAX_ETHPORTS; portid++)
{
if (!rte_eth_dev_is_valid_port(portid))
continue;

ret = rte_eth_dev_info_get(portid, &device_info);
if (ret < 0)
{
fprintf(stderr,
"Invalid or no info for port %i, err: %s\n",
portid, rte_strerror(ret));
continue;
}
ret = rte_eth_dev_get_name_by_port(portid, device_name_by_port);
if (ret < 0)
{
fprintf(stderr,
"No name info returned for port %i, err: %s\n",
portid, rte_strerror(ret));
continue;
}
struct rte_eth_dev_owner device_owner;
ret = rte_eth_dev_owner_get(portid, &device_owner);
if (ret < 0)
{
fprintf(stderr, "Could not get ownership for port %i (%s)\n",
portid, device_name_by_port);
memset(&device_owner, 0, sizeof(struct rte_eth_dev_owner));
}

if (!device_owner.name[0])
strcpy(device_owner.name, "null");

struct rte_ether_addr macaddr;
ret = rte_eth_macaddr_get(portid, &macaddr);
if (ret < 0)
{
fprintf(stderr, "Could not get macaddr info for port %i (%s)\n",
portid, device_name_by_port);
memset(&macaddr, 0, sizeof(struct rte_ether_addr));
}
printf("dpdk-devname found port=%i "
"driver=%s "
"get_name_by_port_name=%s "
"owner_id=0x%016lx "
"owner_name=%s "
"macaddr=%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n",
portid,
device_info.driver_name,
device_name_by_port,
device_owner.id,
device_owner.name,
macaddr.addr_bytes[0],
macaddr.addr_bytes[1],
macaddr.addr_bytes[2],
macaddr.addr_bytes[3],
macaddr.addr_bytes[4],
macaddr.addr_bytes[5]
);
}

/* clean up the EAL */
rte_eal_cleanup();

return 0;
}
12 changes: 12 additions & 0 deletions microsoft/testsuites/dpdk/devname/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2017 Intel Corporation

# meson file, for building this example as part of a main DPDK build.
#
# To build this example as a standalone application with an already-installed
# DPDK instance, use 'make'

allow_experimental_apis = true
sources = files(
'main.c',
)
18 changes: 13 additions & 5 deletions microsoft/testsuites/dpdk/dpdktestpmd.py
Original file line number Diff line number Diff line change
@@ -199,6 +199,7 @@ class DpdkSourceInstall(Installer):
"multi_process/client_server_mp/mp_server",
"multi_process/client_server_mp/mp_client",
"multi_process/symmetric_mp",
"devname",
]

def _check_if_installed(self) -> bool:
@@ -256,14 +257,21 @@ def get_installed_version(self) -> VersionInfo:
"libdpdk", update_cached=True
)

__devname_files = ["main.c", "Makefile", "meson.build"]

def _install(self) -> None:
super()._install()
_ = self._node.tools[Git].clone(
url="https://github.com/mcgov/devname.git",
cwd=self.asset_path.joinpath("examples"),
dir_name="devname",
# copy devname application into the examples directory
devname_local_folder = PurePath(__file__).parent.joinpath("devname")
self._node.shell.mkdir(
self.asset_path.joinpath("examples/devname"), parents=False, exist_ok=False
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might not want to have exist_ok=False? But it would be a good check if I end up trying to build DPDK twice without wiping the directory... Not sure.

)
self._sample_applications += ["devname"]
for file in self.__devname_files:
self._node.shell.copy(
devname_local_folder.joinpath(file),
self.asset_path.joinpath(f"examples/devname/{file}"),
)
# stringify the example app list
if self._sample_applications:
sample_apps = f"-Dexamples={','.join(self._sample_applications)}"
else:
Loading
Oops, something went wrong.