Skip to content

Commit 251149c

Browse files
Fix for CR-1182821: AIE Status was unable to get good data and was outputting empty files (#8178) (#8181)
* Fix for CR-1182821. The issue was race conditions between destructors of global static objects that was exposed with upgrades to petalinux. Signed-off-by: Jason Villarreal <[email protected]> * Removing unintentional space Signed-off-by: Jason Villarreal <[email protected]> --------- Signed-off-by: Jason Villarreal <[email protected]> (cherry picked from commit e21cee0) Co-authored-by: Jason Villarreal <[email protected]>
1 parent 6885947 commit 251149c

File tree

7 files changed

+53
-35
lines changed

7 files changed

+53
-35
lines changed

src/runtime_src/core/edge/user/aie_sys_parser.cpp

+11-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
22
* Copyright (C) 2021 Xilinx, Inc
3+
* Copyright (C) 2024 Advanced Micro Devices, Inc. - All rights reserved
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License"). You may
56
* not use this file except in compliance with the License. A copy of the
@@ -20,8 +21,8 @@
2021

2122
#include <filesystem>
2223

23-
std::fstream aie_sys_parser::sysfs_open_path(const std::string& path,
24-
bool write, bool binary)
24+
std::fstream
25+
aie_sys_parser::sysfs_open_path(const std::string& path, bool write, bool binary) const
2526
{
2627
std::fstream fs;
2728
std::ios::openmode mode = write ? std::ios::out : std::ios::in;
@@ -41,13 +42,14 @@ std::fstream aie_sys_parser::sysfs_open_path(const std::string& path,
4142
return fs;
4243
}
4344

44-
std::fstream aie_sys_parser::sysfs_open(const std::string& entry,
45-
bool write, bool binary)
45+
std::fstream
46+
aie_sys_parser::sysfs_open(const std::string& entry, bool write, bool binary) const
4647
{
4748
return sysfs_open_path(entry, write, binary);
4849
}
4950

50-
void aie_sys_parser::sysfs_get(const std::string& entry, std::vector<std::string>& sv)
51+
void
52+
aie_sys_parser::sysfs_get(const std::string& entry, std::vector<std::string>& sv) const
5153
{
5254
sv.clear();
5355
std::fstream fs = sysfs_open(entry, false, false);
@@ -88,8 +90,7 @@ Function parse the above input content for given row and column and generate abo
8890
Input is in non-standard format, where ':', '|', and "," are the delimiters.
8991
*/
9092
void
91-
aie_sys_parser::addrecursive(const int col, const int row, const std::string& tag, const std::string& line,
92-
boost::property_tree::ptree &pt)
93+
aie_sys_parser::addrecursive(const int col, const int row, const std::string& tag, const std::string& line, boost::property_tree::ptree &pt) const
9394
{
9495
std::string n(tag);
9596
boost::property_tree::ptree value;
@@ -144,9 +145,9 @@ aie_sys_parser::addrecursive(const int col, const int row, const std::string& ta
144145
* If present, reads and parse the content of each sysfs.
145146
*/
146147
boost::property_tree::ptree
147-
aie_sys_parser::aie_sys_read(const int col, const int row)
148+
aie_sys_parser::aie_sys_read(const int col, const int row) const
148149
{
149-
const static std::vector<std::string> tags{"core","dma","lock","errors","event","bd"};
150+
const std::vector<std::string> tags{"core","dma","lock","errors","event","bd"};
150151
std::vector<std::string> data;
151152
boost::property_tree::ptree pt;
152153
for(auto& tag:tags) {
@@ -160,13 +161,6 @@ aie_sys_parser::aie_sys_read(const int col, const int row)
160161
return pt;
161162
}
162163

163-
aie_sys_parser *aie_sys_parser::get_parser(const std::string& aiepart)
164-
{
165-
const std::string sroot = "/sys/class/aie/aiepart_" + aiepart + "/";
166-
static aie_sys_parser dev(sroot);
167-
return &dev;
168-
}
169-
170-
aie_sys_parser::aie_sys_parser(const std::string& root) : sysfs_root(root)
164+
aie_sys_parser::aie_sys_parser(const std::string& root) : sysfs_root("sys/class/aie/aiepart_" + root + "/")
171165
{
172166
}

src/runtime_src/core/edge/user/aie_sys_parser.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
22
* Copyright (C) 2021 Xilinx, Inc
3+
* Copyright (C) 2024 Advanced Micro Devices, Inc. - All rights reserved
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License"). You may
56
* not use this file except in compliance with the License. A copy of the
@@ -24,20 +25,19 @@
2425
class aie_sys_parser {
2526

2627
private:
27-
std::fstream sysfs_open_path(const std::string& path, bool write, bool binary);
28-
std::fstream sysfs_open(const std::string& entry, bool write, bool binary);
29-
void sysfs_get(const std::string& entry, std::vector<std::string>& sv);
28+
std::fstream sysfs_open_path(const std::string& path, bool write, bool binary) const;
29+
std::fstream sysfs_open(const std::string& entry, bool write, bool binary) const;
30+
void sysfs_get(const std::string& entry, std::vector<std::string>& sv) const;
3031
void addrecursive(const int col, const int row, const std::string& tag, const std::string& line,
31-
boost::property_tree::ptree &pt);
32+
boost::property_tree::ptree &pt) const;
3233

3334
std::string sysfs_root;
34-
aie_sys_parser(const std::string& sysfs_base);
3535
aie_sys_parser(const aie_sys_parser& s) = delete;
3636
aie_sys_parser& operator=(const aie_sys_parser& s) = delete;
3737

3838
public:
39-
static aie_sys_parser *get_parser(const std::string& aiepart);
40-
boost::property_tree::ptree aie_sys_read(const int col, const int row);
39+
aie_sys_parser(const std::string& sysfs_base);
40+
boost::property_tree::ptree aie_sys_read(const int col, const int row) const;
4141

4242
};
4343

src/runtime_src/core/edge/user/device_linux.cpp

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright (C) 2020-2022 Xilinx, Inc
3-
// Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
3+
// Copyright (C) 2023-2024 Advanced Micro Devices, Inc. All rights reserved.
44
#include "device_linux.h"
55
#include "xrt.h"
66
#include "zynq_dev.h"
@@ -212,12 +212,13 @@ struct aie_core_info_sysfs
212212
boost::property_tree::ptree ptarray;
213213
aie_metadata_info aie_meta = get_aie_metadata_info(device);
214214
const std::string aiepart = std::to_string(aie_meta.shim_row) + "_" + std::to_string(aie_meta.num_cols);
215+
const aie_sys_parser asp(aiepart);
215216

216217
/* Loop each all aie core tiles and collect core, dma, events, errors, locks status. */
217218
for (int i = 0; i < aie_meta.num_cols; ++i)
218219
for (int j = 0; j < (aie_meta.num_rows-1); ++j)
219220
ptarray.push_back(std::make_pair(std::to_string(i) + "_" + std::to_string(j),
220-
aie_sys_parser::get_parser(aiepart)->aie_sys_read(i,(j + aie_meta.core_row))));
221+
asp.aie_sys_read(i,(j + aie_meta.core_row))));
221222

222223
boost::property_tree::ptree pt;
223224
pt.add_child("aie_core",ptarray);
@@ -239,11 +240,12 @@ struct aie_shim_info_sysfs
239240
boost::property_tree::ptree ptarray;
240241
aie_metadata_info aie_meta = get_aie_metadata_info(device);
241242
const std::string aiepart = std::to_string(aie_meta.shim_row) + "_" + std::to_string(aie_meta.num_cols);
243+
const aie_sys_parser asp(aiepart);
242244

243245
/* Loop all shim tiles and collect all dma, events, errors, locks status */
244246
for (int i=0; i < aie_meta.num_cols; ++i) {
245247
ptarray.push_back(std::make_pair(std::to_string(i) + "_" + std::to_string(aie_meta.shim_row),
246-
aie_sys_parser::get_parser(aiepart)->aie_sys_read(i, aie_meta.shim_row)));
248+
asp.aie_sys_read(i, aie_meta.shim_row)));
247249
}
248250

249251
boost::property_tree::ptree pt;
@@ -266,12 +268,15 @@ struct aie_mem_info_sysfs
266268
boost::property_tree::ptree ptarray;
267269
aie_metadata_info aie_meta = get_aie_metadata_info(device);
268270
const std::string aiepart = std::to_string(aie_meta.shim_row) + "_" + std::to_string(aie_meta.num_cols);
269-
270-
/* Loop all mem tiles and collect all dma, events, errors, locks status */
271-
for (int i = 0; i < aie_meta.num_cols; ++i)
272-
for (int j = 0; j < (aie_meta.num_mem_row-1); ++j)
273-
ptarray.push_back(std::make_pair(std::to_string(i) + "_" + std::to_string(j),
274-
aie_sys_parser::get_parser(aiepart)->aie_sys_read(i,(j + aie_meta.mem_row))));
271+
const aie_sys_parser asp(aiepart);
272+
273+
if (aie_meta.num_mem_row != 0) {
274+
/* Loop all mem tiles and collect all dma, events, errors, locks status */
275+
for (int i = 0; i < aie_meta.num_cols; ++i)
276+
for (int j = 0; j < (aie_meta.num_mem_row-1); ++j)
277+
ptarray.push_back(std::make_pair(std::to_string(i) + "_" + std::to_string(j),
278+
asp.aie_sys_read(i,(j + aie_meta.mem_row))));
279+
}
275280

276281
boost::property_tree::ptree pt;
277282
pt.add_child("aie_mem",ptarray);

src/runtime_src/core/edge/user/shim.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ shim::
141141
xdp::aie::finish_flush_device(this);
142142
#endif
143143
xdp::aie::ctr::end_poll(this);
144-
xdp::aie::sts::end_poll(this);
145144

146145
// The BO cache unmaps and releases all execbo, but this must
147146
// be done before the device (mKernelFD) is closed.

src/runtime_src/core/edge/user/zynq_dev.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
22
* Copyright (C) 2019-2022 Xilinx, Inc
3+
* Copyright (C) 2024 Advanced Micro Devices, Inc. - All rights reserved
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License"). You may
56
* not use this file except in compliance with the License. A copy of the
@@ -21,6 +22,8 @@
2122
#include <regex>
2223
#include "zynq_dev.h"
2324

25+
#include "plugin/xdp/aie_status.h"
26+
2427
static std::fstream sysfs_open_path(const std::string& path, std::string& err,
2528
bool write, bool binary)
2629
{
@@ -153,6 +156,11 @@ zynq_device::zynq_device(const std::string& root) : sysfs_root(root)
153156
{
154157
}
155158

159+
zynq_device::~zynq_device()
160+
{
161+
xdp::aie::sts::end_poll(nullptr);
162+
}
163+
156164
std::string
157165
get_render_devname()
158166
{

src/runtime_src/core/edge/user/zynq_dev.h

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
22
* Copyright (C) 2019-2022 Xilinx, Inc
3+
* Copyright (C) 2024 Advanced Micro Devices, Inc. - All rights reserved
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License"). You may
56
* not use this file except in compliance with the License. A copy of the
@@ -58,6 +59,7 @@ class zynq_device {
5859
zynq_device(const std::string& sysfs_base);
5960
zynq_device(const zynq_device& s) = delete;
6061
zynq_device& operator=(const zynq_device& s) = delete;
62+
~zynq_device();
6163
};
6264

6365
std::string get_render_devname();

src/runtime_src/xdp/profile/plugin/aie_status/aie_status_plugin.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,16 @@ namespace xdp {
447447
// Last chance at writing status reports
448448
for (auto w : writers)
449449
w->write(false, handle);
450-
450+
451+
// When ending polling for a device, if we are on edge we must instead
452+
// shut down all of the threads and not just a single one in order
453+
// to avoid race conditions between the zynq driver destructor and our own.
454+
//
455+
// Currently, Edge is the only supported type of platform so we can
456+
// safely end all threads here, but this must be revisited if we extend
457+
// AIE status functionality to other types of platforms.
458+
endPoll();
459+
/*
451460
// Ask threads to stop
452461
mThreadCtrlMap[handle] = false;
453462
@@ -468,6 +477,7 @@ namespace xdp {
468477
}
469478
470479
mThreadCtrlMap.erase(handle);
480+
*/
471481
}
472482

473483
void AIEStatusPlugin::endPoll()

0 commit comments

Comments
 (0)