From patchwork Tue May 12 12:05:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 11543039 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 A5FBF15E6 for ; Tue, 12 May 2020 12:06:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 990392078E for ; Tue, 12 May 2020 12:06:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729568AbgELMGI (ORCPT ); Tue, 12 May 2020 08:06:08 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:35054 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729207AbgELMGI (ORCPT ); Tue, 12 May 2020 08:06:08 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dafna) with ESMTPSA id 7F9C32A20B2 From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: dafna.hirschfeld@collabora.com, helen.koike@collabora.com, ezequiel@collabora.com, hverkuil@xs4all.nl, kernel@collabora.com, dafna3@gmail.com, sakari.ailus@linux.intel.com, linux-rockchip@lists.infradead.org, mchehab@kernel.org, laurent.pinchart@ideasonboard.com Subject: [PATCH 1/5] media: staging: rkisp1: return IRQ_NONE in isr when irq isn't for ISP Date: Tue, 12 May 2020 14:05:18 +0200 Message-Id: <20200512120522.25960-2-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200512120522.25960-1-dafna.hirschfeld@collabora.com> References: <20200512120522.25960-1-dafna.hirschfeld@collabora.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Helen Koike rkisp1 shares the interrupt line, then it shouldn't always return IRQ_HANDLED, otherwise it can flag as handled an interrupt that wans't meant for ISP. return IRQ_NONE when the interrupt wans't meant for ISP Fixes: d65dd85281fb ("media: staging: rkisp1: add Rockchip ISP1 base driver") Signed-off-by: Helen Koike Signed-off-by: Dafna Hirschfeld Reported-by: kbuild test robot Acked-by: Helen Koike Reviewed-by: Laurent Pinchart --- drivers/staging/media/rkisp1/rkisp1-capture.c | 7 ++++++- drivers/staging/media/rkisp1/rkisp1-common.h | 6 +++--- drivers/staging/media/rkisp1/rkisp1-dev.c | 14 ++++++++++---- drivers/staging/media/rkisp1/rkisp1-isp.c | 12 ++++++++---- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/drivers/staging/media/rkisp1/rkisp1-capture.c b/drivers/staging/media/rkisp1/rkisp1-capture.c index f69235f82c45..19021875e8a9 100644 --- a/drivers/staging/media/rkisp1/rkisp1-capture.c +++ b/drivers/staging/media/rkisp1/rkisp1-capture.c @@ -649,12 +649,15 @@ static void rkisp1_handle_buffer(struct rkisp1_capture *cap) rkisp1_set_next_buf(cap); } -void rkisp1_capture_isr(struct rkisp1_device *rkisp1) +irqreturn_t rkisp1_capture_isr(struct rkisp1_device *rkisp1) { unsigned int i; u32 status; status = rkisp1_read(rkisp1, RKISP1_CIF_MI_MIS); + if (!status) + return IRQ_NONE; + rkisp1_write(rkisp1, status, RKISP1_CIF_MI_ICR); for (i = 0; i < ARRAY_SIZE(rkisp1->capture_devs); ++i) { @@ -682,6 +685,8 @@ void rkisp1_capture_isr(struct rkisp1_device *rkisp1) cap->is_streaming = false; wake_up(&cap->done); } + + return IRQ_HANDLED; } /* ---------------------------------------------------------------------------- diff --git a/drivers/staging/media/rkisp1/rkisp1-common.h b/drivers/staging/media/rkisp1/rkisp1-common.h index 0c4fe503adc9..33dffe21c769 100644 --- a/drivers/staging/media/rkisp1/rkisp1-common.h +++ b/drivers/staging/media/rkisp1/rkisp1-common.h @@ -305,9 +305,9 @@ void rkisp1_isp_unregister(struct rkisp1_device *rkisp1); const struct rkisp1_isp_mbus_info *rkisp1_isp_mbus_info_get(u32 mbus_code); -void rkisp1_isp_isr(struct rkisp1_device *rkisp1); -void rkisp1_mipi_isr(struct rkisp1_device *rkisp1); -void rkisp1_capture_isr(struct rkisp1_device *rkisp1); +irqreturn_t rkisp1_isp_isr(struct rkisp1_device *rkisp1); +irqreturn_t rkisp1_mipi_isr(struct rkisp1_device *rkisp1); +irqreturn_t rkisp1_capture_isr(struct rkisp1_device *rkisp1); void rkisp1_stats_isr(struct rkisp1_stats *stats, u32 isp_ris); void rkisp1_params_isr(struct rkisp1_device *rkisp1, u32 isp_mis); diff --git a/drivers/staging/media/rkisp1/rkisp1-dev.c b/drivers/staging/media/rkisp1/rkisp1-dev.c index 9ac38bafb839..b7f43dab71c8 100644 --- a/drivers/staging/media/rkisp1/rkisp1-dev.c +++ b/drivers/staging/media/rkisp1/rkisp1-dev.c @@ -387,10 +387,13 @@ static int rkisp1_entities_register(struct rkisp1_device *rkisp1) return ret; } -static irqreturn_t rkisp1_isr(int irq, void *ctx) +irqreturn_t rkisp1_isr(int irq, void *ctx) { struct device *dev = ctx; struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); + irqreturn_t isp_ret; + irqreturn_t cap_ret; + irqreturn_t mipi_ret; /* * Call rkisp1_capture_isr() first to handle the frame that @@ -398,9 +401,12 @@ static irqreturn_t rkisp1_isr(int irq, void *ctx) * it is potentially incremented by rkisp1_isp_isr() in the vertical * sync. */ - rkisp1_capture_isr(rkisp1); - rkisp1_isp_isr(rkisp1); - rkisp1_mipi_isr(rkisp1); + cap_ret = rkisp1_capture_isr(rkisp1); + isp_ret = rkisp1_isp_isr(rkisp1); + mipi_ret = rkisp1_mipi_isr(rkisp1); + + if (isp_ret == IRQ_NONE && cap_ret == IRQ_NONE && mipi_ret == IRQ_NONE) + return IRQ_NONE; return IRQ_HANDLED; } diff --git a/drivers/staging/media/rkisp1/rkisp1-isp.c b/drivers/staging/media/rkisp1/rkisp1-isp.c index dc2b59a0160a..19ab0ed323aa 100644 --- a/drivers/staging/media/rkisp1/rkisp1-isp.c +++ b/drivers/staging/media/rkisp1/rkisp1-isp.c @@ -1046,13 +1046,13 @@ void rkisp1_isp_unregister(struct rkisp1_device *rkisp1) * Interrupt handlers */ -void rkisp1_mipi_isr(struct rkisp1_device *rkisp1) +irqreturn_t rkisp1_mipi_isr(struct rkisp1_device *rkisp1) { u32 val, status; status = rkisp1_read(rkisp1, RKISP1_CIF_MIPI_MIS); if (!status) - return; + return IRQ_NONE; rkisp1_write(rkisp1, status, RKISP1_CIF_MIPI_ICR); @@ -1087,6 +1087,8 @@ void rkisp1_mipi_isr(struct rkisp1_device *rkisp1) } else { rkisp1->debug.mipi_error++; } + + return IRQ_HANDLED; } static void rkisp1_isp_queue_event_sof(struct rkisp1_isp *isp) @@ -1106,13 +1108,13 @@ static void rkisp1_isp_queue_event_sof(struct rkisp1_isp *isp) v4l2_event_queue(isp->sd.devnode, &event); } -void rkisp1_isp_isr(struct rkisp1_device *rkisp1) +irqreturn_t rkisp1_isp_isr(struct rkisp1_device *rkisp1) { u32 status, isp_err; status = rkisp1_read(rkisp1, RKISP1_CIF_ISP_MIS); if (!status) - return; + return IRQ_NONE; rkisp1_write(rkisp1, status, RKISP1_CIF_ISP_ICR); @@ -1148,4 +1150,6 @@ void rkisp1_isp_isr(struct rkisp1_device *rkisp1) * Do the updates in the order of the processing flow. */ rkisp1_params_isr(rkisp1, status); + + return IRQ_HANDLED; } From patchwork Tue May 12 12:05:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 11543043 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 B8236186E for ; Tue, 12 May 2020 12:06:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AB11620674 for ; Tue, 12 May 2020 12:06:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729569AbgELMGI (ORCPT ); Tue, 12 May 2020 08:06:08 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:35068 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728085AbgELMGI (ORCPT ); Tue, 12 May 2020 08:06:08 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dafna) with ESMTPSA id 6E0EC2A20CA From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: dafna.hirschfeld@collabora.com, helen.koike@collabora.com, ezequiel@collabora.com, hverkuil@xs4all.nl, kernel@collabora.com, dafna3@gmail.com, sakari.ailus@linux.intel.com, linux-rockchip@lists.infradead.org, mchehab@kernel.org, laurent.pinchart@ideasonboard.com Subject: [PATCH 2/5] media: staging: rkisp1: use a macro for the statistics flags mask Date: Tue, 12 May 2020 14:05:19 +0200 Message-Id: <20200512120522.25960-3-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200512120522.25960-1-dafna.hirschfeld@collabora.com> References: <20200512120522.25960-1-dafna.hirschfeld@collabora.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The mask of the ready statistics flags is used in several places in the code using bitwise-or. Use a macro for that to make the code more readable. Signed-off-by: Dafna Hirschfeld Acked-by: Helen Koike Reviewed-by: Laurent Pinchart --- drivers/staging/media/rkisp1/rkisp1-common.h | 4 ++++ drivers/staging/media/rkisp1/rkisp1-isp.c | 5 +---- drivers/staging/media/rkisp1/rkisp1-stats.c | 12 +++--------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/staging/media/rkisp1/rkisp1-common.h b/drivers/staging/media/rkisp1/rkisp1-common.h index 33dffe21c769..c0ab16c6b3db 100644 --- a/drivers/staging/media/rkisp1/rkisp1-common.h +++ b/drivers/staging/media/rkisp1/rkisp1-common.h @@ -42,6 +42,10 @@ #define RKISP1_MAX_BUS_CLK 8 +#define RKISP1_STATS_MEAS_MASK (RKISP1_CIF_ISP_AWB_DONE | \ + RKISP1_CIF_ISP_AFM_FIN | \ + RKISP1_CIF_ISP_EXP_END | \ + RKISP1_CIF_ISP_HIST_MEASURE_RDY) enum rkisp1_rsz_pad { RKISP1_RSZ_PAD_SINK, RKISP1_RSZ_PAD_SRC, diff --git a/drivers/staging/media/rkisp1/rkisp1-isp.c b/drivers/staging/media/rkisp1/rkisp1-isp.c index 19ab0ed323aa..49b47e1734b0 100644 --- a/drivers/staging/media/rkisp1/rkisp1-isp.c +++ b/drivers/staging/media/rkisp1/rkisp1-isp.c @@ -1137,10 +1137,7 @@ irqreturn_t rkisp1_isp_isr(struct rkisp1_device *rkisp1) /* New frame from the sensor received */ isp_ris = rkisp1_read(rkisp1, RKISP1_CIF_ISP_RIS); - if (isp_ris & (RKISP1_CIF_ISP_AWB_DONE | - RKISP1_CIF_ISP_AFM_FIN | - RKISP1_CIF_ISP_EXP_END | - RKISP1_CIF_ISP_HIST_MEASURE_RDY)) + if (isp_ris & RKISP1_STATS_MEAS_MASK) rkisp1_stats_isr(&rkisp1->stats, isp_ris); } diff --git a/drivers/staging/media/rkisp1/rkisp1-stats.c b/drivers/staging/media/rkisp1/rkisp1-stats.c index 6dfcbdc3deb8..12998db955e6 100644 --- a/drivers/staging/media/rkisp1/rkisp1-stats.c +++ b/drivers/staging/media/rkisp1/rkisp1-stats.c @@ -407,22 +407,16 @@ void rkisp1_stats_isr(struct rkisp1_stats *stats, u32 isp_ris) spin_lock(&stats->irq_lock); - val = RKISP1_CIF_ISP_AWB_DONE | RKISP1_CIF_ISP_AFM_FIN | - RKISP1_CIF_ISP_EXP_END | RKISP1_CIF_ISP_HIST_MEASURE_RDY; + val = RKISP1_STATS_MEAS_MASK; rkisp1_write(rkisp1, val, RKISP1_CIF_ISP_ICR); isp_mis_tmp = rkisp1_read(rkisp1, RKISP1_CIF_ISP_MIS); - if (isp_mis_tmp & - (RKISP1_CIF_ISP_AWB_DONE | RKISP1_CIF_ISP_AFM_FIN | - RKISP1_CIF_ISP_EXP_END | RKISP1_CIF_ISP_HIST_MEASURE_RDY)) + if (isp_mis_tmp & RKISP1_STATS_MEAS_MASK) rkisp1->debug.stats_error++; if (!stats->is_streaming) goto unlock; - if (isp_ris & (RKISP1_CIF_ISP_AWB_DONE | - RKISP1_CIF_ISP_AFM_FIN | - RKISP1_CIF_ISP_EXP_END | - RKISP1_CIF_ISP_HIST_MEASURE_RDY)) { + if (isp_ris & RKISP1_STATS_MEAS_MASK) { work = kzalloc(sizeof(*work), GFP_ATOMIC); if (work) { INIT_WORK(&work->work, From patchwork Tue May 12 12:05:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 11543045 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 C6EF8912 for ; Tue, 12 May 2020 12:06:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B136E2082E for ; Tue, 12 May 2020 12:06:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729593AbgELMGK (ORCPT ); Tue, 12 May 2020 08:06:10 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:35082 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729524AbgELMGJ (ORCPT ); Tue, 12 May 2020 08:06:09 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dafna) with ESMTPSA id 2EDE92A20C9 From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: dafna.hirschfeld@collabora.com, helen.koike@collabora.com, ezequiel@collabora.com, hverkuil@xs4all.nl, kernel@collabora.com, dafna3@gmail.com, sakari.ailus@linux.intel.com, linux-rockchip@lists.infradead.org, mchehab@kernel.org, laurent.pinchart@ideasonboard.com Subject: [PATCH 3/5] media: staging: rkisp1: stats: use spin_lock_irqsave for irq_lock Date: Tue, 12 May 2020 14:05:20 +0200 Message-Id: <20200512120522.25960-4-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200512120522.25960-1-dafna.hirschfeld@collabora.com> References: <20200512120522.25960-1-dafna.hirschfeld@collabora.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Currently 'spin_lock' is used in order to lock the 'irq_lock'. This should be replaced with 'spin_lock_irqsave' since it is used in the irq handler. Signed-off-by: Dafna Hirschfeld --- drivers/staging/media/rkisp1/rkisp1-stats.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/staging/media/rkisp1/rkisp1-stats.c b/drivers/staging/media/rkisp1/rkisp1-stats.c index 12998db955e6..5578fdeb8a18 100644 --- a/drivers/staging/media/rkisp1/rkisp1-stats.c +++ b/drivers/staging/media/rkisp1/rkisp1-stats.c @@ -403,9 +403,10 @@ void rkisp1_stats_isr(struct rkisp1_stats *stats, u32 isp_ris) struct rkisp1_device *rkisp1 = stats->rkisp1; struct rkisp1_isp_readout_work *work; unsigned int isp_mis_tmp = 0; + unsigned long flags; u32 val; - spin_lock(&stats->irq_lock); + spin_lock_irqsave(&stats->irq_lock, flags); val = RKISP1_STATS_MEAS_MASK; rkisp1_write(rkisp1, val, RKISP1_CIF_ISP_ICR); @@ -435,7 +436,7 @@ void rkisp1_stats_isr(struct rkisp1_stats *stats, u32 isp_ris) } unlock: - spin_unlock(&stats->irq_lock); + spin_unlock_irqrestore(&stats->irq_lock, flags); } static void rkisp1_init_stats(struct rkisp1_stats *stats) From patchwork Tue May 12 12:05:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 11543047 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 265D015E6 for ; Tue, 12 May 2020 12:06:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 178D32078A for ; Tue, 12 May 2020 12:06:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729595AbgELMGL (ORCPT ); Tue, 12 May 2020 08:06:11 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:35096 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729207AbgELMGK (ORCPT ); Tue, 12 May 2020 08:06:10 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dafna) with ESMTPSA id C64F32A20C6 From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: dafna.hirschfeld@collabora.com, helen.koike@collabora.com, ezequiel@collabora.com, hverkuil@xs4all.nl, kernel@collabora.com, dafna3@gmail.com, sakari.ailus@linux.intel.com, linux-rockchip@lists.infradead.org, mchehab@kernel.org, laurent.pinchart@ideasonboard.com Subject: [PATCH 4/5] media: staging: rkisp1: stats: replace locks wq_lock, irq_lock with one lock Date: Tue, 12 May 2020 14:05:21 +0200 Message-Id: <20200512120522.25960-5-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200512120522.25960-1-dafna.hirschfeld@collabora.com> References: <20200512120522.25960-1-dafna.hirschfeld@collabora.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.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 'stats_lock' that protects both the buffers list and the 'is_streaming' variable. Signed-off-by: Dafna Hirschfeld --- drivers/staging/media/rkisp1/rkisp1-common.h | 5 ++-- drivers/staging/media/rkisp1/rkisp1-stats.c | 27 ++++++++++---------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/drivers/staging/media/rkisp1/rkisp1-common.h b/drivers/staging/media/rkisp1/rkisp1-common.h index c0ab16c6b3db..c635bb0a7727 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 + * @stats_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 stats_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 5578fdeb8a18..e6fb2c5f3b3e 100644 --- a/drivers/staging/media/rkisp1/rkisp1-stats.c +++ b/drivers/staging/media/rkisp1/rkisp1-stats.c @@ -130,12 +130,13 @@ static void rkisp1_stats_vb2_buf_queue(struct vb2_buffer *vb) container_of(vbuf, struct rkisp1_buffer, vb); struct vb2_queue *vq = vb->vb2_queue; struct rkisp1_stats *stats_dev = vq->drv_priv; + unsigned long flags; stats_buf->vaddr[0] = vb2_plane_vaddr(vb, 0); - mutex_lock(&stats_dev->wq_lock); + spin_lock_irqsave(&stats_dev->stats_lock, flags); list_add_tail(&stats_buf->queue, &stats_dev->stat); - mutex_unlock(&stats_dev->wq_lock); + spin_unlock_irqrestore(&stats_dev->stats_lock, flags); } static int rkisp1_stats_vb2_buf_prepare(struct vb2_buffer *vb) @@ -156,13 +157,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_irqsave(&stats->irq_lock, flags); + spin_lock_irqsave(&stats->stats_lock, flags); stats->is_streaming = false; - spin_unlock_irqrestore(&stats->irq_lock, flags); + spin_unlock_irqrestore(&stats->stats_lock, flags); drain_workqueue(stats->readout_wq); - mutex_lock(&stats->wq_lock); + spin_lock_irqsave(&stats->stats_lock, flags); for (i = 0; i < RKISP1_ISP_STATS_REQ_BUFS_MAX; i++) { if (list_empty(&stats->stat)) break; @@ -171,7 +172,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_irqrestore(&stats->stats_lock, flags); } static int @@ -333,6 +334,7 @@ rkisp1_stats_send_measurement(struct rkisp1_stats *stats, unsigned int frame_sequence = atomic_read(&stats->rkisp1->isp.frame_sequence); u64 timestamp = ktime_get_ns(); + unsigned long flags; if (frame_sequence != meas_work->frame_id) { dev_warn(stats->rkisp1->dev, @@ -341,14 +343,14 @@ rkisp1_stats_send_measurement(struct rkisp1_stats *stats, frame_sequence = meas_work->frame_id; } - mutex_lock(&stats->wq_lock); + spin_lock_irqsave(&stats->stats_lock, flags); /* 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_irqrestore(&stats->stats_lock, flags); if (!cur_buf) return; @@ -406,7 +408,7 @@ void rkisp1_stats_isr(struct rkisp1_stats *stats, u32 isp_ris) unsigned long flags; u32 val; - spin_lock_irqsave(&stats->irq_lock, flags); + spin_lock_irqsave(&stats->stats_lock, flags); val = RKISP1_STATS_MEAS_MASK; rkisp1_write(rkisp1, val, RKISP1_CIF_ISP_ICR); @@ -436,7 +438,7 @@ void rkisp1_stats_isr(struct rkisp1_stats *stats, u32 isp_ris) } unlock: - spin_unlock_irqrestore(&stats->irq_lock, flags); + spin_unlock_irqrestore(&stats->stats_lock, flags); } static void rkisp1_init_stats(struct rkisp1_stats *stats) @@ -456,10 +458,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->stats_lock); strscpy(vdev->name, RKISP1_STATS_DEV_NAME, sizeof(vdev->name)); @@ -506,7 +507,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; } @@ -520,5 +520,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); } From patchwork Tue May 12 12:05:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 11543049 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 C739914B4 for ; Tue, 12 May 2020 12:06:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A54AC20747 for ; Tue, 12 May 2020 12:06:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729382AbgELMGM (ORCPT ); Tue, 12 May 2020 08:06:12 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:35068 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728085AbgELMGL (ORCPT ); Tue, 12 May 2020 08:06:11 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dafna) with ESMTPSA id 708352A20C7 From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: dafna.hirschfeld@collabora.com, helen.koike@collabora.com, ezequiel@collabora.com, hverkuil@xs4all.nl, kernel@collabora.com, dafna3@gmail.com, sakari.ailus@linux.intel.com, linux-rockchip@lists.infradead.org, mchehab@kernel.org, laurent.pinchart@ideasonboard.com Subject: [PATCH 5/5] media: staging: rkisp1: replace workqueue with threaded irq for reading statistics registers Date: Tue, 12 May 2020 14:05:22 +0200 Message-Id: <20200512120522.25960-6-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200512120522.25960-1-dafna.hirschfeld@collabora.com> References: <20200512120522.25960-1-dafna.hirschfeld@collabora.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Reading the statistics registers might take too long to run inside the irq handler. Currently it is deferred to bottom half using workqueues. This patch replaces the workqueue with threaded interrupts for reading the statistics registers. A new struct type 'rkisp1_kstats_buffer' is used as the statistics buffers. The struct has a field 'ris' which is the flags of ready statistics. If new statistics are ready, the irq handler sets this variable and the frame sequence on the next available buffer and returns IRQ_WAKE_THREAD. Then the threaded interrupt reads the registers and calls vb2_buffer_done. Signed-off-by: Dafna Hirschfeld Reported-by: kbuild test robot --- drivers/staging/media/rkisp1/TODO | 1 - drivers/staging/media/rkisp1/rkisp1-common.h | 5 +- drivers/staging/media/rkisp1/rkisp1-dev.c | 8 +- drivers/staging/media/rkisp1/rkisp1-isp.c | 5 +- drivers/staging/media/rkisp1/rkisp1-stats.c | 167 ++++++++----------- 5 files changed, 76 insertions(+), 110 deletions(-) diff --git a/drivers/staging/media/rkisp1/TODO b/drivers/staging/media/rkisp1/TODO index c0cbec0a164d..bdb1b8f73556 100644 --- a/drivers/staging/media/rkisp1/TODO +++ b/drivers/staging/media/rkisp1/TODO @@ -1,5 +1,4 @@ * Fix pad format size for statistics and parameters entities. -* Use threaded interrupt for rkisp1_stats_isr(), remove work queue. * Fix checkpatch errors. * Review and comment every lock * Handle quantization diff --git a/drivers/staging/media/rkisp1/rkisp1-common.h b/drivers/staging/media/rkisp1/rkisp1-common.h index c635bb0a7727..c8adcdf661ab 100644 --- a/drivers/staging/media/rkisp1/rkisp1-common.h +++ b/drivers/staging/media/rkisp1/rkisp1-common.h @@ -190,8 +190,6 @@ struct rkisp1_stats { struct list_head stat; struct v4l2_format vdev_fmt; bool is_streaming; - - struct workqueue_struct *readout_wq; }; /* @@ -308,10 +306,11 @@ void rkisp1_isp_unregister(struct rkisp1_device *rkisp1); const struct rkisp1_isp_mbus_info *rkisp1_isp_mbus_info_get(u32 mbus_code); +irqreturn_t rkisp1_read_stats_threaded_irq(int irq, void *ctx); irqreturn_t rkisp1_isp_isr(struct rkisp1_device *rkisp1); irqreturn_t rkisp1_mipi_isr(struct rkisp1_device *rkisp1); irqreturn_t rkisp1_capture_isr(struct rkisp1_device *rkisp1); -void rkisp1_stats_isr(struct rkisp1_stats *stats, u32 isp_ris); +irqreturn_t rkisp1_stats_isr(struct rkisp1_stats *stats, u32 isp_ris); void rkisp1_params_isr(struct rkisp1_device *rkisp1, u32 isp_mis); int rkisp1_capture_devs_register(struct rkisp1_device *rkisp1); diff --git a/drivers/staging/media/rkisp1/rkisp1-dev.c b/drivers/staging/media/rkisp1/rkisp1-dev.c index b7f43dab71c8..12e2e8559acd 100644 --- a/drivers/staging/media/rkisp1/rkisp1-dev.c +++ b/drivers/staging/media/rkisp1/rkisp1-dev.c @@ -405,6 +405,8 @@ irqreturn_t rkisp1_isr(int irq, void *ctx) isp_ret = rkisp1_isp_isr(rkisp1); mipi_ret = rkisp1_mipi_isr(rkisp1); + if (isp_ret == IRQ_WAKE_THREAD) + return IRQ_WAKE_THREAD; if (isp_ret == IRQ_NONE && cap_ret == IRQ_NONE && mipi_ret == IRQ_NONE) return IRQ_NONE; @@ -490,8 +492,10 @@ static int rkisp1_probe(struct platform_device *pdev) if (irq < 0) return irq; - ret = devm_request_irq(dev, irq, rkisp1_isr, IRQF_SHARED, - dev_driver_string(dev), dev); + ret = devm_request_threaded_irq(dev, irq, rkisp1_isr, + rkisp1_read_stats_threaded_irq, + IRQF_SHARED, + dev_driver_string(dev), dev); if (ret) { dev_err(dev, "request irq failed: %d\n", ret); return ret; diff --git a/drivers/staging/media/rkisp1/rkisp1-isp.c b/drivers/staging/media/rkisp1/rkisp1-isp.c index 49b47e1734b0..09893073af00 100644 --- a/drivers/staging/media/rkisp1/rkisp1-isp.c +++ b/drivers/staging/media/rkisp1/rkisp1-isp.c @@ -1111,6 +1111,7 @@ static void rkisp1_isp_queue_event_sof(struct rkisp1_isp *isp) irqreturn_t rkisp1_isp_isr(struct rkisp1_device *rkisp1) { u32 status, isp_err; + irqreturn_t ret = IRQ_HANDLED; status = rkisp1_read(rkisp1, RKISP1_CIF_ISP_MIS); if (!status) @@ -1138,7 +1139,7 @@ irqreturn_t rkisp1_isp_isr(struct rkisp1_device *rkisp1) /* New frame from the sensor received */ isp_ris = rkisp1_read(rkisp1, RKISP1_CIF_ISP_RIS); if (isp_ris & RKISP1_STATS_MEAS_MASK) - rkisp1_stats_isr(&rkisp1->stats, isp_ris); + ret = rkisp1_stats_isr(&rkisp1->stats, isp_ris); } /* @@ -1148,5 +1149,5 @@ irqreturn_t rkisp1_isp_isr(struct rkisp1_device *rkisp1) */ rkisp1_params_isr(rkisp1, status); - return IRQ_HANDLED; + return ret; } diff --git a/drivers/staging/media/rkisp1/rkisp1-stats.c b/drivers/staging/media/rkisp1/rkisp1-stats.c index e6fb2c5f3b3e..f5eaa81362ea 100644 --- a/drivers/staging/media/rkisp1/rkisp1-stats.c +++ b/drivers/staging/media/rkisp1/rkisp1-stats.c @@ -18,19 +18,9 @@ #define RKISP1_ISP_STATS_REQ_BUFS_MIN 2 #define RKISP1_ISP_STATS_REQ_BUFS_MAX 8 -enum rkisp1_isp_readout_cmd { - RKISP1_ISP_READOUT_MEAS, - RKISP1_ISP_READOUT_META, -}; - -struct rkisp1_isp_readout_work { - struct work_struct work; - struct rkisp1_stats *stats; - - unsigned int frame_id; - unsigned int isp_ris; - enum rkisp1_isp_readout_cmd readout; - struct vb2_buffer *vb; +struct rkisp1_kstats_buffer { + struct rkisp1_buffer buff; + u32 ris; }; static int rkisp1_stats_enum_fmt_meta_cap(struct file *file, void *priv, @@ -126,16 +116,17 @@ static int rkisp1_stats_vb2_queue_setup(struct vb2_queue *vq, static void rkisp1_stats_vb2_buf_queue(struct vb2_buffer *vb) { struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); - struct rkisp1_buffer *stats_buf = - container_of(vbuf, struct rkisp1_buffer, vb); + struct rkisp1_kstats_buffer *kstats_buf = + container_of(vbuf, struct rkisp1_kstats_buffer, buff.vb); struct vb2_queue *vq = vb->vb2_queue; struct rkisp1_stats *stats_dev = vq->drv_priv; unsigned long flags; - stats_buf->vaddr[0] = vb2_plane_vaddr(vb, 0); + kstats_buf->buff.vaddr[0] = vb2_plane_vaddr(vb, 0); + kstats_buf->ris = 0; spin_lock_irqsave(&stats_dev->stats_lock, flags); - list_add_tail(&stats_buf->queue, &stats_dev->stat); + list_add_tail(&kstats_buf->buff.queue, &stats_dev->stat); spin_unlock_irqrestore(&stats_dev->stats_lock, flags); } @@ -152,25 +143,19 @@ static int rkisp1_stats_vb2_buf_prepare(struct vb2_buffer *vb) static void rkisp1_stats_vb2_stop_streaming(struct vb2_queue *vq) { struct rkisp1_stats *stats = vq->drv_priv; - struct rkisp1_buffer *buf; + struct rkisp1_kstats_buffer *buf; unsigned long flags; unsigned int i; - /* Make sure no new work queued in isr before draining wq */ spin_lock_irqsave(&stats->stats_lock, flags); stats->is_streaming = false; - spin_unlock_irqrestore(&stats->stats_lock, flags); - - drain_workqueue(stats->readout_wq); - - spin_lock_irqsave(&stats->stats_lock, flags); for (i = 0; i < RKISP1_ISP_STATS_REQ_BUFS_MAX; i++) { if (list_empty(&stats->stat)) break; buf = list_first_entry(&stats->stat, - struct rkisp1_buffer, queue); - list_del(&buf->queue); - vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); + struct rkisp1_kstats_buffer, buff.queue); + list_del(&buf->buff.queue); + vb2_buffer_done(&buf->buff.vb.vb2_buf, VB2_BUF_STATE_ERROR); } spin_unlock_irqrestore(&stats->stats_lock, flags); } @@ -207,7 +192,7 @@ rkisp1_stats_init_vb2_queue(struct vb2_queue *q, struct rkisp1_stats *stats) q->drv_priv = stats; q->ops = &rkisp1_stats_vb2_ops; q->mem_ops = &vb2_vmalloc_memops; - q->buf_struct_size = sizeof(struct rkisp1_buffer); + q->buf_struct_size = sizeof(struct rkisp1_kstats_buffer); q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; q->lock = &node->vlock; @@ -325,85 +310,81 @@ static void rkisp1_stats_get_bls_meas(struct rkisp1_stats *stats, } } -static void -rkisp1_stats_send_measurement(struct rkisp1_stats *stats, - struct rkisp1_isp_readout_work *meas_work) +irqreturn_t rkisp1_read_stats_threaded_irq(int irq, void *ctx) { + struct device *dev = ctx; + struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); + struct rkisp1_stats *stats = &rkisp1->stats; + struct rkisp1_kstats_buffer *kstats_buf = NULL; struct rkisp1_stat_buffer *cur_stat_buf; - struct rkisp1_buffer *cur_buf = NULL; - unsigned int frame_sequence = - atomic_read(&stats->rkisp1->isp.frame_sequence); - u64 timestamp = ktime_get_ns(); unsigned long flags; - - if (frame_sequence != meas_work->frame_id) { - dev_warn(stats->rkisp1->dev, - "Measurement late(%d, %d)\n", - frame_sequence, meas_work->frame_id); - frame_sequence = meas_work->frame_id; - } + u64 timestamp = ktime_get_ns(); spin_lock_irqsave(&stats->stats_lock, flags); - /* 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); + if (!stats->is_streaming) { + spin_unlock_irqrestore(&stats->stats_lock, flags); + return IRQ_HANDLED; + } + if (list_empty(&stats->stat)) { + spin_unlock_irqrestore(&stats->stats_lock, flags); + WARN("%s: threaded irq waked but there are no buffers", + __func__); + return IRQ_HANDLED; + } + kstats_buf = list_first_entry(&stats->stat, + struct rkisp1_kstats_buffer, buff.queue); + + /* + * each waked irq thread reads exactly one ready statistics + * so it is a bug if no statistics are ready + */ + if (!kstats_buf->ris) { + spin_unlock_irqrestore(&stats->stats_lock, flags); + WARN("%s: threaded irq waked but buffer holds no measures", + __func__); + return IRQ_HANDLED; } + list_del(&kstats_buf->buff.queue); spin_unlock_irqrestore(&stats->stats_lock, flags); - if (!cur_buf) - return; - cur_stat_buf = - (struct rkisp1_stat_buffer *)(cur_buf->vaddr[0]); + (struct rkisp1_stat_buffer *)(kstats_buf->buff.vaddr[0]); - if (meas_work->isp_ris & RKISP1_CIF_ISP_AWB_DONE) { + if (kstats_buf->ris & RKISP1_CIF_ISP_AWB_DONE) { rkisp1_stats_get_awb_meas(stats, cur_stat_buf); cur_stat_buf->meas_type |= RKISP1_CIF_ISP_STAT_AWB; } - if (meas_work->isp_ris & RKISP1_CIF_ISP_AFM_FIN) { + if (kstats_buf->ris & RKISP1_CIF_ISP_AFM_FIN) { rkisp1_stats_get_afc_meas(stats, cur_stat_buf); cur_stat_buf->meas_type |= RKISP1_CIF_ISP_STAT_AFM_FIN; } - if (meas_work->isp_ris & RKISP1_CIF_ISP_EXP_END) { + if (kstats_buf->ris & RKISP1_CIF_ISP_EXP_END) { rkisp1_stats_get_aec_meas(stats, cur_stat_buf); rkisp1_stats_get_bls_meas(stats, cur_stat_buf); cur_stat_buf->meas_type |= RKISP1_CIF_ISP_STAT_AUTOEXP; } - if (meas_work->isp_ris & RKISP1_CIF_ISP_HIST_MEASURE_RDY) { + if (kstats_buf->ris & RKISP1_CIF_ISP_HIST_MEASURE_RDY) { rkisp1_stats_get_hst_meas(stats, cur_stat_buf); cur_stat_buf->meas_type |= RKISP1_CIF_ISP_STAT_HIST; } - vb2_set_plane_payload(&cur_buf->vb.vb2_buf, 0, + vb2_set_plane_payload(&kstats_buf->buff.vb.vb2_buf, 0, sizeof(struct rkisp1_stat_buffer)); - cur_buf->vb.sequence = frame_sequence; - cur_buf->vb.vb2_buf.timestamp = timestamp; - vb2_buffer_done(&cur_buf->vb.vb2_buf, VB2_BUF_STATE_DONE); + kstats_buf->buff.vb.vb2_buf.timestamp = timestamp; + vb2_buffer_done(&kstats_buf->buff.vb.vb2_buf, VB2_BUF_STATE_DONE); + return IRQ_HANDLED; } -static void rkisp1_stats_readout_work(struct work_struct *work) -{ - struct rkisp1_isp_readout_work *readout_work = - container_of(work, struct rkisp1_isp_readout_work, work); - struct rkisp1_stats *stats = readout_work->stats; - - if (readout_work->readout == RKISP1_ISP_READOUT_MEAS) - rkisp1_stats_send_measurement(stats, readout_work); - kfree(readout_work); -} - -void rkisp1_stats_isr(struct rkisp1_stats *stats, u32 isp_ris) +irqreturn_t rkisp1_stats_isr(struct rkisp1_stats *stats, u32 isp_ris) { - unsigned int frame_sequence = - atomic_read(&stats->rkisp1->isp.frame_sequence); struct rkisp1_device *rkisp1 = stats->rkisp1; - struct rkisp1_isp_readout_work *work; + struct rkisp1_isp *isp = &rkisp1->isp; + struct rkisp1_kstats_buffer *buf = NULL; + irqreturn_t ret = IRQ_HANDLED; unsigned int isp_mis_tmp = 0; unsigned long flags; u32 val; @@ -417,28 +398,22 @@ void rkisp1_stats_isr(struct rkisp1_stats *stats, u32 isp_ris) if (isp_mis_tmp & RKISP1_STATS_MEAS_MASK) rkisp1->debug.stats_error++; - if (!stats->is_streaming) + if (!stats->is_streaming || !(isp_ris & RKISP1_STATS_MEAS_MASK)) goto unlock; - if (isp_ris & RKISP1_STATS_MEAS_MASK) { - work = kzalloc(sizeof(*work), GFP_ATOMIC); - if (work) { - INIT_WORK(&work->work, - rkisp1_stats_readout_work); - work->readout = RKISP1_ISP_READOUT_MEAS; - work->stats = stats; - work->frame_id = frame_sequence; - work->isp_ris = isp_ris; - if (!queue_work(stats->readout_wq, - &work->work)) - kfree(work); - } else { - dev_err(stats->rkisp1->dev, - "Could not allocate work\n"); + + list_for_each_entry(buf, &stats->stat, buff.queue) { + if (!buf->ris) { + buf->buff.vb.sequence = + atomic_read(&isp->frame_sequence); + buf->ris = isp_ris; + ret = IRQ_WAKE_THREAD; + break; } } unlock: spin_unlock_irqrestore(&stats->stats_lock, flags); + return ret; } static void rkisp1_init_stats(struct rkisp1_stats *stats) @@ -489,19 +464,8 @@ int rkisp1_stats_register(struct rkisp1_stats *stats, goto err_cleanup_media_entity; } - stats->readout_wq = alloc_workqueue("measurement_queue", - WQ_UNBOUND | WQ_MEM_RECLAIM, - 1); - - if (!stats->readout_wq) { - ret = -ENOMEM; - goto err_unreg_vdev; - } - return 0; -err_unreg_vdev: - video_unregister_device(vdev); err_cleanup_media_entity: media_entity_cleanup(&vdev->entity); err_release_queue: @@ -515,7 +479,6 @@ void rkisp1_stats_unregister(struct rkisp1_stats *stats) struct rkisp1_vdev_node *node = &stats->vnode; struct video_device *vdev = &node->vdev; - destroy_workqueue(stats->readout_wq); video_unregister_device(vdev); media_entity_cleanup(&vdev->entity); vb2_queue_release(vdev->queue);