| 408 | } |
| 409 | |
| 410 | struct timers *timers_check(const struct timers *timers, const char *abortstr) |
| 411 | { |
| 412 | unsigned int l, i, off; |
| 413 | uint64_t base; |
| 414 | |
| 415 | l = 0; |
| 416 | if (!timers->level[0]) |
| 417 | goto past_levels; |
| 418 | |
| 419 | /* First level is simple. */ |
| 420 | off = timers->base % PER_LEVEL; |
| 421 | for (i = 0; i < PER_LEVEL; i++) { |
| 422 | struct list_head *h; |
| 423 | |
| 424 | h = &timers->level[l]->list[(i+off) % PER_LEVEL]; |
| 425 | if (!timer_list_check(h, timers->base + i, timers->base + i, |
| 426 | timers->firsts[l], abortstr)) |
| 427 | return NULL; |
| 428 | } |
| 429 | |
| 430 | /* For other levels, "current" bucket has been emptied, and may contain |
| 431 | * entries for the current + level_size bucket. */ |
| 432 | for (l = 1; l < ARRAY_SIZE(timers->level) && timers->level[l]; l++) { |
| 433 | uint64_t per_bucket = 1ULL << (TIMER_LEVEL_BITS * l); |
| 434 | |
| 435 | off = ((timers->base >> (l*TIMER_LEVEL_BITS)) % PER_LEVEL); |
| 436 | /* We start at *next* bucket. */ |
| 437 | base = (timers->base & ~(per_bucket - 1)) + per_bucket; |
| 438 | |
| 439 | for (i = 1; i <= PER_LEVEL; i++) { |
| 440 | struct list_head *h; |
| 441 | |
| 442 | h = &timers->level[l]->list[(i+off) % PER_LEVEL]; |
| 443 | if (!timer_list_check(h, base, base + per_bucket - 1, |
| 444 | timers->firsts[l], abortstr)) |
| 445 | return NULL; |
| 446 | base += per_bucket; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | past_levels: |
| 451 | base = (timers->base & ~((1ULL << (TIMER_LEVEL_BITS * l)) - 1)) |
| 452 | + (1ULL << (TIMER_LEVEL_BITS * l)) - 1; |
| 453 | if (!timer_list_check(&timers->far, base, -1ULL, |
| 454 | timers->firsts[ARRAY_SIZE(timers->level)], |
| 455 | abortstr)) |
| 456 | return NULL; |
| 457 | |
| 458 | return (struct timers *)timers; |
| 459 | } |
| 460 | |
| 461 | #ifdef CCAN_TIMER_DEBUG |
| 462 | static void dump_bucket_stats(FILE *fp, const struct list_head *h) |