Changeset 495 for soft/giet_vm/giet_common/kernel_malloc.c
- Timestamp:
- Feb 8, 2015, 12:55:35 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_common/kernel_malloc.c
r466 r495 6 6 //////////////////////////////////////////////////////////////////////////////// 7 7 // Implementation note: 8 // - As this code is used to implement the S BT lock ptotecting TTY0,8 // - As this code is used to implement the SQT lock ptotecting TTY0, 9 9 // all functions here use the kernel _nolock_printf() function. 10 10 // - It must exist one vseg with the HEAP type in each cluster. The length … … 37 37 #include "mapping_info.h" 38 38 #include "kernel_malloc.h" 39 #include " locks.h"39 #include "kernel_locks.h" 40 40 #include "tty0.h" 41 41 #include "utils.h" … … 45 45 /////////////////////////////////////////////////////////////////////////////// 46 46 47 extern kernel_heap_t kernel_heap[X_SIZE][Y_SIZE]; 47 __attribute__((section(".kdata"))) 48 kernel_heap_t kernel_heap[X_SIZE][Y_SIZE]; 48 49 49 50 /////////////////////////////////////////////////////////////////////////////// … … 83 84 (size <= 0x80000000) ? 31 :\ 84 85 32 86 85 87 #if GIET_DEBUG_SYS_MALLOC 86 88 //////////////////////////////////////////////// … … 115 117 " - free[22] = %x\n" 116 118 " - free[23] = %x\n", 117 kernel_heap[x][y].x, kernel_heap[x][y].y,119 x, y, 118 120 kernel_heap[x][y].heap_base, kernel_heap[x][y].heap_size, 119 121 kernel_heap[x][y].free[0] , kernel_heap[x][y].free[1], … … 135 137 136 138 137 ///////////////////////////////////////////// 138 void_get_heap_info( unsigned int* heap_base,139 unsigned int* heap_size,140 unsigned int x,141 unsigned int y )139 ///////////////////////////////////////////////////// 140 unsigned int _get_heap_info( unsigned int* heap_base, 141 unsigned int* heap_size, 142 unsigned int x, 143 unsigned int y ) 142 144 { 143 145 mapping_header_t * header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; … … 155 157 if ( (x >= X_SIZE) || (y >= Y_SIZE) ) 156 158 { 157 _nolock_printf(" [GIET ERROR] _get_heap_info() illegal (%d,%d) coordinates\n",158 x , y );159 _nolock_printf("\n[GIET ERROR] _get_heap_info()" 160 " illegal (%d,%d) coordinates\n", x , y ); 159 161 _exit(); 160 162 } … … 172 174 *heap_base = vsegs[vseg_id].vbase; 173 175 *heap_size = vobjs[vobj_id].length; 174 return ;176 return 0; 175 177 } 176 178 } 177 179 178 // exit if not found 179 _nolock_printf("[GIET ERROR] _get_heap_info() heap[%d][%d] vseg not found\n", 180 x , y ); 181 _exit(); 182 180 return 1; 183 181 } // end _get_heap_info() 184 182 … … 191 189 unsigned int heap_size; 192 190 unsigned int heap_index; 193 194 191 unsigned int index; 195 192 unsigned int x; 196 193 unsigned int y; 194 unsigned int ko; 197 195 198 196 for ( x = 0 ; x < X_SIZE ; x++ ) … … 201 199 { 202 200 // get heap_base, heap size, and heap index 203 _get_heap_info( &heap_base, &heap_size, x, y ); 204 heap_index = GET_SIZE_INDEX( heap_size ); 205 206 // checking heap segment constraints 207 if ( heap_size != (1<<heap_index) ) 201 ko = _get_heap_info( &heap_base, &heap_size, x, y ); 202 203 if ( ko ) // no kernel heap found in cluster[x][y] 208 204 { 209 _nolock_printf("[GIET ERROR] in _heap_init()" 210 " kernel_heap[â°d,â°d] not power of 2\n", x , y ); 211 _exit(); 205 // initialise kernel_heap[x][y] descriptor 206 kernel_heap[x][y].heap_base = 0; 207 kernel_heap[x][y].heap_size = 0; 208 _spin_lock_init( &kernel_heap[x][y].lock ); 212 209 } 213 if ( heap_base % heap_size )210 else // kernel heap found in cluster[x][y] 214 211 { 215 _nolock_printf("[GIET ERROR] in _heap_init()" 216 " kernel_heap[â°d,â°d] not aligned\n", x , y ); 217 _exit(); 212 heap_index = GET_SIZE_INDEX( heap_size ); 213 214 // check heap[x][y] constraints 215 if ( heap_size != (1<<heap_index) ) 216 { 217 _nolock_printf("\n[GIET ERROR] in _heap_init()" 218 " kernel_heap[â°d,â°d] not power of 2\n", x , y ); 219 _exit(); 220 } 221 if ( heap_base % heap_size ) 222 { 223 _nolock_printf("\n[GIET ERROR] in _heap_init()" 224 " kernel_heap[â°d,â°d] not aligned\n", x , y ); 225 _exit(); 226 } 227 228 // initialise the free[] array 229 for ( index = 0 ; index < 32 ; index++ ) 230 { 231 if (index == heap_index) kernel_heap[x][y].free[index] = heap_base; 232 else kernel_heap[x][y].free[index] = 0; 233 } 234 235 // initialise kernel_heap[x][y] descriptor 236 kernel_heap[x][y].heap_base = heap_base; 237 kernel_heap[x][y].heap_size = heap_size; 238 _spin_lock_init( &kernel_heap[x][y].lock ); 218 239 } 219 240 220 // initialise the free[] array221 for ( index = 0 ; index < 32 ; index++ )222 {223 if (index == heap_index) kernel_heap[x][y].free[index] = heap_base;224 else kernel_heap[x][y].free[index] = 0;225 }226 unsigned int* ptr = (unsigned int*)heap_base;227 *ptr = 0;228 229 // initialise kernel_heap[x][y] descriptor230 kernel_heap[x][y].x = x;231 kernel_heap[x][y].y = y;232 kernel_heap[x][y].heap_base = heap_base;233 kernel_heap[x][y].heap_size = heap_size;234 235 _spin_lock_init( &kernel_heap[x][y].lock );236 237 241 #if GIET_DEBUG_SYS_MALLOC 238 _nolock_printf("\n[DEBUG KERNEL_MALLOC] Completing kernel_heap[%d][%d] initialisation\n",239 x, y );242 _nolock_printf("\n[DEBUG KERNEL_MALLOC] Completing kernel_heap[%d][%d]" 243 " initialisation\n", x, y ); 240 244 _display_free_array(x,y); 241 245 #endif … … 248 252 249 253 ////////////////////////////////////////////// 250 unsigned int split_block( kernel_heap_t* heap,251 unsigned int vaddr,252 unsigned int searched_index,253 unsigned int requested_index )254 unsigned int _split_block( kernel_heap_t* heap, 255 unsigned int vaddr, 256 unsigned int searched_index, 257 unsigned int requested_index ) 254 258 { 255 259 // push the upper half block into free[searched_index-1] … … 258 262 heap->free[searched_index-1] = (unsigned int)new; 259 263 260 if ( searched_index == requested_index + 1 ) // terminal case:return lower half block264 if ( searched_index == requested_index + 1 ) // return lower half block 261 265 { 262 266 return vaddr; … … 264 268 else // non terminal case : lower half block must be split again 265 269 { 266 return split_block( heap, vaddr, searched_index-1, requested_index );267 } 268 } // end split_block()270 return _split_block( heap, vaddr, searched_index-1, requested_index ); 271 } 272 } // end _split_block() 269 273 270 274 271 275 272 276 ///////////////////////////////////////////// 273 unsigned int get_block( kernel_heap_t* heap,274 unsigned int searched_index,275 unsigned int requested_index )277 unsigned int _get_block( kernel_heap_t* heap, 278 unsigned int searched_index, 279 unsigned int requested_index ) 276 280 { 277 281 // test terminal case … … 285 289 if ( vaddr == 0 ) // block not found : search in free[searched_index+1] 286 290 { 287 return get_block( heap, searched_index+1, requested_index );291 return _get_block( heap, searched_index+1, requested_index ); 288 292 } 289 293 else // block found : pop it from free[searched_index] … … 300 304 else // split is required 301 305 { 302 return split_block( heap, vaddr, searched_index, requested_index );306 return _split_block( heap, vaddr, searched_index, requested_index ); 303 307 } 304 308 } 305 309 } 306 } // end get_block()310 } // end _get_block() 307 311 308 312 … … 314 318 { 315 319 // checking arguments 316 if ( size == 0)317 { 318 _nolock_printf(" [GIET ERROR] _remote_malloc() : requested size = 0\n");320 if ( x >= X_SIZE ) 321 { 322 _nolock_printf("\n[GIET ERROR] _remote_malloc() : x coordinate too large\n"); 319 323 _exit(); 320 324 } 321 if ( x >= X_SIZE )322 { 323 _nolock_printf(" [GIET ERROR] _remote_malloc() : xcoordinate too large\n");325 if ( y >= Y_SIZE ) 326 { 327 _nolock_printf("\n[GIET ERROR] _remote_malloc() : y coordinate too large\n"); 324 328 _exit(); 325 329 } 326 if ( y >= Y_SIZE)327 { 328 _nolock_printf(" [GIET ERROR] _remote_malloc() : y coordinate too large\n");330 if ( kernel_heap[x][y].heap_size == 0 ) 331 { 332 _nolock_printf("\n[GIET ERROR] _remote_malloc() : No heap[%d][%d]\n", x, y ); 329 333 _exit(); 334 330 335 } 331 336 … … 340 345 341 346 // call the recursive function get_block 342 unsigned int base = get_block( &kernel_heap[x][y],343 requested_index,344 requested_index );347 unsigned int base = _get_block( &kernel_heap[x][y], 348 requested_index, 349 requested_index ); 345 350 // release the lock 346 351 _spin_lock_release( &kernel_heap[x][y].lock ); 347 352 353 if ( base == 0 ) 354 { 355 _nolock_printf("\n[GIET ERROR] _remote_malloc() : no more space " 356 "in heap[%d][%d]", x, y ); 357 } 358 348 359 #if GIET_DEBUG_SYS_MALLOC 349 360 _nolock_printf("\n[DEBUG KERNEL_MALLOC] malloc vaddr %x from kernel_heap[%d][%d]\n", … … 354 365 return (void*)base; 355 366 356 } // end remote_malloc()367 } // end _remote_malloc() 357 368 358 369
Note: See TracChangeset
for help on using the changeset viewer.