From patchwork Mon May 17 18:37:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 12262843 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB9DEC433ED for ; Mon, 17 May 2021 18:38:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C3671611ED for ; Mon, 17 May 2021 18:38:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235555AbhEQSjc (ORCPT ); Mon, 17 May 2021 14:39:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229736AbhEQSjc (ORCPT ); Mon, 17 May 2021 14:39:32 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61EF6C061573 for ; Mon, 17 May 2021 11:38:14 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id q5so7483733wrs.4 for ; Mon, 17 May 2021 11:38:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=r3w59S3cRCL6la/fQ2ihysYOi34FUudTPWCo8KCLDz4=; b=dSB4BJMxwbTfX2NJImHipExoMduhsdy/G5qXcUUS3dUsrYQSZsqmivfizw8tkd8Xi5 dN3yDu8IagJT2p0PDsRElroZ0zsZN5N+JqdFnC6x9sdetBclEsIb8B6bFz8nnU9MnJ8E opcD+raSRiKm3Krv6baRecQpdQ+lux+7IxphJYHrjwYkUC2nRsCRjD0VCEZXmY04t8LI HBmgO4X7iQyTH48eQJDDoYOKTECGzJ5UCHqX9WOUJAoFhUU0LnkGGo1EKbDXf2M5Tx/m PaKrTYejYoNNxUb/lKhJ1nK9JqOSyG+SI2jjlj5u+kMC99DLgzuTdpE8vKeYcf2JKtOV b7VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=r3w59S3cRCL6la/fQ2ihysYOi34FUudTPWCo8KCLDz4=; b=gF2G/Hx3vIEzt2r8TMMzoAc3bgrrZ07Y9P1WO6/WqFmhmkJKDfls3khA+1XAEgwnel sU71a7LdJ8Z7BecX7++eRFcTkrOdtn+VBO7XREJ6MRzwoqHFVKm6FhWaQ09ZNxOcDuQ/ 5q6sCAzXqS/C/Wf60vK6nE4hALDwR5HdGq516XthweukQlGzBe98hNI16AStK1+NiKnD 09HX7ibD9wI9/bIF46H/9FkOkBGFwbsyn8IuCBEwBl4+6Av1q26/w93DSiU1vfWyXD0t 60tIQA/QGX4NcyPZC4kg0DnmQ2c06LAuz8Bt0hoEaTp3G9QicZWtOYOdVTzwgp1crGr1 BbTg== X-Gm-Message-State: AOAM533zxnnJ6zR71aLtV3NIkZvrL+pRAZi0TirN+Czpz01kBlZyv4UK 4AzIJ7mtipj9gNx2OqGkhYw= X-Google-Smtp-Source: ABdhPJwk9wK3xEYeGxuK43/5bkvCQDmvFMbJ2sJ507RgpNwwykFFDWAW0a1X072hZ7f74BICGU/eyQ== X-Received: by 2002:a05:6000:1ac7:: with SMTP id i7mr1314447wry.380.1621276693147; Mon, 17 May 2021 11:38:13 -0700 (PDT) Received: from arch-x1c3.. (cpc92308-cmbg19-2-0-cust99.5-4.cable.virginm.net. [82.24.248.100]) by smtp.gmail.com with ESMTPSA id f3sm18076625wrp.7.2021.05.17.11.38.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 11:38:12 -0700 (PDT) From: Emil Velikov To: Mauro Carvalho Chehab , Hans Verkuil , Ezequiel Garcia , Philipp Zabel , Alexandre Courbot , Mikhail Ulyanov , kernel@collabora.com Cc: linux-media@vger.kernel.org Subject: [PATCH 1/5] media: v4l2: print the fh, during qbuf/dqbuf tracing Date: Mon, 17 May 2021 19:37:57 +0100 Message-Id: <20210517183801.1255496-2-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517183801.1255496-1-emil.l.velikov@gmail.com> References: <20210517183801.1255496-1-emil.l.velikov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Emil Velikov To correlate the buffer handling with specific jobs, we need to provide the file handle (pointer) used. Signed-off-by: Emil Velikov --- drivers/media/v4l2-core/v4l2-ioctl.c | 10 ++++++++-- include/trace/events/v4l2.h | 22 ++++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index 31d1342e61e8..4b56493a1bae 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -3343,10 +3343,16 @@ video_usercopy(struct file *file, unsigned int orig_cmd, unsigned long arg, } if (err == 0) { + struct video_device *vdev = video_devdata(file); + struct v4l2_fh *fh = NULL; + + if (test_bit(V4L2_FL_USES_V4L2_FH, &vdev->flags)) + fh = file->private_data; + if (cmd == VIDIOC_DQBUF) - trace_v4l2_dqbuf(video_devdata(file)->minor, parg); + trace_v4l2_dqbuf(fh, parg); else if (cmd == VIDIOC_QBUF) - trace_v4l2_qbuf(video_devdata(file)->minor, parg); + trace_v4l2_qbuf(fh, parg); } if (has_array_args) { diff --git a/include/trace/events/v4l2.h b/include/trace/events/v4l2.h index 248bc09bfc99..e07311cfe5ca 100644 --- a/include/trace/events/v4l2.h +++ b/include/trace/events/v4l2.h @@ -7,6 +7,7 @@ #include #include +#include /* Enums require being exported to userspace, for user tool parsing */ #undef EM @@ -98,12 +99,12 @@ SHOW_FIELD { V4L2_TC_USERBITS_8BITCHARS, "USERBITS_8BITCHARS" }) DECLARE_EVENT_CLASS(v4l2_event_class, - TP_PROTO(int minor, struct v4l2_buffer *buf), - - TP_ARGS(minor, buf), + TP_PROTO(struct v4l2_fh *fh, struct v4l2_buffer *buf), + TP_ARGS(fh, buf), TP_STRUCT__entry( __field(int, minor) + __field(struct v4l2_fh *, fh) __field(u32, index) __field(u32, type) __field(u32, bytesused) @@ -124,7 +125,8 @@ DECLARE_EVENT_CLASS(v4l2_event_class, ), TP_fast_assign( - __entry->minor = minor; + __entry->minor = fh ? fh->vdev->minor : -1; + __entry->fh = fh; __entry->index = buf->index; __entry->type = buf->type; __entry->bytesused = buf->bytesused; @@ -144,12 +146,12 @@ DECLARE_EVENT_CLASS(v4l2_event_class, __entry->sequence = buf->sequence; ), - TP_printk("minor = %d, index = %u, type = %s, bytesused = %u, " + TP_printk("minor = %d, fh = %p, index = %u, type = %s, bytesused = %u, " "flags = %s, field = %s, timestamp = %llu, " "timecode = { type = %s, flags = %s, frames = %u, " "seconds = %u, minutes = %u, hours = %u, " "userbits = { %u %u %u %u } }, sequence = %u", __entry->minor, - __entry->index, show_type(__entry->type), + __entry->fh, __entry->index, show_type(__entry->type), __entry->bytesused, show_flags(__entry->flags), show_field(__entry->field), @@ -169,13 +171,13 @@ DECLARE_EVENT_CLASS(v4l2_event_class, ) DEFINE_EVENT(v4l2_event_class, v4l2_dqbuf, - TP_PROTO(int minor, struct v4l2_buffer *buf), - TP_ARGS(minor, buf) + TP_PROTO(struct v4l2_fh *fh, struct v4l2_buffer *buf), + TP_ARGS(fh, buf) ); DEFINE_EVENT(v4l2_event_class, v4l2_qbuf, - TP_PROTO(int minor, struct v4l2_buffer *buf), - TP_ARGS(minor, buf) + TP_PROTO(struct v4l2_fh *fh, struct v4l2_buffer *buf), + TP_ARGS(fh, buf) ); DECLARE_EVENT_CLASS(vb2_v4l2_event_class, From patchwork Mon May 17 18:37:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 12262845 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF3E6C433B4 for ; Mon, 17 May 2021 18:38:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 94082611ED for ; Mon, 17 May 2021 18:38:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235605AbhEQSje (ORCPT ); Mon, 17 May 2021 14:39:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229736AbhEQSjd (ORCPT ); Mon, 17 May 2021 14:39:33 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61E3CC061573 for ; Mon, 17 May 2021 11:38:16 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id z17so7462005wrq.7 for ; Mon, 17 May 2021 11:38:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sdEsts3GmeksCsp4kc3Smg1R34rKcnsE9RxXjG1xDPM=; b=UWWeQWMWSfuE2J/C7TLe3IV/exseYdOoePVh/DXxbwhifQ1YadIlYXbPIFNh8kncr6 Nxs1KJ5gV3r6AwwnSoCsuf4sP3ryjWGsUHzv6JaMKcQGxJNdUYKpJchkB/wZdY4V04nY ESaaqXr8X2seWiN/Y6687vdjQ0GNVcbwWoX1sd/0czW1XzrpHi/SkEGwrFvpZ5D91JYx TULwJBZ0boQbog4y2s66E7vAarGr01uSsg4MnnXX6xC78TbuawIBSjmiiwAChkCtr8kf ncs++AtDPPjZl0WfOT/zXQ6YZkvOfFk6lGclwZ8kMQuJM10gZzm1njU0ALdqlK8B3nua PuuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sdEsts3GmeksCsp4kc3Smg1R34rKcnsE9RxXjG1xDPM=; b=bV/uhwH4oL6Zmx2jF/sEBHPFbREdk9MkbJAykkzUsYbSK32FsCAdFm8Wj5SNq8ivhw kNOYijhLE2ubeiDYeO3ajdcmzsUAnlHSc4dx3jeki2tOhTvRzI5kS++mEO830N6myaNl AuJUh3lMahZMmqTi4Blk/3lZ/IaGIYGiz5DNzjOBYOql0ySBTAmrHsFt6c47cEcRQDPI /Q9G0QhBxJ2VipAkDfpN2Gr4/c9kOUnVwEr7GDIWBUmoW9L73iKasy5NUBU4ZdWY4Lc3 bu6eHUW9DzgKzX0hZYQr5fH4jP68kUmNeLqY7h9NyHr0jfNVl15nBA05j/MxJGyYNmRe K1lA== X-Gm-Message-State: AOAM531+Fu00bek1NDL87l/zyQxPMBCTfXXGZw7owt20pCeboWELsaVH tpx8ZWMbYXk02G/MoqkSMFI= X-Google-Smtp-Source: ABdhPJx8KRTBNH+kbbivTpUDIm25pUQY7asyxLGm6wq/TMmX2g1/nf6LlYCN3jbDypD9Y2/0b0L9Lg== X-Received: by 2002:adf:e6c2:: with SMTP id y2mr1253244wrm.384.1621276695130; Mon, 17 May 2021 11:38:15 -0700 (PDT) Received: from arch-x1c3.. (cpc92308-cmbg19-2-0-cust99.5-4.cable.virginm.net. [82.24.248.100]) by smtp.gmail.com with ESMTPSA id f3sm18076625wrp.7.2021.05.17.11.38.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 11:38:13 -0700 (PDT) From: Emil Velikov To: Mauro Carvalho Chehab , Hans Verkuil , Ezequiel Garcia , Philipp Zabel , Alexandre Courbot , Mikhail Ulyanov , kernel@collabora.com Cc: linux-media@vger.kernel.org Subject: [PATCH 2/5] media: v4l2: add VIDIOC_S_FMT tracing Date: Mon, 17 May 2021 19:37:58 +0100 Message-Id: <20210517183801.1255496-3-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517183801.1255496-1-emil.l.velikov@gmail.com> References: <20210517183801.1255496-1-emil.l.velikov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Emil Velikov Add tracing for VIDIOC_S_FMT, which can be correlated to job and buffer submission traces. Since we're setting the format itself, we do not have distinct buffer (index) here. Yet, we can still use the minor/fh/type to link the trace to the corresponding job. Co-authored-by: Robert Beckett Signed-off-by: Robert Beckett Signed-off-by: Emil Velikov --- drivers/media/v4l2-core/v4l2-ioctl.c | 2 + drivers/media/v4l2-core/v4l2-trace.c | 1 + include/trace/events/v4l2.h | 132 +++++++++++++++++++++++++++ include/uapi/linux/videodev2.h | 1 + 4 files changed, 136 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index 4b56493a1bae..66a039ed8a43 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -1662,6 +1662,8 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, return ret; v4l_sanitize_format(p); + trace_v4l2_ioctl_s_fmt(file, fh, p); + switch (p->type) { case V4L2_BUF_TYPE_VIDEO_CAPTURE: if (unlikely(!ops->vidioc_s_fmt_vid_cap)) diff --git a/drivers/media/v4l2-core/v4l2-trace.c b/drivers/media/v4l2-core/v4l2-trace.c index 95f3b02e1f84..6df26fc7c39c 100644 --- a/drivers/media/v4l2-core/v4l2-trace.c +++ b/drivers/media/v4l2-core/v4l2-trace.c @@ -10,3 +10,4 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(vb2_v4l2_buf_done); EXPORT_TRACEPOINT_SYMBOL_GPL(vb2_v4l2_buf_queue); EXPORT_TRACEPOINT_SYMBOL_GPL(vb2_v4l2_dqbuf); EXPORT_TRACEPOINT_SYMBOL_GPL(vb2_v4l2_qbuf); +EXPORT_TRACEPOINT_SYMBOL_GPL(v4l2_ioctl_s_fmt); diff --git a/include/trace/events/v4l2.h b/include/trace/events/v4l2.h index e07311cfe5ca..d11e38676e48 100644 --- a/include/trace/events/v4l2.h +++ b/include/trace/events/v4l2.h @@ -6,8 +6,10 @@ #define _TRACE_V4L2_H #include +#include #include #include +#include /* Enums require being exported to userspace, for user tool parsing */ #undef EM @@ -264,6 +266,136 @@ DEFINE_EVENT(vb2_v4l2_event_class, vb2_v4l2_qbuf, TP_ARGS(q, vb) ); +#ifdef CREATE_TRACE_POINTS +#define __trace_array_name(a, arr, num) (((unsigned)(a)) < num ? arr[a] : "unknown") +static inline void __trace_sprint_v4l2_format(char *str, size_t size, struct v4l2_format *p) +{ + const struct v4l2_pix_format *pix; + const struct v4l2_pix_format_mplane *mp; + const struct v4l2_vbi_format *vbi; + const struct v4l2_sliced_vbi_format *sliced; + const struct v4l2_window *win; + const struct v4l2_sdr_format *sdr; + const struct v4l2_meta_format *meta; + + switch (p->type) { + case V4L2_BUF_TYPE_VIDEO_CAPTURE: + case V4L2_BUF_TYPE_VIDEO_OUTPUT: + pix = &p->fmt.pix; + snprintf(str, size, "width=%u, height=%u, pixelformat=%c%c%c%c, " + "field=%s, bytesperline=%u, sizeimage=%u, " + "colorspace=%d, flags=0x%x, ycbcr_enc=%u, " + "quantization=%u, xfer_func=%u", + pix->width, pix->height, + (pix->pixelformat & 0xff), + (pix->pixelformat >> 8) & 0xff, + (pix->pixelformat >> 16) & 0xff, + (pix->pixelformat >> 24) & 0xff, + __trace_array_name(pix->field, v4l2_field_names, V4L2_FIELD_NUM), + pix->bytesperline, pix->sizeimage, + pix->colorspace, pix->flags, pix->ycbcr_enc, + pix->quantization, pix->xfer_func); + break; + case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: + case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: + mp = &p->fmt.pix_mp; + snprintf(str, size, "width=%u, height=%u, pixelformat=%c%c%c%c, " + "field=%s, num_planes=%u, " + "colorspace=%d, flags=0x%x, ycbcr_enc=%u, " + "quantization=%u, xfer_func=%u}", + mp->width, mp->height, + (mp->pixelformat & 0xff), + (mp->pixelformat >> 8) & 0xff, + (mp->pixelformat >> 16) & 0xff, + (mp->pixelformat >> 24) & 0xff, + __trace_array_name(mp->field, v4l2_field_names, V4L2_FIELD_NUM), + mp->num_planes, + mp->colorspace, mp->flags, mp->ycbcr_enc, + mp->quantization, mp->xfer_func); + break; + case V4L2_BUF_TYPE_VIDEO_OVERLAY: + case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: + win = &p->fmt.win; + /* Note: we can't print the clip list here since the clips + * pointer is a userspace pointer, not a kernelspace + * pointer. */ + snprintf(str, size, "wxh=%dx%d, x,y=%d,%d, field=%s, " + "chromakey=0x%08x, clipcount=%u, clips=%p, " + "bitmap=%p, global_alpha=0x%02x", + win->w.width, win->w.height, win->w.left, win->w.top, + __trace_array_name(win->field, v4l2_field_names, V4L2_FIELD_NUM), + win->chromakey, win->clipcount, win->clips, + win->bitmap, win->global_alpha); + break; + case V4L2_BUF_TYPE_VBI_CAPTURE: + case V4L2_BUF_TYPE_VBI_OUTPUT: + vbi = &p->fmt.vbi; + pr_cont("sampling_rate=%u, offset=%u, samples_per_line=%u, " + "sample_format=%c%c%c%c, start=%u,%u, count=%u,%u", + vbi->sampling_rate, vbi->offset, + vbi->samples_per_line, + (vbi->sample_format & 0xff), + (vbi->sample_format >> 8) & 0xff, + (vbi->sample_format >> 16) & 0xff, + (vbi->sample_format >> 24) & 0xff, + vbi->start[0], vbi->start[1], + vbi->count[0], vbi->count[1]); + break; + case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: + case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: + sliced = &p->fmt.sliced; + snprintf(str, size, "service_set=0x%08x, io_size=%d", + sliced->service_set, sliced->io_size); + break; + case V4L2_BUF_TYPE_SDR_CAPTURE: + case V4L2_BUF_TYPE_SDR_OUTPUT: + sdr = &p->fmt.sdr; + snprintf(str, size, "pixelformat=%c%c%c%c", + (sdr->pixelformat >> 0) & 0xff, + (sdr->pixelformat >> 8) & 0xff, + (sdr->pixelformat >> 16) & 0xff, + (sdr->pixelformat >> 24) & 0xff); + break; + case V4L2_BUF_TYPE_META_CAPTURE: + case V4L2_BUF_TYPE_META_OUTPUT: + meta = &p->fmt.meta; + snprintf(str, size, "dataformat=%c%c%c%c, buffersize=%u", + (meta->dataformat >> 0) & 0xff, + (meta->dataformat >> 8) & 0xff, + (meta->dataformat >> 16) & 0xff, + (meta->dataformat >> 24) & 0xff, + meta->buffersize); + break; + } +} +#endif + +#define V4L2_FMT_MAX 256 + +/* v4l2-ioctl trace events */ +TRACE_EVENT(v4l2_ioctl_s_fmt, + TP_PROTO(struct file *file, struct v4l2_fh *fh, struct v4l2_format *fmt), + TP_ARGS(file, fh, fmt), + + TP_STRUCT__entry( + __field(int, minor) + __field(struct v4l2_fh *, fh) + __field(u32, type) + __dynamic_array(char, details, V4L2_FMT_MAX) + ), + + TP_fast_assign( + __entry->minor = video_devdata(file)->minor; + __entry->fh = fh; + __entry->type = fmt->type; + __trace_sprint_v4l2_format(__get_str(details), V4L2_FMT_MAX, fmt); + ), + + TP_printk("minor = %d, fh = %p, type = %s, %s", + __entry->minor, __entry->fh, + show_type(__entry->type), __get_str(details)) +); + #endif /* if !defined(_TRACE_V4L2_H) || defined(TRACE_HEADER_MULTI_READ) */ /* This part must be outside protection */ diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index 79dbde3bcf8d..f9f4b63fb50f 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -105,6 +105,7 @@ enum v4l2_field { V4L2_FIELD_INTERLACED_BT = 9, /* both fields interlaced, top field first and the bottom field is transmitted first */ + V4L2_FIELD_NUM }; #define V4L2_FIELD_HAS_TOP(field) \ ((field) == V4L2_FIELD_TOP ||\ From patchwork Mon May 17 18:37:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 12262847 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D908CC43460 for ; Mon, 17 May 2021 18:38:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BBBF3611CC for ; Mon, 17 May 2021 18:38:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235606AbhEQSjf (ORCPT ); Mon, 17 May 2021 14:39:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229736AbhEQSjf (ORCPT ); Mon, 17 May 2021 14:39:35 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64510C061573 for ; Mon, 17 May 2021 11:38:18 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id v12so7476124wrq.6 for ; Mon, 17 May 2021 11:38:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i+nszOoD23Eg2Y7U0BVUuhhlHTsGEYFChABYmw32+P4=; b=NuMulHwJmu95SR3cCPgqe23DGlr3Epwp+Nq7ftrxitY55HkjZ8WvFOthgnACDBk2+5 k2PLTb87DRpSAsLx2HJZN3PPIz2PL1AiN05osWRmUjhh/404hLmQLWSvhqnt/9CAA7hU AQxZ4oJ/jKtatFTHlS/QqCYlH/7rWua4j65VW+yIhUzcMOeOIfJHBaQvhWLFYrA423sO 7pgLAJTjCAczCZwALV3kXEZEPFEressNpMERn1DrLsZcfEo54Vs6QUeMl6Zzy/7xrGBc aLXKZULWIKuURNb6iR320Kyq920+9SKxjZiMrO+uU4x+/r1OmdfofdfgbbvLAugFxtEK CEaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i+nszOoD23Eg2Y7U0BVUuhhlHTsGEYFChABYmw32+P4=; b=g43g7Afe4F35KhNMChXKLxacwBI9X4YrpJAW2hMT+kcIiHQjBEX20jc7g1sAJlUh6t I38tJFocmfSgb6vf+RWvL8bJ6w8gdwjqqMLfVDgrfsNoEwaACw0fv93NUmkcjRXDHchO vPpGyzFoIxxPooPT+b8yYLeuEOmXhVRKjTYl1RZ6C030N0Myh2D9KKVE4qe93qe2oobI TvTwGGBn5r3+VPV6x+7ZBmlDVSG0JGSEKowu9QicRe9klfqGJN0VyzI+ooVFuGo9X/tC b/2d65AL6BvFwuOx0h+QHH9sGMG0W+hRvuPCrOKiQlMmuD07C0ZTfjpGLnJp6le9VPaJ zjQQ== X-Gm-Message-State: AOAM5317fDFQDPnPEuzLDw7Xqh7PJtpOL0NOqiF5z7OgppwToQXSl/DC 9+IAEGiuQxhD6xqi/pGlF0o= X-Google-Smtp-Source: ABdhPJyqpkdPaW7qdDDm+JfaisXzT8y3g39ZX23oSdficfjYsq0t5gdrLJuBx6leUKk1WJvtfHNphg== X-Received: by 2002:adf:ed46:: with SMTP id u6mr190339wro.295.1621276697146; Mon, 17 May 2021 11:38:17 -0700 (PDT) Received: from arch-x1c3.. (cpc92308-cmbg19-2-0-cust99.5-4.cable.virginm.net. [82.24.248.100]) by smtp.gmail.com with ESMTPSA id f3sm18076625wrp.7.2021.05.17.11.38.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 11:38:15 -0700 (PDT) From: Emil Velikov To: Mauro Carvalho Chehab , Hans Verkuil , Ezequiel Garcia , Philipp Zabel , Alexandre Courbot , Mikhail Ulyanov , kernel@collabora.com Cc: linux-media@vger.kernel.org Subject: [PATCH 3/5] media: v4l2-mem2mem: add job tracing Date: Mon, 17 May 2021 19:37:59 +0100 Message-Id: <20210517183801.1255496-4-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517183801.1255496-1-emil.l.velikov@gmail.com> References: <20210517183801.1255496-1-emil.l.velikov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Emil Velikov Add ftrace events to trace job submission and processing. In particular, allow for tracking the whole job from the initial submission/schedule stage until its completion. Since there can be only a single job, per given file handle we use the handle pointer as a unique identifier. This will allow us to correlate that with the buffers used and their lifespan - coming with later patches. Co-authored-by: Robert Beckett Signed-off-by: Robert Beckett Signed-off-by: Emil Velikov --- Not 100% sold on v4l2_m2m_queue_job(). Currently we denote with src/dst the buffer index, while use use index throughout the rest of the series. Should we suffix those with _index? Additionally, we don't print the type - which is known albeit not machine read-able. I'm leaning towards having making each of those an {src,dst}_buf { .index = foo, .type = bar }. Does that sound reasonable? drivers/media/v4l2-core/v4l2-mem2mem.c | 15 +++ drivers/media/v4l2-core/v4l2-trace.c | 7 ++ include/media/v4l2-mem2mem.h | 11 +++ include/trace/events/v4l2.h | 128 +++++++++++++++++++++++++ 4 files changed, 161 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c index e7f4bf5bc8dd..bf83d1fae701 100644 --- a/drivers/media/v4l2-core/v4l2-mem2mem.c +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c @@ -20,6 +20,7 @@ #include #include #include +#include MODULE_DESCRIPTION("Mem to mem device framework for videobuf"); MODULE_AUTHOR("Pawel Osciak, "); @@ -281,6 +282,7 @@ static void v4l2_m2m_try_run(struct v4l2_m2m_dev *m2m_dev) spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags); dprintk("Running job on m2m_ctx: %p\n", m2m_dev->curr_ctx); + trace_v4l2_m2m_run_job(m2m_dev->curr_ctx); m2m_dev->m2m_ops->device_run(m2m_dev->curr_ctx->priv); } @@ -300,10 +302,12 @@ static void __v4l2_m2m_try_queue(struct v4l2_m2m_dev *m2m_dev, struct vb2_v4l2_buffer *dst, *src; dprintk("Trying to schedule a job for m2m_ctx: %p\n", m2m_ctx); + trace_v4l2_m2m_schedule(m2m_ctx); if (!m2m_ctx->out_q_ctx.q.streaming || !m2m_ctx->cap_q_ctx.q.streaming) { dprintk("Streaming needs to be on for both queues\n"); + trace_v4l2_m2m_schedule_failed(m2m_ctx, V4L2_M2M_NOT_STREAMING); return; } @@ -312,11 +316,13 @@ static void __v4l2_m2m_try_queue(struct v4l2_m2m_dev *m2m_dev, /* If the context is aborted then don't schedule it */ if (m2m_ctx->job_flags & TRANS_ABORT) { dprintk("Aborted context\n"); + trace_v4l2_m2m_schedule_failed(m2m_ctx, V4L2_M2M_ABORTED); goto job_unlock; } if (m2m_ctx->job_flags & TRANS_QUEUED) { dprintk("On job queue already\n"); + trace_v4l2_m2m_schedule_failed(m2m_ctx, V4L2_M2M_ALREADY_QUEUED); goto job_unlock; } @@ -324,10 +330,12 @@ static void __v4l2_m2m_try_queue(struct v4l2_m2m_dev *m2m_dev, dst = v4l2_m2m_next_dst_buf(m2m_ctx); if (!src && !m2m_ctx->out_q_ctx.buffered) { dprintk("No input buffers available\n"); + trace_v4l2_m2m_schedule_failed(m2m_ctx, V4L2_M2M_NO_SRC); goto job_unlock; } if (!dst && !m2m_ctx->cap_q_ctx.buffered) { dprintk("No output buffers available\n"); + trace_v4l2_m2m_schedule_failed(m2m_ctx, V4L2_M2M_NO_DST); goto job_unlock; } @@ -343,6 +351,7 @@ static void __v4l2_m2m_try_queue(struct v4l2_m2m_dev *m2m_dev, if (!dst && !m2m_ctx->cap_q_ctx.buffered) { dprintk("No output buffers available after returning held buffer\n"); + trace_v4l2_m2m_schedule_failed(m2m_ctx, V4L2_M2M_NO_DST_POST_HELD); goto job_unlock; } } @@ -354,17 +363,20 @@ static void __v4l2_m2m_try_queue(struct v4l2_m2m_dev *m2m_dev, if (m2m_ctx->has_stopped) { dprintk("Device has stopped\n"); + trace_v4l2_m2m_schedule_failed(m2m_ctx, V4L2_M2M_DEV_STOPPED); goto job_unlock; } if (m2m_dev->m2m_ops->job_ready && (!m2m_dev->m2m_ops->job_ready(m2m_ctx->priv))) { dprintk("Driver not ready\n"); + trace_v4l2_m2m_schedule_failed(m2m_ctx, V4L2_M2M_DRV_NOT_READY); goto job_unlock; } list_add_tail(&m2m_ctx->queue, &m2m_dev->job_queue); m2m_ctx->job_flags |= TRANS_QUEUED; + trace_v4l2_m2m_queue_job(m2m_ctx, src ? &src->vb2_buf : NULL, dst ? &dst->vb2_buf : NULL); job_unlock: spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job); @@ -426,6 +438,7 @@ static void v4l2_m2m_cancel_job(struct v4l2_m2m_ctx *m2m_ctx) if (m2m_dev->m2m_ops->job_abort) m2m_dev->m2m_ops->job_abort(m2m_ctx->priv); dprintk("m2m_ctx %p running, will wait to complete\n", m2m_ctx); + trace_v4l2_m2m_cancel_job_wait(m2m_ctx); wait_event(m2m_ctx->finished, !(m2m_ctx->job_flags & TRANS_RUNNING)); } else if (m2m_ctx->job_flags & TRANS_QUEUED) { @@ -438,6 +451,7 @@ static void v4l2_m2m_cancel_job(struct v4l2_m2m_ctx *m2m_ctx) /* Do nothing, was not on queue/running */ spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags); } + trace_v4l2_m2m_cancel_job(m2m_ctx); } /* @@ -477,6 +491,7 @@ static bool _v4l2_m2m_job_finish(struct v4l2_m2m_dev *m2m_dev, m2m_dev->curr_ctx->job_flags &= ~(TRANS_QUEUED | TRANS_RUNNING); wake_up(&m2m_dev->curr_ctx->finished); m2m_dev->curr_ctx = NULL; + trace_v4l2_m2m_finish_job(m2m_ctx); return true; } diff --git a/drivers/media/v4l2-core/v4l2-trace.c b/drivers/media/v4l2-core/v4l2-trace.c index 6df26fc7c39c..cde408d06fdc 100644 --- a/drivers/media/v4l2-core/v4l2-trace.c +++ b/drivers/media/v4l2-core/v4l2-trace.c @@ -11,3 +11,10 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(vb2_v4l2_buf_queue); EXPORT_TRACEPOINT_SYMBOL_GPL(vb2_v4l2_dqbuf); EXPORT_TRACEPOINT_SYMBOL_GPL(vb2_v4l2_qbuf); EXPORT_TRACEPOINT_SYMBOL_GPL(v4l2_ioctl_s_fmt); +EXPORT_TRACEPOINT_SYMBOL_GPL(v4l2_m2m_schedule); +EXPORT_TRACEPOINT_SYMBOL_GPL(v4l2_m2m_schedule_failed); +EXPORT_TRACEPOINT_SYMBOL_GPL(v4l2_m2m_queue_job); +EXPORT_TRACEPOINT_SYMBOL_GPL(v4l2_m2m_run_job); +EXPORT_TRACEPOINT_SYMBOL_GPL(v4l2_m2m_cancel_job_wait); +EXPORT_TRACEPOINT_SYMBOL_GPL(v4l2_m2m_cancel_job); +EXPORT_TRACEPOINT_SYMBOL_GPL(v4l2_m2m_finish_job); diff --git a/include/media/v4l2-mem2mem.h b/include/media/v4l2-mem2mem.h index 5a91b548ecc0..82bf54254bd8 100644 --- a/include/media/v4l2-mem2mem.h +++ b/include/media/v4l2-mem2mem.h @@ -15,6 +15,17 @@ #include +enum v4l2_m2m_state { + V4L2_M2M_NOT_STREAMING, + V4L2_M2M_ABORTED, + V4L2_M2M_ALREADY_QUEUED, + V4L2_M2M_NO_SRC, + V4L2_M2M_NO_DST, + V4L2_M2M_NO_DST_POST_HELD, + V4L2_M2M_DEV_STOPPED, + V4L2_M2M_DRV_NOT_READY +}; + /** * struct v4l2_m2m_ops - mem-to-mem device driver callbacks * @device_run: required. Begin the actual job (transaction) inside this diff --git a/include/trace/events/v4l2.h b/include/trace/events/v4l2.h index d11e38676e48..8e382bad5f8e 100644 --- a/include/trace/events/v4l2.h +++ b/include/trace/events/v4l2.h @@ -10,6 +10,7 @@ #include #include #include +#include /* Enums require being exported to userspace, for user tool parsing */ #undef EM @@ -55,6 +56,21 @@ SHOW_TYPE SHOW_FIELD +#define show_reason(state) \ + __print_symbolic(state, SHOW_REASON) + +#define SHOW_REASON \ + EM( V4L2_M2M_NOT_STREAMING, "NOT_STREAMING" ) \ + EM( V4L2_M2M_ABORTED, "ABORTED" ) \ + EM( V4L2_M2M_ALREADY_QUEUED, "ALREADY_QUEUED" ) \ + EM( V4L2_M2M_NO_SRC, "NO_SRC" ) \ + EM( V4L2_M2M_NO_DST, "NO_DST" ) \ + EM( V4L2_M2M_NO_DST_POST_HELD, "NO_DST_POST_HELD" ) \ + EM( V4L2_M2M_DEV_STOPPED, "DEV_STOPPED" ) \ + EMe(V4L2_M2M_DRV_NOT_READY, "DRV_NOT_READY" ) + +SHOW_REASON + /* * Now redefine the EM() and EMe() macros to map the enums to the strings * that will be printed in the output. @@ -266,6 +282,118 @@ DEFINE_EVENT(vb2_v4l2_event_class, vb2_v4l2_qbuf, TP_ARGS(q, vb) ); +/* + * v4l_m2m job tracing + * expected order of events: + * v4l2_m2m_schedule <= start of a job trace + * [v4l2_m2m_schedule_failed*] + * v4l2_m2m_queue_job <= job queued on list of ready jobs + * v4l2_m2m_run_job <= driver told to run the job + * [v4l2_m2m_cancel_job_wait] <= job cancelled, but waiting for completion as it is already running + * [v4l2_m2m_cancel_job*] <= job cancelled + * v4l2_m2m_finish_job <= job finished, end of trace + * + * events in [] indicate optional events, that may appear, but usually would not be expected + * events with * indicate terminal events that end a trace early + * + * A typical job timeline would be a 3 segment period: + * [ scheduled | queued | running ] + * ^ ^ ^ ^ + * |-----------|--------|---------|-- v4l2_m2m_schedule + * |--------|---------|-- v4l2_m2m_queue_job + * |---------|-- v4l2_m2m_run_job + * |-- v4l2_m2m_finish_job + */ +DECLARE_EVENT_CLASS(v4l2_m2m_event_class, + TP_PROTO(struct v4l2_m2m_ctx *ctx), + TP_ARGS(ctx), + + TP_STRUCT__entry( + __field(int, minor) + __field(struct v4l2_fh *, fh) + ), + + TP_fast_assign( + struct v4l2_fh *owner = ctx->cap_q_ctx.q.owner; + + __entry->minor = owner ? owner->vdev->minor : -1; + __entry->fh = owner; + ), + + TP_printk("minor = %d, fh = %p", + __entry->minor, __entry->fh) +) + +DEFINE_EVENT(v4l2_m2m_event_class, v4l2_m2m_schedule, + TP_PROTO(struct v4l2_m2m_ctx *ctx), + TP_ARGS(ctx) +); + +TRACE_EVENT(v4l2_m2m_schedule_failed, + TP_PROTO(struct v4l2_m2m_ctx *ctx, enum v4l2_m2m_state reason), + TP_ARGS(ctx, reason), + + TP_STRUCT__entry( + __field(int, minor) + __field(struct v4l2_fh *, fh) + __field(enum v4l2_m2m_state, reason) + ), + + TP_fast_assign( + struct v4l2_fh *owner = ctx->cap_q_ctx.q.owner; + + __entry->minor = owner ? owner->vdev->minor : -1; + __entry->fh = owner; + __entry->reason = reason; + ), + + TP_printk("minor = %d, fh = %p, reason = %s", + __entry->minor, __entry->fh, show_reason(__entry->reason)) +) + +TRACE_EVENT(v4l2_m2m_queue_job, + TP_PROTO(struct v4l2_m2m_ctx *ctx, struct vb2_buffer *src, struct vb2_buffer *dst), + TP_ARGS(ctx, src, dst), + + TP_STRUCT__entry( + __field(int, minor) + __field(struct v4l2_fh *, fh) + __field(s32, src) + __field(s32, dst) + ), + + TP_fast_assign( + struct v4l2_fh *owner = ctx->cap_q_ctx.q.owner; + + __entry->minor = owner ? owner->vdev->minor : -1; + __entry->fh = owner; + __entry->src = src ? (s32)src->index : -1; + __entry->dst = dst ? (s32)dst->index : -1; + ), + TP_printk("minor = %d, fh = %p, src = %d, dst = %d", + __entry->minor, __entry->fh, __entry->src, __entry->dst) +); + +DEFINE_EVENT(v4l2_m2m_event_class, v4l2_m2m_run_job, + TP_PROTO(struct v4l2_m2m_ctx *ctx), + TP_ARGS(ctx) +); + +DEFINE_EVENT(v4l2_m2m_event_class, v4l2_m2m_cancel_job_wait, + TP_PROTO(struct v4l2_m2m_ctx *ctx), + TP_ARGS(ctx) +); + +DEFINE_EVENT(v4l2_m2m_event_class, v4l2_m2m_cancel_job, + TP_PROTO(struct v4l2_m2m_ctx *ctx), + TP_ARGS(ctx) +); + +DEFINE_EVENT(v4l2_m2m_event_class, v4l2_m2m_finish_job, + TP_PROTO(struct v4l2_m2m_ctx *ctx), + TP_ARGS(ctx) +); + #ifdef CREATE_TRACE_POINTS #define __trace_array_name(a, arr, num) (((unsigned)(a)) < num ? arr[a] : "unknown") static inline void __trace_sprint_v4l2_format(char *str, size_t size, struct v4l2_format *p) From patchwork Mon May 17 18:38:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 12262849 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E88EEC433ED for ; Mon, 17 May 2021 18:38:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CEF02611ED for ; Mon, 17 May 2021 18:38:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235656AbhEQSji (ORCPT ); Mon, 17 May 2021 14:39:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229736AbhEQSjh (ORCPT ); Mon, 17 May 2021 14:39:37 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36FECC061573 for ; Mon, 17 May 2021 11:38:20 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id b7so3512444wmh.5 for ; Mon, 17 May 2021 11:38:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SYzxheHALR2wAy1lf1jbrDxUPl4nLVew24TkSWR6byE=; b=Le2MW7ThCns8XZtSFRnaVE7D1SH7IPUaszXs4w6s5fLdy9d2I4TvwfbDWbUBcwSfrk fpBen4y+KSUVvy+LpnVvyEQvd16EyrmrKNgOeLzwSvfIlQsKalQ65gEtbfQqFCWt0REp exNIIwzUguKIQ/6ndo1cKA1FkNT9OOLE1WYDd4evyRw9wwvl3VUs2ThOPICVSstzuq7c UxYA8f10qGU/r7otIaaAJTFHQ5Ydq6gzwwydaP6Ta57u+B1kmZlX5V9dhHQbtAXGrK5a qNklytGf1MWCJ3Lw0r6jC7Z7pi9WDGV9cYTlK6TLX9Nc3L9mtTS8YKIISg4xSR4XOGoM FiIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SYzxheHALR2wAy1lf1jbrDxUPl4nLVew24TkSWR6byE=; b=kLTh3SlpEbVnETINUxfVFJyK43cW0ZtnvWLKH7MoMbr5H7Li20YgU7WT+vB47nyDjQ j/30faOT7RiJusFduwq9uhtedeIp5dGmm+zpXTzUJ+pbN1aiac22ObrT8MeezUw1t90y WF+tPdZAutpHNljD2miZXnD4T+vCvdiPMo7XDFoHUQPaqwuMnEOw9OGvWV+0rHuW+u+B GrIJ9nmX/FeRvJDD1oj0yiTR5InlScJ+mbk6cp/y4ypTcAYesOQr+y/+KQnaTRU/tEKh uGRbktl9UTKIFTdnUm7MFQowtT04sHtHAyLWiriaZqXOiFa68qB2zEOSDtZPWP7HqgRr PBww== X-Gm-Message-State: AOAM532PHhtdHF1KOmlCZMv7RroeYWtkZxNDbxmmsxZugY9Qa2gQQeQb 52W1iMiQd9S94+Lxolu6GHY= X-Google-Smtp-Source: ABdhPJz/1xaZrP35J2vd51xrH6ZKNVT3+O6GSzQVEQec+7I3vrSf+EA0Sud2Xi2XZD5WiXPfb9vhDw== X-Received: by 2002:a1c:2685:: with SMTP id m127mr434924wmm.135.1621276698944; Mon, 17 May 2021 11:38:18 -0700 (PDT) Received: from arch-x1c3.. (cpc92308-cmbg19-2-0-cust99.5-4.cable.virginm.net. [82.24.248.100]) by smtp.gmail.com with ESMTPSA id f3sm18076625wrp.7.2021.05.17.11.38.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 11:38:18 -0700 (PDT) From: Emil Velikov To: Mauro Carvalho Chehab , Hans Verkuil , Ezequiel Garcia , Philipp Zabel , Alexandre Courbot , Mikhail Ulyanov , kernel@collabora.com Cc: linux-media@vger.kernel.org Subject: [PATCH 4/5] media: v4l2-mem2mem: add v4l2_m2m_buf_done trace point Date: Mon, 17 May 2021 19:38:00 +0100 Message-Id: <20210517183801.1255496-5-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517183801.1255496-1-emil.l.velikov@gmail.com> References: <20210517183801.1255496-1-emil.l.velikov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Emil Velikov Move the function out of the header, as required by the trace API and add a tracepoint. Signed-off-by: Emil Velikov --- drivers/media/v4l2-core/v4l2-mem2mem.c | 9 ++++++ drivers/media/v4l2-core/v4l2-trace.c | 1 + include/media/v4l2-mem2mem.h | 10 +++---- include/trace/events/v4l2.h | 41 ++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c index bf83d1fae701..a83d3e4e7a85 100644 --- a/drivers/media/v4l2-core/v4l2-mem2mem.c +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c @@ -555,6 +555,15 @@ void v4l2_m2m_buf_done_and_job_finish(struct v4l2_m2m_dev *m2m_dev, } EXPORT_SYMBOL(v4l2_m2m_buf_done_and_job_finish); +void +v4l2_m2m_buf_done(struct vb2_v4l2_buffer *buf, enum vb2_buffer_state state) +{ + // TODO: Emil move the trace after done? + trace_v4l2_m2m_buf_done(&buf->vb2_buf, state); + vb2_buffer_done(&buf->vb2_buf, state); +} +EXPORT_SYMBOL(v4l2_m2m_buf_done); + void v4l2_m2m_suspend(struct v4l2_m2m_dev *m2m_dev) { unsigned long flags; diff --git a/drivers/media/v4l2-core/v4l2-trace.c b/drivers/media/v4l2-core/v4l2-trace.c index cde408d06fdc..b70208101f3c 100644 --- a/drivers/media/v4l2-core/v4l2-trace.c +++ b/drivers/media/v4l2-core/v4l2-trace.c @@ -11,6 +11,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(vb2_v4l2_buf_queue); EXPORT_TRACEPOINT_SYMBOL_GPL(vb2_v4l2_dqbuf); EXPORT_TRACEPOINT_SYMBOL_GPL(vb2_v4l2_qbuf); EXPORT_TRACEPOINT_SYMBOL_GPL(v4l2_ioctl_s_fmt); +EXPORT_TRACEPOINT_SYMBOL_GPL(v4l2_m2m_buf_done); EXPORT_TRACEPOINT_SYMBOL_GPL(v4l2_m2m_schedule); EXPORT_TRACEPOINT_SYMBOL_GPL(v4l2_m2m_schedule_failed); EXPORT_TRACEPOINT_SYMBOL_GPL(v4l2_m2m_queue_job); diff --git a/include/media/v4l2-mem2mem.h b/include/media/v4l2-mem2mem.h index 82bf54254bd8..013fd355ff82 100644 --- a/include/media/v4l2-mem2mem.h +++ b/include/media/v4l2-mem2mem.h @@ -229,11 +229,11 @@ void v4l2_m2m_buf_done_and_job_finish(struct v4l2_m2m_dev *m2m_dev, struct v4l2_m2m_ctx *m2m_ctx, enum vb2_buffer_state state); -static inline void -v4l2_m2m_buf_done(struct vb2_v4l2_buffer *buf, enum vb2_buffer_state state) -{ - vb2_buffer_done(&buf->vb2_buf, state); -} +/** + * Something something + */ +void +v4l2_m2m_buf_done(struct vb2_v4l2_buffer *buf, enum vb2_buffer_state state); /** * v4l2_m2m_clear_state() - clear encoding/decoding state diff --git a/include/trace/events/v4l2.h b/include/trace/events/v4l2.h index 8e382bad5f8e..a545f6a13d0a 100644 --- a/include/trace/events/v4l2.h +++ b/include/trace/events/v4l2.h @@ -56,6 +56,20 @@ SHOW_TYPE SHOW_FIELD +#define show_state(state) \ + __print_symbolic(state, SHOW_STATE) + +#define SHOW_STATE \ + EM( VB2_BUF_STATE_DEQUEUED, "DEQUEUED" ) \ + EM( VB2_BUF_STATE_IN_REQUEST, "IN_REQUEST" ) \ + EM( VB2_BUF_STATE_PREPARING, "PREPARING" ) \ + EM( VB2_BUF_STATE_QUEUED, "QUEUED" ) \ + EM( VB2_BUF_STATE_ACTIVE, "ACTIVE" ) \ + EM( VB2_BUF_STATE_DONE, "DONE" ) \ + EMe(VB2_BUF_STATE_ERROR, "ERROR" ) + +SHOW_STATE + #define show_reason(state) \ __print_symbolic(state, SHOW_REASON) @@ -282,6 +296,33 @@ DEFINE_EVENT(vb2_v4l2_event_class, vb2_v4l2_qbuf, TP_ARGS(q, vb) ); +TRACE_EVENT(v4l2_m2m_buf_done, + TP_PROTO(struct vb2_buffer *vb, enum vb2_buffer_state state), + TP_ARGS(vb, state), + + TP_STRUCT__entry( + __field(int, minor) + __field(struct v4l2_fh *, fh) + __field(s32, index) + __field(u32, type) + __field(enum vb2_buffer_state, state) + ), + + TP_fast_assign( + struct v4l2_fh *owner = vb->vb2_queue->owner; + + __entry->minor = owner ? owner->vdev->minor : -1; + __entry->fh = owner; + __entry->index = vb->index; + __entry->type = vb->type; + __entry->state = state; + ), + + TP_printk("minor = %d, fh = %p, index = %u, type = %s, state = %s", + __entry->minor, __entry->fh, __entry->index, + show_type(__entry->type), show_state(__entry->state)) +); + /* * v4l_m2m job tracing * expected order of events: From patchwork Mon May 17 18:38:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 12262851 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B73D0C433B4 for ; Mon, 17 May 2021 18:38:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D08361261 for ; Mon, 17 May 2021 18:38:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235683AbhEQSjj (ORCPT ); Mon, 17 May 2021 14:39:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235655AbhEQSji (ORCPT ); Mon, 17 May 2021 14:39:38 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF65CC061756 for ; Mon, 17 May 2021 11:38:21 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id f6-20020a1c1f060000b0290175ca89f698so104773wmf.5 for ; Mon, 17 May 2021 11:38:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n1j+gTiuTI/Oc9/gjCOyXowKZQPwbNlwNIgJl2Ell+c=; b=U7xC3U69zLf/Rzt39qi+60qZkr1dS+7CsKi/2Nc9C8ETxTVQfADnpOtEFQ9s2/dZVc bTX6JwwCiW9npbWaYUg8R42vVyVo14umzrJwsSaytZN+YddWJGum+jh1AD3IpRsEc879 cCVxzivetDxLdACL3/5X2xxVdMKhiRsUhxPT19J9l5JdW8+HXD4NfnCjJqTPVt8qzwqu rdVkAUGb6bFXXQ0+M2WYadaMp6iJhPMvATqLJN8fo3eHdqXFFEB/5fbh7dFk6ODSuaxi WhvCk7BYbZJyscTteCUeKkrlUcqJdEB0sGfgqlRsc9nUeSRsHXuhOLgBKXPiLWitRopK EbJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n1j+gTiuTI/Oc9/gjCOyXowKZQPwbNlwNIgJl2Ell+c=; b=rb8QDu7EADhEauSodYKxPEMXf6VVKo/5k+gFnCDGqAnFU49++hrB9zgxT5jaTUcMGu cWnYhQmSjEJVvbZtoSWD0QV4Uc3QoQlp22g/AP2RS87Zzmkl2QFhYfCa21s9Dp4Oyth+ B9UYu/D1QPFlSiIWhI/7zXB5lKBKTqIvrp9RCp97VEPdg9bC6gpau/PIandGA2J2LioH N+yT7ZLUQd2steDJLphnlT9AZA3JzrrQO+VK+kT4YT+dXOv10ixlhZez6sN0IOpbD8CV 3z00TJeHeTk4/emzQ939HLi94cLACMq8VELIUuHkiMx3iNUpBMg3kyRFc8H45IXs3lRo 51tQ== X-Gm-Message-State: AOAM5304x8AKxYnFKQQVCfNw3jEQ1ZaPfSwz2sMNoL2g/B1J6Q5njWAd e1wJ06ML7bjOQJee51/gr8o= X-Google-Smtp-Source: ABdhPJxaPhi43STP9/d23C7/2lGJGpeTIyhuouOqmbxLXKxBHXZ11P87OSZhZ0j3b31lADx6/12UsQ== X-Received: by 2002:a1c:9d02:: with SMTP id g2mr417016wme.119.1621276700451; Mon, 17 May 2021 11:38:20 -0700 (PDT) Received: from arch-x1c3.. (cpc92308-cmbg19-2-0-cust99.5-4.cable.virginm.net. [82.24.248.100]) by smtp.gmail.com with ESMTPSA id f3sm18076625wrp.7.2021.05.17.11.38.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 11:38:19 -0700 (PDT) From: Emil Velikov To: Mauro Carvalho Chehab , Hans Verkuil , Ezequiel Garcia , Philipp Zabel , Alexandre Courbot , Mikhail Ulyanov , kernel@collabora.com Cc: linux-media@vger.kernel.org Subject: [PATCH 5/5] media: v4l2-mem2mem: add v4l2_m2m_stream_on/off tracepoints Date: Mon, 17 May 2021 19:38:01 +0100 Message-Id: <20210517183801.1255496-6-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517183801.1255496-1-emil.l.velikov@gmail.com> References: <20210517183801.1255496-1-emil.l.velikov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Emil Velikov v4l2_m2m_stream_on/off are essentially the start/end points in between which jobs can be scheduled. Userspace can easily request a stream_off, while the last job is being processed - we might want to indicate that in the traces. Signed-off-by: Emil Velikov --- drivers/media/v4l2-core/v4l2-mem2mem.c | 2 ++ drivers/media/v4l2-core/v4l2-trace.c | 2 ++ include/trace/events/v4l2.h | 34 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c index a83d3e4e7a85..6aa4ecafac6b 100644 --- a/drivers/media/v4l2-core/v4l2-mem2mem.c +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c @@ -852,6 +852,7 @@ int v4l2_m2m_streamon(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, int ret; vq = v4l2_m2m_get_vq(m2m_ctx, type); + trace_v4l2_m2m_stream_on(m2m_ctx, vq); ret = vb2_streamon(vq, type); if (!ret) v4l2_m2m_try_schedule(m2m_ctx); @@ -895,6 +896,7 @@ int v4l2_m2m_streamoff(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, wake_up(&m2m_ctx->finished); } spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job); + trace_v4l2_m2m_stream_off(m2m_ctx, &q_ctx->q); return 0; } diff --git a/drivers/media/v4l2-core/v4l2-trace.c b/drivers/media/v4l2-core/v4l2-trace.c index b70208101f3c..ce9d393eb69e 100644 --- a/drivers/media/v4l2-core/v4l2-trace.c +++ b/drivers/media/v4l2-core/v4l2-trace.c @@ -19,3 +19,5 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(v4l2_m2m_run_job); EXPORT_TRACEPOINT_SYMBOL_GPL(v4l2_m2m_cancel_job_wait); EXPORT_TRACEPOINT_SYMBOL_GPL(v4l2_m2m_cancel_job); EXPORT_TRACEPOINT_SYMBOL_GPL(v4l2_m2m_finish_job); +EXPORT_TRACEPOINT_SYMBOL_GPL(v4l2_m2m_stream_on); +EXPORT_TRACEPOINT_SYMBOL_GPL(v4l2_m2m_stream_off); diff --git a/include/trace/events/v4l2.h b/include/trace/events/v4l2.h index a545f6a13d0a..a48a8859a4ef 100644 --- a/include/trace/events/v4l2.h +++ b/include/trace/events/v4l2.h @@ -326,6 +326,7 @@ TRACE_EVENT(v4l2_m2m_buf_done, /* * v4l_m2m job tracing * expected order of events: + * v4l2_m2m_stream_on <= userspace request to start stream processing * v4l2_m2m_schedule <= start of a job trace * [v4l2_m2m_schedule_failed*] * v4l2_m2m_queue_job <= job queued on list of ready jobs @@ -333,6 +334,7 @@ TRACE_EVENT(v4l2_m2m_buf_done, * [v4l2_m2m_cancel_job_wait] <= job cancelled, but waiting for completion as it is already running * [v4l2_m2m_cancel_job*] <= job cancelled * v4l2_m2m_finish_job <= job finished, end of trace + * v4l2_m2m_stream_off <= userspace request to stop stream processing * * events in [] indicate optional events, that may appear, but usually would not be expected * events with * indicate terminal events that end a trace early @@ -435,6 +437,38 @@ DEFINE_EVENT(v4l2_m2m_event_class, v4l2_m2m_finish_job, TP_ARGS(ctx) ); +DECLARE_EVENT_CLASS(v4l2_m2m_streaming_class, + TP_PROTO(struct v4l2_m2m_ctx *ctx, struct vb2_queue *queue), + TP_ARGS(ctx, queue), + + TP_STRUCT__entry( + __field(int, minor) + __field(struct v4l2_fh *, fh) + __field(u32, type) + ), + + TP_fast_assign( + struct v4l2_fh *owner = ctx->cap_q_ctx.q.owner; + + __entry->minor = owner ? owner->vdev->minor : -1; + __entry->fh = owner; + __entry->type = queue->type; + + ), + TP_printk("minor = %d, fh = %p, type = %p", + __entry->minor, __entry->fh, show_type(__entry->type)) +) + +DEFINE_EVENT(v4l2_m2m_streaming_class, v4l2_m2m_stream_on, + TP_PROTO(struct v4l2_m2m_ctx *ctx, struct vb2_queue *queue), + TP_ARGS(ctx, queue) +); + +DEFINE_EVENT(v4l2_m2m_streaming_class, v4l2_m2m_stream_off, + TP_PROTO(struct v4l2_m2m_ctx *ctx, struct vb2_queue *queue), + TP_ARGS(ctx, queue) +); + #ifdef CREATE_TRACE_POINTS #define __trace_array_name(a, arr, num) (((unsigned)(a)) < num ? arr[a] : "unknown") static inline void __trace_sprint_v4l2_format(char *str, size_t size, struct v4l2_format *p)