2018-11-28 18:09:56 +08:00
|
|
|
/*
|
2019-12-30 21:40:24 +08:00
|
|
|
* Copyright (C) 2018-2020 Intel Corporation
|
2018-11-28 18:09:56 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/memory_manager/deferrable_allocation_deletion.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/command_stream/command_stream_receiver.h"
|
|
|
|
#include "shared/source/helpers/engine_control.h"
|
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
|
|
|
#include "shared/source/os_interface/os_context.h"
|
2018-11-28 18:09:56 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2018-11-28 18:09:56 +08:00
|
|
|
|
|
|
|
DeferrableAllocationDeletion::DeferrableAllocationDeletion(MemoryManager &memoryManager, GraphicsAllocation &graphicsAllocation) : memoryManager(memoryManager),
|
|
|
|
graphicsAllocation(graphicsAllocation) {}
|
2018-11-29 18:20:02 +08:00
|
|
|
bool DeferrableAllocationDeletion::apply() {
|
|
|
|
if (graphicsAllocation.isUsed()) {
|
2019-11-05 20:13:20 +08:00
|
|
|
bool isStillUsed = false;
|
2019-02-18 20:59:16 +08:00
|
|
|
for (auto &engine : memoryManager.getRegisteredEngines()) {
|
|
|
|
auto contextId = engine.osContext->getContextId();
|
|
|
|
if (graphicsAllocation.isUsedByOsContext(contextId)) {
|
|
|
|
auto currentContextTaskCount = *engine.commandStreamReceiver->getTagAddress();
|
|
|
|
if (graphicsAllocation.getTaskCount(contextId) <= currentContextTaskCount) {
|
|
|
|
graphicsAllocation.releaseUsageInOsContext(contextId);
|
|
|
|
} else {
|
2019-11-05 20:13:20 +08:00
|
|
|
isStillUsed = true;
|
2019-02-18 20:59:16 +08:00
|
|
|
engine.commandStreamReceiver->flushBatchedSubmissions();
|
2018-11-28 18:09:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-05 20:13:20 +08:00
|
|
|
if (isStillUsed) {
|
2018-11-29 18:20:02 +08:00
|
|
|
return false;
|
|
|
|
}
|
2018-11-28 18:09:56 +08:00
|
|
|
}
|
|
|
|
memoryManager.freeGraphicsMemory(&graphicsAllocation);
|
2018-11-29 18:20:02 +08:00
|
|
|
return true;
|
2018-11-28 18:09:56 +08:00
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|