Restructure the folder
Move rocm_smi related function to rocm_smi folder. Move amd_smi to top level include/ and src/ folder. Remove obsolte oam folder. Change the CMakeLists.txt to update folder locations. Change-Id: I52e6be739e49f3b0545865f25364787f5985e9c3
This commit is contained in:
@@ -1,120 +0,0 @@
|
||||
#
|
||||
# Minimum version of cmake required
|
||||
#
|
||||
|
||||
message("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
|
||||
message(" CMake OAM (Library) ")
|
||||
message("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
|
||||
|
||||
## Verbose output.
|
||||
set(CMAKE_VERBOSE_MAKEFILE on)
|
||||
|
||||
# Required Defines first:
|
||||
|
||||
message("")
|
||||
message("Build Configuration:")
|
||||
# message("-----------BuildType: " ${CMAKE_BUILD_TYPE})
|
||||
# message("------------Compiler: " ${CMAKE_CXX_COMPILER})
|
||||
# message("-------------Version: " ${CMAKE_CXX_COMPILER_VERSION})
|
||||
message("--------Proj Src Dir: " ${PROJECT_SOURCE_DIR})
|
||||
# message("--------Proj Bld Dir: " ${PROJECT_BINARY_DIR})
|
||||
# message("--------Proj Lib Dir: " ${PROJECT_BINARY_DIR}/lib)
|
||||
# message("--------Proj Exe Dir: " ${PROJECT_BINARY_DIR}/bin)
|
||||
# message("--------RSMI Lib Dir: " ${RSMI_LIB_DIR})
|
||||
# message("--------RSMI Inc Dir: " ${OAM_INC_DIR})
|
||||
# message("")
|
||||
|
||||
set(OAM_ROOT "${PROJECT_SOURCE_DIR}/oam")
|
||||
set(OAM_NAME "oam")
|
||||
set(OAM_COMPONENT "lib${OAM_NAME}")
|
||||
set(OAM_TARGET "${OAM_NAME}")
|
||||
|
||||
################# Determine the library version #########################
|
||||
set(SO_VERSION_GIT_TAG_PREFIX "oam_so_ver")
|
||||
|
||||
# VERSION_* variables should be set by get_version_from_tag
|
||||
message("Package version: ${PKG_VERSION_STR}")
|
||||
|
||||
# Debian package specific variables
|
||||
# Set a default value for the package version
|
||||
get_version_from_tag("1.0.0.0" ${SO_VERSION_GIT_TAG_PREFIX} GIT)
|
||||
|
||||
# VERSION_* variables should be set by get_version_from_tag
|
||||
if ( ${ROCM_PATCH_VERSION} )
|
||||
set ( VERSION_PATCH ${ROCM_PATCH_VERSION})
|
||||
set(SO_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
||||
else()
|
||||
set(SO_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}")
|
||||
endif ()
|
||||
set(${OAM_NAME}_VERSION_MAJOR "${VERSION_MAJOR}")
|
||||
set(${OAM_NAME}_VERSION_MINOR "${VERSION_MINOR}")
|
||||
set(${OAM_NAME}_VERSION_PATCH "0")
|
||||
set(${OAM_NAME}_VERSION_BUILD "0")
|
||||
message("SOVERSION: ${SO_VERSION_STRING}")
|
||||
|
||||
|
||||
# Create a configure file to get version info from within library
|
||||
configure_file(
|
||||
"${OAM_ROOT}/src/${OAM_TARGET}Config.in"
|
||||
"${OAM_ROOT}/include/oam/${OAM_TARGET}Config.h")
|
||||
|
||||
set(OAM_SRC_DIR "src")
|
||||
set(OAM_INC_DIR "include")
|
||||
set(OAM_DOCS_DIR "docs")
|
||||
|
||||
set(OAM_SRC_LIST ${CMN_SRC_LIST} "${OAM_SRC_DIR}/amd_oam.cc")
|
||||
|
||||
set(OAM_INC_LIST ${COMMON_INC_DIR} "${OAM_INC_DIR}")
|
||||
set(OAM_EXAMPLE_EXE "oam_ex")
|
||||
|
||||
add_executable(${OAM_EXAMPLE_EXE} "example/oam_example.c")
|
||||
target_include_directories(${OAM_EXAMPLE_EXE} PRIVATE ${OAM_INC_LIST})
|
||||
target_link_libraries(${OAM_EXAMPLE_EXE} ${OAM_TARGET})
|
||||
add_library(${OAM_TARGET} ${CMN_SRC_LIST} ${OAM_SRC_LIST}
|
||||
${CMN_INC_LIST} ${OAM_INC_LIST})
|
||||
target_link_libraries(${OAM_TARGET} pthread rt dl)
|
||||
target_include_directories(${OAM_TARGET} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include ${COMMON_PROJ_ROOT}/common/shared_mutex)
|
||||
|
||||
## Set the VERSION and SOVERSION values
|
||||
set_property(TARGET ${OAM_TARGET} PROPERTY
|
||||
SOVERSION "${VERSION_MAJOR}")
|
||||
set_property(TARGET ${OAM_TARGET} PROPERTY
|
||||
VERSION "${SO_VERSION_STRING}")
|
||||
|
||||
## If the library is a release, strip the target library
|
||||
if ("${CMAKE_BUILD_TYPE}" STREQUAL Release)
|
||||
if(${BUILD_SHARED_LIBS}) #striping only for .so
|
||||
add_custom_command(
|
||||
TARGET ${OAM_TARGET}
|
||||
POST_BUILD COMMAND ${CMAKE_STRIP} lib${OAM_TARGET}.so)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
# use the target_include_directories() command to specify the include directories for the target
|
||||
target_include_directories(${OAM_TARGET}
|
||||
PUBLIC
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
|
||||
"$<INSTALL_INTERFACE:{OAM_NAME}/include>")
|
||||
|
||||
|
||||
## Add the install directives for the runtime library.
|
||||
install(TARGETS ${OAM_TARGET}
|
||||
EXPORT rocm_smiTargets
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib
|
||||
COMPONENT ${OAM_COMPONENT})
|
||||
install(FILES ${COMMON_SRC_ROOT}/oam/include/oam/oam_mapi.h
|
||||
${COMMON_SRC_ROOT}/oam/include/oam/amd_oam.h
|
||||
DESTINATION include/oam)
|
||||
|
||||
# Generate Doxygen documentation
|
||||
if (DOXYGEN_FOUND)
|
||||
configure_file(${OAM_DOCS_DIR}/docs/rsmi_doxygen.cfg
|
||||
${OAM_DOCS_DIR}/Doxyfile @ONLY)
|
||||
add_custom_target(doc
|
||||
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Generating AMD OAM API documentation with Doxygen" VERBATIM)
|
||||
endif(DOXYGEN_FOUND)
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include "oam/oam_mapi.h"
|
||||
#include "oam/amd_oam.h"
|
||||
|
||||
const oam_ops_t amd_oam_ops = {
|
||||
.init = amdoam_init,
|
||||
.free = amdoam_free,
|
||||
// .get_mapi_version = amdoam_get_mapi_version,
|
||||
.discover_devices = amdoam_discover_devices,
|
||||
.get_dev_properties = amdoam_get_dev_properties,
|
||||
.get_pci_properties = amdoam_get_pci_properties,
|
||||
.get_sensors_count = amdoam_get_sensors_count,
|
||||
.get_error_description = amdoam_get_error_description,
|
||||
.get_sensors_info = amdoam_get_sensors_info,
|
||||
};
|
||||
|
||||
static int get_sensor_info(uint32_t device_id, oam_sensor_type_t type,
|
||||
uint32_t num_sensors, char unit[]) {
|
||||
uint32_t j;
|
||||
oam_sensor_info_t *sensor_info = calloc(num_sensors,
|
||||
sizeof(oam_sensor_info_t));
|
||||
if (!sensor_info) {
|
||||
printf("Allocating power_info failed\n");
|
||||
return -1;
|
||||
}
|
||||
amd_oam_ops.get_sensors_info(device_id, type, num_sensors, sensor_info);
|
||||
for ( j = 0; j < num_sensors ; j++) {
|
||||
printf("\tSensor Name : %s \n", sensor_info[j].sensor_name);
|
||||
printf("\tSensor Type : %d \n", sensor_info[j].sensor_type);
|
||||
printf("\tSensor Value : %ld %s\n", sensor_info[j].value, unit);
|
||||
}
|
||||
free(sensor_info);
|
||||
printf("\t**************************************\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
uint32_t dev_cnt = 0;
|
||||
oam_mapi_version_t version;
|
||||
oam_dev_properties_t *devs_prop;
|
||||
int i;
|
||||
oam_pci_info_t pci_info;
|
||||
oam_sensor_count_t sensor_count;
|
||||
const char *string;
|
||||
|
||||
if (amd_oam_ops.init()) {
|
||||
printf("init failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// amd_oam_ops.get_mapi_version(&version);
|
||||
if (!amd_oam_ops.discover_devices(&dev_cnt))
|
||||
printf("%d AMD devices are discovered\n", dev_cnt);
|
||||
if (!dev_cnt) {
|
||||
printf("No devices are found.\n");
|
||||
return amd_oam_ops.free();
|
||||
}
|
||||
devs_prop = calloc(dev_cnt, sizeof(oam_dev_properties_t));
|
||||
if (!devs_prop) {
|
||||
printf("Allocating dev_prop failed\n");
|
||||
return amd_oam_ops.free();
|
||||
}
|
||||
|
||||
amd_oam_ops.get_dev_properties(dev_cnt, devs_prop);
|
||||
for (i = 0; i < dev_cnt; i++) {
|
||||
printf("Device %d:\n", i);
|
||||
printf("\tdevice id %d\n", devs_prop[i].device_id);
|
||||
printf("\tdevice_vendor %s\n", devs_prop[i].device_vendor);
|
||||
printf("\tdevice_name %s\n", devs_prop[i].device_name);
|
||||
printf("\tsku_name %s\n", devs_prop[i].sku_name);
|
||||
printf("\tboard_name %s\n", devs_prop[i].board_name);
|
||||
printf("\tboard_revision %s\n", devs_prop[i].board_revision);
|
||||
printf("\tboard_serial_number %s\n",
|
||||
devs_prop[i].board_serial_number);
|
||||
|
||||
if (!amd_oam_ops.get_pci_properties(
|
||||
devs_prop[i].device_id, &pci_info)) {
|
||||
printf("\tPCI domain : 0x%d \n", pci_info.domain);
|
||||
printf("\tPCI bus : 0x%d \n", pci_info.bus);
|
||||
printf("\tPCI device : 0x%d \n", pci_info.device);
|
||||
printf("\tPCI function : 0x%d \n", pci_info.function);
|
||||
}
|
||||
|
||||
printf("\t**************************************\n");
|
||||
if (amd_oam_ops.get_sensors_count(
|
||||
devs_prop[i].device_id, &sensor_count))
|
||||
continue;
|
||||
printf("\tNumber of Power Sensors : %d \n",
|
||||
sensor_count.num_power_sensors);
|
||||
if (get_sensor_info(devs_prop[i].device_id,OAM_SENSOR_TYPE_POWER,
|
||||
sensor_count.num_power_sensors, "uW"))
|
||||
goto failure;
|
||||
|
||||
printf("\tNumber of Voltage Sensors : %d \n",
|
||||
sensor_count.num_voltage_sensors);
|
||||
if (get_sensor_info(devs_prop[i].device_id, OAM_SENSOR_TYPE_VOLTAGE,
|
||||
sensor_count.num_voltage_sensors, "mV"))
|
||||
goto failure;
|
||||
|
||||
printf("\tNumber of Current Sensors : %d \n",
|
||||
sensor_count.num_current_sensors);
|
||||
if (get_sensor_info(devs_prop[i].device_id, OAM_SENSOR_TYPE_CURRENT,
|
||||
sensor_count.num_current_sensors, "A"))
|
||||
goto failure;
|
||||
|
||||
printf("\tNumber of Temperature Sensors : %d \n",
|
||||
sensor_count.num_temperature_sensors);
|
||||
if (get_sensor_info(devs_prop[i].device_id, OAM_SENSOR_TYPE_TEMP,
|
||||
sensor_count.num_temperature_sensors, "mC"))
|
||||
goto failure;
|
||||
|
||||
printf("\tNumber of Fan Sensors : %d \n", sensor_count.num_fans);
|
||||
if (get_sensor_info(devs_prop[i].device_id, OAM_SENSOR_TYPE_FAN_SPEED,
|
||||
sensor_count.num_fans, "rpm"))
|
||||
goto failure;
|
||||
}
|
||||
|
||||
amd_oam_ops.get_error_description(1, &string);
|
||||
printf("error code 1: %s\n", string);
|
||||
|
||||
failure:
|
||||
free(devs_prop);
|
||||
amd_oam_ops.free();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Open Compute Project
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* 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
|
||||
* AUTHORS 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 IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef OAM_INCLUDE_OAM_AMD_OAM_H_
|
||||
#define OAM_INCLUDE_OAM_AMD_OAM_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#include <cstdint>
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif // __cplusplus
|
||||
|
||||
#include "oam/oam_mapi.h"
|
||||
|
||||
typedef enum {
|
||||
AMDOAM_STATUS_SUCCESS = 0x0,
|
||||
/* copy RSMI errors */
|
||||
AMDOAM_STATUS_INVALID_ARGS,
|
||||
AMDOAM_STATUS_NOT_SUPPORTED,
|
||||
AMDOAM_STATUS_FILE_ERROR,
|
||||
AMDOAM_STATUS_PERMISSION,
|
||||
AMDOAM_STATUS_OUT_OF_RESOURCES,
|
||||
AMDOAM_STATUS_INTERNAL_EXCEPTION,
|
||||
AMDOAM_STATUS_INPUT_OUT_OF_BOUNDS,
|
||||
AMDOAM_STATUS_INIT_ERROR,
|
||||
/* end of RSMI error code */
|
||||
AMDOAM_STATUS_ERROR, // Generic error return if not otherwise specified
|
||||
AMDOAM_STATUS_NOT_FOUND,
|
||||
} amdoam_status_t;
|
||||
|
||||
int amdoam_init(void);
|
||||
int amdoam_free(void);
|
||||
// int amdoam_get_mapi_version(oam_mapi_version_t *version);
|
||||
int amdoam_discover_devices(uint32_t *device_count);
|
||||
int amdoam_get_dev_properties(uint32_t dev_inx,
|
||||
oam_dev_properties_t *prop);
|
||||
int amdoam_get_pci_properties(uint32_t device_id, oam_pci_info_t *pci_info);
|
||||
int amdoam_get_sensors_count(uint32_t device_id,
|
||||
oam_sensor_count_t *sensor_count);
|
||||
int amdoam_get_error_description(int code, const char **description);
|
||||
int amdoam_get_sensors_info(uint32_t device_id, oam_sensor_type_t type,
|
||||
uint32_t num_sensors, oam_sensor_info_t sensor_info[]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
#endif // OAM_INCLUDE_OAM_AMD_OAM_H_
|
||||
@@ -1,635 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Open Compute Project
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* 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
|
||||
* AUTHORS 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 IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef OAM_INCLUDE_OAM_OAM_MAPI_H_
|
||||
#define OAM_INCLUDE_OAM_OAM_MAPI_H_
|
||||
|
||||
/**
|
||||
* \file oam_mapi.h
|
||||
* \brief OAM management and monitoring library API definitions
|
||||
*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
/**
|
||||
* \struct oam_mapi_version_t
|
||||
* \brief OAM library API version
|
||||
* \details TBD
|
||||
* All the libraries versions are expected to be backward compatible.
|
||||
* The major version increment indicates a new API has been added.
|
||||
* Minor version increment indicates an interface change.
|
||||
*/
|
||||
typedef struct oam_mapi_version {
|
||||
uint32_t major;
|
||||
uint32_t minor;
|
||||
} oam_mapi_version_t;
|
||||
|
||||
/**
|
||||
* \struct oam_dev_properties_t
|
||||
* \brief Network identifier for the device
|
||||
* \details Immutable network identifier for the device.
|
||||
* This is unique across the entire network.
|
||||
*/
|
||||
typedef struct oam_net_dev_id {
|
||||
/*!< unique network identifier for the device */
|
||||
int network_id;
|
||||
} oam_net_dev_id_t;
|
||||
|
||||
/*
|
||||
* various lengths for device properties
|
||||
*/
|
||||
#define DEVICE_VENDOR_LEN 128
|
||||
#define DEVICE_NAME_LEN 128
|
||||
#define DEVICE_SKU_LEN 128
|
||||
#define BOARD_NAME_LEN 128
|
||||
#define BOARD_REVISION_LEN 128
|
||||
#define BOARD_SERIAL_NUM_LEN 128
|
||||
|
||||
/**
|
||||
* \struct oam_dev_properties_t
|
||||
* \brief TBD
|
||||
* \details TBD
|
||||
*/
|
||||
typedef struct oam_dev_properties {
|
||||
/*!< Immutable local identifier for the device */
|
||||
uint32_t device_id;
|
||||
/*!< vendor name */
|
||||
char device_vendor[DEVICE_VENDOR_LEN];
|
||||
/*!< Device name */
|
||||
char device_name[DEVICE_NAME_LEN];
|
||||
/*!< SKU name */
|
||||
char sku_name[DEVICE_SKU_LEN];
|
||||
/*!< Board name */
|
||||
char board_name[BOARD_NAME_LEN];
|
||||
/*!< Board revision */
|
||||
char board_revision[BOARD_REVISION_LEN];
|
||||
/*!<
|
||||
* Board Serial Number or UUID any other identifier, which can be used
|
||||
* to identify devices uniquely and physically.
|
||||
*/
|
||||
char board_serial_number[BOARD_SERIAL_NUM_LEN];
|
||||
} oam_dev_properties_t;
|
||||
|
||||
/**
|
||||
* \struct oam_sensor_count_t
|
||||
* \brief TBD
|
||||
* \details TBD
|
||||
* Various sensor related information
|
||||
*/
|
||||
typedef struct oam_sensor_count {
|
||||
uint32_t num_temperature_sensors;
|
||||
uint32_t num_power_sensors;
|
||||
uint32_t num_voltage_sensors;
|
||||
uint32_t num_current_sensors;
|
||||
uint32_t num_fans;
|
||||
} oam_sensor_count_t;
|
||||
|
||||
/**
|
||||
* \enum oam_sensor_type_t
|
||||
* \brief Sensor types
|
||||
* \details This enumerated type defines available sensors types.
|
||||
*/
|
||||
typedef enum oam_sensor_type {
|
||||
OAM_SENSOR_TYPE_POWER = 0,
|
||||
OAM_SENSOR_TYPE_VOLTAGE,
|
||||
OAM_SENSOR_TYPE_CURRENT,
|
||||
OAM_SENSOR_TYPE_TEMP,
|
||||
OAM_SENSOR_TYPE_FAN_SPEED,
|
||||
OAM_SENSOR_TYPE_UNKNOWN
|
||||
} oam_sensor_type_t;
|
||||
|
||||
/**
|
||||
* \enum oam_power_sensor_scale_t
|
||||
* \brief scale for power measurements
|
||||
* \details This enumerated type defines available scales for power measurements
|
||||
*/
|
||||
typedef enum oam_power_sensor_scale {
|
||||
OAM_POWER_SCALE_uW = 0,
|
||||
OAM_POWER_SCALE_mW,
|
||||
OAM_POWER_SCALE_W,
|
||||
} oam_power_sensor_scale_t;
|
||||
|
||||
/**
|
||||
* \enum oam_voltage_sensor_scale_t
|
||||
* \brief scale for voltage measurements
|
||||
* \details This enumerated type defines available scales for voltage measurements
|
||||
*/
|
||||
typedef enum oam_voltage_sensor_scale {
|
||||
OAM_VOLTAGE_SCALE_uV = 0,
|
||||
OAM_VOLTAGE_SCALE_mV,
|
||||
OAM_VOLTAGE_SCALE_V,
|
||||
} oam_voltage_sensor_scale_t;
|
||||
|
||||
/**
|
||||
* \enum oam_current_sensor_scale_t
|
||||
* \brief scale for current measurements
|
||||
* \details This enumerated type defines available scales for current measurements
|
||||
*/
|
||||
typedef enum oam_current_sensor_scale {
|
||||
OAM_CURRENT_SCALE_uA = 0,
|
||||
OAM_CURRENT_SCALE_mA,
|
||||
OAM_CURRENT_SCALE_A,
|
||||
} oam_current_sensor_scale_t;
|
||||
|
||||
/**
|
||||
* \enum oam_temp_sensor_scale_t
|
||||
* \brief scale for temp measurements
|
||||
* \details This enumerated type defines available scales for temp measurements
|
||||
*/
|
||||
typedef enum oam_temp_sensor_scale {
|
||||
OAM_TEMP_SCALE_C = 0,
|
||||
OAM_TEMP_SCALE_F
|
||||
} oam_temp_sensor_scale_t;
|
||||
|
||||
/**
|
||||
* \enum oam_fan_sensor_scale_t
|
||||
* \brief scale for power measurements
|
||||
* \details This enumerated type defines available scales for power measurements
|
||||
*/
|
||||
typedef enum oam_fan_sensor_scale {
|
||||
OAM_FAN_SPEED_Hz = 0,
|
||||
OAM_FAN_SPEED_KHz,
|
||||
OAM_FAN_SPEED_MHz
|
||||
} oam_fan_sensor_scale_t;
|
||||
|
||||
typedef union oam_sensor_scale {
|
||||
oam_power_sensor_scale_t power_scale;
|
||||
oam_voltage_sensor_scale_t volate_scale;
|
||||
oam_current_sensor_scale_t current_scale;
|
||||
oam_temp_sensor_scale_t temp_scale;
|
||||
oam_fan_sensor_scale_t fan_scale;
|
||||
} oam_sensor_scale_t;
|
||||
|
||||
/**
|
||||
* \struct oam_dev_handle_t
|
||||
* \brief Device handle
|
||||
* \details Device handle obtained using open call
|
||||
* The same handle is used by all the APIs which are used to perform
|
||||
* specific operation on that device.
|
||||
*/
|
||||
typedef struct oam_dev_handle {
|
||||
void *handle;
|
||||
} oam_dev_handle_t;
|
||||
|
||||
/**
|
||||
* \enum oam_dev_mode_t
|
||||
* \brief Device open modes
|
||||
* \details This enumerated type defines modes in which the device can be opened
|
||||
* For some operations e.g. health check user should open the device
|
||||
* in exclusive mode, so that if there are many applications using the same
|
||||
* device there are no side effects.
|
||||
*/
|
||||
typedef enum oam_dev_mode {
|
||||
OAM_DEV_MODE_EXCLUSIVE = 0,
|
||||
OAM_DEV_MODE_NONEXLUSIVE = 1,
|
||||
OAM_DEV_MODE_UNKNOWN = 0xFF
|
||||
} oam_dev_mode_t;
|
||||
|
||||
/**
|
||||
* \def OAM_SENSOR_NAME_MAX
|
||||
* \brief length of sensor name
|
||||
*/
|
||||
#define OAM_SENSOR_NAME_MAX 256
|
||||
|
||||
/**
|
||||
* \struct oam_sensor_info_t
|
||||
* \brief Sensor information
|
||||
* \details Structure to store various info of sensors.
|
||||
*/
|
||||
typedef struct oam_sensor_info {
|
||||
char sensor_name[OAM_SENSOR_NAME_MAX];
|
||||
oam_sensor_type_t sensor_type;
|
||||
oam_sensor_scale_t scale;
|
||||
int64_t value;
|
||||
} oam_sensor_info_t;
|
||||
|
||||
/**
|
||||
* \struct oam_dev_error_count_t
|
||||
* \brief Device error information
|
||||
* \details Various types of errors reported by device.
|
||||
*/
|
||||
typedef struct oam_dev_error_count {
|
||||
uint32_t total_error_count;
|
||||
uint32_t fatal_error_count;
|
||||
uint32_t unknown_error_count;
|
||||
uint32_t ecc_error_count;
|
||||
} oam_dev_error_count_t;
|
||||
|
||||
/**
|
||||
* \struct oam_firmware_version_t
|
||||
* \brief Device error information
|
||||
* \details Structure to store various firmware versions of OAM module
|
||||
*/
|
||||
typedef struct oam_firmware_version {
|
||||
oam_mapi_version_t device_boot_fw_version;
|
||||
oam_mapi_version_t device_fw_version;
|
||||
oam_mapi_version_t board_boot_fw_version;
|
||||
oam_mapi_version_t board_fw_version;
|
||||
} oam_firmware_version_t;
|
||||
|
||||
/**
|
||||
* \struct oam_pci_info_t
|
||||
* \brief PCI information for the device
|
||||
* \details Structure to store PCI (Domain, BDF) information of the device
|
||||
*/
|
||||
typedef struct oam_pci_info {
|
||||
uint16_t domain;
|
||||
uint8_t bus;
|
||||
uint8_t device;
|
||||
uint8_t function;
|
||||
} oam_pci_info_t;
|
||||
|
||||
/**
|
||||
* \enum oam_net_port_state_t
|
||||
* \brief Network port state
|
||||
* \details This enumerated type defines various states of the network port
|
||||
*/
|
||||
typedef enum oam_net_port_state {
|
||||
OAM_NET_PORT_DISABLED = 0,
|
||||
OAM_NET_PORT_ENABLED = 1
|
||||
} oam_net_port_state_t;
|
||||
|
||||
/**
|
||||
* \enum oam_net_port_status_t
|
||||
* \brief Network port status
|
||||
* \details This enumerated type defines various status of the network port
|
||||
*/
|
||||
typedef enum oam_net_port_status {
|
||||
OAM_NET_PORT_UP = 0,
|
||||
OAM_NET_PORT_DOWN = 1,
|
||||
} oam_net_port_status_t;
|
||||
|
||||
/**
|
||||
* \enum oam_net_port_id_t
|
||||
* \brief Network port identifiers
|
||||
* \details This enumerated type defines various identifiers for network ports
|
||||
*/
|
||||
typedef enum oam_net_port_id {
|
||||
OAM_NET_PORT0 = 0,
|
||||
OAM_NET_PORT1 = 1,
|
||||
OAM_NET_PORT2 = 2,
|
||||
OAM_NET_PORT_MAX = 0xFFFF
|
||||
} oam_net_port_id_t;
|
||||
|
||||
/**
|
||||
* \enum oam_firmware_modes_t
|
||||
* \brief Supported mode to update firmware on device
|
||||
* \details This enumerated type defines various modes which are supported by
|
||||
* the device to update firmware.
|
||||
*/
|
||||
typedef enum oam_firmware_modes {
|
||||
OAM_DOWNLOAD_ONLY = 0,
|
||||
OAM_DOWNLOAD_ACTIVATE = 1
|
||||
} oam_firmware_modes_t;
|
||||
|
||||
/**
|
||||
* \def OAM_NET_PORT_NAME
|
||||
* \brief length of network port name
|
||||
*/
|
||||
#define OAM_NET_PORT_NAME 256
|
||||
|
||||
/**
|
||||
* \struct oam_net_port_desc
|
||||
* \brief Network port description
|
||||
* \details Structure to store additional details about the network port
|
||||
*/
|
||||
typedef struct oam_net_port_desc {
|
||||
char name[OAM_NET_PORT_NAME];
|
||||
} oam_net_port_desc_t;
|
||||
|
||||
/**
|
||||
* \def OAM_DEV_HOST_NAME
|
||||
* \brief length of host name
|
||||
*/
|
||||
#define OAM_DEV_HOST_NAME 256
|
||||
|
||||
/**
|
||||
* \struct oam_net_dev_info_t
|
||||
* \brief Information about the device on a network
|
||||
* \details Structure to store additional details about the network device
|
||||
* on a particular network.
|
||||
*/
|
||||
typedef struct oam_net_dev_info {
|
||||
oam_net_dev_id_t net_dev_id;
|
||||
char host_name[OAM_DEV_HOST_NAME];
|
||||
oam_pci_info_t pci_info;
|
||||
} oam_net_dev_info_t;
|
||||
|
||||
/**
|
||||
* \struct oam_neighbour_info_t
|
||||
* \brief Information about device neighburs
|
||||
* \details Structure to store information about device neighbours on the
|
||||
* network
|
||||
*/
|
||||
typedef struct oam_neighbour_info {
|
||||
oam_net_port_id_t device_port;
|
||||
oam_net_dev_info_t device_info;
|
||||
} oam_neighbour_info_t;
|
||||
|
||||
/**
|
||||
* \enum oam_dev_tpc_id_t
|
||||
* \brief TPC identifiers
|
||||
* \details This enumerated type defines various identifiers for TPCs
|
||||
*/
|
||||
typedef enum oam_dev_tpc_id {
|
||||
OAM_DEV_TPC0,
|
||||
OAM_DEV_TPC1,
|
||||
OAM_DEV_TPC2,
|
||||
OAM_DEV_TPC_MAX
|
||||
} oam_dev_tpc_id_t;
|
||||
|
||||
/**
|
||||
* \def OAM_TPC_NAME
|
||||
* \brief length of TPC name
|
||||
*/
|
||||
#define OAM_TPC_NAME 256
|
||||
|
||||
/**
|
||||
* \struct oam_tpc_desc_t
|
||||
* \brief TPC description
|
||||
* \details Structure to store information about TPC e.g. name corresponding
|
||||
* to the id etc.
|
||||
*/
|
||||
typedef struct oam_tpc_desc {
|
||||
char name[256];
|
||||
} oam_tpc_desc_t;
|
||||
|
||||
/**
|
||||
* \struct oam_dev_tpc_stats_t
|
||||
* \brief TPC statistical information
|
||||
* \details Structure to store information about TPC statistical information
|
||||
* e.g. TPC utilization
|
||||
*/
|
||||
typedef struct oam_dev_tpc_stats {
|
||||
double util;
|
||||
} oam_dev_tpc_stats_t;
|
||||
|
||||
/**
|
||||
* \enum oam_dev_mem_id_t
|
||||
* \brief Device memory identifiers
|
||||
* \details This enumerated type defines various identifiers for device memories
|
||||
*/
|
||||
typedef enum oam_dev_mem_id {
|
||||
OAM_DEV_MEM0,
|
||||
OAM_DEV_MEM1,
|
||||
OAM_DEV_MEM2,
|
||||
OAM_DEV_MEM_MAX
|
||||
} oam_dev_mem_id_t;
|
||||
|
||||
/**
|
||||
* \struct oam_mem_desc_t
|
||||
* \brief Device memory description
|
||||
* \details Structure to store additional details about device memories port
|
||||
*/
|
||||
typedef struct oam_mem_desc {
|
||||
char name[256];
|
||||
} oam_mem_desc_t;
|
||||
|
||||
/**
|
||||
* \struct oam_dev_mem_stats_t
|
||||
* \brief Device memory statistical information
|
||||
* \details Structure to store various statastical information about device
|
||||
* memory.
|
||||
*/
|
||||
typedef struct oam_dev_mem_stats {
|
||||
uint32_t total_mem;
|
||||
uint32_t allocated_mem;
|
||||
uint32_t free_mem;
|
||||
} oam_dev_mem_stats_t;
|
||||
|
||||
/**
|
||||
* \struct oam_net_port_pkt_stats_t
|
||||
* \brief Device network port statistical information
|
||||
* \details Structure to store various statastical information about the network
|
||||
* packets on a given port.
|
||||
*/
|
||||
typedef struct oam_net_port_pkt_stats {
|
||||
uint64_t rx_count;
|
||||
uint64_t tx_count;
|
||||
uint64_t rx_errors;
|
||||
uint64_t tx_errors;
|
||||
} oam_net_port_pkt_stats_t;
|
||||
|
||||
/**
|
||||
* \struct oam_ops_t
|
||||
* \brief OAM Device operations
|
||||
* \details Structure provides list of APIs which needs to be
|
||||
* supported by the OAM library.
|
||||
*/
|
||||
typedef struct oam_ops {
|
||||
/*!<
|
||||
* to initialise library instance and perform version compatibility
|
||||
* check
|
||||
*/
|
||||
int (*init)(void);
|
||||
int (*free)(void);
|
||||
|
||||
/*!<
|
||||
* To get error description from the error code
|
||||
*/
|
||||
int (*get_error_description)(int error_code, const char **error_description);
|
||||
|
||||
/*!<
|
||||
* To retrieve the OAM Management interface version
|
||||
*/
|
||||
int (*get_mapi_version)(oam_mapi_version_t *version);
|
||||
|
||||
/*!<
|
||||
* To retrieve the number of devices present/discovered by the library
|
||||
*/
|
||||
int (*discover_devices)(uint32_t *device_count);
|
||||
|
||||
/*!<
|
||||
* To retrieve device properties for each discovered devices
|
||||
*/
|
||||
int (*get_dev_properties)(uint32_t device_count,
|
||||
oam_dev_properties_t *devices);
|
||||
|
||||
/*!<
|
||||
* To retrieve PCI properties of the device
|
||||
*/
|
||||
int (*get_pci_properties)(uint32_t device_id, oam_pci_info_t *pci_info);
|
||||
|
||||
/*!<
|
||||
* To query the number of various sensors present
|
||||
*/
|
||||
int (*get_sensors_count)(uint32_t device_id,
|
||||
oam_sensor_count_t *sensor_count);
|
||||
|
||||
/*!<
|
||||
* Open the device and obtain handle
|
||||
*/
|
||||
int (*open_device)(uint32_t *dev_id, oam_dev_mode_t mode,
|
||||
oam_dev_handle_t *handle);
|
||||
int (*close_device)(oam_dev_handle_t *handle);
|
||||
|
||||
|
||||
/*!<
|
||||
* To read various sensor values for a given sensor type
|
||||
*/
|
||||
int (*get_sensors_info)(uint32_t device_id,
|
||||
oam_sensor_type_t type,
|
||||
uint32_t num_sensors,
|
||||
oam_sensor_info_t sensor_info[]);
|
||||
/*!<
|
||||
* To read current error count of the device
|
||||
*/
|
||||
int (*get_device_error_count)(oam_dev_handle_t *handle,
|
||||
oam_dev_error_count_t *count);
|
||||
|
||||
/*!<
|
||||
* To update firmware on the device
|
||||
* fw_image contains a null terminated string which specifies complete
|
||||
* path where the firmware image is located
|
||||
*/
|
||||
int (*download_firmware)(uint32_t *device_id, char *fw_image,
|
||||
oam_firmware_modes_t mode);
|
||||
|
||||
/*!<
|
||||
* To query firmware versions
|
||||
*/
|
||||
int (*get_firmware_version)(uint32_t *device_id,
|
||||
oam_firmware_version_t *version);
|
||||
|
||||
|
||||
/*!<
|
||||
* to get network id from device id
|
||||
*/
|
||||
int (*get_net_dev_id)(uint32_t *device_id, oam_net_dev_id_t *net_device);
|
||||
|
||||
/*!<
|
||||
* Network management APIs.
|
||||
*/
|
||||
|
||||
/*!<
|
||||
* discover network.
|
||||
*/
|
||||
int (*discover_network)(int *net_dev_count);
|
||||
int (*get_dev_net_properties)(oam_net_dev_info_t *net_dev_info);
|
||||
|
||||
int (*get_neighbour_count)(uint32_t *device,
|
||||
oam_net_port_id_t local_port_id,
|
||||
uint32_t *neighbor_count);
|
||||
|
||||
int (*get_neighbours_info)(uint32_t *device,
|
||||
oam_net_port_id_t local_port_id,
|
||||
uint32_t *neighbors_count,
|
||||
oam_neighbour_info_t *neighbours_info);
|
||||
|
||||
int (*configure_network)(oam_net_dev_id_t *net_devices,
|
||||
uint32_t *net_device_count,
|
||||
char *network_name);
|
||||
|
||||
int (*destroy_network)(char *network_name);
|
||||
|
||||
int (*query_network)(char *network_name, oam_net_dev_info_t *devices,
|
||||
uint32_t *device_count);
|
||||
|
||||
int (*get_network_count)(uint32_t *network_count);
|
||||
int (*list_networks)(char *network_names[]);
|
||||
|
||||
/*!<
|
||||
* Various statistics related to blocks
|
||||
*/
|
||||
|
||||
/*!<
|
||||
* To query number of ports
|
||||
*/
|
||||
int (*get_net_port_count)(oam_dev_handle_t *handle, uint32_t *count,
|
||||
oam_net_port_id_t *port_ids);
|
||||
|
||||
int (*get_net_port_desc)(oam_dev_handle_t *handle, oam_net_port_id_t *port,
|
||||
oam_net_port_desc_t *desc);
|
||||
|
||||
int (*get_net_port_state)(oam_dev_handle_t *handle, oam_net_port_id_t *port,
|
||||
oam_net_port_state_t *state);
|
||||
|
||||
int (*check_net_port_status)(oam_dev_handle_t *handle,
|
||||
oam_net_port_id_t *port,
|
||||
oam_net_port_status_t *status);
|
||||
int (*get_net_port_pkt_stats)(oam_dev_handle_t *handle,
|
||||
oam_net_port_id_t *port,
|
||||
uint32_t duration_sec,
|
||||
oam_net_port_pkt_stats_t *stats);
|
||||
|
||||
int (*query_net_port_bandwidth)(oam_dev_handle_t *handle,
|
||||
oam_net_port_id_t *port,
|
||||
uint32_t duration_sec,
|
||||
double *bandwidth);
|
||||
|
||||
int (*get_tpc_count)(oam_dev_handle_t *handle, uint32_t *count,
|
||||
oam_dev_tpc_id_t *tpc_ids);
|
||||
|
||||
int (*get_tpc_desc)(oam_dev_handle_t *handle, oam_dev_tpc_id_t *tpc_id,
|
||||
oam_tpc_desc_t *desc);
|
||||
|
||||
int (*get_tpc_stats)(oam_dev_handle_t *handle,
|
||||
oam_dev_tpc_id_t *port,
|
||||
oam_dev_tpc_stats_t *stats,
|
||||
uint32_t duration_sec);
|
||||
|
||||
int (*get_mem_count)(oam_dev_handle_t *handle, uint32_t *count,
|
||||
oam_dev_mem_id_t *mem_ids);
|
||||
|
||||
int (*get_mem_desc)(oam_dev_handle_t *handle, oam_dev_mem_id_t *tpc_id,
|
||||
oam_mem_desc_t *desc);
|
||||
|
||||
int (*get_mem_stats)(oam_dev_handle_t *handle, oam_dev_mem_id_t *mem_id,
|
||||
oam_dev_mem_stats_t *stats);
|
||||
|
||||
/*!<
|
||||
* To check the health of the individual components, libraries
|
||||
* generates test workload to check if the block is functioning properly
|
||||
* or not. So no other workload should be running while calling these
|
||||
* APIs
|
||||
*/
|
||||
int (*check_tpc_health)(uint32_t *device_id, oam_dev_tpc_id_t *tpc_id);
|
||||
int (*check_net_port_health)(uint32_t *device_id, oam_net_port_id_t *port);
|
||||
int (*check_mem_health)(uint32_t *device_id, oam_dev_mem_id_t *port);
|
||||
|
||||
/*
|
||||
* Following needs more attention, will work on in next
|
||||
int (*get_fan_speed)(oam_dev_t *oam);
|
||||
int (*set_fan_speed)(oam_dev_t *oam, int speed);
|
||||
|
||||
int (*get_power_cap)(oam_dev_t *oam);
|
||||
int (*set_power_cap)(oam_dev_t *oam, int power);
|
||||
|
||||
int (*get_telemetry)(oam_dev_t *oam);
|
||||
*/
|
||||
|
||||
} oam_ops_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OAM_INCLUDE_OAM_OAM_MAPI_H_
|
||||
@@ -1,392 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Open Compute Project
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* 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
|
||||
* AUTHORS 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 IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <dirent.h>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <regex> // NOLINT
|
||||
#include <map>
|
||||
|
||||
#include "rocm_smi/rocm_smi_common.h"
|
||||
#include "rocm_smi/rocm_smi_main.h"
|
||||
#include "rocm_smi/rocm_smi_device.h"
|
||||
#include "rocm_smi/rocm_smi_utils.h"
|
||||
#include "rocm_smi/rocm_smi_exception.h"
|
||||
#include "rocm_smi/rocm_smi_counters.h"
|
||||
#include "rocm_smi/rocm_smi_kfd.h"
|
||||
#include "rocm_smi/rocm_smi.h"
|
||||
|
||||
#include "oam/oam_mapi.h"
|
||||
#include "oam/amd_oam.h"
|
||||
|
||||
static const std::map<int, const char *> err_map = {
|
||||
{ AMDOAM_STATUS_INVALID_ARGS, "Invalid arguments" },
|
||||
{ AMDOAM_STATUS_NOT_SUPPORTED, "Feature not supported" },
|
||||
{ AMDOAM_STATUS_FILE_ERROR, "Problem accessing a file" },
|
||||
{ AMDOAM_STATUS_PERMISSION, "Permission denied" },
|
||||
{ AMDOAM_STATUS_OUT_OF_RESOURCES, "Not enough memory or other resource" },
|
||||
{ AMDOAM_STATUS_INTERNAL_EXCEPTION, "An internal exception was caught" },
|
||||
{ AMDOAM_STATUS_INPUT_OUT_OF_BOUNDS,
|
||||
"The provided input is out of allowable or safe range" },
|
||||
{ AMDOAM_STATUS_INIT_ERROR, "AMDOAM is not initialized or init failed" },
|
||||
{ AMDOAM_STATUS_ERROR, "Generic error" },
|
||||
{ AMDOAM_STATUS_NOT_FOUND, "An item was searched for but not found" }
|
||||
};
|
||||
|
||||
#define TRY try {
|
||||
#define CATCH } catch (...) {return handleRSMIException();}
|
||||
|
||||
static bool rsmi_initialized;
|
||||
|
||||
static int rsmi_status_to_amdoam_errorcode(rsmi_status_t status) {
|
||||
if (status > RSMI_STATUS_INIT_ERROR)
|
||||
return -AMDOAM_STATUS_ERROR;
|
||||
else
|
||||
return -1 * static_cast<int>(status);
|
||||
}
|
||||
|
||||
static int handleRSMIException() {
|
||||
rsmi_status_t ret = amd::smi::handleException();
|
||||
return rsmi_status_to_amdoam_errorcode(ret);
|
||||
}
|
||||
|
||||
int amdoam_get_error_description(int code, const char **description) {
|
||||
if (description == nullptr)
|
||||
return -AMDOAM_STATUS_INVALID_ARGS;
|
||||
|
||||
auto search = err_map.find(code);
|
||||
if (search == err_map.end())
|
||||
return -AMDOAM_STATUS_NOT_FOUND;
|
||||
|
||||
*description = search->second;
|
||||
return AMDOAM_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
int amdoam_init(void) {
|
||||
TRY
|
||||
|
||||
rsmi_status_t status = rsmi_init(0);
|
||||
|
||||
if (status != RSMI_STATUS_SUCCESS)
|
||||
return rsmi_status_to_amdoam_errorcode(status);
|
||||
|
||||
rsmi_initialized = true;
|
||||
return AMDOAM_STATUS_SUCCESS;
|
||||
|
||||
CATCH
|
||||
}
|
||||
|
||||
int amdoam_free(void) {
|
||||
rsmi_status_t status = rsmi_shut_down();
|
||||
|
||||
if (status != RSMI_STATUS_SUCCESS)
|
||||
return rsmi_status_to_amdoam_errorcode(status);
|
||||
|
||||
return AMDOAM_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
int amdoam_discover_devices(uint32_t *device_count) {
|
||||
rsmi_status_t status;
|
||||
|
||||
if (device_count == nullptr) {
|
||||
return -AMDOAM_STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
status = rsmi_num_monitor_devices(device_count);
|
||||
if (status != RSMI_STATUS_SUCCESS)
|
||||
return rsmi_status_to_amdoam_errorcode(status);
|
||||
|
||||
return AMDOAM_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
int amdoam_get_pci_properties(uint32_t device_id, oam_pci_info_t *pci_info) {
|
||||
uint64_t bdfid;
|
||||
|
||||
TRY
|
||||
if (pci_info == nullptr) {
|
||||
return -AMDOAM_STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
rsmi_status_t status = rsmi_dev_pci_id_get(device_id, &bdfid);
|
||||
if (status != RSMI_STATUS_SUCCESS)
|
||||
return rsmi_status_to_amdoam_errorcode(status);
|
||||
|
||||
pci_info->domain = (uint16_t)(bdfid >> 32) & 0xffff;
|
||||
pci_info->bus = (bdfid >> 8) & 0xff;
|
||||
pci_info->device = (bdfid >> 3) & 0x1f;
|
||||
pci_info->function = bdfid & 0x7;
|
||||
CATCH
|
||||
|
||||
return AMDOAM_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
int amdoam_get_dev_properties(uint32_t num_devices,
|
||||
oam_dev_properties_t *devices) {
|
||||
const size_t buf_size = 32;
|
||||
char buf[buf_size] = "";
|
||||
uint32_t dev_inx;
|
||||
oam_dev_properties_t *dev = devices;
|
||||
|
||||
TRY
|
||||
if (devices == nullptr)
|
||||
return -AMDOAM_STATUS_INVALID_ARGS;
|
||||
if (!rsmi_initialized)
|
||||
return -AMDOAM_STATUS_INIT_ERROR;
|
||||
|
||||
for (dev_inx = 0; dev_inx < num_devices; dev_inx++) {
|
||||
dev->device_id = dev_inx;
|
||||
/* If fails to get any following properties, it's not treated as a deal
|
||||
* breaker. Variable not filled means that property is not available on
|
||||
* this device or AMD doesn't support that property.
|
||||
*/
|
||||
rsmi_dev_vendor_name_get(dev_inx, dev->device_vendor, DEVICE_VENDOR_LEN);
|
||||
rsmi_dev_name_get(dev_inx, dev->device_name, DEVICE_NAME_LEN);
|
||||
rsmi_dev_vbios_version_get(dev_inx, buf, buf_size);
|
||||
if (std::strlen(buf) > 0) {
|
||||
std::strncpy(dev->sku_name, &buf[4], 6);
|
||||
std::strncpy(dev->board_name, buf, 12);
|
||||
}
|
||||
rsmi_dev_serial_number_get(dev_inx, dev->board_serial_number,
|
||||
BOARD_SERIAL_NUM_LEN);
|
||||
++dev;
|
||||
}
|
||||
CATCH
|
||||
|
||||
return AMDOAM_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
get_num_sensors(std::string hwmon_path, std::string fn_reg) {
|
||||
uint32_t sensor_max = 0;
|
||||
std::string fn_reg_ex = "\\b" + fn_reg + "([0-9]+)([^ ]*)";
|
||||
std::string fn;
|
||||
std::smatch m;
|
||||
int32_t temp = 0;
|
||||
std::string s1("in");
|
||||
std::regex re(fn_reg_ex);
|
||||
auto hwmon_dir = opendir(hwmon_path.c_str());
|
||||
assert(hwmon_dir != nullptr);
|
||||
auto dentry = readdir(hwmon_dir);
|
||||
while (dentry != nullptr) {
|
||||
fn = dentry->d_name;
|
||||
if (std::regex_search(fn, m, re)) {
|
||||
std::string output = std::regex_replace(
|
||||
fn,
|
||||
std::regex("[^0-9]*([0-9]+).*"),
|
||||
std::string("$1"));
|
||||
temp = stoi(output);
|
||||
|
||||
assert(temp >= 0);
|
||||
|
||||
if (s1.compare(fn_reg) == 0)
|
||||
++temp;
|
||||
if (static_cast<uint32_t>(temp) > sensor_max)
|
||||
sensor_max = static_cast<uint32_t>(temp);
|
||||
}
|
||||
dentry = readdir(hwmon_dir);
|
||||
}
|
||||
|
||||
closedir(hwmon_dir);
|
||||
return sensor_max;
|
||||
}
|
||||
|
||||
|
||||
int amdoam_get_sensors_count(uint32_t device_id,
|
||||
oam_sensor_count_t *sensor_count) {
|
||||
uint32_t dv_ind = device_id;
|
||||
|
||||
TRY
|
||||
if (sensor_count == nullptr)
|
||||
return -AMDOAM_STATUS_INVALID_ARGS;
|
||||
GET_DEV_FROM_INDX
|
||||
assert(dev->monitor() != nullptr);
|
||||
std::string hwmon_path = dev->monitor()->path();
|
||||
sensor_count->num_temperature_sensors = get_num_sensors(hwmon_path, "temp");
|
||||
sensor_count->num_fans = get_num_sensors(hwmon_path, "fan");
|
||||
sensor_count->num_voltage_sensors = get_num_sensors(hwmon_path, "in");
|
||||
sensor_count->num_power_sensors = get_num_sensors(hwmon_path, "power");
|
||||
sensor_count->num_current_sensors = get_num_sensors(hwmon_path, "current");
|
||||
CATCH
|
||||
|
||||
return AMDOAM_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
int amdoam_get_sensors_info(uint32_t device_id, oam_sensor_type_t type,
|
||||
uint32_t num_sensors, oam_sensor_info_t sensor_info[]) {
|
||||
uint32_t dv_ind = device_id;
|
||||
std::string val_str;
|
||||
uint32_t i;
|
||||
rsmi_status_t status;
|
||||
|
||||
TRY
|
||||
if ((sensor_info == nullptr) || (type >= OAM_SENSOR_TYPE_UNKNOWN))
|
||||
return -AMDOAM_STATUS_INVALID_ARGS;
|
||||
GET_DEV_FROM_INDX
|
||||
assert(dev->monitor() != nullptr);
|
||||
switch (type) {
|
||||
case OAM_SENSOR_TYPE_POWER:
|
||||
for (i = 0; i < num_sensors; i++) {
|
||||
snprintf(sensor_info[i].sensor_name, OAM_SENSOR_NAME_MAX,
|
||||
"POWER_SENSOR_%d", i+1);
|
||||
sensor_info[i].sensor_type = type;
|
||||
status = rsmi_dev_power_ave_get(device_id, i,
|
||||
reinterpret_cast<uint64_t*>(&sensor_info[i].value));
|
||||
if (status != RSMI_STATUS_SUCCESS)
|
||||
return rsmi_status_to_amdoam_errorcode(status);
|
||||
}
|
||||
break;
|
||||
|
||||
case OAM_SENSOR_TYPE_VOLTAGE:
|
||||
for (i = 0; i < num_sensors; i++) {
|
||||
snprintf(sensor_info[i].sensor_name, OAM_SENSOR_NAME_MAX,
|
||||
"VOLTAGE_SENSOR_%d", i);
|
||||
sensor_info[i].sensor_type = type;
|
||||
status = rsmi_dev_volt_metric_get(device_id, RSMI_VOLT_TYPE_VDDGFX,
|
||||
RSMI_VOLT_CURRENT, &sensor_info[i].value);
|
||||
if (status != RSMI_STATUS_SUCCESS)
|
||||
return rsmi_status_to_amdoam_errorcode(status);
|
||||
}
|
||||
break;
|
||||
|
||||
case OAM_SENSOR_TYPE_TEMP:
|
||||
for (i = 0; i < num_sensors; i++) {
|
||||
snprintf(sensor_info[i].sensor_name, OAM_SENSOR_NAME_MAX,
|
||||
"TEMP_SENSOR_%d", i+1);
|
||||
sensor_info[i].sensor_type = type;
|
||||
status = rsmi_dev_temp_metric_get(device_id, i, RSMI_TEMP_CURRENT,
|
||||
&sensor_info[i].value);
|
||||
if (status != RSMI_STATUS_SUCCESS)
|
||||
return rsmi_status_to_amdoam_errorcode(status);
|
||||
}
|
||||
break;
|
||||
|
||||
case OAM_SENSOR_TYPE_FAN_SPEED:
|
||||
for (i = 0; i < num_sensors; i++) {
|
||||
snprintf(sensor_info[i].sensor_name, OAM_SENSOR_NAME_MAX,
|
||||
"FAN_SENSOR_%d", i+1);
|
||||
sensor_info[i].sensor_type = type;
|
||||
status = rsmi_dev_fan_speed_get(device_id, i, &sensor_info[i].value);
|
||||
if (status != RSMI_STATUS_SUCCESS)
|
||||
return rsmi_status_to_amdoam_errorcode(status);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return -AMDOAM_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
CATCH
|
||||
|
||||
return AMDOAM_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// TODO(x): This function doesn't work for OAM. It's just a version
|
||||
// of rsmi_dev_ecc_count_get(), which has similar functionality.
|
||||
// The purpose here is just to drive refactoring; e.g., making macros
|
||||
// available and previously static functions global.
|
||||
int
|
||||
get_device_error_count(oam_dev_handle_t *handle,
|
||||
oam_dev_error_count_t *count) {
|
||||
std::vector<std::string> val_vec;
|
||||
rsmi_status_t ret;
|
||||
|
||||
TRY
|
||||
// TODO(x): replace with final code...
|
||||
// Below, we are just returning errors for RSMI_GPU_BLOCK_GFX as a
|
||||
// placeholder
|
||||
(void)handle; // Just ignore for now
|
||||
|
||||
rsmi_gpu_block_t block = RSMI_GPU_BLOCK_GFX;
|
||||
|
||||
// The macro CHK_SUPPORT_VAR assumes the existence of a device index variable
|
||||
// "dv_ind". Presumably, the device index will come from the "handle"
|
||||
// pointer. Since I don't know how that will be implemented, for now we
|
||||
// will just make up a device index:
|
||||
uint32_t dv_ind = 0;
|
||||
CHK_SUPPORT_VAR(count, block)
|
||||
|
||||
amd::smi::DevInfoTypes type;
|
||||
switch (block) {
|
||||
case RSMI_GPU_BLOCK_UMC:
|
||||
type = amd::smi::kDevErrCntUMC;
|
||||
break;
|
||||
|
||||
case RSMI_GPU_BLOCK_SDMA:
|
||||
type = amd::smi::kDevErrCntSDMA;
|
||||
break;
|
||||
|
||||
case RSMI_GPU_BLOCK_GFX:
|
||||
type = amd::smi::kDevErrCntGFX;
|
||||
break;
|
||||
|
||||
case RSMI_GPU_BLOCK_MMHUB:
|
||||
type = amd::smi::kDevErrCntMMHUB;
|
||||
break;
|
||||
|
||||
case RSMI_GPU_BLOCK_PCIE_BIF:
|
||||
type = amd::smi::kDevErrCntPCIEBIF;
|
||||
break;
|
||||
|
||||
case RSMI_GPU_BLOCK_HDP:
|
||||
type = amd::smi::kDevErrCntHDP;
|
||||
break;
|
||||
|
||||
case RSMI_GPU_BLOCK_XGMI_WAFL:
|
||||
type = amd::smi::kDevErrCntXGMIWAFL;
|
||||
break;
|
||||
|
||||
default:
|
||||
return RSMI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
DEVICE_MUTEX
|
||||
|
||||
ret = GetDevValueVec(type, dv_ind, &val_vec);
|
||||
|
||||
if (ret == RSMI_STATUS_FILE_ERROR) {
|
||||
return RSMI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
if (ret != RSMI_STATUS_SUCCESS) {
|
||||
return static_cast<int>(ret);
|
||||
}
|
||||
|
||||
assert(val_vec.size() == 2);
|
||||
|
||||
std::string junk;
|
||||
std::istringstream fs1(val_vec[0]);
|
||||
|
||||
fs1 >> junk;
|
||||
assert(junk == "ue:");
|
||||
fs1 >> count->total_error_count;
|
||||
|
||||
std::istringstream fs2(val_vec[1]);
|
||||
|
||||
fs2 >> junk;
|
||||
assert(junk == "ce:");
|
||||
fs2 >> count->total_error_count;
|
||||
|
||||
return static_cast<int>(ret);
|
||||
CATCH
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* =============================================================================
|
||||
* ROC Runtime Conformance Release License
|
||||
* =============================================================================
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_ROCM_SMI_ROCM_SMI64CONFIG_H_
|
||||
#define INCLUDE_ROCM_SMI_ROCM_SMI64CONFIG_H_
|
||||
|
||||
// This file is generated on build.
|
||||
|
||||
#define rocm_smi_VERSION_MAJOR @rocm_smi_VERSION_MAJOR@
|
||||
#define rocm_smi_VERSION_MINOR @rocm_smi_VERSION_MINOR@
|
||||
#define rocm_smi_VERSION_PATCH @rocm_smi_VERSION_PATCH@
|
||||
#define rocm_smi_VERSION_BUILD "@rocm_smi_VERSION_BUILD@"
|
||||
|
||||
#endif // INCLUDE_ROCM_SMI_ROCM_SMI64CONFIG_H_
|
||||
Reference in New Issue
Block a user