From b1488adddac84bf03e2ec9ce9b97ca88baedc454 Mon Sep 17 00:00:00 2001 From: Chungkai Mei Date: Thu, 29 Jun 2023 04:17:39 +0000 Subject: [PATCH] boost uclamp_min for loading modules in parallel Unlike loading modules in serial, current parallel method cannot accumlate its utilization so usage of big cpu is really low in heterogeneous system, To make use of big core when we load kernel modules in parallel. we boost uclamp min for these parallel threads. Bug: 288847187 Test: redeuce about 6~10%(30-55ms) loading time for Pixel 7 Change-Id: I55e9ee4294f93b3039d519b5716fa55d58f3d625 Signed-off-by: Chungkai Mei --- libmodprobe/libmodprobe.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/libmodprobe/libmodprobe.cpp b/libmodprobe/libmodprobe.cpp index 858b9555f..64e70f7c5 100644 --- a/libmodprobe/libmodprobe.cpp +++ b/libmodprobe/libmodprobe.cpp @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include @@ -33,6 +35,19 @@ #include #include +struct sched_attr { + unsigned int size; + unsigned int sched_policy; + unsigned long long sched_flags; + int sched_nice; + unsigned int sched_priority; + unsigned long long sched_runtime; + unsigned long long sched_deadline; + unsigned long long sched_period; + unsigned int sched_util_min; + unsigned int sched_util_max; +}; + std::string Modprobe::MakeCanonical(const std::string& module_path) { auto start = module_path.find_last_of('/'); if (start == std::string::npos) { @@ -497,6 +512,17 @@ bool Modprobe::LoadModulesParallel(int num_threads) { // Load independent modules in parallel auto thread_function = [&] { +#if defined(__NR_sched_setattr) && defined(SCHED_FLAG_RESET_ON_FORK) + int pid = getpid(); + sched_attr attr = {}; + attr.size = sizeof(attr); + attr.sched_flags = + (SCHED_FLAG_RESET_ON_FORK | SCHED_FLAG_KEEP_ALL | SCHED_FLAG_UTIL_CLAMP_MIN); + attr.sched_util_min = 1024; + + syscall(__NR_sched_setattr, pid, attr, 0); +#endif + std::unique_lock lk(vector_lock); while (!mods_path_to_load.empty()) { auto ret_load = true;