Skip to content

introduce X86_FEATURES for linux glibc/musl #2942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

devnexen
Copy link
Contributor

@devnexen devnexen commented Oct 6, 2022

Closes #2929

@rust-highfive
Copy link

r? @Amanieu

(rust-highfive has picked a reviewer for you, use r? to override)

@devnexen devnexen force-pushed the hwcap_x86_linux branch 3 times, most recently from efdc47e to 2f146e9 Compare October 6, 2022 12:21
@devnexen devnexen marked this pull request as ready for review October 6, 2022 12:50
@JohnTitor
Copy link
Member

It's unfortunate that such a big change is introduced without a test, I'm not sure if it really fits the libc crate. Could you clarify why tests are missing and those should be here?

@devnexen
Copy link
Contributor Author

devnexen commented Oct 9, 2022

I m not sure it will be accepted since it s not really libc but more kernel space, it took me a while to add those :-) but I understand if you close.

@JohnTitor
Copy link
Member

@rust-lang/libc Any thoughts on this? I'm slightly in favor of closing this but if anyone has an objection, drop a comment here.

@thomcc
Copy link
Member

thomcc commented Oct 10, 2022

@devnexen is there a reason we can't cover these with tests? What header are they in?

@devnexen
Copy link
Contributor Author

They are in header only found in kernel source

@joshtriplett
Copy link
Member

I'd like to see these added. But is there some way we could avoid duplicating them between glibc and musl, and for that matter between x86 and x86-64? They're identical in all four cases.

In general, things from the Linux kernel headers should be identical across all C libraries.

@joshtriplett
Copy link
Member

👍, this new version looks much better to me, and seems reasonable to merge.

@JohnTitor Any objections, or would you be fine with merging this?

@JohnTitor
Copy link
Member

JohnTitor commented Oct 12, 2022

I'm still concerned these don't have a test.
And as far as I've noticed, these're also unstable, i.e. could be changed easily. Example commits are torvalds/linux@d45476d, torvalds/linux@356edec, torvalds/linux@f098add. Since we don't have any policy for the supported kernel version, we cannot change it soonish when something is changed/removed (currently we haven't changed/removed items directly but have deprecated them, moreover CI won't let us know about these changes :(). So I'm not sure if these really fit with this crate.

@devnexen
Copy link
Contributor Author

@JohnTitor has a point. Fine by me if we close it.

@joshtriplett
Copy link
Member

I don't think we can easily test these unless the kernel headers are available on the test system.

And I do think these are important for users making use of auxv.

@JohnTitor
Copy link
Member

Then these could be provided via another crate like mach on macOS.

@joshtriplett
Copy link
Member

My apologies, I only just now realized that this is adding all the CPU feature constants, not just those visible in auxv. This should only add those visible in binary form to userspace; the visible ones are stable.

@joshtriplett
Copy link
Member

Also, arguably, the visible ones should be moved to a uapi header in the kernel.

@JohnTitor
Copy link
Member

If you only add items that you want to use and these are stable and small enough to review, I'm fine to accept ignoring tests.

@JohnTitor
Copy link
Member

@devnexen Could you address #2942 (comment)? I think we could merge once it's done.

@JohnTitor
Copy link
Member

@joshtriplett Could you review the new diff?

pub const X86_FEATURE_AVX512BW: ::c_ulong = 288 + 30;
pub const X86_FEATURE_AVX512VL: ::c_ulong = 288 + 31;
pub const X86_FEATURE_AVX512_BF16: ::c_ulong = 384 + 5;
pub const X86_FEATURE_AVX512VBMIK: ::c_ulong = 512 + 1;
Copy link
Member

Choose a reason for hiding this comment

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

I can't find this feature name on torvalds/linux master, is this a typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point.

@workingjubilee
Copy link
Member

I don't know if we should be exposing these if they only are mentioned in the kernel, even if they are in the uapi headers (and they currently aren't, afaict) because as mentioned in #2713, pedantically but correctly, the libc is allowed to have a varying definition here, and I can't find them exposed by musl or glibc either.

This is traditionally something where people have just bypassed the libc and kernel by using the CPUID interface, because on x86, that doesn't require privileges.

@bors
Copy link
Contributor

bors commented Apr 18, 2023

☔ The latest upstream changes (presumably #3173) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing HWCAP definitions for x86_64
8 participants