From eca87cb9ca18e7aa82ab240c3161d562152262af Mon Sep 17 00:00:00 2001 From: Suren Baghdasaryan Date: Sat, 2 Feb 2019 14:19:41 -0800 Subject: [PATCH] Fix non-Android build targets Non-Android build targets are missing sys/prctl.h header and functionality should be disabled for them like it was done previously inside sched_policy.cpp. Also make the set_sched_policy/get_sched_policy functionality backward compatible by creating stubs for non-Android targets. Bug: 111307099 Test: built sdk_gphone_x86-sdk_addon_mac target using forrest Change-Id: I1c195267e287a84a21c588bd61d7c452bff6cfbe Merged-In: I1c195267e287a84a21c588bd61d7c452bff6cfbe Signed-off-by: Suren Baghdasaryan --- libprocessgroup/sched_policy.cpp | 17 +++++++++++++++++ libprocessgroup/task_profiles.cpp | 11 ++++++++++- libprocessgroup/task_profiles.h | 14 ++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/libprocessgroup/sched_policy.cpp b/libprocessgroup/sched_policy.cpp index 4c8aa6dd7..337b032f2 100644 --- a/libprocessgroup/sched_policy.cpp +++ b/libprocessgroup/sched_policy.cpp @@ -36,6 +36,8 @@ static inline SchedPolicy _policy(SchedPolicy p) { return p == SP_DEFAULT ? SP_SYSTEM_DEFAULT : p; } +#if defined(__ANDROID__) + int set_cpuset_policy(int tid, SchedPolicy policy) { if (tid == 0) { tid = GetThreadId(); @@ -195,6 +197,21 @@ int get_sched_policy(int tid, SchedPolicy* policy) { return 0; } +#else + +/* Stubs for non-Android targets. */ + +int set_sched_policy(int, SchedPolicy) { + return 0; +} + +int get_sched_policy(int, SchedPolicy* policy) { + *policy = SP_SYSTEM_DEFAULT; + return 0; +} + +#endif + const char* get_sched_policy_name(SchedPolicy policy) { policy = _policy(policy); static const char* const kSchedPolicyNames[] = { diff --git a/libprocessgroup/task_profiles.cpp b/libprocessgroup/task_profiles.cpp index eb50f8539..ec6cbbc45 100644 --- a/libprocessgroup/task_profiles.cpp +++ b/libprocessgroup/task_profiles.cpp @@ -18,7 +18,6 @@ #define LOG_TAG "libprocessgroup" #include -#include #include #include @@ -32,6 +31,11 @@ #include #include +// To avoid issues in sdk_mac build +#if defined(__ANDROID__) +#include +#endif + using android::base::GetThreadId; using android::base::StringPrintf; using android::base::unique_fd; @@ -69,6 +73,9 @@ bool SetClampsAction::ExecuteForTask(int) const { return false; } +// To avoid issues in sdk_mac build +#if defined(__ANDROID__) + bool SetTimerSlackAction::IsTimerSlackSupported(int tid) { auto file = StringPrintf("/proc/%d/timerslack_ns", tid); @@ -97,6 +104,8 @@ bool SetTimerSlackAction::ExecuteForTask(int tid) const { return true; } +#endif + bool SetAttributeAction::ExecuteForProcess(uid_t, pid_t pid) const { return ExecuteForTask(pid); } diff --git a/libprocessgroup/task_profiles.h b/libprocessgroup/task_profiles.h index 684762aa1..886ead141 100644 --- a/libprocessgroup/task_profiles.h +++ b/libprocessgroup/task_profiles.h @@ -63,6 +63,9 @@ class SetClampsAction : public ProfileAction { int clamp_; }; +// To avoid issues in sdk_mac build +#if defined(__ANDROID__) + class SetTimerSlackAction : public ProfileAction { public: SetTimerSlackAction(unsigned long slack) noexcept : slack_(slack) {} @@ -75,6 +78,17 @@ class SetTimerSlackAction : public ProfileAction { static bool IsTimerSlackSupported(int tid); }; +#else + +class SetTimerSlackAction : public ProfileAction { + public: + SetTimerSlackAction(unsigned long) noexcept {} + + virtual bool ExecuteForTask(int) const { return true; } +}; + +#endif + // Set attribute profile element class SetAttributeAction : public ProfileAction { public: