Skip to content

Commit 404428b

Browse files
committed
Call pollForCompletion if AUB subcapture is active only
Change-Id: I0f5c35efa6c5b828fe88c15084fec03bb24af4e7 Signed-off-by: Milczarek, Slawomir <[email protected]>
1 parent 5bb0d8c commit 404428b

File tree

3 files changed

+138
-7
lines changed

3 files changed

+138
-7
lines changed

runtime/command_stream/aub_command_stream_receiver_hw.inl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ FlushStamp AUBCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
327327
}
328328

329329
if (subCaptureManager->isSubCaptureMode()) {
330+
pollForCompletion();
330331
subCaptureManager->disableSubCapture();
331332
}
332333

@@ -547,6 +548,12 @@ template <typename GfxFamily>
547548
void AUBCommandStreamReceiverHw<GfxFamily>::pollForCompletionImpl() {
548549
this->pollForCompletionTaskCount = this->latestSentTaskCount;
549550

551+
if (subCaptureManager->isSubCaptureMode()) {
552+
if (!subCaptureManager->isSubCaptureEnabled()) {
553+
return;
554+
}
555+
}
556+
550557
if (hardwareContextController) {
551558
hardwareContextController->pollForCompletion();
552559
return;

unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,10 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIs
288288
}
289289

290290
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptureModeWhenProcessResidencyIsCalledButSubCaptureIsDisabledThenItShouldntWriteMemory) {
291+
auto aubSubCaptureManagerMock = std::unique_ptr<AubSubCaptureManagerMock>(new AubSubCaptureManagerMock(""));
291292
auto aubExecutionEnvironment = getEnvironment<MockAubCsr<FamilyType>>(true, true, true);
292293
auto aubCsr = aubExecutionEnvironment->template getCsr<MockAubCsr<FamilyType>>();
293294

294-
auto aubSubCaptureManagerMock = std::unique_ptr<AubSubCaptureManagerMock>(new AubSubCaptureManagerMock(""));
295295
aubSubCaptureManagerMock->subCaptureMode = AubSubCaptureManager::SubCaptureMode::Toggle;
296296
aubSubCaptureManagerMock->disableSubCapture();
297297
aubCsr->subCaptureManager = aubSubCaptureManagerMock.get();
@@ -306,13 +306,13 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptur
306306

307307
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptureModeWhenProcessResidencyIsCalledButAllocationSizeIsZeroThenItShouldntWriteMemory) {
308308
DebugManagerStateRestore stateRestore;
309+
auto aubSubCaptureManagerMock = std::unique_ptr<AubSubCaptureManagerMock>(new AubSubCaptureManagerMock(""));
309310
auto aubExecutionEnvironment = getEnvironment<MockAubCsr<FamilyType>>(true, true, true);
310311
auto aubCsr = aubExecutionEnvironment->template getCsr<MockAubCsr<FamilyType>>();
311312

312313
const DispatchInfo dispatchInfo;
313314
MultiDispatchInfo multiDispatchInfo;
314315
multiDispatchInfo.push(dispatchInfo);
315-
auto aubSubCaptureManagerMock = std::unique_ptr<AubSubCaptureManagerMock>(new AubSubCaptureManagerMock(""));
316316
aubSubCaptureManagerMock->subCaptureMode = AubSubCaptureManager::SubCaptureMode::Toggle;
317317
aubSubCaptureManagerMock->setSubCaptureToggleActive(true);
318318
aubSubCaptureManagerMock->activateSubCapture(multiDispatchInfo);
@@ -327,11 +327,11 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptur
327327
}
328328

329329
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptureModeWhenFlushIsCalledButSubCaptureIsDisabledThenItShouldntInitializeEngineInfo) {
330+
auto aubSubCaptureManagerMock = std::unique_ptr<AubSubCaptureManagerMock>(new AubSubCaptureManagerMock(""));
330331
auto aubExecutionEnvironment = getEnvironment<AUBCommandStreamReceiverHw<FamilyType>>(true, true, true);
331332
auto aubCsr = aubExecutionEnvironment->template getCsr<AUBCommandStreamReceiverHw<FamilyType>>();
332333
LinearStream cs(aubExecutionEnvironment->commandBuffer);
333334

334-
auto aubSubCaptureManagerMock = std::unique_ptr<AubSubCaptureManagerMock>(new AubSubCaptureManagerMock(""));
335335
aubSubCaptureManagerMock->subCaptureMode = AubSubCaptureManager::SubCaptureMode::Toggle;
336336
aubSubCaptureManagerMock->disableSubCapture();
337337
aubCsr->subCaptureManager = aubSubCaptureManagerMock.get();
@@ -436,11 +436,11 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInNonStanda
436436

437437
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandaloneAndSubCaptureModeWhenFlushIsCalledButSubCaptureIsDisabledThenItShouldUpdateHwTagWithLatestSentTaskCount) {
438438
DebugManagerStateRestore stateRestore;
439+
auto aubSubCaptureManagerMock = std::unique_ptr<AubSubCaptureManagerMock>(new AubSubCaptureManagerMock(""));
439440
auto aubExecutionEnvironment = getEnvironment<MockAubCsr<FamilyType>>(true, true, true);
440441
auto aubCsr = aubExecutionEnvironment->template getCsr<MockAubCsr<FamilyType>>();
441442
LinearStream cs(aubExecutionEnvironment->commandBuffer);
442443

443-
auto aubSubCaptureManagerMock = std::unique_ptr<AubSubCaptureManagerMock>(new AubSubCaptureManagerMock(""));
444444
aubSubCaptureManagerMock->subCaptureMode = AubSubCaptureManager::SubCaptureMode::Toggle;
445445
aubSubCaptureManagerMock->disableSubCapture();
446446
aubCsr->subCaptureManager = aubSubCaptureManagerMock.get();
@@ -461,11 +461,11 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon
461461

462462
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInNonStandaloneAndSubCaptureModeWhenFlushIsCalledButSubCaptureIsDisabledThenItShouldNotUpdateHwTagWithLatestSentTaskCount) {
463463
DebugManagerStateRestore stateRestore;
464+
auto aubSubCaptureManagerMock = std::unique_ptr<AubSubCaptureManagerMock>(new AubSubCaptureManagerMock(""));
464465
auto aubExecutionEnvironment = getEnvironment<MockAubCsr<FamilyType>>(true, true, false);
465466
auto aubCsr = aubExecutionEnvironment->template getCsr<MockAubCsr<FamilyType>>();
466467
LinearStream cs(aubExecutionEnvironment->commandBuffer);
467468

468-
auto aubSubCaptureManagerMock = std::unique_ptr<AubSubCaptureManagerMock>(new AubSubCaptureManagerMock(""));
469469
aubSubCaptureManagerMock->subCaptureMode = AubSubCaptureManager::SubCaptureMode::Toggle;
470470
aubSubCaptureManagerMock->disableSubCapture();
471471
aubCsr->subCaptureManager = aubSubCaptureManagerMock.get();
@@ -488,14 +488,14 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInNonStanda
488488
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptureModeWhenFlushIsCalledAndSubCaptureIsEnabledThenItShouldDeactivateSubCapture) {
489489
DebugManagerStateRestore stateRestore;
490490

491+
auto aubSubCaptureManagerMock = std::unique_ptr<AubSubCaptureManagerMock>(new AubSubCaptureManagerMock(""));
491492
auto aubExecutionEnvironment = getEnvironment<MockAubCsr<FamilyType>>(true, true, false);
492493
auto aubCsr = aubExecutionEnvironment->template getCsr<MockAubCsr<FamilyType>>();
493494
LinearStream cs(aubExecutionEnvironment->commandBuffer);
494495

495496
const DispatchInfo dispatchInfo;
496497
MultiDispatchInfo multiDispatchInfo;
497498
multiDispatchInfo.push(dispatchInfo);
498-
auto aubSubCaptureManagerMock = std::unique_ptr<AubSubCaptureManagerMock>(new AubSubCaptureManagerMock(""));
499499
aubSubCaptureManagerMock->subCaptureMode = AubSubCaptureManager::SubCaptureMode::Toggle;
500500
aubSubCaptureManagerMock->setSubCaptureToggleActive(true);
501501
aubSubCaptureManagerMock->activateSubCapture(multiDispatchInfo);
@@ -511,6 +511,32 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptur
511511
EXPECT_FALSE(aubCsr->subCaptureManager->isSubCaptureEnabled());
512512
}
513513

514+
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptureModeWhenFlushIsCalledAndSubCaptureIsEnabledThenItShouldCallPollForCompletion) {
515+
DebugManagerStateRestore stateRestore;
516+
517+
auto aubSubCaptureManagerMock = std::unique_ptr<AubSubCaptureManagerMock>(new AubSubCaptureManagerMock(""));
518+
auto aubExecutionEnvironment = getEnvironment<MockAubCsr<FamilyType>>(true, true, false);
519+
auto aubCsr = aubExecutionEnvironment->template getCsr<MockAubCsr<FamilyType>>();
520+
LinearStream cs(aubExecutionEnvironment->commandBuffer);
521+
522+
const DispatchInfo dispatchInfo;
523+
MultiDispatchInfo multiDispatchInfo;
524+
multiDispatchInfo.push(dispatchInfo);
525+
aubSubCaptureManagerMock->subCaptureMode = AubSubCaptureManager::SubCaptureMode::Toggle;
526+
aubSubCaptureManagerMock->setSubCaptureToggleActive(true);
527+
aubSubCaptureManagerMock->activateSubCapture(multiDispatchInfo);
528+
aubCsr->subCaptureManager = aubSubCaptureManagerMock.get();
529+
ASSERT_TRUE(aubCsr->subCaptureManager->isSubCaptureEnabled());
530+
531+
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
532+
533+
ResidencyContainer allocationsForResidency = {};
534+
535+
aubCsr->flush(batchBuffer, allocationsForResidency);
536+
537+
EXPECT_TRUE(aubCsr->pollForCompletionCalled);
538+
}
539+
514540
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandaloneModeWhenFlushIsCalledThenItShouldCallMakeResidentOnCommandBufferAllocation) {
515541
auto aubExecutionEnvironment = getEnvironment<MockAubCsr<FamilyType>>(true, true, true);
516542
auto aubCsr = aubExecutionEnvironment->template getCsr<MockAubCsr<FamilyType>>();
@@ -610,6 +636,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInNonStanda
610636

611637
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandaloneAndSubCaptureModeWhenFlushIsCalledAndSubCaptureIsEnabledThenItShouldCallMakeResidentOnCommandBufferAndResidencyAllocations) {
612638
DebugManagerStateRestore stateRestore;
639+
auto aubSubCaptureManagerMock = std::unique_ptr<AubSubCaptureManagerMock>(new AubSubCaptureManagerMock(""));
613640
auto aubExecutionEnvironment = getEnvironment<MockAubCsr<FamilyType>>(true, true, true);
614641
auto aubCsr = aubExecutionEnvironment->template getCsr<MockAubCsr<FamilyType>>();
615642
auto memoryManager = aubExecutionEnvironment->executionEnvironment->memoryManager.get();
@@ -619,7 +646,6 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon
619646
const DispatchInfo dispatchInfo;
620647
MultiDispatchInfo multiDispatchInfo;
621648
multiDispatchInfo.push(dispatchInfo);
622-
auto aubSubCaptureManagerMock = std::unique_ptr<AubSubCaptureManagerMock>(new AubSubCaptureManagerMock(""));
623649
aubSubCaptureManagerMock->subCaptureMode = AubSubCaptureManager::SubCaptureMode::Toggle;
624650
aubSubCaptureManagerMock->setSubCaptureToggleActive(true);
625651
aubSubCaptureManagerMock->activateSubCapture(multiDispatchInfo);

unit_tests/command_stream/aub_file_stream_tests.cpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
#include "unit_tests/mocks/mock_aub_csr.h"
1818
#include "unit_tests/mocks/mock_aub_file_stream.h"
1919
#include "unit_tests/mocks/mock_aub_manager.h"
20+
#include "unit_tests/mocks/mock_aub_subcapture_manager.h"
2021
#include "unit_tests/mocks/mock_execution_environment.h"
2122
#include "unit_tests/mocks/mock_graphics_allocation.h"
23+
#include "unit_tests/mocks/mock_mdi.h"
2224
#include "unit_tests/mocks/mock_os_context.h"
2325

2426
#include "driver_version.h"
@@ -325,6 +327,102 @@ HWTEST_F(AubFileStreamTests, givenNewTasksSinceLastPollWhenCallingExpectMemoryTh
325327
EXPECT_TRUE(aubStream->registerPollCalled);
326328
}
327329

330+
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverInSubCaptureModeWhenPollForCompletionIsCalledAndSubCaptureIsEnabledThenItShouldCallRegisterPoll) {
331+
DebugManagerStateRestore stateRestore;
332+
auto aubSubCaptureManagerMock = std::unique_ptr<AubSubCaptureManagerMock>(new AubSubCaptureManagerMock(""));
333+
auto aubStream = std::make_unique<MockAubFileStream>();
334+
auto aubExecutionEnvironment = getEnvironment<MockAubCsr<FamilyType>>(true, true, true);
335+
auto aubCsr = aubExecutionEnvironment->template getCsr<MockAubCsr<FamilyType>>();
336+
aubCsr->stream = aubStream.get();
337+
338+
const DispatchInfo dispatchInfo;
339+
MultiDispatchInfo multiDispatchInfo;
340+
multiDispatchInfo.push(dispatchInfo);
341+
aubSubCaptureManagerMock->subCaptureMode = AubSubCaptureManager::SubCaptureMode::Toggle;
342+
aubSubCaptureManagerMock->setSubCaptureToggleActive(true);
343+
aubSubCaptureManagerMock->activateSubCapture(multiDispatchInfo);
344+
aubCsr->subCaptureManager = aubSubCaptureManagerMock.get();
345+
ASSERT_TRUE(aubCsr->subCaptureManager->isSubCaptureEnabled());
346+
347+
aubCsr->latestSentTaskCount = 50;
348+
aubCsr->pollForCompletionTaskCount = 49;
349+
ASSERT_FALSE(aubStream->registerPollCalled);
350+
351+
aubCsr->pollForCompletion();
352+
353+
EXPECT_TRUE(aubStream->registerPollCalled);
354+
}
355+
356+
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverInSubCaptureModeWhenPollForCompletionIsCalledButSubCaptureIsDisabledThenItShouldntCallRegisterPoll) {
357+
DebugManagerStateRestore stateRestore;
358+
auto aubSubCaptureManagerMock = std::unique_ptr<AubSubCaptureManagerMock>(new AubSubCaptureManagerMock(""));
359+
auto aubStream = std::make_unique<MockAubFileStream>();
360+
auto aubExecutionEnvironment = getEnvironment<MockAubCsr<FamilyType>>(true, true, true);
361+
auto aubCsr = aubExecutionEnvironment->template getCsr<MockAubCsr<FamilyType>>();
362+
aubCsr->stream = aubStream.get();
363+
364+
aubSubCaptureManagerMock->subCaptureMode = AubSubCaptureManager::SubCaptureMode::Toggle;
365+
aubSubCaptureManagerMock->disableSubCapture();
366+
aubCsr->subCaptureManager = aubSubCaptureManagerMock.get();
367+
ASSERT_FALSE(aubCsr->subCaptureManager->isSubCaptureEnabled());
368+
369+
aubCsr->latestSentTaskCount = 50;
370+
aubCsr->pollForCompletionTaskCount = 49;
371+
ASSERT_FALSE(aubStream->registerPollCalled);
372+
373+
aubCsr->pollForCompletion();
374+
375+
EXPECT_FALSE(aubStream->registerPollCalled);
376+
}
377+
378+
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWithHardwareContextInSubCaptureModeWhenPollForCompletionIsCalledAndSubCaptureIsEnabledThenItShouldCallPollForCompletionOnHwContext) {
379+
DebugManagerStateRestore stateRestore;
380+
auto aubSubCaptureManagerMock = std::unique_ptr<AubSubCaptureManagerMock>(new AubSubCaptureManagerMock(""));
381+
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment);
382+
MockOsContext osContext(0, 1, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false);
383+
aubCsr.setupContext(osContext);
384+
auto hardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
385+
386+
const DispatchInfo dispatchInfo;
387+
MultiDispatchInfo multiDispatchInfo;
388+
multiDispatchInfo.push(dispatchInfo);
389+
aubSubCaptureManagerMock->subCaptureMode = AubSubCaptureManager::SubCaptureMode::Toggle;
390+
aubSubCaptureManagerMock->setSubCaptureToggleActive(true);
391+
aubSubCaptureManagerMock->activateSubCapture(multiDispatchInfo);
392+
aubCsr.subCaptureManager = aubSubCaptureManagerMock.get();
393+
ASSERT_TRUE(aubCsr.subCaptureManager->isSubCaptureEnabled());
394+
395+
aubCsr.latestSentTaskCount = 50;
396+
aubCsr.pollForCompletionTaskCount = 49;
397+
ASSERT_FALSE(hardwareContext->pollForCompletionCalled);
398+
399+
aubCsr.pollForCompletion();
400+
401+
EXPECT_TRUE(hardwareContext->pollForCompletionCalled);
402+
}
403+
404+
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWithHardwareContextInSubCaptureModeWhenPollForCompletionIsCalledButSubCaptureIsDisabledThenItShouldntCallPollForCompletionOnHwContext) {
405+
DebugManagerStateRestore stateRestore;
406+
auto aubSubCaptureManagerMock = std::unique_ptr<AubSubCaptureManagerMock>(new AubSubCaptureManagerMock(""));
407+
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment);
408+
MockOsContext osContext(0, 1, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false);
409+
aubCsr.setupContext(osContext);
410+
auto hardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
411+
412+
aubSubCaptureManagerMock->subCaptureMode = AubSubCaptureManager::SubCaptureMode::Toggle;
413+
aubSubCaptureManagerMock->disableSubCapture();
414+
aubCsr.subCaptureManager = aubSubCaptureManagerMock.get();
415+
ASSERT_FALSE(aubCsr.subCaptureManager->isSubCaptureEnabled());
416+
417+
aubCsr.latestSentTaskCount = 50;
418+
aubCsr.pollForCompletionTaskCount = 49;
419+
ASSERT_FALSE(hardwareContext->pollForCompletionCalled);
420+
421+
aubCsr.pollForCompletion();
422+
423+
EXPECT_FALSE(hardwareContext->pollForCompletionCalled);
424+
}
425+
328426
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenMakeResidentIsCalledThenItShouldCallTheExpectedFunctions) {
329427
auto aubExecutionEnvironment = getEnvironment<MockAubCsr<FamilyType>>(true, true, true);
330428
auto aubCsr = aubExecutionEnvironment->template getCsr<MockAubCsr<FamilyType>>();

0 commit comments

Comments
 (0)