zephyr_time.c 863 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include "platform_api_vmcore.h"
  6. uint64
  7. os_time_get_boot_us()
  8. {
  9. return k_uptime_get() * 1000;
  10. }
  11. uint64
  12. os_time_thread_cputime_us(void)
  13. {
  14. /* On certain boards, enabling userspace could impact the collection of
  15. * thread runtime statistics */
  16. #ifdef CONFIG_THREAD_RUNTIME_STATS
  17. k_tid_t tid;
  18. struct k_thread_runtime_stats stats;
  19. uint32 clock_freq;
  20. uint64 cpu_cycles, time_in_us = 0;
  21. tid = k_current_get();
  22. if (k_thread_runtime_stats_get(tid, &stats) == 0) {
  23. cpu_cycles = stats.execution_cycles;
  24. clock_freq = CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC;
  25. time_in_us = (cpu_cycles * 1000000) / clock_freq;
  26. }
  27. return time_in_us;
  28. #else
  29. return os_time_get_boot_us();
  30. #endif
  31. }