mirror of
https://github.com/torvalds/linux.git
synced 2026-06-01 11:03:43 +02:00
perf parse-events: Switch tracepoints to io_dir__readdir
Avoid DIR allocations when scanning sysfs by using io_dir for the readdir implementation, that allocates about 1kb on the stack. Signed-off-by: Ian Rogers <irogers@google.com> Link: https://lore.kernel.org/r/20250222061015.303622-7-irogers@google.com Signed-off-by: Namhyung Kim <namhyung@kernel.org>
This commit is contained in:
parent
56406bd557
commit
bb327140f5
|
|
@ -17,6 +17,7 @@
|
|||
#include "strbuf.h"
|
||||
#include "debug.h"
|
||||
#include <api/fs/tracing_path.h>
|
||||
#include <api/io_dir.h>
|
||||
#include <perf/cpumap.h>
|
||||
#include <util/parse-events-bison.h>
|
||||
#include <util/parse-events-flex.h>
|
||||
|
|
@ -554,8 +555,8 @@ static int add_tracepoint_multi_event(struct parse_events_state *parse_state,
|
|||
struct parse_events_terms *head_config, YYLTYPE *loc)
|
||||
{
|
||||
char *evt_path;
|
||||
struct dirent *evt_ent;
|
||||
DIR *evt_dir;
|
||||
struct io_dirent64 *evt_ent;
|
||||
struct io_dir evt_dir;
|
||||
int ret = 0, found = 0;
|
||||
|
||||
evt_path = get_events_file(sys_name);
|
||||
|
|
@ -563,14 +564,14 @@ static int add_tracepoint_multi_event(struct parse_events_state *parse_state,
|
|||
tracepoint_error(err, errno, sys_name, evt_name, loc->first_column);
|
||||
return -1;
|
||||
}
|
||||
evt_dir = opendir(evt_path);
|
||||
if (!evt_dir) {
|
||||
io_dir__init(&evt_dir, open(evt_path, O_CLOEXEC | O_DIRECTORY | O_RDONLY));
|
||||
if (evt_dir.dirfd < 0) {
|
||||
put_events_file(evt_path);
|
||||
tracepoint_error(err, errno, sys_name, evt_name, loc->first_column);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (!ret && (evt_ent = readdir(evt_dir))) {
|
||||
while (!ret && (evt_ent = io_dir__readdir(&evt_dir))) {
|
||||
if (!strcmp(evt_ent->d_name, ".")
|
||||
|| !strcmp(evt_ent->d_name, "..")
|
||||
|| !strcmp(evt_ent->d_name, "enable")
|
||||
|
|
@ -592,7 +593,7 @@ static int add_tracepoint_multi_event(struct parse_events_state *parse_state,
|
|||
}
|
||||
|
||||
put_events_file(evt_path);
|
||||
closedir(evt_dir);
|
||||
close(evt_dir.dirfd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -615,17 +616,23 @@ static int add_tracepoint_multi_sys(struct parse_events_state *parse_state,
|
|||
struct parse_events_error *err,
|
||||
struct parse_events_terms *head_config, YYLTYPE *loc)
|
||||
{
|
||||
struct dirent *events_ent;
|
||||
DIR *events_dir;
|
||||
struct io_dirent64 *events_ent;
|
||||
struct io_dir events_dir;
|
||||
int ret = 0;
|
||||
char *events_dir_path = get_tracing_file("events");
|
||||
|
||||
events_dir = tracing_events__opendir();
|
||||
if (!events_dir) {
|
||||
if (!events_dir_path) {
|
||||
tracepoint_error(err, errno, sys_name, evt_name, loc->first_column);
|
||||
return -1;
|
||||
}
|
||||
io_dir__init(&events_dir, open(events_dir_path, O_CLOEXEC | O_DIRECTORY | O_RDONLY));
|
||||
put_events_file(events_dir_path);
|
||||
if (events_dir.dirfd < 0) {
|
||||
tracepoint_error(err, errno, sys_name, evt_name, loc->first_column);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (!ret && (events_ent = readdir(events_dir))) {
|
||||
while (!ret && (events_ent = io_dir__readdir(&events_dir))) {
|
||||
if (!strcmp(events_ent->d_name, ".")
|
||||
|| !strcmp(events_ent->d_name, "..")
|
||||
|| !strcmp(events_ent->d_name, "enable")
|
||||
|
|
@ -639,8 +646,7 @@ static int add_tracepoint_multi_sys(struct parse_events_state *parse_state,
|
|||
ret = add_tracepoint_event(parse_state, list, events_ent->d_name,
|
||||
evt_name, err, head_config, loc);
|
||||
}
|
||||
|
||||
closedir(events_dir);
|
||||
close(events_dir.dirfd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user