Repository: Xilinx/XRT
Pull request #8799: CR-1228350 fix : Virtualizing configure options for alveo/pcie 
Author: login: aktondak
Created: 2025-03-04T19:36:49Z | Merged: 2025-03-05T00:15:53Z

<!-- Thanks for sending a pull request! Please fill out below, remove sections that don't apply for your pull request.  -->
#### Problem solved by the commit
This PR changes the xrt-smi configure options for alveo/edge case vs MCDM/XDNA case. MCDM and XDNA will have a minimal list of configure options

#### Bug / issue (if any) fixed, which PR introduced the bug, how it was discovered
https://jira.xilinx.com/browse/CR-1228350

#### How problem was solved, alternative solutions (if any) and why they were rejected
The problem was solved by creating a default structure configure options for the default, alveo and edge cases which consists of a list of all options. This structure will be overridden by MCDM and XDNA shims to only show a minimal list of configure options.

#### Risks (if any) associated the changes in the commit
None

#### What has been tested and how, request additional testing if necessary
Tested on windows platform

#### Documentation impact (if any)
None



Diff:
diff --git a/src/runtime_src/core/common/smi.cpp b/src/runtime_src/core/common/smi.cpp
index fb5bf09a14a..9974c14eb0d 100644
--- a/src/runtime_src/core/common/smi.cpp
+++ b/src/runtime_src/core/common/smi.cpp
@@ -43,13 +43,15 @@ to_ptree() const
 }
 
 smi_base::
-smi_base()
-{
-
-  examine_report_desc = {
+smi_base() : 
+  examine_report_desc {
     {"host", "Host information", "common"}
-  };
-}
+  },
+  configure_options {
+    {"device", "d", "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", "common", "", "string"},
+    {"help", "h", "Help to use this sub-command", "common", "", "none"}
+  }
+{}
 
 std::vector<basic_option> 
 smi_base::
@@ -131,22 +133,8 @@ construct_configure_subcommand() const
   subcommand.put("type", "common");
   subcommand.put("description", "Device and host configuration");
 
-  std::vector<option> options = {
-    {"device", "d", "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", "common", "", "string"},
-    {"help", "h", "Help to use this sub-command", "common", "", "none"},
-    {"daemon", "", "Update the device daemon configuration", "hidden", "", "none"},
-    {"purge", "", "Remove the daemon configuration file", "hidden", "", "string"},
-    {"host", "", "IP or hostname for device peer", "hidden", "", "string"},
-    {"security", "", "Update the security level for the device", "hidden", "", "string"},
-    {"clk_throttle", "", "Enable/disable the device clock throttling", "hidden", "", "string"},
-    {"ct_threshold_power_override", "", "Update the power threshold in watts", "hidden", "", "string"},
-    {"ct_threshold_temp_override", "", "Update the temperature threshold in celsius", "hidden", "", "string"},
-    {"ct_reset", "", "Reset all throttling options", "hidden", "", "string"},
-    {"showx", "", "Display the device configuration settings", "hidden", "", "string"}
-  };
-
   ptree options_ptree;
-  for (const auto& option : options) {
+  for (const auto& option : configure_options) {
     options_ptree.push_back(std::make_pair("", option.to_ptree()));
   }
 
diff --git a/src/runtime_src/core/common/smi.h b/src/runtime_src/core/common/smi.h
index e18f8909ef2..09465283089 100644
--- a/src/runtime_src/core/common/smi.h
+++ b/src/runtime_src/core/common/smi.h
@@ -54,6 +54,7 @@ class smi_base {
 
   tuple_vector validate_test_desc;
   tuple_vector examine_report_desc;
+  std::vector<option> configure_options;
 
   std::vector<basic_option> 
   construct_option_description(const tuple_vector&) const;
diff --git a/src/runtime_src/core/edge/user/smi.cpp b/src/runtime_src/core/edge/user/smi.cpp
index 80854ada3c1..c9396930a2d 100644
--- a/src/runtime_src/core/edge/user/smi.cpp
+++ b/src/runtime_src/core/edge/user/smi.cpp
@@ -37,6 +37,20 @@ smi_edge() : smi_base()
     {"qspi-status", "QSPI write protection status", "common"},
     {"thermal", "Thermal sensors present on the device", "common"}
   };
+
+  configure_options = {
+    {"device", "d", "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", "common", "", "string"},
+    {"help", "h", "Help to use this sub-command", "common", "", "none"},
+    {"daemon", "", "Update the device daemon configuration", "hidden", "", "none"},
+    {"purge", "", "Remove the daemon configuration file", "hidden", "", "string"},
+    {"host", "", "IP or hostname for device peer", "hidden", "", "string"},
+    {"security", "", "Update the security level for the device", "hidden", "", "string"},
+    {"clk_throttle", "", "Enable/disable the device clock throttling", "hidden", "", "string"},
+    {"ct_threshold_power_override", "", "Update the power threshold in watts", "hidden", "", "string"},
+    {"ct_threshold_temp_override", "", "Update the temperature threshold in celsius", "hidden", "", "string"},
+    {"ct_reset", "", "Reset all throttling options", "hidden", "", "string"},
+    {"showx", "", "Display the device configuration settings", "hidden", "", "string"}
+  };
 }
 
 // Create an instance of the derived class
diff --git a/src/runtime_src/core/pcie/linux/smi.cpp b/src/runtime_src/core/pcie/linux/smi.cpp
index aacfa45c69c..ea1375b5eb6 100644
--- a/src/runtime_src/core/pcie/linux/smi.cpp
+++ b/src/runtime_src/core/pcie/linux/smi.cpp
@@ -39,6 +39,20 @@ smi_pcie() : smi_base()
     {"qspi-status", "QSPI write protection status", "common"},
     {"thermal", "Thermal sensors present on the device", "common"}
   };
+
+  configure_options = {
+    {"device", "d", "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", "common", "", "string"},
+    {"help", "h", "Help to use this sub-command", "common", "", "none"},
+    {"daemon", "", "Update the device daemon configuration", "hidden", "", "none"},
+    {"purge", "", "Remove the daemon configuration file", "hidden", "", "string"},
+    {"host", "", "IP or hostname for device peer", "hidden", "", "string"},
+    {"security", "", "Update the security level for the device", "hidden", "", "string"},
+    {"clk_throttle", "", "Enable/disable the device clock throttling", "hidden", "", "string"},
+    {"ct_threshold_power_override", "", "Update the power threshold in watts", "hidden", "", "string"},
+    {"ct_threshold_temp_override", "", "Update the temperature threshold in celsius", "hidden", "", "string"},
+    {"ct_reset", "", "Reset all throttling options", "hidden", "", "string"},
+    {"showx", "", "Display the device configuration settings", "hidden", "", "string"}
+  };
 }
 
 // Create an instance of the derived class


Reviews:
user: login: AShivangi
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-04T19:40:53Z
user: login: aktondak
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-04T19:55:00Z
user: login: AShivangi
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-04T19:55:27Z
user: login: aktondak
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-04T20:43:40Z
user: login: AShivangi
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-03-04T21:18:37Z

Review comments:
diff_hunk: @@ -49,6 +49,20 @@ smi_base()
   examine_report_desc = {
     {"host", "Host information", "common"}
   };
+
+  configure_options = {
path: src/runtime_src/core/common/smi.cpp
user: login: AShivangi
body: shouldn't this go in alveo/smi.cpp?
created_at: 2025-03-04T19:40:52Z
author_association: COLLABORATOR
diff_hunk: @@ -49,6 +49,20 @@ smi_base()
   examine_report_desc = {
     {"host", "Host information", "common"}
   };
+
+  configure_options = {
path: src/runtime_src/core/common/smi.cpp
user: login: aktondak
body: I have updated the change.
Now the default behavior is a minimal list of 2 options which are going to be used by MCDM and XDNA shims.
edge and pcie shims have this exhaustive list 
created_at: 2025-03-04T19:55:00Z
author_association: COLLABORATOR
diff_hunk: @@ -37,6 +37,20 @@ smi_edge() : smi_base()
     {"qspi-status", "QSPI write protection status", "common"},
     {"thermal", "Thermal sensors present on the device", "common"}
   };
+
+  configure_options = {
+    {"device", "d", "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", "common", "", "string"},
+    {"help", "h", "Help to use this sub-command", "common", "", "none"},
path: src/runtime_src/core/edge/user/smi.cpp
user: login: AShivangi
body: Is it ok if these are repeated?
created_at: 2025-03-04T19:55:27Z
author_association: COLLABORATOR
diff_hunk: @@ -37,6 +37,20 @@ smi_edge() : smi_base()
     {"qspi-status", "QSPI write protection status", "common"},
     {"thermal", "Thermal sensors present on the device", "common"}
   };
+
+  configure_options = {
+    {"device", "d", "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", "common", "", "string"},
+    {"help", "h", "Help to use this sub-command", "common", "", "none"},
path: src/runtime_src/core/edge/user/smi.cpp
user: login: aktondak
body: configure_options structure is used as a whole. These are not repeated since the whole vector is constructed for smi_edge
created_at: 2025-03-04T20:43:39Z
author_association: COLLABORATOR

PR comments:
user: login: gbuildx
created_at: 2025-03-04T19:38:03Z
body: Can one of the admins verify this patch?
author_association: COLLABORATOR
user: login: stsoe
created_at: 2025-03-04T22:12:20Z
body: Before this gets out of hand, I thought I would mention that clang-tidy is unhappy about protected data members.  A cpp core guideline is that we should avoid protected data members. 
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c133-avoid-protected-data

For the validata_test_desc and examine_report_desc, it is better to make these private and have constructors that take tuple vector by value and moves the content into the private data members.   Why?  Because if you tomorrow need to change the content of tuple vector (new element or reordered element), then you can add tuple_vector_extended as data members while still preserving compatibility for old tuple_vector constructors, which now of course would have to transform into tuple_vector_extended.

This may not seem overly important as we manage all uses of smi across our projects, but imagine a true exported API, where ABI compatibility is required.  It would sure be a disaster to use protected data members in such a case.
author_association: COLLABORATOR
user: login: aktondak
created_at: 2025-03-05T17:00:16Z
body: > Before this gets out of hand, I thought I would mention that clang-tidy is unhappy about protected data members. A cpp core guideline is that we should avoid protected data members. https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c133-avoid-protected-data
> 
> For the validata_test_desc and examine_report_desc, it is better to make these private and have constructors that take tuple vector by value and moves the content into the private data members. Why? Because if you tomorrow need to change the content of tuple vector (new element or reordered element), then you can add tuple_vector_extended as data members while still preserving compatibility for old tuple_vector constructors, which now of course would have to transform into tuple_vector_extended.
> 
> This may not seem overly important as we manage all uses of smi across our projects, but imagine a true exported API, where ABI compatibility is required. It would sure be a disaster to use protected data members in such a case.

I agree with this. Thanks for the feedback.
I'll take care of this in a future change since this is already merged. 
author_association: COLLABORATOR