From nobody Tue Sep 9 23:41:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; 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 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1748756577621720.9079218875157; Sat, 31 May 2025 22:42:57 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 90A3712B1; Sun, 1 Jun 2025 01:42:56 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 1C5791357; Sun, 1 Jun 2025 01:41:52 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id BFEAF1298; Sun, 1 Jun 2025 01:41:46 -0400 (EDT) Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 09DC01182 for ; Sun, 1 Jun 2025 01:41:46 -0400 (EDT) Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-6046ecc3e43so5515915a12.3 for ; Sat, 31 May 2025 22:41:45 -0700 (PDT) Received: from tulp.my.domain (80-115-115-199.cable.dynamic.v4.ziggo.nl. [80.115.115.199]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-adb35af4456sm399732266b.182.2025.05.31.22.41.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 May 2025 22:41:43 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748756504; x=1749361304; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nBxpdXkDxPeM5AeA/n7ILT9lQg+ISgquul0qtl1WpYw=; b=S1AxlLs/dnyNjb6LIaEd3IyMObK1XjOWzlk7V18wl/ojq61UvuCCVX9N/hfb4IKyee KJmnYBtzVfRs88tnwHyNtbGfb1eZmR2OxqPWvslT9zjhwvXd3js2aPcT5jrQGYGv4vcs L4gyNUPHTJ11UHsc57p1CDVGVBKxKSpiifjhhunRZCk/2PrpuARCMpHDwAxJtWIRc0sT GWVQ46IZ7douJxHy2TN68VpgCP2L8X9gY7jItrSCxDxQouJAsjW4n3djWWKXn30eZi1O mIYyOz4varVUQDjvcsbJsE0j0gCSzuUPeZ3ALmdFFw2O0h0Jf9hMas+LW06kz1WG1JL9 y3Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748756504; x=1749361304; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nBxpdXkDxPeM5AeA/n7ILT9lQg+ISgquul0qtl1WpYw=; b=i6KfRg8YQU/n3fxi2re9SLppvbo0Pt5wSYbmMcujM9m21L8okNpWR03RUAni/jodtc HHM53Y5A6tPFXXdCrYdr02Qg30Bh3MIQ9QknqAUyE01wWn3P28vx3rceVvhl/Yl0ZeFe cnaf8dz0Y32G6ujGyQO/QC3w1oBfr0MeUP5/rjATIGDI8BuptoMrhE1bvJSg+bVrSDmY rQOL1/JFSLWkZ2CjiWRNkETUNnmi7zpeK8Y9ELw9RyG++TnuHIcT9yU5rJtGZyNnTljq UwYHYxrf8aC4HNtdAzovTNYOeyfqhrBrQWWXagyea/xRsFhUM0sOTGUDWCj3bbqO4XDU HsWg== X-Gm-Message-State: AOJu0YyFU37yXWPABdJaVQvPIMLUS1CfZAHc4berUAYNr8vjd8C7OMIM 7JzJC7U1YTCXEZjceumvFeh/ZZCg5m7+PfbuORqOW/4G0exCb4TvII/hbLkg43R0JJo= X-Gm-Gg: ASbGncuYbcg1t7+LSlXjOZpNM7crzf2ZC2XO8wHbcHONHBy9K+ffoPOUcoAYFxhVlAM S1jAKqA4is7D9TpzdFIhVGOMCa0lXenYlqNGEMJNWhIFnihmvYKhOVIARDGpLWNbi5jnmSTzCN/ 35n1XgrmxDtzLZ1rhFluK+AWD0pZpp11+WtOaF/vv9xt34ZWE1H1512xD5zhpAkoqRl2DhqySDk W7RuKCljKr0TGPa4JwfeO+iHG3sC9ZHgglGNos9Cm0eZ81NFYmbV6W65Vyr4gA5erZdvrSre8Tv cCc2KJHssTweHsFLiif6E6eFuHRog9p9iAbFQtcLirajFEdm4USSjypzYAgkcoUoZWGY02iO7X4 36v20q8vGbSTaer5j2R823ar1 X-Google-Smtp-Source: AGHT+IGqdFHwugNTzuqDnChRtgcK8NHGZBSiO34HzfK5zZ3DuArHGYCilJGEcaKOgxEuCJC83tEwkA== X-Received: by 2002:a17:907:2cc2:b0:ad5:3156:2c0c with SMTP id a640c23a62f3a-adb322afceamr819995666b.26.1748756504220; Sat, 31 May 2025 22:41:44 -0700 (PDT) From: Roman Bogorodskiy To: devel@lists.libvirt.org Subject: [PATCH v2 2/4] virprocess: implement virProcessGetStatInfo() for FreeBSD Date: Sun, 1 Jun 2025 07:40:24 +0200 Message-ID: <20250601054026.59551-3-bogorodskiy@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250601054026.59551-1-bogorodskiy@gmail.com> References: <20250601054026.59551-1-bogorodskiy@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: UDGYXXVXD5S5PK65W2WKHJHLX7FAHZGR X-Message-ID-Hash: UDGYXXVXD5S5PK65W2WKHJHLX7FAHZGR X-MailFrom: bogorodskiy@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Roman Bogorodskiy X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748756579799116600 Content-Type: text/plain; charset="utf-8" Use the "kern.proc.pid" sysctl and retrieve information from the kinfo_proc struct. Signed-off-by: Roman Bogorodskiy --- src/util/virprocess.c | 104 +++++++++++++++++++++++++++++++----------- 1 file changed, 78 insertions(+), 26 deletions(-) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 05db76d834..3889ba90f9 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1812,7 +1812,85 @@ virProcessGetStatInfo(unsigned long long *cpuTime, =20 return 0; } +#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +int +virProcessGetStatInfo(unsigned long long *cpuTime, + unsigned long long *userTime, + unsigned long long *sysTime, + int *lastCpu, + unsigned long long *vm_rss, + pid_t pid, + pid_t tid) +{ + struct kinfo_proc p; + int mib[4]; + size_t len =3D 4; + unsigned long long utime =3D 0; + unsigned long long stime =3D 0; + unsigned long long rss =3D 0; + int cpu =3D 0; + const long pagesize =3D virGetSystemPageSizeKB(); + + sysctlnametomib("kern.proc.pid", mib, &len); + + len =3D sizeof(struct kinfo_proc); + mib[3] =3D pid; + + if (sysctl(mib, 4, &p, &len, NULL, 0) < 0) { + virReportSystemError(errno, "%s", + _("Unable to query process stats")); + return -1; + } + + utime =3D p.ki_rusage.ru_utime.tv_sec; + stime =3D p.ki_rusage.ru_stime.tv_sec; + rss =3D p.ki_rssize * pagesize; + cpu =3D p.ki_lastcpu_old; + + if (cpuTime) + *cpuTime =3D utime + stime; + if (userTime) + *userTime =3D utime; + if (sysTime) + *sysTime =3D stime; + if (lastCpu) + *lastCpu =3D cpu; + if (vm_rss) + *vm_rss =3D rss; + + VIR_DEBUG("Got status for %d/%d user=3D%llu sys=3D%llu cpu=3D%d rss=3D= %lld", + (int) pid, tid, utime, stime, cpu, rss); + + return 0; +} +#else +int +virProcessGetStatInfo(unsigned long long *cpuTime, + unsigned long long *userTime, + unsigned long long *sysTime, + int *lastCpu, + unsigned long long *vm_rss, + pid_t pid G_GNUC_UNUSED, + pid_t tid G_GNUC_UNUSED) +{ + /* We don't have a way to collect this information on non-Linux + * platforms, so just report neutral values */ + if (cpuTime) + *cpuTime =3D 0; + if (userTime) + *userTime =3D 0; + if (sysTime) + *sysTime =3D 0; + if (lastCpu) + *lastCpu =3D 0; + if (vm_rss) + *vm_rss =3D 0; + + return 0; +} +#endif =20 +#ifdef __linux__ int virProcessGetSchedInfo(unsigned long long *cpuWait, pid_t pid, @@ -1879,33 +1957,7 @@ virProcessGetSchedInfo(unsigned long long *cpuWait, =20 return 0; } - #else -int -virProcessGetStatInfo(unsigned long long *cpuTime, - unsigned long long *userTime, - unsigned long long *sysTime, - int *lastCpu, - unsigned long long *vm_rss, - pid_t pid G_GNUC_UNUSED, - pid_t tid G_GNUC_UNUSED) -{ - /* We don't have a way to collect this information on non-Linux - * platforms, so just report neutral values */ - if (cpuTime) - *cpuTime =3D 0; - if (userTime) - *userTime =3D 0; - if (sysTime) - *sysTime =3D 0; - if (lastCpu) - *lastCpu =3D 0; - if (vm_rss) - *vm_rss =3D 0; - - return 0; -} - int virProcessGetSchedInfo(unsigned long long *cpuWait, pid_t pid G_GNUC_UNUSED, --=20 2.49.0