From dad4749731b6796e34fa239739caf0a4e643889f Mon Sep 17 00:00:00 2001 From: Suren Baghdasaryan Date: Mon, 14 Jan 2019 16:57:55 -0800 Subject: [PATCH 1/3] Add libprocessgroup into VNDK Include libprocessgroup into vndk in preparation for sched_policy functions to be moved into it. Bug: 111307099 Test: builds, boots Merged-In: I09a528cac8821df3201c2428b151fd2eaece3ccb Change-Id: I09a528cac8821df3201c2428b151fd2eaece3ccb Signed-off-by: Suren Baghdasaryan --- libprocessgroup/Android.bp | 3 +++ libprocessgroup/processgroup.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libprocessgroup/Android.bp b/libprocessgroup/Android.bp index c38279df4..05397292c 100644 --- a/libprocessgroup/Android.bp +++ b/libprocessgroup/Android.bp @@ -3,7 +3,10 @@ cc_library { name: "libprocessgroup", host_supported: true, recovery_available: true, + vendor_available: true, shared_libs: ["libbase"], + // for cutils/android_filesystem_config.h + header_libs: [ "libcutils_headers" ], export_include_dirs: ["include"], cflags: [ "-Wall", diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp index 9df8dd96f..8d2ac3d57 100644 --- a/libprocessgroup/processgroup.cpp +++ b/libprocessgroup/processgroup.cpp @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include From facd40d0e1dc681f7a483810cc1e72448f270cf6 Mon Sep 17 00:00:00 2001 From: Suren Baghdasaryan Date: Fri, 21 Dec 2018 11:34:23 -0800 Subject: [PATCH 2/3] libcutils: Move sched_policy functions into libprocessgroup Move functions operating on cgroups from sched_policy.h in libcutils into sched_policy_ctrl.h under libprocessgroup. This consolidates cgroup-related functionality inside libprocessgroup. Bug: 111307099 Test: builds, boots Merged-In: Iba75f33281162b889989214d0325a5973d53ed2d Change-Id: Iba75f33281162b889989214d0325a5973d53ed2d Signed-off-by: Suren Baghdasaryan --- libcutils/Android.bp | 7 +- libcutils/include/cutils/sched_policy.h | 63 +-------------- libcutils/tests/Android.bp | 1 + libprocessgroup/Android.bp | 33 +++++++- .../include/processgroup/sched_policy.h | 80 +++++++++++++++++++ .../sched_policy.cpp | 2 +- 6 files changed, 121 insertions(+), 65 deletions(-) create mode 100644 libprocessgroup/include/processgroup/sched_policy.h rename {libcutils => libprocessgroup}/sched_policy.cpp (99%) diff --git a/libcutils/Android.bp b/libcutils/Android.bp index 4291212a1..0dbbc3f2f 100644 --- a/libcutils/Android.bp +++ b/libcutils/Android.bp @@ -66,7 +66,6 @@ cc_library { "load_file.cpp", "native_handle.cpp", "record_stream.cpp", - "sched_policy.cpp", "sockets.cpp", "strdup16to8.cpp", "strdup8to16.cpp", @@ -178,8 +177,12 @@ cc_library { "libbase_headers", "libcutils_headers", "libutils_headers", + "libprocessgroup_headers", + ], + export_header_lib_headers: [ + "libcutils_headers", + "libprocessgroup_headers", ], - export_header_lib_headers: ["libcutils_headers"], local_include_dirs: ["include"], cflags: [ diff --git a/libcutils/include/cutils/sched_policy.h b/libcutils/include/cutils/sched_policy.h index cf91b76f4..538ff6b9b 100644 --- a/libcutils/include/cutils/sched_policy.h +++ b/libcutils/include/cutils/sched_policy.h @@ -17,67 +17,10 @@ #ifndef __CUTILS_SCHED_POLICY_H #define __CUTILS_SCHED_POLICY_H -#include - -#ifdef __cplusplus -extern "C" { -#endif - /* - * Check if Linux kernel enables CPUSETS feature. - * - * Return value: 1 if Linux kernel CONFIG_CPUSETS=y; 0 otherwise. + * For backwards compatibility only + * New users should include processgroup/sched_policy.h directly */ -extern bool cpusets_enabled(); - -/* - * Check if Linux kernel enables SCHEDTUNE feature (only available in Android - * common kernel or Linaro LSK, not in mainline Linux as of v4.9) - * - * Return value: 1 if Linux kernel CONFIG_CGROUP_SCHEDTUNE=y; 0 otherwise. - */ -extern bool schedboost_enabled(); - -/* Keep in sync with THREAD_GROUP_* in frameworks/base/core/java/android/os/Process.java */ -typedef enum { - SP_DEFAULT = -1, - SP_BACKGROUND = 0, - SP_FOREGROUND = 1, - SP_SYSTEM = 2, // can't be used with set_sched_policy() - SP_AUDIO_APP = 3, - SP_AUDIO_SYS = 4, - SP_TOP_APP = 5, - SP_RT_APP = 6, - SP_RESTRICTED = 7, - SP_CNT, - SP_MAX = SP_CNT - 1, - SP_SYSTEM_DEFAULT = SP_FOREGROUND, -} SchedPolicy; - -extern int set_cpuset_policy(int tid, SchedPolicy policy); - -/* Assign thread tid to the cgroup associated with the specified policy. - * If the thread is a thread group leader, that is it's gettid() == getpid(), - * then the other threads in the same thread group are _not_ affected. - * On platforms which support gettid(), zero tid means current thread. - * Return value: 0 for success, or -errno for error. - */ -extern int set_sched_policy(int tid, SchedPolicy policy); - -/* Return the policy associated with the cgroup of thread tid via policy pointer. - * On platforms which support gettid(), zero tid means current thread. - * Return value: 0 for success, or -1 for error and set errno. - */ -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; - * the caller is responsible for displaying the useful part of the string. - */ -extern const char *get_sched_policy_name(SchedPolicy policy); - -#ifdef __cplusplus -} -#endif +#include #endif /* __CUTILS_SCHED_POLICY_H */ diff --git a/libcutils/tests/Android.bp b/libcutils/tests/Android.bp index 788419038..72ae55921 100644 --- a/libcutils/tests/Android.bp +++ b/libcutils/tests/Android.bp @@ -59,6 +59,7 @@ test_libraries = [ "libcutils", "liblog", "libbase", + "libprocessgroup", ] cc_test { diff --git a/libprocessgroup/Android.bp b/libprocessgroup/Android.bp index 05397292c..21d453ef6 100644 --- a/libprocessgroup/Android.bp +++ b/libprocessgroup/Android.bp @@ -1,13 +1,42 @@ +cc_library_headers { + name: "libprocessgroup_headers", + vendor_available: true, + recovery_available: true, + host_supported: true, + export_include_dirs: ["include"], + target: { + linux_bionic: { + enabled: true, + }, + windows: { + enabled: true, + }, + }, +} + cc_library { - srcs: ["processgroup.cpp"], + srcs: [ + "processgroup.cpp", + "sched_policy.cpp", + ], name: "libprocessgroup", host_supported: true, recovery_available: true, vendor_available: true, + vndk: { + enabled: true, + support_system_process: true, + }, shared_libs: ["libbase"], // for cutils/android_filesystem_config.h - header_libs: [ "libcutils_headers" ], + header_libs: [ + "libcutils_headers", + "libprocessgroup_headers", + ], export_include_dirs: ["include"], + export_header_lib_headers: [ + "libprocessgroup_headers", + ], cflags: [ "-Wall", "-Werror", diff --git a/libprocessgroup/include/processgroup/sched_policy.h b/libprocessgroup/include/processgroup/sched_policy.h new file mode 100644 index 000000000..79a32fdeb --- /dev/null +++ b/libprocessgroup/include/processgroup/sched_policy.h @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Check if Linux kernel enables CPUSETS feature. + * + * Return value: 1 if Linux kernel CONFIG_CPUSETS=y; 0 otherwise. + */ +extern bool cpusets_enabled(); + +/* + * Check if Linux kernel enables SCHEDTUNE feature (only available in Android + * common kernel or Linaro LSK, not in mainline Linux as of v4.9) + * + * Return value: 1 if Linux kernel CONFIG_CGROUP_SCHEDTUNE=y; 0 otherwise. + */ +extern bool schedboost_enabled(); + +/* Keep in sync with THREAD_GROUP_* in frameworks/base/core/java/android/os/Process.java */ +typedef enum { + SP_DEFAULT = -1, + SP_BACKGROUND = 0, + SP_FOREGROUND = 1, + SP_SYSTEM = 2, // can't be used with set_sched_policy() + SP_AUDIO_APP = 3, + SP_AUDIO_SYS = 4, + SP_TOP_APP = 5, + SP_RT_APP = 6, + SP_RESTRICTED = 7, + SP_CNT, + SP_MAX = SP_CNT - 1, + SP_SYSTEM_DEFAULT = SP_FOREGROUND, +} SchedPolicy; + +extern int set_cpuset_policy(int tid, SchedPolicy policy); + +/* Assign thread tid to the cgroup associated with the specified policy. + * If the thread is a thread group leader, that is it's gettid() == getpid(), + * then the other threads in the same thread group are _not_ affected. + * On platforms which support gettid(), zero tid means current thread. + * Return value: 0 for success, or -errno for error. + */ +extern int set_sched_policy(int tid, SchedPolicy policy); + +/* Return the policy associated with the cgroup of thread tid via policy pointer. + * On platforms which support gettid(), zero tid means current thread. + * Return value: 0 for success, or -1 for error and set errno. + */ +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; + * the caller is responsible for displaying the useful part of the string. + */ +extern const char *get_sched_policy_name(SchedPolicy policy); + +#ifdef __cplusplus +} +#endif diff --git a/libcutils/sched_policy.cpp b/libprocessgroup/sched_policy.cpp similarity index 99% rename from libcutils/sched_policy.cpp rename to libprocessgroup/sched_policy.cpp index 3fa548f78..f95d7e48f 100644 --- a/libcutils/sched_policy.cpp +++ b/libprocessgroup/sched_policy.cpp @@ -14,7 +14,7 @@ ** limitations under the License. */ -#include +#include #define LOG_TAG "SchedPolicy" From 02843339f998f05c712549658c9f8f8bc14ff57d Mon Sep 17 00:00:00 2001 From: Suren Baghdasaryan Date: Fri, 21 Dec 2018 12:30:16 -0800 Subject: [PATCH 3/3] Add dependencies on libprocessgroup for sched_policy users After moving sched_policy functions into libprocessgroup its users require additional dependency and inclusion of sched_policy_ctrl.h header. Exempt-From-Owner-Approval: janitorial Bug: 111307099 Test: builds, boots Merged-In: Icc052080e1bce46ce06f7264446950cab0490a95 Change-Id: Icc052080e1bce46ce06f7264446950cab0490a95 Signed-off-by: Suren Baghdasaryan --- healthd/Android.mk | 1 + libprocessgroup/Android.bp | 5 ++++- libutils/Android.bp | 3 +++ libutils/Threads.cpp | 2 +- lmkd/Android.bp | 1 + logcat/Android.bp | 2 +- logcat/logcat.cpp | 2 +- logd/Android.bp | 1 + logd/main.cpp | 2 +- 9 files changed, 14 insertions(+), 5 deletions(-) diff --git a/healthd/Android.mk b/healthd/Android.mk index 80bf84ae8..2127b9603 100644 --- a/healthd/Android.mk +++ b/healthd/Android.mk @@ -109,6 +109,7 @@ CHARGER_STATIC_LIBRARIES := \ libbase \ libutils \ libcutils \ + libprocessgroup \ liblog \ libm \ libc \ diff --git a/libprocessgroup/Android.bp b/libprocessgroup/Android.bp index 21d453ef6..d04a79a66 100644 --- a/libprocessgroup/Android.bp +++ b/libprocessgroup/Android.bp @@ -27,7 +27,10 @@ cc_library { enabled: true, support_system_process: true, }, - shared_libs: ["libbase"], + shared_libs: [ + "libbase", + "liblog", + ], // for cutils/android_filesystem_config.h header_libs: [ "libcutils_headers", diff --git a/libutils/Android.bp b/libutils/Android.bp index 3e8417eb9..fb7ca3254 100644 --- a/libutils/Android.bp +++ b/libutils/Android.bp @@ -22,11 +22,13 @@ cc_library_headers { "liblog_headers", "libsystem_headers", "libcutils_headers", + "libprocessgroup_headers", ], export_header_lib_headers: [ "liblog_headers", "libsystem_headers", "libcutils_headers", + "libprocessgroup_headers", ], export_include_dirs: ["include"], @@ -82,6 +84,7 @@ cc_defaults { shared_libs: [ "libcutils", + "libprocessgroup", "libdl", "libvndksupport", ], diff --git a/libutils/Threads.cpp b/libutils/Threads.cpp index 64bc4025d..31ca1383e 100644 --- a/libutils/Threads.cpp +++ b/libutils/Threads.cpp @@ -36,7 +36,7 @@ #include -#include +#include #if defined(__ANDROID__) # define __android_unused diff --git a/lmkd/Android.bp b/lmkd/Android.bp index 903d0e243..f9ed57cce 100644 --- a/lmkd/Android.bp +++ b/lmkd/Android.bp @@ -5,6 +5,7 @@ cc_binary { shared_libs: [ "libcutils", "liblog", + "libprocessgroup", ], static_libs: [ "libstatslogc", diff --git a/logcat/Android.bp b/logcat/Android.bp index 0543aba73..5030b1563 100644 --- a/logcat/Android.bp +++ b/logcat/Android.bp @@ -24,8 +24,8 @@ cc_defaults { ], shared_libs: [ "libbase", - "libcutils", "libpcrecpp", + "libprocessgroup", ], static_libs: ["liblog"], logtags: ["event.logtags"], diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp index 87bc6ae84..15e07feef 100644 --- a/logcat/logcat.cpp +++ b/logcat/logcat.cpp @@ -49,11 +49,11 @@ #include #include #include -#include #include #include #include #include +#include #include #include diff --git a/logd/Android.bp b/logd/Android.bp index 3abfc2171..bdbdf12e4 100644 --- a/logd/Android.bp +++ b/logd/Android.bp @@ -73,6 +73,7 @@ cc_binary { "libcutils", "libbase", "libpackagelistparser", + "libprocessgroup", "libcap", ], diff --git a/logd/main.cpp b/logd/main.cpp index 8c38d9aa3..fd3cdf877 100644 --- a/logd/main.cpp +++ b/logd/main.cpp @@ -38,12 +38,12 @@ #include #include #include -#include #include #include #include #include #include +#include #include #include "CommandListener.h"