From 404843372eb2436e2c2fc6a54e9cf81f158eb751 Mon Sep 17 00:00:00 2001 From: liujialiang Date: Fri, 31 May 2024 15:46:02 +0800 Subject: [PATCH] [LLDB]Change the scheduling of gdbserver on ohos Description: The performance of gdbserver will be affected by kernel's general scheduling policy on ohos. This will make IDE time out sometimes, cause IDE give time limitation for every operation of lldb. For example, when debugging native in DevEco and use setvalue, it will show "Modifying value" probably. So we change the sched_utils_min to get more cpu supply. BTW, there is a conflict between musl's sched.h and linux/sched.h, so redefine needed defines and structs locally. This problem has been resolved on linux 6.10(https://github.com/torvalds/linux/commit/d844fe65f0957024c3e1b0bf2a0615246184d9bc). Issue:https://gitee.com/openharmony/third_party_llvm-project/issues/IA533S Test: We test ide base debug options one thousand times with auto testsuits. No "time out" failed. Signed-off-by: liujialiang Change-Id: I3f75d2897f54572319e5802e0befb7cfda060329 --- lldb/tools/lldb-server/lldb-gdbserver.cpp | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/lldb/tools/lldb-server/lldb-gdbserver.cpp b/lldb/tools/lldb-server/lldb-gdbserver.cpp index eca66cfc4967..8b4d43198f9a 100644 --- a/lldb/tools/lldb-server/lldb-gdbserver.cpp +++ b/lldb/tools/lldb-server/lldb-gdbserver.cpp @@ -17,6 +17,10 @@ #include #endif +#if defined(__OHOS_FAMILY__) +#include +#endif + #include "LLDBServerUtilities.h" #include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h" #include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h" @@ -319,7 +323,49 @@ DESCRIPTION }; } // namespace +#if defined(__OHOS_FAMILY__) +#ifndef SCHED_FLAG_UTIL_CLAMP_MIN +#define SCHED_FLAG_UTIL_CLAMP_MIN 0x20 +#endif +struct sched_attr { + __u32 size; + __u32 sched_policy; + __u64 sched_flags; + __s32 sched_nice; + __u32 sched_priority; + __u64 sched_runtime; + __u64 sched_deadline; + __u64 sched_period; + __u32 sched_util_min; + __u32 sched_util_max; +}; + +static int +sched_setattr(lldb::pid_t pid, const struct sched_attr *attr, unsigned int flags) { + return syscall(__NR_sched_setattr, pid, attr, flags); +} + +static int +sched_getattr(lldb::pid_t pid, const struct sched_attr *attr, unsigned int size, unsigned int flags) { + return syscall(__NR_sched_getattr, pid, attr, size, flags); +} +#endif + int main_gdbserver(int argc, char *argv[]) { +#if defined(__OHOS_FAMILY__) + struct sched_attr attr; + int schret = sched_getattr(0, &attr, sizeof(sched_attr), 0); + if (schret != 0) { + llvm::errs() << llvm::format("lldb-server get sched failed: {0}\n", errno); + } else { + attr.sched_flags = SCHED_FLAG_UTIL_CLAMP_MIN; + attr.sched_util_min = 512; // [0, 1024]. The higher, the more cpu supply. + schret = sched_setattr(0, &attr, 0); + if (schret != 0) { + llvm::errs() << llvm::format("lldb-server set sched failed: {0}\n", errno); + } + } +#endif Status error; MainLoop mainloop; #ifndef _WIN32 -- Gitee