Message ID | 20230331202949.810326-2-namhyung@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp825879vqo; Fri, 31 Mar 2023 13:40:31 -0700 (PDT) X-Google-Smtp-Source: AKy350bC/pSdHnPlowKSjZlIPoo+N1vOzwA0+X+ndv/9BebcvwrUcXF+Lf6mbYTVypyI3O2dG07K X-Received: by 2002:a17:906:1685:b0:930:660d:8f92 with SMTP id s5-20020a170906168500b00930660d8f92mr29523753ejd.52.1680295231297; Fri, 31 Mar 2023 13:40:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680295231; cv=none; d=google.com; s=arc-20160816; b=F6iTkwsbsWQuYASWU+bIiLdwYCDmJxNyQNTuVXIfIzm7kWv88MXhOEe1aT0qkeQ4Hz 91FiNTBku/uHF1alONhzfoYOuV9G5HsI1n1cBw23ofY5jJJe7PZk74yKYWGnJAjCEzTq tK4XdvFlMisgLvwykTLZHvm15oro/BSHClvMiH0ZPz7b27d3TiJV6CUYZxlF0J5hCPEt ZSDs9psEeJ3wvwfdkyV6sccU3on+RSSSABskMKabenRs4Gad7sysvgO3zApE4a61P1oF pDedp66sR6OSC8GD51dMghrcrZTdQNde89Flsqt2hUWALvrpfdGZAvjEDyfycXu5QMxr hXIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=PLhh5lXY8mRzGTGozorwCPHUrnN37AS+DlWp1fZ57Ms=; b=NYJ4HsoKxuYK/DPhNwMYqvsPDQzOUp8rfJpTjSfcsw3oq4UAaxRRbRwmIHpJH/DG9X fsi9y5WqZf1IJuUlFjpaDaZHzl+QAB/WnknG6Bno7RZWr+JTMi9p2e8D72MBeagyIYYP t6rNj7EvDGxcXRHsVQTsFJW2LO4yi5p0sMbtpsIRVdQcqOsZUqZs1bnJXaSHgjBCDVbO 7b9j7Aby3WiGl80ZJLhRY0T1g5xiAAewGfbP7Ykk4XUN/RruYldz+yB6qMhytKZYU0Xk ThslkLc/GJIia5sLQ+Bh3fQJT01fD6fzx17P8/08AHzAxSe9JCSeX+GsDRHD6J463NnT MaBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PvobSiVq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ci7-20020a170906c34700b0093dfe066be0si350948ejb.530.2023.03.31.13.39.58; Fri, 31 Mar 2023 13:40:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PvobSiVq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233170AbjCaU37 (ORCPT <rfc822;dexuan.linux@gmail.com> + 99 others); Fri, 31 Mar 2023 16:29:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230193AbjCaU3y (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 31 Mar 2023 16:29:54 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B04151A96F; Fri, 31 Mar 2023 13:29:53 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id z19so22399376plo.2; Fri, 31 Mar 2023 13:29:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680294593; x=1682886593; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=PLhh5lXY8mRzGTGozorwCPHUrnN37AS+DlWp1fZ57Ms=; b=PvobSiVqjZzQJUcSIk/NI+SPYWuV2Nz3Hlt7g2jd0iCPqdnUnbU4PzRkNpdH8c+u+Y 1cF6Dx8r6hPGf3zgke+nPrA38Mdn94Fd/UIUv4HagZUVxHlYCm9tpty+nCLy234NXqOB Ig4bFULimXNrEzcgbLkHvZw1u0qZUEjVcFVcL2MOX0aYd8mqv/8gX9+8Fv1VGS3itjwn c7KuhQuUAo6wVAYBnby5flX3cJwP7Cj9u/oX8s8ifF2r5FSFcnBHTXb+37aRDxA92QUd nOCPk7W1PiEEetdSDpEnQWM1MABcTe3PPeY/jDoonJEWRThpWnvSqHDsfURWjzogKkCG c2SQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680294593; x=1682886593; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=PLhh5lXY8mRzGTGozorwCPHUrnN37AS+DlWp1fZ57Ms=; b=RPOFpK+UKSl6sHW0u2BF6jcrc9RSongPPkH/g77e7r6CLKnZe/59dtfktRe/5z1a3C nPOb57BqZtl0D6RW29wZD7zoqi5TuCv0jiN73ppjv1+B4qFdK+VfrAlStB6dAfB3Kwhh P6EeVzmve3aXj3maK21HOwAmow09IdEG1yhcb4dS8P5ey1HME7f3r9NsfmM6cRvojry1 P0+qIa3GNEmH2Ku77di5dWg0YsiXOVaNvbc1xis9IwKdWEHcZP/07uWCN1dfSjoQ0ov5 LbYZEzlr/atA000fJJRdzeQC2+RAQeYBHkRhnodkVQohVuNXnS7BydVsR/67FKKSP76c pcXw== X-Gm-Message-State: AAQBX9dcpHmGN0XMj+egaKuMz7tFugjQtteA83q6hXUcWPw+Z1Mfwldb YU9hKFJrbKo6P/p/TPlkGJc= X-Received: by 2002:a17:903:2290:b0:1a1:a727:a802 with SMTP id b16-20020a170903229000b001a1a727a802mr11880427plh.19.1680294593101; Fri, 31 Mar 2023 13:29:53 -0700 (PDT) Received: from bangji.hsd1.ca.comcast.net ([2601:647:6780:44b0:5cfb:ad2c:e6f5:d42f]) by smtp.gmail.com with ESMTPSA id t14-20020a1709028c8e00b001a1dc2be791sm1916803plo.259.2023.03.31.13.29.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 13:29:52 -0700 (PDT) Sender: Namhyung Kim <namhyung@gmail.com> From: Namhyung Kim <namhyung@kernel.org> To: Arnaldo Carvalho de Melo <acme@kernel.org>, Jiri Olsa <jolsa@kernel.org> Cc: Ian Rogers <irogers@google.com>, Adrian Hunter <adrian.hunter@intel.com>, Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@kernel.org>, LKML <linux-kernel@vger.kernel.org>, linux-perf-users@vger.kernel.org, Kan Liang <kan.liang@linux.intel.com>, Leo Yan <leo.yan@linaro.org> Subject: [PATCH 1/9] perf list: Use relative path for tracepoint scan Date: Fri, 31 Mar 2023 13:29:41 -0700 Message-Id: <20230331202949.810326-2-namhyung@kernel.org> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog In-Reply-To: <20230331202949.810326-1-namhyung@kernel.org> References: <20230331202949.810326-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761917252319718589?= X-GMAIL-MSGID: =?utf-8?q?1761917252319718589?= |
Series |
perf tools: Update pmu scan using openat() (v1)
|
|
Commit Message
Namhyung Kim
March 31, 2023, 8:29 p.m. UTC
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/print-events.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
Comments
Em Fri, Mar 31, 2023 at 01:29:41PM -0700, Namhyung Kim escreveu: > Signed-off-by: Namhyung Kim <namhyung@kernel.org> > --- > tools/perf/util/print-events.c | 26 ++++++++++++++++++++------ > 1 file changed, 20 insertions(+), 6 deletions(-) Add to add this to fix on Alma Linux 8, and scandirat isn't being found on musl libc (Alpine Linux), probably we'll need some scaffolding... - Arnaldo diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 26a7e017c9284c01..28aa0b9300253d0a 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -6,6 +6,7 @@ #include <string.h> #include <fcntl.h> #include <sys/param.h> +#include <unistd.h> #include <api/fs/tracing_path.h> #include <linux/stddef.h> > diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c > index 62e9ea7dcf40..26a7e017c928 100644 > --- a/tools/perf/util/print-events.c > +++ b/tools/perf/util/print-events.c > @@ -4,6 +4,7 @@ > #include <stdio.h> > #include <stdlib.h> > #include <string.h> > +#include <fcntl.h> > #include <sys/param.h> > > #include <api/fs/tracing_path.h> > @@ -59,12 +60,20 @@ static const struct event_symbol event_symbols_tool[PERF_TOOL_MAX] = { > void print_tracepoint_events(const struct print_callbacks *print_cb, void *print_state) > { > struct dirent **sys_namelist = NULL; > + char *events_path = get_tracing_file("events"); > int sys_items = tracing_events__scandir_alphasort(&sys_namelist); > + int events_fd = open(events_path, O_PATH); > + > + put_tracing_file(events_path); > + if (events_fd < 0) { > + printf("Error: failed to open tracing events directory\n"); > + return; > + } > > for (int i = 0; i < sys_items; i++) { > struct dirent *sys_dirent = sys_namelist[i]; > struct dirent **evt_namelist = NULL; > - char *dir_path; > + int dir_fd; > int evt_items; > > if (sys_dirent->d_type != DT_DIR || > @@ -72,22 +81,26 @@ void print_tracepoint_events(const struct print_callbacks *print_cb, void *print > !strcmp(sys_dirent->d_name, "..")) > continue; > > - dir_path = get_events_file(sys_dirent->d_name); > - if (!dir_path) > + dir_fd = openat(events_fd, sys_dirent->d_name, O_PATH); > + if (dir_fd < 0) > continue; > > - evt_items = scandir(dir_path, &evt_namelist, NULL, alphasort); > + evt_items = scandirat(events_fd, sys_dirent->d_name, &evt_namelist, NULL, alphasort); > for (int j = 0; j < evt_items; j++) { > struct dirent *evt_dirent = evt_namelist[j]; > char evt_path[MAXPATHLEN]; > + int evt_fd; > > if (evt_dirent->d_type != DT_DIR || > !strcmp(evt_dirent->d_name, ".") || > !strcmp(evt_dirent->d_name, "..")) > continue; > > - if (tp_event_has_id(dir_path, evt_dirent) != 0) > + snprintf(evt_path, sizeof(evt_path), "%s/id", evt_dirent->d_name); > + evt_fd = openat(dir_fd, evt_path, O_RDONLY); > + if (evt_fd < 0) > continue; > + close(evt_fd); > > snprintf(evt_path, MAXPATHLEN, "%s:%s", > sys_dirent->d_name, evt_dirent->d_name); > @@ -103,10 +116,11 @@ void print_tracepoint_events(const struct print_callbacks *print_cb, void *print > /*long_desc=*/NULL, > /*encoding_desc=*/NULL); > } > - free(dir_path); > + close(dir_fd); > free(evt_namelist); > } > free(sys_namelist); > + close(events_fd); > } > > void print_sdt_events(const struct print_callbacks *print_cb, void *print_state) > -- > 2.40.0.348.gf938b09366-goog >
Em Mon, Apr 03, 2023 at 06:59:10PM -0300, Arnaldo Carvalho de Melo escreveu: > Em Fri, Mar 31, 2023 at 01:29:41PM -0700, Namhyung Kim escreveu: > > Signed-off-by: Namhyung Kim <namhyung@kernel.org> > > --- > > tools/perf/util/print-events.c | 26 ++++++++++++++++++++------ > > 1 file changed, 20 insertions(+), 6 deletions(-) > > Add to add this to fix on Alma Linux 8, and scandirat isn't being found > on musl libc (Alpine Linux), probably we'll need some scaffolding... Some discussion about this for some other project: https://gitlab.com/apparmor/apparmor/-/merge_requests/107 > - Arnaldo > > > diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c > index 26a7e017c9284c01..28aa0b9300253d0a 100644 > --- a/tools/perf/util/print-events.c > +++ b/tools/perf/util/print-events.c > @@ -6,6 +6,7 @@ > #include <string.h> > #include <fcntl.h> > #include <sys/param.h> > +#include <unistd.h> > > #include <api/fs/tracing_path.h> > #include <linux/stddef.h> > > > diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c > > index 62e9ea7dcf40..26a7e017c928 100644 > > --- a/tools/perf/util/print-events.c > > +++ b/tools/perf/util/print-events.c > > @@ -4,6 +4,7 @@ > > #include <stdio.h> > > #include <stdlib.h> > > #include <string.h> > > +#include <fcntl.h> > > #include <sys/param.h> > > > > #include <api/fs/tracing_path.h> > > @@ -59,12 +60,20 @@ static const struct event_symbol event_symbols_tool[PERF_TOOL_MAX] = { > > void print_tracepoint_events(const struct print_callbacks *print_cb, void *print_state) > > { > > struct dirent **sys_namelist = NULL; > > + char *events_path = get_tracing_file("events"); > > int sys_items = tracing_events__scandir_alphasort(&sys_namelist); > > + int events_fd = open(events_path, O_PATH); > > + > > + put_tracing_file(events_path); > > + if (events_fd < 0) { > > + printf("Error: failed to open tracing events directory\n"); > > + return; > > + } > > > > for (int i = 0; i < sys_items; i++) { > > struct dirent *sys_dirent = sys_namelist[i]; > > struct dirent **evt_namelist = NULL; > > - char *dir_path; > > + int dir_fd; > > int evt_items; > > > > if (sys_dirent->d_type != DT_DIR || > > @@ -72,22 +81,26 @@ void print_tracepoint_events(const struct print_callbacks *print_cb, void *print > > !strcmp(sys_dirent->d_name, "..")) > > continue; > > > > - dir_path = get_events_file(sys_dirent->d_name); > > - if (!dir_path) > > + dir_fd = openat(events_fd, sys_dirent->d_name, O_PATH); > > + if (dir_fd < 0) > > continue; > > > > - evt_items = scandir(dir_path, &evt_namelist, NULL, alphasort); > > + evt_items = scandirat(events_fd, sys_dirent->d_name, &evt_namelist, NULL, alphasort); > > for (int j = 0; j < evt_items; j++) { > > struct dirent *evt_dirent = evt_namelist[j]; > > char evt_path[MAXPATHLEN]; > > + int evt_fd; > > > > if (evt_dirent->d_type != DT_DIR || > > !strcmp(evt_dirent->d_name, ".") || > > !strcmp(evt_dirent->d_name, "..")) > > continue; > > > > - if (tp_event_has_id(dir_path, evt_dirent) != 0) > > + snprintf(evt_path, sizeof(evt_path), "%s/id", evt_dirent->d_name); > > + evt_fd = openat(dir_fd, evt_path, O_RDONLY); > > + if (evt_fd < 0) > > continue; > > + close(evt_fd); > > > > snprintf(evt_path, MAXPATHLEN, "%s:%s", > > sys_dirent->d_name, evt_dirent->d_name); > > @@ -103,10 +116,11 @@ void print_tracepoint_events(const struct print_callbacks *print_cb, void *print > > /*long_desc=*/NULL, > > /*encoding_desc=*/NULL); > > } > > - free(dir_path); > > + close(dir_fd); > > free(evt_namelist); > > } > > free(sys_namelist); > > + close(events_fd); > > } > > > > void print_sdt_events(const struct print_callbacks *print_cb, void *print_state) > > -- > > 2.40.0.348.gf938b09366-goog > > > > -- > > - Arnaldo
Em Mon, Apr 03, 2023 at 06:59:10PM -0300, Arnaldo Carvalho de Melo escreveu: > Em Fri, Mar 31, 2023 at 01:29:41PM -0700, Namhyung Kim escreveu: > > Signed-off-by: Namhyung Kim <namhyung@kernel.org> > > --- > > tools/perf/util/print-events.c | 26 ++++++++++++++++++++------ > > 1 file changed, 20 insertions(+), 6 deletions(-) > > Add to add this to fix on Alma Linux 8, and scandirat isn't being found > on musl libc (Alpine Linux), probably we'll need some scaffolding... About scandirat I'm adding the feature test below and this patch to the patch that starts using scandirat(): diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 28aa0b9300253d0a..386b1ab0b60e1d93 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -58,11 +58,9 @@ static const struct event_symbol event_symbols_tool[PERF_TOOL_MAX] = { /* * Print the events from <debugfs_mount_point>/tracing/events */ -void print_tracepoint_events(const struct print_callbacks *print_cb, void *print_state) +void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unused, void *print_state __maybe_unused) { - struct dirent **sys_namelist = NULL; char *events_path = get_tracing_file("events"); - int sys_items = tracing_events__scandir_alphasort(&sys_namelist); int events_fd = open(events_path, O_PATH); put_tracing_file(events_path); @@ -71,6 +69,11 @@ void print_tracepoint_events(const struct print_callbacks *print_cb, void *print return; } +#ifdef HAVE_SCANDIRAT_SUPPORT +{ + struct dirent **sys_namelist = NULL; + int sys_items = tracing_events__scandir_alphasort(&sys_namelist); + for (int i = 0; i < sys_items; i++) { struct dirent *sys_dirent = sys_namelist[i]; struct dirent **evt_namelist = NULL; @@ -120,7 +123,13 @@ void print_tracepoint_events(const struct print_callbacks *print_cb, void *print close(dir_fd); free(evt_namelist); } + free(sys_namelist); +} +#else + printf("\nWARNING: Your libc doesn't have the scandir function, please ask its maintainers to implement it.\n" + " As a rough fallback, please do 'ls %s' to see the available tracepoint events.\n", events_path); +#endif close(events_fd); } From b25f9de2f944a550b063322b7210f4392e622a5e Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo <acme@redhat.com> Date: Tue, 4 Apr 2023 11:05:57 -0300 Subject: [PATCH 1/1] tools build: Add a feature test for scandirat(), that is not implemented so far in musl and uclibc We use it just when listing tracepoint events, and for root, so just emit a warning about it to get users to ask the library maintainers to implement it, as suggested in this systemd ticket: https://github.com/systemd/casync/issues/129 Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Ian Rogers <irogers@google.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> --- tools/build/Makefile.feature | 1 + tools/build/feature/Makefile | 4 ++++ tools/build/feature/test-all.c | 5 +++++ tools/perf/Makefile.config | 4 ++++ 4 files changed, 14 insertions(+) diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature index 214622d7537cc56b..934e2777a2dbcd90 100644 --- a/tools/build/Makefile.feature +++ b/tools/build/Makefile.feature @@ -64,6 +64,7 @@ FEATURE_TESTS_BASIC := \ lzma \ get_cpuid \ bpf \ + scandirat \ sched_getcpu \ sdt \ setns \ diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index 0a3b9281f8b08000..0f0aa9b7d7b5e43c 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile @@ -65,6 +65,7 @@ FILES= \ test-gettid.bin \ test-jvmti.bin \ test-jvmti-cmlr.bin \ + test-scandirat.bin \ test-sched_getcpu.bin \ test-setns.bin \ test-libopencsd.bin \ @@ -129,6 +130,9 @@ $(OUTPUT)test-get_current_dir_name.bin: $(OUTPUT)test-glibc.bin: $(BUILD) +$(OUTPUT)test-scandirat.bin: + $(BUILD) + $(OUTPUT)test-sched_getcpu.bin: $(BUILD) diff --git a/tools/build/feature/test-all.c b/tools/build/feature/test-all.c index 957c02c7b163b579..6f4bf386a3b5c4b0 100644 --- a/tools/build/feature/test-all.c +++ b/tools/build/feature/test-all.c @@ -114,6 +114,10 @@ # include "test-pthread-barrier.c" #undef main +#define main main_test_scandirat +# include "test-scandirat.c" +#undef main + #define main main_test_sched_getcpu # include "test-sched_getcpu.c" #undef main @@ -206,6 +210,7 @@ int main(int argc, char *argv[]) main_test_get_cpuid(); main_test_bpf(); main_test_libcrypto(); + main_test_scandirat(); main_test_sched_getcpu(); main_test_sdt(); main_test_setns(); diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index dd203f0a2b7e64e1..16bea51f0bcd95ea 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -478,6 +478,10 @@ ifdef NO_DWARF NO_LIBDW_DWARF_UNWIND := 1 endif +ifeq ($(feature-scandirat), 1) + CFLAGS += -DHAVE_SCANDIRAT_SUPPORT +endif + ifeq ($(feature-sched_getcpu), 1) CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT endif
Hi Arnaldo, On Tue, Apr 4, 2023 at 7:10 AM Arnaldo Carvalho de Melo <acme@kernel.org> wrote: > > Em Mon, Apr 03, 2023 at 06:59:10PM -0300, Arnaldo Carvalho de Melo escreveu: > > Em Fri, Mar 31, 2023 at 01:29:41PM -0700, Namhyung Kim escreveu: > > > Signed-off-by: Namhyung Kim <namhyung@kernel.org> > > > --- > > > tools/perf/util/print-events.c | 26 ++++++++++++++++++++------ > > > 1 file changed, 20 insertions(+), 6 deletions(-) > > > > Add to add this to fix on Alma Linux 8, and scandirat isn't being found > > on musl libc (Alpine Linux), probably we'll need some scaffolding... > > About scandirat I'm adding the feature test below and this patch to the > patch that starts using scandirat(): Thanks for doing this! > > diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c > index 28aa0b9300253d0a..386b1ab0b60e1d93 100644 > --- a/tools/perf/util/print-events.c > +++ b/tools/perf/util/print-events.c > @@ -58,11 +58,9 @@ static const struct event_symbol event_symbols_tool[PERF_TOOL_MAX] = { > /* > * Print the events from <debugfs_mount_point>/tracing/events > */ > -void print_tracepoint_events(const struct print_callbacks *print_cb, void *print_state) > +void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unused, void *print_state __maybe_unused) > { > - struct dirent **sys_namelist = NULL; > char *events_path = get_tracing_file("events"); > - int sys_items = tracing_events__scandir_alphasort(&sys_namelist); > int events_fd = open(events_path, O_PATH); > > put_tracing_file(events_path); > @@ -71,6 +69,11 @@ void print_tracepoint_events(const struct print_callbacks *print_cb, void *print > return; > } > > +#ifdef HAVE_SCANDIRAT_SUPPORT > +{ > + struct dirent **sys_namelist = NULL; > + int sys_items = tracing_events__scandir_alphasort(&sys_namelist); > + > for (int i = 0; i < sys_items; i++) { > struct dirent *sys_dirent = sys_namelist[i]; > struct dirent **evt_namelist = NULL; > @@ -120,7 +123,13 @@ void print_tracepoint_events(const struct print_callbacks *print_cb, void *print > close(dir_fd); > free(evt_namelist); > } > + > free(sys_namelist); > +} > +#else > + printf("\nWARNING: Your libc doesn't have the scandir function, please ask its maintainers to implement it.\n" > + " As a rough fallback, please do 'ls %s' to see the available tracepoint events.\n", events_path); > +#endif > close(events_fd); > } > > > From b25f9de2f944a550b063322b7210f4392e622a5e Mon Sep 17 00:00:00 2001 > From: Arnaldo Carvalho de Melo <acme@redhat.com> > Date: Tue, 4 Apr 2023 11:05:57 -0300 > Subject: [PATCH 1/1] tools build: Add a feature test for scandirat(), that is > not implemented so far in musl and uclibc > > We use it just when listing tracepoint events, and for root, so just > emit a warning about it to get users to ask the library maintainers to > implement it, as suggested in this systemd ticket: > > https://github.com/systemd/casync/issues/129 > > Cc: Adrian Hunter <adrian.hunter@intel.com> > Cc: Ian Rogers <irogers@google.com> > Cc: Jiri Olsa <jolsa@kernel.org> > Cc: Namhyung Kim <namhyung@kernel.org> > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> > --- > tools/build/Makefile.feature | 1 + > tools/build/feature/Makefile | 4 ++++ > tools/build/feature/test-all.c | 5 +++++ > tools/perf/Makefile.config | 4 ++++ Maybe you forgot to add the tools/build/feature/test-scandirat.c :) Thanks, Namhyung > 4 files changed, 14 insertions(+) > > diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature > index 214622d7537cc56b..934e2777a2dbcd90 100644 > --- a/tools/build/Makefile.feature > +++ b/tools/build/Makefile.feature > @@ -64,6 +64,7 @@ FEATURE_TESTS_BASIC := \ > lzma \ > get_cpuid \ > bpf \ > + scandirat \ > sched_getcpu \ > sdt \ > setns \ > diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile > index 0a3b9281f8b08000..0f0aa9b7d7b5e43c 100644 > --- a/tools/build/feature/Makefile > +++ b/tools/build/feature/Makefile > @@ -65,6 +65,7 @@ FILES= \ > test-gettid.bin \ > test-jvmti.bin \ > test-jvmti-cmlr.bin \ > + test-scandirat.bin \ > test-sched_getcpu.bin \ > test-setns.bin \ > test-libopencsd.bin \ > @@ -129,6 +130,9 @@ $(OUTPUT)test-get_current_dir_name.bin: > $(OUTPUT)test-glibc.bin: > $(BUILD) > > +$(OUTPUT)test-scandirat.bin: > + $(BUILD) > + > $(OUTPUT)test-sched_getcpu.bin: > $(BUILD) > > diff --git a/tools/build/feature/test-all.c b/tools/build/feature/test-all.c > index 957c02c7b163b579..6f4bf386a3b5c4b0 100644 > --- a/tools/build/feature/test-all.c > +++ b/tools/build/feature/test-all.c > @@ -114,6 +114,10 @@ > # include "test-pthread-barrier.c" > #undef main > > +#define main main_test_scandirat > +# include "test-scandirat.c" > +#undef main > + > #define main main_test_sched_getcpu > # include "test-sched_getcpu.c" > #undef main > @@ -206,6 +210,7 @@ int main(int argc, char *argv[]) > main_test_get_cpuid(); > main_test_bpf(); > main_test_libcrypto(); > + main_test_scandirat(); > main_test_sched_getcpu(); > main_test_sdt(); > main_test_setns(); > diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config > index dd203f0a2b7e64e1..16bea51f0bcd95ea 100644 > --- a/tools/perf/Makefile.config > +++ b/tools/perf/Makefile.config > @@ -478,6 +478,10 @@ ifdef NO_DWARF > NO_LIBDW_DWARF_UNWIND := 1 > endif > > +ifeq ($(feature-scandirat), 1) > + CFLAGS += -DHAVE_SCANDIRAT_SUPPORT > +endif > + > ifeq ($(feature-sched_getcpu), 1) > CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT > endif > -- > 2.39.2 >
On April 4, 2023 7:08:31 PM GMT-03:00, Namhyung Kim <namhyung@kernel.org> wrote: >> --- >> tools/build/Makefile.feature | 1 + >> tools/build/feature/Makefile | 4 ++++ >> tools/build/feature/test-all.c | 5 +++++ >> tools/perf/Makefile.config | 4 ++++ > >Maybe you forgot to add the tools/build/feature/test-scandirat.c :) Yeah , I noticed that and fixed it: https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/tree/tools/build/feature/test-scandirat.c?h=tmp.perf-tools-next - Arnaldo
diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 62e9ea7dcf40..26a7e017c928 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -4,6 +4,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <fcntl.h> #include <sys/param.h> #include <api/fs/tracing_path.h> @@ -59,12 +60,20 @@ static const struct event_symbol event_symbols_tool[PERF_TOOL_MAX] = { void print_tracepoint_events(const struct print_callbacks *print_cb, void *print_state) { struct dirent **sys_namelist = NULL; + char *events_path = get_tracing_file("events"); int sys_items = tracing_events__scandir_alphasort(&sys_namelist); + int events_fd = open(events_path, O_PATH); + + put_tracing_file(events_path); + if (events_fd < 0) { + printf("Error: failed to open tracing events directory\n"); + return; + } for (int i = 0; i < sys_items; i++) { struct dirent *sys_dirent = sys_namelist[i]; struct dirent **evt_namelist = NULL; - char *dir_path; + int dir_fd; int evt_items; if (sys_dirent->d_type != DT_DIR || @@ -72,22 +81,26 @@ void print_tracepoint_events(const struct print_callbacks *print_cb, void *print !strcmp(sys_dirent->d_name, "..")) continue; - dir_path = get_events_file(sys_dirent->d_name); - if (!dir_path) + dir_fd = openat(events_fd, sys_dirent->d_name, O_PATH); + if (dir_fd < 0) continue; - evt_items = scandir(dir_path, &evt_namelist, NULL, alphasort); + evt_items = scandirat(events_fd, sys_dirent->d_name, &evt_namelist, NULL, alphasort); for (int j = 0; j < evt_items; j++) { struct dirent *evt_dirent = evt_namelist[j]; char evt_path[MAXPATHLEN]; + int evt_fd; if (evt_dirent->d_type != DT_DIR || !strcmp(evt_dirent->d_name, ".") || !strcmp(evt_dirent->d_name, "..")) continue; - if (tp_event_has_id(dir_path, evt_dirent) != 0) + snprintf(evt_path, sizeof(evt_path), "%s/id", evt_dirent->d_name); + evt_fd = openat(dir_fd, evt_path, O_RDONLY); + if (evt_fd < 0) continue; + close(evt_fd); snprintf(evt_path, MAXPATHLEN, "%s:%s", sys_dirent->d_name, evt_dirent->d_name); @@ -103,10 +116,11 @@ void print_tracepoint_events(const struct print_callbacks *print_cb, void *print /*long_desc=*/NULL, /*encoding_desc=*/NULL); } - free(dir_path); + close(dir_fd); free(evt_namelist); } free(sys_namelist); + close(events_fd); } void print_sdt_events(const struct print_callbacks *print_cb, void *print_state)