cpu-timers.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * CPU timers state API
  3. *
  4. * Copyright 2020 SUSE LLC
  5. *
  6. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  7. * See the COPYING file in the top-level directory.
  8. *
  9. */
  10. #ifndef SYSTEM_CPU_TIMERS_H
  11. #define SYSTEM_CPU_TIMERS_H
  12. #include "qemu/timer.h"
  13. /* init the whole cpu timers API, including icount, ticks, and cpu_throttle */
  14. void cpu_timers_init(void);
  15. /* icount - Instruction Counter API */
  16. /**
  17. * ICountMode: icount enablement state:
  18. *
  19. * @ICOUNT_DISABLED: Disabled - Do not count executed instructions.
  20. * @ICOUNT_PRECISE: Enabled - Fixed conversion of insn to ns via "shift" option
  21. * @ICOUNT_ADAPTATIVE: Enabled - Runtime adaptive algorithm to compute shift
  22. */
  23. typedef enum {
  24. ICOUNT_DISABLED = 0,
  25. ICOUNT_PRECISE,
  26. ICOUNT_ADAPTATIVE,
  27. } ICountMode;
  28. #if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
  29. extern ICountMode use_icount;
  30. #define icount_enabled() (use_icount)
  31. #else
  32. #define icount_enabled() ICOUNT_DISABLED
  33. #endif
  34. /*
  35. * Update the icount with the executed instructions. Called by
  36. * cpus-tcg vCPU thread so the main-loop can see time has moved forward.
  37. */
  38. void icount_update(CPUState *cpu);
  39. /* get raw icount value */
  40. int64_t icount_get_raw(void);
  41. /* return the virtual CPU time in ns, based on the instruction counter. */
  42. int64_t icount_get(void);
  43. /*
  44. * convert an instruction counter value to ns, based on the icount shift.
  45. * This shift is set as a fixed value with the icount "shift" option
  46. * (precise mode), or it is constantly approximated and corrected at
  47. * runtime in adaptive mode.
  48. */
  49. int64_t icount_to_ns(int64_t icount);
  50. /**
  51. * icount_configure: configure the icount options, including "shift"
  52. * @opts: Options to parse
  53. * @errp: pointer to a NULL-initialized error object
  54. *
  55. * Return: true on success, else false setting @errp with error
  56. */
  57. bool icount_configure(QemuOpts *opts, Error **errp);
  58. /* used by tcg vcpu thread to calc icount budget */
  59. int64_t icount_round(int64_t count);
  60. /* if the CPUs are idle, start accounting real time to virtual clock. */
  61. void icount_start_warp_timer(void);
  62. void icount_account_warp_timer(void);
  63. void icount_notify_exit(void);
  64. /*
  65. * CPU Ticks and Clock
  66. */
  67. /* Caller must hold BQL */
  68. void cpu_enable_ticks(void);
  69. /* Caller must hold BQL */
  70. void cpu_disable_ticks(void);
  71. /*
  72. * return the time elapsed in VM between vm_start and vm_stop.
  73. * cpu_get_ticks() uses units of the host CPU cycle counter.
  74. */
  75. int64_t cpu_get_ticks(void);
  76. /*
  77. * Returns the monotonic time elapsed in VM, i.e.,
  78. * the time between vm_start and vm_stop
  79. */
  80. int64_t cpu_get_clock(void);
  81. void qemu_timer_notify_cb(void *opaque, QEMUClockType type);
  82. /* get/set VIRTUAL clock and VM elapsed ticks via the cpus accel interface */
  83. int64_t cpus_get_virtual_clock(void);
  84. void cpus_set_virtual_clock(int64_t new_time);
  85. int64_t cpus_get_elapsed_ticks(void);
  86. #endif /* SYSTEM_CPU_TIMERS_H */