Re: [RFC][PATCH 1/4] add jiffies_to_nsecs() helper and fix up size of usecs

2005-07-16 Thread Nishanth Aravamudan
On 15.07.2005 [14:14:25 +0200], Pavel Machek wrote:
> Hi!
> 
> > > > +static inline u64 jiffies_to_nsecs(const unsigned long j)
> > > > +{
> > > > +#if HZ <= NSEC_PER_SEC && !(NSEC_PER_SEC % HZ)
> > > > +   return (NSEC_PER_SEC / HZ) * (u64)j;
> > > > +#elif HZ > NSEC_PER_SEC && !(HZ % NSEC_PER_SEC)
> > > > +   return ((u64)j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
> > > > +#else
> > > > +   return ((u64)j * NSEC_PER_SEC) / HZ;
> > > > +#endif
> > > > +}
> > > 
> > > That might look a little better something like:
> > > 
> > > static inline u64 jiffies_to_nsecs(const unsigned long __j)
> > > {
> > >   u64 j = __j;
> > > 
> > >   if (HZ <= NSEC_PER_SEC && !(NSEC_PER_SEC % HZ))
> > >   return (NSEC_PER_SEC / HZ) * j;
> > >   else if (HZ > NSEC_PER_SEC && !(HZ % NSEC_PER_SEC))
> > >   return (j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
> > >   else
> > >   return (j * NSEC_PER_SEC) / HZ;
> > > }
> > > 
> > > Compilers are smart :)
> > 
> > Well, I was trying to keep it similar to the other conversion functions.
> > I guess the compiler can evaluate the conditional full of constants at
> > compile-time regardless of whether it is #if or if ().
> > 
> > I can make these changes if others would like them as well.
> 
> Yes, please. And feel free to convert nearby functions, too ;-).

I have a patch to make this change for all the jiffies <--> human-time
functions, but have a problem. I noticed that these functions, in the
if/else form (as opposed to #if/#else) will warn about division-by-zero
problems, as (HZ / MSEC_PER_SEC), (HZ / USEC_PER_SEC) & (HZ /
NSEC_PER_SEC) are all 0 if HZ < 1000 (which, of course, is the default
now :) ). Any suggestions? Just leave the functions as is? Even then,
I'm going to update this patch to use USEC_PER_SEC and MSEC_PER_SEC in
the other conversion functions like I use NSEC_PER_SEC in the first
version.

Thanks,
Nish
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH 1/4] add jiffies_to_nsecs() helper and fix up size of usecs

2005-07-16 Thread Pavel Machek
Hi!

> > > +static inline u64 jiffies_to_nsecs(const unsigned long j)
> > > +{
> > > +#if HZ <= NSEC_PER_SEC && !(NSEC_PER_SEC % HZ)
> > > + return (NSEC_PER_SEC / HZ) * (u64)j;
> > > +#elif HZ > NSEC_PER_SEC && !(HZ % NSEC_PER_SEC)
> > > + return ((u64)j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
> > > +#else
> > > + return ((u64)j * NSEC_PER_SEC) / HZ;
> > > +#endif
> > > +}
> > 
> > That might look a little better something like:
> > 
> > static inline u64 jiffies_to_nsecs(const unsigned long __j)
> > {
> > u64 j = __j;
> > 
> > if (HZ <= NSEC_PER_SEC && !(NSEC_PER_SEC % HZ))
> > return (NSEC_PER_SEC / HZ) * j;
> > else if (HZ > NSEC_PER_SEC && !(HZ % NSEC_PER_SEC))
> > return (j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
> > else
> > return (j * NSEC_PER_SEC) / HZ;
> > }
> > 
> > Compilers are smart :)
> 
> Well, I was trying to keep it similar to the other conversion functions.
> I guess the compiler can evaluate the conditional full of constants at
> compile-time regardless of whether it is #if or if ().
> 
> I can make these changes if others would like them as well.

Yes, please. And feel free to convert nearby functions, too ;-).
Pavel
-- 
teflon -- maybe it is a trademark, but it should not be.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH 1/4] add jiffies_to_nsecs() helper and fix up size of usecs

2005-07-16 Thread Pavel Machek
Hi!

   +static inline u64 jiffies_to_nsecs(const unsigned long j)
   +{
   +#if HZ = NSEC_PER_SEC  !(NSEC_PER_SEC % HZ)
   + return (NSEC_PER_SEC / HZ) * (u64)j;
   +#elif HZ  NSEC_PER_SEC  !(HZ % NSEC_PER_SEC)
   + return ((u64)j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
   +#else
   + return ((u64)j * NSEC_PER_SEC) / HZ;
   +#endif
   +}
  
  That might look a little better something like:
  
  static inline u64 jiffies_to_nsecs(const unsigned long __j)
  {
  u64 j = __j;
  
  if (HZ = NSEC_PER_SEC  !(NSEC_PER_SEC % HZ))
  return (NSEC_PER_SEC / HZ) * j;
  else if (HZ  NSEC_PER_SEC  !(HZ % NSEC_PER_SEC))
  return (j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
  else
  return (j * NSEC_PER_SEC) / HZ;
  }
  
  Compilers are smart :)
 
 Well, I was trying to keep it similar to the other conversion functions.
 I guess the compiler can evaluate the conditional full of constants at
 compile-time regardless of whether it is #if or if ().
 
 I can make these changes if others would like them as well.

Yes, please. And feel free to convert nearby functions, too ;-).
Pavel
-- 
teflon -- maybe it is a trademark, but it should not be.
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH 1/4] add jiffies_to_nsecs() helper and fix up size of usecs

2005-07-16 Thread Nishanth Aravamudan
On 15.07.2005 [14:14:25 +0200], Pavel Machek wrote:
 Hi!
 
+static inline u64 jiffies_to_nsecs(const unsigned long j)
+{
+#if HZ = NSEC_PER_SEC  !(NSEC_PER_SEC % HZ)
+   return (NSEC_PER_SEC / HZ) * (u64)j;
+#elif HZ  NSEC_PER_SEC  !(HZ % NSEC_PER_SEC)
+   return ((u64)j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
+#else
+   return ((u64)j * NSEC_PER_SEC) / HZ;
+#endif
+}
   
   That might look a little better something like:
   
   static inline u64 jiffies_to_nsecs(const unsigned long __j)
   {
 u64 j = __j;
   
 if (HZ = NSEC_PER_SEC  !(NSEC_PER_SEC % HZ))
 return (NSEC_PER_SEC / HZ) * j;
 else if (HZ  NSEC_PER_SEC  !(HZ % NSEC_PER_SEC))
 return (j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
 else
 return (j * NSEC_PER_SEC) / HZ;
   }
   
   Compilers are smart :)
  
  Well, I was trying to keep it similar to the other conversion functions.
  I guess the compiler can evaluate the conditional full of constants at
  compile-time regardless of whether it is #if or if ().
  
  I can make these changes if others would like them as well.
 
 Yes, please. And feel free to convert nearby functions, too ;-).

I have a patch to make this change for all the jiffies -- human-time
functions, but have a problem. I noticed that these functions, in the
if/else form (as opposed to #if/#else) will warn about division-by-zero
problems, as (HZ / MSEC_PER_SEC), (HZ / USEC_PER_SEC)  (HZ /
NSEC_PER_SEC) are all 0 if HZ  1000 (which, of course, is the default
now :) ). Any suggestions? Just leave the functions as is? Even then,
I'm going to update this patch to use USEC_PER_SEC and MSEC_PER_SEC in
the other conversion functions like I use NSEC_PER_SEC in the first
version.

Thanks,
Nish
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH 1/4] add jiffies_to_nsecs() helper and fix up size of usecs

2005-07-14 Thread Nishanth Aravamudan
On 14.07.2005 [13:54:47 -0700], Dave Hansen wrote:
> On Thu, 2005-07-14 at 13:28 -0700, Nishanth Aravamudan wrote:
> > +static inline u64 jiffies_to_nsecs(const unsigned long j)
> > +{
> > +#if HZ <= NSEC_PER_SEC && !(NSEC_PER_SEC % HZ)
> > +   return (NSEC_PER_SEC / HZ) * (u64)j;
> > +#elif HZ > NSEC_PER_SEC && !(HZ % NSEC_PER_SEC)
> > +   return ((u64)j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
> > +#else
> > +   return ((u64)j * NSEC_PER_SEC) / HZ;
> > +#endif
> > +}
> 
> That might look a little better something like:
> 
> static inline u64 jiffies_to_nsecs(const unsigned long __j)
> {
>   u64 j = __j;
> 
>   if (HZ <= NSEC_PER_SEC && !(NSEC_PER_SEC % HZ))
>   return (NSEC_PER_SEC / HZ) * j;
>   else if (HZ > NSEC_PER_SEC && !(HZ % NSEC_PER_SEC))
>   return (j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
>   else
>   return (j * NSEC_PER_SEC) / HZ;
> }
> 
> Compilers are smart :)

Well, I was trying to keep it similar to the other conversion functions.
I guess the compiler can evaluate the conditional full of constants at
compile-time regardless of whether it is #if or if ().

I can make these changes if others would like them as well.

Thanks,
Nish
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH 1/4] add jiffies_to_nsecs() helper and fix up size of usecs

2005-07-14 Thread Dave Hansen
On Thu, 2005-07-14 at 13:28 -0700, Nishanth Aravamudan wrote:
> +static inline u64 jiffies_to_nsecs(const unsigned long j)
> +{
> +#if HZ <= NSEC_PER_SEC && !(NSEC_PER_SEC % HZ)
> + return (NSEC_PER_SEC / HZ) * (u64)j;
> +#elif HZ > NSEC_PER_SEC && !(HZ % NSEC_PER_SEC)
> + return ((u64)j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
> +#else
> + return ((u64)j * NSEC_PER_SEC) / HZ;
> +#endif
> +}

That might look a little better something like:

static inline u64 jiffies_to_nsecs(const unsigned long __j)
{
u64 j = __j;

if (HZ <= NSEC_PER_SEC && !(NSEC_PER_SEC % HZ))
return (NSEC_PER_SEC / HZ) * j;
else if (HZ > NSEC_PER_SEC && !(HZ % NSEC_PER_SEC))
return (j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
else
return (j * NSEC_PER_SEC) / HZ;
}

Compilers are smart :)

-- Dave

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC][PATCH 1/4] add jiffies_to_nsecs() helper and fix up size of usecs

2005-07-14 Thread Nishanth Aravamudan
From: Nishanth Aravamudan <[EMAIL PROTECTED]>

Description: Add a jiffies_to_nsecs() helper function. Make consistent
the size of microseconds (unsigned long) throughout the conversion
functions.

Signed-off-by: Nishanth Aravamudan <[EMAIL PROTECTED]>

---

 jiffies.h |   15 +--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff -urpN 2.6.13-rc3-base/include/linux/jiffies.h 
2.6.13-rc3-dev/include/linux/jiffies.h
--- 2.6.13-rc3-base/include/linux/jiffies.h 2005-03-01 23:37:31.0 
-0800
+++ 2.6.13-rc3-dev/include/linux/jiffies.h  2005-07-14 12:43:44.0 
-0700
@@ -263,7 +263,7 @@ static inline unsigned int jiffies_to_ms
 #endif
 }
 
-static inline unsigned int jiffies_to_usecs(const unsigned long j)
+static inline unsigned long jiffies_to_usecs(const unsigned long j)
 {
 #if HZ <= 100 && !(100 % HZ)
return (100 / HZ) * j;
@@ -274,6 +274,17 @@ static inline unsigned int jiffies_to_us
 #endif
 }
 
+static inline u64 jiffies_to_nsecs(const unsigned long j)
+{
+#if HZ <= NSEC_PER_SEC && !(NSEC_PER_SEC % HZ)
+   return (NSEC_PER_SEC / HZ) * (u64)j;
+#elif HZ > NSEC_PER_SEC && !(HZ % NSEC_PER_SEC)
+   return ((u64)j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
+#else
+   return ((u64)j * NSEC_PER_SEC) / HZ;
+#endif
+}
+
 static inline unsigned long msecs_to_jiffies(const unsigned int m)
 {
if (m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
@@ -287,7 +298,7 @@ static inline unsigned long msecs_to_jif
 #endif
 }
 
-static inline unsigned long usecs_to_jiffies(const unsigned int u)
+static inline unsigned long usecs_to_jiffies(const unsigned long u)
 {
if (u > jiffies_to_usecs(MAX_JIFFY_OFFSET))
return MAX_JIFFY_OFFSET;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC][PATCH 1/4] add jiffies_to_nsecs() helper and fix up size of usecs

2005-07-14 Thread Nishanth Aravamudan
From: Nishanth Aravamudan [EMAIL PROTECTED]

Description: Add a jiffies_to_nsecs() helper function. Make consistent
the size of microseconds (unsigned long) throughout the conversion
functions.

Signed-off-by: Nishanth Aravamudan [EMAIL PROTECTED]

---

 jiffies.h |   15 +--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff -urpN 2.6.13-rc3-base/include/linux/jiffies.h 
2.6.13-rc3-dev/include/linux/jiffies.h
--- 2.6.13-rc3-base/include/linux/jiffies.h 2005-03-01 23:37:31.0 
-0800
+++ 2.6.13-rc3-dev/include/linux/jiffies.h  2005-07-14 12:43:44.0 
-0700
@@ -263,7 +263,7 @@ static inline unsigned int jiffies_to_ms
 #endif
 }
 
-static inline unsigned int jiffies_to_usecs(const unsigned long j)
+static inline unsigned long jiffies_to_usecs(const unsigned long j)
 {
 #if HZ = 100  !(100 % HZ)
return (100 / HZ) * j;
@@ -274,6 +274,17 @@ static inline unsigned int jiffies_to_us
 #endif
 }
 
+static inline u64 jiffies_to_nsecs(const unsigned long j)
+{
+#if HZ = NSEC_PER_SEC  !(NSEC_PER_SEC % HZ)
+   return (NSEC_PER_SEC / HZ) * (u64)j;
+#elif HZ  NSEC_PER_SEC  !(HZ % NSEC_PER_SEC)
+   return ((u64)j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
+#else
+   return ((u64)j * NSEC_PER_SEC) / HZ;
+#endif
+}
+
 static inline unsigned long msecs_to_jiffies(const unsigned int m)
 {
if (m  jiffies_to_msecs(MAX_JIFFY_OFFSET))
@@ -287,7 +298,7 @@ static inline unsigned long msecs_to_jif
 #endif
 }
 
-static inline unsigned long usecs_to_jiffies(const unsigned int u)
+static inline unsigned long usecs_to_jiffies(const unsigned long u)
 {
if (u  jiffies_to_usecs(MAX_JIFFY_OFFSET))
return MAX_JIFFY_OFFSET;
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH 1/4] add jiffies_to_nsecs() helper and fix up size of usecs

2005-07-14 Thread Dave Hansen
On Thu, 2005-07-14 at 13:28 -0700, Nishanth Aravamudan wrote:
 +static inline u64 jiffies_to_nsecs(const unsigned long j)
 +{
 +#if HZ = NSEC_PER_SEC  !(NSEC_PER_SEC % HZ)
 + return (NSEC_PER_SEC / HZ) * (u64)j;
 +#elif HZ  NSEC_PER_SEC  !(HZ % NSEC_PER_SEC)
 + return ((u64)j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
 +#else
 + return ((u64)j * NSEC_PER_SEC) / HZ;
 +#endif
 +}

That might look a little better something like:

static inline u64 jiffies_to_nsecs(const unsigned long __j)
{
u64 j = __j;

if (HZ = NSEC_PER_SEC  !(NSEC_PER_SEC % HZ))
return (NSEC_PER_SEC / HZ) * j;
else if (HZ  NSEC_PER_SEC  !(HZ % NSEC_PER_SEC))
return (j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
else
return (j * NSEC_PER_SEC) / HZ;
}

Compilers are smart :)

-- Dave

-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH 1/4] add jiffies_to_nsecs() helper and fix up size of usecs

2005-07-14 Thread Nishanth Aravamudan
On 14.07.2005 [13:54:47 -0700], Dave Hansen wrote:
 On Thu, 2005-07-14 at 13:28 -0700, Nishanth Aravamudan wrote:
  +static inline u64 jiffies_to_nsecs(const unsigned long j)
  +{
  +#if HZ = NSEC_PER_SEC  !(NSEC_PER_SEC % HZ)
  +   return (NSEC_PER_SEC / HZ) * (u64)j;
  +#elif HZ  NSEC_PER_SEC  !(HZ % NSEC_PER_SEC)
  +   return ((u64)j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
  +#else
  +   return ((u64)j * NSEC_PER_SEC) / HZ;
  +#endif
  +}
 
 That might look a little better something like:
 
 static inline u64 jiffies_to_nsecs(const unsigned long __j)
 {
   u64 j = __j;
 
   if (HZ = NSEC_PER_SEC  !(NSEC_PER_SEC % HZ))
   return (NSEC_PER_SEC / HZ) * j;
   else if (HZ  NSEC_PER_SEC  !(HZ % NSEC_PER_SEC))
   return (j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
   else
   return (j * NSEC_PER_SEC) / HZ;
 }
 
 Compilers are smart :)

Well, I was trying to keep it similar to the other conversion functions.
I guess the compiler can evaluate the conditional full of constants at
compile-time regardless of whether it is #if or if ().

I can make these changes if others would like them as well.

Thanks,
Nish
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/