media: videobuf2: Print videobuf2 buffer state by name
Subsystems (2)
PATCH 1/1 media: videobuf2: Print videobuf2 buffer state by name
For debugging purposes, seeing the state integer
representation is really inconvenient.
Improve this and be developer-friendly by printing the state name instead.
--- .../media/common/videobuf2/videobuf2-core.c | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-)
drivers/media/common/videobuf2/videobuf2-core.c +24 -8
@@ -191,6 +191,20 @@ module_param(debug, int, 0644);static void __vb2_queue_cancel (struct vb2_queue *q);static void __enqueue_in_driver (struct vb2_buffer *vb); +static const char *const vb2_state_names[] = { + [VB2_BUF_STATE_DEQUEUED ] ="dequeued" , + [VB2_BUF_STATE_IN_REQUEST ] ="in request" , + [VB2_BUF_STATE_PREPARING ] ="preparing" , + [VB2_BUF_STATE_QUEUED ] ="queued" , + [VB2_BUF_STATE_ACTIVE ] ="active" , + [VB2_BUF_STATE_DONE ] ="done" , + [VB2_BUF_STATE_ERROR ] ="error" , +}; + +#define vb2_state_name (s) \ + (((unsigned int)(s)) < ARRAY_SIZE(vb2_state_names) ? \ + vb2_state_names[s] : "unknown") +/* * __vb2_buf_mem_alloc() - allocate video memory for the given buffer */
@@ -1015,8 +1029,8 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)*/ vb->cnt_buf_done++;#endif -dprintk (q,4 ,"done processing on buffer %d, state: %d\n" , - vb->index, state); +dprintk (q,4 ,"done processing on buffer %d, state: %s\n" , + vb->index,vb2_state_name (state));if (state !=VB2_BUF_STATE_QUEUED )__vb2_buf_mem_finish (vb);
@@ -1490,8 +1504,8 @@ int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb) vb = q->bufs[index];if (vb->state !=VB2_BUF_STATE_DEQUEUED ) { -dprintk (q,1 ,"invalid buffer state %d\n" , - vb->state); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }if (vb->prepared) {
@@ -1670,7 +1684,8 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb,dprintk (q,1 ,"buffer still being prepared\n" );return -EINVAL ;default : -dprintk (q,1 ,"invalid buffer state %d\n" , vb->state); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }
@@ -1884,7 +1899,8 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,dprintk (q,3 ,"returning done buffer with errors\n" );break ;default : -dprintk (q,1 ,"invalid buffer state\n" ); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }
@@ -1915,8 +1931,8 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,media_request_put (vb->request); vb->request =NULL ; -dprintk (q,2 ,"dqbuf of buffer %d, with state %d\n" , - vb->index, vb->state); +dprintk (q,2 ,"dqbuf of buffer %d, state: %s\n" , + vb->index,vb2_state_name (vb->state));return 0 ;
Signature · 1 line
2.27.0
Quoted 23 lines · Ezequiel Garcia
For debugging purposes, seeing the state integer
representation is really inconvenient.Improve this and be developer-friendly by printing the state name instead.
Suggested-by Nicolas Dufresne <[email protected]>Signed-off-by Ezequiel Garcia <[email protected]>--- .../media/common/videobuf2/videobuf2-core.c | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-)drivers/media/common/videobuf2/videobuf2-core.c +3
-0@@ -191,6 +191,20 @@ module_param(debug, int, 0644);static void __vb2_queue_cancel (struct vb2_queue *q);static void __enqueue_in_driver (struct vb2_buffer *vb); +static const char *const vb2_state_names[] = { + [VB2_BUF_STATE_DEQUEUED ] ="dequeued" , + [VB2_BUF_STATE_IN_REQUEST ] ="in request" ,
drivers/media/common/videobuf2/videobuf2-core.c module_param(debug, int, 0644); · line 206
Quoted 10 lines
drivers/media/common/videobuf2/videobuf2-core.c +10
-0+ [VB2_BUF_STATE_PREPARING] = "preparing", + [VB2_BUF_STATE_QUEUED] = "queued", + [VB2_BUF_STATE_ACTIVE] = "active", + [VB2_BUF_STATE_DONE] = "done", + [VB2_BUF_STATE_ERROR] = "error", +}; + +#define vb2_state_name (s) \ + (((unsigned int)(s)) < ARRAY_SIZE(vb2_state_names) ? \ + vb2_state_names[s] : "unknown")
Can you turn this into a function?
That avoids this checkpatch warning:
CHECK: Macro argument reuse 's' - possible side-effects? #37: FILE: drivers/media/common/videobuf2/videobuf2-core.c:204:
+#define vb2_state_name(s) \
+ (((unsigned int)(s)) < ARRAY_SIZE(vb2_state_names) ? \
+ vb2_state_names[s] : "unknown")
And I think a function is cleaner as well.
This looks good otherwise.
Regards,
Hans
Quoted 58 lines
drivers/media/common/videobuf2/videobuf2-core.c +11
-8+/* * __vb2_buf_mem_alloc() - allocate video memory for the given buffer */ @@ -1015,8 +1029,8 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)*/ vb->cnt_buf_done++;#endif -dprintk (q,4 ,"done processing on buffer %d, state: %d\n" , - vb->index, state); +dprintk (q,4 ,"done processing on buffer %d, state: %s\n" , + vb->index,vb2_state_name (state));if (state !=VB2_BUF_STATE_QUEUED )__vb2_buf_mem_finish (vb);@@ -1490,8 +1504,8 @@ int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb) vb = q->bufs[index];if (vb->state !=VB2_BUF_STATE_DEQUEUED ) { -dprintk (q,1 ,"invalid buffer state %d\n" , - vb->state); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }if (vb->prepared) {@@ -1670,7 +1684,8 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb,dprintk (q,1 ,"buffer still being prepared\n" );return -EINVAL ;default : -dprintk (q,1 ,"invalid buffer state %d\n" , vb->state); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }@@ -1884,7 +1899,8 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,dprintk (q,3 ,"returning done buffer with errors\n" );break ;default : -dprintk (q,1 ,"invalid buffer state\n" ); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }@@ -1915,8 +1931,8 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,media_request_put (vb->request); vb->request =NULL ; -dprintk (q,2 ,"dqbuf of buffer %d, with state %d\n" , - vb->index, vb->state); +dprintk (q,2 ,"dqbuf of buffer %d, state: %s\n" , + vb->index,vb2_state_name (vb->state));return 0 ;
PATCH v2 1/1 media: videobuf2: Print videobuf2 buffer state by name
In reply to Ezequiel GarciaFor debugging purposes, seeing the state integer
representation is really inconvenient.
Improve this and be developer-friendly by printing the state name instead.
---
v2:
* Use a proper function instead of a C macro.
.../media/common/videobuf2/videobuf2-core.c | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-)
drivers/media/common/videobuf2/videobuf2-core.c +27 -8
@@ -191,6 +191,23 @@ module_param(debug, int, 0644);static void __vb2_queue_cancel (struct vb2_queue *q);static void __enqueue_in_driver (struct vb2_buffer *vb); +static inline const char *vb2_state_name (enum vb2_buffer_state s) +{ +static const char *const state_names[] = { + [VB2_BUF_STATE_DEQUEUED ] ="dequeued" , + [VB2_BUF_STATE_IN_REQUEST ] ="in request" , + [VB2_BUF_STATE_PREPARING ] ="preparing" , + [VB2_BUF_STATE_QUEUED ] ="queued" , + [VB2_BUF_STATE_ACTIVE ] ="active" , + [VB2_BUF_STATE_DONE ] ="done" , + [VB2_BUF_STATE_ERROR ] ="error" , + }; + +if ((unsigned int )(s) <ARRAY_SIZE (state_names)) +return state_names[s]; +return "unknown" ; +} +/* * __vb2_buf_mem_alloc() - allocate video memory for the given buffer */
@@ -1015,8 +1032,8 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)*/ vb->cnt_buf_done++;#endif -dprintk (q,4 ,"done processing on buffer %d, state: %d\n" , - vb->index, state); +dprintk (q,4 ,"done processing on buffer %d, state: %s\n" , + vb->index,vb2_state_name (state));if (state !=VB2_BUF_STATE_QUEUED )__vb2_buf_mem_finish (vb);
@@ -1490,8 +1507,8 @@ int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb) vb = q->bufs[index];if (vb->state !=VB2_BUF_STATE_DEQUEUED ) { -dprintk (q,1 ,"invalid buffer state %d\n" , - vb->state); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }if (vb->prepared) {
@@ -1670,7 +1687,8 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb,dprintk (q,1 ,"buffer still being prepared\n" );return -EINVAL ;default : -dprintk (q,1 ,"invalid buffer state %d\n" , vb->state); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }
@@ -1884,7 +1902,8 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,dprintk (q,3 ,"returning done buffer with errors\n" );break ;default : -dprintk (q,1 ,"invalid buffer state\n" ); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }
@@ -1915,8 +1934,8 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,media_request_put (vb->request); vb->request =NULL ; -dprintk (q,2 ,"dqbuf of buffer %d, with state %d\n" , - vb->index, vb->state); +dprintk (q,2 ,"dqbuf of buffer %d, state: %s\n" , + vb->index,vb2_state_name (vb->state));return 0 ;
Signature · 1 line
2.27.0
PATCH v3 1/1 media: videobuf2: Print videobuf2 buffer state by name
For debugging purposes, seeing the state integer
representation is really inconvenient.
Improve this and be developer-friendly by printing the state name instead.
---
v3:
* Drop static modifier from the now local name array. v2:
* Use a proper function instead of a C macro.
.../media/common/videobuf2/videobuf2-core.c | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-)
drivers/media/common/videobuf2/videobuf2-core.c +27 -8
@@ -191,6 +191,23 @@ module_param(debug, int, 0644);static void __vb2_queue_cancel (struct vb2_queue *q);static void __enqueue_in_driver (struct vb2_buffer *vb); +static inline const char *vb2_state_name (enum vb2_buffer_state s) +{ +const char *const state_names[] = { + [VB2_BUF_STATE_DEQUEUED ] ="dequeued" , + [VB2_BUF_STATE_IN_REQUEST ] ="in request" , + [VB2_BUF_STATE_PREPARING ] ="preparing" , + [VB2_BUF_STATE_QUEUED ] ="queued" , + [VB2_BUF_STATE_ACTIVE ] ="active" , + [VB2_BUF_STATE_DONE ] ="done" , + [VB2_BUF_STATE_ERROR ] ="error" , + }; + +if ((unsigned int )(s) <ARRAY_SIZE (state_names)) +return state_names[s]; +return "unknown" ; +} +/* * __vb2_buf_mem_alloc() - allocate video memory for the given buffer */
@@ -1015,8 +1032,8 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)*/ vb->cnt_buf_done++;#endif -dprintk (q,4 ,"done processing on buffer %d, state: %d\n" , - vb->index, state); +dprintk (q,4 ,"done processing on buffer %d, state: %s\n" , + vb->index,vb2_state_name (state));if (state !=VB2_BUF_STATE_QUEUED )__vb2_buf_mem_finish (vb);
@@ -1490,8 +1507,8 @@ int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb) vb = q->bufs[index];if (vb->state !=VB2_BUF_STATE_DEQUEUED ) { -dprintk (q,1 ,"invalid buffer state %d\n" , - vb->state); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }if (vb->prepared) {
@@ -1670,7 +1687,8 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb,dprintk (q,1 ,"buffer still being prepared\n" );return -EINVAL ;default : -dprintk (q,1 ,"invalid buffer state %d\n" , vb->state); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }
@@ -1884,7 +1902,8 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,dprintk (q,3 ,"returning done buffer with errors\n" );break ;default : -dprintk (q,1 ,"invalid buffer state\n" ); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }
@@ -1915,8 +1934,8 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,media_request_put (vb->request); vb->request =NULL ; -dprintk (q,2 ,"dqbuf of buffer %d, with state %d\n" , - vb->index, vb->state); +dprintk (q,2 ,"dqbuf of buffer %d, state: %s\n" , + vb->index,vb2_state_name (vb->state));return 0 ;
Signature · 1 line
2.27.0
Quoted 22 lines · Ezequiel Garcia
For debugging purposes, seeing the state integer
representation is really inconvenient.Improve this and be developer-friendly by printing the state name instead.
Suggested-by Nicolas Dufresne <[email protected]>Signed-off-by Ezequiel Garcia <[email protected]>---
v3:
* Drop static modifier from the now local name array. v2:
* Use a proper function instead of a C macro..../media/common/videobuf2/videobuf2-core.c | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-)drivers/media/common/videobuf2/videobuf2-core.c +0
-0
drivers/media/common/videobuf2/videobuf2-core.c module_param(debug, int, 0644); · line 194
Quoted 4 lines
drivers/media/common/videobuf2/videobuf2-core.c +1
-0@@ -191,6 +191,23 @@ module_param(debug, int, 0644);static void __vb2_queue_cancel (struct vb2_queue *q);static void __enqueue_in_driver (struct vb2_buffer *vb); +static inline const char *vb2_state_name (enum vb2_buffer_state s)
Why inline? That adds nothing of value. It's too big for an inline anyway and it's only used when debug is on.
drivers/media/common/videobuf2/videobuf2-core.c module_param(debug, int, 0644); · line 196
Quoted 2 lines
drivers/media/common/videobuf2/videobuf2-core.c +2
-0+{ +const char *const state_names[] = {
This really should be static, local or not. I'm not sure why you dropped that. Possibly because of the inline?
Regards,
Hans
Quoted 71 lines
drivers/media/common/videobuf2/videobuf2-core.c +24
-8+ [VB2_BUF_STATE_DEQUEUED] = "dequeued", + [VB2_BUF_STATE_IN_REQUEST] = "in request", + [VB2_BUF_STATE_PREPARING] = "preparing", + [VB2_BUF_STATE_QUEUED] = "queued", + [VB2_BUF_STATE_ACTIVE] = "active", + [VB2_BUF_STATE_DONE] = "done", + [VB2_BUF_STATE_ERROR] = "error", + }; + +if ((unsigned int )(s) <ARRAY_SIZE (state_names)) +return state_names[s]; +return "unknown" ; +} +/* * __vb2_buf_mem_alloc() - allocate video memory for the given buffer */ @@ -1015,8 +1032,8 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)*/ vb->cnt_buf_done++;#endif -dprintk (q,4 ,"done processing on buffer %d, state: %d\n" , - vb->index, state); +dprintk (q,4 ,"done processing on buffer %d, state: %s\n" , + vb->index,vb2_state_name (state));if (state !=VB2_BUF_STATE_QUEUED )__vb2_buf_mem_finish (vb);@@ -1490,8 +1507,8 @@ int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb) vb = q->bufs[index];if (vb->state !=VB2_BUF_STATE_DEQUEUED ) { -dprintk (q,1 ,"invalid buffer state %d\n" , - vb->state); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }if (vb->prepared) {@@ -1670,7 +1687,8 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb,dprintk (q,1 ,"buffer still being prepared\n" );return -EINVAL ;default : -dprintk (q,1 ,"invalid buffer state %d\n" , vb->state); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }@@ -1884,7 +1902,8 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,dprintk (q,3 ,"returning done buffer with errors\n" );break ;default : -dprintk (q,1 ,"invalid buffer state\n" ); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }@@ -1915,8 +1934,8 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,media_request_put (vb->request); vb->request =NULL ; -dprintk (q,2 ,"dqbuf of buffer %d, with state %d\n" , - vb->index, vb->state); +dprintk (q,2 ,"dqbuf of buffer %d, state: %s\n" , + vb->index,vb2_state_name (vb->state));return 0 ;
Quoted 26 lines · Hans Verkuil
Quoted 25 lines · Ezequiel Garcia
For debugging purposes, seeing the state integer
representation is really inconvenient.Improve this and be developer-friendly by printing the state name instead.
Suggested-by Nicolas Dufresne <[email protected]>Signed-off-by Ezequiel Garcia <[email protected]>---
v3:
* Drop static modifier from the now local name array. v2:
* Use a proper function instead of a C macro..../media/common/videobuf2/videobuf2-core.c | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-)drivers/media/common/videobuf2/videobuf2-core.c +0
-0@@ -191,6 +191,23 @@ module_param(debug, int, 0644);static void __vb2_queue_cancel (struct vb2_queue *q);static void __enqueue_in_driver (struct vb2_buffer *vb);
Quoted 5 lines
drivers/media/common/videobuf2/videobuf2-core.c module_param(debug, int, 0644); · line 194
Quoted 1 line
drivers/media/common/videobuf2/videobuf2-core.c +1
-0+static inline const char *vb2_state_name (enum vb2_buffer_state s)Why inline? That adds nothing of value. It's too big for an inline anyway and it's only used when debug is on.
Yes, you're right.
Quoted 6 lines
drivers/media/common/videobuf2/videobuf2-core.c module_param(debug, int, 0644); · line 196
Quoted 2 lines
drivers/media/common/videobuf2/videobuf2-core.c +2
-0+{ +const char *const state_names[] = {This really should be static, local or not. I'm not sure why you dropped that. Possibly because of the inline?
I was hesitant about this, as you can see. After some thought, it seemed a waste of space to have this array allocated statically.
Could you clarify this for me? Why do you believe it should be static?
Thanks,
Ezequiel
Quoted 75 lines
Regards,
Hans
Quoted 71 lines
drivers/media/common/videobuf2/videobuf2-core.c +24
-8+ [VB2_BUF_STATE_DEQUEUED] = "dequeued", + [VB2_BUF_STATE_IN_REQUEST] = "in request", + [VB2_BUF_STATE_PREPARING] = "preparing", + [VB2_BUF_STATE_QUEUED] = "queued", + [VB2_BUF_STATE_ACTIVE] = "active", + [VB2_BUF_STATE_DONE] = "done", + [VB2_BUF_STATE_ERROR] = "error", + }; + +if ((unsigned int )(s) <ARRAY_SIZE (state_names)) +return state_names[s]; +return "unknown" ; +} +/* * __vb2_buf_mem_alloc() - allocate video memory for the given buffer */ @@ -1015,8 +1032,8 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)*/ vb->cnt_buf_done++;#endif -dprintk (q,4 ,"done processing on buffer %d, state: %d\n" , - vb->index, state); +dprintk (q,4 ,"done processing on buffer %d, state: %s\n" , + vb->index,vb2_state_name (state));if (state !=VB2_BUF_STATE_QUEUED )__vb2_buf_mem_finish (vb);@@ -1490,8 +1507,8 @@ int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb) vb = q->bufs[index];if (vb->state !=VB2_BUF_STATE_DEQUEUED ) { -dprintk (q,1 ,"invalid buffer state %d\n" , - vb->state); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }if (vb->prepared) {@@ -1670,7 +1687,8 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb,dprintk (q,1 ,"buffer still being prepared\n" );return -EINVAL ;default : -dprintk (q,1 ,"invalid buffer state %d\n" , vb->state); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }@@ -1884,7 +1902,8 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,dprintk (q,3 ,"returning done buffer with errors\n" );break ;default : -dprintk (q,1 ,"invalid buffer state\n" ); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }@@ -1915,8 +1934,8 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,media_request_put (vb->request); vb->request =NULL ; -dprintk (q,2 ,"dqbuf of buffer %d, with state %d\n" , - vb->index, vb->state); +dprintk (q,2 ,"dqbuf of buffer %d, state: %s\n" , + vb->index,vb2_state_name (vb->state));return 0 ;
Quoted 42 lines · Ezequiel Garcia
Quoted 26 lines · Hans Verkuil
Quoted 25 lines · Ezequiel Garcia
For debugging purposes, seeing the state integer
representation is really inconvenient.Improve this and be developer-friendly by printing the state name instead.
Suggested-by Nicolas Dufresne <[email protected]>Signed-off-by Ezequiel Garcia <[email protected]>---
v3:
* Drop static modifier from the now local name array. v2:
* Use a proper function instead of a C macro..../media/common/videobuf2/videobuf2-core.c | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-)drivers/media/common/videobuf2/videobuf2-core.c +0
-0@@ -191,6 +191,23 @@ module_param(debug, int, 0644);static void __vb2_queue_cancel (struct vb2_queue *q);static void __enqueue_in_driver (struct vb2_buffer *vb);Quoted 5 lines
drivers/media/common/videobuf2/videobuf2-core.c module_param(debug, int, 0644); · line 194
Quoted 1 line
drivers/media/common/videobuf2/videobuf2-core.c +1
-0+static inline const char *vb2_state_name (enum vb2_buffer_state s)Why inline? That adds nothing of value. It's too big for an inline anyway and it's only used when debug is on.
Yes, you're right.
Quoted 6 lines
drivers/media/common/videobuf2/videobuf2-core.c module_param(debug, int, 0644); · line 196
Quoted 2 lines
drivers/media/common/videobuf2/videobuf2-core.c +2
-0+{ +const char *const state_names[] = {This really should be static, local or not. I'm not sure why you dropped that. Possibly because of the inline?
Quoted 4 lines
I was hesitant about this, as you can see. After some thought, it seemed a waste of space to have this array allocated statically.
Could you clarify this for me? Why do you believe it should be static?
If it is not static, then the compiler could create this array every time you enter this function. It probably is smart enough to avoid that, but there is no guarantee. This array is constant, will never change, so why not make it static? I'm not really should what you waste here.
Regards,
Hans
Quoted 81 lines
Thanks,
EzequielQuoted 75 lines
Regards,
Hans
Quoted 71 lines
drivers/media/common/videobuf2/videobuf2-core.c +24
-8+ [VB2_BUF_STATE_DEQUEUED] = "dequeued", + [VB2_BUF_STATE_IN_REQUEST] = "in request", + [VB2_BUF_STATE_PREPARING] = "preparing", + [VB2_BUF_STATE_QUEUED] = "queued", + [VB2_BUF_STATE_ACTIVE] = "active", + [VB2_BUF_STATE_DONE] = "done", + [VB2_BUF_STATE_ERROR] = "error", + }; + +if ((unsigned int )(s) <ARRAY_SIZE (state_names)) +return state_names[s]; +return "unknown" ; +} +/* * __vb2_buf_mem_alloc() - allocate video memory for the given buffer */ @@ -1015,8 +1032,8 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)*/ vb->cnt_buf_done++;#endif -dprintk (q,4 ,"done processing on buffer %d, state: %d\n" , - vb->index, state); +dprintk (q,4 ,"done processing on buffer %d, state: %s\n" , + vb->index,vb2_state_name (state));if (state !=VB2_BUF_STATE_QUEUED )__vb2_buf_mem_finish (vb);@@ -1490,8 +1507,8 @@ int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb) vb = q->bufs[index];if (vb->state !=VB2_BUF_STATE_DEQUEUED ) { -dprintk (q,1 ,"invalid buffer state %d\n" , - vb->state); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }if (vb->prepared) {@@ -1670,7 +1687,8 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb,dprintk (q,1 ,"buffer still being prepared\n" );return -EINVAL ;default : -dprintk (q,1 ,"invalid buffer state %d\n" , vb->state); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }@@ -1884,7 +1902,8 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,dprintk (q,3 ,"returning done buffer with errors\n" );break ;default : -dprintk (q,1 ,"invalid buffer state\n" ); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }@@ -1915,8 +1934,8 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,media_request_put (vb->request); vb->request =NULL ; -dprintk (q,2 ,"dqbuf of buffer %d, with state %d\n" , - vb->index, vb->state); +dprintk (q,2 ,"dqbuf of buffer %d, state: %s\n" , + vb->index,vb2_state_name (vb->state));return 0 ;
PATCH v4 1/1 media: videobuf2: Print videobuf2 buffer state by name
In reply to Ezequiel GarciaFor debugging purposes, seeing the state integer
representation is really inconvenient.
Improve this and be developer-friendly by printing the state name instead.
---
v4:
* Drop inline modifier.
* Add back static modifier from the now local name array. v3:
* Drop static modifier from the now local name array. v2:
* Use a proper function instead of a C macro.
.../media/common/videobuf2/videobuf2-core.c | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-)
drivers/media/common/videobuf2/videobuf2-core.c +27 -8
@@ -191,6 +191,23 @@ module_param(debug, int, 0644);static void __vb2_queue_cancel (struct vb2_queue *q);static void __enqueue_in_driver (struct vb2_buffer *vb); +static const char *vb2_state_name (enum vb2_buffer_state s) +{ +static const char *const state_names[] = { + [VB2_BUF_STATE_DEQUEUED ] ="dequeued" , + [VB2_BUF_STATE_IN_REQUEST ] ="in request" , + [VB2_BUF_STATE_PREPARING ] ="preparing" , + [VB2_BUF_STATE_QUEUED ] ="queued" , + [VB2_BUF_STATE_ACTIVE ] ="active" , + [VB2_BUF_STATE_DONE ] ="done" , + [VB2_BUF_STATE_ERROR ] ="error" , + }; + +if ((unsigned int )(s) <ARRAY_SIZE (state_names)) +return state_names[s]; +return "unknown" ; +} +/* * __vb2_buf_mem_alloc() - allocate video memory for the given buffer */
@@ -1015,8 +1032,8 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)*/ vb->cnt_buf_done++;#endif -dprintk (q,4 ,"done processing on buffer %d, state: %d\n" , - vb->index, state); +dprintk (q,4 ,"done processing on buffer %d, state: %s\n" , + vb->index,vb2_state_name (state));if (state !=VB2_BUF_STATE_QUEUED )__vb2_buf_mem_finish (vb);
@@ -1490,8 +1507,8 @@ int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb) vb = q->bufs[index];if (vb->state !=VB2_BUF_STATE_DEQUEUED ) { -dprintk (q,1 ,"invalid buffer state %d\n" , - vb->state); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }if (vb->prepared) {
@@ -1670,7 +1687,8 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb,dprintk (q,1 ,"buffer still being prepared\n" );return -EINVAL ;default : -dprintk (q,1 ,"invalid buffer state %d\n" , vb->state); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }
@@ -1884,7 +1902,8 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,dprintk (q,3 ,"returning done buffer with errors\n" );break ;default : -dprintk (q,1 ,"invalid buffer state\n" ); +dprintk (q,1 ,"invalid buffer state %s\n" , +vb2_state_name (vb->state));return -EINVAL ; }
@@ -1915,8 +1934,8 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,media_request_put (vb->request); vb->request =NULL ; -dprintk (q,2 ,"dqbuf of buffer %d, with state %d\n" , - vb->index, vb->state); +dprintk (q,2 ,"dqbuf of buffer %d, state: %s\n" , + vb->index,vb2_state_name (vb->state));return 0 ;
Signature · 1 line
2.27.0