From nobody Wed May 14 18:58:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1519983100671425.71466718736235; Fri, 2 Mar 2018 01:31:40 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7197C4E8A8; Fri, 2 Mar 2018 09:31:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 350AE5F71B; Fri, 2 Mar 2018 09:31:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C122D4A46E; Fri, 2 Mar 2018 09:31:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w229TLBV017606 for ; Fri, 2 Mar 2018 04:29:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1265460BEB; Fri, 2 Mar 2018 09:29:21 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 075C460C4E for ; Fri, 2 Mar 2018 09:29:20 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 51851356D4 for ; Fri, 2 Mar 2018 09:29:19 +0000 (UTC) Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w229KcxK087243 for ; Fri, 2 Mar 2018 04:29:19 -0500 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gf36ha1uj-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 02 Mar 2018 04:29:18 -0500 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 2 Mar 2018 09:29:16 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 2 Mar 2018 09:29:14 -0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w229TEbU51576876 for ; Fri, 2 Mar 2018 09:29:14 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C7C6A42042 for ; Fri, 2 Mar 2018 09:21:41 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9DD2942041 for ; Fri, 2 Mar 2018 09:21:41 +0000 (GMT) Received: from bradbury.ibm.com (unknown [9.152.222.40]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Fri, 2 Mar 2018 09:21:41 +0000 (GMT) From: Viktor Mihajlovski To: libvir-list@redhat.com Date: Fri, 2 Mar 2018 10:29:07 +0100 In-Reply-To: <1519982951-15767-1-git-send-email-mihajlov@linux.vnet.ibm.com> References: <1519982951-15767-1-git-send-email-mihajlov@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18030209-0012-0000-0000-000005B7D68E X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18030209-0013-0000-0000-00001933DEB3 Message-Id: <1519982951-15767-3-git-send-email-mihajlov@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-03-02_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803020109 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 02 Mar 2018 09:29:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 02 Mar 2018 09:29:19 +0000 (UTC) for IP:'148.163.156.1' DOMAIN:'mx0a-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'mihajlov@de.ibm.com' RCPT:'' X-RedHat-Spam-Score: -0.702 (RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_PASS) 148.163.156.1 mx0a-001b2d01.pphosted.com 148.163.156.1 mx0a-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/6] qemu: use query-cpus-fast in JSON monitor X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 02 Mar 2018 09:31:39 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Use query-cpus-fast instead of query-cpus if supported by QEMU. Based on the QEMU_CAPS_QUERY_CPUS_FAST capability. Signed-off-by: Viktor Mihajlovski Reviewed-by: Boris Fiuczynski --- src/qemu/qemu_monitor.c | 10 ++++++++-- src/qemu/qemu_monitor_json.c | 26 +++++++++++++++++--------- src/qemu/qemu_monitor_json.h | 3 ++- tests/qemumonitorjsontest.c | 2 +- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index ad5c572..dad1383 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -2012,6 +2012,7 @@ qemuMonitorGetCPUInfo(qemuMonitorPtr mon, int ret =3D -1; int rc; qemuMonitorCPUInfoPtr info =3D NULL; + bool fast; =20 QEMU_CHECK_MONITOR(mon); =20 @@ -2028,8 +2029,12 @@ qemuMonitorGetCPUInfo(qemuMonitorPtr mon, (qemuMonitorJSONGetHotpluggableCPUs(mon, &hotplugcpus, &nhotplugcp= us)) < 0) goto cleanup; =20 + fast =3D virQEMUCapsGet(QEMU_DOMAIN_PRIVATE(mon->vm)->qemuCaps, + QEMU_CAPS_QUERY_CPUS_FAST); + if (mon->json) - rc =3D qemuMonitorJSONQueryCPUs(mon, &cpuentries, &ncpuentries, ho= tplug); + rc =3D qemuMonitorJSONQueryCPUs(mon, &cpuentries, &ncpuentries, ho= tplug, + fast); else rc =3D qemuMonitorTextQueryCPUs(mon, &cpuentries, &ncpuentries); =20 @@ -2082,7 +2087,8 @@ qemuMonitorGetCpuHalted(qemuMonitorPtr mon, QEMU_CHECK_MONITOR_NULL(mon); =20 if (mon->json) - rc =3D qemuMonitorJSONQueryCPUs(mon, &cpuentries, &ncpuentries, fa= lse); + rc =3D qemuMonitorJSONQueryCPUs(mon, &cpuentries, &ncpuentries, fa= lse, + false); else rc =3D qemuMonitorTextQueryCPUs(mon, &cpuentries, &ncpuentries); =20 diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index a09e93e..2ecdf0a 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -1466,7 +1466,8 @@ int qemuMonitorJSONSystemReset(qemuMonitorPtr mon) static int qemuMonitorJSONExtractCPUInfo(virJSONValuePtr data, struct qemuMonitorQueryCpusEntry **entries, - size_t *nentries) + size_t *nentries, + bool fast) { struct qemuMonitorQueryCpusEntry *cpus =3D NULL; int ret =3D -1; @@ -1491,11 +1492,13 @@ qemuMonitorJSONExtractCPUInfo(virJSONValuePtr data, } =20 /* Some older qemu versions don't report the thread_id so treat th= is as - * non-fatal, simply returning no data */ - ignore_value(virJSONValueObjectGetNumberInt(entry, "CPU", &cpuid)); - ignore_value(virJSONValueObjectGetNumberInt(entry, "thread_id", &t= hread)); + * non-fatal, simply returning no data. + * The return data of query-cpus-fast has different field names + */ + ignore_value(virJSONValueObjectGetNumberInt(entry, fast ? "cpu-ind= ex" : "CPU", &cpuid)); + ignore_value(virJSONValueObjectGetNumberInt(entry, fast ? "thread-= id" : "thread_id", &thread)); ignore_value(virJSONValueObjectGetBoolean(entry, "halted", &halted= )); - qom_path =3D virJSONValueObjectGetString(entry, "qom_path"); + qom_path =3D virJSONValueObjectGetString(entry, fast ? "qom-path" = : "qom_path"); =20 cpus[i].qemu_id =3D cpuid; cpus[i].tid =3D thread; @@ -1520,10 +1523,12 @@ qemuMonitorJSONExtractCPUInfo(virJSONValuePtr data, * @mon: monitor object * @entries: filled with detected entries on success * @nentries: number of entries returned + * @force: force exit on error + * @fast: use query-cpus-fast * * Queries qemu for cpu-related information. Failure to execute the comman= d or * extract results does not produce an error as libvirt can continue witho= ut - * this information. + * this information, unless the caller has specified @force =3D=3D true. * * Returns 0 on success, -1 on a fatal error (oom ...) and -2 if the * query failed gracefully. @@ -1532,10 +1537,13 @@ int qemuMonitorJSONQueryCPUs(qemuMonitorPtr mon, struct qemuMonitorQueryCpusEntry **entries, size_t *nentries, - bool force) + bool force, + bool fast) { int ret =3D -1; - virJSONValuePtr cmd =3D qemuMonitorJSONMakeCommand("query-cpus", NULL); + virJSONValuePtr cmd =3D + qemuMonitorJSONMakeCommand(fast ? "query-cpus-fast" : "query-cpus", + NULL); virJSONValuePtr reply =3D NULL; virJSONValuePtr data; =20 @@ -1553,7 +1561,7 @@ qemuMonitorJSONQueryCPUs(qemuMonitorPtr mon, goto cleanup; } =20 - ret =3D qemuMonitorJSONExtractCPUInfo(data, entries, nentries); + ret =3D qemuMonitorJSONExtractCPUInfo(data, entries, nentries, fast); =20 cleanup: virJSONValueFree(cmd); diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index ec243be..e03299a 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -60,7 +60,8 @@ int qemuMonitorJSONSystemReset(qemuMonitorPtr mon); int qemuMonitorJSONQueryCPUs(qemuMonitorPtr mon, struct qemuMonitorQueryCpusEntry **entries, size_t *nentries, - bool force); + bool force, + bool fast); int qemuMonitorJSONGetVirtType(qemuMonitorPtr mon, virDomainVirtType *virtType); int qemuMonitorJSONUpdateVideoMemorySize(qemuMonitorPtr mon, diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 908ec3a..6824623 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1420,7 +1420,7 @@ testQemuMonitorJSONqemuMonitorJSONQueryCPUs(const voi= d *data) goto cleanup; =20 if (qemuMonitorJSONQueryCPUs(qemuMonitorTestGetMonitor(test), - &cpudata, &ncpudata, true) < 0) + &cpudata, &ncpudata, true, false) < 0) goto cleanup; =20 if (ncpudata !=3D 4) { --=20 1.9.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list