From 8f13e6ecb3a8f26f5c81311e4b5909e1ab566530 Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Tue, 29 Sep 2020 03:47:57 -0700 Subject: [PATCH] Fix CPU core calculation Summary: The code that parses `/proc/cpuinfo` expects IDs to be sequential. This is not always the case, so keep track of which IDs appear instead of keeping the maximum, when counting. Reviewed By: jvillard Differential Revision: D23987776 fbshipit-source-id: 98d267560 --- infer/src/base/Utils.ml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/infer/src/base/Utils.ml b/infer/src/base/Utils.ml index bf7c663ae..410eb8976 100644 --- a/infer/src/base/Utils.ml +++ b/infer/src/base/Utils.ml @@ -469,23 +469,23 @@ let physical_cores () = let physical_or_core_regxp = Re.Str.regexp "\\(physical id\\|core id\\)[^0-9]+\\([0-9]+\\).*" in - let rec loop max_socket_id max_core_id = + let rec loop sockets cores = match In_channel.input_line ~fix_win_eol:true ic with | None -> - (max_socket_id + 1, max_core_id + 1) + (Int.Set.length sockets, Int.Set.length cores) | Some line when Re.Str.string_match physical_or_core_regxp line 0 -> ( let value = Re.Str.matched_group 2 line |> int_of_string in match Re.Str.matched_group 1 line with | "physical id" -> - loop (max value max_socket_id) max_core_id + loop (Int.Set.add sockets value) cores | "core id" -> - loop max_socket_id (max value max_core_id) + loop sockets (Int.Set.add cores value) | _ -> L.die InternalError "Couldn't parse line '%s' from /proc/cpuinfo." line ) | Some _ -> - loop max_socket_id max_core_id + loop sockets cores in - let sockets, cores_per_socket = loop 0 0 in + let sockets, cores_per_socket = loop Int.Set.empty Int.Set.empty in sockets * cores_per_socket )