From 10f354f46d8bd442fadb97be4ccc49ba87898f02 Mon Sep 17 00:00:00 2001 From: Luden Date: Sun, 24 Apr 2016 16:27:18 +0200 Subject: domx: connection robustness improvements CMA-enabled kernel for tuna devices will unload Ducati firmware when it's not in use to free extra memory for applications. On the first access to /dev/rpmsg-omx1 it will reload the firmware. However, in the process of this reloading device drivers will be reset, therefore causing errors when either opening the device or performing the first operation on it. Moreover, the previously opened handle will be invalidated in this case. Therefore, the connection loop is modified to retry both open() and first ioctl()calls instead of just open() and to reopen the device on retries. Also, because the reload can happen relatively fast when there are not too many pages to migrate, we use smaller waiting period but increased number of retries to improve camera start latency. Change-Id: I4b919f457c0e3bc43f99381c405e364b3326f583 --- domx/domx/omx_rpc/src/omx_rpc.c | 45 ++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/domx/domx/omx_rpc/src/omx_rpc.c b/domx/domx/omx_rpc/src/omx_rpc.c index e78d92b..3a6c33c 100755 --- a/domx/domx/omx_rpc/src/omx_rpc.c +++ b/domx/domx/omx_rpc/src/omx_rpc.c @@ -72,7 +72,7 @@ #define RPC_MSGPIPE_SIZE (4) #define RPC_MSG_SIZE_FOR_PIPE (sizeof(OMX_PTR)) -#define MAX_ATTEMPTS 15 +#define MAX_ATTEMPTS 60 #define RPC_getPacket(nPacketSize, pPacket) do { \ pPacket = TIMM_OSAL_Malloc(nPacketSize, TIMM_OSAL_TRUE, 0, TIMMOSAL_MEM_SEGMENT_INT); \ @@ -124,16 +124,29 @@ RPC_OMX_ERRORTYPE RPC_InstanceInit(OMX_STRING cComponentName, "Malloc failed"); TIMM_OSAL_Memset(pRPCCtx, 0, sizeof(RPC_OMX_CONTEXT)); - /*Assuming that open maintains an internal count for multi instance */ - DOMX_DEBUG("Calling open on the device"); + DOMX_DEBUG("Calling open and OMX_IOCCONNECT ioctl on the device"); while (1) { pRPCCtx->fd_omx = open("/dev/rpmsg-omx1", O_RDWR); - if(pRPCCtx->fd_omx >= 0 || errno != ENOENT || nAttempts == MAX_ATTEMPTS) - break; - DOMX_DEBUG("errno from open= %d, REATTEMPTING OPEN!!!!",errno); + if(pRPCCtx->fd_omx >= 0) + { + status = ioctl(pRPCCtx->fd_omx, OMX_IOCCONNECT, &sReq); + if (status >= 0) + break; + if (errno != ENXIO || nAttempts == MAX_ATTEMPTS) + break; + DOMX_DEBUG("errno from ioctl = %d, retrying...",errno); + close(pRPCCtx->fd_omx); + } + else + { + if ((errno != ENOENT && errno != ENXIO) || nAttempts == MAX_ATTEMPTS) + break; + DOMX_DEBUG("errno from open= %d, retrying...",errno); + } + nAttempts++; - usleep(1000000); + usleep(250000); } if(pRPCCtx->fd_omx < 0) { @@ -141,15 +154,15 @@ RPC_OMX_ERRORTYPE RPC_InstanceInit(OMX_STRING cComponentName, eError = RPC_OMX_ErrorInsufficientResources; goto EXIT; } - DOMX_DEBUG("Open was successful, pRPCCtx->fd_omx = %d", - pRPCCtx->fd_omx); -//AD -// strncpy(sReq.name, cComponentName, OMX_MAX_STRINGNAME_SIZE); - - DOMX_DEBUG("Calling ioctl"); - status = ioctl(pRPCCtx->fd_omx, OMX_IOCCONNECT, &sReq); - RPC_assert(status >= 0, RPC_OMX_ErrorInsufficientResources, - "Can't connect"); + if(status < 0) + { + DOMX_ERROR("Can't ioctl device, errorno from ioctl = %d",errno); + eError = RPC_OMX_ErrorInsufficientResources; + close(pRPCCtx->fd_omx); + goto EXIT; + } + DOMX_DEBUG("Open and OMX_IOCCONNECT were successful, pRPCCtx->fd_omx = %d, ioctl status = %d", + pRPCCtx->fd_omx, status); for (i = 0; i < RPC_OMX_MAX_FUNCTION_LIST; i++) { -- cgit v1.1