uvc debugfs interface, initial patch
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi Alexey,
Quoted 3 lines · On Wednesday 21 September 2011 08:27:06 Alexey Fisher wrote:
this is initial patch for debugfs interface. I didn't implemented all requests, i think the size of this patch is any way too big now.
I've finally found time to go through your patch :-) I'm sorry for the way too long delay.
Quoted 6 lines
Here is how it's working. After driver is loaded it create debugfs/usb/uvcvideo directory. If some device is attached it create device dir like this: 001.007_046d.0991 (first part is usb bus, second is usb id). In this directory it create file called stats. Here is the content of this file:
Quoted 13 lines
usb id: 046d:0991, usb bus: 001:007
packet size: 944(6)
state: idle <-- show the state of device. capture or idle start time: 1316585466 <- unix epoch time in seconds.
capture time: 106 <- capture time in seconds.
format: YUV 4:2:2 (YUYV)
resolution: 320x240 @ 30decode_start: 846880 <- this show how many payloads we started to decoding.bad_header: 0 <-- haw many payloads was dropped, because of bad headeruvc_empty: 604160 <-- correct uvc payloads without video datauvc_stream_err: 0 <-- count of payloads with err bit set
sequence: 955 <-- count of fid switchesout_of_sync: 0 <-- out of sync calls
I like the patch but have lots of small comments. Instead of playing ping-pong with you to get everything fixed, I've reworked your patch. The result can be found as replies to this e-mail.
First of all I've split the patch in two. The first patch adds debugfs support to the driver, and the second patch exports video stream statistics. This makes review easier.
Then, I've modified statistics gathering to store per-stream stats instead of per-device as a UVC device can expose several streams.
Finally I've removed the state information from the statistics, as they're not really statistics. It should be easi to add them back in a "state" or "info" debugfs file once we agree on these patches.
Both patches are currently authored by me. I'll will use your name and e-mail address if you send me your SoB line.
Laurent Pinchart (2):
uvcvideo: Add debugfs support
uvcvideo: Extract video stream statistics
drivers/media/video/uvc/Makefile | 2 +- drivers/media/video/uvc/uvc_debugfs.c | 136 +++++++++++++++++++++++++++++++++ drivers/media/video/uvc/uvc_driver.c | 21 ++++- drivers/media/video/uvc/uvc_video.c | 111 ++++++++++++++++++++++++++- drivers/media/video/uvc/uvcvideo.h | 39 ++++++++++ 5 files changed, 302 insertions(+), 7 deletions(-) create mode 100644 drivers/media/video/uvc/uvc_debugfs.c
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 1/2 uvcvideo: Add debugfs support
In reply to a message not in the archiveCreate a debugfs entry per UVC stream. This will be used to export stream statistics.
--- drivers/media/video/uvc/Makefile | 2 +- drivers/media/video/uvc/uvc_debugfs.c | 76 +++++++++++++++++++++++++++++++++ drivers/media/video/uvc/uvc_driver.c | 21 +++++++-- drivers/media/video/uvc/uvcvideo.h | 9 ++++ 4 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 drivers/media/video/uvc/uvc_debugfs.c
drivers/media/video/uvc/Makefile +1 -1
@@ -1,5 +1,5 @@ uvcvideo-objs := uvc_driver.o uvc_queue.o uvc_v4l2.o uvc_video.o uvc_ctrl.o \ - uvc_status.o uvc_isight.o + uvc_status.o uvc_isight.o uvc_debugfs.o ifeq ($(CONFIG_MEDIA_CONTROLLER),y) uvcvideo-objs += uvc_entity.o endif
drivers/media/video/uvc/uvc_debugfs.c new file +76 -0
76 lines not on this page · raw message
drivers/media/video/uvc/uvc_driver.c +16 -5
@@ -1675,6 +1675,8 @@ static void uvc_unregister_video(struct uvc_device *dev)video_unregister_device (stream->vdev); stream->vdev =NULL ; + +uvc_debugfs_cleanup_stream (stream); }/* Decrement the stream count and call uvc_delete explicitly if there
@@ -1700,6 +1702,8 @@ static int uvc_register_video(struct uvc_device *dev,return ret; } +uvc_debugfs_init_stream (stream); +/* Register the device with V4L. */ vdev =video_device_alloc ();if (vdev ==NULL ) {
@@ -2405,17 +2409,24 @@ struct uvc_driver uvc_driver = {static int __init uvc_init (void ) { -int result; +int ret; - result =usb_register (&uvc_driver.driver); -if (result ==0 ) - printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n"); -return result; +uvc_debugfs_init (); + + ret =usb_register (&uvc_driver.driver); +if (ret <0 ) { +uvc_debugfs_cleanup (); +return ret; + } + + printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n"); +return 0 ; } static void __exit uvc_cleanup(void) {usb_deregister (&uvc_driver.driver); +uvc_debugfs_cleanup (); }module_init (uvc_init);
drivers/media/video/uvc/uvcvideo.h +9 -0
@@ -403,6 +403,9 @@ struct uvc_streaming {__u32 sequence;__u8 last_fid; + +/* debugfs */ +struct dentry *debugfs_dir; };enum uvc_device_state {
@@ -605,4 +608,10 @@ extern struct usb_host_endpoint *uvc_find_endpoint(void uvc_video_decode_isight (struct urb *urb,struct uvc_streaming *stream,struct uvc_buffer *buf); +/* debugfs */ +int uvc_debugfs_init (void ); +void uvc_debugfs_cleanup (void ); +int uvc_debugfs_init_stream (struct uvc_streaming *stream); +void uvc_debugfs_cleanup_stream (struct uvc_streaming *stream); +#endif
Signature · 1 line
1.7.3.4
PATCH 2/2 uvcvideo: Extract video stream statistics
In reply to a message not in the archiveExport the statistics through debugfs.
--- drivers/media/video/uvc/uvc_debugfs.c | 60 ++++++++++++++++++ drivers/media/video/uvc/uvc_video.c | 111 ++++++++++++++++++++++++++++++++- drivers/media/video/uvc/uvcvideo.h | 32 +++++++++- 3 files changed, 201 insertions(+), 2 deletions(-)
drivers/media/video/uvc/uvc_debugfs.c +60 -0
@@ -18,6 +18,57 @@#include "uvcvideo.h" /* ----------------------------------------------------------------------------- +* Statistics +*/ + +#define UVC_DEBUGFS_BUF_SIZE 1024 + +struct uvc_debugfs_buffer { +size_t count; +char data[UVC_DEBUGFS_BUF_SIZE ]; +}; + +static int uvc_debugfs_stats_open (struct inode *inode,struct file *file) +{ +struct uvc_streaming *stream = inode->i_private; +struct uvc_debugfs_buffer *buf; + + buf =kmalloc (sizeof (*buf),GFP_KERNEL ); +if (buf ==NULL ) +return -ENOMEM ; + + buf->count =uvc_video_stats_dump (stream, buf->data,sizeof (buf->data)); + + file->private_data = buf; +return 0 ; +} + +static ssize_t uvc_debugfs_stats_read (struct file *file,char __user *user_buf, +size_t nbytes,loff_t *ppos) +{ +struct uvc_debugfs_buffer *buf = file->private_data; + +return simple_read_from_buffer (user_buf, nbytes, ppos, buf->data, + buf->count); +} + +static int uvc_debugfs_stats_release (struct inode *inode,struct file *file) +{ +kfree (file->private_data); + file->private_data =NULL ; + +return 0 ; +} + +static const struct file_operations uvc_debugfs_stats_fops = { + .owner =THIS_MODULE , + .open = uvc_debugfs_stats_open, + .llseek = no_llseek, + .read = uvc_debugfs_stats_read, + .release = uvc_debugfs_stats_release, +}; + +/* ----------------------------------------------------------------------------- * Global and stream initialization/cleanup */
@@ -43,6 +94,15 @@ int uvc_debugfs_init_stream(struct uvc_streaming *stream) stream->debugfs_dir = dent; + dent =debugfs_create_file ("stats" ,0600 , stream->debugfs_dir, + stream, &uvc_debugfs_stats_fops); +if (IS_ERR_OR_NULL (dent)) { +uvc_printk (KERN_INFO ,"Unable to create debugfs %s directory.\n" , + dir_name); +uvc_debugfs_cleanup_stream (stream); +return -ENODEV ; + } +return 0 ; }
drivers/media/video/uvc/uvc_video.c +110 -1
142 lines not on this page · raw message
drivers/media/video/uvc/uvcvideo.h +31 -1
@@ -356,6 +356,28 @@ struct uvc_video_chain {struct mutex ctrl_mutex;/* Protects ctrl.info */ }; +struct uvc_stats_frame { +unsigned int size;/* Number of bytes captured */ +unsigned int first_data;/* Index of the first non-empty packet */ + +unsigned int nb_packets;/* Number of packets */ +unsigned int nb_empty;/* Number of empty packets */ +unsigned int nb_invalid;/* Number of packets with an invalid header */ +unsigned int nb_errors;/* Number of packets with the error bit set */ +}; + +struct uvc_stats_stream { +struct timespec start_ts;/* Stream start timestamp */ +struct timespec stop_ts;/* Stream stop timestamp */ + +unsigned int nb_frames;/* Number of frames */ + +unsigned int nb_packets;/* Number of packets */ +unsigned int nb_empty;/* Number of empty packets */ +unsigned int nb_invalid;/* Number of packets with an invalid header */ +unsigned int nb_errors;/* Number of packets with the error bit set */ +}; +struct uvc_streaming {struct list_head list;struct uvc_device *dev;
@@ -406,6 +428,10 @@ struct uvc_streaming {/* debugfs */ struct dentry *debugfs_dir; +struct { +struct uvc_stats_frame frame; +struct uvc_stats_stream stream; + } stats; };enum uvc_device_state {
@@ -477,6 +503,7 @@ struct uvc_driver {#define UVC_TRACE_SUSPEND (1 << 8)#define UVC_TRACE_STATUS (1 << 9)#define UVC_TRACE_VIDEO (1 << 10) +#define UVC_TRACE_STATS (1 << 11)#define UVC_WARN_MINMAX 0#define UVC_WARN_PROBE_DEF 1
@@ -608,10 +635,13 @@ extern struct usb_host_endpoint *uvc_find_endpoint(void uvc_video_decode_isight (struct urb *urb,struct uvc_streaming *stream,struct uvc_buffer *buf); -/* debugfs */ +/* debugfs and statistics */ int uvc_debugfs_init (void );void uvc_debugfs_cleanup (void );int uvc_debugfs_init_stream (struct uvc_streaming *stream);void uvc_debugfs_cleanup_stream (struct uvc_streaming *stream); +size_t uvc_video_stats_dump (struct uvc_streaming *stream,char *buf, +size_t size); +#endif
Signature · 1 line
1.7.3.4