linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tomasz Figa <tfiga@chromium.org>
To: Xia Jiang <xia.jiang@mediatek.com>
Cc: Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Mauro Carvalho Chehab <mchehab+samsung@kernel.org>,
	Rob Herring <robh+dt@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Rick Chang <rick.chang@mediatek.com>,
	Linux Media Mailing List <linux-media@vger.kernel.org>,
	linux-devicetree <devicetree@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	"list@263.net:IOMMU DRIVERS <iommu@lists.linux-foundation.org>,
	Joerg Roedel <joro@8bytes.org>,"
	<linux-arm-kernel@lists.infradead.org>,
	"moderated list:ARM/Mediatek SoC support" 
	<linux-mediatek@lists.infradead.org>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	srv_heupstream <srv_heupstream@mediatek.com>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Hsu Wei-Cheng <mojahsu@chromium.org>,
	Nicolas Boichat <drinkcat@chromium.org>,
	maoguang.meng@mediatek.com, Sj Huang <sj.huang@mediatek.com>
Subject: Re: [PATCH v8 06/14] media: platform: Improve the implementation of the system PM ops
Date: Wed, 27 May 2020 16:46:39 +0200	[thread overview]
Message-ID: <CAHD77HkUrO4em_=7aJqHLU0WnkdsiGJYHMgEyv23fbztQfupCA@mail.gmail.com> (raw)
In-Reply-To: <1590544320.12671.10.camel@mhfsdcap03>

On Wed, May 27, 2020 at 3:58 AM Xia Jiang <xia.jiang@mediatek.com> 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 <xia.jiang@mediatek.com>
> > > ---
> > >  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

  reply	other threads:[~2020-05-27 14:46 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-03  9:40 [PATCH v8 00/14] Add support for mt2701 JPEG ENC support Xia Jiang
2020-04-03  9:40 ` [PATCH v8 01/14] media: platform: Improve subscribe event flow for bug fixing Xia Jiang
2020-05-21 13:45   ` Tomasz Figa
2020-04-03  9:40 ` [PATCH v8 02/14] media: platform: Improve queue set up " Xia Jiang
2020-05-21 13:46   ` Tomasz Figa
2020-04-03  9:40 ` [PATCH v8 03/14] media: platform: Improve getting and requesting irq " Xia Jiang
2020-05-21 13:47   ` Tomasz Figa
2020-04-03  9:40 ` [PATCH v8 04/14] media: platform: Change the fixed device node number to unfixed value Xia Jiang
2020-05-11  8:39   ` Hans Verkuil
2020-05-21 13:59   ` Tomasz Figa
2020-06-05  6:02     ` Xia Jiang
2020-04-03  9:40 ` [PATCH v8 05/14] media: platform: Improve power on and power off flow Xia Jiang
2020-05-21 15:22   ` Tomasz Figa
2020-06-05  6:03     ` Xia Jiang
2020-04-03  9:40 ` [PATCH v8 06/14] media: platform: Improve the implementation of the system PM ops Xia Jiang
2020-05-21 15:32   ` Tomasz Figa
2020-05-27  1:52     ` Xia Jiang
2020-05-27 14:46       ` Tomasz Figa [this message]
2020-04-03  9:40 ` [PATCH v8 07/14] media: platform: Use kernel native functions for improving code quality Xia Jiang
2020-05-21 15:41   ` Tomasz Figa
2020-06-05  6:41     ` Xia Jiang
2020-04-03  9:40 ` [PATCH v8 08/14] media: platform: Change case " Xia Jiang
2020-05-11  8:37   ` Hans Verkuil
2020-06-05  8:04     ` Xia Jiang
2020-04-03  9:40 ` [PATCH v8 09/14] media: platform: Change MTK_JPEG_COMP_MAX macro definition location Xia Jiang
2020-05-21 15:44   ` Tomasz Figa
2020-04-03  9:40 ` [PATCH v8 10/14] media: platform: Delete redundant code for improving code quality Xia Jiang
2020-05-21 15:49   ` Tomasz Figa
2020-06-05  6:41     ` Xia Jiang
2020-04-03  9:40 ` [PATCH v8 11/14] media: dt-bindings: Add jpeg enc device tree node document Xia Jiang
2020-05-21 16:00   ` Tomasz Figa
2020-06-18  3:40     ` Xia Jiang
2020-06-18 12:34       ` Tomasz Figa
2020-04-03  9:40 ` [PATCH v8 12/14] arm: dts: Add jpeg enc device tree node Xia Jiang
2020-04-07  3:52   ` Yingjoe Chen
2020-04-03  9:40 ` [PATCH v8 13/14] media: platform: Rename jpeg dec file name Xia Jiang
2020-05-21 16:02   ` Tomasz Figa
2020-04-03  9:40 ` [PATCH v8 14/14] media: platform: Add jpeg dec/enc feature Xia Jiang
2020-05-11  9:04   ` Hans Verkuil
2020-05-21 16:08     ` Tomasz Figa
2020-06-05  8:07     ` Xia Jiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHD77HkUrO4em_=7aJqHLU0WnkdsiGJYHMgEyv23fbztQfupCA@mail.gmail.com' \
    --to=tfiga@chromium.org \
    --cc=devicetree@vger.kernel.org \
    --cc=drinkcat@chromium.org \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=m.szyprowski@samsung.com \
    --cc=maoguang.meng@mediatek.com \
    --cc=matthias.bgg@gmail.com \
    --cc=mchehab+samsung@kernel.org \
    --cc=mojahsu@chromium.org \
    --cc=rick.chang@mediatek.com \
    --cc=robh+dt@kernel.org \
    --cc=senozhatsky@chromium.org \
    --cc=sj.huang@mediatek.com \
    --cc=srv_heupstream@mediatek.com \
    --cc=xia.jiang@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).