2015-04-01 14:41:15

by Aaron Sierra

[permalink] [raw]
Subject: Re: [PATCH] mtd: fsl_ifc_nand: use msecs_to_jiffies for time conversion

----- Original Message -----
> From: "Nicholas Mc Guire" <[email protected]>
> Sent: Friday, March 13, 2015 6:23:47 AM
>
> This is only an API consolidation and should make things more readable
> it replaces var * HZ / 1000 by msecs_to_jiffies(var) which helps readability
> and also handles all corner-cases properly.
>
> Signed-off-by: Nicholas Mc Guire <[email protected]>
> ---
>
> Patch was compile tested with corenet64_smp_defconfig
> (implies CONFIG_MTD_NAND_FSL_IFC=y)
>
> Patch is against 4.0-rc3 (localversion-next is -next-20150313
>
> drivers/mtd/nand/fsl_ifc_nand.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mtd/nand/fsl_ifc_nand.c
> b/drivers/mtd/nand/fsl_ifc_nand.c
> index 4c05f4f..51394e5 100644
> --- a/drivers/mtd/nand/fsl_ifc_nand.c
> +++ b/drivers/mtd/nand/fsl_ifc_nand.c
> @@ -317,7 +317,7 @@ static void fsl_ifc_run_command(struct mtd_info *mtd)
>
> /* wait for command complete flag or timeout */
> wait_event_timeout(ctrl->nand_wait, ctrl->nand_stat,
> - IFC_TIMEOUT_MSECS * HZ/1000);
> + msecs_to_jiffies(IFC_TIMEOUT_MSECS));

Nicholas,
Your patch makes me think that this timeout value should be calculated
once during initialization and stored in a new member of
struct fsl_ifc_mtd. That would improve readability AND have some
positive impact on performance.

-Aaron S.

>
> /* ctrl->nand_stat will be updated from IRQ context */
> if (!ctrl->nand_stat)
> @@ -860,7 +860,7 @@ static void fsl_ifc_sram_init(struct fsl_ifc_mtd *priv)
>
> /* wait for command complete flag or timeout */
> wait_event_timeout(ctrl->nand_wait, ctrl->nand_stat,
> - IFC_TIMEOUT_MSECS * HZ/1000);
> + msecs_to_jiffies(IFC_TIMEOUT_MSECS));
>
> if (ctrl->nand_stat != IFC_NAND_EVTER_STAT_OPC)
> printk(KERN_ERR "fsl-ifc: Failed to Initialise SRAM\n");
> --
> 1.7.10.4
>
>


2015-04-01 14:24:51

by Nicholas Mc Guire

[permalink] [raw]
Subject: Re: [PATCH] mtd: fsl_ifc_nand: use msecs_to_jiffies for time conversion

On Wed, 01 Apr 2015, Aaron Sierra wrote:

> ----- Original Message -----
> > From: "Nicholas Mc Guire" <[email protected]>
> > Sent: Friday, March 13, 2015 6:23:47 AM
> >
> > This is only an API consolidation and should make things more readable
> > it replaces var * HZ / 1000 by msecs_to_jiffies(var) which helps readability
> > and also handles all corner-cases properly.
> >
> > Signed-off-by: Nicholas Mc Guire <[email protected]>
> > ---
> >
> > Patch was compile tested with corenet64_smp_defconfig
> > (implies CONFIG_MTD_NAND_FSL_IFC=y)
> >
> > Patch is against 4.0-rc3 (localversion-next is -next-20150313
> >
> > drivers/mtd/nand/fsl_ifc_nand.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/mtd/nand/fsl_ifc_nand.c
> > b/drivers/mtd/nand/fsl_ifc_nand.c
> > index 4c05f4f..51394e5 100644
> > --- a/drivers/mtd/nand/fsl_ifc_nand.c
> > +++ b/drivers/mtd/nand/fsl_ifc_nand.c
> > @@ -317,7 +317,7 @@ static void fsl_ifc_run_command(struct mtd_info *mtd)
> >
> > /* wait for command complete flag or timeout */
> > wait_event_timeout(ctrl->nand_wait, ctrl->nand_stat,
> > - IFC_TIMEOUT_MSECS * HZ/1000);
> > + msecs_to_jiffies(IFC_TIMEOUT_MSECS));
>
> Nicholas,
> Your patch makes me think that this timeout value should be calculated
> once during initialization and stored in a new member of
> struct fsl_ifc_mtd. That would improve readability AND have some
> positive impact on performance.
>

is it not a bit wasteful to put it into struct fsl_ifc_mtd
which is used quite often in here ?

#define IFC_TIMEOUT msecs_to_jiffies(500)

sould do - its only referenced twice and would achieve what you
suggested - initializing it in one location and improved readability

wait_event_timeout(ctrl->nand_wait, ctrl->nand_stat, IFC_TIMEOUT);

would there be any disadvantage of this solution?

thx!
hofrat

2015-04-01 15:11:01

by Aaron Sierra

[permalink] [raw]
Subject: Re: [PATCH] mtd: fsl_ifc_nand: use msecs_to_jiffies for time conversion

----- Original Message -----
> From: "Nicholas Mc Guire" <[email protected]>
> Sent: Wednesday, April 1, 2015 9:24:44 AM
>
> On Wed, 01 Apr 2015, Aaron Sierra wrote:
>
> > ----- Original Message -----
> > > From: "Nicholas Mc Guire" <[email protected]>
> > > Sent: Friday, March 13, 2015 6:23:47 AM
> > >
> > > This is only an API consolidation and should make things more readable
> > > it replaces var * HZ / 1000 by msecs_to_jiffies(var) which helps
> > > readability
> > > and also handles all corner-cases properly.
> > >
> > > Signed-off-by: Nicholas Mc Guire <[email protected]>
> > > ---
> > >
> > > Patch was compile tested with corenet64_smp_defconfig
> > > (implies CONFIG_MTD_NAND_FSL_IFC=y)
> > >
> > > Patch is against 4.0-rc3 (localversion-next is -next-20150313
> > >
> > > drivers/mtd/nand/fsl_ifc_nand.c | 4 ++--
> > > 1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/mtd/nand/fsl_ifc_nand.c
> > > b/drivers/mtd/nand/fsl_ifc_nand.c
> > > index 4c05f4f..51394e5 100644
> > > --- a/drivers/mtd/nand/fsl_ifc_nand.c
> > > +++ b/drivers/mtd/nand/fsl_ifc_nand.c
> > > @@ -317,7 +317,7 @@ static void fsl_ifc_run_command(struct mtd_info *mtd)
> > >
> > > /* wait for command complete flag or timeout */
> > > wait_event_timeout(ctrl->nand_wait, ctrl->nand_stat,
> > > - IFC_TIMEOUT_MSECS * HZ/1000);
> > > + msecs_to_jiffies(IFC_TIMEOUT_MSECS));
> >
> > Nicholas,
> > Your patch makes me think that this timeout value should be calculated
> > once during initialization and stored in a new member of
> > struct fsl_ifc_mtd. That would improve readability AND have some
> > positive impact on performance.
> >
>
> is it not a bit wasteful to put it into struct fsl_ifc_mtd
> which is used quite often in here ?

Storing the timeout in the private structure would use 4 or 8 bytes,
but the structure is passed around as pointer reference, so there is
no added overhead there.

> #define IFC_TIMEOUT msecs_to_jiffies(500)
>
> sould do - its only referenced twice and would achieve what you
> suggested - initializing it in one location and improved readability
>
> wait_event_timeout(ctrl->nand_wait, ctrl->nand_stat, IFC_TIMEOUT);
>
> would there be any disadvantage of this solution?

I don't have an issue with the compactness of your code. The issue
to me is that msecs_to_jiffies() is a real function call, not a macro.
That means that there would be a branch to that function followed by a
non-trivial calculation *every* time fsl_ifc_run_command() is called.

If the timeout value were calculated during init, then the cost of
accessing it would simply a pointer dereference.

-Aaron S.

2015-04-01 15:19:06

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] mtd: fsl_ifc_nand: use msecs_to_jiffies for time conversion

On Wed, 2015-04-01 at 10:08 -0500, Aaron Sierra wrote:
> ----- Original Message -----
> > From: "Nicholas Mc Guire" <[email protected]>
> > Sent: Wednesday, April 1, 2015 9:24:44 AM
> >
> > On Wed, 01 Apr 2015, Aaron Sierra wrote:
> >
> > > ----- Original Message -----
> > > > From: "Nicholas Mc Guire" <[email protected]>
> > > > Sent: Friday, March 13, 2015 6:23:47 AM
> > > >
> > > > This is only an API consolidation and should make things more readable
> > > > it replaces var * HZ / 1000 by msecs_to_jiffies(var) which helps
> > > > readability
> > > > and also handles all corner-cases properly.
> > > >
> > > > Signed-off-by: Nicholas Mc Guire <[email protected]>
> > > > ---
> > > >
> > > > Patch was compile tested with corenet64_smp_defconfig
> > > > (implies CONFIG_MTD_NAND_FSL_IFC=y)
> > > >
> > > > Patch is against 4.0-rc3 (localversion-next is -next-20150313
> > > >
> > > > drivers/mtd/nand/fsl_ifc_nand.c | 4 ++--
> > > > 1 file changed, 2 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/drivers/mtd/nand/fsl_ifc_nand.c
> > > > b/drivers/mtd/nand/fsl_ifc_nand.c
> > > > index 4c05f4f..51394e5 100644
> > > > --- a/drivers/mtd/nand/fsl_ifc_nand.c
> > > > +++ b/drivers/mtd/nand/fsl_ifc_nand.c
> > > > @@ -317,7 +317,7 @@ static void fsl_ifc_run_command(struct mtd_info *mtd)
> > > >
> > > > /* wait for command complete flag or timeout */
> > > > wait_event_timeout(ctrl->nand_wait, ctrl->nand_stat,
> > > > - IFC_TIMEOUT_MSECS * HZ/1000);
> > > > + msecs_to_jiffies(IFC_TIMEOUT_MSECS));
> > >
> > > Nicholas,
> > > Your patch makes me think that this timeout value should be calculated
> > > once during initialization and stored in a new member of
> > > struct fsl_ifc_mtd. That would improve readability AND have some
> > > positive impact on performance.
> > >
> >
> > is it not a bit wasteful to put it into struct fsl_ifc_mtd
> > which is used quite often in here ?cho
>
> Storing the timeout in the private structure would use 4 or 8 bytes,
> but the structure is passed around as pointer reference, so there is
> no added overhead there.
>
> > #define IFC_TIMEOUT msecs_to_jiffies(500)
> >
> > sould do - its only referenced twice and would achieve what you
> > suggested - initializing it in one location and improved readability
> >
> > wait_event_timeout(ctrl->nand_wait, ctrl->nand_stat, IFC_TIMEOUT);
> >
> > would there be any disadvantage of this solution?
>
> I don't have an issue with the compactness of your code. The issue
> to me is that msecs_to_jiffies() is a real function call, not a macro.
> That means that there would be a branch to that function followed by a
> non-trivial calculation *every* time fsl_ifc_run_command() is called.
>
> If the timeout value were calculated during init, then the cost of
> accessing it would simply a pointer dereference.

Nicholas, any progress on that builtin_const_p variant

2015-04-02 00:20:24

by Nicholas Mc Guire

[permalink] [raw]
Subject: Re: [PATCH] mtd: fsl_ifc_nand: use msecs_to_jiffies for time conversion

On Wed, 01 Apr 2015, Joe Perches wrote:

> On Wed, 2015-04-01 at 10:08 -0500, Aaron Sierra wrote:
> > ----- Original Message -----
> > > From: "Nicholas Mc Guire" <[email protected]>
> > > Sent: Wednesday, April 1, 2015 9:24:44 AM
> > >
> > > On Wed, 01 Apr 2015, Aaron Sierra wrote:
> > >
> > > > ----- Original Message -----
> > > > > From: "Nicholas Mc Guire" <[email protected]>
> > > > > Sent: Friday, March 13, 2015 6:23:47 AM
> > > > >
> > > > > This is only an API consolidation and should make things more readable
> > > > > it replaces var * HZ / 1000 by msecs_to_jiffies(var) which helps
> > > > > readability
> > > > > and also handles all corner-cases properly.
> > > > >
> > > > > Signed-off-by: Nicholas Mc Guire <[email protected]>
> > > > > ---
> > > > >
> > > > > Patch was compile tested with corenet64_smp_defconfig
> > > > > (implies CONFIG_MTD_NAND_FSL_IFC=y)
> > > > >
> > > > > Patch is against 4.0-rc3 (localversion-next is -next-20150313
> > > > >
> > > > > drivers/mtd/nand/fsl_ifc_nand.c | 4 ++--
> > > > > 1 file changed, 2 insertions(+), 2 deletions(-)
> > > > >
> > > > > diff --git a/drivers/mtd/nand/fsl_ifc_nand.c
> > > > > b/drivers/mtd/nand/fsl_ifc_nand.c
> > > > > index 4c05f4f..51394e5 100644
> > > > > --- a/drivers/mtd/nand/fsl_ifc_nand.c
> > > > > +++ b/drivers/mtd/nand/fsl_ifc_nand.c
> > > > > @@ -317,7 +317,7 @@ static void fsl_ifc_run_command(struct mtd_info *mtd)
> > > > >
> > > > > /* wait for command complete flag or timeout */
> > > > > wait_event_timeout(ctrl->nand_wait, ctrl->nand_stat,
> > > > > - IFC_TIMEOUT_MSECS * HZ/1000);
> > > > > + msecs_to_jiffies(IFC_TIMEOUT_MSECS));
> > > >
> > > > Nicholas,
> > > > Your patch makes me think that this timeout value should be calculated
> > > > once during initialization and stored in a new member of
> > > > struct fsl_ifc_mtd. That would improve readability AND have some
> > > > positive impact on performance.
> > > >
> > >
> > > is it not a bit wasteful to put it into struct fsl_ifc_mtd
> > > which is used quite often in here ?cho
> >
> > Storing the timeout in the private structure would use 4 or 8 bytes,
> > but the structure is passed around as pointer reference, so there is
> > no added overhead there.
> >
> > > #define IFC_TIMEOUT msecs_to_jiffies(500)
> > >
> > > sould do - its only referenced twice and would achieve what you
> > > suggested - initializing it in one location and improved readability
> > >
> > > wait_event_timeout(ctrl->nand_wait, ctrl->nand_stat, IFC_TIMEOUT);
> > >
> > > would there be any disadvantage of this solution?
> >
> > I don't have an issue with the compactness of your code. The issue
> > to me is that msecs_to_jiffies() is a real function call, not a macro.
> > That means that there would be a branch to that function followed by a
> > non-trivial calculation *every* time fsl_ifc_run_command() is called.
> >
> > If the timeout value were calculated during init, then the cost of
> > accessing it would simply a pointer dereference.
>
> Nicholas, any progress on that builtin_const_p variant
>
did not get to it yet - but thats the next thing
on my fun list.

thx!
hofrat