Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 : #ifndef COMMON_AICPUSD_FEATURE_CTRL_H
11 : #define COMMON_AICPUSD_FEATURE_CTRL_H
12 :
13 : #include <cstdint>
14 : #include <atomic>
15 : #include "aicpusd_info.h"
16 :
17 : namespace AicpuSchedule {
18 : // min number of vDeviceId
19 : constexpr const uint32_t VDEVICE_MIN_CPU_NUM = 32U;
20 : // mid number of vDeviceId
21 : constexpr const uint32_t VDEVICE_MID_CPU_NUM = 48U;
22 : // max number of vDeviceId
23 : constexpr const uint32_t VDEVICE_MAX_CPU_NUM = 64U;
24 :
25 : class FeatureCtrl {
26 : public:
27 : static void Init(const int64_t hardwareVersion, const uint32_t deviceId);
28 :
29 : static bool IsAosCore();
30 :
31 : static bool ShouldAddtocGroup();
32 :
33 : static bool ShouldSkipSupplyEvent();
34 :
35 : static bool IsBindPidByHal();
36 :
37 : static bool IsHeterogeneousProduct();
38 :
39 : static bool IsNoNeedDumpOpDebugProduct();
40 :
41 : static bool IsDoubleDieProduct();
42 :
43 : static bool BindCpuOnlyOneDevice();
44 :
45 : static bool IfCheckEventSender();
46 :
47 : static bool IsUseMsqV2();
48 :
49 : static bool ShouldInitDrvThread();
50 :
51 : static bool ShouldLoadExtendKernelSo();
52 :
53 : static bool ShouldSubmitTaskOneByOne();
54 :
55 : static bool ShouldMonitorWork();
56 :
57 : static bool ShouldSetModuleNullData();
58 :
59 32 : static inline bool IsVfMode(const uint32_t deviceId, const uint32_t vfId)
60 : {
61 32 : if ((IsVfModeCheckedByDeviceId(deviceId)) || (vfId > 0)) {
62 6 : return true;
63 : } else {
64 26 : return false;
65 : }
66 : }
67 :
68 209 : static inline bool IsVfModeCheckedByDeviceId(const uint32_t deviceId)
69 : {
70 209 : if ((deviceId >= VDEVICE_MIN_CPU_NUM) && (deviceId < VDEVICE_MAX_CPU_NUM)) {
71 12 : return true;
72 : } else {
73 197 : return false;
74 : }
75 : }
76 :
77 60 : static inline bool IsVfModeDie1(const uint32_t deviceId)
78 : {
79 60 : if ((deviceId >= VDEVICE_MID_CPU_NUM) && (deviceId < VDEVICE_MAX_CPU_NUM)) {
80 2 : return true;
81 : } else {
82 58 : return false;
83 : }
84 : }
85 :
86 2 : static inline void SetTsMsgVersion(uint16_t version)
87 : {
88 2 : if (isSetTsMsgVersion_) {
89 0 : return;
90 : }
91 2 : tsMsgVersion_ = version;
92 2 : isSetTsMsgVersion_ = true;
93 2 : return;
94 : }
95 :
96 243 : static inline uint16_t GetTsMsgVersion() { return tsMsgVersion_; }
97 :
98 25 : static inline void ClearTsMsgVersionInfo()
99 : {
100 25 : tsMsgVersion_ = 0;
101 25 : isSetTsMsgVersion_ = false;
102 25 : }
103 :
104 136 : static inline AicpuSchedMode GetAicpuSchedMode() { return aicpuSchedMode_; }
105 :
106 : private:
107 : FeatureCtrl() = default;
108 : ~FeatureCtrl() = default;
109 :
110 : FeatureCtrl(FeatureCtrl const&) = delete;
111 : FeatureCtrl& operator=(FeatureCtrl const&) = delete;
112 : FeatureCtrl(FeatureCtrl&&) = delete;
113 : FeatureCtrl& operator=(FeatureCtrl&&) = delete;
114 : static void InitMsqEnableStatus(const uint32_t deviceId);
115 : static bool aicpuFeatureBindPidByHal_;
116 : static bool aicpuFeatureDoubleDieProduct_;
117 : static bool aicpuFeatureCheckEventSender_;
118 : static bool aicpuFeatureInitDrvScheModule_;
119 : static bool aicpuFeatureLoadExtendKernelSo_;
120 : static bool aicpuFeatureAddToCGroup_;
121 : static bool aicpuFeatureSubmitTaskOneByOne_;
122 : static bool aicpuFeatureMonitorWork_;
123 : static bool aicpuFeatureSetModelNullData_;
124 : static uint16_t tsMsgVersion_;
125 : static std::atomic<bool> isSetTsMsgVersion_;
126 : static bool aicpuFeatureUseMsqV2_;
127 : static AicpuSchedMode aicpuSchedMode_;
128 : };
129 :
130 : } // namespace AicpuSchedule
131 :
132 : #endif // COMMON_AICPUSD_FEATURE_CTRL_H
|