From 2ff2fc7a2ddf9d2cdd385da77708e15ee465c591 Mon Sep 17 00:00:00 2001 From: wangxiaoding Date: Fri, 30 Dec 2022 16:15:10 +0800 Subject: [PATCH] fix: govern soc_perf inner_api. Signed-off-by: wangxiaoding --- BUILD.gn | 117 ------------------ bundle.json | 19 +-- common/include/socperf_log.h | 75 +++++++++++ common/src/socperf_log.cpp | 22 ++++ include/client/socperf_proxy.h | 43 ------- interfaces/inner_api/socperf_client/BUILD.gn | 45 +++++++ .../include}/i_socperf_service.h | 52 ++++++-- .../include/socperf_action_type.h | 32 +++++ .../socperf_client/include}/socperf_client.h | 58 ++++++++- .../socperf_client/include/socperf_proxy.h | 90 ++++++++++++++ .../libsocperf_client.versionscript | 27 ++++ .../socperf_client/src}/socperf_client.cpp | 3 +- .../socperf_client/src}/socperf_proxy.cpp | 0 profile/BUILD.gn | 36 ++++++ {configs => profile}/socperf_boost_config.xml | 0 .../socperf_resource_config.xml | 0 sa_profile/BUILD.gn | 19 +++ services/BUILD.gn | 82 ++++++++++++ .../core => services/core/include}/socperf.h | 11 +- .../core/include}/socperf_common.h | 65 +++------- .../core/include}/socperf_handler.h | 25 ++-- {src/core => services/core/src}/socperf.cpp | 83 +++++-------- .../core/src}/socperf_handler.cpp | 0 .../server/include}/socperf_server.h | 8 +- .../server/include}/socperf_stub.h | 8 +- .../server/src}/socperf_server.cpp | 0 .../server/src}/socperf_stub.cpp | 0 soc_perf.gni | 23 ++++ .../loadconfigxmlfile_fuzzer/BUILD.gn | 34 +++-- .../loadconfigxmlfile_fuzzer.cpp | 29 +++-- test/fuzztest/socperf_fuzzer/BUILD.gn | 35 ++---- .../socperf_fuzzer/socperf_fuzzer.cpp | 53 +++++--- test/unittest/BUILD.gn | 40 ++++-- 33 files changed, 751 insertions(+), 383 deletions(-) delete mode 100644 BUILD.gn create mode 100644 common/include/socperf_log.h create mode 100644 common/src/socperf_log.cpp delete mode 100644 include/client/socperf_proxy.h create mode 100644 interfaces/inner_api/socperf_client/BUILD.gn rename {include => interfaces/inner_api/socperf_client/include}/i_socperf_service.h (52%) create mode 100644 interfaces/inner_api/socperf_client/include/socperf_action_type.h rename {include/client => interfaces/inner_api/socperf_client/include}/socperf_client.h (52%) create mode 100644 interfaces/inner_api/socperf_client/include/socperf_proxy.h create mode 100644 interfaces/inner_api/socperf_client/libsocperf_client.versionscript rename {src/client => interfaces/inner_api/socperf_client/src}/socperf_client.cpp (98%) rename {src/client => interfaces/inner_api/socperf_client/src}/socperf_proxy.cpp (100%) create mode 100644 profile/BUILD.gn rename {configs => profile}/socperf_boost_config.xml (100%) rename {configs => profile}/socperf_resource_config.xml (100%) create mode 100644 sa_profile/BUILD.gn create mode 100644 services/BUILD.gn rename {include/core => services/core/include}/socperf.h (92%) rename {include => services/core/include}/socperf_common.h (78%) rename {include/core => services/core/include}/socperf_handler.h (80%) rename {src/core => services/core/src}/socperf.cpp (91%) rename {src/core => services/core/src}/socperf_handler.cpp (100%) rename {include/server => services/server/include}/socperf_server.h (88%) rename {include/server => services/server/include}/socperf_stub.h (82%) rename {src/server => services/server/src}/socperf_server.cpp (100%) rename {src/server => services/server/src}/socperf_stub.cpp (100%) create mode 100644 soc_perf.gni diff --git a/BUILD.gn b/BUILD.gn deleted file mode 100644 index 05b75bd..0000000 --- a/BUILD.gn +++ /dev/null @@ -1,117 +0,0 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. -# 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. - -import("//build/ohos.gni") -import("//build/ohos/sa_profile/sa_profile.gni") - -ohos_sa_profile("socperf_sa_profile") { - sources = [ "sa_profile/1906.xml" ] - part_name = "soc_perf" -} - -ohos_prebuilt_etc("socperf_resource_config") { - source = "configs/socperf_resource_config.xml" - install_enable = true - module_install_dir = "etc/soc_perf" - part_name = "soc_perf" - subsystem_name = "resourceschedule" -} -ohos_prebuilt_etc("socperf_boost_config") { - source = "configs/socperf_boost_config.xml" - install_enable = true - module_install_dir = "etc/soc_perf" - part_name = "soc_perf" - subsystem_name = "resourceschedule" -} -group("socperf_config") { - deps = [ - ":socperf_boost_config", - ":socperf_resource_config", - ] -} - -ohos_shared_library("socperf_server") { - sources = [ - "src/core/socperf.cpp", - "src/core/socperf_handler.cpp", - "src/server/socperf_server.cpp", - "src/server/socperf_stub.cpp", - ] - include_dirs = [ - "include", - "include/server", - "include/core", - "//base/customization/config_policy/interfaces/innerkits/include", - ] - deps = [ - "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", - "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", - "//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk:system_ability_fwk", - "//third_party/libxml2:xml2", - ] - external_deps = [ - "c_utils:utils", - "config_policy:configpolicy_util", - "eventhandler:libeventhandler", - "hitrace_native:hitrace_meter", - ] - part_name = "soc_perf" - subsystem_name = "resourceschedule" -} - -config("socperf_client_public_config") { - include_dirs = [ - "include", - "include/client", - ] -} - -ohos_shared_library("socperf_client") { - sources = [ - "src/client/socperf_client.cpp", - "src/client/socperf_proxy.cpp", - ] - include_dirs = [ - "include", - "include/client", - "//foundation/systemabilitymgr/safwk/services/safwk/include", - ] - public_configs = [ ":socperf_client_public_config" ] - deps = [ - "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", - "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", - "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - ] - part_name = "soc_perf" - subsystem_name = "resourceschedule" - external_deps = [ "c_utils:utils" ] -} - -ohos_executable("socperf_test") { - sources = [ "test/unittest/socperf_test.cpp" ] - include_dirs = [ - "include", - "include/client", - ] - deps = [ - "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", - "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", - "//foundation/resourceschedule/resource_schedule_service/soc_perf:socperf_client", - "//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk:system_ability_fwk", - "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - ] - install_enable = true - part_name = "soc_perf" - subsystem_name = "resourceschedule" - external_deps = [ "c_utils:utils" ] -} diff --git a/bundle.json b/bundle.json index d21cd92..af12299 100644 --- a/bundle.json +++ b/bundle.json @@ -39,21 +39,24 @@ }, "build": { "sub_component": [ - "//foundation/resourceschedule/resource_schedule_service/soc_perf:socperf_client", - "//foundation/resourceschedule/resource_schedule_service/soc_perf:socperf_server", - "//foundation/resourceschedule/resource_schedule_service/soc_perf:socperf_sa_profile", - "//foundation/resourceschedule/resource_schedule_service/soc_perf:socperf_config", - "//foundation/resourceschedule/resource_schedule_service/soc_perf:socperf_test" + "//foundation/resourceschedule/resource_schedule_service/soc_perf/profile:socperf_config", + "//foundation/resourceschedule/resource_schedule_service/soc_perf/sa_profile:socperf_sa_profile", + "//foundation/resourceschedule/resource_schedule_service/soc_perf/interfaces/inner_api/socperf_client:socperf_client", + "//foundation/resourceschedule/resource_schedule_service/soc_perf/services:socperf_server", + "//foundation/resourceschedule/resource_schedule_service/soc_perf/test/unittest:socperf_test" ], "inner_kits": [ { "header": { - "header_base": "//foundation/resourceschedule/resource_schedule_service/soc_perf/include/client", + "header_base": "//foundation/resourceschedule/resource_schedule_service/soc_perf/interfaces/inner_api/socperf_client/include", "header_files": [ - "socperf_client.h" + "i_socperf_service.h", + "socperf_action_type.h", + "socperf_client.h", + "socperf_proxy.h" ] }, - "name": "//foundation/resourceschedule/resource_schedule_service/soc_perf:socperf_client" + "name": "//foundation/resourceschedule/resource_schedule_service/soc_perf/interfaces/inner_api/socperf_client:socperf_client" } ], "test": [ diff --git a/common/include/socperf_log.h b/common/include/socperf_log.h new file mode 100644 index 0000000..200734a --- /dev/null +++ b/common/include/socperf_log.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef SOC_PERF_COMMON_INCLUDE_SOCPERF_LOG_H +#define SOC_PERF_COMMON_INCLUDE_SOCPERF_LOG_H + +#include "hilog/log.h" + +namespace OHOS { +namespace SOCPERF { +#ifndef LOG_TAG_SOC_PERF +#define LOG_TAG_SOC_PERF "socperf" +#endif + +#ifndef LOG_TAG_DOMAIN_ID_SOC_PERF +#define LOG_TAG_DOMAIN_ID_SOC_PERF 0xD001703 +#endif + +static constexpr OHOS::HiviewDFX::HiLogLabel SOC_PERF_LOG_LABEL = { + LOG_CORE, + LOG_TAG_DOMAIN_ID_SOC_PERF, + LOG_TAG_SOC_PERF +}; + +class SocPerfLog { +public: + SocPerfLog() = delete; + ~SocPerfLog() = delete; + + static bool IsDebugLogEnabled() + { + return isDebugLogEnabled_; + } + + static void EnableDebugLog() + { + isDebugLogEnabled_ = true; + } + + static void DisableDebugLog() + { + isDebugLogEnabled_ = false; + } + +private: + static bool isDebugLogEnabled_; +}; + +#define SOC_PERF_PRINT_LOG(Level, fmt, ...) \ + OHOS::HiviewDFX::HiLog::Level(SOC_PERF_LOG_LABEL, fmt, ##__VA_ARGS__) + +#define SOC_PERF_LOGD(fmt, ...) \ + if (SocPerfLog::IsDebugLogEnabled()) \ + SOC_PERF_PRINT_LOG(Debug, fmt, ##__VA_ARGS__) + +#define SOC_PERF_LOGI(fmt, ...) SOC_PERF_PRINT_LOG(Info, fmt, ##__VA_ARGS__) +#define SOC_PERF_LOGW(fmt, ...) SOC_PERF_PRINT_LOG(Warn, fmt, ##__VA_ARGS__) +#define SOC_PERF_LOGE(fmt, ...) SOC_PERF_PRINT_LOG(Error, fmt, ##__VA_ARGS__) +#define SOC_PERF_LOGF(fmt, ...) SOC_PERF_PRINT_LOG(Fatal, fmt, ##__VA_ARGS__) +} // namespace SOCPERF +} // namespace OHOS + +#endif // SOC_PERF_COMMON_INCLUDE_SOCPERF_LOG_H diff --git a/common/src/socperf_log.cpp b/common/src/socperf_log.cpp new file mode 100644 index 0000000..90c819d --- /dev/null +++ b/common/src/socperf_log.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * 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. + */ + +#include "socperf_log.h" + +namespace OHOS { +namespace SOCPERF { +bool SocPerfLog::isDebugLogEnabled_ = HiLogIsLoggable(LOG_TAG_DOMAIN_ID_SOC_PERF, LOG_TAG_SOC_PERF, LOG_DEBUG); +} // namespace SOCPERF +} // namespace OHOS diff --git a/include/client/socperf_proxy.h b/include/client/socperf_proxy.h deleted file mode 100644 index 9e5e068..0000000 --- a/include/client/socperf_proxy.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef SOC_PERF_INCLUDE_CLIENT_SOCPERF_PROXY_H -#define SOC_PERF_INCLUDE_CLIENT_SOCPERF_PROXY_H - -#include "i_socperf_service.h" - -namespace OHOS { -namespace SOCPERF { -class SocPerfProxy : public IRemoteProxy { -public: - void PerfRequest(int32_t cmdId, const std::string& msg) override; - void PerfRequestEx(int32_t cmdId, bool onOffTag, const std::string& msg) override; - void PowerLimitBoost(bool onOffTag, const std::string& msg) override; - void ThermalLimitBoost(bool onOffTag, const std::string& msg) override; - void LimitRequest(int32_t clientId, - const std::vector& tags, const std::vector& configs, const std::string& msg) override; - -public: - explicit SocPerfProxy(const sptr &impl) - : IRemoteProxy(impl) {} - virtual ~SocPerfProxy() {} - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace SOCPERF -} // namespace OHOS - -#endif // SOC_PERF_INCLUDE_CLIENT_SOCPERF_PROXY_H diff --git a/interfaces/inner_api/socperf_client/BUILD.gn b/interfaces/inner_api/socperf_client/BUILD.gn new file mode 100644 index 0000000..b1bbc71 --- /dev/null +++ b/interfaces/inner_api/socperf_client/BUILD.gn @@ -0,0 +1,45 @@ +# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# 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. + +import("//build/ohos.gni") +import( + "//foundation/resourceschedule/resource_schedule_service/soc_perf/soc_perf.gni") + +config("socperf_client_public_config") { + include_dirs = [ + "include", + "${socperf_common}/include", + ] +} + +ohos_shared_library("socperf_client") { + sources = [ + "${socperf_common}/src/socperf_log.cpp", + "src/socperf_client.cpp", + "src/socperf_proxy.cpp", + ] + + public_configs = [ ":socperf_client_public_config" ] + + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_single", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + innerapi_tags = [ "platformsdk" ] + part_name = "soc_perf" + subsystem_name = "resourceschedule" +} diff --git a/include/i_socperf_service.h b/interfaces/inner_api/socperf_client/include/i_socperf_service.h similarity index 52% rename from include/i_socperf_service.h rename to interfaces/inner_api/socperf_client/include/i_socperf_service.h index 44d1394..abbafb5 100644 --- a/include/i_socperf_service.h +++ b/interfaces/inner_api/socperf_client/include/i_socperf_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * 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 @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef SOC_PERF_INCLUDE_I_SOCPERF_SERVICE_H -#define SOC_PERF_INCLUDE_I_SOCPERF_SERVICE_H +#ifndef SOC_PERF_INTERFACES_INNER_API_SOCPERF_CLIENT_INCLUDE_I_SOCPERF_SERVICE_H +#define SOC_PERF_INTERFACES_INNER_API_SOCPERF_CLIENT_INCLUDE_I_SOCPERF_SERVICE_H #include #include "iremote_broker.h" @@ -25,21 +25,53 @@ #include "system_ability_definition.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" -#include "socperf_common.h" +#include "socperf_action_type.h" namespace OHOS { namespace SOCPERF { class ISocPerfService : public IRemoteBroker { public: - ISocPerfService() = default; - ~ISocPerfService() override = default; - DISALLOW_COPY_AND_MOVE(ISocPerfService); - -public: + /** + * @brief Sending a performance request. + * + * @param cmdId scene id defined in config file. + * @param msg Additional string info, which is used for other extensions. + */ virtual void PerfRequest(int32_t cmdId, const std::string& msg) = 0; + + /** + * @brief Sending a performance request. + * + * @param cmdId Scene id defined in config file. + * @param onOffTag Indicates the start of end of a long-term frequency increase event. + * @param msg Additional string info, which is used for other extensions. + */ virtual void PerfRequestEx(int32_t cmdId, bool onOffTag, const std::string& msg) = 0; + + /** + * @brief Sending a power limit boost request. + * + * @param onOffTag Indicates the start of end of a power limit boost event. + * @param msg Additional string info, which is used for other extensions. + */ virtual void PowerLimitBoost(bool onOffTag, const std::string& msg) = 0; + + /** + * @brief Sending a thermal limit boost request. + * + * @param onOffTag Indicates the start of end of a thermal limit boost event. + * @param msg Additional string info, which is used for other extensions. + */ virtual void ThermalLimitBoost(bool onOffTag, const std::string& msg) = 0; + + /** + * @brief Sending a limit request. + * + * @param clientId Used to indentify the caller of frequency limiting, such as + * the thermal module or power consumption module. + * @param configs Indicates the specific value to be limited. + * @param msg Additional string info, which is used for other extensions. + */ virtual void LimitRequest(int32_t clientId, const std::vector& tags, const std::vector& configs, const std::string& msg) = 0; @@ -58,4 +90,4 @@ public: } // namespace SOCPERF } // namespace OHOS -#endif // SOC_PERF_INCLUDE_I_SOCPERF_SERVICE_H +#endif // SOC_PERF_INTERFACES_INNER_API_SOCPERF_CLIENT_INCLUDE_I_SOCPERF_SERVICE_H diff --git a/interfaces/inner_api/socperf_client/include/socperf_action_type.h b/interfaces/inner_api/socperf_client/include/socperf_action_type.h new file mode 100644 index 0000000..9e4ef9c --- /dev/null +++ b/interfaces/inner_api/socperf_client/include/socperf_action_type.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef SOC_PERF_INTERFACES_INNER_API_SOCPERF_CLIENT_INCLUDE_SOCPERF_ACTION_TYPE_H +#define SOC_PERF_INTERFACES_INNER_API_SOCPERF_CLIENT_INCLUDE_SOCPERF_ACTION_TYPE_H + +#include + +namespace OHOS { +namespace SOCPERF { +enum ActionType : uint32_t { + ACTION_TYPE_PERF, + ACTION_TYPE_POWER, + ACTION_TYPE_THERMAL, + ACTION_TYPE_MAX +}; +} // namespace SOCPERF +} // namespace OHOS + +#endif // SOC_PERF_INTERFACES_INNER_API_SOCPERF_CLIENT_INCLUDE_SOCPERF_ACTION_TYPE_H diff --git a/include/client/socperf_client.h b/interfaces/inner_api/socperf_client/include/socperf_client.h similarity index 52% rename from include/client/socperf_client.h rename to interfaces/inner_api/socperf_client/include/socperf_client.h index 771df22..a638e48 100644 --- a/include/client/socperf_client.h +++ b/interfaces/inner_api/socperf_client/include/socperf_client.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * 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 @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef SOC_PERF_INCLUDE_CLIENT_SOCPERF_CLIENT_H -#define SOC_PERF_INCLUDE_CLIENT_SOCPERF_CLIENT_H +#ifndef SOC_PERF_INTERFACES_INNER_API_SOCPERF_CLIENT_INCLUDE_SOCPERF_CLIENT_H +#define SOC_PERF_INTERFACES_INNER_API_SOCPERF_CLIENT_INCLUDE_SOCPERF_CLIENT_H #include // for int32_t #include // for string @@ -25,13 +25,61 @@ namespace OHOS { namespace SOCPERF { class SocPerfClient { public: + /** + * @brief Get the Instance object + * + * @return SocPerfClient& + */ + static SocPerfClient& GetInstance(); + + /** + * @brief Sending a performance request. + * + * @param cmdId Scene id defined in config file. + * @param msg Additional string info, which is used for other extensions. + */ void PerfRequest(int32_t cmdId, const std::string& msg); + + /** + * @brief Sending a performance request. + * + * @param cmdId Scene id defined in config file. + * @param onOffTag Indicates the start of end of a long-term frequency increase event. + * @param msg Additional string info, which is used for other extensions. + */ void PerfRequestEx(int32_t cmdId, bool onOffTag, const std::string& msg); + + /** + * @brief Sending a power limit boost request. + * + * @param onOffTag Indicates the start of end of a power limit boost event. + * @param msg Additional string info, which is used for other extensions. + */ void PowerLimitBoost(bool onOffTag, const std::string& msg); + + /** + * @brief Sending a thermal limit boost request. + * + * @param onOffTag Indicates the start of end of a thermal limit boost event. + * @param msg Additional string info, which is used for other extensions. + */ void ThermalLimitBoost(bool onOffTag, const std::string& msg); + + /** + * @brief Sending a limit request. + * + * @param clientId Used to indentify the caller of frequency limiting, such as + * the thermal module or power consumption module. + * @param configs Indicates the specific value to be limited. + * @param msg Additional string info, which is used for other extensions. + */ void LimitRequest(int32_t clientId, const std::vector& tags, const std::vector& configs, const std::string& msg); - static SocPerfClient& GetInstance(); + + /** + * @brief Reset SocperfClient + * + */ void ResetClient(); private: @@ -63,4 +111,4 @@ private: } // namespace SOCPERF } // namespace OHOS -#endif // SOC_PERF_INCLUDE_CLIENT_SOCPERF_CLIENT_H +#endif // SOC_PERF_INTERFACES_INNER_API_SOCPERF_CLIENT_INCLUDE_SOCPERF_CLIENT_H diff --git a/interfaces/inner_api/socperf_client/include/socperf_proxy.h b/interfaces/inner_api/socperf_client/include/socperf_proxy.h new file mode 100644 index 0000000..67f3faa --- /dev/null +++ b/interfaces/inner_api/socperf_client/include/socperf_proxy.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef SOC_PERF_INTERFACES_INNER_API_SOCPERF_CLIENT_INCLUDE_SOCPERF_PROXY_H +#define SOC_PERF_INTERFACES_INNER_API_SOCPERF_CLIENT_INCLUDE_SOCPERF_PROXY_H + +#include "i_socperf_service.h" + +namespace OHOS { +namespace SOCPERF { +class SocPerfProxy : public IRemoteProxy { +public: + /** + * @brief Sending a performance request. + * + * @param cmdId Scene id defined in config file. + * @param msg Additional string info, which is used for other extensions. + */ + void PerfRequest(int32_t cmdId, const std::string& msg) override; + + /** + * @brief Sending a performance request. + * + * @param cmdId Scene id defined in config file. + * @param onOffTag Indicates the start of end of a long-term frequency increase event. + * @param msg Additional string info, which is used for other extensions. + */ + void PerfRequestEx(int32_t cmdId, bool onOffTag, const std::string& msg) override; + + /** + * @brief Sending a power limit boost request. + * + * @param onOffTag Indicates the start of end of a power limit boost event. + * @param msg Additional string info, which is used for other extensions. + */ + void PowerLimitBoost(bool onOffTag, const std::string& msg) override; + + /** + * @brief Sending a thermal limit boost request. + * + * @param onOffTag Indicates the start of end of a thermal limit boost event. + * @param msg Additional string info, which is used for other extensions. + */ + void ThermalLimitBoost(bool onOffTag, const std::string& msg) override; + + /** + * @brief Sending a limit request. + * + * @param clientId Used to indentify the caller of frequency limiting, such as + * the thermal module or power consumption module. + * @param configs Indicates the specific value to be limited. + * @param msg Additional string info, which is used for other extensions. + */ + void LimitRequest(int32_t clientId, + const std::vector& tags, const std::vector& configs, const std::string& msg) override; + +public: + /** + * @brief Construct a new SocPerfProxy object. + * + * @param impl RemoteObject. + */ + explicit SocPerfProxy(const sptr &impl) + : IRemoteProxy(impl) {} + + /** + * @brief Destroy the SocPerfProxy object. + * + */ + virtual ~SocPerfProxy() {} + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace SOCPERF +} // namespace OHOS + +#endif // SOC_PERF_INTERFACES_INNER_API_SOCPERF_CLIENT_INCLUDE_SOCPERF_PROXY_H diff --git a/interfaces/inner_api/socperf_client/libsocperf_client.versionscript b/interfaces/inner_api/socperf_client/libsocperf_client.versionscript new file mode 100644 index 0000000..d870698 --- /dev/null +++ b/interfaces/inner_api/socperf_client/libsocperf_client.versionscript @@ -0,0 +1,27 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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. + +1.0 { + global: + *ISocPerfService*; + *SocPerfClient*GetInstance*; + *SocPerfClient*PerfRequest*; + *SocPerfClient*PerfRequestEx*; + *SocPerfClient*PowerLimitBoost*; + *SocPerfClient*ThermalLimitBoost*; + *SocPerfClient*LimitRequest*; + *SocPerfClient*ResetClient*; + *SocPerfProxy*; + local: + *; +}; diff --git a/src/client/socperf_client.cpp b/interfaces/inner_api/socperf_client/src/socperf_client.cpp similarity index 98% rename from src/client/socperf_client.cpp rename to interfaces/inner_api/socperf_client/src/socperf_client.cpp index 7f1a82a..ab271f9 100644 --- a/src/client/socperf_client.cpp +++ b/interfaces/inner_api/socperf_client/src/socperf_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * 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 @@ -16,6 +16,7 @@ #include "socperf_client.h" #include // for basic_string, to_string #include // for getpid, gettid +#include "socperf_log.h" namespace OHOS { namespace SOCPERF { diff --git a/src/client/socperf_proxy.cpp b/interfaces/inner_api/socperf_client/src/socperf_proxy.cpp similarity index 100% rename from src/client/socperf_proxy.cpp rename to interfaces/inner_api/socperf_client/src/socperf_proxy.cpp diff --git a/profile/BUILD.gn b/profile/BUILD.gn new file mode 100644 index 0000000..d5b9789 --- /dev/null +++ b/profile/BUILD.gn @@ -0,0 +1,36 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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. + +import("//build/ohos.gni") + +ohos_prebuilt_etc("socperf_resource_config") { + source = "socperf_resource_config.xml" + install_enable = true + module_install_dir = "etc/soc_perf" + part_name = "soc_perf" + subsystem_name = "resourceschedule" +} +ohos_prebuilt_etc("socperf_boost_config") { + source = "socperf_boost_config.xml" + install_enable = true + module_install_dir = "etc/soc_perf" + part_name = "soc_perf" + subsystem_name = "resourceschedule" +} + +group("socperf_config") { + deps = [ + ":socperf_boost_config", + ":socperf_resource_config", + ] +} diff --git a/configs/socperf_boost_config.xml b/profile/socperf_boost_config.xml similarity index 100% rename from configs/socperf_boost_config.xml rename to profile/socperf_boost_config.xml diff --git a/configs/socperf_resource_config.xml b/profile/socperf_resource_config.xml similarity index 100% rename from configs/socperf_resource_config.xml rename to profile/socperf_resource_config.xml diff --git a/sa_profile/BUILD.gn b/sa_profile/BUILD.gn new file mode 100644 index 0000000..92fd0c1 --- /dev/null +++ b/sa_profile/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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. + +import("//build/ohos/sa_profile/sa_profile.gni") + +ohos_sa_profile("socperf_sa_profile") { + sources = [ "1906.xml" ] + part_name = "soc_perf" +} diff --git a/services/BUILD.gn b/services/BUILD.gn new file mode 100644 index 0000000..5682b6d --- /dev/null +++ b/services/BUILD.gn @@ -0,0 +1,82 @@ +# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# 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. + +import("//build/ohos.gni") +import( + "//foundation/resourceschedule/resource_schedule_service/soc_perf/soc_perf.gni") + +config("socperf_server_config") { + include_dirs = [ + "core/include", + "server/include", + "${socperf_common}/include", + "${socperf_interfaces}/inner_api/socperf_client/include", + ] +} + +ohos_shared_library("socperf_server") { + configs = [ ":socperf_server_config" ] + + sources = [ + "${socperf_common}/src/socperf_log.cpp", + "core/src/socperf.cpp", + "core/src/socperf_handler.cpp", + "server/src/socperf_server.cpp", + "server/src/socperf_stub.cpp", + ] + + deps = [ "//third_party/libxml2:xml2" ] + + external_deps = [ + "c_utils:utils", + "config_policy:configpolicy_util", + "eventhandler:libeventhandler", + "hitrace_native:hitrace_meter", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_single", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + configs += [ "//build/config/gcc:symbol_visibility_hidden" ] + part_name = "soc_perf" + subsystem_name = "resourceschedule" +} + +ohos_static_library("socperf_server_static") { + configs = [ ":socperf_server_config" ] + + sources = [ + "${socperf_common}/src/socperf_log.cpp", + "core/src/socperf.cpp", + "core/src/socperf_handler.cpp", + "server/src/socperf_server.cpp", + "server/src/socperf_stub.cpp", + ] + + deps = [ "//third_party/libxml2:xml2" ] + + external_deps = [ + "c_utils:utils", + "config_policy:configpolicy_util", + "eventhandler:libeventhandler", + "hitrace_native:hitrace_meter", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_single", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + part_name = "soc_perf" + subsystem_name = "resourceschedule" +} diff --git a/include/core/socperf.h b/services/core/include/socperf.h similarity index 92% rename from include/core/socperf.h rename to services/core/include/socperf.h index a981ee7..67061e6 100644 --- a/include/core/socperf.h +++ b/services/core/include/socperf.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * 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 @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef SOC_PERF_INCLUDE_CORE_SOCPERF_H -#define SOC_PERF_INCLUDE_CORE_SOCPERF_H +#ifndef SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_H +#define SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_H #include #include @@ -22,7 +22,6 @@ #include #include "libxml/parser.h" #include "libxml/tree.h" -#include "i_socperf_service.h" #include "socperf_common.h" #include "socperf_handler.h" @@ -46,7 +45,6 @@ private: std::unordered_map> perfActionsInfo; std::vector> handlers; bool enabled = false; - bool debugLogEnabled = false; std::unordered_map> resNodeInfo; std::unordered_map> govResNodeInfo; @@ -77,5 +75,4 @@ private: }; } // namespace SOCPERF } // namespace OHOS - -#endif // SOC_PERF_INCLUDE_CORE_SOCPERF_H +#endif // SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_H diff --git a/include/socperf_common.h b/services/core/include/socperf_common.h similarity index 78% rename from include/socperf_common.h rename to services/core/include/socperf_common.h index 835446e..8f57656 100644 --- a/include/socperf_common.h +++ b/services/core/include/socperf_common.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * 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 @@ -13,66 +13,35 @@ * limitations under the License. */ -#ifndef SOC_PERF_INCLUDE_SOCPERF_COMMON_H -#define SOC_PERF_INCLUDE_SOCPERF_COMMON_H +#ifndef SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_COMMON_H +#define SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_COMMON_H +#include #include #include #include #include -#include "hilog/log.h" +#include "socperf_log.h" +#include "socperf_action_type.h" namespace OHOS { namespace SOCPERF { -#define LOG_TAG_SOC_PERF "socperf" -#define LOG_TAG_DOMAIN_ID_SOC_PERF 0xD001703 - -static constexpr OHOS::HiviewDFX::HiLogLabel SOC_PERF_LOG_LABEL = { - LOG_CORE, - LOG_TAG_DOMAIN_ID_SOC_PERF, - LOG_TAG_SOC_PERF -}; - -#define SOC_PERF_LOGF(...) (void)OHOS::HiviewDFX::HiLog::Fatal(SOC_PERF_LOG_LABEL, __VA_ARGS__) -#define SOC_PERF_LOGE(...) (void)OHOS::HiviewDFX::HiLog::Error(SOC_PERF_LOG_LABEL, __VA_ARGS__) -#define SOC_PERF_LOGW(...) (void)OHOS::HiviewDFX::HiLog::Warn(SOC_PERF_LOG_LABEL, __VA_ARGS__) -#define SOC_PERF_LOGI(...) (void)OHOS::HiviewDFX::HiLog::Info(SOC_PERF_LOG_LABEL, __VA_ARGS__) -#define SOC_PERF_LOGD(...) (void)OHOS::HiviewDFX::HiLog::Debug(SOC_PERF_LOG_LABEL, __VA_ARGS__) - enum EventType { EVENT_INVALID = -1, EVENT_OFF, EVENT_ON }; -enum ActionType { - ACTION_TYPE_PERF, - ACTION_TYPE_POWER, - ACTION_TYPE_THERMAL, - ACTION_TYPE_MAX -}; - -namespace { - const int32_t INNER_EVENT_ID_INIT_RES_NODE_INFO = 0; - const int32_t INNER_EVENT_ID_INIT_GOV_RES_NODE_INFO = 1; - const int32_t INNER_EVENT_ID_DO_FREQ_ACTION = 2; - const int32_t INNER_EVENT_ID_DO_FREQ_ACTION_DELAYED = 3; - const int32_t INNER_EVENT_ID_POWER_LIMIT_BOOST_FREQ = 4; - const int32_t INNER_EVENT_ID_THERMAL_LIMIT_BOOST_FREQ = 5; -} - -namespace { - const std::string SOCPERF_RESOURCE_CONFIG_XML = "etc/soc_perf/socperf_resource_config.xml"; - const std::string SOCPERF_BOOST_CONFIG_XML = "etc/soc_perf/socperf_boost_config.xml"; - const int64_t MAX_INT_VALUE = 0x7FFFFFFFFFFFFFFF; - const int64_t MIN_INT_VALUE = 0x8000000000000000; - const int32_t INVALID_VALUE = -1; - const int32_t MAX_HANDLER_THREADS = 5; - const int32_t MIN_RESOURCE_ID = 1000; - const int32_t MAX_RESOURCE_ID = 5999; - const int32_t RES_ID_AND_VALUE_PAIR = 2; - const int32_t RES_ID_NUMS_PER_TYPE = 1000; -} +const std::string SOCPERF_RESOURCE_CONFIG_XML = "etc/soc_perf/socperf_resource_config.xml"; +const std::string SOCPERF_BOOST_CONFIG_XML = "etc/soc_perf/socperf_boost_config.xml"; +const int64_t MAX_INT_VALUE = 0x7FFFFFFFFFFFFFFF; +const int64_t MIN_INT_VALUE = 0x8000000000000000; +const int32_t INVALID_VALUE = -1; +const int32_t MAX_HANDLER_THREADS = 5; +const int32_t MIN_RESOURCE_ID = 1000; +const int32_t MAX_RESOURCE_ID = 5999; +const int32_t RES_ID_AND_VALUE_PAIR = 2; +const int32_t RES_ID_NUMS_PER_TYPE = 1000; class ResNode { public: @@ -372,4 +341,4 @@ static inline std::vector Split(std::string str, std::string patter } // namespace SOCPERF } // namespace OHOS -#endif // SOC_PERF_INCLUDE_SOCPERF_COMMON_H +#endif // SOC_PERF_SERVICES_CORE_INCLUDE_COMMON_H diff --git a/include/core/socperf_handler.h b/services/core/include/socperf_handler.h similarity index 80% rename from include/core/socperf_handler.h rename to services/core/include/socperf_handler.h index a4e8b6c..33fc7e0 100644 --- a/include/core/socperf_handler.h +++ b/services/core/include/socperf_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * 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 @@ -13,14 +13,14 @@ * limitations under the License. */ -#ifndef SOC_PERF_INCLUDE_CORE_SOCPERF_HANDLER_H -#define SOC_PERF_INCLUDE_CORE_SOCPERF_HANDLER_H +#ifndef SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_HANDLER_H +#define SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_HANDLER_H + -#include // for int32_t -#include // for allocator -#include // for unordered_map -#include // for string #include // for shared_ptr +#include // for string +#include // for unordered_map +#include // for uint32_t #include "event_handler.h" // for EventHandler #include "event_runner.h" #include "inner_event.h" // for InnerEvent, InnerEvent::Pointer @@ -31,6 +31,15 @@ namespace OHOS { namespace SOCPERF { class ResStatus; } } namespace OHOS { namespace SOCPERF { +enum SocPerfInnerEvent : uint32_t { + INNER_EVENT_ID_INIT_RES_NODE_INFO = 0, + INNER_EVENT_ID_INIT_GOV_RES_NODE_INFO, + INNER_EVENT_ID_DO_FREQ_ACTION, + INNER_EVENT_ID_DO_FREQ_ACTION_DELAYED, + INNER_EVENT_ID_POWER_LIMIT_BOOST_FREQ, + INNER_EVENT_ID_THERMAL_LIMIT_BOOST_FREQ, +}; + class SocPerfHandler : public AppExecFwk::EventHandler { public: explicit SocPerfHandler(const std::shared_ptr& runner); @@ -63,4 +72,4 @@ private: } // namespace SOCPERF } // namespace OHOS -#endif +#endif // SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_HANDLER_H diff --git a/src/core/socperf.cpp b/services/core/src/socperf.cpp similarity index 91% rename from src/core/socperf.cpp rename to services/core/src/socperf.cpp index bca4fd2..96873fe 100644 --- a/src/core/socperf.cpp +++ b/services/core/src/socperf.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * 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 @@ -29,8 +29,6 @@ SocPerf::~SocPerf() bool SocPerf::Init() { - debugLogEnabled = HiLogIsLoggable(LOG_TAG_DOMAIN_ID_SOC_PERF, LOG_TAG_SOC_PERF, LOG_DEBUG); - if (!LoadConfigXmlFile(SOCPERF_RESOURCE_CONFIG_XML)) { SOC_PERF_LOGE("%{public}s, Failed to load %{public}s", __func__, SOCPERF_RESOURCE_CONFIG_XML.c_str()); return false; @@ -57,9 +55,7 @@ bool SocPerf::Init() enabled = true; - if (debugLogEnabled) { - SOC_PERF_LOGD("%{public}s, SocPerf Init SUCCESS!", __func__); - } + SOC_PERF_LOGD("%{public}s, SocPerf Init SUCCESS!", __func__); return true; } @@ -74,9 +70,8 @@ void SocPerf::PerfRequest(int32_t cmdId, const std::string& msg) SOC_PERF_LOGE("%{public}s, Invalid PerfRequest cmdId[%{public}d]", __func__, cmdId); return; } - if (debugLogEnabled) { - SOC_PERF_LOGD("%{public}s, cmdId[%{public}d]msg[%{public}s]", __func__, cmdId, msg.c_str()); - } + SOC_PERF_LOGD("%{public}s, cmdId[%{public}d]msg[%{public}s]", __func__, cmdId, msg.c_str()); + std::string trace_str(__func__); trace_str.append(",cmdId[").append(std::to_string(cmdId)).append("]"); trace_str.append(",msg[").append(msg).append("]"); @@ -95,10 +90,9 @@ void SocPerf::PerfRequestEx(int32_t cmdId, bool onOffTag, const std::string& msg SOC_PERF_LOGE("%{public}s, Invalid PerfRequestEx cmdId[%{public}d]", __func__, cmdId); return; } - if (debugLogEnabled) { - SOC_PERF_LOGD("%{public}s, cmdId[%{public}d]onOffTag[%{public}d]msg[%{public}s]", - __func__, cmdId, onOffTag, msg.c_str()); - } + SOC_PERF_LOGD("%{public}s, cmdId[%{public}d]onOffTag[%{public}d]msg[%{public}s]", + __func__, cmdId, onOffTag, msg.c_str()); + std::string trace_str(__func__); trace_str.append(",cmdId[").append(std::to_string(cmdId)).append("]"); trace_str.append(",onOff[").append(std::to_string(onOffTag)).append("]"); @@ -114,9 +108,8 @@ void SocPerf::PowerLimitBoost(bool onOffTag, const std::string& msg) SOC_PERF_LOGE("%{public}s, SocPerf disabled!", __func__); return; } - if (debugLogEnabled) { - SOC_PERF_LOGD("%{public}s, onOffTag[%{public}d]msg[%{public}s]", __func__, onOffTag, msg.c_str()); - } + SOC_PERF_LOGD("%{public}s, onOffTag[%{public}d]msg[%{public}s]", __func__, onOffTag, msg.c_str()); + std::string trace_str(__func__); trace_str.append(",onOff[").append(std::to_string(onOffTag)).append("]"); trace_str.append(",msg[").append(msg).append("]"); @@ -134,9 +127,7 @@ void SocPerf::ThermalLimitBoost(bool onOffTag, const std::string& msg) SOC_PERF_LOGE("%{public}s, SocPerf disabled!", __func__); return; } - if (debugLogEnabled) { - SOC_PERF_LOGD("%{public}s, onOffTag[%{public}d]msg[%{public}s]", __func__, onOffTag, msg.c_str()); - } + SOC_PERF_LOGD("%{public}s, onOffTag[%{public}d]msg[%{public}s]", __func__, onOffTag, msg.c_str()); std::string trace_str(__func__); trace_str.append(",onOff[").append(std::to_string(onOffTag)).append("]"); trace_str.append(",msg[").append(msg).append("]"); @@ -163,11 +154,9 @@ void SocPerf::LimitRequest(int32_t clientId, SOC_PERF_LOGE("%{public}s, clientId must be between ACTION_TYPE_PERF and ACTION_TYPE_MAX!", __func__); return; } - if (debugLogEnabled) { - for (int32_t i = 0; i < (int32_t)tags.size(); i++) { - SOC_PERF_LOGD("%{public}s, clientId[%{public}d],tags[%{public}d],configs[%{public}lld],msg[%{public}s]", - __func__, clientId, tags[i], (long long)configs[i], msg.c_str()); - } + for (int32_t i = 0; i < (int32_t)tags.size(); i++) { + SOC_PERF_LOGD("%{public}s, clientId[%{public}d],tags[%{public}d],configs[%{public}lld],msg[%{public}s]", + __func__, clientId, tags[i], (long long)configs[i], msg.c_str()); } for (int32_t i = 0; i < (int32_t)tags.size(); i++) { int32_t resId = tags[i]; @@ -277,9 +266,7 @@ bool SocPerf::LoadConfigXmlFile(std::string configFile) return false; } xmlFreeDoc(file); - if (debugLogEnabled) { - SOC_PERF_LOGD("%{public}s, Success to Load %{public}s", __func__, configFile.c_str()); - } + SOC_PERF_LOGD("%{public}s, Success to Load %{public}s", __func__, configFile.c_str()); return true; } @@ -295,9 +282,7 @@ bool SocPerf::CreateHandlers() } handlers[i] = std::make_shared(runner); } - if (debugLogEnabled) { - SOC_PERF_LOGD("%{public}s, Success to Create All Handler threads", __func__); - } + SOC_PERF_LOGD("%{public}s, Success to Create All Handler threads", __func__); return true; } @@ -651,27 +636,25 @@ bool SocPerf::CheckActionResIdAndValueValid(std::string configFile) void SocPerf::PrintCachedInfo() { - if (debugLogEnabled) { - SOC_PERF_LOGD("------------------------------------"); - SOC_PERF_LOGD("resNodeInfo(%{public}d)", (int32_t)resNodeInfo.size()); - for (auto iter = resNodeInfo.begin(); iter != resNodeInfo.end(); ++iter) { - std::shared_ptr resNode = iter->second; - resNode->PrintString(); - } - SOC_PERF_LOGD("------------------------------------"); - SOC_PERF_LOGD("govResNodeInfo(%{public}d)", (int32_t)govResNodeInfo.size()); - for (auto iter = govResNodeInfo.begin(); iter != govResNodeInfo.end(); ++iter) { - std::shared_ptr govResNode = iter->second; - govResNode->PrintString(); - } - SOC_PERF_LOGD("------------------------------------"); - SOC_PERF_LOGD("perfActionsInfo(%{public}d)", (int32_t)perfActionsInfo.size()); - for (auto iter = perfActionsInfo.begin(); iter != perfActionsInfo.end(); ++iter) { - std::shared_ptr actions = iter->second; - actions->PrintString(); - } - SOC_PERF_LOGD("------------------------------------"); + SOC_PERF_LOGD("------------------------------------"); + SOC_PERF_LOGD("resNodeInfo(%{public}d)", (int32_t)resNodeInfo.size()); + for (auto iter = resNodeInfo.begin(); iter != resNodeInfo.end(); ++iter) { + std::shared_ptr resNode = iter->second; + resNode->PrintString(); } + SOC_PERF_LOGD("------------------------------------"); + SOC_PERF_LOGD("govResNodeInfo(%{public}d)", (int32_t)govResNodeInfo.size()); + for (auto iter = govResNodeInfo.begin(); iter != govResNodeInfo.end(); ++iter) { + std::shared_ptr govResNode = iter->second; + govResNode->PrintString(); + } + SOC_PERF_LOGD("------------------------------------"); + SOC_PERF_LOGD("perfActionsInfo(%{public}d)", (int32_t)perfActionsInfo.size()); + for (auto iter = perfActionsInfo.begin(); iter != perfActionsInfo.end(); ++iter) { + std::shared_ptr actions = iter->second; + actions->PrintString(); + } + SOC_PERF_LOGD("------------------------------------"); } } // namespace SOCPERF } // namespace OHOS diff --git a/src/core/socperf_handler.cpp b/services/core/src/socperf_handler.cpp similarity index 100% rename from src/core/socperf_handler.cpp rename to services/core/src/socperf_handler.cpp diff --git a/include/server/socperf_server.h b/services/server/include/socperf_server.h similarity index 88% rename from include/server/socperf_server.h rename to services/server/include/socperf_server.h index 4df2729..7af60a2 100644 --- a/include/server/socperf_server.h +++ b/services/server/include/socperf_server.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * 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 @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef SOC_PERF_INCLUDE_SERVER_SOCPERF_SERVER_H -#define SOC_PERF_INCLUDE_SERVER_SOCPERF_SERVER_H +#ifndef SOC_PERF_SERVICES_SERVER_INCLUDE_SOCPERF_SERVER_H +#define SOC_PERF_SERVICES_SERVER_INCLUDE_SOCPERF_SERVER_H #include #include @@ -53,4 +53,4 @@ private: } // namespace SOCPERF } // namespace OHOS -#endif // SOC_PERF_INCLUDE_SERVER_SOCPERF_SERVER_H +#endif // SOC_PERF_SERVICES_SERVER_INCLUDE_SOCPERF_SERVER_H diff --git a/include/server/socperf_stub.h b/services/server/include/socperf_stub.h similarity index 82% rename from include/server/socperf_stub.h rename to services/server/include/socperf_stub.h index 0b15b12..cf1e10d 100644 --- a/include/server/socperf_stub.h +++ b/services/server/include/socperf_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * 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 @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef SOC_PERF_INCLUDE_SERVER_SOCPERF_STUB_H -#define SOC_PERF_INCLUDE_SERVER_SOCPERF_STUB_H +#ifndef SOC_PERF_SERVICES_SERVER_INCLUDE_SOCPERF_STUB_H +#define SOC_PERF_SERVICES_SERVER_INCLUDE_SOCPERF_STUB_H #include // for int32_t, uint32_t #include "i_socperf_service.h" @@ -33,4 +33,4 @@ public: } // namespace SOCPERF } // namespace OHOS -#endif // SOC_PERF_INCLUDE_SERVER_SOCPERF_STUB_H +#endif // SOC_PERF_SERVICES_SERVER_INCLUDE_SOCPERF_STUB_H diff --git a/src/server/socperf_server.cpp b/services/server/src/socperf_server.cpp similarity index 100% rename from src/server/socperf_server.cpp rename to services/server/src/socperf_server.cpp diff --git a/src/server/socperf_stub.cpp b/services/server/src/socperf_stub.cpp similarity index 100% rename from src/server/socperf_stub.cpp rename to services/server/src/socperf_stub.cpp diff --git a/soc_perf.gni b/soc_perf.gni new file mode 100644 index 0000000..e86d6f7 --- /dev/null +++ b/soc_perf.gni @@ -0,0 +1,23 @@ +# Copyright (C) 2023 Huawei Device Co., Ltd. +# 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. + +socperf_path = + "//foundation/resourceschedule/resource_schedule_service/soc_perf" + +socperf_services = "${socperf_path}/services" + +socperf_common = "${socperf_path}/common" + +socperf_interfaces = "${socperf_path}/interfaces" + +socperf_test = "${socperf_path}/test" diff --git a/test/fuzztest/loadconfigxmlfile_fuzzer/BUILD.gn b/test/fuzztest/loadconfigxmlfile_fuzzer/BUILD.gn index 021f548..a378741 100644 --- a/test/fuzztest/loadconfigxmlfile_fuzzer/BUILD.gn +++ b/test/fuzztest/loadconfigxmlfile_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 Huawei Device Co., Ltd. # 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 @@ -14,52 +14,46 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") +import( + "//foundation/resourceschedule/resource_schedule_service/soc_perf/soc_perf.gni") module_output_path = "resource_schedule_service/soc_perf" ##############################fuzztest########################################## config("module_private_config") { - visibility = [ ":*" ] - include_dirs = [ - "//foundation/resourceschedule/resource_schedule_service/soc_perf/include/server", - "//foundation/resourceschedule/resource_schedule_service/soc_perf/include/core", - "//foundation/resourceschedule/resource_schedule_service/soc_perf/include", + "${socperf_common}/include", + "${socperf_interfaces}/inner_api/socperf_client/include", + "${socperf_services}/core/include", + "${socperf_services}/server/include", ] } ohos_fuzztest("LoadConfigXmlFileFuzzTest") { module_out_path = module_output_path - fuzz_config_file = "//foundation/resourceschedule/resource_schedule_service/soc_perf/test/fuzztest/loadconfigxmlfile_fuzzer" - + fuzz_config_file = "${socperf_test}/fuzztest/loadconfigxmlfile_fuzzer" configs = [ ":module_private_config" ] - include_dirs = [] + cflags = [ "-g", "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", ] + sources = [ "loadconfigxmlfile_fuzzer.cpp" ] - deps = [ - "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", - "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", - "//foundation/resourceschedule/resource_schedule_service/soc_perf:socperf_server", - "//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk:system_ability_fwk", - "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//third_party/libxml2:xml2", - ] + deps = [ "${socperf_services}:socperf_server_static" ] + external_deps = [ "c_utils:utils", - "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", ] } ############################################################################### group("fuzztest") { testonly = true - deps = [] - deps += [ + deps = [ # deps file ":LoadConfigXmlFileFuzzTest", ] diff --git a/test/fuzztest/loadconfigxmlfile_fuzzer/loadconfigxmlfile_fuzzer.cpp b/test/fuzztest/loadconfigxmlfile_fuzzer/loadconfigxmlfile_fuzzer.cpp index fb92235..933451d 100644 --- a/test/fuzztest/loadconfigxmlfile_fuzzer/loadconfigxmlfile_fuzzer.cpp +++ b/test/fuzztest/loadconfigxmlfile_fuzzer/loadconfigxmlfile_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * 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 @@ -22,28 +22,41 @@ namespace OHOS { namespace SOCPERF { const std::string fuzzedFile = "myFuzzed.xml"; const int32_t FILE_RETURN_SUCCESS = 1; + std::mutex mutexLock; + std::unique_ptr socPerf = nullptr; - bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + bool DoInit() { + std::lock_guard lock(mutexLock); + if (socPerf) { + return true; + } + socPerf = std::make_unique(); + return socPerf != nullptr; + } + + void DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + if (!DoInit()) { + return; + } + // generate fuzzed xml FILE *pFile = fopen(fuzzedFile.c_str(), "wb"); if (!pFile) { - return false; + return; } int32_t retCode = fwrite(reinterpret_cast(data), size, 1, pFile); // 1 means count=1 if (retCode < FILE_RETURN_SUCCESS) { (void)fclose(pFile); pFile = nullptr; - return false; + return; } (void)fclose(pFile); pFile = nullptr; - - std::shared_ptr socPerf = std::make_shared(); - bool ret = socPerf->LoadConfigXmlFile(fuzzedFile); - return ret; + socPerf->LoadConfigXmlFile(fuzzedFile); } } // namespace SOCPERF } // namespace OHOS diff --git a/test/fuzztest/socperf_fuzzer/BUILD.gn b/test/fuzztest/socperf_fuzzer/BUILD.gn index 119b64a..1c4793b 100644 --- a/test/fuzztest/socperf_fuzzer/BUILD.gn +++ b/test/fuzztest/socperf_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 Huawei Device Co., Ltd. # 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 @@ -14,44 +14,33 @@ #####################hydra-fuzz################### import("//build/config/features.gni") import("//build/test.gni") +import( + "//foundation/resourceschedule/resource_schedule_service/soc_perf/soc_perf.gni") module_output_path = "resource_schedule_service/soc_perf" ##############################fuzztest########################################## -config("module_private_config") { - visibility = [ ":*" ] - - include_dirs = [ - "//foundation/resourceschedule/resource_schedule_service/soc_perf/include/server", - "//foundation/resourceschedule/resource_schedule_service/soc_perf/include/core", - "//foundation/resourceschedule/resource_schedule_service/soc_perf/include", - ] -} - ohos_fuzztest("SocPerfFuzzTest") { module_out_path = module_output_path - fuzz_config_file = "//foundation/resourceschedule/resource_schedule_service/soc_perf/test/fuzztest/socperf_fuzzer" - - configs = [ ":module_private_config" ] + fuzz_config_file = "${socperf_test}/fuzztest/socperf_fuzzer" include_dirs = [] + cflags = [ "-g", "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", ] + sources = [ "socperf_fuzzer.cpp" ] - deps = [ - "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", - "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", - "//foundation/resourceschedule/resource_schedule_service/soc_perf:socperf_server", - "//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk:system_ability_fwk", - "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//third_party/libxml2:xml2", - ] + deps = [ "${socperf_interfaces}/inner_api/socperf_client:socperf_client" ] + external_deps = [ "c_utils:utils", - "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_single", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", ] } diff --git a/test/fuzztest/socperf_fuzzer/socperf_fuzzer.cpp b/test/fuzztest/socperf_fuzzer/socperf_fuzzer.cpp index 1dfd766..9ea93f2 100644 --- a/test/fuzztest/socperf_fuzzer/socperf_fuzzer.cpp +++ b/test/fuzztest/socperf_fuzzer/socperf_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * 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 @@ -15,39 +15,54 @@ #include "socperf_fuzzer.h" -#define private public -#include "socperf_server.h" -#include "socperf_stub.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" + +#include "i_socperf_service.h" +#include "socperf_log.h" namespace OHOS { namespace SOCPERF { constexpr int32_t MIN_LEN = 4; - static bool isInited = false; + std::mutex mutexLock; + sptr remoteObj = nullptr; + + bool DoInit() + { + std::lock_guard lock(mutexLock); + if (remoteObj) { + return true; + } + auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!samgr) { + return false; + } + remoteObj = samgr->GetSystemAbility(SOC_PERF_SERVICE_SA_ID); + if (!remoteObj) { + return false; + } + return true; + } int32_t onRemoteRequest(uint32_t code, MessageParcel& data) { - int32_t ret = -1; + if (!DoInit()) { + return -1; + } MessageParcel reply; MessageOption option; - if (!isInited) { - if (!DelayedSingleton::GetInstance()->socPerf.Init()) { - return ret; - } - isInited = true; - } - ret = DelayedSingleton::GetInstance()->OnRemoteRequest(code, data, reply, option); - return ret; + return remoteObj->SendRequest(code, data, reply, option); } - void DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { if (size <= MIN_LEN) { - return; + return false; } MessageParcel dataMessageParcel; - if (!dataMessageParcel.WriteInterfaceToken(SocPerfStub::GetDescriptor())) { - return; + if (!dataMessageParcel.WriteInterfaceToken(IRemoteStub::GetDescriptor())) { + return false; } uint32_t code = *(reinterpret_cast(data)); @@ -56,7 +71,9 @@ namespace SOCPERF { dataMessageParcel.WriteBuffer(data + sizeof(uint32_t), size); dataMessageParcel.RewindRead(0); + SOC_PERF_LOGD("_______________"); onRemoteRequest(code, dataMessageParcel); + return true; } } // namespace SOCPERF } // namespace OHOS diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 4757763..9836147 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 Huawei Device Co., Ltd. # 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 @@ -12,6 +12,8 @@ # limitations under the License. import("//build/test.gni") +import( + "//foundation/resourceschedule/resource_schedule_service/soc_perf/soc_perf.gni") module_output_path = "soc_perf/socperftest" @@ -19,9 +21,9 @@ config("module_private_config") { visibility = [ ":*" ] include_dirs = [ - "//foundation/resourceschedule/resource_schedule_service/soc_perf/include/client", - "//foundation/resourceschedule/resource_schedule_service/soc_perf/include/core", - "//foundation/resourceschedule/resource_schedule_service/soc_perf/include", + "${socperf_common}/include", + "${socperf_interfaces}/inner_api/socperf_client/include", + "${socperf_services}/core/include", ] } @@ -33,20 +35,40 @@ ohos_unittest("SocPerfSubTest") { configs = [ ":module_private_config" ] deps = [ - "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", - "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", - "//foundation/resourceschedule/resource_schedule_service/soc_perf:socperf_client", - "//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk:system_ability_fwk", - "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "${socperf_interfaces}/inner_api/socperf_client:socperf_client", "//third_party/googletest:gtest_main", "//third_party/libxml2:xml2", ] + external_deps = [ "c_utils:utils", "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_single", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", ] } +ohos_executable("socperf_test") { + sources = [ "socperf_test.cpp" ] + + deps = [ "${socperf_interfaces}/inner_api/socperf_client:socperf_client" ] + + external_deps = [ + "c_utils:utils", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_single", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + install_enable = true + part_name = "soc_perf" + subsystem_name = "resourceschedule" +} + group("unittest") { testonly = true deps = [ ":SocPerfSubTest" ]