tools: ynl: turn the page-pool sample into a real tool
Subsystems (3)
Jakub Kicinski
maintainerv2 cover tools: ynl: turn the page-pool sample into a real tool
The page-pool YNL sample is quite useful. It's helps calculate recycling rate and memory consumption. Since we still haven't figured out a way to integrate with iproute2 (not for the lack of thinking how to solve it) - create a ynltool command in ynl.
Add page-pool and qstats support.
Most commands can use the Python YNL CLI directly but low level stats often need aggregation or some math on top to be useful. Specifically in this patch set:
- page pool stats are aggregated and recycling rate computed
- per-queue stats are used to compute traffic balance across queues
v2:
- patch 1 was applied already
- [patch 1 (was 2)] use kernel version
- [patch 2 (was 3)] Makefile cleanup
v1: https://lore.kernel.org/[email protected]
Jakub Kicinski (4):
tools: ynltool: create skeleton for the C command
tools: ynltool: add page-pool stats
tools: ynltool: add qstats support
tools: ynltool: add traffic distribution balance
tools/net/ynl/Makefile | 3 +- tools/net/ynl/ynltool/Makefile | 55 +++ tools/net/ynl/ynltool/json_writer.h | 75 ++++ tools/net/ynl/ynltool/main.h | 66 +++ tools/net/ynl/samples/page-pool.c | 149 ------- tools/net/ynl/ynltool/json_writer.c | 288 +++++++++++++ tools/net/ynl/ynltool/main.c | 242 +++++++++++ tools/net/ynl/ynltool/page-pool.c | 461 +++++++++++++++++++++ tools/net/ynl/ynltool/qstats.c | 621 ++++++++++++++++++++++++++++ tools/net/ynl/ynltool/.gitignore | 1 + 10 files changed, 1811 insertions(+), 150 deletions(-) create mode 100644 tools/net/ynl/ynltool/Makefile create mode 100644 tools/net/ynl/ynltool/json_writer.h create mode 100644 tools/net/ynl/ynltool/main.h delete mode 100644 tools/net/ynl/samples/page-pool.c create mode 100644 tools/net/ynl/ynltool/json_writer.c create mode 100644 tools/net/ynl/ynltool/main.c create mode 100644 tools/net/ynl/ynltool/page-pool.c create mode 100644 tools/net/ynl/ynltool/qstats.c create mode 100644 tools/net/ynl/ynltool/.gitignore
Signature · 1 line
2.51.1
Jakub Kicinski
maintainerPATCH v2 1/4 tools: ynltool: create skeleton for the C command
Based on past discussions it seems like integration of YNL into iproute2 is unlikely. YNL itself is not great as a C library, since it has no backward compat (we routinely change types).
Most of the operations can be performed with the generic Python CLI directly. There is, however, a handful of operations where summarization of kernel output is very useful (mostly related to stats: page-pool, qstat).
Create a command (inspired by bpftool, I think it stood the test of time reasonably well) to be able to plug the subcommands into.
---
v2:
- use kernel source version
v1: https://lore.kernel.org/[email protected]
--- tools/net/ynl/Makefile | 3 +- tools/net/ynl/ynltool/Makefile | 52 +++++ tools/net/ynl/ynltool/json_writer.h | 75 ++++++++ tools/net/ynl/ynltool/main.h | 62 ++++++ tools/net/ynl/ynltool/json_writer.c | 288 ++++++++++++++++++++++++++++ tools/net/ynl/ynltool/main.c | 240 +++++++++++++++++++++++ tools/net/ynl/ynltool/.gitignore | 1 + 7 files changed, 720 insertions(+), 1 deletion(-) create mode 100644 tools/net/ynl/ynltool/Makefile create mode 100644 tools/net/ynl/ynltool/json_writer.h create mode 100644 tools/net/ynl/ynltool/main.h create mode 100644 tools/net/ynl/ynltool/json_writer.c create mode 100644 tools/net/ynl/ynltool/main.c create mode 100644 tools/net/ynl/ynltool/.gitignore
tools/net/ynl/Makefile +2 -1
@@ -12,10 +12,11 @@ endif libdir ?= $(prefix)/$(libdir_relative) includedir ?= $(prefix)/include -SUBDIRS = lib generated samples +SUBDIRS = lib generated samples ynltool all: $(SUBDIRS) libynl.a +ynltool: | lib generated libynl.a samples: | lib generated libynl.a: | lib generated @echo -e "\tAR $@"
tools/net/ynl/ynltool/Makefile new file +52 -0
52 lines not on this page · raw message
tools/net/ynl/ynltool/json_writer.h new file +75 -0
75 lines not on this page · raw message
tools/net/ynl/ynltool/main.h new file +62 -0
62 lines not on this page · raw message
tools/net/ynl/ynltool/json_writer.c new file +288 -0
288 lines not on this page · raw message
tools/net/ynl/ynltool/main.c new file +240 -0
240 lines not on this page · raw message
tools/net/ynl/ynltool/.gitignore new file +1 -0
@@ -0,0 +1 @@ +ynltool
Signature · 1 line
2.51.1
Paolo Abeni
maintainerRe: [PATCH net-next v2 1/4] tools: ynltool: create skeleton for the C command
Quoted 10 lines · Jakub Kicinski
Based on past discussions it seems like integration of YNL into iproute2 is unlikely. YNL itself is not great as a C library, since it has no backward compat (we routinely change types).
Most of the operations can be performed with the generic Python CLI directly. There is, however, a handful of operations where summarization of kernel output is very useful (mostly related to stats: page-pool, qstat).
Create a command (inspired by bpftool, I think it stood the test
FTR, it took me a little to understand that for this patch at least is "inspired" alike the notorious MS socket implementation ;)
Quoted 86 lines
of time reasonably well) to be able to plug the subcommands into.
Signed-off-by Jakub Kicinski <[email protected]>---
v2:
- use kernel source version
v1: https://lore.kernel.org/[email protected]--- tools/net/ynl/Makefile | 3 +- tools/net/ynl/ynltool/Makefile | 52 +++++ tools/net/ynl/ynltool/json_writer.h | 75 ++++++++ tools/net/ynl/ynltool/main.h | 62 ++++++ tools/net/ynl/ynltool/json_writer.c | 288 ++++++++++++++++++++++++++++ tools/net/ynl/ynltool/main.c | 240 +++++++++++++++++++++++ tools/net/ynl/ynltool/.gitignore | 1 + 7 files changed, 720 insertions(+), 1 deletion(-) create mode 100644 tools/net/ynl/ynltool/Makefile create mode 100644 tools/net/ynl/ynltool/json_writer.h create mode 100644 tools/net/ynl/ynltool/main.h create mode 100644 tools/net/ynl/ynltool/json_writer.c create mode 100644 tools/net/ynl/ynltool/main.c create mode 100644 tools/net/ynl/ynltool/.gitignoretools/net/ynl/Makefile +2
-1@@ -12,10 +12,11 @@ endif libdir ?= $(prefix)/$(libdir_relative) includedir ?= $(prefix)/include -SUBDIRS = lib generated samples +SUBDIRS = lib generated samples ynltool all: $(SUBDIRS) libynl.a +ynltool: | lib generated libynl.a samples: | lib generated libynl.a: | lib generated @echo -e "\tAR $@"tools/net/ynl/ynltool/Makefile new file +39
-0@@ -0,0 +1,52 @@ +# SPDX-License-Identifier: GPL-2.0-only + +include ../Makefile.deps + +INSTALL ?= install +prefix ?= /usr + +CC := gcc +CFLAGS := -Wall -Wextra -Werror -O2 +ifeq ("$(DEBUG)","1") + CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan +endif +CFLAGS += -I../lib + +SRC_VERSION := \ + $(shell make --no-print-directory -sC ../../../.. kernelversion || \ + echo "unknown") + +CFLAGS += -DSRC_VERSION='"$(SRC_VERSION)"' + +SRCS := $(wildcard *.c) +OBJS := $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) + +YNLTOOL := $(OUTPUT)ynltool + +include $(wildcard *.d) + +all: $(YNLTOOL) + +Q = @ + +$(YNLTOOL): $(OBJS) + $(Q)echo -e "\tLINK $@" + $(Q)$(CC) $(CFLAGS) -o $@ $(OBJS) + +%.o: %.c main.h json_writer.h + $(Q)echo -e "\tCC $@" + $(Q)$(COMPILE.c) -MMD -c -o $@ $< +
tools/net/ynl/ynltool/Makefile line 49
Quoted 10 lines
tools/net/ynl/ynltool/Makefile new file +10
-0+clean: + rm -f *.o *.d *~ + +distclean: clean + rm -f $(YNLTOOL) + +bindir ?= /usr/bin + +install: $(YNLTOOL) + install -m 0755 $(YNLTOOL) $(DESTDIR)$(bindir)/$(YNLTOOL)
Minor nit: $(INSTALL) above?
Also possibly using/including scripts/Makefile.include could avoid some code duplication? (or at least make the V=1 option effective)/
/P
Paolo Abeni
maintainerRe: [PATCH net-next v2 1/4] tools: ynltool: create skeleton for the C command
Quoted 8 lines · Paolo Abeni
tools/net/ynl/ynltool/Makefile line 49
Quoted 2 lines · Jakub Kicinski
tools/net/ynl/ynltool/Makefile new file +2
-0+install: $(YNLTOOL) + install -m 0755 $(YNLTOOL) $(DESTDIR)$(bindir)/$(YNLTOOL)Minor nit: $(INSTALL) above?
Also possibly using/including
scripts/Makefile.includecould avoid some code duplication? (or at least make the V=1 option effective)/
All very minor. I think it's better to follow-up (if agreed) than to repost.
/P
Jakub Kicinski
maintainerPATCH v2 2/4 tools: ynltool: add page-pool stats
In reply to Jakub KicinskiReplace the page-pool sample with page pool support in ynltool.
# ynltool page-pool stats
eth0[2] page pools: 18 (zombies: 0)
refs: 171456 bytes: 702283776 (refs: 0 bytes: 0)
recycling: 97.3% (alloc: 2679:6134966 recycle: 1250981:4719386)
# ynltool -j page-pool stats | jq
[
{
"ifname": "eth0",
"ifindex": 2,
"page_pools": 18,
"zombies": 0,
"live": {
"refs": 171456,
"bytes": 702283776
},
"zombie": {
"refs": 0,
"bytes": 0
},
"recycling_pct": 97.2746,
"alloc": {
"slow": 2679,
"fast": 6135029
},
"recycle": {
"ring": 1250997,
"cache": 4719432
}
}
]# ynltool page-pool stats group-by pp pool id: 108 dev: eth0[2] napi: 530 inflight: 9472 pages 38797312 bytes recycling: 95.5% (alloc: 148:208379 recycle: 45386:153842) pool id: 107 dev: eth0[2] napi: 529 inflight: 9408 pages 38535168 bytes recycling: 94.9% (alloc: 147:180178 recycle: 42251:128808)
---
v2:
- cleanup the Makefile deps a little
v1: https://lore.kernel.org/[email protected]
--- tools/net/ynl/ynltool/Makefile | 11 +- tools/net/ynl/ynltool/main.h | 3 + tools/net/ynl/samples/page-pool.c | 149 ---------- tools/net/ynl/ynltool/main.c | 3 +- tools/net/ynl/ynltool/page-pool.c | 461 ++++++++++++++++++++++++++++++ 5 files changed, 473 insertions(+), 154 deletions(-) delete mode 100644 tools/net/ynl/samples/page-pool.c create mode 100644 tools/net/ynl/ynltool/page-pool.c
tools/net/ynl/ynltool/Makefile +7 -4
@@ -10,7 +10,7 @@ CFLAGS := -Wall -Wextra -Werror -O2 ifeq ("$(DEBUG)","1") CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan endif -CFLAGS += -I../lib +CFLAGS += -I../lib -I../generated -I../../../include/uapi/ SRC_VERSION := \ $(shell make --no-print-directory -sC ../../../.. kernelversion || \
@@ -29,14 +29,17 @@ all: $(YNLTOOL) Q = @ -$(YNLTOOL): $(OBJS) +$(YNLTOOL): ../libynl.a $(OBJS) $(Q)echo -e "\tLINK $@" - $(Q)$(CC) $(CFLAGS) -o $@ $(OBJS) + $(Q)$(CC) $(CFLAGS) -o $@ $(OBJS) ../libynl.a -lmnl -%.o: %.c main.h json_writer.h +%.o: %.c ../libynl.a $(Q)echo -e "\tCC $@" $(Q)$(COMPILE.c) -MMD -c -o $@ $< +../libynl.a: + $(Q)$(MAKE) -C ../ + clean: rm -f *.o *.d *~
tools/net/ynl/ynltool/main.h +3 -0
@@ -59,4 +59,7 @@ struct cmd {int cmd_select (const struct cmd *cmds,int argc,char **argv,int (*help)(int argc,char **argv)); +/* subcommands */ +int do_page_pool (int argc,char **argv); +#endif /* __YNLTOOL_H */
tools/net/ynl/samples/page-pool.c deleted +0 -149
149 lines not on this page · raw message
tools/net/ynl/ynltool/main.c +2 -1
@@ -47,7 +47,7 @@ static int do_help(int argc __attribute__((unused)),"Usage: %s [OPTIONS] OBJECT { COMMAND | help }\n" " %s version\n" "\n" -" OBJECT := { }\n" +" OBJECT := { page-pool }\n" " " HELP_SPEC_OPTIONS "\n" "" , bin_name, bin_name);
@@ -71,6 +71,7 @@ static int do_version(int argc __attribute__((unused)),static const struct cmd commands[] = { {"help" , do_help }, + {"page-pool" , do_page_pool }, {"version" , do_version }, {0 } };
tools/net/ynl/ynltool/page-pool.c new file +461 -0
461 lines not on this page · raw message
Signature · 1 line
2.51.1
Jakub Kicinski
maintainerPATCH v2 3/4 tools: ynltool: add qstats support
In reply to Jakub Kicinski $ ynltool qstat
eth0 rx-packets: 493192163 rx-bytes: 1442544543997
tx-packets: 745999838 tx-bytes: 4574215826482
tx-stop: 7033 tx-wake: 7033 $ ynltool qstat show group-by queue
eth0 rx-0 packets: 70196880 bytes: 178633973750
eth0 rx-1 packets: 63623419 bytes: 197274745250
...
eth0 tx-1 packets: 98645810 bytes: 631247647938
stop: 1048 wake: 1048
eth0 tx-2 packets: 86775824 bytes: 563930471952
stop: 1126 wake: 1126
... $ ynltool -j qstat | jq
[
{
"ifname": "eth0",
"ifindex": 2,
"rx": {
"packets": 493396439,
"bytes": 1443608198921
},
"tx": {
"packets": 746239978,
"bytes": 4574333772645,
"stop": 7072,
"wake": 7072
}
}
]--- tools/net/ynl/ynltool/main.h | 1 + tools/net/ynl/ynltool/main.c | 3 +- tools/net/ynl/ynltool/qstats.c | 330 +++++++++++++++++++++++++++++++++ 3 files changed, 333 insertions(+), 1 deletion(-) create mode 100644 tools/net/ynl/ynltool/qstats.c
tools/net/ynl/ynltool/main.h +1 -0
@@ -61,5 +61,6 @@ int cmd_select(const struct cmd *cmds, int argc, char **argv,/* subcommands */ int do_page_pool (int argc,char **argv); +int do_qstats (int argc,char **argv);#endif /* __YNLTOOL_H */
tools/net/ynl/ynltool/main.c +2 -1
@@ -47,7 +47,7 @@ static int do_help(int argc __attribute__((unused)),"Usage: %s [OPTIONS] OBJECT { COMMAND | help }\n" " %s version\n" "\n" -" OBJECT := { page-pool }\n" +" OBJECT := { page-pool | qstats }\n" " " HELP_SPEC_OPTIONS "\n" "" , bin_name, bin_name);
@@ -72,6 +72,7 @@ static int do_version(int argc __attribute__((unused)),static const struct cmd commands[] = { {"help" , do_help }, {"page-pool" , do_page_pool }, + {"qstats" , do_qstats }, {"version" , do_version }, {0 } };
tools/net/ynl/ynltool/qstats.c new file +330 -0
330 lines not on this page · raw message
Signature · 1 line
2.51.1
Jakub Kicinski
maintainerPATCH v2 4/4 tools: ynltool: add traffic distribution balance
In reply to Jakub KicinskiThe main if not only use case for per-queue stats today is checking for traffic imbalance. Add simple traffic balance analysis to qstats.
$ ynltool qstat balance
eth0 rx 44 queues:
rx-packets : cv=6.9% ns=24.2% stddev=512006493
min=6278921110 max=8011570575 mean=7437054644
rx-bytes : cv=6.9% ns=24.1% stddev=759670503060
min=9326315769440 max=11884393670786 mean=11035439201354
... $ ynltool -j qstat balance | jq
[
{
"ifname": "eth0",
"ifindex": 2,
"queue-type": "rx",
"rx-packets": {
"queue-count": 44,
"min": 6278301665,
"max": 8010780185,
"mean": 7.43635E+9,
"stddev": 5.12012E+8,
"coefficient-of-variation": 6.88525,
"normalized-spread": 24.249
},
...--- tools/net/ynl/ynltool/Makefile | 2 +- tools/net/ynl/ynltool/qstats.c | 293 ++++++++++++++++++++++++++++++++- 2 files changed, 293 insertions(+), 2 deletions(-)
tools/net/ynl/ynltool/Makefile +1 -1
@@ -31,7 +31,7 @@ Q = @ $(YNLTOOL): ../libynl.a $(OBJS) $(Q)echo -e "\tLINK $@" - $(Q)$(CC) $(CFLAGS) -o $@ $(OBJS) ../libynl.a -lmnl + $(Q)$(CC) $(CFLAGS) -o $@ $(OBJS) ../libynl.a -lmnl -lm %.o: %.c ../libynl.a $(Q)echo -e "\tCC $@"
tools/net/ynl/ynltool/qstats.c +292 -1
330 lines not on this page · raw message
Signature · 1 line
2.51.1
Quoted 13 lines · Jakub Kicinski
The page-pool YNL sample is quite useful. It's helps calculate recycling rate and memory consumption. Since we still haven't figured out a way to integrate with iproute2 (not for the lack of thinking how to solve it) - create a ynltool command in ynl.
Add page-pool and qstats support.
Most commands can use the Python YNL CLI directly but low level stats often need aggregation or some math on top to be useful. Specifically in this patch set:
- page pool stats are aggregated and recycling rate computed
- per-queue stats are used to compute traffic balance across queues
Quoted 4 lines
v2:
- patch 1 was applied already
- [patch 1 (was 2)] use kernel version
- [patch 2 (was 3)]Makefilecleanup
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 8 lines · On Fri, 7 Nov 2025 08:22:23 -0800 you wrote:
The page-pool YNL sample is quite useful. It's helps calculate recycling rate and memory consumption. Since we still haven't figured out a way to integrate with iproute2 (not for the lack of thinking how to solve it) - create a ynltool command in ynl.
Add page-pool and qstats support.
[...]
Here is the summary with links:
- [net-next,v2,1/4] tools: ynltool: create skeleton for the C command
https://git.kernel.org/netdev/net-next/c/b02d229013aa - [net-next,v2,2/4] tools: ynltool: add page-pool stats https://git.kernel.org/netdev/net-next/c/124dac9b421c - [net-next,v2,3/4] tools: ynltool: add qstats support https://git.kernel.org/netdev/net-next/c/3f0a638d45fc - [net-next,v2,4/4] tools: ynltool: add traffic distribution balance https://git.kernel.org/netdev/net-next/c/9eef97a9dea3
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html