Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp828177ybm; Wed, 27 May 2020 08:58:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkcfdKDpAI6m/xAZVf/PKtTxYqGB+TJSKyDkoXW1LiW70WhAuJ8qD56ADkNLZxyjhETYHu X-Received: by 2002:a17:906:48ce:: with SMTP id d14mr4491745ejt.468.1590595131732; Wed, 27 May 2020 08:58:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590595131; cv=none; d=google.com; s=arc-20160816; b=ABUtW9oFM/wozNn8hxgp8s6pkC+pMngZESvCNxI1G++e9njChE358NUzU5WJDVSWQC onOnyEO0s0kW7jyv7Lm4ZVwc2braCZzc7NYfH3PlLMaxwP9LKZGWlpNB1NmmS2Y22uD6 yAPGlBVNGcnVR1WGfjmA+nSNDh2EGekV9wnK498x91Wup33jb3MobzglH3zXEiY/VSNJ GzJlgrSbBkXRX2viuMd3t9yHdKQYomLhx1KXTOF2NsRbLMCO1v9xQek4/Omkkc9kjYfv /evVuGBd0V+f+Kq4MLchwRYuKOudmrS84JBXan4a0+ZBIipyOqbrTKv0Mp8BNdTL69WC z9iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=AU7716CyemDmasYys+I/AcpiH3oj4x9jWwzzxX5tgKU=; b=IZN+duDba+3mNj9MUxuV/cnpwoWP3fcyhe3HI8ojmo1NdJgx6jXMdYQiZJ3Dp5Ybat AWwEFGxzWPEMwjipthiEScvrNjZUDSWzRH1TUbZIcuFZJ7twKl6l9CwuZstewkmjD5mC aItCQUm/aWwIrJBbPuFU5BZq+rtdOvXn03E6h3CeCs3Ie40E0XoyHUD354bJ52RaE8fe L0bomMiaLtnMezsX8znBXSDUeAJfSbI5DJKB8++aQ42iXxrGG/U1S5uqhsifCyZsGXpm alEz62bBAIxBtTMKeAwWMVYvqvg1Wlf0+fgTRdTeunubgihMmrS4ME1heJKFCzxbFveR 3wcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VStnWt6j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t15si1915594edw.497.2020.05.27.08.58.28; Wed, 27 May 2020 08:58:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VStnWt6j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389249AbgE0Oqw (ORCPT + 99 others); Wed, 27 May 2020 10:46:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388680AbgE0Oqv (ORCPT ); Wed, 27 May 2020 10:46:51 -0400 Received: from mail-il1-x143.google.com (mail-il1-x143.google.com [IPv6:2607:f8b0:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB2CFC03E96E for ; Wed, 27 May 2020 07:46:51 -0700 (PDT) Received: by mail-il1-x143.google.com with SMTP id d1so1739410ila.8 for ; Wed, 27 May 2020 07:46:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=AU7716CyemDmasYys+I/AcpiH3oj4x9jWwzzxX5tgKU=; b=VStnWt6jTjFgaMVpk3oAYnsncjATXU/wAutYtmJZxldXplcS0pQN70hvvNDVsOPkH4 vnpNBR2ZdymxIB23xtSA8Lf6Q+U1apKa27CyqmEcDbIor/6l6or9W2gJF5nwV4rqyhy5 zn5mI5nrRB5YSUzlGDB5NcEQTR9RL2pEiZTE8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=AU7716CyemDmasYys+I/AcpiH3oj4x9jWwzzxX5tgKU=; b=r6Hzs1x0EVCV6xdKs3x5QaeV2T9ZvkWz9auId9VUUXI+yfqtMOxQhmNltZl1amsRy3 7vG7asT5I9V/QmJSB0/w7xU3FRz2gmTrDEui0uUZLadafcjAtyP/OUlU/Qu0ENy/SNTH Vz8jQvdHG2yUu4Y/zscGm1jEIHJg1PbQZHtR5L+7i2jUeNY9PivfBorfX1IDGX57pVpB yRq386hqaLkf530tFnnQf1kmGgvRKWjXxct3BPFt+4i/QNlCWgzDy8ugJmJcyHqBByk6 A/XR9awNxh9lCCNL1Ns1XN6etGxMdAkm/DsVKup16LH8eh7ADCOjnkhZnSp6E/bFmDTd ASyA== X-Gm-Message-State: AOAM531rX0MJwE6jNVfzUCZEuWLYaRjURN9yi6Qyh4IhcjPuuS2zVM30 cUvxMy48cPKQ3uS8fe/r7gtVbvdl+XdYW0nTO0ARPA== X-Received: by 2002:a92:d182:: with SMTP id z2mr6049581ilz.47.1590590811109; Wed, 27 May 2020 07:46:51 -0700 (PDT) MIME-Version: 1.0 References: <20200403094033.8288-1-xia.jiang@mediatek.com> <20200403094033.8288-7-xia.jiang@mediatek.com> <20200521153257.GF209565@chromium.org> <1590544320.12671.10.camel@mhfsdcap03> In-Reply-To: <1590544320.12671.10.camel@mhfsdcap03> From: Tomasz Figa Date: Wed, 27 May 2020 16:46:39 +0200 Message-ID: Subject: Re: [PATCH v8 06/14] media: platform: Improve the implementation of the system PM ops To: Xia Jiang Cc: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Rick Chang , Linux Media Mailing List , linux-devicetree , Linux Kernel Mailing List , "list@263.net:IOMMU DRIVERS , Joerg Roedel ," , "moderated list:ARM/Mediatek SoC support" , Marek Szyprowski , srv_heupstream , Sergey Senozhatsky , Hsu Wei-Cheng , Nicolas Boichat , maoguang.meng@mediatek.com, Sj Huang Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 27, 2020 at 3:58 AM Xia Jiang wrote: > > On Thu, 2020-05-21 at 15:32 +0000, Tomasz Figa wrote: > > Hi Xia, > > > > On Fri, Apr 03, 2020 at 05:40:25PM +0800, Xia Jiang wrote: > > > Cancel reset hw operation in suspend and resume function because this > > > will be done in device_run(). > > > > This and... > > > > > Add spin_lock and unlock operation in irq and resume function to make > > > sure that the current frame is processed completely before suspend. > > > > ...this are two separate changes. Please split. > > > > > > > > Signed-off-by: Xia Jiang > > > --- > > > drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c | 11 +++++++++-- > > > 1 file changed, 9 insertions(+), 2 deletions(-) > > > > > > diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c > > > index dd5cadd101ef..2fa3711fdc9b 100644 > > > --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c > > > +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c > > > @@ -911,6 +911,8 @@ static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv) > > > u32 dec_ret; > > > int i; > > > > > > + spin_lock(&jpeg->hw_lock); > > > + > > > > nit: For consistency, it is recommended to always use the same, i.e. the > > strongest, spin_(un)lock_ primitives when operating on the same spinlock. > > In this case it would be the irqsave(restore) variants. > > > > > dec_ret = mtk_jpeg_dec_get_int_status(jpeg->dec_reg_base); > > > dec_irq_ret = mtk_jpeg_dec_enum_result(dec_ret); > > > ctx = v4l2_m2m_get_curr_priv(jpeg->m2m_dev); > > > @@ -941,6 +943,7 @@ static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv) > > > v4l2_m2m_buf_done(src_buf, buf_state); > > > v4l2_m2m_buf_done(dst_buf, buf_state); > > > v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx); > > > + spin_unlock(&jpeg->hw_lock); > > > pm_runtime_put_sync(ctx->jpeg->dev); > > > return IRQ_HANDLED; > > > } > > > @@ -1191,7 +1194,6 @@ static __maybe_unused int mtk_jpeg_pm_suspend(struct device *dev) > > > { > > > struct mtk_jpeg_dev *jpeg = dev_get_drvdata(dev); > > > > > > - mtk_jpeg_dec_reset(jpeg->dec_reg_base); > > > mtk_jpeg_clk_off(jpeg); > > > > > > return 0; > > > @@ -1202,19 +1204,24 @@ static __maybe_unused int mtk_jpeg_pm_resume(struct device *dev) > > > struct mtk_jpeg_dev *jpeg = dev_get_drvdata(dev); > > > > > > mtk_jpeg_clk_on(jpeg); > > > - mtk_jpeg_dec_reset(jpeg->dec_reg_base); > > > > > > return 0; > > > } > > > > > > static __maybe_unused int mtk_jpeg_suspend(struct device *dev) > > > { > > > + struct mtk_jpeg_dev *jpeg = dev_get_drvdata(dev); > > > + unsigned long flags; > > > int ret; > > > > > > if (pm_runtime_suspended(dev)) > > > return 0; > > > > > > + spin_lock_irqsave(&jpeg->hw_lock, flags); > > > > What does this spinlock protect us from? I can see that it would prevent > > the interrupt handler from being called, but is it okay to suspend the > > system without handling the interrupt? > Dear Tomasz, > I mean that if current image is processed in irq handler,suspend > function can not get the lock(it was locked in irq handler).Should I > move the spin_lock_irqsave(&jpeg->hw_lock, flags) to the start location > of suspend function or Do we have any guarantee that the interrupt handler would be executed and acquire the spinlock before mtk_jpeg_suspend() is called? > use wait_event_timeout() to handle the interrupt > before suspend? Yes, that would indeed work better. :) However, please refer to the v4l2_m2m suspend/resume helpers [1] and the MTK FD driver [2] for how to implement this nicely. [1] https://patchwork.kernel.org/patch/11272917/ [2] https://patchwork.kernel.org/patch/11272903/ Best regards, Tomasz