Skip to content

CristianSLazar/Process-scheduler

Repository files navigation

Copyright Cristian-Stefan Lazar 324CA

crate Scheduler

This crate provides implementation for 3 schedulers:

  • Round Robin
  • Round Robin with priorities
  • Completely Fair Scheduler (CFS)
Expand description

Data structure that implements a round robin scheduler.

Fields§

§running_process: Option<Pcb>

The process running on the processor.

§stopped_process: Option<Pcb>

Intermediate state a process is in during syscalls.

§remaining_time: usize

The remaining execution time for the scheduled process.

§ready_processes: Vec<Pcb>

The list of all processes ready to be scheduled.

§waiting_processes: Vec<Pcb>

The list of all processes waiting for an event or sleeping.

§timeslice: NonZeroUsize

The amount of time a ready process gets on the processor.

§minimum_remaining_timeslice: usize

The minimum required time on the processor the stopped process must have remaining for it to be scheduled imediately after the syscall that stopped it.

§highest_pid: usize

The highest pid given to a process.

§sleep_time: usize

The amount of time the processor needs to sleep for a process to wake up if there are no ready processes to schedule. Is 0 if there are ready processes.

Implementations§

§

pub fn new(timeslice: NonZeroUsize, minimum_remaining_timeslice: usize) -> Self

Creates a new RoundRobinScheduler.

fn increment_timings(&mut self, _reason: &StopReason)

Increments the timings for all processes.

fn wakeup_processes(&mut self)

Moves processes that have waked up into the list of ready processes.

fn sleep(&mut self)

Sleeps for the amount of time needed for a process to become ready for scheduling.

fn new_process(&mut self, priority: i8)

Forks a new process with the given priority.

fn set_ready(&mut self, process: Pcb)

Sets a process into the ready state.

fn set_running(&mut self, process: Pcb)

Sets a process to into the running state.

fn is_done(&self) -> bool

Returns true if there are no more processes, false otherwise.

fn pid_1_exists(&self) -> bool

Returns true if the process with pid 1 exists, false otherwise.

fn scheduled_process(&mut self) -> Option<Pcb>

Returns the process scheduled to be run.

Returns the minimal amount of time the processor needs to sleep for a process to become ready for scheduling.

fn get_all_processes(&self) -> Vec<&Pcb>

Return an vector of refrences to all processes.

fn syscall_handler(
    &mut self,
    syscall: Syscall,
    remaining_time: usize
) -> SyscallResult

Handles syscalls recievied from the running process.

Trait Implementations§

§
§

fn next(&mut self) -> SchedulingDecision

Returns the action that the OS has to perform next.
§

fn stop(&mut self, _reason: StopReason) -> SyscallResult

The scheduler is informed about the stopping of a process and the reason.
§

fn list(&mut self) -> Vec<&dyn Process>

Returns the list of processes.

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for Twhere
    T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · §

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · §

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

const: unstable · §

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · §

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for Twhere
    U: Into<T>,

§
The type returned in the event of a conversion error.
const: unstable · §

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · §

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Expand description

Data structure that implements a round robin scheduler.

Fields§

§running_process: Option<Pcb>

The process running on the processor.

§stopped_process: Option<Pcb>

Intermediate state a process is in during syscalls.

§remaining_time: usize

The remaining execution time for the scheduled process.

§ready_processes: Vec<Vec<Pcb>>

The list of process queues, separated by priority.

§waiting_processes: Vec<Pcb>

The list of all processes waiting for an event or sleeping.

§timeslice: NonZeroUsize

The amount of time a ready process gets on the processor.

§minimum_remaining_timeslice: usize

The minimum required time on the processor the stopped process must have remaining for it to be scheduled imediately after the syscall that stopped it.

§highest_pid: usize

The highest pid given to a process.

§sleep_time: usize

The amount of time the processor needs to sleep for a process to wake up if there are no ready processes to schedule. Is 0 if there are ready processes.

Implementations§

§

pub fn new(timeslice: NonZeroUsize, minimum_remaining_timeslice: usize) -> Self

fn wakeup_processes(&mut self)

Moves processes that have waked up into the list of ready processes.

fn increment_timings(&mut self, _reason: &StopReason)

Increments the timings for all processes.

fn sleep(&mut self)

Sleeps for the amount of time needed for a process to become ready for scheduling.

fn new_process(&mut self, priority: i8)

Forks a new process with the given priority.

fn syscall_handler(
    &mut self,
    syscall: Syscall,
    remaining_time: usize
) -> SyscallResult

Handles syscalls recievied from the running process.

fn is_done(&self) -> bool

Returns true if there are no more processes, false otherwise.

fn pid_1_exists(&self) -> bool

Returns true if the process with pid 1 exists, false otherwise.

fn scheduled_process(&mut self) -> Option<Pcb>

Returns the process scheduled to be run.

Returns the minimal amount of time the processor needs to sleep for a process to become ready for scheduling.

fn set_ready(&mut self, process: Pcb)

Sets a process into the ready state.

fn set_running(&mut self, process: Pcb)

Sets a process to into the running state.

fn get_all_processes(&self) -> Vec<&Pcb>

Return an vector of refrences to all processes.

Trait Implementations§

§
§

fn next(&mut self) -> SchedulingDecision

Returns the action that the OS has to perform next.
§

fn stop(&mut self, _reason: StopReason) -> SyscallResult

The scheduler is informed about the stopping of a process and the reason.
§

fn list(&mut self) -> Vec<&dyn Process>

Returns the list of processes.

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for Twhere
    T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · §

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · §

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

const: unstable · §

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · §

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for Twhere
    U: Into<T>,

§
The type returned in the event of a conversion error.
const: unstable · §

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · §

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Expand description

Data structure that implements a round robin scheduler.

Fields§

§running_process: Option<Pcb>

The process running on the processor.

§stopped_process: Option<Pcb>

Intermediate state a process is in during syscalls.

§remaining_time: usize

The remaining execution time for the scheduled process.

§ready_processes: Vec<Pcb>

The list of all processes ready to be scheduled.

§waiting_processes: Vec<Pcb>

The list of all processes waiting for an event or sleeping.

§cpu_time: NonZeroUsize

The amount of time a ready process gets on the processor.

§minimum_remaining_timeslice: usize

The minimum required time on the processor the stopped process must have remaining for it to be scheduled imediately after the syscall that stopped it.

§highest_pid: usize

The highest pid given to a process.

§sleep_time: usize

The amount of time the processor needs to sleep for a process to wake up if there are no ready processes to schedule. Is 0 if there are ready processes.

Implementations§

§

impl Cfs

pub fn new(cpu_time: NonZeroUsize, minimum_remaining_timeslice: usize) -> Self

Creates a new Cfs.

fn increment_timings(&mut self, _reason: &StopReason)

Increments the timings for all processes.

fn wakeup_processes(&mut self)

Moves processes that have waked up into the list of ready processes.

fn sleep(&mut self)

Sleeps for the amount of time needed for a process to become ready for scheduling.

fn new_process(&mut self, priority: i8, vruntime: usize)

Forks a new process with the given priority.

fn size(&self) -> usize

Returns the total number of processes.

fn set_ready(&mut self, process: Pcb)

Sets a process into the ready state.

fn set_running(&mut self, process: Pcb, timeslice: usize)

Sets a process to into the running state.

fn is_done(&self) -> bool

Returns true if there are no more processes, false otherwise.

fn pid_1_exists(&self) -> bool

Returns true if the process with pid 1 exists, false otherwise.

fn scheduled_process(&mut self) -> Option<Pcb>

Returns the process scheduled to be run.

Returns the minimal amount of time the processor needs to sleep for a process to become ready for scheduling.

fn get_all_processes(&self) -> Vec<&Pcb>

Return an vector of refrences to all processes.

fn min_vruntime(&self) -> usize

Gets the minimum timeslice from all processes.

Computes the timeslice for the scheduled process.

fn syscall_handler(
    &mut self,
    syscall: Syscall,
    remaining_time: usize
) -> SyscallResult

Handles syscalls recievied from the running process.

Trait Implementations§

§

impl Scheduler for Cfs

§

fn next(&mut self) -> SchedulingDecision

Returns the action that the OS has to perform next.
§

fn stop(&mut self, _reason: StopReason) -> SyscallResult

The scheduler is informed about the stopping of a process and the reason.
§

fn list(&mut self) -> Vec<&dyn Process>

Returns the list of processes.

Auto Trait Implementations§

§
§

impl Send for Cfs

§

impl Sync for Cfs

§

impl Unpin for Cfs

§

impl UnwindSafe for Cfs

Blanket Implementations§

§

impl<T> Any for Twhere
    T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · §

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · §

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

const: unstable · §

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · §

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for Twhere
    U: Into<T>,

§
The type returned in the event of a conversion error.
const: unstable · §

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · §

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published