Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: sched_setscheduler() gets EINVAL for normal policies #105

Merged
merged 1 commit into from
Dec 7, 2023

Conversation

taoky
Copy link
Contributor

@taoky taoky commented Jul 31, 2023

By stracing system76-scheduler daemon, it could be found that most calls to sched_setscheduler() returns EINVAL:

sched_setscheduler(2730973, SCHED_IDLE, [1]) = -1 EINVAL (Invalid argument)
sched_setscheduler(2730974, SCHED_IDLE, [1]) = -1 EINVAL (Invalid argument)
sched_setscheduler(2730975, SCHED_IDLE, [1]) = -1 EINVAL (Invalid argument)
sched_setscheduler(2730984, SCHED_OTHER, [1]) = -1 EINVAL (Invalid argument)
sched_setscheduler(2730985, SCHED_OTHER, [1]) = -1 EINVAL (Invalid argument)
sched_setscheduler(2730986, SCHED_OTHER, [1]) = -1 EINVAL (Invalid argument)
sched_setscheduler(2730987, SCHED_OTHER, [1]) = -1 EINVAL (Invalid argument)
^Cstrace: Process 2730332 detached

In sched_setscheduler(2) it says that:

       Currently, Linux supports the following "normal" (i.e., non-real-time)  scheduling
       policies as values that may be specified in policy:

       SCHED_OTHER   the standard round-robin time-sharing policy;

       SCHED_BATCH   for "batch" style execution of processes; and

       SCHED_IDLE    for running very low priority background jobs.

       For each of the above policies, param->sched_priority must be 0.

       Various  "real-time" policies are also supported, for special time-critical appli‐
       cations that need precise control over the way in which runnable threads  are  se‐
       lected  for execution.  For the rules governing when a process may use these poli‐
       cies, see sched(7).  The real-time policies that may be specified in policy are:

       SCHED_FIFO    a first-in, first-out policy; and

       SCHED_RR      a round-robin policy.

       For each of the above policies, param->sched_priority specifies a scheduling  pri‐
       ority  for  the  thread.   This  is  a  number  in  the  range returned by calling
       sched_get_priority_min(2) and sched_get_priority_max(2) with the specified policy.
       On Linux, these system calls return, respectively, 1 and 99.
...
...
...
       EINVAL (sched_setscheduler()) param does not make sense for the specified policy.

Thus SchedPriority is only meaningful for FIFO & RR policy. This PR tries addressing this bug by using sched_priority value in set_policy() only when the policy is a real-time one.

In sched_setscheduler(2):
For each of the above policies (other batch rr),
param->sched_priority must be 0.
However, currently SchedPriority is set to 1 by default,
which causes sched_setscheduler() gets EINVAL errno.
@mmstick mmstick requested a review from a team July 31, 2023 12:36
@jacobgkau jacobgkau self-assigned this Jul 31, 2023
@gabriele2000
Copy link

Any news on this?

@jackpot51
Copy link
Member

Any news on this?

We will get this QA'd and merged soon.

Copy link
Member

@jacobgkau jacobgkau left a comment

Choose a reason for hiding this comment

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

Sorry for the delay in getting to this.

I confirmed this change makes the -1 EINVAL (Invalid argument) lines (when switching focus between windows) go away.

Regression testing passed:

  • Focus-based assignments are working with the default config (both .debs and Flatpaks).
  • Focus-based assignments work with custom values in /etc.
  • nice -n # works with the default config.
  • A custom profile with no niceness defined still has foreground/background applied.
    • Only foreground niceness is applied in this situation. (Not a regression.)
  • A custom profile with a niceness defined inline (under process-scheduler/) works.
  • A custom profile with a niceness defined separately (in config.kdl) works.
  • Config reloading works with system76-scheduler daemon reload, systemctl reload com.system76.Scheduler.service, and systemctl restart com.system76.Scheduler.service.
  • PipeWire integration works; when an app starts playing audio, it's assigned the niceness of the pipewire group and retains it until it's closed. It gets regular foreground/background niceness again when it's relaunched (or sooner if the audio stream stops.)
  • After disabling the foreground/background profiles, other profiles still work.

@mmstick mmstick merged commit b8d6545 into pop-os:master Dec 7, 2023
4 of 5 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants