Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions ocaml/xenopsd/lib/topology.ml
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,18 @@ module NUMA = struct
let compare (Node a) (Node b) = compare a b
end)

(* -1 in 32 bits *)
let unreachable_distance = 0xFFFFFFFF
let max_valid_distance = 0xFF

let self_distance = 10

let is_unreachable d = d > max_valid_distance || d < 0

let () =
(* 32-bit *)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit surprised that when this is read from Xen and converted to an int, that it is not sign extended and thus would be -1 in all cases. it seems we are currently treating the return value as an unsigned number.

assert (is_unreachable 0xFFFFFFFF) ;
(* 64-bit, the value returned by Xen could change *)
assert (is_unreachable ~-1)

(* no mutation is exposed in the interface, therefore this is immutable *)
type t = {
distances: int array array
Expand Down Expand Up @@ -198,10 +205,10 @@ module NUMA = struct
seq_range 0 (Array.length d)
|> Seq.filter_map (fun i ->
let self = d.(i).(i) in
if self <> unreachable_distance then
Some i
else
if is_unreachable self then
None
else
Some i
)
in
let numa_nodes = Seq.length valid_nodes in
Expand Down Expand Up @@ -235,7 +242,7 @@ module NUMA = struct
Array.iteri
(fun i node ->
let self = distances.(node).(node) in
if self <> unreachable_distance then
if not (is_unreachable self) then
node_cpus.(node) <- CPUSet.add i node_cpus.(node)
)
cpu_to_node ;
Expand All @@ -254,10 +261,8 @@ module NUMA = struct
|> Array.to_seqi
|> Seq.for_all (fun (i, row) ->
let d = distances.(i).(i) in
(d = unreachable_distance || d = self_distance)
&& Array.for_all
(fun d -> d >= self_distance || d = unreachable_distance)
row
(is_unreachable d || d = self_distance)
&& Array.for_all (fun d -> d >= self_distance || is_unreachable d) row
)
in

Expand Down
Loading