Skip to content
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

ML timeline buffer needs to be 12KB aligned now #8585

Merged
merged 3 commits into from
Oct 31, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ namespace xdp {
}
};

MLTimelineClientDevImpl::MLTimelineClientDevImpl(VPDatabase*dB)
: MLTimelineImpl(dB)
MLTimelineClientDevImpl::MLTimelineClientDevImpl(VPDatabase*dB, uint32_t sz)
: MLTimelineImpl(dB, sz)
{
xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT",
"Created ML Timeline Plugin for Client Device.");
Expand Down Expand Up @@ -134,16 +134,16 @@ namespace xdp {
// Record Timer TS in JSON
// Assuming correct Stub has been called and Write Buffer contains valid data

uint32_t max_count = mBufSz / (3*sizeof(uint32_t));
uint32_t maxCount = mBufSz / RECORD_TIMER_ENTRY_SZ_IN_BYTES;
// Each record timer entry has 32bit ID and 32bit AIE High Timer + 32bit AIE Low Timer value.

uint32_t numEntries = max_count;
uint32_t numEntries = maxCount;
std::stringstream msg;
msg << "A maximum of " << numEntries << " record can be accommodated in given buffer of bytes size 0x"
<< std::hex << mBufSz << std::dec << std::endl;
xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT", msg.str());

if (numEntries <= max_count) {
if (numEntries <= maxCount) {
for (uint32_t i = 0 ; i < numEntries; i++) {
boost::property_tree::ptree ptIdTS;
uint32_t id = *ptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace xdp {
{
std::unique_ptr<ResultBOContainer> mResultBOHolder;
public :
MLTimelineClientDevImpl(VPDatabase* dB);
MLTimelineClientDevImpl(VPDatabase* dB, uint32_t sz);

~MLTimelineClientDevImpl();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

namespace xdp {

// Each record timer entry has 32bit ID and 32bit AIE High Timer + 32bit AIE Low Timer value.
constexpr uint32_t RECORD_TIMER_ENTRY_SZ_IN_BYTES = 3*sizeof(uint32_t);

class VPDatabase;

class MLTimelineImpl
Expand All @@ -30,8 +33,9 @@ namespace xdp {
uint32_t mBufSz;

public:
MLTimelineImpl(VPDatabase* dB)
: db(dB)
MLTimelineImpl(VPDatabase* dB, uint32_t sz)
: db(dB),
mBufSz(sz)
{}

MLTimelineImpl() = delete;
Expand All @@ -40,11 +44,6 @@ namespace xdp {

virtual void updateDevice(void*) = 0;
virtual void finishflushDevice(void*, uint64_t) = 0;

void setBufSize(uint32_t sz)
{
mBufSz = sz;
}
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,47 @@ namespace xdp {

uint32_t ParseMLTimelineBufferSizeConfig()
{
uint32_t bufSz = 0x20000;
uint32_t bufSz = 0;
std::string szCfgStr = xrt_core::config::get_ml_timeline_buffer_size();
std::smatch subStr;

std::stringstream msg;

const std::regex validSzRegEx("\\s*([0-9]+)\\s*(K|k|M|m|)\\s*");
if (std::regex_match(szCfgStr, subStr, validSzRegEx)) {
uint32_t szKB = 0;
try {
if ("K" == subStr[2] || "k" == subStr[2]) {
bufSz = (uint32_t)std::stoull(subStr[1]) * uint_constants::one_kb;
szKB = (uint32_t)std::stoull(subStr[1]);
} else if ("M" == subStr[2] || "m" == subStr[2]) {
bufSz = (uint32_t)std::stoull(subStr[1]) * uint_constants::one_mb;
// Convert to KB now
szKB = (uint32_t)std::stoull(subStr[1]) * uint_constants::one_kb;
}
if (0 != (szKB % RECORD_TIMER_ENTRY_SZ_IN_BYTES)) {
/* Adjust given ML Timeline Buffer Size for alignment to avoid incorrect reads when Host Buffer
* gets overwritten with excess record timer data.
*/
uint32_t q = szKB / RECORD_TIMER_ENTRY_SZ_IN_BYTES;
// Round up to next 12KB aligned size
szKB = (q + 1) * RECORD_TIMER_ENTRY_SZ_IN_BYTES;
bufSz = szKB * uint_constants::one_kb;
std::stringstream amsg;
amsg << "Adjusting given ML Timeline Buffer Size " << szCfgStr
<< " to 0x" << std::hex << bufSz << std::dec << " (in bytes) for alignment." << std::endl;
xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT", amsg.str());
} else if (szKB) {
bufSz = szKB * uint_constants::one_kb;
}

} catch (const std::exception &e) {
std::stringstream msg;
msg << "Invalid string specified for ML Timeline Buffer Size. Using default size of 128KB."
<< e.what() << std::endl;
xrt_core::message::send(xrt_core::message::severity_level::warning, "XRT", msg.str());
msg << "Hit exception " << e.what() << ". ";
}

} else {
xrt_core::message::send(xrt_core::message::severity_level::warning, "XRT",
"Invalid string specified for ML Timeline Buffer Size. Using default size of 128KB.");
}
if (0 == bufSz) {
bufSz = 0x30000;
msg << "Invalid string " << szCfgStr << " specified for ML Timeline Buffer Size. Using default size of 192KB." << std::endl;
xrt_core::message::send(xrt_core::message::severity_level::warning, "XRT", msg.str());
}

return bufSz;
}

Expand Down Expand Up @@ -117,9 +134,8 @@ namespace xdp {
(db->getStaticInfo()).updateDeviceClient(deviceId, coreDevice, false);
(db->getStaticInfo()).setDeviceName(deviceId, winDeviceName);

mMultiImpl[hwCtxImpl] = std::make_pair(implId, std::make_unique<MLTimelineClientDevImpl>(db));
mMultiImpl[hwCtxImpl] = std::make_pair(implId, std::make_unique<MLTimelineClientDevImpl>(db, mBufSz));
auto mlImpl = mMultiImpl[hwCtxImpl].second.get();
mlImpl->setBufSize(mBufSz);
mlImpl->updateDevice(hwCtxImpl);

#endif
Expand Down
Loading