Fix for deadlock in mapImage scenarios.

- due to the fact that device mutex was obtained to prevent threaded access to
image there was a problem when other thread was also doing readImage call
That thread got read Image kernel mutex first and then it was acquiring device
mutex, which was taken by other thread doing mapImage call.

- In current code device mutex is not taken to service mapImage call, instead
image is being guarded by its own mutex.

Change-Id: Ic4c5a019708d7ec5b240bc5b08c5a65173827392
This commit is contained in:
Mrozek, Michal
2018-01-03 12:23:19 +01:00
parent 5cfb102359
commit ec59a900e1
3 changed files with 47 additions and 5 deletions

View File

@@ -94,6 +94,50 @@ TEST_F(EnqueueMapImageTest, reuseMappedPtrForTiledImg) {
EXPECT_EQ(CL_SUCCESS, retVal);
}
template <typename GfxFamily>
struct mockedImage : public ImageHw<GfxFamily> {
using ImageHw<GfxFamily>::ImageHw;
void setAllocatedMappedPtr(void *allocatedMappedPtr) override {
ownershipTaken = this->hasOwnership();
MemObj::setAllocatedMappedPtr(allocatedMappedPtr);
}
bool ownershipTaken = false;
};
HWTEST_F(EnqueueMapImageTest, givenTiledImageWhenMapImageIsCalledThenStorageIsSetWithImageMutexTaken) {
auto imageFormat = image->getImageFormat();
auto imageDesc = image->getImageDesc();
auto graphicsAllocation = image->getGraphicsAllocation();
auto surfaceFormatInfo = image->getSurfaceFormatInfo();
mockedImage<FamilyType> mockImage(context,
0,
4096u,
nullptr,
imageFormat,
imageDesc,
false,
graphicsAllocation,
true,
true,
0,
&surfaceFormatInfo,
nullptr);
mockImage.createFunction = image->createFunction;
auto mapFlags = CL_MAP_READ;
const size_t origin[3] = {0, 0, 0};
const size_t region[3] = {0, 0, 0};
pCmdQ->enqueueMapImage(
&mockImage, true, mapFlags, origin,
region, nullptr, nullptr, 0,
nullptr, nullptr, retVal);
EXPECT_TRUE(mockImage.ownershipTaken);
}
TEST_F(EnqueueMapImageTest, checkPointer) {
auto mapFlags = CL_MAP_READ;
const size_t origin[3] = {0, 0, 0};