From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
James Clark <james.clark@linaro.org>,
Xu Yang <xu.yang_2@nxp.com>,
Thomas Falcon <thomas.falcon@intel.com>,
Andi Kleen <ak@linux.intel.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
bpf@vger.kernel.org, Atish Patra <atishp@rivosinc.com>,
Beeman Strong <beeman@rivosinc.com>, Leo Yan <leo.yan@arm.com>,
Vince Weaver <vincent.weaver@maine.edu>
Subject: [PATCH v3 07/15] perf pmu: Use fd rather than FILE from new_alias
Date: Thu, 28 Aug 2025 13:59:22 -0700 [thread overview]
Message-ID: <20250828205930.4007284-8-irogers@google.com> (raw)
In-Reply-To: <20250828205930.4007284-1-irogers@google.com>
The FILE argument was necessary for the scanner but now that
functionality is not being used we can switch to just using
io__getline which should cut down on stdio buffer usage.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/pmu.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index b44dfe4c73fc..818be59db2c6 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -563,7 +563,7 @@ static int update_alias(const struct pmu_event *pe,
}
static int perf_pmu__new_alias(struct perf_pmu *pmu, const char *name,
- const char *desc, const char *val, FILE *val_fd,
+ const char *desc, const char *val, int val_fd,
const struct pmu_event *pe, enum event_source src)
{
struct perf_pmu_alias *alias, *old_alias;
@@ -614,12 +614,15 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, const char *name,
if (ret)
return ret;
- if (!val_fd) {
+ if (val_fd < 0) {
alias->terms = strdup(val);
} else {
+ char buf[256];
+ struct io io;
size_t line_len;
- ret = getline(&alias->terms, &line_len, val_fd) < 0 ? -errno : 0;
+ io__init(&io, val_fd, buf, sizeof(buf));
+ ret = io__getline(&io, &alias->terms, &line_len) < 0 ? -errno : 0;
if (ret) {
pr_err("Failed to read alias %s\n", name);
return ret;
@@ -698,7 +701,6 @@ static int __pmu_aliases_parse(struct perf_pmu *pmu, int events_dir_fd)
while ((evt_ent = io_dir__readdir(&event_dir))) {
char *name = evt_ent->d_name;
int fd;
- FILE *file;
if (!strcmp(name, ".") || !strcmp(name, ".."))
continue;
@@ -714,17 +716,12 @@ static int __pmu_aliases_parse(struct perf_pmu *pmu, int events_dir_fd)
pr_debug("Cannot open %s\n", name);
continue;
}
- file = fdopen(fd, "r");
- if (!file) {
- close(fd);
- continue;
- }
if (perf_pmu__new_alias(pmu, name, /*desc=*/ NULL,
- /*val=*/ NULL, file, /*pe=*/ NULL,
+ /*val=*/ NULL, fd, /*pe=*/ NULL,
EVENT_SRC_SYSFS) < 0)
pr_debug("Cannot set up %s\n", name);
- fclose(file);
+ close(fd);
}
pmu->sysfs_aliases_loaded = true;
@@ -1041,7 +1038,7 @@ static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe,
{
struct perf_pmu *pmu = vdata;
- perf_pmu__new_alias(pmu, pe->name, pe->desc, pe->event, /*val_fd=*/ NULL,
+ perf_pmu__new_alias(pmu, pe->name, pe->desc, pe->event, /*val_fd=*/ -1,
pe, EVENT_SRC_CPU_JSON);
return 0;
}
@@ -1090,7 +1087,7 @@ static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe,
pe->name,
pe->desc,
pe->event,
- /*val_fd=*/ NULL,
+ /*val_fd=*/ -1,
pe,
EVENT_SRC_SYS_JSON);
}
--
2.51.0.318.gd7df087d1a-goog
next prev parent reply other threads:[~2025-08-28 21:00 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-28 20:59 [PATCH v3 00/15] Legacy hardware/cache events as json Ian Rogers
2025-08-28 20:59 ` [PATCH v3 01/15] perf parse-events: Fix legacy cache events if event is duplicated in a PMU Ian Rogers
2025-08-28 20:59 ` [PATCH v3 02/15] perf perf_api_probe: Avoid scanning all PMUs, try software PMU first Ian Rogers
2025-08-28 20:59 ` [PATCH v3 03/15] perf record: Skip don't fail for events that don't open Ian Rogers
2025-08-28 20:59 ` [PATCH v3 04/15] perf jevents: Support copying the source json files to OUTPUT Ian Rogers
2025-08-28 20:59 ` [PATCH v3 05/15] perf pmu: Don't eagerly parse event terms Ian Rogers
2025-08-28 20:59 ` [PATCH v3 06/15] perf parse-events: Remove unused FILE input argument to scanner Ian Rogers
2025-08-28 20:59 ` Ian Rogers [this message]
2025-08-28 20:59 ` [PATCH v3 08/15] perf pmu: Factor term parsing into a perf_event_attr into a helper Ian Rogers
2025-08-28 20:59 ` [PATCH v3 09/15] perf parse-events: Add terms for legacy hardware and cache config values Ian Rogers
2025-08-28 20:59 ` [PATCH v3 10/15] perf jevents: Add legacy json terms and default_core event table helper Ian Rogers
2025-08-28 20:59 ` [PATCH v3 11/15] perf pmu: Add and use legacy_terms in alias information Ian Rogers
2025-08-28 20:59 ` [PATCH v3 12/15] perf jevents: Add legacy-hardware and legacy-cache json Ian Rogers
2025-08-28 20:59 ` [PATCH v3 13/15] perf print-events: Remove print_hwcache_events Ian Rogers
2025-08-28 20:59 ` [PATCH v3 14/15] perf print-events: Remove print_symbol_events Ian Rogers
2025-08-28 20:59 ` [PATCH v3 15/15] perf parse-events: Remove hard coded legacy hardware and cache parsing Ian Rogers
2025-09-03 8:06 ` [PATCH v3 00/15] Legacy hardware/cache events as json Thomas Richter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250828205930.4007284-8-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=atishp@rivosinc.com \
--cc=beeman@rivosinc.com \
--cc=bpf@vger.kernel.org \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=leo.yan@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=thomas.falcon@intel.com \
--cc=vincent.weaver@maine.edu \
--cc=xu.yang_2@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).