62,233 → 62,217 |
extern void (*evt_epil) (void); |
|
extern unsigned int apic_clk_per_msec; |
extern unsigned char use_tsc, use_apic; |
|
/* Switched to timespec */ |
int oneshot_event_post(struct timespec time, void (*handler) (void *p), |
void *par) |
int oneshot_event_post(struct timespec time, void (*handler) (void *p), void *par) |
{ |
struct event *p; |
struct event *p1, *t; |
struct timespec now, tmp; |
int done; |
DWORD tnext; |
struct event *p; |
struct event *p1, *t; |
struct timespec now, tmp; |
int done; |
DWORD tnext; |
|
TRACER_LOGEVENT(FTrace_EVT_timer_post, 0, 0); |
TRACER_LOGEVENT(FTrace_EVT_timer_post, 0, 0); |
|
if (!freeevents) { |
message("NO FREE EVENTS !\n"); |
ll_abort(20); |
return -1; |
} |
/* Extract from the ``free events'' queue */ |
p = freeevents; |
freeevents = p->next; |
if (!freeevents) { |
message("NO FREE EVENTS !\n"); |
ll_abort(20); |
return -1; |
} |
/* Extract from the ``free events'' queue */ |
p = freeevents; |
freeevents = p->next; |
|
/* Fill the event fields */ |
p->handler = handler; |
TIMESPEC_ASSIGN(&(p->time), &time); |
p->par = par; |
/* Fill the event fields */ |
p->handler = handler; |
TIMESPEC_ASSIGN(&(p->time), &time); |
p->par = par; |
|
/* ...And insert it in the event queue!!! */ |
/* ...And insert it in the event queue!!! */ |
|
t = NULL; |
done = 0; |
/* walk through list, finding spot, adjusting ticks parameter */ |
for (p1 = firstevent; p1; p1 = t->next) { |
if (TIMESPEC_A_GT_B((&time), (&p1->time))) { |
t = p1; |
} else |
break; |
} |
t = NULL; |
done = 0; |
/* walk through list, finding spot, adjusting ticks parameter */ |
for (p1 = firstevent; p1; p1 = t->next) { |
if (TIMESPEC_A_GT_B((&time), (&p1->time))) { |
t = p1; |
} else |
break; |
} |
|
/* adjust next entry */ |
if (t) { |
t->next = p; |
} else { |
firstevent = p; |
if (!activeEvent) { |
#ifndef __TSC__ |
ll_gettime(TIME_NEW, &now); |
#else |
ll_read_timespec(&now); |
#endif |
if (TIMESPEC_A_GT_B(&now, &(firstevent->time))) { |
NULL_TIMESPEC(&tmp); |
} else { |
SUBTIMESPEC(&(firstevent->time), &now, &tmp); |
} |
tnext = TIMESPEC2USEC(&tmp); |
#ifndef __APIC__ |
mul32div32to32(tnext,1193182,1000000,tnext); |
pit_setconstant(0, tnext); |
#else |
mul32div32to32(tnext,apic_clk_per_msec,1000,tnext); |
set_APIC_timer(tnext); |
#endif |
/* adjust next entry */ |
if (t) { |
t->next = p; |
} else { |
firstevent = p; |
if (!activeEvent) { |
if (!use_tsc) { |
ll_gettime(TIME_NEW, &now); |
} else { |
ll_read_timespec(&now); |
} |
if (TIMESPEC_A_GT_B(&now, &(firstevent->time))) { |
NULL_TIMESPEC(&tmp); |
} else { |
SUBTIMESPEC(&(firstevent->time), &now, &tmp); |
} |
tnext = TIMESPEC2USEC(&tmp); |
if (!use_apic) { |
mul32div32to32(tnext,1193182,1000000,tnext); |
pit_setconstant(0, tnext); |
} else { |
mul32div32to32(tnext,apic_clk_per_msec,1000,tnext); |
set_APIC_timer(tnext); |
} |
} |
} |
} |
p->next = p1; |
p->next = p1; |
|
return p->index; |
return p->index; |
} |
|
|
|
void oneshot_wake_up(void) |
{ /* CHANGE the NAME, please... */ |
struct event *p = NULL, *pp; |
struct timespec now, ttmp; |
#ifndef __TSC__ |
WORD tmp; |
#endif |
DWORD tnext; |
{ |
/* CHANGE the NAME, please... */ |
struct event *p = NULL, *pp; |
struct timespec now, ttmp; |
WORD tmp; |
DWORD tnext; |
|
TRACER_LOGEVENT(FTrace_EVT_timer_wakeup_start, 0, 0); |
TRACER_LOGEVENT(FTrace_EVT_timer_wakeup_start, 0, 0); |
|
#ifndef __TSC__ |
|
tmp = pit_read(frc); |
ADDPITSPEC((WORD) (lastTime - tmp), &globalCounter); |
lastTime = tmp; |
if (!use_tsc) { |
tmp = pit_read(frc); |
ADDPITSPEC((WORD) (lastTime - tmp), &globalCounter); |
lastTime = tmp; |
|
PITSPEC2TIMESPEC(&globalCounter, &now); |
PITSPEC2TIMESPEC(&globalCounter, &now); |
} else { |
ll_read_timespec(&now); |
} |
|
#else |
if (firstevent != NULL) { |
activeEvent = 1; |
if (TIMESPEC_A_GT_B(&now, &(firstevent->time))) { |
if (!activeInt && evt_prol != NULL) { |
evt_prol(); |
} |
activeInt++; |
|
ll_read_timespec(&now); |
for (p = firstevent; p != NULL; p = pp) { |
if ((p->time.tv_sec > now.tv_sec) || |
((p->time.tv_sec == now.tv_sec) |
&& (p->time.tv_nsec > now.tv_nsec))) { |
break; |
} |
pp = p->next; |
p->next = freeevents; |
freeevents = p; |
firstevent = pp; |
p->handler(p->par); |
} |
|
if (activeInt == 1 && evt_epil != NULL) { |
evt_epil(); |
} |
activeInt--; |
} |
|
#endif |
if (!use_tsc) { |
tmp = pit_read(frc); |
ADDPITSPEC((WORD) (lastTime - tmp), &globalCounter); |
lastTime = tmp; |
|
PITSPEC2TIMESPEC(&globalCounter, &now); |
} else { |
ll_read_timespec(&now); |
} |
|
if (firstevent != NULL) { |
activeEvent = 1; |
if (TIMESPEC_A_GT_B(&now, &(firstevent->time))) { |
if (!activeInt && evt_prol != NULL) { |
evt_prol(); |
} |
activeInt++; |
|
for (p = firstevent; p != NULL; p = pp) { |
if ((p->time.tv_sec > now.tv_sec) || |
((p->time.tv_sec == now.tv_sec) |
&& (p->time.tv_nsec > now.tv_nsec))) { |
break; |
if (TIMESPEC_A_GT_B(&now, &(firstevent->time))) { |
NULL_TIMESPEC(&ttmp); |
} else { |
SUBTIMESPEC(&(firstevent->time), &now, &ttmp); |
} |
pp = p->next; |
p->next = freeevents; |
freeevents = p; |
firstevent = pp; |
p->handler(p->par); |
} |
|
if (activeInt == 1 && evt_epil != NULL) { |
evt_epil(); |
} |
activeInt--; |
} |
|
#ifndef __TSC__ |
|
tmp = pit_read(frc); |
ADDPITSPEC((WORD) (lastTime - tmp), &globalCounter); |
lastTime = tmp; |
|
PITSPEC2TIMESPEC(&globalCounter, &now); |
|
#else |
|
ll_read_timespec(&now); |
|
#endif |
|
|
if (TIMESPEC_A_GT_B(&now, &(firstevent->time))) { |
NULL_TIMESPEC(&ttmp); |
/* SUBTIMESPEC(&(firstevent->time), &now, &ttmp); */ |
tnext = TIMESPEC2USEC(&ttmp); |
if (!use_apic) { |
mul32div32to32(tnext,1193182,1000000,tnext); |
pit_setconstant(0, tnext); |
} else { |
mul32div32to32(tnext,apic_clk_per_msec,1000,tnext); |
set_APIC_timer(tnext); |
} |
activeEvent = 0; |
} else { |
SUBTIMESPEC(&(firstevent->time), &now, &ttmp); |
if (!use_apic) |
pit_setconstant(0, 0xFFFF); |
else |
set_APIC_timer(0xFFFFFFFF); |
} |
/* SUBTIMESPEC(&(firstevent->time), &now, &ttmp); */ |
tnext = TIMESPEC2USEC(&ttmp); |
#ifndef __APIC__ |
mul32div32to32(tnext,1193182,1000000,tnext); |
pit_setconstant(0, tnext); |
#else |
mul32div32to32(tnext,apic_clk_per_msec,1000,tnext); |
set_APIC_timer(tnext); |
#endif |
activeEvent = 0; |
} else { |
#ifndef __APIC__ |
pit_setconstant(0, 0xFFFF); |
#else |
set_APIC_timer(0xFFFFFFFF); |
#endif |
} |
|
TRACER_LOGEVENT(FTrace_EVT_timer_wakeup_end, (unsigned short int)currCtx, 0); |
|
TRACER_LOGEVENT(FTrace_EVT_timer_wakeup_end, (unsigned short int)currCtx, 0); |
} |
|
int oneshot_event_delete(int index) |
{ |
struct event *p1, *t; |
struct timespec tmp, now; |
DWORD tnext; |
int firstdeleted = FALSE; |
struct event *p1, *t; |
struct timespec tmp, now; |
DWORD tnext; |
int firstdeleted = FALSE; |
|
TRACER_LOGEVENT(FTrace_EVT_timer_delete, 0, 0); |
TRACER_LOGEVENT(FTrace_EVT_timer_delete, 0, 0); |
|
if (index == -1) |
return -1; |
t = NULL; |
/* walk through list, finding spot, adjusting ticks parameter */ |
|
for (p1 = firstevent; (p1) && (index != p1->index); p1 = t->next) { |
t = p1; |
} |
|
if (p1 == NULL) { |
return -1; |
} |
if (t == NULL) { |
firstevent = p1->next; |
firstdeleted = TRUE; |
} else { |
t->next = p1->next; |
} |
|
p1->next = freeevents; |
freeevents = p1; |
|
if (!activeEvent) { |
if (firstevent == NULL) { |
#ifndef __APIC__ |
pit_setconstant(0, 0xFFFF); |
#else |
set_APIC_timer(0xFFFFFFFF); |
#endif |
} else { |
if (firstdeleted) { |
#ifndef __TSC__ |
ll_gettime(TIME_NEW, &now); |
#else |
ll_read_timespec(&now); |
#endif |
if (TIMESPEC_A_GT_B(&now, &(firstevent->time))) { |
NULL_TIMESPEC(&tmp); |
} else { |
SUBTIMESPEC(&(firstevent->time), &now, &tmp); |
} |
/*SUBTIMESPEC(&now, &(firstevent->time), &tmp); */ |
tnext = TIMESPEC2USEC(&tmp); |
#ifndef __APIC__ |
mul32div32to32(tnext,1193182,1000000,tnext); |
pit_setconstant(0, tnext); |
#else |
mul32div32to32(tnext,apic_clk_per_msec,1000,tnext); |
set_APIC_timer(tnext); |
#endif |
if (index == -1) |
return -1; |
t = NULL; |
/* walk through list, finding spot, adjusting ticks parameter */ |
|
for (p1 = firstevent; (p1) && (index != p1->index); p1 = t->next) { |
t = p1; |
} |
} |
} |
return 1; |
|
if (p1 == NULL) { |
return -1; |
} |
if (t == NULL) { |
firstevent = p1->next; |
firstdeleted = TRUE; |
} else { |
t->next = p1->next; |
} |
|
p1->next = freeevents; |
freeevents = p1; |
|
if (!activeEvent) { |
if (firstevent == NULL) { |
if (!use_apic) |
pit_setconstant(0, 0xFFFF); |
else |
set_APIC_timer(0xFFFFFFFF); |
} else { |
if (firstdeleted) { |
if (!use_tsc) |
ll_gettime(TIME_NEW, &now); |
else |
ll_read_timespec(&now); |
if (TIMESPEC_A_GT_B(&now, &(firstevent->time))) { |
NULL_TIMESPEC(&tmp); |
} else { |
SUBTIMESPEC(&(firstevent->time), &now, &tmp); |
} |
/*SUBTIMESPEC(&now, &(firstevent->time), &tmp); */ |
tnext = TIMESPEC2USEC(&tmp); |
if (!use_apic) { |
mul32div32to32(tnext,1193182,1000000,tnext); |
pit_setconstant(0, tnext); |
} else { |
mul32div32to32(tnext,apic_clk_per_msec,1000,tnext); |
set_APIC_timer(tnext); |
} |
} |
} |
} |
return 1; |
} |