Skip to content

Commit

Permalink
VITIS-13557 Display clocks on-demand (Xilinx#8520)
Browse files Browse the repository at this point in the history
* move clock reporting to advanced

Signed-off-by: AShivangi <[email protected]>

* rename some files

Signed-off-by: AShivangi <[email protected]>

---------

Signed-off-by: AShivangi <[email protected]>
  • Loading branch information
AShivangi authored Oct 14, 2024
1 parent efa944b commit 344019f
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 29 deletions.
56 changes: 29 additions & 27 deletions src/runtime_src/core/common/info_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,32 +333,6 @@ enum_to_str(CLOCK_TYPE type)
}
}

void
add_clock_info(const xrt_core::device* device, ptree_type& pt)
{
ptree_type pt_clock_array;

try {
auto raw = xrt_core::device_query<xq::clock_freq_topology_raw>(device);
if (raw.empty())
return;

ptree_type pt_clocks;
auto clock_topology = reinterpret_cast<const clock_freq_topology*>(raw.data());
for (int i = 0; i < clock_topology->m_count; i++) {
ptree_type pt_clock;
pt_clock.add("id", clock_topology->m_clock_freq[i].m_name);
pt_clock.add("description", enum_to_str(static_cast<CLOCK_TYPE>(clock_topology->m_clock_freq[i].m_type)));
pt_clock.add("freq_mhz", clock_topology->m_clock_freq[i].m_freq_Mhz);
pt_clock_array.push_back(std::make_pair("", pt_clock));
}
pt.put_child("clocks", pt_clock_array);
}
catch (const xq::no_such_key&) {
// ignoring if not available: Edge Case
}
}

void
add_tops_info(const xrt_core::device* device, ptree_type& pt)
{
Expand Down Expand Up @@ -463,7 +437,8 @@ add_platform_info(const xrt_core::device* device, ptree_type& pt_platform_array)
else
add_controller_info(device, pt_platform);
add_mac_info(device, pt_platform);
add_clock_info(device, pt_platform);
auto pt_clock_array = xrt_core::platform::get_clock_info(device);
pt_platform.put_child("clocks", pt_clock_array);
add_config_info(device, pt_platform);
break;
}
Expand All @@ -484,6 +459,33 @@ add_platform_info(const xrt_core::device* device, ptree_type& pt_platform_array)

namespace xrt_core { namespace platform {

ptree_type
get_clock_info(const xrt_core::device* device)
{
ptree_type pt;

try {
auto raw = xrt_core::device_query<xq::clock_freq_topology_raw>(device);
if (raw.empty())
return pt;

ptree_type pt_clock_array;
auto clock_topology = reinterpret_cast<const clock_freq_topology*>(raw.data());
for (int i = 0; i < clock_topology->m_count; i++) {
ptree_type pt_clock;
pt_clock.add("id", clock_topology->m_clock_freq[i].m_name);
pt_clock.add("description", enum_to_str(static_cast<CLOCK_TYPE>(clock_topology->m_clock_freq[i].m_type)));
pt_clock.add("freq_mhz", clock_topology->m_clock_freq[i].m_freq_Mhz);
pt_clock_array.push_back(std::make_pair("", pt_clock));
}
pt.put_child("clocks", pt_clock_array);
}
catch (const xq::no_such_key&) {
// ignoring if not available: Edge Case
}
return pt;
}

ptree_type
platform_info(const xrt_core::device* device)
{
Expand Down
4 changes: 4 additions & 0 deletions src/runtime_src/core/common/info_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ XRT_CORE_COMMON_EXPORT
boost::property_tree::ptree
pcie_info(const xrt_core::device* device);

XRT_CORE_COMMON_EXPORT
boost::property_tree::ptree
get_clock_info(const xrt_core::device* device);

}} // platform, xrt

#endif
1 change: 1 addition & 0 deletions src/runtime_src/core/tools/xbutil2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ file(GLOB XBUTIL_V2_SUBCMD_FILES
"OO_HostMem.cpp"
"OO_Performance.cpp"
"OO_Preemption.cpp"
"OO_Reports.cpp"
)

# Merge the files into one collection
Expand Down
108 changes: 108 additions & 0 deletions src/runtime_src/core/tools/xbutil2/OO_Reports.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.

// ------ I N C L U D E F I L E S -------------------------------------------
// Local - Include Files
#include "OO_Reports.h"
#include "tools/common/XBUtilitiesCore.h"
#include "tools/common/XBUtilities.h"
#include "tools/common/XBHelpMenusCore.h"
#include "core/common/info_platform.h"

// 3rd Party Library - Include Files
#include <boost/program_options.hpp>
#include <boost/algorithm/string.hpp>
namespace po = boost::program_options;
using bpt = boost::property_tree::ptree;

// ----- C L A S S M E T H O D S -------------------------------------------

OO_Reports::OO_Reports( const std::string &_longName, bool _isHidden )
: OptionOptions(_longName, _isHidden, "Hidden reports")
, m_device("")
, m_action("")
, m_help(false)
{
m_optionsDescription.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")
("mode", boost::program_options::value<decltype(m_action)>(&m_action)->required(), "Action to perform: clocks")
;

m_positionalOptions.
add("mode", 1 /* max_count */)
;
}

void
OO_Reports::execute(const SubCmdOptions& _options) const
{
XBUtilities::verbose("SubCommand option: report");

XBUtilities::verbose("Option(s):");
for (auto & aString : _options)
XBUtilities::verbose(std::string(" ") + aString);

// Honor help option first
if (std::find(_options.begin(), _options.end(), "--help") != _options.end()) {
printHelp();
return;
}

// Parse sub-command ...
po::variables_map vm;

try {
po::options_description all_options("All Options");
all_options.add(m_optionsDescription);
po::command_line_parser parser(_options);
XBUtilities::process_arguments(vm, parser, all_options, m_positionalOptions, true);
} catch(boost::program_options::error&) {
if(m_help) {
printHelp();
throw xrt_core::error(std::errc::operation_canceled);
}
// Exit if neither action or device specified
if(m_action.empty()) {
std::cerr << boost::format("ERROR: the required argument for option '--report' is missing\n");
printHelp();
throw xrt_core::error(std::errc::operation_canceled);
}
}

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

try {
device = XBUtilities::get_device(boost::algorithm::to_lower_copy(m_device), true /*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();
throw xrt_core::error(std::errc::operation_canceled);
}

try {
if (boost::iequals(m_action, "clock")) {
bpt empty_tree;
auto clocks = xrt_core::platform::get_clock_info(device.get());
const bpt& pt_clock_array = clocks.get_child("clocks", empty_tree);
if(pt_clock_array.empty())
return;

std::cout << std::endl << "Clocks" << std::endl;
for (const auto& kc : pt_clock_array) {
const bpt& pt_clock = kc.second;
std::string clock_name_type = pt_clock.get<std::string>("id");
std::cout << boost::format(" %-23s: %3s MHz\n") % clock_name_type % pt_clock.get<std::string>("freq_mhz");
}
}
else {
throw xrt_core::error(boost::str(boost::format("Invalid report value: '%s'\n") % m_action));
}
}
catch(const xrt_core::error& e) {
std::cerr << boost::format("\nERROR: %s\n") % e.what();
printHelp();
throw xrt_core::error(std::errc::operation_canceled);
}
}
22 changes: 22 additions & 0 deletions src/runtime_src/core/tools/xbutil2/OO_Reports.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.

#ifndef __OO_Reports_h_
#define __OO_Reports_h_

#include "tools/common/OptionOptions.h"

class OO_Reports : public OptionOptions {
public:
virtual void execute( const SubCmdOptions &_options ) const;

public:
OO_Reports( const std::string &_longName, bool _isHidden = false);

private:
std::string m_device;
std::string m_action;
bool m_help;
};

#endif
4 changes: 3 additions & 1 deletion src/runtime_src/core/tools/xbutil2/SubCmdAdvanced.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2020-2022 Xilinx, Inc
// Copyright (C) 2022-2023 Advanced Micro Devices, Inc. All rights reserved.
// Copyright (C) 2022-2024 Advanced Micro Devices, Inc. All rights reserved.

// ------ I N C L U D E F I L E S -------------------------------------------
// Local - Include Files
#include "OO_AieClockFreq.h"
#include "OO_AieRegRead.h"
#include "OO_MemRead.h"
#include "OO_MemWrite.h"
#include "OO_Reports.h"
#include "SubCmdAdvanced.h"

#include "common/device.h"
Expand Down Expand Up @@ -51,6 +52,7 @@ SubCmdAdvanced::SubCmdAdvanced(bool _isHidden, bool _isDepricated, bool _isPreli

addSubOption(std::make_shared<OO_MemRead>("read-mem"));
addSubOption(std::make_shared<OO_MemWrite>("write-mem"));
addSubOption(std::make_shared<OO_Reports>("report"));
// Only defined for embedded platform
#ifndef ENABLE_NATIVE_SUBCMDS_AND_REPORTS
addSubOption(std::make_shared<OO_AieRegRead>("read-aie-reg"));
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/tools/xbutil2/xbutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ R"(
}]
},{
"advanced":[{
"suboption": ["read-aie-reg", "aie-clock"]
"suboption": ["read-aie-reg", "aie-clock", "report"]
}]
},{
"validate": [{
Expand Down

0 comments on commit 344019f

Please sign in to comment.