xref: /linux/tools/perf/util/cgroup.h (revision f4f346c3465949ebba80c6cc52cd8d2eeaa545fd)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __CGROUP_H__
3 #define __CGROUP_H__
4 
5 #include <linux/compiler.h>
6 #include <linux/refcount.h>
7 #include <linux/rbtree.h>
8 #include "util/env.h"
9 
10 struct option;
11 
12 struct cgroup {
13 	struct rb_node		node;
14 	u64			id;
15 	char			*name;
16 	int			fd;
17 	refcount_t		refcnt;
18 };
19 
20 extern int nr_cgroups; /* number of explicit cgroups defined */
21 extern bool cgrp_event_expanded;
22 
23 struct cgroup *cgroup__get(struct cgroup *cgroup);
24 void cgroup__put(struct cgroup *cgroup);
25 
26 struct evlist;
27 struct rblist;
28 
29 struct cgroup *cgroup__new(const char *name, bool do_open);
30 struct cgroup *evlist__findnew_cgroup(struct evlist *evlist, const char *name);
31 int evlist__expand_cgroup(struct evlist *evlist, const char *cgroups, bool open_cgroup);
32 
33 void evlist__set_default_cgroup(struct evlist *evlist, struct cgroup *cgroup);
34 
35 int parse_cgroups(const struct option *opt, const char *str, int unset);
36 
37 struct cgroup *cgroup__findnew(struct perf_env *env, uint64_t id,
38 			       const char *path);
39 struct cgroup *cgroup__find(struct perf_env *env, uint64_t id);
40 struct cgroup *__cgroup__find(struct rb_root *root, uint64_t id);
41 
42 void perf_env__purge_cgroups(struct perf_env *env);
43 
44 #ifdef HAVE_FILE_HANDLE
45 int read_cgroup_id(struct cgroup *cgrp);
46 #else
read_cgroup_id(struct cgroup * cgrp __maybe_unused)47 static inline int read_cgroup_id(struct cgroup *cgrp __maybe_unused)
48 {
49 	return -1;
50 }
51 #endif  /* HAVE_FILE_HANDLE */
52 
53 /* read all cgroups in the system and save them in the rbtree */
54 void read_all_cgroups(struct rb_root *root);
55 
56 int cgroup_is_v2(const char *subsys);
57 
58 #endif /* __CGROUP_H__ */
59