fix: use pointer instead of std::function

MSVC Compiler found an issue that there could be an attempt to
reference a deleted function when using std::function.
As the functionality of ioctlHelper::getGpuTime is very straightforward,
simple function pointer should be sufficient to make the job and
it mitigates overhead of std::function.

Related-To: NEO-8324
Signed-off-by: Naklicki, Mateusz <mateusz.naklicki@intel.com>
This commit is contained in:
Naklicki, Mateusz
2023-10-25 00:38:23 +00:00
committed by Compute-Runtime-Automation
parent 157d7a327a
commit 1352bde5c8
4 changed files with 11 additions and 24 deletions

View File

@@ -633,12 +633,12 @@ void IoctlHelper::initializeGetGpuTimeFunction() {
reg.offset = REG_GLOBAL_TIMESTAMP_UN;
err = this->ioctl(DrmIoctl::RegRead, &reg);
if (err) {
this->getGpuTime = getGpuTime32;
this->getGpuTime = &getGpuTime32;
} else {
this->getGpuTime = getGpuTimeSplitted;
this->getGpuTime = &getGpuTimeSplitted;
}
} else {
this->getGpuTime = getGpuTime36;
this->getGpuTime = &getGpuTime36;
}
}
@@ -647,7 +647,7 @@ bool IoctlHelper::setGpuCpuTimes(TimeStampData *pGpuCpuTime, OSTime *osTime) {
return false;
}
if (!this->getGpuTime) {
if (this->getGpuTime == nullptr) {
return false;
}

View File

@@ -15,7 +15,6 @@
#include <cstddef>
#include <cstdint>
#include <functional>
#include <memory>
#include <optional>
#include <string>
@@ -168,7 +167,7 @@ class IoctlHelper {
virtual void initializeGetGpuTimeFunction();
virtual bool setGpuCpuTimes(TimeStampData *pGpuCpuTime, OSTime *osTime);
std::function<bool(::NEO::Drm &, uint64_t *)> getGpuTime;
bool (*getGpuTime)(::NEO::Drm &, uint64_t *) = nullptr;
protected:
Drm &drm;

View File

@@ -649,17 +649,13 @@ TEST_F(IoctlPrelimHelperTests, whenGettingTimeThenTimeIsCorrect) {
ASSERT_EQ(true, ioctlHelper.initialize());
{
auto p = ioctlHelper.getGpuTime;
bool (*const *ptr)(Drm &, uint64_t *) = p.target<bool (*)(Drm &, uint64_t *)>();
EXPECT_EQ(*ptr, &::NEO::getGpuTime36);
EXPECT_EQ(ioctlHelper.getGpuTime, &getGpuTime36);
}
{
drm->ioctlRes = -1;
ioctlHelper.initializeGetGpuTimeFunction();
auto p = ioctlHelper.getGpuTime;
bool (*const *ptr)(Drm &, uint64_t *) = p.target<bool (*)(Drm &, uint64_t *)>();
EXPECT_EQ(*ptr, &::NEO::getGpuTime32);
EXPECT_EQ(ioctlHelper.getGpuTime, &getGpuTime32);
}
DrmMockCustom::IoctlResExt ioctlToPass = {1, 0};
@@ -668,9 +664,7 @@ TEST_F(IoctlPrelimHelperTests, whenGettingTimeThenTimeIsCorrect) {
drm->ioctlRes = -1;
drm->ioctlResExt = &ioctlToPass; // 2nd ioctl is successful
ioctlHelper.initializeGetGpuTimeFunction();
auto p = ioctlHelper.getGpuTime;
bool (*const *ptr)(Drm &, uint64_t *) = p.target<bool (*)(Drm &, uint64_t *)>();
EXPECT_EQ(*ptr, &::NEO::getGpuTimeSplitted);
EXPECT_EQ(ioctlHelper.getGpuTime, &getGpuTimeSplitted);
drm->ioctlResExt = &drm->none;
}
}

View File

@@ -759,17 +759,13 @@ TEST(IoctlHelperTestsUpstream, whenGettingTimeThenTimeIsCorrect) {
ASSERT_EQ(true, ioctlHelper.initialize());
{
auto p = ioctlHelper.getGpuTime;
bool (*const *ptr)(Drm &, uint64_t *) = p.target<bool (*)(Drm &, uint64_t *)>();
EXPECT_EQ(*ptr, &::NEO::getGpuTime36);
EXPECT_EQ(ioctlHelper.getGpuTime, &getGpuTime36);
}
{
drm->ioctlRes = -1;
ioctlHelper.initializeGetGpuTimeFunction();
auto p = ioctlHelper.getGpuTime;
bool (*const *ptr)(Drm &, uint64_t *) = p.target<bool (*)(Drm &, uint64_t *)>();
EXPECT_EQ(*ptr, &::NEO::getGpuTime32);
EXPECT_EQ(ioctlHelper.getGpuTime, &getGpuTime32);
}
DrmMockCustom::IoctlResExt ioctlToPass = {1, 0};
@@ -778,9 +774,7 @@ TEST(IoctlHelperTestsUpstream, whenGettingTimeThenTimeIsCorrect) {
drm->ioctlRes = -1;
drm->ioctlResExt = &ioctlToPass; // 2nd ioctl is successful
ioctlHelper.initializeGetGpuTimeFunction();
auto p = ioctlHelper.getGpuTime;
bool (*const *ptr)(Drm &, uint64_t *) = p.target<bool (*)(Drm &, uint64_t *)>();
EXPECT_EQ(*ptr, &::NEO::getGpuTimeSplitted);
EXPECT_EQ(ioctlHelper.getGpuTime, &getGpuTimeSplitted);
drm->ioctlResExt = &drm->none;
}
}