source: trunk/kernel/mm/page.h @ 498

Last change on this file since 498 was 486, checked in by viala@…, 6 years ago

[mm] Add void type to function prototypes with no parameter

File size: 9.3 KB
RevLine 
[1]1/*
2 * page.h - physical page descriptor and related operations
3 *
4 * Authors Ghassan Almalles (2008,2009,2010,2011,2012)
5 *         Alain Greiner    (2016)
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 _PAGE_H_
26#define _PAGE_H_
27
[14]28#include <kernel_config.h>
[457]29#include <hal_kernel_types.h>
[1]30#include <spinlock.h>
31#include <list.h>
32#include <slist.h>
33#include <xlist.h>
34
35/***   Forward declarations   ***/
36
37struct mapper_s;
[18]38
[1]39/*************************************************************************************
40 * This  defines the flags that can be attached to a physical page.
41 ************************************************************************************/
42
43#define PG_INIT             0x0001     // page descriptor has been initialised
44#define PG_RESERVED         0x0002     // cannot be allocated by PPM
45#define PG_FREE             0x0004     // page can be allocated by PPM
[18]46#define PG_INLOAD           0x0008     // on-going load from disk
[1]47#define PG_IO_ERR           0x0010     // mapper signals a read/write access error
48#define PG_BUFFER           0x0020     // used in blockio.c
49#define PG_DIRTY            0x0040     // page has been written
50#define PG_LOCKED       0x0080     // page is locked
[23]51#define PG_COW          0x0100     // page is copy-on-write
[1]52
53#define PG_ALL          0xFFFF     // All flags
54
55/*************************************************************************************
56 * This structure defines a physical page descriptor.
[23]57 * Size is 64 bytes for a 32 bits core...
[469]58 * The spinlock is used to test/modify the forks counter.
[433]59 * TODO : the list of waiting threads seems to be unused [AG]
[469]60 * TODO : the refcount use has to be clarified
[1]61 ************************************************************************************/
62
63typedef struct page_s
64{
[23]65    uint32_t          flags;          /*! flags defined above                  (4)  */
[68]66    uint32_t          order;          /*! log2( number of small pages)         (4)  */
[1]67    struct mapper_s * mapper;         /*! local pointer on associated mapper   (4)  */
68    uint32_t          index;          /*! page index in mapper                 (4)  */
[18]69        list_entry_t      list;           /*! for both dirty pages and free pages  (8)  */
[1]70    xlist_entry_t     wait_root;      /*! root of list of waiting threads      (16) */
71        uint32_t          refcount;       /*! reference counter                    (4)  */
[433]72        uint32_t          forks;          /*! number of pending forks              (4)  */
[469]73        spinlock_t        lock;           /*! protect the forks field              (4)  */
[1]74}
75page_t;
76
77/*************************************************************************************
78 * This function initializes one page descriptor.
[23]79 *************************************************************************************
[1]80 * @ page    : pointer to page descriptor
81 ************************************************************************************/
82inline void page_init( page_t * page );
83
84/*************************************************************************************
[23]85 * This function atomically set one or several flags in page descriptor flags.
86 *************************************************************************************
[1]87 * @ page    : pointer to page descriptor.
[18]88 * @ value   : all non zero bits in value will be set.
[1]89 ************************************************************************************/
90inline void page_set_flag( page_t   * page,
[23]91                           uint32_t   value );
[1]92
93/*************************************************************************************
[23]94 * This function atomically reset one or several flags in page descriptor flags.
95 *************************************************************************************
[1]96 * @ page    : pointer to page descriptor.
[18]97 * @ value   : all non zero bits in value will be cleared.
[1]98 ************************************************************************************/
99inline void page_clear_flag( page_t   * page,
[23]100                             uint32_t   value );
[1]101
102/*************************************************************************************
[22]103 * This function tests the value of one or several flags in page descriptor flags.
[23]104 *************************************************************************************
[1]105 * @ page    : pointer to page descriptor.
106 * @ value   : all non zero bits will be tested.
[18]107 * @ returns true if at least one non zero bit in value is set / false otherwise.
[1]108 ************************************************************************************/
109inline bool_t page_is_flag( page_t   * page,
[23]110                            uint32_t   value );
[1]111
112/*************************************************************************************
113 * This function synchronizes (i.e. update the disk) all dirty pages in a cluster.
[22]114 * It scans the PPM dirty list, that should be empty when this operation is completed.
[1]115 ************************************************************************************/
[486]116void sync_all_pages( void );
[1]117
118/*************************************************************************************
[22]119 * This function sets the PG_DIRTY flag in the page descriptor,
120 * and registers the page in the dirty list in PPM.
[23]121 *************************************************************************************
[1]122 * @ page     : pointer on page descriptor.
123 * @ returns true if page was not dirty / returns false if page was dirty
124 ************************************************************************************/
125bool_t page_do_dirty( page_t * page );
126
127/*************************************************************************************
[22]128 * This function resets the PG_DIRTY flag in the page descriptor,
129 * and removes the page from the dirty list in PPM.
[23]130 *************************************************************************************
[1]131 * @ page     : pointer on page descriptor.
[18]132 * @ returns true if page was dirty / returns false if page was not dirty
[1]133 ************************************************************************************/
134bool_t page_undo_dirty( page_t * page );
135
136/*************************************************************************************
[22]137 * This function resets to 0 all bytes in a given page.
[23]138 *************************************************************************************
[1]139 * @ page     : pointer on page descriptor.
140 ************************************************************************************/
141void page_zero( page_t * page );
142
143/*************************************************************************************
144 * This blocking function set the PG_LOCKED flag on the page.
145 * It deschedule if the page has already been locked by another thread,
[18]146 * and returns only when the flag has been successfully set.
[23]147 *************************************************************************************
[1]148 * @ page     : pointer on page descriptor.
149 ************************************************************************************/
150void page_lock( page_t * page );
151
152/*************************************************************************************
[22]153 * This blocking function resets the PG_LOCKED flag on the page, if there is no
154 * other waiting thread. If there is waiting thread(s), it activates the first
[1]155 * waiting thread without modifying the PG_LOCKED flag.
[23]156 *************************************************************************************
[1]157 * @ page     : pointer on page descriptor.
158 ************************************************************************************/
159void page_unlock( page_t * page );
160
161/*************************************************************************************
[22]162 * This blocking function atomically increments the page refcount.
[23]163 *************************************************************************************
[1]164 * @ page     : pointer on page descriptor.
165 ************************************************************************************/
166inline void page_refcount_up( page_t * page );
167
168/*************************************************************************************
[22]169 * This blocking function atomically decrements the page refcount.
[23]170 *************************************************************************************
[1]171 * @ page     : pointer on page descriptor.
172 ************************************************************************************/
173inline void page_refcount_down( page_t * page );
174
175/*************************************************************************************
176 * This function display the values contained in a page descriptor.
[23]177 *************************************************************************************
178 * @ page     : pointer on page descriptor.
[1]179 ************************************************************************************/
180void page_print( page_t * page );
181
182
183#endif  /* _PAGE_H_ */
Note: See TracBrowser for help on using the repository browser.