lkml.org 
[lkml]   [1996]   [Jun]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Subjectstruct timespec
Date
Hello *!

Last week, I found out, that timespec is declared as
struct timespec {
long tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};

However pthreads declares it in its own header files as
struct timespec {
long ts_sec; /* seconds */
long ts_nsec; /* nanoseconds */
};
which seems a little bit more intuitive to me.

I made a little patch, which replaces tv_n?sec in ts_n?sec. The
only change I had to do has been in kernel/sched.c and <linux/time.h>.
Additionaly I found a line saying ``Linus, please fill in the correct
value here'' in kernel/sched.c. Linus, please have a look at that
line and correct it, if necessary.

BTW, does anybody know, why all kernel versions reside in
a linux dircetory and not in linux-version?

Thomas

Patch for tv_n?sec --> ts_n?sec follows:

----- cut here -----

diff -rc linux-2.0.0/include/linux/time.h linux/include/linux/time.h
*** linux-2.0.0/include/linux/time.h Tue Feb 13 18:55:59 1996
--- linux/include/linux/time.h Mon Jun 17 15:28:21 1996
***************
*** 2,9 ****
#define _LINUX_TIME_H

struct timespec {
! long tv_sec; /* seconds */
! long tv_nsec; /* nanoseconds */
};

struct timeval {
--- 2,9 ----
#define _LINUX_TIME_H

struct timespec {
! long ts_sec; /* seconds */
! long ts_nsec; /* nanoseconds */
};

struct timeval {
diff -rc linux-2.0.0/kernel/sched.c linux/kernel/sched.c
*** linux-2.0.0/kernel/sched.c Tue May 7 11:06:51 1996
--- linux/kernel/sched.c Mon Jun 17 15:23:55 1996
***************
*** 1273,1280 ****
if (error)
return error;

! t.tv_sec = 0;
! t.tv_nsec = 0; /* <-- Linus, please fill correct value in here */
return -ENOSYS; /* and then delete this line. Thanks! */
memcpy_tofs(interval, &t, sizeof(struct timespec));

--- 1273,1280 ----
if (error)
return error;

! t.ts_sec = 0;
! t.ts_nsec = 0; /* <-- Linus, please fill correct value in here */
return -ENOSYS; /* and then delete this line. Thanks! */
memcpy_tofs(interval, &t, sizeof(struct timespec));

***************
*** 1287,1294 ****
*/
static unsigned long timespectojiffies(struct timespec *value)
{
! unsigned long sec = (unsigned) value->tv_sec;
! long nsec = value->tv_nsec;

if (sec > (LONG_MAX / HZ))
return LONG_MAX;
--- 1287,1294 ----
*/
static unsigned long timespectojiffies(struct timespec *value)
{
! unsigned long sec = (unsigned) value->ts_sec;
! long nsec = value->ts_nsec;

if (sec > (LONG_MAX / HZ))
return LONG_MAX;
***************
*** 1299,1306 ****

static void jiffiestotimespec(unsigned long jiffies, struct timespec *value)
{
! value->tv_nsec = (jiffies % HZ) * (1000000000L / HZ);
! value->tv_sec = jiffies / HZ;
return;
}

--- 1299,1306 ----

static void jiffiestotimespec(unsigned long jiffies, struct timespec *value)
{
! value->ts_nsec = (jiffies % HZ) * (1000000000L / HZ);
! value->ts_sec = jiffies / HZ;
return;
}

***************
*** 1321,1340 ****
return error;
}

! if (t.tv_nsec >= 1000000000L || t.tv_nsec < 0 || t.tv_sec < 0)
return -EINVAL;

! if (t.tv_sec == 0 && t.tv_nsec <= 2000000L &&
current->policy != SCHED_OTHER) {
/*
* Short delay requests up to 2 ms will be handled with
* high precision by a busy wait for all real-time processes.
*/
! udelay((t.tv_nsec + 999) / 1000);
return 0;
}

! expire = timespectojiffies(&t) + (t.tv_sec || t.tv_nsec) + jiffies;
current->timeout = expire;
current->state = TASK_INTERRUPTIBLE;
schedule();
--- 1321,1340 ----
return error;
}

! if (t.ts_nsec >= 1000000000L || t.ts_nsec < 0 || t.ts_sec < 0)
return -EINVAL;

! if (t.ts_sec == 0 && t.ts_nsec <= 2000000L &&
current->policy != SCHED_OTHER) {
/*
* Short delay requests up to 2 ms will be handled with
* high precision by a busy wait for all real-time processes.
*/
! udelay((t.ts_nsec + 999) / 1000);
return 0;
}

! expire = timespectojiffies(&t) + (t.ts_sec || t.ts_nsec) + jiffies;
current->timeout = expire;
current->state = TASK_INTERRUPTIBLE;
schedule();



\
 
 \ /
  Last update: 2005-03-22 13:37    [W:0.065 / U:0.136 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site