timing.c 859 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) 2020 Intel Corporation.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <kernel.h>
  7. #include <sys_clock.h>
  8. #include <timing/timing.h>
  9. void arch_timing_init(void)
  10. {
  11. }
  12. void arch_timing_start(void)
  13. {
  14. }
  15. void arch_timing_stop(void)
  16. {
  17. }
  18. timing_t arch_timing_counter_get(void)
  19. {
  20. return k_cycle_get_32();
  21. }
  22. uint64_t arch_timing_cycles_get(volatile timing_t *const start,
  23. volatile timing_t *const end)
  24. {
  25. return (*end - *start);
  26. }
  27. uint64_t arch_timing_freq_get(void)
  28. {
  29. return sys_clock_hw_cycles_per_sec();
  30. }
  31. uint64_t arch_timing_cycles_to_ns(uint64_t cycles)
  32. {
  33. return k_cyc_to_ns_floor64(cycles);
  34. }
  35. uint64_t arch_timing_cycles_to_ns_avg(uint64_t cycles, uint32_t count)
  36. {
  37. return arch_timing_cycles_to_ns(cycles) / count;
  38. }
  39. uint32_t arch_timing_freq_get_mhz(void)
  40. {
  41. return (uint32_t)(arch_timing_freq_get() / 1000000U);
  42. }