Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2424020rdb; Mon, 5 Feb 2024 06:18:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IE01l+2AVjqQU2fp65H/OLooxe9Gwifeiglum82WY9p8eS2AzOHteftbDos7CdFsyD3so3S X-Received: by 2002:a05:6830:1ca:b0:6e1:377e:c426 with SMTP id r10-20020a05683001ca00b006e1377ec426mr14635026ota.19.1707142687305; Mon, 05 Feb 2024 06:18:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707142687; cv=pass; d=google.com; s=arc-20160816; b=wFCLJv47jWCO4F4XgpRHaRrE5gyBtgRmIfx+nw+VL5FzetHiO1hrP5RwCgb7vf3DTU XXWtPBtbkh1GUIwlEiOO86htr/0RKa7kowGYtRkKi5QMfhjYDDtJCMZiwlttSGt+uwnF fgcKarmQQXBZVzK0QNxUn1bLMqZt00JYh5/B/tkPFRmiYONzFv2bRhnFuafhHV7hxp1+ 50i010V/Fok1vySWNtwlRWeQ7hx4GqUpiZe0XjWSUjvBAYvl0/amtZWRQNwwsZ9nkdG3 tFCeKyRPs1SVal80/iZ9wXdhHy+OBAnk287BWg78oJoo6eTQQML6BAl4Cs0Vu8k7AVCE 17uA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id; bh=ZyGoSJKhp5/s+dPHSHv1nZiE3SpJGKjwj6hEW42pO6o=; fh=3xSQuskzCx64O2kM9hchckXbONivI9bKtpCw/hTaJ/c=; b=t95oHR8CAha49/PyX5uJD75O7K5A5uzXlPE4Vvnni7xs1zusxRqFTicQgaepOyc66O aCGpdxgaux9YpZGOZqfHVBjx28dz35vojf/LXEyFb4TiVvO8DUKIVIW2sH1jGGWKwmrZ isPOD/2epr7zzT7rEY9eCRj2zSMy1wJ/E+WEj4dvI/D9nkJq2orGfficcURo+J6Z1L3g Iiqe6z03PwJg5AVODrGeMeQhYbgFOc1wNBi4eNpxjxF2VBV2mzrBL6wqUAzp+jlndu27 44l4HEJ8zJuq639BegQOnUYmkW0xgMur+QauLyN58PZq+vsQrUGpX3PbEHvdTNNM9Rrv 9FRg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-52800-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52800-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl X-Forwarded-Encrypted: i=1; AJvYcCWGEwdWH6nndfemgBi5vNNqpiWb1bdGnkMRl0W0bCsnT04Wr8ipB/lJqEo5I6c7tfk4fsaxK6TbZZKbpvt5l0hge3VrKW0ja5UmIg+liQ== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id y1-20020a05622a004100b0042c258c14e3si2430179qtw.244.2024.02.05.06.18.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 06:18:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-52800-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-52800-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52800-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 187271C2521A for ; Mon, 5 Feb 2024 14:16:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E888A2C859; Mon, 5 Feb 2024 14:15:30 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 280D22DF87; Mon, 5 Feb 2024 14:15:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707142530; cv=none; b=e6ThGwfGebfiVNOkT47oVvwv2pPlI09UB3Z9MkvXYhJR9da4D+ie0obkQTe5laC0JaA47Kv919yUJGw+zbH19B1pqOymsyav70FbNUGYHc9J8aMikGjnGjY/TYewTXGouswKtcGA8IIOToPgVYWrLyu92/PtYoPtDPnpdGA3g4U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707142530; c=relaxed/simple; bh=gUmWB0WUxmbFtOW6iXntjLks2xNk20WwAGRGYL9uiH0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Q/YdcuPA2QGK4JVGaaXJqZT3oJicRRmJv5kxndZfirnMbm+Nb4HRO9Znzxz8yRgXb0i4GDO91WP8LehLqnjqiGl6zuL59bzDxPwH1vqp6SnQXojyAKyi/0fOl/NxbKzgkaL1q+J0JqKDLqkyymHdJP1/vdfj3Epy+B/+LV8E2I4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8CC27C433C7; Mon, 5 Feb 2024 14:15:28 +0000 (UTC) Message-ID: Date: Mon, 5 Feb 2024 15:15:26 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v18 6/9] media: core: Free range of buffers Content-Language: en-US, nl To: Benjamin Gaignard , mchehab@kernel.org Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, kernel@collabora.com References: <20240126110141.135896-1-benjamin.gaignard@collabora.com> <20240126110141.135896-7-benjamin.gaignard@collabora.com> From: Hans Verkuil Autocrypt: addr=hverkuil@xs4all.nl; keydata= xsFNBFQ84W0BEAC7EF1iL4s3tY8cRTVkJT/297h0Hz0ypA+ByVM4CdU9sN6ua/YoFlr9k0K4 BFUlg7JzJoUuRbKxkYb8mmqOe722j7N3HO8+ofnio5cAP5W0WwDpM0kM84BeHU0aPSTsWiGR yw55SOK2JBSq7hueotWLfJLobMWhQii0Zd83hGT9SIt9uHaHjgwmtTH7MSTIiaY6N14nw2Ud C6Uykc1va0Wqqc2ov5ihgk/2k2SKa02ookQI3e79laOrbZl5BOXNKR9LguuOZdX4XYR3Zi6/ BsJ7pVCK9xkiVf8svlEl94IHb+sa1KrlgGv3fn5xgzDw8Z222TfFceDL/2EzUyTdWc4GaPMC E/c1B4UOle6ZHg02+I8tZicjzj5+yffv1lB5A1btG+AmoZrgf0X2O1B96fqgHx8w9PIpVERN YsmkfxvhfP3MO3oHh8UY1OLKdlKamMneCLk2up1Zlli347KMjHAVjBAiy8qOguKF9k7HOjif JCLYTkggrRiEiE1xg4tblBNj8WGyKH+u/hwwwBqCd/Px2HvhAsJQ7DwuuB3vBAp845BJYUU3 06kRihFqbO0vEt4QmcQDcbWINeZ2zX5TK7QQ91ldHdqJn6MhXulPKcM8tCkdD8YNXXKyKqNl UVqXnarz8m2JCbHgjEkUlAJCNd6m3pfESLZwSWsLYL49R5yxIwARAQABzSFIYW5zIFZlcmt1 aWwgPGh2ZXJrdWlsQH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ovhDxKyhFwXOP0Rv8H378/+14TaykknRBIKEc0+lcr+EMOSUR5eg4aURb8Gc3Uc7fgQ6q UssTXzHPyj1hAyDpfu8DzAwlh4kKFTodxSsKAjI45SLjadSc94/5Gy8645Y1KgBzBPTH7Q== In-Reply-To: <20240126110141.135896-7-benjamin.gaignard@collabora.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 26/01/2024 12:01, Benjamin Gaignard wrote: > Improve __vb2_queue_free() and __vb2_free_mem() to free > range of buffers and not only the last few buffers. > Intoduce starting index to be flexible on range and change the loops Intoduce -> Introduce > according to this parameters. parameters -> parameter > > Signed-off-by: Benjamin Gaignard > --- > .../media/common/videobuf2/videobuf2-core.c | 56 +++++++++---------- > 1 file changed, 26 insertions(+), 30 deletions(-) > > diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c > index 1506fbe8fc76..8486a2f2c09d 100644 > --- a/drivers/media/common/videobuf2/videobuf2-core.c > +++ b/drivers/media/common/videobuf2/videobuf2-core.c > @@ -540,17 +540,16 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, > } > > /* > - * __vb2_free_mem() - release all video buffer memory for a given queue > + * __vb2_free_mem() - release video buffer memory for a given range of > + * buffers in a given queue > */ > -static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers) > +static void __vb2_free_mem(struct vb2_queue *q, unsigned int start, unsigned int count) > { > - unsigned int buffer; > + unsigned int i; > struct vb2_buffer *vb; > - unsigned int q_num_buffers = vb2_get_num_buffers(q); > > - for (buffer = q_num_buffers - buffers; buffer < q_num_buffers; > - ++buffer) { > - vb = vb2_get_buffer(q, buffer); > + for (i = start; i < start + count; i++) { > + vb = vb2_get_buffer(q, i); > if (!vb) > continue; > > @@ -565,35 +564,33 @@ static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers) > } > > /* > - * __vb2_queue_free() - free buffers at the end of the queue - video memory and > + * __vb2_queue_free() - free @count buffers from @start index of the queue - video memory and > * related information, if no buffers are left return the queue to an > * uninitialized state. Might be called even if the queue has already been freed. > */ > -static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) > +static void __vb2_queue_free(struct vb2_queue *q, unsigned int start, unsigned int count) > { > - unsigned int buffer; > - unsigned int q_num_buffers = vb2_get_num_buffers(q); > + unsigned int i; > > lockdep_assert_held(&q->mmap_lock); > > /* Call driver-provided cleanup function for each buffer, if provided */ > - for (buffer = q_num_buffers - buffers; buffer < q_num_buffers; > - ++buffer) { > - struct vb2_buffer *vb = vb2_get_buffer(q, buffer); > + for (i = start; i < start + count; i++) { > + struct vb2_buffer *vb = vb2_get_buffer(q, i); > > if (vb && vb->planes[0].mem_priv) > call_void_vb_qop(vb, buf_cleanup, vb); > } > > /* Release video buffer memory */ > - __vb2_free_mem(q, buffers); > + __vb2_free_mem(q, start, count); > > #ifdef CONFIG_VIDEO_ADV_DEBUG > /* > * Check that all the calls were balanced during the life-time of this > * queue. If not then dump the counters to the kernel log. > */ > - if (q_num_buffers) { > + if (vb2_get_num_buffers(q)) { > bool unbalanced = q->cnt_start_streaming != q->cnt_stop_streaming || > q->cnt_prepare_streaming != q->cnt_unprepare_streaming || > q->cnt_wait_prepare != q->cnt_wait_finish; > @@ -619,8 +616,8 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) > q->cnt_stop_streaming = 0; > q->cnt_unprepare_streaming = 0; > } > - for (buffer = 0; buffer < vb2_get_num_buffers(q); buffer++) { > - struct vb2_buffer *vb = vb2_get_buffer(q, buffer); > + for (i = start; i < start + count; i++) { > + struct vb2_buffer *vb = vb2_get_buffer(q, i); > bool unbalanced; > > if (!vb) > @@ -637,7 +634,7 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) > > if (unbalanced) { > pr_info("unbalanced counters for queue %p, buffer %d:\n", > - q, buffer); > + q, i); > if (vb->cnt_buf_init != vb->cnt_buf_cleanup) > pr_info(" buf_init: %u buf_cleanup: %u\n", > vb->cnt_buf_init, vb->cnt_buf_cleanup); > @@ -671,9 +668,8 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) > #endif > > /* Free vb2 buffers */ > - for (buffer = q_num_buffers - buffers; buffer < q_num_buffers; > - ++buffer) { > - struct vb2_buffer *vb = vb2_get_buffer(q, buffer); > + for (i = start; i < start + count; i++) { > + struct vb2_buffer *vb = vb2_get_buffer(q, i); > > if (!vb) > continue; > @@ -713,7 +709,7 @@ EXPORT_SYMBOL(vb2_buffer_in_use); > static bool __buffers_in_use(struct vb2_queue *q) > { > unsigned int buffer; > - for (buffer = 0; buffer < vb2_get_num_buffers(q); ++buffer) { > + for (buffer = 0; buffer < q->max_num_buffers; ++buffer) { > struct vb2_buffer *vb = vb2_get_buffer(q, buffer); > > if (!vb) > @@ -899,7 +895,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, > * queued without ever calling STREAMON. > */ > __vb2_queue_cancel(q); > - __vb2_queue_free(q, q_num_bufs); > + __vb2_queue_free(q, 0, q->max_num_buffers); > mutex_unlock(&q->mmap_lock); > > /* > @@ -1002,7 +998,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, > * from already queued buffers and it will reset q->memory to > * VB2_MEMORY_UNKNOWN. > */ > - __vb2_queue_free(q, allocated_buffers); > + __vb2_queue_free(q, first_index, allocated_buffers); > mutex_unlock(&q->mmap_lock); > return ret; > } > @@ -1127,7 +1123,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, > * from already queued buffers and it will reset q->memory to > * VB2_MEMORY_UNKNOWN. > */ > - __vb2_queue_free(q, allocated_buffers); > + __vb2_queue_free(q, *first_index, allocated_buffers); > mutex_unlock(&q->mmap_lock); > return -ENOMEM; > } > @@ -1742,7 +1738,7 @@ static int vb2_start_streaming(struct vb2_queue *q) > * Forcefully reclaim buffers if the driver did not > * correctly return them to vb2. > */ > - for (i = 0; i < vb2_get_num_buffers(q); ++i) { > + for (i = 0; i < q->max_num_buffers; ++i) { > vb = vb2_get_buffer(q, i); > > if (!vb) > @@ -2148,7 +2144,7 @@ static void __vb2_queue_cancel(struct vb2_queue *q) > * to vb2 in stop_streaming(). > */ > if (WARN_ON(atomic_read(&q->owned_by_drv_count))) { > - for (i = 0; i < vb2_get_num_buffers(q); i++) { > + for (i = 0; i < q->max_num_buffers; i++) { > struct vb2_buffer *vb = vb2_get_buffer(q, i); > > if (!vb) > @@ -2192,7 +2188,7 @@ static void __vb2_queue_cancel(struct vb2_queue *q) > * call to __fill_user_buffer() after buf_finish(). That order can't > * be changed, so we can't move the buf_finish() to __vb2_dqbuf(). > */ > - for (i = 0; i < vb2_get_num_buffers(q); i++) { > + for (i = 0; i < q->max_num_buffers; i++) { > struct vb2_buffer *vb; > struct media_request *req; > > @@ -2619,7 +2615,7 @@ void vb2_core_queue_release(struct vb2_queue *q) > __vb2_cleanup_fileio(q); > __vb2_queue_cancel(q); > mutex_lock(&q->mmap_lock); > - __vb2_queue_free(q, vb2_get_num_buffers(q)); > + __vb2_queue_free(q, 0, q->max_num_buffers); > vb2_core_free_buffers_storage(q); > mutex_unlock(&q->mmap_lock); > } Regards, Hans