refactor: add test for mutex order in enqueueBlit

Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
This commit is contained in:
Maciej Plewka
2025-09-17 11:07:28 +00:00
committed by Compute-Runtime-Automation
parent 8310b10987
commit ea57fb4e2b
3 changed files with 58 additions and 18 deletions

View File

@@ -444,19 +444,19 @@ class CommandQueueHw : public CommandQueue {
TagNodeBase *multiRootDeviceSyncNode,
CsrDependencyContainer *csrDependencies);
CompletionStamp enqueueCommandWithoutKernel(Surface **surfaces,
size_t surfaceCount,
LinearStream *commandStream,
size_t commandStreamStart,
bool &blocking,
const EnqueueProperties &enqueueProperties,
TimestampPacketDependencies &timestampPacketDependencies,
EventsRequest &eventsRequest,
EventBuilder &eventBuilder,
TaskCountType taskLevel,
CsrDependencies &csrDeps,
CommandStreamReceiver *bcsCsr,
bool hasRelaxedOrderingDependencies);
MOCKABLE_VIRTUAL CompletionStamp enqueueCommandWithoutKernel(Surface **surfaces,
size_t surfaceCount,
LinearStream *commandStream,
size_t commandStreamStart,
bool &blocking,
const EnqueueProperties &enqueueProperties,
TimestampPacketDependencies &timestampPacketDependencies,
EventsRequest &eventsRequest,
EventBuilder &eventBuilder,
TaskCountType taskLevel,
CsrDependencies &csrDeps,
CommandStreamReceiver *bcsCsr,
bool hasRelaxedOrderingDependencies);
void processDispatchForCacheFlush(Surface **surfaces,
size_t numSurfaces,
LinearStream *commandStream,

View File

@@ -266,8 +266,10 @@ class MockCommandQueueHw : public CommandQueueHw<GfxFamily> {
using BaseClass = CommandQueueHw<GfxFamily>;
public:
using BaseClass::bcsAllowed;
using BaseClass::bcsEngineCount;
using BaseClass::bcsEngines;
using BaseClass::bcsInitialized;
using BaseClass::bcsQueueEngineType;
using BaseClass::bcsSplitInitialized;
using BaseClass::bcsStates;
@@ -531,6 +533,10 @@ class MockCommandQueueHw : public CommandQueueHw<GfxFamily> {
return this->commandStream;
}
ADDMETHOD(processDispatchForBlitEnqueue, BlitProperties, true, {}, (CommandStreamReceiver & blitCommandStreamReceiver, const MultiDispatchInfo &multiDispatchInfo, TimestampPacketDependencies &timestampPacketDependencies, const EventsRequest &eventsRequest, LinearStream *commandStream, uint32_t commandType, bool queueBlocked, bool profilingEnabled, TagNodeBase *multiRootDeviceEventSync), (blitCommandStreamReceiver, multiDispatchInfo, timestampPacketDependencies, eventsRequest, commandStream, commandType, queueBlocked, profilingEnabled, multiRootDeviceEventSync));
ADDMETHOD(enqueueCommandWithoutKernel, CompletionStamp, true, {}, (Surface * *surfaces, size_t surfaceCount, LinearStream *commandStream, size_t commandStreamStart, bool &blocking, const EnqueueProperties &enqueueProperties, TimestampPacketDependencies &timestampPacketDependencies, EventsRequest &eventsRequest, EventBuilder &eventBuilder, TaskCountType taskLevel, CsrDependencies &csrDeps, CommandStreamReceiver *bcsCsr, bool hasRelaxedOrderingDependencies), (surfaces, surfaceCount, commandStream, commandStreamStart, blocking, enqueueProperties, timestampPacketDependencies, eventsRequest, eventBuilder, taskLevel, csrDeps, bcsCsr, hasRelaxedOrderingDependencies));
std::vector<Kernel *> lastEnqueuedKernels;
MultiDispatchInfo storedMultiDispatchInfo;
BuiltinOpParams kernelParams;

View File

@@ -12,6 +12,7 @@
#include "opencl/source/command_queue/command_queue_hw.h"
#include "opencl/test/unit_test/command_queue/enqueue_fixture.h"
#include "opencl/test/unit_test/fixtures/hello_world_fixture.h"
#include "opencl/test/unit_test/mocks/mock_command_queue.h"
typedef HelloWorldFixture<HelloWorldFixtureFactory> EnqueueKernelFixture;
typedef Test<EnqueueKernelFixture> EnqueueKernelTest;
@@ -88,11 +89,6 @@ HWTEST_TEMPLATED_F(EnqueueKernelTestWithMockCsrHw2, givenCsrInBatchingModeWhenFi
EXPECT_EQ(mockedSubmissionsAggregator->peekInspectionId() - 1u, mockCsr->flushCalledCount);
}
template <typename GfxFamily>
struct MockCommandQueueHw : public CommandQueueHw<GfxFamily> {
using CommandQueue::bcsInitialized;
};
HWTEST_F(EnqueueKernelTest, givenTwoThreadsAndBcsEnabledWhenEnqueueWriteBufferAndEnqueueNDRangeKernelInLoopThenIsNoRace) {
DebugManagerStateRestore debugRestorer;
debugManager.flags.ForceCsrLockInBcsEnqueueOnlyForGpgpuSubmission.set(1);
@@ -594,3 +590,41 @@ HWTEST_F(EnqueueKernelTest, givenBcsEnabledAndQueuePerThreadWhenHalfQueuesEnqueu
retVal = clReleaseContext(context);
EXPECT_EQ(CL_SUCCESS, retVal);
}
HWTEST_F(EnqueueKernelTest, givenCommandQueueAndCsrBlockedWhenEnqueueBlitCalledThenDeadLockIsNotReached) {
using CsrType = UltCommandStreamReceiver<FamilyType>;
HardwareInfo *hwInfo = pDevice->executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo();
hwInfo->capabilityTable.blitterOperationsSupported = true;
REQUIRE_FULL_BLITTER_OR_SKIP(*pDevice->executionEnvironment->rootDeviceEnvironments[0]);
auto mockClDevice = std::make_unique<MockClDevice>(MockDevice::createWithExecutionEnvironment<MockDevice>(hwInfo, pDevice->executionEnvironment, 0));
MockContext context{mockClDevice.get()};
MockCommandQueueHw<FamilyType> commandQueueHw(&context, mockClDevice.get(), nullptr);
commandQueueHw.processDispatchForBlitEnqueueCallBase = false;
commandQueueHw.enqueueCommandWithoutKernelCallBase = false;
commandQueueHw.bcsAllowed = true;
MultiDispatchInfo multiDispatchInfo = {};
auto mockCsr = static_cast<CsrType *>(commandQueueHw.getBcsCommandStreamReceiver(aub_stream::EngineType::ENGINE_BCS));
std::thread th1;
std::thread th2;
{
std::atomic<bool> thread1Started = false;
std::atomic<bool> thread2Started = false;
TakeOwnershipWrapper<CommandQueueHw<FamilyType>> queueOwnership(commandQueueHw);
auto csrOwnership = mockCsr->obtainUniqueOwnership();
th1 = std::thread([&]() {
thread1Started = true;
commandQueueHw.template enqueueBlit<CL_COMMAND_READ_BUFFER>(multiDispatchInfo, 0, nullptr, nullptr, false, *mockCsr, nullptr);
});
th2 = std::thread([&]() {
thread2Started = true;
TakeOwnershipWrapper<CommandQueueHw<FamilyType>> threadQueueOwnership(commandQueueHw);
auto threadCsrOwnership = mockCsr->obtainUniqueOwnership();
});
while (!thread1Started || !thread2Started) {
};
}
th1.join();
th2.join();
}