From nobody Mon Feb 9 02:51:07 2026 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; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1531121554703620.90270372758; Mon, 9 Jul 2018 00:32:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 469FD30832EE; Mon, 9 Jul 2018 07:32:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E45BC600CD; Mon, 9 Jul 2018 07:32:32 +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 8E08F1800B6B; Mon, 9 Jul 2018 07:32:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w697WCGY015334 for ; Mon, 9 Jul 2018 03:32:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2B8FF100194B; Mon, 9 Jul 2018 07:32:12 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 23C251001949 for ; Mon, 9 Jul 2018 07:32:10 +0000 (UTC) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 1B28F3DE42 for ; Mon, 9 Jul 2018 07:32:09 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jul 2018 00:32:07 -0700 Received: from david-unc.bj.intel.com ([10.238.145.77]) by fmsmga004.fm.intel.com with ESMTP; 09 Jul 2018 00:32:06 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,329,1526367600"; d="scan'208";a="69734032" From: Wang Huaqiang To: libvir-list@redhat.com Date: Mon, 9 Jul 2018 15:00:56 +0800 Message-Id: <1531119658-18549-9-git-send-email-huaqiang.wang@intel.com> In-Reply-To: <1531119658-18549-1-git-send-email-huaqiang.wang@intel.com> References: <1531119658-18549-1-git-send-email-huaqiang.wang@intel.com> 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.29]); Mon, 09 Jul 2018 07:32:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 09 Jul 2018 07:32:09 +0000 (UTC) for IP:'192.55.52.88' DOMAIN:'mga01.intel.com' HELO:'mga01.intel.com' FROM:'huaqiang.wang@intel.com' RCPT:'' X-RedHat-Spam-Score: -5.001 (RCVD_IN_DNSWL_HI, SPF_PASS) 192.55.52.88 mga01.intel.com 192.55.52.88 mga01.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, Wang Huaqiang , bing.niu@intel.com, jian-feng.ding@intel.com, rui.zang@intel.com Subject: [libvirt] [PATCHv2 08/10] tool: add command cpuresource to interact with cpu resources 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 09 Jul 2018 07:32:34 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" A tool to create, destroy and query resource monitoring group lively. --- tools/virsh-domain.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 139 insertions(+) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index e9b88f0..6aa674e 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -7677,6 +7677,139 @@ cmdIOThreadDel(vshControl *ctl, const vshCmd *cmd) return ret; } =20 +static const vshCmdInfo info_cpuresource[] =3D { + {.name =3D "help", + .data =3D N_("get or set hardware CPU RDT monitoring group") + }, + {.name =3D "desc", + .data =3D N_("Create or destroy CPU resource monitoring group.\n" + " To get current CPU resource monitoring group status: " + " virsh # cpuresource [domain]") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_cpurescource[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "group_name", + .type =3D VSH_OT_ALIAS, + .help =3D "group-name" + }, + {.name =3D "group-name", + .type =3D VSH_OT_STRING, + .flags =3D VSH_OFLAG_REQ_OPT, + .help =3D N_("group name to manipulate") + }, + {.name =3D "vcpulist", + .type =3D VSH_OT_STRING, + .flags =3D VSH_OFLAG_REQ_OPT, + .help =3D N_("ids of vcpus to manipulate") + }, + {.name =3D "create", + .type =3D VSH_OT_BOOL, + .help =3D N_("Create CPU resctrl monitoring group for functions such = as " + "monitoring cache occupancy"), + }, + {.name =3D "destroy", + .type =3D VSH_OT_BOOL, + .help =3D N_("Destroy CPU resctrl monitoring group") + }, + VIRSH_COMMON_OPT_LIVE(N_("modify/get running state")), + VIRSH_COMMON_OPT_CONFIG(N_("modify/get persistent configuration")), + VIRSH_COMMON_OPT_DOMAIN_CURRENT, + {.name =3D NULL} +}; + + +static bool +cmdCpuResource(vshControl *ctl, const vshCmd *cmd) +{ + virDomainPtr dom; + bool ret =3D false; + char *status =3D NULL; + int action =3D 0; + bool config =3D vshCommandOptBool(cmd, "config"); + bool live =3D vshCommandOptBool(cmd, "live"); + bool enable =3D vshCommandOptBool(cmd, "create"); + bool disable =3D vshCommandOptBool(cmd, "destroy"); + bool current =3D vshCommandOptBool(cmd, "current"); + const char *vcpustr =3D NULL; + const char *group_name =3D NULL; + unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; + char **tok =3D NULL; + size_t ntok =3D 0; + size_t i =3D 0; + int maxvcpus =3D 0; + + VSH_EXCLUSIVE_OPTIONS_VAR(enable, disable); + + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + + VSH_REQUIRE_OPTION("disable", "group-name"); + + if (config) + flags |=3D VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |=3D VIR_DOMAIN_AFFECT_LIVE; + + if (vshCommandOptStringReq(ctl, cmd, "group-name", &group_name)) + return false; + + if (vshCommandOptStringReq(ctl, cmd, "vcpulist", &vcpustr)) + return false; + + if (enable && !vcpustr && !group_name) { + vshError(ctl, _("Option --create requires at least one " + "of the options --group-name or --vcpulist")); + return false; + } + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (!enable && !disable) { + if (virDomainGetCPUResmonSts(dom, group_name, &status) < 0) + goto cleanup; + + if (!status) + goto cleanup; + + maxvcpus =3D virDomainGetMaxVcpus(dom); + if (maxvcpus =3D=3D -1) + goto cleanup; + + if (!(tok =3D virStringSplitCount(status, ";", maxvcpus + 1, &ntok= ))) + goto cleanup; + + if (ntok > maxvcpus) + ntok =3D maxvcpus; + + vshPrint(ctl, "CPU Resource Monitoring Group Status: \n"); + + for (i =3D 0; i < ntok; i++) + vshPrint(ctl, " %s\n", tok[i]); + } else { + if (disable) + action =3D 2; + if (enable) + action =3D 1; + + if (virDomainSetCPUResmon(dom, vcpustr, group_name, action, flags)= < 0) + goto cleanup; + + if (!status) + goto cleanup; + } + + ret =3D true; + cleanup: + VIR_FREE(status); + virStringListFree(tok); + virshDomainFree(dom); + return ret; +} + /* * "cpu-stats" command */ @@ -13726,6 +13859,12 @@ const vshCmdDef domManagementCmds[] =3D { .info =3D info_attach_device, .flags =3D 0 }, + {.name =3D "cpu-resource", + .handler =3D cmdCpuResource, + .opts =3D opts_cpurescource, + .info =3D info_cpuresource, + .flags =3D 0 + }, {.name =3D "attach-disk", .handler =3D cmdAttachDisk, .opts =3D opts_attach_disk, --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list