From cff7a505e85277c605a27d38ee5c8358a0d29ad7 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Fri, 18 Apr 2008 13:58:37 +0100 Subject: [PATCH] Changed time representation to posix style struct timeval/ gettimeofday. --- src/generic/time.c | 37 ++++++++----------- tasks/fs0/main.c | 10 ++--- tasks/libl4/include/l4lib/arch-arm/syscalls.h | 15 +------- tasks/libposix/SConstruct | 1 + tasks/libposix/time.c | 17 +++++++++ 5 files changed, 40 insertions(+), 40 deletions(-) create mode 100644 tasks/libposix/time.c diff --git a/src/generic/time.c b/src/generic/time.c index 2e6db8d..396903c 100644 --- a/src/generic/time.c +++ b/src/generic/time.c @@ -29,20 +29,23 @@ static inline void increase_jiffies(void) } -/* Represents time since epoch */ +/* Internal representation of time since epoch */ struct time_info { int reader; u32 thz; /* Ticks in this hertz so far */ - u32 sec; - u32 min; - u32 hour; - u64 day; + u64 sec; /* Seconds so far */ +}; + +/* Used by posix systems */ +struct timeval { + int tv_sec; + int tv_usec; }; static struct time_info systime = { 0 }; /* - * A terribly basic (probably erroneous) + * A very basic (probably erroneous) * rule-of-thumb time calculation. */ void update_system_time(void) @@ -54,41 +57,31 @@ void update_system_time(void) /* Increase just like jiffies, but reset every HZ */ systime.thz++; + /* On every HZ increase seconds */ if (systime.thz == HZ) { systime.thz = 0; systime.sec++; } - if (systime.sec == 60) { - systime.sec = 0; - systime.min++; - } - if (systime.min == 60) { - systime.min = 0; - systime.hour++; - } - if (systime.hour == 24) { - systime.hour = 0; - systime.day++; - } } /* Read system time */ int sys_time(struct syscall_args *args) { - struct time_info *ti = (struct time_info *)args->r0; + struct timeval *tv = (struct timeval *)args->r0; int set = (int)args->r1; int retries = 20; - if (check_access((unsigned long)ti, sizeof(*ti), MAP_USR_RW_FLAGS) < 0) + if (check_access((unsigned long)tv, sizeof(*tv), MAP_USR_RW_FLAGS) < 0) return -EINVAL; /* Get time */ if (!set) { while(retries > 0) { systime.reader = 1; - memcpy(ti, &systime, sizeof(*ti)); - retries--; + tv->tv_sec = systime.sec; + tv->tv_usec = 1000000 * systime.thz / HZ; + retries--; if (systime.reader) break; } diff --git a/tasks/fs0/main.c b/tasks/fs0/main.c index bc087f3..57974bd 100644 --- a/tasks/fs0/main.c +++ b/tasks/fs0/main.c @@ -15,6 +15,7 @@ #include #include #include +#include /* * TODO: @@ -99,7 +100,7 @@ void handle_fs_requests(void) void main(void) { - struct time_info ti; + struct timeval tv; printf("\n%s: Started with tid: %d\n", __TASKNAME__, self_tid()); @@ -107,12 +108,11 @@ void main(void) wait_pager(PAGER_TID); - if (l4_time(&ti, 0) < 0) { + if (gettimeofday(&tv, 0) < 0) { printf("Reading the time has failed.\n"); } else { - printf("Current time since system started: %u ticks, " - "%u seconds, %u minutes, %u hours, %llu days.\n", - ti.thz, ti.sec, ti.min, ti.hour, ti.day); + printf("Current time since system started: %u useconds, " + "%u seconds.\n", tv.tv_usec, tv.tv_sec); } printf("%s: Listening requests.\n", __TASKNAME__); diff --git a/tasks/libl4/include/l4lib/arch-arm/syscalls.h b/tasks/libl4/include/l4lib/arch-arm/syscalls.h index 4155400..d5d270e 100644 --- a/tasks/libl4/include/l4lib/arch-arm/syscalls.h +++ b/tasks/libl4/include/l4lib/arch-arm/syscalls.h @@ -68,20 +68,9 @@ typedef int (*__l4_kmem_control_t)(unsigned long pfn, int npages, int grant); extern __l4_kmem_control_t __l4_kmem_control; int l4_kmem_control(unsigned long pfn, int npages, int grant); -/* Represents time since epoch, a c0 specific structure. */ -struct time_info { - int reader; - u32 thz; /* Ticks in this hertz so far */ - u32 sec; - u32 min; - u32 hour; - u64 day; -}; - -typedef int (*__l4_time_t)(struct time_info *ti, int set); +typedef int (*__l4_time_t)(void *timeval, int set); extern __l4_time_t __l4_time; -int l4_time(void *time_info, int set); - +int l4_time(void *timeval, int set); /* To be supplied by server tasks. */ diff --git a/tasks/libposix/SConstruct b/tasks/libposix/SConstruct index 714c86d..352c734 100644 --- a/tasks/libposix/SConstruct +++ b/tasks/libposix/SConstruct @@ -16,6 +16,7 @@ config_h = join(project_root, "include/l4/config.h") env = Environment(CC = 'arm-none-linux-gnueabi-gcc', CCFLAGS = ['-g', '-std=gnu99', '-nostdlib', '-ffreestanding'], LINKFLAGS = ['-nostdlib'], + CPPPATH = ['#include'], ENV = {'PATH' : os.environ['PATH']}, LIBS = 'gcc') diff --git a/tasks/libposix/time.c b/tasks/libposix/time.c new file mode 100644 index 0000000..189905e --- /dev/null +++ b/tasks/libposix/time.c @@ -0,0 +1,17 @@ + +#include +#include +#include + +int gettimeofday(struct timeval *tv, struct timezone *tz) +{ + int ret = l4_time(tv, 0); + + /* If error, return positive error code */ + if (ret < 0) { + errno = -ret; + return -1; + } + /* else return value */ + return ret; +}