From nobody Wed Jun 24 21:44:10 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) client-ip=38.145.34.151; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=suse.de Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [38.145.34.151]) by mx.zohomail.com with SMTPS id 1781712980792901.7415286842822; Wed, 17 Jun 2026 09:16:20 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 6C4FC41AE6; Wed, 17 Jun 2026 12:16:19 -0400 (EDT) Received: from [172.19.199.7] (unknown [10.16.107.18]) by lists.libvirt.org (Postfix) with ESMTP id A94B241D01; Wed, 17 Jun 2026 12:15:08 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 0E92641AC7; Wed, 17 Jun 2026 12:14:57 -0400 (EDT) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 701FA41A12 for ; Wed, 17 Jun 2026 12:14:55 -0400 (EDT) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A5B2C75A14; Wed, 17 Jun 2026 16:14:53 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 5AF17779A8; Wed, 17 Jun 2026 16:14:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id XrtyE/3HMmqEDAAAD6G6ig (envelope-from ); Wed, 17 Jun 2026 16:14:53 +0000 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1781712893; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=E49VsLQwFCdMOpazFwYbhO2L+dDC8VSnJcKNx6xEl8U=; b=DSBhraw17ldAYP5/DmiUp2qPmeRgFxTAicSJaVTnsE7Vuc7FI3ksAopnOelaerUJ/ewOG0 aaJ5thjyAprbS0aQmv46jKswUy3nNg6GhoqcR7AAQJq5zOPO0cPckRhbyA58z+Pr07Zr20 yCyDUGy9d/SOCjQUP0wWlR5P4tLT2WA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1781712893; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=E49VsLQwFCdMOpazFwYbhO2L+dDC8VSnJcKNx6xEl8U=; b=hGP3mkTRnS0KInHYbhx45jHG2DaKiCZ9nBBjKaWoqukjyP9owIISeioJmFcnBTxpKMlY5V L9/y3gil9ZucchDA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1781712893; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=E49VsLQwFCdMOpazFwYbhO2L+dDC8VSnJcKNx6xEl8U=; b=DSBhraw17ldAYP5/DmiUp2qPmeRgFxTAicSJaVTnsE7Vuc7FI3ksAopnOelaerUJ/ewOG0 aaJ5thjyAprbS0aQmv46jKswUy3nNg6GhoqcR7AAQJq5zOPO0cPckRhbyA58z+Pr07Zr20 yCyDUGy9d/SOCjQUP0wWlR5P4tLT2WA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1781712893; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=E49VsLQwFCdMOpazFwYbhO2L+dDC8VSnJcKNx6xEl8U=; b=hGP3mkTRnS0KInHYbhx45jHG2DaKiCZ9nBBjKaWoqukjyP9owIISeioJmFcnBTxpKMlY5V L9/y3gil9ZucchDA== From: Claudio Fontana To: devel@lists.libvirt.org Subject: [PATCH v2] util: virHostCPUGetStatsLinux: add guest_nice to VIR_NODE_CPU_STATS_GUEST Date: Wed, 17 Jun 2026 18:14:37 +0200 Message-Id: <20260617161437.3638-1-cfontana@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.983]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email,suse.de:mid]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FUZZY_RATELIMITED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_THREE(0.00)[4]; RCVD_TLS_ALL(0.00)[] Message-ID-Hash: 5AARZIIBMNKVN5R3N5AQI32ZNHTCIZ6Z X-Message-ID-Hash: 5AARZIIBMNKVN5R3N5AQI32ZNHTCIZ6Z X-MailFrom: cfontana@suse.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Claudio Fontana , Peter Krempa X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (found 2 invalid signatures) X-ZM-MESSAGEID: 1781712986204158500 Content-Type: text/plain; charset="utf-8" On Linux the accounting stats come from /proc/stat entries and the mapping = is: https://www.kernel.org/doc/html/latest/filesystems/proc.html VIR_NODE_CPU_STATS_KERNEL =3D (system + irq + softirq) VIR_NODE_CPU_STATS_USER =3D (user + nice) VIR_NODE_CPU_STATS_IDLE =3D idle =3D N/A, irq is accounted by libvirt as KERNEL VIR_NODE_CPU_STATS_IOWAIT =3D iowait VIR_NODE_CPU_STATS_GUEST =3D guest VIR_NODE_CPU_STATS_GUEST was introduced in: b5878727c714 ("util: virHostCPUGetStatsLinux: support VIR_NODE_CPU_STATS_GUEST") with the goal of specifically accounting the CPU time spent running guest V= CPUs. Unfortunately at the time it was not considered that to get a measure of th= is time, "guest" is not sufficient, because any guest that is "niced" is accou= nted in a separate category, "guest_nice". This patch rectifies the situation by adding the guest_nice counter, so that VIR_NODE_CPU_STATS_GUEST =3D (guest + guest_nice) which makes the statistic useful to the caller, as the totals sum up correc= tly. In order to find the total USER time spent running host tasks, for example: cpu_user_host =3D VIR_NODE_CPU_STATS_USER - VIR_NODE_CPU_STATS_GUEST this follows from the fact that "guest" is included in "user" accounting, and "guest_nice" is included in "nice" accounting. Extend the existing tests artificially to capture this specific case. Fixes: b5878727c714d813c820ad4a1b695fbbb5ffc84e Signed-off-by: Claudio Fontana Reviewed-by: Peter Krempa --- src/util/virhostcpu.c | 2 +- tests/virhostcpudata/linux-cpustat-24cpu.out | 8 ++++---- tests/virhostcpudata/linux-cpustat-24cpu.stat | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index 1db096ba24..f2b25e940b 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -882,7 +882,7 @@ virHostCPUGetStatsLinux(FILE *procstat, return -1; =20 if (virHostCPUStatsAssign(¶ms[4], VIR_NODE_CPU_STATS_GUEST, - guest * TICK_TO_NSEC) < 0) + (guest + guest_nice) * TICK_TO_NSEC)= < 0) return -1; return 0; } diff --git a/tests/virhostcpudata/linux-cpustat-24cpu.out b/tests/virhostcp= udata/linux-cpustat-24cpu.out index f3183f5c41..a975702a06 100644 --- a/tests/virhostcpudata/linux-cpustat-24cpu.out +++ b/tests/virhostcpudata/linux-cpustat-24cpu.out @@ -1,16 +1,16 @@ cpu: kernel: 8751170 user: 14128079 -idle: 1816344522 +idle: 1816344521 iowait: 81323 -guest: 5880634 +guest: 5880635 =20 cpu0: kernel: 447603 user: 749021 -idle: 75399242 +idle: 75399241 iowait: 5295 -guest: 331814 +guest: 331815 =20 cpu1: kernel: 167215 diff --git a/tests/virhostcpudata/linux-cpustat-24cpu.stat b/tests/virhostc= pudata/linux-cpustat-24cpu.stat index bc9d449e1c..e13035b5f0 100644 --- a/tests/virhostcpudata/linux-cpustat-24cpu.stat +++ b/tests/virhostcpudata/linux-cpustat-24cpu.stat @@ -1,5 +1,5 @@ -cpu 14126233 1846 7764352 1816344522 81323 395581 591237 0 5880634 0 -cpu0 748997 24 320851 75399242 5295 22050 104702 0 331814 0 +cpu 14126233 1846 7764352 1816344521 81323 395581 591237 0 5880634 1 +cpu0 748997 24 320851 75399241 5295 22050 104702 0 331814 1 cpu1 337325 1 140909 76178612 1121 8962 17344 0 166726 0 cpu2 666860 29 269302 75649696 4298 18473 21155 0 272094 0 cpu3 328387 77 211400 76131634 1219 9701 6573 0 115551 0 --=20 2.35.3