-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[libc][sched] Implement CPU_ZERO, CPU_ISSET, CPU_SET macros
#131524
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
Conversation
Signed-off-by: krishna2803 <[email protected]>
Signed-off-by: krishna2803 <[email protected]>
Signed-off-by: krishna2803 <[email protected]>
Signed-off-by: krishna2803 <[email protected]>
Signed-off-by: krishna2803 <[email protected]>
Signed-off-by: krishna2803 <[email protected]>
| #define LLVM_LIBC_TYPES_CPU_SET_T_H | ||
|
|
||
| #define __CPU_SETSIZE 1024 | ||
| #define __NCPUBITS 8 * sizeof(unsigned long) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need parens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in c94712f1
Signed-off-by: krishna2803 <[email protected]>
| const size_t bit_position = static_cast<size_t>(cpu) % NCPUBITS; | ||
|
|
||
| const unsigned long mask = 1UL << bit_position; | ||
| return (set->__mask[element_index] & mask) != 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the standard say when these pointers are null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these macros are glibc extensions, the man page itself doesn't define a way to deal with null pointers. i found an implementation of those in glibc's code and surprisingly even that doesn't handle null pointers. ref:
#define __CPU_ISSET_S(cpu, setsize, cpusetp) \
(__extension__ \
({ size_t __cpu = (cpu); \
__cpu / 8 < (setsize) \
? ((((const __cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
& __CPUMASK (__cpu))) != 0 \
: 0; }))for implementing these macros (CPU_ZERO et al), i looked at our existing implementation for CPU_COUNT ref:
llvm-project/libc/src/sched/linux/sched_getcpucount.cpp
Lines 19 to 26 in c94712f
| LLVM_LIBC_FUNCTION(int, __sched_getcpucount, | |
| (size_t cpuset_size, const cpu_set_t *mask)) { | |
| int result = 0; | |
| for (size_t i = 0; i < cpuset_size / sizeof(long); ++i) { | |
| result += __builtin_popcountl(mask->__mask[i]); | |
| } | |
| return result; | |
| } |
and even that doesn't handle null pointers!
should i implement a nullptr guard for these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, can you add null check with https://github.com/llvm/llvm-project/blob/main/libc/src/__support/macros/null_check.h for these functions in this PR? Thanks,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done! 522c6697
|
|
||
| #include "src/__support/common.h" // LLVM_LIBC_FUNCTION | ||
| #include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL | ||
| #include "src/__support/common.h" // LLVM_LIBC_FUNCTION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Update the cmake dependency of these targets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done! 9b0d165e
Signed-off-by: krishna2803 <[email protected]>
This PR implements the following macros for
sched.h:CPU_ZEROCPU_ISSETCPU_SETFixes #124642