1 | /* |
---|
2 | * remote_spinlock.h - kernel remote spinlock definition. |
---|
3 | * |
---|
4 | * Authors Mohamed Karaoui (2016) |
---|
5 | * Alain Greiner (2016) |
---|
6 | * |
---|
7 | * Copyright (c) UPMC Sorbonne Universites |
---|
8 | * |
---|
9 | * This file is part of ALMOS-MKH. |
---|
10 | * |
---|
11 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
12 | * under the terms of the GNU General Public License as published by |
---|
13 | * the Free Software Foundation; version 2.0 of the License. |
---|
14 | * |
---|
15 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
18 | * General Public License for more details. |
---|
19 | * |
---|
20 | * You should have received a copy of the GNU General Public License |
---|
21 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
22 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
23 | */ |
---|
24 | |
---|
25 | #ifndef _REMOTE_SPINLOCK_H_ |
---|
26 | #define _REMOTE_SPINLOCK_H_ |
---|
27 | |
---|
28 | #include <kernel_config.h> |
---|
29 | #include <hal_types.h> |
---|
30 | #include <xlist.h> |
---|
31 | |
---|
32 | /*************************************************************************************** |
---|
33 | * This structure defines a remote spinlock, that can be used to protect |
---|
34 | * exclusive access to a trans-cluster shared resource. It can be taken by any |
---|
35 | * thread running in any cluster. All access functions use remote pointers. |
---|
36 | * The "owner" and "list" are optionnal fields used for debug. |
---|
37 | * It register the list of all remote spinlocks taken by a given thread. |
---|
38 | **************************************************************************************/ |
---|
39 | |
---|
40 | typedef struct remote_spinlock_s |
---|
41 | { |
---|
42 | volatile uint32_t taken; /*! free if 0 / taken if non zero */ |
---|
43 | |
---|
44 | #if CONFIG_LOCKS_DEBUG |
---|
45 | xptr_t owner; /*! extended pointer on the owner thread */ |
---|
46 | xlist_entry_t list; /*! list of all remote_lock taken by owner */ |
---|
47 | #endif |
---|
48 | |
---|
49 | } |
---|
50 | remote_spinlock_t; |
---|
51 | |
---|
52 | /*************************************************************************************** |
---|
53 | * This function initializes a remote spinlock. |
---|
54 | *************************************************************************************** |
---|
55 | * @ lock_xp : extended pointer on the remote spinlock |
---|
56 | **************************************************************************************/ |
---|
57 | void remote_spinlock_init( xptr_t lock_xp ); |
---|
58 | |
---|
59 | /******************************************************************************************* |
---|
60 | * This blocking function uses a busy waiting strategy to lock a remote spinlock. |
---|
61 | * It polls the lock and returns only when the lock has been taken. |
---|
62 | * All IRQs are disabled and will keep disabled until the lock is released. |
---|
63 | * It increments the calling thread local_locks count when the lock has been taken. |
---|
64 | ******************************************************************************************* |
---|
65 | * @ lock_xp : extended pointer on the remote spinlock. |
---|
66 | * @ irq_state : buffer to save the SR state (in the calling thread stack) |
---|
67 | ******************************************************************************************/ |
---|
68 | void remote_spinlock_lock_busy( xptr_t lock_xp, |
---|
69 | uint32_t * irq_state ); |
---|
70 | |
---|
71 | /******************************************************************************************* |
---|
72 | * This function releases a remote busy_waiting spinlock. |
---|
73 | * It restores the CPU SR state. |
---|
74 | * It decrements the calling thread locks count. |
---|
75 | ******************************************************************************************* |
---|
76 | * @ lock_xp : extended pointer on remote spinlock. |
---|
77 | * @ irq_state : value to be resrored in CPU SR |
---|
78 | ******************************************************************************************/ |
---|
79 | void remote_spinlock_unlock_busy( xptr_t lock_xp, |
---|
80 | uint32_t irq_state ); |
---|
81 | |
---|
82 | /*************************************************************************************** |
---|
83 | * This blocking function locks a remote spinlock. |
---|
84 | * If the lock is already taken, the calling thread deschedule, and retry |
---|
85 | * when it is rescheduled. |
---|
86 | * It increments the calling thread locks count when the lock has been taken. |
---|
87 | *************************************************************************************** |
---|
88 | * @ lock_xp : extended pointer on the remote spinlock |
---|
89 | **************************************************************************************/ |
---|
90 | void remote_spinlock_lock( xptr_t lock_xp ); |
---|
91 | |
---|
92 | /*************************************************************************************** |
---|
93 | * This non blocking function try once to lock a remote spinlock. |
---|
94 | * It increments the calling thread locks count in case of success. |
---|
95 | *************************************************************************************** |
---|
96 | * @ lock_xp : extended pointer on the remote spinlock |
---|
97 | * @ returns O if success / returns non zero if lock already taken. |
---|
98 | **************************************************************************************/ |
---|
99 | error_t remote_spinlock_trylock( xptr_t lock_xp ); |
---|
100 | |
---|
101 | /*************************************************************************************** |
---|
102 | * This function releases a remote spinlock. |
---|
103 | * It decrements the calling thread locks count. |
---|
104 | *************************************************************************************** |
---|
105 | * @ lock_xp : extended pointer on the remote spinlock |
---|
106 | **************************************************************************************/ |
---|
107 | void remote_spinlock_unlock( xptr_t lock_xp ); |
---|
108 | |
---|
109 | #endif |
---|