* [PULL v3 00/47] Misc patches for QEMU 5.1 soft freeze
@ 2020-07-10 23:49 Paolo Bonzini
2020-07-10 23:49 ` [PULL v3 41/47] cpu-throttle: new module, extracted from cpus.c Paolo Bonzini
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Paolo Bonzini @ 2020-07-10 23:49 UTC (permalink / raw)
To: qemu-devel
The following changes since commit 45db94cc90c286a9965a285ba19450f448760a09:
Merge remote-tracking branch 'remotes/mcayland/tags/qemu-openbios-20200707' into staging (2020-07-10 16:43:40 +0100)
are available in the Git repository at:
git://github.com/bonzini/qemu.git tags/for-upstream
for you to fetch changes up to 56908dc5041aa424fd1495b6c6beb78c539d93e1:
linux-headers: update again to 5.8 (2020-07-10 19:26:55 -0400)
----------------------------------------------------------------
* Make checkpatch say 'qemu' instead of 'kernel' (Aleksandar)
* Fix PSE guests with emulated NPT (Alexander B. #1)
* Fix leak (Alexander B. #2)
* HVF fixes (Roman, Cameron)
* New Sapphire Rapids CPUID bits (Cathy)
* cpus.c and softmmu/ cleanups (Claudio)
* TAP driver tweaks (Daniel, Havard)
* object-add bugfix and testcases (Eric A.)
* Fix Coverity MIN_CONST and MAX_CONST (Eric B.)
* "info lapic" improvement (Jan)
* SSE fixes (Joseph)
* "-msg guest-name" option (Mario)
* support for AMD nested live migration (myself)
* Small i386 TCG fixes (myself)
* improved error reporting for Xen (myself)
* fix "-cpu host -overcommit cpu-pm=on" (myself)
* Add accel/Kconfig (Philippe)
* iscsi sense handling fixes (Yongji)
* Misc bugfixes
----------------------------------------------------------------
v2->v3: dropped Philippe's KVM series as it seemed to make some tests flaky
added Linux kernel headers update/fix
fixed Cocoa includes
Aleksandar Markovic (1):
checkpatch: Change occurences of 'kernel' to 'qemu' in user messages
Alexander Boettcher (1):
tcg/svm: use host cr4 during NPT page table walk
Alexander Bulekov (1):
pc: fix leak in pc_system_flash_cleanup_unused
Cameron Esfahani (1):
i386: hvf: Make long mode enter and exit clearer
Cathy Zhang (2):
target/i386: Add SERIALIZE cpu feature
target/i386: Enable TSX Suspend Load Address Tracking feature
Claudio Fontana (2):
softmmu: move softmmu only files from root
cpu-throttle: new module, extracted from cpus.c
Daniel P. Berrangé (1):
scripts: improve message when TAP based tests fail
Eric Auger (3):
qom: Introduce object_property_try_add_child()
tests/qmp-cmd-test: Add qmp/object-add-duplicate-id
tests/qmp-cmd-test: Add qmp/object-add-failure-modes
Eric Blake (1):
coverity: provide Coverity-friendly MIN_CONST and MAX_CONST
Havard Skinnemoen (1):
tests: Inject test name also when the test fails
Jan Kiszka (1):
apic: Report current_count via 'info lapic'
Joseph Myers (2):
target/i386: set SSE FTZ in correct floating-point state
target/i386: fix IEEE SSE floating-point exception raising
Luwei Kang (1):
target/i386: Correct the warning message of Intel PT
Mario Smarduch (1):
util/qemu-error: prepend guest name to error message to identify affected VM owner
Paolo Bonzini (8):
KVM: add support for AMD nested live migration
Makefile: simplify MINIKCONF rules
target/i386: remove gen_io_end
target/i386: implement undocumented "smsw r32" behavior
KVM: x86: believe what KVM says about WAITPKG
target/i386: sev: provide proper error reporting for query-sev-capabilities
target/i386: sev: fail query-sev-capabilities if QEMU cannot use SEV
linux-headers: update again to 5.8
Philippe Mathieu-Daudé (10):
hw/core/null-machine: Do not initialize unused chardev backends
MAINTAINERS: Fix KVM path expansion glob
MAINTAINERS: Add an 'overall' entry for accelerators
MAINTAINERS: Cover the HAX accelerator stub
Makefile: Remove dangerous EOL trailing backslash
Makefile: Write MINIKCONF variables as one entry per line
accel/Kconfig: Extract accel selectors into their own config
accel/Kconfig: Add the TCG selector
accel/tcg: Add stub for probe_access()
cpus: Move CPU code from exec.c to cpus-common.c
Roman Bolshakov (7):
i386: hvf: Set env->eip in macvm_set_rip()
i386: hvf: Move synchronize functions to sysemu
i386: hvf: Add hvf_cpu_synchronize_pre_loadvm()
i386: hvf: Move Guest LMA reset to macvm_set_cr0()
i386: hvf: Don't duplicate register reset
i386: hvf: Clean up synchronize functions
MAINTAINERS: Add Cameron as HVF co-maintainer
Thomas Huth (1):
softmmu/vl: Remove the check for colons in -accel parameters
Xie Yongji (2):
iscsi: handle check condition status in retry loop
iscsi: return -EIO when sense fields are meaningless
Kconfig | 4 +
Kconfig.host | 7 -
MAINTAINERS | 29 +-
Makefile | 12 +-
Makefile.target | 7 +-
accel/Kconfig | 9 +
accel/stubs/tcg-stub.c | 7 +
block/iscsi.c | 22 +-
cpus-common.c | 18 +
exec.c | 22 -
hw/core/null-machine.c | 5 +
hw/i386/pc_sysfw.c | 5 +
hw/intc/apic.c | 18 -
hw/intc/apic_common.c | 19 +
include/hw/core/cpu.h | 37 --
include/hw/i386/apic_internal.h | 1 +
include/qemu/error-report.h | 2 +
include/qemu/main-loop.h | 5 +
include/qemu/osdep.h | 21 +-
include/qom/object.h | 26 +-
include/sysemu/cpu-throttle.h | 68 +++
include/sysemu/hvf.h | 2 +-
include/sysemu/hw_accel.h | 13 +
linux-headers/asm-arm/unistd-common.h | 1 +
linux-headers/asm-x86/kvm.h | 5 +-
migration/migration.c | 1 +
migration/ram.c | 1 +
qemu-options.hx | 12 +-
qom/object.c | 21 +-
qom/object_interfaces.c | 7 +-
scripts/checkpatch.pl | 6 +-
scripts/tap-driver.pl | 2 +-
softmmu/Makefile.objs | 11 +
arch_init.c => softmmu/arch_init.c | 0
balloon.c => softmmu/balloon.c | 0
softmmu/cpu-throttle.c | 122 ++++
cpus.c => softmmu/cpus.c | 107 +---
ioport.c => softmmu/ioport.c | 0
memory.c => softmmu/memory.c | 0
memory_mapping.c => softmmu/memory_mapping.c | 0
qtest.c => softmmu/qtest.c | 0
softmmu/vl.c | 14 +-
target/i386/Makefile.objs | 1 +
target/i386/cpu.c | 13 +-
target/i386/cpu.h | 10 +
target/i386/excp_helper.c | 4 +-
target/i386/fpu_helper.c | 37 +-
target/i386/gdbstub.c | 1 +
target/i386/helper.c | 6 +-
target/i386/helper.h | 1 +
target/i386/hvf/hvf.c | 137 +----
target/i386/hvf/vmx.h | 17 +-
target/i386/kvm.c | 53 +-
target/i386/kvm_i386.h | 1 +
target/i386/machine.c | 31 +-
target/i386/monitor.c | 10 +-
target/i386/ops_sse.h | 28 +-
target/i386/sev-stub.c | 3 +-
target/i386/sev.c | 27 +-
target/i386/sev_i386.h | 2 +-
target/i386/svm.h | 1 +
target/i386/svm_helper.c | 7 +-
target/i386/tcg-stub.c | 25 +
target/i386/translate.c | 36 +-
tests/Makefile.include | 2 +-
tests/qtest/qmp-cmd-test.c | 109 +++-
tests/tcg/i386/Makefile.target | 4 +
tests/tcg/i386/test-i386-sse-exceptions.c | 813 +++++++++++++++++++++++++++
ui/cocoa.m | 1 +
util/qemu-error.c | 7 +
70 files changed, 1615 insertions(+), 441 deletions(-)
create mode 100644 Kconfig
create mode 100644 accel/Kconfig
create mode 100644 include/sysemu/cpu-throttle.h
rename arch_init.c => softmmu/arch_init.c (100%)
rename balloon.c => softmmu/balloon.c (100%)
create mode 100644 softmmu/cpu-throttle.c
rename cpus.c => softmmu/cpus.c (95%)
rename ioport.c => softmmu/ioport.c (100%)
rename memory.c => softmmu/memory.c (100%)
rename memory_mapping.c => softmmu/memory_mapping.c (100%)
rename qtest.c => softmmu/qtest.c (100%)
create mode 100644 target/i386/tcg-stub.c
create mode 100644 tests/tcg/i386/test-i386-sse-exceptions.c
--
2.26.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PULL v3 41/47] cpu-throttle: new module, extracted from cpus.c
2020-07-10 23:49 [PULL v3 00/47] Misc patches for QEMU 5.1 soft freeze Paolo Bonzini
@ 2020-07-10 23:49 ` Paolo Bonzini
2020-07-10 23:49 ` [PULL v3 47/47] linux-headers: update again to 5.8 Paolo Bonzini
2020-07-11 18:27 ` [PULL v3 00/47] Misc patches for QEMU 5.1 soft freeze Peter Maydell
2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2020-07-10 23:49 UTC (permalink / raw)
To: qemu-devel; +Cc: Laurent Vivier, Alex Bennée, Claudio Fontana
From: Claudio Fontana <cfontana@suse.de>
move the vcpu throttling functionality into its own module.
This functionality is not specific to any accelerator,
and it is used currently by migration to slow down guests to try to
have migrations converge, and by the cocoa MacOS UI to throttle speed.
cpu-throttle contains the controls to adjust and inspect throttle
settings, start (set) and stop vcpu throttling, and the throttling
function itself that is run periodically on vcpus to make them take a nap.
Execution of the throttling function on all vcpus is triggered by a timer,
registered at module initialization.
No functionality change.
Signed-off-by: Claudio Fontana <cfontana@suse.de>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Laurent Vivier <lvivier@redhat.com>
Message-Id: <20200629093504.3228-3-cfontana@suse.de>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
MAINTAINERS | 1 +
include/hw/core/cpu.h | 37 -----------
include/qemu/main-loop.h | 5 ++
include/sysemu/cpu-throttle.h | 68 +++++++++++++++++++
migration/migration.c | 1 +
migration/ram.c | 1 +
softmmu/Makefile.objs | 1 +
softmmu/cpu-throttle.c | 122 ++++++++++++++++++++++++++++++++++
softmmu/cpus.c | 95 +++-----------------------
ui/cocoa.m | 1 +
10 files changed, 208 insertions(+), 124 deletions(-)
create mode 100644 include/sysemu/cpu-throttle.h
create mode 100644 softmmu/cpu-throttle.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 28f33123ec..361ae5c662 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2247,6 +2247,7 @@ F: util/qemu-timer.c
F: softmmu/vl.c
F: softmmu/main.c
F: softmmu/cpus.c
+F: softmmu/cpu-throttle.c
F: qapi/run-state.json
Human Monitor (HMP)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index b3f4b79318..5542577d2b 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -822,43 +822,6 @@ bool cpu_exists(int64_t id);
*/
CPUState *cpu_by_arch_id(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);
diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h
index a6d20b0719..8e98613656 100644
--- a/include/qemu/main-loop.h
+++ b/include/qemu/main-loop.h
@@ -303,6 +303,11 @@ void qemu_mutex_unlock_iothread(void);
*/
void qemu_cond_wait_iothread(QemuCond *cond);
+/*
+ * qemu_cond_timedwait_iothread: like the previous, but with timeout
+ */
+void qemu_cond_timedwait_iothread(QemuCond *cond, int ms);
+
/* internal interfaces */
void qemu_fd_register(int fd);
diff --git a/include/sysemu/cpu-throttle.h b/include/sysemu/cpu-throttle.h
new file mode 100644
index 0000000000..d65bdef6d0
--- /dev/null
+++ b/include/sysemu/cpu-throttle.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2012 SUSE LINUX Products GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see
+ * <http://www.gnu.org/licenses/gpl-2.0.html>
+ */
+
+#ifndef SYSEMU_CPU_THROTTLE_H
+#define SYSEMU_CPU_THROTTLE_H
+
+#include "qemu/timer.h"
+
+/**
+ * cpu_throttle_init:
+ *
+ * Initialize the CPU throttling API.
+ */
+void cpu_throttle_init(void);
+
+/**
+ * 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);
+
+#endif /* SYSEMU_CPU_THROTTLE_H */
diff --git a/migration/migration.c b/migration/migration.c
index 92e44e021e..4e658c397e 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -23,6 +23,7 @@
#include "socket.h"
#include "sysemu/runstate.h"
#include "sysemu/sysemu.h"
+#include "sysemu/cpu-throttle.h"
#include "rdma.h"
#include "ram.h"
#include "migration/global_state.h"
diff --git a/migration/ram.c b/migration/ram.c
index 5554a7d2d8..76d4fee5d5 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -52,6 +52,7 @@
#include "migration/colo.h"
#include "block.h"
#include "sysemu/sysemu.h"
+#include "sysemu/cpu-throttle.h"
#include "savevm.h"
#include "qemu/iov.h"
#include "multifd.h"
diff --git a/softmmu/Makefile.objs b/softmmu/Makefile.objs
index a4bd9f2f52..a414a74c50 100644
--- a/softmmu/Makefile.objs
+++ b/softmmu/Makefile.objs
@@ -2,6 +2,7 @@ softmmu-main-y = softmmu/main.o
obj-y += arch_init.o
obj-y += cpus.o
+obj-y += cpu-throttle.o
obj-y += balloon.o
obj-y += ioport.o
obj-y += memory.o
diff --git a/softmmu/cpu-throttle.c b/softmmu/cpu-throttle.c
new file mode 100644
index 0000000000..4e6b2818ca
--- /dev/null
+++ b/softmmu/cpu-throttle.c
@@ -0,0 +1,122 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "qemu/thread.h"
+#include "hw/core/cpu.h"
+#include "qemu/main-loop.h"
+#include "sysemu/cpus.h"
+#include "sysemu/cpu-throttle.h"
+
+/* vcpu throttling controls */
+static QEMUTimer *throttle_timer;
+static unsigned int throttle_percentage;
+
+#define CPU_THROTTLE_PCT_MIN 1
+#define CPU_THROTTLE_PCT_MAX 99
+#define CPU_THROTTLE_TIMESLICE_NS 10000000
+
+static void cpu_throttle_thread(CPUState *cpu, run_on_cpu_data opaque)
+{
+ double pct;
+ double throttle_ratio;
+ int64_t sleeptime_ns, endtime_ns;
+
+ if (!cpu_throttle_get_percentage()) {
+ return;
+ }
+
+ pct = (double)cpu_throttle_get_percentage() / 100;
+ throttle_ratio = pct / (1 - pct);
+ /* Add 1ns to fix double's rounding error (like 0.9999999...) */
+ sleeptime_ns = (int64_t)(throttle_ratio * CPU_THROTTLE_TIMESLICE_NS + 1);
+ endtime_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + sleeptime_ns;
+ while (sleeptime_ns > 0 && !cpu->stop) {
+ if (sleeptime_ns > SCALE_MS) {
+ qemu_cond_timedwait_iothread(cpu->halt_cond,
+ sleeptime_ns / SCALE_MS);
+ } else {
+ qemu_mutex_unlock_iothread();
+ g_usleep(sleeptime_ns / SCALE_US);
+ qemu_mutex_lock_iothread();
+ }
+ sleeptime_ns = endtime_ns - qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
+ }
+ atomic_set(&cpu->throttle_thread_scheduled, 0);
+}
+
+static void cpu_throttle_timer_tick(void *opaque)
+{
+ CPUState *cpu;
+ double pct;
+
+ /* Stop the timer if needed */
+ if (!cpu_throttle_get_percentage()) {
+ return;
+ }
+ CPU_FOREACH(cpu) {
+ if (!atomic_xchg(&cpu->throttle_thread_scheduled, 1)) {
+ async_run_on_cpu(cpu, cpu_throttle_thread,
+ RUN_ON_CPU_NULL);
+ }
+ }
+
+ pct = (double)cpu_throttle_get_percentage() / 100;
+ timer_mod(throttle_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL_RT) +
+ CPU_THROTTLE_TIMESLICE_NS / (1 - pct));
+}
+
+void cpu_throttle_set(int new_throttle_pct)
+{
+ /* Ensure throttle percentage is within valid range */
+ new_throttle_pct = MIN(new_throttle_pct, CPU_THROTTLE_PCT_MAX);
+ new_throttle_pct = MAX(new_throttle_pct, CPU_THROTTLE_PCT_MIN);
+
+ atomic_set(&throttle_percentage, new_throttle_pct);
+
+ timer_mod(throttle_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL_RT) +
+ CPU_THROTTLE_TIMESLICE_NS);
+}
+
+void cpu_throttle_stop(void)
+{
+ atomic_set(&throttle_percentage, 0);
+}
+
+bool cpu_throttle_active(void)
+{
+ return (cpu_throttle_get_percentage() != 0);
+}
+
+int cpu_throttle_get_percentage(void)
+{
+ return atomic_read(&throttle_percentage);
+}
+
+void cpu_throttle_init(void)
+{
+ throttle_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL_RT,
+ cpu_throttle_timer_tick, NULL);
+}
diff --git a/softmmu/cpus.c b/softmmu/cpus.c
index d94456ed29..a802e899ab 100644
--- a/softmmu/cpus.c
+++ b/softmmu/cpus.c
@@ -61,6 +61,8 @@
#include "hw/boards.h"
#include "hw/hw.h"
+#include "sysemu/cpu-throttle.h"
+
#ifdef CONFIG_LINUX
#include <sys/prctl.h>
@@ -84,14 +86,6 @@ static QemuMutex qemu_global_mutex;
int64_t max_delay;
int64_t max_advance;
-/* vcpu throttling controls */
-static QEMUTimer *throttle_timer;
-static unsigned int throttle_percentage;
-
-#define CPU_THROTTLE_PCT_MIN 1
-#define CPU_THROTTLE_PCT_MAX 99
-#define CPU_THROTTLE_TIMESLICE_NS 10000000
-
bool cpu_is_stopped(CPUState *cpu)
{
return cpu->stopped || !runstate_is_running();
@@ -738,90 +732,12 @@ static const VMStateDescription vmstate_timers = {
}
};
-static void cpu_throttle_thread(CPUState *cpu, run_on_cpu_data opaque)
-{
- double pct;
- double throttle_ratio;
- int64_t sleeptime_ns, endtime_ns;
-
- if (!cpu_throttle_get_percentage()) {
- return;
- }
-
- pct = (double)cpu_throttle_get_percentage()/100;
- throttle_ratio = pct / (1 - pct);
- /* Add 1ns to fix double's rounding error (like 0.9999999...) */
- sleeptime_ns = (int64_t)(throttle_ratio * CPU_THROTTLE_TIMESLICE_NS + 1);
- endtime_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + sleeptime_ns;
- while (sleeptime_ns > 0 && !cpu->stop) {
- if (sleeptime_ns > SCALE_MS) {
- qemu_cond_timedwait(cpu->halt_cond, &qemu_global_mutex,
- sleeptime_ns / SCALE_MS);
- } else {
- qemu_mutex_unlock_iothread();
- g_usleep(sleeptime_ns / SCALE_US);
- qemu_mutex_lock_iothread();
- }
- sleeptime_ns = endtime_ns - qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
- }
- atomic_set(&cpu->throttle_thread_scheduled, 0);
-}
-
-static void cpu_throttle_timer_tick(void *opaque)
-{
- CPUState *cpu;
- double pct;
-
- /* Stop the timer if needed */
- if (!cpu_throttle_get_percentage()) {
- return;
- }
- CPU_FOREACH(cpu) {
- if (!atomic_xchg(&cpu->throttle_thread_scheduled, 1)) {
- async_run_on_cpu(cpu, cpu_throttle_thread,
- RUN_ON_CPU_NULL);
- }
- }
-
- pct = (double)cpu_throttle_get_percentage()/100;
- timer_mod(throttle_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL_RT) +
- CPU_THROTTLE_TIMESLICE_NS / (1-pct));
-}
-
-void cpu_throttle_set(int new_throttle_pct)
-{
- /* Ensure throttle percentage is within valid range */
- new_throttle_pct = MIN(new_throttle_pct, CPU_THROTTLE_PCT_MAX);
- new_throttle_pct = MAX(new_throttle_pct, CPU_THROTTLE_PCT_MIN);
-
- atomic_set(&throttle_percentage, new_throttle_pct);
-
- timer_mod(throttle_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL_RT) +
- CPU_THROTTLE_TIMESLICE_NS);
-}
-
-void cpu_throttle_stop(void)
-{
- atomic_set(&throttle_percentage, 0);
-}
-
-bool cpu_throttle_active(void)
-{
- return (cpu_throttle_get_percentage() != 0);
-}
-
-int cpu_throttle_get_percentage(void)
-{
- return atomic_read(&throttle_percentage);
-}
-
void cpu_ticks_init(void)
{
seqlock_init(&timers_state.vm_clock_seqlock);
qemu_spin_init(&timers_state.vm_clock_lock);
vmstate_register(NULL, 0, &vmstate_timers, &timers_state);
- throttle_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL_RT,
- cpu_throttle_timer_tick, NULL);
+ cpu_throttle_init();
}
void configure_icount(QemuOpts *opts, Error **errp)
@@ -1879,6 +1795,11 @@ void qemu_cond_wait_iothread(QemuCond *cond)
qemu_cond_wait(cond, &qemu_global_mutex);
}
+void qemu_cond_timedwait_iothread(QemuCond *cond, int ms)
+{
+ qemu_cond_timedwait(cond, &qemu_global_mutex, ms);
+}
+
static bool all_vcpus_paused(void)
{
CPUState *cpu;
diff --git a/ui/cocoa.m b/ui/cocoa.m
index cb556e4e66..0910b4a716 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -32,6 +32,7 @@
#include "ui/input.h"
#include "sysemu/sysemu.h"
#include "sysemu/runstate.h"
+#include "sysemu/cpu-throttle.h"
#include "qapi/error.h"
#include "qapi/qapi-commands-block.h"
#include "qapi/qapi-commands-misc.h"
--
2.26.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PULL v3 47/47] linux-headers: update again to 5.8
2020-07-10 23:49 [PULL v3 00/47] Misc patches for QEMU 5.1 soft freeze Paolo Bonzini
2020-07-10 23:49 ` [PULL v3 41/47] cpu-throttle: new module, extracted from cpus.c Paolo Bonzini
@ 2020-07-10 23:49 ` Paolo Bonzini
2020-07-11 18:27 ` [PULL v3 00/47] Misc patches for QEMU 5.1 soft freeze Peter Maydell
2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2020-07-10 23:49 UTC (permalink / raw)
To: qemu-devel
5.8-rc1 inadvertently broke userspace ABI compatibility. Merge
again with latest kvm/master to undo that.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
| 1 +
| 5 +++--
2 files changed, 4 insertions(+), 2 deletions(-)
--git a/linux-headers/asm-arm/unistd-common.h b/linux-headers/asm-arm/unistd-common.h
index 23de64e44c..57cd1f21db 100644
--- a/linux-headers/asm-arm/unistd-common.h
+++ b/linux-headers/asm-arm/unistd-common.h
@@ -392,5 +392,6 @@
#define __NR_clone3 (__NR_SYSCALL_BASE + 435)
#define __NR_openat2 (__NR_SYSCALL_BASE + 437)
#define __NR_pidfd_getfd (__NR_SYSCALL_BASE + 438)
+#define __NR_faccessat2 (__NR_SYSCALL_BASE + 439)
#endif /* _ASM_ARM_UNISTD_COMMON_H */
--git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h
index 17c5a038f4..0780f97c18 100644
--- a/linux-headers/asm-x86/kvm.h
+++ b/linux-headers/asm-x86/kvm.h
@@ -408,14 +408,15 @@ struct kvm_vmx_nested_state_data {
};
struct kvm_vmx_nested_state_hdr {
- __u32 flags;
__u64 vmxon_pa;
__u64 vmcs12_pa;
- __u64 preemption_timer_deadline;
struct {
__u16 flags;
} smm;
+
+ __u32 flags;
+ __u64 preemption_timer_deadline;
};
struct kvm_svm_nested_state_data {
--
2.26.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PULL v3 00/47] Misc patches for QEMU 5.1 soft freeze
2020-07-10 23:49 [PULL v3 00/47] Misc patches for QEMU 5.1 soft freeze Paolo Bonzini
2020-07-10 23:49 ` [PULL v3 41/47] cpu-throttle: new module, extracted from cpus.c Paolo Bonzini
2020-07-10 23:49 ` [PULL v3 47/47] linux-headers: update again to 5.8 Paolo Bonzini
@ 2020-07-11 18:27 ` Peter Maydell
2 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2020-07-11 18:27 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: QEMU Developers
On Sat, 11 Jul 2020 at 00:50, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> The following changes since commit 45db94cc90c286a9965a285ba19450f448760a09:
>
> Merge remote-tracking branch 'remotes/mcayland/tags/qemu-openbios-20200707' into staging (2020-07-10 16:43:40 +0100)
>
> are available in the Git repository at:
>
> git://github.com/bonzini/qemu.git tags/for-upstream
>
> for you to fetch changes up to 56908dc5041aa424fd1495b6c6beb78c539d93e1:
>
> linux-headers: update again to 5.8 (2020-07-10 19:26:55 -0400)
>
> ----------------------------------------------------------------
> * Make checkpatch say 'qemu' instead of 'kernel' (Aleksandar)
> * Fix PSE guests with emulated NPT (Alexander B. #1)
> * Fix leak (Alexander B. #2)
> * HVF fixes (Roman, Cameron)
> * New Sapphire Rapids CPUID bits (Cathy)
> * cpus.c and softmmu/ cleanups (Claudio)
> * TAP driver tweaks (Daniel, Havard)
> * object-add bugfix and testcases (Eric A.)
> * Fix Coverity MIN_CONST and MAX_CONST (Eric B.)
> * "info lapic" improvement (Jan)
> * SSE fixes (Joseph)
> * "-msg guest-name" option (Mario)
> * support for AMD nested live migration (myself)
> * Small i386 TCG fixes (myself)
> * improved error reporting for Xen (myself)
> * fix "-cpu host -overcommit cpu-pm=on" (myself)
> * Add accel/Kconfig (Philippe)
> * iscsi sense handling fixes (Yongji)
> * Misc bugfixes
>
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/5.1
for any user-visible changes.
-- PMM
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-07-11 18:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-10 23:49 [PULL v3 00/47] Misc patches for QEMU 5.1 soft freeze Paolo Bonzini
2020-07-10 23:49 ` [PULL v3 41/47] cpu-throttle: new module, extracted from cpus.c Paolo Bonzini
2020-07-10 23:49 ` [PULL v3 47/47] linux-headers: update again to 5.8 Paolo Bonzini
2020-07-11 18:27 ` [PULL v3 00/47] Misc patches for QEMU 5.1 soft freeze Peter Maydell
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.