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

Last change on this file since 335 was 279, checked in by alain, 7 years ago

1) Introduce independant command fields for the various devices in the thread descriptor.
2) Introduce a new dev_pic_enable_ipi() function in the generic PIC device
3) Fix two bugs identified by Maxime in the scheduler initialisation, and in the sched_select().
4) fix several bugs in the TSAR hal_kentry.S.
5) Introduce a third kgiet segment (besides kdata and kcode) in the TSAR bootloader.

File size: 5.6 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 * Each FIFO requires 8 + (12 * CONFIG_REMOTE_FIFO_SLOTS) bytes.
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    : [out] pointer on buffer for extracted item.
70 * @ return  0 on success, EAGAIN if the buffer is empty.
71 ***********************************************************************************/
72error_t local_fifo_get_item( remote_fifo_t * fifo, 
73                             uint64_t      * item );
74
75/************************************************************************************
76 * This blocking function puts one item to a remote fifo identified
77 * by an extended pointer.
78 * This function gets a write ticket using a remote_atomic_increment on the
79 * write slot. Then, it waits until the slot is empty, using a descheduling
80 * policy without blocking.
81 ************************************************************************************
82 * @ fifo    : extended pointer to the fifo in remote cluster.
83 * @ item    : item to be stored.
84 * @ first   : [out] true if first item registered in remote fifo.
85 * @ return  0 on success / EBUSY if a contention has been detected.
86 ***********************************************************************************/
87error_t remote_fifo_put_item( xptr_t     fifo,
88                              uint64_t   item,
89                              bool_t   * first );
90
91/************************************************************************************
92 * Query if local fifo is empty
93 ************************************************************************************
94 * @ fifo    : pointer to the fifo.
95 * @ return true if the fifo is empty, false otherwise.
96 ***********************************************************************************/
97bool_t local_fifo_is_empty( remote_fifo_t * fifo );
98
99/************************************************************************************
100 * Query if remote fifo is full
101 ************************************************************************************
102 * @ fifo    : pointer to the fifo in remote cluster.
103 * @ cxy         : remote cluster index.
104 * @ return true if the fifo is full, false otherwise.
105 ***********************************************************************************/
106bool_t remote_fifo_is_full( xptr_t fifo );
107
108/************************************************************************************
109 * Query number ot items in remote fifo.
110 ************************************************************************************
111 * @ fifo     : pointer to the fifo in remote cluster.
112 * @ cxy          : remote cluster index.
113 * @ return  number of items.
114 ***********************************************************************************/
115uint32_t remote_fifo_items( xptr_t fifo );
116
117
118#endif  /* _REMOTE_FIFO_H_ */
Note: See TracBrowser for help on using the repository browser.