Skip to content
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

Add realtime scheduling calls to std.os.linux (issue #19671) #19675

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

curuvar
Copy link

@curuvar curuvar commented Apr 17, 2024

Add the following system calls to std.os.linux:

  • sched_setscheduler
  • sched_getscheduler
  • sched_setparam
  • sched_getparam
  • sched_get_priority_min
  • sched_get_priority_max

Also add required sched_param structure and SCHED constant definitions:

  • pub const sched_param
  • pub const SCHED

sched_priority: i32,
};

pub const SCHED = struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

should this not be an enum, rather than a struct?

Copy link
Author

Choose a reason for hiding this comment

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

The problem with it being an enum is that the RESET_ON_FORK is not an independent value, but a flag that is ORed with one of the other values.

Copy link
Contributor

@rohlem rohlem Apr 17, 2024

Choose a reason for hiding this comment

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

I think the recommended thing to do would be to make it a packed struct, something like this (untested):

pub const SCHED = packed struct(i32) {
  pub const Mode = enum(u3) {
    /// normal multi-user scheduling
    pub const OTHER = 0;
    /// FIFO realtime scheduling
    pub const FIFO = 1;
    /// Round-robin realtime scheduling
    pub const RR = 2;
    /// For "batch" style execution of processes
    pub const BATCH = 3;
    /// Low latency scheduling
    pub const ISO = 4;
    /// For running very low priority background jobs
    pub const IDLE = 5;
    /// Sporadic task model deadline scheduling
    pub const DEADLINE = 6;
  };
  mode: Mode, //bits [0, 2]
  _3: u27 = 0, //bits [3, 29]
  /// set to true to stop children from inheriting policies
  RESET_ON_FORK: bool = false, //bit 30
  _31: u1 = 0, //bit 31
}

Copy link
Author

Choose a reason for hiding this comment

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

Thank you. I will update my code accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants