[erlang-questions] FreeBSD cpu topology detection

Garret Smith garret.smith@REDACTED
Mon Oct 20 22:27:58 CEST 2014


On Sun, Oct 19, 2014 at 8:37 AM, Paul Guyot <pguyot@REDACTED> wrote:
>
>>>> No one reported that topology detection worked.
>>
>> Well, you didn't ask for that information.:-) Nor did you mention either
>> the FreeBSD or the OTP version where you were seeing the problem...
>> FWIW, it seems to work just fine for me on the 2-core/4-logical and
>> 4-core/8-logical FreeBSD systems I use regularly, with a variety of
>> FreeBSD and OTP versions. I'm also pretty sure Raimo would have
>> mentioned if it was broken on any of his machines.
>>
>> Since another poster also saw the problem, and mentioned that he was
>> running FreeBSD 10.something, it might be a FreeBSD-10-specific problem
>> - personally I haven't tried Erlang/OTP on FreeBSD-10 yet.
>
> I am amazed that the parser is written (which I authored) instead of being debugged… I don't mean it's exceptional code, and it actually needed more love and especially tests…
>
> The issue is not FreeBSD 10 but rather FreeBSD 10's default compiler (clang). There was a bug in this code with an undefined behavior. Older versions of gcc (which we use) behave as expected by the code, while clang and gcc devel (4.9) do not (only gcc 4.9 warns about it).
>
> I pushed a three-line fix :
> https://github.com/pguyot/otp/commit/c8ae3f2797d9c613e07b916683c51efea2da81aa
>
> This fix has the advantage of not introducing unwanted regression.
>
> Garret, could you please test it and determine if it works for you?
> I am definitely willing to debug this old code if you do provide unworking outputs of kern.sched.topology_spec.
>
> As a side note, I'm wondering why your code reads the number of cores with sysctl kern.smp.cpus. This is filled by the emulator upstream.
>
> Paul
> --
> Semiocast            http://semiocast.com/
> +33.183627948 - 20 rue Lacaze, 75014 Paris
>

I had tried quite a few things with the existing code before giving
up, including the FreeBSD port, manual compile with clang 3.4.1 and
gcc 4.8.3.  Apparently gcc 4.8.3 isn't old enough to have the proper
undefined behavior.  I was expecting some change in the XML on FreeBSD
10.1.

I used kern.smp.cpus sysctl to pre-allocate all erts_cpu_topology_t
and avoid the realloc as you have on lines 1500 and 1627.  Not sure
why this might be necessary since a difference in the number of
(logical) CPUs read from the topology and sysctl should be an error.

The patch you provided fixes CPU topology detection on my machine with
both clang 3.4.1 and gcc 4.8.3.

-Garret



More information about the erlang-questions mailing list