From c7eca430066d82d2230a7bcec2bc4d8e244979d2 Mon Sep 17 00:00:00 2001 From: Divyanand Rangu Date: Mon, 28 Oct 2024 15:36:17 +0530 Subject: [PATCH] lmkd: fix higher event being reset by lower and polling start When both Medium and Critical events occur at same time, depending on how the events are queued, the later event resets the former event. We'd want the subsequent polling (till next event is triggered) to happen with higher event. So, it is fine if Critical event overrides Medium, but not other way around. Let's see below scenario where both Medium and Critical events occur (at T0) and handled one after other T0: critical event handled. T0 + 2ms: medium event handled. T0 + 102ms: medium event polling check. //This should be critical poll Bug: 376003899 Change-Id: I16ff3b999d7531435324a628ac17968fd4cae8cf --- lmkd.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lmkd.cpp b/lmkd.cpp index ae982dc..f5e7a74 100644 --- a/lmkd.cpp +++ b/lmkd.cpp @@ -211,6 +211,7 @@ static int mpevfd[VMPRESS_LEVEL_COUNT] = { -1, -1, -1 }; static bool pidfd_supported; static int last_kill_pid_or_fd = -1; static struct timespec last_kill_tm; +enum vmpressure_level prev_level = VMPRESS_LEVEL_LOW; static bool monitors_initialized; static bool boot_completed_handled = false; @@ -2731,6 +2732,20 @@ static void mp_event_psi(int data, uint32_t events, struct polling_params *poll_ return; } + if (events > 0 ) { + /* Ignore a lower event within the first polling window. */ + if (level < prev_level) { + if (debug_process_killing) + ALOGI("Ignoring %s pressure event; occurred too soon.", + level_name[level]); + return; + } + prev_level = level; + } else { + /* Reset event level after the first polling window. */ + prev_level = VMPRESS_LEVEL_LOW; + } + record_wakeup_time(&curr_tm, events ? Event : Polling, &wi); bool kill_pending = is_kill_pending();