Changes between Version 10 and Version 11 of scheduler


Ignore:
Timestamp:
Sep 3, 2017, 1:43:07 PM (7 years ago)
Author:
alain
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • scheduler

    v10 v11  
    66
    77There is one private scheduler per core, and ALMOS-MKH does not support thread migration: threads are assigned to a given core at thread creation, and will never be executed by another core, until thread destruction.
    8 ALMOS-MKH implement a preemptive policy for time sharing between all threads assigned to given core. The <cpu_context> and <fpu_context> fields in the thread descriptor define the storage required to save (or initialize) the core registers values when the thread is not running. A fixed number of TICK periods - called quantum - is allocated to a running thread. The value of the TICK period (in milli-second) is defined by the CONFIG_SCHED_TICK_MS_PERIOD parameter. The number of TICKS  is defined by the CONFIG_SCHED_TICKS_PER_QUANTUM configuration parameter.
    9 Finally, the max number of threads assigned to a given core is defined by the CONFIG_SCHED_MAX_THREADS_NR configuration parameter.
     8ALMOS-MKH implement a preemptive policy for time sharing between all threads assigned to given core. The <cpu_context> and <fpu_context> fields in the thread descriptor define the storage required to save (or initialize) the core registers values when the thread is not running. A fixed number of TICK periods - called quantum - is allocated to a running thread.
     9 * The value of the TICK period (in milli-second) is defined by the CONFIG_SCHED_TICK_MS_PERIOD parameter.
     10 * The number of TICKS  is defined by the CONFIG_SCHED_TICKS_PER_QUANTUM configuration parameter.
     11 * The max number of threads assigned to a given core is defined by the CONFIG_SCHED_MAX_THREADS_NR configuration parameter.
    1012
    1113== B) Thread states ==
     
    1315ALMOS-MKH defines two types of threads:
    1416 * USER threads are POSIX compliant threads, defined in a given user process. A main thread is always created for an user process. Other threads are created by the pthread_create() syscall.
    15  * KERNEL threads implement kernels services, such as RPC threads executing the Remote Procedure Calls, the DEV threads implementing IO channels operations, or the IDLE thread that is a default (low-power) thread.
     17 * KERNEL threads implement kernels services: RPC threads execute the Remote Procedure Calls; DEV threads implement IO channels operations, and IDLE thread is the default (low-power) thread.
    1618
    1719From the scheduler point of view, any thread (KERNEL or USER) can be in three states:
     
    2325A thread generally enter in the BLOCKED state, when a given resource is not available, by calling the thread_block() function that set the relevant bit in the <blocked> bit-vector. It returns to the READY state when another thread releases the blocking resource, and call the thread_unblock() function, that reset the relevant bit. The thread_unblock() function can be called by any thread running in any cluster.
    2426
    25 This simple blocking / unblocking mechanism is well suited to the Multi-Kernel-Hybrid architecture, as it uses simple local / remote_write accesses.
     27This simple blocking / unblocking mechanism is well suited to the Multi-Kernel-Hybrid architecture, as it does not require to move the blocked thread from one queue to another queue:
     28 * when a thread A is blocked on a busy shared resource, it makes a local_write to its <blocked> bit-vector, register itself in the resource waiting queue, and call the sched_yield() function.
     29 * when the resource is released by the owner thread B - running in any cluster - thread B pop the first waiting thread from the waiting queue, and uses a remote_write access to unblock thread A.
    2630
    2731== C) Scheduling policy ==
    2832
    2933Each scheduler maintains two separate, circular, lists of threads: one list of KERNEL threads, and one list of USER threads. The KERNEL threads have a higher priority than the USER threads, and each list is handled with a round-robin priority. When the sched_yield() function is called to perform a context switch for a given core, it implement the following policy:
    30  1. It scan the KERNEL list to find a READY thread. It executes this KERNEL thread if found.
     34 1. It scan the KERNEL list to find a READY thread (other than the IDLE thread). It executes this KERNEL thread if found.
    3135 1. If no KERNEL thread is found, it scan the USER list to fin a READY thread. It executes this USER thread if found.
    3236 1. If there is no KERNEL thread and no USER thread (other than the calling thread), the calling thread continues execution.
    3337 1. If there is no READY thread, it executes the IDLE thread.
    3438
    35 The kernel has the possibility to force the selection of a given thread, identified by the sched_yield() function argument. This is used to reduce the RPC latency, using an IPI (Inter-Processor-Interrupt) to force
    36 a context switch on a given remote core, and force execution of the relevant RPC thread..
     39The kernel has the possibility to force the selection of a given thread by passing a non-null argument to the sched_yield() function. This is used to reduce the RPC latency: when a core executing the rpc_check() function detect a pending RPC, it select an RPC thread, and force execution of this RPC thread.
     40
     41Finally ALMOS_MKH implements the following scheduling priority :   RPC > DEV > USER > IDLE
    3742
    3843== D) Delayed Context Switches ==
    3944
    4045Context switches can have two causes:
    41 The RUNNING thread can explicitly ask to be descheduled. When such a thing happens, it is guaranteed that the current thread does not hold any kernel locks.
     46The RUNNING thread can explicitly ask to be descheduled, when blocked on a shared resource. Before descheduling, the thread should release all kernel locks.
    4247But the scheduling policy being preemptive,  the RUNNING thread can hold one (or several) kernel lock(s) when receiving a TICK interrupt.
    4348
     
    4651 2. All kernel functions used to release kernel locks check this THREAD_FLAG_SCHED. When this flag is set, and the last lock is released by the calling thread, the sched_yield() is immediately executed.
    4752
    48 More generally, ALMOS-MKH supports descheduling of an USER thread that is currently in kernel mode - as a result of a syscall. In other words, sys calls can be interrupted by interrupts signaling the completion of an I/O operations, or by the TICK interrupt, requiring a context switch.
     53More generally, ALMOS-MKH supports descheduling of an USER thread that is currently in kernel mode - as a result of a syscall. In other words, syscalls can be interrupted by interrupts signaling the completion of an I/O operations, or by the TICK interrupt, requiring a context switch.
    4954
    5055== E) Floating Point Unit ==