* Load new value into hardware timer. */
| 376 | * Load new value into hardware timer. |
| 377 | */ |
| 378 | static void |
| 379 | loadtimer(sbintime_t now, int start) |
| 380 | { |
| 381 | struct pcpu_state *state; |
| 382 | sbintime_t new; |
| 383 | sbintime_t *next; |
| 384 | uint64_t tmp; |
| 385 | int eq; |
| 386 | |
| 387 | if (timer->et_flags & ET_FLAGS_PERCPU) { |
| 388 | state = DPCPU_PTR(timerstate); |
| 389 | next = &state->nexttick; |
| 390 | } else |
| 391 | next = &nexttick; |
| 392 | if (periodic) { |
| 393 | if (start) { |
| 394 | /* |
| 395 | * Try to start all periodic timers aligned |
| 396 | * to period to make events synchronous. |
| 397 | */ |
| 398 | tmp = now % timerperiod; |
| 399 | new = timerperiod - tmp; |
| 400 | if (new < tmp) /* Left less then passed. */ |
| 401 | new += timerperiod; |
| 402 | CTR5(KTR_SPARE2, "load p at %d: now %d.%08x first in %d.%08x", |
| 403 | curcpu, (int)(now >> 32), (u_int)(now & 0xffffffff), |
| 404 | (int)(new >> 32), (u_int)(new & 0xffffffff)); |
| 405 | *next = new + now; |
| 406 | et_start(timer, new, timerperiod); |
| 407 | } |
| 408 | } else { |
| 409 | new = getnextevent(); |
| 410 | eq = (new == *next); |
| 411 | CTR4(KTR_SPARE2, "load at %d: next %d.%08x eq %d", |
| 412 | curcpu, (int)(new >> 32), (u_int)(new & 0xffffffff), eq); |
| 413 | if (!eq) { |
| 414 | *next = new; |
| 415 | et_start(timer, new - now, 0); |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | /* |
| 421 | * Prepare event timer parameters after configuration changes. |
no test coverage detected