[1] | 1 | /* |
---|
[68] | 2 | * remote_fifo.h - Lock-less Single-Reader Multiple-Writers FIFO |
---|
[1] | 3 | * |
---|
[68] | 4 | * Authors : Mohamed Lamine Karaoui (2015) |
---|
| 5 | * Alain Greiner (2016,2017) |
---|
[1] | 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 | |
---|
[14] | 28 | #include <kernel_config.h> |
---|
[1] | 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. |
---|
[68] | 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. |
---|
[1] | 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 |
---|
[279] | 42 | * configuration parameter CONFIG_REMOTE_FIFO_SLOTS for all fifos. requiring |
---|
| 43 | * Each FIFO requires 8 + (12 * CONFIG_REMOTE_FIFO_SLOTS) bytes. |
---|
[1] | 44 | ***********************************************************************************/ |
---|
[68] | 45 | |
---|
[1] | 46 | typedef struct remote_fifo_s |
---|
| 47 | { |
---|
| 48 | volatile uint32_t wr_id; /*! write slot index */ |
---|
| 49 | volatile uint32_t rd_id; /*! read slot index */ |
---|
[68] | 50 | volatile uint32_t valid[CONFIG_REMOTE_FIFO_SLOTS]; /*! empty slot if 0 */ |
---|
| 51 | uint64_t data[CONFIG_REMOTE_FIFO_SLOTS]; /*! fifo slot content */ |
---|
[1] | 52 | } |
---|
| 53 | remote_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 | ***********************************************************************************/ |
---|
| 61 | void 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. |
---|
[279] | 69 | * @ item : [out] pointer on buffer for extracted item. |
---|
[1] | 70 | * @ return 0 on success, EAGAIN if the buffer is empty. |
---|
| 71 | ***********************************************************************************/ |
---|
| 72 | error_t local_fifo_get_item( remote_fifo_t * fifo, |
---|
[68] | 73 | uint64_t * item ); |
---|
[1] | 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 |
---|
[279] | 79 | * write slot. Then, it waits until the slot is empty, using a descheduling |
---|
| 80 | * policy without blocking. |
---|
[1] | 81 | ************************************************************************************ |
---|
| 82 | * @ fifo : extended pointer to the fifo in remote cluster. |
---|
[279] | 83 | * @ item : item to be stored. |
---|
[68] | 84 | * @ first : [out] true if first item registered in remote fifo. |
---|
[1] | 85 | * @ return 0 on success / EBUSY if a contention has been detected. |
---|
| 86 | ***********************************************************************************/ |
---|
| 87 | error_t remote_fifo_put_item( xptr_t fifo, |
---|
[279] | 88 | uint64_t item, |
---|
[1] | 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 | ***********************************************************************************/ |
---|
| 97 | bool_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 | ***********************************************************************************/ |
---|
| 106 | bool_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 | ***********************************************************************************/ |
---|
| 115 | uint32_t remote_fifo_items( xptr_t fifo ); |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | #endif /* _REMOTE_FIFO_H_ */ |
---|