Ignore:
Timestamp:
Oct 4, 2018, 11:47:36 PM (6 years ago)
Author:
alain
Message:

Complete restructuration of kernel locks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/scheduler.h

    r470 r564  
    22 * scheduler.h - Core scheduler definition.
    33 *
    4  * Author    Alain Greiner (2016)
     4 * Author    Alain Greiner (2016,2017,2018)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    2727#include <hal_kernel_types.h>
    2828#include <list.h>
    29 #include <spinlock.h>
     29#include <busylock.h>
    3030
    3131/****  Forward declarations  ****/
     
    4040typedef struct scheduler_s
    4141{
    42     spinlock_t        lock;            /*! lock protecting lists of threads                 */
     42    busylock_t        lock;            /*! lock protecting scheduler state                  */
    4343    uint16_t          u_threads_nr;    /*! total number of attached user threads            */
    4444    uint16_t          k_threads_nr;    /*! total number of attached kernel threads          */
     
    6161/*********************************************************************************************
    6262 * This function atomically register a new thread in a given core scheduler.
     63 * Note: There is no specific sched_remove_thread(), as a thread is always deleted
     64 * by the ched_handle_signals() function, called by the sched_yield() function.
    6365 *********************************************************************************************
    6466 * @ core    : local pointer on the core descriptor.
     
    7072/*********************************************************************************************
    7173 * This function is the only method to make a context switch. It is called in cas of TICK,
    72  * or when when a thread explicitely requires a scheduling.
    73  * It handles the pending signals for all threads attached to the core running the calling
    74  * thread, and calls the sched_select() function to select a new thread.
    75  * The cause argument is only used for debug by the sched_display() function, and
    76  * indicates the scheduling cause.
     74 * or when a thread explicitely requires to be descheduled.
     75 * It takes the scheduler busylock to atomically update the scheduled state.
     76 * It calls the sched_select() private function to select a new thread. After switch, it
     77 * calls the sched_handle_signals() private function to handle the pending REQ_ACK and
     78 * REQ_DELETE flagss for all threads attached to the scheduler: it deletes all threads
     79 * marked for delete (and the process descriptor when the deleted thread is the main thread).
     80 * As the REQ_DELETE flag can be asynchronously set (between the select and the handle),
     81 * the sched_handle-signals() function check that the thread to delete is not the new thread,
     82 * because a thread cannot delete itself.
     83 * The cause argument is only used for debug by the sched_display() functions, and indicates
     84 * the scheduling cause.
    7785 *********************************************************************************************
    7886 * @ cause    : character string defining the scheduling cause.
     
    8088void sched_yield( const char * cause );
    8189
    82 /*********************************************************************************************
    83  * This function scan all threads attached to a given scheduler, and executes the relevant
    84  * actions for pending THREAD_FLAG_REQ_ACK or THREAD_FLAG_REQ_DELETE requests.
    85  * It is called in by the sched_yield() function, with IRQ disabled.
    86  * - REQ_ACK : it checks that target thread is blocked, decrements the response counter
    87  *   to acknowledge the client thread, and reset the pending request.
    88  * - REQ_DELETE : it detach the target thread from parent if attached, detach it from
    89  *   the process, remove it from scheduler, release memory allocated to thread descriptor,
    90  *   and destroy the process descriptor it the target thread was the last thread.
    91  *********************************************************************************************
    92  * @ core    : local pointer on the core descriptor.
    93  ********************************************************************************************/
    94 void sched_handle_signals( struct core_s * core );
    95 
    96 /*********************************************************************************************
    97  * This function does NOT modify the scheduler state.
    98  * It just select a thread in the list of attached threads, implementing the following
    99  * three steps policy:
    100  * 1) It scan the list of kernel threads, from the next thread after the last executed one,
    101  *    and returns the first runnable found : not IDLE, not blocked, client queue not empty.
    102  *    It can be the current thread.
    103  * 2) If no kernel thread found, it scan the list of user thread, from the next thread after
    104  *    the last executed one, and returns the first runable found : not blocked.
    105  *    It can be the current thread.
    106  * 3) If no runable thread found, it returns the idle thread.
    107  *********************************************************************************************
    108  * @ core    : local pointer on scheduler.
    109  * @ returns pointer on selected thread descriptor
    110  ********************************************************************************************/
    111 struct thread_s * sched_select( struct scheduler_s * sched );
    112 
    11390/*********************************************************************************************
    11491 * This debug function displays on TXT0 the internal state of a local scheduler,
    115  * identified by the core local index <lid>.
     92 * identified by the core local index <lid>. It must be called by a local thread.
    11693 *********************************************************************************************
    11794 * @ lid      : local index of target core.
     
    123100 * identified by the target cluster identifier <cxy> and the core local index <lid>.
    124101 * It can be called by a thread running in any cluster, as it uses remote accesses,
    125  * to scan the scheduler local lists of threads.
     102 * to scan the scheduler lists of threads.
    126103 *********************************************************************************************
    127104 * @ cxy      : target cluster identifier
Note: See TracChangeset for help on using the changeset viewer.