|
| 1 | +/* |
| 2 | + * Copyright (C) 2021-2022 Intel Corporation |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: MIT |
| 5 | + * |
| 6 | + */ |
| 7 | + |
| 8 | +#pragma once |
| 9 | +#include "level_zero/tools/source/sysman/performance/linux/os_performance_imp_prelim.h" |
| 10 | + |
| 11 | +#include "sysman/linux/fs_access.h" |
| 12 | +#include "sysman/performance/performance.h" |
| 13 | +#include "sysman/performance/performance_imp.h" |
| 14 | + |
| 15 | +namespace L0 { |
| 16 | +namespace ult { |
| 17 | + |
| 18 | +const std::string mediaFreqFactorSubDevice0("gt/gt0/media_freq_factor"); |
| 19 | +const std::string mediaScaleSubDevice0("gt/gt0/media_freq_factor.scale"); |
| 20 | +const std::string baseFreqFactorSubDevice0("gt/gt0/base_freq_factor"); |
| 21 | +const std::string baseScaleSubDevice0("gt/gt0/base_freq_factor.scale"); |
| 22 | +const std::string mediaFreqFactorSubDevice1("gt/gt1/media_freq_factor"); |
| 23 | +const std::string mediaScaleSubDevice1("gt/gt1/media_freq_factor.scale"); |
| 24 | +const std::string baseFreqFactorSubDevice1("gt/gt1/base_freq_factor"); |
| 25 | +const std::string baseScaleSubDevice1("gt/gt1/base_freq_factor.scale"); |
| 26 | +const std::string pwrBalance("sys_pwr_balance"); |
| 27 | +class PerformanceSysfsAccess : public SysfsAccess {}; |
| 28 | + |
| 29 | +template <> |
| 30 | +struct Mock<PerformanceSysfsAccess> : public PerformanceSysfsAccess { |
| 31 | + ze_result_t mockReadResult = ZE_RESULT_SUCCESS; |
| 32 | + ze_result_t mockCanReadResult = ZE_RESULT_SUCCESS; |
| 33 | + ze_bool_t isComputeInvalid = false; |
| 34 | + ze_bool_t isReturnUnknownFailure = false; |
| 35 | + ze_bool_t returnNegativeFactor = false; |
| 36 | + ze_bool_t isMediaBaseFailure = false; |
| 37 | + |
| 38 | + ze_result_t getValWithMultiplierReturnOne(const std::string file, double &val) { |
| 39 | + if ((file.compare(baseFreqFactorSubDevice0) == 0) || (file.compare(baseFreqFactorSubDevice1) == 0)) { |
| 40 | + val = mockBaseVal1; |
| 41 | + } else if ((file.compare(mediaFreqFactorSubDevice0) == 0) || (file.compare(mediaFreqFactorSubDevice1) == 0)) { |
| 42 | + val = mockMediaVal1; |
| 43 | + } else if ((file.compare(mediaScaleSubDevice0) == 0) || (file.compare(mediaScaleSubDevice1) == 0) || (file.compare(baseScaleSubDevice0) == 0) || (file.compare(baseScaleSubDevice1) == 0)) { |
| 44 | + val = mockScale; |
| 45 | + } else if (file.compare(pwrBalance) == 0) { |
| 46 | + val = mockPwrBalance; |
| 47 | + } else { |
| 48 | + return ZE_RESULT_ERROR_NOT_AVAILABLE; |
| 49 | + } |
| 50 | + return ZE_RESULT_SUCCESS; |
| 51 | + } |
| 52 | + |
| 53 | + ze_result_t getValUnknownFailure(const std::string file, double &val) { |
| 54 | + if ((file.compare(baseFreqFactorSubDevice0) == 0) || (file.compare(baseFreqFactorSubDevice1) == 0)) { |
| 55 | + val = 64.0; |
| 56 | + } else if ((file.compare(mediaFreqFactorSubDevice0) == 0) || (file.compare(mediaFreqFactorSubDevice1) == 0)) { |
| 57 | + val = 384.0; |
| 58 | + } else if ((file.compare(mediaScaleSubDevice0) == 0) || (file.compare(mediaScaleSubDevice1) == 0) || (file.compare(baseScaleSubDevice0) == 0) || (file.compare(baseScaleSubDevice1) == 0)) { |
| 59 | + val = mockScale; |
| 60 | + } else if (file.compare(pwrBalance) == 0) { |
| 61 | + val = 100.0; |
| 62 | + } else { |
| 63 | + return ZE_RESULT_ERROR_NOT_AVAILABLE; |
| 64 | + } |
| 65 | + return ZE_RESULT_SUCCESS; |
| 66 | + } |
| 67 | + |
| 68 | + ze_result_t getValNegative(const std::string file, double &val) { |
| 69 | + const std::list<std::string> nodeList = {baseFreqFactorSubDevice0, baseFreqFactorSubDevice1, mediaFreqFactorSubDevice0, mediaFreqFactorSubDevice1, mediaScaleSubDevice0, mediaScaleSubDevice1, baseScaleSubDevice0, baseScaleSubDevice1, pwrBalance}; |
| 70 | + for (const auto &node : nodeList) { |
| 71 | + if ((file.compare(node) == 0)) { |
| 72 | + val = -1.0; |
| 73 | + return ZE_RESULT_SUCCESS; |
| 74 | + } |
| 75 | + } |
| 76 | + return ZE_RESULT_ERROR_NOT_AVAILABLE; |
| 77 | + } |
| 78 | + |
| 79 | + ze_result_t getValMediaBaseFailure(const std::string file, double &val) { |
| 80 | + if ((file.compare(baseFreqFactorSubDevice0) == 0) || (file.compare(baseFreqFactorSubDevice1) == 0) || (file.compare(mediaFreqFactorSubDevice0) == 0) || (file.compare(mediaFreqFactorSubDevice1) == 0) || (file.compare(pwrBalance) == 0)) { |
| 81 | + return ZE_RESULT_ERROR_NOT_AVAILABLE; |
| 82 | + } |
| 83 | + if ((file.compare(mediaScaleSubDevice0) == 0) || (file.compare(mediaScaleSubDevice1) == 0) || (file.compare(baseScaleSubDevice0) == 0) || (file.compare(baseScaleSubDevice1) == 0)) { |
| 84 | + val = mockScale; |
| 85 | + } |
| 86 | + return ZE_RESULT_SUCCESS; |
| 87 | + } |
| 88 | + |
| 89 | + ze_result_t getValComputeInvalid(const std::string file, double &val) { |
| 90 | + if ((file.compare(baseFreqFactorSubDevice0) == 0) || (file.compare(baseFreqFactorSubDevice1) == 0)) { |
| 91 | + val = 1024.0; |
| 92 | + } else if ((file.compare(mediaScaleSubDevice0) == 0) || (file.compare(mediaScaleSubDevice1) == 0) || (file.compare(baseScaleSubDevice0) == 0) || (file.compare(baseScaleSubDevice1) == 0)) { |
| 93 | + val = mockScale; |
| 94 | + } else { |
| 95 | + return ZE_RESULT_ERROR_NOT_AVAILABLE; |
| 96 | + } |
| 97 | + return ZE_RESULT_SUCCESS; |
| 98 | + } |
| 99 | + |
| 100 | + ze_result_t getValScaleFailure(const std::string file, double &val) { |
| 101 | + if ((file.compare(mediaScaleSubDevice0) == 0) || (file.compare(mediaScaleSubDevice1) == 0) || (file.compare(baseScaleSubDevice0) == 0) || (file.compare(baseScaleSubDevice1) == 0)) { |
| 102 | + return ZE_RESULT_ERROR_NOT_AVAILABLE; |
| 103 | + } |
| 104 | + return ZE_RESULT_SUCCESS; |
| 105 | + } |
| 106 | + |
| 107 | + ze_result_t canRead(const std::string file) override { |
| 108 | + if (mockCanReadResult != ZE_RESULT_SUCCESS) { |
| 109 | + return mockCanReadResult; |
| 110 | + } |
| 111 | + |
| 112 | + if ((file.compare(baseFreqFactorSubDevice0) == 0) || (file.compare(baseFreqFactorSubDevice1) == 0) || (file.compare(mediaFreqFactorSubDevice0) == 0) || (file.compare(mediaFreqFactorSubDevice1) == 0) || (file.compare(pwrBalance) == 0)) { |
| 113 | + return ZE_RESULT_SUCCESS; |
| 114 | + } |
| 115 | + return ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS; |
| 116 | + } |
| 117 | + |
| 118 | + ze_result_t write(const std::string file, const double val) override { |
| 119 | + if ((file.compare(baseFreqFactorSubDevice0) == 0) || (file.compare(baseFreqFactorSubDevice1) == 0)) { |
| 120 | + mockBaseVal1 = val; |
| 121 | + } else if ((file.compare(mediaFreqFactorSubDevice0) == 0) || (file.compare(mediaFreqFactorSubDevice1) == 0)) { |
| 122 | + mockMediaVal1 = val; |
| 123 | + } else if (file.compare(pwrBalance) == 0) { |
| 124 | + mockPwrBalance = val; |
| 125 | + } else { |
| 126 | + return ZE_RESULT_ERROR_NOT_AVAILABLE; |
| 127 | + } |
| 128 | + return ZE_RESULT_SUCCESS; |
| 129 | + } |
| 130 | + |
| 131 | + ze_result_t read(const std::string file, double &val) override { |
| 132 | + if (mockReadResult != ZE_RESULT_SUCCESS) { |
| 133 | + return mockReadResult; |
| 134 | + } |
| 135 | + |
| 136 | + if (isReturnUnknownFailure) { |
| 137 | + return getValUnknownFailure(file, val); |
| 138 | + } else if (isMediaBaseFailure) { |
| 139 | + return getValMediaBaseFailure(file, val); |
| 140 | + } else if (isComputeInvalid) { |
| 141 | + return getValComputeInvalid(file, val); |
| 142 | + } else if (returnNegativeFactor) { |
| 143 | + return getValNegative(file, val); |
| 144 | + } else { |
| 145 | + return getValWithMultiplierReturnOne(file, val); |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + double mockBaseVal1 = 128.0; |
| 150 | + double mockMediaVal1 = 256.0; |
| 151 | + double mockMultiplierBase = 256.0; |
| 152 | + double mockMultiplierMedia = 512.0; |
| 153 | + double mockScale = 0.00390625; |
| 154 | + double mockPwrBalance = 0.0; |
| 155 | + Mock<PerformanceSysfsAccess>() = default; |
| 156 | +}; |
| 157 | + |
| 158 | +class PublicLinuxPerformanceImp : public L0::LinuxPerformanceImp { |
| 159 | + public: |
| 160 | + PublicLinuxPerformanceImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId, zes_engine_type_flag_t domain) : LinuxPerformanceImp(pOsSysman, onSubdevice, subdeviceId, domain) {} |
| 161 | + using LinuxPerformanceImp::domain; |
| 162 | + using LinuxPerformanceImp::pSysfsAccess; |
| 163 | +}; |
| 164 | + |
| 165 | +} // namespace ult |
| 166 | +} // namespace L0 |
0 commit comments