All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sowjanya Komatineni <skomatineni-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
To: Dmitry Osipenko <digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org,
	frankc-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org,
	hverkuil-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org
Cc: linux-media-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [RFC PATCH v1 3/5] media: tegra-video: Move PM runtime handle to streaming
Date: Tue, 28 Apr 2020 08:22:02 -0700	[thread overview]
Message-ID: <5741d5d3-e474-e23c-4841-809df5760067@nvidia.com> (raw)
In-Reply-To: <ce31e273-f424-f13e-5cd6-0db2589a2a10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>


On 4/28/20 8:15 AM, Dmitry Osipenko wrote:
> External email: Use caution opening links or attachments
>
>
> 28.04.2020 18:08, Sowjanya Komatineni пишет:
>> On 4/28/20 7:59 AM, Dmitry Osipenko wrote:
>>> External email: Use caution opening links or attachments
>>>
>>>
>>> 28.04.2020 17:51, Sowjanya Komatineni пишет:
>>>> On 4/28/20 6:59 AM, Dmitry Osipenko wrote:
>>>>> External email: Use caution opening links or attachments
>>>>>
>>>>>
>>>>> 28.04.2020 07:20, Sowjanya Komatineni пишет:
>>>>>> diff --git a/drivers/staging/media/tegra-video/csi.c
>>>>>> b/drivers/staging/media/tegra-video/csi.c
>>>>>> index b3dd0c3..29ccdae 100644
>>>>>> --- a/drivers/staging/media/tegra-video/csi.c
>>>>>> +++ b/drivers/staging/media/tegra-video/csi.c
>>>>>> @@ -272,8 +272,25 @@ static int tegra_csi_s_stream(struct v4l2_subdev
>>>>>> *subdev, int enable)
>>>>>>          struct tegra_vi_channel *chan =
>>>>>> v4l2_get_subdev_hostdata(subdev);
>>>>>>          struct tegra_csi_channel *csi_chan = to_csi_chan(subdev);
>>>>>>          struct tegra_csi *csi = csi_chan->csi;
>>>>>> +     int ret;
>>>>>> +
>>>>>> +     if (enable && atomic_add_return(1, &csi->clk_refcnt) == 1) {
>>>>>> +             ret = pm_runtime_get_sync(csi->dev);
>>>>>> +             if (ret < 0) {
>>>>>> +                     dev_err(csi->dev,
>>>>>> +                             "failed to get runtime PM: %d\n", ret);
>>>>>> +                     pm_runtime_put_noidle(csi->dev);
> Why this pm_runtime_put_noidle() is needed? This should be wrong, please
> remove it.

pm_runtime_get_sync() increments power.usage_count prior to rpm_resume

if rpm_resume fails it does not decrement usage_count.

So to balance count on failure, calling pm_runtime_put_noidle()

>
>>>>>> +                     atomic_dec(&csi->clk_refcnt);
>>>>>> +                     return ret;
>>>>>> +             }
>>>>>> +     }
>>>>>> +
>>>>>> +     ret = csi->ops->csi_streaming(csi_chan, chan->pg_mode, enable);
>>>>>>
>>>>>> -     return csi->ops->csi_streaming(csi_chan, chan->pg_mode, enable);
>>>>>> +     if ((ret < 0 || !enable) &&
>>>>>> atomic_dec_and_test(&csi->clk_refcnt))
>>>>>> +             pm_runtime_put_sync(csi->dev);
>>>>> Runtime PM maintains its own refcount, why these
>>>>> clk_refcnt/power_on_refcnt are needed?
>>>> Streaming is per channel and we can't turn power/clocks off while other
>>>> channels may still be running.
>>>>
>>> All channels use the same CSI device. You should remove the custom
>>> refcounting.
>>>
>>> BTW, next time you'll really need to do refcounting, use the generic
>>> kref.
>> Before channel stream we enable power/clocks and after streaming we stop.
>>
>> So without refcount, on stream stop of any of the channel RPM put turns
>> power/clock but other channels will still be streaming.
>>
> Runtime PM uses its own refcounting. Please consult the RPM code and
> documentation.
>
> https://elixir.bootlin.com/linux/v5.7-rc3/source/include/linux/pm_runtime.h#L78
> https://elixir.bootlin.com/linux/v5.7-rc3/source/drivers/base/power/runtime.c#L1079
Got it. Will remove refcount for RPM put/get

WARNING: multiple messages have this Message-ID (diff)
From: Sowjanya Komatineni <skomatineni@nvidia.com>
To: Dmitry Osipenko <digetx@gmail.com>, <thierry.reding@gmail.com>,
	<jonathanh@nvidia.com>, <frankc@nvidia.com>, <hverkuil@xs4all.nl>
Cc: <linux-media@vger.kernel.org>, <linux-tegra@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH v1 3/5] media: tegra-video: Move PM runtime handle to streaming
Date: Tue, 28 Apr 2020 08:22:02 -0700	[thread overview]
Message-ID: <5741d5d3-e474-e23c-4841-809df5760067@nvidia.com> (raw)
In-Reply-To: <ce31e273-f424-f13e-5cd6-0db2589a2a10@gmail.com>


On 4/28/20 8:15 AM, Dmitry Osipenko wrote:
> External email: Use caution opening links or attachments
>
>
> 28.04.2020 18:08, Sowjanya Komatineni пишет:
>> On 4/28/20 7:59 AM, Dmitry Osipenko wrote:
>>> External email: Use caution opening links or attachments
>>>
>>>
>>> 28.04.2020 17:51, Sowjanya Komatineni пишет:
>>>> On 4/28/20 6:59 AM, Dmitry Osipenko wrote:
>>>>> External email: Use caution opening links or attachments
>>>>>
>>>>>
>>>>> 28.04.2020 07:20, Sowjanya Komatineni пишет:
>>>>>> diff --git a/drivers/staging/media/tegra-video/csi.c
>>>>>> b/drivers/staging/media/tegra-video/csi.c
>>>>>> index b3dd0c3..29ccdae 100644
>>>>>> --- a/drivers/staging/media/tegra-video/csi.c
>>>>>> +++ b/drivers/staging/media/tegra-video/csi.c
>>>>>> @@ -272,8 +272,25 @@ static int tegra_csi_s_stream(struct v4l2_subdev
>>>>>> *subdev, int enable)
>>>>>>          struct tegra_vi_channel *chan =
>>>>>> v4l2_get_subdev_hostdata(subdev);
>>>>>>          struct tegra_csi_channel *csi_chan = to_csi_chan(subdev);
>>>>>>          struct tegra_csi *csi = csi_chan->csi;
>>>>>> +     int ret;
>>>>>> +
>>>>>> +     if (enable && atomic_add_return(1, &csi->clk_refcnt) == 1) {
>>>>>> +             ret = pm_runtime_get_sync(csi->dev);
>>>>>> +             if (ret < 0) {
>>>>>> +                     dev_err(csi->dev,
>>>>>> +                             "failed to get runtime PM: %d\n", ret);
>>>>>> +                     pm_runtime_put_noidle(csi->dev);
> Why this pm_runtime_put_noidle() is needed? This should be wrong, please
> remove it.

pm_runtime_get_sync() increments power.usage_count prior to rpm_resume

if rpm_resume fails it does not decrement usage_count.

So to balance count on failure, calling pm_runtime_put_noidle()

>
>>>>>> +                     atomic_dec(&csi->clk_refcnt);
>>>>>> +                     return ret;
>>>>>> +             }
>>>>>> +     }
>>>>>> +
>>>>>> +     ret = csi->ops->csi_streaming(csi_chan, chan->pg_mode, enable);
>>>>>>
>>>>>> -     return csi->ops->csi_streaming(csi_chan, chan->pg_mode, enable);
>>>>>> +     if ((ret < 0 || !enable) &&
>>>>>> atomic_dec_and_test(&csi->clk_refcnt))
>>>>>> +             pm_runtime_put_sync(csi->dev);
>>>>> Runtime PM maintains its own refcount, why these
>>>>> clk_refcnt/power_on_refcnt are needed?
>>>> Streaming is per channel and we can't turn power/clocks off while other
>>>> channels may still be running.
>>>>
>>> All channels use the same CSI device. You should remove the custom
>>> refcounting.
>>>
>>> BTW, next time you'll really need to do refcounting, use the generic
>>> kref.
>> Before channel stream we enable power/clocks and after streaming we stop.
>>
>> So without refcount, on stream stop of any of the channel RPM put turns
>> power/clock but other channels will still be streaming.
>>
> Runtime PM uses its own refcounting. Please consult the RPM code and
> documentation.
>
> https://elixir.bootlin.com/linux/v5.7-rc3/source/include/linux/pm_runtime.h#L78
> https://elixir.bootlin.com/linux/v5.7-rc3/source/drivers/base/power/runtime.c#L1079
Got it. Will remove refcount for RPM put/get

  parent reply	other threads:[~2020-04-28 15:22 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-28  4:20 [RFC PATCH v1 0/5] media: tegra: Tegra video driver follow-up patches Sowjanya Komatineni
2020-04-28  4:20 ` Sowjanya Komatineni
2020-04-28  4:20 ` [RFC PATCH v1 1/5] MAINTAINERS: Rename Tegra Video driver path Sowjanya Komatineni
2020-04-28  4:20   ` Sowjanya Komatineni
2020-04-28  4:20 ` [RFC PATCH v1 2/5] media: tegra: Rename driver path to tegra-video Sowjanya Komatineni
2020-04-28  4:20   ` Sowjanya Komatineni
2020-04-28  4:20 ` [RFC PATCH v1 3/5] media: tegra-video: Move PM runtime handle to streaming Sowjanya Komatineni
2020-04-28  4:20   ` Sowjanya Komatineni
     [not found]   ` <1588047650-29402-4-git-send-email-skomatineni-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2020-04-28 13:59     ` Dmitry Osipenko
2020-04-28 13:59       ` Dmitry Osipenko
     [not found]       ` <631390cb-9aff-0e3f-6c39-81d6c565987e-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2020-04-28 14:51         ` Sowjanya Komatineni
2020-04-28 14:51           ` Sowjanya Komatineni
     [not found]           ` <3ef69413-a606-b475-f530-d5534760b73b-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2020-04-28 14:59             ` Dmitry Osipenko
2020-04-28 14:59               ` Dmitry Osipenko
     [not found]               ` <2b334095-fadb-bf0a-f7a8-62fc798c2bd2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2020-04-28 15:08                 ` Sowjanya Komatineni
2020-04-28 15:08                   ` Sowjanya Komatineni
2020-04-28 15:15                   ` Dmitry Osipenko
     [not found]                     ` <ce31e273-f424-f13e-5cd6-0db2589a2a10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2020-04-28 15:22                       ` Sowjanya Komatineni [this message]
2020-04-28 15:22                         ` Sowjanya Komatineni
     [not found]                         ` <5741d5d3-e474-e23c-4841-809df5760067-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2020-04-28 16:04                           ` Dmitry Osipenko
2020-04-28 16:04                             ` Dmitry Osipenko
     [not found]                             ` <f6e34203-3e4b-b804-30a5-bf78445ab366-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2020-04-30 13:24                               ` Dmitry Osipenko
2020-04-30 13:24                                 ` Dmitry Osipenko
2020-04-28 14:05     ` Dmitry Osipenko
2020-04-28 14:05       ` Dmitry Osipenko
     [not found] ` <1588047650-29402-1-git-send-email-skomatineni-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2020-04-28  4:20   ` [RFC PATCH v1 4/5] media: tegra-video: Rearrange SoC specific to Tegra210 and cleanup files Sowjanya Komatineni
2020-04-28  4:20     ` Sowjanya Komatineni
2020-04-28  7:38   ` [RFC PATCH v1 0/5] media: tegra: Tegra video driver follow-up patches Hans Verkuil
2020-04-28  7:38     ` Hans Verkuil
     [not found]     ` <5f065fc5-0f45-6b9e-068c-28d0a2e4684e-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org>
2020-04-28 14:52       ` Sowjanya Komatineni
2020-04-28 14:52         ` Sowjanya Komatineni
2020-04-28  4:20 ` [RFC PATCH v1 5/5] media: tegra-video: Remove module macros for vi and csi driver Sowjanya Komatineni
2020-04-28  4:20   ` Sowjanya Komatineni

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=5741d5d3-e474-e23c-4841-809df5760067@nvidia.com \
    --to=skomatineni-ddmlm1+adcrqt0dzr+alfa@public.gmane.org \
    --cc=digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=frankc-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
    --cc=hverkuil-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org \
    --cc=jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-media-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.