Skip to contentSkip to conversation

tools: bpftool: fix minor issues in bpftool and its documentation

PATCH Applied Quentin Monnet 3 participants 8 messages Apr 12, 2019 – Apr 16, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover tools: bpftool: fix minor issues in bpftool and its documentation

Hi,
This series brings a number of small fixes to bpftool and the related manual pages.

The first two patches are on bpftool itself (remove blank lines when dumping programs, do not set errno when showing a tree of cgroup programs).

The next two patches are fixes for the manual pages (missing keyword, wrong option name for showing bpftool version). The last one is not exactly a fix, but rather an addition to the man page, explaining how to dump program statistics.

Quentin Monnet (5):
tools: bpftool: remove blank line after btf_id when listing programs
tools: bpftool: reset errno for "bpftool cgroup tree"
tools: bpftool: fix man page documentation for "pinmaps" keyword
tools: bpftool: fix short option name for printing version in man
pages
tools: bpftool: add a note on program statistics in man page

 tools/bpf/bpftool/Documentation/bpftool-cgroup.rst  |  2 +-
 tools/bpf/bpftool/Documentation/bpftool-feature.rst |  2 +-
 tools/bpf/bpftool/Documentation/bpftool-map.rst     |  2 +-
 tools/bpf/bpftool/Documentation/bpftool-net.rst     |  2 +-
 tools/bpf/bpftool/Documentation/bpftool-perf.rst    |  2 +-
 tools/bpf/bpftool/Documentation/bpftool-prog.rst    | 12 ++++++++++--
 tools/bpf/bpftool/Documentation/bpftool.rst         |  2 +-
 tools/bpf/bpftool/cgroup.c                          |  7 +++++++
 tools/bpf/bpftool/prog.c                            |  2 +-
 9 files changed, 24 insertions(+), 9 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/5 tools: bpftool: remove blank line after btf_id when listing programs

Commit 569b0c77735d ("tools/bpftool: show btf id in program information") made bpftool print an empty line after each program entry when listing the BPF programs loaded on the system (plain output). This is especially confusing when some programs have an associated BTF id, and others don't. Let's remove the blank line.

---
 tools/bpf/bpftool/prog.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/prog.c +1 -1
index 81067803189e..4b7a307b9fc9 100644
@@ -323,7 +323,7 @@ static void print_prog_plain(struct bpf_prog_info *info, int fd)
 	}
 
 	if (info->btf_id)
-		printf("\n\tbtf_id %d\n", info->btf_id);
+		printf("\n\tbtf_id %d", info->btf_id);
 
 	printf("\n");
 }
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/5 tools: bpftool: reset errno for "bpftool cgroup tree"

In reply to Quentin Monnet

When trying to dump the tree of all cgroups under a given root node, bpftool attempts to query programs of all available attach types. Some of those attach types do not support queries, therefore several of the calls are actually expected to fail.

Those calls set errno to EINVAL, which has no consequence for dumping the rest of the tree. It does have consequences however if errno is inspected at a later time. For example, bpftool batch mode relies on errno to determine whether a command has succeeded, and whether it should carry on with the next command. Setting errno to EINVAL when everything worked as expected would therefore make such command fail:

        # echo 'cgroup tree \n net show' | \
                bpftool batch file -

To improve this, reset errno when its value is EINVAL after attempting to show programs for all existing attach types in do_show_tree_fn().

---
 tools/bpf/bpftool/cgroup.c | 7 +++++++
 1 file changed, 7 insertions(+)
tools/bpf/bpftool/cgroup.c +7 -0
index 4b5c8da2a7c0..a81b34343eb8 100644
@@ -248,6 +248,13 @@ static int do_show_tree_fn(const char *fpath, const struct stat *sb,
 	for (type = 0; type < __MAX_BPF_ATTACH_TYPE; type++)
 		show_attached_bpf_progs(cgroup_fd, type, ftw->level);
 
+	if (errno == EINVAL)
+		/* Last attach type does not support query.
+		 * Do not report an error for this, especially because batch
+		 * mode would stop processing commands.
+		 */
+		errno = 0;
+
 	if (json_output) {
 		jsonw_end_array(json_wtr);
 		jsonw_end_object(json_wtr);
Signature · 1 line
2.17.1
#3 lore raw

PATCH 3/5 tools: bpftool: fix man page documentation for "pinmaps" keyword

In reply to Quentin Monnet

The "pinmaps" keyword is present in the man page, in the verbose description of the "bpftool prog load" command. However, it is missing from the summary of available commands at the beginning of the file. Add it there as well.

---
 tools/bpf/bpftool/Documentation/bpftool-prog.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/Documentation/bpftool-prog.rst +1 -1
index 9386bd6e0396..49c33939239f 100644
@@ -25,7 +25,7 @@ PROG COMMANDS
 |	**bpftool** **prog dump xlated** *PROG* [{**file** *FILE* | **opcodes** | **visual** | **linum**}]
 |	**bpftool** **prog dump jited**  *PROG* [{**file** *FILE* | **opcodes** | **linum**}]
 |	**bpftool** **prog pin** *PROG* *FILE*
-|	**bpftool** **prog { load | loadall }** *OBJ* *PATH* [**type** *TYPE*] [**map** {**idx** *IDX* | **name** *NAME*} *MAP*] [**dev** *NAME*]
+|	**bpftool** **prog { load | loadall }** *OBJ* *PATH* [**type** *TYPE*] [**map** {**idx** *IDX* | **name** *NAME*} *MAP*] [**dev** *NAME*] [**pinmaps** *MAP_DIR*]
 |	**bpftool** **prog attach** *PROG* *ATTACH_TYPE* [*MAP*]
 |	**bpftool** **prog detach** *PROG* *ATTACH_TYPE* [*MAP*]
 |	**bpftool** **prog tracelog**
Signature · 1 line
2.17.1
#5 lore raw

PATCH 5/5 tools: bpftool: add a note on program statistics in man page

In reply to Quentin Monnet

Linux kernel now supports statistics for BPF programs, and bpftool is able to dump them. However, these statistics are not enabled by default, and administrators may not know how to access them.

Add a paragraph in bpftool documentation, under the description of the "bpftool prog show" command, to explain that such statistics are available and that their collection is controlled via a dedicated sysctl knob.

---
 tools/bpf/bpftool/Documentation/bpftool-prog.rst | 8 ++++++++
 1 file changed, 8 insertions(+)
tools/bpf/bpftool/Documentation/bpftool-prog.rst +8 -0
index f2beb79a77e7..bb9bb00c0c2c 100644
@@ -56,6 +56,14 @@ DESCRIPTION
 		  Output will start with program ID followed by program type and
 		  zero or more named attributes (depending on kernel version).
 
+		  Since Linux 5.1 the kernel can collect statistics on BPF
+		  programs (such as the total time spent running the program,
+		  and the number of times it was run). If available, bpftool
+		  shows such statistics. However, the kernel does not collect
+		  them by defaults, as it slightly impacts performance on each
+		  program run. Activation or deactivation of the feature is
+		  performed via the **kernel.bpf_stats_enabled** sysctl knob.
+
 	**bpftool prog dump xlated** *PROG* [{ **file** *FILE* | **opcodes** | **visual** | **linum** }]
 		  Dump eBPF instructions of the program from the kernel. By
 		  default, eBPF will be disassembled and printed to standard
Signature · 1 line
2.17.1
#4 lore raw

PATCH 4/5 tools: bpftool: fix short option name for printing version in man pages

In reply to Quentin Monnet

Manual pages would tell that option "-v" (lower case) would print the version number for bpftool. This is wrong: the short name of the option is "-V" (upper case). Fix the documentation accordingly.

---
 tools/bpf/bpftool/Documentation/bpftool-cgroup.rst  | 2 +-
 tools/bpf/bpftool/Documentation/bpftool-feature.rst | 2 +-
 tools/bpf/bpftool/Documentation/bpftool-map.rst     | 2 +-
 tools/bpf/bpftool/Documentation/bpftool-net.rst     | 2 +-
 tools/bpf/bpftool/Documentation/bpftool-perf.rst    | 2 +-
 tools/bpf/bpftool/Documentation/bpftool-prog.rst    | 2 +-
 tools/bpf/bpftool/Documentation/bpftool.rst         | 2 +-
 7 files changed, 7 insertions(+), 7 deletions(-)
tools/bpf/bpftool/Documentation/bpftool-cgroup.rst +1 -1
index 9bb9ace54ba8..5e3b7d9d7599 100644
@@ -99,7 +99,7 @@ OPTIONS
 	-h, --help
 		  Print short generic help message (similar to **bpftool help**).
 
-	-v, --version
+	-V, --version
 		  Print version number (similar to **bpftool version**).
 
 	-j, --json
tools/bpf/bpftool/Documentation/bpftool-feature.rst +1 -1
index 82de03dd8f52..10177343b7ce 100644
@@ -63,7 +63,7 @@ OPTIONS
 	-h, --help
 		  Print short generic help message (similar to **bpftool help**).
 
-	-v, --version
+	-V, --version
 		  Print version number (similar to **bpftool version**).
 
 	-j, --json
tools/bpf/bpftool/Documentation/bpftool-map.rst +1 -1
index 5c984ffc9f01..55ecf80ca03e 100644
@@ -135,7 +135,7 @@ OPTIONS
 	-h, --help
 		  Print short generic help message (similar to **bpftool help**).
 
-	-v, --version
+	-V, --version
 		  Print version number (similar to **bpftool version**).
 
 	-j, --json
tools/bpf/bpftool/Documentation/bpftool-net.rst +1 -1
index 779dab3650ee..6b692b428373 100644
@@ -55,7 +55,7 @@ OPTIONS
 	-h, --help
 		  Print short generic help message (similar to **bpftool help**).
 
-	-v, --version
+	-V, --version
 		  Print version number (similar to **bpftool version**).
 
 	-j, --json
tools/bpf/bpftool/Documentation/bpftool-perf.rst +1 -1
index bca5590a80d0..86154740fabb 100644
@@ -43,7 +43,7 @@ OPTIONS
 	-h, --help
 		  Print short generic help message (similar to **bpftool help**).
 
-	-v, --version
+	-V, --version
 		  Print version number (similar to **bpftool version**).
 
 	-j, --json
tools/bpf/bpftool/Documentation/bpftool-prog.rst +1 -1
index 49c33939239f..f2beb79a77e7 100644
@@ -144,7 +144,7 @@ OPTIONS
 	-h, --help
 		  Print short generic help message (similar to **bpftool help**).
 
-	-v, --version
+	-V, --version
 		  Print version number (similar to **bpftool version**).
 
 	-j, --json
tools/bpf/bpftool/Documentation/bpftool.rst +1 -1
index 4f2188845dd8..deb2ca911ddf 100644
@@ -49,7 +49,7 @@ OPTIONS
 	-h, --help
 		  Print short help message (similar to **bpftool help**).
 
-	-v, --version
+	-V, --version
 		  Print version number (similar to **bpftool version**).
 
 	-j, --json
Signature · 1 line
2.17.1
Acked-by on the v1 series
#6 lore raw
In reply to Quentin Monnet
Quoted 5 lines · Quentin Monnet

Hi,
This series brings a number of small fixes to bpftool and the related manual pages.

Quoted 7 lines

The first two patches are on bpftool itself (remove blank lines when dumping programs, do not set errno when showing a tree of cgroup programs).

The next two patches are fixes for the manual pages (missing keyword, wrong option name for showing bpftool version). The last one is not exactly a fix, but rather an addition to the man page, explaining how to dump program statistics.

For the set:

Quoted 23 lines

Quentin Monnet (5):
tools: bpftool: remove blank line after btf_id when listing programs
tools: bpftool: reset errno for "bpftool cgroup tree"
tools: bpftool: fix man page documentation for "pinmaps" keyword
tools: bpftool: fix short option name for printing version in man
pages
tools: bpftool: add a note on program statistics in man page

 tools/bpf/bpftool/Documentation/bpftool-cgroup.rst  |  2 +-
 tools/bpf/bpftool/Documentation/bpftool-feature.rst |  2 +-
 tools/bpf/bpftool/Documentation/bpftool-map.rst     |  2 +-
 tools/bpf/bpftool/Documentation/bpftool-net.rst     |  2 +-
 tools/bpf/bpftool/Documentation/bpftool-perf.rst    |  2 +-
 tools/bpf/bpftool/Documentation/bpftool-prog.rst    | 12 ++++++++++--
 tools/bpf/bpftool/Documentation/bpftool.rst         |  2 +-
 tools/bpf/bpftool/cgroup.c                          |  7 +++++++
 tools/bpf/bpftool/prog.c                            |  2 +-
 9 files changed, 24 insertions(+), 9 deletions(-)

--
2.17.1

maintainer Applied
#7 lore raw
In reply to Quentin Monnet
Quoted 20 lines · Quentin Monnet

Hi,
This series brings a number of small fixes to bpftool and the related manual pages.

The first two patches are on bpftool itself (remove blank lines when dumping programs, do not set errno when showing a tree of cgroup programs).

The next two patches are fixes for the manual pages (missing keyword, wrong option name for showing bpftool version). The last one is not exactly a fix, but rather an addition to the man page, explaining how to dump program statistics.

Quentin Monnet (5):
tools: bpftool: remove blank line after btf_id when listing programs
tools: bpftool: reset errno for "bpftool cgroup tree"
tools: bpftool: fix man page documentation for "pinmaps" keyword
tools: bpftool: fix short option name for printing version in man
pages
tools: bpftool: add a note on program statistics in man page

Quoted 11 lines
 tools/bpf/bpftool/Documentation/bpftool-cgroup.rst  |  2 +-
 tools/bpf/bpftool/Documentation/bpftool-feature.rst |  2 +-
 tools/bpf/bpftool/Documentation/bpftool-map.rst     |  2 +-
 tools/bpf/bpftool/Documentation/bpftool-net.rst     |  2 +-
 tools/bpf/bpftool/Documentation/bpftool-perf.rst    |  2 +-
 tools/bpf/bpftool/Documentation/bpftool-prog.rst    | 12 ++++++++++--
 tools/bpf/bpftool/Documentation/bpftool.rst         |  2 +-
 tools/bpf/bpftool/cgroup.c                          |  7 +++++++
 tools/bpf/bpftool/prog.c                            |  2 +-
 9 files changed, 24 insertions(+), 9 deletions(-)

Applied, thanks!