Skip to content

Commit 709fc49

Browse files
thomassaBob Ball
authored andcommitted
CP-20679: Optimise some bits, simplify others
A small optimisation: pass the appropriate value of compatibility_metadata to the PGPU constructor, rather than creating the object and then populating the field afterwards. Doing this involved changing some of the underlying functions, and we make fewer database lookups now. Also the code now passes the correct debug-string to the xcp-idl xmlrpc call that fetches the gpgu metadata. Also removed some needless detail from a specified return-type in an mli file. Signed-off-by: Thomas Sanders <[email protected]>
1 parent 156a5f7 commit 709fc49

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

ocaml/xapi/xapi_gpumon.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ module Nvidia = struct
4242
let key = "nvidia"
4343

4444
(* N.B. the pgpu must be in the local host where this function runs *)
45-
let get_pgpu_compatibility_metadata ~__context ~pgpu =
45+
let get_pgpu_compatibility_metadata ~dbg ~pgpu_pci_address =
4646
let get = Gpumon_client.Client.Nvidia.get_pgpu_metadata in
47-
let pci = Db.PGPU.get_PCI ~__context ~self:pgpu in
48-
let address = Db.PCI.get_pci_id ~__context ~self:pci in
49-
[key, get "xapi_gpumon" address]
47+
[key, get dbg pgpu_pci_address]
5048

5149
end (* Nvidia *)

ocaml/xapi/xapi_gpumon.mli

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ module Nvidia : sig
2525
* is the opaque string of data from the graphics driver.
2626
* IMPORTANT: This must be called on the host that has the GPU installed in it. *)
2727
val get_pgpu_compatibility_metadata:
28-
__context:Context.t ->
29-
pgpu:[ `PGPU ] API.Ref.t ->
30-
(string * string Gpumon_client.Client.RPCM.t) list
28+
dbg: string ->
29+
pgpu_pci_address: string ->
30+
(string * string) list
3131

3232
end

ocaml/xapi/xapi_pgpu.ml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,19 @@ let calculate_max_capacities ~__context ~pCI ~size ~supported_VGPU_types =
2929
vgpu_type, max_capacity)
3030
supported_VGPU_types
3131

32-
let set_compatibility_metadata ~__context ~pgpu =
33-
let pci = Db.PGPU.get_PCI ~__context ~self:pgpu in
34-
if Db.PCI.get_vendor_id ~__context ~self:pci = Xapi_pci.id_of_int Xapi_vgpu_type.Nvidia.vendor_id then (
35-
let () = Db.PGPU.set_compatibility_metadata ~__context ~self:pgpu
36-
~value:(Xapi_gpumon.Nvidia.get_pgpu_compatibility_metadata ~__context ~pgpu)
37-
in ()
38-
)
32+
let fetch_compatibility_metadata ~__context ~pgpu_pci =
33+
if Db.PCI.get_vendor_id ~__context ~self:pgpu_pci =
34+
Xapi_pci.id_of_int Xapi_vgpu_type.Nvidia.vendor_id
35+
then (
36+
let dbg = Context.string_of_task __context in
37+
let pgpu_pci_address = Db.PCI.get_pci_id ~__context ~self:pgpu_pci in
38+
Xapi_gpumon.Nvidia.get_pgpu_compatibility_metadata ~dbg ~pgpu_pci_address
39+
) else []
40+
41+
let populate_compatibility_metadata ~__context ~pgpu ~pgpu_pci =
42+
let () = Db.PGPU.set_compatibility_metadata ~__context ~self:pgpu
43+
~value:(fetch_compatibility_metadata ~__context ~pgpu_pci)
44+
in ()
3945

4046
let create ~__context ~pCI ~gPU_group ~host ~other_config
4147
~supported_VGPU_types ~size ~dom0_access
@@ -49,12 +55,11 @@ let create ~__context ~pCI ~gPU_group ~host ~other_config
4955
~gPU_group ~host ~other_config ~size
5056
~supported_VGPU_max_capacities ~dom0_access
5157
~is_system_display_device
52-
~compatibility_metadata:[];
58+
~compatibility_metadata:(fetch_compatibility_metadata ~__context ~pgpu_pci:pCI);
5359
Db.PGPU.set_supported_VGPU_types ~__context
5460
~self:pgpu ~value:supported_VGPU_types;
5561
Db.PGPU.set_enabled_VGPU_types ~__context
5662
~self:pgpu ~value:supported_VGPU_types;
57-
set_compatibility_metadata ~__context ~pgpu;
5863
debug "PGPU ref='%s' created (host = '%s')" (Ref.string_of pgpu) (Ref.string_of host);
5964
pgpu
6065

@@ -191,7 +196,7 @@ let update_gpus ~__context =
191196
Db.PGPU.set_is_system_display_device ~__context
192197
~self:rf
193198
~value:is_system_display_device;
194-
set_compatibility_metadata ~__context ~pgpu:rf;
199+
populate_compatibility_metadata ~__context ~pgpu:rf ~pgpu_pci:pci;
195200
(rf, rc)
196201
with Not_found ->
197202
(* If a new PCI has appeared then we know this is a system boot.

0 commit comments

Comments
 (0)