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 void psi_trigger_destroy(struct psi_trigger *t);
30 
31 __poll_t psi_trigger_poll(void **trigger_ptr, struct file *file,
32 			poll_table *wait);
33 
34 #ifdef CONFIG_CGROUPS
cgroup_psi(struct cgroup * cgrp)35 static inline struct psi_group *cgroup_psi(struct cgroup *cgrp)
36 {
37 	return cgroup_ino(cgrp) == 1 ? &psi_system : cgrp->psi;
38 }
39 
40 int psi_cgroup_alloc(struct cgroup *cgrp);
41 void psi_cgroup_free(struct cgroup *cgrp);
42 void cgroup_move_task(struct task_struct *p, struct css_set *to);
43 void psi_cgroup_restart(struct psi_group *group);
44 #endif
45 
46 #else /* CONFIG_PSI */
47 
psi_init(void)48 static inline void psi_init(void) {}
49 
psi_memstall_enter(unsigned long * flags)50 static inline void psi_memstall_enter(unsigned long *flags) {}
psi_memstall_leave(unsigned long * flags)51 static inline void psi_memstall_leave(unsigned long *flags) {}
52 
53 #ifdef CONFIG_CGROUPS
psi_cgroup_alloc(struct cgroup * cgrp)54 static inline int psi_cgroup_alloc(struct cgroup *cgrp)
55 {
56 	return 0;
57 }
psi_cgroup_free(struct cgroup * cgrp)58 static inline void psi_cgroup_free(struct cgroup *cgrp)
59 {
60 }
cgroup_move_task(struct task_struct * p,struct css_set * to)61 static inline void cgroup_move_task(struct task_struct *p, struct css_set *to)
62 {
63 	rcu_assign_pointer(p->cgroups, to);
64 }
psi_cgroup_restart(struct psi_group * group)65 static inline void psi_cgroup_restart(struct psi_group *group) {}
66 #endif
67 
68 #endif /* CONFIG_PSI */
69 
70 #endif /* _LINUX_PSI_H */
71