Skip to content

Commit 21bcc72

Browse files
namhyungacmel
authored andcommitted
perf tools: Add cgroup_is_v2() helper
The cgroup_is_v2() is to check if the given subsystem is mounted on cgroup v2 or not. It'll be used by BPF cgroup code later. Signed-off-by: Namhyung Kim <[email protected]> Acked-by: Ian Rogers <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Song Liu <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 69e874d commit 21bcc72

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

tools/perf/util/cgroup.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/zalloc.h>
1010
#include <sys/types.h>
1111
#include <sys/stat.h>
12+
#include <sys/statfs.h>
1213
#include <fcntl.h>
1314
#include <stdlib.h>
1415
#include <string.h>
@@ -70,6 +71,24 @@ int read_cgroup_id(struct cgroup *cgrp)
7071
}
7172
#endif /* HAVE_FILE_HANDLE */
7273

74+
#ifndef CGROUP2_SUPER_MAGIC
75+
#define CGROUP2_SUPER_MAGIC 0x63677270
76+
#endif
77+
78+
int cgroup_is_v2(const char *subsys)
79+
{
80+
char mnt[PATH_MAX + 1];
81+
struct statfs stbuf;
82+
83+
if (cgroupfs_find_mountpoint(mnt, PATH_MAX + 1, subsys))
84+
return -1;
85+
86+
if (statfs(mnt, &stbuf) < 0)
87+
return -1;
88+
89+
return (stbuf.f_type == CGROUP2_SUPER_MAGIC);
90+
}
91+
7392
static struct cgroup *evlist__find_cgroup(struct evlist *evlist, const char *str)
7493
{
7594
struct evsel *counter;

tools/perf/util/cgroup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@ static inline int read_cgroup_id(struct cgroup *cgrp __maybe_unused)
4848
}
4949
#endif /* HAVE_FILE_HANDLE */
5050

51+
int cgroup_is_v2(const char *subsys);
52+
5153
#endif /* __CGROUP_H__ */

0 commit comments

Comments
 (0)