source: trunk/kernel/libk/remote_spinlock.h @ 458

Last change on this file since 458 was 457, checked in by alain, 6 years ago

This version modifies the exec syscall and fixes a large number of small bugs.
The version number has been updated (0.1)

File size: 5.3 KB
Line 
1/*
2 * remote_spinlock.h - kernel remote spinlock definition.
3 *
4 * Author  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-MKH; 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_SPINLOCK_H_
25#define _REMOTE_SPINLOCK_H_
26
27#include <kernel_config.h>
28#include <hal_kernel_types.h>
29#include <xlist.h>
30
31/***************************************************************************************
32 * This structure defines a remote spinlock, that can be used to protect
33 * exclusive access to a trans-cluster shared resource. It can be taken by any
34 * thread running in any cluster. All access functions use remote pointers.
35 * The "owner" and "list" are optionnal fields used for debug.
36 * It register the list of all remote spinlocks taken by a given thread.
37 **************************************************************************************/
38
39typedef struct remote_spinlock_s
40{
41    volatile uint32_t     taken;       /*! free if 0 / taken if non zero             */
42
43#if DEBUG_REMOTE_SPINLOCKS
44    xptr_t                owner;       /*! extended pointer on the owner thread      */
45    xlist_entry_t         list;        /*! list of all remote_lock taken by owner    */
46#endif
47
48} 
49remote_spinlock_t;
50
51/***************************************************************************************
52 * This function initializes a remote spinlock.
53 ***************************************************************************************
54 * @ lock_xp : extended pointer on the remote spinlock
55 **************************************************************************************/
56void remote_spinlock_init( xptr_t   lock_xp );
57
58/*******************************************************************************************
59 * This blocking function uses a busy waiting strategy to lock a remote spinlock.
60 * It polls the lock and returns only when the lock has been taken.
61 * All IRQs are disabled and will keep disabled until the lock is released.
62 * It increments the calling thread local_locks count when the lock has been taken.
63 *******************************************************************************************
64 * @ lock_xp    : extended pointer on the remote spinlock.
65 * @ irq_state  : buffer to save the SR state (in the calling thread stack)
66 ******************************************************************************************/
67void remote_spinlock_lock_busy( xptr_t     lock_xp,
68                                uint32_t * irq_state );
69
70/*******************************************************************************************
71 * This function releases a remote busy_waiting spinlock.
72 * It restores the CPU SR state.
73 * It decrements the calling thread locks count.
74 *******************************************************************************************
75 * @ lock_xp    : extended pointer on remote spinlock.
76 * @ irq_state  : value to be resrored in CPU SR
77 ******************************************************************************************/
78void remote_spinlock_unlock_busy( xptr_t     lock_xp,
79                                  uint32_t   irq_state );
80
81/***************************************************************************************
82 * This blocking function locks a remote spinlock.
83 * If the lock is already taken, the calling thread deschedule, and retry
84 * when it is rescheduled.
85 * It increments the calling thread locks count when the lock has been taken.
86 ***************************************************************************************
87 * @ lock_xp   : extended pointer on the remote spinlock
88 **************************************************************************************/
89void remote_spinlock_lock( xptr_t lock_xp );
90
91/***************************************************************************************
92 * This non blocking function try once to lock a remote spinlock.
93 * It increments the calling thread locks count in case of success.
94 ***************************************************************************************
95 * @ lock_xp    : extended pointer on the remote spinlock
96 * @ returns O if success / returns non zero if lock already taken.
97 **************************************************************************************/
98error_t remote_spinlock_trylock( xptr_t  lock_xp );
99
100/***************************************************************************************
101 * This function releases a remote spinlock.
102 * It decrements the calling thread locks count.
103 ***************************************************************************************
104 * @ lock_xp    : extended pointer on the remote spinlock
105 **************************************************************************************/
106void remote_spinlock_unlock( xptr_t  lock_xp );
107
108#endif
Note: See TracBrowser for help on using the repository browser.