From 79a0ab5609786c7bc94719b83538b10e3a982b3d Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Wed, 21 Feb 2024 15:27:31 +0100 Subject: [PATCH] Add 'threads_per_core' in 'Host.cpu_info' Discussed here: https://github.com/xapi-project/xen-api/issues/5462 Signed-off-by: Benjamin Reis --- ocaml/tests/common/test_common.ml | 2 ++ ocaml/xapi-idl/xen/xenops_interface.ml | 1 + ocaml/xapi/cpuid_helpers.ml | 2 ++ ocaml/xapi/cpuid_helpers.mli | 2 ++ ocaml/xapi/create_misc.ml | 6 ++++-- ocaml/xenopsd/lib/xenops_server_skeleton.ml | 1 + ocaml/xenopsd/xc/xenops_server_xen.ml | 2 ++ 7 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ocaml/tests/common/test_common.ml b/ocaml/tests/common/test_common.ml index 786a6eaca61..d1433868fdc 100644 --- a/ocaml/tests/common/test_common.ml +++ b/ocaml/tests/common/test_common.ml @@ -42,6 +42,7 @@ let default_cpu_info = * localhost to be counted *) ("cpu_count", "0") ; ("socket_count", "0") + ; ("threads_per_core", "0") ; ("vendor", "Abacus") ; ("speed", "") ; ("modelname", "") @@ -77,6 +78,7 @@ let make_localhost ~__context ?(features = Features.all_features) () = { cpu_count= 1 ; socket_count= 1 + ; threads_per_core= 1 ; vendor= "" ; speed= "" ; modelname= "" diff --git a/ocaml/xapi-idl/xen/xenops_interface.ml b/ocaml/xapi-idl/xen/xenops_interface.ml index ab240a53cb5..083c345f149 100644 --- a/ocaml/xapi-idl/xen/xenops_interface.ml +++ b/ocaml/xapi-idl/xen/xenops_interface.ml @@ -461,6 +461,7 @@ module Host = struct type cpu_info = { cpu_count: int ; socket_count: int + ; threads_per_core: int ; vendor: string ; speed: string ; modelname: string diff --git a/ocaml/xapi/cpuid_helpers.ml b/ocaml/xapi/cpuid_helpers.ml index db346fcef27..571a7f073b6 100644 --- a/ocaml/xapi/cpuid_helpers.ml +++ b/ocaml/xapi/cpuid_helpers.ml @@ -43,6 +43,8 @@ let cpu_count = Map_check.(field "cpu_count" int) let socket_count = Map_check.(field "socket_count" int) +let threads_per_core = Map_check.(field "threads_per_core" int) + let vendor = Map_check.(field "vendor" string) let get_flags_for_vm ~__context vm cpu_info = diff --git a/ocaml/xapi/cpuid_helpers.mli b/ocaml/xapi/cpuid_helpers.mli index ee1fbeb0d26..4d5f091d7f6 100644 --- a/ocaml/xapi/cpuid_helpers.mli +++ b/ocaml/xapi/cpuid_helpers.mli @@ -28,6 +28,8 @@ val cpu_count : int Map_check.field val socket_count : int Map_check.field +val threads_per_core : int Map_check.field + val features : [`vm] Xenops_interface.CPU_policy.t Map_check.field val features_pv : [`host] Xenops_interface.CPU_policy.t Map_check.field diff --git a/ocaml/xapi/create_misc.ml b/ocaml/xapi/create_misc.ml index a0d14ae94b9..7a2630ea57f 100644 --- a/ocaml/xapi/create_misc.ml +++ b/ocaml/xapi/create_misc.ml @@ -567,6 +567,7 @@ let create_host_cpu ~__context host_info = [ ("cpu_count", string_of_int cpu_info.cpu_count) ; ("socket_count", string_of_int cpu_info.socket_count) + ; ("threads_per_core", string_of_int cpu_info.threads_per_core) ; ("vendor", cpu_info.vendor) ; ("speed", cpu_info.speed) ; ("modelname", cpu_info.modelname) @@ -592,10 +593,11 @@ let create_host_cpu ~__context host_info = let old_cpu_info = Db.Host.get_cpu_info ~__context ~self:host in debug "create_host_cpuinfo: setting host cpuinfo: socket_count=%d, \ - cpu_count=%d, features_hvm=%s, features_pv=%s, features_hvm_host=%s, \ - features_pv_host=%s" + cpu_count=%d, threads_per_core=%d, features_hvm=%s, features_pv=%s, \ + features_hvm_host=%s, features_pv_host=%s" (Map_check.getf socket_count cpu) (Map_check.getf cpu_count cpu) + (Map_check.getf threads_per_core cpu) (Map_check.getf features_hvm cpu |> CPU_policy.to_string) (Map_check.getf features_pv cpu |> CPU_policy.to_string) (Map_check.getf features_hvm_host cpu |> CPU_policy.to_string) diff --git a/ocaml/xenopsd/lib/xenops_server_skeleton.ml b/ocaml/xenopsd/lib/xenops_server_skeleton.ml index c688aa79233..dc1b826f85e 100644 --- a/ocaml/xenopsd/lib/xenops_server_skeleton.ml +++ b/ocaml/xenopsd/lib/xenops_server_skeleton.ml @@ -26,6 +26,7 @@ module HOST = struct { Host.cpu_count= 0 ; socket_count= 0 + ; threads_per_core= 0 ; vendor= "unknown" ; speed= "" ; modelname= "" diff --git a/ocaml/xenopsd/xc/xenops_server_xen.ml b/ocaml/xenopsd/xc/xenops_server_xen.ml index a04dabe98c6..4de4bbc3573 100644 --- a/ocaml/xenopsd/xc/xenops_server_xen.ml +++ b/ocaml/xenopsd/xc/xenops_server_xen.ml @@ -985,6 +985,7 @@ module HOST = struct let socket_count = p.nr_cpus / (p.threads_per_core * p.cores_per_socket) in + let threads_per_core = p.threads_per_core in let features = get_cpu_featureset xc Featureset_host in (* this is Default policy in Xen's terminology, used on boot for new VMs *) let features_pv_host = get_cpu_featureset xc Featureset_pv in @@ -1012,6 +1013,7 @@ module HOST = struct { Host.cpu_count ; socket_count + ; threads_per_core ; vendor ; speed ; modelname