source: trunk/kernel/libk/remote_barrier.h @ 613

Last change on this file since 613 was 581, checked in by alain, 6 years ago

1) Improve the busylock debug infrastructure.
2) introduce a non-distributed, but portable implementation for the pthread_barrier.

File size: 6.1 KB
RevLine 
[1]1/*
[563]2 * remote_barrier.h - POSIX barrier definition.               
[1]3 *
[563]4 * Author  Alain Greiner (2016,2017,2018)
[1]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
[23]12 * the Free Software Foundation; version 2.0 of the License.
[1]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_BARRIER_H_
25#define _REMOTE_BARRIER_H_
26
[14]27#include <kernel_config.h>
[457]28#include <hal_kernel_types.h>
[563]29#include <remote_busylock.h>
[23]30#include <xlist.h>
[1]31
[23]32/***************************************************************************************
33 *          This file defines a POSIX compliant barrier.
34 *
[581]35 * It is used by multi-threaded user applications to synchronise threads running in
[563]36 * different clusters, as all access functions uses hal_remote_l32() / hal_remote_s32()
37 * remote access primitives.
[23]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
[1]54/*****************************************************************************************
[23]55 * This structure defines the barrier descriptor.
56 * - It contains an xlist of all barriers dynamically created by a given process,
57 *   rooted in the reference process descriptor.
58 * - It contains the root of another xlist to register all arrived threads.
[1]59 ****************************************************************************************/
60
61typedef struct remote_barrier_s
62{
[581]63    remote_busylock_t  lock;          /*! lock protecting list of waiting threads       */
[23]64    intptr_t           ident;         /*! virtual address in user space == identifier   */
65    uint32_t           current;       /*! number of arrived threads                     */
66    uint32_t           sense;         /*! barrier state (toggle)                        */
67    uint32_t           nb_threads;    /*! number of expected threads                    */ 
68    xlist_entry_t      list;          /*! member of list of barriers in same process    */
[581]69    xlist_entry_t      root;          /*! root of list of waiting threads               */
[1]70} 
71remote_barrier_t;
72
73
[23]74/*****************************************************************************************
75 * This function returns an extended pointer on the remote barrier identified
76 * by its virtual address in a given user process. It makes an associative search,
77 * scanning the list of barriers rooted in the reference process descriptor.
78 *****************************************************************************************
79 * @ ident    : barrier virtual address, used as identifier.
80 * @ returns extended pointer on barrier if success / returns XPTR_NULL if not found.
81 ****************************************************************************************/
82xptr_t remote_barrier_from_ident( intptr_t  ident );
83
84/*****************************************************************************************
85 * This function implement the pthread_barrier_init() syscall.
86 * It allocates memory for the barrier descriptor in the reference cluster for
87 * the calling process, it initializes the barrier state, and register it in the
88 * list of barriers owned by the reference process.
89 *****************************************************************************************
90 * @ count       : number of expected threads.
91 * @ ident       : barrier identifier (virtual address in user space).
92 * @ return 0 if success / return ENOMEM if failure.
93 ****************************************************************************************/
94error_t remote_barrier_create( intptr_t ident,
95                               uint32_t count );
96
97/*****************************************************************************************
98 * This function implement the pthread_barrier_destroy() syscall.
99 * It releases thr memory allocated for the barrier descriptor, and remove the barrier
100 * from the list of barriers owned by the reference process.
101 *****************************************************************************************
102 * @ barrier_xp  : extended pointer on barrier descriptor.
103 ****************************************************************************************/
104void remote_barrier_destroy( xptr_t   barrier_xp );
105
106/*****************************************************************************************
107 * This function implement the pthread_barrier_wait() syscall.
108 * It returns only when the number of expected threads (registered in the barrier
109 * dexcriptor) reach the barrier.
110 *****************************************************************************************
111 * @ barrier_xp   : extended pointer on barrier descriptor.
112 ****************************************************************************************/
113void remote_barrier_wait( xptr_t   barrier_xp );
114
115
[1]116#endif  /* _REMOTE_BARRIER_H_ */
Note: See TracBrowser for help on using the repository browser.