mirror of
https://github.com/drasko/codezero.git
synced 2026-07-20 14:15:24 +02:00
Changed time representation to posix style struct timeval/ gettimeofday.
This commit is contained in:
@@ -29,20 +29,23 @@ static inline void increase_jiffies(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Represents time since epoch */
|
/* Internal representation of time since epoch */
|
||||||
struct time_info {
|
struct time_info {
|
||||||
int reader;
|
int reader;
|
||||||
u32 thz; /* Ticks in this hertz so far */
|
u32 thz; /* Ticks in this hertz so far */
|
||||||
u32 sec;
|
u64 sec; /* Seconds so far */
|
||||||
u32 min;
|
};
|
||||||
u32 hour;
|
|
||||||
u64 day;
|
/* Used by posix systems */
|
||||||
|
struct timeval {
|
||||||
|
int tv_sec;
|
||||||
|
int tv_usec;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct time_info systime = { 0 };
|
static struct time_info systime = { 0 };
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A terribly basic (probably erroneous)
|
* A very basic (probably erroneous)
|
||||||
* rule-of-thumb time calculation.
|
* rule-of-thumb time calculation.
|
||||||
*/
|
*/
|
||||||
void update_system_time(void)
|
void update_system_time(void)
|
||||||
@@ -54,41 +57,31 @@ void update_system_time(void)
|
|||||||
/* Increase just like jiffies, but reset every HZ */
|
/* Increase just like jiffies, but reset every HZ */
|
||||||
systime.thz++;
|
systime.thz++;
|
||||||
|
|
||||||
|
/* On every HZ increase seconds */
|
||||||
if (systime.thz == HZ) {
|
if (systime.thz == HZ) {
|
||||||
systime.thz = 0;
|
systime.thz = 0;
|
||||||
systime.sec++;
|
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 */
|
/* Read system time */
|
||||||
int sys_time(struct syscall_args *args)
|
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 set = (int)args->r1;
|
||||||
int retries = 20;
|
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;
|
return -EINVAL;
|
||||||
|
|
||||||
/* Get time */
|
/* Get time */
|
||||||
if (!set) {
|
if (!set) {
|
||||||
while(retries > 0) {
|
while(retries > 0) {
|
||||||
systime.reader = 1;
|
systime.reader = 1;
|
||||||
memcpy(ti, &systime, sizeof(*ti));
|
tv->tv_sec = systime.sec;
|
||||||
retries--;
|
tv->tv_usec = 1000000 * systime.thz / HZ;
|
||||||
|
|
||||||
|
retries--;
|
||||||
if (systime.reader)
|
if (systime.reader)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include <kdata.h>
|
#include <kdata.h>
|
||||||
#include <syscalls.h>
|
#include <syscalls.h>
|
||||||
#include <task.h>
|
#include <task.h>
|
||||||
|
#include <posix/sys/time.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO:
|
* TODO:
|
||||||
@@ -99,7 +100,7 @@ void handle_fs_requests(void)
|
|||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
struct time_info ti;
|
struct timeval tv;
|
||||||
|
|
||||||
printf("\n%s: Started with tid: %d\n", __TASKNAME__, self_tid());
|
printf("\n%s: Started with tid: %d\n", __TASKNAME__, self_tid());
|
||||||
|
|
||||||
@@ -107,12 +108,11 @@ void main(void)
|
|||||||
|
|
||||||
wait_pager(PAGER_TID);
|
wait_pager(PAGER_TID);
|
||||||
|
|
||||||
if (l4_time(&ti, 0) < 0) {
|
if (gettimeofday(&tv, 0) < 0) {
|
||||||
printf("Reading the time has failed.\n");
|
printf("Reading the time has failed.\n");
|
||||||
} else {
|
} else {
|
||||||
printf("Current time since system started: %u ticks, "
|
printf("Current time since system started: %u useconds, "
|
||||||
"%u seconds, %u minutes, %u hours, %llu days.\n",
|
"%u seconds.\n", tv.tv_usec, tv.tv_sec);
|
||||||
ti.thz, ti.sec, ti.min, ti.hour, ti.day);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%s: Listening requests.\n", __TASKNAME__);
|
printf("%s: Listening requests.\n", __TASKNAME__);
|
||||||
|
|||||||
@@ -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;
|
extern __l4_kmem_control_t __l4_kmem_control;
|
||||||
int l4_kmem_control(unsigned long pfn, int npages, int grant);
|
int l4_kmem_control(unsigned long pfn, int npages, int grant);
|
||||||
|
|
||||||
/* Represents time since epoch, a c0 specific structure. */
|
typedef int (*__l4_time_t)(void *timeval, int set);
|
||||||
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);
|
|
||||||
extern __l4_time_t __l4_time;
|
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. */
|
/* To be supplied by server tasks. */
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ config_h = join(project_root, "include/l4/config.h")
|
|||||||
env = Environment(CC = 'arm-none-linux-gnueabi-gcc',
|
env = Environment(CC = 'arm-none-linux-gnueabi-gcc',
|
||||||
CCFLAGS = ['-g', '-std=gnu99', '-nostdlib', '-ffreestanding'],
|
CCFLAGS = ['-g', '-std=gnu99', '-nostdlib', '-ffreestanding'],
|
||||||
LINKFLAGS = ['-nostdlib'],
|
LINKFLAGS = ['-nostdlib'],
|
||||||
|
CPPPATH = ['#include'],
|
||||||
ENV = {'PATH' : os.environ['PATH']},
|
ENV = {'PATH' : os.environ['PATH']},
|
||||||
LIBS = 'gcc')
|
LIBS = 'gcc')
|
||||||
|
|
||||||
|
|||||||
17
tasks/libposix/time.c
Normal file
17
tasks/libposix/time.c
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
#include <l4lib/arch/syscalls.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user