diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_commands.py b/projects/amdsmi/amdsmi_cli/amdsmi_commands.py index f827321c1a0..30cc01ba088 100644 --- a/projects/amdsmi/amdsmi_cli/amdsmi_commands.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_commands.py @@ -564,8 +564,6 @@ def list_switchs(self, args): return False if args.switch == None: args.switch = self.device_handles_switchs - if isinstance(args.switch, list): - switchCount = len(args.switch) return False if isinstance(args.switch, list): switchCount = len(args.switch) @@ -598,8 +596,6 @@ def list(self, args, multiple_devices=False, gpu=None, nic=None, switch=None): args.switch = switch gpuCount = 0 - nicCount = 0 - switchCount = 0 # Handle No GPU passed if args.gpu == None: @@ -633,7 +629,7 @@ def list(self, args, multiple_devices=False, gpu=None, nic=None, switch=None): if self.helpers.is_ainic_initialized() or self.helpers.is_brcm_nic_initialized(): nics,ainics = self._get_nics_from_args(args) if len(nics) > 0: - self.list_brcm_nic(args, False, nic=ainics) + self.list_brcm_nic(args, False, nic=nics) if len(ainics) > 0: self.list_ainic(args, False, nic=ainics) @@ -1738,20 +1734,20 @@ def _static_ainic(self, args, multiple_devices=False, nic=None): if args.nic: try: nic_info = amdsmi_interface.amdsmi_get_ainic_info(args.nic, True) - filter = [] + info_filter = [] if hasattr(args, "asic") and getattr(args, "asic"): - filter.append("asic") + info_filter.append("asic") if hasattr(args, "bus") and getattr(args, "bus"): - filter.append("bus") + info_filter.append("bus") if hasattr(args, "driver") and getattr(args, "driver"): - filter.append("driver") + info_filter.append("driver") if hasattr(args, "numa") and getattr(args, "numa"): - filter.append("numa") - if len(filter) == 0 or len(filter) == 4: + info_filter.append("numa") + if len(info_filter) == 0 or len(info_filter) == 4: static_dict["nic"] = nic_info else: nic_info_filtered = {} - for attr in filter: #remove all attributes except the one in filter: + for attr in info_filter: #remove all attributes except the one in info_filter: nic_info_filtered = nic_info_filtered | {key: value for key, value in nic_info.items() if key.lower() == attr} static_dict["nic"] = nic_info_filtered except amdsmi_exception.AmdSmiLibraryException as e: @@ -1951,8 +1947,6 @@ def firmware_nic(self, args, multiple_devices=False, nic=None, fw_list=True): except amdsmi_exception.AmdSmiLibraryException as e: logging.debug("Failed to get firmware info for nic %s | %s", nic_id, e.get_error_info()) - multiple_devices_csv_override = False - self.logger.store_nic_output(args.nic, 'values', fw_info) if multiple_devices: @@ -4714,9 +4708,9 @@ def topology_nic(self, args, multiple_devices=False, gpu=None, nic=None, self.helpers.check_required_groups() self.group_check_printed = True - isSingleNICRequest = False #-N option - isSingleSwitchRequest= False #-bs option - isSingleGPURequest = False #-g option + is_single_nic_request = False #-N option + is_single_switch_request = False #-bs option + is_single_gpu_request = False #-g option gpucount = 0 niccount = 0 @@ -4727,24 +4721,24 @@ def topology_nic(self, args, multiple_devices=False, gpu=None, nic=None, if not isinstance(args.nic, list): args.nic = [args.nic] if len(args.nic) == 1: - isSingleNICRequest = True + is_single_nic_request = True niccount = len(args.nic) - if args.switch == None: + if args.switch is None: args.switch = self.device_handles_switchs if not isinstance(args.switch, list): args.switch = [args.switch] if len(args.switch) == 1: - isSingleSwitchRequest = True + is_single_switch_request = True switchcount = len(args.switch) - if args.gpu == None: + if args.gpu is None: args.gpu = self.device_handles if not isinstance(args.gpu, list): args.gpu = [args.gpu] if len(args.gpu) == 1: - isSingleGPURequest = True - gpucount = len(args.switch) + is_single_gpu_request = True + gpucount = len(args.gpu) # Clear the table header self.logger.table_header = ''.rjust(12) @@ -4768,7 +4762,10 @@ def topology_nic(self, args, multiple_devices=False, gpu=None, nic=None, for gpu_dest in args.gpu: gpu_bdf = amdsmi_interface.amdsmi_get_gpu_device_bdf(gpu_dest) gpu_id = self.helpers.get_gpu_id_from_device_handle(gpu_dest) - status = amdsmi_interface.amdsmi_get_nic_gpu_topo_info(dest_nic,gpu_dest) + try: + status = amdsmi_interface.amdsmi_get_nic_gpu_topo_info(dest_nic, gpu_dest) + except amdsmi_exception.AmdSmiLibraryException as e: + status = "N/A" gpu_statuses_for_nic.append((gpu_bdf, status)) # Store BDF and status as tuple # Store NIC BDF and associated GPU statuses in the dictionary @@ -4798,7 +4795,7 @@ def topology_nic(self, args, multiple_devices=False, gpu=None, nic=None, # Add NIC rows with their associated GPU statuses for idx, (nic_bdf, gpu_info) in enumerate(topo_dict.items()): - if not isSingleNICRequest: + if not is_single_nic_request: if self.logger.is_human_readable_format(): nic_row = {'brcm_nic': f"BRCM_NIC{idx}".ljust(12), 'bdf': f"{nic_bdf}".ljust(18) } else: @@ -4860,15 +4857,15 @@ def topology_nic(self, args, multiple_devices=False, gpu=None, nic=None, if self.logger.is_human_readable_format(): tabular_output.append(header_row) - if isSingleNICRequest: + if is_single_nic_request: gpucount = 0 niccount = 1 switchcount = 0 - if isSingleSwitchRequest: + if is_single_switch_request: gpucount = 0 niccount = 0 switchcount = 1 - if isSingleGPURequest: + if is_single_gpu_request: gpucount = 1 niccount = 0 switchcount = 0 @@ -7144,12 +7141,12 @@ def monitor(self, args, multiple_devices=False, watching_output=False, gpu=None, if process: args.process = process if brcm_nic or args.brcm_nic: - self.monitor_nic(args, multiple_devices, watching_output, args.nic, watch, watch_time, iterations, - args.temperature, args.brcm_nic) + self.metric_nic(args, multiple_devices, watching_output, watch, watch_time, iterations, + nic=args.nic, nic_temperature=args.temperature) return if brcm_switch or args.brcm_switch: - self.monitor_switch(args, multiple_devices, watching_output, args.switch, watch, watch_time, iterations, - args.pcie, args.brcm_switch) + self.metric_switch(args, multiple_devices, watching_output, watch, watch_time, iterations, + switch=args.switch) return if not self.helpers.is_virtual_os(): if violation: diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_helpers.py b/projects/amdsmi/amdsmi_cli/amdsmi_helpers.py index 71603f105fe..fe0ac6761fd 100755 --- a/projects/amdsmi/amdsmi_cli/amdsmi_helpers.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_helpers.py @@ -350,7 +350,7 @@ def get_gpu_choices(self): device_handles = [] try: - # amdsmi_get_processor_handles returns the device_handles storted for gpu_id + # amdsmi_get_processor_handles returns the device_handles sorted for gpu_id device_handles = amdsmi_interface.amdsmi_get_processor_handles() except amdsmi_interface.AmdSmiLibraryException as e: if e.err_code in (amdsmi_interface.amdsmi_wrapper.AMDSMI_STATUS_NOT_INIT, @@ -388,8 +388,6 @@ def get_gpu_choices(self): def nic_choices_from_nic_info(self, nic_info, nic_id, device_handle, max_padding, nic_choices, nic_choices_str): bdf = nic_info['bdf'] - - #uuid="abc" uuid = nic_info['UUID'] nic_choices[str(nic_id)] = { @@ -412,7 +410,7 @@ def get_nic_choices(self): ainic_device_handles = [] try: - # get_nic_handles returns the device_handles storted for nic_id + # get_nic_handles returns the device_handles sorted for nic_id nic_device_handles = amdsmi_interface.get_nic_handles() ainic_device_handles = amdsmi_interface.get_ainic_handles() @@ -452,7 +450,7 @@ def get_switch_choices(self): device_handles = [] try: - # get_switch_handles returns the device_handles storted for switch_id + # get_switch_handles returns the device_handles sorted for switch_id device_handles = amdsmi_interface.get_switch_handles() except amdsmi_interface.AmdSmiLibraryException as e: @@ -472,8 +470,6 @@ def get_switch_choices(self): for switch_id, device_handle in enumerate(device_handles): bdf = amdsmi_interface.amdsmi_get_switch_device_bdf(device_handle) - - #uuid="abc" uuid = amdsmi_interface.amdsmi_get_switch_device_uuid(device_handle) switch_choices[str(switch_id)] = { @@ -599,9 +595,6 @@ def get_device_handles_from_nic_selections(self, nic_selections: List[str], nic_ # Check if passed nic is a nic ID or UUID if nic_selection == nic_id or nic_selection.lower() == uuid: - - device_type=amdsmi_interface.amdsmi_get_processor_type(device_handle) - selected_device_handles.append(device_handle) valid_nic_choice = True break @@ -612,7 +605,7 @@ def get_device_handles_from_nic_selections(self, nic_selections: List[str], nic_ break if not valid_nic_choice: - logging.debug(f"AMDSMIHelpers.get_device_handles_from_gpu_selections - Unable to convert {nic_selection}") + logging.debug(f"AMDSMIHelpers.get_device_handles_from_nic_selections - Unable to convert {nic_selection}") return False, nic_selection @@ -627,7 +620,7 @@ def get_device_handles_from_switch_selections(self, switch_selections: List[str] Args: switch_selections (list[str]): Selected switch ID(s), BDF(s), or UUID(s): ex: ID:0 | BDF:0000:23:00.0 | UUID:ffffffff-0000-1000-0000-000000000000 - switch_choices (dict{switch_choices}): This is a dictionary of the possible gpu_choices + switch_choices (dict{switch_choices}): This is a dictionary of the possible switch_choices Returns: (True, list[device_handles]): Returns a list of all the switch_selections converted to amdsmi device_handles @@ -654,9 +647,6 @@ def get_device_handles_from_switch_selections(self, switch_selections: List[str] # Check if passed switch is a switch ID or UUID if switch_selection == switch_id or switch_selection.lower() == uuid: - - device_type=amdsmi_interface.amdsmi_get_processor_type(device_handle) - selected_device_handles.append(device_handle) valid_switch_choice = True break @@ -671,7 +661,7 @@ def get_device_handles_from_switch_selections(self, switch_selections: List[str] pass if not valid_switch_choice: - logging.debug(f"AMDSMIHelpers.get_device_handles_from_gpu_selections - Unable to convert {switch_selection}") + logging.debug(f"AMDSMIHelpers.get_device_handles_from_switch_selections - Unable to convert {switch_selection}") return False, switch_selection diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_logger.py b/projects/amdsmi/amdsmi_cli/amdsmi_logger.py index a9f7ff31961..cbc587ebd91 100644 --- a/projects/amdsmi/amdsmi_cli/amdsmi_logger.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_logger.py @@ -471,7 +471,7 @@ def store_ainic_output(self, device_handle, argument, data): self._store_ainic_output_amdsmi(nic_id=nic_id, argument=argument, data=data) def store_switch_output(self, device_handle, argument, data): - """ Convert device handle to nic id and store output + """ Convert device handle to switch id and store output params: device_handle - device handle object to the target device output argument (str) - key to store data diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_parser.py b/projects/amdsmi/amdsmi_cli/amdsmi_parser.py index a34ebe5637d..f036146676a 100644 --- a/projects/amdsmi/amdsmi_cli/amdsmi_parser.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_parser.py @@ -510,7 +510,7 @@ def _nic_select(self, nic_choices): amdsmi_helpers = self.helpers class _NICSelectAction(argparse.Action): - ouputformat=self.helpers.get_output_format() + output_format=self.helpers.get_output_format() # Checks the values def __call__(self, parser, args, values, option_string=None): if "all" in nic_choices: @@ -521,9 +521,9 @@ def __call__(self, parser, args, values, option_string=None): setattr(args, self.dest, selected_device_handles) else: if selected_device_handles == '': - raise amdsmi_cli_exceptions.AmdSmiMissingParameterValueException("--nic", _NICSelectAction.ouputformat) + raise amdsmi_cli_exceptions.AmdSmiMissingParameterValueException("--nic", _NICSelectAction.output_format) else: - raise amdsmi_cli_exceptions.AmdSmiDeviceNotFoundException(selected_device_handles, _NICSelectAction.ouputformat) + raise amdsmi_cli_exceptions.AmdSmiDeviceNotFoundException(selected_device_handles, _NICSelectAction.output_format) return _NICSelectAction @@ -537,8 +537,8 @@ def _switch_select(self, switch_choices): """ amdsmi_helpers = self.helpers - class _switchSelectAction(argparse.Action): - ouputformat=self.helpers.get_output_format() + class _SwitchSelectAction(argparse.Action): + output_format=self.helpers.get_output_format() # Checks the values def __call__(self, parser, args, values, option_string=None): if "all" in switch_choices: @@ -549,12 +549,12 @@ def __call__(self, parser, args, values, option_string=None): setattr(args, self.dest, selected_device_handles) else: if selected_device_handles == '': - raise amdsmi_cli_exceptions.AmdSmiMissingParameterValueException("--switch", _switchSelectAction.ouputformat) + raise amdsmi_cli_exceptions.AmdSmiMissingParameterValueException("--switch", _SwitchSelectAction.output_format) else: - raise amdsmi_cli_exceptions.AmdSmiDeviceNotFoundException(selected_device_handles, _switchSelectAction.ouputformat) + raise amdsmi_cli_exceptions.AmdSmiDeviceNotFoundException(selected_device_handles, _SwitchSelectAction.output_format) - return _switchSelectAction + return _SwitchSelectAction def _cpu_select(self, cpu_choices): diff --git a/projects/amdsmi/example/amd_smi_drm_example.cc b/projects/amdsmi/example/amd_smi_drm_example.cc index 3019b4e597a..9e0291bd768 100644 --- a/projects/amdsmi/example/amd_smi_drm_example.cc +++ b/projects/amdsmi/example/amd_smi_drm_example.cc @@ -286,7 +286,7 @@ static const std::map {AMDSMI_PROCESSOR_TYPE_NON_AMD_CPU, "NON_AMD_CPU"}, {AMDSMI_PROCESSOR_TYPE_AMD_CPU_CORE, "AMD_CPU_CORE"}, {AMDSMI_PROCESSOR_TYPE_AMD_NIC, "AMD_AINIC"}, - {AMDSMI_PROCESSOR_TYPE_BRCM_NIC, "BRCM_NIC,"}, + {AMDSMI_PROCESSOR_TYPE_BRCM_NIC, "BRCM_NIC"}, {AMDSMI_PROCESSOR_TYPE_BRCM_SWITCH, "BRCM_SWITCH"} }; diff --git a/projects/amdsmi/include/amd_smi/impl/amd_smi_system.h b/projects/amdsmi/include/amd_smi/impl/amd_smi_system.h index 2d4c1d30d07..742374c39fb 100644 --- a/projects/amdsmi/include/amd_smi/impl/amd_smi_system.h +++ b/projects/amdsmi/include/amd_smi/impl/amd_smi_system.h @@ -36,7 +36,7 @@ #ifdef BRCM_NIC #include "amd_smi/impl/nic/amd_smi_no_drm_nic.h" #include "amd_smi/impl/nic/amd_smi_no_drm_switch.h" -#endif//BRCM_NIC +#endif // BRCM_NIC namespace amd::smi { // Singleton: Only one system in an application @@ -88,9 +88,9 @@ class AMDSmiSystem { smi_nic_ctx_t ainic_ctx_; std::vector ai_nic_info_; #ifdef BRCM_NIC - AMDSmiNoDrmNIC no_drm_nic; - AMDSmiNoDrmSwitch no_drm_switch; -#endif//BRCM_NIC + AMDSmiNoDrmNIC no_drm_nic_; + AMDSmiNoDrmSwitch no_drm_switch_; +#endif // BRCM_NIC std::vector sockets_; std::set processors_; // Track valid processors std::set nic_processors_; // Track valid nic processors diff --git a/projects/amdsmi/include/amd_smi/impl/nic/amd_smi_lspci_commands.h b/projects/amdsmi/include/amd_smi/impl/nic/amd_smi_lspci_commands.h index 3f071f92372..200a05e7259 100644 --- a/projects/amdsmi/include/amd_smi/impl/nic/amd_smi_lspci_commands.h +++ b/projects/amdsmi/include/amd_smi/impl/nic/amd_smi_lspci_commands.h @@ -31,7 +31,7 @@ #include "amd_smi/amdsmi.h" #include "rocm_smi/rocm_smi_logger.h" -amdsmi_status_t get_lspci_device_data(std::string bdfStr, std::string search_key, std::string &version); -amdsmi_status_t get_lspci_root_switch(amdsmi_bdf_t devicehBdf, amdsmi_bdf_t *switchBdf); +amdsmi_status_t get_lspci_device_data(std::string bdf_str, std::string search_key, std::string &version); +amdsmi_status_t get_lspci_root_switch(amdsmi_bdf_t device_bdf, amdsmi_bdf_t *switchBdf); -#endif //AMD_SMI_LSPCI_COMMANDS_H_ \ No newline at end of file +#endif // AMD_SMI_LSPCI_COMMANDS_H_ \ No newline at end of file diff --git a/projects/amdsmi/include/amd_smi/impl/nic/amd_smi_no_drm_nic.h b/projects/amdsmi/include/amd_smi/impl/nic/amd_smi_no_drm_nic.h index 9d3da2f4216..877db37f7cc 100644 --- a/projects/amdsmi/include/amd_smi/impl/nic/amd_smi_no_drm_nic.h +++ b/projects/amdsmi/include/amd_smi/impl/nic/amd_smi_no_drm_nic.h @@ -52,14 +52,14 @@ class AMDSmiNoDrmNIC { uint32_t get_vendor_id(); amdsmi_status_t amd_query_nic_info(uint32_t nic_index, amdsmi_brcm_nic_info_t& info); - amdsmi_status_t amd_query_nic_uuid(std::string devicePath, std::string& version); - amdsmi_status_t amd_query_nic_temp(std::string hwmonPath, amdsmi_brcm_nic_temperature_metric_t& info); - amdsmi_status_t amd_query_nic_device(std::string hwmonPath, amdsmi_brcm_nic_hwmon_device_t& info); - amdsmi_status_t amd_query_nic_power(std::string hwmonPath, amdsmi_brcm_nic_hwmon_power_t& info); - amdsmi_status_t amd_query_nic_numa_affinity(std::string devicePath, int32_t *numa_node); - amdsmi_status_t amd_query_nic_cpu_affinity(std::string devicePath, std::string& cpu_affinity); + amdsmi_status_t amd_query_nic_uuid(std::string device_path, std::string& version); + amdsmi_status_t amd_query_nic_temp(std::string hwmon_path, amdsmi_brcm_nic_temperature_metric_t& info); + amdsmi_status_t amd_query_nic_device(std::string hwmon_path, amdsmi_brcm_nic_hwmon_device_t& info); + amdsmi_status_t amd_query_nic_power(std::string hwmon_path, amdsmi_brcm_nic_hwmon_power_t& info); + amdsmi_status_t amd_query_nic_numa_affinity(std::string device_path, int32_t *numa_node); + amdsmi_status_t amd_query_nic_cpu_affinity(std::string device_path, std::string& cpu_affinity); - amdsmi_status_t amd_query_nic_fw_info(std::string devicePath, amdsmi_brcm_nic_firmware_t& info); + amdsmi_status_t amd_query_nic_fw_info(std::string device_path, amdsmi_brcm_nic_firmware_t& info); private: // when file is not found, the empty string will be returned std::vector device_paths_; diff --git a/projects/amdsmi/include/amd_smi/impl/nic/amd_smi_no_drm_switch.h b/projects/amdsmi/include/amd_smi/impl/nic/amd_smi_no_drm_switch.h index 0f59db840a1..4bc48310550 100644 --- a/projects/amdsmi/include/amd_smi/impl/nic/amd_smi_no_drm_switch.h +++ b/projects/amdsmi/include/amd_smi/impl/nic/amd_smi_no_drm_switch.h @@ -51,12 +51,12 @@ class AMDSmiNoDrmSwitch { bool check_if_no_drm_is_supported(); uint32_t get_vendor_id(); - amdsmi_status_t amd_query_switch_link(std::string devicePath, amdsmi_brcm_switch_link_metric_t& info); - amdsmi_status_t amd_query_switch_uuid(std::string bdfStr, std::string& serial); - amdsmi_status_t amd_query_switch_numa_affinity(std::string devicePath, int32_t *numa_node); - amdsmi_status_t amd_query_switch_cpu_affinity(std::string devicePath, std::string& cpu_affinity); - amdsmi_status_t amd_query_switch_device( std::string devicePath,amdsmi_brcm_switch_device_metric_t &info); - amdsmi_status_t amd_query_switch_power( std::string devicePath,amdsmi_brcm_switch_power_metric_t &info); + amdsmi_status_t amd_query_switch_link(std::string device_path, amdsmi_brcm_switch_link_metric_t& info); + amdsmi_status_t amd_query_switch_uuid(std::string bdf_str, std::string& serial); + amdsmi_status_t amd_query_switch_numa_affinity(std::string device_path, int32_t *numa_node); + amdsmi_status_t amd_query_switch_cpu_affinity(std::string device_path, std::string& cpu_affinity); + amdsmi_status_t amd_query_switch_device( std::string device_path,amdsmi_brcm_switch_device_metric_t &info); + amdsmi_status_t amd_query_switch_power( std::string device_path,amdsmi_brcm_switch_power_metric_t &info); private: // when file is not found, the empty string will be returned diff --git a/projects/amdsmi/py-interface/amdsmi_interface.py b/projects/amdsmi/py-interface/amdsmi_interface.py index 0dddfb356f0..785056bb82e 100644 --- a/projects/amdsmi/py-interface/amdsmi_interface.py +++ b/projects/amdsmi/py-interface/amdsmi_interface.py @@ -1222,30 +1222,6 @@ def get_ainic_handles() -> List[amdsmi_wrapper.amdsmi_processor_handle]: ]) return nic_handles -def amdsmi_get_processor_handles_devices() -> List[amdsmi_wrapper.amdsmi_processor_handle]: - - socket_handles = amdsmi_get_socket_handles() # Assuming this retrieves socket handles - gpu_handles = [] - - # Retrieve GPU handles - gpu_handles.extend(get_gpu_handles()) - - # Retrieve NIC handles - nic_handles = get_nic_handles() - gpu_handles.extend(nic_handles) - - # Retrieve Switch handles - switch_handles = get_switch_handles() - gpu_handles.extend(switch_handles) - - ainic_handles = get_ainic_handles() - gpu_handles.extend(ainic_handles) - - gpu_handles_count = len(gpu_handles) - #print(f"Total GPU and NIC handles: {gpu_handles_count}") - - return gpu_handles - def amdsmi_get_cpucore_handles() -> List[c_void_p]: cores_count = ctypes.c_uint32(0) null_ptr = POINTER(amdsmi_wrapper.amdsmi_processor_handle)() @@ -2459,19 +2435,19 @@ def amdsmi_get_nic_temp_info( processor_handle, amdsmi_wrapper.amdsmi_processor_handle ) - power_measure = amdsmi_wrapper.amdsmi_brcm_nic_temperature_metric_t() + temp_measure = amdsmi_wrapper.amdsmi_brcm_nic_temperature_metric_t() _check_res( amdsmi_wrapper.amdsmi_get_nic_temp_info( - processor_handle, ctypes.byref(power_measure) + processor_handle, ctypes.byref(temp_measure) ) ) temp_info_dict = { - "NIC_TEMP_CURRENT": math.trunc(power_measure.nic_temp_input / 1000), - "NIC_TEMP_CRIT_ALARM": power_measure.nic_temp_crit_alarm, - "NIC_TEMP_EMERGENCY_ALARM": power_measure.nic_temp_emergency_alarm, - "NIC_TEMP_SHUTDOWN_ALARM": power_measure.nic_temp_shutdown_alarm, - "NIC_TEMP_MAX_ALARM": power_measure.nic_temp_max_alarm, + "NIC_TEMP_CURRENT": math.trunc(temp_measure.nic_temp_input / 1000), + "NIC_TEMP_CRIT_ALARM": temp_measure.nic_temp_crit_alarm, + "NIC_TEMP_EMERGENCY_ALARM": temp_measure.nic_temp_emergency_alarm, + "NIC_TEMP_SHUTDOWN_ALARM": temp_measure.nic_temp_shutdown_alarm, + "NIC_TEMP_MAX_ALARM": temp_measure.nic_temp_max_alarm, } for key, value in temp_info_dict.items(): if value == 0xFFFF: @@ -2515,18 +2491,18 @@ def amdsmi_get_switch_link_info( processor_handle, amdsmi_wrapper.amdsmi_processor_handle ) - power_measure = amdsmi_wrapper.struct_amdsmi_brcm_switch_link_metric_t() + link_measure = amdsmi_wrapper.struct_amdsmi_brcm_switch_link_metric_t() _check_res( amdsmi_wrapper.amdsmi_get_switch_link_info( - processor_handle, ctypes.byref(power_measure) + processor_handle, ctypes.byref(link_measure) ) ) link_info_dict = { - "CURRENT_LINK_SPEED": power_measure.current_link_speed, - "MAX_LINK_SPEED": power_measure.max_link_speed, - "CURRENT_LINK_WIDTH": power_measure.current_link_width, - "MAX_LINK_WIDTH": power_measure.max_link_width, + "CURRENT_LINK_SPEED": link_measure.current_link_speed, + "MAX_LINK_SPEED": link_measure.max_link_speed, + "CURRENT_LINK_WIDTH": link_measure.current_link_width, + "MAX_LINK_WIDTH": link_measure.max_link_width, } for key, value in link_info_dict.items(): diff --git a/projects/amdsmi/rocm_smi/src/rocm_smi_main.cc b/projects/amdsmi/rocm_smi/src/rocm_smi_main.cc index 139f55236db..947735015e7 100644 --- a/projects/amdsmi/rocm_smi/src/rocm_smi_main.cc +++ b/projects/amdsmi/rocm_smi/src/rocm_smi_main.cc @@ -1027,7 +1027,7 @@ static bool isBRCMnic(std::string dev_path) { std::ostringstream ss; std::string vend_path = dev_path + kPathDeviceVendor; if (!FileExists(vend_path.c_str())) { - ss << __PRETTY_FUNCTION__ << " | device_path = " << dev_path << " is an BRCMnic device - " + ss << __PRETTY_FUNCTION__ << " | device_path = " << dev_path << " is a BRCM NIC device - " << (isBRCMnic ? "TRUE" : " FALSE"); LOG_DEBUG(ss); return isBRCMnic; @@ -1037,7 +1037,7 @@ static bool isBRCMnic(std::string dev_path) { fs.open(vend_path); if (!fs.is_open()) { - ss << __PRETTY_FUNCTION__ << " | device_path = " << dev_path << " is an BRCMnic device - " + ss << __PRETTY_FUNCTION__ << " | device_path = " << dev_path << " is a BRCM NIC device - " << (isBRCMnic ? "TRUE" : " FALSE"); LOG_DEBUG(ss); return isBRCMnic; @@ -1052,7 +1052,7 @@ static bool isBRCMnic(std::string dev_path) { if (vendor_id == kBRCMnicId) { isBRCMnic = true; } - ss << __PRETTY_FUNCTION__ << " | device_path = " << dev_path << " is an BRCMnic device - " + ss << __PRETTY_FUNCTION__ << " | device_path = " << dev_path << " is a BRCM NIC device - " << (isBRCMnic ? "TRUE" : " FALSE"); LOG_DEBUG(ss); return isBRCMnic; @@ -1065,7 +1065,7 @@ static bool isBRCMswitch(std::string dev_path) { std::string ldev_path = dev_path + kPathDevice; if (!FileExists(vend_path.c_str()) || !FileExists(ldev_path.c_str())) { - ss << __PRETTY_FUNCTION__ << " | device_path = " << dev_path << " is an BRCMswitch device - " + ss << __PRETTY_FUNCTION__ << " | device_path = " << dev_path << " is a BRCM switch device - " << (isBRCMswitch ? "TRUE" : " FALSE"); LOG_DEBUG(ss); return isBRCMswitch; @@ -1076,7 +1076,7 @@ static bool isBRCMswitch(std::string dev_path) { dfs.open(ldev_path); if (!vfs.is_open() || !dfs.is_open()) { - ss << __PRETTY_FUNCTION__ << " | device_path = " << dev_path << " is an BRCMswitch device - " + ss << __PRETTY_FUNCTION__ << " | device_path = " << dev_path << " is a BRCM switch device - " << (isBRCMswitch ? "TRUE" : " FALSE"); LOG_DEBUG(ss); return isBRCMswitch; @@ -1094,7 +1094,7 @@ static bool isBRCMswitch(std::string dev_path) { if (vendor_id == kBRCMswitchId && dev_id == kBRCMswitchDId) { isBRCMswitch = true; } - ss << __PRETTY_FUNCTION__ << " | device_path = " << dev_path << " is an BRCMswitch device - " + ss << __PRETTY_FUNCTION__ << " | device_path = " << dev_path << " is a BRCM switch device - " << (isBRCMswitch ? "TRUE" : " FALSE"); LOG_DEBUG(ss); return isBRCMswitch; diff --git a/projects/amdsmi/src/amd_smi/amd_smi.cc b/projects/amdsmi/src/amd_smi/amd_smi.cc index 3feb2ca21f3..f6b1c2378ae 100644 --- a/projects/amdsmi/src/amd_smi/amd_smi.cc +++ b/projects/amdsmi/src/amd_smi/amd_smi.cc @@ -58,7 +58,7 @@ #include "amd_smi/impl/nic/amd_smi_nic_device.h" #include "amd_smi/impl/nic/amd_smi_switch_device.h" #include "amd_smi/impl/nic/amd_smi_lspci_commands.h" -#endif//BRCM_NIC +#endif // BRCM_NIC #include "amd_smi/impl/amd_smi_uuid.h" #include "amd_smi/impl/xf86drm.h" #include "amd_smi/impl/amd_smi_utils.h" @@ -295,7 +295,7 @@ amdsmi_status_t rsmi_switch_wrapper(F &&f, amdsmi_processor_handle processor_han } return r; } -#endif//BRCM_NIC +#endif // BRCM_NIC amdsmi_status_t amdsmi_init(uint64_t flags) { @@ -759,11 +759,11 @@ amdsmi_status_t amdsmi_get_processor_count_from_handles(amdsmi_processor_handle* amdsmi_status_t r = amdsmi_get_processor_type(processor_handles[i], &processor_type); if (r != AMDSMI_STATUS_SUCCESS) return r; - if(processor_type == AMDSMI_PROCESSOR_TYPE_AMD_CPU) { + if (processor_type == AMDSMI_PROCESSOR_TYPE_AMD_CPU) { count_cpusockets++; - } else if(processor_type == AMDSMI_PROCESSOR_TYPE_AMD_CPU_CORE) { + } else if (processor_type == AMDSMI_PROCESSOR_TYPE_AMD_CPU_CORE) { count_cpucores++; - } else if(processor_type == AMDSMI_PROCESSOR_TYPE_AMD_GPU) { + } else if (processor_type == AMDSMI_PROCESSOR_TYPE_AMD_GPU) { count_gpus++; } } @@ -829,7 +829,7 @@ amdsmi_get_gpu_device_bdf(amdsmi_processor_handle processor_handle, amdsmi_bdf_t AMDSMI_CHECK_INIT(); - if (bdf == NULL) { + if (bdf == nullptr) { return AMDSMI_STATUS_INVAL; } @@ -863,12 +863,12 @@ amdsmi_get_ainic_info(amdsmi_processor_handle processor_handle, amd::smi::AMDSmi amdsmi_status_t amdsmi_get_nic_asic_info(amdsmi_processor_handle processor_handle, amdsmi_nic_asic_info_t *info) { AMDSMI_CHECK_INIT(); - if (info == NULL) { + if (info == nullptr) { return AMDSMI_STATUS_INVAL; } amd::smi::AMDSmiAINICDevice::AINICInfo ainic_info = {}; amdsmi_status_t status = amdsmi_get_ainic_info(processor_handle, &ainic_info); - if(status != AMDSMI_STATUS_SUCCESS){ + if (status != AMDSMI_STATUS_SUCCESS) { return status; } *info = ainic_info.asic; @@ -877,12 +877,12 @@ amdsmi_status_t amdsmi_get_nic_asic_info(amdsmi_processor_handle processor_handl amdsmi_status_t amdsmi_get_nic_bus_info(amdsmi_processor_handle processor_handle, amdsmi_nic_bus_info_t *info) { AMDSMI_CHECK_INIT(); - if (info == NULL) { + if (info == nullptr) { return AMDSMI_STATUS_INVAL; } amd::smi::AMDSmiAINICDevice::AINICInfo ainic_info = {}; amdsmi_status_t status = amdsmi_get_ainic_info(processor_handle, &ainic_info); - if(status != AMDSMI_STATUS_SUCCESS){ + if (status != AMDSMI_STATUS_SUCCESS) { return status; } *info = ainic_info.bus; @@ -891,12 +891,12 @@ amdsmi_status_t amdsmi_get_nic_bus_info(amdsmi_processor_handle processor_handle amdsmi_status_t amdsmi_get_nic_driver_info(amdsmi_processor_handle processor_handle, amdsmi_nic_driver_info_t *info) { AMDSMI_CHECK_INIT(); - if (info == NULL) { + if (info == nullptr) { return AMDSMI_STATUS_INVAL; } amd::smi::AMDSmiAINICDevice::AINICInfo ainic_info = {}; amdsmi_status_t status = amdsmi_get_ainic_info(processor_handle, &ainic_info); - if(status != AMDSMI_STATUS_SUCCESS){ + if (status != AMDSMI_STATUS_SUCCESS) { return status; } *info = ainic_info.driver; @@ -905,12 +905,12 @@ amdsmi_status_t amdsmi_get_nic_driver_info(amdsmi_processor_handle processor_han amdsmi_status_t amdsmi_get_nic_numa_info(amdsmi_processor_handle processor_handle, amdsmi_nic_numa_info_t *info) { AMDSMI_CHECK_INIT(); - if (info == NULL) { + if (info == nullptr) { return AMDSMI_STATUS_INVAL; } amd::smi::AMDSmiAINICDevice::AINICInfo ainic_info = {}; amdsmi_status_t status = amdsmi_get_ainic_info(processor_handle, &ainic_info); - if(status != AMDSMI_STATUS_SUCCESS){ + if (status != AMDSMI_STATUS_SUCCESS) { return status; } *info = ainic_info.numa; @@ -919,12 +919,12 @@ amdsmi_status_t amdsmi_get_nic_numa_info(amdsmi_processor_handle processor_handl amdsmi_status_t amdsmi_get_nic_port_info(amdsmi_processor_handle processor_handle, amdsmi_nic_port_info_t *info) { AMDSMI_CHECK_INIT(); - if (info == NULL) { + if (info == nullptr) { return AMDSMI_STATUS_INVAL; } amd::smi::AMDSmiAINICDevice::AINICInfo ainic_info = {}; amdsmi_status_t status = amdsmi_get_ainic_info(processor_handle, &ainic_info); - if(status != AMDSMI_STATUS_SUCCESS){ + if (status != AMDSMI_STATUS_SUCCESS) { return status; } *info = ainic_info.port; @@ -933,12 +933,12 @@ amdsmi_status_t amdsmi_get_nic_port_info(amdsmi_processor_handle processor_handl amdsmi_status_t amdsmi_get_nic_rdma_dev_info(amdsmi_processor_handle processor_handle, amdsmi_nic_rdma_devices_info_t *info) { AMDSMI_CHECK_INIT(); - if (info == NULL) { + if (info == nullptr) { return AMDSMI_STATUS_INVAL; } amd::smi::AMDSmiAINICDevice::AINICInfo ainic_info = {}; amdsmi_status_t status = amdsmi_get_ainic_info(processor_handle, &ainic_info); - if(status != AMDSMI_STATUS_SUCCESS){ + if (status != AMDSMI_STATUS_SUCCESS) { return status; } *info = ainic_info.rdma_dev; @@ -949,7 +949,7 @@ amdsmi_status_t amdsmi_get_nic_rdma_dev_info(amdsmi_processor_handle processor_h amdsmi_status_t amdsmi_get_nic_info(amdsmi_processor_handle processor_handle, amdsmi_brcm_nic_info_t *info) { AMDSMI_CHECK_INIT(); - if (info == NULL) { + if (info == nullptr) { return AMDSMI_STATUS_INVAL; } @@ -965,7 +965,7 @@ amdsmi_status_t amdsmi_get_nic_temp_info(amdsmi_processor_handle processor_handl amdsmi_brcm_nic_temperature_metric_t *info) { AMDSMI_CHECK_INIT(); - if (info == NULL) { + if (info == nullptr) { return AMDSMI_STATUS_INVAL; } @@ -980,7 +980,7 @@ amdsmi_status_t amdsmi_get_nic_temp_info(amdsmi_processor_handle processor_handl amdsmi_status_t amdsmi_get_nic_power_info(amdsmi_processor_handle processor_handle, amdsmi_brcm_nic_hwmon_power_t *info) { AMDSMI_CHECK_INIT(); - if (info == NULL) { + if (info == nullptr) { return AMDSMI_STATUS_INVAL; } amd::smi::AMDSmiNICDevice *nic_device = nullptr; @@ -994,7 +994,7 @@ amdsmi_status_t amdsmi_get_nic_power_info(amdsmi_processor_handle processor_hand amdsmi_status_t amdsmi_get_nic_device_info(amdsmi_processor_handle processor_handle, amdsmi_brcm_nic_hwmon_device_t *info) { AMDSMI_CHECK_INIT(); - if (info == NULL) { + if (info == nullptr) { return AMDSMI_STATUS_INVAL; } amd::smi::AMDSmiNICDevice *nic_device = nullptr; @@ -1008,7 +1008,7 @@ amdsmi_status_t amdsmi_get_nic_device_info(amdsmi_processor_handle processor_han amdsmi_status_t amdsmi_get_nic_metrics_info(amdsmi_processor_handle processor_handle, amdsmi_brcm_nic_hwmon_metrics_t *metrics) { AMDSMI_CHECK_INIT(); - if (metrics == NULL) { + if (metrics == nullptr) { return AMDSMI_STATUS_INVAL; } @@ -1060,7 +1060,7 @@ amdsmi_status_t amdsmi_get_switch_device_bdf(amdsmi_processor_handle processor_h amdsmi_bdf_t* bdf) { AMDSMI_CHECK_INIT(); - if (bdf == NULL) { + if (bdf == nullptr) { return AMDSMI_STATUS_INVAL; } @@ -1077,7 +1077,7 @@ amdsmi_status_t amdsmi_get_switch_link_info(amdsmi_processor_handle processor_ha amdsmi_brcm_switch_link_metric_t *info) { AMDSMI_CHECK_INIT(); - if (info == NULL) { + if (info == nullptr) { return AMDSMI_STATUS_INVAL; } @@ -1093,7 +1093,7 @@ amdsmi_status_t amdsmi_get_switch_power_info(amdsmi_processor_handle processor_h amdsmi_brcm_switch_power_metric_t *info) { AMDSMI_CHECK_INIT(); - if (info == NULL) { + if (info == nullptr) { return AMDSMI_STATUS_INVAL; } @@ -1109,7 +1109,7 @@ amdsmi_status_t amdsmi_get_switch_device_info(amdsmi_processor_handle processor_ amdsmi_brcm_switch_device_metric_t *info) { AMDSMI_CHECK_INIT(); - if (info == NULL) { + if (info == nullptr) { return AMDSMI_STATUS_INVAL; } amdsmi_status_t ret; @@ -1132,7 +1132,7 @@ amdsmi_status_t amdsmi_get_switch_device_info(amdsmi_processor_handle processor_ amdsmi_status_t amdsmi_get_switch_metrics_info(amdsmi_processor_handle processor_handle, amdsmi_brcm_switch_metric_t *info){ AMDSMI_CHECK_INIT(); - if (info == NULL) { + if (info == nullptr) { return AMDSMI_STATUS_INVAL; } amdsmi_status_t ret; @@ -1164,7 +1164,7 @@ amdsmi_status_t amdsmi_get_switch_metrics_info(amdsmi_processor_handle processor amdsmi_status_t amdsmi_get_nic_fw_info(amdsmi_processor_handle processor_handle, amdsmi_brcm_nic_firmware_t *info) { AMDSMI_CHECK_INIT(); - if (info == NULL) { + if (info == nullptr) { return AMDSMI_STATUS_INVAL; } amd::smi::AMDSmiNICDevice *nic_device = nullptr; @@ -1173,7 +1173,7 @@ amdsmi_status_t amdsmi_get_nic_fw_info(amdsmi_processor_handle processor_handle, nic_device->amd_query_nic_firmware_info(*info); return AMDSMI_STATUS_SUCCESS; } -#endif//BRCM_NIC +#endif // BRCM_NIC amdsmi_status_t amdsmi_get_nic_rdma_port_statistics( amdsmi_processor_handle processor_handle, @@ -1199,27 +1199,27 @@ amdsmi_status_t amdsmi_get_nic_rdma_port_statistics( LOG_ERROR(ss); return status; } - if(nic_info.rdma_dev.num_rdma_dev < 1) { + if (nic_info.rdma_dev.num_rdma_dev < 1) { ss << __PRETTY_FUNCTION__ << " | No RDMA devices found"; LOG_ERROR(ss); return AMDSMI_STATUS_NOT_SUPPORTED; } - else if(rdma_port_index >= nic_info.rdma_dev.num_rdma_dev) { + else if (rdma_port_index >= nic_info.rdma_dev.num_rdma_dev) { ss << __PRETTY_FUNCTION__ << " | NIC ports (" << rdma_port_index << ") is out of range (max ports:" << nic_info.rdma_dev.num_rdma_dev << ")"; LOG_ERROR(ss); return AMDSMI_STATUS_NOT_SUPPORTED; } - else if(nic_info.rdma_dev.rdma_dev_info[0].num_rdma_ports < 1) { + else if (nic_info.rdma_dev.rdma_dev_info[0].num_rdma_ports < 1) { ss << __PRETTY_FUNCTION__ << " | No RDMA ports found"; LOG_ERROR(ss); return AMDSMI_STATUS_NOT_SUPPORTED; } - else if(!num_stats) { + else if (!num_stats) { ss << __PRETTY_FUNCTION__ << " | Invalid num_stats pointer"; LOG_ERROR(ss); return AMDSMI_STATUS_INVAL; } - else if(!stats && *num_stats > 0) { + else if (!stats && *num_stats > 0) { ss << __PRETTY_FUNCTION__ << " | Invalid stats and num_stats pointers"; LOG_ERROR(ss); return AMDSMI_STATUS_INVAL; @@ -1230,7 +1230,7 @@ amdsmi_status_t amdsmi_get_nic_rdma_port_statistics( int port_num = nic_info.rdma_dev.rdma_dev_info[0].rdma_port_info[rdma_port_index].rdma_port; std::string directory_path = "/sys/class/net/" + netdev + "/device/infiniband/" + rdmadev + "/subsystem/" + rdmadev + "/subsystem/" + rdmadev + "/ports/" + std::to_string(port_num) + "/hw_counters/"; - if(!std::filesystem::exists(directory_path)) { + if (!std::filesystem::exists(directory_path)) { ss << __PRETTY_FUNCTION__ << " | Directory does not exist: " << directory_path; LOG_ERROR(ss); return AMDSMI_STATUS_FILE_ERROR; @@ -1239,7 +1239,7 @@ amdsmi_status_t amdsmi_get_nic_rdma_port_statistics( uint32_t idx = 0; for (const auto& entry : std::filesystem::directory_iterator(directory_path)) { if (std::filesystem::is_regular_file(entry.path())) { - if(stats && num_stats && idx < *num_stats) { + if (stats && num_stats && idx < *num_stats) { snprintf(stats[idx].name, sizeof(stats[idx].name), "%s", entry.path().filename().string().c_str()); std::ifstream in(entry.path()); if (!in.is_open()) { @@ -1252,7 +1252,7 @@ amdsmi_status_t amdsmi_get_nic_rdma_port_statistics( ++idx; } } - if(num_stats) { + if (num_stats) { *num_stats = idx; } return AMDSMI_STATUS_SUCCESS; @@ -4737,7 +4737,7 @@ amdsmi_status_t amdsmi_get_gpu_topo_cpu_affinity(amdsmi_processor_handle process unsigned int *cpu_aff_length, char *cpu_aff_data) { AMDSMI_CHECK_INIT(); - if (cpu_aff_length == nullptr || cpu_aff_data == nullptr || cpu_aff_length == nullptr || + if (cpu_aff_length == nullptr || cpu_aff_data == nullptr || *cpu_aff_length < AMDSMI_MAX_STRING_LENGTH) { return AMDSMI_STATUS_INVAL; } @@ -4766,18 +4766,18 @@ amdsmi_status_t amdsmi_get_nic_gpu_topo_info(amdsmi_processor_handle nic_process amdsmi_processor_handle gpu_processor_handle, size_t *topo_info_length, char *topo_info) { std::ostringstream ss; AMDSMI_CHECK_INIT(); - if (topo_info_length == nullptr || topo_info == nullptr || topo_info_length == nullptr || + if (topo_info_length == nullptr || topo_info == nullptr || *topo_info_length < AMDSMI_MAX_STRING_LENGTH) { return AMDSMI_STATUS_INVAL; } amdsmi_status_t status = AMDSMI_STATUS_SUCCESS; amd::smi::AMDSmiNICDevice *nic_device = nullptr; amdsmi_status_t r = get_nic_device_from_handle(nic_processor_handle, &nic_device); - if (status != AMDSMI_STATUS_SUCCESS) { + if (r != AMDSMI_STATUS_SUCCESS) { ss << __PRETTY_FUNCTION__ - << " | Received invalid NIC handler. Return code: " << status; + << " | Received invalid NIC handler. Return code: " << r; LOG_INFO(ss); - return status; + return r; } amd::smi::AMDSmiGPUDevice* gpu_device = nullptr; status = get_gpu_device_from_handle(gpu_processor_handle, &gpu_device); @@ -4787,16 +4787,16 @@ amdsmi_status_t amdsmi_get_nic_gpu_topo_info(amdsmi_processor_handle nic_process LOG_INFO(ss); return status; } - amdsmi_bdf_t nic_switchBdf = {}; - status = amdsmi_get_root_switch(nic_device->get_bdf(), &nic_switchBdf); + amdsmi_bdf_t nic_switch_bdf = {}; + status = amdsmi_get_root_switch(nic_device->get_bdf(), &nic_switch_bdf); if (status != AMDSMI_STATUS_SUCCESS) { ss << __PRETTY_FUNCTION__ << " | Not able to get nic's switch bdf. Return code: " << status; LOG_INFO(ss); return status; } - amdsmi_bdf_t gpu_switchBdf = {}; - status = amdsmi_get_root_switch(gpu_device->get_bdf(), &gpu_switchBdf); + amdsmi_bdf_t gpu_switch_bdf = {}; + status = amdsmi_get_root_switch(gpu_device->get_bdf(), &gpu_switch_bdf); if (status != AMDSMI_STATUS_SUCCESS) { ss << __PRETTY_FUNCTION__ << " | Not able to get gpu's switch bdf. Return code: " << status; @@ -4817,27 +4817,27 @@ amdsmi_status_t amdsmi_get_nic_gpu_topo_info(amdsmi_processor_handle nic_process ss << __PRETTY_FUNCTION__ << " | Not able to get nic's NUMA. Return code: " << status; LOG_INFO(ss); - return status; + return AMDSMI_STATUS_NO_DATA; } - if(gpu_numa_node != nic_numa_node) { + if (gpu_numa_node != nic_numa_node) { snprintf(topo_info, *topo_info_length - 1, "%s", "X-NUMA"); return AMDSMI_STATUS_SUCCESS; } - if(gpu_numa_node == nic_numa_node) { + if (gpu_numa_node == nic_numa_node) { snprintf(topo_info, *topo_info_length - 1, "%s", "NUMA"); - if ((gpu_switchBdf.bus_number == nic_switchBdf.bus_number) && - (gpu_switchBdf.device_number == nic_switchBdf.device_number) && - (gpu_switchBdf.domain_number == nic_switchBdf.domain_number) && - (gpu_switchBdf.function_number == nic_switchBdf.function_number)) { + if ((gpu_switch_bdf.bus_number == nic_switch_bdf.bus_number) && + (gpu_switch_bdf.device_number == nic_switch_bdf.device_number) && + (gpu_switch_bdf.domain_number == nic_switch_bdf.domain_number) && + (gpu_switch_bdf.function_number == nic_switch_bdf.function_number)) { snprintf(topo_info, *topo_info_length - 1, "%s", "PCIe"); } } return AMDSMI_STATUS_SUCCESS; } -amdsmi_status_t amdsmi_get_root_switch(amdsmi_bdf_t devicehBdf, amdsmi_bdf_t *switchBdf) { +amdsmi_status_t amdsmi_get_root_switch(amdsmi_bdf_t device_bdf, amdsmi_bdf_t *switch_bdf) { AMDSMI_CHECK_INIT(); - amdsmi_status_t status = get_lspci_root_switch(devicehBdf, switchBdf); + amdsmi_status_t status = get_lspci_root_switch(device_bdf, switch_bdf); return status; } @@ -4856,7 +4856,7 @@ amdsmi_status_t amdsmi_get_nic_topo_cpu_affinity(amdsmi_processor_handle process unsigned int *cpu_aff_length, char *cpu_aff_data) { amdsmi_status_t status = AMDSMI_STATUS_SUCCESS; AMDSMI_CHECK_INIT(); - if (cpu_aff_length == nullptr || cpu_aff_data == nullptr || cpu_aff_length == nullptr || + if (cpu_aff_length == nullptr || cpu_aff_data == nullptr || *cpu_aff_length < AMDSMI_MAX_STRING_LENGTH) { return AMDSMI_STATUS_INVAL; } @@ -4893,7 +4893,7 @@ amdsmi_status_t amdsmi_get_switch_topo_cpu_affinity(amdsmi_processor_handle proc size_t *cpu_aff_length, char *cpu_aff_data) { amdsmi_status_t status = AMDSMI_STATUS_SUCCESS; AMDSMI_CHECK_INIT(); - if (cpu_aff_length == nullptr || cpu_aff_data == nullptr || cpu_aff_length == nullptr || + if (cpu_aff_length == nullptr || cpu_aff_data == nullptr || *cpu_aff_length < AMDSMI_MAX_STRING_LENGTH) { return AMDSMI_STATUS_INVAL; } @@ -4914,7 +4914,7 @@ amdsmi_status_t amdsmi_get_switch_topo_cpu_affinity(amdsmi_processor_handle proc snprintf(cpu_aff_data, *cpu_aff_length - 1, "%s", cpu_affinity.c_str()); return status; } -#endif//BRCM_NIC +#endif // BRCM_NIC amdsmi_status_t amdsmi_get_lib_version(amdsmi_version_t *version) { if (version == nullptr) return AMDSMI_STATUS_INVAL; @@ -5317,7 +5317,7 @@ amdsmi_get_gpu_cper_entries( uint64_t *cursor) { std::string path; - if(amd::smi::FileExists(static_cast(processor_handle))) { + if (amd::smi::FileExists(static_cast(processor_handle))) { path = std::string(static_cast(processor_handle)); } else { @@ -5358,46 +5358,46 @@ amdsmi_status_t amdsmi_get_afids_from_cper( ss << __PRETTY_FUNCTION__ << "\n:" << __LINE__ << "[AFIDS] begin\n"; LOG_DEBUG(ss); - if(!cper_buffer) { + if (!cper_buffer) { ss << __PRETTY_FUNCTION__ << "\n:" << __LINE__ << "[AFIDS] cper_buffer should be a valid memory address\n"; LOG_ERROR(ss); return AMDSMI_STATUS_INVAL; } - else if(!buf_size) { + else if (!buf_size) { ss << __PRETTY_FUNCTION__ << "\n:" << __LINE__ << "[AFIDS] buf_size should be greater than 0\n"; LOG_ERROR(ss); return AMDSMI_STATUS_INVAL; } - else if(!afids) { + else if (!afids) { ss << __PRETTY_FUNCTION__ << "\n:" << __LINE__ << "[AFIDS] afids should be a valid memory address\n"; LOG_ERROR(ss); return AMDSMI_STATUS_INVAL; } - else if(!num_afids) { + else if (!num_afids) { ss << __PRETTY_FUNCTION__ << "\n:" << __LINE__ << "[AFIDS] num_afids should be a valid memory address\n"; LOG_ERROR(ss); return AMDSMI_STATUS_INVAL; } - else if(!*num_afids) { + else if (!*num_afids) { ss << __PRETTY_FUNCTION__ << "\n:" << __LINE__ << "[AFIDS] num_afids should be greater than 0\n"; LOG_ERROR(ss); return AMDSMI_STATUS_INVAL; } const amdsmi_cper_hdr_t *cper = reinterpret_cast(cper_buffer); - if(cper->record_length > buf_size) { + if (cper->record_length > buf_size) { ss << __PRETTY_FUNCTION__ << "\n:" << __LINE__ << "[AFIDS] cper buffer size " << std::dec << buf_size << " is smaller than cper record length " << std::dec << cper->record_length << "\n"; LOG_ERROR(ss); return AMDSMI_STATUS_UNEXPECTED_SIZE; } - else if(strncmp(cper->signature, "CPER", 4) != 0) { + else if (strncmp(cper->signature, "CPER", 4) != 0) { ss << __PRETTY_FUNCTION__ << "\n:" << __LINE__ << "[AFIDS] cper buffer does not have the correct signature\n"; LOG_ERROR(ss); return AMDSMI_STATUS_UNEXPECTED_DATA; } uint32_t i = 0; - for(int afid: cper_decode(cper)) { - if(i < *num_afids) { + for (int afid: cper_decode(cper)) { + if (i < *num_afids) { afids[i] = afid; } ++i; @@ -5643,8 +5643,8 @@ amdsmi_status_t amdsmi_get_nic_device_uuid(amdsmi_processor_handle processor_han amdsmi_status_t r = get_nic_device_from_handle(processor_handle, &nic_device); if (r != AMDSMI_STATUS_SUCCESS) return r; - std::string uuidStr; - status = nic_device->amd_query_nic_uuid(uuidStr); + std::string uuid_str; + status = nic_device->amd_query_nic_uuid(uuid_str); if (status != AMDSMI_STATUS_SUCCESS) { std::ostringstream ss; ss << __PRETTY_FUNCTION__ @@ -5652,7 +5652,7 @@ amdsmi_status_t amdsmi_get_nic_device_uuid(amdsmi_processor_handle processor_han LOG_INFO(ss); return status; } - snprintf(uuid, *uuid_length - 1, "%s", uuidStr.c_str()); + snprintf(uuid, *uuid_length - 1, "%s", uuid_str.c_str()); return status; } @@ -5670,8 +5670,8 @@ amdsmi_status_t amdsmi_get_switch_device_uuid(amdsmi_processor_handle processor_ amdsmi_status_t r = get_switch_device_from_handle(processor_handle, &switch_device); if (r != AMDSMI_STATUS_SUCCESS) return r; - std::string uuidStr; - status = switch_device->amd_query_switch_uuid(uuidStr); + std::string uuid_str; + status = switch_device->amd_query_switch_uuid(uuid_str); if (status != AMDSMI_STATUS_SUCCESS) { std::ostringstream ss; ss << __PRETTY_FUNCTION__ @@ -5679,10 +5679,10 @@ amdsmi_status_t amdsmi_get_switch_device_uuid(amdsmi_processor_handle processor_ LOG_INFO(ss); return status; } - snprintf(uuid, *uuid_length - 1, "%s", uuidStr.c_str()); + snprintf(uuid, *uuid_length - 1, "%s", uuid_str.c_str()); return status; } -#endif//BRCM_NIC +#endif // BRCM_NIC amdsmi_status_t amdsmi_get_pcie_info(amdsmi_processor_handle processor_handle, amdsmi_pcie_info_t *info) { AMDSMI_CHECK_INIT(); std::ostringstream ss; @@ -6477,16 +6477,16 @@ amdsmi_status_t amdsmi_get_cpu_affinity_with_scope(amdsmi_processor_handle proce return status; } - if(node_id < 0) { + if (node_id < 0) { return AMDSMI_STATUS_NOT_FOUND; } std::memset(cpu_set, 0, cpu_set_size * sizeof(uint64_t)); - switch(scope) { + switch (scope) { case AMDSMI_AFFINITY_SCOPE_NODE: { std::vector bitmask = gpu_device->get_bitmask_from_numa_node(node_id, cpu_set_size); - if(bitmask[0] == std::numeric_limits::max()){ + if (bitmask[0] == std::numeric_limits::max()) { return AMDSMI_STATUS_REFCOUNT_OVERFLOW; } else { std::memcpy(cpu_set, bitmask.data(), cpu_set_size * sizeof(uint64_t)); @@ -6498,7 +6498,7 @@ amdsmi_status_t amdsmi_get_cpu_affinity_with_scope(amdsmi_processor_handle proce { uint32_t drm_card = gpu_device->get_card_id(); std::vector bitmask = gpu_device->get_bitmask_from_local_cpulist(drm_card, cpu_set_size); - if(bitmask[0] == std::numeric_limits::max()){ + if (bitmask[0] == std::numeric_limits::max()) { return AMDSMI_STATUS_REFCOUNT_OVERFLOW; } else { std::memcpy(cpu_set, bitmask.data(), cpu_set_size * sizeof(uint64_t)); @@ -7521,7 +7521,7 @@ amdsmi_status_t amdsmi_get_hsmp_metrics_table(amdsmi_processor_handle processor_ if (processor_handle == nullptr) return AMDSMI_STATUS_INVAL; - if(sizeof(amdsmi_hsmp_metrics_table_t) != sizeof(struct hsmp_metric_table)) + if (sizeof(amdsmi_hsmp_metrics_table_t) != sizeof(struct hsmp_metric_table)) return AMDSMI_STATUS_UNEXPECTED_SIZE; amdsmi_status_t r = amdsmi_get_processor_info(processor_handle, SIZE, proc_id); diff --git a/projects/amdsmi/src/amd_smi/amd_smi_drm.cc b/projects/amdsmi/src/amd_smi/amd_smi_drm.cc index ad98f524bad..fd7fced70db 100644 --- a/projects/amdsmi/src/amd_smi/amd_smi_drm.cc +++ b/projects/amdsmi/src/amd_smi/amd_smi_drm.cc @@ -175,8 +175,8 @@ amdsmi_status_t AMDSmiDrm::get_bdf_by_index(uint32_t gpu_index, amdsmi_bdf_t *bd } amdsmi_status_t AMDSmiDrm::amdgpu_query_cpu_affinity(const std::string &device_path, std::string &cpu_affinity) { - std::string cpuAffFile = "cpulistaffinity"; - cpu_affinity = smi_brcm_get_value_string(device_path, cpuAffFile); + std::string cpu_aff_file = "cpulistaffinity"; + cpu_affinity = smi_brcm_get_value_string(device_path, cpu_aff_file); return AMDSMI_STATUS_SUCCESS; } diff --git a/projects/amdsmi/src/amd_smi/amd_smi_system.cc b/projects/amdsmi/src/amd_smi/amd_smi_system.cc index ec44a2dbacd..5858c72320c 100644 --- a/projects/amdsmi/src/amd_smi/amd_smi_system.cc +++ b/projects/amdsmi/src/amd_smi/amd_smi_system.cc @@ -32,7 +32,7 @@ #ifdef BRCM_NIC #include "amd_smi/impl/nic/amd_smi_nic_device.h" #include "amd_smi/impl/nic/amd_smi_switch_device.h" -#endif//BRCM_NIC +#endif // BRCM_NIC #include "amd_smi/impl/amd_smi_utils.h" #include "amd_smi/impl/amd_smi_common.h" #include "rocm_smi/rocm_smi.h" @@ -493,11 +493,16 @@ const auto &AMDSmiSystem::get_ai_nic_info() const { amdsmi_status_t AMDSmiSystem::populate_brcm_nic_devices() { #ifdef BRCM_NIC uint32_t device_count = 0; - amdsmi_status_t amd_smi_status = no_drm_nic.init(); - + amdsmi_status_t amd_smi_status = no_drm_nic_.init(); + if (amd_smi_status != AMDSMI_STATUS_SUCCESS) { + // No NIC driver/support present (e.g. CI without NIC hardware) - not fatal + return AMDSMI_STATUS_SUCCESS; + } + rsmi_status_t ret = rsmi_num_nic_monitor_devices(&device_count); if (ret != RSMI_STATUS_SUCCESS) { - return amd::smi::rsmi_to_amdsmi_status(ret); + // No NIC devices or driver not available - not fatal, continue with empty list + return AMDSMI_STATUS_SUCCESS; } for (uint32_t i = 0; i < device_count; i++) { @@ -539,10 +544,10 @@ amdsmi_status_t AMDSmiSystem::populate_brcm_nic_devices() { .domain_number = domain_number }; - auto device = std::make_unique(i, bdf, no_drm_nic); + auto device = std::make_unique(i, bdf, no_drm_nic_); std::string nicPath; - if ( (no_drm_nic.get_device_path_by_index(i, &nicPath)) != AMDSMI_STATUS_SUCCESS) continue; + if ( (no_drm_nic_.get_device_path_by_index(i, &nicPath)) != AMDSMI_STATUS_SUCCESS) continue; std::string driverPath = nicPath + "/driver"; std::string command = "readlink " + driverPath; std::string getData; @@ -553,17 +558,23 @@ amdsmi_status_t AMDSmiSystem::populate_brcm_nic_devices() { nic_processors_.insert(deviceget()); device.release(); } -#endif//BRCM_NIC +#endif // BRCM_NIC return AMDSMI_STATUS_SUCCESS; } amdsmi_status_t AMDSmiSystem::populate_brcm_switch_devices() { #ifdef BRCM_NIC uint32_t device_count = 0; - amdsmi_status_t amd_smi_status = no_drm_switch.init(); + amdsmi_status_t amd_smi_status = no_drm_switch_.init(); + if (amd_smi_status != AMDSMI_STATUS_SUCCESS) { + // No switch driver/support present (e.g. CI without NIC hardware) - not fatal + return AMDSMI_STATUS_SUCCESS; + } + rsmi_status_t ret = rsmi_num_switch_monitor_devices(&device_count); if (ret != RSMI_STATUS_SUCCESS) { - return amd::smi::rsmi_to_amdsmi_status(ret); + // No switch devices or driver not available - not fatal, continue with empty list + return AMDSMI_STATUS_SUCCESS; } for (uint32_t i = 0; i < device_count; i++) { @@ -605,7 +616,7 @@ amdsmi_status_t AMDSmiSystem::populate_brcm_switch_devices() { bdf.bus_number = (bdfid >> 8) & 0xff; bdf.domain_number = (bdfid >> 32) & 0xffffffff; - AMDSmiProcessor* device = new AMDSmiSWITCHDevice(i, bdf, no_drm_switch); + AMDSmiProcessor* device = new AMDSmiSWITCHDevice(i, bdf, no_drm_switch_); socket->add_processor(device); switch_processors_.insert(device); } diff --git a/projects/amdsmi/src/nic/ai-nic/amdsmi_unified/CMakeLists.txt b/projects/amdsmi/src/nic/ai-nic/amdsmi_unified/CMakeLists.txt index d078c91a7c3..d337ca4300b 100644 --- a/projects/amdsmi/src/nic/ai-nic/amdsmi_unified/CMakeLists.txt +++ b/projects/amdsmi/src/nic/ai-nic/amdsmi_unified/CMakeLists.txt @@ -33,9 +33,15 @@ set(NIC_BUILD_DIR ${CMAKE_BINARY_DIR}/build) set(NIC_INTERFACE_DIR ${CMAKE_BINARY_DIR}/interface) set(NIC_DEFAULT_CXX_FLAGS "-Wall -Wextra -Werror -Wno-missing-field-initializers -Wno-array-bounds -Wmissing-declarations -Werror=conversion -Wshift-negative-value -fPIC") -set(NIC_DEFAULT_CXX_FLAGS "${NIC_DEFAULT_CXX_FLAGS} -Wl,-z,relro,-z,noexecstack,-z,noexecheap -Wl,--strip-debug -Wl,--strip-all") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${NIC_DEFAULT_CXX_FLAGS}") +# Linker hardening flags - applied only at link time, not during compilation. +# These were previously in CMAKE_CXX_FLAGS which caused -Wunused-command-line-argument +# errors with clang-based compilers (e.g. amdclang). +set(NIC_LINKER_FLAGS "-Wl,-z,relro,-z,noexecstack,-z,noexecheap -Wl,--strip-debug -Wl,--strip-all") +set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${NIC_LINKER_FLAGS}") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${NIC_LINKER_FLAGS}") + file(GLOB CPP_SRCS "${NIC_SOURCE_DIR}/*.cpp") add_library(amdsminic STATIC ${CPP_SRCS}) set_target_properties(amdsminic PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${NIC_BUILD_DIR}) diff --git a/projects/amdsmi/src/nic/ai-nic/amdsmi_unified/inc/smi_nic.h b/projects/amdsmi/src/nic/ai-nic/amdsmi_unified/inc/smi_nic.h index b2f92b92132..a47d939d24a 100644 --- a/projects/amdsmi/src/nic/ai-nic/amdsmi_unified/inc/smi_nic.h +++ b/projects/amdsmi/src/nic/ai-nic/amdsmi_unified/inc/smi_nic.h @@ -84,6 +84,7 @@ class SmiInfiniBand { void add_port(const SmiInfiniBandPort& port); const std::vector& ports() const; uint8_t ports_num() const; + NicType type() const; private: std::string name_; diff --git a/projects/amdsmi/src/nic/ai-nic/amdsmi_unified/src/smi_nic.cpp b/projects/amdsmi/src/nic/ai-nic/amdsmi_unified/src/smi_nic.cpp index 5fbf90b69a4..cd99745c775 100644 --- a/projects/amdsmi/src/nic/ai-nic/amdsmi_unified/src/smi_nic.cpp +++ b/projects/amdsmi/src/nic/ai-nic/amdsmi_unified/src/smi_nic.cpp @@ -534,6 +534,11 @@ uint8_t SmiInfiniBand::ports_num() const return static_cast(ports_.size()); } +NicType SmiInfiniBand::type() const +{ + return type_; +} + // **** SmiNic **** SmiNic::SmiNic(const std::string& iface, const std::string& bdf, NicType type, diff --git a/projects/amdsmi/src/nic/brcm-nic/amd_smi_lspci_commands.cc b/projects/amdsmi/src/nic/brcm-nic/amd_smi_lspci_commands.cc index 30390253807..fc224605a0d 100644 --- a/projects/amdsmi/src/nic/brcm-nic/amd_smi_lspci_commands.cc +++ b/projects/amdsmi/src/nic/brcm-nic/amd_smi_lspci_commands.cc @@ -33,14 +33,14 @@ #include "amd_smi/impl/nic/amd_smi_lspci_commands.h" #include "amd_smi/impl/amd_smi_utils.h" -amdsmi_status_t get_lspci_device_data(std::string bdfStr, std::string search_key, std::string& version) { +amdsmi_status_t get_lspci_device_data(std::string bdf_str, std::string search_key, std::string& version) { std::string lspci_data; - std::string command = "lspci -s " + bdfStr + " -vv | grep -i '" + search_key + "'"; + std::string command = "lspci -s " + bdf_str + " -vv | grep -i '" + search_key + "'"; - if (smi_brcm_execute_cmd_get_data(command, &lspci_data) != AMDSMI_STATUS_SUCCESS){ + if (smi_brcm_execute_cmd_get_data(command, &lspci_data) != AMDSMI_STATUS_SUCCESS) { std::ostringstream ss; ss << __PRETTY_FUNCTION__ << " | " - << "Failed to execute command: lspci -s " << bdfStr << " -vv | grep -i " << search_key << "."; + << "Failed to execute command: lspci -s " << bdf_str << " -vv | grep -i " << search_key << "."; LOG_ERROR(ss); return AMDSMI_STATUS_NOT_SUPPORTED; @@ -59,7 +59,7 @@ amdsmi_status_t get_lspci_device_data(std::string bdfStr, std::string search_key return AMDSMI_STATUS_SUCCESS; } -amdsmi_status_t get_lspci_root_switch(amdsmi_bdf_t devicehBdf, amdsmi_bdf_t *switchBdf) { +amdsmi_status_t get_lspci_root_switch(amdsmi_bdf_t device_bdf, amdsmi_bdf_t *switchBdf) { amdsmi_status_t status = AMDSMI_STATUS_SUCCESS; std::string lspci_data; @@ -86,17 +86,17 @@ amdsmi_status_t get_lspci_root_switch(amdsmi_bdf_t devicehBdf, amdsmi_bdf_t *swi // Loop through and get the switch list while (std::getline(lines, line)) { - if(line.find("LSI PCIe Switch management endpoint") != std::string::npos){ + if (line.find("LSI PCIe Switch management endpoint") != std::string::npos) { //get Bus bus_pos = line.rfind(']----'); - if (bus_pos == std::string::npos){ + if (bus_pos == std::string::npos) { // Check if the Bus position is not found, then continue to the next line continue; } //Get device dev_pos = line.rfind('.'); - if (dev_pos == std::string::npos){ + if (dev_pos == std::string::npos) { // Check if the device position is not found, then continue to the next line continue; } @@ -176,7 +176,7 @@ amdsmi_status_t get_lspci_root_switch(amdsmi_bdf_t devicehBdf, amdsmi_bdf_t *swi } - if (devicehBdf.bus_number >= switch_bus_start && devicehBdf.bus_number <= switch_bus_end){ + if (device_bdf.bus_number >= switch_bus_start && device_bdf.bus_number <= switch_bus_end){ switchBdf->bus_number = d.bus_number; switchBdf->device_number = d.device_number; switchBdf->function_number = d.function_number; diff --git a/projects/amdsmi/src/nic/brcm-nic/amd_smi_nic_device.cc b/projects/amdsmi/src/nic/brcm-nic/amd_smi_nic_device.cc index b27ec572612..88786e6515e 100644 --- a/projects/amdsmi/src/nic/brcm-nic/amd_smi_nic_device.cc +++ b/projects/amdsmi/src/nic/brcm-nic/amd_smi_nic_device.cc @@ -79,8 +79,8 @@ amdsmi_status_t AMDSmiNICDevice::amd_query_nic_info(amdsmi_brcm_nic_info_t& info amdsmi_status_t AMDSmiNICDevice::amd_query_nic_temp_info(amdsmi_brcm_nic_temperature_metric_t& info) const { amdsmi_status_t ret; - std::string hwmonPath; - ret = nodrm_.get_hwmon_path_by_index(nic_id_, &hwmonPath); + std::string hwmon_path; + ret = nodrm_.get_hwmon_path_by_index(nic_id_, &hwmon_path); if (ret != AMDSMI_STATUS_SUCCESS) { std::ostringstream ss; ss << __PRETTY_FUNCTION__ << " | " @@ -89,13 +89,13 @@ amdsmi_status_t AMDSmiNICDevice::amd_query_nic_temp_info(amdsmi_brcm_nic_tempera return AMDSMI_STATUS_NOT_SUPPORTED; } - return nodrm_.amd_query_nic_temp(hwmonPath, info); + return nodrm_.amd_query_nic_temp(hwmon_path, info); } amdsmi_status_t AMDSmiNICDevice::amd_query_nic_power_info(amdsmi_brcm_nic_hwmon_power_t& info) const { amdsmi_status_t ret; - std::string hwmonPath; - ret = nodrm_.get_hwmon_path_by_index(nic_id_, &hwmonPath); + std::string hwmon_path; + ret = nodrm_.get_hwmon_path_by_index(nic_id_, &hwmon_path); if (ret != AMDSMI_STATUS_SUCCESS) { std::ostringstream ss; ss << __PRETTY_FUNCTION__ << " | " @@ -104,13 +104,13 @@ amdsmi_status_t AMDSmiNICDevice::amd_query_nic_power_info(amdsmi_brcm_nic_hwmon_ return AMDSMI_STATUS_NOT_SUPPORTED; } - return nodrm_.amd_query_nic_power(hwmonPath, info); + return nodrm_.amd_query_nic_power(hwmon_path, info); } amdsmi_status_t AMDSmiNICDevice::amd_query_nic_device_info(amdsmi_brcm_nic_hwmon_device_t& info) const { amdsmi_status_t ret; - std::string hwmonPath; - ret = nodrm_.get_hwmon_path_by_index(nic_id_, &hwmonPath); + std::string hwmon_path; + ret = nodrm_.get_hwmon_path_by_index(nic_id_, &hwmon_path); if (ret != AMDSMI_STATUS_SUCCESS) { std::ostringstream ss; ss << __PRETTY_FUNCTION__ << " | " @@ -118,13 +118,13 @@ amdsmi_status_t AMDSmiNICDevice::amd_query_nic_device_info(amdsmi_brcm_nic_hwmon LOG_DEBUG(ss); return AMDSMI_STATUS_NOT_SUPPORTED; } - return nodrm_.amd_query_nic_device(hwmonPath, info); + return nodrm_.amd_query_nic_device(hwmon_path, info); } amdsmi_status_t AMDSmiNICDevice::amd_query_nic_uuid(std::string& version) const { amdsmi_status_t ret; - std::string devicePath; - ret = nodrm_.get_device_path_by_index(nic_id_, &devicePath); + std::string device_path; + ret = nodrm_.get_device_path_by_index(nic_id_, &device_path); if (ret != AMDSMI_STATUS_SUCCESS) { std::ostringstream ss; ss << __PRETTY_FUNCTION__ << " | " @@ -133,13 +133,13 @@ amdsmi_status_t AMDSmiNICDevice::amd_query_nic_uuid(std::string& version) const return AMDSMI_STATUS_NOT_SUPPORTED; } - return nodrm_.amd_query_nic_uuid(devicePath, version); + return nodrm_.amd_query_nic_uuid(device_path, version); } amdsmi_status_t AMDSmiNICDevice::amd_query_nic_numa_affinity(int32_t *numa_node) const { amdsmi_status_t ret; - std::string devicePath; - ret = nodrm_.get_device_path_by_index(nic_id_, &devicePath); + std::string device_path; + ret = nodrm_.get_device_path_by_index(nic_id_, &device_path); if (ret != AMDSMI_STATUS_SUCCESS) { std::ostringstream ss; ss << __PRETTY_FUNCTION__ << " | " @@ -148,7 +148,7 @@ amdsmi_status_t AMDSmiNICDevice::amd_query_nic_numa_affinity(int32_t *numa_node) return AMDSMI_STATUS_NOT_SUPPORTED; } - return nodrm_.amd_query_nic_numa_affinity(devicePath, numa_node); + return nodrm_.amd_query_nic_numa_affinity(device_path, numa_node); } amdsmi_status_t AMDSmiNICDevice::amd_query_nic_cpu_affinity(std::string& cpu_affinity) const { diff --git a/projects/amdsmi/src/nic/brcm-nic/amd_smi_no_drm_nic.cc b/projects/amdsmi/src/nic/brcm-nic/amd_smi_no_drm_nic.cc index b7f7360b95c..2e1ce1a497b 100644 --- a/projects/amdsmi/src/nic/brcm-nic/amd_smi_no_drm_nic.cc +++ b/projects/amdsmi/src/nic/brcm-nic/amd_smi_no_drm_nic.cc @@ -51,6 +51,7 @@ amdsmi_status_t AMDSmiNoDrmNIC::init() { bool has_valid_hw_mon = false; for (uint32_t i=0; i < devices.size(); i++) { + has_valid_hw_mon = false; auto rocm_smi_device = devices[i]; uint64_t bdfid = rocm_smi_device->bdfid(); amdsmi_bdf_t bdf = {}; @@ -112,9 +113,9 @@ amdsmi_status_t AMDSmiNoDrmNIC::amd_query_nic_info(uint32_t nic_index, amdsmi_br amdsmi_status_t ret = AMDSMI_STATUS_SUCCESS; get_bdf_by_index(nic_index, &info.nic_bdf); - std::string strInterfaceName; - get_interface_name_by_index(nic_index, &strInterfaceName); - snprintf(info.nic_device_name, sizeof(info.nic_device_name)-1, "%s", strInterfaceName.c_str()); + std::string str_interface_name; + get_interface_name_by_index(nic_index, &str_interface_name); + snprintf(info.nic_device_name, sizeof(info.nic_device_name)-1, "%s", str_interface_name.c_str()); char bdf_str[20]; snprintf(bdf_str, sizeof(bdf_str)-1, "%04lx:%02x:%02x.%d", info.nic_bdf.domain_number, info.nic_bdf.bus_number, info.nic_bdf.device_number, @@ -129,31 +130,37 @@ amdsmi_status_t AMDSmiNoDrmNIC::amd_query_nic_info(uint32_t nic_index, amdsmi_br snprintf(info.nic_firmware_version, sizeof(info.nic_firmware_version)-1, "%s", fw_version.c_str()); } catch (const std::invalid_argument &e) { - std::cerr << "AMDSmiNoDrmNIC::amd_query_nic_info - Error: Invalid argument exception caught in std::stoi.\n" - << "Exception message: " << e.what() << std::endl; + std::ostringstream ss; + ss << __PRETTY_FUNCTION__ << " | " << "Invalid argument exception: " << e.what(); + LOG_ERROR(ss); + return AMDSMI_STATUS_API_FAILED; } catch (const std::out_of_range &e) { - std::cerr << "AMDSmiNoDrmNIC::amd_query_nic_info - Error: Out of range exception caught in std::stoi.\n" - << "Exception message: " << e.what() << std::endl; + std::ostringstream ss; + ss << __PRETTY_FUNCTION__ << " | " << "Out of range exception: " << e.what(); + LOG_ERROR(ss); + return AMDSMI_STATUS_API_FAILED; } catch (const std::exception &e) { - std::cerr << "AMDSmiNoDrmNIC::amd_query_nic_info - An error occurred: " << e.what() - << std::endl; + std::ostringstream ss; + ss << __PRETTY_FUNCTION__ << " | " << "An error occurred: " << e.what(); + LOG_ERROR(ss); + return AMDSMI_STATUS_API_FAILED; } - std::string devicePath; - get_device_path_by_index(nic_index, &devicePath); - std::string netPath = devicePath + "/net"; - auto net_node_dir = opendir(netPath.c_str()); + std::string device_path; + get_device_path_by_index(nic_index, &device_path); + std::string net_path = device_path + "/net"; + auto net_node_dir = opendir(net_path.c_str()); if (net_node_dir != nullptr) { auto dentry = readdir(net_node_dir); - std::string macPath; + std::string mac_path; while ((dentry = readdir(net_node_dir)) != nullptr) { if ((strcmp(dentry->d_name, ".") == 0) || (strcmp(dentry->d_name, "..") == 0)) { continue; } - macPath = netPath + "/" + dentry->d_name; - std::string macAddress = "address"; - std::string strUUID = smi_brcm_get_value_string(macPath, macAddress); - snprintf(info.nic_uuid, sizeof(info.nic_uuid)-1, "%s", strUUID.c_str()); + mac_path = net_path + "/" + dentry->d_name; + std::string mac_address = "address"; + std::string str_uuid = smi_brcm_get_value_string(mac_path, mac_address); + snprintf(info.nic_uuid, sizeof(info.nic_uuid)-1, "%s", str_uuid.c_str()); } closedir(net_node_dir); } @@ -161,7 +168,7 @@ amdsmi_status_t AMDSmiNoDrmNIC::amd_query_nic_info(uint32_t nic_index, amdsmi_br return AMDSMI_STATUS_SUCCESS; } -amdsmi_status_t AMDSmiNoDrmNIC::amd_query_nic_temp(std::string hwmonPath, +amdsmi_status_t AMDSmiNoDrmNIC::amd_query_nic_temp(std::string hwmon_path, amdsmi_brcm_nic_temperature_metric_t &info) { // Get nic temperature info std::string crit_alarm = "temp1_crit_alarm"; @@ -176,28 +183,30 @@ amdsmi_status_t AMDSmiNoDrmNIC::amd_query_nic_temp(std::string hwmonPath, std::string nic_shutdown = "temp1_shutdown"; try { - info.nic_temp_crit_alarm = smi_brcm_get_value_u32(hwmonPath, crit_alarm); - info.nic_temp_emergency_alarm = smi_brcm_get_value_u32(hwmonPath, emergency_alarm); - info.nic_temp_shutdown_alarm = smi_brcm_get_value_u32(hwmonPath, shutdown_alarm); - info.nic_temp_max_alarm = smi_brcm_get_value_u32(hwmonPath, max_alarm); + info.nic_temp_crit_alarm = smi_brcm_get_value_u32(hwmon_path, crit_alarm); + info.nic_temp_emergency_alarm = smi_brcm_get_value_u32(hwmon_path, emergency_alarm); + info.nic_temp_shutdown_alarm = smi_brcm_get_value_u32(hwmon_path, shutdown_alarm); + info.nic_temp_max_alarm = smi_brcm_get_value_u32(hwmon_path, max_alarm); - info.nic_temp_crit = smi_brcm_get_value_u32(hwmonPath, nic_crit); - info.nic_temp_emergency = smi_brcm_get_value_u32(hwmonPath, nic_emergency); - info.nic_temp_input = smi_brcm_get_value_u32(hwmonPath, nic_input); - info.nic_temp_max = smi_brcm_get_value_u32(hwmonPath, nic_max); - info.nic_temp_shutdown = smi_brcm_get_value_u32(hwmonPath, nic_shutdown); + info.nic_temp_crit = smi_brcm_get_value_u32(hwmon_path, nic_crit); + info.nic_temp_emergency = smi_brcm_get_value_u32(hwmon_path, nic_emergency); + info.nic_temp_input = smi_brcm_get_value_u32(hwmon_path, nic_input); + info.nic_temp_max = smi_brcm_get_value_u32(hwmon_path, nic_max); + info.nic_temp_shutdown = smi_brcm_get_value_u32(hwmon_path, nic_shutdown); } catch (const std::exception& e) { - std::cerr << "AMDSmiNoDrmNIC::amd_query_nic_temp - An error occurred: " << e.what() - << std::endl; + std::ostringstream ss; + ss << __PRETTY_FUNCTION__ << " | " << "An error occurred: " << e.what(); + LOG_ERROR(ss); + return AMDSMI_STATUS_API_FAILED; } return AMDSMI_STATUS_SUCCESS; } -amdsmi_status_t AMDSmiNoDrmNIC::amd_query_nic_power(std::string hwmonPath, amdsmi_brcm_nic_hwmon_power_t &info) { +amdsmi_status_t AMDSmiNoDrmNIC::amd_query_nic_power(std::string hwmon_path, amdsmi_brcm_nic_hwmon_power_t &info) { // Get power metrics for a NIC try { - hwmonPath = hwmonPath+"/power"; + hwmon_path = hwmon_path+"/power"; std::string async = "async"; std::string control = "control"; std::string runtime_active_kids = "runtime_active_kids"; @@ -207,29 +216,38 @@ amdsmi_status_t AMDSmiNoDrmNIC::amd_query_nic_power(std::string hwmonPath, amdsm std::string runtime_suspended_time = "runtime_suspended_time"; std::string runtime_usage = "runtime_usage"; - snprintf(info.nic_power_async, sizeof(info.nic_power_async)-1, "%s", smi_brcm_get_value_string(hwmonPath, async).c_str()); - snprintf(info.nic_power_control, sizeof(info.nic_power_control)-1, "%s", smi_brcm_get_value_string(hwmonPath, control).c_str()); - info.nic_power_runtime_active_time = smi_brcm_get_value_u32(hwmonPath, runtime_active_time); - snprintf(info.nic_power_runtime_status, sizeof(info.nic_power_runtime_status)-1, "%s", smi_brcm_get_value_string(hwmonPath, runtime_status).c_str()); - info.nic_power_runtime_usage = smi_brcm_get_value_u32(hwmonPath, runtime_usage); - info.nic_power_runtime_active_kids = smi_brcm_get_value_u32(hwmonPath, runtime_active_kids); - snprintf(info.nic_power_runtime_enabled, sizeof(info.nic_power_runtime_enabled)-1, "%s", smi_brcm_get_value_string(hwmonPath, runtime_enabled).c_str()); - info.nic_power_runtime_suspended_time = smi_brcm_get_value_u32(hwmonPath, runtime_suspended_time); + snprintf(info.nic_power_async, sizeof(info.nic_power_async)-1, "%s", smi_brcm_get_value_string(hwmon_path, async).c_str()); + snprintf(info.nic_power_control, sizeof(info.nic_power_control)-1, "%s", smi_brcm_get_value_string(hwmon_path, control).c_str()); + info.nic_power_runtime_active_time = smi_brcm_get_value_u32(hwmon_path, runtime_active_time); + snprintf(info.nic_power_runtime_status, sizeof(info.nic_power_runtime_status)-1, "%s", smi_brcm_get_value_string(hwmon_path, runtime_status).c_str()); + info.nic_power_runtime_usage = smi_brcm_get_value_u32(hwmon_path, runtime_usage); + info.nic_power_runtime_active_kids = smi_brcm_get_value_u32(hwmon_path, runtime_active_kids); + snprintf(info.nic_power_runtime_enabled, sizeof(info.nic_power_runtime_enabled)-1, "%s", smi_brcm_get_value_string(hwmon_path, runtime_enabled).c_str()); + info.nic_power_runtime_suspended_time = smi_brcm_get_value_u32(hwmon_path, runtime_suspended_time); } catch (const std::invalid_argument& e) { - printf("AMDSmiNoDrmNIC::amd_query_nic_power - Invalid argument: %s\n", e.what()); + std::ostringstream ss; + ss << __PRETTY_FUNCTION__ << " | " << "Invalid argument: " << e.what(); + LOG_ERROR(ss); + return AMDSMI_STATUS_API_FAILED; } catch (const std::out_of_range& e) { - printf("Out of range error: %s\n", e.what()); + std::ostringstream ss; + ss << __PRETTY_FUNCTION__ << " | " << "Out of range error: " << e.what(); + LOG_ERROR(ss); + return AMDSMI_STATUS_API_FAILED; } catch (...) { - printf("AMDSmiNoDrmNIC::amd_query_nic_power - Error: Exception caught during NIC power query.\n"); + std::ostringstream ss; + ss << __PRETTY_FUNCTION__ << " | " << "Exception caught during NIC power query."; + LOG_ERROR(ss); + return AMDSMI_STATUS_API_FAILED; } return AMDSMI_STATUS_SUCCESS; } -amdsmi_status_t AMDSmiNoDrmNIC::amd_query_nic_device(std::string hwmonPath, amdsmi_brcm_nic_hwmon_device_t &info) { +amdsmi_status_t AMDSmiNoDrmNIC::amd_query_nic_device(std::string hwmon_path, amdsmi_brcm_nic_hwmon_device_t &info) { try { - hwmonPath = hwmonPath+"/device"; + hwmon_path = hwmon_path+"/device"; std::string aer_dev_correctable = "aer_dev_correctable"; std::string aer_dev_fatal = "aer_dev_fatal"; std::string aer_dev_nonfatal = "aer_dev_nonfatal"; @@ -271,74 +289,81 @@ amdsmi_status_t AMDSmiNoDrmNIC::amd_query_nic_device(std::string hwmonPath, amds std::string vendor = "vendor"; std::string vpd = "vpd"; - snprintf(info.nic_device_aer_dev_correctable, sizeof(info.nic_device_aer_dev_correctable)-1, "%s", smi_brcm_get_value_string(hwmonPath, aer_dev_correctable).c_str()); - snprintf(info.nic_device_aer_dev_fatal, sizeof(info.nic_device_aer_dev_fatal)-1, "%s", smi_brcm_get_value_string(hwmonPath, aer_dev_fatal).c_str()); - snprintf(info.nic_device_aer_dev_nonfatal, sizeof(info.nic_device_aer_dev_nonfatal)-1, "%s", smi_brcm_get_value_string(hwmonPath, aer_dev_nonfatal).c_str()); - info.nic_device_ari_enabled = smi_brcm_get_value_u32(hwmonPath, ari_enabled); - info.nic_device_broken_parity_status = smi_brcm_get_value_u32(hwmonPath, broken_parity_status); - snprintf(info.nic_device_class, sizeof(info.nic_device_class)-1, "%s", smi_brcm_get_value_string(hwmonPath, device_class).c_str()); - snprintf(info.nic_device_config, sizeof(info.nic_device_config)-1, "%s", smi_brcm_get_value_string(hwmonPath, config).c_str()); - info.nic_device_consistent_dma_mask_bits = smi_brcm_get_value_u32(hwmonPath, consistent_dma_mask_bit); - snprintf(info.nic_device_current_link_speed, sizeof(info.nic_device_current_link_speed)-1, "%s", smi_brcm_get_value_string(hwmonPath, current_link_speed).c_str()); - info.nic_device_current_link_width = smi_brcm_get_value_u32(hwmonPath, current_link_width); - info.nic_device_d3cold_allowed = smi_brcm_get_value_u32(hwmonPath, d3cold_allowed); - snprintf(info.nic_device_device, sizeof(info.nic_device_device)-1, "%s", smi_brcm_get_value_string(hwmonPath, device).c_str()); - info.nic_device_dma_mask_bits = smi_brcm_get_value_u32(hwmonPath, dma_mask_bits); - snprintf(info.nic_device_driver_override, sizeof(info.nic_device_driver_override)-1, "%s", smi_brcm_get_value_string(hwmonPath, driver_override).c_str()); - info.nic_device_enable = smi_brcm_get_value_u32(hwmonPath, enable); - info.nic_device_irq = smi_brcm_get_value_u32(hwmonPath, irq); - snprintf(info.nic_device_local_cpulist, sizeof(info.nic_device_local_cpulist)-1, "%s", smi_brcm_get_value_string(hwmonPath, local_cpulist).c_str()); - snprintf(info.nic_device_local_cpus, sizeof(info.nic_device_local_cpus)-1, "%s", smi_brcm_get_value_string(hwmonPath, local_cpus).c_str()); - snprintf(info.nic_device_max_link_speed, sizeof(info.nic_device_max_link_speed)-1, "%s", smi_brcm_get_value_string(hwmonPath, max_link_speed).c_str()); - info.nic_device_max_link_width = smi_brcm_get_value_u32(hwmonPath, max_link_width); - snprintf(info.nic_device_modalias, sizeof(info.nic_device_modalias)-1, "%s", smi_brcm_get_value_string(hwmonPath, modalias).c_str()); - info.nic_device_msi_bus = smi_brcm_get_value_u32(hwmonPath, msi_bus); - info.nic_device_numa_node = smi_brcm_get_value_u32(hwmonPath, numa_node); - snprintf(info.nic_device_pools, sizeof(info.nic_device_pools)-1, "%s", smi_brcm_get_value_string(hwmonPath, pools).c_str()); - snprintf(info.nic_device_power_state, sizeof(info.nic_device_power_state)-1, "%s", smi_brcm_get_value_string(hwmonPath, power_state).c_str()); - snprintf(info.nic_device_reset_method, sizeof(info.nic_device_reset_method)-1, "%s", smi_brcm_get_value_string(hwmonPath, reset_method).c_str()); - snprintf(info.nic_device_resource, sizeof(info.nic_device_resource)-1, "%s", smi_brcm_get_value_string(hwmonPath, resource).c_str()); - snprintf(info.nic_device_revision, sizeof(info.nic_device_revision)-1, "%s", smi_brcm_get_value_string(hwmonPath, revision).c_str()); - info.nic_device_sriov_drivers_autoprobe = smi_brcm_get_value_u32(hwmonPath, sriov_drivers_autoprobe); - info.nic_device_sriov_numvfs = smi_brcm_get_value_u32(hwmonPath, sriov_numvfs); - info.nic_device_sriov_offset = smi_brcm_get_value_u32(hwmonPath, sriov_offset); - info.nic_device_sriov_stride = smi_brcm_get_value_u32(hwmonPath, sriov_stride); - info.nic_device_sriov_totalvfs = smi_brcm_get_value_u32(hwmonPath, sriov_totalvfs); - info.nic_device_sriov_vf_device = smi_brcm_get_value_u32(hwmonPath, sriov_vf_device); - info.nic_device_sriov_vf_total_msix = smi_brcm_get_value_u32(hwmonPath, sriov_vf_total_msix); - snprintf(info.nic_device_subsystem_device, sizeof(info.nic_device_subsystem_device-1), "%s", smi_brcm_get_value_string(hwmonPath, subsystem_device).c_str()); - snprintf(info.nic_device_subsystem_vendor, sizeof(info.nic_device_subsystem_vendor-1), "%s", smi_brcm_get_value_string(hwmonPath, subsystem_vendor).c_str()); - snprintf(info.nic_device_uevent, sizeof(info.nic_device_uevent-1), "%s", smi_brcm_get_value_string(hwmonPath, uevent).c_str()); - snprintf(info.nic_device_vendor, sizeof(info.nic_device_vendor-1), "%s", smi_brcm_get_value_string(hwmonPath, vendor).c_str()); - snprintf(info.nic_device_vpd, sizeof(info.nic_device_vpd-1), "%s", smi_brcm_get_value_string(hwmonPath, vpd).c_str()); + snprintf(info.nic_device_aer_dev_correctable, sizeof(info.nic_device_aer_dev_correctable)-1, "%s", smi_brcm_get_value_string(hwmon_path, aer_dev_correctable).c_str()); + snprintf(info.nic_device_aer_dev_fatal, sizeof(info.nic_device_aer_dev_fatal)-1, "%s", smi_brcm_get_value_string(hwmon_path, aer_dev_fatal).c_str()); + snprintf(info.nic_device_aer_dev_nonfatal, sizeof(info.nic_device_aer_dev_nonfatal)-1, "%s", smi_brcm_get_value_string(hwmon_path, aer_dev_nonfatal).c_str()); + info.nic_device_ari_enabled = smi_brcm_get_value_u32(hwmon_path, ari_enabled); + info.nic_device_broken_parity_status = smi_brcm_get_value_u32(hwmon_path, broken_parity_status); + snprintf(info.nic_device_class, sizeof(info.nic_device_class)-1, "%s", smi_brcm_get_value_string(hwmon_path, device_class).c_str()); + snprintf(info.nic_device_config, sizeof(info.nic_device_config)-1, "%s", smi_brcm_get_value_string(hwmon_path, config).c_str()); + info.nic_device_consistent_dma_mask_bits = smi_brcm_get_value_u32(hwmon_path, consistent_dma_mask_bit); + snprintf(info.nic_device_current_link_speed, sizeof(info.nic_device_current_link_speed)-1, "%s", smi_brcm_get_value_string(hwmon_path, current_link_speed).c_str()); + info.nic_device_current_link_width = smi_brcm_get_value_u32(hwmon_path, current_link_width); + info.nic_device_d3cold_allowed = smi_brcm_get_value_u32(hwmon_path, d3cold_allowed); + snprintf(info.nic_device_device, sizeof(info.nic_device_device)-1, "%s", smi_brcm_get_value_string(hwmon_path, device).c_str()); + info.nic_device_dma_mask_bits = smi_brcm_get_value_u32(hwmon_path, dma_mask_bits); + snprintf(info.nic_device_driver_override, sizeof(info.nic_device_driver_override)-1, "%s", smi_brcm_get_value_string(hwmon_path, driver_override).c_str()); + info.nic_device_enable = smi_brcm_get_value_u32(hwmon_path, enable); + info.nic_device_irq = smi_brcm_get_value_u32(hwmon_path, irq); + snprintf(info.nic_device_local_cpulist, sizeof(info.nic_device_local_cpulist)-1, "%s", smi_brcm_get_value_string(hwmon_path, local_cpulist).c_str()); + snprintf(info.nic_device_local_cpus, sizeof(info.nic_device_local_cpus)-1, "%s", smi_brcm_get_value_string(hwmon_path, local_cpus).c_str()); + snprintf(info.nic_device_max_link_speed, sizeof(info.nic_device_max_link_speed)-1, "%s", smi_brcm_get_value_string(hwmon_path, max_link_speed).c_str()); + info.nic_device_max_link_width = smi_brcm_get_value_u32(hwmon_path, max_link_width); + snprintf(info.nic_device_modalias, sizeof(info.nic_device_modalias)-1, "%s", smi_brcm_get_value_string(hwmon_path, modalias).c_str()); + info.nic_device_msi_bus = smi_brcm_get_value_u32(hwmon_path, msi_bus); + info.nic_device_numa_node = smi_brcm_get_value_u32(hwmon_path, numa_node); + snprintf(info.nic_device_pools, sizeof(info.nic_device_pools)-1, "%s", smi_brcm_get_value_string(hwmon_path, pools).c_str()); + snprintf(info.nic_device_power_state, sizeof(info.nic_device_power_state)-1, "%s", smi_brcm_get_value_string(hwmon_path, power_state).c_str()); + snprintf(info.nic_device_reset_method, sizeof(info.nic_device_reset_method)-1, "%s", smi_brcm_get_value_string(hwmon_path, reset_method).c_str()); + snprintf(info.nic_device_resource, sizeof(info.nic_device_resource)-1, "%s", smi_brcm_get_value_string(hwmon_path, resource).c_str()); + snprintf(info.nic_device_revision, sizeof(info.nic_device_revision)-1, "%s", smi_brcm_get_value_string(hwmon_path, revision).c_str()); + info.nic_device_sriov_drivers_autoprobe = smi_brcm_get_value_u32(hwmon_path, sriov_drivers_autoprobe); + info.nic_device_sriov_numvfs = smi_brcm_get_value_u32(hwmon_path, sriov_numvfs); + info.nic_device_sriov_offset = smi_brcm_get_value_u32(hwmon_path, sriov_offset); + info.nic_device_sriov_stride = smi_brcm_get_value_u32(hwmon_path, sriov_stride); + info.nic_device_sriov_totalvfs = smi_brcm_get_value_u32(hwmon_path, sriov_totalvfs); + info.nic_device_sriov_vf_device = smi_brcm_get_value_u32(hwmon_path, sriov_vf_device); + info.nic_device_sriov_vf_total_msix = smi_brcm_get_value_u32(hwmon_path, sriov_vf_total_msix); + snprintf(info.nic_device_subsystem_device, sizeof(info.nic_device_subsystem_device)-1, "%s", smi_brcm_get_value_string(hwmon_path, subsystem_device).c_str()); + snprintf(info.nic_device_subsystem_vendor, sizeof(info.nic_device_subsystem_vendor)-1, "%s", smi_brcm_get_value_string(hwmon_path, subsystem_vendor).c_str()); + snprintf(info.nic_device_uevent, sizeof(info.nic_device_uevent)-1, "%s", smi_brcm_get_value_string(hwmon_path, uevent).c_str()); + snprintf(info.nic_device_vendor, sizeof(info.nic_device_vendor)-1, "%s", smi_brcm_get_value_string(hwmon_path, vendor).c_str()); + snprintf(info.nic_device_vpd, sizeof(info.nic_device_vpd)-1, "%s", smi_brcm_get_value_string(hwmon_path, vpd).c_str()); } catch (const std::invalid_argument& e) { - std::cerr << "AMDSmiNoDrmNIC::amd_query_nic_device - Error: Invalid argument exception caught in std::stoi.\n" - << "Exception message: " << e.what() << std::endl; + std::ostringstream ss; + ss << __PRETTY_FUNCTION__ << " | " << "Invalid argument exception: " << e.what(); + LOG_ERROR(ss); + return AMDSMI_STATUS_API_FAILED; } catch (const std::out_of_range& e) { - std::cerr << "AMDSmiNoDrmNIC::amd_query_nic_device - Error: Out of range exception caught in std::stoi.\n" - << "Exception message: " << e.what() << std::endl; + std::ostringstream ss; + ss << __PRETTY_FUNCTION__ << " | " << "Out of range exception: " << e.what(); + LOG_ERROR(ss); + return AMDSMI_STATUS_API_FAILED; } catch (const std::exception& e) { - std::cerr << "AMDSmiNoDrmNIC::amd_query_nic_device - An error occurred: " << e.what() << std::endl; + std::ostringstream ss; + ss << __PRETTY_FUNCTION__ << " | " << "An error occurred: " << e.what(); + LOG_ERROR(ss); + return AMDSMI_STATUS_API_FAILED; } return AMDSMI_STATUS_SUCCESS; } -amdsmi_status_t AMDSmiNoDrmNIC::amd_query_nic_fw_info(std::string bdfStr, +amdsmi_status_t AMDSmiNoDrmNIC::amd_query_nic_fw_info(std::string bdf_str, amdsmi_brcm_nic_firmware_t &info) { // Retrieve firmware version information from the NIC. // // Args: - // bdfStr (std::string): Bus-Device-Function value of the NIC. + // bdf_str (std::string): Bus-Device-Function value of the NIC. // info (amdsmi_brcm_nic_firmware_t): Structure to hold the firmware // version information. std::string fw_pkg_version, fw_efi_version, fw_version, fw_ncsi_version, fw_roce_version; try { - get_lspci_device_data(bdfStr, "V0] Vendor specific: ", fw_pkg_version); - get_lspci_device_data(bdfStr, "V1] Vendor specific: ", fw_efi_version); - get_lspci_device_data(bdfStr, "V3] Vendor specific: ", fw_version); - get_lspci_device_data(bdfStr, "V8] Vendor specific: ", fw_ncsi_version); - get_lspci_device_data(bdfStr, "VA] Vendor specific: ", fw_roce_version); + get_lspci_device_data(bdf_str, "V0] Vendor specific: ", fw_pkg_version); + get_lspci_device_data(bdf_str, "V1] Vendor specific: ", fw_efi_version); + get_lspci_device_data(bdf_str, "V3] Vendor specific: ", fw_version); + get_lspci_device_data(bdf_str, "V8] Vendor specific: ", fw_ncsi_version); + get_lspci_device_data(bdf_str, "VA] Vendor specific: ", fw_roce_version); snprintf(info.nic_fw_pkg_version, sizeof(info.nic_fw_pkg_version)-1, "%s", fw_pkg_version.c_str()); snprintf(info.nic_fw_efi_version, sizeof(info.nic_fw_efi_version)-1, "%s", fw_efi_version.c_str()); @@ -347,14 +372,20 @@ amdsmi_status_t AMDSmiNoDrmNIC::amd_query_nic_fw_info(std::string bdfStr, snprintf(info.nic_fw_roce_version, sizeof(info.nic_fw_roce_version)-1, "%s", fw_roce_version.c_str()); } catch (const std::invalid_argument &e) { - std::cerr << "AMDSmiNoDrmNIC::amd_query_nic_fw_info - Error: Invalid argument exception caught in std::stoi.\n" - << "Exception message: " << e.what() << std::endl; + std::ostringstream ss; + ss << __PRETTY_FUNCTION__ << " | " << "Invalid argument exception: " << e.what(); + LOG_ERROR(ss); + return AMDSMI_STATUS_API_FAILED; } catch (const std::out_of_range &e) { - std::cerr << "AMDSmiNoDrmNIC::amd_query_nic_fw_info - Error: Out of range exception caught in std::stoi.\n" - << "Exception message: " << e.what() << std::endl; + std::ostringstream ss; + ss << __PRETTY_FUNCTION__ << " | " << "Out of range exception: " << e.what(); + LOG_ERROR(ss); + return AMDSMI_STATUS_API_FAILED; } catch (const std::exception &e) { - std::cerr << "AMDSmiNoDrmNIC::amd_query_nic_fw_info - An error occurred: " << e.what() - << std::endl; + std::ostringstream ss; + ss << __PRETTY_FUNCTION__ << " | " << "An error occurred: " << e.what(); + LOG_ERROR(ss); + return AMDSMI_STATUS_API_FAILED; } return AMDSMI_STATUS_SUCCESS; } @@ -431,46 +462,46 @@ std::vector AMDSmiNoDrmNIC::get_bdfs() { } -amdsmi_status_t AMDSmiNoDrmNIC::amd_query_nic_uuid(std::string devicePath, std::string &version) { +amdsmi_status_t AMDSmiNoDrmNIC::amd_query_nic_uuid(std::string device_path, std::string &version) { // Get NIC MAC address - std::string netPath = devicePath + "/net"; - auto net_node_dir = opendir(netPath.c_str()); + std::string net_path = device_path + "/net"; + auto net_node_dir = opendir(net_path.c_str()); if (net_node_dir == nullptr) { std::ostringstream ss; ss << __PRETTY_FUNCTION__ << " | " - << "Failed to open net node directory: " << netPath << ". Error " << AMDSMI_STATUS_FILE_ERROR << "."; + << "Failed to open net node directory: " << net_path << ". Error " << AMDSMI_STATUS_FILE_ERROR << "."; LOG_DEBUG(ss); return AMDSMI_STATUS_FILE_ERROR; } auto dentry = readdir(net_node_dir); - std::string macPath; + std::string mac_path; while ((dentry = readdir(net_node_dir)) != nullptr) { // Skip "." and ".." directories if ((strcmp(dentry->d_name, ".") == 0) || (strcmp(dentry->d_name, "..") == 0)) { continue; } - macPath = netPath + "/" + dentry->d_name; - std::string macAddress = "address"; - version = smi_brcm_get_value_string(macPath, macAddress); + mac_path = net_path + "/" + dentry->d_name; + std::string mac_address = "address"; + version = smi_brcm_get_value_string(mac_path, mac_address); } closedir(net_node_dir); return AMDSMI_STATUS_SUCCESS; } -amdsmi_status_t AMDSmiNoDrmNIC::amd_query_nic_numa_affinity(std::string devicePath, int32_t *numa_node) { +amdsmi_status_t AMDSmiNoDrmNIC::amd_query_nic_numa_affinity(std::string device_path, int32_t *numa_node) { // Get NIC NUMA affinity - std::string numaFile = "numa_node"; - uint32_t numa = smi_brcm_get_value_u32(devicePath, numaFile); + std::string numa_file = "numa_node"; + uint32_t numa = smi_brcm_get_value_u32(device_path, numa_file); *numa_node = numa; return AMDSMI_STATUS_SUCCESS; } -amdsmi_status_t AMDSmiNoDrmNIC::amd_query_nic_cpu_affinity(std::string devicePath, std::string &cpu_affinity) { +amdsmi_status_t AMDSmiNoDrmNIC::amd_query_nic_cpu_affinity(std::string device_path, std::string &cpu_affinity) { // Get NIC CPU affinity - std::string cpuAffFile = "cpulistaffinity"; - cpu_affinity = smi_brcm_get_value_string(devicePath, cpuAffFile); + std::string cpu_aff_file = "cpulistaffinity"; + cpu_affinity = smi_brcm_get_value_string(device_path, cpu_aff_file); return AMDSMI_STATUS_SUCCESS; } diff --git a/projects/amdsmi/src/nic/brcm-nic/amd_smi_no_drm_switch.cc b/projects/amdsmi/src/nic/brcm-nic/amd_smi_no_drm_switch.cc index cba6db56878..761285959b2 100644 --- a/projects/amdsmi/src/nic/brcm-nic/amd_smi_no_drm_switch.cc +++ b/projects/amdsmi/src/nic/brcm-nic/amd_smi_no_drm_switch.cc @@ -139,7 +139,7 @@ amdsmi_status_t AMDSmiNoDrmSwitch::cleanup() { return AMDSMI_STATUS_SUCCESS; } -amdsmi_status_t AMDSmiNoDrmSwitch::amd_query_switch_link( std::string devicePath, +amdsmi_status_t AMDSmiNoDrmSwitch::amd_query_switch_link( std::string device_path, amdsmi_brcm_switch_link_metric_t &info) { std::string current_speed = "current_link_speed"; @@ -147,36 +147,36 @@ amdsmi_status_t AMDSmiNoDrmSwitch::amd_query_switch_link( std::string devicePath std::string current_width = "current_link_width"; std::string max_width = "max_link_width"; - snprintf(info.current_link_speed, sizeof(info.current_link_speed)-1, "%s", smi_brcm_get_value_string(devicePath, current_speed).c_str()); - snprintf(info.max_link_speed, sizeof(info.max_link_speed)-1, "%s", smi_brcm_get_value_string(devicePath, max_speed).c_str()); - snprintf(info.current_link_width, sizeof(info.current_link_width)-1, "%s", smi_brcm_get_value_string(devicePath, current_width).c_str()); - snprintf(info.max_link_width, sizeof(info.max_link_width)-1, "%s", smi_brcm_get_value_string(devicePath, max_width).c_str()); + snprintf(info.current_link_speed, sizeof(info.current_link_speed)-1, "%s", smi_brcm_get_value_string(device_path, current_speed).c_str()); + snprintf(info.max_link_speed, sizeof(info.max_link_speed)-1, "%s", smi_brcm_get_value_string(device_path, max_speed).c_str()); + snprintf(info.current_link_width, sizeof(info.current_link_width)-1, "%s", smi_brcm_get_value_string(device_path, current_width).c_str()); + snprintf(info.max_link_width, sizeof(info.max_link_width)-1, "%s", smi_brcm_get_value_string(device_path, max_width).c_str()); return AMDSMI_STATUS_SUCCESS; } -amdsmi_status_t AMDSmiNoDrmSwitch::amd_query_switch_uuid(std::string bdfStr, std::string& serial) { +amdsmi_status_t AMDSmiNoDrmSwitch::amd_query_switch_uuid(std::string bdf_str, std::string& serial) { - get_lspci_device_data(bdfStr, "Device Serial Number ", serial); + get_lspci_device_data(bdf_str, "Device Serial Number ", serial); return AMDSMI_STATUS_SUCCESS; } -amdsmi_status_t AMDSmiNoDrmSwitch::amd_query_switch_numa_affinity(std::string devicePath, int32_t *numa_node) { - std::string numaFile = "numa_node"; - uint32_t numa = smi_brcm_get_value_u32(devicePath, numaFile); +amdsmi_status_t AMDSmiNoDrmSwitch::amd_query_switch_numa_affinity(std::string device_path, int32_t *numa_node) { + std::string numa_file = "numa_node"; + uint32_t numa = smi_brcm_get_value_u32(device_path, numa_file); *numa_node = numa; return AMDSMI_STATUS_SUCCESS; } -amdsmi_status_t AMDSmiNoDrmSwitch::amd_query_switch_cpu_affinity(std::string devicePath, std::string &cpu_affinity) { - std::string cpuAffFile = "cpulistaffinity"; - cpu_affinity = smi_brcm_get_value_string(devicePath, cpuAffFile); +amdsmi_status_t AMDSmiNoDrmSwitch::amd_query_switch_cpu_affinity(std::string device_path, std::string &cpu_affinity) { + std::string cpu_aff_file = "cpulistaffinity"; + cpu_affinity = smi_brcm_get_value_string(device_path, cpu_aff_file); return AMDSMI_STATUS_SUCCESS; } -amdsmi_status_t AMDSmiNoDrmSwitch::amd_query_switch_device( std::string devicePath, +amdsmi_status_t AMDSmiNoDrmSwitch::amd_query_switch_device( std::string device_path, amdsmi_brcm_switch_device_metric_t &info) { std::string brcm_device_aer_dev_correctable = "aer_dev_correctable"; @@ -217,46 +217,46 @@ amdsmi_status_t AMDSmiNoDrmSwitch::amd_query_switch_device( std::string devicePa std::string brcm_device_uevent = "uevent"; std::string brcm_device_vendor = "vendor"; - snprintf(info.brcm_device_aer_dev_correctable, sizeof(info.brcm_device_aer_dev_correctable)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_aer_dev_correctable).c_str()); - snprintf(info.brcm_device_aer_dev_fatal, sizeof(info.brcm_device_aer_dev_fatal)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_aer_dev_fatal).c_str()); - snprintf(info.brcm_device_aer_dev_nonfatal, sizeof(info.brcm_device_aer_dev_nonfatal)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_aer_dev_nonfatal).c_str()); - snprintf(info.brcm_device_ari_enabled, sizeof(info.brcm_device_ari_enabled)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_ari_enabled).c_str()); - snprintf(info.brcm_device_broken_parity_status, sizeof(info.brcm_device_broken_parity_status)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_broken_parity_status).c_str()); - snprintf(info.brcm_device_class, sizeof(info.brcm_device_class)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_class).c_str()); - snprintf(info.brcm_device_config, sizeof(info.brcm_device_config)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_config).c_str()); - snprintf(info.brcm_device_consistent_dma_mask_bits, sizeof(info.brcm_device_consistent_dma_mask_bits)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_consistent_dma_mask_bits).c_str()); - snprintf(info.brcm_device_current_link_speed, sizeof(info.brcm_device_current_link_speed)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_current_link_speed).c_str()); - snprintf(info.brcm_device_current_link_width, sizeof(info.brcm_device_current_link_width)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_current_link_width).c_str()); - snprintf(info.brcm_device_d3cold_allowed, sizeof(info.brcm_device_d3cold_allowed)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_d3cold_allowed).c_str()); - snprintf(info.brcm_device_device, sizeof(info.brcm_device_device)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_device).c_str()); - snprintf(info.brcm_device_dma_mask_bits, sizeof(info.brcm_device_dma_mask_bits)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_dma_mask_bits).c_str()); - snprintf(info.brcm_device_driver_override, sizeof(info.brcm_device_driver_override)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_driver_override).c_str()); - snprintf(info.brcm_device_enable, sizeof(info.brcm_device_enable)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_enable).c_str()); - snprintf(info.brcm_device_irq, sizeof(info.brcm_device_irq)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_irq).c_str()); - snprintf(info.brcm_device_local_cpulist, sizeof(info.brcm_device_local_cpulist)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_local_cpulist).c_str()); - snprintf(info.brcm_device_local_cpus, sizeof(info.brcm_device_local_cpus)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_local_cpus).c_str()); - snprintf(info.brcm_device_max_link_speed, sizeof(info.brcm_device_max_link_speed)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_max_link_speed).c_str()); - snprintf(info.brcm_device_max_link_width, sizeof(info.brcm_device_max_link_width)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_max_link_width).c_str()); - snprintf(info.brcm_device_modalias, sizeof(info.brcm_device_modalias)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_modalias).c_str()); - snprintf(info.brcm_device_msi_bus, sizeof(info.brcm_device_msi_bus)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_msi_bus).c_str()); - snprintf(info.brcm_device_numa_node, sizeof(info.brcm_device_numa_node)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_numa_node).c_str()); - snprintf(info.brcm_device_pools, sizeof(info.brcm_device_pools)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_pools).c_str()); - snprintf(info.brcm_device_power_state, sizeof(info.brcm_device_power_state)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_power_state).c_str()); - snprintf(info.brcm_device_reset_method, sizeof(info.brcm_device_reset_method)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_reset_method).c_str()); - snprintf(info.brcm_device_resource, sizeof(info.brcm_device_resource)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_resource).c_str()); - snprintf(info.brcm_device_revision, sizeof(info.brcm_device_revision)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_revision).c_str()); - snprintf(info.brcm_device_subsystem_device, sizeof(info.brcm_device_subsystem_device)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_subsystem_device).c_str()); - snprintf(info.brcm_device_subsystem_vendor, sizeof(info.brcm_device_subsystem_vendor)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_subsystem_vendor).c_str()); - snprintf(info.brcm_device_uevent, sizeof(info.brcm_device_uevent)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_uevent).c_str()); - snprintf(info.brcm_device_vendor, sizeof(info.brcm_device_vendor)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_device_vendor).c_str()); + snprintf(info.brcm_device_aer_dev_correctable, sizeof(info.brcm_device_aer_dev_correctable)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_aer_dev_correctable).c_str()); + snprintf(info.brcm_device_aer_dev_fatal, sizeof(info.brcm_device_aer_dev_fatal)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_aer_dev_fatal).c_str()); + snprintf(info.brcm_device_aer_dev_nonfatal, sizeof(info.brcm_device_aer_dev_nonfatal)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_aer_dev_nonfatal).c_str()); + snprintf(info.brcm_device_ari_enabled, sizeof(info.brcm_device_ari_enabled)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_ari_enabled).c_str()); + snprintf(info.brcm_device_broken_parity_status, sizeof(info.brcm_device_broken_parity_status)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_broken_parity_status).c_str()); + snprintf(info.brcm_device_class, sizeof(info.brcm_device_class)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_class).c_str()); + snprintf(info.brcm_device_config, sizeof(info.brcm_device_config)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_config).c_str()); + snprintf(info.brcm_device_consistent_dma_mask_bits, sizeof(info.brcm_device_consistent_dma_mask_bits)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_consistent_dma_mask_bits).c_str()); + snprintf(info.brcm_device_current_link_speed, sizeof(info.brcm_device_current_link_speed)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_current_link_speed).c_str()); + snprintf(info.brcm_device_current_link_width, sizeof(info.brcm_device_current_link_width)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_current_link_width).c_str()); + snprintf(info.brcm_device_d3cold_allowed, sizeof(info.brcm_device_d3cold_allowed)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_d3cold_allowed).c_str()); + snprintf(info.brcm_device_device, sizeof(info.brcm_device_device)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_device).c_str()); + snprintf(info.brcm_device_dma_mask_bits, sizeof(info.brcm_device_dma_mask_bits)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_dma_mask_bits).c_str()); + snprintf(info.brcm_device_driver_override, sizeof(info.brcm_device_driver_override)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_driver_override).c_str()); + snprintf(info.brcm_device_enable, sizeof(info.brcm_device_enable)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_enable).c_str()); + snprintf(info.brcm_device_irq, sizeof(info.brcm_device_irq)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_irq).c_str()); + snprintf(info.brcm_device_local_cpulist, sizeof(info.brcm_device_local_cpulist)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_local_cpulist).c_str()); + snprintf(info.brcm_device_local_cpus, sizeof(info.brcm_device_local_cpus)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_local_cpus).c_str()); + snprintf(info.brcm_device_max_link_speed, sizeof(info.brcm_device_max_link_speed)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_max_link_speed).c_str()); + snprintf(info.brcm_device_max_link_width, sizeof(info.brcm_device_max_link_width)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_max_link_width).c_str()); + snprintf(info.brcm_device_modalias, sizeof(info.brcm_device_modalias)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_modalias).c_str()); + snprintf(info.brcm_device_msi_bus, sizeof(info.brcm_device_msi_bus)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_msi_bus).c_str()); + snprintf(info.brcm_device_numa_node, sizeof(info.brcm_device_numa_node)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_numa_node).c_str()); + snprintf(info.brcm_device_pools, sizeof(info.brcm_device_pools)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_pools).c_str()); + snprintf(info.brcm_device_power_state, sizeof(info.brcm_device_power_state)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_power_state).c_str()); + snprintf(info.brcm_device_reset_method, sizeof(info.brcm_device_reset_method)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_reset_method).c_str()); + snprintf(info.brcm_device_resource, sizeof(info.brcm_device_resource)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_resource).c_str()); + snprintf(info.brcm_device_revision, sizeof(info.brcm_device_revision)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_revision).c_str()); + snprintf(info.brcm_device_subsystem_device, sizeof(info.brcm_device_subsystem_device)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_subsystem_device).c_str()); + snprintf(info.brcm_device_subsystem_vendor, sizeof(info.brcm_device_subsystem_vendor)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_subsystem_vendor).c_str()); + snprintf(info.brcm_device_uevent, sizeof(info.brcm_device_uevent)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_uevent).c_str()); + snprintf(info.brcm_device_vendor, sizeof(info.brcm_device_vendor)-1, "%s", smi_brcm_get_value_string(device_path, brcm_device_vendor).c_str()); return AMDSMI_STATUS_SUCCESS; } -amdsmi_status_t AMDSmiNoDrmSwitch::amd_query_switch_power( std::string devicePath, +amdsmi_status_t AMDSmiNoDrmSwitch::amd_query_switch_power( std::string device_path, amdsmi_brcm_switch_power_metric_t &info) { - devicePath = devicePath+"/power"; + device_path = device_path+"/power"; std::string brcm_power_async = "async"; std::string brcm_power_control = "control"; std::string brcm_power_runtime_active_kids = "runtime_active_kids"; @@ -275,23 +275,23 @@ amdsmi_status_t AMDSmiNoDrmSwitch::amd_query_switch_power( std::string devicePat std::string brcm_power_wakeup_max_time_ms = "wakeup_max_time_ms"; std::string brcm_power_wakeup_total_time_ms = "wakeup_total_time_ms"; - snprintf(info.brcm_power_async, sizeof(info.brcm_power_async)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_power_async).c_str()); - snprintf(info.brcm_power_control, sizeof(info.brcm_power_control)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_power_control).c_str()); - snprintf(info.brcm_power_runtime_active_kids, sizeof(info.brcm_power_runtime_active_kids)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_power_runtime_active_kids).c_str()); - snprintf(info.brcm_power_runtime_active_time, sizeof(info.brcm_power_runtime_active_time)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_power_runtime_active_time).c_str()); - snprintf(info.brcm_power_runtime_enabled, sizeof(info.brcm_power_runtime_enabled)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_power_runtime_enabled).c_str()); - snprintf(info.brcm_power_runtime_status, sizeof(info.brcm_power_runtime_status)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_power_runtime_status).c_str()); - snprintf(info.brcm_power_runtime_suspended_time, sizeof(info.brcm_power_runtime_suspended_time)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_power_runtime_suspended_time).c_str()); - snprintf(info.brcm_power_runtime_usage, sizeof(info.brcm_power_runtime_usage)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_power_runtime_usage).c_str()); - snprintf(info.brcm_power_wakeup, sizeof(info.brcm_power_wakeup)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_power_wakeup).c_str()); - snprintf(info.brcm_power_wakeup_abort_count, sizeof(info.brcm_power_wakeup_abort_count)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_power_wakeup_abort_count).c_str()); - snprintf(info.brcm_power_wakeup_active, sizeof(info.brcm_power_wakeup_active)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_power_wakeup_active).c_str()); - snprintf(info.brcm_power_wakeup_active_count, sizeof(info.brcm_power_wakeup_active_count)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_power_wakeup_active_count).c_str()); - snprintf(info.brcm_power_wakeup_count, sizeof(info.brcm_power_wakeup_count)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_power_wakeup_count).c_str()); - snprintf(info.brcm_power_wakeup_expire_count, sizeof(info.brcm_power_wakeup_expire_count)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_power_wakeup_expire_count).c_str()); - snprintf(info.brcm_power_wakeup_last_time_ms, sizeof(info.brcm_power_wakeup_last_time_ms)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_power_wakeup_last_time_ms).c_str()); - snprintf(info.brcm_power_wakeup_max_time_ms, sizeof(info.brcm_power_wakeup_max_time_ms)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_power_wakeup_max_time_ms).c_str()); - snprintf(info.brcm_power_wakeup_total_time_ms, sizeof(info.brcm_power_wakeup_total_time_ms)-1, "%s", smi_brcm_get_value_string(devicePath, brcm_power_wakeup_total_time_ms).c_str()); + snprintf(info.brcm_power_async, sizeof(info.brcm_power_async)-1, "%s", smi_brcm_get_value_string(device_path, brcm_power_async).c_str()); + snprintf(info.brcm_power_control, sizeof(info.brcm_power_control)-1, "%s", smi_brcm_get_value_string(device_path, brcm_power_control).c_str()); + snprintf(info.brcm_power_runtime_active_kids, sizeof(info.brcm_power_runtime_active_kids)-1, "%s", smi_brcm_get_value_string(device_path, brcm_power_runtime_active_kids).c_str()); + snprintf(info.brcm_power_runtime_active_time, sizeof(info.brcm_power_runtime_active_time)-1, "%s", smi_brcm_get_value_string(device_path, brcm_power_runtime_active_time).c_str()); + snprintf(info.brcm_power_runtime_enabled, sizeof(info.brcm_power_runtime_enabled)-1, "%s", smi_brcm_get_value_string(device_path, brcm_power_runtime_enabled).c_str()); + snprintf(info.brcm_power_runtime_status, sizeof(info.brcm_power_runtime_status)-1, "%s", smi_brcm_get_value_string(device_path, brcm_power_runtime_status).c_str()); + snprintf(info.brcm_power_runtime_suspended_time, sizeof(info.brcm_power_runtime_suspended_time)-1, "%s", smi_brcm_get_value_string(device_path, brcm_power_runtime_suspended_time).c_str()); + snprintf(info.brcm_power_runtime_usage, sizeof(info.brcm_power_runtime_usage)-1, "%s", smi_brcm_get_value_string(device_path, brcm_power_runtime_usage).c_str()); + snprintf(info.brcm_power_wakeup, sizeof(info.brcm_power_wakeup)-1, "%s", smi_brcm_get_value_string(device_path, brcm_power_wakeup).c_str()); + snprintf(info.brcm_power_wakeup_abort_count, sizeof(info.brcm_power_wakeup_abort_count)-1, "%s", smi_brcm_get_value_string(device_path, brcm_power_wakeup_abort_count).c_str()); + snprintf(info.brcm_power_wakeup_active, sizeof(info.brcm_power_wakeup_active)-1, "%s", smi_brcm_get_value_string(device_path, brcm_power_wakeup_active).c_str()); + snprintf(info.brcm_power_wakeup_active_count, sizeof(info.brcm_power_wakeup_active_count)-1, "%s", smi_brcm_get_value_string(device_path, brcm_power_wakeup_active_count).c_str()); + snprintf(info.brcm_power_wakeup_count, sizeof(info.brcm_power_wakeup_count)-1, "%s", smi_brcm_get_value_string(device_path, brcm_power_wakeup_count).c_str()); + snprintf(info.brcm_power_wakeup_expire_count, sizeof(info.brcm_power_wakeup_expire_count)-1, "%s", smi_brcm_get_value_string(device_path, brcm_power_wakeup_expire_count).c_str()); + snprintf(info.brcm_power_wakeup_last_time_ms, sizeof(info.brcm_power_wakeup_last_time_ms)-1, "%s", smi_brcm_get_value_string(device_path, brcm_power_wakeup_last_time_ms).c_str()); + snprintf(info.brcm_power_wakeup_max_time_ms, sizeof(info.brcm_power_wakeup_max_time_ms)-1, "%s", smi_brcm_get_value_string(device_path, brcm_power_wakeup_max_time_ms).c_str()); + snprintf(info.brcm_power_wakeup_total_time_ms, sizeof(info.brcm_power_wakeup_total_time_ms)-1, "%s", smi_brcm_get_value_string(device_path, brcm_power_wakeup_total_time_ms).c_str()); return AMDSMI_STATUS_SUCCESS; } diff --git a/projects/amdsmi/src/nic/brcm-nic/amd_smi_switch_device.cc b/projects/amdsmi/src/nic/brcm-nic/amd_smi_switch_device.cc index 73f418f8f78..1fab49c35aa 100644 --- a/projects/amdsmi/src/nic/brcm-nic/amd_smi_switch_device.cc +++ b/projects/amdsmi/src/nic/brcm-nic/amd_smi_switch_device.cc @@ -62,29 +62,29 @@ pthread_mutex_t* AMDSmiSWITCHDevice::get_mutex() { amdsmi_status_t AMDSmiSWITCHDevice::amd_query_switch_link_info(amdsmi_brcm_switch_link_metric_t& info) const { amdsmi_status_t ret; - std::string devicePath; - ret = nodrm_.get_device_path_by_index(switch_id_, &devicePath); + std::string device_path; + ret = nodrm_.get_device_path_by_index(switch_id_, &device_path); if (ret != AMDSMI_STATUS_SUCCESS) return AMDSMI_STATUS_NOT_SUPPORTED; - return nodrm_.amd_query_switch_link(devicePath, info); + return nodrm_.amd_query_switch_link(device_path, info); } amdsmi_status_t AMDSmiSWITCHDevice::amd_query_switch_power_info(amdsmi_brcm_switch_power_metric_t& info) const { amdsmi_status_t ret; - std::string devicePath; //sys/bus/pci/devices/0000:9b:00.0 - ret = nodrm_.get_device_path_by_index(switch_id_, &devicePath); + std::string device_path; //sys/bus/pci/devices/0000:9b:00.0 + ret = nodrm_.get_device_path_by_index(switch_id_, &device_path); if (ret != AMDSMI_STATUS_SUCCESS) return AMDSMI_STATUS_NOT_SUPPORTED; - return nodrm_.amd_query_switch_power(devicePath, info); + return nodrm_.amd_query_switch_power(device_path, info); } amdsmi_status_t AMDSmiSWITCHDevice::amd_query_switch_device_info(amdsmi_brcm_switch_device_metric_t& info) const { amdsmi_status_t ret; - std::string devicePath; - ret = nodrm_.get_device_path_by_index(switch_id_, &devicePath); + std::string device_path; + ret = nodrm_.get_device_path_by_index(switch_id_, &device_path); if (ret != AMDSMI_STATUS_SUCCESS) return AMDSMI_STATUS_NOT_SUPPORTED; - return nodrm_.amd_query_switch_device(devicePath, info); + return nodrm_.amd_query_switch_device(device_path, info); } amdsmi_status_t AMDSmiSWITCHDevice::amd_query_switch_uuid(std::string& serial) const { @@ -103,11 +103,11 @@ amdsmi_status_t AMDSmiSWITCHDevice::amd_query_switch_uuid(std::string& serial) c amdsmi_status_t AMDSmiSWITCHDevice::amd_query_switch_numa_affinity(int32_t *numa_node) const { amdsmi_status_t ret; - std::string devicePath; - ret = nodrm_.get_device_path_by_index(switch_id_, &devicePath); + std::string device_path; + ret = nodrm_.get_device_path_by_index(switch_id_, &device_path); if (ret != AMDSMI_STATUS_SUCCESS) return AMDSMI_STATUS_NOT_SUPPORTED; - return nodrm_.amd_query_switch_numa_affinity(devicePath, numa_node); + return nodrm_.amd_query_switch_numa_affinity(device_path, numa_node); } amdsmi_status_t AMDSmiSWITCHDevice::amd_query_switch_cpu_affinity(std::string& cpu_affinity) const { diff --git a/projects/amdsmi/tests/amd_smi_test/functional/sys_info_read.cc b/projects/amdsmi/tests/amd_smi_test/functional/sys_info_read.cc index 0e09c9482a3..bdc55c62109 100644 --- a/projects/amdsmi/tests/amd_smi_test/functional/sys_info_read.cc +++ b/projects/amdsmi/tests/amd_smi_test/functional/sys_info_read.cc @@ -226,7 +226,7 @@ void TestSysInfoRead::Run(void) { << nic_gpu_topo_info << std::endl; } } -#endif//BRCM_NIC +#endif // BRCM_NIC // vendor_id, unique_id, target_gfx_version amdsmi_asic_info_t asic_info = {}; err = amdsmi_get_gpu_asic_info(processor_handles_[i], &asic_info);