source: trunk/kernel/libk/remote_fifo.h @ 86

Last change on this file since 86 was 68, checked in by alain, 7 years ago

Fix bug in kernel_init, and reduce size of remote_fifo.

File size: 5.7 KB
Line 
1/*
2 * remote_fifo.h - Lock-less Single-Reader Multiple-Writers FIFO
3 *
4 * Authors : Mohamed Lamine Karaoui (2015)
5 *           Alain Greiner (2016,2017)
6 *
7 * Copyright (c) UPMC Sorbonne Universites
8 *
9 * This file is part of ALMOS-MKH.
10 *
11 * ALMOS-MHH 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_FIFO_H_
26#define _REMOTE_FIFO_H_
27
28#include <kernel_config.h>
29#include <hal_types.h>
30#include <errno.h>
31#include <hal_remote.h>
32
33/************************************************************************************
34 * This structure defines a generic, single reader, multiple writers
35 * remote FIFO, that is used by the RPCs for inter cluster communications.
36 * The accesses are implemented using a lock-free algorithm, as it uses a ticket
37 * based mechanism to handle concurrent access between multiple writers.
38 * Each FIF0 slot can contain one 64 bits integer.
39 * In case of FIFO full, the writer deschedule without blocking, to retry later.
40 *
41 * WARNING : the number of slots is statically defined by the global
42 * configuration parameter CONFIG_REMOTE_FIFO_SLOTS for all fifos, requiring
43 * 12 * CONFIG_REMOTE_FIFO_SLOTS bytes for each FIFO.
44 ***********************************************************************************/
45
46typedef struct remote_fifo_s
47{
48        volatile uint32_t  wr_id;                            /*! write slot index      */
49        volatile uint32_t  rd_id;                            /*! read  slot index      */
50    volatile uint32_t  valid[CONFIG_REMOTE_FIFO_SLOTS];  /*! empty slot if 0       */
51        uint64_t           data[CONFIG_REMOTE_FIFO_SLOTS];   /*! fifo slot content     */
52}
53remote_fifo_t;
54
55/************************************************************************************
56 * This function initializes the local FIFO as empty.
57 * It can only initialise a local FIFO.
58 ************************************************************************************
59 * @ fifo    : pointer to the local fifo.
60 ***********************************************************************************/
61void local_fifo_init( remote_fifo_t * fifo );
62
63/************************************************************************************
64 * This non blocking function tries to get one item from the local fifo.
65 * The reader must get exclusive access before calling this function. 
66 * The read slot index is incremented.
67 ************************************************************************************
68 * @ fifo    : pointer to the local fifo.
69 * @ item    : pointer on destination buffer for extracted item.
70 * @ size    : actual number of bytes in one item.
71 * @ return  0 on success, EAGAIN if the buffer is empty.
72 ***********************************************************************************/
73error_t local_fifo_get_item( remote_fifo_t * fifo, 
74                             uint64_t      * item );
75
76/************************************************************************************
77 * This blocking function puts one item to a remote fifo identified
78 * by an extended pointer.
79 * This function gets a write ticket using a remote_atomic_increment on the
80 * write slot index and waits until the slot is empty, using a descheduling
81 * policy (without blocking).
82 ************************************************************************************
83 * @ fifo    : extended pointer to the fifo in remote cluster.
84 * @ item    : pointer on a local buffer containing the item to be stored.
85 * @ first   : [out] true if first item registered in remote fifo.
86 * @ return  0 on success / EBUSY if a contention has been detected.
87 ***********************************************************************************/
88error_t remote_fifo_put_item( xptr_t     fifo,
89                              uint64_t * item,
90                              bool_t   * first );
91
92/************************************************************************************
93 * Query if local fifo is empty
94 ************************************************************************************
95 * @ fifo    : pointer to the fifo.
96 * @ return true if the fifo is empty, false otherwise.
97 ***********************************************************************************/
98bool_t local_fifo_is_empty( remote_fifo_t * fifo );
99
100/************************************************************************************
101 * Query if remote fifo is full
102 ************************************************************************************
103 * @ fifo    : pointer to the fifo in remote cluster.
104 * @ cxy         : remote cluster index.
105 * @ return true if the fifo is full, false otherwise.
106 ***********************************************************************************/
107bool_t remote_fifo_is_full( xptr_t fifo );
108
109/************************************************************************************
110 * Query number ot items in remote fifo.
111 ************************************************************************************
112 * @ fifo     : pointer to the fifo in remote cluster.
113 * @ cxy          : remote cluster index.
114 * @ return  number of items.
115 ***********************************************************************************/
116uint32_t remote_fifo_items( xptr_t fifo );
117
118
119#endif  /* _REMOTE_FIFO_H_ */
Note: See TracBrowser for help on using the repository browser.