| 491 | } |
| 492 | |
| 493 | static int |
| 494 | timer_sanity_check(void) |
| 495 | { |
| 496 | #ifdef RTE_LIBEAL_USE_HPET |
| 497 | if (eal_timer_source != EAL_TIMER_HPET) { |
| 498 | printf("Not using HPET, can't sanity check timer sources\n"); |
| 499 | return 0; |
| 500 | } |
| 501 | |
| 502 | const uint64_t t_hz = rte_get_tsc_hz(); |
| 503 | const uint64_t h_hz = rte_get_hpet_hz(); |
| 504 | printf("Hertz values: TSC = %"PRIu64", HPET = %"PRIu64"\n", t_hz, h_hz); |
| 505 | |
| 506 | const uint64_t tsc_start = rte_get_tsc_cycles(); |
| 507 | const uint64_t hpet_start = rte_get_hpet_cycles(); |
| 508 | rte_delay_ms(100); /* delay 1/10 second */ |
| 509 | const uint64_t tsc_end = rte_get_tsc_cycles(); |
| 510 | const uint64_t hpet_end = rte_get_hpet_cycles(); |
| 511 | printf("Measured cycles: TSC = %"PRIu64", HPET = %"PRIu64"\n", |
| 512 | tsc_end-tsc_start, hpet_end-hpet_start); |
| 513 | |
| 514 | const double tsc_time = (double)(tsc_end - tsc_start)/t_hz; |
| 515 | const double hpet_time = (double)(hpet_end - hpet_start)/h_hz; |
| 516 | /* get the percentage that the times differ by */ |
| 517 | const double time_diff = fabs(tsc_time - hpet_time)*100/tsc_time; |
| 518 | printf("Measured time: TSC = %.4f, HPET = %.4f\n", tsc_time, hpet_time); |
| 519 | |
| 520 | printf("Elapsed time measured by TSC and HPET differ by %f%%\n", |
| 521 | time_diff); |
| 522 | if (time_diff > 0.1) { |
| 523 | printf("Error times differ by >0.1%%"); |
| 524 | return -1; |
| 525 | } |
| 526 | #endif |
| 527 | return 0; |
| 528 | } |
| 529 | |
| 530 | static int |
| 531 | test_timer(void) |
no test coverage detected