Permalink
Browse files

Number of cores detection fix: single-core CPUs;

The original code expected this structure:

1> erlang:system_info(cpu_topology).
[{processor,[{core,[{thread,{logical,0}},
                    {thread,{logical,1}}]},
             {core,[{thread,{logical,2}},{thread,{logical,3}}]},
             {core,[{thread,{logical,4}},{thread,{logical,5}}]},
             {core,[{thread,{logical,6}},{thread,{logical,7}}]}]}]

...while on some single-core (yet with multiple physical CPUs),
the result of the same function looks like:

1> erlang:system_info(cpu_topology).
[{processor,{logical,0}},{processor,{logical,1}}]
  • Loading branch information...
1 parent f3eb1f1 commit e5cad5f8373e96714fddb184f1953cb5875e63ec Tomas Morstein committed Apr 6, 2013
Showing with 7 additions and 3 deletions.
  1. +7 −3 src/stdinout_pool_server.erl
@@ -36,10 +36,14 @@ count_cpus(undefined, Count) ->
Count;
count_cpus([], Count) ->
Count;
-count_cpus([{node, [{processor, Cores}]} | T], Count) ->
+count_cpus([{node, [{processor, Cores}]} | T], Count) when is_list (Cores) ->
count_cpus(T, Count + length(Cores));
-count_cpus([{processor, Cores} | T], Count) ->
- count_cpus(T, Count + length(Cores)).
+count_cpus([{node, [{processor, _}]} | T], Count) ->
+ count_cpus(T, Count + 1);
+count_cpus([{processor, Cores} | T], Count) when is_list (Cores) ->
+ count_cpus(T, Count + length(Cores));
+count_cpus([{processor, _} | T], Count) ->
+ count_cpus(T, Count + 1).
%%====================================================================
%% gen_server callbacks

0 comments on commit e5cad5f

Please sign in to comment.