Microoptimize time math. As soon as our event periods are always below ome
second we may not add intereger parts by using bintime_addx() instead of bintime_add(). Profiling shows handleevents() time redction by 15%.
This commit is contained in:
parent
369763e31a
commit
c0722d20d3
@ -205,19 +205,21 @@ handleevents(struct bintime *now, int fake)
|
|||||||
|
|
||||||
runs = 0;
|
runs = 0;
|
||||||
while (bintime_cmp(now, &state->nexthard, >=)) {
|
while (bintime_cmp(now, &state->nexthard, >=)) {
|
||||||
bintime_add(&state->nexthard, &hardperiod);
|
bintime_addx(&state->nexthard, hardperiod.frac);
|
||||||
runs++;
|
runs++;
|
||||||
}
|
}
|
||||||
if ((timer->et_flags & ET_FLAGS_PERCPU) == 0 &&
|
if (runs) {
|
||||||
bintime_cmp(&state->nexthard, &nexthard, >))
|
if ((timer->et_flags & ET_FLAGS_PERCPU) == 0 &&
|
||||||
nexthard = state->nexthard;
|
bintime_cmp(&state->nexthard, &nexthard, >))
|
||||||
if (runs && fake < 2) {
|
nexthard = state->nexthard;
|
||||||
hardclock_cnt(runs, usermode);
|
if (fake < 2) {
|
||||||
done = 1;
|
hardclock_cnt(runs, usermode);
|
||||||
|
done = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
runs = 0;
|
runs = 0;
|
||||||
while (bintime_cmp(now, &state->nextstat, >=)) {
|
while (bintime_cmp(now, &state->nextstat, >=)) {
|
||||||
bintime_add(&state->nextstat, &statperiod);
|
bintime_addx(&state->nextstat, statperiod.frac);
|
||||||
runs++;
|
runs++;
|
||||||
}
|
}
|
||||||
if (runs && fake < 2) {
|
if (runs && fake < 2) {
|
||||||
@ -227,7 +229,7 @@ handleevents(struct bintime *now, int fake)
|
|||||||
if (profiling) {
|
if (profiling) {
|
||||||
runs = 0;
|
runs = 0;
|
||||||
while (bintime_cmp(now, &state->nextprof, >=)) {
|
while (bintime_cmp(now, &state->nextprof, >=)) {
|
||||||
bintime_add(&state->nextprof, &profperiod);
|
bintime_addx(&state->nextprof, profperiod.frac);
|
||||||
runs++;
|
runs++;
|
||||||
}
|
}
|
||||||
if (runs && !fake) {
|
if (runs && !fake) {
|
||||||
@ -356,7 +358,7 @@ timercb(struct eventtimer *et, void *arg)
|
|||||||
next = &nexttick;
|
next = &nexttick;
|
||||||
if (periodic) {
|
if (periodic) {
|
||||||
now = *next; /* Ex-next tick time becomes present time. */
|
now = *next; /* Ex-next tick time becomes present time. */
|
||||||
bintime_add(next, &timerperiod); /* Next tick in 1 period. */
|
bintime_addx(next, timerperiod.frac); /* Next tick in 1 period. */
|
||||||
} else {
|
} else {
|
||||||
binuptime(&now); /* Get present time from hardware. */
|
binuptime(&now); /* Get present time from hardware. */
|
||||||
next->sec = -1; /* Next tick is not scheduled yet. */
|
next->sec = -1; /* Next tick is not scheduled yet. */
|
||||||
@ -433,7 +435,7 @@ loadtimer(struct bintime *now, int start)
|
|||||||
new.sec = 0;
|
new.sec = 0;
|
||||||
new.frac = timerperiod.frac - tmp;
|
new.frac = timerperiod.frac - tmp;
|
||||||
if (new.frac < tmp) /* Left less then passed. */
|
if (new.frac < tmp) /* Left less then passed. */
|
||||||
bintime_add(&new, &timerperiod);
|
bintime_addx(&new, timerperiod.frac);
|
||||||
CTR5(KTR_SPARE2, "load p at %d: now %d.%08x first in %d.%08x",
|
CTR5(KTR_SPARE2, "load p at %d: now %d.%08x first in %d.%08x",
|
||||||
curcpu, now->sec, (unsigned int)(now->frac >> 32),
|
curcpu, now->sec, (unsigned int)(now->frac >> 32),
|
||||||
new.sec, (unsigned int)(new.frac >> 32));
|
new.sec, (unsigned int)(new.frac >> 32));
|
||||||
@ -531,7 +533,7 @@ configtimer(int start)
|
|||||||
if (start) {
|
if (start) {
|
||||||
/* Initialize time machine parameters. */
|
/* Initialize time machine parameters. */
|
||||||
next = now;
|
next = now;
|
||||||
bintime_add(&next, &timerperiod);
|
bintime_addx(&next, timerperiod.frac);
|
||||||
if (periodic)
|
if (periodic)
|
||||||
nexttick = next;
|
nexttick = next;
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user