DriverDev-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] FBTFT: fb_agm1264k: usleep_range is preferred over udelay
@ 2019-09-09  1:26 Sreeram Veluthakkal
  2019-09-09  9:56 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Sreeram Veluthakkal @ 2019-09-09  1:26 UTC (permalink / raw)
  To: gregkh
  Cc: devel, linux-fbdev, nishadkamdar, linux-kernel, dri-devel,
	payal.s.kshirsagar.98, Sreeram Veluthakkal

This patch fixes the issue:
FILE: drivers/staging/fbtft/fb_agm1264k-fl.c:88:
CHECK: usleep_range is preferred over udelay; see Documentation/timers/timers-howto.rst
+       udelay(20);

Signed-off-by: Sreeram Veluthakkal <srrmvlt@gmail.com>
---
 drivers/staging/fbtft/fb_agm1264k-fl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/fbtft/fb_agm1264k-fl.c b/drivers/staging/fbtft/fb_agm1264k-fl.c
index eeeeec97ad27..2dece71fd3b5 100644
--- a/drivers/staging/fbtft/fb_agm1264k-fl.c
+++ b/drivers/staging/fbtft/fb_agm1264k-fl.c
@@ -85,7 +85,7 @@ static void reset(struct fbtft_par *par)
 	dev_dbg(par->info->device, "%s()\n", __func__);
 
 	gpiod_set_value(par->gpio.reset, 0);
-	udelay(20);
+	usleep_range(20, 40);
 	gpiod_set_value(par->gpio.reset, 1);
 	mdelay(120);
 }
-- 
2.17.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] FBTFT: fb_agm1264k: usleep_range is preferred over udelay
  2019-09-09  1:26 [PATCH] FBTFT: fb_agm1264k: usleep_range is preferred over udelay Sreeram Veluthakkal
@ 2019-09-09  9:56 ` Greg KH
  2019-09-09 11:50   ` Sreeram Veluthakkal
  0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2019-09-09  9:56 UTC (permalink / raw)
  To: Sreeram Veluthakkal
  Cc: devel, linux-fbdev, nishadkamdar, linux-kernel, dri-devel,
	payal.s.kshirsagar.98

On Sun, Sep 08, 2019 at 08:26:05PM -0500, Sreeram Veluthakkal wrote:
> This patch fixes the issue:
> FILE: drivers/staging/fbtft/fb_agm1264k-fl.c:88:
> CHECK: usleep_range is preferred over udelay; see Documentation/timers/timers-howto.rst
> +       udelay(20);
> 
> Signed-off-by: Sreeram Veluthakkal <srrmvlt@gmail.com>
> ---
>  drivers/staging/fbtft/fb_agm1264k-fl.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/fbtft/fb_agm1264k-fl.c b/drivers/staging/fbtft/fb_agm1264k-fl.c
> index eeeeec97ad27..2dece71fd3b5 100644
> --- a/drivers/staging/fbtft/fb_agm1264k-fl.c
> +++ b/drivers/staging/fbtft/fb_agm1264k-fl.c
> @@ -85,7 +85,7 @@ static void reset(struct fbtft_par *par)
>  	dev_dbg(par->info->device, "%s()\n", __func__);
>  
>  	gpiod_set_value(par->gpio.reset, 0);
> -	udelay(20);
> +	usleep_range(20, 40);

Is it "safe" to wait 40?  This kind of change you can only do if you
know this is correct.  Have you tested this with hardware?

thanks,

greg k-h
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] FBTFT: fb_agm1264k: usleep_range is preferred over udelay
  2019-09-09  9:56 ` Greg KH
@ 2019-09-09 11:50   ` Sreeram Veluthakkal
  2019-09-10  7:59     ` Geert Uytterhoeven
  0 siblings, 1 reply; 4+ messages in thread
From: Sreeram Veluthakkal @ 2019-09-09 11:50 UTC (permalink / raw)
  To: Greg KH
  Cc: devel, linux-fbdev, nishadkamdar, linux-kernel, dri-devel,
	payal.s.kshirsagar.98

On Mon, Sep 09, 2019 at 10:56:25AM +0100, Greg KH wrote:
> On Sun, Sep 08, 2019 at 08:26:05PM -0500, Sreeram Veluthakkal wrote:
> > This patch fixes the issue:
> > FILE: drivers/staging/fbtft/fb_agm1264k-fl.c:88:
> > CHECK: usleep_range is preferred over udelay; see Documentation/timers/timers-howto.rst
> > +       udelay(20);
> > 
> > Signed-off-by: Sreeram Veluthakkal <srrmvlt@gmail.com>
> > ---
> >  drivers/staging/fbtft/fb_agm1264k-fl.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/staging/fbtft/fb_agm1264k-fl.c b/drivers/staging/fbtft/fb_agm1264k-fl.c
> > index eeeeec97ad27..2dece71fd3b5 100644
> > --- a/drivers/staging/fbtft/fb_agm1264k-fl.c
> > +++ b/drivers/staging/fbtft/fb_agm1264k-fl.c
> > @@ -85,7 +85,7 @@ static void reset(struct fbtft_par *par)
> >  	dev_dbg(par->info->device, "%s()\n", __func__);
> >  
> >  	gpiod_set_value(par->gpio.reset, 0);
> > -	udelay(20);
> > +	usleep_range(20, 40);
> 
> Is it "safe" to wait 40?  This kind of change you can only do if you
> know this is correct.  Have you tested this with hardware?
> 
> thanks,
> 
> greg k-h

Hi Greg, No I haven't tested it, I don't have the hw. I dug depeer in to the usleep_range

https://github.com/torvalds/linux/blob/master/kernel/time/timer.c#L1993
	u64 delta = (u64)(max - min) * NSEC_PER_USEC;

 * The @delta argument gives the kernel the freedom to schedule the
 * actual wakeup to a time that is both power and performance friendly.
 * The kernel give the normal best effort behavior for "@expires+@delta",
 * but may decide to fire the timer earlier, but no earlier than @expires.

My understanding is that keeping delta 0 (min=max=20) would be equivalent. 
I can revise the patch to usleep_range(20, 20) or usleep_range(20, 21) for a 1 usec delta.
What do you suggest?

thanks,
Sreeram
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] FBTFT: fb_agm1264k: usleep_range is preferred over udelay
  2019-09-09 11:50   ` Sreeram Veluthakkal
@ 2019-09-10  7:59     ` Geert Uytterhoeven
  0 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2019-09-10  7:59 UTC (permalink / raw)
  To: Sreeram Veluthakkal
  Cc: driverdevel, Linux Fbdev development list, nishadkamdar, Greg KH,
	Linux Kernel Mailing List, DRI Development,
	payal.s.kshirsagar.98

Hi Sreeram,

On Tue, Sep 10, 2019 at 2:25 AM Sreeram Veluthakkal <srrmvlt@gmail.com> wrote:
> On Mon, Sep 09, 2019 at 10:56:25AM +0100, Greg KH wrote:
> > On Sun, Sep 08, 2019 at 08:26:05PM -0500, Sreeram Veluthakkal wrote:
> > > This patch fixes the issue:
> > > FILE: drivers/staging/fbtft/fb_agm1264k-fl.c:88:
> > > CHECK: usleep_range is preferred over udelay; see Documentation/timers/timers-howto.rst
> > > +       udelay(20);
> > >
> > > Signed-off-by: Sreeram Veluthakkal <srrmvlt@gmail.com>

Thanks for your patch!

> > > --- a/drivers/staging/fbtft/fb_agm1264k-fl.c
> > > +++ b/drivers/staging/fbtft/fb_agm1264k-fl.c
> > > @@ -85,7 +85,7 @@ static void reset(struct fbtft_par *par)
> > >     dev_dbg(par->info->device, "%s()\n", __func__);
> > >
> > >     gpiod_set_value(par->gpio.reset, 0);
> > > -   udelay(20);
> > > +   usleep_range(20, 40);
> >
> > Is it "safe" to wait 40?  This kind of change you can only do if you
> > know this is correct.  Have you tested this with hardware?
> >
> > thanks,
> >
> > greg k-h
>
> Hi Greg, No I haven't tested it, I don't have the hw. I dug depeer in to the usleep_range
>
> https://github.com/torvalds/linux/blob/master/kernel/time/timer.c#L1993
>         u64 delta = (u64)(max - min) * NSEC_PER_USEC;
>
>  * The @delta argument gives the kernel the freedom to schedule the
>  * actual wakeup to a time that is both power and performance friendly.
>  * The kernel give the normal best effort behavior for "@expires+@delta",
>  * but may decide to fire the timer earlier, but no earlier than @expires.
>
> My understanding is that keeping delta 0 (min=max=20) would be equivalent.
> I can revise the patch to usleep_range(20, 20) or usleep_range(20, 21) for a 1 usec delta.
> What do you suggest?

Please read the comment above the line you're referring to:

 * In non-atomic context where the exact wakeup time is flexible, use
 * usleep_range() instead of udelay().  The sleep improves responsiveness
 * by avoiding the CPU-hogging busy-wait of udelay(), and the range reduces
 * power usage by allowing hrtimers to take advantage of an already-
 * scheduled interrupt instead of scheduling a new one just for this sleep.

Is this function always called in non-atomic context?
If it  may be called in atomic context, replacing the udelay() call by a
usleep*() call will break the driver.

See also "the first and most important question" in
Documentation/timers/timers-howto.rst, as referred to by the checkpatch.pl
message.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-09  1:26 [PATCH] FBTFT: fb_agm1264k: usleep_range is preferred over udelay Sreeram Veluthakkal
2019-09-09  9:56 ` Greg KH
2019-09-09 11:50   ` Sreeram Veluthakkal
2019-09-10  7:59     ` Geert Uytterhoeven

DriverDev-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/driverdev-devel/0 driverdev-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 driverdev-devel driverdev-devel/ https://lore.kernel.org/driverdev-devel \
		driverdev-devel@linuxdriverproject.org devel@driverdev.osuosl.org driverdev-devel@archiver.kernel.org
	public-inbox-index driverdev-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.linuxdriverproject.driverdev-devel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox