提交 725b1368 编写于 作者: E Eric Dumazet 提交者: Ingo Molnar

perf tools: Dont use openat()

openat() is still a young glibc facility, better to not use it in a
non performance critical program (perf list)

Many machines have older glibc (RHEL 4 Update 5 -> glibc-2.3.4-2.36
on my dev machine for example).
Signed-off-by: NEric Dumazet <eric.dumazet@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Ulrich Drepper <drepper@redhat.com>
LKML-Reference: <4ABB767D.6080004@gmail.com>
Signed-off-by: NIngo Molnar <mingo@elte.hu>
上级 a255a998
...@@ -165,33 +165,31 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config) ...@@ -165,33 +165,31 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
DIR *sys_dir, *evt_dir; DIR *sys_dir, *evt_dir;
struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
char id_buf[4]; char id_buf[4];
int sys_dir_fd, fd; int fd;
u64 id; u64 id;
char evt_path[MAXPATHLEN]; char evt_path[MAXPATHLEN];
char dir_path[MAXPATHLEN];
if (valid_debugfs_mount(debugfs_path)) if (valid_debugfs_mount(debugfs_path))
return NULL; return NULL;
sys_dir = opendir(debugfs_path); sys_dir = opendir(debugfs_path);
if (!sys_dir) if (!sys_dir)
goto cleanup; return NULL;
sys_dir_fd = dirfd(sys_dir);
for_each_subsystem(sys_dir, sys_dirent, sys_next) { for_each_subsystem(sys_dir, sys_dirent, sys_next) {
int dfd = openat(sys_dir_fd, sys_dirent.d_name,
O_RDONLY|O_DIRECTORY), evt_dir_fd; snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path,
if (dfd == -1) sys_dirent.d_name);
continue; evt_dir = opendir(dir_path);
evt_dir = fdopendir(dfd); if (!evt_dir)
if (!evt_dir) {
close(dfd);
continue; continue;
}
evt_dir_fd = dirfd(evt_dir);
for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
snprintf(evt_path, MAXPATHLEN, "%s/id",
snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path,
evt_dirent.d_name); evt_dirent.d_name);
fd = openat(evt_dir_fd, evt_path, O_RDONLY); fd = open(evt_path, O_RDONLY);
if (fd < 0) if (fd < 0)
continue; continue;
if (read(fd, id_buf, sizeof(id_buf)) < 0) { if (read(fd, id_buf, sizeof(id_buf)) < 0) {
...@@ -225,7 +223,6 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config) ...@@ -225,7 +223,6 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
closedir(evt_dir); closedir(evt_dir);
} }
cleanup:
closedir(sys_dir); closedir(sys_dir);
return NULL; return NULL;
} }
...@@ -761,28 +758,24 @@ static void print_tracepoint_events(void) ...@@ -761,28 +758,24 @@ static void print_tracepoint_events(void)
{ {
DIR *sys_dir, *evt_dir; DIR *sys_dir, *evt_dir;
struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
int sys_dir_fd;
char evt_path[MAXPATHLEN]; char evt_path[MAXPATHLEN];
char dir_path[MAXPATHLEN];
if (valid_debugfs_mount(debugfs_path)) if (valid_debugfs_mount(debugfs_path))
return; return;
sys_dir = opendir(debugfs_path); sys_dir = opendir(debugfs_path);
if (!sys_dir) if (!sys_dir)
goto cleanup; return;
sys_dir_fd = dirfd(sys_dir);
for_each_subsystem(sys_dir, sys_dirent, sys_next) { for_each_subsystem(sys_dir, sys_dirent, sys_next) {
int dfd = openat(sys_dir_fd, sys_dirent.d_name,
O_RDONLY|O_DIRECTORY), evt_dir_fd; snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path,
if (dfd == -1) sys_dirent.d_name);
continue; evt_dir = opendir(dir_path);
evt_dir = fdopendir(dfd); if (!evt_dir)
if (!evt_dir) {
close(dfd);
continue; continue;
}
evt_dir_fd = dirfd(evt_dir);
for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
snprintf(evt_path, MAXPATHLEN, "%s:%s", snprintf(evt_path, MAXPATHLEN, "%s:%s",
sys_dirent.d_name, evt_dirent.d_name); sys_dirent.d_name, evt_dirent.d_name);
...@@ -791,8 +784,6 @@ static void print_tracepoint_events(void) ...@@ -791,8 +784,6 @@ static void print_tracepoint_events(void)
} }
closedir(evt_dir); closedir(evt_dir);
} }
cleanup:
closedir(sys_dir); closedir(sys_dir);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册