From nobody Tue May 7 05:13:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=quarantine dis=none) header.from=selectel.ru ARC-Seal: i=1; a=rsa-sha256; t=1613388179; cv=none; d=zohomail.com; s=zohoarc; b=GDjsR0ClUvq/C80ufv8jtseDpHNuBkWR8QzVmRjs1k0jrkdFVRTEa/fNW6vXczWubG9juV2GdK9n/b7rS8/bXavvvW0yOFkW2QFmGxXLR30mmHwdFR/gMYNeaUKKfcWsGoPoP5N6vH/l6yusbsSy6inRcjRCt0WoZSgXy7rcYYg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613388179; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=3NRgJLRmPP3j9rLo5GoQUNCANgLbaip8n/vRkBfwOIQ=; b=LaCEsA5JPvbcHmoPxzfZI+KLtYD2P2TkZ8zogg+sg4OUEeD/lTUoO/nMMDnaCbuomPsmIKqFPlqeDzXdpD1rzb6J4OcuZtHiGe+6YgkeJWQZ1QTedhm1GzcTBBdtBJ8bIcn2TwOGOjM8n1ujM/WAnrl0MKnavOjqawTlmQESLos= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1613388179044244.68557595637913; Mon, 15 Feb 2021 03:22:59 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-364-0aqLRxdlOF68weK8ZcgcWw-1; Mon, 15 Feb 2021 06:22:56 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7CDBE814737; Mon, 15 Feb 2021 11:22:50 +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 2D91B72162; Mon, 15 Feb 2021 11:22:50 +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 1A49A18095C9; Mon, 15 Feb 2021 11:22:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11FBMGI1025160 for ; Mon, 15 Feb 2021 06:22:16 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9CCF15F274; Mon, 15 Feb 2021 11:22:16 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 950535F262 for ; Mon, 15 Feb 2021 11:22:14 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6208980231B for ; Mon, 15 Feb 2021 11:22:14 +0000 (UTC) Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-304-hE4g0pjyO6i0I0-2hPmdww-1; Mon, 15 Feb 2021 06:22:11 -0500 Received: by mail-lf1-f51.google.com with SMTP id v30so9557377lfq.6 for ; Mon, 15 Feb 2021 03:22:11 -0800 (PST) Received: from some-laptop.eq.selectel.org ([79.134.222.178]) by smtp.gmail.com with ESMTPSA id w8sm173684lft.44.2021.02.15.03.22.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 03:22:09 -0800 (PST) X-MC-Unique: 0aqLRxdlOF68weK8ZcgcWw-1 X-MC-Unique: hE4g0pjyO6i0I0-2hPmdww-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3NRgJLRmPP3j9rLo5GoQUNCANgLbaip8n/vRkBfwOIQ=; b=XB0g5rzhQjPphwD1ykgPIjYqbnUXOux6Tg0PauuQaIAlawaAd4hmfcIkQE0c+JSIUT X4LP/yveptrfzcNYnyUjHyn5tHnVSboL/vbr1T6khto7slSPsUDMkQtSusjzuuzpvbDI 2KmEyJ4PrL4YDnaddAHuZ2nprwbhUoikW0VXzMhzXFZg7t53FmSnJDHLfBAd8a6yCTh7 pUaiRzH68hMNVHy/O8pLb7TWc9Gw3SKXArKecTFpS4uN159/Ly5NNFGlXKACf1YPktrI pFQO5eh/lQpaFFMrj2M3oZRrG2hb7hPeR15AcqFPj9H/mx8tm/Kzu6mGnrXyhZE9VYKc K1iA== X-Gm-Message-State: AOAM530zCE+j27hQgOapx4bGVb6iV/kZd9fe0mK7NKs6+tTuVHR+CGbZ AQkrT0SVqO54jvlnC8cABYeeC58ONvXOFA== X-Google-Smtp-Source: ABdhPJwDxqX+oOaJ6WFxhPLGyeGjLKRozyosdhPzIWctdkXEwAHDMmiePUZIMuARu0IU+1YTEGkIsg== X-Received: by 2002:a05:6512:3047:: with SMTP id b7mr8941640lfb.279.1613388129738; Mon, 15 Feb 2021 03:22:09 -0800 (PST) From: Aleksei Zakharov To: libvir-list@redhat.com Subject: [PATCH v3 1/1] qemu: add per-vcpu delay stats Date: Mon, 15 Feb 2021 14:21:45 +0300 Message-Id: <20210215112145.21162-2-zaharov@selectel.ru> In-Reply-To: <20210215112145.21162-1-zaharov@selectel.ru> References: <20210204110010.23828-1-zaharov@selectel.ru> <20210215112145.21162-1-zaharov@selectel.ru> X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: zakharov.a.g@yandex.ru, Aleksei Zakharov 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 2 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch adds delay time (steal time inside guest) to libvirt domain per-vcpu stats. Delay time is a consequence of the overloaded CPU. Knowledge of the delay time of a virtual machine helps to react exactly when needed and rebalance the load between hosts. This is used by cloud providers to provide quality of service, especially when the CPU is oversubscripted. It's more convenient to work with this metric in a context of a libvirt domain. Any monitoring software may use this information. Signed-off-by: Aleksei Zakharov --- src/qemu/qemu_driver.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 3d54653217..319bc60632 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1332,6 +1332,29 @@ static char *qemuConnectGetCapabilities(virConnectPt= r conn) { return virCapabilitiesFormatXML(caps); } =20 +static int +qemuGetSchedstatDelay(unsigned long long *cpudelay, + pid_t pid, pid_t tid) +{ + g_autofree char *proc =3D NULL; + unsigned long long oncpu =3D 0; + g_autofree FILE *schedstat =3D NULL; + + if (tid) + proc =3D g_strdup_printf("/proc/%d/task/%d/schedstat", (int)pid, (= int)tid); + else + proc =3D g_strdup_printf("/proc/%d/schedstat", (int)pid); + if (!proc) + return -1; + + schedstat =3D fopen(proc, "r"); + if (!schedstat || fscanf(schedstat, "%llu %llu", &oncpu, cpudelay) < 2= ) { + return -1; + } + + VIR_FORCE_FCLOSE(schedstat); + return 0; +} =20 static int qemuGetSchedInfo(unsigned long long *cpuWait, @@ -1470,6 +1493,7 @@ static int qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, unsigned long long *cpuwait, + unsigned long long *cpudelay, int maxinfo, unsigned char *cpumaps, int maplen) @@ -1529,6 +1553,11 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, return -1; } =20 + if (cpudelay) { + if (qemuGetSchedstatDelay(&(cpudelay[ncpuinfo]), vm->pid, vcpu= pid) < 0) + return -1; + } + ncpuinfo++; } =20 @@ -4873,7 +4902,7 @@ qemuDomainGetVcpus(virDomainPtr dom, goto cleanup; } =20 - ret =3D qemuDomainHelperGetVcpus(vm, info, NULL, maxinfo, cpumaps, map= len); + ret =3D qemuDomainHelperGetVcpus(vm, info, NULL, NULL, maxinfo, cpumap= s, maplen); =20 cleanup: virDomainObjEndAPI(&vm); @@ -17870,7 +17899,6 @@ qemuDomainGetStatsMemoryBandwidth(virQEMUDriverPtr = driver, return ret; } =20 - static int qemuDomainGetStatsCpuCache(virQEMUDriverPtr driver, virDomainObjPtr dom, @@ -18060,6 +18088,7 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver, int ret =3D -1; virVcpuInfoPtr cpuinfo =3D NULL; g_autofree unsigned long long *cpuwait =3D NULL; + g_autofree unsigned long long *cpudelay =3D NULL; =20 if (virTypedParamListAddUInt(params, virDomainDefGetVcpus(dom->def), "vcpu.current") < 0) @@ -18071,6 +18100,7 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver, =20 cpuinfo =3D g_new0(virVcpuInfo, virDomainDefGetVcpus(dom->def)); cpuwait =3D g_new0(unsigned long long, virDomainDefGetVcpus(dom->def)); + cpudelay =3D g_new0(unsigned long long, virDomainDefGetVcpus(dom->def)= ); =20 if (HAVE_JOB(privflags) && virDomainObjIsActive(dom) && qemuDomainRefreshVcpuHalted(driver, dom, QEMU_ASYNC_JOB_NONE) < 0)= { @@ -18079,7 +18109,7 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver, virResetLastError(); } =20 - if (qemuDomainHelperGetVcpus(dom, cpuinfo, cpuwait, + if (qemuDomainHelperGetVcpus(dom, cpuinfo, cpuwait, cpudelay, virDomainDefGetVcpus(dom->def), NULL, 0) < 0) { virResetLastError(); @@ -18104,6 +18134,10 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver, "vcpu.%u.wait", cpuinfo[i].number) = < 0) goto cleanup; =20 + if (virTypedParamListAddULLong(params, cpudelay[i], + "vcpu.%u.delay", cpuinfo[i].number= ) < 0) + goto cleanup; + /* state below is extracted from the individual vcpu structs */ if (!(vcpu =3D virDomainDefGetVcpu(dom->def, cpuinfo[i].number))) continue; --=20 2.17.1