1 #ifndef _LINUX_PSI_TYPES_H
2 #define _LINUX_PSI_TYPES_H
4 #include <linux/kthread.h>
5 #include <linux/seqlock.h>
6 #include <linux/types.h>
7 #include <linux/kref.h>
8 #include <linux/wait.h>
12 /* Tracked task states */
17 NR_PSI_TASK_COUNTS = 3,
20 /* Task state bitmasks */
21 #define TSK_IOWAIT (1 << NR_IOWAIT)
22 #define TSK_MEMSTALL (1 << NR_MEMSTALL)
23 #define TSK_RUNNING (1 << NR_RUNNING)
25 /* Resources that workloads could be stalled on */
34 * Pressure states for each resource:
36 * SOME: Stalled tasks & working tasks
37 * FULL: Stalled tasks & no working tasks
45 /* Only per-CPU, to weigh the CPU in the global average: */
50 enum psi_aggregators {
56 struct psi_group_cpu {
57 /* 1st cacheline updated by the scheduler */
59 /* Aggregator needs to know of concurrent changes */
60 seqcount_t seq ____cacheline_aligned_in_smp;
62 /* States of the tasks belonging to this group */
63 unsigned int tasks[NR_PSI_TASK_COUNTS];
65 /* Aggregate pressure state derived from the tasks */
68 /* Period time sampling buckets for each state of interest (ns) */
69 u32 times[NR_PSI_STATES];
71 /* Time of last task change in this group (rq_clock) */
74 /* 2nd cacheline updated by the aggregator */
76 /* Delta detection against the sampling buckets */
77 u32 times_prev[NR_PSI_AGGREGATORS][NR_PSI_STATES]
78 ____cacheline_aligned_in_smp;
81 /* PSI growth tracking window */
83 /* Window size in ns */
86 /* Start time of the current window in ns */
89 /* Value at the start of the window */
92 /* Value growth in the previous window */
97 /* PSI state being monitored by the trigger */
98 enum psi_states state;
100 /* User-spacified threshold in ns */
103 /* List node inside triggers list */
104 struct list_head node;
106 /* Backpointer needed during trigger destruction */
107 struct psi_group *group;
109 /* Wait queue for polling */
110 wait_queue_head_t event_wait;
112 /* Pending event flag */
115 /* Tracking window */
116 struct psi_window win;
119 * Time last event was generated. Used for rate-limiting
120 * events to one per window
124 /* Refcounting to prevent premature destruction */
125 struct kref refcount;
129 /* Protects data used by the aggregator */
130 struct mutex avgs_lock;
132 /* Per-cpu task state & time tracking */
133 struct psi_group_cpu __percpu *pcpu;
135 /* Running pressure averages */
136 u64 avg_total[NR_PSI_STATES - 1];
140 /* Aggregator work control */
141 struct delayed_work avgs_work;
143 /* Total stall times and sampled pressure averages */
144 u64 total[NR_PSI_AGGREGATORS][NR_PSI_STATES - 1];
145 unsigned long avg[NR_PSI_STATES - 1][3];
147 /* Monitor work control */
148 atomic_t poll_scheduled;
149 struct kthread_worker __rcu *poll_kworker;
150 struct kthread_delayed_work poll_work;
152 /* Protects data used by the monitor */
153 struct mutex trigger_lock;
155 /* Configured polling triggers */
156 struct list_head triggers;
157 u32 nr_triggers[NR_PSI_STATES - 1];
161 /* Total stall times at the start of monitor activation */
162 u64 polling_total[NR_PSI_STATES - 1];
163 u64 polling_next_update;
167 #else /* CONFIG_PSI */
169 struct psi_group { };
171 #endif /* CONFIG_PSI */
173 #endif /* _LINUX_PSI_TYPES_H */