From 2c896b64b4927e5b526da02196a348a0abb84616 Mon Sep 17 00:00:00 2001 From: "Mrozek, Michal" Date: Fri, 11 May 2018 08:10:18 +0200 Subject: [PATCH] DrmGemCloseWorker now works on BufferObject instead of DrmAllocation. Change-Id: I490edfc7532081eb31f700be70781c276dbc2916 --- .../os_interface/linux/drm_gem_close_worker.cpp | 14 +++++--------- runtime/os_interface/linux/drm_gem_close_worker.h | 8 ++++---- .../linux/drm_gem_close_worker_tests.cpp | 12 ++++-------- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/runtime/os_interface/linux/drm_gem_close_worker.cpp b/runtime/os_interface/linux/drm_gem_close_worker.cpp index 40fe047d17..fcd9e8eb5a 100644 --- a/runtime/os_interface/linux/drm_gem_close_worker.cpp +++ b/runtime/os_interface/linux/drm_gem_close_worker.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -54,7 +54,7 @@ DrmGemCloseWorker::~DrmGemCloseWorker() { closeThread(); } -void DrmGemCloseWorker::push(DrmAllocation *bo) { +void DrmGemCloseWorker::push(BufferObject *bo) { std::unique_lock lock(closeWorkerMutex); workCount++; queue.push(bo); @@ -74,19 +74,15 @@ bool DrmGemCloseWorker::isEmpty() { return workCount.load() == 0; } -inline void DrmGemCloseWorker::close(DrmAllocation *alloc) { - auto bo = alloc->getBO(); - +inline void DrmGemCloseWorker::close(BufferObject *bo) { bo->wait(-1); memoryManager.unreference(bo); workCount--; - - delete alloc; } void DrmGemCloseWorker::worker() { - DrmAllocation *workItem = nullptr; - std::queue localQueue; + BufferObject *workItem = nullptr; + std::queue localQueue; std::unique_lock lock(closeWorkerMutex); lock.unlock(); diff --git a/runtime/os_interface/linux/drm_gem_close_worker.h b/runtime/os_interface/linux/drm_gem_close_worker.h index d6f9289f01..16618a4a1c 100644 --- a/runtime/os_interface/linux/drm_gem_close_worker.h +++ b/runtime/os_interface/linux/drm_gem_close_worker.h @@ -32,7 +32,7 @@ namespace OCLRT { class DrmMemoryManager; -class DrmAllocation; +class BufferObject; enum gemCloseWorkerMode { gemCloseWorkerInactive, @@ -47,20 +47,20 @@ class DrmGemCloseWorker { DrmGemCloseWorker(const DrmGemCloseWorker &) = delete; DrmGemCloseWorker &operator=(const DrmGemCloseWorker &) = delete; - void push(DrmAllocation *allocation); + void push(BufferObject *allocation); void close(bool blocking); bool isEmpty(); protected: - void close(DrmAllocation *workItem); + void close(BufferObject *workItem); void closeThread(); void worker(); bool active; std::thread *thread; - std::queue queue; + std::queue queue; std::atomic workCount; DrmMemoryManager &memoryManager; diff --git a/unit_tests/os_interface/linux/drm_gem_close_worker_tests.cpp b/unit_tests/os_interface/linux/drm_gem_close_worker_tests.cpp index 4180f03cdc..15885fe751 100644 --- a/unit_tests/os_interface/linux/drm_gem_close_worker_tests.cpp +++ b/unit_tests/os_interface/linux/drm_gem_close_worker_tests.cpp @@ -112,9 +112,8 @@ TEST_F(DrmGemCloseWorkerTests, gemClose) { auto worker = new DrmGemCloseWorker(*mm); auto bo = new BufferObjectWrapper(this->drmMock, 1); - auto alloc = new DrmAllocationWrapper(bo); - worker->push(alloc); + worker->push(bo); delete worker; } @@ -124,9 +123,8 @@ TEST_F(DrmGemCloseWorkerTests, gemCloseExit) { auto worker = new DrmGemCloseWorker(*mm); auto bo = new BufferObjectWrapper(this->drmMock, 1); - auto alloc = new DrmAllocationWrapper(bo); - worker->push(alloc); + worker->push(bo); //wait for worker to complete or deadCnt drops while (!worker->isEmpty() && (deadCnt-- > 0)) @@ -145,9 +143,8 @@ TEST_F(DrmGemCloseWorkerTests, close) { auto worker = new DrmGemCloseWorker(*mm); auto bo = new BufferObjectWrapper(this->drmMock, 1); - auto alloc = new DrmAllocationWrapper(bo); - worker->push(alloc); + worker->push(bo); worker->close(false); //wait for worker to complete or deadCnt drops @@ -164,10 +161,9 @@ TEST_F(DrmGemCloseWorkerTests, givenAllocationWhenAskedForUnreferenceWithForceFl auto worker = new DrmGemCloseWorker(*mm); auto bo = new BufferObjectWrapper(this->drmMock, 1); - auto alloc = new DrmAllocationWrapper(bo); bo->reference(); - worker->push(alloc); + worker->push(bo); auto r = mm->unreference(bo, true); EXPECT_EQ(1u, r);