Skip to content

Implement itimer syscalls with generic timer handling framework#274

Open
arihant2math wants to merge 3 commits intohexagonal-sun:masterfrom
arihant2math:better-timers
Open

Implement itimer syscalls with generic timer handling framework#274
arihant2math wants to merge 3 commits intohexagonal-sun:masterfrom
arihant2math:better-timers

Conversation

@arihant2math
Copy link
Copy Markdown
Collaborator

Replaces #267 with a generic callback framework to handle arbitrary timers.

Interval timers are an POSIX feature and come in three forms (real, virtual, prof). This PR only implements itimers on the wall clock.

I've moved all the clock syscalls to src/clock/syscalls/

Known issues/followups/etc.:

  • We don't move tasks between CPUs, but if we did, removing an itimer might fail because removing from non-local wakeup queues isn't supported.
  • No support for virtual/prof, they likely can be implemented by doing a scheduler check before starting a task, however that requires some infrastructure.
  • Other timers depend on the current date, which can be adjusted and is different from wall time, so we need a separate wakeup queue for that.
  • Linux helps prevent interrupt spam by preventing interrupts from being scheduling too early in the future (i.e. interrupts must be scheduled atleast X nanoseconds in the future) and by grouping interrupts that are within ~50ns of each other, we probably should do this too.

Testing: usertest

@arihant2math arihant2math changed the title Implement itimer syscalls w/ generic framework Implement itimer syscalls with generic timer handling framework Apr 6, 2026
Comment thread src/clock/syscalls/itimer.rs
crate::drivers::timer::SYS_TIMER
.get()
.unwrap()
.schedule_timer(
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Should we also remove scheduled timers on task exit? in exit.rs, just iterate the namespace and call remove_scheduled_timer() for any that are set.

Comment thread src/process/clone.rs
fd_table: files,
cwd,
root,
i_timers: SpinLock::new(*current_task.i_timers.lock_save_irq()),
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Is this correct? According to the man page for timer_create():

Timers are not inherited by the child of a [fork(2)](https://man7.org/linux/man-pages/man2/fork.2.html), and are
       disarmed and deleted during an [execve(2)](https://man7.org/linux/man-pages/man2/execve.2.html).

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.

2 participants