Commit | Line | Data |
---|---|---|
7cafcfd8 JW |
1 | #ifndef _LINUX_PSI_TYPES_H |
2 | #define _LINUX_PSI_TYPES_H | |
3 | ||
4 | #include <linux/seqlock.h> | |
5 | #include <linux/types.h> | |
6 | ||
7 | #ifdef CONFIG_PSI | |
8 | ||
9 | /* Tracked task states */ | |
10 | enum psi_task_count { | |
11 | NR_IOWAIT, | |
12 | NR_MEMSTALL, | |
13 | NR_RUNNING, | |
f42ae2d6 | 14 | NR_PSI_TASK_COUNTS = 3, |
7cafcfd8 JW |
15 | }; |
16 | ||
17 | /* Task state bitmasks */ | |
18 | #define TSK_IOWAIT (1 << NR_IOWAIT) | |
19 | #define TSK_MEMSTALL (1 << NR_MEMSTALL) | |
20 | #define TSK_RUNNING (1 << NR_RUNNING) | |
21 | ||
22 | /* Resources that workloads could be stalled on */ | |
23 | enum psi_res { | |
24 | PSI_IO, | |
25 | PSI_MEM, | |
26 | PSI_CPU, | |
f42ae2d6 | 27 | NR_PSI_RESOURCES = 3, |
7cafcfd8 JW |
28 | }; |
29 | ||
30 | /* | |
31 | * Pressure states for each resource: | |
32 | * | |
33 | * SOME: Stalled tasks & working tasks | |
34 | * FULL: Stalled tasks & no working tasks | |
35 | */ | |
36 | enum psi_states { | |
37 | PSI_IO_SOME, | |
38 | PSI_IO_FULL, | |
39 | PSI_MEM_SOME, | |
40 | PSI_MEM_FULL, | |
41 | PSI_CPU_SOME, | |
42 | /* Only per-CPU, to weigh the CPU in the global average: */ | |
43 | PSI_NONIDLE, | |
f42ae2d6 | 44 | NR_PSI_STATES = 6, |
7cafcfd8 JW |
45 | }; |
46 | ||
47 | struct psi_group_cpu { | |
48 | /* 1st cacheline updated by the scheduler */ | |
49 | ||
50 | /* Aggregator needs to know of concurrent changes */ | |
51 | seqcount_t seq ____cacheline_aligned_in_smp; | |
52 | ||
53 | /* States of the tasks belonging to this group */ | |
54 | unsigned int tasks[NR_PSI_TASK_COUNTS]; | |
55 | ||
f42ae2d6 SB |
56 | /* Aggregate pressure state derived from the tasks */ |
57 | u32 state_mask; | |
58 | ||
7cafcfd8 JW |
59 | /* Period time sampling buckets for each state of interest (ns) */ |
60 | u32 times[NR_PSI_STATES]; | |
61 | ||
62 | /* Time of last task change in this group (rq_clock) */ | |
63 | u64 state_start; | |
64 | ||
65 | /* 2nd cacheline updated by the aggregator */ | |
66 | ||
67 | /* Delta detection against the sampling buckets */ | |
68 | u32 times_prev[NR_PSI_STATES] ____cacheline_aligned_in_smp; | |
69 | }; | |
70 | ||
71 | struct psi_group { | |
b7e7fd44 SB |
72 | /* Protects data used by the aggregator */ |
73 | struct mutex avgs_lock; | |
7cafcfd8 JW |
74 | |
75 | /* Per-cpu task state & time tracking */ | |
76 | struct psi_group_cpu __percpu *pcpu; | |
77 | ||
b7e7fd44 SB |
78 | /* Running pressure averages */ |
79 | u64 avg_total[NR_PSI_STATES - 1]; | |
80 | u64 avg_last_update; | |
81 | u64 avg_next_update; | |
82 | struct delayed_work avgs_work; | |
7cafcfd8 JW |
83 | |
84 | /* Total stall times and sampled pressure averages */ | |
85 | u64 total[NR_PSI_STATES - 1]; | |
86 | unsigned long avg[NR_PSI_STATES - 1][3]; | |
87 | }; | |
88 | ||
89 | #else /* CONFIG_PSI */ | |
90 | ||
91 | struct psi_group { }; | |
92 | ||
93 | #endif /* CONFIG_PSI */ | |
94 | ||
95 | #endif /* _LINUX_PSI_TYPES_H */ |