Refactor TimestampPacket class

Signed-off-by: Bartosz Dunajski <bartosz.dunajski@intel.com>
This commit is contained in:
Bartosz Dunajski
2021-03-22 15:14:49 +00:00
committed by Compute-Runtime-Automation
parent 689028992a
commit 3dc3ad36f8
11 changed files with 159 additions and 128 deletions

View File

@@ -147,24 +147,23 @@ uint64_t Event::getTimestampPacketAddress() {
}
ze_result_t EventImp::calculateProfilingData() {
globalStartTS = timestampsData->packets[0].globalStart;
globalEndTS = timestampsData->packets[0].globalEnd;
contextStartTS = timestampsData->packets[0].contextStart;
contextEndTS = timestampsData->packets[0].contextEnd;
globalStartTS = timestampsData->getGlobalStartValue(0);
globalEndTS = timestampsData->getGlobalEndValue(0);
contextStartTS = timestampsData->getContextStartValue(0);
contextEndTS = timestampsData->getContextEndValue(0);
for (auto i = 1u; i < packetsInUse; i++) {
auto &packet = timestampsData->packets[i];
if (globalStartTS > packet.globalStart) {
globalStartTS = packet.globalStart;
if (globalStartTS > timestampsData->getGlobalStartValue(i)) {
globalStartTS = timestampsData->getGlobalStartValue(i);
}
if (contextStartTS > packet.contextStart) {
contextStartTS = packet.contextStart;
if (contextStartTS > timestampsData->getContextStartValue(i)) {
contextStartTS = timestampsData->getContextStartValue(i);
}
if (contextEndTS < packet.contextEnd) {
contextEndTS = packet.contextEnd;
if (contextEndTS < timestampsData->getContextEndValue(i)) {
contextEndTS = timestampsData->getContextEndValue(i);
}
if (globalEndTS < packet.globalEnd) {
globalEndTS = packet.globalEnd;
if (globalEndTS < timestampsData->getGlobalEndValue(i)) {
globalEndTS = timestampsData->getGlobalEndValue(i);
}
}
@@ -172,20 +171,11 @@ ze_result_t EventImp::calculateProfilingData() {
}
void EventImp::assignTimestampData(void *address) {
auto baseAddr = reinterpret_cast<uint64_t>(address);
uint32_t packetsToCopy = packetsInUse ? packetsInUse : NEO::TimestampPacketSizeControl::preferredPacketCount;
auto copyData = [&](uint32_t &timestampField, auto tsAddr) {
memcpy_s(static_cast<void *>(&timestampField), sizeof(uint32_t), reinterpret_cast<void *>(tsAddr), sizeof(uint32_t));
};
for (uint32_t i = 0; i < packetsToCopy; i++) {
auto &packet = timestampsData->packets[i];
copyData(packet.globalStart, baseAddr + offsetof(TimestampPacketStorage::Packet, globalStart));
copyData(packet.contextStart, baseAddr + offsetof(TimestampPacketStorage::Packet, contextStart));
copyData(packet.globalEnd, baseAddr + offsetof(TimestampPacketStorage::Packet, globalEnd));
copyData(packet.contextEnd, baseAddr + offsetof(TimestampPacketStorage::Packet, contextEnd));
baseAddr += sizeof(struct TimestampPacketStorage::Packet);
timestampsData->assignDataToAllTimestamps(i, address);
address = ptrOffset(address, sizeof(struct TimestampPacketStorage::Packet));
}
}
@@ -215,7 +205,7 @@ ze_result_t EventImp::hostEventSetValueTimestamps(uint32_t eventVal) {
auto baseAddr = reinterpret_cast<uint64_t>(hostAddress);
auto signalScopeFlag = this->signalScope;
auto eventTsSetFunc = [&](auto tsAddr) {
auto eventTsSetFunc = [&eventVal, &signalScopeFlag](auto tsAddr) {
auto tsptr = reinterpret_cast<void *>(tsAddr);
memcpy_s(tsptr, sizeof(uint32_t), static_cast<void *>(&eventVal), sizeof(uint32_t));

View File

@@ -276,11 +276,10 @@ TEST_F(TimestampEventCreate, givenEventTimestampsCreatedWhenResetIsInvokeThenCor
EXPECT_NE(nullptr, event->timestampsData);
for (auto i = 0u; i < NEO::TimestampPacketSizeControl::preferredPacketCount; i++) {
auto &packet = event->timestampsData->packets[i];
EXPECT_EQ(Event::State::STATE_INITIAL, packet.contextStart);
EXPECT_EQ(Event::State::STATE_INITIAL, packet.globalStart);
EXPECT_EQ(Event::State::STATE_INITIAL, packet.contextEnd);
EXPECT_EQ(Event::State::STATE_INITIAL, packet.globalEnd);
EXPECT_EQ(static_cast<uint64_t>(Event::State::STATE_INITIAL), event->timestampsData->getContextStartValue(i));
EXPECT_EQ(static_cast<uint64_t>(Event::State::STATE_INITIAL), event->timestampsData->getGlobalStartValue(i));
EXPECT_EQ(static_cast<uint64_t>(Event::State::STATE_INITIAL), event->timestampsData->getContextEndValue(i));
EXPECT_EQ(static_cast<uint64_t>(Event::State::STATE_INITIAL), event->timestampsData->getGlobalEndValue(i));
}
EXPECT_EQ(0u, event->getPacketsInUse());