Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 130 → Rev 131

/shark/trunk/oslib/kl/time.c
32,6 → 32,7
#include <ll/i386/stdlib.h>
#include <ll/i386/error.h>
#include <ll/i386/mem.h>
#include <ll/i386/advtimer.h>
#include <ll/sys/ll/ll-data.h>
#include <ll/sys/ll/ll-func.h>
#include <ll/sys/ll/time.h>
142,11 → 143,11
#if 1
if (activeEvent) {
if (tsres != NULL) {
read_timespec(tsres);
ll_read_timespec(tsres);
} else {
struct timespec tmp;
 
read_timespec(&tmp);
ll_read_timespec(&tmp);
return TIMESPEC2USEC(&tmp);
}
return TIMESPEC2USEC(tsres);
159,11 → 160,11
}
if(tsres != NULL) {
read_timespec(tsres);
ll_read_timespec(tsres);
} else {
struct timespec tmp;
 
read_timespec(&tmp);
ll_read_timespec(&tmp);
return TIMESPEC2USEC(&tmp);
}
return TIMESPEC2USEC(tsres);
171,12 → 172,12
 
if (mode == TIME_NEW) {
if (tsres != NULL) {
read_timespec(tsres);
ll_read_timespec(tsres);
return TIMESPEC2USEC(tsres);
} else {
struct timespec tmp;
 
read_timespec(&tmp);
ll_read_timespec(&tmp);
return TIMESPEC2USEC(&tmp);
}
}
184,11 → 185,11
if (mode == TIME_EXACT) {
if (timermode == LL_PERIODIC) {
if (tsres != NULL) {
read_timespec(tsres);
ll_read_timespec(tsres);
} else {
struct timespec tmp;
 
read_timespec(&tmp);
ll_read_timespec(&tmp);
return TIMESPEC2USEC(&tmp);
}
return TIMESPEC2USEC(tsres);
/shark/trunk/oslib/kl/event.c
34,6 → 34,8
#include <ll/i386/hw-arch.h>
#include <ll/i386/pic.h>
#include <ll/i386/pit.h>
#include <ll/i386/advtimer.h>
 
#include <ll/sys/ll/ll-data.h>
#include <ll/sys/ll/ll-instr.h>
#include <ll/sys/ll/time.h>
175,7 → 177,7
if (!use_tsc) {
ADDNANO2TIMESPEC(nts, &actTime);
} else {
read_timespec(&actTime);
ll_read_timespec(&actTime);
}
for (p = firstevent; p != NULL; p = pp) {
/shark/trunk/oslib/kl/event1.c
31,6 → 31,8
#include <ll/i386/stdlib.h>
#include <ll/i386/mem.h>
#include <ll/i386/pit.h>
#include <ll/i386/advtimer.h>
 
#include <ll/sys/ll/ll-data.h>
#include <ll/sys/ll/time.h>
#include <ll/sys/ll/event.h>
131,7 → 133,7
 
} else {
 
read_timespec(&now);
ll_read_timespec(&now);
 
}
 
172,7 → 174,7
 
} else {
 
read_timespec(&now);
ll_read_timespec(&now);
 
}
 
/shark/trunk/oslib/kl/init.c
29,6 → 29,7
#include <ll/i386/error.h>
#include <ll/i386/pit.h>
#include <ll/i386/pic.h>
#include <ll/i386/advtimer.h>
 
#include <ll/i386/tss-ctx.h>
#include <ll/i386/hw-arch.h>
183,7 → 184,7
void abort_tail(int code)
{
message("ABORT %d !!!",code);
restore_CMOS();
ll_restore_CMOS();
l1_end();
sti();
l1_exit(1);
191,7 → 192,7
 
void ll_end(void)
{
restore_CMOS();
ll_restore_CMOS();
l1_end();
}
 
/shark/trunk/oslib/kl/advtimer.c
184,7 → 184,7
}
 
//Low level time read function
void read_timespec(struct timespec *tspec)
void ll_read_timespec(struct timespec *tspec)
{
 
signed long long actual_tsc;
197,8 → 197,6
rdtscll(actual_tsc);
 
tspec->tsc = actual_tsc;
dt = actual_tsc - init_tsc;
UNSIGNED_TSC2NSEC(dt,&dn);
223,7 → 221,7
 
if (use_cmos) {
 
message("CMOS adjustment enabled\n");
message("CMOS adjustement enabled\n");
cli();
249,7 → 247,7
 
}
 
void restore_CMOS()
void ll_restore_CMOS()
{
if (use_cmos) {
cli();
/shark/trunk/oslib/ll/i386/advtimer.h
57,5 → 57,41
 
#define RTC_IRQ 8
 
extern signed long long clk_per_msec;
 
extern __inline__ void UNSIGNED_TSC2NSEC(unsigned long long tsc, unsigned long long *n)
{
 
unsigned long nl,nh;
 
nl = *n & 0xFFFFFFFF;
nh = *n >> 32;
__asm__("mull %%ecx\n\t"
"movl %%eax,%%esi\n\t"
"movl %%edx,%%edi\n\t"
"xorl %%edx,%%edx\n\t"
"movl %6,%%eax\n\t"
"mull %%ecx\n\t"
"addl %%edi,%%eax\n\t"
"adcl $0,%%edx\n\t"
"movl %5,%%ecx\n\t"
"divl %%ecx\n\t"
"xchgl %%eax,%%esi\n\t"
"divl %%ecx\n\t"
: "=a" (nl), "=S" (nh)
: "c" (1000000), "a" ((unsigned long)(tsc & 0xFFFFFFFF)), "d" (0),
"m" ((unsigned long)(clk_per_msec)), "m" ((unsigned long)(tsc >> 32)),
"S" (0), "D" (0));
 
*n = nh;
*n <<= 32;
*n |= nl;
 
}
 
void ll_init_advtimer(void);
void ll_restore_CMOS(void);
 
END_DEF
#endif
/shark/trunk/oslib/ll/sys/ll/time.h
19,13 → 19,6
* For legalese, check out the included GPL license.
*/
 
/* Added Advanced Timer Code
*
* Date: 8.4.2003
* Author: Giacomo Guidi <giacomo@gandalf.sssup.it>
*
*/
 
/* Inline functions for managing timespec structures.
All timespec values are pointers!!!
This file defines these functions:
41,7 → 34,7
t = t + n
ADDUSEC2TIMESPEC(m, t)
t = t + m
SUBTIMESPEC(s1, s2, d)
SUBTIMESPEC(s1, s2, d) Works well only if s1 >= s2
d = s1 - s2
ADDTIMESPEC(s1, s2, d)
d = s1 + s2
56,10 → 49,6
TIMESPEC_ASSIGN(t1,t2)
t1 = t2 */
 
/* Advanced Timer Support
* Giacomo Guidi <giacomo@gandalf.sssup.it>
*/
 
#ifndef __LL_SYS_LL_TIME_H__
#define __LL_SYS_LL_TIME_H__
 
66,66 → 55,11
#include <ll/i386/defs.h>
BEGIN_DEF
 
extern signed long long clk_per_msec;
extern signed long long init_tsc;
 
extern unsigned char use_tsc;
 
struct timespec {
long tv_sec; /* Seconds */
long tv_nsec; /* Nanoseconds */
long long tsc; /* 64 bit TSC */
long tv_sec; /* Seconds */
long tv_nsec; /* Nanoseconds */
};
 
extern __inline__ void UNSIGNED_TSC2NSEC(unsigned long long tsc, unsigned long long *n)
{
 
unsigned long nl,nh;
 
nl = *n & 0xFFFFFFFF;
nh = *n >> 32;
__asm__("mull %%ecx\n\t"
"movl %%eax,%%esi\n\t"
"movl %%edx,%%edi\n\t"
"xorl %%edx,%%edx\n\t"
"movl %6,%%eax\n\t"
"mull %%ecx\n\t"
"addl %%edi,%%eax\n\t"
"adcl $0,%%edx\n\t"
"movl %5,%%ecx\n\t"
"divl %%ecx\n\t"
"xchgl %%eax,%%esi\n\t"
"divl %%ecx\n\t"
: "=a" (nl), "=S" (nh)
: "c" (1000000), "a" ((unsigned long)(tsc & 0xFFFFFFFF)), "d" (0),
"m" ((unsigned long)(clk_per_msec)), "m" ((unsigned long)(tsc >> 32)),
"S" (0), "D" (0));
 
*n = nh;
*n <<= 32;
*n |= nl;
 
}
 
extern __inline__ void ADJUST_TIMESPEC(struct timespec *t)
{
signed long long dt,dn;
dt = t->tsc - init_tsc;
if (dt >= 0) UNSIGNED_TSC2NSEC((unsigned long long)(dt),(unsigned long long *)&dn);
else {
UNSIGNED_TSC2NSEC((unsigned long long)(-dt),(unsigned long long *)&dn);
dn -= dn;
}
 
t->tv_sec = dn / 1000000000;
t->tv_nsec = dn % 1000000000;
 
}
 
/*
* these macros come from the Utah Flux oskit...
*/
132,85 → 66,64
 
#define TIMESPEC2NANOSEC(t) ((t)->tv_sec * 1000000000 + (t)->tv_nsec)
#define TIMESPEC2USEC(t) ((t)->tv_sec * 1000000 + (t)->tv_nsec / 1000)
#define NULL_TIMESPEC(t) ((t)->tv_sec = (t)->tv_nsec = 0, (t)->tsc = 0)
#define NULL_TIMESPEC(t) ((t)->tv_sec = (t)->tv_nsec = 0)
#define ADDNANO2TIMESPEC(n, t) ((t)->tv_nsec += (n), \
(t)->tv_sec += (t)->tv_nsec / 1000000000, \
(t)->tv_nsec %= 1000000000)
 
extern __inline__ void ADDNANO2TIMESPEC(const signed long n, struct timespec *t)
{
t->tv_nsec += n;
t->tv_sec += t->tv_nsec / 1000000000;
t->tv_nsec %= 1000000000;
#define SUBTIMESPEC(s1, s2, d) \
((d)->tv_nsec = ((s1)->tv_nsec >= (s2)->tv_nsec) ? \
(((d)->tv_sec = (s1)->tv_sec - (s2)->tv_sec), \
(s1)->tv_nsec - (s2)->tv_nsec) \
: \
(((d)->tv_sec = (s1)->tv_sec - (s2)->tv_sec - 1), \
(1000000000 + (s1)->tv_nsec - (s2)->tv_nsec)))
 
if (use_tsc) t->tsc += clk_per_msec * n / 1000000;
}
extern __inline__ void ADDUSEC2TIMESPEC(const signed long m, struct timespec *t)
{
t->tv_nsec += m * 1000;
t->tv_sec += t->tv_nsec / 1000000000;
t->tv_nsec %= 1000000000;
/*
* ...and these not!
*/
 
if (use_tsc) t->tsc += clk_per_msec * m / 1000;
 
}
 
extern __inline__ void SUBTIMESPEC(const struct timespec *s1,
const struct timespec *s2,
struct timespec *d)
{
if (s1->tv_nsec >= s2->tv_nsec) {
d->tv_sec = s1->tv_sec - s2->tv_sec;
d->tv_nsec = s1->tv_nsec - s2->tv_nsec;
} else {
d->tv_sec = s1->tv_sec - s2->tv_sec - 1;
d->tv_nsec = 1000000000 + s1->tv_nsec - s2->tv_nsec;
}
if (use_tsc) d->tsc = s1->tsc - s2->tsc + init_tsc;
}
 
extern __inline__ void ADDTIMESPEC(const struct timespec *s1,
const struct timespec *s2,
struct timespec *d)
{
d->tv_sec = s1->tv_sec + s2->tv_sec;
d->tv_nsec = s1->tv_nsec + s2->tv_nsec;
d->tv_sec = s1->tv_sec + s2->tv_sec;
d->tv_nsec = s1->tv_nsec + s2->tv_nsec;
 
if (d->tv_nsec < 0) {
d->tv_sec--;
d->tv_nsec += 1000000000;
} else if (d->tv_nsec >= 1000000000) {
d->tv_sec++;
d->tv_nsec -= 1000000000;
}
if (d->tv_nsec < 0) {
d->tv_sec--;
d->tv_nsec += 1000000000;
} else if (d->tv_nsec >= 1000000000) {
d->tv_sec++;
d->tv_nsec -= 1000000000;
}
}
 
if (use_tsc) d->tsc = s1->tsc + s2->tsc - init_tsc;
 
}
#define ADDUSEC2TIMESPEC(m, t) ((t)->tv_nsec += (m%1000000)*1000, \
(t)->tv_sec += ((t)->tv_nsec / 1000000000) + (m/1000000), \
(t)->tv_nsec %= 1000000000)
 
#define TIMESPEC_A_LT_B(a,b) \
( \
((a)->tv_sec < (b)->tv_sec) || \
((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec < (b)->tv_nsec) \
((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec < (b)->tv_nsec) \
)
 
#define TIMESPEC_A_GT_B(a,b) \
( \
((a)->tv_sec > (b)->tv_sec) || \
((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec > (b)->tv_nsec) \
((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec > (b)->tv_nsec) \
)
 
#define TIMESPEC_A_EQ_B(a,b) \
((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec == (b)->tv_nsec)
 
#define TIMESPEC_A_NEQ_B(a,b) \
#define TIMESPEC_A_NEQ_B(a,b) \
((a)->tv_sec != (b)->tv_sec || (a)->tv_nsec != (b)->tv_nsec)
 
#define TIMESPEC_ASSIGN(t1,t2) \
((t1)->tv_sec = (t2)->tv_sec, (t1)->tv_nsec = (t2)->tv_nsec, (t1)->tsc = (t2)->tsc)
((t1)->tv_sec = (t2)->tv_sec, (t1)->tv_nsec = (t2)->tv_nsec)
 
#if 0
#define PITSPEC2TIMESPEC(a,b) \
235,12 → 148,8
#endif
 
TIME ll_gettime(int mode, struct timespec *tsres);
void ll_read_timespec(struct timespec *tspec);
 
//Advanced Timer (advtimer.c)
void read_timespec(struct timespec *tspec);
void ll_init_advtimer(void);
void restore_CMOS(void);
 
#define TIME_PTICK 1
#define TIME_EXACT 2
#define TIME_NEW 3