All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] jiffies.h: Better error message and add "const" where
@ 2008-03-29 13:32 Robert P. J. Day
  2008-03-29 13:46 ` Julia Lawall
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Robert P. J. Day @ 2008-03-29 13:32 UTC (permalink / raw)
  To: kernel-janitors


Add a more informative error message for bad values of HZ, and add
"const" argument qualification for a couple routines for which it's
appropriate.

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

---

  compile-tested on x86.

 include/linux/jiffies.h |    6 +++---
 kernel/time.c           |    4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
index e0b5b68..07a988f 100644
--- a/include/linux/jiffies.h
+++ b/include/linux/jiffies.h
@@ -36,7 +36,7 @@
 #elif HZ >= 6144 && HZ < 12288
 # define SHIFT_HZ	13
 #else
-# error You lose.
+# error Invalid value of HZ.
 #endif

 /* LATCH is used in the interval timer and ftape setup. */
@@ -277,8 +277,8 @@ extern void jiffies_to_timespec(const unsigned long jiffies,
 extern unsigned long timeval_to_jiffies(const struct timeval *value);
 extern void jiffies_to_timeval(const unsigned long jiffies,
 			       struct timeval *value);
-extern clock_t jiffies_to_clock_t(long x);
-extern unsigned long clock_t_to_jiffies(unsigned long x);
+extern clock_t jiffies_to_clock_t(const long x);
+extern unsigned long clock_t_to_jiffies(const unsigned long x);
 extern u64 jiffies_64_to_clock_t(u64 x);
 extern u64 nsec_to_clock_t(u64 x);

diff --git a/kernel/time.c b/kernel/time.c
index a5ec013..18bf135 100644
--- a/kernel/time.c
+++ b/kernel/time.c
@@ -576,7 +576,7 @@ EXPORT_SYMBOL(jiffies_to_timeval);
 /*
  * Convert jiffies/jiffies_64 to clock_t and back.
  */
-clock_t jiffies_to_clock_t(long x)
+clock_t jiffies_to_clock_t(const long x)
 {
 #if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) = 0
 # if HZ < USER_HZ
@@ -592,7 +592,7 @@ clock_t jiffies_to_clock_t(long x)
 }
 EXPORT_SYMBOL(jiffies_to_clock_t);

-unsigned long clock_t_to_jiffies(unsigned long x)
+unsigned long clock_t_to_jiffies(const unsigned long x)
 {
 #if (HZ % USER_HZ)=0
 	if (x >= ~0UL / (HZ / USER_HZ))

====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
    Have classroom, will lecture.

http://crashcourse.ca                          Waterloo, Ontario, CANADA
====================================

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

* Re: [PATCH] jiffies.h: Better error message and add "const" where
  2008-03-29 13:32 [PATCH] jiffies.h: Better error message and add "const" where Robert P. J. Day
@ 2008-03-29 13:46 ` Julia Lawall
  2008-03-29 13:49 ` [PATCH] jiffies.h: Better error message and add "const" where applicable Matthew Wilcox
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2008-03-29 13:46 UTC (permalink / raw)
  To: kernel-janitors

On Sat, 29 Mar 2008, Robert P. J. Day wrote:

> 
> Add a more informative error message for bad values of HZ, and add
> "const" argument qualification for a couple routines for which it's
> appropriate.

What is the criterion for adding const?  For example, should there be 
const on the declaration of gran in the following function (also in 
kernel/time.c)?

struct timespec timespec_trunc(struct timespec t, unsigned gran)
{
        /*
         * Division is pretty slow so avoid it for common cases.
         * Currently current_kernel_time() never returns better than
         * jiffies resolution. Exploit that.
         */
        if (gran <= jiffies_to_usecs(1) * 1000) {
                /* nothing */
        } else if (gran = 1000000000) {
                t.tv_nsec = 0;
        } else {
                t.tv_nsec -= t.tv_nsec % gran;
        }
        return t;
}

julia

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

* Re: [PATCH] jiffies.h: Better error message and add "const" where applicable.
  2008-03-29 13:32 [PATCH] jiffies.h: Better error message and add "const" where Robert P. J. Day
  2008-03-29 13:46 ` Julia Lawall
@ 2008-03-29 13:49 ` Matthew Wilcox
  2008-03-29 13:50 ` [PATCH] jiffies.h: Better error message and add "const" where Robert P. J. Day
  2008-03-29 13:54 ` Robert P. J. Day
  3 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox @ 2008-03-29 13:49 UTC (permalink / raw)
  To: kernel-janitors

On Sat, Mar 29, 2008 at 09:32:39AM -0400, Robert P. J. Day wrote:
> Add a more informative error message for bad values of HZ, and add
> "const" argument qualification for a couple routines for which it's
> appropriate.

What effect do you think adding the 'const' has?  Remember, C is
pass-by-value.

More useful might be to mark the functions with __attribute_const__.

-- 
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."

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

* Re: [PATCH] jiffies.h: Better error message and add "const" where
  2008-03-29 13:32 [PATCH] jiffies.h: Better error message and add "const" where Robert P. J. Day
  2008-03-29 13:46 ` Julia Lawall
  2008-03-29 13:49 ` [PATCH] jiffies.h: Better error message and add "const" where applicable Matthew Wilcox
@ 2008-03-29 13:50 ` Robert P. J. Day
  2008-03-29 13:54 ` Robert P. J. Day
  3 siblings, 0 replies; 5+ messages in thread
From: Robert P. J. Day @ 2008-03-29 13:50 UTC (permalink / raw)
  To: kernel-janitors

On Sat, 29 Mar 2008, Julia Lawall wrote:

> On Sat, 29 Mar 2008, Robert P. J. Day wrote:
>
> > Add a more informative error message for bad values of HZ, and add
> > "const" argument qualification for a couple routines for which
> > it's appropriate.
>
> What is the criterion for adding const?  For example, should there
> be const on the declaration of gran in the following function (also
> in kernel/time.c)?
>
> struct timespec timespec_trunc(struct timespec t, unsigned gran)
> {
>         /*
>          * Division is pretty slow so avoid it for common cases.
>          * Currently current_kernel_time() never returns better than
>          * jiffies resolution. Exploit that.
>          */
>         if (gran <= jiffies_to_usecs(1) * 1000) {
>                 /* nothing */
>         } else if (gran = 1000000000) {
>                 t.tv_nsec = 0;
>         } else {
>                 t.tv_nsec -= t.tv_nsec % gran;
>         }
>         return t;
> }

yes, i guess it would be appropriate there as well -- i just didn't
notice that.  i was digging through the jiffies code so those were the
only ones that jumped out at me.  maybe i'll look through jiffies.h
more carefully and see what else i missed and update the patch.

rday
--

====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
    Have classroom, will lecture.

http://crashcourse.ca                          Waterloo, Ontario, CANADA
====================================

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

* Re: [PATCH] jiffies.h: Better error message and add "const" where
  2008-03-29 13:32 [PATCH] jiffies.h: Better error message and add "const" where Robert P. J. Day
                   ` (2 preceding siblings ...)
  2008-03-29 13:50 ` [PATCH] jiffies.h: Better error message and add "const" where Robert P. J. Day
@ 2008-03-29 13:54 ` Robert P. J. Day
  3 siblings, 0 replies; 5+ messages in thread
From: Robert P. J. Day @ 2008-03-29 13:54 UTC (permalink / raw)
  To: kernel-janitors

On Sat, 29 Mar 2008, Matthew Wilcox wrote:

> On Sat, Mar 29, 2008 at 09:32:39AM -0400, Robert P. J. Day wrote:
> > Add a more informative error message for bad values of HZ, and add
> > "const" argument qualification for a couple routines for which
> > it's appropriate.
>
> What effect do you think adding the 'const' has?  Remember, C is
> pass-by-value.

simple consistency -- "const" is used elsewhere on prototypes in
jiffies.h:

...
extern unsigned int jiffies_to_msecs(const unsigned long j);
extern unsigned int jiffies_to_usecs(const unsigned long j);
extern unsigned long msecs_to_jiffies(const unsigned int m);
extern unsigned long usecs_to_jiffies(const unsigned int u);
... etc etc ...

> More useful might be to mark the functions with __attribute_const__.

good point ... under the circumstances, then, what's worth doing in
that header file?  adding __attribute_const__ where appropriate?  or
just leaving things as they are?  i'm good either way, i just happen
to like consistency.

rday
--

====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
    Have classroom, will lecture.

http://crashcourse.ca                          Waterloo, Ontario, CANADA
====================================

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

end of thread, other threads:[~2008-03-29 13:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-29 13:32 [PATCH] jiffies.h: Better error message and add "const" where Robert P. J. Day
2008-03-29 13:46 ` Julia Lawall
2008-03-29 13:49 ` [PATCH] jiffies.h: Better error message and add "const" where applicable Matthew Wilcox
2008-03-29 13:50 ` [PATCH] jiffies.h: Better error message and add "const" where Robert P. J. Day
2008-03-29 13:54 ` Robert P. J. Day

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.