Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 142 → Rev 130

/shark/trunk/oslib/kl/advtimer.c
184,7 → 184,7
}
 
//Low level time read function
void ll_read_timespec(struct timespec *tspec)
void read_timespec(struct timespec *tspec)
{
 
signed long long actual_tsc;
197,6 → 197,8
rdtscll(actual_tsc);
 
tspec->tsc = actual_tsc;
dt = actual_tsc - init_tsc;
UNSIGNED_TSC2NSEC(dt,&dn);
221,7 → 223,7
 
if (use_cmos) {
 
message("CMOS adjustement enabled\n");
message("CMOS adjustment enabled\n");
cli();
247,7 → 249,7
 
}
 
void ll_restore_CMOS()
void restore_CMOS()
{
if (use_cmos) {
cli();
/shark/trunk/oslib/kl/time.c
32,7 → 32,6
#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>
143,11 → 142,11
#if 1
if (activeEvent) {
if (tsres != NULL) {
ll_read_timespec(tsres);
read_timespec(tsres);
} else {
struct timespec tmp;
 
ll_read_timespec(&tmp);
read_timespec(&tmp);
return TIMESPEC2USEC(&tmp);
}
return TIMESPEC2USEC(tsres);
160,11 → 159,11
}
if(tsres != NULL) {
ll_read_timespec(tsres);
read_timespec(tsres);
} else {
struct timespec tmp;
 
ll_read_timespec(&tmp);
read_timespec(&tmp);
return TIMESPEC2USEC(&tmp);
}
return TIMESPEC2USEC(tsres);
172,12 → 171,12
 
if (mode == TIME_NEW) {
if (tsres != NULL) {
ll_read_timespec(tsres);
read_timespec(tsres);
return TIMESPEC2USEC(tsres);
} else {
struct timespec tmp;
 
ll_read_timespec(&tmp);
read_timespec(&tmp);
return TIMESPEC2USEC(&tmp);
}
}
185,11 → 184,11
if (mode == TIME_EXACT) {
if (timermode == LL_PERIODIC) {
if (tsres != NULL) {
ll_read_timespec(tsres);
read_timespec(tsres);
} else {
struct timespec tmp;
 
ll_read_timespec(&tmp);
read_timespec(&tmp);
return TIMESPEC2USEC(&tmp);
}
return TIMESPEC2USEC(tsres);
/shark/trunk/oslib/kl/event.c
34,8 → 34,6
#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>
177,7 → 175,7
if (!use_tsc) {
ADDNANO2TIMESPEC(nts, &actTime);
} else {
ll_read_timespec(&actTime);
read_timespec(&actTime);
}
for (p = firstevent; p != NULL; p = pp) {
/shark/trunk/oslib/kl/event1.c
31,8 → 31,6
#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>
133,7 → 131,7
 
} else {
 
ll_read_timespec(&now);
read_timespec(&now);
 
}
 
174,7 → 172,7
 
} else {
 
ll_read_timespec(&now);
read_timespec(&now);
 
}
 
/shark/trunk/oslib/kl/init.c
29,7 → 29,6
#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>
184,7 → 183,7
void abort_tail(int code)
{
message("ABORT %d !!!",code);
ll_restore_CMOS();
restore_CMOS();
l1_end();
sti();
l1_exit(1);
192,7 → 191,7
 
void ll_end(void)
{
ll_restore_CMOS();
restore_CMOS();
l1_end();
}
 
/shark/trunk/oslib/ll/sys/ll/time.h
19,6 → 19,13
* 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:
34,7 → 41,7
t = t + n
ADDUSEC2TIMESPEC(m, t)
t = t + m
SUBTIMESPEC(s1, s2, d) Works well only if s1 >= s2
SUBTIMESPEC(s1, s2, d)
d = s1 - s2
ADDTIMESPEC(s1, s2, d)
d = s1 + s2
49,6 → 56,10
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__
 
55,11 → 66,66
#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 tv_sec; /* Seconds */
long tv_nsec; /* Nanoseconds */
long long tsc; /* 64 bit TSC */
};
 
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...
*/
66,64 → 132,85
 
#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)
#define ADDNANO2TIMESPEC(n, t) ((t)->tv_nsec += (n), \
(t)->tv_sec += (t)->tv_nsec / 1000000000, \
(t)->tv_nsec %= 1000000000)
#define NULL_TIMESPEC(t) ((t)->tv_sec = (t)->tv_nsec = 0, (t)->tsc = 0)
 
#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)))
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;
 
/*
* ...and these not!
*/
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;
 
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)->tv_sec = (t2)->tv_sec, (t1)->tv_nsec = (t2)->tv_nsec, (t1)->tsc = (t2)->tsc)
 
#if 0
#define PITSPEC2TIMESPEC(a,b) \
148,8 → 235,12
#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
/shark/trunk/oslib/ll/i386/advtimer.h
57,41 → 57,5
 
#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