Update init_psi_monitor to include MEMORY/IO/CPU resources. am: d872253483 am: 1868632e37

Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/3050182

Change-Id: I77c41a13aa8a22c445ea8499d4ed20bb6a9a8a0d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Lakshman Annadorai 2024-04-30 19:20:03 +00:00 committed by Automerger Merge Worker
commit c4d3f30a83
3 changed files with 28 additions and 19 deletions

View File

@ -22,9 +22,7 @@
__BEGIN_DECLS __BEGIN_DECLS
#define PSI_PATH_MEMORY "/proc/pressure/memory" enum psi_resource { PSI_MEMORY, PSI_IO, PSI_CPU, PSI_RESOURCE_COUNT };
#define PSI_PATH_IO "/proc/pressure/io"
#define PSI_PATH_CPU "/proc/pressure/cpu"
enum psi_stall_type { enum psi_stall_type {
PSI_SOME, PSI_SOME,
@ -45,16 +43,22 @@ struct psi_data {
struct psi_stats cpu_stats[PSI_TYPE_COUNT]; struct psi_stats cpu_stats[PSI_TYPE_COUNT];
}; };
static const char* psi_resource_file[PSI_RESOURCE_COUNT] = {
"/proc/pressure/memory",
"/proc/pressure/io",
"/proc/pressure/cpu",
};
/* /*
* Initializes psi monitor. * Initializes psi monitor for the given psi resource type.
* stall_type, threshold_us and window_us are monitor parameters * stall_type, threshold_us and window_us are monitor parameters
* When successful, the function returns file descriptor that can * When successful, the function returns file descriptor that can
* be used with poll/epoll syscalls to wait for EPOLLPRI events. * be used with poll/epoll syscalls to wait for EPOLLPRI events.
* When unsuccessful, the function returns -1 and errno is set * When unsuccessful, the function returns -1 and errno is set
* appropriately. * appropriately.
*/ */
int init_psi_monitor(enum psi_stall_type stall_type, int init_psi_monitor(enum psi_stall_type stall_type, int threshold_us, int window_us,
int threshold_us, int window_us); enum psi_resource resource = PSI_MEMORY);
/* /*
* Registers psi monitor file descriptor fd on the epoll instance * Registers psi monitor file descriptor fd on the epoll instance

View File

@ -33,13 +33,18 @@ static const char* stall_type_name[] = {
"full", "full",
}; };
int init_psi_monitor(enum psi_stall_type stall_type, int init_psi_monitor(enum psi_stall_type stall_type, int threshold_us, int window_us,
int threshold_us, int window_us) { enum psi_resource resource) {
if (resource < PSI_MEMORY || resource >= PSI_RESOURCE_COUNT) {
ALOGE("Invalid psi resource type: %d", resource);
errno = EINVAL;
return -1;
}
int fd; int fd;
int res; int res;
char buf[256]; char buf[256];
fd = TEMP_FAILURE_RETRY(open(PSI_PATH_MEMORY, O_WRONLY | O_CLOEXEC)); fd = TEMP_FAILURE_RETRY(open(psi_resource_file[resource], O_WRONLY | O_CLOEXEC));
if (fd < 0) { if (fd < 0) {
ALOGE("No kernel psi monitor support (errno=%d)", errno); ALOGE("No kernel psi monitor support (errno=%d)", errno);
return -1; return -1;
@ -58,16 +63,16 @@ int init_psi_monitor(enum psi_stall_type stall_type,
} }
if (res >= (ssize_t)sizeof(buf)) { if (res >= (ssize_t)sizeof(buf)) {
ALOGE("%s line overflow for psi stall type '%s'", ALOGE("%s line overflow for psi stall type '%s'", psi_resource_file[resource],
PSI_PATH_MEMORY, stall_type_name[stall_type]); stall_type_name[stall_type]);
errno = EINVAL; errno = EINVAL;
goto err; goto err;
} }
res = TEMP_FAILURE_RETRY(write(fd, buf, strlen(buf) + 1)); res = TEMP_FAILURE_RETRY(write(fd, buf, strlen(buf) + 1));
if (res < 0) { if (res < 0) {
ALOGE("%s write failed for psi stall type '%s'; errno=%d", ALOGE("%s write failed for psi stall type '%s'; errno=%d", psi_resource_file[resource],
PSI_PATH_MEMORY, stall_type_name[stall_type], errno); stall_type_name[stall_type], errno);
goto err; goto err;
} }

View File

@ -2035,24 +2035,24 @@ static int psi_parse(struct reread_data *file_data, struct psi_stats stats[], bo
static int psi_parse_mem(struct psi_data *psi_data) { static int psi_parse_mem(struct psi_data *psi_data) {
static struct reread_data file_data = { static struct reread_data file_data = {
.filename = PSI_PATH_MEMORY, .filename = psi_resource_file[PSI_MEMORY],
.fd = -1, .fd = -1,
}; };
return psi_parse(&file_data, psi_data->mem_stats, true); return psi_parse(&file_data, psi_data->mem_stats, true);
} }
static int psi_parse_io(struct psi_data *psi_data) { static int psi_parse_io(struct psi_data *psi_data) {
static struct reread_data file_data = { static struct reread_data file_data = {
.filename = PSI_PATH_IO, .filename = psi_resource_file[PSI_IO],
.fd = -1, .fd = -1,
}; };
return psi_parse(&file_data, psi_data->io_stats, true); return psi_parse(&file_data, psi_data->io_stats, true);
} }
static int psi_parse_cpu(struct psi_data *psi_data) { static int psi_parse_cpu(struct psi_data *psi_data) {
static struct reread_data file_data = { static struct reread_data file_data = {
.filename = PSI_PATH_CPU, .filename = psi_resource_file[PSI_CPU],
.fd = -1, .fd = -1,
}; };
return psi_parse(&file_data, psi_data->cpu_stats, false); return psi_parse(&file_data, psi_data->cpu_stats, false);
} }