Dont print errno for BO binding result after success

Fixes incorrect errors reported for bind and unbind operations
in printfs activated with the debug key PrintBOBindingResult.

Related-To: NEO-5869

Signed-off-by: Milczarek, Slawomir <slawomir.milczarek@intel.com>
This commit is contained in:
Milczarek, Slawomir 2022-02-04 15:28:20 +00:00 committed by Compute-Runtime-Automation
parent 673e954168
commit f02b6cd521
4 changed files with 134 additions and 12 deletions

View File

@ -392,6 +392,110 @@ TEST(DrmBufferObject, givenPerContextVmRequiredWhenBoBoundAndUnboundThenCorrectB
EXPECT_FALSE(bo.bindInfo[contextId][0]);
}
TEST(DrmBufferObject, givenPrintBOBindingResultWhenBOBindAndUnbindSucceedsThenPrintDebugInformationAboutBOBindingResult) {
struct DrmMockToSucceedBindBufferObject : public DrmMock {
DrmMockToSucceedBindBufferObject(RootDeviceEnvironment &rootDeviceEnvironment)
: DrmMock(rootDeviceEnvironment) {}
int bindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObject *bo) override { return 0; }
int unbindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObject *bo) override { return 0; }
};
DebugManagerStateRestore restore;
DebugManager.flags.PrintBOBindingResult.set(true);
auto executionEnvironment = new ExecutionEnvironment;
executionEnvironment->setDebuggingEnabled();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
executionEnvironment->calculateMaxOsContextCount();
executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
auto drm = new DrmMockToSucceedBindBufferObject(*executionEnvironment->rootDeviceEnvironments[0]);
executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(drm));
executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u);
std::unique_ptr<Device> device(MockDevice::createWithExecutionEnvironment<MockDevice>(defaultHwInfo.get(), executionEnvironment, 0));
auto osContextCount = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount();
MockBufferObject bo(drm, 0, 0, osContextCount);
EXPECT_EQ(osContextCount, bo.bindInfo.size());
auto contextId = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount() / 2;
auto osContext = device->getExecutionEnvironment()->memoryManager->getRegisteredEngines()[contextId].osContext;
osContext->ensureContextInitialized();
testing::internal::CaptureStdout();
bo.bind(osContext, 0);
EXPECT_TRUE(bo.bindInfo[contextId][0]);
std::string bindOutput = testing::internal::GetCapturedStdout();
EXPECT_STREQ(bindOutput.c_str(), "bind BO-0 to VM 0, drmVmId = 1, range: 0 - 0, size: 0, result: 0\n");
testing::internal::CaptureStdout();
bo.unbind(osContext, 0);
EXPECT_FALSE(bo.bindInfo[contextId][0]);
std::string unbindOutput = testing::internal::GetCapturedStdout();
EXPECT_STREQ(unbindOutput.c_str(), "unbind BO-0 from VM 0, drmVmId = 1, range: 0 - 0, size: 0, result: 0\n");
}
TEST(DrmBufferObject, givenPrintBOBindingResultWhenBOBindAndUnbindFailsThenPrintDebugInformationAboutBOBindingResultWithErrno) {
struct DrmMockToFailBindBufferObject : public DrmMock {
DrmMockToFailBindBufferObject(RootDeviceEnvironment &rootDeviceEnvironment)
: DrmMock(rootDeviceEnvironment) {}
int bindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObject *bo) override { return -1; }
int unbindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObject *bo) override { return -1; }
int getErrno() override { return EINVAL; }
};
DebugManagerStateRestore restore;
DebugManager.flags.PrintBOBindingResult.set(true);
auto executionEnvironment = new ExecutionEnvironment;
executionEnvironment->setDebuggingEnabled();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
executionEnvironment->calculateMaxOsContextCount();
executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
auto drm = new DrmMockToFailBindBufferObject(*executionEnvironment->rootDeviceEnvironments[0]);
executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(drm));
executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u);
std::unique_ptr<Device> device(MockDevice::createWithExecutionEnvironment<MockDevice>(defaultHwInfo.get(), executionEnvironment, 0));
auto osContextCount = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount();
MockBufferObject bo(drm, 0, 0, osContextCount);
EXPECT_EQ(osContextCount, bo.bindInfo.size());
auto contextId = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount() / 2;
auto osContext = device->getExecutionEnvironment()->memoryManager->getRegisteredEngines()[contextId].osContext;
osContext->ensureContextInitialized();
testing::internal::CaptureStderr();
bo.bind(osContext, 0);
EXPECT_FALSE(bo.bindInfo[contextId][0]);
std::string bindOutput = testing::internal::GetCapturedStderr();
EXPECT_THAT(bindOutput.c_str(), testing::HasSubstr("bind BO-0 to VM 0, drmVmId = 1, range: 0 - 0, size: 0, result: -1, errno: 22"));
testing::internal::CaptureStderr();
bo.bindInfo[contextId][0] = true;
bo.unbind(osContext, 0);
EXPECT_TRUE(bo.bindInfo[contextId][0]);
std::string unbindOutput = testing::internal::GetCapturedStderr();
EXPECT_THAT(unbindOutput.c_str(), testing::HasSubstr("unbind BO-0 from VM 0, drmVmId = 1, range: 0 - 0, size: 0, result: -1, errno: 22"));
}
TEST(DrmBufferObject, whenBindExtHandleAddedThenItIsStored) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);

View File

@ -179,16 +179,35 @@ int BufferObject::exec(uint32_t used, size_t startOffset, unsigned int flags, bo
return err;
}
void BufferObject::printBOBindingResult(OsContext *osContext, uint32_t vmHandleId, bool bind, int retVal) {
if (retVal == 0) {
if (bind) {
PRINT_DEBUG_STRING(DebugManager.flags.PrintBOBindingResult.get(), stdout, "bind BO-%d to VM %u, drmVmId = %u, range: %llx - %llx, size: %lld, result: %d\n",
this->handle, vmHandleId, static_cast<const OsContextLinux *>(osContext)->getDrmVmIds().size() ? static_cast<const OsContextLinux *>(osContext)->getDrmVmIds()[vmHandleId] : 0, this->gpuAddress, ptrOffset(this->gpuAddress, this->size), this->size, retVal);
} else {
PRINT_DEBUG_STRING(DebugManager.flags.PrintBOBindingResult.get(), stdout, "unbind BO-%d from VM %u, drmVmId = %u, range: %llx - %llx, size: %lld, result: %d\n",
this->handle, vmHandleId, static_cast<const OsContextLinux *>(osContext)->getDrmVmIds().size() ? static_cast<const OsContextLinux *>(osContext)->getDrmVmIds()[vmHandleId] : 0, this->gpuAddress, ptrOffset(this->gpuAddress, this->size), this->size, retVal);
}
} else {
auto err = this->drm->getErrno();
if (bind) {
PRINT_DEBUG_STRING(DebugManager.flags.PrintBOBindingResult.get(), stderr, "bind BO-%d to VM %u, drmVmId = %u, range: %llx - %llx, size: %lld, result: %d, errno: %d(%s)\n",
this->handle, vmHandleId, static_cast<const OsContextLinux *>(osContext)->getDrmVmIds().size() ? static_cast<const OsContextLinux *>(osContext)->getDrmVmIds()[vmHandleId] : 0, this->gpuAddress, ptrOffset(this->gpuAddress, this->size), this->size, retVal, err, strerror(err));
} else {
PRINT_DEBUG_STRING(DebugManager.flags.PrintBOBindingResult.get(), stderr, "unbind BO-%d from VM %u, drmVmId = %u, range: %llx - %llx, size: %lld, result: %d, errno: %d(%s)\n",
this->handle, vmHandleId, static_cast<const OsContextLinux *>(osContext)->getDrmVmIds().size() ? static_cast<const OsContextLinux *>(osContext)->getDrmVmIds()[vmHandleId] : 0, this->gpuAddress, ptrOffset(this->gpuAddress, this->size), this->size, retVal, err, strerror(err));
}
}
}
int BufferObject::bind(OsContext *osContext, uint32_t vmHandleId) {
int retVal = 0;
auto contextId = getOsContextId(osContext);
if (!this->bindInfo[contextId][vmHandleId]) {
retVal = this->drm->bindBufferObject(osContext, vmHandleId, this);
auto err = this->drm->getErrno();
PRINT_DEBUG_STRING(DebugManager.flags.PrintBOBindingResult.get(), stderr, "bind BO-%d to VM %u, drmVmId = %u, range: %llx - %llx, size: %lld, result: %d, errno: %d(%s)\n",
this->handle, vmHandleId, static_cast<const OsContextLinux *>(osContext)->getDrmVmIds().size() ? static_cast<const OsContextLinux *>(osContext)->getDrmVmIds()[vmHandleId] : 0, this->gpuAddress, ptrOffset(this->gpuAddress, this->size), this->size, retVal, err, strerror(err));
if (DebugManager.flags.PrintBOBindingResult.get()) {
printBOBindingResult(osContext, vmHandleId, true, retVal);
}
if (!retVal) {
this->bindInfo[contextId][vmHandleId] = true;
}
@ -201,11 +220,9 @@ int BufferObject::unbind(OsContext *osContext, uint32_t vmHandleId) {
auto contextId = getOsContextId(osContext);
if (this->bindInfo[contextId][vmHandleId]) {
retVal = this->drm->unbindBufferObject(osContext, vmHandleId, this);
auto err = this->drm->getErrno();
PRINT_DEBUG_STRING(DebugManager.flags.PrintBOBindingResult.get(), stderr, "unbind BO-%d from VM %u, drmVmId = %u, range: %llx - %llx, size: %lld, result: %d, errno: %d(%s)\n",
this->handle, vmHandleId, static_cast<const OsContextLinux *>(osContext)->getDrmVmIds().size() ? static_cast<const OsContextLinux *>(osContext)->getDrmVmIds()[vmHandleId] : 0, this->gpuAddress, ptrOffset(this->gpuAddress, this->size), this->size, retVal, err, strerror(err));
if (DebugManager.flags.PrintBOBindingResult.get()) {
printBOBindingResult(osContext, vmHandleId, false, retVal);
}
if (!retVal) {
this->bindInfo[contextId][vmHandleId] = false;
}

View File

@ -156,6 +156,7 @@ class BufferObject {
uint32_t getOsContextId(OsContext *osContext);
MOCKABLE_VIRTUAL void fillExecObject(drm_i915_gem_exec_object2 &execObject, OsContext *osContext, uint32_t vmHandleId, uint32_t drmContextId);
void fillExecObjectImpl(drm_i915_gem_exec_object2 &execObject, OsContext *osContext, uint32_t vmHandleId);
void printBOBindingResult(OsContext *osContext, uint32_t vmHandleId, bool bind, int retVal);
void *lockedAddress; // CPU side virtual address

View File

@ -140,8 +140,8 @@ class Drm : public DriverModel {
bool createVirtualMemoryAddressSpace(uint32_t vmCount);
void destroyVirtualMemoryAddressSpace();
uint32_t getVirtualMemoryAddressSpace(uint32_t vmId);
int bindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObject *bo);
int unbindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObject *bo);
MOCKABLE_VIRTUAL int bindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObject *bo);
MOCKABLE_VIRTUAL int unbindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObject *bo);
int setupHardwareInfo(DeviceDescriptor *, bool);
void setupSystemInfo(HardwareInfo *hwInfo, SystemInfo *sysInfo);
void setupCacheInfo(const HardwareInfo &hwInfo);