This is an archive of the discontinued LLVM Phabricator instance.

[libc] add CPU_COUNT macro and backing function
ClosedPublic

Authored by michaelrj on Oct 4 2022, 10:26 AM.

Details

Summary

Add the macro CPU_COUNT as well as a backing function to implement the
functionality.

Diff Detail

Event Timeline

michaelrj created this revision.Oct 4 2022, 10:26 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptOct 4 2022, 10:26 AM
michaelrj requested review of this revision.Oct 4 2022, 10:26 AM
sivachandra added inline comments.Oct 4 2022, 11:50 AM
libc/include/llvm-libc-macros/linux/sched-macros.h
14

These macros get activated only in the full build mode. So, do we really need a separate helper like CPU_COUNT_S? The internal function can be llvm libc only (as in full build only) and can take a single argument for the set?

libc/spec/gnu_ext.td
56

This should go into https://github.com/llvm/llvm-project/blob/main/libc/spec/llvm_libc_ext.td. Also, the function is really an internal function - it's name should have the __ prefix.

libc/src/sched/linux/sched_getcpucount.cpp
33

We can use __builtin_popcountl here as this function will only be used with LLVM libc's definition of cpu_set_t.

michaelrj updated this revision to Diff 465149.Oct 4 2022, 2:01 PM
michaelrj marked 2 inline comments as done.

move function definition into llvm_libc_ext.td
rename function to __sched_getcpucount

libc/include/llvm-libc-macros/linux/sched-macros.h
14

CPU_COUNT_S is another macro that linux defines, and given that that exists it makes more sense to have one internal function that takes the same arguments and just chain the macros like this.

libc/spec/gnu_ext.td
56

in that case I should probably also move __llvm_libc_syscall into llvm_libc_ext.td in a followup patch.

sivachandra accepted this revision.Oct 4 2022, 2:08 PM
sivachandra added inline comments.
libc/spec/gnu_ext.td
56

Yes, I missed that.

This revision is now accepted and ready to land.Oct 4 2022, 2:08 PM
michaelrj updated this revision to Diff 465201.Oct 4 2022, 3:22 PM

fix the non-full build and add a comment about the namespaced macro

This revision was landed with ongoing or failed builds.Oct 4 2022, 3:23 PM
This revision was automatically updated to reflect the committed changes.