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

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

This version is a major evolution: The physical memory allocators,
defined in the kmem.c, ppm.c, and kcm.c files have been modified
to support remote accesses. The RPCs that were previously user
to allocate physical memory in a remote cluster have been removed.
This has been done to cure a dead-lock in case of concurrent page-faults.

This version 2.2 has been tested on a (4 clusters / 2 cores per cluster)
TSAR architecture, for both the "sort" and the "fft" applications.

File size: 4.8 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
50////////////////////////////////////////////
51inline void page_set_flag( page_t   * page,
52                           uint32_t   value )
53{
54        hal_atomic_or( (uint32_t *)&page->flags , (uint32_t)value );
55}
56
57//////////////////////////////////////////////
58inline void page_clear_flag( page_t   * page,
59                             uint32_t   value )
60{
61        hal_atomic_and( (uint32_t *)&page->flags , ~value );
62}
63
64//////////////////////////////////////////////
65inline bool_t page_is_flag( page_t   * page,
66                            uint32_t   value )
67{
68    return ( (page->flags & value) ? 1 : 0 );
69}
70
71////////////////////////////////////////////
72inline void page_refcount_up( page_t *page )
73{
74    hal_atomic_add( &page->refcount , +1 );
75}
76
77//////////////////////////////////////////////
78inline void page_refcount_down( page_t *page )
79{
80    hal_atomic_add( &page->refcount , -1 );
81}
82
83///////////////////////////////
84void page_zero( page_t * page )
85{
86        uint32_t   size = (1 << page->order) * CONFIG_PPM_PAGE_SIZE;
87
88        xptr_t base_xp = ppm_page2base( XPTR( local_cxy , page ) );
89
90        memset( GET_PTR( base_xp ) , 0 , size );
91}
92
93
94
95
96///////////////////////////////////////////////
97inline void page_remote_init( xptr_t  page_xp )
98{
99        hal_remote_memset( page_xp , 0 , sizeof(page_t) );
100
101    cxy_t    page_cxy = GET_CXY( page_xp );
102    page_t * page_ptr = GET_PTR( page_xp );
103
104        remote_busylock_init( XPTR( page_cxy , &page_ptr->lock ), LOCK_PAGE_STATE );
105}
106
107////////////////////////////////////////////////////
108inline void page_remote_set_flag( xptr_t    page_xp,
109                                  uint32_t  value )
110{
111    cxy_t    page_cxy = GET_CXY( page_xp );
112    page_t * page_ptr = GET_PTR( page_xp );
113
114        hal_remote_atomic_or( XPTR( page_cxy , &page_ptr->flags ) , value );
115}
116
117//////////////////////////////////////////////////////
118inline void page_remote_clear_flag( xptr_t    page_xp,
119                                    uint32_t  value )
120{
121    cxy_t    page_cxy = GET_CXY( page_xp );
122    page_t * page_ptr = GET_PTR( page_xp );
123
124        hal_remote_atomic_and( XPTR( page_cxy , &page_ptr->flags ) , ~value );
125}
126
127/////////////////////////////////////////////////////
128inline bool_t page_remote_is_flag( xptr_t    page_xp,
129                                   uint32_t  value )
130{
131    cxy_t    page_cxy = GET_CXY( page_xp );
132    page_t * page_ptr = GET_PTR( page_xp );
133
134    uint32_t flags = hal_remote_l32( XPTR( page_cxy , &page_ptr->flags ) );
135   
136    return (flags & value) ? 1 : 0;
137}
138
139/////////////////////////////////////////////////////
140inline void page_remote_refcount_up( xptr_t page_xp )
141{
142    cxy_t    page_cxy = GET_CXY( page_xp );
143    page_t * page_ptr = GET_PTR( page_xp );
144
145    hal_remote_atomic_add( XPTR( page_cxy , &page_ptr->refcount ) , 1 );
146}
147
148///////////////////////////////////////////////////////
149inline void page_remote_refcount_down( xptr_t page_xp )
150{
151    cxy_t    page_cxy = GET_CXY( page_xp );
152    page_t * page_ptr = GET_PTR( page_xp );
153
154    hal_remote_atomic_add( XPTR( page_cxy , &page_ptr->refcount ) , -1 );
155}
156
157///////////////////////////////////////////
158void page_remote_display( xptr_t  page_xp )
159{
160    page_t  page;   // local copy of page decriptor
161
162    hal_remote_memcpy( XPTR( local_cxy , &page ) , page_xp , sizeof( page_t ) );
163                     
164        printk("*** Page %d in cluster %x : ppn %x / flags %x / order %d / refcount %d\n",
165                page.index,
166            GET_CXY( page_xp ),
167                ppm_page2ppn( page_xp ),
168                page.flags,
169                page.order,
170                page.refcount );
171}
172
173
174
Note: See TracBrowser for help on using the repository browser.