This is an archive of the discontinued LLVM Phabricator instance.

[libc] Fix sched_getscheduler return value
ClosedPublic

Authored by mikhail.ramalho on Jul 31 2023, 8:27 AM.

Details

Summary

This patch fixes the return time for sched_getscheduler which was set to
always zero. The syscall documentation, however, defines:

On success, sched_getscheduler() returns the policy for the thread (a
nonnegative integer).

I also changed the return type for sched_setscheduler, but this change
didn't impact and test case.

This patch also removes the duplicated code from param_and_scheduler_test.cpp
and adds SCHED_BATCH and SCHED_IDLE to the tests.

Diff Detail

Event Timeline

Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 31 2023, 8:27 AM
mikhail.ramalho requested review of this revision.Jul 31 2023, 8:27 AM

Overall LGTM from my side but please wait for @michaelrj's review.

libc/test/src/sched/param_and_scheduler_test.cpp
40

I think the duplicated code is present to help with debugging.

michaelrj added inline comments.Jul 31 2023, 11:33 AM
libc/test/src/sched/param_and_scheduler_test.cpp
40

the reason these tests were separated to begin with is the ASSERT macro only reports the line its on. This makes it very hard to debug test failures where the error doesn't obviously map to a specific input to your test function. In this case I'd recommend making testSched a proper function, then making each of the calls its own TEST to solve that problem.

Minus test changes LGTM. But I am not a maintainer for this project so please wait on michael or sivachandras approval.

mikhail.ramalho updated this revision to Diff 546087.EditedAug 1 2023, 8:59 AM
  • Changed test case to should sched policy on failure, it should look like:
[ RUN      ] LlvmLibcSchedTest.Sched_SCHED_FIFO
/home/mgadelha/tools/llvm-project/libc/test/src/sched/param_and_scheduler_test.cpp:135: FAILURE
      Expected: __llvm_libc::sched_setscheduler(0, policy, nullptr)
      Which is: -1
To be equal to: 0
      Which is: 0
[  FAILED  ] LlvmLibcSchedTest.Sched_SCHED_FIFO

In this case, SCHED_FIFO was policy used.

  • Rebased
This revision is now accepted and ready to land.Aug 1 2023, 10:05 AM