1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_PSI_H
3 #define _LINUX_PSI_H
4
5 #include <linux/jump_label.h>
6 #include <linux/psi_types.h>
7 #include <linux/sched.h>
8 #include <linux/poll.h>
9 #include <linux/cgroup-defs.h>
10 #include <linux/cgroup.h>
11
12 struct seq_file;
13 struct css_set;
14
15 #ifdef CONFIG_PSI
16
17 extern struct static_key_false psi_disabled;
18 extern struct psi_group psi_system;
19
20 void psi_init(void);
21
22 void psi_memstall_enter(unsigned long *flags);
23 void psi_memstall_leave(unsigned long *flags);
24
25 int psi_show(struct seq_file *s, struct psi_group *group, enum psi_res res);
26 struct psi_trigger *psi_trigger_create(struct psi_group *group, char *buf,
27 enum psi_res res, struct file *file,
28 struct kernfs_open_file *of,
29 bool *need_rtpoll_worker);
30 int psi_trigger_create_rtpoll_worker(struct psi_group *group);
31 void psi_trigger_destroy(struct psi_trigger *t);
32
33 __poll_t psi_trigger_poll(void **trigger_ptr, struct file *file,
34 poll_table *wait);
35
36 #ifdef CONFIG_CGROUPS
cgroup_psi(struct cgroup * cgrp)37 static inline struct psi_group *cgroup_psi(struct cgroup *cgrp)
38 {
39 return cgroup_ino(cgrp) == 1 ? &psi_system : cgrp->psi;
40 }
41
42 int psi_cgroup_alloc(struct cgroup *cgrp);
43 void psi_cgroup_free(struct cgroup *cgrp);
44 void cgroup_move_task(struct task_struct *p, struct css_set *to);
45 void psi_cgroup_restart(struct psi_group *group);
46 #endif
47
48 #else /* CONFIG_PSI */
49
psi_init(void)50 static inline void psi_init(void) {}
51
psi_memstall_enter(unsigned long * flags)52 static inline void psi_memstall_enter(unsigned long *flags) {}
psi_memstall_leave(unsigned long * flags)53 static inline void psi_memstall_leave(unsigned long *flags) {}
54
55 #ifdef CONFIG_CGROUPS
psi_cgroup_alloc(struct cgroup * cgrp)56 static inline int psi_cgroup_alloc(struct cgroup *cgrp)
57 {
58 return 0;
59 }
psi_cgroup_free(struct cgroup * cgrp)60 static inline void psi_cgroup_free(struct cgroup *cgrp)
61 {
62 }
cgroup_move_task(struct task_struct * p,struct css_set * to)63 static inline void cgroup_move_task(struct task_struct *p, struct css_set *to)
64 {
65 rcu_assign_pointer(p->cgroups, to);
66 }
psi_cgroup_restart(struct psi_group * group)67 static inline void psi_cgroup_restart(struct psi_group *group) {}
68 #endif
69
70 #endif /* CONFIG_PSI */
71
72 #endif /* _LINUX_PSI_H */
73