From 2f0b0bbea89d4b42480dec205c3c513ad5dc6134 Mon Sep 17 00:00:00 2001 From: liuchungang <1397328542@qq.com> Date: Wed, 17 Jan 2024 09:34:12 +0800 Subject: [PATCH 1/5] add qos_manager ndk interface implement Signed-off-by: liuchungang <1397328542@qq.com> --- bundle.json | 3 +- frameworks/native/BUILD.gn | 42 ++++++++ frameworks/native/qos_ndk.cpp | 77 +++++++++++++++ interfaces/inner_api/qos.h | 2 + interfaces/kits/BUILD.gn | 27 ++++++ interfaces/kits/c/qos.h | 108 +++++++++++++++++++++ interfaces/kits/libqos.ndk.json | 5 + qos/qos.cpp | 20 ++++ services/include/qos_interface.h | 2 + services/src/qos_interface.cpp | 31 ++++++ test/BUILD.gn | 43 ++++++++ test/unittest/phone/qos_interface_test.cpp | 38 ++++++++ test/unittest/phone/qos_ndk_test.cpp | 96 ++++++++++++++++++ test/unittest/phone/qos_test.cpp | 26 +++++ 14 files changed, 519 insertions(+), 1 deletion(-) create mode 100644 frameworks/native/BUILD.gn create mode 100644 frameworks/native/qos_ndk.cpp create mode 100644 interfaces/kits/BUILD.gn create mode 100644 interfaces/kits/c/qos.h create mode 100644 interfaces/kits/libqos.ndk.json create mode 100644 test/unittest/phone/qos_ndk_test.cpp diff --git a/bundle.json b/bundle.json index 22658b9..689ab6e 100644 --- a/bundle.json +++ b/bundle.json @@ -44,7 +44,8 @@ "//foundation/resourceschedule/qos_manager/sa_profile:concurrent_task_sa_profile", "//foundation/resourceschedule/qos_manager/services:concurrentsvc", "//foundation/resourceschedule/qos_manager/frameworks/concurrent_task_client:concurrent_task_client", - "//foundation/resourceschedule/qos_manager/qos:qos" + "//foundation/resourceschedule/qos_manager/qos:qos", + "//foundation/resourceschedule/qos_manager/frameworks/native:qos_ndk" ], "inner_kits": [ { diff --git a/frameworks/native/BUILD.gn b/frameworks/native/BUILD.gn new file mode 100644 index 0000000..860bfc6 --- /dev/null +++ b/frameworks/native/BUILD.gn @@ -0,0 +1,42 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/ohos/ndk/ndk.gni") + +ohos_shared_library("qos_ndk") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + + include_dirs = [ + "../../interfaces/", + "../../interfaces/kits/c/", + ] + + sources = [ "qos_ndk.cpp" ] + + if (defined( + global_parts_info.hmosresourceschedule_frame_aware_sched_override)) { + defines = [ "QOS_EXT_ENABLE" ] + } + + deps = [ "../../qos:qos" ] + + innerapi_tags = [ "ndk" ] + subsystem_name = "resourceschedule" + part_name = "qos_manager" +} diff --git a/frameworks/native/qos_ndk.cpp b/frameworks/native/qos_ndk.cpp new file mode 100644 index 0000000..68b8b5a --- /dev/null +++ b/frameworks/native/qos_ndk.cpp @@ -0,0 +1,77 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "qos.h" +#include "inner_api/qos.h" +#include +#include +#include + +static constexpr int ERROR_NUM = -1; + +using namespace OHOS::QOS; +using namespace std; + +const unordered_map qos_map = { + {QoS_Level::QOS_BACKGROUND, QosLevel::QOS_BACKGROUND}, + {QoS_Level::QOS_UTILITY, QosLevel::QOS_UTILITY}, + {QoS_Level::QOS_DEFAULT, QosLevel::QOS_DEFAULT}, + {QoS_Level::QOS_USER_INITIATED, QosLevel::QOS_USER_INITIATED}, + {QoS_Level::QOS_DEADLINE_REQUEST, QosLevel::QOS_DEADLINE_REQUEST}, + {QoS_Level::QOS_USER_INTERACTIVE, QosLevel::QOS_USER_INTERACTIVE} +}; + +const unordered_map qos_reverse_map = { + {QosLevel::QOS_BACKGROUND, QoS_Level::QOS_BACKGROUND}, + {QosLevel::QOS_UTILITY, QoS_Level::QOS_UTILITY}, + {QosLevel::QOS_DEFAULT, QoS_Level::QOS_DEFAULT}, + {QosLevel::QOS_USER_INITIATED, QoS_Level::QOS_USER_INITIATED}, + {QosLevel::QOS_DEADLINE_REQUEST, QoS_Level::QOS_DEADLINE_REQUEST}, + {QosLevel::QOS_USER_INTERACTIVE, QoS_Level::QOS_USER_INTERACTIVE} +}; + + +int OH_QoS_SetThreadQoS(QoS_Level level) +{ + auto iter = qos_map.find(level); + if (iter == qos_map.end()) { + return ERROR_NUM; + } + return QosController::GetInstance().SetThreadQosForOtherThread(iter->second, gettid()); +} + +int OH_QoS_ResetThreadQoS(void) +{ + return QosController::GetInstance().ResetThreadQosForOtherThread(gettid()); +} + +int OH_QoS_GetThreadQoS(QoS_Level *level) +{ + if (level == nullptr) { + return ERROR_NUM; + } +#ifdef QOS_EXT_ENABLE + enum QosLevel qosLevel; + int ret = QosController::GetInstance().GetThreadQosForOtherThread(qosLevel, gettid()); + if (ret < 0) { + return ERROR_NUM; + } + auto iter = qos_reverse_map.find(qosLevel); + if (iter == qos_reverse_map.end()) { + return ERROR_NUM; + } + *level = iter->second; +#endif + return 0; +} \ No newline at end of file diff --git a/interfaces/inner_api/qos.h b/interfaces/inner_api/qos.h index c74ff55..e8d3724 100644 --- a/interfaces/inner_api/qos.h +++ b/interfaces/inner_api/qos.h @@ -35,6 +35,7 @@ public: int SetThreadQosForOtherThread(enum QosLevel level, int tid); int ResetThreadQosForOtherThread(int tid); + int GetThreadQosForOtherThread(enum QosLevel &level, int tid); private: QosController() = default; @@ -50,6 +51,7 @@ int SetThreadQos(enum QosLevel level); int SetQosForOtherThread(enum QosLevel level, int tid); int ResetThreadQos(); int ResetQosForOtherThread(int tid); +int GetThreadQos(enum QosLevel &level); } // namespace QOS } // namespace OHOS diff --git a/interfaces/kits/BUILD.gn b/interfaces/kits/BUILD.gn new file mode 100644 index 0000000..e9a77f1 --- /dev/null +++ b/interfaces/kits/BUILD.gn @@ -0,0 +1,27 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/ohos/ndk/ndk.gni") + +ohos_ndk_headers("qos_header") { + dest_dir = "$ndk_headers_out_dir/qos" + sources = [ "./c/qos.h" ] +} + +ohos_ndk_library("libqos_ndk") { + output_name = "qos_ndk" + ndk_description_file = "./libqos.ndk.json" + system_capability = "SystemCapability.Resourceschedule.QoS.Core" + system_capability_headers = [ "$ndk_headers_out_dir/qos/qos.h" ] +} diff --git a/interfaces/kits/c/qos.h b/interfaces/kits/c/qos.h new file mode 100644 index 0000000..8bfb938 --- /dev/null +++ b/interfaces/kits/c/qos.h @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef QOS_H +#define QOS_H +/** + * @addtogroup QoS + * @{ + * + * @brief QoS provides APIs. + * + * @since 12 + */ + +/** + * @file qos.h + * + * @brief Declares the QoS interfaces in C. + * @library libqos.z.so + * @syscap SystemCapability.Resourceschedule.QoS.Core + * @since 12 + */ +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Describes the level of QoS. + * + * @since 12 + */ +typedef enum QoS_Level { + /** + * @brief Means the QoS level is background. + */ + QOS_BACKGROUND = 0, + + /** + * @brief Means the QoS level is utility. + */ + QOS_UTILITY, + + /** + * @brief Means the QoS level is default. + */ + QOS_DEFAULT, + + /** + * @brief Means the QoS level is user-initiated. + */ + QOS_USER_INITIATED, + + /** + * @brief Means the QoS level is user-request. + */ + QOS_DEADLINE_REQUEST, + + /** + * @brief Means the QoS level is user-interactive. + */ + QOS_USER_INTERACTIVE, +} QoS_Level; + +/** + * @brief Set the QoS level of the current thread. + * + * @param level Indicates the level to set. Specific level can be referenced {@link QoS_Level}. + * @return Returns int32_t, return value == 0, success, otherwise value == -1, failed. + * @see QoS_Level + * @since 12 + */ +int OH_QoS_SetThreadQoS(QoS_Level level); + +/** + * @brief Cancel the QoS level of the current thread. + * + * @return Returns int32_t, return value == 0, success, otherwise value == -1, failed. + * @see QoS_Level + * @since 12 + */ +int OH_QoS_ResetThreadQoS(); + +/** + * @brief Obtains the QoS level of the current thread. + * + * @param level This parameter is the output parameter, + * and the QoS level of the thread as a {@link QoS_Level} is written to this variable. + * @return Returns int32_t, return value == 0, success, otherwise value == -1, failed. + * @see QoS_Level + * @since 12 + */ +int OH_QoS_GetThreadQoS(QoS_Level *level); +#ifdef __cplusplus +}; +#endif +#endif //QOS_H diff --git a/interfaces/kits/libqos.ndk.json b/interfaces/kits/libqos.ndk.json new file mode 100644 index 0000000..7347e00 --- /dev/null +++ b/interfaces/kits/libqos.ndk.json @@ -0,0 +1,5 @@ +[ + { "name": "OH_QoS_SetThreadQoS" }, + { "name": "OH_QoS_ResetThreadQoS" }, + { "name": "OH_QoS_GetThreadQoS" } +] \ No newline at end of file diff --git a/qos/qos.cpp b/qos/qos.cpp index 0fd92ca..a81bdab 100644 --- a/qos/qos.cpp +++ b/qos/qos.cpp @@ -59,6 +59,21 @@ int QosController::ResetThreadQosForOtherThread(int tid) return ret; } +int QosController::GetThreadQosForOtherThread(enum QosLevel &level, int tid) +{ + struct QosCtrlData data; + int ret = QosGetForOther(tid, data); + if (ret == 0) { + CONCUR_LOGD("[Qos] qoslevel get for tid %{public}d success", tid); + } else { + CONCUR_LOGE("[Qos] qoslevel get for tid %{public}d failure", tid); + } +#ifdef QOS_EXT_ENABLE + level = static_cast(data.qos); +#endif + return ret; +} + int SetThreadQos(enum QosLevel level) { int tid = gettid(); @@ -80,5 +95,10 @@ int ResetQosForOtherThread(int tid) { return QosController::GetInstance().ResetThreadQosForOtherThread(tid); } + +int GetThreadQos(enum QosLevel &level) +{ + return QosController::GetInstance().GetThreadQosForOtherThread(level, gettid()); +} } // namespace QOS } // namespace OHOS diff --git a/services/include/qos_interface.h b/services/include/qos_interface.h index f32df50..e727ebd 100644 --- a/services/include/qos_interface.h +++ b/services/include/qos_interface.h @@ -179,6 +179,8 @@ int QosApplyForOther(unsigned int level, int tid); int QosLeave(void); int QosLeaveForOther(int tid); int QosPolicySet(const struct QosPolicyDatas *policyDatas); +int QosGet(struct QosCtrlData &data); +int QosGetForOther(int tid, struct QosCtrlData &data); #ifdef __cplusplus } diff --git a/services/src/qos_interface.cpp b/services/src/qos_interface.cpp index 0e27a43..da86ed2 100644 --- a/services/src/qos_interface.cpp +++ b/services/src/qos_interface.cpp @@ -332,3 +332,34 @@ int QosPolicySet(const struct QosPolicyDatas *policyDatas) close(fd); return ret; } + +int QosGet(struct QosCtrlData &data) +{ + int tid = gettid(); + return QosGetForOther(tid, data); +} + +int QosGetForOther(int tid, struct QosCtrlData &data) +{ + int fd; + int ret = 0; + + fd = TrivalOpenQosCtrlNode(); + if (fd < 0) { + return fd; + } +#ifdef QOS_EXT_ENABLE + data.type = static_cast(QosManipulateType::QOS_GET); + data.pid = tid; + data.qos = -1; + + ret = ioctl(fd, QOS_CTRL_BASIC_OPERATION, &data); +#ifdef QOS_DEBUG + if (ret < 0) { + printf("get qos failed for task %d\n", tid); + } +#endif +#endif + close(fd); + return ret; +} \ No newline at end of file diff --git a/test/BUILD.gn b/test/BUILD.gn index 5049499..ea52ab4 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -24,6 +24,7 @@ config("test_config") { "../include/", "../frameworks/concurrent_task_client/include", "../interfaces/inner_api/", + "../interfaces/kits/", "../services/include/", "//third_party/jsoncpp/include/", "//foundation/resourceschedule/frame_aware_sched/common/include/", @@ -143,6 +144,12 @@ ohos_unittest("qos_interface_test") { configs = [ ":test_config" ] sources = [ "unittest/phone/qos_interface_test.cpp" ] + + if (defined( + global_parts_info.hmosresourceschedule_frame_aware_sched_override)) { + defines = [ "QOS_EXT_ENABLE" ] + } + deps = [ "../frameworks/concurrent_task_client:concurrent_task_client", "../services:concurrentsvc", @@ -218,6 +225,12 @@ ohos_unittest("qos_test") { configs = [ ":test_config" ] sources = [ "unittest/phone/qos_test.cpp" ] + + if (defined( + global_parts_info.hmosresourceschedule_frame_aware_sched_override)) { + defines = [ "QOS_EXT_ENABLE" ] + } + deps = [ "../qos:qos" ] external_deps = [ "c_utils:utils", @@ -232,6 +245,35 @@ ohos_unittest("qos_test") { part_name = "qos_manager" } +ohos_unittest("qos_ndk_test") { + module_out_path = module_output_path + + configs = [ ":test_config" ] + + sources = [ "unittest/phone/qos_ndk_test.cpp" ] + + if (defined( + global_parts_info.hmosresourceschedule_frame_aware_sched_override)) { + defines = [ "QOS_EXT_ENABLE" ] + } + + deps = [ + "../frameworks/native:qos_ndk", + "../qos:qos", + ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] + + if (is_standard_system) { + public_deps = gtest_public_deps + } + + subsystem_name = "resourceschedule" + part_name = "qos_manager" +} + group("concurrent_unittest") { testonly = true deps = [] @@ -243,6 +285,7 @@ group("concurrent_unittest") { ":concurrent_task_service_ability_test", ":concurrent_task_service_test", ":qos_interface_test", + ":qos_ndk_test", ":qos_policy_test", ":qos_test", ] diff --git a/test/unittest/phone/qos_interface_test.cpp b/test/unittest/phone/qos_interface_test.cpp index e45def5..36a21b5 100644 --- a/test/unittest/phone/qos_interface_test.cpp +++ b/test/unittest/phone/qos_interface_test.cpp @@ -261,6 +261,44 @@ HWTEST_F(QosInterfaceTest, QosPolicyTest, TestSize.Level1) EXPECT_EQ(ret, 0); #endif } + +/** + * @tc.name: QosGetTest + * @tc.desc: Test whether the QosGet interface are normal. + * @tc.type: FUNC + */ +HWTEST_F(QosInterfaceTest, QosGetTest, TestSize.Level1) +{ + struct QosCtrlData data; + unsigned int level = 4; + int ret = QosApply(level); + EXPECT_EQ(ret, 0); +#ifdef QOS_EXT_ENABLE + ret = QosGet(data); + sleep(5); + EXPECT_EQ(ret, 0); + EXPECT_EQ(data.qos, level); +#endif +} + +/** + * @tc.name: QosGetForOtherTest + * @tc.desc: Test whether the QosGetForOther interface are normal. + * @tc.type: FUNC + */ +HWTEST_F(QosInterfaceTest, QosGetForOtherTest, TestSize.Level1) +{ + struct QosCtrlData data; + unsigned int level = 3; + int tid = gettid(); + int ret = QosApplyForOther(level, tid); + EXPECT_EQ(ret, 0); +#ifdef QOS_EXT_ENABLE + ret = QosGetForOther(tid, data); + EXPECT_EQ(ret, 0); + EXPECT_EQ(data.qos, level); +#endif +} } } } diff --git a/test/unittest/phone/qos_ndk_test.cpp b/test/unittest/phone/qos_ndk_test.cpp new file mode 100644 index 0000000..db0aadd --- /dev/null +++ b/test/unittest/phone/qos_ndk_test.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "gtest/gtest.h" +#include "c/qos.h" + +namespace OHOS { +namespace QOS { +using namespace testing; +using namespace testing::ext; +using namespace OHOS::QOS; + +class QoSNdkTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void QoSNdkTest::SetUpTestCase() +{ +} + +void QoSNdkTest::TearDownTestCase() +{ +} + +void QoSNdkTest::SetUp() +{ +} + +void QoSNdkTest::TearDown() +{ +} + +/** + * @tc.name: QoSNdkTest + * @tc.desc: Verify the Set and Reset QoSLevel function. + * @tc.type: FUNC + */ +HWTEST_F(QoSNdkTest, SetThreadQoSNdkTest1, TestSize.Level1) +{ + int ret = OH_QoS_SetThreadQoS(QoS_Level::QOS_BACKGROUND); + EXPECT_EQ(ret, 0); + ret = OH_QoS_SetThreadQoS(QoS_Level::QOS_UTILITY); + EXPECT_EQ(ret, 0); + ret = OH_QoS_SetThreadQoS(QoS_Level::QOS_DEFAULT); + EXPECT_EQ(ret, 0); + ret = OH_QoS_SetThreadQoS(QoS_Level::QOS_USER_INITIATED); + EXPECT_EQ(ret, 0); + ret = OH_QoS_SetThreadQoS(QoS_Level::QOS_DEADLINE_REQUEST); + EXPECT_EQ(ret, 0); + ret = OH_QoS_SetThreadQoS(QoS_Level::QOS_USER_INTERACTIVE); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(QoSNdkTest, ResetThreadQoSNdkTest, TestSize.Level1) +{ + int ret = OH_QoS_SetThreadQoS(QoS_Level::QOS_USER_INTERACTIVE); + EXPECT_EQ(ret, 0); + ret = OH_QoS_ResetThreadQoS(); + EXPECT_EQ(ret, 0); +} + +HWTEST_F(QoSNdkTest, GetThreadQoSNdkTest1, TestSize.Level1) +{ + int ret = OH_QoS_GetThreadQoS(nullptr); + EXPECT_EQ(ret, -1); +#ifdef QOS_EXT_ENABLE + ret = OH_QoS_SetThreadQoS(QoS_Level::QOS_USER_INTERACTIVE); + EXPECT_EQ(ret, 0); + enum QoS_Level level; + ret = OH_QoS_GetThreadQoS(&level); + EXPECT_EQ(ret, 0); + EXPECT_EQ(level, QoS_Level::QOS_USER_INTERACTIVE); +#endif +} + + +} // QOS +} // OHOS \ No newline at end of file diff --git a/test/unittest/phone/qos_test.cpp b/test/unittest/phone/qos_test.cpp index 9ad1842..12f07d4 100644 --- a/test/unittest/phone/qos_test.cpp +++ b/test/unittest/phone/qos_test.cpp @@ -100,5 +100,31 @@ HWTEST_F(QosTest, ResetThreadQosTest2, TestSize.Level1) ret = ResetQosForOtherThread(gettid()); EXPECT_EQ(ret, 0); } + +HWTEST_F(QosTest, GetThreadQosTest1, TestSize.Level1) +{ + int ret = SetThreadQos(QosLevel::QOS_USER_INITIATED); + EXPECT_EQ(ret, 0); + enum QosLevel level; +#ifdef QOS_EXT_ENABLE + ret = GetThreadQos(level); + EXPECT_EQ(ret, 0); + EXPECT_EQ(static_cast(level), static_cast(QosLevel::QOS_USER_INITIATED)); + ret = SetThreadQos(QosLevel::QOS_USER_INTERACTIVE); + EXPECT_EQ(ret, 0); + ret = GetThreadQos(level); + EXPECT_EQ(ret, 0); + EXPECT_EQ(static_cast(level), static_cast(QosLevel::QOS_USER_INTERACTIVE)); +#endif +} + +HWTEST_F(QosTest, GetThreadQosTest2, TestSize.Level1) +{ + int ret = ResetThreadQos(); + EXPECT_EQ(ret, 0); + enum QosLevel level; + ret = GetThreadQos(level); + EXPECT_EQ(ret, 0); +} } // QOS } // OHOS \ No newline at end of file -- Gitee From 651f34627f80e3218da9b23735cbb4c68522e337 Mon Sep 17 00:00:00 2001 From: liuchungang <1397328542@qq.com> Date: Tue, 23 Jan 2024 11:21:34 +0800 Subject: [PATCH 2/5] add qos_manager ndk interface implement Signed-off-by: liuchungang <1397328542@qq.com> --- frameworks/native/BUILD.gn | 7 +------ frameworks/native/qos_ndk.cpp | 4 +--- interfaces/kits/BUILD.gn | 2 +- interfaces/kits/c/qos.h | 8 ++++---- qos/qos.cpp | 2 ++ test/BUILD.gn | 14 -------------- test/unittest/phone/qos_ndk_test.cpp | 2 +- 7 files changed, 10 insertions(+), 29 deletions(-) diff --git a/frameworks/native/BUILD.gn b/frameworks/native/BUILD.gn index 860bfc6..c10920e 100644 --- a/frameworks/native/BUILD.gn +++ b/frameworks/native/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2024 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -29,11 +29,6 @@ ohos_shared_library("qos_ndk") { sources = [ "qos_ndk.cpp" ] - if (defined( - global_parts_info.hmosresourceschedule_frame_aware_sched_override)) { - defines = [ "QOS_EXT_ENABLE" ] - } - deps = [ "../../qos:qos" ] innerapi_tags = [ "ndk" ] diff --git a/frameworks/native/qos_ndk.cpp b/frameworks/native/qos_ndk.cpp index 68b8b5a..46b0abc 100644 --- a/frameworks/native/qos_ndk.cpp +++ b/frameworks/native/qos_ndk.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Huawei Device Co., Ltd. +* Copyright (c) 2024 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 @@ -61,7 +61,6 @@ int OH_QoS_GetThreadQoS(QoS_Level *level) if (level == nullptr) { return ERROR_NUM; } -#ifdef QOS_EXT_ENABLE enum QosLevel qosLevel; int ret = QosController::GetInstance().GetThreadQosForOtherThread(qosLevel, gettid()); if (ret < 0) { @@ -72,6 +71,5 @@ int OH_QoS_GetThreadQoS(QoS_Level *level) return ERROR_NUM; } *level = iter->second; -#endif return 0; } \ No newline at end of file diff --git a/interfaces/kits/BUILD.gn b/interfaces/kits/BUILD.gn index e9a77f1..b7e16f8 100644 --- a/interfaces/kits/BUILD.gn +++ b/interfaces/kits/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2024 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 diff --git a/interfaces/kits/c/qos.h b/interfaces/kits/c/qos.h index 8bfb938..1e6dd2f 100644 --- a/interfaces/kits/c/qos.h +++ b/interfaces/kits/c/qos.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef QOS_H -#define QOS_H +#ifndef QOS_MANAGER_NDK_API_QOS_H +#define QOS_MANAGER_NDK_API_QOS_H /** * @addtogroup QoS * @{ @@ -105,4 +105,4 @@ int OH_QoS_GetThreadQoS(QoS_Level *level); #ifdef __cplusplus }; #endif -#endif //QOS_H +#endif //QOS_MANAGER_NDK_API_QOS_H diff --git a/qos/qos.cpp b/qos/qos.cpp index a81bdab..1717206 100644 --- a/qos/qos.cpp +++ b/qos/qos.cpp @@ -70,6 +70,8 @@ int QosController::GetThreadQosForOtherThread(enum QosLevel &level, int tid) } #ifdef QOS_EXT_ENABLE level = static_cast(data.qos); +#else + level = QosLevel::QOS_DEFAULT; #endif return ret; } diff --git a/test/BUILD.gn b/test/BUILD.gn index ea52ab4..f41ca00 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -145,11 +145,6 @@ ohos_unittest("qos_interface_test") { sources = [ "unittest/phone/qos_interface_test.cpp" ] - if (defined( - global_parts_info.hmosresourceschedule_frame_aware_sched_override)) { - defines = [ "QOS_EXT_ENABLE" ] - } - deps = [ "../frameworks/concurrent_task_client:concurrent_task_client", "../services:concurrentsvc", @@ -226,10 +221,6 @@ ohos_unittest("qos_test") { sources = [ "unittest/phone/qos_test.cpp" ] - if (defined( - global_parts_info.hmosresourceschedule_frame_aware_sched_override)) { - defines = [ "QOS_EXT_ENABLE" ] - } deps = [ "../qos:qos" ] external_deps = [ @@ -252,11 +243,6 @@ ohos_unittest("qos_ndk_test") { sources = [ "unittest/phone/qos_ndk_test.cpp" ] - if (defined( - global_parts_info.hmosresourceschedule_frame_aware_sched_override)) { - defines = [ "QOS_EXT_ENABLE" ] - } - deps = [ "../frameworks/native:qos_ndk", "../qos:qos", diff --git a/test/unittest/phone/qos_ndk_test.cpp b/test/unittest/phone/qos_ndk_test.cpp index db0aadd..6b0e900 100644 --- a/test/unittest/phone/qos_ndk_test.cpp +++ b/test/unittest/phone/qos_ndk_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 -- Gitee From 11ca4f9eccd4cc93b2133057a19a97bb4b8eee3b Mon Sep 17 00:00:00 2001 From: liuchungang <1397328542@qq.com> Date: Tue, 23 Jan 2024 11:30:49 +0800 Subject: [PATCH 3/5] add qos_manager ndk interface implement Signed-off-by: liuchungang <1397328542@qq.com> --- test/BUILD.gn | 1 - 1 file changed, 1 deletion(-) diff --git a/test/BUILD.gn b/test/BUILD.gn index f41ca00..cc3690a 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -221,7 +221,6 @@ ohos_unittest("qos_test") { sources = [ "unittest/phone/qos_test.cpp" ] - deps = [ "../qos:qos" ] external_deps = [ "c_utils:utils", -- Gitee From 576bd36bebf020ae63c194dffe47152a8ba970c5 Mon Sep 17 00:00:00 2001 From: liuchungang <1397328542@qq.com> Date: Tue, 23 Jan 2024 11:39:58 +0800 Subject: [PATCH 4/5] add qos_manager ndk interface implement Signed-off-by: liuchungang <1397328542@qq.com> --- interfaces/kits/c/qos.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/c/qos.h b/interfaces/kits/c/qos.h index 1e6dd2f..2528add 100644 --- a/interfaces/kits/c/qos.h +++ b/interfaces/kits/c/qos.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef QOS_MANAGER_NDK_API_QOS_H -#define QOS_MANAGER_NDK_API_QOS_H +#ifndef QOS_MANAGER_NATIVE_API_QOS_H +#define QOS_MANAGER_NATIVE_API_QOS_H /** * @addtogroup QoS * @{ @@ -105,4 +105,4 @@ int OH_QoS_GetThreadQoS(QoS_Level *level); #ifdef __cplusplus }; #endif -#endif //QOS_MANAGER_NDK_API_QOS_H +#endif //QOS_MANAGER_NATIVE_API_QOS_H -- Gitee From d3bf2a62a6830e2ed884674e210a574572b80d01 Mon Sep 17 00:00:00 2001 From: liuchungang <1397328542@qq.com> Date: Tue, 23 Jan 2024 11:51:41 +0800 Subject: [PATCH 5/5] add qos_manager ndk interface implement Signed-off-by: liuchungang <1397328542@qq.com> --- frameworks/native/BUILD.gn | 3 +++ interfaces/kits/BUILD.gn | 3 ++- interfaces/kits/c/qos.h | 14 ++++++++++---- interfaces/kits/libqos.ndk.json | 15 ++++++++++++--- qos/qos.cpp | 9 ++++++--- services/include/qos_interface.h | 4 ++-- services/src/qos_interface.cpp | 8 +++++--- test/unittest/phone/qos_interface_test.cpp | 12 ++++++------ 8 files changed, 46 insertions(+), 22 deletions(-) diff --git a/frameworks/native/BUILD.gn b/frameworks/native/BUILD.gn index c10920e..77ad594 100644 --- a/frameworks/native/BUILD.gn +++ b/frameworks/native/BUILD.gn @@ -31,6 +31,9 @@ ohos_shared_library("qos_ndk") { deps = [ "../../qos:qos" ] + output_name = "qos" + output_extension = "so" + innerapi_tags = [ "ndk" ] subsystem_name = "resourceschedule" part_name = "qos_manager" diff --git a/interfaces/kits/BUILD.gn b/interfaces/kits/BUILD.gn index b7e16f8..f8791c1 100644 --- a/interfaces/kits/BUILD.gn +++ b/interfaces/kits/BUILD.gn @@ -20,7 +20,8 @@ ohos_ndk_headers("qos_header") { } ohos_ndk_library("libqos_ndk") { - output_name = "qos_ndk" + output_name = "qos" + output_extension = "so" ndk_description_file = "./libqos.ndk.json" system_capability = "SystemCapability.Resourceschedule.QoS.Core" system_capability_headers = [ "$ndk_headers_out_dir/qos/qos.h" ] diff --git a/interfaces/kits/c/qos.h b/interfaces/kits/c/qos.h index 2528add..c92ab5b 100644 --- a/interfaces/kits/c/qos.h +++ b/interfaces/kits/c/qos.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef QOS_MANAGER_NATIVE_API_QOS_H -#define QOS_MANAGER_NATIVE_API_QOS_H +#ifndef QOS_H +#define QOS_H /** * @addtogroup QoS * @{ @@ -28,7 +28,13 @@ * @file qos.h * * @brief Declares the QoS interfaces in C. - * @library libqos.z.so + * + * Quality-of-service (QoS) refers to the priority scheduling attribute of tasks + * in OpenHarmony. Developers can use QoS to categorize tasks to be executed to + * indicate the degree of their relevance to user interactions, the system can + * schedule the time and running order of tasks according to the QoS set by the tasks. + * + * @library libqos.so * @syscap SystemCapability.Resourceschedule.QoS.Core * @since 12 */ @@ -105,4 +111,4 @@ int OH_QoS_GetThreadQoS(QoS_Level *level); #ifdef __cplusplus }; #endif -#endif //QOS_MANAGER_NATIVE_API_QOS_H +#endif //QOS_H diff --git a/interfaces/kits/libqos.ndk.json b/interfaces/kits/libqos.ndk.json index 7347e00..e2b9422 100644 --- a/interfaces/kits/libqos.ndk.json +++ b/interfaces/kits/libqos.ndk.json @@ -1,5 +1,14 @@ [ - { "name": "OH_QoS_SetThreadQoS" }, - { "name": "OH_QoS_ResetThreadQoS" }, - { "name": "OH_QoS_GetThreadQoS" } + { + "first_introduced": "12", + "name": "OH_QoS_SetThreadQoS" + }, + { + "first_introduced": "12", + "name": "OH_QoS_ResetThreadQoS" + }, + { + "first_introduced": "12", + "name": "OH_QoS_GetThreadQoS" + } ] \ No newline at end of file diff --git a/qos/qos.cpp b/qos/qos.cpp index 1717206..924f686 100644 --- a/qos/qos.cpp +++ b/qos/qos.cpp @@ -61,15 +61,18 @@ int QosController::ResetThreadQosForOtherThread(int tid) int QosController::GetThreadQosForOtherThread(enum QosLevel &level, int tid) { - struct QosCtrlData data; - int ret = QosGetForOther(tid, data); + int qos; + int ret = QosGetForOther(tid, qos); if (ret == 0) { CONCUR_LOGD("[Qos] qoslevel get for tid %{public}d success", tid); } else { CONCUR_LOGE("[Qos] qoslevel get for tid %{public}d failure", tid); } #ifdef QOS_EXT_ENABLE - level = static_cast(data.qos); + level = static_cast(qos); + if (level < QosLevel::QOS_BACKGROUND || level >= QosLevel::QOS_MAX) { + level = QosLevel::QOS_DEFAULT; + } #else level = QosLevel::QOS_DEFAULT; #endif diff --git a/services/include/qos_interface.h b/services/include/qos_interface.h index e727ebd..cafa8ac 100644 --- a/services/include/qos_interface.h +++ b/services/include/qos_interface.h @@ -179,8 +179,8 @@ int QosApplyForOther(unsigned int level, int tid); int QosLeave(void); int QosLeaveForOther(int tid); int QosPolicySet(const struct QosPolicyDatas *policyDatas); -int QosGet(struct QosCtrlData &data); -int QosGetForOther(int tid, struct QosCtrlData &data); +int QosGet(int &level); +int QosGetForOther(int tid, int &level); #ifdef __cplusplus } diff --git a/services/src/qos_interface.cpp b/services/src/qos_interface.cpp index da86ed2..103c2ab 100644 --- a/services/src/qos_interface.cpp +++ b/services/src/qos_interface.cpp @@ -333,13 +333,13 @@ int QosPolicySet(const struct QosPolicyDatas *policyDatas) return ret; } -int QosGet(struct QosCtrlData &data) +int QosGet(int &level) { int tid = gettid(); - return QosGetForOther(tid, data); + return QosGetForOther(tid, level); } -int QosGetForOther(int tid, struct QosCtrlData &data) +int QosGetForOther(int tid, int &level) { int fd; int ret = 0; @@ -349,6 +349,7 @@ int QosGetForOther(int tid, struct QosCtrlData &data) return fd; } #ifdef QOS_EXT_ENABLE + struct QosCtrlData data; data.type = static_cast(QosManipulateType::QOS_GET); data.pid = tid; data.qos = -1; @@ -359,6 +360,7 @@ int QosGetForOther(int tid, struct QosCtrlData &data) printf("get qos failed for task %d\n", tid); } #endif + level = data.qos; #endif close(fd); return ret; diff --git a/test/unittest/phone/qos_interface_test.cpp b/test/unittest/phone/qos_interface_test.cpp index 36a21b5..485c508 100644 --- a/test/unittest/phone/qos_interface_test.cpp +++ b/test/unittest/phone/qos_interface_test.cpp @@ -269,15 +269,15 @@ HWTEST_F(QosInterfaceTest, QosPolicyTest, TestSize.Level1) */ HWTEST_F(QosInterfaceTest, QosGetTest, TestSize.Level1) { - struct QosCtrlData data; + int qos; unsigned int level = 4; int ret = QosApply(level); EXPECT_EQ(ret, 0); #ifdef QOS_EXT_ENABLE - ret = QosGet(data); + ret = QosGet(qos); sleep(5); EXPECT_EQ(ret, 0); - EXPECT_EQ(data.qos, level); + EXPECT_EQ(qos, level); #endif } @@ -288,15 +288,15 @@ HWTEST_F(QosInterfaceTest, QosGetTest, TestSize.Level1) */ HWTEST_F(QosInterfaceTest, QosGetForOtherTest, TestSize.Level1) { - struct QosCtrlData data; + int qos; unsigned int level = 3; int tid = gettid(); int ret = QosApplyForOther(level, tid); EXPECT_EQ(ret, 0); #ifdef QOS_EXT_ENABLE - ret = QosGetForOther(tid, data); + ret = QosGetForOther(tid, qos); EXPECT_EQ(ret, 0); - EXPECT_EQ(data.qos, level); + EXPECT_EQ(qos, level); #endif } } -- Gitee