mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 07:43:54 -06:00
cpu: Provide vcpu throttling interface
Provide a method to throttle guest cpu execution. CPUState is augmented with timeout controls and throttle start/stop functions. To throttle the guest cpu the caller simply has to call the throttle set function and provide a percentage of throttle time. Signed-off-by: Jason J. Herne <jjherne@linux.vnet.ibm.com> Reviewed-by: Matthew Rosato <mjrosato@linux.vnet.ibm.com> Signed-off-by: Juan Quintela <quintela@redhat.com> Reviewed-by: Juan Quintela <quintela@redhat.com>
This commit is contained in:
parent
2a6e6e59df
commit
2adcc85d40
2 changed files with 120 additions and 0 deletions
|
@ -321,6 +321,11 @@ struct CPUState {
|
|||
uint32_t can_do_io;
|
||||
int32_t exception_index; /* used by m68k TCG */
|
||||
|
||||
/* Used to keep track of an outstanding cpu throttle thread for migration
|
||||
* autoconverge
|
||||
*/
|
||||
bool throttle_thread_scheduled;
|
||||
|
||||
/* Note that this is accessed at the start of every TB via a negative
|
||||
offset from AREG0. Leave this field at the end so as to make the
|
||||
(absolute value) offset as small as possible. This reduces code
|
||||
|
@ -565,6 +570,43 @@ CPUState *qemu_get_cpu(int index);
|
|||
*/
|
||||
bool cpu_exists(int64_t id);
|
||||
|
||||
/**
|
||||
* cpu_throttle_set:
|
||||
* @new_throttle_pct: Percent of sleep time. Valid range is 1 to 99.
|
||||
*
|
||||
* Throttles all vcpus by forcing them to sleep for the given percentage of
|
||||
* time. A throttle_percentage of 25 corresponds to a 75% duty cycle roughly.
|
||||
* (example: 10ms sleep for every 30ms awake).
|
||||
*
|
||||
* cpu_throttle_set can be called as needed to adjust new_throttle_pct.
|
||||
* Once the throttling starts, it will remain in effect until cpu_throttle_stop
|
||||
* is called.
|
||||
*/
|
||||
void cpu_throttle_set(int new_throttle_pct);
|
||||
|
||||
/**
|
||||
* cpu_throttle_stop:
|
||||
*
|
||||
* Stops the vcpu throttling started by cpu_throttle_set.
|
||||
*/
|
||||
void cpu_throttle_stop(void);
|
||||
|
||||
/**
|
||||
* cpu_throttle_active:
|
||||
*
|
||||
* Returns: %true if the vcpus are currently being throttled, %false otherwise.
|
||||
*/
|
||||
bool cpu_throttle_active(void);
|
||||
|
||||
/**
|
||||
* cpu_throttle_get_percentage:
|
||||
*
|
||||
* Returns the vcpu throttle percentage. See cpu_throttle_set for details.
|
||||
*
|
||||
* Returns: The throttle percentage in range 1 to 99.
|
||||
*/
|
||||
int cpu_throttle_get_percentage(void);
|
||||
|
||||
#ifndef CONFIG_USER_ONLY
|
||||
|
||||
typedef void (*CPUInterruptHandler)(CPUState *, int);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue