From nobody Tue Nov 4 15:31:27 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530218398702105.77042981127374; Thu, 28 Jun 2018 13:39:58 -0700 (PDT) Received: from localhost ([::1]:38461 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYdhu-0001s3-01 for importer@patchew.org; Thu, 28 Jun 2018 16:39:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38446) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYdB8-0007qW-SC for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:06:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYdB7-0001Da-Gn for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:06:06 -0400 Received: from mail-wr0-x231.google.com ([2a00:1450:400c:c0c::231]:33824) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fYdB7-0001BF-5B for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:06:05 -0400 Received: by mail-wr0-x231.google.com with SMTP id a12-v6so6696549wro.1 for ; Thu, 28 Jun 2018 13:06:05 -0700 (PDT) Received: from 640k.lan ([82.84.124.111]) by smtp.gmail.com with ESMTPSA id 127-v6sm6211110wmd.18.2018.06.28.13.06.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jun 2018 13:06:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=GIAKt95pMF87VnIjy3k+f8byIK6fvVRPB5Njv5iPqQ8=; b=shLze0t68p5iQ+xQipNQqOgt6aJFMUlkyMwF/y7y2vClA5GW4xh8q1Zhw/7YHBgYXa viKSpdZfu0fz8JXOXVlH1zUhdPaabfKIsurcyw9BGB7oDH2Pe3QSwyM2nMFuXJ4o/Yf+ ym1/YX0YqvoRf1rP+hgSKP7u4/jBrFFYOHByjRLpOcviQ9Agknmn3M2r/QmQAYHBWqmh YKur+1aVJabSfQ284LfMhb3Ku72QQXcH8Cl1u2shrsHdwiSUstzQGKAhfAyRUfq6M6Mg NKnInzDdtN0kiUU5S7UX1E6WEXb46X/N7tsL6wn7BR7tILOGAHiu0zZOMEY2+/Syd0ig LSKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=GIAKt95pMF87VnIjy3k+f8byIK6fvVRPB5Njv5iPqQ8=; b=UCrAZsM9vD/b5a2O2ACXa1UqCrWR5HHeCL4KKt+aDWVSimBlT8AvAofWaKRUBrnubo GdraOMjVt5nh9nGZ6Wwuj6g+9O9G8khAD7yGMAK9GTijSu1QlQATNPtebm6uoJ9oJ87N N7dY8rybFXpVGIjuxCtuFL3zpU2jJOajEaHzVXYJ68dBE11o2gfIOYPU2RG5507Rtntc IEvMJPpBBXCLbcoy89NesgsRN6LYyVXPOrAJ5It12M6nIlplP4PNhIlg+6BhwPdzrgOE /VNJhE/Kwsvz4/w0buXthM3aLy+UG03A+mUoFOPWtCsd+LRePwVls9zC1wffYnwlcmLh lQig== X-Gm-Message-State: APt69E0HJpJium9Kx5pfXeYYP/n4gPhbfryHXRGdSqY/A6Y93e5s7U4F /dO1ajD2nOkt//z0a4S/oVkCRSw0 X-Google-Smtp-Source: AAOMgpcH1iyIsRRqbNdBfybO2XTUS7bq3Bb5Fufquzra0jCdL0hdJgzNpPOS1oLKe/qi6w0gNi3DVg== X-Received: by 2002:a5d:428a:: with SMTP id k10-v6mr6086952wrq.225.1530216363890; Thu, 28 Jun 2018 13:06:03 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 28 Jun 2018 22:05:01 +0200 Message-Id: <1530216310-52873-52-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1530216310-52873-1-git-send-email-pbonzini@redhat.com> References: <1530216310-52873-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::231 Subject: [Qemu-devel] [PULL 51/60] kvm: support -overcommit cpu-pm=on|off X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Michael S. Tsirkin" With this flag, kvm allows guest to control host CPU power state. This increases latency for other processes using same host CPU in an unpredictable way, but if decreases idle entry/exit times for the running VCPU, so to use it QEMU needs a hint about whether host CPU is overcommitted, hence the flag name. Follow-up patches will expose this capability to guest (using mwait leaf). Based on a patch by Wanpeng Li . Signed-off-by: Michael S. Tsirkin Message-Id: <20180622192148.178309-2-mst@redhat.com> Signed-off-by: Paolo Bonzini --- include/sysemu/sysemu.h | 1 + qemu-options.hx | 24 ++++++++++++++++++++++++ target/i386/kvm.c | 23 +++++++++++++++++++++++ vl.c | 32 +++++++++++++++++++++++++++++++- 4 files changed, 79 insertions(+), 1 deletion(-) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index e893f72..b921c6f 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -128,6 +128,7 @@ extern bool boot_strict; extern uint8_t *boot_splash_filedata; extern size_t boot_splash_filedata_size; extern bool enable_mlock; +extern bool enable_cpu_pm; extern uint8_t qemu_extra_params_fw[2]; extern QEMUClockType rtc_clock; extern const char *mem_path; diff --git a/qemu-options.hx b/qemu-options.hx index 3e45483..81b1e99 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3325,6 +3325,30 @@ mlocking qemu and guest memory can be enabled via @o= ption{mlock=3Don} (enabled by default). ETEXI =20 +DEF("overcommit", HAS_ARG, QEMU_OPTION_overcommit, + "--overcommit [mem-lock=3Don|off][cpu-pm=3Don|off]\n" + " run qemu with overcommit hints\n" + " mem-lock=3Don|off controls memory lock support (defau= lt: off)\n" + " cpu-pm=3Don|off controls cpu power management (defaul= t: off)\n", + QEMU_ARCH_ALL) +STEXI +@item -overcommit mem-lock=3Don|off +@item -overcommit cpu-pm=3Don|off +@findex -overcommit +Run qemu with hints about host resource overcommit. The default is +to assume that host overcommits all resources. + +Locking qemu and guest memory can be enabled via @option{mem-lock=3Don} (d= isabled +by default). This works when host memory is not overcommitted and reduces= the +worst-case latency for guest. This is equivalent to @option{realtime}. + +Guest ability to manage power state of host cpus (increasing latency for o= ther +processes on the same host cpu, but decreasing latency for guest) can be +enabled via @option{cpu-pm=3Don} (disabled by default). This works best w= hen +host CPU is not overcommitted. When used, host estimates of CPU cycle and = power +utilization will be incorrect, not taking into account guest idle time. +ETEXI + DEF("gdb", HAS_ARG, QEMU_OPTION_gdb, \ "-gdb dev wait for gdb connection on 'dev'\n", QEMU_ARCH_ALL) STEXI diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 2d174f3..dc991f6 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1387,6 +1387,29 @@ int kvm_arch_init(MachineState *ms, KVMState *s) smram_machine_done.notify =3D register_smram_listener; qemu_add_machine_init_done_notifier(&smram_machine_done); } + + if (enable_cpu_pm) { + int disable_exits =3D kvm_check_extension(s, KVM_CAP_X86_DISABLE_E= XITS); + int ret; + +/* Work around for kernel header with a typo. TODO: fix header and drop. */ +#if defined(KVM_X86_DISABLE_EXITS_HTL) && !defined(KVM_X86_DISABLE_EXITS_H= LT) +#define KVM_X86_DISABLE_EXITS_HLT KVM_X86_DISABLE_EXITS_HTL +#endif + if (disable_exits) { + disable_exits &=3D (KVM_X86_DISABLE_EXITS_MWAIT | + KVM_X86_DISABLE_EXITS_HLT | + KVM_X86_DISABLE_EXITS_PAUSE); + } + + ret =3D kvm_vm_enable_cap(s, KVM_CAP_X86_DISABLE_EXITS, 0, + disable_exits); + if (ret < 0) { + error_report("kvm: guest stopping CPU not supported: %s", + strerror(-ret)); + } + } + return 0; } =20 diff --git a/vl.c b/vl.c index 7c9f19a..ef6cfce 100644 --- a/vl.c +++ b/vl.c @@ -142,6 +142,7 @@ ram_addr_t ram_size; const char *mem_path =3D NULL; int mem_prealloc =3D 0; /* force preallocation of physical target memory */ bool enable_mlock =3D false; +bool enable_cpu_pm =3D false; int nb_nics; NICInfo nd_table[MAX_NICS]; int autostart; @@ -390,6 +391,22 @@ static QemuOptsList qemu_realtime_opts =3D { }, }; =20 +static QemuOptsList qemu_overcommit_opts =3D { + .name =3D "overcommit", + .head =3D QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts.head), + .desc =3D { + { + .name =3D "mem-lock", + .type =3D QEMU_OPT_BOOL, + }, + { + .name =3D "cpu-pm", + .type =3D QEMU_OPT_BOOL, + }, + { /* end of list */ } + }, +}; + static QemuOptsList qemu_msg_opts =3D { .name =3D "msg", .head =3D QTAILQ_HEAD_INITIALIZER(qemu_msg_opts.head), @@ -3906,7 +3923,20 @@ int main(int argc, char **argv, char **envp) if (!opts) { exit(1); } - enable_mlock =3D qemu_opt_get_bool(opts, "mlock", true); + /* Don't override the -overcommit option if set */ + enable_mlock =3D enable_mlock || + qemu_opt_get_bool(opts, "mlock", true); + break; + case QEMU_OPTION_overcommit: + opts =3D qemu_opts_parse_noisily(qemu_find_opts("overcommi= t"), + optarg, false); + if (!opts) { + exit(1); + } + /* Don't override the -realtime option if set */ + enable_mlock =3D enable_mlock || + qemu_opt_get_bool(opts, "mem-lock", false); + enable_cpu_pm =3D qemu_opt_get_bool(opts, "cpu-pm", false); break; case QEMU_OPTION_msg: opts =3D qemu_opts_parse_noisily(qemu_find_opts("msg"), op= targ, --=20 1.8.3.1