From patchwork Sun Apr 24 05:10:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 12824771 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99B1BC433FE for ; Sun, 24 Apr 2022 05:10:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238246AbiDXFNz (ORCPT ); Sun, 24 Apr 2022 01:13:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238228AbiDXFNn (ORCPT ); Sun, 24 Apr 2022 01:13:43 -0400 Received: from nautica.notk.org (ipv6.notk.org [IPv6:2001:41d0:1:7a93::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56877B1E; Sat, 23 Apr 2022 22:10:42 -0700 (PDT) Received: by nautica.notk.org (Postfix, from userid 108) id 2B207C021; Sun, 24 Apr 2022 07:10:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1650777041; bh=wnaQmB/OwGIOtKdRHm+IOTugJI2pRqMAdNdx5pQ7kzM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jAl2c+qYxGYnCs4n+hsrIsmM4PADw8in+63+nixCeLXfZ/CHQf+7F8G1Qjrc7Kjzg uf6RguKXAbLvg+ERK2xXSDfTiUVHHSOVr3YCibtAxhDJP1K5B8mqxLbVXRQMxQQuNP NIei81d9tLesyB78eXE0dQZIuJVmRLdUSsES0GRz9RkYXGkb4EDoUvnt0P6caPSROR nSEuWaShiePbMDtd4xKukqw+rLCtsyW9BAQbRK60Y/sVigrAc3FfrLOigqKc6ic9Fl aPWW79yA4csxrXqoG0wbxdecGGLJkivbVPbzSttZZ1kIjWjQudn1q2Kz1sLQuFpq83 MZh7aOeCkOTgA== Received: from odin.codewreck.org (localhost [127.0.0.1]) by nautica.notk.org (Postfix) with ESMTPS id E99E0C01D; Sun, 24 Apr 2022 07:10:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1650777040; bh=wnaQmB/OwGIOtKdRHm+IOTugJI2pRqMAdNdx5pQ7kzM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hpLemM1y73xMSYxt5t47CmkkobilnVQay0gmcSQ4V3i8qXFNoszr3CK/plzm8D5Xm ACGOB5pvo5TAibicjEp2jHbM0RvLk+vsCxMyYJMBkRUjwtqp87Gu1eaV+4rAzAtZig IB97yh9r7TXV2fKLLkGpaAXGGGXy39xrnwLECQFVl08cGJSDNPZUvqRZaWpEypnVvB C8vbr3/qDNgQR1j6yfrVRCf95UdgUM64aSDuDZ5HS/gCiRF/TpCXvl0AoK8GNAtj0i 4CPv397WQ/kSYZQpEs4uRKCDqFvQd8kQ91aKa02ttP1sqLczUUJW9ZOwpkESQ/kzbI vIbt+3RQdiArQ== Received: from localhost (odin.codewreck.org [local]) by odin.codewreck.org (OpenSMTPD) with ESMTPA id 8d80284b; Sun, 24 Apr 2022 05:10:26 +0000 (UTC) From: Dominique Martinet To: bpf@vger.kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, KP Singh , John Fastabend , Yonghong Song , Song Liu , Martin KaFai Lau , Andrii Nakryiko , Daniel Borkmann , Alexei Starovoitov , Dominique Martinet Subject: [PATCH 1/4] tools/bpf/runqslower: musl compat: explicitly link with libargp if found Date: Sun, 24 Apr 2022 14:10:19 +0900 Message-Id: <20220424051022.2619648-2-asmadeus@codewreck.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220424051022.2619648-1-asmadeus@codewreck.org> References: <20220424051022.2619648-1-asmadeus@codewreck.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net musl doesn't implement argp.h and requires an explicit lib for it, so we must test for -largp presence and use it if appropriate Signed-off-by: Dominique Martinet --- After having done this work I noticed runqslower is not actually installed, so ideally instead of all of this it'd make more sense to just not build it: would it make sense to take it out of the defaults build targets? I could just directly build the appropriate targets from tools/bpf directory with 'make bpftool bpf_dbg bpf_asm bpf_jit_disasm', but ideally I'd like to keep alpine's build script way of calling make from the tools parent directory, and 'make bpf' there is all or nothing. OTOH, we might as well keep this to allow people on alpine/void linux to build runqslower if they want to. I didn't add libargp to default features check so it shouldn't change much except for runqslower itself. As an example it might be better to keep it independant from kbuild but it already wasn't so I don't see much harm here. tools/bpf/runqslower/Makefile | 30 +++++++++++++++++++++++++++++- tools/build/feature/Makefile | 4 ++++ tools/build/feature/test-all.c | 4 ++++ tools/build/feature/test-libargp.c | 14 ++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tools/build/feature/test-libargp.c diff --git a/tools/bpf/runqslower/Makefile b/tools/bpf/runqslower/Makefile index da6de16a3dfb..20a1d9a2a908 100644 --- a/tools/bpf/runqslower/Makefile +++ b/tools/bpf/runqslower/Makefile @@ -23,6 +23,34 @@ VMLINUX_BTF_PATHS := $(if $(O),$(O)/vmlinux) \ VMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firstword \ $(wildcard $(VMLINUX_BTF_PATHS)))) +# musl requires linking with an external libargp +FEATURE_USER = .runqslower +FEATURE_TEST = libargp +FEATURE_DISPLAY = + +check_feat := 1 +NON_CHECK_FEAT_TARGETS := clean +ifdef MAKECMDGOALS +ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),) + check_feat := 0 +endif +endif + +ifeq ($(check_feat),1) +ifeq ($(FEATURES_DUMP),) +srctree := $(abspath ../../..) +include $(srctree)/tools/build/Makefile.feature +else +include $(FEATURES_DUMP) +endif +endif + +LIBS = -lelf -lz +$(call feature_check,libargp) +ifeq ($(feature-libargp), 1) +LIBS += -largp +endif + ifeq ($(V),1) Q = else @@ -49,7 +77,7 @@ clean: libbpf_hdrs: $(BPFOBJ) $(OUTPUT)/runqslower: $(OUTPUT)/runqslower.o $(BPFOBJ) - $(QUIET_LINK)$(CC) $(CFLAGS) $^ -lelf -lz -o $@ + $(QUIET_LINK)$(CC) $(CFLAGS) $^ $(LIBS) -o $@ $(OUTPUT)/runqslower.o: runqslower.h $(OUTPUT)/runqslower.skel.h \ $(OUTPUT)/runqslower.bpf.o | libbpf_hdrs diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index de66e1cc0734..ceb4224a0ede 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile @@ -37,6 +37,7 @@ FILES= \ test-libtraceevent.bin \ test-libtracefs.bin \ test-libcrypto.bin \ + test-libargp.bin \ test-libunwind.bin \ test-libunwind-debug-frame.bin \ test-libunwind-x86.bin \ @@ -205,6 +206,9 @@ $(OUTPUT)test-libtracefs.bin: $(OUTPUT)test-libcrypto.bin: $(BUILD) -lcrypto +$(OUTPUT)test-libargp.bin: + $(BUILD) -largp + $(OUTPUT)test-gtk2.bin: $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) -Wno-deprecated-declarations diff --git a/tools/build/feature/test-all.c b/tools/build/feature/test-all.c index 5ffafb967b6e..149d3ef4a439 100644 --- a/tools/build/feature/test-all.c +++ b/tools/build/feature/test-all.c @@ -146,6 +146,10 @@ # include "test-libcrypto.c" #undef main +#define main main_test_libargp +# include "test-libargp.c" +#undef main + #define main main_test_sdt # include "test-sdt.c" #undef main diff --git a/tools/build/feature/test-libargp.c b/tools/build/feature/test-libargp.c new file mode 100644 index 000000000000..63b65d1f11fe --- /dev/null +++ b/tools/build/feature/test-libargp.c @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +#include + +const char *argp_program_version = "test-libargp"; +static const struct argp_option opts[] = { {} }; + +int main(int argc, char **argv) +{ + static const struct argp argp = { + .options = opts, + }; + argp_parse(&argp, argc, argv, 0, NULL, NULL); + return 0; +} From patchwork Sun Apr 24 05:10:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 12824772 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69CBBC4332F for ; Sun, 24 Apr 2022 05:10:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238260AbiDXFN4 (ORCPT ); Sun, 24 Apr 2022 01:13:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238229AbiDXFNo (ORCPT ); Sun, 24 Apr 2022 01:13:44 -0400 Received: from nautica.notk.org (ipv6.notk.org [IPv6:2001:41d0:1:7a93::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01AA2F5A; Sat, 23 Apr 2022 22:10:44 -0700 (PDT) Received: by nautica.notk.org (Postfix, from userid 108) id C8438C024; Sun, 24 Apr 2022 07:10:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1650777042; bh=JjK2qZC6PYh0WxsLxO/AP8NF3SuTpsFKmckJsckwiLU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uniNiW3L0wGZ72WLOCJ83RLybJVknlSpeP4TvmO3yDYv+dqBTJmarYYqfrDXmC7XA e0p4jdpudAU0xE+RNoHlce8VzbZNL3BD/Rg7kmPNEUR9/3UeVXUbu8mODCyT75pSVX FzNJmAgHSPe5C7Qva7JrF7e+ESwCfVYNwK5Aae55JiZMHq58tD47PrBeqYWJAO+QRY HWGyMG0cCuYI3DWpvPnuU3oYh5O2oXi/aw4JY8xsYx89kumb/JByzhEX3LLSQIEHpb wsaozj5e62pKFtK6wOw6b+3faOsY8OIwCMYBTF59Abp2HPut9b92hfB21RV9YwacRX i3Vs6Kz0LDG2g== Received: from odin.codewreck.org (localhost [127.0.0.1]) by nautica.notk.org (Postfix) with ESMTPS id 3B5BFC01E; Sun, 24 Apr 2022 07:10:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1650777042; bh=JjK2qZC6PYh0WxsLxO/AP8NF3SuTpsFKmckJsckwiLU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uniNiW3L0wGZ72WLOCJ83RLybJVknlSpeP4TvmO3yDYv+dqBTJmarYYqfrDXmC7XA e0p4jdpudAU0xE+RNoHlce8VzbZNL3BD/Rg7kmPNEUR9/3UeVXUbu8mODCyT75pSVX FzNJmAgHSPe5C7Qva7JrF7e+ESwCfVYNwK5Aae55JiZMHq58tD47PrBeqYWJAO+QRY HWGyMG0cCuYI3DWpvPnuU3oYh5O2oXi/aw4JY8xsYx89kumb/JByzhEX3LLSQIEHpb wsaozj5e62pKFtK6wOw6b+3faOsY8OIwCMYBTF59Abp2HPut9b92hfB21RV9YwacRX i3Vs6Kz0LDG2g== Received: from localhost (odin.codewreck.org [local]) by odin.codewreck.org (OpenSMTPD) with ESMTPA id c4a5b06b; Sun, 24 Apr 2022 05:10:26 +0000 (UTC) From: Dominique Martinet To: bpf@vger.kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, KP Singh , John Fastabend , Yonghong Song , Song Liu , Martin KaFai Lau , Andrii Nakryiko , Daniel Borkmann , Alexei Starovoitov , Dominique Martinet Subject: [PATCH 2/4] tools/bpf: musl compat: do not use DEFFILEMODE Date: Sun, 24 Apr 2022 14:10:20 +0900 Message-Id: <20220424051022.2619648-3-asmadeus@codewreck.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220424051022.2619648-1-asmadeus@codewreck.org> References: <20220424051022.2619648-1-asmadeus@codewreck.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net DEFFILEMODE is not defined on musl libc. Linus has expressed preference towards using explicit octal value in the past over combinaisons of S_Ix{USR,GRP,OTH}, so just replace it with 0666 directly Signed-off-by: Dominique Martinet --- I wanted to link to the Linus mail that said this, but it turns out there weren't any list in Cc... I could be making this up but here's the relevant part of his mail, which I hope is acceptable to forward as there's nothing personal in it: ---- Date: Sat, 27 Feb 2021 11:29:31 -0800 From: Linus Torvalds Subject: Re: [RFC][PATCHSET] inode type bits fixes Message-ID: [...] Finally, I absolutely _abhor_ the crazy "S_%&^%&^$" macros. They are completely illegible garbage, imnsho. I'm looking at that + mode = stat->st_mode & S_IALLUGO; + mode |= inode->i_mode & ~S_IALLUGO; and I'm like "WTF is that random character sequence again". In this case, it's everything but the format. I think it would be more legible written the other way around, ie + mode = stat->st_mode & ~S_IFMT; + mode |= inode->i_mode & S_IFMT; because at least that one has _less_ of the stupid random-generated letters. Every single one of the "UGO" things are pure and utter crap. The octal representation of the actual permissions masks are _way_ more legible than the insane "standard" names for them. ---- tools/bpf/bpf_jit_disasm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/bpf/bpf_jit_disasm.c b/tools/bpf/bpf_jit_disasm.c index c8ae95804728..f748863e294c 100644 --- a/tools/bpf/bpf_jit_disasm.c +++ b/tools/bpf/bpf_jit_disasm.c @@ -303,7 +303,7 @@ int main(int argc, char **argv) goto done; } - ofd = open(ofile, O_WRONLY | O_CREAT | O_TRUNC, DEFFILEMODE); + ofd = open(ofile, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (ofd < 0) { fprintf(stderr, "Could not open file %s for writing: ", ofile); perror(NULL); From patchwork Sun Apr 24 05:10:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 12824774 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9CEDC433EF for ; Sun, 24 Apr 2022 05:11:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238272AbiDXFOA (ORCPT ); Sun, 24 Apr 2022 01:14:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238231AbiDXFNz (ORCPT ); Sun, 24 Apr 2022 01:13:55 -0400 Received: from nautica.notk.org (ipv6.notk.org [IPv6:2001:41d0:1:7a93::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D35FE5F96; Sat, 23 Apr 2022 22:10:49 -0700 (PDT) Received: by nautica.notk.org (Postfix, from userid 108) id A6871C01A; Sun, 24 Apr 2022 07:10:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1650777048; bh=CStdIA73LibAElNfhkI3XlBob8QVrmyzne2SWxpRvv0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pdq0kV5cghzVIWCiiJL8t25DcJflly+3Ev32VcptGtkHgpaUI2Y+0YUuu/9jlD8xA /fC3/kWuc4Q/wrXui1Xo6/emOXSSOzW8jGSP7siqh6XPoHIX8HM1e/weKgXGs8jtM0 EbgsaP4hTKP3SxXXv5ywrtxIscbjJ+tVRIRJ89UOZ5HYJMyxRVs1SBmf5uIuCCTgfl BgFQfYVhlGFKAKDApohmDTsC3hNjItTqwcjjM4yTgxmCtT1GRswuUF4uFoNgXVLVIT x+3wV7C+bdQfBiDobSNJX1NW+0wfPgKH6MGff21k8CPue1UgbrxZYep84bJPzt8SWe 8KQ5cDmWrgLCw== Received: from odin.codewreck.org (localhost [127.0.0.1]) by nautica.notk.org (Postfix) with ESMTPS id 65E7CC01B; Sun, 24 Apr 2022 07:10:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1650777047; bh=CStdIA73LibAElNfhkI3XlBob8QVrmyzne2SWxpRvv0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AUX94Y9hKyJ+Z1JQlZq122jwh7L8oU6s7ReVpBZ3OInyWt9FpGiClIS2yRF+qVKtz /6lS9GnoW1e9MxSOj2BAullP38sKZ2tbpcf8Eg9XLE7cHPkj9ivLUXPMqGKprPMdc1 k13pqpVggksFKXZD5gBlBhuF9rkbMuxDW9pbfczsvriCFWq4MPIqbAJ+qqiD3oc6g7 avfTfl8Q/ei40yYb8tKtM5lPK8YH3BJOrTBvd0+2bLObkvawCMQPhvtHBefZJkMD0N f2GAGF1BmHT1P+0chHugqjnLb89lkfh/rWn6vGdF3fH1GICvvYac1rRdQzWeKCla+B N8HISy+HqOoqA== Received: from localhost (odin.codewreck.org [local]) by odin.codewreck.org (OpenSMTPD) with ESMTPA id 1de1c1c9; Sun, 24 Apr 2022 05:10:26 +0000 (UTC) From: Dominique Martinet To: bpf@vger.kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, KP Singh , John Fastabend , Yonghong Song , Song Liu , Martin KaFai Lau , Andrii Nakryiko , Daniel Borkmann , Alexei Starovoitov , Dominique Martinet Subject: [PATCH 3/4] tools/bpf: musl compat: replace nftw with FTW_ACTIONRETVAL Date: Sun, 24 Apr 2022 14:10:21 +0900 Message-Id: <20220424051022.2619648-4-asmadeus@codewreck.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220424051022.2619648-1-asmadeus@codewreck.org> References: <20220424051022.2619648-1-asmadeus@codewreck.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net musl nftw implementation does not support FTW_ACTIONRETVAL. There have been multiple attempts at pushing the feature in musl upstream but it has been refused or ignored all the times: https://www.openwall.com/lists/musl/2021/03/26/1 https://www.openwall.com/lists/musl/2022/01/22/1 In this case we only care about /proc//fd/, so it's not too difficult to reimplement directly instead, and the new implementation makes 'bpftool perf' slightly faster because it doesn't needlessly stat/readdir unneeded directories (54ms -> 13ms on my machine) Signed-off-by: Dominique Martinet Acked-by: Quentin Monnet --- Alternatively alpine has one package where they reimplemented nftw with FTW_ACTIONRETVAL support locally, so if reaaallly needed we could do the same here.. But honestly doing two readdirs is probably just as simple for this particular case. tools/bpf/bpftool/perf.c | 116 ++++++++++++++++++++------------------- 1 file changed, 59 insertions(+), 57 deletions(-) diff --git a/tools/bpf/bpftool/perf.c b/tools/bpf/bpftool/perf.c index 50de087b0db7..de793872544e 100644 --- a/tools/bpf/bpftool/perf.c +++ b/tools/bpf/bpftool/perf.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include @@ -147,81 +147,83 @@ static void print_perf_plain(int pid, int fd, __u32 prog_id, __u32 fd_type, } } -static int show_proc(const char *fpath, const struct stat *sb, - int tflag, struct FTW *ftwbuf) +static int show_proc(void) { __u64 probe_offset, probe_addr; __u32 len, prog_id, fd_type; - int err, pid = 0, fd = 0; + int err, pid, fd; + DIR *proc, *pid_fd; + struct dirent *proc_de, *pid_fd_de; const char *pch; char buf[4096]; - /* prefix always /proc */ - pch = fpath + 5; - if (*pch == '\0') - return 0; + proc = opendir("/proc"); + if (!proc) + return -1; + while ((proc_de = readdir(proc))) { + pid = 0; + pch = proc_de->d_name; - /* pid should be all numbers */ - pch++; - while (isdigit(*pch)) { - pid = pid * 10 + *pch - '0'; - pch++; + /* pid should be all numbers */ + while (isdigit(*pch)) { + pid = pid * 10 + *pch - '0'; + pch++; + } + if (*pch != '\0') + continue; + + err = snprintf(buf, sizeof(buf), "/proc/%s/fd", proc_de->d_name); + if (err < 0 || err >= (int)sizeof(buf)) + continue; + + pid_fd = opendir(buf); + if (!pid_fd) + continue; + + while ((pid_fd_de = readdir(pid_fd))) { + fd = 0; + pch = pid_fd_de->d_name; + + /* fd should be all numbers */ + while (isdigit(*pch)) { + fd = fd * 10 + *pch - '0'; + pch++; + } + if (*pch != '\0') + continue; + + /* query (pid, fd) for potential perf events */ + len = sizeof(buf); + err = bpf_task_fd_query(pid, fd, 0, buf, &len, &prog_id, &fd_type, + &probe_offset, &probe_addr); + if (err < 0) + continue; + + if (json_output) + print_perf_json(pid, fd, prog_id, fd_type, buf, probe_offset, + probe_addr); + else + print_perf_plain(pid, fd, prog_id, fd_type, buf, probe_offset, + probe_addr); + } + closedir(pid_fd); } - if (*pch == '\0') - return 0; - if (*pch != '/') - return FTW_SKIP_SUBTREE; - - /* check /proc//fd directory */ - pch++; - if (strncmp(pch, "fd", 2)) - return FTW_SKIP_SUBTREE; - pch += 2; - if (*pch == '\0') - return 0; - if (*pch != '/') - return FTW_SKIP_SUBTREE; - - /* check /proc//fd/ */ - pch++; - while (isdigit(*pch)) { - fd = fd * 10 + *pch - '0'; - pch++; - } - if (*pch != '\0') - return FTW_SKIP_SUBTREE; - - /* query (pid, fd) for potential perf events */ - len = sizeof(buf); - err = bpf_task_fd_query(pid, fd, 0, buf, &len, &prog_id, &fd_type, - &probe_offset, &probe_addr); - if (err < 0) - return 0; - - if (json_output) - print_perf_json(pid, fd, prog_id, fd_type, buf, probe_offset, - probe_addr); - else - print_perf_plain(pid, fd, prog_id, fd_type, buf, probe_offset, - probe_addr); - + closedir(proc); return 0; } static int do_show(int argc, char **argv) { - int flags = FTW_ACTIONRETVAL | FTW_PHYS; - int err = 0, nopenfd = 16; + int err; if (!has_perf_query_support()) return -1; if (json_output) jsonw_start_array(json_wtr); - if (nftw("/proc", show_proc, nopenfd, flags) == -1) { - p_err("%s", strerror(errno)); - err = -1; - } + + err = show_proc(); + if (json_output) jsonw_end_array(json_wtr); From patchwork Sun Apr 24 05:10:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 12824773 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 709A0C433FE for ; Sun, 24 Apr 2022 05:11:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238244AbiDXFN7 (ORCPT ); Sun, 24 Apr 2022 01:13:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238253AbiDXFNz (ORCPT ); Sun, 24 Apr 2022 01:13:55 -0400 Received: from nautica.notk.org (ipv6.notk.org [IPv6:2001:41d0:1:7a93::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF5446174; Sat, 23 Apr 2022 22:10:51 -0700 (PDT) Received: by nautica.notk.org (Postfix, from userid 108) id 5C511C021; Sun, 24 Apr 2022 07:10:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1650777050; bh=7qSdX1fQc8qaq/0kGWbdqAbwUgwAzFodhcpGt82loR8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cdWarBr5CnPsGzKSetCqZpdT5ZKydqge7UiNqi+BUKoDD2rrbENWcT4IlB2JdwlOx 2PTD8YGbNmqriodTcDW+1JFuswkszJQAFrJLmwCI5jgO3UBGJhkF9Y6eOYfknRgQJt 6Cp2YbKYtaoJhbzK8E8TrsH6uDnVeYHKRCJpjlTTOngbVpI7dtLZaygTwNWVGaSwGL zzYY0pzl3coJL/9Cu/FMmlc7wCwfgm76KE1d4gUrViS9L0pxQ0hXQYGNSX8TJzfWQR omrbTSS1BX00n28oLbxUqraCdDmRMfYM6b2KMYitcMp9sjiPr3jnHxYlRdap4R07kz ZJLCTlhnc4yBw== Received: from odin.codewreck.org (localhost [127.0.0.1]) by nautica.notk.org (Postfix) with ESMTPS id 3705DC01E; Sun, 24 Apr 2022 07:10:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1650777049; bh=7qSdX1fQc8qaq/0kGWbdqAbwUgwAzFodhcpGt82loR8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JgfIS7pUGdGHNkVlxWV4bZXPoJoi9lirfrl8o/cOJt0ezuoXj6eddMm/hxfXlXsSm VDxGtvGCWHBDb3tgD6BPEdCgwOziRhdl8SY2UHqXelUuYpuiFwU1FLFlcmMhcBGnwb 9ZAPz1K3VNetc70zr4JGqpsklbHqt7+JNGd2whkAU/Oa9k+mL0Zq2EuJ+rcbwWgXrg 3XSVlk4KT3J/+tmCE/KqwJJXgJDuxOXV2bOXeEPZ7W973D9LUWo6IK6kzIL7ySdyZl vFWlqaVkP1SgUakf8LdyoyrrgtGdJssLpTaDHhJpzcoP5QalcEaWQkJCfVCesrLPoz dS97PnXpNrejA== Received: from localhost (odin.codewreck.org [local]) by odin.codewreck.org (OpenSMTPD) with ESMTPA id e78b8354; Sun, 24 Apr 2022 05:10:26 +0000 (UTC) From: Dominique Martinet To: bpf@vger.kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, KP Singh , John Fastabend , Yonghong Song , Song Liu , Martin KaFai Lau , Andrii Nakryiko , Daniel Borkmann , Alexei Starovoitov , Dominique Martinet Subject: [PATCH 4/4] tools/bpf: replace sys/fcntl.h by fcntl.h Date: Sun, 24 Apr 2022 14:10:22 +0900 Message-Id: <20220424051022.2619648-5-asmadeus@codewreck.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220424051022.2619648-1-asmadeus@codewreck.org> References: <20220424051022.2619648-1-asmadeus@codewreck.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net musl does not like including sys/fcntl.h directly: 1 | #warning redirecting incorrect #include to Signed-off-by: Dominique Martinet Acked-by: Quentin Monnet --- tools/bpf/bpftool/tracelog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/bpf/bpftool/tracelog.c b/tools/bpf/bpftool/tracelog.c index e80a5c79b38f..bf1f02212797 100644 --- a/tools/bpf/bpftool/tracelog.c +++ b/tools/bpf/bpftool/tracelog.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include "main.h"