Changeset 23 for trunk/kernel/libk/remote_barrier.h
- Timestamp:
- Jun 18, 2017, 10:06:41 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/remote_barrier.h
r14 r23 1 1 /* 2 * remote_barrier.h - distributed kernel barrier definition2 * remote_barrier.h - Access a POSIX barrier. 3 3 * 4 4 * Author Alain Greiner (2016) … … 10 10 * ALMOS-MKH is free software; you can redistribute it and/or modify it 11 11 * under the terms of the GNU General Public License as published by 12 err* the Free Software Foundation; version 2.0 of the License.12 * the Free Software Foundation; version 2.0 of the License. 13 13 * 14 14 * ALMOS-MKH is distributed in the hope that it will be useful, but … … 27 27 #include <kernel_config.h> 28 28 #include <hal_types.h> 29 #include <remote_spinlock.h> 30 #include <xlist.h> 31 32 /*************************************************************************************** 33 * This file defines a POSIX compliant barrier. 34 * 35 * It is used by multi-threaded applications to synchronise threads running in 36 * different clusters, as all access functions uses hal_remote_lw() / hal_remote_sw() 37 * portable remote access primitives. 38 * 39 * A barrier is declared by a given user process as a "pthread_barrier_t" global variable. 40 * This user type is implemented as an unsigned long, but the value is not used by the 41 * kernel. ALMOS-MKH uses only the barrier virtual address as an identifier. 42 * For each user barrier, ALMOS-MKH creates a kernel "remote_barrier_t" structure, 43 * dynamically allocated in the reference cluster by the remote_barrier_create() function, 44 * and destroyed by the remote_barrier_destroy() function, using RPC if the calling thread 45 * is not running in the reference cluster. 46 * 47 * The blocking "remote_barrier_wait()" function implements a descheduling policy when 48 * the calling thread is not the last expected thread: the calling thread is registered 49 * in a waiting queue, rooted in the barrier structure, and the the calling thread 50 * is blocked on the THREAD_BLOCKED_USERSYNC condition. The last arrived thread 51 * unblocks all registtered waiting threads. 52 * 53 * Implementation note: 54 * This barrier is also used by the kernel in the parallel kernel_init phase, as the 55 * remote_barrier() function does not require barrier initialisation, when the barrier 56 * is statically allocated by the compiler in the kdata segment. 57 * **************************************************************************************/ 29 58 30 59 /***************************************************************************************** 31 * This structure defines a distributed "rendez-vous" barrier, that can be used 32 * to synchronise several kernel threads running in different clusters 33 * It is used in the parallel kernel_init phase. 34 * It does not need to be initialised, but it must be statically allocated 35 * in the KDATA segment to be properly initialised by the compiler/loader. 60 * This structure defines the barrier descriptor. 61 * - It contains an xlist of all barriers dynamically created by a given process, 62 * rooted in the reference process descriptor. 63 * - It contains the root of another xlist to register all arrived threads. 36 64 ****************************************************************************************/ 37 65 38 66 typedef struct remote_barrier_s 39 67 { 40 uint32_t current; // number of arrived threads 41 uint32_t sense; // barrier state (toggle) 42 uint32_t pad[(CONFIG_CACHE_LINE_SIZE>>2)-2]; 68 remote_spinlock_t lock; /*! lock protecting list of arrived threads */ 69 intptr_t ident; /*! virtual address in user space == identifier */ 70 uint32_t current; /*! number of arrived threads */ 71 uint32_t sense; /*! barrier state (toggle) */ 72 uint32_t nb_threads; /*! number of expected threads */ 73 xlist_entry_t list; /*! member of list of barriers in same process */ 74 xlist_entry_t root; /*! root of list of arrived threads */ 43 75 } 44 76 remote_barrier_t; 45 77 46 78 /***************************************************************************************** 47 * This blocking function implements a toggle barrier. It returns only when all48 * expected threads reach the barrier. It can be used several times without49 * specific initialisation.50 * It is portable, as it uses the remote_lw() & remote_sw() access functions.51 * @ xp : extended pointer on barrier in remote cluster52 * @ count : number of expected thread79 * This function is directly used by the kernel in the kernel_init phase, 80 * because it does not require barrier state initialisation. 81 * It returns only when the <count> expected threads reach the barrier. 82 ***************************************************************************************** 83 * @ barrier_xp : extended pointer on barrier descriptor. 84 * @ count : number of expected threads. 53 85 ****************************************************************************************/ 54 inline void remote_barrier( xptr_t xp,86 inline void remote_barrier( xptr_t barrier_xp, 55 87 uint32_t count ); 56 88 57 89 90 /***************************************************************************************** 91 * This function returns an extended pointer on the remote barrier identified 92 * by its virtual address in a given user process. It makes an associative search, 93 * scanning the list of barriers rooted in the reference process descriptor. 94 ***************************************************************************************** 95 * @ ident : barrier virtual address, used as identifier. 96 * @ returns extended pointer on barrier if success / returns XPTR_NULL if not found. 97 ****************************************************************************************/ 98 xptr_t remote_barrier_from_ident( intptr_t ident ); 99 100 /***************************************************************************************** 101 * This function implement the pthread_barrier_init() syscall. 102 * It allocates memory for the barrier descriptor in the reference cluster for 103 * the calling process, it initializes the barrier state, and register it in the 104 * list of barriers owned by the reference process. 105 ***************************************************************************************** 106 * @ count : number of expected threads. 107 * @ ident : barrier identifier (virtual address in user space). 108 * @ return 0 if success / return ENOMEM if failure. 109 ****************************************************************************************/ 110 error_t remote_barrier_create( intptr_t ident, 111 uint32_t count ); 112 113 /***************************************************************************************** 114 * This function implement the pthread_barrier_destroy() syscall. 115 * It releases thr memory allocated for the barrier descriptor, and remove the barrier 116 * from the list of barriers owned by the reference process. 117 ***************************************************************************************** 118 * @ barrier_xp : extended pointer on barrier descriptor. 119 ****************************************************************************************/ 120 void remote_barrier_destroy( xptr_t barrier_xp ); 121 122 /***************************************************************************************** 123 * This function implement the pthread_barrier_wait() syscall. 124 * It returns only when the number of expected threads (registered in the barrier 125 * dexcriptor) reach the barrier. 126 ***************************************************************************************** 127 * @ barrier_xp : extended pointer on barrier descriptor. 128 ****************************************************************************************/ 129 void remote_barrier_wait( xptr_t barrier_xp ); 130 131 58 132 #endif /* _REMOTE_BARRIER_H_ */
Note: See TracChangeset
for help on using the changeset viewer.