From patchwork Fri Jun 26 08:51:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 11627413 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 879C31392 for ; Fri, 26 Jun 2020 12:29:39 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 59B72207FC for ; Fri, 26 Jun 2020 12:29:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Bp6ggLZG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 59B72207FC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=g3y8ZyzE+gVjl4Enr6bjhMomdFXQWydOT7Og5vUfU4k=; b=Bp6ggLZGiyXdPhc10xYE7BISBw wusrE1IgGG3l56sKMtfJnt9Z/cLKrdDBko01V6uLaRMcPrd+pOI3COgRT+aTbtxTlc5DnfRrXFtGM 5UkCaTh0SZnS9ekx+Tvhaw1076vJZ8Da+1L6OlO2L/OYPT4Z5+g0Pg2s3CJI72Q7JmhD4PROHPPsO vfNJ3kGoAE3sZtKO27wLdVFlF7RPAPFv4mGH/fK96YVDhZRyf8O+hY2Wcs8MGlsj354Gwjvw7aAMW p/DC5o/6XuY+6AJgzBqmIvGT7si3Y3drcxAioGEs/mt2gvb+bpV3zvyiKKC1ua+O4Fp6hQNNcvWeS jaJjHnsQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jonTz-0006xl-2k; Fri, 26 Jun 2020 12:29:27 +0000 Received: from bhuna.collabora.co.uk ([2a00:1098:0:82:1000:25:2eeb:e3e3]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jomO7-00080S-IU for linux-rockchip@lists.infradead.org; Fri, 26 Jun 2020 11:19:23 +0000 Received: from localhost.localdomain (p200300cb8737cf00e1b48557745ca459.dip0.t-ipconnect.de [IPv6:2003:cb:8737:cf00:e1b4:8557:745c:a459]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: dafna) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 9C5882A59BF; Fri, 26 Jun 2020 09:51:50 +0100 (BST) From: Dafna Hirschfeld To: linux-media@vger.kernel.org, laurent.pinchart@ideasonboard.com Subject: [PATCH v2 3/4] media: staging: rkisp1: stats: replace locks wq_lock, irq_lock with one lock Date: Fri, 26 Jun 2020 10:51:40 +0200 Message-Id: <20200626085141.7646-4-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200626085141.7646-1-dafna.hirschfeld@collabora.com> References: <20200626085141.7646-1-dafna.hirschfeld@collabora.com> X-Spam-Note: CRM114 invocation failed X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mchehab@kernel.org, dafna.hirschfeld@collabora.com, dafna3@gmail.com, tfiga@chromium.org, hverkuil@xs4all.nl, linux-rockchip@lists.infradead.org, helen.koike@collabora.com, sakari.ailus@linux.intel.com, kernel@collabora.com, ezequiel@collabora.com MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org This patch removes two locks in the rkisp1_stats struct: - The mutex 'wq_lock' that is used to protect the buffers list 'stat' - The spin_lock 'irq_lock' that is used to protect the variable 'is_streaming' It replaces them with one spin_lock 'lock' that protects both the buffers list and the 'is_streaming' variable. In later patch the reading of the statistics will move to the isr so there will be no need for the mutex 'wq_lock' Signed-off-by: Dafna Hirschfeld Acked-by: Helen Koike --- drivers/staging/media/rkisp1/rkisp1-common.h | 5 ++-- drivers/staging/media/rkisp1/rkisp1-stats.c | 25 +++++++++----------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/drivers/staging/media/rkisp1/rkisp1-common.h b/drivers/staging/media/rkisp1/rkisp1-common.h index d2c669091fae..c92ae1b7093f 100644 --- a/drivers/staging/media/rkisp1/rkisp1-common.h +++ b/drivers/staging/media/rkisp1/rkisp1-common.h @@ -178,7 +178,7 @@ struct rkisp1_capture { /* * struct rkisp1_stats - ISP Statistics device * - * @irq_lock: buffer queue lock + * @lock: locks the buffer list 'stat' and 'is_streaming' * @stat: stats buffer list * @readout_wq: workqueue for statistics information read */ @@ -186,13 +186,12 @@ struct rkisp1_stats { struct rkisp1_vdev_node vnode; struct rkisp1_device *rkisp1; - spinlock_t irq_lock; + spinlock_t lock; /* locks 'is_streaming', and 'stats' */ struct list_head stat; struct v4l2_format vdev_fmt; bool is_streaming; struct workqueue_struct *readout_wq; - struct mutex wq_lock; }; /* diff --git a/drivers/staging/media/rkisp1/rkisp1-stats.c b/drivers/staging/media/rkisp1/rkisp1-stats.c index d4f0df4342e0..58329e6b0598 100644 --- a/drivers/staging/media/rkisp1/rkisp1-stats.c +++ b/drivers/staging/media/rkisp1/rkisp1-stats.c @@ -133,9 +133,9 @@ static void rkisp1_stats_vb2_buf_queue(struct vb2_buffer *vb) stats_buf->vaddr[0] = vb2_plane_vaddr(vb, 0); - mutex_lock(&stats_dev->wq_lock); + spin_lock_irq(&stats_dev->lock); list_add_tail(&stats_buf->queue, &stats_dev->stat); - mutex_unlock(&stats_dev->wq_lock); + spin_unlock_irq(&stats_dev->lock); } static int rkisp1_stats_vb2_buf_prepare(struct vb2_buffer *vb) @@ -155,13 +155,13 @@ static void rkisp1_stats_vb2_stop_streaming(struct vb2_queue *vq) unsigned int i; /* Make sure no new work queued in isr before draining wq */ - spin_lock_irq(&stats->irq_lock); + spin_lock_irq(&stats->lock); stats->is_streaming = false; - spin_unlock_irq(&stats->irq_lock); + spin_unlock_irq(&stats->lock); drain_workqueue(stats->readout_wq); - mutex_lock(&stats->wq_lock); + spin_lock_irq(&stats->lock); for (i = 0; i < RKISP1_ISP_STATS_REQ_BUFS_MAX; i++) { if (list_empty(&stats->stat)) break; @@ -170,7 +170,7 @@ static void rkisp1_stats_vb2_stop_streaming(struct vb2_queue *vq) list_del(&buf->queue); vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); } - mutex_unlock(&stats->wq_lock); + spin_unlock_irq(&stats->lock); } static int @@ -340,14 +340,14 @@ rkisp1_stats_send_measurement(struct rkisp1_stats *stats, frame_sequence = meas_work->frame_id; } - mutex_lock(&stats->wq_lock); + spin_lock_irq(&stats->lock); /* get one empty buffer */ if (!list_empty(&stats->stat)) { cur_buf = list_first_entry(&stats->stat, struct rkisp1_buffer, queue); list_del(&cur_buf->queue); } - mutex_unlock(&stats->wq_lock); + spin_unlock_irq(&stats->lock); if (!cur_buf) return; @@ -396,7 +396,7 @@ void rkisp1_stats_isr(struct rkisp1_stats *stats, u32 isp_ris) struct rkisp1_isp_readout_work *work; unsigned int isp_mis_tmp = 0; - spin_lock(&stats->irq_lock); + spin_lock(&stats->lock); rkisp1_write(rkisp1, RKISP1_STATS_MEAS_MASK, RKISP1_CIF_ISP_ICR); @@ -425,7 +425,7 @@ void rkisp1_stats_isr(struct rkisp1_stats *stats, u32 isp_ris) } unlock: - spin_unlock(&stats->irq_lock); + spin_unlock(&stats->lock); } static void rkisp1_init_stats(struct rkisp1_stats *stats) @@ -445,10 +445,9 @@ int rkisp1_stats_register(struct rkisp1_stats *stats, int ret; stats->rkisp1 = rkisp1; - mutex_init(&stats->wq_lock); mutex_init(&node->vlock); INIT_LIST_HEAD(&stats->stat); - spin_lock_init(&stats->irq_lock); + spin_lock_init(&stats->lock); strscpy(vdev->name, RKISP1_STATS_DEV_NAME, sizeof(vdev->name)); @@ -495,7 +494,6 @@ int rkisp1_stats_register(struct rkisp1_stats *stats, err_release_queue: vb2_queue_release(vdev->queue); mutex_destroy(&node->vlock); - mutex_destroy(&stats->wq_lock); return ret; } @@ -509,5 +507,4 @@ void rkisp1_stats_unregister(struct rkisp1_stats *stats) media_entity_cleanup(&vdev->entity); vb2_queue_release(vdev->queue); mutex_destroy(&node->vlock); - mutex_destroy(&stats->wq_lock); }