jiffies and co

Gerard Roudier (groudier@club-internet.fr)
Mon, 16 Aug 1999 11:49:26 +0200 (MET DST)


Hi all,

I was just working on making the 'jiffies and co' stuff as clean as
possible in the ncr/sym SCSI drivers. By 'clean', I mean also:
- Not referencing explicetely either the 'jiffies' variable and its
actual type.
Btw, assuming it is a lvalue is not restrictive given the 64 bit that
is coming and the need of atomic arithmetic operations on time values.

Why is jiffies type still 'unsigned long', given that all calculations
that try to be not too wrong with wrap-around just cast timer values to
signed long?

On the other hand, the current time_xxx() stuff in the kernel does not
allow me to achieve the cleanness I would want to achieve, and has proven
to be very confusing and not handy at all, but the below simple stuff, for
example, seems to fit my expectations quite well:

/*
* Hide the actual type of a time value, only assuming that it is
* a lvalue (required to deal intelligently with atomic changes).
*/
typedef long ktime_t;

/*
* Calculate the difference between time value a and time value b.
* Returns a signed long value that is quite suitable for common timeout
* handling. (note that the casts should be useless given ktime_t)
*/
#define ktime_dif(a, b) ((long)(a) - (long)(b))

/*
* Add a signed value (in kernel tics) to a kernel time value.
*/
#define ktime_add(a, o) ((long)(a) + o)

/*
* Get the current kernel time (jiffies) + signed delay.
* Still quite enough to handle common timeouts.
* The delay argument could be removed given timer_add().
*/
#define ktime_get(o) ((long)(jiffies) + o)

To kernel maintainer (and Linus and Alan in particular :-) ):

Will my patch be refused if I use this stuff instead of the one that is
proposed in timer.h ?

Regards,
Gérard.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/