From df67107ac4c2a73307597cb763d6c060e8844051 Mon Sep 17 00:00:00 2001 From: "T.J. Mercier" Date: Thu, 30 May 2024 00:18:30 +0000 Subject: [PATCH 1/3] libprocessgroup: Use default member initializers ... instead of direct initialization in the default constructor implementation. This allows us to just explicitly default the constructor and provide no implementation. Initialize class variables in the header and remove no-op constructor to simplify code. Bug: 346584259 Test: m Change-Id: Iba57f5cfbf8e4d5d18ce178d39f8bcd2d76c8aaa --- libprocessgroup/cgroup_map.h | 4 ++-- .../cgrouprc_format/cgroup_controller.cpp | 5 ----- .../include/processgroup/format/cgroup_controller.h | 12 ++++++------ 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/libprocessgroup/cgroup_map.h b/libprocessgroup/cgroup_map.h index 5c6d3e21c..9dd5bf5b1 100644 --- a/libprocessgroup/cgroup_map.h +++ b/libprocessgroup/cgroup_map.h @@ -32,7 +32,7 @@ class CgroupController { public: // Does not own controller explicit CgroupController(const ACgroupController* controller) - : controller_(controller), state_(UNKNOWN) {} + : controller_(controller) {} uint32_t version() const; const char* name() const; @@ -53,7 +53,7 @@ class CgroupController { }; const ACgroupController* controller_ = nullptr; - ControllerState state_; + ControllerState state_ = ControllerState::UNKNOWN; }; class CgroupMap { diff --git a/libprocessgroup/cgrouprc_format/cgroup_controller.cpp b/libprocessgroup/cgrouprc_format/cgroup_controller.cpp index 202b23eed..baf8f9da3 100644 --- a/libprocessgroup/cgrouprc_format/cgroup_controller.cpp +++ b/libprocessgroup/cgrouprc_format/cgroup_controller.cpp @@ -20,11 +20,6 @@ namespace android { namespace cgrouprc { namespace format { -CgroupController::CgroupController() : version_(0), flags_(0) { - memset(name_, 0, sizeof(name_)); - memset(path_, 0, sizeof(path_)); -} - CgroupController::CgroupController(uint32_t version, uint32_t flags, const std::string& name, const std::string& path) : CgroupController() { diff --git a/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_controller.h b/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_controller.h index 40d85480b..8d3aa5697 100644 --- a/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_controller.h +++ b/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_controller.h @@ -16,7 +16,7 @@ #pragma once -#include +#include #include namespace android { @@ -26,7 +26,7 @@ namespace format { // Minimal controller description to be mmapped into process address space struct CgroupController { public: - CgroupController(); + CgroupController() = default; CgroupController(uint32_t version, uint32_t flags, const std::string& name, const std::string& path); @@ -41,10 +41,10 @@ struct CgroupController { static constexpr size_t CGROUP_NAME_BUF_SZ = 16; static constexpr size_t CGROUP_PATH_BUF_SZ = 32; - uint32_t version_; - uint32_t flags_; - char name_[CGROUP_NAME_BUF_SZ]; - char path_[CGROUP_PATH_BUF_SZ]; + uint32_t version_ = 0; + uint32_t flags_ = 0; + char name_[CGROUP_NAME_BUF_SZ] = {}; + char path_[CGROUP_PATH_BUF_SZ] = {}; }; } // namespace format From 10826481bae21a4c5ddf7ee30f0719a72994ae6b Mon Sep 17 00:00:00 2001 From: "T.J. Mercier" Date: Thu, 30 May 2024 15:13:11 +0000 Subject: [PATCH 2/3] libprocessgroup: Don't delegate to default constructor Manually calling a defaulted default constructor from a another constructor is superfluous, and can increase code size if the default constructor is not otherwise used. There's nothing to delegate, so remove the call. Bug: 346584259 Test: m Change-Id: Ia16aa041fdee7434587cf90645d7f95cba4e0d10 --- libprocessgroup/cgrouprc_format/cgroup_controller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libprocessgroup/cgrouprc_format/cgroup_controller.cpp b/libprocessgroup/cgrouprc_format/cgroup_controller.cpp index baf8f9da3..56e67df59 100644 --- a/libprocessgroup/cgrouprc_format/cgroup_controller.cpp +++ b/libprocessgroup/cgrouprc_format/cgroup_controller.cpp @@ -22,7 +22,7 @@ namespace format { CgroupController::CgroupController(uint32_t version, uint32_t flags, const std::string& name, const std::string& path) - : CgroupController() { +{ // strlcpy isn't available on host. Although there is an implementation // in licutils, libcutils itself depends on libcgrouprc_format, causing // a circular dependency. From 54bfde03e1e0284fe01ceb143f9fe482be7db3cd Mon Sep 17 00:00:00 2001 From: "T.J. Mercier" Date: Tue, 4 Jun 2024 23:25:29 +0000 Subject: [PATCH 3/3] libprocessgroup: Remove unused includes; add missing ones No functional changes. Bug: 346584259 Test: m Change-Id: I68fa51f86b6baaa34fb2cdfdc16a4d1ff61e1e5f --- libprocessgroup/cgroup_map.cpp | 14 -------------- libprocessgroup/cgroup_map.h | 5 ----- .../processgroup/format/cgroup_controller.h | 1 + .../include/processgroup/format/cgroup_file.h | 2 ++ libprocessgroup/sched_policy.cpp | 1 + libprocessgroup/setup/cgroup_descriptor.h | 5 +++++ libprocessgroup/task_profiles.cpp | 2 ++ libprocessgroup/task_profiles.h | 4 ++-- 8 files changed, 13 insertions(+), 21 deletions(-) diff --git a/libprocessgroup/cgroup_map.cpp b/libprocessgroup/cgroup_map.cpp index c8ae2161a..ebc059944 100644 --- a/libprocessgroup/cgroup_map.cpp +++ b/libprocessgroup/cgroup_map.cpp @@ -18,33 +18,19 @@ #define LOG_TAG "libprocessgroup" #include -#include -#include -#include -#include -#include -#include -#include -#include #include #include #include #include -#include #include #include -#include #include -#include -#include #include -using android::base::GetBoolProperty; using android::base::StartsWith; using android::base::StringPrintf; -using android::base::unique_fd; using android::base::WriteStringToFile; static constexpr const char* CGROUP_PROCS_FILE = "/cgroup.procs"; diff --git a/libprocessgroup/cgroup_map.h b/libprocessgroup/cgroup_map.h index 9dd5bf5b1..31925d5d7 100644 --- a/libprocessgroup/cgroup_map.h +++ b/libprocessgroup/cgroup_map.h @@ -16,14 +16,9 @@ #pragma once -#include #include -#include -#include -#include #include -#include #include diff --git a/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_controller.h b/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_controller.h index 8d3aa5697..9427a1cf9 100644 --- a/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_controller.h +++ b/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_controller.h @@ -16,6 +16,7 @@ #pragma once +#include #include #include diff --git a/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_file.h b/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_file.h index f1678a114..2d9786fe6 100644 --- a/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_file.h +++ b/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_file.h @@ -16,6 +16,8 @@ #pragma once +#include + #include namespace android { diff --git a/libprocessgroup/sched_policy.cpp b/libprocessgroup/sched_policy.cpp index 1005b1e3e..0f2640a0a 100644 --- a/libprocessgroup/sched_policy.cpp +++ b/libprocessgroup/sched_policy.cpp @@ -19,6 +19,7 @@ #define LOG_TAG "SchedPolicy" #include +#include #include #include diff --git a/libprocessgroup/setup/cgroup_descriptor.h b/libprocessgroup/setup/cgroup_descriptor.h index 699c03cec..9982bfc73 100644 --- a/libprocessgroup/setup/cgroup_descriptor.h +++ b/libprocessgroup/setup/cgroup_descriptor.h @@ -16,6 +16,11 @@ #pragma once +#include +#include + +#include + #include namespace android { diff --git a/libprocessgroup/task_profiles.cpp b/libprocessgroup/task_profiles.cpp index 0c2252b17..48705481c 100644 --- a/libprocessgroup/task_profiles.cpp +++ b/libprocessgroup/task_profiles.cpp @@ -17,7 +17,9 @@ //#define LOG_NDEBUG 0 #define LOG_TAG "libprocessgroup" +#include #include +#include #include #include diff --git a/libprocessgroup/task_profiles.h b/libprocessgroup/task_profiles.h index 7e3c50d9f..184e9e35f 100644 --- a/libprocessgroup/task_profiles.h +++ b/libprocessgroup/task_profiles.h @@ -16,10 +16,10 @@ #pragma once -#include #include -#include + #include +#include #include #include #include