On 07/02/2015 12:43 PM, Paolo Bonzini wrote:
On 02/07/2015 18:36, Jason J. Herne wrote:
+static void cpu_throttle_thread(void *opaque)
+{
+ double pct = (double)throttle_percentage/100;
+ double throttle_ratio = pct / (1 - pct);
+ long sleeptime_ms = (long)(throttle_ratio * CPU_THROTTLE_TIMESLICE);
+
+ if (!throttle_percentage) {
+ return;
+ }
+
+ qemu_mutex_unlock_iothread();
+ g_usleep(sleeptime_ms * 1000); /* Convert ms to us for usleep call */
+ qemu_mutex_lock_iothread();
+}
+
+static void cpu_throttle_timer_tick(void *opaque)
+{
+ CPUState *cpu;
+
+ /* Stop the timer if needed */
+ if (!throttle_percentage) {
+ return;
+ }
+ CPU_FOREACH(cpu) {
+ async_run_on_cpu(cpu, cpu_throttle_thread, NULL);
+ }
+
+ timer_mod(throttle_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL_RT) +
+ CPU_THROTTLE_TIMESLICE);
+}
This could cause callbacks to pile up I think. David, do you have any
idea how to fix it?
Paolo
I'm not sure how callbacks can pile up here. If the vcpus are running
then their thread's will execute the callbacks. If they are not running
then the use of QEMU_CLOCK_VIRTUAL_RT will prevent the callbacks from
stacking because the timer is not running, right?
--
-- Jason J. Herne (jjhe...@linux.vnet.ibm.com)