| 1 |
/* |
| 2 |
* Copyright (c) 2018-2019, Intel Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included |
| 12 |
* in all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
//! |
| 23 |
//! \file cm_event_ex.cpp |
| 24 |
//! \brief Contains Class CmEventEx definitions |
| 25 |
//! |
| 26 |
|
| 27 |
#include "cm_event_ex.h" |
| 28 |
#include "cm_hal.h" |
| 29 |
#include "cm_tracker.h" |
| 30 |
#include "cm_notifier.h" |
| 31 |
|
| 32 |
CmEventEx::~CmEventEx() |
| 33 |
{ |
| 34 |
if (m_cmTracker) |
| 35 |
{ |
| 36 |
m_cmTracker->DeAssociateEvent(this); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
void CmEventEx::SetTaskOsData(MOS_RESOURCE *resource, HANDLE handle) |
| 41 |
{ |
| 42 |
UNUSED(handle); |
| 43 |
if (resource != nullptr) |
| 44 |
{ |
| 45 |
mos_bo_reference((MOS_LINUX_BO *)(resource->bo)); |
| 46 |
m_osData = resource->bo; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
int32_t CmEventEx::WaitForTaskFinished(uint32_t timeOutMs) |
| 51 |
{ |
| 52 |
int32_t result = mos_bo_wait((MOS_LINUX_BO*)m_osData, 1000000LL*timeOutMs); |
| 53 |
mos_bo_clear_relocs((MOS_LINUX_BO*)m_osData, 0); |
| 54 |
|
| 55 |
if (result) { |
| 56 |
return CM_EXCEED_MAX_TIMEOUT; //translate the drm ecode (-ETIME or potentional variants) to CM ecode. |
| 57 |
} |
| 58 |
if (m_state != CM_STATUS_FINISHED) |
| 59 |
{ |
| 60 |
Query(); |
| 61 |
} |
| 62 |
|
| 63 |
if (m_state == CM_STATUS_FINISHED) |
| 64 |
{ |
| 65 |
return CM_SUCCESS; |
| 66 |
} |
| 67 |
else |
| 68 |
{ |
| 69 |
// if bo_wait() returns success but status is not finished in time stamp |
| 70 |
// it indicates something wrong in KMD, such as gpu reset happens. |
| 71 |
// need to return error code to application. |
| 72 |
return CM_EXCEED_MAX_TIMEOUT; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
int32_t CmEventEx::GetStatus(CM_STATUS &status) |
| 77 |
{ |
| 78 |
static const uint64_t TIME_OUT = 10000; // 10 microseconds. |
| 79 |
if (m_state != CM_STATUS_FINISHED) |
| 80 |
{ |
| 81 |
if (!m_osSignalTriggered) |
| 82 |
{ |
| 83 |
CM_CHK_NULL_RETURN_CMERROR(m_osData); |
| 84 |
MOS_LINUX_BO *buffer_object = reinterpret_cast<MOS_LINUX_BO*>(m_osData); |
| 85 |
int result = mos_bo_wait(buffer_object, TIME_OUT); |
| 86 |
mos_bo_clear_relocs(buffer_object, 0); |
| 87 |
m_osSignalTriggered = (result == 0); |
| 88 |
} |
| 89 |
if (m_osSignalTriggered) |
| 90 |
{ |
| 91 |
Query(); |
| 92 |
} |
| 93 |
} |
| 94 |
status = m_state; |
| 95 |
return CM_SUCCESS; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
void CmEventEx::RleaseOsData() |
| 100 |
{ |
| 101 |
mos_bo_unreference((MOS_LINUX_BO*)m_osData); |
| 102 |
} |