source: trunk/kernel/mm/mapper.h @ 657

Last change on this file since 657 was 657, checked in by alain, 4 years ago

Introduce remote_buf.c/.h & socket.c/.h files.
Update dev_nic.c/.h files.

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