source: trunk/kernel/libk/remote_busylock.h @ 622

Last change on this file since 622 was 619, checked in by alain, 6 years ago

1) Fix a bug in KSH : after the "load" command,

the [ksh] prompt is now printed after completion
of the loaded application.

2) Fix a bug in vmm_handle_cow() : the copy-on-write

use now a hal_remote_memcpy() to replicate the page content.


File size: 5.2 KB
Line 
1/*
2 * remote_busylock.h: remote kernel busy-waiting lock definition.     
3 *
4 * Authors  Alain Greiner (2016,2017,2018)
5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-kernel; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#ifndef _REMOTE_BUSYLOCK_H_
25#define _REMOTE_BUSYLOCK_H_
26
27#include <kernel_config.h>
28#include <hal_kernel_types.h>
29#include <hal_shared_types.h>
30#include <xlist.h>
31
32/*******************************************************************************************
33 * This synchronisation object sequencializes all concurrent read or write accesses to a
34 * shared object located in any cluster, made by any thread(s) running in any cluster.
35 * It uses a busy waiting policy when the lock is taken by another thread, and should
36 * be used ro execute very short actions, such as basic allocators, or to protect 
37 * higher level synchronisation objects, such as remote_queuelock and remote_rwlock.
38 *
39 * WARNING: a thread cannot yield when it is owning a busylock (local or remote).
40 *
41 * - To acquire the lock, we use a ticket policy to avoid starvation: the calling thread
42 *   makes an atomic increment on a "ticket" allocator, and keep polling the "current"
43 *   value  until current == ticket.
44 *
45 * - To release the lock, the owner thread increments the "current" value,
46 *   decrements its busylocks counter.
47 *
48 * - When a thread takes a busylock, it enters a critical section: the busylock_acquire()
49 *   function disables the IRQs, takes the lock, increments the thread busylocks counter,
50 *    save the SR in the lock descriptor and returns.
51 *
52 * - The busylock_release() function decrements the thread busylock counter,
53 *   restores the SR to exit the critical section, and returns
54 *
55 * - If a thread owning a busylock (local or remote) tries to deschedule, the scheduler
56 *   signals a kernel panic.
57 ******************************************************************************************/
58
59/*******************************************************************************************
60 * This structure defines a remote_busylock.
61 * - The <ticket> and <current> fields implement the ticket policy described above.
62 * - The <type> and <xlist> fields are used for debug. The type defines the lock usage,
63 *   as detailed in the kernel_config.h file.
64 * - The <save_sr> field is used to implement the critical section as decribed above.
65 ******************************************************************************************/
66
67typedef struct remote_busylock_s
68{
69        uint32_t            ticket;      /*! next free ticket index                           */
70    volatile uint32_t   current;     /*! current owner index                              */
71    uint32_t            type;        /*! lock type for debug                              */
72    reg_t               save_sr;     /*! SR value                                         */
73
74#if DEBUG_BUSYLOCK
75    xlist_entry_t       xlist;       /*! member of list of locks taken by same thread     */
76#endif
77
78}
79remote_busylock_t;
80
81/*******************************************************************************************
82 * This function initializes a remote busylock.
83 *******************************************************************************************
84 * @ lock_xp    : extended pointer on remote busylock.
85 * @ type       : lock type for debug.
86 ******************************************************************************************/
87void remote_busylock_init( xptr_t   lock_xp,
88                           uint32_t type );
89
90/*******************************************************************************************
91 * This blocking function uses a busy waiting strategy to acquire a remote_busylock.
92 * It makes an atomic increment on the "ticket" field to get a ticket value and increment
93 * the ticket allocator.
94 * Then it polls the "current" field until (current == ticket), and returns.
95 *******************************************************************************************
96 * @ lock_xp    : extended pointer on remote busylock
97 ******************************************************************************************/
98void remote_busylock_acquire( xptr_t   lock_xp );
99
100/*******************************************************************************************
101 * This function releases a busylock by incrementing the "current field".
102 *******************************************************************************************
103 * @ lock_xp       : extended pointer on remote busylock
104 ******************************************************************************************/
105void remote_busylock_release( xptr_t  lock_xp );
106
107#endif  /* _REMOTE_BUSYLOCK_H_ */
Note: See TracBrowser for help on using the repository browser.