Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1542466 > unrolled thread

[PATCH] drm/i915: use udelay for very small delays

Started byNicholas Mc Guire <hofrat@osadl.org>
First post2016-12-15 05:10 +0100
Last post2016-12-15 10:00 +0100
Articles 5 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] drm/i915: use udelay for very small delays Nicholas Mc Guire <hofrat@osadl.org> - 2016-12-15 05:10 +0100
    Re: [PATCH] drm/i915: use udelay for very small delays Jani Nikula <jani.nikula@linux.intel.com> - 2016-12-15 09:50 +0100
      Re: [PATCH] drm/i915: use udelay for very small delays Nicholas Mc Guire <der.herr@hofr.at> - 2016-12-15 10:00 +0100
        Re: [PATCH] drm/i915: use udelay for very small delays Jani Nikula <jani.nikula@linux.intel.com> - 2016-12-15 10:40 +0100
      Re: [PATCH] drm/i915: use udelay for very small delays Jani Nikula <jani.nikula@linux.intel.com> - 2016-12-15 10:00 +0100

#1542466 — [PATCH] drm/i915: use udelay for very small delays

FromNicholas Mc Guire <hofrat@osadl.org>
Date2016-12-15 05:10 +0100
Subject[PATCH] drm/i915: use udelay for very small delays
Message-ID<sOvwJ-121-3@gated-at.bofh.it>
usleep_range() is intended for delays in the 10us to 10ms range that need
good precision. a useleep_range(1, will effectively be no more than an
imprecise udelay with some added cache disruption as it will fire more or
less immediately - use udelay() here.

Fixes: commit be4fc046bed3 ("drm/i915: add VLV DSI PLL Calculations")
Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
---

Problem located by coccinelle

The requirement of waiting at least 0.5 us is assured with the udelay(1)
here which should be more effective than a usleep_range() - would 
ndelay(500) make sense here ?

Patch was compile tested with: x86_64_defconfig (implies CONFIG_DRM_I915)

Patch is against 4.9.0 (localvrsion-next is next-20161214)

 drivers/gpu/drm/i915/intel_dsi_pll.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/intel_dsi_pll.c b/drivers/gpu/drm/i915/intel_dsi_pll.c
index 56eff60..0ec040e 100644
--- a/drivers/gpu/drm/i915/intel_dsi_pll.c
+++ b/drivers/gpu/drm/i915/intel_dsi_pll.c
@@ -157,7 +157,7 @@ static void vlv_enable_dsi_pll(struct intel_encoder *encoder,
 		      config->dsi_pll.ctrl & ~DSI_PLL_VCO_EN);
 
 	/* wait at least 0.5 us after ungating before enabling VCO */
-	usleep_range(1, 10);
+	udelay(1);
 
 	vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, config->dsi_pll.ctrl);
 
-- 
2.1.4

[toc] | [next] | [standalone]


#1542558

FromJani Nikula <jani.nikula@linux.intel.com>
Date2016-12-15 09:50 +0100
Message-ID<sOzTI-3AH-17@gated-at.bofh.it>
In reply to#1542466
On Thu, 15 Dec 2016, Nicholas Mc Guire <hofrat@osadl.org> wrote:
> usleep_range() is intended for delays in the 10us to 10ms range that need
> good precision. a useleep_range(1, will effectively be no more than an
> imprecise udelay with some added cache disruption as it will fire more or
> less immediately - use udelay() here.
>
> Fixes: commit be4fc046bed3 ("drm/i915: add VLV DSI PLL Calculations")
> Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
> ---
>
> Problem located by coccinelle
>
> The requirement of waiting at least 0.5 us is assured with the udelay(1)
> here which should be more effective than a usleep_range() - would 
> ndelay(500) make sense here ?

This is in the modeset path, i.e. pretty slow anyway. In this case, the
point is not to try hard to minimize the wait, the point is to guarantee
"at least 0.5 us" has passed. If the CPU can do something else,
including dozing off, in the mean time, great. I think we should stick
with usleep_range().

I think the question is, how do we express this in code? IMO udelay() is
not the answer.

And why doesn't usleep_range() kernel-doc mention anything about the
ranges?


BR,
Jani.


>
> Patch was compile tested with: x86_64_defconfig (implies CONFIG_DRM_I915)
>
> Patch is against 4.9.0 (localvrsion-next is next-20161214)
>
>  drivers/gpu/drm/i915/intel_dsi_pll.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/intel_dsi_pll.c b/drivers/gpu/drm/i915/intel_dsi_pll.c
> index 56eff60..0ec040e 100644
> --- a/drivers/gpu/drm/i915/intel_dsi_pll.c
> +++ b/drivers/gpu/drm/i915/intel_dsi_pll.c
> @@ -157,7 +157,7 @@ static void vlv_enable_dsi_pll(struct intel_encoder *encoder,
>  		      config->dsi_pll.ctrl & ~DSI_PLL_VCO_EN);
>  
>  	/* wait at least 0.5 us after ungating before enabling VCO */
> -	usleep_range(1, 10);
> +	udelay(1);
>  
>  	vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, config->dsi_pll.ctrl);

-- 
Jani Nikula, Intel Open Source Technology Center

[toc] | [prev] | [next] | [standalone]


#1542561

FromNicholas Mc Guire <der.herr@hofr.at>
Date2016-12-15 10:00 +0100
Message-ID<sOA3n-3DP-1@gated-at.bofh.it>
In reply to#1542558
On Thu, Dec 15, 2016 at 10:47:57AM +0200, Jani Nikula wrote:
> On Thu, 15 Dec 2016, Nicholas Mc Guire <hofrat@osadl.org> wrote:
> > usleep_range() is intended for delays in the 10us to 10ms range that need
> > good precision. a useleep_range(1, will effectively be no more than an
> > imprecise udelay with some added cache disruption as it will fire more or
> > less immediately - use udelay() here.
> >
> > Fixes: commit be4fc046bed3 ("drm/i915: add VLV DSI PLL Calculations")
> > Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
> > ---
> >
> > Problem located by coccinelle
> >
> > The requirement of waiting at least 0.5 us is assured with the udelay(1)
> > here which should be more effective than a usleep_range() - would 
> > ndelay(500) make sense here ?
> 
> This is in the modeset path, i.e. pretty slow anyway. In this case, the
> point is not to try hard to minimize the wait, the point is to guarantee
> "at least 0.5 us" has passed. If the CPU can do something else,
> including dozing off, in the mean time, great. I think we should stick
> with usleep_range().

well in that case maybe an acceptable solution would be to set it to 
some suitable range 10,20 us ? or if not critical preferably even with a large
upper limit.

> 
> I think the question is, how do we express this in code? IMO udelay() is
> not the answer.

if the delay need to be kept short then no - then its not the answer
but usleep_ranges(1,2) I think is effectively just an inefficient version
of udelay(1), by the time the timer is setup and the task gives
up the cpu the timer would fire.

> 
> And why doesn't usleep_range() kernel-doc mention anything about the
> ranges?
> 

interesting - that might be part of the reason there are many findings
Documentation/timers/timers-howto.txt does

        SLEEPING FOR ~USECS OR SMALL MSECS ( 10us - 20ms):
                * Use usleep_range

thx!
hofrat

[toc] | [prev] | [next] | [standalone]


#1542592

FromJani Nikula <jani.nikula@linux.intel.com>
Date2016-12-15 10:40 +0100
Message-ID<sOAG6-45w-43@gated-at.bofh.it>
In reply to#1542561
On Thu, 15 Dec 2016, Nicholas Mc Guire <der.herr@hofr.at> wrote:
> On Thu, Dec 15, 2016 at 10:47:57AM +0200, Jani Nikula wrote:
>> On Thu, 15 Dec 2016, Nicholas Mc Guire <hofrat@osadl.org> wrote:
>> > usleep_range() is intended for delays in the 10us to 10ms range that need
>> > good precision. a useleep_range(1, will effectively be no more than an
>> > imprecise udelay with some added cache disruption as it will fire more or
>> > less immediately - use udelay() here.
>> >
>> > Fixes: commit be4fc046bed3 ("drm/i915: add VLV DSI PLL Calculations")
>> > Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
>> > ---
>> >
>> > Problem located by coccinelle
>> >
>> > The requirement of waiting at least 0.5 us is assured with the udelay(1)
>> > here which should be more effective than a usleep_range() - would 
>> > ndelay(500) make sense here ?
>> 
>> This is in the modeset path, i.e. pretty slow anyway. In this case, the
>> point is not to try hard to minimize the wait, the point is to guarantee
>> "at least 0.5 us" has passed. If the CPU can do something else,
>> including dozing off, in the mean time, great. I think we should stick
>> with usleep_range().
>
> well in that case maybe an acceptable solution would be to set it to 
> some suitable range 10,20 us ? or if not critical preferably even with a large
> upper limit.

I'd be fine with 10, 50 here. Please do send the patch, Cc: me.

>> 
>> I think the question is, how do we express this in code? IMO udelay() is
>> not the answer.
>
> if the delay need to be kept short then no - then its not the answer
> but usleep_ranges(1,2) I think is effectively just an inefficient version
> of udelay(1), by the time the timer is setup and the task gives
> up the cpu the timer would fire.
>
>> 
>> And why doesn't usleep_range() kernel-doc mention anything about the
>> ranges?
>> 
>
> interesting - that might be part of the reason there are many findings
> Documentation/timers/timers-howto.txt does
>
>         SLEEPING FOR ~USECS OR SMALL MSECS ( 10us - 20ms):
>                 * Use usleep_range

I'd appreciate short additions to the kernel-doc documentation of each
function to document the approximate range it's appropriate for. People
will know where to look if their use doesn't fall in that range.

Thanks,
Jani.

-- 
Jani Nikula, Intel Open Source Technology Center

[toc] | [prev] | [next] | [standalone]


#1542563

FromJani Nikula <jani.nikula@linux.intel.com>
Date2016-12-15 10:00 +0100
Message-ID<sOA3n-3DP-15@gated-at.bofh.it>
In reply to#1542558
On Thu, 15 Dec 2016, Jani Nikula <jani.nikula@linux.intel.com> wrote:
> On Thu, 15 Dec 2016, Nicholas Mc Guire <hofrat@osadl.org> wrote:
>> usleep_range() is intended for delays in the 10us to 10ms range that need
>> good precision. a useleep_range(1, will effectively be no more than an
>> imprecise udelay with some added cache disruption as it will fire more or
>> less immediately - use udelay() here.
>>
>> Fixes: commit be4fc046bed3 ("drm/i915: add VLV DSI PLL Calculations")
>> Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
>> ---
>>
>> Problem located by coccinelle
>>
>> The requirement of waiting at least 0.5 us is assured with the udelay(1)
>> here which should be more effective than a usleep_range() - would 
>> ndelay(500) make sense here ?
>
> This is in the modeset path, i.e. pretty slow anyway. In this case, the
> point is not to try hard to minimize the wait, the point is to guarantee
> "at least 0.5 us" has passed. If the CPU can do something else,
> including dozing off, in the mean time, great. I think we should stick
> with usleep_range().
>
> I think the question is, how do we express this in code? IMO udelay() is
> not the answer.
>
> And why doesn't usleep_range() kernel-doc mention anything about the
> ranges?
>
>
> BR,
> Jani.
>
>
>>
>> Patch was compile tested with: x86_64_defconfig (implies CONFIG_DRM_I915)
>>
>> Patch is against 4.9.0 (localvrsion-next is next-20161214)
>>
>>  drivers/gpu/drm/i915/intel_dsi_pll.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/i915/intel_dsi_pll.c b/drivers/gpu/drm/i915/intel_dsi_pll.c
>> index 56eff60..0ec040e 100644
>> --- a/drivers/gpu/drm/i915/intel_dsi_pll.c
>> +++ b/drivers/gpu/drm/i915/intel_dsi_pll.c
>> @@ -157,7 +157,7 @@ static void vlv_enable_dsi_pll(struct intel_encoder *encoder,
>>  		      config->dsi_pll.ctrl & ~DSI_PLL_VCO_EN);
>>  
>>  	/* wait at least 0.5 us after ungating before enabling VCO */
>> -	usleep_range(1, 10);
>> +	udelay(1);
>>  
>>  	vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, config->dsi_pll.ctrl);

PS. This vlv_cck_write() call will do sideband communication with
millisecond range timeouts.


-- 
Jani Nikula, Intel Open Source Technology Center

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web