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
RevLine 
[1]1/*
2 * page.c - physical page related operations implementation
3 *
4 * Authors  Ghassan Almaless (2008,2009,2010,2011,2012)
[23]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-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
[457]25#include <hal_kernel_types.h>
[1]26#include <hal_special.h>
27#include <hal_atomic.h>
28#include <list.h>
[567]29#include <queuelock.h>
[1]30#include <memcpy.h>
31#include <printk.h>
32#include <vfs.h>
33#include <process.h>
34#include <page.h>
35
[567]36
[1]37////////////////////////////////////////
38inline void page_init( page_t   * page )
39{
40        page->flags    = 0;
41        page->order    = 0;
[23]42        page->mapper   = NULL;
[1]43        page->index    = 0;
[22]44        page->refcount = 0;
[433]45        page->forks    = 0;
[23]46
[567]47        remote_busylock_init( XPTR( local_cxy , &page->lock ), LOCK_PAGE_STATE );
48
[1]49        list_entry_init( &page->list );
50}
51
52////////////////////////////////////////////
53inline void page_set_flag( page_t   * page,
[23]54                           uint32_t   value )
[1]55{
[22]56        hal_atomic_or( (uint32_t *)&page->flags , (uint32_t)value );
[1]57}
58
59//////////////////////////////////////////////
60inline void page_clear_flag( page_t   * page,
[23]61                             uint32_t   value )
[1]62{
[22]63        hal_atomic_and( (uint32_t *)&page->flags , ~((uint32_t)value) );
[1]64}
65
66//////////////////////////////////////////////
67inline bool_t page_is_flag( page_t   * page,
[23]68                            uint32_t   value )
[1]69{
[23]70    return ( (page->flags & value) ? 1 : 0 );
[1]71}
72
73////////////////////////////////////////////
74inline void page_refcount_up( page_t *page )
75{
[23]76    hal_atomic_add( &page->refcount , +1 );
[1]77}
78
79//////////////////////////////////////////////
80inline void page_refcount_down( page_t *page )
81{
[23]82    hal_atomic_add( &page->refcount , -1 );
[1]83}
84
85///////////////////////////////
86void page_zero( page_t * page )
87{
[315]88        uint32_t   size = (1 << page->order) * CONFIG_PPM_PAGE_SIZE;
[1]89
[315]90        xptr_t base_xp = ppm_page2base( XPTR( local_cxy , page ) );
[1]91
[315]92        memset( GET_PTR( base_xp ) , 0 , size );
[1]93}
94
[632]95
96////////////////////////////////////////////////////
97inline void page_remote_set_flag( xptr_t    page_xp,
98                                  uint32_t  value )
[1]99{
[632]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 );
[1]104}
105
[632]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.