Implements: https://linux.die.net/man/2/sched_yield
Possibly we don't need the return value check / errno as according to
both the manpage (and current linux source) sched_yield cannot fail.
Differential D147985
[LIBC] Implement `sched_yield()` goldstein.w.n on Apr 10 2023, 6:07 PM. Authored by
Details
Implements: https://linux.die.net/man/2/sched_yield Possibly we don't need the return value check / errno as according to
Diff Detail
Event TimelineComment Actions The function looks good, but since you're adding a new function there's a bit of extra configuration that needs to be done. I'll walk you through it here, but if you want an example then this patch should also show what needs to be done: https://reviews.llvm.org/D147970. First, we need the function to have a FunctionSpec in the spec/ folder. For this function it will be in spec/gnu_ext.td, alongside sched_getaffinity. I know this looks like a lot, but each part should be fairly quick. Feel free to reach out if you want more guidance on how to do it. Comment Actions Done, thanks for the guidance. As an aside, are you planning to implement anything along the lines of gnu ifunc? If not is the method Also are you guys planning on implementing dynamic loader? Comment Actions
Yes, the method is to build with architecture-specific flags. You can see examples of this in files like https://github.com/llvm/llvm-project/blob/main/libc/src/string/memory_utils/op_x86.h and https://github.com/llvm/llvm-project/blob/main/libc/src/math/generic/sinf.cpp The model is to consider the libc functions as just another part of your application code that gets statically linked in. So you build the libc with the same optimization level, sanitizers, architecture defines, etc. you build your application with, and then deploy appropriately.
At some point, though it's not a current area of investment for anyone. If this is an area that interests you, patches are welcome! Comment Actions You're just missing the test file then I'll approve.
Comment Actions LGTM with nit
Comment Actions OK from my side but please wait for @michaelrj who is leading this review.
Comment Actions good catch that this should be in posix, it should be good to go once you make this change, if you want to make sure that everything is working then run ninja libc-integration-tests as well as check-libc
|
@michaelrj are you sure this is the right place for sched_yield. Seems to be part of POSIX specification:
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sched.h.html