From mboxrd@z Thu Jan 1 00:00:00 1970 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=-10.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 AE2C0C433E0 for ; Wed, 1 Jul 2020 13:02:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 870D720809 for ; Wed, 1 Jul 2020 13:02:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=st.com header.i=@st.com header.b="BQAL6nV5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730745AbgGANB6 (ORCPT ); Wed, 1 Jul 2020 09:01:58 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:49384 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730556AbgGANBp (ORCPT ); Wed, 1 Jul 2020 09:01:45 -0400 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 061CrtDW021936; Wed, 1 Jul 2020 15:01:36 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=Io/xIwvPlzgTUZBNydeV0zeJ7opdV/UYH9UZpq0FPPg=; b=BQAL6nV556PhRwpC0iWa+SEy+9SaEjfO2/Gods394u9c942XSaOSrlm2xshBtgwDpnch 9jXU+2fO5cyUyxeL8Or36JkOdiUC/c1I2GRDQsgDTd5DjcARFddZpulopxMZftBLvqXZ jQOcMLKozoicZQaFbNyOuZZSptl1neohXC+LRq2DjiDE37LTkd1TUgo3tUmsfm+vdlUq N995FufAhckwNox0IOxR19HOtBmEjUT4qKQkKrrh9xMTuh4pZXyxBAUIEnY/5axfowqq Sbsy1zm54fptkPzjSCUM8qebWfBP6xDyQXzY0wWP/wS85wyaikoF3yzWQAovoOnllWEE dg== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 31wuk1j45h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Jul 2020 15:01:35 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 7FA1510003D; Wed, 1 Jul 2020 15:01:35 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag3node3.st.com [10.75.127.9]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 6564A2B66E1; Wed, 1 Jul 2020 15:01:35 +0200 (CEST) Received: from localhost (10.75.127.50) by SFHDAG3NODE3.st.com (10.75.127.9) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Wed, 1 Jul 2020 15:01:34 +0200 From: Benjamin Gaignard To: , , , , CC: , , , , , , , , Benjamin Gaignard Subject: [PATCH v7 2/3] media: stm32-dcmi: Set minimum cpufreq requirement Date: Wed, 1 Jul 2020 15:01:28 +0200 Message-ID: <20200701130129.30961-3-benjamin.gaignard@st.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20200701130129.30961-1-benjamin.gaignard@st.com> References: <20200701130129.30961-1-benjamin.gaignard@st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG5NODE2.st.com (10.75.127.14) To SFHDAG3NODE3.st.com (10.75.127.9) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-07-01_08:2020-07-01,2020-07-01 signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Before start streaming set cpufreq minimum frequency requirement. The cpufreq governor will adapt the frequencies and we will have no latency for handling interrupts. The frequency requirement is retrieved from the device-tree node. Signed-off-by: Benjamin Gaignard Reviewed-by: Valentin Schneider Acked-by: Hugues Fruchet --- version 7: - rebase on v5.8-rc3 - add reviewed and ack-by - fix test condition drivers/media/platform/stm32/stm32-dcmi.c | 138 ++++++++++++++++++++++++++++-- 1 file changed, 130 insertions(+), 8 deletions(-) diff --git a/drivers/media/platform/stm32/stm32-dcmi.c b/drivers/media/platform/stm32/stm32-dcmi.c index b8931490b83b..2b7b60ba1d4d 100644 --- a/drivers/media/platform/stm32/stm32-dcmi.c +++ b/drivers/media/platform/stm32/stm32-dcmi.c @@ -13,10 +13,13 @@ #include #include +#include +#include #include #include #include #include +#include #include #include #include @@ -99,6 +102,8 @@ enum state { #define OVERRUN_ERROR_THRESHOLD 3 +static DEFINE_PER_CPU(struct freq_qos_request, qos_req); + struct dcmi_graph_entity { struct v4l2_async_subdev asd; @@ -133,6 +138,7 @@ struct stm32_dcmi { struct resource *res; struct reset_control *rstc; int sequence; + int irq; struct list_head buffers; struct dcmi_buf *active; @@ -173,6 +179,11 @@ struct stm32_dcmi { struct media_device mdev; struct media_pad vid_cap_pad; struct media_pipeline pipeline; + + struct mutex freq_lock; + u32 min_frequency; + cpumask_var_t boosted; + struct irq_affinity_notify notify; }; static inline struct stm32_dcmi *notifier_to_dcmi(struct v4l2_async_notifier *n) @@ -722,6 +733,99 @@ static void dcmi_pipeline_stop(struct stm32_dcmi *dcmi) dcmi_pipeline_s_stream(dcmi, 0); } +static void dcmi_get_min_frequency(struct stm32_dcmi *dcmi) +{ + struct device_node *np = dcmi->mdev.dev->of_node; + + dcmi->min_frequency = FREQ_QOS_MIN_DEFAULT_VALUE; + + of_property_read_u32(np, "st,stm32-dcmi-min-frequency", + &dcmi->min_frequency); +} + +static void dcmi_irq_notifier_notify(struct irq_affinity_notify *notify, + const cpumask_t *mask) +{ + struct stm32_dcmi *dcmi = container_of(notify, + struct stm32_dcmi, + notify); + struct cpufreq_policy *p; + int cpu; + + mutex_lock(&dcmi->freq_lock); + /* + * For all boosted CPUs check if it is still the case + * if not remove the request + */ + for_each_cpu(cpu, dcmi->boosted) { + if (cpumask_test_cpu(cpu, mask)) + continue; + + p = cpufreq_cpu_get(cpu); + if (!p) + continue; + + freq_qos_remove_request(&per_cpu(qos_req, cpu)); + cpumask_andnot(dcmi->boosted, dcmi->boosted, p->cpus); + + cpufreq_cpu_put(p); + } + + /* + * For CPUs in the mask check if they are boosted if not add + * a request + */ + for_each_cpu(cpu, mask) { + if (cpumask_test_cpu(cpu, dcmi->boosted)) + continue; + + p = cpufreq_cpu_get(cpu); + if (!p) + continue; + + freq_qos_add_request(&p->constraints, &per_cpu(qos_req, cpu), + FREQ_QOS_MIN, dcmi->min_frequency); + cpumask_or(dcmi->boosted, dcmi->boosted, p->cpus); + cpufreq_cpu_put(p); + } + + mutex_unlock(&dcmi->freq_lock); +} + +static void dcmi_irq_notifier_release(struct kref *ref) +{ + /* + * This is required by affinity notifier. We don't have anything to + * free here. + */ +} + +static void dcmi_set_min_frequency(struct stm32_dcmi *dcmi, s32 freq) +{ + struct irq_affinity_notify *notify = &dcmi->notify; + struct cpumask clear; + + if (freq != FREQ_QOS_MIN_DEFAULT_VALUE) { + /* + * Register the notifier before doing any change, so the + * callback can be queued if an affinity change happens *while* + * we are requesting the boosts. + */ + irq_set_affinity_notifier(dcmi->irq, notify); + dcmi_irq_notifier_notify(notify, + irq_get_affinity_mask(dcmi->irq)); + } else { + /* + * Unregister the notifier before clearing the boost requests, + * as we don't want to boost again if an affinity change happens + * *while* we are clearing the requests + */ + irq_set_affinity_notifier(dcmi->irq, NULL); + cpumask_clear(&clear); + dcmi_irq_notifier_notify(notify, &clear); + } +} + static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count) { struct stm32_dcmi *dcmi = vb2_get_drv_priv(vq); @@ -736,11 +840,13 @@ static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count) goto err_release_buffers; } + dcmi_set_min_frequency(dcmi, dcmi->min_frequency); + ret = media_pipeline_start(&dcmi->vdev->entity, &dcmi->pipeline); if (ret < 0) { dev_err(dcmi->dev, "%s: Failed to start streaming, media pipeline start error (%d)\n", __func__, ret); - goto err_pm_put; + goto err_drop_qos; } ret = dcmi_pipeline_start(dcmi); @@ -835,7 +941,8 @@ static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count) err_media_pipeline_stop: media_pipeline_stop(&dcmi->vdev->entity); -err_pm_put: +err_drop_qos: + dcmi_set_min_frequency(dcmi, FREQ_QOS_MIN_DEFAULT_VALUE); pm_runtime_put(dcmi->dev); err_release_buffers: @@ -863,6 +970,8 @@ static void dcmi_stop_streaming(struct vb2_queue *vq) media_pipeline_stop(&dcmi->vdev->entity); + dcmi_set_min_frequency(dcmi, FREQ_QOS_MIN_DEFAULT_VALUE); + spin_lock_irq(&dcmi->irqlock); /* Disable interruptions */ @@ -1834,11 +1943,11 @@ static int dcmi_probe(struct platform_device *pdev) struct device_node *np = pdev->dev.of_node; const struct of_device_id *match = NULL; struct v4l2_fwnode_endpoint ep = { .bus_type = 0 }; + struct irq_affinity_notify *notify; struct stm32_dcmi *dcmi; struct vb2_queue *q; struct dma_chan *chan; struct clk *mclk; - int irq; int ret = 0; match = of_match_device(of_match_ptr(stm32_dcmi_of_match), &pdev->dev); @@ -1879,9 +1988,9 @@ static int dcmi_probe(struct platform_device *pdev) dcmi->bus.bus_width = ep.bus.parallel.bus_width; dcmi->bus.data_shift = ep.bus.parallel.data_shift; - irq = platform_get_irq(pdev, 0); - if (irq <= 0) - return irq ? irq : -ENXIO; + dcmi->irq = platform_get_irq(pdev, 0); + if (dcmi->irq <= 0) + return dcmi->irq ? dcmi->irq : -ENXIO; dcmi->res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!dcmi->res) { @@ -1895,11 +2004,12 @@ static int dcmi_probe(struct platform_device *pdev) return PTR_ERR(dcmi->regs); } - ret = devm_request_threaded_irq(&pdev->dev, irq, dcmi_irq_callback, + ret = devm_request_threaded_irq(&pdev->dev, dcmi->irq, + dcmi_irq_callback, dcmi_irq_thread, IRQF_ONESHOT, dev_name(&pdev->dev), dcmi); if (ret) { - dev_err(&pdev->dev, "Unable to request irq %d\n", irq); + dev_err(&pdev->dev, "Unable to request irq %d\n", dcmi->irq); return ret; } @@ -1922,6 +2032,7 @@ static int dcmi_probe(struct platform_device *pdev) spin_lock_init(&dcmi->irqlock); mutex_init(&dcmi->lock); mutex_init(&dcmi->dma_lock); + mutex_init(&dcmi->freq_lock); init_completion(&dcmi->complete); INIT_LIST_HEAD(&dcmi->buffers); @@ -1930,6 +2041,13 @@ static int dcmi_probe(struct platform_device *pdev) dcmi->state = STOPPED; dcmi->dma_chan = chan; + if (!alloc_cpumask_var(&dcmi->boosted, GFP_KERNEL)) + return -ENODEV; + + notify = &dcmi->notify; + notify->notify = dcmi_irq_notifier_notify; + notify->release = dcmi_irq_notifier_release; + q = &dcmi->queue; dcmi->v4l2_dev.mdev = &dcmi->mdev; @@ -2022,6 +2140,8 @@ static int dcmi_probe(struct platform_device *pdev) dev_info(&pdev->dev, "Probe done\n"); + dcmi_get_min_frequency(dcmi); + platform_set_drvdata(pdev, dcmi); pm_runtime_enable(&pdev->dev); @@ -2049,6 +2169,8 @@ static int dcmi_remove(struct platform_device *pdev) pm_runtime_disable(&pdev->dev); + free_cpumask_var(dcmi->boosted); + v4l2_async_notifier_unregister(&dcmi->notifier); v4l2_async_notifier_cleanup(&dcmi->notifier); media_entity_cleanup(&dcmi->vdev->entity); -- 2.15.0 From mboxrd@z Thu Jan 1 00:00:00 1970 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=-10.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 74CB9C433E1 for ; Wed, 1 Jul 2020 13:03:14 +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 3380E20780 for ; Wed, 1 Jul 2020 13:03:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="dNKzU8Qe"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=st.com header.i=@st.com header.b="BQAL6nV5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3380E20780 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=st.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.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:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version: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=kHiVhP7O4yDghUhUwWMWRtjeGgR5vv7mFE3SoLEoWSk=; b=dNKzU8Qe24UyIv+mzkqDsRUPK RHOELiK5Qq0GKk12yUqwf2dmWROaWL43uXE3KGYjTJGHwYQE3/7M7Tj40wJxJvkfrUXvtDKvvGMy3 RayG5W02VOHO/JH5s41oN16trZJbrHz9XP4NtXJdOyvqrmL/yjh+8tQiNHf/0Xzo9moA3WeyBpKd9 fzNwrujYN1FxppCtauAmWdFCSv4+6BkVniC8I4BiX808FTkU/VDoMwoNl0a1UQ6WWn3lA4QKn4+Gj DPEeMbpumYhg5zc6eqlf7xELv9XAbWhfBH89K6DYDQYs6r0xmyICgVHxjj7tZUKVyfSkMNhL9Lqei g5NxgpmJg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqcMy-0001dq-QC; Wed, 01 Jul 2020 13:01:44 +0000 Received: from mx07-00178001.pphosted.com ([62.209.51.94]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqcMu-0001bj-6S for linux-arm-kernel@lists.infradead.org; Wed, 01 Jul 2020 13:01:41 +0000 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 061CrtDW021936; Wed, 1 Jul 2020 15:01:36 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=Io/xIwvPlzgTUZBNydeV0zeJ7opdV/UYH9UZpq0FPPg=; b=BQAL6nV556PhRwpC0iWa+SEy+9SaEjfO2/Gods394u9c942XSaOSrlm2xshBtgwDpnch 9jXU+2fO5cyUyxeL8Or36JkOdiUC/c1I2GRDQsgDTd5DjcARFddZpulopxMZftBLvqXZ jQOcMLKozoicZQaFbNyOuZZSptl1neohXC+LRq2DjiDE37LTkd1TUgo3tUmsfm+vdlUq N995FufAhckwNox0IOxR19HOtBmEjUT4qKQkKrrh9xMTuh4pZXyxBAUIEnY/5axfowqq Sbsy1zm54fptkPzjSCUM8qebWfBP6xDyQXzY0wWP/wS85wyaikoF3yzWQAovoOnllWEE dg== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 31wuk1j45h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Jul 2020 15:01:35 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 7FA1510003D; Wed, 1 Jul 2020 15:01:35 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag3node3.st.com [10.75.127.9]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 6564A2B66E1; Wed, 1 Jul 2020 15:01:35 +0200 (CEST) Received: from localhost (10.75.127.50) by SFHDAG3NODE3.st.com (10.75.127.9) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Wed, 1 Jul 2020 15:01:34 +0200 From: Benjamin Gaignard To: , , , , Subject: [PATCH v7 2/3] media: stm32-dcmi: Set minimum cpufreq requirement Date: Wed, 1 Jul 2020 15:01:28 +0200 Message-ID: <20200701130129.30961-3-benjamin.gaignard@st.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20200701130129.30961-1-benjamin.gaignard@st.com> References: <20200701130129.30961-1-benjamin.gaignard@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG5NODE2.st.com (10.75.127.14) To SFHDAG3NODE3.st.com (10.75.127.9) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-07-01_08:2020-07-01, 2020-07-01 signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200701_090140_502379_BCDE396F X-CRM114-Status: GOOD ( 25.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, vincent.guittot@linaro.org, Benjamin Gaignard , rjw@rjwysocki.net, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, valentin.schneider@arm.com, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Before start streaming set cpufreq minimum frequency requirement. The cpufreq governor will adapt the frequencies and we will have no latency for handling interrupts. The frequency requirement is retrieved from the device-tree node. Signed-off-by: Benjamin Gaignard Reviewed-by: Valentin Schneider Acked-by: Hugues Fruchet --- version 7: - rebase on v5.8-rc3 - add reviewed and ack-by - fix test condition drivers/media/platform/stm32/stm32-dcmi.c | 138 ++++++++++++++++++++++++++++-- 1 file changed, 130 insertions(+), 8 deletions(-) diff --git a/drivers/media/platform/stm32/stm32-dcmi.c b/drivers/media/platform/stm32/stm32-dcmi.c index b8931490b83b..2b7b60ba1d4d 100644 --- a/drivers/media/platform/stm32/stm32-dcmi.c +++ b/drivers/media/platform/stm32/stm32-dcmi.c @@ -13,10 +13,13 @@ #include #include +#include +#include #include #include #include #include +#include #include #include #include @@ -99,6 +102,8 @@ enum state { #define OVERRUN_ERROR_THRESHOLD 3 +static DEFINE_PER_CPU(struct freq_qos_request, qos_req); + struct dcmi_graph_entity { struct v4l2_async_subdev asd; @@ -133,6 +138,7 @@ struct stm32_dcmi { struct resource *res; struct reset_control *rstc; int sequence; + int irq; struct list_head buffers; struct dcmi_buf *active; @@ -173,6 +179,11 @@ struct stm32_dcmi { struct media_device mdev; struct media_pad vid_cap_pad; struct media_pipeline pipeline; + + struct mutex freq_lock; + u32 min_frequency; + cpumask_var_t boosted; + struct irq_affinity_notify notify; }; static inline struct stm32_dcmi *notifier_to_dcmi(struct v4l2_async_notifier *n) @@ -722,6 +733,99 @@ static void dcmi_pipeline_stop(struct stm32_dcmi *dcmi) dcmi_pipeline_s_stream(dcmi, 0); } +static void dcmi_get_min_frequency(struct stm32_dcmi *dcmi) +{ + struct device_node *np = dcmi->mdev.dev->of_node; + + dcmi->min_frequency = FREQ_QOS_MIN_DEFAULT_VALUE; + + of_property_read_u32(np, "st,stm32-dcmi-min-frequency", + &dcmi->min_frequency); +} + +static void dcmi_irq_notifier_notify(struct irq_affinity_notify *notify, + const cpumask_t *mask) +{ + struct stm32_dcmi *dcmi = container_of(notify, + struct stm32_dcmi, + notify); + struct cpufreq_policy *p; + int cpu; + + mutex_lock(&dcmi->freq_lock); + /* + * For all boosted CPUs check if it is still the case + * if not remove the request + */ + for_each_cpu(cpu, dcmi->boosted) { + if (cpumask_test_cpu(cpu, mask)) + continue; + + p = cpufreq_cpu_get(cpu); + if (!p) + continue; + + freq_qos_remove_request(&per_cpu(qos_req, cpu)); + cpumask_andnot(dcmi->boosted, dcmi->boosted, p->cpus); + + cpufreq_cpu_put(p); + } + + /* + * For CPUs in the mask check if they are boosted if not add + * a request + */ + for_each_cpu(cpu, mask) { + if (cpumask_test_cpu(cpu, dcmi->boosted)) + continue; + + p = cpufreq_cpu_get(cpu); + if (!p) + continue; + + freq_qos_add_request(&p->constraints, &per_cpu(qos_req, cpu), + FREQ_QOS_MIN, dcmi->min_frequency); + cpumask_or(dcmi->boosted, dcmi->boosted, p->cpus); + cpufreq_cpu_put(p); + } + + mutex_unlock(&dcmi->freq_lock); +} + +static void dcmi_irq_notifier_release(struct kref *ref) +{ + /* + * This is required by affinity notifier. We don't have anything to + * free here. + */ +} + +static void dcmi_set_min_frequency(struct stm32_dcmi *dcmi, s32 freq) +{ + struct irq_affinity_notify *notify = &dcmi->notify; + struct cpumask clear; + + if (freq != FREQ_QOS_MIN_DEFAULT_VALUE) { + /* + * Register the notifier before doing any change, so the + * callback can be queued if an affinity change happens *while* + * we are requesting the boosts. + */ + irq_set_affinity_notifier(dcmi->irq, notify); + dcmi_irq_notifier_notify(notify, + irq_get_affinity_mask(dcmi->irq)); + } else { + /* + * Unregister the notifier before clearing the boost requests, + * as we don't want to boost again if an affinity change happens + * *while* we are clearing the requests + */ + irq_set_affinity_notifier(dcmi->irq, NULL); + cpumask_clear(&clear); + dcmi_irq_notifier_notify(notify, &clear); + } +} + static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count) { struct stm32_dcmi *dcmi = vb2_get_drv_priv(vq); @@ -736,11 +840,13 @@ static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count) goto err_release_buffers; } + dcmi_set_min_frequency(dcmi, dcmi->min_frequency); + ret = media_pipeline_start(&dcmi->vdev->entity, &dcmi->pipeline); if (ret < 0) { dev_err(dcmi->dev, "%s: Failed to start streaming, media pipeline start error (%d)\n", __func__, ret); - goto err_pm_put; + goto err_drop_qos; } ret = dcmi_pipeline_start(dcmi); @@ -835,7 +941,8 @@ static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count) err_media_pipeline_stop: media_pipeline_stop(&dcmi->vdev->entity); -err_pm_put: +err_drop_qos: + dcmi_set_min_frequency(dcmi, FREQ_QOS_MIN_DEFAULT_VALUE); pm_runtime_put(dcmi->dev); err_release_buffers: @@ -863,6 +970,8 @@ static void dcmi_stop_streaming(struct vb2_queue *vq) media_pipeline_stop(&dcmi->vdev->entity); + dcmi_set_min_frequency(dcmi, FREQ_QOS_MIN_DEFAULT_VALUE); + spin_lock_irq(&dcmi->irqlock); /* Disable interruptions */ @@ -1834,11 +1943,11 @@ static int dcmi_probe(struct platform_device *pdev) struct device_node *np = pdev->dev.of_node; const struct of_device_id *match = NULL; struct v4l2_fwnode_endpoint ep = { .bus_type = 0 }; + struct irq_affinity_notify *notify; struct stm32_dcmi *dcmi; struct vb2_queue *q; struct dma_chan *chan; struct clk *mclk; - int irq; int ret = 0; match = of_match_device(of_match_ptr(stm32_dcmi_of_match), &pdev->dev); @@ -1879,9 +1988,9 @@ static int dcmi_probe(struct platform_device *pdev) dcmi->bus.bus_width = ep.bus.parallel.bus_width; dcmi->bus.data_shift = ep.bus.parallel.data_shift; - irq = platform_get_irq(pdev, 0); - if (irq <= 0) - return irq ? irq : -ENXIO; + dcmi->irq = platform_get_irq(pdev, 0); + if (dcmi->irq <= 0) + return dcmi->irq ? dcmi->irq : -ENXIO; dcmi->res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!dcmi->res) { @@ -1895,11 +2004,12 @@ static int dcmi_probe(struct platform_device *pdev) return PTR_ERR(dcmi->regs); } - ret = devm_request_threaded_irq(&pdev->dev, irq, dcmi_irq_callback, + ret = devm_request_threaded_irq(&pdev->dev, dcmi->irq, + dcmi_irq_callback, dcmi_irq_thread, IRQF_ONESHOT, dev_name(&pdev->dev), dcmi); if (ret) { - dev_err(&pdev->dev, "Unable to request irq %d\n", irq); + dev_err(&pdev->dev, "Unable to request irq %d\n", dcmi->irq); return ret; } @@ -1922,6 +2032,7 @@ static int dcmi_probe(struct platform_device *pdev) spin_lock_init(&dcmi->irqlock); mutex_init(&dcmi->lock); mutex_init(&dcmi->dma_lock); + mutex_init(&dcmi->freq_lock); init_completion(&dcmi->complete); INIT_LIST_HEAD(&dcmi->buffers); @@ -1930,6 +2041,13 @@ static int dcmi_probe(struct platform_device *pdev) dcmi->state = STOPPED; dcmi->dma_chan = chan; + if (!alloc_cpumask_var(&dcmi->boosted, GFP_KERNEL)) + return -ENODEV; + + notify = &dcmi->notify; + notify->notify = dcmi_irq_notifier_notify; + notify->release = dcmi_irq_notifier_release; + q = &dcmi->queue; dcmi->v4l2_dev.mdev = &dcmi->mdev; @@ -2022,6 +2140,8 @@ static int dcmi_probe(struct platform_device *pdev) dev_info(&pdev->dev, "Probe done\n"); + dcmi_get_min_frequency(dcmi); + platform_set_drvdata(pdev, dcmi); pm_runtime_enable(&pdev->dev); @@ -2049,6 +2169,8 @@ static int dcmi_remove(struct platform_device *pdev) pm_runtime_disable(&pdev->dev); + free_cpumask_var(dcmi->boosted); + v4l2_async_notifier_unregister(&dcmi->notifier); v4l2_async_notifier_cleanup(&dcmi->notifier); media_entity_cleanup(&dcmi->vdev->entity); -- 2.15.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel