tools lib api fs: Move cgroupsfs_find_mountpoint()
Namhyung Kim
maintainerPATCH 1/1 tools lib api fs: Move cgroupsfs_find_mountpoint()
Move it from tools/perf/util/cgroup.c as it can be used by other places. Note that cgroup filesystem is different from others since it's usually mounted separately (in v1) for each subsystem.
I just copied the code with a little modification to pass a name of subsystem.
--- tools/lib/api/fs/Build | 1 + tools/lib/api/fs/cgroup.c | 67 +++++++++++++++++++++++++++++++++++++++ tools/lib/api/fs/fs.h | 2 ++ tools/perf/util/cgroup.c | 63 ++---------------------------------- 4 files changed, 72 insertions(+), 61 deletions(-) create mode 100644 tools/lib/api/fs/cgroup.c
tools/lib/api/fs/Build +1 -0
@@ -1,2 +1,3 @@ libapi-y += fs.o libapi-y += tracing_path.o +libapi-y += cgroup.o
tools/lib/api/fs/cgroup.c new file +67 -0
67 lines not on this page · raw message
tools/lib/api/fs/fs.h +2 -0
@@ -28,6 +28,8 @@ FS(bpf_fs)#undef FS +int cgroupfs_find_mountpoint (char *buf,size_t maxlen,const char *subsys); +int filename__read_int (const char *filename,int *value);int filename__read_ull (const char *filename,unsigned long long *value);int filename__read_xll (const char *filename,unsigned long long *value);
tools/perf/util/cgroup.c +2 -61
84 lines not on this page · raw message
Signature · 1 line
2.25.0.341.g760bfbb309-goog
On Mon, Jan 27, 2020 at 07:00:31PM +0900, Namhyung Kim wrote:
SNIP
Quoted 12 lines
tools/perf/util/cgroup.c +0
-8- -if (strlen (path) < maxlen) { -strcpy (buf, path); -return 0 ; - } -return -1 ; -} -static int open_cgroup (const char *name) {char path[PATH_MAX +1 ];
tools/perf/util/cgroup.c static int open_cgroup(const char *name) · line 23
Quoted 5 lines
tools/perf/util/cgroup.c +1
-1@@ -79,7 +20,7 @@ static int open_cgroup(const char *name)int fd; -if (cgroupfs_find_mountpoint (mnt,PATH_MAX +1 )) +if (cgroupfs_find_mountpoint (mnt,PATH_MAX +1 ,"perf_event" ))
nice, but could you please follow fs API names and change the name to cgroupfs__mountpoint
I think we don't need to define the rest of the functions now, if they are not used
#define FS(name) \ const char *name##__mountpoint(void); \ const char *name##__mount(void); \ bool name##__configured(void); \
just follow the function name
thanks,
jirka
Quoted 6 lines
tools/perf/util/cgroup.c +0
-0return -1 ;scnprintf (path,PATH_MAX ,"%s/%s" , mnt, name);Signature · 1 line
2.25.0.341.g760bfbb309-goog
Namhyung Kim
maintainerHi Jiri,
Quoted 29 lines · Jiri Olsa
On Mon, Jan 27, 2020 at 07:00:31PM +0900, Namhyung Kim wrote:
SNIP
Quoted 12 lines
tools/perf/util/cgroup.c +0
-8- -if (strlen (path) < maxlen) { -strcpy (buf, path); -return 0 ; - } -return -1 ; -} -static int open_cgroup (const char *name) {char path[PATH_MAX +1 ];tools/perf/util/cgroup.c static int open_cgroup(const char *name) · line 23
Quoted 5 lines
tools/perf/util/cgroup.c +1
-1@@ -79,7 +20,7 @@ static int open_cgroup(const char *name)int fd; -if (cgroupfs_find_mountpoint (mnt,PATH_MAX +1 )) +if (cgroupfs_find_mountpoint (mnt,PATH_MAX +1 ,"perf_event" ))nice, but could you please follow fs API names and change the name to
cgroupfs__mountpointI think we don't need to define the rest of the functions now, if they are not used
Quoted 6 lines
#define FS(name) \ const char *name##__mountpoint(void); \ const char *name##__mount(void); \ bool name##__configured(void); \just follow the function name
I thought about it too, but still it has different arguments. So I left it as is... Do you really want to rename?
Thanks
Namhyung
Quoted 37 lines · Namhyung Kim
Hi Jiri,
Quoted 34 lines · Jiri Olsa
On Mon, Jan 27, 2020 at 07:00:31PM +0900, Namhyung Kim wrote:
SNIP
Quoted 12 lines
tools/perf/util/cgroup.c +0
-8- -if (strlen (path) < maxlen) { -strcpy (buf, path); -return 0 ; - } -return -1 ; -} -static int open_cgroup (const char *name) {char path[PATH_MAX +1 ];tools/perf/util/cgroup.c static int open_cgroup(const char *name) · line 23
Quoted 5 lines
tools/perf/util/cgroup.c +1
-1@@ -79,7 +20,7 @@ static int open_cgroup(const char *name)int fd; -if (cgroupfs_find_mountpoint (mnt,PATH_MAX +1 )) +if (cgroupfs_find_mountpoint (mnt,PATH_MAX +1 ,"perf_event" ))nice, but could you please follow fs API names and change the name to
cgroupfs__mountpointI think we don't need to define the rest of the functions now, if they are not used
#define FS(name) \ const char *name##__mountpoint(void); \ const char *name##__mount(void); \ bool name##__configured(void); \
Quoted 4 lines
Quoted 1 line
just follow the function name
I thought about it too, but still it has different arguments. So I left it as is... Do you really want to rename?
yea I think we should keep the same name, Arnaldo?
jirka
Quoted 4 lines
Thanks
Namhyung
Namhyung Kim
maintainerPATCH v2 1/1 tools lib api fs: Move cgroupsfs__mountpoint()
Move it from tools/perf/util/cgroup.c as it can be used by other places. Note that cgroup filesystem is different from others since it's usually mounted separately (in v1) for each subsystem.
I just copied the code with a little modification to pass a name of subsystem and renamed it to follow other APIs.
---
* rename to cgroupfs__mountpoint()
tools/lib/api/fs/Build | 1 + tools/lib/api/fs/cgroup.c | 67 +++++++++++++++++++++++++++++++++++++++ tools/lib/api/fs/fs.h | 2 ++ tools/perf/util/cgroup.c | 63 ++---------------------------------- 4 files changed, 72 insertions(+), 61 deletions(-) create mode 100644 tools/lib/api/fs/cgroup.c
tools/lib/api/fs/Build +1 -0
@@ -1,2 +1,3 @@ libapi-y += fs.o libapi-y += tracing_path.o +libapi-y += cgroup.o
tools/lib/api/fs/cgroup.c new file +67 -0
67 lines not on this page · raw message
tools/lib/api/fs/fs.h +2 -0
@@ -28,6 +28,8 @@ FS(bpf_fs)#undef FS +int cgroupfs__mountpoint (char *buf,size_t maxlen,const char *subsys); +int filename__read_int (const char *filename,int *value);int filename__read_ull (const char *filename,unsigned long long *value);int filename__read_xll (const char *filename,unsigned long long *value);
tools/perf/util/cgroup.c +2 -61
84 lines not on this page · raw message
Signature · 1 line
2.25.0.341.g760bfbb309-goog
Re: [PATCH v2] tools lib api fs: Move cgroupsfs__mountpoint()
Quoted 9 lines · Namhyung Kim
Move it from
tools/perf/util/cgroup.cas it can be used by other places. Note that cgroup filesystem is different from others since it's usually mounted separately (in v1) for each subsystem.I just copied the code with a little modification to pass a name of subsystem and renamed it to follow other APIs.
Suggested-by Jiri Olsa <[email protected]>Signed-off-by Namhyung Kim <[email protected]>
thanks,
jirka
Quoted 197 lines
---
* rename tocgroupfs__mountpoint()tools/lib/api/fs/Build | 1 + tools/lib/api/fs/cgroup.c | 67 +++++++++++++++++++++++++++++++++++++++ tools/lib/api/fs/fs.h | 2 ++ tools/perf/util/cgroup.c | 63 ++---------------------------------- 4 files changed, 72 insertions(+), 61 deletions(-) create mode 100644 tools/lib/api/fs/cgroup.ctools/lib/api/fs/Build +1
-0@@ -1,2 +1,3 @@ libapi-y += fs.o libapi-y += tracing_path.o +libapi-y += cgroup.otools/lib/api/fs/cgroup.c new file +67
-0@@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/stringify.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "fs.h" + +int cgroupfs__mountpoint (char *buf,size_t maxlen,const char *subsys) +{ +FILE *fp; +char mountpoint[PATH_MAX +1 ], tokens[PATH_MAX +1 ], type[PATH_MAX +1 ]; +char path_v1[PATH_MAX +1 ], path_v2[PATH_MAX +2 ], *path; +char *token, *saved_ptr =NULL ; + + fp =fopen ("/proc/mounts" ,"r" ); +if (!fp) +return -1 ; + +/* +* in order to handle split hierarchy, we need to scan /proc/mounts +* and inspect every cgroupfs mount point to find one that has +* perf_event subsystem +*/ + path_v1[0 ] ='\0' ; + path_v2[0 ] ='\0' ; + + while (fscanf(fp, "%*s %"__stringify(PATH_MAX)"s %"__stringify(PATH_MAX)"s %" + __stringify(PATH_MAX)"s %*d %*d\n", + mountpoint, type, tokens) ==3 ) { + +if (!path_v1[0 ] && !strcmp (type,"cgroup" )) { + + token =strtok_r (tokens,"," , &saved_ptr); + +while (token !=NULL ) { +if (subsys && !strcmp (token, subsys)) { +strcpy (path_v1, mountpoint); +break ; + } + token =strtok_r (NULL ,"," , &saved_ptr); + } + } + +if (!path_v2[0 ] && !strcmp (type,"cgroup2" )) +strcpy (path_v2, mountpoint); + +if (path_v1[0 ] && path_v2[0 ]) +break ; + } +fclose (fp); + +if (path_v1[0 ]) + path = path_v1; +else if (path_v2[0 ]) + path = path_v2; +else +return -1 ; + +if (strlen (path) < maxlen) { +strcpy (buf, path); +return 0 ; + } +return -1 ; +}tools/lib/api/fs/fs.h +2
-0@@ -28,6 +28,8 @@ FS(bpf_fs)#undef FS +int cgroupfs__mountpoint (char *buf,size_t maxlen,const char *subsys); +int filename__read_int (const char *filename,int *value);int filename__read_ull (const char *filename,unsigned long long *value);int filename__read_xll (const char *filename,unsigned long long *value);tools/perf/util/cgroup.c +2
-61@@ -3,75 +3,16 @@#include "evsel.h" #include "cgroup.h" #include "evlist.h" -#include <linux/stringify.h> #include <linux/zalloc.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdlib.h> #include <string.h> +#include <api/fs/fs.h> int nr_cgroups; -static int -cgroupfs_find_mountpoint (char *buf,size_t maxlen) -{ -FILE *fp; -char mountpoint[PATH_MAX +1 ], tokens[PATH_MAX +1 ], type[PATH_MAX +1 ]; -char path_v1[PATH_MAX +1 ], path_v2[PATH_MAX +2 ], *path; -char *token, *saved_ptr =NULL ; - - fp =fopen ("/proc/mounts" ,"r" ); -if (!fp) -return -1 ; - -/* -* in order to handle split hierarchy, we need to scan /proc/mounts -* and inspect every cgroupfs mount point to find one that has -* perf_event subsystem -*/ - path_v1[0 ] ='\0' ; - path_v2[0 ] ='\0' ; - - while (fscanf(fp, "%*s %"__stringify(PATH_MAX)"s %"__stringify(PATH_MAX)"s %" - __stringify(PATH_MAX)"s %*d %*d\n", - mountpoint, type, tokens) ==3 ) { - -if (!path_v1[0 ] && !strcmp (type,"cgroup" )) { - - token =strtok_r (tokens,"," , &saved_ptr); - -while (token !=NULL ) { -if (!strcmp (token,"perf_event" )) { -strcpy (path_v1, mountpoint); -break ; - } - token =strtok_r (NULL ,"," , &saved_ptr); - } - } - -if (!path_v2[0 ] && !strcmp (type,"cgroup2" )) -strcpy (path_v2, mountpoint); - -if (path_v1[0 ] && path_v2[0 ]) -break ; - } -fclose (fp); - -if (path_v1[0 ]) - path = path_v1; -else if (path_v2[0 ]) - path = path_v2; -else -return -1 ; - -if (strlen (path) < maxlen) { -strcpy (buf, path); -return 0 ; - } -return -1 ; -} -static int open_cgroup (const char *name) {char path[PATH_MAX +1 ];@@ -79,7 +20,7 @@ static int open_cgroup(const char *name)int fd; -if (cgroupfs_find_mountpoint (mnt,PATH_MAX +1 )) +if (cgroupfs__mountpoint (mnt,PATH_MAX +1 ,"perf_event" ))return -1 ;scnprintf (path,PATH_MAX ,"%s/%s" , mnt, name);Signature · 1 line
2.25.0.341.g760bfbb309-goog
Arnaldo Carvalho de Melo
AppliedRe: [PATCH v2] tools lib api fs: Move cgroupsfs__mountpoint()
Em Tue, Jan 28, 2020 at 10:40:57AM +0100, Jiri Olsa escreveu:
Quoted 5 lines · Namhyung Kim
Quoted 4 lines
Move it from
tools/perf/util/cgroup.cas it can be used by other places. Note that cgroup filesystem is different from others since it's usually mounted separately (in v1) for each subsystem.
Quoted 7 lines
Quoted 5 lines
I just copied the code with a little modification to pass a name of subsystem and renamed it to follow other APIs.
Suggested-by Jiri Olsa <[email protected]>Signed-off-by Namhyung Kim <[email protected]>Acked-by Jiri Olsa <[email protected]>
Thanks, applied to perf/core.
- Arnaldo
Quoted 201 lines
thanks,
jirkaQuoted 197 lines
---
* rename tocgroupfs__mountpoint()tools/lib/api/fs/Build | 1 + tools/lib/api/fs/cgroup.c | 67 +++++++++++++++++++++++++++++++++++++++ tools/lib/api/fs/fs.h | 2 ++ tools/perf/util/cgroup.c | 63 ++---------------------------------- 4 files changed, 72 insertions(+), 61 deletions(-) create mode 100644 tools/lib/api/fs/cgroup.ctools/lib/api/fs/Build +1
-0@@ -1,2 +1,3 @@ libapi-y += fs.o libapi-y += tracing_path.o +libapi-y += cgroup.otools/lib/api/fs/cgroup.c new file +67
-0@@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/stringify.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "fs.h" + +int cgroupfs__mountpoint (char *buf,size_t maxlen,const char *subsys) +{ +FILE *fp; +char mountpoint[PATH_MAX +1 ], tokens[PATH_MAX +1 ], type[PATH_MAX +1 ]; +char path_v1[PATH_MAX +1 ], path_v2[PATH_MAX +2 ], *path; +char *token, *saved_ptr =NULL ; + + fp =fopen ("/proc/mounts" ,"r" ); +if (!fp) +return -1 ; + +/* +* in order to handle split hierarchy, we need to scan /proc/mounts +* and inspect every cgroupfs mount point to find one that has +* perf_event subsystem +*/ + path_v1[0 ] ='\0' ; + path_v2[0 ] ='\0' ; + + while (fscanf(fp, "%*s %"__stringify(PATH_MAX)"s %"__stringify(PATH_MAX)"s %" + __stringify(PATH_MAX)"s %*d %*d\n", + mountpoint, type, tokens) ==3 ) { + +if (!path_v1[0 ] && !strcmp (type,"cgroup" )) { + + token =strtok_r (tokens,"," , &saved_ptr); + +while (token !=NULL ) { +if (subsys && !strcmp (token, subsys)) { +strcpy (path_v1, mountpoint); +break ; + } + token =strtok_r (NULL ,"," , &saved_ptr); + } + } + +if (!path_v2[0 ] && !strcmp (type,"cgroup2" )) +strcpy (path_v2, mountpoint); + +if (path_v1[0 ] && path_v2[0 ]) +break ; + } +fclose (fp); + +if (path_v1[0 ]) + path = path_v1; +else if (path_v2[0 ]) + path = path_v2; +else +return -1 ; + +if (strlen (path) < maxlen) { +strcpy (buf, path); +return 0 ; + } +return -1 ; +}tools/lib/api/fs/fs.h +2
-0@@ -28,6 +28,8 @@ FS(bpf_fs)#undef FS +int cgroupfs__mountpoint (char *buf,size_t maxlen,const char *subsys); +int filename__read_int (const char *filename,int *value);int filename__read_ull (const char *filename,unsigned long long *value);int filename__read_xll (const char *filename,unsigned long long *value);tools/perf/util/cgroup.c +2
-61@@ -3,75 +3,16 @@#include "evsel.h" #include "cgroup.h" #include "evlist.h" -#include <linux/stringify.h> #include <linux/zalloc.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdlib.h> #include <string.h> +#include <api/fs/fs.h> int nr_cgroups; -static int -cgroupfs_find_mountpoint (char *buf,size_t maxlen) -{ -FILE *fp; -char mountpoint[PATH_MAX +1 ], tokens[PATH_MAX +1 ], type[PATH_MAX +1 ]; -char path_v1[PATH_MAX +1 ], path_v2[PATH_MAX +2 ], *path; -char *token, *saved_ptr =NULL ; - - fp =fopen ("/proc/mounts" ,"r" ); -if (!fp) -return -1 ; - -/* -* in order to handle split hierarchy, we need to scan /proc/mounts -* and inspect every cgroupfs mount point to find one that has -* perf_event subsystem -*/ - path_v1[0 ] ='\0' ; - path_v2[0 ] ='\0' ; - - while (fscanf(fp, "%*s %"__stringify(PATH_MAX)"s %"__stringify(PATH_MAX)"s %" - __stringify(PATH_MAX)"s %*d %*d\n", - mountpoint, type, tokens) ==3 ) { - -if (!path_v1[0 ] && !strcmp (type,"cgroup" )) { - - token =strtok_r (tokens,"," , &saved_ptr); - -while (token !=NULL ) { -if (!strcmp (token,"perf_event" )) { -strcpy (path_v1, mountpoint); -break ; - } - token =strtok_r (NULL ,"," , &saved_ptr); - } - } - -if (!path_v2[0 ] && !strcmp (type,"cgroup2" )) -strcpy (path_v2, mountpoint); - -if (path_v1[0 ] && path_v2[0 ]) -break ; - } -fclose (fp); - -if (path_v1[0 ]) - path = path_v1; -else if (path_v2[0 ]) - path = path_v2; -else -return -1 ; - -if (strlen (path) < maxlen) { -strcpy (buf, path); -return 0 ; - } -return -1 ; -} -static int open_cgroup (const char *name) {char path[PATH_MAX +1 ];@@ -79,7 +20,7 @@ static int open_cgroup(const char *name)int fd; -if (cgroupfs_find_mountpoint (mnt,PATH_MAX +1 )) +if (cgroupfs__mountpoint (mnt,PATH_MAX +1 ,"perf_event" ))return -1 ;scnprintf (path,PATH_MAX ,"%s/%s" , mnt, name);Signature · 1 line
2.25.0.341.g760bfbb309-goog
Signature · 1 line
- Arnaldo
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 7982a898515064ba180d958bfc89ed22d13905ee Gitweb: https://git.kernel.org/tip/7982a898515064ba180d958bfc89ed22d13905ee Author: Namhyung Kim <[email protected]> AuthorDate: Mon, 27 Jan 2020 19:00:31 +09:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Wed, 04 Mar 2020 10:34:09 -03:00
tools lib api fs: Move cgroupsfs_find_mountpoint()
Move it from tools/perf/util/cgroup.c as it can be used by other places. Note that cgroup filesystem is different from others since it's usually mounted separately (in v1) for each subsystem.
I just copied the code with a little modification to pass a name of subsystem.
--- tools/lib/api/fs/Build | 1 +- tools/lib/api/fs/cgroup.c | 67 ++++++++++++++++++++++++++++++++++++++- tools/lib/api/fs/fs.h | 2 +- tools/perf/util/cgroup.c | 63 +----------------------------------- 4 files changed, 72 insertions(+), 61 deletions(-) create mode 100644 tools/lib/api/fs/cgroup.c
tools/lib/api/fs/Build +1 -0
@@ -1,2 +1,3 @@ libapi-y += fs.o libapi-y += tracing_path.o +libapi-y += cgroup.o
tools/lib/api/fs/cgroup.c new file +67 -0
67 lines not on this page · raw message
tools/lib/api/fs/fs.h +2 -0
@@ -28,6 +28,8 @@ FS(bpf_fs)#undef FS +int cgroupfs_find_mountpoint (char *buf,size_t maxlen,const char *subsys); +int filename__read_int (const char *filename,int *value);int filename__read_ull (const char *filename,unsigned long long *value);int filename__read_xll (const char *filename,unsigned long long *value);
tools/perf/util/cgroup.c +2 -61
84 lines not on this page · raw message