| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | /* pressure.h -- Linux Pressure Stall Information (PSI) parser |
| 3 | |
| 4 | This program is free software: you can redistribute it and/or modify |
| 5 | it under the terms of the GNU General Public License as published by |
| 6 | the Free Software Foundation; either version 3 of the License, or |
| 7 | (at your option) any later version. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License |
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 16 | |
| 17 | #ifndef _PRESSURE_H_ |
| 18 | #define _PRESSURE_H_ |
| 19 | |
| 20 | #ifdef __cplusplus |
| 21 | extern "C" |
| 22 | { |
| 23 | #endif |
| 24 | |
| 25 | #define PATH_PROC_PRESSURE "/proc/pressure" |
| 26 | #define PATH_PSI_PROC_CPU PATH_PROC_PRESSURE "/cpu" |
| 27 | #define PATH_PSI_PROC_IO PATH_PROC_PRESSURE "/io" |
| 28 | #define PATH_PSI_PROC_MEMORY PATH_PROC_PRESSURE "/memory" |
| 29 | |
| 30 | enum linux_psi_id /* Linux PSI modes */ |
| 31 | { |
| 32 | LINUX_PSI_NONE = 0, |
| 33 | LINUX_PSI_CPU, |
| 34 | LINUX_PSI_IO, |
| 35 | LINUX_PSI_MEMORY |
| 36 | }; |
| 37 | |
| 38 | /* Structure for pressure-stall cpu statistics. |
| 39 | * - avg* fields: percentage of time in the last 10, 60 and 300 seconds |
| 40 | * respectively that processes were starved of CPU, |
| 41 | * - total: total time in microseconds that processes were starved of CPU. |
| 42 | */ |
| 43 | struct proc_psi_oneline |
| 44 | { |
| 45 | unsigned long long total; |
| 46 | double avg10; |
| 47 | double avg60; |
| 48 | double avg300; |
| 49 | }; |
| 50 | |
| 51 | /* Structure for pressure-stall io and memory statistics |
| 52 | * |
| 53 | * For memory, large numbers in 'full' means no runnable/non-idle process |
| 54 | * was able to run and the CPU was busy doing housekeeping work related |
| 55 | * to paging. Even small numbers clearly indicate workloads that are |
| 56 | * being starved of RAM. So, while the numbers in 'some' indicate that |
| 57 | * while the system is strained of resources and some runnable processes |
| 58 | * are starved, it does mean that other processes continue to run and |
| 59 | * real work is getting done. |
| 60 | */ |
| 61 | struct proc_psi_twolines |
| 62 | { |
| 63 | unsigned long long some_total; |
| 64 | unsigned long long full_total; |
| 65 | double some_avg10; |
| 66 | double some_avg60; |
| 67 | double some_avg300; |
| 68 | double full_avg10; |
| 69 | double full_avg60; |
| 70 | double full_avg300; |
| 71 | }; |
| 72 | |
| 73 | int proc_psi_read_cpu (struct proc_psi_oneline **psi_cpu, |
| 74 | unsigned long long *starvation, unsigned long delay); |
| 75 | int proc_psi_read_io (struct proc_psi_twolines **psi_io, |
| 76 | unsigned long long *starvation, unsigned long delay); |
| 77 | int proc_psi_read_memory (struct proc_psi_twolines **psi_memory, |
| 78 | unsigned long long *starvation, |
| 79 | unsigned long delay); |
| 80 | |
| 81 | #ifdef __cplusplus |
| 82 | } |
| 83 | #endif |
| 84 | |
| 85 | #endif /* pressure.h */ |