Skip to content

Commit

Permalink
Debug for client_contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
6by9 committed Oct 25, 2019
1 parent 06fb0ef commit b1887d5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
8 changes: 6 additions & 2 deletions interface/mmal/vc/mmal_vc_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ typedef struct MMAL_COMPONENT_MODULE_T

MMAL_BOOL_T event_ctx_initialised;
MMAL_VC_CLIENT_BUFFER_CONTEXT_T event_ctx; /**< Used as the ctx for event buffers */
uint32_t event_ctx_handle; /**< Used as the ctx for event buffers */
} MMAL_COMPONENT_MODULE_T;


Expand Down Expand Up @@ -226,7 +227,7 @@ static MMAL_STATUS_T mmal_vc_port_enable(MMAL_PORT_T *port, MMAL_PORT_BH_CB_T cb
for (i = 0; i < pool->headers_num; i++)
{
drv = mmal_buffer_header_driver_data(pool->header[i]);
drv->client_context = mmal_vc_allocate_client_context(&port->component->priv->module->event_ctx);
drv->client_context = port->component->priv->module->event_ctx_handle;
drv->magic = MMAL_MAGIC;
}

Expand Down Expand Up @@ -533,7 +534,6 @@ static void mmal_vc_port_send_callback(mmal_worker_buffer_from_host *msg)
{
MMAL_BUFFER_HEADER_T *buffer;
MMAL_PORT_T *port;
//FIXME
MMAL_VC_CLIENT_BUFFER_CONTEXT_T *client_context = mmal_vc_lookup_client_context(msg->drvbuf.client_context);

vcos_assert(client_context);
Expand Down Expand Up @@ -805,6 +805,7 @@ static MMAL_STATUS_T mmal_vc_component_destroy(MMAL_COMPONENT_T *component)
mmal_ports_free(component->clock, component->clock_num);

mmal_queue_destroy(component->priv->module->callback_queue);
mmal_vc_release_client_context(&component->priv->module->event_ctx);

vcos_free(component->priv->module);
component->priv->module = NULL;
Expand All @@ -815,6 +816,8 @@ static MMAL_STATUS_T mmal_vc_component_destroy(MMAL_COMPONENT_T *component)
mmal_vc_release_client_component(component);
mmal_vc_shm_exit();
mmal_vc_deinit();
mmal_vc_dump_client_components();
mmal_vc_dump_client_contexts();
return status;
}

Expand Down Expand Up @@ -1540,6 +1543,7 @@ static MMAL_STATUS_T mmal_vc_component_create(const char *name, MMAL_COMPONENT_T
module->event_ctx_initialised = MMAL_FALSE;
module->event_ctx.magic = MMAL_MAGIC;
module->event_ctx.callback_event = mmal_vc_port_send_event_callback;
module->event_ctx_handle = mmal_vc_allocate_client_context(&module->event_ctx);

/* populate component structure */
component->priv->pf_enable = mmal_vc_component_enable;
Expand Down
38 changes: 37 additions & 1 deletion interface/mmal/vc/mmal_vc_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,24 @@ void mmal_vc_release_client_component(MMAL_COMPONENT_T *component)
vcos_mutex_unlock(&client_component_pool.lock);
}

void mmal_vc_dump_client_components(void)
{
int i;
int count = 0;

vcos_mutex_lock(&client_component_pool.lock);
for (i=0; i<MAX_COMPONENT_HANDLES; i++)
{
if (client_component_pool.components[i].inuse)
{
LOG_ERROR("%s: Entry %d in use for context %p", __func__, i, client_component_pool.components[i].component);
count++;
}
}
vcos_mutex_unlock(&client_component_pool.lock);
LOG_ERROR("%s: %u entries in use", __func__, count);
}

#define MAX_CLIENT_CONTEXTS 128

typedef struct
Expand Down Expand Up @@ -209,7 +227,7 @@ void mmal_vc_release_client_context(MMAL_VC_CLIENT_BUFFER_CONTEXT_T *context)
int i;

vcos_mutex_lock(&client_context_pool.lock);
for (i=0; i<MAX_COMPONENT_HANDLES; i++)
for (i=0; i<MAX_CLIENT_CONTEXTS; i++)
{
if (client_context_pool.contexts[i].ctx == context)
{
Expand All @@ -220,6 +238,24 @@ void mmal_vc_release_client_context(MMAL_VC_CLIENT_BUFFER_CONTEXT_T *context)
vcos_mutex_unlock(&client_context_pool.lock);
}

void mmal_vc_dump_client_contexts(void)
{
int i;
int count = 0;

vcos_mutex_lock(&client_context_pool.lock);
for (i=0; i<MAX_CLIENT_CONTEXTS; i++)
{
if (client_context_pool.contexts[i].inuse)
{
LOG_ERROR("%s: Entry %d in use for context %p", __func__, i, client_context_pool.contexts[i].ctx);
count++;
}
}
vcos_mutex_unlock(&client_context_pool.lock);
LOG_ERROR("%s: %u entries in use", __func__, count);
}

/* One client per process/VC connection. Multiple threads may
* be using a single client.
*/
Expand Down
2 changes: 2 additions & 0 deletions interface/mmal/vc/mmal_vc_client_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ MMAL_STATUS_T mmal_vc_send_message(MMAL_CLIENT_T *client,

uint32_t mmal_vc_allocate_client_component(MMAL_COMPONENT_T *component);
void mmal_vc_release_client_component(MMAL_COMPONENT_T *component);
void mmal_vc_dump_client_components(void);

uint32_t mmal_vc_allocate_client_context(MMAL_VC_CLIENT_BUFFER_CONTEXT_T *context);
MMAL_VC_CLIENT_BUFFER_CONTEXT_T *mmal_vc_lookup_client_context(int index);
void mmal_vc_release_client_context(MMAL_VC_CLIENT_BUFFER_CONTEXT_T *context);
void mmal_vc_dump_client_contexts(void);
#endif

0 comments on commit b1887d5

Please sign in to comment.