Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@alexandruradovici
Copy link
Contributor

Pull Request Overview

This pull request fixes the way in which ProcessStandard verifies if a process is ready to run. Additionally it changes the order in which Process::ready verifies the states, to return faster if a process is Running.

The Process::ready function was designed when the YieldedFor state did not exist. The function decides that a process is able to do work if it is in the Running state of if it has any scheduled tasks. This is correct if the process is Yielded, as any task can be dispatched to the process.

The function does not take into account that the process might be in the YieldedFor state, where only a specific task can be dispatched (returned) to the process.

This has a consequence for the scheduling. Suppose we have a scheduler that picks the process that has performed the minimum number of syscalls or has exceeded its timeslice the least times:

  1. the scheduler picks process A to run
  2. process A is in the YieldedFor state waiting for an action from process B (probably a custom IPC call implemented in a capsule)
  3. calling Process::ready for process A returns true as there are additional tasks in the queue, but not the one that the process yielded for
  4. the kernel tries to run the process and figures out that it cannot return any value, as the up call that the process expects is not in the tasks queue
  5. the kernel asks the scheduler for a new process
  6. the scheduler will pick the same process, as it is the one with the minimum values (of syscalls or timeslice expires)

The Process::ready function should take into account the YieldedFor case. There are two solutions here:

  1. Process::ready iterates the tasks and figures out if YieldedFor can return
  2. YieldedFor has an extra payload to store whether it can return or not and Process::ready reads that payload
    • every time an up call is scheduled, this payload is set to true
    • every time a process calls yield-wait-for, the queue is verified and the extra payload is set accordingly

This pull request uses the second approach, as it only needs to verify the tasks list when yield-wait-for is called or when an upcall is scheduled. The first approach would iterate the tasks list at every time Process::ready is called, that is often.

Testing Strategy

This pull request was tested by @alexandruradovici.

TODO or Help Wanted

Feedback

Documentation Updated

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make prepush.

Copy link
Contributor

@bradjc bradjc left a comment

Choose a reason for hiding this comment

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

Approach 1 would be a lot simpler. Not sure I'm convinced it's worth it to modify the State.

@alexandruradovici
Copy link
Contributor Author

Approach 1 would be a lot simpler. Not sure I'm convinced it's worth it to modify the State.

Agree, but ready is called very often and will induce a penalty.

Copy link
Contributor

@brghena brghena left a comment

Choose a reason for hiding this comment

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

This is good overall. A couple of small things, notably I think there's a logic bug.

Comment on lines +438 to +444
/// Modify the yielded-for-state to signal that there is an upcall
/// scheduled for `UpcallId`.
///
/// This will fail (i.e. not do anything) if the process was not previously
/// running.
fn set_yielded_for_state_ready(&self, upcall_id: UpcallId);

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add this to enqueue_task rather than adding a new API?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants