From nobody Sun Apr 28 20:50:02 2024 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; dkim=fail; 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1563444181; cv=none; d=zoho.com; s=zohoarc; b=cVZIZHdlTmmOoJMCRME5f/XsEqHTf6ri/tOpyybUb8XA6GrjAwM6Z7LiAG1JKiFZowwoFbD4/9W8siEBwCQQgayyKd41/tIaZuC2PiFcbtQleqcJxWbOrF/OBjwYuFSd++6CKGLzvjBSCd0dMzLo4hiNA7xwktZE8FdVCY3ZKZA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563444181; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=faHSskHJ5y7DdaDOea4OucuhS1NmT+DhyfISIxJZW6U=; b=BVTyRypKwuFuonCJtPhL4lEttpWigfpx2ULRHpWibHDexpuj4hXJ8sN4/TrXAInowoWkMJEkb/ODfbjCf413PKwmN95ijCqlxGuLj1YhM/p+Poof00pP+Tk1cHD4RQaG9cLCe2e+wPiedAaRM4A1h14lvlGePtnZeszONKTL7p0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563444181648431.48462658875076; Thu, 18 Jul 2019 03:03:01 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8335D89ACB; Thu, 18 Jul 2019 10:02:57 +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 A501519C65; Thu, 18 Jul 2019 10:02:56 +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 697681800206; Thu, 18 Jul 2019 10:02:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x6IA2qsf029641 for ; Thu, 18 Jul 2019 06:02:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id DCAAD6013B; Thu, 18 Jul 2019 10:02:52 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D72A9600D1 for ; Thu, 18 Jul 2019 10:02:50 +0000 (UTC) Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9BA1A87638 for ; Thu, 18 Jul 2019 10:02:49 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id n9so28067314wru.0 for ; Thu, 18 Jul 2019 03:02:49 -0700 (PDT) Received: from archpc.localdomain (x8d1ee222.agdsn.tu-dresden.de. [141.30.226.34]) by smtp.gmail.com with ESMTPSA id s188sm19769401wmf.40.2019.07.18.03.02.46 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 18 Jul 2019 03:02:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=k46RLVZnbJcK4G5v0tIAleT0Dx2a0cGnqJsl03LVN54=; b=nRzzMcgHFwXmOeqzBY+hTno+lNUFs7ziimjes8aZMGml6T29uSiRk59dm/7ADnKR5m SB49vKIg9hoPlduOGfkngSzc9IzIlyWVfqRqE2uENVAhhccf7rq5rIH3n9987o+BTHYm lT2AcLPI9d28hiqRuy25Q+Xme6dgt7oDIrNDoLrnSEXCQtU5XypFMI4z9Bt4kC3AHy52 xypUZCWL3q8x1kmSe/88bHzLUgoJ9V3+eDMtulNHVfU7q5DUnBllw4SYdk+ibtqfLVNE pWx+SaWs9KBziJHZn/drV7gvD4EHXBN/ubrmoCuHRpGJU368NkhnN+Qyc5YMJeUwjMpD jV1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=k46RLVZnbJcK4G5v0tIAleT0Dx2a0cGnqJsl03LVN54=; b=FVIOY/ZDZl/DrulMljPwj6wxTbihZ0JUtPuhBQs6//t1mWTWagaP0YmCIbBG3vR8N1 pn8mMyJVq5P+kaIdaHLWMRI03hIsJUGhecZa2g1QL25gWTWbBDguC950FneRbvU1s4f/ uqhpNlNO36LtmtR98h6qWsVzVlELi+APgfKvByYtt3M/iPXSSDSoRqNDPe0SajsKahoe z7dufysh6SSEX0Em3P42022RvmPs0rKzPFzLcouTSn+6f1Rr+hEaca8nHQSvrL5RMyYT 6N4WIXQpV1Yc8zt77hMi0BIn5SXE/iXAJPHqdiTNn2V3/fCAv8dawxhJOM8j+0fXS5qm u6IA== X-Gm-Message-State: APjAAAUEBurGa2oaSQWmZDoJef0bCpCNtponYvk9tiIrbzL5W0hywnpb jYro+/WYQpvPYXz6TD8k6FKSZlLBMEzvwA== X-Google-Smtp-Source: APXvYqxd7u11qn+PcCaEwCD3ZPnDxCJxpf/LaqJHEN5g151x0DBsE3JGYD2QASNeAW7bteK2MLfjpw== X-Received: by 2002:a5d:6709:: with SMTP id o9mr48918703wru.301.1563444167885; Thu, 18 Jul 2019 03:02:47 -0700 (PDT) From: Ilias Stamatis To: libvir-list@redhat.com Date: Thu, 18 Jul 2019 12:02:43 +0200 Message-Id: <20190718100243.1953-1-stamatis.iliass@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 18 Jul 2019 10:02:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 18 Jul 2019 10:02:49 +0000 (UTC) for IP:'209.85.221.65' DOMAIN:'mail-wr1-f65.google.com' HELO:'mail-wr1-f65.google.com' FROM:'stamatis.iliass@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.099 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS) 209.85.221.65 mail-wr1-f65.google.com 209.85.221.65 mail-wr1-f65.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] test_driver: implement virDomainGetCPUStats 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 18 Jul 2019 10:02:59 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Ilias Stamatis --- src/test/test_driver.c | 131 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index fcb80c9e47..2907c043cb 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -3258,6 +3258,136 @@ static int testDomainSetMetadata(virDomainPtr dom, return ret; } + +static int +testDomainGetDomainTotalCpuStats(virTypedParameterPtr params, + int nparams) +{ + if (nparams =3D=3D 0) /* return supported number of params */ + return 3; + + if (virTypedParameterAssign(¶ms[0], VIR_DOMAIN_CPU_STATS_CPUTIME, + VIR_TYPED_PARAM_ULLONG, 77102913900) < 0) + return -1; + + if (nparams > 1 && + virTypedParameterAssign(¶ms[1], + VIR_DOMAIN_CPU_STATS_USERTIME, + VIR_TYPED_PARAM_ULLONG, 45650000000) < 0) + return -1; + + if (nparams > 2 && + virTypedParameterAssign(¶ms[2], + VIR_DOMAIN_CPU_STATS_SYSTEMTIME, + VIR_TYPED_PARAM_ULLONG, 11390000000) < 0) + return -1; + + if (nparams > 3) + nparams =3D 3; + + return nparams; +} + + +static int +testDomainGetPercpuStats(virTypedParameterPtr params, + unsigned int nparams, + int start_cpu, + unsigned int ncpus, + int total_cpus) +{ + size_t i; + int need_cpus; + int param_idx; + int ret =3D -1; + + /* return the number of supported params */ + if (nparams =3D=3D 0 && ncpus !=3D 0) + return 2; + + /* return total number of cpus */ + if (ncpus =3D=3D 0) { + ret =3D total_cpus; + goto cleanup; + } + + if (start_cpu >=3D total_cpus) { + virReportError(VIR_ERR_INVALID_ARG, + _("start_cpu %d larger than maximum of %d"), + start_cpu, total_cpus - 1); + goto cleanup; + } + + /* return percpu cputime in index 0 */ + param_idx =3D 0; + + /* number of cpus to compute */ + need_cpus =3D MIN(total_cpus, start_cpu + ncpus); + + for (i =3D 0; i < need_cpus; i++) { + if (i < start_cpu) + continue; + int idx =3D (i - start_cpu) * nparams + param_idx; + if (virTypedParameterAssign(¶ms[idx], + VIR_DOMAIN_CPU_STATS_CPUTIME, + VIR_TYPED_PARAM_ULLONG, + 202542145062 + 10 * i) < 0) + goto cleanup; + } + + /* return percpu vcputime in index 1 */ + param_idx =3D 1; + + if (param_idx < nparams) { + for (i =3D start_cpu; i < need_cpus; i++) { + int idx =3D (i - start_cpu) * nparams + param_idx; + if (virTypedParameterAssign(¶ms[idx], + VIR_DOMAIN_CPU_STATS_VCPUTIME, + VIR_TYPED_PARAM_ULLONG, + 26254023765 + 10 * i) < 0) + goto cleanup; + } + param_idx++; + } + + ret =3D param_idx; + cleanup: + return ret; +} + + +static int +testDomainGetCPUStats(virDomainPtr dom, + virTypedParameterPtr params, + unsigned int nparams, + int start_cpu, + unsigned int ncpus, + unsigned int flags) +{ + virDomainObjPtr vm =3D NULL; + testDriverPtr privconn =3D dom->conn->privateData; + int ret =3D -1; + + virCheckFlags(VIR_TYPED_PARAM_STRING_OKAY, -1); + + if (!(vm =3D testDomObjFromDomain(dom))) + return -1; + + if (virDomainObjCheckActive(vm) < 0) + goto cleanup; + + if (start_cpu =3D=3D -1) + ret =3D testDomainGetDomainTotalCpuStats(params, nparams); + else + ret =3D testDomainGetPercpuStats(params, nparams, start_cpu, ncpus, + privconn->nodeInfo.cores); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + + static int testDomainSendProcessSignal(virDomainPtr dom, long long pid_value, @@ -7794,6 +7924,7 @@ static virHypervisorDriver testHypervisorDriver =3D { .domainSendKey =3D testDomainSendKey, /* 5.5.0 */ .domainGetMetadata =3D testDomainGetMetadata, /* 1.1.3 */ .domainSetMetadata =3D testDomainSetMetadata, /* 1.1.3 */ + .domainGetCPUStats =3D testDomainGetCPUStats, /* 5.6.0 */ .domainSendProcessSignal =3D testDomainSendProcessSignal, /* 5.5.0 */ .connectGetCPUModelNames =3D testConnectGetCPUModelNames, /* 1.1.3 */ .domainManagedSave =3D testDomainManagedSave, /* 1.1.4 */ -- 2.22.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list