Skip to content

XRT-SMI Configure and Examine migration #8906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/runtime_src/core/common/query_requests.h
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,8 @@ struct xrt_smi_lists : request
{
enum class type {
validate_tests,
examine_reports
examine_reports,
configure_option_options,
};
using result_type = std::vector<std::tuple<std::string, std::string, std::string>>;
static const key_type key = key_type::xrt_smi_lists;
Expand Down
33 changes: 33 additions & 0 deletions src/runtime_src/core/common/smi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ construct_subcommand_json() const
return pt;
}

tuple_vector
subcommand::
get_option_options() const
{
tuple_vector option_options;
for (const auto& [name, option] : m_options) {
if (option->get_is_optionOption()) {
option_options.emplace_back(std::make_tuple(name, option->m_description, option->m_type));
}
}
return option_options;
}

std::string
smi::
build_smi_config() const
Expand Down Expand Up @@ -114,6 +127,20 @@ get_list(const std::string& subcommand, const std::string& suboption) const
return option->get_description_array();
}

tuple_vector
smi::
get_option_options(const std::string& subcommand) const
{
const auto it = m_subcommands.find(subcommand);
if (it == m_subcommands.end()) {
throw std::runtime_error("Subcommand not found: " + subcommand);
}

const auto& subcmd = it->second;

return subcmd.get_option_options();
}

smi*
instance()
{
Expand All @@ -127,4 +154,10 @@ get_list(const std::string& subcommand, const std::string& suboption)
return instance()->get_list(subcommand, suboption);
}

tuple_vector
get_option_options(const std::string& subcommand)
{
return instance()->get_option_options(subcommand);
}

} // namespace xrt_core::smi
16 changes: 16 additions & 0 deletions src/runtime_src/core/common/smi.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class option : public basic_option {
get_description_array() const {
throw std::runtime_error("Illegal call to get_description_array()");
}

bool
get_is_optionOption() const {
return b_is_optionOption;
}
};

// This class is used to represent an option with a multiline description.
Expand Down Expand Up @@ -101,6 +106,9 @@ class subcommand {
get_options() const
{ return m_options; }

tuple_vector
get_option_options() const;

boost::property_tree::ptree
construct_subcommand_json() const;

Expand Down Expand Up @@ -134,6 +142,10 @@ class smi {
tuple_vector
get_list(const std::string& subcommand, const std::string& suboption) const;

XRT_CORE_COMMON_EXPORT
tuple_vector
get_option_options(const std::string& subcommand) const;

};

XRT_CORE_COMMON_EXPORT
Expand All @@ -144,4 +156,8 @@ XRT_CORE_COMMON_EXPORT
tuple_vector
get_list(const std::string& subcommand, const std::string& suboption);

XRT_CORE_COMMON_EXPORT
tuple_vector
get_option_options(const std::string& subcommand);

} // namespace xrt_core::smi
2 changes: 2 additions & 0 deletions src/runtime_src/core/edge/user/device_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,8 @@ struct xrt_smi_lists
return xrt_core::smi::get_list("validate", "run");
case xrt_core::query::xrt_smi_lists::type::examine_reports:
return xrt_core::smi::get_list("examine", "report");
case xrt_core::query::xrt_smi_lists::type::configure_option_options:
return xrt_core::smi::get_option_options("configure");
default:
throw xrt_core::query::no_such_key(key, "Not implemented");
}
Expand Down
11 changes: 2 additions & 9 deletions src/runtime_src/core/edge/user/smi_edge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,8 @@ create_configure_subcommand()
std::map<std::string, std::shared_ptr<xrt_core::smi::option>> configure_suboptions;
configure_suboptions.emplace("device", std::make_shared<xrt_core::smi::option>("device", "d", "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", "common", "", "string"));
configure_suboptions.emplace("help", std::make_shared<xrt_core::smi::option>("help", "h", "Help to use this sub-command", "common", "", "none"));
configure_suboptions.emplace("daemon", std::make_shared<xrt_core::smi::option>("daemon", "", "Update the device daemon configuration", "hidden", "", "none"));
configure_suboptions.emplace("purge", std::make_shared<xrt_core::smi::option>("purge", "", "Remove the daemon configuration file", "hidden", "", "string"));
configure_suboptions.emplace("host", std::make_shared<xrt_core::smi::option>("host", "", "IP or hostname for device peer", "hidden", "", "string"));
configure_suboptions.emplace("security", std::make_shared<xrt_core::smi::option>("security", "", "Update the security level for the device", "hidden", "", "string"));
configure_suboptions.emplace("clk_throttle", std::make_shared<xrt_core::smi::option>("clk_throttle", "", "Enable/disable the device clock throttling", "hidden", "", "string"));
configure_suboptions.emplace("ct_threshold_power_override", std::make_shared<xrt_core::smi::option>("ct_threshold_power_override", "", "Update the power threshold in watts", "hidden", "", "string"));
configure_suboptions.emplace("ct_threshold_temp_override", std::make_shared<xrt_core::smi::option>("ct_threshold_temp_override", "", "Update the temperature threshold in celsius", "hidden", "", "string"));
configure_suboptions.emplace("ct_reset", std::make_shared<xrt_core::smi::option>("ct_reset", "", "Reset all throttling options", "hidden", "", "string"));
configure_suboptions.emplace("showx", std::make_shared<xrt_core::smi::option>("showx", "", "Display the device configuration settings", "hidden", "", "string"));
configure_suboptions.emplace("p2p", std::make_shared<xrt_core::smi::option>("p2p", "", "Controls P2P functionality\n", "common", "", "string", true));
configure_suboptions.emplace("host-mem", std::make_shared<xrt_core::smi::option>("host-mem", "", "Controls host-mem functionality\n", "common", "", "string", true));

return {"configure", "Device and host configuration", "common", std::move(configure_suboptions)};
}
Expand Down
2 changes: 2 additions & 0 deletions src/runtime_src/core/pcie/linux/device_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,8 @@ struct xrt_smi_lists
return xrt_core::smi::get_list("validate", "run");
case xrt_core::query::xrt_smi_lists::type::examine_reports:
return xrt_core::smi::get_list("examine", "report");
case xrt_core::query::xrt_smi_lists::type::configure_option_options:
return xrt_core::smi::get_option_options("configure");
default:
throw xrt_core::query::no_such_key(key, "Not implemented");
}
Expand Down
12 changes: 3 additions & 9 deletions src/runtime_src/core/pcie/linux/smi_pcie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,9 @@ create_configure_subcommand()
std::map<std::string, std::shared_ptr<xrt_core::smi::option>> configure_suboptions;
configure_suboptions.emplace("device", std::make_shared<xrt_core::smi::option>("device", "d", "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", "common", "", "string"));
configure_suboptions.emplace("help", std::make_shared<xrt_core::smi::option>("help", "h", "Help to use this sub-command", "common", "", "none"));
configure_suboptions.emplace("daemon", std::make_shared<xrt_core::smi::option>("daemon", "", "Update the device daemon configuration", "hidden", "", "none"));
configure_suboptions.emplace("purge", std::make_shared<xrt_core::smi::option>("purge", "", "Remove the daemon configuration file", "hidden", "", "string"));
configure_suboptions.emplace("host", std::make_shared<xrt_core::smi::option>("host", "", "IP or hostname for device peer", "hidden", "", "string"));
configure_suboptions.emplace("security", std::make_shared<xrt_core::smi::option>("security", "", "Update the security level for the device", "hidden", "", "string"));
configure_suboptions.emplace("clk_throttle", std::make_shared<xrt_core::smi::option>("clk_throttle", "", "Enable/disable the device clock throttling", "hidden", "", "string"));
configure_suboptions.emplace("ct_threshold_power_override", std::make_shared<xrt_core::smi::option>("ct_threshold_power_override", "", "Update the power threshold in watts", "hidden", "", "string"));
configure_suboptions.emplace("ct_threshold_temp_override", std::make_shared<xrt_core::smi::option>("ct_threshold_temp_override", "", "Update the temperature threshold in celsius", "hidden", "", "string"));
configure_suboptions.emplace("ct_reset", std::make_shared<xrt_core::smi::option>("ct_reset", "", "Reset all throttling options", "hidden", "", "string"));
configure_suboptions.emplace("showx", std::make_shared<xrt_core::smi::option>("showx", "", "Display the device configuration settings", "hidden", "", "string"));
configure_suboptions.emplace("p2p", std::make_shared<xrt_core::smi::option>("p2p", "", "Controls P2P functionality\n", "common", "", "string", true));
configure_suboptions.emplace("host-mem", std::make_shared<xrt_core::smi::option>("host-mem", "", "Controls host-mem functionality\n", "common", "", "string", true));


return {"configure", "Device and host configuration", "common", std::move(configure_suboptions)};
}
Expand Down
108 changes: 53 additions & 55 deletions src/runtime_src/core/tools/common/SubCmdConfigureInternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,18 @@ static boost::property_tree::ptree m_configurations;
SubCmdConfigureInternal::SubCmdConfigureInternal(bool _isHidden, bool _isDepricated, bool _isPreliminary, bool _isUserDomain, const boost::property_tree::ptree& configurations)
: SubCmd("configure",
_isUserDomain ? "Device and host configuration" : "Advanced options for configuring a device")
, m_device("")
, m_help(false)
, m_isUserDomain(_isUserDomain)
, m_daemon(false)
, m_purge(false)
, m_host("")
, m_security("")
, m_clk_throttle("")
, m_power_override("")
, m_temp_override("")
, m_ct_reset("")
, m_showx(false)
{
const std::string longDescription = _isUserDomain ? "Device and host configuration." : "Advanced options for configuring a device";
setLongDescription(longDescription);
Expand All @@ -102,10 +113,28 @@ SubCmdConfigureInternal::SubCmdConfigureInternal(bool _isHidden, bool _isDeprica
setIsDeprecated(_isDepricated);
setIsPreliminary(_isPreliminary);

for (const auto& option : optionOptionsCollection){
addSubOption(option);
if (!m_isUserDomain) {
// Options previously hidden under the config command
configHiddenOptions.add_options()
("daemon", boost::program_options::bool_switch(&m_daemon), "Update the device daemon configuration")
("purge", boost::program_options::bool_switch(&m_purge), "Remove the daemon configuration file")
("host", boost::program_options::value<decltype(m_host)>(&m_host), "IP or hostname for device peer")
("security", boost::program_options::value<decltype(m_security)>(&m_security), "Update the security level for the device")
("clk_throttle", boost::program_options::value<decltype(m_clk_throttle)>(&m_clk_throttle), "Enable/disable the device clock throttling")
("ct_threshold_power_override", boost::program_options::value<decltype(m_power_override)>(&m_power_override), "Update the power threshold in watts")
("ct_threshold_temp_override", boost::program_options::value<decltype(m_temp_override)>(&m_temp_override), "Update the temperature threshold in celsius")
("ct_reset", boost::program_options::value<decltype(m_ct_reset)>(&m_ct_reset), "Reset all throttling options")
("showx", boost::program_options::bool_switch(&m_showx), "Display the device configuration settings")
;

m_hiddenOptions.add(configHiddenOptions);
}

m_commonOptions.add_options()
("device,d", boost::program_options::value<decltype(m_device)>(&m_device), "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest")
("help", boost::program_options::bool_switch(&m_help), "Help to use this sub-command")
;

m_commandConfig = configurations;
}

Expand Down Expand Up @@ -289,17 +318,15 @@ SubCmdConfigureInternal::execute(const SubCmdOptions& _options) const
{
XBU::verbose("SubCommand: configure");
po::variables_map vm;
SubCmdConfigureOptions options;
// Used for the suboption arguments.
const auto unrecognized_options = process_arguments(vm, _options, false);
fill_option_values(vm, options);
// Find the subOption
auto optionOption = checkForSubOption(vm, XBU::get_device_class(options.m_device, m_isUserDomain));
auto optionOption = checkForSubOption(vm, XBU::get_device_class(m_device, m_isUserDomain));

if (!optionOption && m_isUserDomain) {
// No suboption print help
if (options.m_help) {
printHelp(false, "", XBU::get_device_class(options.m_device, m_isUserDomain));
if (m_help) {
printHelp(false, "", XBU::get_device_class(m_device, m_isUserDomain));
return;
}
// If help was not requested and additional options dont match we must throw to prevent
Expand All @@ -314,7 +341,7 @@ SubCmdConfigureInternal::execute(const SubCmdOptions& _options) const
else {
std::cerr << "ERROR: Suboption missing" << std::endl;
}
printHelp(false, "", XBU::get_device_class(options.m_device, m_isUserDomain));
printHelp(false, "", XBU::get_device_class(m_device, m_isUserDomain));
throw xrt_core::error(std::errc::operation_canceled);
}

Expand All @@ -331,31 +358,31 @@ SubCmdConfigureInternal::execute(const SubCmdOptions& _options) const
// Take care of executing hidden options for xbmgmt.
if (!m_isUserDomain) {
// -- process "help" option -----------------------------------------------
if (options.m_help) {
if (m_help) {
printHelp();
return;
}

// Non-device options
// Remove the daemon config file
if (options.m_purge) {
if (m_purge) {
XBU::verbose("Sub command: --purge");
remove_daemon_config();
return;
}

// Update daemon
if (options.m_daemon) {
if (m_daemon) {
XBU::verbose("Sub command: --daemon");
update_daemon_config(options.m_host);
update_daemon_config(m_host);
return;
}

// Find device of interest
std::shared_ptr<xrt_core::device> device;

try {
device = XBU::get_device(boost::algorithm::to_lower_copy(options.m_device), false /*inUserDomain*/);
device = XBU::get_device(boost::algorithm::to_lower_copy(m_device), false /*inUserDomain*/);
} catch (const std::runtime_error& e) {
// Catch only the exceptions that we have generated earlier
std::cerr << boost::format("ERROR: %s\n") % e.what();
Expand All @@ -370,9 +397,9 @@ SubCmdConfigureInternal::execute(const SubCmdOptions& _options) const

// Config commands
// Option:m_showx
if (options.m_showx) {
if (m_showx) {
XBU::verbose("Sub command: --showx");
if(options.m_daemon)
if(m_daemon)
show_daemon_conf();

show_device_conf(device.get());
Expand All @@ -383,58 +410,29 @@ SubCmdConfigureInternal::execute(const SubCmdOptions& _options) const
bool is_something_updated = false;

// Update security
if (!options.m_security.empty())
is_something_updated = update_device_conf(device.get(), options.m_security, config_type::security);
if (!m_security.empty())
is_something_updated = update_device_conf(device.get(), m_security, config_type::security);

// Clock throttling
if (!options.m_clk_throttle.empty())
is_something_updated = update_device_conf(device.get(), options.m_clk_throttle, config_type::clk_throttling);
if (!m_clk_throttle.empty())
is_something_updated = update_device_conf(device.get(), m_clk_throttle, config_type::clk_throttling);

// Update threshold power override
if (!options.m_power_override.empty())
is_something_updated = update_device_conf(device.get(), options.m_power_override, config_type::threshold_power_override);
if (!m_power_override.empty())
is_something_updated = update_device_conf(device.get(), m_power_override, config_type::threshold_power_override);

// Update threshold temp override
if (!options.m_temp_override.empty())
is_something_updated = update_device_conf(device.get(), options.m_temp_override, config_type::threshold_temp_override);
if (!m_temp_override.empty())
is_something_updated = update_device_conf(device.get(), m_temp_override, config_type::threshold_temp_override);

// m_ct_reset?? TODO needs better comment
if (!options.m_ct_reset.empty())
is_something_updated = update_device_conf(device.get(), options.m_ct_reset, config_type::reset);
if (!m_ct_reset.empty())
is_something_updated = update_device_conf(device.get(), m_ct_reset, config_type::reset);

if (!is_something_updated) {
std::cerr << "ERROR: Please specify a valid option to configure the device" << "\n\n";
printHelp(false, "", XBU::get_device_class(options.m_device, m_isUserDomain));
printHelp(false, "", XBU::get_device_class(m_device, m_isUserDomain));
throw xrt_core::error(std::errc::operation_canceled);
}
}
}

void
SubCmdConfigureInternal::fill_option_values(const boost::program_options::variables_map& vm, SubCmdConfigureOptions& options) const
{
options.m_device = vm.count("device") ? vm["device"].as<std::string>() : "";
options.m_help = vm.count("help") ? vm["help"].as<bool>() : false;
options.m_daemon = vm.count("daemon") ? vm["daemon"].as<bool>() : false;
options.m_purge = vm.count("purge") ? vm["purge"].as<bool>() : false;
options.m_host = vm.count("host") ? vm["host"].as<std::string>() : "";
options.m_security = vm.count("security") ? vm["security"].as<std::string>() : "";
options.m_clk_throttle = vm.count("clk_throttle") ? vm["clk_throttle"].as<std::string>() : "";
options.m_power_override = vm.count("ct_threshold_power_override") ? vm["ct_threshold_power_override"].as<std::string>() : "";
options.m_temp_override = vm.count("ct_threshold_temp_override") ? vm["ct_threshold_temp_override"].as<std::string>() : "";
options.m_ct_reset = vm.count("ct_reset") ? vm["ct_reset"].as<std::string>() : "";
options.m_showx = vm.count("showx") ? vm["showx"].as<bool>() : false;
}

void
SubCmdConfigureInternal::setOptionConfig(const boost::property_tree::ptree &config)
{
m_jsonConfig = SubCmdJsonObjects::JsonConfig(config.get_child("subcommands"), getName());
try{
m_jsonConfig.addProgramOptions(m_commonOptions, "common", getName());
m_jsonConfig.addProgramOptions(m_hiddenOptions, "hidden", getName());
}
catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
}
}
Loading
Loading