source: trunk/kernel/mm/page.c @ 632

Last change on this file since 632 was 632, checked in by alain, 5 years ago

This version replace the RPC by direct remote memory access
for physical pages allacation/release.
It is commited before being tested.

File size: 4.5 KB
Line 
1/*
2 * page.c - physical page related operations implementation
3 *
4 * Authors  Ghassan Almaless (2008,2009,2010,2011,2012)
5 *          Alain Greiner    (2016,2017)
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#include <hal_kernel_types.h>
26#include <hal_special.h>
27#include <hal_atomic.h>
28#include <list.h>
29#include <queuelock.h>
30#include <memcpy.h>
31#include <printk.h>
32#include <vfs.h>
33#include <process.h>
34#include <page.h>
35
36
37////////////////////////////////////////
38inline void page_init( page_t   * page )
39{
40        page->flags    = 0;
41        page->order    = 0;
42        page->mapper   = NULL;
43        page->index    = 0;
44        page->refcount = 0;
45        page->forks    = 0;
46
47        remote_busylock_init( XPTR( local_cxy , &page->lock ), LOCK_PAGE_STATE );
48
49        list_entry_init( &page->list );
50}
51
52////////////////////////////////////////////
53inline void page_set_flag( page_t   * page,
54                           uint32_t   value )
55{
56        hal_atomic_or( (uint32_t *)&page->flags , (uint32_t)value );
57}
58
59//////////////////////////////////////////////
60inline void page_clear_flag( page_t   * page,
61                             uint32_t   value )
62{
63        hal_atomic_and( (uint32_t *)&page->flags , ~((uint32_t)value) );
64}
65
66//////////////////////////////////////////////
67inline bool_t page_is_flag( page_t   * page,
68                            uint32_t   value )
69{
70    return ( (page->flags & value) ? 1 : 0 );
71}
72
73////////////////////////////////////////////
74inline void page_refcount_up( page_t *page )
75{
76    hal_atomic_add( &page->refcount , +1 );
77}
78
79//////////////////////////////////////////////
80inline void page_refcount_down( page_t *page )
81{
82    hal_atomic_add( &page->refcount , -1 );
83}
84
85///////////////////////////////
86void page_zero( page_t * page )
87{
88        uint32_t   size = (1 << page->order) * CONFIG_PPM_PAGE_SIZE;
89
90        xptr_t base_xp = ppm_page2base( XPTR( local_cxy , page ) );
91
92        memset( GET_PTR( base_xp ) , 0 , size );
93}
94
95
96////////////////////////////////////////////////////
97inline void page_remote_set_flag( xptr_t    page_xp,
98                                  uint32_t  value )
99{
100    cxy_t    page_cxy = GET_CXY( page_xp );
101    page_t * page_ptr = GET_PTR( page_xp );
102
103        hal_remote_atomic_or( XPTR( page_cxy , &page_ptr->flags ) , value );
104}
105
106//////////////////////////////////////////////////////
107inline void page_remote_clear_flag( xptr_t    page_xp,
108                                    uint32_t  value )
109{
110    cxy_t    page_cxy = GET_CXY( page_xp );
111    page_t * page_ptr = GET_PTR( page_xp );
112
113        hal_remote_atomic_and( XPTR( page_cxy , &page_ptr->flags ) , value );
114}
115
116/////////////////////////////////////////////////////
117inline bool_t page_remote_is_flag( xptr_t    page_xp,
118                                   uint32_t  value )
119{
120    cxy_t    page_cxy = GET_CXY( page_xp );
121    page_t * page_ptr = GET_PTR( page_xp );
122
123    uint32_t flags = hal_remote_l32( XPTR( page_cxy , &page_ptr->flags ) );
124   
125    return (flags & value) ? 1 : 0;
126}
127
128/////////////////////////////////////////////////////
129inline void page_remote_refcount_up( xptr_t page_xp )
130{
131    cxy_t    page_cxy = GET_CXY( page_xp );
132    page_t * page_ptr = GET_PTR( page_xp );
133
134    hal_remote_atomic_add( XPTR( page_cxy , &page_ptr->refcount ) , 1 );
135}
136
137///////////////////////////////////////////////////////
138inline void page_remote_refcount_down( xptr_t page_xp )
139{
140    cxy_t    page_cxy = GET_CXY( page_xp );
141    page_t * page_ptr = GET_PTR( page_xp );
142
143    hal_remote_atomic_add( XPTR( page_cxy , &page_ptr->refcount ) , -1 );
144}
145
146///////////////////////////////////////////
147void page_remote_display( xptr_t  page_xp )
148{
149    page_t  page;   // local copy of page decriptor
150
151    hal_remote_memcpy( XPTR( local_cxy , &page ) , page_xp , sizeof( page_t ) );
152                     
153        printk("*** Page %d in cluster %x : ppn %x / flags %x / order %d / refcount %d\n",
154                page.index,
155            GET_CXY( page_xp ),
156                ppm_page2ppn( page_xp ),
157                page.flags,
158                page.order,
159                page.refcount );
160}
161
162
163
Note: See TracBrowser for help on using the repository browser.