| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "basic-forward.h" |
| 5 |
#include "parse-util.h" |
| 6 |
|
| 7 |
typedef enum PressureType { |
| 8 |
PRESSURE_TYPE_SOME, |
| 9 |
PRESSURE_TYPE_FULL, |
| 10 |
} PressureType; |
| 11 |
|
| 12 |
typedef enum PressureResource { |
| 13 |
PRESSURE_MEMORY, |
| 14 |
PRESSURE_CPU, |
| 15 |
PRESSURE_IO, |
| 16 |
_PRESSURE_RESOURCE_MAX, |
| 17 |
_PRESSURE_RESOURCE_INVALID = -EINVAL, |
| 18 |
} PressureResource; |
| 19 |
|
| 20 |
/* Averages are stored in fixed-point with 11 bit fractions */ |
| 21 |
typedef struct ResourcePressure { |
| 22 |
loadavg_t avg10; |
| 23 |
loadavg_t avg60; |
| 24 |
loadavg_t avg300; |
| 25 |
usec_t total; |
| 26 |
} ResourcePressure; |
| 27 |
|
| 28 |
/** Upstream 4.20+ format |
| 29 |
* |
| 30 |
* some avg10=0.22 avg60=0.17 avg300=1.11 total=58761459 |
| 31 |
* full avg10=0.23 avg60=0.16 avg300=1.08 total=58464525 |
| 32 |
*/ |
| 33 |
int read_resource_pressure(const char *path, PressureType type, ResourcePressure *ret); |
| 34 |
|
| 35 |
/* Was the kernel compiled with CONFIG_PSI=y? 1 if yes, 0 if not, negative on error. */ |
| 36 |
int is_pressure_supported(void); |
| 37 |
|
| 38 |
/* Metadata for each pressure resource type, for use in sd-event and PID 1 */ |
| 39 |
typedef struct PressureResourceInfo { |
| 40 |
const char *name; /* "memory", "cpu", "io" */ |
| 41 |
const char *env_watch; /* "MEMORY_PRESSURE_WATCH", etc. */ |
| 42 |
const char *env_write; /* "MEMORY_PRESSURE_WRITE", etc. */ |
| 43 |
} PressureResourceInfo; |
| 44 |
|
| 45 |
extern const PressureResourceInfo pressure_resource_info[_PRESSURE_RESOURCE_MAX]; |
| 46 |
|
| 47 |
static inline const PressureResourceInfo* pressure_resource_get_info(PressureResource resource) { |
| 48 |
assert(resource >= 0 && resource < _PRESSURE_RESOURCE_MAX); |
| 49 |
return &pressure_resource_info[resource]; |
| 50 |
} |
| 51 |
|
| 52 |
DECLARE_STRING_TABLE_LOOKUP(pressure_resource, PressureResource); |
| 53 |
|
| 54 |
/* Default parameters for pressure watch logic in sd-event and PID 1 */ |
| 55 |
#define PRESSURE_DEFAULT_TYPE "some" |
| 56 |
#define PRESSURE_DEFAULT_THRESHOLD_USEC (200 * USEC_PER_MSEC) |
| 57 |
#define PRESSURE_DEFAULT_WINDOW_USEC (2 * USEC_PER_SEC) |