cpu_usage.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * SPDX-License-Identifier: Apache-2.0
  3. *
  4. * Change Logs:
  5. * Date Author Notes
  6. * 2020-12-04 tyx first implementation
  7. */
  8. #ifndef __CPU_USAGE_H__
  9. #define __CPU_USAGE_H__
  10. #include "rtthread.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #define CPU_USAGE_STATE_DEACTIVATED (0x0)
  15. #define CPU_USAGE_STATE_ACTIVATED (0x1)
  16. #define CPU_USAGE_STATE_SUSPEND (0x2)
  17. struct cpu_usage
  18. {
  19. struct rt_timer time; /* Period timer */
  20. rt_uint8_t state; /* Running state */
  21. rt_uint8_t cpus; /* Number of CPUs */
  22. rt_uint16_t reserved;
  23. rt_tick_t suspend_tick; /* CPU suspend timestamp */
  24. rt_tick_t period; /* Stat Period */
  25. struct _idle_stat
  26. {
  27. rt_tick_t idle_tick;
  28. rt_tick_t last_tick;
  29. rt_tick_t load;
  30. rt_thread_t tid;
  31. }
  32. idle_stat[1];
  33. };
  34. typedef struct cpu_usage cpu_usage_t;
  35. int cpu_usage_init(void);
  36. void cpu_usage_deinit(void);
  37. cpu_usage_t *cpu_usage_obj(void);
  38. void cpu_usage_suspend(void);
  39. void cpu_usage_resume(void);
  40. float cpu_load_average(void);
  41. #ifdef __cplusplus
  42. }
  43. #endif
  44. #endif