From a91216fbb99f4e2675adef2f2a0d9423c25cf2b6 Mon Sep 17 00:00:00 2001 From: HaoyangT Date: Mon, 17 Jan 2022 14:54:02 +0800 Subject: [PATCH] socperf Signed-off-by: HaoyangT --- bundle.json => ressched/bundle.json | 2 + .../innerkits/ressched_client/BUILD.gn | 14 +- .../include/res_sched_client.h | 54 +- .../ressched_client/include/res_sched_proxy.h | 38 ++ .../include/res_sched_service.h | 45 ++ .../ressched_client/src/res_sched_client.cpp | 60 +- .../ressched_client/src/res_sched_proxy.cpp | 31 + ressched/plugins/socperf_plugin/BUILD.gn | 40 ++ .../socperf_plugin/include/socperf_plugin.h | 27 + .../socperf_plugin/src/socperf_plugin.cpp | 68 ++ ressched/profile/res_sched_plugin_switch.xml | 1 + ressched/sa_profile/1901.xml | 2 +- ressched/services/BUILD.gn | 9 +- .../include/res_sched_server.h | 43 ++ .../include/res_sched_service_stub.h} | 0 .../resschedservice/include/res_sched_stub.h | 35 + .../resschedservice/src/res_sched_server.cpp | 40 ++ .../src/res_sched_service_ability_stub.cpp | 0 .../resschedservice/src/res_sched_stub.cpp | 36 + soc_perf/BUILD.gn | 155 +++++ soc_perf/bundle.json | 60 ++ .../configs/rk3568/socperf_boost_config.xml | 17 + .../configs/rk3568/socperf_power_config.xml | 17 + .../rk3568/socperf_resource_config.xml | 15 + .../configs/rk3568/socperf_thermal_config.xml | 17 + .../configs/wagner/socperf_boost_config.xml | 67 ++ .../configs/wagner/socperf_power_config.xml | 15 + .../wagner/socperf_resource_config.xml | 202 ++++++ .../configs/wagner/socperf_thermal_config.xml | 15 + soc_perf/include/client/socperf_client.h | 64 ++ soc_perf/include/client/socperf_proxy.h | 45 ++ soc_perf/include/core/socperf.h | 81 +++ soc_perf/include/core/socperf_handler.h | 58 ++ soc_perf/include/server/socperf_server.h | 53 ++ soc_perf/include/server/socperf_stub.h | 35 + soc_perf/include/socperf_common.h | 361 ++++++++++ soc_perf/include/socperf_service.h | 61 ++ soc_perf/init/socperf_service.cfg | 16 + soc_perf/sa_profile/1902.xml | 11 + soc_perf/src/client/socperf_client.cpp | 163 +++++ soc_perf/src/client/socperf_proxy.cpp | 103 +++ soc_perf/src/core/socperf.cpp | 615 ++++++++++++++++++ soc_perf/src/core/socperf_handler.cpp | 340 ++++++++++ soc_perf/src/server/socperf_server.cpp | 81 +++ soc_perf/src/server/socperf_stub.cpp | 80 +++ soc_perf/test/BUILD.gn | 0 soc_perf/test/socperf_sub_test.cpp | 0 soc_perf/test/socperf_test.cpp | 146 +++++ 48 files changed, 3398 insertions(+), 40 deletions(-) rename bundle.json => ressched/bundle.json (87%) create mode 100644 ressched/interfaces/innerkits/ressched_client/include/res_sched_proxy.h create mode 100644 ressched/interfaces/innerkits/ressched_client/include/res_sched_service.h create mode 100644 ressched/interfaces/innerkits/ressched_client/src/res_sched_proxy.cpp create mode 100644 ressched/plugins/socperf_plugin/BUILD.gn create mode 100644 ressched/plugins/socperf_plugin/include/socperf_plugin.h create mode 100644 ressched/plugins/socperf_plugin/src/socperf_plugin.cpp create mode 100644 ressched/services/resschedservice/include/res_sched_server.h rename ressched/{plugins/.gitkeep => services/resschedservice/include/res_sched_service_stub.h} (100%) create mode 100644 ressched/services/resschedservice/include/res_sched_stub.h create mode 100644 ressched/services/resschedservice/src/res_sched_server.cpp create mode 100644 ressched/services/resschedservice/src/res_sched_service_ability_stub.cpp create mode 100644 ressched/services/resschedservice/src/res_sched_stub.cpp create mode 100644 soc_perf/BUILD.gn create mode 100644 soc_perf/bundle.json create mode 100644 soc_perf/configs/rk3568/socperf_boost_config.xml create mode 100644 soc_perf/configs/rk3568/socperf_power_config.xml create mode 100644 soc_perf/configs/rk3568/socperf_resource_config.xml create mode 100644 soc_perf/configs/rk3568/socperf_thermal_config.xml create mode 100644 soc_perf/configs/wagner/socperf_boost_config.xml create mode 100644 soc_perf/configs/wagner/socperf_power_config.xml create mode 100644 soc_perf/configs/wagner/socperf_resource_config.xml create mode 100644 soc_perf/configs/wagner/socperf_thermal_config.xml create mode 100644 soc_perf/include/client/socperf_client.h create mode 100644 soc_perf/include/client/socperf_proxy.h create mode 100644 soc_perf/include/core/socperf.h create mode 100644 soc_perf/include/core/socperf_handler.h create mode 100644 soc_perf/include/server/socperf_server.h create mode 100644 soc_perf/include/server/socperf_stub.h create mode 100644 soc_perf/include/socperf_common.h create mode 100644 soc_perf/include/socperf_service.h create mode 100644 soc_perf/init/socperf_service.cfg create mode 100644 soc_perf/sa_profile/1902.xml create mode 100644 soc_perf/src/client/socperf_client.cpp create mode 100644 soc_perf/src/client/socperf_proxy.cpp create mode 100644 soc_perf/src/core/socperf.cpp create mode 100644 soc_perf/src/core/socperf_handler.cpp create mode 100644 soc_perf/src/server/socperf_server.cpp create mode 100644 soc_perf/src/server/socperf_stub.cpp create mode 100644 soc_perf/test/BUILD.gn create mode 100644 soc_perf/test/socperf_sub_test.cpp create mode 100644 soc_perf/test/socperf_test.cpp diff --git a/bundle.json b/ressched/bundle.json similarity index 87% rename from bundle.json rename to ressched/bundle.json index 37b21847..43d6b9ad 100644 --- a/bundle.json +++ b/ressched/bundle.json @@ -34,6 +34,8 @@ "sub_component": [ "//foundation/resourceschedule/resource_schedule_service/ressched/services:resschedsvc", "//foundation/resourceschedule/resource_schedule_service/ressched/interfaces/innerkits/ressched_client:ressched_client", + "//foundation/resourceschedule/resource_schedule_service/ressched/plugins/socperf_plugin:socperf_plugin", + "//foundation/resourceschedule/resource_schedule_service/ressched/etc/init:resourceschedule.cfg", "//foundation/resourceschedule/resource_schedule_service/ressched/profile:ressched_plugin_config", "//foundation/resourceschedule/resource_schedule_service/ressched/profile:ressched_plugin_switch", "//foundation/resourceschedule/resource_schedule_service/ressched/sa_profile:ressched_sa_profile" diff --git a/ressched/interfaces/innerkits/ressched_client/BUILD.gn b/ressched/interfaces/innerkits/ressched_client/BUILD.gn index 620af9b2..c58297c2 100644 --- a/ressched/interfaces/innerkits/ressched_client/BUILD.gn +++ b/ressched/interfaces/innerkits/ressched_client/BUILD.gn @@ -9,7 +9,7 @@ # 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. +# limitations under the License. import("//build/ohos.gni") import("//build/test.gni") @@ -36,12 +36,22 @@ ohos_shared_library("ressched_client") { public_configs = [ ":client_public_config" ] - sources = [ "src/res_sched_client.cpp" ] + sources = [ + "src/res_sched_client.cpp", + "src/res_sched_proxy.cpp", + ] + + include_dirs = [ + "include" + ] deps = [ "${ressched_services}:resschedsvc", "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", "//utils/native/base:utils", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", ] external_deps = [ diff --git a/ressched/interfaces/innerkits/ressched_client/include/res_sched_client.h b/ressched/interfaces/innerkits/ressched_client/include/res_sched_client.h index 13b1494d..c4cc30f7 100644 --- a/ressched/interfaces/innerkits/ressched_client/include/res_sched_client.h +++ b/ressched/interfaces/innerkits/ressched_client/include/res_sched_client.h @@ -13,46 +13,44 @@ * limitations under the License. */ -#ifndef FOUNDATION_RESOURCESCHEDULE_INTERFACES_INNERKITS_RESSCHED_CLIENT_INCLUDE_RES_SCHED_CLIENT_H -#define FOUNDATION_RESOURCESCHEDULE_INTERFACES_INNERKITS_RESSCHED_CLIENT_INCLUDE_RES_SCHED_CLIENT_H +#ifndef RES_SCHED_CLIENT_H +#define RES_SCHED_CLIENT_H -#include "iremote_object.h" +#include "res_sched_service.h" namespace OHOS { namespace ResourceSchedule { -/* - * this class wraped the functions of IResSchedService,effect is the same. - * but through ResSchedClient, you don't need to get IResSchedService from samgr, - * just use the functions is ok. - */ class ResSchedClient { public: - /** - * Only need one client connect to ResSchedService, singleton pattern. - * - * @return Returns the only one implement of ResSchedClient. - */ + void ReportData(uint32_t resType, int64_t value, const std::string& payload); static ResSchedClient& GetInstance(); + void ResetClient(); - /** - * Report source data to resource schedule service in the same process. - * - * @param resType Resource type, all of the type have listed in res_type.h. - * @param value Value of resource type, defined by the developers. - * @param payload is empty is valid. The interface only used for In-Process call. - * ATTENTION: payload is empty is valid. The interface only used for In-Process call. - */ - void ReportDataInProcess(uint32_t resType, int64_t value, const std::string& payload); +private: + ResSchedClient() {} + ~ResSchedClient() {}; -protected: - ResSchedClient() = default; - virtual ~ResSchedClient() = default; +private: + bool CheckClientValid(); private: - DISALLOW_COPY_AND_MOVE(ResSchedClient); -}; + class ResSchedDeathRecipient : public IRemoteObject::DeathRecipient { + public: + ResSchedDeathRecipient(ResSchedClient &resSchedClient); + ~ResSchedDeathRecipient(); + + virtual void OnRemoteDied(const wptr &object) override; + + private: + ResSchedClient &resSchedClient_; + }; + +private: + sptr proxy; + sptr recipient_; +}; } // namespace ResourceSchedule } // namespace OHOS -#endif // FOUNDATION_RESOURCESCHEDULE_INTERFACES_INNERKITS_RESSCHED_CLIENT_INCLUDE_RES_SCHED_CLIENT_H \ No newline at end of file +#endif // RES_SCHED_CLIENT_H \ No newline at end of file diff --git a/ressched/interfaces/innerkits/ressched_client/include/res_sched_proxy.h b/ressched/interfaces/innerkits/ressched_client/include/res_sched_proxy.h new file mode 100644 index 00000000..750b5055 --- /dev/null +++ b/ressched/interfaces/innerkits/ressched_client/include/res_sched_proxy.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021 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 RES_SCHED_PROXY_H +#define RES_SCHED_PROXY_H + +#include "res_sched_service.h" + +namespace OHOS { +namespace ResourceSchedule { +class ResSchedProxy : public IRemoteProxy { +public: + void ReportData(uint32_t resType, int64_t value, const std::string& payload) override; + +public: + explicit ResSchedProxy(const sptr &impl) + : IRemoteProxy(impl) {} + virtual ~ResSchedProxy() {} + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace ResourceSchedule +} // namespace OHOS + +#endif // RES_SCHED_PROXY_H \ No newline at end of file diff --git a/ressched/interfaces/innerkits/ressched_client/include/res_sched_service.h b/ressched/interfaces/innerkits/ressched_client/include/res_sched_service.h new file mode 100644 index 00000000..e4fc9167 --- /dev/null +++ b/ressched/interfaces/innerkits/ressched_client/include/res_sched_service.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021 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 RES_SCHED_ISERVICE_H +#define RES_SCHED_ISERVICE_H + +#include +#include "iremote_broker.h" +#include "iremote_stub.h" +#include "iremote_proxy.h" +#include "iremote_object.h" +#include "system_ability.h" +#include "system_ability_definition.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace ResourceSchedule { +class IResSchedService : public IRemoteBroker { +public: + virtual void ReportData(uint32_t resType, int64_t value, const std::string& payload) = 0; +public: + enum { + TRANS_IPC_ID_REPORT_DATA = 0x0001, + }; + +public: + DECLARE_INTERFACE_DESCRIPTOR(u"Resourceschedule.IResSchedService"); +}; +} // namespace ResourceSchedule +} // namespace OHOS + +#endif // RES_SCHED_ISERVICE_H \ No newline at end of file diff --git a/ressched/interfaces/innerkits/ressched_client/src/res_sched_client.cpp b/ressched/interfaces/innerkits/ressched_client/src/res_sched_client.cpp index f39be272..a01c460a 100644 --- a/ressched/interfaces/innerkits/ressched_client/src/res_sched_client.cpp +++ b/ressched/interfaces/innerkits/ressched_client/src/res_sched_client.cpp @@ -14,24 +14,70 @@ */ #include "res_sched_client.h" -#include "if_system_ability_manager.h" -#include "res_sched_log.h" -#include "res_sched_mgr.h" -#include "system_ability_definition.h" +#include namespace OHOS { namespace ResourceSchedule { - ResSchedClient& ResSchedClient::GetInstance() { static ResSchedClient instance; return instance; } -void ResSchedClient::ReportDataInProcess(uint32_t resType, int64_t value, const std::string& payload) +bool ResSchedClient::CheckClientValid() +{ + if (proxy != nullptr) { + return true; + } + + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + return false; + } + + sptr object = samgr->GetSystemAbility(RES_SCHED_SYS_ABILITY_ID); + if (object == nullptr) { + return false; + } + + proxy = iface_cast(object); + if (proxy == nullptr || (proxy->AsObject() == nullptr)) { + return false; + } + + recipient_ = new ResSchedDeathRecipient(*this); + if (recipient_ == nullptr) { + return false; + } + proxy->AsObject()->AddDeathRecipient(recipient_); + + return true; +} + +void ResSchedClient::ResetClient() +{ + if ((proxy != nullptr) && (proxy->AsObject() != nullptr)) { + proxy->AsObject()->RemoveDeathRecipient(recipient_); + } + proxy = nullptr; +} + +ResSchedClient::ResSchedDeathRecipient::ResSchedDeathRecipient(ResSchedClient &resSchedClient) + : resSchedClient_(resSchedClient){}; + +ResSchedClient::ResSchedDeathRecipient::~ResSchedDeathRecipient(){}; + +void ResSchedClient::ResSchedDeathRecipient::OnRemoteDied(const wptr &remote) { - ResSchedMgr::GetInstance().ReportData(resType, value, payload); + resSchedClient_.ResetClient(); } +void ResSchedClient::ReportData(uint32_t resType, int64_t value, const std::string& payload) +{ + if (!CheckClientValid()) { + return; + } + proxy->ReportData(resType, value, payload); +} } // namespace ResourceSchedule } // namespace OHOS \ No newline at end of file diff --git a/ressched/interfaces/innerkits/ressched_client/src/res_sched_proxy.cpp b/ressched/interfaces/innerkits/ressched_client/src/res_sched_proxy.cpp new file mode 100644 index 00000000..5362d49c --- /dev/null +++ b/ressched/interfaces/innerkits/ressched_client/src/res_sched_proxy.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2021 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 "res_sched_proxy.h" + +namespace OHOS { +namespace ResourceSchedule { +void ResSchedProxy::ReportData(uint32_t resType, int64_t value, const std::string& payload) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteUint32(resType); + data.WriteInt64(value); + data.WriteString(payload); + Remote()->SendRequest(TRANS_IPC_ID_REPORT_DATA, data, reply, option); +} +} // namespace ResourceSchedule +} // namespace OHOS \ No newline at end of file diff --git a/ressched/plugins/socperf_plugin/BUILD.gn b/ressched/plugins/socperf_plugin/BUILD.gn new file mode 100644 index 00000000..4d4d86df --- /dev/null +++ b/ressched/plugins/socperf_plugin/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved. + +import("//build/ohos.gni") +import("//foundation/resourceschedule/resource_schedule_service/ressched/ressched.gni") + +config("socperf_plugin_config") { + include_dirs = [ + "include/", + "//utils/native/base/include", + ] +} + +ohos_shared_library("socperf_plugin") { + configs = [ + ":socperf_plugin_config", + "${ressched_services}:ressched_config", + "${ressched_interfaces}/innerkits/ressched_client:client_public_config", + ] + + sources = [ + "src/socperf_plugin.cpp", + ] + + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//utils/native/base:utils", + "${ressched_services}:resschedsvc", + "//foundation/resourceschedule/resource_schedule_service/soc_perf:socperf_client", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + ] + + external_deps = [ + "appexecfwk_standard:libeventhandler", + ] + + subsystem_name = "resourceschedule" + part_name = "resource_schedule_service" +} diff --git a/ressched/plugins/socperf_plugin/include/socperf_plugin.h b/ressched/plugins/socperf_plugin/include/socperf_plugin.h new file mode 100644 index 00000000..6f65998a --- /dev/null +++ b/ressched/plugins/socperf_plugin/include/socperf_plugin.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved. + * Description: SocPerf plugin. + */ + +#ifndef SOC_PERF_PLUGIN_H +#define SOC_PERF_PLUGIN_H + +#include "single_instance.h" +#include "plugin.h" + +namespace OHOS { +namespace ResourceSchedule { +class SocPerfPlugin : public Plugin { + DECLARE_SINGLE_INSTANCE(SocPerfPlugin) + +public: + void Init() override; + + void Disable() override; + + void DispatchResource(const std::shared_ptr& resData) override; +}; +} // namespace ResourceSchedule +} // namespace OHOS + +#endif //SOC_PERF_PLUGIN_H diff --git a/ressched/plugins/socperf_plugin/src/socperf_plugin.cpp b/ressched/plugins/socperf_plugin/src/socperf_plugin.cpp new file mode 100644 index 00000000..293b19df --- /dev/null +++ b/ressched/plugins/socperf_plugin/src/socperf_plugin.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved. + * Description: SocPerf plugin. + */ + +#include +#include "socperf_plugin.h" +#include "res_type.h" +#include "res_sched_log.h" +#include "plugin_mgr.h" +#include "config_info.h" +#include "socperf_client.h" + +namespace OHOS { +namespace ResourceSchedule { +using namespace ResType; +namespace { + const std::string LIB_NAME = "libsocperf_plugin.z.so"; +} +IMPLEMENT_SINGLE_INSTANCE(SocPerfPlugin) + +void SocPerfPlugin::Init() +{ + PluginMgr::GetInstance().SubscribeResource(LIB_NAME, RES_TYPE_SCREEN_STATUS); + RESSCHED_LOGI("SocPerfPlugin::Init success"); +} + +void SocPerfPlugin::Disable() +{ + PluginMgr::GetInstance().UnSubscribeResource(LIB_NAME, RES_TYPE_SCREEN_STATUS); + RESSCHED_LOGI("SocPerfPlugin::Disable success"); +} + +void SocPerfPlugin::DispatchResource(const std::shared_ptr& data) +{ + RESSCHED_LOGD("SocPerfPlugin::DispatchResource status type %{public}u", data->resType); + + if (data->resType == RES_TYPE_SCREEN_STATUS) { + OHOS::SOCPERF::SocPerfClient::GetInstance().PerfRequest(10000, ""); + return; + } +} + +extern "C" bool OnPluginInit(std::string& libName) +{ + if (libName != LIB_NAME) { + RESSCHED_LOGE("SocPerfPlugin::OnPluginInit lib name is not match"); + return false; + } + SocPerfPlugin::GetInstance().Init(); + RESSCHED_LOGI("SocPerfPlugin::OnPluginInit success."); + return true; +} + +extern "C" void OnPluginDisable() +{ + SocPerfPlugin::GetInstance().Disable(); + RESSCHED_LOGI("SocPerfPlugin::OnPluginDisable success."); +} + +extern "C" void OnDispatchResource(const std::shared_ptr& data) +{ + SocPerfPlugin::GetInstance().DispatchResource(data); + RESSCHED_LOGI("SocPerfPlugin::OnDispatchResource success."); +} + +} +} \ No newline at end of file diff --git a/ressched/profile/res_sched_plugin_switch.xml b/ressched/profile/res_sched_plugin_switch.xml index 7e016ab2..ced76bda 100644 --- a/ressched/profile/res_sched_plugin_switch.xml +++ b/ressched/profile/res_sched_plugin_switch.xml @@ -14,4 +14,5 @@ * limitations under the License. --> + diff --git a/ressched/sa_profile/1901.xml b/ressched/sa_profile/1901.xml index 0ac21fe7..db6e0cff 100644 --- a/ressched/sa_profile/1901.xml +++ b/ressched/sa_profile/1901.xml @@ -14,7 +14,7 @@ * limitations under the License. --> - foundation + resourceschedule 1901 libresschedsvc.z.so diff --git a/ressched/services/BUILD.gn b/ressched/services/BUILD.gn index 62fb37af..e57c38de 100644 --- a/ressched/services/BUILD.gn +++ b/ressched/services/BUILD.gn @@ -9,7 +9,7 @@ # 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. +# limitations under the License. import("//build/ohos.gni") import("//build/test.gni") @@ -26,6 +26,7 @@ config("ressched_config") { "//utils/system/safwk/native/include", "//utils/native/base/include", "//third_party/libxml2/include", + "//foundation/resourceschedule/resource_schedule_service/ressched/interfaces/innerkits/ressched_client/include" ] } @@ -40,13 +41,17 @@ ohos_shared_library("resschedsvc") { "//foundation/resourceschedule/resource_schedule_service/ressched/services/resschedmgr/resschedfwk/src/plugin_mgr.cpp", "//foundation/resourceschedule/resource_schedule_service/ressched/services/resschedmgr/resschedfwk/src/plugin_switch.cpp", "//foundation/resourceschedule/resource_schedule_service/ressched/services/resschedmgr/resschedfwk/src/res_sched_mgr.cpp", - "//foundation/resourceschedule/resource_schedule_service/ressched/services/resschedservice/src/res_sched_service_ability.cpp", + "//foundation/resourceschedule/resource_schedule_service/ressched/services/resschedservice/src/res_sched_server.cpp", + "//foundation/resourceschedule/resource_schedule_service/ressched/services/resschedservice/src/res_sched_stub.cpp" ] deps = [ "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", "//third_party/libxml2:xml2", "//utils/native/base:utils", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", ] external_deps = [ diff --git a/ressched/services/resschedservice/include/res_sched_server.h b/ressched/services/resschedservice/include/res_sched_server.h new file mode 100644 index 00000000..4b04ee33 --- /dev/null +++ b/ressched/services/resschedservice/include/res_sched_server.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021 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 RES_SCHED_SERVER_H +#define RES_SCHED_SERVER_H + +#include "res_sched_service.h" +#include "res_sched_stub.h" +#include "res_sched_mgr.h" + +namespace OHOS { +namespace ResourceSchedule { +class ResSchedServer : public SystemAbility, public ResSchedStub { +DECLARE_SYSTEM_ABILITY(ResSchedServer); + +public: + void ReportData(uint32_t resType, int64_t value, const std::string& payload) override; + +public: + ResSchedServer(int32_t systemAbilityId, bool runOnCreate) + : SystemAbility(systemAbilityId, runOnCreate) {} + ~ResSchedServer() {} + +protected: + void OnStart() override; + void OnStop() override; +}; +} // namespace ResourceSchedule +} // namespace OHOS + +#endif // RES_SCHED_SERVER_H \ No newline at end of file diff --git a/ressched/plugins/.gitkeep b/ressched/services/resschedservice/include/res_sched_service_stub.h similarity index 100% rename from ressched/plugins/.gitkeep rename to ressched/services/resschedservice/include/res_sched_service_stub.h diff --git a/ressched/services/resschedservice/include/res_sched_stub.h b/ressched/services/resschedservice/include/res_sched_stub.h new file mode 100644 index 00000000..0778efb0 --- /dev/null +++ b/ressched/services/resschedservice/include/res_sched_stub.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 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 RES_SCHED_STUB_H +#define RES_SCHED_STUB_H + +#include "res_sched_service.h" + +namespace OHOS { +namespace ResourceSchedule { +class ResSchedStub : public IRemoteStub { +public: + virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) override; + +public: + ResSchedStub() {} + ~ResSchedStub() {} +}; +} // namespace ResourceSchedule +} // namespace OHOS + +#endif // RES_SCHED_STUB_H \ No newline at end of file diff --git a/ressched/services/resschedservice/src/res_sched_server.cpp b/ressched/services/resschedservice/src/res_sched_server.cpp new file mode 100644 index 00000000..bd8edf3f --- /dev/null +++ b/ressched/services/resschedservice/src/res_sched_server.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021 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 "res_sched_server.h" + +namespace OHOS { +namespace ResourceSchedule { +REGISTER_SYSTEM_ABILITY_BY_ID(ResSchedServer, RES_SCHED_SYS_ABILITY_ID, true); + +void ResSchedServer::OnStart() +{ + if (!Publish(this)) { + return; + } + ResSchedMgr::GetInstance().Init(); +} + +void ResSchedServer::OnStop() +{ + ResSchedMgr::GetInstance().Stop(); +} + +void ResSchedServer::ReportData(uint32_t resType, int64_t value, const std::string& payload) +{ + ResSchedMgr::GetInstance().ReportData(resType, value, payload); +} +} // namespace ResourceSchedule +} // namespace OHOS diff --git a/ressched/services/resschedservice/src/res_sched_service_ability_stub.cpp b/ressched/services/resschedservice/src/res_sched_service_ability_stub.cpp new file mode 100644 index 00000000..e69de29b diff --git a/ressched/services/resschedservice/src/res_sched_stub.cpp b/ressched/services/resschedservice/src/res_sched_stub.cpp new file mode 100644 index 00000000..2db298be --- /dev/null +++ b/ressched/services/resschedservice/src/res_sched_stub.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 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 "res_sched_stub.h" + +namespace OHOS { +namespace ResourceSchedule { +int ResSchedStub::OnRemoteRequest(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + switch (code) { + case TRANS_IPC_ID_REPORT_DATA: { + uint32_t resType = data.ReadUint32(); + int64_t value = data.ReadInt64(); + std::string payload = data.ReadString(); + ReportData(resType, value, payload); + return 0; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } +} +} // namespace ResourceSchedule +} // namespace OHOS diff --git a/soc_perf/BUILD.gn b/soc_perf/BUILD.gn new file mode 100644 index 00000000..00b41bcc --- /dev/null +++ b/soc_perf/BUILD.gn @@ -0,0 +1,155 @@ +import("//build/ohos.gni") +import("//build/ohos/sa_profile/sa_profile.gni") + +################################################## +ohos_sa_profile("socperf_sa_profile") { + sources = [ + "sa_profile/1902.xml" + ] + part_name = "soc_perf" +} +################################################## + + + +################################################## +ohos_prebuilt_etc("socperf_resource_config") { + if (device_name == "rk3568") { + source = "configs/rk3568/socperf_resource_config.xml" + } else { + source = "configs/wagner/socperf_resource_config.xml" + } + module_install_dir = "etc/socperf" + part_name = "soc_perf" + subsystem_name = "resourceschedule" +} +ohos_prebuilt_etc("socperf_boost_config") { + if (device_name == "rk3568") { + source = "configs/rk3568/socperf_boost_config.xml" + } else { + source = "configs/wagner/socperf_boost_config.xml" + } + module_install_dir = "etc/socperf" + part_name = "soc_perf" + subsystem_name = "resourceschedule" +} +ohos_prebuilt_etc("socperf_power_config") { + if (device_name == "rk3568") { + source = "configs/rk3568/socperf_power_config.xml" + } else { + source = "configs/wagner/socperf_power_config.xml" + } + module_install_dir = "etc/socperf" + part_name = "soc_perf" + subsystem_name = "resourceschedule" +} +ohos_prebuilt_etc("socperf_thermal_config") { + if (device_name == "rk3568") { + source = "configs/rk3568/socperf_thermal_config.xml" + } else { + source = "configs/wagner/socperf_thermal_config.xml" + } + module_install_dir = "etc/socperf" + part_name = "soc_perf" + subsystem_name = "resourceschedule" +} +################################################## + + + +################################################## +ohos_prebuilt_etc("socperf_service_init") { + source = "init/socperf_service.cfg" + relative_install_dir = "init" + part_name = "soc_perf" + subsystem_name = "resourceschedule" +} +################################################## + + + +################################################## +ohos_shared_library("socperf_server") { + sources = [ + "src/server/socperf_server.cpp", + "src/server/socperf_stub.cpp", + "src/core/socperf.cpp", + "src/core/socperf_handler.cpp" + ] + include_dirs = [ + "include", + "include/server", + "include/core" + ] + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//utils/native/base:utils", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//third_party/libxml2:xml2", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler" + ] + 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" + ] + public_configs = [ + ":socperf_client_public_config" + ] + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//utils/native/base:utils", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + ] + part_name = "soc_perf" + subsystem_name = "resourceschedule" +} +################################################## + + + +################################################## +ohos_executable("socperf_test") { + sources = [ + "test/socperf_test.cpp" + ] + include_dirs = [ + "include", + "include/client" + ] + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//utils/native/base:utils", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/resourceschedule/resource_schedule_service/soc_perf:socperf_client" + ] + install_enable = true + part_name = "soc_perf" + subsystem_name = "resourceschedule" +} +################################################## diff --git a/soc_perf/bundle.json b/soc_perf/bundle.json new file mode 100644 index 00000000..dbcff836 --- /dev/null +++ b/soc_perf/bundle.json @@ -0,0 +1,60 @@ +{ + "name": "@ohos/resource_schedule_service", + "description": "resource schedule service", + "version": "3.1", + "license": "Apache License 2.0", + "publishAs": "code-segment", + "segment": { + "destPath": "https://gitee.com/openharmony/resourceschedule_resource_schedule_service" + }, + "scripts": {}, + "component": { + "name": "soc_perf", + "subsystem": "resourceschedule", + "features": [], + "adapted_system_type": [ + "mini", + "small", + "standard" + ], + "rom": "", + "ram": "", + "deps": { + "components": [ + "libeventhandler", + "ipc_core", + "samgr_proxy", + "system_ability_fwk" + ], + "third_party": [ + "xml2" + ] + }, + "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_service_init", + "//foundation/resourceschedule/resource_schedule_service/soc_perf:socperf_resource_config", + "//foundation/resourceschedule/resource_schedule_service/soc_perf:socperf_boost_config", + "//foundation/resourceschedule/resource_schedule_service/soc_perf:socperf_power_config", + "//foundation/resourceschedule/resource_schedule_service/soc_perf:socperf_thermal_config", + "//foundation/resourceschedule/resource_schedule_service/soc_perf:socperf_test" + ], + "inner_kits": [ + { + "header": { + "header_base": "//foundation/resourceschedule/resource_schedule_service/soc_perf/include/client", + "header_files": [ + "socperf_client.h" + ] + }, + "name": "//foundation/resourceschedule/resource_schedule_service/soc_perf:socperf_client" + } + ], + "test": [ + ] + } + } +} \ No newline at end of file diff --git a/soc_perf/configs/rk3568/socperf_boost_config.xml b/soc_perf/configs/rk3568/socperf_boost_config.xml new file mode 100644 index 00000000..0ff9451b --- /dev/null +++ b/soc_perf/configs/rk3568/socperf_boost_config.xml @@ -0,0 +1,17 @@ + + + + 3000 + 1608000 + 1800000 + + + 2500 + 1800000 + 1992000 + + + 0 + 1800000 + + \ No newline at end of file diff --git a/soc_perf/configs/rk3568/socperf_power_config.xml b/soc_perf/configs/rk3568/socperf_power_config.xml new file mode 100644 index 00000000..18c77e9f --- /dev/null +++ b/soc_perf/configs/rk3568/socperf_power_config.xml @@ -0,0 +1,17 @@ + + + + 2000 + 408000 + 1416000 + + + 1500 + 408000 + 1104000 + + + 0 + 1104000 + + \ No newline at end of file diff --git a/soc_perf/configs/rk3568/socperf_resource_config.xml b/soc_perf/configs/rk3568/socperf_resource_config.xml new file mode 100644 index 00000000..4ee67bea --- /dev/null +++ b/soc_perf/configs/rk3568/socperf_resource_config.xml @@ -0,0 +1,15 @@ + + + + + 408000 + /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq + 408000 600000 816000 1104000 1416000 1608000 1800000 1992000 + + + 1992000 + /sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq + 408000 600000 816000 1104000 1416000 1608000 1800000 1992000 + + + \ No newline at end of file diff --git a/soc_perf/configs/rk3568/socperf_thermal_config.xml b/soc_perf/configs/rk3568/socperf_thermal_config.xml new file mode 100644 index 00000000..e41a4716 --- /dev/null +++ b/soc_perf/configs/rk3568/socperf_thermal_config.xml @@ -0,0 +1,17 @@ + + + + 1000 + 408000 + 816000 + + + 500 + 408000 + 600000 + + + 0 + 600000 + + \ No newline at end of file diff --git a/soc_perf/configs/wagner/socperf_boost_config.xml b/soc_perf/configs/wagner/socperf_boost_config.xml new file mode 100644 index 00000000..c9d63375 --- /dev/null +++ b/soc_perf/configs/wagner/socperf_boost_config.xml @@ -0,0 +1,67 @@ + + + + 1500 + 288000000 + 1661000000 + 893000000 + + + 1000 + 1700000 + 2343000 + 2631000 + 109 + + + 4000 + 100 + 125 + 104 + 100 + 100 + 100 + 110 + 110 + 110 + 110 + 110 + 110 + 110 + 110 + 110 + 120 + 120 + 120 + + + 400 + 1700000 + 2343000 + 2631000 + 288000000 + 1661000000 + 109 + + + 1000 + 100 + 100 + 100 + 100 + 100 + 100 + 110 + 110 + 110 + 110 + 110 + 110 + 110 + 110 + 110 + 120 + 120 + 120 + + \ No newline at end of file diff --git a/soc_perf/configs/wagner/socperf_power_config.xml b/soc_perf/configs/wagner/socperf_power_config.xml new file mode 100644 index 00000000..9c03ce8b --- /dev/null +++ b/soc_perf/configs/wagner/socperf_power_config.xml @@ -0,0 +1,15 @@ + + + + 5000 + 1517000 + 1652000 + 2400000 + + + 0 + 1604000 + 1767000 + 2516000 + + \ No newline at end of file diff --git a/soc_perf/configs/wagner/socperf_resource_config.xml b/soc_perf/configs/wagner/socperf_resource_config.xml new file mode 100644 index 00000000..e70fccfc --- /dev/null +++ b/soc_perf/configs/wagner/socperf_resource_config.xml @@ -0,0 +1,202 @@ + + + + + 884000 + /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq + 884000 960000 1037000 1133000 1229000 1325000 1421000 1517000 1604000 1700000 1796000 1892000 1968000 2045000 + + + 2045000 + /sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq + 884000 960000 1037000 1133000 1229000 1325000 1421000 1517000 1604000 1700000 1796000 1892000 1968000 2045000 + + + 826000 + /sys/devices/system/cpu/cpufreq/policy1/scaling_min_freq + 826000 941000 1056000 1172000 1287000 1402000 1517000 1652000 1767000 1882000 1988000 2093000 2199000 2266000 2343000 2468000 2544000 + + + 2544000 + /sys/devices/system/cpu/cpufreq/policy1/scaling_max_freq + 826000 941000 1056000 1172000 1287000 1402000 1517000 1652000 1767000 1882000 1988000 2093000 2199000 2266000 2343000 2468000 2544000 + + + 1402000 + /sys/devices/system/cpu/cpufreq/policy2/scaling_min_freq + 1402000 1690000 1815000 1940000 2055000 2170000 2285000 2400000 2516000 2631000 2756000 2871000 3005000 3130000 + + + 3130000 + /sys/devices/system/cpu/cpufreq/policy2/scaling_max_freq + 1402000 1690000 1815000 1940000 2055000 2170000 2285000 2400000 2516000 2631000 2756000 2871000 3005000 3130000 + + + 260000000 + /sys/class/devfreq/gpufreq/min_freq + 260000000 288000000 327000000 365000000 413000000 461000000 509000000 557000000 615000000 653000000 682000000 720000000 759000000 + + + 759000000 + /sys/class/devfreq/gpufreq/max_freq + 260000000 288000000 327000000 365000000 413000000 461000000 509000000 557000000 615000000 653000000 682000000 720000000 759000000 + + + 418000000 + /sys/class/devfreq/ddrfreq/min_freq + 418000000 902000000 1104000000 1373000000 1661000000 1795000000 2131000000 + + + 2131000000 + /sys/class/devfreq/ddrfreq/max_freq + 418000000 902000000 1104000000 1373000000 1661000000 1795000000 2131000000 + + + 413000000 + /sys/class/devfreq/l3c_devfreq/min_freq + 413000000 528000000 644000000 701000000 797000000 893000000 980000000 1056000000 1143000000 1229000000 1316000000 1402000000 1488000000 1575000000 1700000000 + + + 1700000000 + /sys/class/devfreq/l3c_devfreq/max_freq + 413000000 528000000 644000000 701000000 797000000 893000000 980000000 1056000000 1143000000 1229000000 1316000000 1402000000 1488000000 1575000000 1700000000 + + + + + 100 + /sys/devices/system/cpu/cpufreq/policy0/schedutil/go_hispeed_load + /sys/devices/system/cpu/cpufreq/policy0/schedutil/hispeed_freq + /sys/devices/system/cpu/cpufreq/policy0/schedutil/target_loads + 95|1325000|75 884000:80 1133000:85 1325000:90 1892000:96 + 95|1421000|75 884000:80 1133000:85 1325000:90 1892000:96 + 95|1421000|75 884000:80 + + + 100 + /sys/devices/system/cpu/cpufreq/policy1/schedutil/go_hispeed_load + /sys/devices/system/cpu/cpufreq/policy1/schedutil/hispeed_freq + /sys/devices/system/cpu/cpufreq/policy1/schedutil/target_loads + 95|1056000|90 1767000:95 + 95|1172000|85 1402000:90 2093000:93 2266000:95 + 90|1882000|80 1882000:90 + 70|1882000|70 1882000:80 + 80|2343000|70 2343000:98 + 30|2199000|30 2199000:80 + + + 100 + /sys/devices/system/cpu/cpufreq/policy2/schedutil/go_hispeed_load + /sys/devices/system/cpu/cpufreq/policy2/schedutil/hispeed_freq + /sys/devices/system/cpu/cpufreq/policy2/schedutil/target_loads + 95|1690000|95 + 95|2170000|90 2400000:95 2631000:98 + 95|2170000|90 2400000:95 2631000:1000 + 80|2400000|80 2631000:95:2756000:1000 + 80|2400000|80 2631000:95 2756000:98 + 90|2170000|80 2400000:95 2631000:98 2871000:1000 + 90|2170000|80 2631000:95 2756000:98 + 90|2170000|80 + 70|2631000|70 2631000:80 + 30|2631000|30 2631000:90 + + + 100 + /sys/devices/system/cpu/cpufreq/policy0/schedutil/above_hispeed_delay + 19000 1700000:59000 + 19000 + 10000 + + + 100 + /sys/devices/system/cpu/cpufreq/policy1/schedutil/above_hispeed_delay + 10000 1287000:30000 1517000:50000 1767000:79000 + 10000 + 5000 + + + 100 + /sys/devices/system/cpu/cpufreq/policy2/schedutil/above_hispeed_delay + 19000 1940000:39000 2285000:79000 2631000:99000 + 10000 2631000:39000 2871000:59000 3005000:39000 + + + 100 + /sys/devices/system/cpu/cpufreq/policy0/schedutil/min_sample_time + 19000 + 59000 + 79000 + + + 100 + /sys/devices/system/cpu/cpufreq/policy1/schedutil/min_sample_time + 10000 + 79000 + + + 100 + /sys/devices/system/cpu/cpufreq/policy2/schedutil/min_sample_time + 10000 3130000:39000 + 39000 3130000:59000 + 59000 + 79000 + + + 110 + /sys/devices/system/cpu/cpufreq/policy0/schedutil/fast_ramp_up + 0 + 1 + + + 110 + /sys/devices/system/cpu/cpufreq/policy1/schedutil/fast_ramp_up + 0 + 1 + + + 110 + /sys/devices/system/cpu/cpufreq/policy2/schedutil/fast_ramp_up + 0 + 1 + + + 100 + /sys/devices/system/cpu/cpufreq/policy0/schedutil/fast_ramp_down + 1 + 0 + + + 100 + /sys/devices/system/cpu/cpufreq/policy1/schedutil/fast_ramp_down + 1 + 0 + + + 100 + /sys/devices/system/cpu/cpufreq/policy2/schedutil/fast_ramp_down + 1 + 0 + + + 120 + /sys/devices/system/cpu/cpufreq/policy0/schedutil/top_task_stats_policy + 3 + 2 + 1 + + + 110 + /sys/devices/system/cpu/cpufreq/policy1/schedutil/top_task_stats_policy + 3 + 2 + 1 + + + 110 + /sys/devices/system/cpu/cpufreq/policy2/schedutil/top_task_stats_policy + 3 + 2 + 1 + + + \ No newline at end of file diff --git a/soc_perf/configs/wagner/socperf_thermal_config.xml b/soc_perf/configs/wagner/socperf_thermal_config.xml new file mode 100644 index 00000000..5331e185 --- /dev/null +++ b/soc_perf/configs/wagner/socperf_thermal_config.xml @@ -0,0 +1,15 @@ + + + + 5000 + 1325000 + 1402000 + 2170000 + + + 0 + 1421000 + 1517000 + 2285000 + + \ No newline at end of file diff --git a/soc_perf/include/client/socperf_client.h b/soc_perf/include/client/socperf_client.h new file mode 100644 index 00000000..92c55807 --- /dev/null +++ b/soc_perf/include/client/socperf_client.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2021 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_CLIENT_H +#define SOC_PERF_CLIENT_H + +#include "socperf_service.h" + +namespace OHOS { +namespace SOCPERF { +class SocPerfClient { +public: + void PerfRequest(int cmdId, const std::string& msg); + void PerfRequestEx(int cmdId, bool onOffTag, const std::string& msg); + void PowerRequest(int cmdId, const std::string& msg); + void PowerRequestEx(int cmdId, bool onOffTag, const std::string& msg); + void PowerLimitBoost(bool onOffTag, const std::string& msg); + void ThermalRequest(int cmdId, const std::string& msg); + void ThermalRequestEx(int cmdId, bool onOffTag, const std::string& msg); + void ThermalLimitBoost(bool onOffTag, const std::string& msg); + static SocPerfClient& GetInstance(); + void ResetClient(); + +private: + SocPerfClient() {} + ~SocPerfClient() {}; + +private: + bool CheckClientValid(); + std::string AddPidAndTidInfo(const std::string& msg); + +private: + class SocPerfDeathRecipient : public IRemoteObject::DeathRecipient { + public: + SocPerfDeathRecipient(SocPerfClient &socPerfClient); + + ~SocPerfDeathRecipient(); + + virtual void OnRemoteDied(const wptr &object) override; + + private: + SocPerfClient &socPerfClient_; + }; + +private: + sptr proxy; + sptr recipient_; +}; +} // namespace SOCPERF +} // namespace OHOS + +#endif // SOC_PERF_CLIENT_H \ No newline at end of file diff --git a/soc_perf/include/client/socperf_proxy.h b/soc_perf/include/client/socperf_proxy.h new file mode 100644 index 00000000..79e6c88c --- /dev/null +++ b/soc_perf/include/client/socperf_proxy.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021 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_PROXY_H +#define SOC_PERF_PROXY_H + +#include "socperf_service.h" + +namespace OHOS { +namespace SOCPERF { +class SocPerfProxy : public IRemoteProxy { +public: + void PerfRequest(int cmdId, const std::string& msg) override; + void PerfRequestEx(int cmdId, bool onOffTag, const std::string& msg) override; + void PowerRequest(int cmdId, const std::string& msg) override; + void PowerRequestEx(int cmdId, bool onOffTag, const std::string& msg) override; + void PowerLimitBoost(bool onOffTag, const std::string& msg) override; + void ThermalRequest(int cmdId, const std::string& msg) override; + void ThermalRequestEx(int cmdId, bool onOffTag, const std::string& msg) override; + void ThermalLimitBoost(bool onOffTag, 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_PROXY_H \ No newline at end of file diff --git a/soc_perf/include/core/socperf.h b/soc_perf/include/core/socperf.h new file mode 100644 index 00000000..c59445b6 --- /dev/null +++ b/soc_perf/include/core/socperf.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2021 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_H +#define SOC_PERF_H + +#include +#include +#include +#include +#include "libxml/parser.h" +#include "libxml/tree.h" +#include "socperf_service.h" +#include "socperf_common.h" +#include "socperf_handler.h" + +namespace OHOS { +namespace SOCPERF { +class SocPerf { +public: + bool Init(); + void PerfRequest(int cmdId, const std::string& msg); + void PerfRequestEx(int cmdId, bool onOffTag, const std::string& msg); + void PowerRequest(int cmdId, const std::string& msg); + void PowerRequestEx(int cmdId, bool onOffTag, const std::string& msg); + void PowerLimitBoost(bool onOffTag, const std::string& msg); + void ThermalRequest(int cmdId, const std::string& msg); + void ThermalRequestEx(int cmdId, bool onOffTag, const std::string& msg); + void ThermalLimitBoost(bool onOffTag, const std::string& msg); + +public: + SocPerf(); + ~SocPerf(); + +private: + std::unordered_map> perfActionInfo; + std::unordered_map> powerActionInfo; + std::unordered_map> thermalActionInfo; + std::vector> handlers; + bool enabled = false; + + std::unordered_map> resNodeInfo; + std::unordered_map> govResNodeInfo; + std::unordered_map resStrToIdInfo; + +private: + bool LoadConfigXmlFile(std::string configFile); + bool CreateHandlers(); + void InitHandlerThreads(); + bool LoadResource(xmlNode* rootNode, std::string configFile); + bool LoadGovResource(xmlNode* rootNode, std::string configFile); + bool LoadCmd(xmlNode* rootNode, std::string configFile); + bool CheckResourceTag(char* id, char* name, char* pair, char* mode, std::string configFile); + bool CheckResourceTag(char* def, char* path, std::string configFile); + bool LoadResourceAvailable(std::shared_ptr resNode, char* node); + bool CheckPairResIdValid(); + bool CheckResDefValid(); + bool CheckGovResourceTag(char* id, char* name, std::string configFile); + bool LoadGovResourceAvailable(std::shared_ptr govResNode, char* level, char* node); + bool CheckGovResDefValid(); + bool CheckCmdTag(char* id, char* name, std::string configFile); + bool CheckActionResIdAndValueValid(std::string configFile); + void DoFreqAction(std::shared_ptr action, int onOff, int actionType); + void PrintCachedInfo(); +}; +} // namespace SOCPERF +} // namespace OHOS + +#endif // SOC_PERF_H \ No newline at end of file diff --git a/soc_perf/include/core/socperf_handler.h b/soc_perf/include/core/socperf_handler.h new file mode 100644 index 00000000..55709fe4 --- /dev/null +++ b/soc_perf/include/core/socperf_handler.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2021 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_HANDLER_H +#define SOC_PERF_HANDLER_H + +#include "event_handler.h" +#include "event_runner.h" +#include "socperf_common.h" +#include +#include +#include +#include +#include + +namespace OHOS { +namespace SOCPERF { +class SocPerfHandler : public AppExecFwk::EventHandler { +public: + explicit SocPerfHandler(const std::shared_ptr& runner); + virtual ~SocPerfHandler() override; + virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) override; + +private: + std::unordered_map> resNodeInfo; + std::unordered_map> govResNodeInfo; + std::unordered_map> resStatusInfo; + bool powerLimitBoost = false; + bool thermalLimitBoost = false; + +private: + void UpdateResActionList(int resId, std::shared_ptr resAction, bool delayed); + void UpdateCandidatesValue(int resId, int type); + void ArbitrateCandidate(int resId); + void ArbitratePairRes(int resId); + void UpdatePairResValue(int minResId, int minResValue, int maxResId, int maxResValue); + void UpdateCurrentValue(int resId, int value); + void WriteNode(std::string path, std::string value); + bool ExistNoCandidate(int resId, std::shared_ptr resStatus, int perf, int power, int thermal); + bool IsGovResId(int resId); + bool IsValidResId(int resId); +}; +} // namespace SOCPERF +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/soc_perf/include/server/socperf_server.h b/soc_perf/include/server/socperf_server.h new file mode 100644 index 00000000..e37b71e7 --- /dev/null +++ b/soc_perf/include/server/socperf_server.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2021 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_SERVER_H +#define SOC_PERF_SERVER_H + +#include "socperf_service.h" +#include "socperf_stub.h" +#include "socperf.h" + +namespace OHOS { +namespace SOCPERF { +class SocPerfServer : public SystemAbility, public SocPerfStub { +DECLARE_SYSTEM_ABILITY(SocPerfServer); + +public: + void PerfRequest(int cmdId, const std::string& msg) override; + void PerfRequestEx(int cmdId, bool onOffTag, const std::string& msg) override; + void PowerRequest(int cmdId, const std::string& msg) override; + void PowerRequestEx(int cmdId, bool onOffTag, const std::string& msg) override; + void PowerLimitBoost(bool onOffTag, const std::string& msg) override; + void ThermalRequest(int cmdId, const std::string& msg) override; + void ThermalRequestEx(int cmdId, bool onOffTag, const std::string& msg) override; + void ThermalLimitBoost(bool onOffTag, const std::string& msg) override; + +public: + SocPerfServer(int32_t systemAbilityId, bool runOnCreate) + : SystemAbility(systemAbilityId, runOnCreate) {} + ~SocPerfServer() {} + +protected: + void OnStart() override; + void OnStop() override; + +private: + SocPerf socPerf; +}; +} // namespace SOCPERF +} // namespace OHOS + +#endif // SOC_PERF_SERVER_H \ No newline at end of file diff --git a/soc_perf/include/server/socperf_stub.h b/soc_perf/include/server/socperf_stub.h new file mode 100644 index 00000000..1b44b2d7 --- /dev/null +++ b/soc_perf/include/server/socperf_stub.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 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_STUB_H +#define SOC_PERF_STUB_H + +#include "socperf_service.h" + +namespace OHOS { +namespace SOCPERF { +class SocPerfStub : public IRemoteStub { +public: + virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) override; + +public: + SocPerfStub() {} + ~SocPerfStub() {} +}; +} // namespace SOCPERF +} // namespace OHOS + +#endif // SOC_PERF_STUB_H \ No newline at end of file diff --git a/soc_perf/include/socperf_common.h b/soc_perf/include/socperf_common.h new file mode 100644 index 00000000..edd776c6 --- /dev/null +++ b/soc_perf/include/socperf_common.h @@ -0,0 +1,361 @@ +/* + * Copyright (c) 2021 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_H +#define SOC_PERF_COMMON_H + +#include +#include +#include +#include +#include "hilog/log.h" + +namespace OHOS { +namespace SOCPERF { +#define LOG_TAG_SOC_PERF "socperf" +#define LOG_TAG_DOMAIN_ID_SOC_PERF 0xD001700 + +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 int INNER_EVENT_ID_INIT_RES_NODE_INFO = 0; + const int INNER_EVENT_ID_INIT_GOV_RES_NODE_INFO = 1; + const int INNER_EVENT_ID_DO_FREQ_ACTION = 2; + const int INNER_EVENT_ID_DO_FREQ_ACTION_DELAYED = 3; + const int INNER_EVENT_ID_POWER_LIMIT_BOOST_FREQ = 4; + const int INNER_EVENT_ID_THERMAL_LIMIT_BOOST_FREQ = 5; +} + +namespace { + const std::string SOCPERF_RESOURCE_CONFIG_XML = "/system/etc/socperf/socperf_resource_config.xml"; + const std::string SOCPERF_BOOST_CONFIG_XML = "/system/etc/socperf/socperf_boost_config.xml"; + const std::string SOCPERF_POWER_CONFIG_XML = "/system/etc/socperf/socperf_power_config.xml"; + const std::string SOCPERF_THERMAL_CONFIG_XML = "/system/etc/socperf/socperf_thermal_config.xml"; + const int MAX_INT_VALUE = 0x7FFFFFFF; + const int MIN_INT_VALUE = 0x80000000; + const int INVALID_VALUE = -1; + const int MAX_HANDLER_THREADS = 5; + const int MIN_RESOURCE_ID = 1000; + const int MAX_RESOURCE_ID = 5999; +} + +class ResNode { +public: + int id; + std::string name; + int def; + std::string path; + int mode; + int pair; + std::unordered_set available; + +public: + ResNode(int resId, std::string resName, int resMode, int resPair) + { + id = resId; + name = resName; + mode = resMode; + pair = resPair; + def = INVALID_VALUE; + } + ~ResNode() {} + + void PrintString() + { + SOC_PERF_LOGD("resNode-> id: [%{public}d], name: [%{public}s]", id, name.c_str()); + SOC_PERF_LOGD(" path: [%{public}s]", path.c_str()); + SOC_PERF_LOGD(" def: [%{public}d], mode: [%{public}d], pair: [%{public}d]", def, mode, pair); + std::string str; + str.append("available(").append(std::to_string((int)available.size())).append("): "); + str.append("["); + for (auto validValue : available) { + str.append(std::to_string(validValue)).append(","); + } + if (!available.empty()) { + str.pop_back(); + } + str.append("]"); + SOC_PERF_LOGD(" %{public}s", str.c_str()); + } +}; + +class GovResNode { +public: + int id; + std::string name; + int def; + std::vector paths; + std::unordered_set available; + std::unordered_map> levelToStr; + +public: + GovResNode(int govResId, std::string govResName) + { + id = govResId; + name = govResName; + def = INVALID_VALUE; + } + ~GovResNode() {} + + void PrintString() + { + SOC_PERF_LOGD("govResNode-> id: [%{public}d], name: [%{public}s]", id, name.c_str()); + SOC_PERF_LOGD(" def: [%{public}d]", def); + for (auto path : paths) { + SOC_PERF_LOGD(" path: [%{public}s]", path.c_str()); + } + std::string str; + str.append("available(").append(std::to_string((int)available.size())).append("): "); + str.append("["); + for (auto validValue : available) { + str.append(std::to_string(validValue)).append(","); + } + if (!available.empty()) { + str.pop_back(); + } + str.append("]"); + SOC_PERF_LOGD(" %{public}s", str.c_str()); + for (auto iter = levelToStr.begin(); iter != levelToStr.end(); ++iter) { + std::string str2; + int level = iter->first; + std::vector result = iter->second; + for (int i = 0; i < (int)result.size(); i++) { + str2.append(result[i]).append(","); + } + if (!result.empty()) { + str2.pop_back(); + } + SOC_PERF_LOGD(" %{public}d: [%{public}s]", level, str2.c_str()); + } + } +}; + +class Action { +public: + int id; + std::string name; + int duration; + std::vector variable; + +public: + Action(int cmdId, std::string cmdName) + { + id = cmdId; + name = cmdName; + duration = INVALID_VALUE; + } + ~Action() {} + + void PrintString() + { + SOC_PERF_LOGD("action-> id: [%{public}d], name: [%{public}s]", id, name.c_str()); + SOC_PERF_LOGD(" duration: [%{public}d]", duration); + std::string str; + str.append("variable(").append(std::to_string((int)variable.size())).append("): ["); + for (int i = 0; i < (int)variable.size(); i++) { + str.append(std::to_string(variable[i])).append(","); + } + if (!variable.empty()) { + str.pop_back(); + } + str.append("]"); + SOC_PERF_LOGD(" %{public}s", str.c_str()); + } +}; + +class ResAction { +public: + int value; + int duration; + int type; + int onOff; + +public: + ResAction(int resActionValue, int resActionDuration, int resActionType, int resActionOnOff) + { + value = resActionValue; + duration = resActionDuration; + type = resActionType; + onOff = resActionOnOff; + } + ~ResAction() {} + + bool TotalSame(std::shared_ptr resAction) + { + if (value == resAction->value + && duration == resAction->duration + && type == resAction->type + && onOff == resAction->onOff) { + return true; + } + return false; + } + + bool PartSame(std::shared_ptr resAction) + { + if (value == resAction->value + && duration == resAction->duration + && type == resAction->type) { + return true; + } + return false; + } +}; + +class ResStatus { +public: + std::vector>> resActionList; + std::vector candidates; + int candidate; + int current; + +public: + ResStatus(int val) + { + resActionList = std::vector>>(ACTION_TYPE_MAX); + candidates = std::vector(ACTION_TYPE_MAX); + candidates[ACTION_TYPE_PERF] = INVALID_VALUE; + candidates[ACTION_TYPE_POWER] = INVALID_VALUE; + candidates[ACTION_TYPE_THERMAL] = INVALID_VALUE; + candidate = val; + current = val; + } + ~ResStatus() {} + + std::string ToString() + { + std::string str; + str.append("perf:["); + for (auto iter = resActionList[ACTION_TYPE_PERF].begin(); + iter != resActionList[ACTION_TYPE_PERF].end(); ++iter) { + str.append(std::to_string((*iter)->value)).append(","); + } + if (!resActionList[ACTION_TYPE_PERF].empty()) { + str.pop_back(); + } + str.append("]power:["); + for (auto iter = resActionList[ACTION_TYPE_POWER].begin(); + iter != resActionList[ACTION_TYPE_POWER].end(); ++iter) { + str.append(std::to_string((*iter)->value)).append(","); + } + if (!resActionList[ACTION_TYPE_POWER].empty()) { + str.pop_back(); + } + str.append("]thermal:["); + for (auto iter = resActionList[ACTION_TYPE_THERMAL].begin(); + iter != resActionList[ACTION_TYPE_THERMAL].end(); ++iter) { + str.append(std::to_string((*iter)->value)).append(","); + } + if (!resActionList[ACTION_TYPE_THERMAL].empty()) { + str.pop_back(); + } + str.append("]candidates["); + for (auto iter = candidates.begin(); iter != candidates.end(); ++iter) { + str.append(std::to_string(*iter)).append(","); + } + str.pop_back(); + str.append("]candidate[").append(std::to_string(candidate)); + str.append("]current[").append(std::to_string(current)).append("]"); + return str; + } +}; + +static inline int Max(int num1, int num2) +{ + if (num1 >= num2) { + return num1; + } + return num2; +} + +static inline int Max(int num1, int num2, int num3) +{ + return Max(Max(num1, num2), num3); +} + +static inline int Min(int num1, int num2) +{ + if (num1 <= num2) { + return num1; + } + return num2; +} + +static inline int Min(int num1, int num2, int num3) +{ + return Min(Min(num1, num2), num3); +} + +static inline bool IsNumber(std::string str) +{ + for (int i = 0; i < (int)str.size(); i++) { + if (str.at(i) < '0' || str.at(i) > '9') { + return false; + } + } + return true; +} + +static inline bool IsValidResId(int id) +{ + if (id < MIN_RESOURCE_ID || id > MAX_RESOURCE_ID) { + return false; + } + return true; +} + +static inline std::vector Split(std::string str, std::string pattern) +{ + int position; + std::vector result; + str += pattern; + int length = str.size(); + for (int i = 0; i < length; i++) { + position = (int)str.find(pattern, i); + if (position < length) { + std::string tmp = str.substr(i, position - i); + result.push_back(tmp); + i = position + pattern.size() - 1; + } + } + return result; +} +} // namespace SOCPERF +} // namespace OHOS + +#endif // SOC_PERF_COMMON_H \ No newline at end of file diff --git a/soc_perf/include/socperf_service.h b/soc_perf/include/socperf_service.h new file mode 100644 index 00000000..ccc06c69 --- /dev/null +++ b/soc_perf/include/socperf_service.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2021 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_ISERVICE_H +#define SOC_PERF_ISERVICE_H + +#include +#include "iremote_broker.h" +#include "iremote_stub.h" +#include "iremote_proxy.h" +#include "iremote_object.h" +#include "system_ability.h" +#include "system_ability_definition.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "socperf_common.h" + +namespace OHOS { +namespace SOCPERF { +class ISocPerfService : public IRemoteBroker { +public: + virtual void PerfRequest(int cmdId, const std::string& msg) = 0; + virtual void PerfRequestEx(int cmdId, bool onOffTag, const std::string& msg) = 0; + virtual void PowerRequest(int cmdId, const std::string& msg) = 0; + virtual void PowerRequestEx(int cmdId, bool onOffTag, const std::string& msg) = 0; + virtual void PowerLimitBoost(bool onOffTag, const std::string& msg) = 0; + virtual void ThermalRequest(int cmdId, const std::string& msg) = 0; + virtual void ThermalRequestEx(int cmdId, bool onOffTag, const std::string& msg) = 0; + virtual void ThermalLimitBoost(bool onOffTag, const std::string& msg) = 0; + +public: + enum { + TRANS_IPC_ID_PERF_REQUEST = 0x0001, + TRANS_IPC_ID_PERF_REQUEST_EX = 0x0002, + TRANS_IPC_ID_POWER_REQUEST = 0x0003, + TRANS_IPC_ID_POWER_REQUEST_EX = 0x0004, + TRANS_IPC_ID_POWER_LIMIT_BOOST_FREQ = 0x0005, + TRANS_IPC_ID_THERMAL_REQUEST = 0x0006, + TRANS_IPC_ID_THERMAL_REQUEST_EX = 0x0007, + TRANS_IPC_ID_THERMAL_LIMIT_BOOST_FREQ = 0x0008, + }; + +public: + DECLARE_INTERFACE_DESCRIPTOR(u"Resourceschedule.ISocPerfService"); +}; +} // namespace SOCPERF +} // namespace OHOS + +#endif // SOC_PERF_ISERVICE_H \ No newline at end of file diff --git a/soc_perf/init/socperf_service.cfg b/soc_perf/init/socperf_service.cfg new file mode 100644 index 00000000..ee921e38 --- /dev/null +++ b/soc_perf/init/socperf_service.cfg @@ -0,0 +1,16 @@ +{ + "jobs" : [{ + "name" : "post-fs-data", + "cmds" : [ + "start socperf_service" + ] + } + ], + "services" : [{ + "name" : "socperf_service", + "path" : ["/system/bin/sa_main", "/system/profile/socperf_service.xml"], + "uid" : "root", + "gid" : ["root", "shell"] + } + ] +} \ No newline at end of file diff --git a/soc_perf/sa_profile/1902.xml b/soc_perf/sa_profile/1902.xml new file mode 100644 index 00000000..b775f75e --- /dev/null +++ b/soc_perf/sa_profile/1902.xml @@ -0,0 +1,11 @@ + + + socperf_service + + 1902 + libsocperf_server.z.so + true + false + 1 + + diff --git a/soc_perf/src/client/socperf_client.cpp b/soc_perf/src/client/socperf_client.cpp new file mode 100644 index 00000000..4a107ca7 --- /dev/null +++ b/soc_perf/src/client/socperf_client.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2021 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_client.h" +#include + +namespace OHOS { +namespace SOCPERF { +SocPerfClient& SocPerfClient::GetInstance() +{ + static SocPerfClient instance; + return instance; +} + +bool SocPerfClient::CheckClientValid() +{ + if (proxy != nullptr) { + return true; + } + + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + SOC_PERF_LOGE("Failed to get SystemAbilityManager."); + return false; + } + + sptr object = samgr->GetSystemAbility(RESSCHEDD_SA_ID); + if (object == nullptr) { + SOC_PERF_LOGE("Failed to get SystemAbility[1902] ."); + return false; + } + + proxy = iface_cast(object); + if (proxy == nullptr || (proxy->AsObject() == nullptr)) { + SOC_PERF_LOGE("Failed to get SocPerfClient."); + return false; + } + + recipient_ = new SocPerfDeathRecipient(*this); + if (recipient_ == nullptr) { + return false; + } + proxy->AsObject()->AddDeathRecipient(recipient_); + + return true; +} + +void SocPerfClient::ResetClient() +{ + if ((proxy != nullptr) && (proxy->AsObject() != nullptr)) { + proxy->AsObject()->RemoveDeathRecipient(recipient_); + } + proxy = nullptr; +} + +SocPerfClient::SocPerfDeathRecipient::SocPerfDeathRecipient(SocPerfClient &socPerfClient) + : socPerfClient_(socPerfClient){}; + +SocPerfClient::SocPerfDeathRecipient::~SocPerfDeathRecipient(){}; + +void SocPerfClient::SocPerfDeathRecipient::OnRemoteDied(const wptr &remote) +{ + socPerfClient_.ResetClient(); +} + +std::string SocPerfClient::AddPidAndTidInfo(const std::string& msg) +{ + std::string str; + int pid = getpid(); + int tid = gettid(); + str.append("pid=").append(std::to_string(pid)).append("|"); + str.append("tid=").append(std::to_string(tid)); + if (msg.size() > 0) { + str.append("|").append(msg); + } + return str; +} + +void SocPerfClient::PerfRequest(int cmdId, const std::string& msg) +{ + if (!CheckClientValid()) { + return; + } + std::string newMsg = AddPidAndTidInfo(msg); + proxy->PerfRequest(cmdId, newMsg); +} + +void SocPerfClient::PerfRequestEx(int cmdId, bool onOffTag, const std::string& msg) +{ + if (!CheckClientValid()) { + return; + } + std::string newMsg = AddPidAndTidInfo(msg); + proxy->PerfRequestEx(cmdId, onOffTag, newMsg); +} + +void SocPerfClient::PowerRequest(int cmdId, const std::string& msg) +{ + if (!CheckClientValid()) { + return; + } + std::string newMsg = AddPidAndTidInfo(msg); + proxy->PowerRequest(cmdId, newMsg); +} + +void SocPerfClient::PowerRequestEx(int cmdId, bool onOffTag, const std::string& msg) +{ + if (!CheckClientValid()) { + return; + } + std::string newMsg = AddPidAndTidInfo(msg); + proxy->PowerRequestEx(cmdId, onOffTag, newMsg); +} + +void SocPerfClient::PowerLimitBoost(bool onOffTag, const std::string& msg) +{ + if (!CheckClientValid()) { + return; + } + std::string newMsg = AddPidAndTidInfo(msg); + proxy->PowerLimitBoost(onOffTag, newMsg); +} + +void SocPerfClient::ThermalRequest(int cmdId, const std::string& msg) +{ + if (!CheckClientValid()) { + return; + } + std::string newMsg = AddPidAndTidInfo(msg); + proxy->ThermalRequest(cmdId, newMsg); +} + +void SocPerfClient::ThermalRequestEx(int cmdId, bool onOffTag, const std::string& msg) +{ + if (!CheckClientValid()) { + return; + } + std::string newMsg = AddPidAndTidInfo(msg); + proxy->ThermalRequestEx(cmdId, onOffTag, newMsg); +} + +void SocPerfClient::ThermalLimitBoost(bool onOffTag, const std::string& msg) +{ + if (!CheckClientValid()) { + return; + } + std::string newMsg = AddPidAndTidInfo(msg); + proxy->ThermalLimitBoost(onOffTag, newMsg); +} +} // namespace SOCPERF +} // namespace OHOS \ No newline at end of file diff --git a/soc_perf/src/client/socperf_proxy.cpp b/soc_perf/src/client/socperf_proxy.cpp new file mode 100644 index 00000000..612685d1 --- /dev/null +++ b/soc_perf/src/client/socperf_proxy.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2021 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_proxy.h" + +namespace OHOS { +namespace SOCPERF { +void SocPerfProxy::PerfRequest(int cmdId, const std::string& msg) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInt32(cmdId); + data.WriteString(msg); + Remote()->SendRequest(TRANS_IPC_ID_PERF_REQUEST, data, reply, option); +} + +void SocPerfProxy::PerfRequestEx(int cmdId, bool onOffTag, const std::string& msg) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInt32(cmdId); + data.WriteBool(onOffTag); + data.WriteString(msg); + Remote()->SendRequest(TRANS_IPC_ID_PERF_REQUEST_EX, data, reply, option); +} + +void SocPerfProxy::PowerRequest(int cmdId, const std::string& msg) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInt32(cmdId); + data.WriteString(msg); + Remote()->SendRequest(TRANS_IPC_ID_POWER_REQUEST, data, reply, option); +} + +void SocPerfProxy::PowerRequestEx(int cmdId, bool onOffTag, const std::string& msg) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInt32(cmdId); + data.WriteBool(onOffTag); + data.WriteString(msg); + Remote()->SendRequest(TRANS_IPC_ID_POWER_REQUEST_EX, data, reply, option); +} + +void SocPerfProxy::PowerLimitBoost(bool onOffTag, const std::string& msg) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteBool(onOffTag); + data.WriteString(msg); + Remote()->SendRequest(TRANS_IPC_ID_POWER_LIMIT_BOOST_FREQ, data, reply, option); +} + +void SocPerfProxy::ThermalRequest(int cmdId, const std::string& msg) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInt32(cmdId); + data.WriteString(msg); + Remote()->SendRequest(TRANS_IPC_ID_THERMAL_REQUEST, data, reply, option); +} + +void SocPerfProxy::ThermalRequestEx(int cmdId, bool onOffTag, const std::string& msg) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInt32(cmdId); + data.WriteBool(onOffTag); + data.WriteString(msg); + Remote()->SendRequest(TRANS_IPC_ID_THERMAL_REQUEST_EX, data, reply, option); +} + +void SocPerfProxy::ThermalLimitBoost(bool onOffTag, const std::string& msg) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteBool(onOffTag); + data.WriteString(msg); + Remote()->SendRequest(TRANS_IPC_ID_THERMAL_LIMIT_BOOST_FREQ, data, reply, option); +} +} // namespace SOCPERF +} // namespace OHOS \ No newline at end of file diff --git a/soc_perf/src/core/socperf.cpp b/soc_perf/src/core/socperf.cpp new file mode 100644 index 00000000..5f8f1475 --- /dev/null +++ b/soc_perf/src/core/socperf.cpp @@ -0,0 +1,615 @@ +/* + * Copyright (c) 2021 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.h" + +namespace OHOS { +namespace SOCPERF { +SocPerf::SocPerf() +{ +} + +SocPerf::~SocPerf() +{ +} + +bool SocPerf::Init() +{ + if (!LoadConfigXmlFile(SOCPERF_RESOURCE_CONFIG_XML)) { + SOC_PERF_LOGE("Failed to load %{public}s", SOCPERF_RESOURCE_CONFIG_XML.c_str()); + return false; + } + + if (!LoadConfigXmlFile(SOCPERF_BOOST_CONFIG_XML)) { + SOC_PERF_LOGE("Failed to load %{public}s", SOCPERF_BOOST_CONFIG_XML.c_str()); + return false; + } + + if (!LoadConfigXmlFile(SOCPERF_POWER_CONFIG_XML)) { + SOC_PERF_LOGE("Failed to load %{public}s", SOCPERF_POWER_CONFIG_XML.c_str()); + return false; + } + + if (!LoadConfigXmlFile(SOCPERF_THERMAL_CONFIG_XML)) { + SOC_PERF_LOGE("Failed to load %{public}s", SOCPERF_THERMAL_CONFIG_XML.c_str()); + return false; + } + + PrintCachedInfo(); + + if (!CreateHandlers()) { + SOC_PERF_LOGE("Failed to create handler threads"); + return false; + } + + InitHandlerThreads(); + + resNodeInfo.clear(); + govResNodeInfo.clear(); + resStrToIdInfo.clear(); + + enabled = true; + return true; +} + +void SocPerf::PerfRequest(int cmdId, const std::string& msg) +{ + if (!enabled) { + SOC_PERF_LOGE("SocPerf disabled!"); + return; + } + if (perfActionInfo.find(cmdId) == perfActionInfo.end() + || perfActionInfo[cmdId]->duration == 0) { + SOC_PERF_LOGE("Invalid PerfRequest cmdId[%{public}d]", cmdId); + return; + } + SOC_PERF_LOGD("PerfRequest cmdId[%{public}d]msg[%{public}s]", cmdId, msg.c_str()); + DoFreqAction(perfActionInfo[cmdId], EVENT_INVALID, ACTION_TYPE_PERF); +} + +void SocPerf::PerfRequestEx(int cmdId, bool onOffTag, const std::string& msg) +{ + if (!enabled) { + SOC_PERF_LOGE("SocPerf disabled!"); + return; + } + if (perfActionInfo.find(cmdId) == perfActionInfo.end()) { + SOC_PERF_LOGE("Invalid PerfRequestEx cmdId[%{public}d]", cmdId); + return; + } + SOC_PERF_LOGD("PerfRequestEx cmdId[%{public}d]onOffTag[%{public}d]msg[%{public}s]", + cmdId, onOffTag, msg.c_str()); + DoFreqAction(perfActionInfo[cmdId], onOffTag ? EVENT_ON : EVENT_OFF, ACTION_TYPE_PERF); +} + +void SocPerf::PowerRequest(int cmdId, const std::string& msg) +{ + if (!enabled) { + SOC_PERF_LOGE("SocPerf disabled!"); + return; + } + if (powerActionInfo.find(cmdId) == powerActionInfo.end() + || powerActionInfo[cmdId]->duration == 0) { + SOC_PERF_LOGE("Invalid PowerRequest cmdId[%{public}d]", cmdId); + return; + } + SOC_PERF_LOGD("PowerRequest cmdId[%{public}d]msg[%{public}s]", cmdId, msg.c_str()); + DoFreqAction(powerActionInfo[cmdId], EVENT_INVALID, ACTION_TYPE_POWER); +} + +void SocPerf::PowerRequestEx(int cmdId, bool onOffTag, const std::string& msg) +{ + if (!enabled) { + SOC_PERF_LOGE("SocPerf disabled!"); + return; + } + if (powerActionInfo.find(cmdId) == powerActionInfo.end()) { + SOC_PERF_LOGE("Invalid PowerRequestEx cmdId[%{public}d]", cmdId); + return; + } + SOC_PERF_LOGD("PowerRequestEx cmdId[%{public}d]onOffTag[%{public}d]msg[%{public}s]", + cmdId, onOffTag, msg.c_str()); + DoFreqAction(powerActionInfo[cmdId], onOffTag ? EVENT_ON : EVENT_OFF, ACTION_TYPE_POWER); +} + +void SocPerf::PowerLimitBoost(bool onOffTag, const std::string& msg) +{ + if (!enabled) { + SOC_PERF_LOGE("SocPerf disabled!"); + return; + } + SOC_PERF_LOGD("PowerLimitBoost onOffTag[%{public}d]msg[%{public}s]", onOffTag, msg.c_str()); + for (auto handler : handlers) { + auto event = AppExecFwk::InnerEvent::Get(INNER_EVENT_ID_POWER_LIMIT_BOOST_FREQ, onOffTag ? 1 : 0); + handler->SendEvent(event); + } +} + +void SocPerf::ThermalRequest(int cmdId, const std::string& msg) +{ + if (!enabled) { + SOC_PERF_LOGE("SocPerf disabled!"); + return; + } + if (thermalActionInfo.find(cmdId) == thermalActionInfo.end() + || thermalActionInfo[cmdId]->duration == 0) { + SOC_PERF_LOGE("Invalid ThermalRequest cmdId[%{public}d]", cmdId); + return; + } + SOC_PERF_LOGD("ThermalRequest cmdId[%{public}d]msg[%{public}s]", cmdId, msg.c_str()); + DoFreqAction(thermalActionInfo[cmdId], EVENT_INVALID, ACTION_TYPE_THERMAL); +} + +void SocPerf::ThermalRequestEx(int cmdId, bool onOffTag, const std::string& msg) +{ + if (!enabled) { + SOC_PERF_LOGE("SocPerf disabled!"); + return; + } + if (thermalActionInfo.find(cmdId) == thermalActionInfo.end()) { + SOC_PERF_LOGE("Invalid ThermalRequestEx cmdId[%{public}d]", cmdId); + return; + } + SOC_PERF_LOGD("ThermalRequestEx cmdId[%{public}d]onOffTag[%{public}d]msg[%{public}s]", + cmdId, onOffTag, msg.c_str()); + DoFreqAction(thermalActionInfo[cmdId], onOffTag ? EVENT_ON : EVENT_OFF, ACTION_TYPE_THERMAL); +} + +void SocPerf::ThermalLimitBoost(bool onOffTag, const std::string& msg) +{ + if (!enabled) { + SOC_PERF_LOGE("SocPerf disabled!"); + return; + } + SOC_PERF_LOGD("ThermalLimitBoost onOffTag[%{public}d]msg[%{public}s]", onOffTag, msg.c_str()); + for (auto handler : handlers) { + auto event = AppExecFwk::InnerEvent::Get(INNER_EVENT_ID_THERMAL_LIMIT_BOOST_FREQ, onOffTag ? 1 : 0); + handler->SendEvent(event); + } +} + +void SocPerf::DoFreqAction(std::shared_ptr action, int onOff, int actionType) +{ + for (int i = 0; i < (int)action->variable.size(); i += 2) { + auto resAction = std::make_shared(action->variable[i + 1], action->duration, actionType, onOff); + auto event = AppExecFwk::InnerEvent::Get(INNER_EVENT_ID_DO_FREQ_ACTION, resAction, action->variable[i]); + handlers[action->variable[i] / 1000 - 1]->SendEvent(event); + } +} + +bool SocPerf::LoadConfigXmlFile(std::string configFile) +{ + xmlKeepBlanksDefault(0); + xmlDoc* file = xmlReadFile(configFile.c_str(), nullptr, 0); + if (file == nullptr) { + SOC_PERF_LOGE("Failed to open xml file"); + return false; + } + xmlNode* rootNode = xmlDocGetRootElement(file); + if (rootNode == nullptr) { + SOC_PERF_LOGE("Failed to get xml file's RootNode"); + return false; + } + if (!xmlStrcmp(rootNode->name, reinterpret_cast("Configs"))) { + if (configFile == SOCPERF_RESOURCE_CONFIG_XML) { + xmlNode* child = rootNode->children; + for (; child; child = child->next) { + if (!xmlStrcmp(child->name, reinterpret_cast("Resource"))) { + if (!LoadResource(child, configFile)) { + return false; + } + } else if (!xmlStrcmp(child->name, reinterpret_cast("GovResource"))) { + if (!LoadGovResource(child, configFile)) { + return false; + } + } + } + } else { + if (!LoadCmd(rootNode, configFile)) { + return false; + } + } + } else { + SOC_PERF_LOGE("Wrong format for xml file"); + return false; + } + xmlFreeDoc(file); + SOC_PERF_LOGD("Success to Load %{public}s", configFile.c_str()); + return true; +} + +bool SocPerf::CreateHandlers() +{ + handlers = std::vector>(MAX_HANDLER_THREADS); + std::string threadName = "socperf_handler"; + for (int i = 0; i < (int)handlers.size(); i++) { + auto runner = AppExecFwk::EventRunner::Create(threadName); + if (runner == nullptr) { + SOC_PERF_LOGE("Failed to Create EventRunner"); + return false; + } + handlers[i] = std::make_shared(runner); + SOC_PERF_LOGD("Success to Create SocPerfHandler"); + } + SOC_PERF_LOGD("Success to Create All Handler threads"); + return true; +} + +void SocPerf::InitHandlerThreads() +{ + for (auto iter = resNodeInfo.begin(); iter != resNodeInfo.end(); ++iter) { + std::shared_ptr resNode = iter->second; + auto event = AppExecFwk::InnerEvent::Get(INNER_EVENT_ID_INIT_RES_NODE_INFO, resNode); + handlers[resNode->id / 1000 - 1]->SendEvent(event); + } + for (auto iter = govResNodeInfo.begin(); iter != govResNodeInfo.end(); ++iter) { + std::shared_ptr govResNode = iter->second; + auto event = AppExecFwk::InnerEvent::Get(INNER_EVENT_ID_INIT_GOV_RES_NODE_INFO, govResNode); + handlers[govResNode->id / 1000 - 1]->SendEvent(event); + } +} + +bool SocPerf::LoadResource(xmlNode* child, std::string configFile) +{ + xmlNode* grandson = child->children; + for (; grandson; grandson = grandson->next) { + if (!xmlStrcmp(grandson->name, reinterpret_cast("res"))) { + char* id = reinterpret_cast(xmlGetProp(grandson, reinterpret_cast("id"))); + char* name = reinterpret_cast(xmlGetProp(grandson, reinterpret_cast("name"))); + char* pair = reinterpret_cast(xmlGetProp(grandson, reinterpret_cast("pair"))); + char* mode = reinterpret_cast(xmlGetProp(grandson, reinterpret_cast("mode"))); + if (!CheckResourceTag(id, name, pair, mode, configFile)) { + return false; + } + xmlNode* greatGrandson = grandson->children; + std::shared_ptr resNode = std::make_shared( + atoi(id), name, (mode != nullptr) ? atoi(mode) : 0, (pair != nullptr) ? atoi(pair) : INVALID_VALUE); + char *def = nullptr; + char *path = nullptr; + char *node = nullptr; + for (; greatGrandson; greatGrandson = greatGrandson->next) { + if (!xmlStrcmp(greatGrandson->name, reinterpret_cast("default"))) { + def = reinterpret_cast(xmlNodeGetContent(greatGrandson)); + } else if (!xmlStrcmp(greatGrandson->name, reinterpret_cast("path"))) { + path = reinterpret_cast(xmlNodeGetContent(greatGrandson)); + } else if (!xmlStrcmp(greatGrandson->name, reinterpret_cast("node"))) { + node = reinterpret_cast(xmlNodeGetContent(greatGrandson)); + } + } + if (!CheckResourceTag(def, path, configFile)) { + return false; + } + resNode->def = atoi(def); + resNode->path = path; + if (node != nullptr && !LoadResourceAvailable(resNode, node)) { + SOC_PERF_LOGE("Invalid resource node for %{public}s", configFile.c_str()); + return false; + } + + resStrToIdInfo.insert(std::pair(resNode->name, resNode->id)); + resNodeInfo.insert(std::pair>(resNode->id, resNode)); + } + } + + if (!CheckPairResIdValid() || !CheckResDefValid()) { + return false; + } + + return true; +} + +bool SocPerf::LoadGovResource(xmlNode* child, std::string configFile) +{ + xmlNode* grandson = child->children; + for (; grandson; grandson = grandson->next) { + if (!xmlStrcmp(grandson->name, reinterpret_cast("res"))) { + char* id = reinterpret_cast(xmlGetProp(grandson, reinterpret_cast("id"))); + char* name = reinterpret_cast(xmlGetProp(grandson, reinterpret_cast("name"))); + if (!CheckGovResourceTag(id, name, configFile)) { + return false; + } + xmlNode* greatGrandson = grandson->children; + std::shared_ptr govResNode = std::make_shared(atoi(id), name); + for (; greatGrandson; greatGrandson = greatGrandson->next) { + if (!xmlStrcmp(greatGrandson->name, reinterpret_cast("default"))) { + char* def = reinterpret_cast(xmlNodeGetContent(greatGrandson)); + if (def == nullptr || !IsNumber(def)) { + SOC_PERF_LOGE("Invalid governor resource default for %{public}s", configFile.c_str()); + return false; + } + govResNode->def = atoi(def); + } else if (!xmlStrcmp(greatGrandson->name, reinterpret_cast("path"))) { + char* path = reinterpret_cast(xmlNodeGetContent(greatGrandson)); + if (path == nullptr) { + SOC_PERF_LOGE("Invalid governor resource path for %{public}s", configFile.c_str()); + return false; + } + govResNode->paths.push_back(path); + } else if (!xmlStrcmp(greatGrandson->name, reinterpret_cast("node"))) { + char* level = reinterpret_cast( + xmlGetProp(greatGrandson, reinterpret_cast("level"))); + char* node = reinterpret_cast(xmlNodeGetContent(greatGrandson)); + if (level == nullptr || !IsNumber(level) || node == nullptr + || !LoadGovResourceAvailable(govResNode, level, node)) { + SOC_PERF_LOGE("Invalid governor resource node for %{public}s", configFile.c_str()); + return false; + } + } + } + + resStrToIdInfo.insert(std::pair(govResNode->name, govResNode->id)); + govResNodeInfo.insert(std::pair>(govResNode->id, govResNode)); + } + } + + if (!CheckGovResDefValid()) { + return false; + } + + return true; +} + +bool SocPerf::LoadCmd(xmlNode* rootNode, std::string configFile) +{ + xmlNode* child = rootNode->children; + for (; child; child = child->next) { + if (!xmlStrcmp(child->name, reinterpret_cast("cmd"))) { + char* id = reinterpret_cast(xmlGetProp(child, reinterpret_cast("id"))); + char* name = reinterpret_cast(xmlGetProp(child, reinterpret_cast("name"))); + if (!CheckCmdTag(id, name, configFile)) { + return false; + } + xmlNode* grandson = child->children; + std::shared_ptr action = std::make_shared(atoi(id), name); + for (; grandson; grandson = grandson->next) { + if (!xmlStrcmp(grandson->name, reinterpret_cast("duration"))) { + char* duration = reinterpret_cast(xmlNodeGetContent(grandson)); + if (duration == nullptr || !IsNumber(duration)) { + SOC_PERF_LOGE("Invalid cmd duration for %{public}s", configFile.c_str()); + return false; + } + action->duration = atoi(duration); + } else { + char* resStr = reinterpret_cast(const_cast(grandson->name)); + char* resValue = reinterpret_cast(xmlNodeGetContent(grandson)); + if (resStr == nullptr || resStrToIdInfo.find(resStr) == resStrToIdInfo.end() + || resValue == nullptr || !IsNumber(resValue)) { + SOC_PERF_LOGE("Invalid cmd resource(%{public}s) for %{public}s, cannot find resId", + resStr, configFile.c_str()); + return false; + } + action->variable.push_back(resStrToIdInfo[resStr]); + action->variable.push_back(atoi(resValue)); + } + } + + if (configFile == SOCPERF_BOOST_CONFIG_XML) { + perfActionInfo.insert(std::pair>(action->id, action)); + } else if (configFile == SOCPERF_POWER_CONFIG_XML) { + powerActionInfo.insert(std::pair>(action->id, action)); + } else if (configFile == SOCPERF_THERMAL_CONFIG_XML) { + thermalActionInfo.insert(std::pair>(action->id, action)); + } + } + } + + if (!CheckActionResIdAndValueValid(configFile)) { + return false; + } + + return true; +} + +bool SocPerf::CheckResourceTag(char* id, char* name, char* pair, char* mode, std::string configFile) +{ + if (id == nullptr || !IsNumber(id) || !IsValidResId(atoi(id))) { + SOC_PERF_LOGE("Invalid resource id for %{public}s", configFile.c_str()); + return false; + } + if (name == nullptr) { + SOC_PERF_LOGE("Invalid resource name for %{public}s", configFile.c_str()); + return false; + } + if (pair != nullptr && (!IsNumber(pair) || !IsValidResId(atoi(pair)))) { + SOC_PERF_LOGE("Invalid resource pair for %{public}s", configFile.c_str()); + return false; + } + if (mode != nullptr && !IsNumber(mode)) { + SOC_PERF_LOGE("Invalid resource mode for %{public}s", configFile.c_str()); + return false; + } + return true; +} + +bool SocPerf::CheckResourceTag(char* def, char* path, std::string configFile) +{ + if (def == nullptr || !IsNumber(def)) { + SOC_PERF_LOGE("Invalid resource default for %{public}s", configFile.c_str()); + return false; + } + if (path == nullptr) { + SOC_PERF_LOGE("Invalid resource path for %{public}s", configFile.c_str()); + return false; + } + return true; +} + +bool SocPerf::LoadResourceAvailable(std::shared_ptr resNode, char* node) +{ + std::string nodeStr = node; + std::vector result = Split(nodeStr, " "); + for (auto str : result) { + if (IsNumber(str)) { + resNode->available.insert(stoi(str)); + } else { + return false; + } + } + return true; +} + +bool SocPerf::CheckPairResIdValid() +{ + for (auto iter = resNodeInfo.begin(); iter != resNodeInfo.end(); ++iter) { + int resId = iter->first; + std::shared_ptr resNode = iter->second; + int pairResId = resNode->pair; + if (resNodeInfo.find(pairResId) == resNodeInfo.end()) { + SOC_PERF_LOGE("resId[%{public}d]'s pairResId[%{public}d] is not valid", resId, pairResId); + return false; + } + } + return true; +} + +bool SocPerf::CheckResDefValid() +{ + for (auto iter = resNodeInfo.begin(); iter != resNodeInfo.end(); ++iter) { + int resId = iter->first; + std::shared_ptr resNode = iter->second; + int def = resNode->def; + if (!resNode->available.empty() && resNode->available.find(def) == resNode->available.end()) { + SOC_PERF_LOGE("resId[%{public}d]'s def[%{public}d] is not valid", resId, def); + return false; + } + } + return true; +} + +bool SocPerf::CheckGovResourceTag(char* id, char* name, std::string configFile) +{ + if (id == nullptr || !IsNumber(id) || !IsValidResId(atoi(id))) { + SOC_PERF_LOGE("Invalid governor resource id for %{public}s", configFile.c_str()); + return false; + } + if (name == nullptr) { + SOC_PERF_LOGE("Invalid governor resource name for %{public}s", configFile.c_str()); + return false; + } + return true; +} + +bool SocPerf::LoadGovResourceAvailable(std::shared_ptr govResNode, char* level, char* node) +{ + govResNode->available.insert(atoi(level)); + std::string nodeStr = node; + std::vector result = Split(nodeStr, "|"); + if (result.size() != govResNode->paths.size()) { + SOC_PERF_LOGE("Invalid governor resource node matches paths"); + return false; + } + govResNode->levelToStr.insert(std::pair>(atoi(level), result)); + return true; +} + +bool SocPerf::CheckGovResDefValid() +{ + for (auto iter = govResNodeInfo.begin(); iter != govResNodeInfo.end(); ++iter) { + int govResId = iter->first; + std::shared_ptr govResNode = iter->second; + int def = govResNode->def; + if (govResNode->available.find(def) == govResNode->available.end()) { + SOC_PERF_LOGE("govResId[%{public}d]'s def[%{public}d] is not valid", govResId, def); + return false; + } + } + return true; +} + +bool SocPerf::CheckCmdTag(char* id, char* name, std::string configFile) +{ + if (id == nullptr || !IsNumber(id)) { + SOC_PERF_LOGE("Invalid cmd id for %{public}s", configFile.c_str()); + return false; + } + if (name == nullptr) { + SOC_PERF_LOGE("Invalid cmd name for %{public}s", configFile.c_str()); + return false; + } + return true; +} + +bool SocPerf::CheckActionResIdAndValueValid(std::string configFile) +{ + std::unordered_map> actionInfo; + if (configFile == SOCPERF_BOOST_CONFIG_XML) { + actionInfo = perfActionInfo; + } else if (configFile == SOCPERF_POWER_CONFIG_XML) { + actionInfo = powerActionInfo; + } else if (configFile == SOCPERF_THERMAL_CONFIG_XML) { + actionInfo = thermalActionInfo; + } + for (auto iter = actionInfo.begin(); iter != actionInfo.end(); ++iter) { + int actionId = iter->first; + std::shared_ptr action = iter->second; + for (int i = 0; i < (int)action->variable.size(); i += 2) { + int resId = action->variable[i]; + int resValue = action->variable[i + 1]; + if (resNodeInfo.find(resId) != resNodeInfo.end()) { + if (!resNodeInfo[resId]->available.empty() + && resNodeInfo[resId]->available.find(resValue) == resNodeInfo[resId]->available.end()) { + SOC_PERF_LOGE("action[%{public}d]'s resValue[%{public}d] is not valid", actionId, resValue); + return false; + } + } else if (govResNodeInfo.find(resId) != govResNodeInfo.end()) { + if (govResNodeInfo[resId]->available.find(resValue) == govResNodeInfo[resId]->available.end()) { + SOC_PERF_LOGE("action[%{public}d]'s resValue[%{public}d] is not valid", actionId, resValue); + return false; + } + } else { + SOC_PERF_LOGE("action[%{public}d]'s resId[%{public}d] is not valid", actionId, resId); + return false; + } + } + } + return true; +} + +void SocPerf::PrintCachedInfo() +{ + SOC_PERF_LOGD("------------------------------------"); + SOC_PERF_LOGD("resNodeInfo(%{public}d)", (int)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)", (int)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("perfActionInfo(%{public}d)", (int)perfActionInfo.size()); + for (auto iter = perfActionInfo.begin(); iter != perfActionInfo.end(); ++iter) { + std::shared_ptr action = iter->second; + action->PrintString(); + } + SOC_PERF_LOGD("------------------------------------"); + SOC_PERF_LOGD("powerActionInfo(%{public}d)", (int)powerActionInfo.size()); + for (auto iter = powerActionInfo.begin(); iter != powerActionInfo.end(); ++iter) { + std::shared_ptr action = iter->second; + action->PrintString(); + } + SOC_PERF_LOGD("------------------------------------"); + SOC_PERF_LOGD("thermalActionInfo(%{public}d)", (int)thermalActionInfo.size()); + for (auto iter = thermalActionInfo.begin(); iter != thermalActionInfo.end(); ++iter) { + std::shared_ptr action = iter->second; + action->PrintString(); + } + SOC_PERF_LOGD("------------------------------------"); +} +} // namespace SOCPERF +} // namespace OHOS \ No newline at end of file diff --git a/soc_perf/src/core/socperf_handler.cpp b/soc_perf/src/core/socperf_handler.cpp new file mode 100644 index 00000000..c5d9a93d --- /dev/null +++ b/soc_perf/src/core/socperf_handler.cpp @@ -0,0 +1,340 @@ +/* + * Copyright (c) 2021 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_handler.h" + +namespace OHOS { +namespace SOCPERF { +SocPerfHandler::SocPerfHandler( + const std::shared_ptr& runner) : AppExecFwk::EventHandler(runner) +{ +} + +SocPerfHandler::~SocPerfHandler() +{ +} + +void SocPerfHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) +{ + switch (event->GetInnerEventId()) { + case INNER_EVENT_ID_INIT_RES_NODE_INFO: { + auto resNode = event->GetSharedObject(); + resNodeInfo.insert(std::pair>(resNode->id, resNode)); + WriteNode(resNode->path, std::to_string(resNode->def)); + auto resStatus = std::make_shared(resNode->def); + resStatusInfo.insert(std::pair>(resNode->id, resStatus)); + break; + } + case INNER_EVENT_ID_INIT_GOV_RES_NODE_INFO: { + auto govResNode = event->GetSharedObject(); + govResNodeInfo.insert(std::pair>(govResNode->id, govResNode)); + for (int i = 0; i < (int)govResNode->paths.size(); i++) { + WriteNode(govResNode->paths[i], govResNode->levelToStr[govResNode->def][i]); + } + auto resStatus = std::make_shared(govResNode->def); + resStatusInfo.insert(std::pair>(govResNode->id, resStatus)); + break; + } + case INNER_EVENT_ID_DO_FREQ_ACTION: { + int resId = event->GetParam(); + if (!IsValidResId(resId)) { + return; + } + std::shared_ptr resAction = event->GetSharedObject(); + UpdateResActionList(resId, resAction, false); + break; + } + case INNER_EVENT_ID_DO_FREQ_ACTION_DELAYED: { + int resId = event->GetParam(); + if (!IsValidResId(resId)) { + return; + } + std::shared_ptr resAction = event->GetSharedObject(); + UpdateResActionList(resId, resAction, true); + break; + } + case INNER_EVENT_ID_POWER_LIMIT_BOOST_FREQ: { + powerLimitBoost = event->GetParam() == 1; + for (auto iter = resStatusInfo.begin(); iter != resStatusInfo.end(); ++iter) { + ArbitrateCandidate(iter->first); + } + break; + } + case INNER_EVENT_ID_THERMAL_LIMIT_BOOST_FREQ: { + thermalLimitBoost = event->GetParam() == 1; + for (auto iter = resStatusInfo.begin(); iter != resStatusInfo.end(); ++iter) { + ArbitrateCandidate(iter->first); + } + break; + } + default: { + break; + } + } +} + +void SocPerfHandler::UpdateResActionList(int resId, std::shared_ptr resAction, bool delayed) +{ + std::shared_ptr resStatus = resStatusInfo[resId]; + int type = resAction->type; + + if (delayed) { + for (auto iter = resStatus->resActionList[type].begin(); + iter != resStatus->resActionList[type].end(); ++iter) { + if (resAction->TotalSame(*iter)) { + resStatus->resActionList[type].erase(iter); + UpdateCandidatesValue(resId, type); + break; + } + } + } else { + switch (resAction->onOff) { + case EVENT_INVALID: { + resStatus->resActionList[type].push_back(resAction); + UpdateCandidatesValue(resId, type); + auto event = AppExecFwk::InnerEvent::Get( + INNER_EVENT_ID_DO_FREQ_ACTION_DELAYED, resAction, resId); + this->SendEvent(event, resAction->duration); + break; + } + case EVENT_ON: { + if (resAction->duration == 0) { + for (auto iter = resStatus->resActionList[type].begin(); + iter != resStatus->resActionList[type].end(); ++iter) { + if (resAction->TotalSame(*iter)) { + resStatus->resActionList[type].erase(iter); + break; + } + } + resStatus->resActionList[type].push_back(resAction); + UpdateCandidatesValue(resId, type); + } else { + resStatus->resActionList[type].push_back(resAction); + UpdateCandidatesValue(resId, type); + auto event = AppExecFwk::InnerEvent::Get( + INNER_EVENT_ID_DO_FREQ_ACTION_DELAYED, resAction, resId); + this->SendEvent(event, resAction->duration); + } + break; + } + case EVENT_OFF: { + for (auto iter = resStatus->resActionList[type].begin(); + iter != resStatus->resActionList[type].end(); ++iter) { + if (resAction->PartSame(*iter) && (*iter)->onOff == EVENT_ON) { + resStatus->resActionList[type].erase(iter); + UpdateCandidatesValue(resId, type); + break; + } + } + break; + } + default: { + break; + } + } + } +} + +void SocPerfHandler::UpdateCandidatesValue(int resId, int type) +{ + std::shared_ptr resStatus = resStatusInfo[resId]; + int prev = resStatus->candidates[type]; + + if (resStatus->resActionList[type].empty()) { + resStatus->candidates[type] = INVALID_VALUE; + } else { + if (type == ACTION_TYPE_PERF) { + int res = MIN_INT_VALUE; + for (auto iter = resStatus->resActionList[type].begin(); + iter != resStatus->resActionList[type].end(); ++iter) { + res = Max(res, (*iter)->value); + } + resStatus->candidates[type] = res; + } else { + int res = MAX_INT_VALUE; + for (auto iter = resStatus->resActionList[type].begin(); + iter != resStatus->resActionList[type].end(); ++iter) { + res = Min(res, (*iter)->value); + } + resStatus->candidates[type] = res; + } + } + + if (resStatus->candidates[type] != prev) { + ArbitrateCandidate(resId); + } +} + +void SocPerfHandler::ArbitrateCandidate(int resId) +{ + std::shared_ptr resStatus = resStatusInfo[resId]; + int candidatePerf = resStatus->candidates[ACTION_TYPE_PERF]; + int candidatePower = resStatus->candidates[ACTION_TYPE_POWER]; + int candidateThermal = resStatus->candidates[ACTION_TYPE_THERMAL]; + + if (ExistNoCandidate(resId, resStatus, candidatePerf, candidatePower, candidateThermal)) { + return; + } + + if (!powerLimitBoost && !thermalLimitBoost) { + if (candidatePerf != INVALID_VALUE) { + resStatus->candidate = Max(candidatePerf, candidatePower, candidateThermal); + } else { + resStatus->candidate = + (candidatePower == INVALID_VALUE) ? candidateThermal : + ((candidateThermal == INVALID_VALUE) ? candidatePower : Min(candidatePower, candidateThermal)); + } + } else if (!powerLimitBoost && thermalLimitBoost) { + resStatus->candidate = + (candidateThermal != INVALID_VALUE) ? candidateThermal : Max(candidatePerf, candidatePower); + } else if (powerLimitBoost && !thermalLimitBoost) { + resStatus->candidate = + (candidatePower != INVALID_VALUE) ? candidatePower : Max(candidatePerf, candidateThermal); + } else { + if (candidatePower == INVALID_VALUE && candidateThermal == INVALID_VALUE) { + resStatus->candidate = candidatePerf; + } else { + resStatus->candidate = + (candidatePower == INVALID_VALUE) ? candidateThermal : + ((candidateThermal == INVALID_VALUE) ? candidatePower : Min(candidatePower, candidateThermal)); + } + } + + ArbitratePairRes(resId); +} + +void SocPerfHandler::ArbitratePairRes(int resId) +{ + if (IsGovResId(resId)) { + UpdateCurrentValue(resId, resStatusInfo[resId]->candidate); + return; + } + + int pairResId = resNodeInfo[resId]->pair; + if (pairResId == INVALID_VALUE) { + UpdateCurrentValue(resId, resStatusInfo[resId]->candidate); + return; + } + + if (resNodeInfo[resId]->mode == 1) { + if (resStatusInfo[resId]->candidate < resStatusInfo[pairResId]->candidate) { + if (powerLimitBoost || thermalLimitBoost) { + UpdatePairResValue(pairResId, + resStatusInfo[resId]->candidate, resId, resStatusInfo[resId]->candidate); + } else { + UpdatePairResValue(pairResId, + resStatusInfo[pairResId]->candidate, resId, resStatusInfo[pairResId]->candidate); + } + } else { + UpdatePairResValue(pairResId, + resStatusInfo[pairResId]->candidate, resId, resStatusInfo[resId]->candidate); + } + } else { + if (resStatusInfo[resId]->candidate > resStatusInfo[pairResId]->candidate) { + if (powerLimitBoost || thermalLimitBoost) { + UpdatePairResValue(resId, + resStatusInfo[pairResId]->candidate, pairResId, resStatusInfo[pairResId]->candidate); + } else { + UpdatePairResValue(resId, + resStatusInfo[resId]->candidate, pairResId, resStatusInfo[resId]->candidate); + } + } else { + UpdatePairResValue(resId, + resStatusInfo[resId]->candidate, pairResId, resStatusInfo[pairResId]->candidate); + } + } +} + +void SocPerfHandler::UpdatePairResValue(int minResId, int minResValue, int maxResId, int maxResValue) +{ + if (resStatusInfo[minResId]->current != minResValue) { + WriteNode(resNodeInfo[minResId]->path, std::to_string(resNodeInfo[minResId]->def)); + } + if (resStatusInfo[maxResId]->current != maxResValue) { + WriteNode(resNodeInfo[maxResId]->path, std::to_string(resNodeInfo[maxResId]->def)); + } + UpdateCurrentValue(minResId, minResValue); + UpdateCurrentValue(maxResId, maxResValue); +} + +void SocPerfHandler::UpdateCurrentValue(int resId, int currValue) +{ + if (resStatusInfo[resId]->current != currValue) { + resStatusInfo[resId]->current = currValue; + if (IsGovResId(resId)) { + SOC_PERF_LOGD("govResId->%{public}d, choose->%{public}d", resId, resStatusInfo[resId]->current); + std::vector targetStrs = govResNodeInfo[resId]->levelToStr[resStatusInfo[resId]->current]; + for (int i = 0; i < (int)govResNodeInfo[resId]->paths.size(); i++) { + WriteNode(govResNodeInfo[resId]->paths[i], targetStrs[i]); + } + } else { + SOC_PERF_LOGD("resId->%{public}d, choose->%{public}d", resId, resStatusInfo[resId]->current); + WriteNode(resNodeInfo[resId]->path, std::to_string(resStatusInfo[resId]->current)); + } + } +} + +void SocPerfHandler::WriteNode(std::string filePath, std::string value) +{ + char path[PATH_MAX + 1] = {0}; + if (filePath.size() == 0 || filePath.size() > PATH_MAX || realpath(filePath.c_str(), path) == nullptr) { + return; + } + FILE* fd = fopen(path, "w"); + if (fd == nullptr) { + return; + } + fprintf(fd, "%s", value.c_str()); + fclose(fd); + fd = nullptr; +} + +bool SocPerfHandler::ExistNoCandidate( + int resId, std::shared_ptr resStatus, int perf, int power, int thermal) +{ + if (perf == INVALID_VALUE && power == INVALID_VALUE && thermal == INVALID_VALUE) { + if (IsGovResId(resId)) { + resStatus->candidate = govResNodeInfo[resId]->def; + } else { + resStatus->candidate = resNodeInfo[resId]->def; + } + ArbitratePairRes(resId); + return true; + } + return false; +} + +bool SocPerfHandler::IsGovResId(int resId) +{ + if (resNodeInfo.find(resId) == resNodeInfo.end() + && govResNodeInfo.find(resId) != govResNodeInfo.end()) { + return true; + } + return false; +} + +bool SocPerfHandler::IsValidResId(int resId) +{ + if (resNodeInfo.find(resId) == resNodeInfo.end() + && govResNodeInfo.find(resId) == govResNodeInfo.end()) { + return false; + } + if (resStatusInfo.find(resId) == resStatusInfo.end()) { + return false; + } + return true; +} +} // namespace SOCPERF +} // namespace OHOS \ No newline at end of file diff --git a/soc_perf/src/server/socperf_server.cpp b/soc_perf/src/server/socperf_server.cpp new file mode 100644 index 00000000..47861dd8 --- /dev/null +++ b/soc_perf/src/server/socperf_server.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2021 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_server.h" + +namespace OHOS { +namespace SOCPERF { +REGISTER_SYSTEM_ABILITY_BY_ID(SocPerfServer, RESSCHEDD_SA_ID, true); + +void SocPerfServer::OnStart() +{ + if (!Publish(this)) { + SOC_PERF_LOGE("Register SystemAbility for SocPerf FAILED."); + return; + } + SOC_PERF_LOGD("Register SystemAbility for SocPerf SUCCESS."); + + if (!socPerf.Init()) { + SOC_PERF_LOGE("SocPerf Init FAILED"); + return; + } + SOC_PERF_LOGD("SocPerf Init SUCCESS."); +} + +void SocPerfServer::OnStop() +{ +} + +void SocPerfServer::PerfRequest(int cmdId, const std::string& msg) +{ + socPerf.PerfRequest(cmdId, msg); +} + +void SocPerfServer::PerfRequestEx(int cmdId, bool onOffTag, const std::string& msg) +{ + socPerf.PerfRequestEx(cmdId, onOffTag, msg); +} + +void SocPerfServer::PowerRequest(int cmdId, const std::string& msg) +{ + socPerf.PowerRequest(cmdId, msg); +} + +void SocPerfServer::PowerRequestEx(int cmdId, bool onOffTag, const std::string& msg) +{ + socPerf.PowerRequestEx(cmdId, onOffTag, msg); +} + +void SocPerfServer::PowerLimitBoost(bool onOffTag, const std::string& msg) +{ + socPerf.PowerLimitBoost(onOffTag, msg); +} + +void SocPerfServer::ThermalRequest(int cmdId, const std::string& msg) +{ + socPerf.ThermalRequest(cmdId, msg); +} + +void SocPerfServer::ThermalRequestEx(int cmdId, bool onOffTag, const std::string& msg) +{ + socPerf.ThermalRequestEx(cmdId, onOffTag, msg); +} + +void SocPerfServer::ThermalLimitBoost(bool onOffTag, const std::string& msg) +{ + socPerf.ThermalLimitBoost(onOffTag, msg); +} +} // namespace SOCPERF +} // namespace OHOS diff --git a/soc_perf/src/server/socperf_stub.cpp b/soc_perf/src/server/socperf_stub.cpp new file mode 100644 index 00000000..e7f1f341 --- /dev/null +++ b/soc_perf/src/server/socperf_stub.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2021 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_stub.h" + +namespace OHOS { +namespace SOCPERF { +int SocPerfStub::OnRemoteRequest(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + switch (code) { + case TRANS_IPC_ID_PERF_REQUEST: { + int cmdId = data.ReadInt32(); + std::string msg = data.ReadString(); + PerfRequest(cmdId, msg); + return 0; + } + case TRANS_IPC_ID_PERF_REQUEST_EX: { + int cmdId = data.ReadInt32(); + bool onOffTag = data.ReadBool(); + std::string msg = data.ReadString(); + PerfRequestEx(cmdId, onOffTag, msg); + return 0; + } + case TRANS_IPC_ID_POWER_REQUEST: { + int cmdId = data.ReadInt32(); + std::string msg = data.ReadString(); + PowerRequest(cmdId, msg); + return 0; + } + case TRANS_IPC_ID_POWER_REQUEST_EX: { + int cmdId = data.ReadInt32(); + bool onOffTag = data.ReadBool(); + std::string msg = data.ReadString(); + PowerRequestEx(cmdId, onOffTag, msg); + return 0; + } + case TRANS_IPC_ID_POWER_LIMIT_BOOST_FREQ: { + bool onOffTag = data.ReadBool(); + std::string msg = data.ReadString(); + PowerLimitBoost(onOffTag, msg); + return 0; + } + case TRANS_IPC_ID_THERMAL_REQUEST: { + int cmdId = data.ReadInt32(); + std::string msg = data.ReadString(); + ThermalRequest(cmdId, msg); + return 0; + } + case TRANS_IPC_ID_THERMAL_REQUEST_EX: { + int cmdId = data.ReadInt32(); + bool onOffTag = data.ReadBool(); + std::string msg = data.ReadString(); + ThermalRequestEx(cmdId, onOffTag, msg); + return 0; + } + case TRANS_IPC_ID_THERMAL_LIMIT_BOOST_FREQ: { + bool onOffTag = data.ReadBool(); + std::string msg = data.ReadString(); + ThermalLimitBoost(onOffTag, msg); + return 0; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } +} +} // namespace SOCPERF +} // namespace OHOS diff --git a/soc_perf/test/BUILD.gn b/soc_perf/test/BUILD.gn new file mode 100644 index 00000000..e69de29b diff --git a/soc_perf/test/socperf_sub_test.cpp b/soc_perf/test/socperf_sub_test.cpp new file mode 100644 index 00000000..e69de29b diff --git a/soc_perf/test/socperf_test.cpp b/soc_perf/test/socperf_test.cpp new file mode 100644 index 00000000..6c46bbea --- /dev/null +++ b/soc_perf/test/socperf_test.cpp @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2021 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_client.h" + +#include + +static inline void PerfRequest(int argc, char *argv[]) +{ + if (argc == 3) { + char* cmdId = argv[2]; + if (cmdId != nullptr) { + OHOS::SOCPERF::SocPerfClient::GetInstance().PerfRequest(atoi(cmdId), ""); + } + } +} + +static inline void PerfRequestEx(int argc, char *argv[]) +{ + if (argc == 4) { + char* cmdId = argv[2]; + char* onOffTag = argv[3]; + if (cmdId != nullptr && onOffTag != nullptr) { + if (strcmp(onOffTag, "true") == 0) { + OHOS::SOCPERF::SocPerfClient::GetInstance().PerfRequestEx(atoi(cmdId), true, ""); + } else if (strcmp(onOffTag, "false") == 0) { + OHOS::SOCPERF::SocPerfClient::GetInstance().PerfRequestEx(atoi(cmdId), false, ""); + } + } + } +} + +static inline void PowerRequest(int argc, char *argv[]) +{ + if (argc == 3) { + char* cmdId = argv[2]; + if (cmdId != nullptr) { + OHOS::SOCPERF::SocPerfClient::GetInstance().PowerRequest(atoi(cmdId), ""); + } + } +} + +static inline void PowerRequestEx(int argc, char *argv[]) +{ + if (argc == 4) { + char* cmdId = argv[2]; + char* onOffTag = argv[3]; + if (cmdId != nullptr && onOffTag != nullptr) { + if (strcmp(onOffTag, "true") == 0) { + OHOS::SOCPERF::SocPerfClient::GetInstance().PowerRequestEx(atoi(cmdId), true, ""); + } else if (strcmp(onOffTag, "false") == 0) { + OHOS::SOCPERF::SocPerfClient::GetInstance().PowerRequestEx(atoi(cmdId), false, ""); + } + } + } +} + +static inline void PowerLimitBoost(int argc, char *argv[]) +{ + if (argc == 3) { + char* onOffTag = argv[2]; + if (onOffTag != nullptr) { + if (strcmp(onOffTag, "true") == 0) { + OHOS::SOCPERF::SocPerfClient::GetInstance().PowerLimitBoost(true, ""); + } else if (strcmp(onOffTag, "false") == 0) { + OHOS::SOCPERF::SocPerfClient::GetInstance().PowerLimitBoost(false, ""); + } + } + } +} + +static inline void ThermalRequest(int argc, char *argv[]) +{ + if (argc == 3) { + char* cmdId = argv[2]; + if (cmdId != nullptr) { + OHOS::SOCPERF::SocPerfClient::GetInstance().ThermalRequest(atoi(cmdId), ""); + } + } +} + +static inline void ThermalRequestEx(int argc, char *argv[]) +{ + if (argc == 4) { + char* cmdId = argv[2]; + char* onOffTag = argv[3]; + if (cmdId != nullptr && onOffTag != nullptr) { + if (strcmp(onOffTag, "true") == 0) { + OHOS::SOCPERF::SocPerfClient::GetInstance().ThermalRequestEx(atoi(cmdId), true, ""); + } else if (strcmp(onOffTag, "false") == 0) { + OHOS::SOCPERF::SocPerfClient::GetInstance().ThermalRequestEx(atoi(cmdId), false, ""); + } + } + } +} + +static inline void ThermalLimitBoost(int argc, char *argv[]) +{ + if (argc == 3) { + char* onOffTag = argv[2]; + if (onOffTag != nullptr) { + if (strcmp(onOffTag, "true") == 0) { + OHOS::SOCPERF::SocPerfClient::GetInstance().ThermalLimitBoost(true, ""); + } else if (strcmp(onOffTag, "false") == 0) { + OHOS::SOCPERF::SocPerfClient::GetInstance().ThermalLimitBoost(false, ""); + } + } + } +} + +int main(int argc, char *argv[]) +{ + if (argc >= 2) { + char* function = argv[1]; + if (strcmp(function, "PerfRequest") == 0) { + PerfRequest(argc, argv); + } else if (strcmp(function, "PerfRequestEx") == 0) { + PerfRequestEx(argc, argv); + } else if (strcmp(function, "PowerRequest") == 0) { + PowerRequest(argc, argv); + } else if (strcmp(function, "PowerRequestEx") == 0) { + PowerRequestEx(argc, argv); + } else if (strcmp(function, "PowerLimitBoost") == 0) { + PowerLimitBoost(argc, argv); + } else if (strcmp(function, "ThermalRequest") == 0) { + ThermalRequest(argc, argv); + } else if (strcmp(function, "ThermalRequestEx") == 0) { + ThermalRequestEx(argc, argv); + } else if (strcmp(function, "ThermalLimitBoost") == 0) { + ThermalLimitBoost(argc, argv); + } + } + return 0; +} \ No newline at end of file -- Gitee