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

Complete restructuration of kernel spinlocks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/libk/remote_sem.h

    r457 r563  
    11/*
    2  * remote_sem.h - POSIX unnammed semaphore definition.
     2 * remote_sem.h - POSIX unnamed semaphore definition.
    33 *
    4  * Author   Alain Greiner    (2016)
     4 * Author   Alain Greiner (2016,2017,2018)
    55 *
    66 * Copyright (c)  UPMC Sorbonne Universites
     
    1010 * ALMOS-MKH is free software; you can redistribute it and/or modify it
    1111 * under the terms of the GNU General Public License as published by
    12  * the Free Software Foundation; version 2.0 of the License.
     12e* the Free Software Foundation; version 2.0 of the License.
    1313 *
    1414 * ALMOS-MKH is distributed in the hope that it will be useful, but
     
    2727#include <hal_kernel_types.h>
    2828#include <xlist.h>
    29 #include <remote_spinlock.h>
     29#include <remote_busylock.h>
    3030
    31 /*********************************************************************************************
    32  *      This file defines a POSIX compliant unnamed semaphore.
     31/********************************************************************************************n
     32 * This is the kernel representation of an user level, POSIX compliant unnamed semaphore.
    3333 *
    34  * A semaphore is declared by a given user process as a "sem_t" global variable.
     34 * It can be used by muti-threaded user applications to synchronise user threads
     35 * running in different clusters.
     36 *
     37* A semaphore is declared by a given user process as a "sem_t" global variable.
    3538 * The user "sem_t" structure is implemented as an unsigned long, but the value is not
    3639 * used by the kernel. ALMOS-MKH uses only the sem_t virtual address as an identifier.
    37  * For each user semaphore, ALMOS-MKH creates a kernel "remote_sem_t" structure.
    38  * - This structure is allocated in the reference cluster by the sem_init() syscall,
    39  *   and destroyed by the sem_destroy() syscall, using RPC if the calling thread is not
    40  *   running in the reference cluster.
    41  * - The threads accessing the semaphore with the sem_get_value(), sem_wait(), sem_post()
    42  *   syscalls can be running in any cluster, as these syscalls access the "remote_sem_t"
    43  *   structure with remote_read / remote_write access functions.
     40 * For each user semaphore, ALMOS-MKH creates a kernel "remote_sem_t" structure,
     41 * dynamically allocated in the reference cluster by the remote_sem_create() function,
     42 * and destroyed by the remote_sem_destroy() function, using RPC if the calling thread is not
     43 * running in the reference cluster.
     44 *
     45 * The threads accessing the semaphore with the sem_get_value(), sem_wait(), sem_post()
     46 * syscalls can be running in any cluster, as these syscalls access the "remote_sem_t"
     47 * structure with remote_read / remote_write access functions.
    4448 ********************************************************************************************/
    4549
    4650
    4751/*********************************************************************************************
    48  * This structure defines the kernel semaphore descriptor.
    49  * - It contains the root of a waiting threads queue, implemented as a distributed xlist.
    50  * - It contains an xlist of all semaphores, rooted in the reference process descriptor.
    51  * - It contains a lock protecting both the semaphore value and the waiting queue.
     52 * This structure defines the kernel implementation of an user level semaphore.
    5253 ********************************************************************************************/
    5354
    5455typedef struct remote_sem_s
    5556{
    56         remote_spinlock_t lock;          /*! lock protecting both count and wait_queue          */
     57        remote_busylock_t lock;          /*! lock protecting the semaphore state                */
    5758        uint32_t          count;         /*! current value                                      */
    5859    intptr_t          ident;         /*! virtual address in user space == identifier        */
     
    6667 * This function returns an extended pointer on the remote semaphore identified
    6768 * by its virtual address in a given user process. It makes an associative search,
    68  * scanning the list of semaphores rooted in the reference process descriptor.
     69 * scanning the list of user semaphores rooted in the reference process descriptor.
    6970 *********************************************************************************************
    7071 * @ process  : pointer on local process descriptor.
    71  * @ vaddr    : semaphore virtual address, used as identifier.
     72 * @ ident    : semaphore virtual address, used as identifier.
    7273 * @ returns extended pointer on semaphore if success / returns XPTR_NULL if not found.
    7374 ********************************************************************************************/
    74 xptr_t remote_sem_from_vaddr( intptr_t  vaddr );
     75xptr_t remote_sem_from_ident( intptr_t  ident );
    7576
    7677/*********************************************************************************************
     
    7879 * It allocates memory for a remote semaphore in reference cluster, using a RPC if required,
    7980 * and initializes it, using remote accesses from values defined by the <vaddr> and <value>
    80  * arguments. It uses also a remote access to return the extended pointer on the semaphore
    81  * in the buffer identified by the <buf_xp> argument.
     81 * arguments. It register this semaphore in the calling process list of user semaphores.
    8282 *********************************************************************************************
    8383 * @ vaddr     : [in] semaphore virtual address, used as identifier.
    8484 * @ value     : [in] semaphore initial value.
    85  * @ sem_xp_xp : [out] extended pointer on buffer to store extended pointer on semaphore.
    8685 * @ returns 0 if success / returns -1 if no memory.
    8786 ********************************************************************************************/
    8887error_t remote_sem_create( intptr_t  vaddr,
    89                            uint32_t  value,
    90                            xptr_t    sem_xp_xp );
     88                           uint32_t  value );
    9189 
    9290/****************************yy***************************************************************
     
    10199/****************************yy***************************************************************
    102100 * This blocking function implements the SEM_WAIT operation.
    103  * - It returns only when the remote semaphore has a non-zero value,
    104  *   and has been atomically decremented.
    105  * -  if the semaphore has a zero value, it register the calling thread in the semaphore
    106  *    waiting queue, block the thread, and yield.
     101 * - It returns only when the remote semaphore has a non-zero value, and has been
     102 *   atomically decremented.
     103 * - If the semaphore has a zero value, it register the calling thread in the semaphore
     104 *   waiting queue, block the thread, and yield.
    107105 *********************************************************************************************
    108106 * @ sem_xp   : [in] extended pointer on semaphore.
     
    112110/****************************yy***************************************************************
    113111 * This function mplements the SEM_POST operation.
    114  * - It atomically increments the remote semaphore if the semaphore waiting queue is empty.
    115  * - If the waiting queue is not empty, it wakes up the first waiting thread.
     112 * - It atomically increments the remote semaphore.
     113 * - If the waiting queue is not empty, it wakes up all waiting thread.
    116114 *********************************************************************************************
    117115 * @ sem_xp   : [in] extended pointer on semaphore.
Note: See TracChangeset for help on using the changeset viewer.