2019-03-04 18:26:11 -06:00
|
|
|
/*
|
2017-10-30 12:12:40 -05:00
|
|
|
* =============================================================================
|
|
|
|
|
* The University of Illinois/NCSA
|
|
|
|
|
* Open Source License (NCSA)
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2017, Advanced Micro Devices, Inc.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Developed by:
|
|
|
|
|
*
|
|
|
|
|
* AMD Research and AMD ROC Software Development
|
|
|
|
|
*
|
|
|
|
|
* Advanced Micro Devices, Inc.
|
|
|
|
|
*
|
|
|
|
|
* www.amd.com
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to
|
|
|
|
|
* deal with the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* - Redistributions of source code must retain the above copyright notice,
|
|
|
|
|
* this list of conditions and the following disclaimers.
|
|
|
|
|
* - Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimers in
|
|
|
|
|
* the documentation and/or other materials provided with the distribution.
|
|
|
|
|
* - Neither the names of <Name of Development Group, Name of Institution>,
|
|
|
|
|
* nor the names of its contributors may be used to endorse or promote
|
|
|
|
|
* products derived from this Software without specific prior written
|
|
|
|
|
* permission.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS WITH THE SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2019-05-04 15:10:58 -05:00
|
|
|
#include <pthread.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
2017-10-30 12:12:40 -05:00
|
|
|
#include <assert.h>
|
|
|
|
|
#include <sys/stat.h>
|
2018-09-16 00:13:29 -05:00
|
|
|
#include <stdint.h>
|
2017-10-30 12:12:40 -05:00
|
|
|
#include <string>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "rocm_smi/rocm_smi_main.h"
|
|
|
|
|
#include "rocm_smi/rocm_smi_device.h"
|
2018-09-16 00:13:29 -05:00
|
|
|
#include "rocm_smi/rocm_smi.h"
|
2019-05-04 15:10:58 -05:00
|
|
|
#include "rocm_smi/rocm_smi_exception.h"
|
2019-07-03 11:29:19 -05:00
|
|
|
#include "rocm_smi/rocm_smi_utils.h"
|
2019-05-04 15:10:58 -05:00
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
#include "shared_mutex.h" // NOLINT
|
|
|
|
|
};
|
2017-10-30 12:12:40 -05:00
|
|
|
|
|
|
|
|
namespace amd {
|
|
|
|
|
namespace smi {
|
|
|
|
|
|
2019-03-01 16:33:11 -06:00
|
|
|
// Sysfs file names
|
2017-10-30 12:12:40 -05:00
|
|
|
static const char *kDevPerfLevelFName = "power_dpm_force_performance_level";
|
|
|
|
|
static const char *kDevDevIDFName = "device";
|
2019-03-15 16:21:37 -05:00
|
|
|
static const char *kDevVendorIDFName = "vendor";
|
|
|
|
|
static const char *kDevSubSysDevIDFName = "subsystem_device";
|
|
|
|
|
static const char *kDevSubSysVendorIDFName = "subsystem_vendor";
|
2017-10-30 12:12:40 -05:00
|
|
|
static const char *kDevOverDriveLevelFName = "pp_sclk_od";
|
|
|
|
|
static const char *kDevGPUSClkFName = "pp_dpm_sclk";
|
|
|
|
|
static const char *kDevGPUMClkFName = "pp_dpm_mclk";
|
2019-03-28 17:01:35 -05:00
|
|
|
static const char *kDevDCEFClkFName = "pp_dpm_dcefclk";
|
|
|
|
|
static const char *kDevFClkFName = "pp_dpm_fclk";
|
|
|
|
|
static const char *kDevSOCClkFName = "pp_dpm_socclk";
|
2018-11-16 15:55:38 -06:00
|
|
|
static const char *kDevGPUPCIEClkFname = "pp_dpm_pcie";
|
2018-11-12 17:25:14 -06:00
|
|
|
static const char *kDevPowerProfileModeFName = "pp_power_profile_mode";
|
2019-01-07 08:44:23 -06:00
|
|
|
static const char *kDevPowerODVoltageFName = "pp_od_clk_voltage";
|
2018-11-12 17:25:14 -06:00
|
|
|
static const char *kDevUsageFName = "gpu_busy_percent";
|
2019-02-24 11:01:18 -06:00
|
|
|
static const char *kDevVBiosVerFName = "vbios_version";
|
2019-02-27 15:10:26 -06:00
|
|
|
static const char *kDevPCIEThruPutFName = "pcie_bw";
|
2019-03-01 16:33:11 -06:00
|
|
|
static const char *kDevErrCntSDMAFName = "ras/sdma_err_count";
|
|
|
|
|
static const char *kDevErrCntUMCFName = "ras/umc_err_count";
|
|
|
|
|
static const char *kDevErrCntGFXFName = "ras/gfx_err_count";
|
2019-04-03 11:17:43 -05:00
|
|
|
static const char *kDevErrCntFeaturesFName = "ras/features";
|
2019-08-06 11:05:23 -05:00
|
|
|
static const char *kDevMemPageBadFName = "ras/gpu_vram_bad_pages";
|
2019-03-04 18:26:11 -06:00
|
|
|
static const char *kDevMemTotGTTFName = "mem_info_gtt_total";
|
|
|
|
|
static const char *kDevMemTotVisVRAMFName = "mem_info_vis_vram_total";
|
|
|
|
|
static const char *kDevMemTotVRAMFName = "mem_info_vram_total";
|
|
|
|
|
static const char *kDevMemUsedGTTFName = "mem_info_gtt_used";
|
|
|
|
|
static const char *kDevMemUsedVisVRAMFName = "mem_info_vis_vram_used";
|
|
|
|
|
static const char *kDevMemUsedVRAMFName = "mem_info_vram_used";
|
2019-05-06 11:26:40 -05:00
|
|
|
static const char *kDevPCIEReplayCountFName = "pcie_replay_count";
|
2019-06-20 06:55:56 -04:00
|
|
|
static const char *kDevUniqueIdFName = "unique_id";
|
2019-06-22 20:54:31 -05:00
|
|
|
static const char *kDevDFCountersAvailableFName = "df_cntr_avail";
|
2019-06-25 14:21:34 -05:00
|
|
|
static const char *kDevMemBusyPercentFName = "mem_busy_percent";
|
2019-07-09 08:46:08 -05:00
|
|
|
static const char *kDevXGMIErrorFName = "xgmi_error";
|
2019-07-22 07:09:53 -05:00
|
|
|
static const char *kDevSerialNumberFName = "serial_number";
|
2019-03-01 16:33:11 -06:00
|
|
|
|
|
|
|
|
// Strings that are found within sysfs files
|
2018-09-16 00:13:29 -05:00
|
|
|
static const char *kDevPerfLevelAutoStr = "auto";
|
|
|
|
|
static const char *kDevPerfLevelLowStr = "low";
|
|
|
|
|
static const char *kDevPerfLevelHighStr = "high";
|
|
|
|
|
static const char *kDevPerfLevelManualStr = "manual";
|
2018-10-25 14:13:55 -05:00
|
|
|
static const char *kDevPerfLevelStandardStr = "profile_standard";
|
|
|
|
|
static const char *kDevPerfLevelMinMClkStr = "profile_min_mclk";
|
|
|
|
|
static const char *kDevPerfLevelMinSClkStr = "profile_min_sclk";
|
|
|
|
|
static const char *kDevPerfLevelPeakStr = "profile_peak";
|
2018-09-16 00:13:29 -05:00
|
|
|
static const char *kDevPerfLevelUnknownStr = "unknown";
|
2017-10-30 12:12:40 -05:00
|
|
|
|
2019-07-09 20:48:28 -05:00
|
|
|
// Firmware version files
|
|
|
|
|
static const char *kDevFwVersionAsdFName = "fw_version/asd_fw_version";
|
|
|
|
|
static const char *kDevFwVersionCeFName = "fw_version/ce_fw_version";
|
|
|
|
|
static const char *kDevFwVersionDmcuFName = "fw_version/dmcu_fw_version";
|
|
|
|
|
static const char *kDevFwVersionMcFName = "fw_version/mc_fw_version";
|
|
|
|
|
static const char *kDevFwVersionMeFName = "fw_version/me_fw_version";
|
|
|
|
|
static const char *kDevFwVersionMecFName = "fw_version/mec_fw_version";
|
|
|
|
|
static const char *kDevFwVersionMec2FName = "fw_version/mec2_fw_version";
|
|
|
|
|
static const char *kDevFwVersionPfpFName = "fw_version/pfp_fw_version";
|
|
|
|
|
static const char *kDevFwVersionRlcFName = "fw_version/rlc_fw_version";
|
|
|
|
|
static const char *kDevFwVersionRlcSrlcFName = "fw_version/rlc_srlc_fw_version";
|
|
|
|
|
static const char *kDevFwVersionRlcSrlgFName = "fw_version/rlc_srlg_fw_version";
|
|
|
|
|
static const char *kDevFwVersionRlcSrlsFName = "fw_version/rlc_srls_fw_version";
|
|
|
|
|
static const char *kDevFwVersionSdmaFName = "fw_version/sdma_fw_version";
|
|
|
|
|
static const char *kDevFwVersionSdma2FName = "fw_version/sdma2_fw_version";
|
|
|
|
|
static const char *kDevFwVersionSmcFName = "fw_version/smc_fw_version";
|
|
|
|
|
static const char *kDevFwVersionSosFName = "fw_version/sos_fw_version";
|
|
|
|
|
static const char *kDevFwVersionTaRasFName = "fw_version/ta_ras_fw_version";
|
|
|
|
|
static const char *kDevFwVersionTaXgmiFName = "fw_version/ta_xgmi_fw_version";
|
|
|
|
|
static const char *kDevFwVersionUvdFName = "fw_version/uvd_fw_version";
|
|
|
|
|
static const char *kDevFwVersionVceFName = "fw_version/vce_fw_version";
|
|
|
|
|
static const char *kDevFwVersionVcnFName = "fw_version/vcn_fw_version";
|
|
|
|
|
|
|
|
|
|
|
2017-10-30 12:12:40 -05:00
|
|
|
static const std::map<DevInfoTypes, const char *> kDevAttribNameMap = {
|
|
|
|
|
{kDevPerfLevel, kDevPerfLevelFName},
|
|
|
|
|
{kDevOverDriveLevel, kDevOverDriveLevelFName},
|
|
|
|
|
{kDevDevID, kDevDevIDFName},
|
2019-03-15 16:21:37 -05:00
|
|
|
{kDevVendorID, kDevVendorIDFName},
|
|
|
|
|
{kDevSubSysDevID, kDevSubSysDevIDFName},
|
|
|
|
|
{kDevSubSysVendorID, kDevSubSysVendorIDFName},
|
2017-10-30 12:12:40 -05:00
|
|
|
{kDevGPUMClk, kDevGPUMClkFName},
|
|
|
|
|
{kDevGPUSClk, kDevGPUSClkFName},
|
2019-03-28 17:01:35 -05:00
|
|
|
{kDevDCEFClk, kDevDCEFClkFName},
|
|
|
|
|
{kDevFClk, kDevFClkFName},
|
|
|
|
|
{kDevSOCClk, kDevSOCClkFName},
|
2019-02-27 15:10:26 -06:00
|
|
|
{kDevPCIEClk, kDevGPUPCIEClkFname},
|
2018-11-12 17:25:14 -06:00
|
|
|
{kDevPowerProfileMode, kDevPowerProfileModeFName},
|
|
|
|
|
{kDevUsage, kDevUsageFName},
|
2019-01-07 08:44:23 -06:00
|
|
|
{kDevPowerODVoltage, kDevPowerODVoltageFName},
|
2019-02-24 11:01:18 -06:00
|
|
|
{kDevVBiosVer, kDevVBiosVerFName},
|
2019-02-27 15:10:26 -06:00
|
|
|
{kDevPCIEThruPut, kDevPCIEThruPutFName},
|
2019-03-01 16:33:11 -06:00
|
|
|
{kDevErrCntSDMA, kDevErrCntSDMAFName},
|
|
|
|
|
{kDevErrCntUMC, kDevErrCntUMCFName},
|
|
|
|
|
{kDevErrCntGFX, kDevErrCntGFXFName},
|
2019-04-03 11:17:43 -05:00
|
|
|
{kDevErrCntFeatures, kDevErrCntFeaturesFName},
|
2019-03-04 18:26:11 -06:00
|
|
|
{kDevMemTotGTT, kDevMemTotGTTFName},
|
|
|
|
|
{kDevMemTotVisVRAM, kDevMemTotVisVRAMFName},
|
2019-06-25 14:21:34 -05:00
|
|
|
{kDevMemBusyPercent, kDevMemBusyPercentFName},
|
2019-03-04 18:26:11 -06:00
|
|
|
{kDevMemTotVRAM, kDevMemTotVRAMFName},
|
|
|
|
|
{kDevMemUsedGTT, kDevMemUsedGTTFName},
|
|
|
|
|
{kDevMemUsedVisVRAM, kDevMemUsedVisVRAMFName},
|
|
|
|
|
{kDevMemUsedVRAM, kDevMemUsedVRAMFName},
|
2019-05-06 11:26:40 -05:00
|
|
|
{kDevPCIEReplayCount, kDevPCIEReplayCountFName},
|
2019-06-20 06:55:56 -04:00
|
|
|
{kDevUniqueId, kDevUniqueIdFName},
|
2019-06-22 20:54:31 -05:00
|
|
|
{kDevDFCountersAvailable, kDevDFCountersAvailableFName},
|
2019-07-09 08:46:08 -05:00
|
|
|
{kDevXGMIError, kDevXGMIErrorFName},
|
2019-07-09 20:48:28 -05:00
|
|
|
{kDevFwVersionAsd, kDevFwVersionAsdFName},
|
|
|
|
|
{kDevFwVersionCe, kDevFwVersionCeFName},
|
|
|
|
|
{kDevFwVersionDmcu, kDevFwVersionDmcuFName},
|
|
|
|
|
{kDevFwVersionMc, kDevFwVersionMcFName},
|
|
|
|
|
{kDevFwVersionMe, kDevFwVersionMeFName},
|
|
|
|
|
{kDevFwVersionMec, kDevFwVersionMecFName},
|
|
|
|
|
{kDevFwVersionMec2, kDevFwVersionMec2FName},
|
|
|
|
|
{kDevFwVersionPfp, kDevFwVersionPfpFName},
|
|
|
|
|
{kDevFwVersionRlc, kDevFwVersionRlcFName},
|
|
|
|
|
{kDevFwVersionRlcSrlc, kDevFwVersionRlcSrlcFName},
|
|
|
|
|
{kDevFwVersionRlcSrlg, kDevFwVersionRlcSrlgFName},
|
|
|
|
|
{kDevFwVersionRlcSrls, kDevFwVersionRlcSrlsFName},
|
|
|
|
|
{kDevFwVersionSdma, kDevFwVersionSdmaFName},
|
|
|
|
|
{kDevFwVersionSdma2, kDevFwVersionSdma2FName},
|
|
|
|
|
{kDevFwVersionSmc, kDevFwVersionSmcFName},
|
|
|
|
|
{kDevFwVersionSos, kDevFwVersionSosFName},
|
|
|
|
|
{kDevFwVersionTaRas, kDevFwVersionTaRasFName},
|
|
|
|
|
{kDevFwVersionTaXgmi, kDevFwVersionTaXgmiFName},
|
|
|
|
|
{kDevFwVersionUvd, kDevFwVersionUvdFName},
|
|
|
|
|
{kDevFwVersionVce, kDevFwVersionVceFName},
|
|
|
|
|
{kDevFwVersionVcn, kDevFwVersionVcnFName},
|
2019-07-22 07:09:53 -05:00
|
|
|
{kDevSerialNumber, kDevSerialNumberFName},
|
2019-08-06 11:05:23 -05:00
|
|
|
{kDevMemPageBad, kDevMemPageBadFName},
|
2018-09-16 00:13:29 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const std::map<rsmi_dev_perf_level, const char *> kDevPerfLvlMap = {
|
|
|
|
|
{RSMI_DEV_PERF_LEVEL_AUTO, kDevPerfLevelAutoStr},
|
|
|
|
|
{RSMI_DEV_PERF_LEVEL_LOW, kDevPerfLevelLowStr},
|
|
|
|
|
{RSMI_DEV_PERF_LEVEL_HIGH, kDevPerfLevelHighStr},
|
|
|
|
|
{RSMI_DEV_PERF_LEVEL_MANUAL, kDevPerfLevelManualStr},
|
2018-10-25 14:13:55 -05:00
|
|
|
{RSMI_DEV_PERF_LEVEL_STABLE_STD, kDevPerfLevelStandardStr},
|
|
|
|
|
{RSMI_DEV_PERF_LEVEL_STABLE_MIN_MCLK, kDevPerfLevelMinMClkStr},
|
|
|
|
|
{RSMI_DEV_PERF_LEVEL_STABLE_MIN_SCLK, kDevPerfLevelMinSClkStr},
|
|
|
|
|
{RSMI_DEV_PERF_LEVEL_STABLE_PEAK, kDevPerfLevelPeakStr},
|
|
|
|
|
|
2018-09-16 00:13:29 -05:00
|
|
|
{RSMI_DEV_PERF_LEVEL_UNKNOWN, kDevPerfLevelUnknownStr},
|
2017-10-30 12:12:40 -05:00
|
|
|
};
|
|
|
|
|
|
2018-09-16 00:13:29 -05:00
|
|
|
#define RET_IF_NONZERO(X) { \
|
|
|
|
|
if (X) return X; \
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 17:26:38 -05:00
|
|
|
Device::Device(std::string p, RocmSMI_env_vars const *e) : path_(p), env_(e) {
|
2017-10-30 12:12:40 -05:00
|
|
|
monitor_ = nullptr;
|
2019-05-04 15:10:58 -05:00
|
|
|
|
|
|
|
|
// Get the device name
|
|
|
|
|
size_t i = path_.rfind('/', path_.length());
|
|
|
|
|
std::string dev = path_.substr(i + 1, path_.length() - i);
|
|
|
|
|
|
|
|
|
|
std::string m_name("/rocm_smi_");
|
|
|
|
|
m_name += dev;
|
|
|
|
|
m_name += '_';
|
|
|
|
|
m_name += std::to_string(geteuid());
|
|
|
|
|
|
|
|
|
|
mutex_ = shared_mutex_init(m_name.c_str(), 0777);
|
|
|
|
|
|
|
|
|
|
if (mutex_.ptr == nullptr) {
|
|
|
|
|
throw amd::smi::rsmi_exception(RSMI_INITIALIZATION_ERROR,
|
|
|
|
|
"Failed to create shared mem. mutex.");
|
|
|
|
|
}
|
2017-10-30 12:12:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Device:: ~Device() {
|
2019-05-04 15:10:58 -05:00
|
|
|
shared_mutex_close(mutex_);
|
2017-10-30 12:12:40 -05:00
|
|
|
}
|
|
|
|
|
|
2019-02-24 11:01:18 -06:00
|
|
|
template <typename T>
|
2019-03-28 17:01:35 -05:00
|
|
|
int Device::openSysfsFileStream(DevInfoTypes type, T *fs, const char *str) {
|
2019-02-24 11:01:18 -06:00
|
|
|
auto sysfs_path = path_;
|
2017-10-30 12:12:40 -05:00
|
|
|
|
2019-02-22 15:05:44 -06:00
|
|
|
if (env_->path_DRM_root_override && type == env_->enum_override) {
|
2019-02-24 11:01:18 -06:00
|
|
|
sysfs_path = env_->path_DRM_root_override;
|
2019-02-25 15:14:46 -06:00
|
|
|
|
2019-03-28 17:01:35 -05:00
|
|
|
if (str) {
|
2019-02-25 15:14:46 -06:00
|
|
|
sysfs_path += ".write";
|
|
|
|
|
}
|
2019-02-22 15:05:44 -06:00
|
|
|
}
|
|
|
|
|
|
2019-02-24 11:01:18 -06:00
|
|
|
sysfs_path += "/device/";
|
|
|
|
|
sysfs_path += kDevAttribNameMap.at(type);
|
2017-10-30 12:12:40 -05:00
|
|
|
|
2019-03-28 17:01:35 -05:00
|
|
|
DBG_FILE_ERROR(sysfs_path, str);
|
2019-06-22 20:54:31 -05:00
|
|
|
bool reg_file;
|
|
|
|
|
|
|
|
|
|
int ret = isRegularFile(sysfs_path, ®_file);
|
|
|
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
if (!reg_file) {
|
2019-05-06 11:26:40 -05:00
|
|
|
return ENOENT;
|
2018-09-16 00:13:29 -05:00
|
|
|
}
|
|
|
|
|
|
2019-02-24 11:01:18 -06:00
|
|
|
fs->open(sysfs_path);
|
2017-10-30 12:12:40 -05:00
|
|
|
|
2019-02-24 11:01:18 -06:00
|
|
|
if (!fs->is_open()) {
|
2018-09-16 00:13:29 -05:00
|
|
|
return errno;
|
2017-10-30 12:12:40 -05:00
|
|
|
}
|
2018-09-16 00:13:29 -05:00
|
|
|
|
2017-10-30 12:12:40 -05:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-24 11:01:18 -06:00
|
|
|
int Device::readDevInfoStr(DevInfoTypes type, std::string *retStr) {
|
|
|
|
|
std::ifstream fs;
|
|
|
|
|
int ret = 0;
|
2019-02-22 15:05:44 -06:00
|
|
|
|
2019-02-24 11:01:18 -06:00
|
|
|
assert(retStr != nullptr);
|
|
|
|
|
|
|
|
|
|
ret = openSysfsFileStream(type, &fs);
|
|
|
|
|
if (ret != 0) {
|
|
|
|
|
return ret;
|
2019-02-22 15:05:44 -06:00
|
|
|
}
|
|
|
|
|
|
2019-02-24 11:01:18 -06:00
|
|
|
fs >> *retStr;
|
|
|
|
|
fs.close();
|
2018-09-16 00:13:29 -05:00
|
|
|
|
2019-02-24 11:01:18 -06:00
|
|
|
return 0;
|
|
|
|
|
}
|
2019-02-22 15:05:44 -06:00
|
|
|
|
2019-02-24 11:01:18 -06:00
|
|
|
int Device::writeDevInfoStr(DevInfoTypes type, std::string valStr) {
|
|
|
|
|
auto tempPath = path_;
|
2018-09-16 00:13:29 -05:00
|
|
|
std::ofstream fs;
|
2019-02-24 11:01:18 -06:00
|
|
|
int ret;
|
2018-09-16 00:13:29 -05:00
|
|
|
|
2019-03-28 17:01:35 -05:00
|
|
|
ret = openSysfsFileStream(type, &fs, valStr.c_str());
|
2019-02-24 11:01:18 -06:00
|
|
|
if (ret != 0) {
|
|
|
|
|
return ret;
|
2018-09-16 00:13:29 -05:00
|
|
|
}
|
|
|
|
|
|
2019-02-22 15:05:44 -06:00
|
|
|
try {
|
|
|
|
|
fs << valStr;
|
|
|
|
|
} catch (...) {
|
|
|
|
|
std::cout << "Write to file threw exception" << std::endl;
|
|
|
|
|
}
|
2018-09-16 00:13:29 -05:00
|
|
|
fs.close();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-25 14:13:55 -05:00
|
|
|
rsmi_dev_perf_level Device::perfLvlStrToEnum(std::string s) {
|
|
|
|
|
rsmi_dev_perf_level pl;
|
|
|
|
|
|
|
|
|
|
for (pl = RSMI_DEV_PERF_LEVEL_FIRST; pl <= RSMI_DEV_PERF_LEVEL_LAST; ) {
|
|
|
|
|
if (s == kDevPerfLvlMap.at(pl)) {
|
|
|
|
|
return pl;
|
|
|
|
|
}
|
|
|
|
|
pl = static_cast<rsmi_dev_perf_level>(static_cast<uint32_t>(pl) + 1);
|
|
|
|
|
}
|
|
|
|
|
return RSMI_DEV_PERF_LEVEL_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-16 00:13:29 -05:00
|
|
|
int Device::writeDevInfo(DevInfoTypes type, uint64_t val) {
|
|
|
|
|
switch (type) {
|
|
|
|
|
// The caller is responsible for making sure "val" is within a valid range
|
|
|
|
|
case kDevOverDriveLevel: // integer between 0 and 20
|
|
|
|
|
case kDevPowerProfileMode:
|
|
|
|
|
return writeDevInfoStr(type, std::to_string(val));
|
|
|
|
|
break;
|
|
|
|
|
|
2018-10-25 14:13:55 -05:00
|
|
|
case kDevPerfLevel: // string: "auto", "low", "high", "manual", ...
|
2018-09-16 00:13:29 -05:00
|
|
|
return writeDevInfoStr(type,
|
|
|
|
|
kDevPerfLvlMap.at((rsmi_dev_perf_level)val));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Device::writeDevInfo(DevInfoTypes type, std::string val) {
|
|
|
|
|
switch (type) {
|
|
|
|
|
case kDevGPUMClk:
|
2019-03-28 17:01:35 -05:00
|
|
|
case kDevDCEFClk:
|
|
|
|
|
case kDevFClk:
|
2018-09-16 00:13:29 -05:00
|
|
|
case kDevGPUSClk:
|
2019-02-27 15:10:26 -06:00
|
|
|
case kDevPCIEClk:
|
2019-02-22 15:05:44 -06:00
|
|
|
case kDevPowerODVoltage:
|
2019-03-28 17:01:35 -05:00
|
|
|
case kDevSOCClk:
|
2018-09-16 00:13:29 -05:00
|
|
|
return writeDevInfoStr(type, val);
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-27 15:10:26 -06:00
|
|
|
int Device::readDevInfoLine(DevInfoTypes type, std::string *line) {
|
|
|
|
|
int ret;
|
|
|
|
|
std::ifstream fs;
|
|
|
|
|
|
|
|
|
|
assert(line != nullptr);
|
|
|
|
|
|
|
|
|
|
ret = openSysfsFileStream(type, &fs);
|
|
|
|
|
if (ret != 0) {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::getline(fs, *line);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-30 12:12:40 -05:00
|
|
|
int Device::readDevInfoMultiLineStr(DevInfoTypes type,
|
|
|
|
|
std::vector<std::string> *retVec) {
|
|
|
|
|
std::string line;
|
2019-02-24 11:01:18 -06:00
|
|
|
int ret;
|
|
|
|
|
std::ifstream fs;
|
2017-10-30 12:12:40 -05:00
|
|
|
|
|
|
|
|
assert(retVec != nullptr);
|
|
|
|
|
|
2019-02-24 11:01:18 -06:00
|
|
|
ret = openSysfsFileStream(type, &fs);
|
|
|
|
|
if (ret != 0) {
|
|
|
|
|
return ret;
|
2017-10-30 12:12:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (std::getline(fs, line)) {
|
|
|
|
|
retVec->push_back(line);
|
|
|
|
|
}
|
2019-01-07 08:44:23 -06:00
|
|
|
|
2019-01-07 08:44:23 -06:00
|
|
|
if (retVec->size() == 0) {
|
2019-08-06 11:05:23 -05:00
|
|
|
return 0;
|
2019-01-07 08:44:23 -06:00
|
|
|
}
|
2019-01-07 08:44:23 -06:00
|
|
|
// Remove any *trailing* empty (whitespace) lines
|
|
|
|
|
while (retVec->back().find_first_not_of(" \t\n\v\f\r") == std::string::npos) {
|
|
|
|
|
retVec->pop_back();
|
|
|
|
|
}
|
2017-10-30 12:12:40 -05:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 18:26:11 -06:00
|
|
|
int Device::readDevInfo(DevInfoTypes type, uint64_t *val) {
|
2017-10-30 12:12:40 -05:00
|
|
|
assert(val != nullptr);
|
|
|
|
|
|
|
|
|
|
std::string tempStr;
|
2018-09-16 00:13:29 -05:00
|
|
|
int ret;
|
2017-10-30 12:12:40 -05:00
|
|
|
switch (type) {
|
|
|
|
|
case kDevDevID:
|
2019-03-15 16:21:37 -05:00
|
|
|
case kDevSubSysDevID:
|
|
|
|
|
case kDevSubSysVendorID:
|
|
|
|
|
case kDevVendorID:
|
2018-09-16 00:13:29 -05:00
|
|
|
ret = readDevInfoStr(type, &tempStr);
|
|
|
|
|
RET_IF_NONZERO(ret);
|
2017-10-30 12:12:40 -05:00
|
|
|
*val = std::stoi(tempStr, 0, 16);
|
|
|
|
|
break;
|
|
|
|
|
|
2018-11-12 17:25:14 -06:00
|
|
|
case kDevUsage:
|
2017-10-30 12:12:40 -05:00
|
|
|
case kDevOverDriveLevel:
|
2019-03-04 18:26:11 -06:00
|
|
|
case kDevMemTotGTT:
|
|
|
|
|
case kDevMemTotVisVRAM:
|
|
|
|
|
case kDevMemTotVRAM:
|
|
|
|
|
case kDevMemUsedGTT:
|
|
|
|
|
case kDevMemUsedVisVRAM:
|
|
|
|
|
case kDevMemUsedVRAM:
|
2019-05-06 11:26:40 -05:00
|
|
|
case kDevPCIEReplayCount:
|
2019-06-22 20:54:31 -05:00
|
|
|
case kDevDFCountersAvailable:
|
2019-06-25 14:21:34 -05:00
|
|
|
case kDevMemBusyPercent:
|
2019-07-09 08:46:08 -05:00
|
|
|
case kDevXGMIError:
|
2018-09-16 00:13:29 -05:00
|
|
|
ret = readDevInfoStr(type, &tempStr);
|
|
|
|
|
RET_IF_NONZERO(ret);
|
2019-03-04 18:26:11 -06:00
|
|
|
*val = std::stoul(tempStr, 0);
|
2017-10-30 12:12:40 -05:00
|
|
|
break;
|
2019-07-09 20:48:28 -05:00
|
|
|
|
2019-06-20 06:55:56 -04:00
|
|
|
case kDevUniqueId:
|
2019-07-09 20:48:28 -05:00
|
|
|
case kDevFwVersionAsd:
|
|
|
|
|
case kDevFwVersionCe:
|
|
|
|
|
case kDevFwVersionDmcu:
|
|
|
|
|
case kDevFwVersionMc:
|
|
|
|
|
case kDevFwVersionMe:
|
|
|
|
|
case kDevFwVersionMec:
|
|
|
|
|
case kDevFwVersionMec2:
|
|
|
|
|
case kDevFwVersionPfp:
|
|
|
|
|
case kDevFwVersionRlc:
|
|
|
|
|
case kDevFwVersionRlcSrlc:
|
|
|
|
|
case kDevFwVersionRlcSrlg:
|
|
|
|
|
case kDevFwVersionRlcSrls:
|
|
|
|
|
case kDevFwVersionSdma:
|
|
|
|
|
case kDevFwVersionSdma2:
|
|
|
|
|
case kDevFwVersionSmc:
|
|
|
|
|
case kDevFwVersionSos:
|
|
|
|
|
case kDevFwVersionTaRas:
|
|
|
|
|
case kDevFwVersionTaXgmi:
|
|
|
|
|
case kDevFwVersionUvd:
|
|
|
|
|
case kDevFwVersionVce:
|
|
|
|
|
case kDevFwVersionVcn:
|
2019-06-20 06:55:56 -04:00
|
|
|
ret = readDevInfoStr(type, &tempStr);
|
|
|
|
|
RET_IF_NONZERO(ret);
|
|
|
|
|
*val = std::stoul(tempStr, 0, 16);
|
|
|
|
|
break;
|
2017-10-30 12:12:40 -05:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2019-03-04 18:26:11 -06:00
|
|
|
|
2017-10-30 12:12:40 -05:00
|
|
|
int Device::readDevInfo(DevInfoTypes type, std::vector<std::string> *val) {
|
|
|
|
|
assert(val != nullptr);
|
|
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
case kDevGPUMClk:
|
|
|
|
|
case kDevGPUSClk:
|
2019-03-28 17:01:35 -05:00
|
|
|
case kDevDCEFClk:
|
|
|
|
|
case kDevFClk:
|
2019-02-27 15:10:26 -06:00
|
|
|
case kDevPCIEClk:
|
2019-03-28 17:01:35 -05:00
|
|
|
case kDevSOCClk:
|
2018-09-16 00:13:29 -05:00
|
|
|
case kDevPowerProfileMode:
|
2019-01-07 08:44:23 -06:00
|
|
|
case kDevPowerODVoltage:
|
2019-03-01 16:33:11 -06:00
|
|
|
case kDevErrCntSDMA:
|
|
|
|
|
case kDevErrCntUMC:
|
|
|
|
|
case kDevErrCntGFX:
|
2019-04-03 11:17:43 -05:00
|
|
|
case kDevErrCntFeatures:
|
2019-08-06 11:05:23 -05:00
|
|
|
case kDevMemPageBad:
|
2018-09-16 00:13:29 -05:00
|
|
|
return readDevInfoMultiLineStr(type, val);
|
2017-10-30 12:12:40 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Device::readDevInfo(DevInfoTypes type, std::string *val) {
|
|
|
|
|
assert(val != nullptr);
|
|
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
case kDevPerfLevel:
|
2018-11-12 17:25:14 -06:00
|
|
|
case kDevUsage:
|
2017-10-30 12:12:40 -05:00
|
|
|
case kDevOverDriveLevel:
|
|
|
|
|
case kDevDevID:
|
2019-03-15 16:21:37 -05:00
|
|
|
case kDevSubSysDevID:
|
|
|
|
|
case kDevSubSysVendorID:
|
|
|
|
|
case kDevVendorID:
|
2019-02-24 11:01:18 -06:00
|
|
|
case kDevVBiosVer:
|
2019-02-27 15:10:26 -06:00
|
|
|
case kDevPCIEThruPut:
|
2019-07-22 07:09:53 -05:00
|
|
|
case kDevSerialNumber:
|
2018-09-16 00:13:29 -05:00
|
|
|
return readDevInfoStr(type, val);
|
2017-10-30 12:12:40 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-16 00:13:29 -05:00
|
|
|
#undef RET_IF_NONZERO
|
2017-10-30 12:12:40 -05:00
|
|
|
} // namespace smi
|
|
|
|
|
} // namespace amd
|