source: trunk/kernel/mm/mapper.h

Last change on this file was 683, checked in by alain, 3 years ago

All modifications required to support the <tcp_chat> application
including error recovery in case of packet loss.A

File size: 16.3 KB
RevLine 
[1]1/*
[611]2 * mapper.h - Kernel cache for VFS files/directories definition.
[1]3 *
4 * Authors   Mohamed Lamine Karaoui (2015)
[623]5 *           Alain Greiner (2016,2017,2018,2019)
[1]6 *
7 * Copyright (c)  UPMC Sorbonne Universites
8 *
9 * This file is part of ALMOS-MKH.
10 *
11 * ALMOS-MKH 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 _MAPPER_H_
26#define _MAPPER_H_
27
[457]28#include <hal_kernel_types.h>
[1]29#include <hal_atomic.h>
30#include <xlist.h>
31#include <grdxt.h>
32#include <rwlock.h>
33
34/****  Forward declarations ****/
35
36struct page_s;
37struct vfs_inode_s;
38
39/*******************************************************************************************
[614]40 * This mapper_t object implements the kernel cache for a given VFS file or directory.
[683]41 * There is one mapper per file/dir.
42 * - It is implemented as a three levels radix tree, entirely stored in the same cluster
43 *   as the inode representing the file/directory.
[18]44 * - The fast retrieval key is the page index in the file.
[1]45 *   The ix1_width, ix2_width, ix3_width sub-indexes are configuration parameters.
46 * - The leaves are pointers on physical page descriptors, dynamically allocated
[683]47 *   in the same cluster as the radix tree.
[610]48 * - The mapper is protected by a "remote_rwlock", to support several simultaneous
49 *   "readers", and only one "writer".
50 * - A "reader" thread, calling the mapper_remote_get_page() function to get a page
[623]51 *   descriptor pointer from the page index in file, can be running in any cluster.
[610]52 * - A "writer" thread, calling the mapper_handle_miss() function to handle a page miss
53 *   must be local (running in the mapper cluster).
[623]54 * - The vfs_fs_move_page() function access the file system to handle a mapper miss,
[246]55 *   or update a dirty page on device.
[610]56 * - The vfs_mapper_load_all() functions is used to load all pages of a directory
57 *   into the mapper (prefetch).
[265]58 * - the mapper_move_user() function is used to move data to or from an user buffer.
[238]59 *   This user space buffer can be physically distributed in several clusters.
[313]60 * - the mapper_move_kernel() function is used to move data to or from a remote kernel
61 *   buffer, that can be physically located in any cluster.
[246]62 * - In the present implementation the cache size for a given file increases on demand,
[683]63 *   and the  allocated memory is only released when the inode is destroyed.
64 *
65 * WARNING : This mapper implementation makes the assumption that the PPM page size
66 *           is 4 Kbytes. This code should be modified to support a generic page size,
67 *           defined by the CONFIG_PPM_PAGE_SIZE parameter.
[1]68 ******************************************************************************************/
69
70
71/*******************************************************************************************
72 * This structure defines the mapper descriptor.
73 ******************************************************************************************/
74
75typedef struct mapper_s
76{
[23]77        struct vfs_inode_s * inode;           /*! owner inode                                     */
[657]78    uint32_t             fs_type;     /*! file system type                                */
[606]79        grdxt_t              rt;              /*! embedded pages cache descriptor (radix tree)    */
80        remote_rwlock_t      lock;        /*! several readers / only one writer               */
[1]81        uint32_t                 refcount;    /*! several vsegs can refer the same file           */
82        xlist_entry_t        vsegs_root;  /*! root of list of vsegs refering this mapper      */
83        xlist_entry_t        wait_root;   /*! root of list of threads waiting on mapper       */
84    list_entry_t         dirty_root;  /*! root of list of dirty pages                     */
85}
86mapper_t;
87
88/*******************************************************************************************
[657]89 * This function allocates physical memory for a mapper descriptor, in cluster
90 * identified by the <cxy> argument. It initializes it (refcount <= 0) / inode <= NULL).
91 * It can be executed by any thread running in any cluster.
[1]92 *******************************************************************************************
[657]93 * @ cxy    : target cluster identifier.
94 * @ type   : FS type.
95 * @ return an extended pointer on created mapper if success / return NULL if no memory
[1]96 ******************************************************************************************/
[657]97xptr_t  mapper_create( cxy_t     cxy,
98                       uint32_t  type );
[1]99
100/*******************************************************************************************
[657]101 * This function releases all physical memory allocated for a mapper, identified
102 * by the <mapper_xp> argument. Both the mapper descriptor and the radix tree are released.
[606]103 * It does NOT synchronize dirty pages. Use the vfs_sync_inode() function if required.
[657]104 * It can be executed by any thread running in any cluster.
[1]105 *******************************************************************************************
[657]106 * @ mapper_xp   : extended pointer on target mapper.
[1]107 ******************************************************************************************/
[657]108void mapper_destroy( xptr_t  mapper_xp );
[1]109
110/*******************************************************************************************
[635]111 * This function load from the IOC device a missing page identified by the <page_id>
112 * argument into a - possibly remote - mapper identified by the <mapper_xp> argument.
113 * It can be executed by a thread running in any cluster.
114 * It allocates a physical page from the remote cluster PPM, initialises it by accessing
115 * the IOC device, and registers the page in the remote mapper radix tree.
[606]116 * WARNING : the calling function mapper_remote_get_page() is supposed to take and release
117 * the lock protecting the mapper in WRITE_MODE.
118 *******************************************************************************************
[635]119 * @ mapper_xp   : [in]  extended pointer on remote mapper.
120 * @ page_id     : [in]  missing page index in file.
121 * @ page_xp     : [out] buffer for extended pointer on missing page descriptor.
122 * @ return 0 if success / return -1 if IOC cannot be accessed.
[606]123 ******************************************************************************************/
[657]124error_t mapper_handle_miss( xptr_t     mapper_xp,
125                            uint32_t   page_id,
126                            xptr_t   * page_xp );
[606]127
128/*******************************************************************************************
[635]129 * This function removes a physical page from a - possibly remote - mapper,
130 * and releases the page to the remote PPM.
131 * It can be executed by any thread running in any cluster.
132 * It takes the mapper lock in WRITE_MODE to update the mapper.
133 *******************************************************************************************
134 * @ mapper     : extended pointer on the remote mapper.
135 * @ page       : local pointer on the page in remote mapper.
136 ******************************************************************************************/
137void mapper_remote_release_page( xptr_t          mapper_xp,
138                                 struct page_s * page );
139
140/*******************************************************************************************
[625]141 * This function move data between a remote mapper, identified by the <mapper_xp> argument,
[610]142 * and a distributed user buffer. It can be called by a thread running in any cluster.
[606]143 * It is called by the vfs_user_move() to implement sys_read() and sys_write() syscalls.
[313]144 * If required, the data transfer is split in "fragments", where one fragment contains
[265]145 * contiguous bytes in the same mapper page.
[313]146 * It uses "hal_uspace" accesses to move a fragment to/from the user buffer.
[1]147 * In case of write, the dirty bit is set for all pages written in the mapper.
[610]148 * The mapper being an extendable cache, it is automatically extended when required.
[606]149 * The "offset" field in the file descriptor, and the "size" field in inode descriptor
150 * are not modified by this function.
[1]151 *******************************************************************************************
[610]152 * @ mapper_xp    : extended pointer on mapper.
[265]153 * @ to_buffer    : mapper -> buffer if true / buffer -> mapper if false.
[23]154 * @ file_offset  : first byte to move in file.
[407]155 * @ u_buf        : user space pointer on user buffer.
[23]156 * @ size         : number of bytes to move.
[606]157 * returns O if success / returns -1 if error.
[1]158 ******************************************************************************************/
[614]159error_t mapper_move_user( xptr_t     mapper_xp,
[313]160                          bool_t     to_buffer,
161                          uint32_t   file_offset,
[407]162                          void     * u_buf,
[313]163                          uint32_t   size );
164
[606]165/********************************************************************************************
[656]166 * This function move <size> bytes from/to a remote mapper, identified by the <mapper_xp>
167 * argument, to/from a remote kernel buffer, identified by the <buffer_xp> argument.
168 * It can be called by a thread running in any cluster.
[313]169 * If required, the data transfer is split in "fragments", where one fragment contains
[656]170 * contiguous bytes in the same mapper page. Each fragment uses a "remote_memcpy".
171 * In case of write to mapper, the dirty bit is set for all pages written in the mapper.
[313]172 *******************************************************************************************
[606]173 * @ mapper_xp    : extended pointer on mapper.
[313]174 * @ to_buffer    : mapper -> buffer if true / buffer -> mapper if false.
175 * @ file_offset  : first byte to move in file.
176 * @ buffer_xp    : extended pointer on kernel buffer.
177 * @ size         : number of bytes to move.
[606]178 * returns O if success / returns -1 if error.
[313]179 ******************************************************************************************/
[606]180error_t mapper_move_kernel( xptr_t     mapper_xp,
[265]181                            bool_t     to_buffer,
182                            uint32_t   file_offset,
[313]183                            xptr_t     buffer_xp,
[265]184                            uint32_t   size );
[1]185
186/*******************************************************************************************
[657]187 * This function returns an extended pointer on a page descriptor for a regular mapper
188 * (i.e. this mapper is NOT the FAT mapper), identified by the <mapper_xp> argument.
[611]189 * The page is identified by <page_id> argument (page index in the file).
190 * It can be executed by a thread running in any cluster, as it uses remote
[606]191 * access primitives to scan the mapper.
192 * In case of miss, this function takes the mapper lock in WRITE_MODE, and call the
193 * mapper_handle_miss() to load the missing page from device to mapper, using an RPC
194 * when the mapper is remote.
195 *******************************************************************************************
196 * @ mapper_xp  : extended pointer on the mapper.
197 * @ page_id    : page index in file
[611]198 * @ returns extended pointer on page descriptor if success / return XPTR_NULL if error.
[606]199 ******************************************************************************************/
[657]200xptr_t mapper_get_page( xptr_t    mapper_xp,
201                        uint32_t  page_id );
[606]202
203/*******************************************************************************************
[657]204 * This function returns an extended pointer on a page descriptor for the FAT mapper.
205 * The page is identified by <page_id> argument (page index in the FAT mapper).
206 * It can be executed by a thread running in any cluster, as it uses remote
207 * access primitives to scan the mapper.
208 * In case of miss, this function takes the mapper lock in WRITE_MODE, and call the
209 * mapper_handle_miss() to load the missing page from device to mapper, using an RPC
210 * when the mapper is remote.
211 *******************************************************************************************
212 * @ mapper_xp  : extended pointer on the mapper.
213 * @ page_id    : page index in file
214 * @ returns extended pointer on page descriptor if success / return XPTR_NULL if error.
215 ******************************************************************************************/
216xptr_t mapper_get_fat_page( xptr_t    mapper_xp,
217                            uint32_t  page_id );
218
219/*******************************************************************************************
[606]220 * This function allows to read a single word in a mapper seen as and array of uint32_t.
[611]221 * It has bee designed to support remote access to the FAT mapper of the FATFS.
[606]222 * It can be called by any thread running in any cluster.
[1]223 * In case of miss, it takes the mapper lock in WRITE_MODE, load the missing
[606]224 * page from device to mapper, and release the mapper lock.
[1]225 *******************************************************************************************
[606]226 * @ mapper_xp  : [in]  extended pointer on the mapper.
[628]227 * @ page_id    : [in]  page index in mapper.
228 * @ word_id    : [in]  32 bits word index in page.
229 * @ value      : [out] local pointer on destination buffer.
[606]230 * @ returns 0 if success / return -1 if error.
[1]231 ******************************************************************************************/
[606]232error_t mapper_remote_get_32( xptr_t     mapper_xp,
[628]233                              uint32_t   page_id,
[606]234                              uint32_t   word_id,
[628]235                              uint32_t * value );
[1]236
[606]237/*******************************************************************************************
238 * This function allows to write a single word to a mapper seen as and array of uint32_t.
[625]239 * It has been designed to support remote access to the FAT mapper of the FATFS.
[606]240 * It can be called by any thread running in any cluster.
241 * In case of miss, it takes the mapper lock in WRITE_MODE, load the missing
242 * page from device to mapper, and release the mapper lock.
[628]243 * It does not update the FAT on IOC device.
[606]244 *******************************************************************************************
245 * @ mapper_xp  : [in]  extended pointer on the mapper.
[628]246 * @ page_id    : [in]  page index in mapper.
247 * @ word_id    : [in]  32 bits word index in page.
[611]248 * @ value      : [in]  value to be written.
[606]249 * @ returns 0 if success / return -1 if error.
250 ******************************************************************************************/
251error_t mapper_remote_set_32( xptr_t     mapper_xp,
[628]252                              uint32_t   page_id,
[606]253                              uint32_t   word_id,
254                              uint32_t   value );
[18]255
[611]256/*******************************************************************************************
[657]257 * This function scan all pages present in the mapper identified by the <mapper_xp>
258 * argument, and synchronize all pages marked as "dirty" on disk.
[623]259 * These pages are unmarked and removed from the local PPM dirty_list.
[657]260 * It can be called by any thread running in any cluster.
[623]261 *******************************************************************************************
[657]262 * @ mapper_xp  : [in]  extended pointer on local mapper.
[623]263 * @ returns 0 if success / return -1 if error.
264 ******************************************************************************************/
[657]265error_t mapper_sync( xptr_t  mapper_xp );
[623]266
267/*******************************************************************************************
[656]268 * This debug function displays the content of a given page of a given mapper, identified
[657]269 * by the <mapper_xp> and <page_id> arguments.
[656]270 * The number of bytes to display in page is defined by the <nbytes> argument.
[611]271 * The format is eigth (32 bits) words per line in hexadecimal.
272 * It can be called by any thread running in any cluster.
273 *******************************************************************************************
274 * @ mapper_xp  : [in]  extended pointer on the mapper.
[657]275 * @ page_id    : [in]  page_index in mapper.
[656]276 * @ nbytes     : [in]  number of bytes in page.
[611]277 * @ returns 0 if success / return -1 if error.
278 ******************************************************************************************/
[656]279void mapper_display_page( xptr_t     mapper_xp,
[657]280                          uint32_t   page_id,
[656]281                          uint32_t   nbytes );
[611]282
283
[1]284#endif /* _MAPPER_H_ */
Note: See TracBrowser for help on using the repository browser.