Adding functionality that will parse gpu_metrics sysfs file

Signed-off-by: Divya Shikre <DivyaUday.Shikre@amd.com>
Change-Id: I3a84870b83eb4cd0ed46f10bb19169c91f99fd8e


[ROCm/rocm_smi_lib commit: 8b48564ce3]
This commit is contained in:
Divya Shikre
2020-09-24 16:06:13 -04:00
committed by Divya Uday Shikre
parent 91267d1440
commit 94fc1524c3
7 changed files with 174 additions and 2 deletions
@@ -757,6 +757,72 @@ typedef struct {
typedef rsmi_od_volt_freq_data_t rsmi_od_volt_freq_data;
/// \endcond
/**
* @brief The following structures hold the gpu metrics values for a device.
*/
struct metrics_table_header {
uint16_t structure_size;
uint8_t format_revision;
uint8_t content_revision;
};
typedef struct {
struct metrics_table_header common_header;
/* Driver attached timestamp (in ns) */
uint64_t system_clock_counter;
/* Temperature */
uint16_t temperature_edge;
uint16_t temperature_hotspot;
uint16_t temperature_mem;
uint16_t temperature_vrgfx;
uint16_t temperature_vrsoc;
uint16_t temperature_vrmem;
/* Utilization */
uint16_t average_gfx_activity;
uint16_t average_umc_activity; // memory controller
uint16_t average_mm_activity; // UVD or VCN
/* Power/Energy */
uint16_t average_socket_power;
uint32_t energy_accumulator;
/* Average clocks */
uint16_t average_gfxclk_frequency;
uint16_t average_socclk_frequency;
uint16_t average_uclk_frequency;
uint16_t average_vclk0_frequency;
uint16_t average_dclk0_frequency;
uint16_t average_vclk1_frequency;
uint16_t average_dclk1_frequency;
/* Current clocks */
uint16_t current_gfxclk;
uint16_t current_socclk;
uint16_t current_uclk;
uint16_t current_vclk0;
uint16_t current_dclk0;
uint16_t current_vclk1;
uint16_t current_dclk1;
/* Throttle status */
uint32_t throttle_status;
/* Fans */
uint16_t current_fan_speed;
/* Link width/speed */
uint8_t pcie_link_width;
uint8_t pcie_link_speed; // in 0.1 GT/s
}rsmi_gpu_metrics_t;
/// \cond Ignore in docs.
typedef rsmi_gpu_metrics_t rsmi_gpu_metrics;
/// \endcond
/**
* @brief This structure holds error counts.
*/
@@ -2014,6 +2080,29 @@ rsmi_status_t rsmi_dev_gpu_clk_freq_get(uint32_t dv_ind,
rsmi_status_t rsmi_dev_od_volt_info_get(uint32_t dv_ind,
rsmi_od_volt_freq_data_t *odv);
/**
* @brief This function retrieves the gpu metrics information
*
* @details Given a device index @p dv_ind and a pointer to a
* ::rsmi_gpu_metrics_t structure @p pgpu_metrics, this function will populate
* @p pgpu_metrics. See ::rsmi_gpu_metrics_t for more details.
*
* @param[in] dv_ind a device index
*
* @param[inout] pgpu_metrics a pointer to an ::rsmi_gpu_metrics_t structure
* If this parameter is nullptr, this function will return
* ::RSMI_STATUS_INVALID_ARGS if the function is supported with the provided,
* arguments and ::RSMI_STATUS_NOT_SUPPORTED if it is not supported with the
* provided arguments.
*
* @retval ::RSMI_STATUS_SUCCESS call was successful
* @retval ::RSMI_STATUS_NOT_SUPPORTED installed software or hardware does not
* support this function with the given arguments
* @retval ::RSMI_STATUS_INVALID_ARGS the provided arguments are not valid
*/
rsmi_status_t rsmi_dev_gpu_metrics_info_get(uint32_t dv_ind,
rsmi_gpu_metrics_t *pgpu_metrics);
/**
* @brief This function sets the clock frequency information
*
@@ -152,7 +152,8 @@ enum DevInfoTypes {
kDevFwVersionVcn,
kDevSerialNumber,
kDevMemPageBad,
kDevNumaNode
kDevNumaNode,
kDevGpuMetrics
};
typedef struct {
@@ -175,6 +176,7 @@ class Device {
int readDevInfoLine(DevInfoTypes type, std::string *line);
int readDevInfo(DevInfoTypes type, std::string *val);
int readDevInfo(DevInfoTypes type, std::vector<std::string> *retVec);
int readDevInfo(DevInfoTypes type, std::vector<unsigned char> *retVec);
int writeDevInfo(DevInfoTypes type, uint64_t val);
int writeDevInfo(DevInfoTypes type, std::string val);
@@ -214,6 +216,8 @@ class Device {
int readDevInfoStr(DevInfoTypes type, std::string *retStr);
int readDevInfoMultiLineStr(DevInfoTypes type,
std::vector<std::string> *retVec);
int readDevInfoBinary(DevInfoTypes type,
std::vector<unsigned char> *retVec);
int writeDevInfoStr(DevInfoTypes type, std::string valStr);
uint64_t bdfid_;
uint64_t kfd_gpu_id_;
@@ -80,6 +80,9 @@ rsmi_status_t handleException();
rsmi_status_t
GetDevValueVec(amd::smi::DevInfoTypes type,
uint32_t dv_ind, std::vector<std::string> *val_vec);
rsmi_status_t
GetDevBinaryVec(amd::smi::DevInfoTypes type,
uint32_t dv_ind, std::vector<unsigned char> *val_vec);
rsmi_status_t ErrnoToRsmiStatus(uint32_t err);
struct pthread_wrap {