This is an archive of the discontinued LLVM Phabricator instance.

[debugserver] This is a small cleanup patch to AVX support detection
ClosedPublic

Authored by beanz on Mar 13 2017, 3:50 PM.

Details

Summary

The first Sandybridge iMacs with AVX support shipped in Spring 2011 with Snow Leopard as their OS. Unfortunately due to a kernel bug debugging AVX code was not really possible until 10.7.4.

The old code here checked the kernel build number to determine when to support AVX, but that code was incorrect. It verified that the kernel build number was greater than xnu-2020, which is the build of the kernel that had the fix for 10.8. The fix was also back ported to 10.7.4. Which means all publicly available OS builds 10.7.4 and later have working AVX support.

This new patch verifies that the host OS is greater than or equal to 10.7.4 by checking that the build number is greater than or equal to 11Exx.

The patch also removes the HasAVX assembly blob in favor of querying the kernel via sysctl for the hardware features.

Using sysctl is slower, however since the code is executed once and the result cached it is a better approach because it is possible for the kernel to disable AVX support on hardware that supports it, so listening to the kernel is a better approach for the debugger to take.

Diff Detail

Repository
rL LLVM

Event Timeline

beanz created this revision.Mar 13 2017, 3:50 PM
beanz updated this revision to Diff 91640.Mar 13 2017, 3:52 PM

Removing some extra changes that accidentally came along for the ride in my initial upload.

jasonmolenda requested changes to this revision.Mar 13 2017, 4:09 PM

Looks good, a few small suggestions from reading the code afresh. I'm not sure how many open source contributors we may have running macOS 10.6 or earlier (or macOS 10.7.[1-3]) but keeping this code is probably still a good idea at this point.

tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
66 ↗(On Diff #91640)

I see what you're doing -- this can either return "false, meaning the sysctlbyname failed or I got a zero value, or true meaning it succeeded and I got a nonzero value" but the use of a bitwise AND is going to look like a bug to any casual reader and make them re-read the code a few times before they've realized it is intended (at least it did me). It might be easier for future maintainers if it's written more like like

if (error != 0 && answer != 0)

return true;

else

return false;

and let the compiler come up with the shorter form when generating the instructions.

99 ↗(On Diff #91640)

Would '@' be clearer here than 0x40? I had to run man ascii to figure out what this was. Maybe a comment saying that we expect the string from KERN_OSVERSION to be something like '11B156' & we're interested in the '11' bit would make it a little easier to read. (I had to run sysctl to look at the string you're parsing to follow along with the logic)

103 ↗(On Diff #91640)

Not a big deal but '\0'.

This revision now requires changes to proceed.Mar 13 2017, 4:09 PM

Hah, I misread what the 'buffer[first_letter] & 0x40' line was doing still. Maybe use isupper() here instead of the bitmask?

zturner added inline comments.
tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
66 ↗(On Diff #91640)

Maybe I'm missing something, but why not just return !error && answer?

beanz updated this revision to Diff 91643.Mar 13 2017, 4:23 PM
beanz edited edge metadata.

Updates based on feedback from Jason and Zachary.

jasonmolenda accepted this revision.Mar 13 2017, 4:25 PM

looks good to me.

tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
66 ↗(On Diff #91640)

That would be fine too. The bitwise in the original is correct, but needlessly confusing IMO.

99 ↗(On Diff #91640)

I misread this myself when writing the above. isupper() is what you're doing - I'd recommend using that instead of the bit mask.

This revision is now accepted and ready to land.Mar 13 2017, 4:25 PM
beanz updated this revision to Diff 91644.Mar 13 2017, 4:28 PM

Forgot a semi-colon...

This revision was automatically updated to reflect the committed changes.
lldb/trunk/tools/debugserver/source/MacOSX/CMakeLists.txt