xref: /openbmc/qemu/include/sysemu/cpu-throttle.h (revision f7160f32)
1 /*
2  * Copyright (c) 2012 SUSE LINUX Products GmbH
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, see
16  * <http://www.gnu.org/licenses/gpl-2.0.html>
17  */
18 
19 #ifndef SYSEMU_CPU_THROTTLE_H
20 #define SYSEMU_CPU_THROTTLE_H
21 
22 #include "qemu/timer.h"
23 
24 /**
25  * cpu_throttle_init:
26  *
27  * Initialize the CPU throttling API.
28  */
29 void cpu_throttle_init(void);
30 
31 /**
32  * cpu_throttle_set:
33  * @new_throttle_pct: Percent of sleep time. Valid range is 1 to 99.
34  *
35  * Throttles all vcpus by forcing them to sleep for the given percentage of
36  * time. A throttle_percentage of 25 corresponds to a 75% duty cycle roughly.
37  * (example: 10ms sleep for every 30ms awake).
38  *
39  * cpu_throttle_set can be called as needed to adjust new_throttle_pct.
40  * Once the throttling starts, it will remain in effect until cpu_throttle_stop
41  * is called.
42  */
43 void cpu_throttle_set(int new_throttle_pct);
44 
45 /**
46  * cpu_throttle_stop:
47  *
48  * Stops the vcpu throttling started by cpu_throttle_set.
49  */
50 void cpu_throttle_stop(void);
51 
52 /**
53  * cpu_throttle_active:
54  *
55  * Returns: %true if the vcpus are currently being throttled, %false otherwise.
56  */
57 bool cpu_throttle_active(void);
58 
59 /**
60  * cpu_throttle_get_percentage:
61  *
62  * Returns the vcpu throttle percentage. See cpu_throttle_set for details.
63  *
64  * Returns: The throttle percentage in range 1 to 99.
65  */
66 int cpu_throttle_get_percentage(void);
67 
68 #endif /* SYSEMU_CPU_THROTTLE_H */
69