1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/helpers/non_copyable_or_moveable.h"
#include "level_zero/tools/source/sysman/linux/fs_access.h"
#include <map>
namespace L0 {
class PlatformMonitoringTech : NEO::NonCopyableOrMovableClass {
public:
PlatformMonitoringTech() = default;
virtual ~PlatformMonitoringTech();
MOCKABLE_VIRTUAL void init(const std::string &deviceName, FsAccess *pFsAccess);
template <typename ReadType>
ze_result_t readValue(const std::string key, ReadType &value);
bool isPmtSupported() { return pmtSupported; }
protected:
bool pmtSupported = false;
char *mappedMemory = nullptr;
private:
static const std::string baseTelemDevice;
static const std::string baseTelemSysFS;
uint64_t size = 0;
uint64_t baseOffset = 0;
};
const std::map<std::string, uint64_t> keyOffsetMap = {
{"PACKAGE_ENERGY", 0x400},
{"COMPUTE_TEMPERATURES", 0x68},
{"SOC_TEMPERATURES", 0x60},
{"CORE_TEMPERATURES", 0x6c}};
template <typename ReadType>
ze_result_t PlatformMonitoringTech::readValue(const std::string key, ReadType &value) {
if (!pmtSupported) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
auto offset = keyOffsetMap.find(key);
if (offset == keyOffsetMap.end()) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
value = *reinterpret_cast<ReadType *>(mappedMemory + offset->second);
return ZE_RESULT_SUCCESS;
}
} // namespace L0
|