Loading libcutils/sched_policy_test.cpp +14 −2 Original line number Diff line number Diff line Loading @@ -107,6 +107,18 @@ TEST(SchedPolicy, set_sched_policy_timerslack) { TEST(SchedPolicy, get_sched_policy_name) { EXPECT_STREQ("bg", get_sched_policy_name(SP_BACKGROUND)); EXPECT_STREQ("error", get_sched_policy_name(SchedPolicy(-2))); EXPECT_STREQ("error", get_sched_policy_name(SP_CNT)); EXPECT_EQ(nullptr, get_sched_policy_name(SchedPolicy(-2))); EXPECT_EQ(nullptr, get_sched_policy_name(SP_CNT)); } TEST(SchedPolicy, get_cpuset_policy_profile_name) { EXPECT_STREQ("CPUSET_SP_BACKGROUND", get_cpuset_policy_profile_name(SP_BACKGROUND)); EXPECT_EQ(nullptr, get_cpuset_policy_profile_name(SchedPolicy(-2))); EXPECT_EQ(nullptr, get_cpuset_policy_profile_name(SP_CNT)); } TEST(SchedPolicy, get_sched_policy_profile_name) { EXPECT_STREQ("SCHED_SP_BACKGROUND", get_sched_policy_profile_name(SP_BACKGROUND)); EXPECT_EQ(nullptr, get_sched_policy_profile_name(SchedPolicy(-2))); EXPECT_EQ(nullptr, get_sched_policy_profile_name(SP_CNT)); } libprocessgroup/include/processgroup/sched_policy.h +12 −1 Original line number Diff line number Diff line Loading @@ -70,11 +70,22 @@ extern int set_sched_policy(int tid, SchedPolicy policy); extern int get_sched_policy(int tid, SchedPolicy* policy); /* Return a displayable string corresponding to policy. * Return value: non-NULL NUL-terminated name of unspecified length; * Return value: NUL-terminated name of unspecified length, nullptr if invalid; * the caller is responsible for displaying the useful part of the string. */ extern const char* get_sched_policy_name(SchedPolicy policy); /* Return the aggregated task profile name corresponding to cpuset policy. * Return value: NUL-terminated name of unspecified length, nullptr if invalid; * the caller could use it to call SetTaskProfiles. */ extern const char* get_cpuset_policy_profile_name(SchedPolicy policy); /* Return the aggregated task profile name corresponding to sched policy. * Return value: NUL-terminated name of unspecified length, nullptr if invalid; * the caller could use it to call SetTaskProfiles. */ extern const char* get_sched_policy_profile_name(SchedPolicy policy); #ifdef __cplusplus } #endif libprocessgroup/sched_policy.cpp +39 −1 Original line number Diff line number Diff line Loading @@ -212,7 +212,45 @@ const char* get_sched_policy_name(SchedPolicy policy) { }; static_assert(arraysize(kSchedPolicyNames) == SP_CNT, "missing name"); if (policy < SP_BACKGROUND || policy >= SP_CNT) { return "error"; return nullptr; } return kSchedPolicyNames[policy]; } const char* get_cpuset_policy_profile_name(SchedPolicy policy) { /* * cpuset profile array for: * SP_DEFAULT(-1), SP_BACKGROUND(0), SP_FOREGROUND(1), * SP_SYSTEM(2), SP_AUDIO_APP(3), SP_AUDIO_SYS(4), * SP_TOP_APP(5), SP_RT_APP(6), SP_RESTRICTED(7) * index is policy + 1 * this need keep in sync with SchedPolicy enum */ static constexpr const char* kCpusetProfiles[SP_CNT + 1] = { "CPUSET_SP_DEFAULT", "CPUSET_SP_BACKGROUND", "CPUSET_SP_FOREGROUND", "CPUSET_SP_SYSTEM", "CPUSET_SP_FOREGROUND", "CPUSET_SP_FOREGROUND", "CPUSET_SP_TOP_APP", "CPUSET_SP_DEFAULT", "CPUSET_SP_RESTRICTED"}; if (policy < SP_DEFAULT || policy >= SP_CNT) { return nullptr; } return kCpusetProfiles[policy + 1]; } const char* get_sched_policy_profile_name(SchedPolicy policy) { /* * sched profile array for: * SP_DEFAULT(-1), SP_BACKGROUND(0), SP_FOREGROUND(1), * SP_SYSTEM(2), SP_AUDIO_APP(3), SP_AUDIO_SYS(4), * SP_TOP_APP(5), SP_RT_APP(6), SP_RESTRICTED(7) * index is policy + 1 * this need keep in sync with SchedPolicy enum */ static constexpr const char* kSchedProfiles[SP_CNT + 1] = { "SCHED_SP_DEFAULT", "SCHED_SP_BACKGROUND", "SCHED_SP_FOREGROUND", "SCHED_SP_DEFAULT", "SCHED_SP_FOREGROUND", "SCHED_SP_FOREGROUND", "SCHED_SP_TOP_APP", "SCHED_SP_RT_APP", "SCHED_SP_DEFAULT"}; if (policy < SP_DEFAULT || policy >= SP_CNT) { return nullptr; } return kSchedProfiles[policy + 1]; } Loading
libcutils/sched_policy_test.cpp +14 −2 Original line number Diff line number Diff line Loading @@ -107,6 +107,18 @@ TEST(SchedPolicy, set_sched_policy_timerslack) { TEST(SchedPolicy, get_sched_policy_name) { EXPECT_STREQ("bg", get_sched_policy_name(SP_BACKGROUND)); EXPECT_STREQ("error", get_sched_policy_name(SchedPolicy(-2))); EXPECT_STREQ("error", get_sched_policy_name(SP_CNT)); EXPECT_EQ(nullptr, get_sched_policy_name(SchedPolicy(-2))); EXPECT_EQ(nullptr, get_sched_policy_name(SP_CNT)); } TEST(SchedPolicy, get_cpuset_policy_profile_name) { EXPECT_STREQ("CPUSET_SP_BACKGROUND", get_cpuset_policy_profile_name(SP_BACKGROUND)); EXPECT_EQ(nullptr, get_cpuset_policy_profile_name(SchedPolicy(-2))); EXPECT_EQ(nullptr, get_cpuset_policy_profile_name(SP_CNT)); } TEST(SchedPolicy, get_sched_policy_profile_name) { EXPECT_STREQ("SCHED_SP_BACKGROUND", get_sched_policy_profile_name(SP_BACKGROUND)); EXPECT_EQ(nullptr, get_sched_policy_profile_name(SchedPolicy(-2))); EXPECT_EQ(nullptr, get_sched_policy_profile_name(SP_CNT)); }
libprocessgroup/include/processgroup/sched_policy.h +12 −1 Original line number Diff line number Diff line Loading @@ -70,11 +70,22 @@ extern int set_sched_policy(int tid, SchedPolicy policy); extern int get_sched_policy(int tid, SchedPolicy* policy); /* Return a displayable string corresponding to policy. * Return value: non-NULL NUL-terminated name of unspecified length; * Return value: NUL-terminated name of unspecified length, nullptr if invalid; * the caller is responsible for displaying the useful part of the string. */ extern const char* get_sched_policy_name(SchedPolicy policy); /* Return the aggregated task profile name corresponding to cpuset policy. * Return value: NUL-terminated name of unspecified length, nullptr if invalid; * the caller could use it to call SetTaskProfiles. */ extern const char* get_cpuset_policy_profile_name(SchedPolicy policy); /* Return the aggregated task profile name corresponding to sched policy. * Return value: NUL-terminated name of unspecified length, nullptr if invalid; * the caller could use it to call SetTaskProfiles. */ extern const char* get_sched_policy_profile_name(SchedPolicy policy); #ifdef __cplusplus } #endif
libprocessgroup/sched_policy.cpp +39 −1 Original line number Diff line number Diff line Loading @@ -212,7 +212,45 @@ const char* get_sched_policy_name(SchedPolicy policy) { }; static_assert(arraysize(kSchedPolicyNames) == SP_CNT, "missing name"); if (policy < SP_BACKGROUND || policy >= SP_CNT) { return "error"; return nullptr; } return kSchedPolicyNames[policy]; } const char* get_cpuset_policy_profile_name(SchedPolicy policy) { /* * cpuset profile array for: * SP_DEFAULT(-1), SP_BACKGROUND(0), SP_FOREGROUND(1), * SP_SYSTEM(2), SP_AUDIO_APP(3), SP_AUDIO_SYS(4), * SP_TOP_APP(5), SP_RT_APP(6), SP_RESTRICTED(7) * index is policy + 1 * this need keep in sync with SchedPolicy enum */ static constexpr const char* kCpusetProfiles[SP_CNT + 1] = { "CPUSET_SP_DEFAULT", "CPUSET_SP_BACKGROUND", "CPUSET_SP_FOREGROUND", "CPUSET_SP_SYSTEM", "CPUSET_SP_FOREGROUND", "CPUSET_SP_FOREGROUND", "CPUSET_SP_TOP_APP", "CPUSET_SP_DEFAULT", "CPUSET_SP_RESTRICTED"}; if (policy < SP_DEFAULT || policy >= SP_CNT) { return nullptr; } return kCpusetProfiles[policy + 1]; } const char* get_sched_policy_profile_name(SchedPolicy policy) { /* * sched profile array for: * SP_DEFAULT(-1), SP_BACKGROUND(0), SP_FOREGROUND(1), * SP_SYSTEM(2), SP_AUDIO_APP(3), SP_AUDIO_SYS(4), * SP_TOP_APP(5), SP_RT_APP(6), SP_RESTRICTED(7) * index is policy + 1 * this need keep in sync with SchedPolicy enum */ static constexpr const char* kSchedProfiles[SP_CNT + 1] = { "SCHED_SP_DEFAULT", "SCHED_SP_BACKGROUND", "SCHED_SP_FOREGROUND", "SCHED_SP_DEFAULT", "SCHED_SP_FOREGROUND", "SCHED_SP_FOREGROUND", "SCHED_SP_TOP_APP", "SCHED_SP_RT_APP", "SCHED_SP_DEFAULT"}; if (policy < SP_DEFAULT || policy >= SP_CNT) { return nullptr; } return kSchedProfiles[policy + 1]; }