From nobody Sun May 19 02:06:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1612436458; cv=none; d=zohomail.com; s=zohoarc; b=Vn7BGPD+LQkZ0Mrh9zpPUiwBWZxyRrtD/UrkBGoxRICT02aYSViGgNrZtPvUftzgbTUvQk7K+2tNlk0roJtRSFBXF2o9KS4YIgwh7kyv97FV+AA98l2alIg/tXRHFUbn5GX+62RZCgcreuXjekCBygXA0K0ifcMMtw4kbLP0TI0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612436458; 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=oGzdNnB23oNcqiEtjQirjA9brfwTbTcCNGkqeBpIreI=; b=mGMN4BxlSii530lj2+UBSKupGiI1zw7IWklOAX6u1tGQdyiHaQdbnFOThxTXkBCwz6I4YbkYsWkMYWMuyxjJ41ie/k7FDulF7NCwIPS13X7IsZd/Ny8Bde5KzNBzoXeaVZfuREltZUna2QywgufweoMkNItjGE58rUokPcXf7+Q= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 161243645862124.982576702869892; Thu, 4 Feb 2021 03:00:58 -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-289-NfR2YViPMaqEb6amzBd0PQ-1; Thu, 04 Feb 2021 06:00:52 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 44E67C7401; Thu, 4 Feb 2021 11:00:46 +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 E590D5B695; Thu, 4 Feb 2021 11:00:45 +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 A89ED57DFA; Thu, 4 Feb 2021 11:00:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 114B0Nsj003349 for ; Thu, 4 Feb 2021 06:00:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4C02E10EB2A9; Thu, 4 Feb 2021 11:00:23 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 478A310EB2A8 for ; Thu, 4 Feb 2021 11:00:23 +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 35825185AD06 for ; Thu, 4 Feb 2021 11:00:23 +0000 (UTC) Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-28-Y6-KDN-uOECbGjw8hiV9JA-1; Thu, 04 Feb 2021 06:00:20 -0500 Received: by mail-lf1-f47.google.com with SMTP id p21so3822755lfu.11 for ; Thu, 04 Feb 2021 03:00:19 -0800 (PST) Received: from some-laptop.eq.selectel.org (89-110-38-38.static.avangarddsl.ru. [89.110.38.38]) by smtp.gmail.com with ESMTPSA id b3sm559619lfb.191.2021.02.04.03.00.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 03:00:17 -0800 (PST) X-MC-Unique: NfR2YViPMaqEb6amzBd0PQ-1 X-MC-Unique: Y6-KDN-uOECbGjw8hiV9JA-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=oGzdNnB23oNcqiEtjQirjA9brfwTbTcCNGkqeBpIreI=; b=AUkI59u8tALxYVgAc6AaI3su4l0XYuUSuHUM3FYcO+7L3V4LM0SxW46a0kmIGxM8mv ZUezjcqL4jMoAOZb8xzeaO8VDIpT5eTnGgYRkDSpj36tcp7B2k3muZHAeMHRLxH2Oonf fby372JU066lLw+McdWzudoAQtMRlqWiMJAJW+twThA4aYQ2YmOoX5qS2gpv5awZBBHo YwEwNogOVrlH66XqNlbBh5k9dVoxnk89sC37hxD/BNyrGp48PxylLZfhMHmPoWvwmnDj j1AJHw4euhGNDjxJXCc2E2Gkk7mjxlz/050Tf6LOZrqOfiDmytb+jBYFH4Gqw8K4sV2Y 89fA== X-Gm-Message-State: AOAM530pYI3uKKypmvjxth1k2yKk8fdBjnve67v/hOYs0a/5Z6WGMmLY DtleEv019tH0hrowiiOZl5ocj/3GxW/JqQ== X-Google-Smtp-Source: ABdhPJyWIUeiThiMiq1SVoWUv3scsY+Lfs5QSdMsOvAsTh1MdPCnb2/IVFf62OdCGc8Qg4rKO+WSEw== X-Received: by 2002:ac2:410e:: with SMTP id b14mr4469977lfi.186.1612436418166; Thu, 04 Feb 2021 03:00:18 -0800 (PST) From: Aleksei Zakharov To: libvir-list@redhat.com Subject: [PATCH v2 1/1] qemu: add per-vcpu delay stats Date: Thu, 4 Feb 2021 14:00:10 +0300 Message-Id: <20210204110010.23828-2-zaharov@selectel.ru> In-Reply-To: <20210204110010.23828-1-zaharov@selectel.ru> References: <20210129152537.GT6906@angien.pipo.sk> <20210204110010.23828-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.78 on 10.11.54.3 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.15 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 | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 69fcd28666..f5f86557e0 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1332,6 +1332,28 @@ 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; + } + + return 0; +} =20 static int qemuGetSchedInfo(unsigned long long *cpuWait, @@ -1470,6 +1492,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 +1552,11 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, return -1; } =20 + if (cpudelay) { + if (qemuGetSchedstatDelay(&(cpudelay[ncpuinfo]), vm->pid, vcpu= pid) < 0) + return -1; + } + ncpuinfo++; } =20 @@ -4873,7 +4901,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); @@ -17868,7 +17896,6 @@ qemuDomainGetStatsMemoryBandwidth(virQEMUDriverPtr = driver, return ret; } =20 - static int qemuDomainGetStatsCpuCache(virQEMUDriverPtr driver, virDomainObjPtr dom, @@ -18058,6 +18085,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) @@ -18069,6 +18097,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)= { @@ -18077,7 +18106,7 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver, virResetLastError(); } =20 - if (qemuDomainHelperGetVcpus(dom, cpuinfo, cpuwait, + if (qemuDomainHelperGetVcpus(dom, cpuinfo, cpuwait, cpudelay, virDomainDefGetVcpus(dom->def), NULL, 0) < 0) { virResetLastError(); @@ -18102,6 +18131,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