From 075008174220c3fcd28eb21b0215f3feb6678d35 Mon Sep 17 00:00:00 2001 From: "T.J. Mercier" Date: Wed, 9 Oct 2024 17:41:32 +0000 Subject: [PATCH] libprocessgroup: Remove prctl interface for setting timer slack Support for the procfs timerslack interface has existed since linux 4.6. All currently supported Android kernels are newer than 4.6, so remove the userspace support for the prctl interface leaving just the use of /proc//timerslack_ns. Bug: 372498744 Change-Id: Ib34cc6fbb4bab328cde51d60ac4e3b26a0d72851 --- libprocessgroup/task_profiles.cpp | 32 +++++++------------------------ libprocessgroup/task_profiles.h | 2 -- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/libprocessgroup/task_profiles.cpp b/libprocessgroup/task_profiles.cpp index 67ecc1d50..bdee9ae75 100644 --- a/libprocessgroup/task_profiles.cpp +++ b/libprocessgroup/task_profiles.cpp @@ -203,33 +203,15 @@ bool SetClampsAction::ExecuteForTask(int) const { // To avoid issues in sdk_mac build #if defined(__ANDROID__) -bool SetTimerSlackAction::IsTimerSlackSupported(pid_t tid) { - auto file = StringPrintf("/proc/%d/timerslack_ns", tid); - - return (access(file.c_str(), W_OK) == 0); -} - bool SetTimerSlackAction::ExecuteForTask(pid_t tid) const { - static bool sys_supports_timerslack = IsTimerSlackSupported(tid); - - // v4.6+ kernels support the /proc//timerslack_ns interface. - // TODO: once we've backported this, log if the open(2) fails. - if (sys_supports_timerslack) { - auto file = StringPrintf("/proc/%d/timerslack_ns", tid); - if (!WriteStringToFile(std::to_string(slack_), file)) { - if (errno == ENOENT) { - // This happens when process is already dead - return true; - } - PLOG(ERROR) << "set_timerslack_ns write failed"; - } - } - - // TODO: Remove when /proc//timerslack_ns interface is backported. - if (tid == 0 || tid == GetThreadId()) { - if (prctl(PR_SET_TIMERSLACK, slack_) == -1) { - PLOG(ERROR) << "set_timerslack_ns prctl failed"; + const auto file = StringPrintf("/proc/%d/timerslack_ns", tid); + if (!WriteStringToFile(std::to_string(slack_), file)) { + if (errno == ENOENT) { + // This happens when process is already dead + return true; } + PLOG(ERROR) << "set_timerslack_ns write failed"; + return false; } return true; diff --git a/libprocessgroup/task_profiles.h b/libprocessgroup/task_profiles.h index abb3ca5c3..2e31158d1 100644 --- a/libprocessgroup/task_profiles.h +++ b/libprocessgroup/task_profiles.h @@ -114,8 +114,6 @@ class SetTimerSlackAction : public ProfileAction { private: unsigned long slack_; - - static bool IsTimerSlackSupported(pid_t tid); }; // Set attribute profile element