| 1 |
/* |
| 2 |
* Copyright (c) 2007-2017, 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_rt_os.cpp |
| 24 |
//! \brief Contains Linux-dependent CmEventRT member functions. |
| 25 |
//! |
| 26 |
|
| 27 |
#include "cm_event_rt.h" |
| 28 |
#include "cm_queue_rt.h" |
| 29 |
|
| 30 |
namespace CMRT_UMD |
| 31 |
{ |
| 32 |
//*----------------------------------------------------------------------------- |
| 33 |
//! Query the status of the task associated with the event |
| 34 |
//! An event is generated when a task ( one kernel or multiples kernels running concurrently ) |
| 35 |
//! is enqueued. |
| 36 |
//! This is a non-blocking call. |
| 37 |
//! INPUT: |
| 38 |
//! The reference to status. For now only two status, CM_STATUS_QUEUED and CM_STATUS_FINISHED, are supported |
| 39 |
//! OUTPUT: |
| 40 |
//! CM_SUCCESS if the status is successfully returned; |
| 41 |
//! CM_FAILURE if not. |
| 42 |
//*----------------------------------------------------------------------------- |
| 43 |
CM_RT_API int32_t CmEventRT::GetStatus(CM_STATUS &status) |
| 44 |
{ |
| 45 |
static const uint64_t TIME_OUT = 10000; // 10 microseconds. |
| 46 |
if (m_status == CM_STATUS_FLUSHED || m_status == CM_STATUS_STARTED) |
| 47 |
{ |
| 48 |
if (!m_osSignalTriggered) |
| 49 |
{ |
| 50 |
CM_CHK_NULL_RETURN_CMERROR(m_osData); |
| 51 |
MOS_LINUX_BO *buffer_object = reinterpret_cast<MOS_LINUX_BO*>(m_osData); |
| 52 |
int result = mos_bo_wait(buffer_object, TIME_OUT); |
| 53 |
mos_bo_clear_relocs(buffer_object, 0); |
| 54 |
m_osSignalTriggered = (result == 0); |
| 55 |
} |
| 56 |
if (m_osSignalTriggered) |
| 57 |
{ |
| 58 |
Query(); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
m_queue->FlushTaskWithoutSync(); |
| 63 |
|
| 64 |
status = m_status; |
| 65 |
return CM_SUCCESS; |
| 66 |
} |
| 67 |
|
| 68 |
//*----------------------------------------------------------------------------- |
| 69 |
//! Wait for the task completed with event-driven mechanism |
| 70 |
//! When the task finished, CM will be notified and waken up by KMD. |
| 71 |
//! INPUT: |
| 72 |
//! Timeout in Milliseconds |
| 73 |
//! OUTPUT: |
| 74 |
//! CM_SUCCESS: if the task finished |
| 75 |
//! CM_EXCEED_MAX_TIMEOUT: if timeout in synchoinization system call. |
| 76 |
//! CM_FEATURE_NOT_SUPPORTED_IN_DRIVER: if driver out-of-sync. |
| 77 |
//! CM_EVENT_DRIVEN_FAILURE : if synchronization system call returns WAIT_FAILED. |
| 78 |
//*---------------------------------------------------------------------------------- |
| 79 |
CM_RT_API int32_t CmEventRT::WaitForTaskFinished(uint32_t timeOutMs) |
| 80 |
{ |
| 81 |
int32_t result = CM_SUCCESS; |
| 82 |
|
| 83 |
if( m_status == CM_STATUS_FINISHED ) |
| 84 |
goto finish; |
| 85 |
|
| 86 |
//Make sure task flushed |
| 87 |
while ( m_status == CM_STATUS_QUEUED ) |
| 88 |
{ |
| 89 |
m_queue->FlushTaskWithoutSync(); //Flush none if 1st task NOT finished yet |
| 90 |
} |
| 91 |
|
| 92 |
CM_ASSERT(m_osData != nullptr); |
| 93 |
|
| 94 |
//Wait bo finished |
| 95 |
result = mos_bo_wait((MOS_LINUX_BO*)m_osData, 1000000LL*timeOutMs); |
| 96 |
mos_bo_clear_relocs((MOS_LINUX_BO*)m_osData, 0); |
| 97 |
if (result) { |
| 98 |
result = CM_EXCEED_MAX_TIMEOUT; //translate the drm ecode (-ETIME or potentional variants) to CM ecode. |
| 99 |
goto finish; |
| 100 |
} |
| 101 |
|
| 102 |
//Query status |
| 103 |
Query(); |
| 104 |
if(m_status != CM_STATUS_FINISHED) |
| 105 |
{ |
| 106 |
// if bo_wai() returns success but status is not finished in time stamp |
| 107 |
// it indicates something wrong in KMD, such as gpu reset happens. |
| 108 |
// need to return error code to application. |
| 109 |
result = CM_EXCEED_MAX_TIMEOUT; |
| 110 |
goto finish; |
| 111 |
} |
| 112 |
|
| 113 |
//Call flush to pop/destroy finished task and flush task in EnqueueedQueue. |
| 114 |
m_queue->FlushTaskWithoutSync(); |
| 115 |
|
| 116 |
finish: |
| 117 |
return result; |
| 118 |
} |
| 119 |
|
| 120 |
//*----------------------------------------------------------------------------- |
| 121 |
//! Unreference the bo in linux. |
| 122 |
//! INPUT: |
| 123 |
//! bo in a void * format |
| 124 |
//! OUTPUT: |
| 125 |
//! No output is needed |
| 126 |
//*----------------------------------------------------------------------------- |
| 127 |
void CmEventRT::UnreferenceIfNeeded(void *pdata) |
| 128 |
{ |
| 129 |
if( pdata ) |
| 130 |
{ |
| 131 |
mos_bo_unreference((MOS_LINUX_BO*)pdata); |
| 132 |
} |
| 133 |
} |
| 134 |
} // namespace |