[PATCH] util: extend virHostCPUGetInfo() for FreeBSD

Roman Bogorodskiy posted 1 patch 2 weeks, 2 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20260307094226.80560-1-bogorodskiy@gmail.com
src/util/virhostcpu.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
[PATCH] util: extend virHostCPUGetInfo() for FreeBSD
Posted by Roman Bogorodskiy 2 weeks, 2 days ago
Extend virHostCPUGetInfo() to report more data on FreeBSD, such as:

 - NUMA domain count
 - CPU core count
 - CPU threads per core count

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
---
 src/util/virhostcpu.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index 113aa6881e..7cecb4b2c8 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -1014,6 +1014,22 @@ virHostCPUGetInfo(virArch hostarch G_GNUC_UNUSED,
     *mhz = cpu_freq / 1000000;
 # endif
 
+# ifdef __FreeBSD__
+#  define FILL_DATA_SYSCTL(var, sysctl, error_msg) \
+    do { \
+        size_t _len = sizeof(*var); \
+        if (sysctlbyname(sysctl, var, &_len, NULL, 0) < 0) { \
+            virReportSystemError(errno, "%s", error_msg); \
+            return -1; \
+        } \
+    } while (0)
+
+    FILL_DATA_SYSCTL(nodes, "vm.ndomains", _("cannot obtain NUMA domain count"));
+    FILL_DATA_SYSCTL(cores, "kern.smp.cores", _("cannot obtain CPU core count"));
+    FILL_DATA_SYSCTL(threads, "kern.smp.threads_per_core",
+                      _("cannot obtain CPU threads per core"));
+# endif /* __FreeBSD__ */
+
     return 0;
 #else
     /* XXX Solaris will need an impl later if they port QEMU driver */
-- 
2.52.0
Re: [PATCH] util: extend virHostCPUGetInfo() for FreeBSD
Posted by Michal Prívozník via Devel 2 weeks ago
On 3/7/26 10:42, Roman Bogorodskiy wrote:
> Extend virHostCPUGetInfo() to report more data on FreeBSD, such as:
> 
>  - NUMA domain count
>  - CPU core count
>  - CPU threads per core count
> 
> Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
> ---
>  src/util/virhostcpu.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Michal