Message ID | 20230914133323.198857-2-benjamin.gaignard@collabora.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp404053vqi; Thu, 14 Sep 2023 07:52:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG/1fj66QMT87XPfZ0ykUP0qGRLrlEGeqBGpF78h4RM/S/nFZzPtMWaHBPmzCFFnltfXaWU X-Received: by 2002:a05:6a20:54a1:b0:155:2c91:f8e5 with SMTP id i33-20020a056a2054a100b001552c91f8e5mr6239757pzk.14.1694703157703; Thu, 14 Sep 2023 07:52:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694703157; cv=none; d=google.com; s=arc-20160816; b=Wcgjf/1edmxkgbFeOJvklmtp7mujGOXUu03CmPATr8uR2e48B4SmlaUZkIPr77UtGq t2Tv4q7yVZBQ9NitVi5/NxeE+B2kwhB9JGR7C0NeCfIlkUsyhMp9Wmcn0qDsF4g9fAKB iOvtmV8CJ/P6AYDOsSdDR5HB25FRhK7pjRvyaolJV8MhmVeFp1ABjVq+aAim6clJh8wx U5XSFuICo6O87HBbi33j/HOzjbZab4pxmgZ1hOIMKGY7kD+TnV0xBV8rKkkAZg1OlfMi GTBLMKKPlDjqWhLUuG8W/nqsr/4e+RLH3dgUSSmtrcYxLKdiAea7UBUfugxXUIs97KJP DsRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1be88CI2RuhWrOGMD26vIYNo9it5Gul2OJz2q+CAvS4=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=sCaTOJCJ4kI6Mh6lv0KTaNxkgoMCGk+D6B5wigdJ0npn98O8L3AAEVUnNGSPEoisSE HS3w7/968NrquJBRvsyE8Jmlbu07EAE1gRWF4MX2fbYSwUsUgZw45EtD1sxwX52NbHMe tod5ci32kf9oXZeypKHa/DyK0M5AwZQciqDxw9brSk3iAk3OkgY5TDNswetkPz2bC1Ew l2aYaQCqmrtSXarFvKIxd0FGvSTfmv7YD19Y+QaJaBYMWFkFycyijMZLEUyUt8ABRgL/ aVHywlOgG+u+YGsGXz9RESIi6brzgYMYAWeVo8E4DUrFuAHOdXWv7+cxxoziZsk9mEO6 rDuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=aSyp7ffu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id bx39-20020a056a02052700b005703b492a23si1816111pgb.308.2023.09.14.07.52.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 07:52:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=aSyp7ffu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id ADEDC8381E68; Thu, 14 Sep 2023 06:33:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239039AbjINNdj (ORCPT <rfc822;chrisfriedt@gmail.com> + 35 others); Thu, 14 Sep 2023 09:33:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230174AbjINNdh (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 14 Sep 2023 09:33:37 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CCF11FC0; Thu, 14 Sep 2023 06:33:33 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:36f2:37bd:ccbb:373f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madras.collabora.co.uk (Postfix) with ESMTPSA id 9993F660734C; Thu, 14 Sep 2023 14:33:31 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1694698412; bh=+eRsvnpNumq6bQf88LlWZR7Lny7uqYBNBiPKeHOjtOs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aSyp7ffubuNGkWb5eWQFg+eXWjYVUNooVpYC/nK0PtWo3aDnYbC4wrVxLTimb72Tl YbjeDlDt10JlG0HL7pr1oRCiK5NXQf2LB6EYt1cAcqy1aYaCMKKWuaGa9B09B8wC0n zC+GhyPII95M+/TAA6VoBiJBDJhvETgIcvFwYXQ4DhyLgimlxBiavxHHJdbNh/FI6o PGGJDDdUf7+2YpCCUyLTqDuzQ/Kt+vBVpVfffjdxGcdDMvCTTOncE6jLOjUlc22BjI JlW6oiKwMcXQkSGNZwDvqIT6T3pkCnleWWYex4bCEEZnLgJ83XhWmUJZwjqkMOHzdB 5/zbTa0w3ffwA== From: Benjamin Gaignard <benjamin.gaignard@collabora.com> To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ming.qian@nxp.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, gregkh@linuxfoundation.org, hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, kernel@collabora.com, Benjamin Gaignard <benjamin.gaignard@collabora.com> Subject: [PATCH v7 01/49] media: videobuf2: Rework offset 'cookie' encoding pattern Date: Thu, 14 Sep 2023 15:32:35 +0200 Message-Id: <20230914133323.198857-2-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230914133323.198857-1-benjamin.gaignard@collabora.com> References: <20230914133323.198857-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 14 Sep 2023 06:33:51 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777025057886219313 X-GMAIL-MSGID: 1777025057886219313 |
Series |
Add DELETE_BUF ioctl
|
|
Commit Message
Benjamin Gaignard
Sept. 14, 2023, 1:32 p.m. UTC
Change how offset 'cookie' field value is computed to make possible
to use more buffers (up to 0x7fff)
With this encoding pattern we know the maximum number that a queue
could store so we can check ing at queue init time.
It also make easier and faster to find buffer and plane from using
the offset field.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
---
.../media/common/videobuf2/videobuf2-core.c | 48 +++++++++----------
1 file changed, 24 insertions(+), 24 deletions(-)
Comments
On 14/09/2023 15:32, Benjamin Gaignard wrote: > Change how offset 'cookie' field value is computed to make possible > to use more buffers (up to 0x7fff) > With this encoding pattern we know the maximum number that a queue > could store so we can check ing at queue init time. > It also make easier and faster to find buffer and plane from using > the offset field. > > Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com> > --- > .../media/common/videobuf2/videobuf2-core.c | 48 +++++++++---------- > 1 file changed, 24 insertions(+), 24 deletions(-) > > diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c > index cf6727d9c81f..cf3b9f5b69b7 100644 > --- a/drivers/media/common/videobuf2/videobuf2-core.c > +++ b/drivers/media/common/videobuf2/videobuf2-core.c > @@ -31,6 +31,10 @@ > > #include <trace/events/vb2.h> > > +#define PLANE_INDEX_SHIFT (PAGE_SHIFT + 3) > +#define PLANE_INDEX_MASK 0x7 > +#define BUFFER_INDEX_MASK 0x7fff It's a bit paranoid, but I would like to add a check for PAGE_SHIFT here: #if PAGE_SHIFT != 12 #error Expected PAGE_SHIFT to be 12 #endif Things will go very wrong if this value ever changes... > + > static int debug; > module_param(debug, int, 0644); > > @@ -358,21 +362,23 @@ static void __setup_offsets(struct vb2_buffer *vb) > unsigned int plane; > unsigned long off = 0; > > - if (vb->index) { > - struct vb2_buffer *prev = q->bufs[vb->index - 1]; > - struct vb2_plane *p = &prev->planes[prev->num_planes - 1]; > - > - off = PAGE_ALIGN(p->m.offset + p->length); > - } > + /* > + * Offsets cookies value have the following constraints: > + * - a buffer could have up to 8 planes. > + * - v4l2 mem2mem use bit 30 to distinguish between source and destination buffers. > + * - must be page aligned > + * That led to this bit mapping: > + * |30 |29 15|14 12|11 0| > + * |DST_QUEUE_OFF_BASE|buffer index|plane index| 0 | > + * where there is 15 bits to store buffer index. typo: is -> are > + */ > + off = vb->index << (PLANE_INDEX_SHIFT); No need for (). > > for (plane = 0; plane < vb->num_planes; ++plane) { > - vb->planes[plane].m.offset = off; > + vb->planes[plane].m.offset = off + (plane << PAGE_SHIFT); > > dprintk(q, 3, "buffer %d, plane %d offset 0x%08lx\n", > vb->index, plane, off); > - > - off += vb->planes[plane].length; > - off = PAGE_ALIGN(off); > } > } > > @@ -2209,21 +2215,15 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off, > return -EBUSY; > } > > - /* > - * Go over all buffers and their planes, comparing the given offset > - * with an offset assigned to each plane. If a match is found, > - * return its buffer and plane numbers. > - */ > - for (buffer = 0; buffer < q->num_buffers; ++buffer) { > - vb = q->bufs[buffer]; > + /* Get buffer and plane from the offset */ > + buffer = (off >> PLANE_INDEX_SHIFT) & BUFFER_INDEX_MASK; > + plane = (off >> PAGE_SHIFT) & PLANE_INDEX_MASK; > > - for (plane = 0; plane < vb->num_planes; ++plane) { > - if (vb->planes[plane].m.offset == off) { > - *_buffer = buffer; > - *_plane = plane; > - return 0; > - } > - } > + vb = q->bufs[buffer]; Hmm, shouldn't there be a sanity check for the buffer value? > + if (vb->planes[plane].m.offset == off) { Does this check make sense? > + *_buffer = buffer; > + *_plane = plane; > + return 0; > } > > return -EINVAL; How about this: /* Get buffer and plane from the offset */ *buffer = (off >> PLANE_INDEX_SHIFT) & BUFFER_INDEX_MASK; *plane = (off >> PAGE_SHIFT) & PLANE_INDEX_MASK; if (*buffer >= q->num_buffers || *plane >= q->bufs[buffer]->num_planes) return -EINVAL; return 0; Regards, Hans
diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index cf6727d9c81f..cf3b9f5b69b7 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -31,6 +31,10 @@ #include <trace/events/vb2.h> +#define PLANE_INDEX_SHIFT (PAGE_SHIFT + 3) +#define PLANE_INDEX_MASK 0x7 +#define BUFFER_INDEX_MASK 0x7fff + static int debug; module_param(debug, int, 0644); @@ -358,21 +362,23 @@ static void __setup_offsets(struct vb2_buffer *vb) unsigned int plane; unsigned long off = 0; - if (vb->index) { - struct vb2_buffer *prev = q->bufs[vb->index - 1]; - struct vb2_plane *p = &prev->planes[prev->num_planes - 1]; - - off = PAGE_ALIGN(p->m.offset + p->length); - } + /* + * Offsets cookies value have the following constraints: + * - a buffer could have up to 8 planes. + * - v4l2 mem2mem use bit 30 to distinguish between source and destination buffers. + * - must be page aligned + * That led to this bit mapping: + * |30 |29 15|14 12|11 0| + * |DST_QUEUE_OFF_BASE|buffer index|plane index| 0 | + * where there is 15 bits to store buffer index. + */ + off = vb->index << (PLANE_INDEX_SHIFT); for (plane = 0; plane < vb->num_planes; ++plane) { - vb->planes[plane].m.offset = off; + vb->planes[plane].m.offset = off + (plane << PAGE_SHIFT); dprintk(q, 3, "buffer %d, plane %d offset 0x%08lx\n", vb->index, plane, off); - - off += vb->planes[plane].length; - off = PAGE_ALIGN(off); } } @@ -2209,21 +2215,15 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off, return -EBUSY; } - /* - * Go over all buffers and their planes, comparing the given offset - * with an offset assigned to each plane. If a match is found, - * return its buffer and plane numbers. - */ - for (buffer = 0; buffer < q->num_buffers; ++buffer) { - vb = q->bufs[buffer]; + /* Get buffer and plane from the offset */ + buffer = (off >> PLANE_INDEX_SHIFT) & BUFFER_INDEX_MASK; + plane = (off >> PAGE_SHIFT) & PLANE_INDEX_MASK; - for (plane = 0; plane < vb->num_planes; ++plane) { - if (vb->planes[plane].m.offset == off) { - *_buffer = buffer; - *_plane = plane; - return 0; - } - } + vb = q->bufs[buffer]; + if (vb->planes[plane].m.offset == off) { + *_buffer = buffer; + *_plane = plane; + return 0; } return -EINVAL;