Changeset 588
- Timestamp:
- Jul 8, 2015, 3:40:18 PM (9 years ago)
- Location:
- soft/giet_vm/giet_libs
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_libs/malloc.c
r541 r588 11 11 12 12 // Global variables defining the heap descriptors array (one heap per cluster) 13 giet_heap_t heap[X_SIZE][Y_SIZE];13 giet_heap_t heap[X_SIZE][Y_SIZE]; 14 14 15 15 // Macro returning the smallest power of 2 larger or equal to size value … … 51 51 unsigned int y ) 52 52 { 53 giet_shr_printf( 54 " - heap_base = %x\n" 55 " - heap_size = %x\n" 56 " - alloc_base = %x\n" 57 " - alloc_size = %x\n" 58 " - free[0] = %x\n" 59 " - free[1] = %x\n" 60 " - free[2] = %x\n" 61 " - free[3] = %x\n" 62 " - free[4] = %x\n" 63 " - free[5] = %x\n" 64 " - free[6] = %x\n" 65 " - free[7] = %x\n" 66 " - free[8] = %x\n" 67 " - free[9] = %x\n" 68 " - free[10] = %x\n" 69 " - free[11] = %x\n" 70 " - free[12] = %x\n" 71 " - free[13] = %x\n" 72 " - free[14] = %x\n" 73 " - free[15] = %x\n" 74 " - free[16] = %x\n" 75 " - free[17] = %x\n" 76 " - free[18] = %x\n" 77 " - free[19] = %x\n" 78 " - free[20] = %x\n" 79 " - free[21] = %x\n" 80 " - free[22] = %x\n" 81 " - free[23] = %x\n", 82 heap[x][y].heap_base, heap[x][y].heap_size, 83 heap[x][y].alloc_base, heap[x][y].alloc_size, 84 heap[x][y].free[0], heap[x][y].free[1], 85 heap[x][y].free[2], heap[x][y].free[3], 86 heap[x][y].free[4], heap[x][y].free[5], 87 heap[x][y].free[6], heap[x][y].free[7], 88 heap[x][y].free[8], heap[x][y].free[9], 89 heap[x][y].free[10], heap[x][y].free[11], 90 heap[x][y].free[12], heap[x][y].free[13], 91 heap[x][y].free[14], heap[x][y].free[15], 92 heap[x][y].free[16], heap[x][y].free[17], 93 heap[x][y].free[18], heap[x][y].free[19], 94 heap[x][y].free[20], heap[x][y].free[21], 95 heap[x][y].free[22], heap[x][y].free[23] ); 96 } // end display_free array() 53 unsigned int next; 54 unsigned int id; 55 unsigned int iter; 56 57 giet_shr_printf("\nUser Heap[%d][%d] base = %x / size = %x\n", x , y , 58 heap[x][y].heap_base, heap[x][y].heap_size ); 59 for ( id = 6 ; id < 28 ; id++ ) 60 { 61 next = heap[x][y].free[id]; 62 giet_shr_printf(" - free[%d] = " , id ); 63 iter = 0; 64 while ( next != 0 ) 65 { 66 giet_shr_printf("%x | ", next ); 67 next = (*(unsigned int*)next); 68 iter++; 69 } 70 giet_shr_printf("0\n"); 71 } 72 } // end display_free_array() 73 74 97 75 98 76 //////////////////////////////// … … 106 84 unsigned int alloc_base; // alloc[] array base 107 85 unsigned int alloc_size; // alloc[] array size 108 unsigned int alloc_index; // size_index in free[array]86 unsigned int alloc_index; // size_index in alloc[array] 109 87 110 88 unsigned int index; // iterator … … 149 127 } 150 128 129 // reset the alloc_size array 130 unsigned int word; 131 unsigned int* tab = (unsigned int*)alloc_base; 132 for ( word = 0 ; word < (alloc_size>>2) ; word++ ) tab[word] = 0; 133 151 134 // split the heap into various sizes blocks, 152 135 // initializes the free[] array and NEXT pointers … … 243 226 244 227 #if GIET_DEBUG_USER_MALLOC 245 giet_shr_printf("\n[DEBUG USER_MALLOC] Mallocrequest for Heap[%d][%d] / size = %x\n",228 giet_shr_printf("\n[DEBUG USER_MALLOC] request for Heap[%d][%d] / size = %x\n", 246 229 x, y, size ); 247 230 #endif … … 250 233 if (size == 0) 251 234 { 252 giet_exit(" ERROR inmalloc() : requested size = 0 \n");235 giet_exit("\nERROR in remote_malloc() : requested size = 0 \n"); 253 236 } 254 237 if ( x >= X_SIZE ) 255 238 { 256 giet_exit(" ERROR inmalloc() : x coordinate too large\n");239 giet_exit("\nERROR in remote_malloc() : x coordinate too large\n"); 257 240 } 258 241 if ( y >= Y_SIZE ) 259 242 { 260 giet_exit(" ERROR inmalloc() : y coordinate too large\n");243 giet_exit("\nERROR in remote_malloc() : y coordinate too large\n"); 261 244 } 262 245 … … 264 247 if ( heap[x][y].init != HEAP_INITIALIZED ) 265 248 { 266 giet_exit(" ERROR inmalloc() : heap not initialized\n");249 giet_exit("\nERROR in remote_malloc() : heap not initialized\n"); 267 250 } 268 251 … … 281 264 requested_index ); 282 265 283 // update the alloc[] array if block found 284 if ( base != 0 ) 285 { 286 unsigned offset = (base - heap[x][y].heap_base) / MIN_BLOCK_SIZE; 287 unsigned char* ptr = (unsigned char*)(heap[x][y].alloc_base + offset); 288 *ptr = requested_index; 289 } 266 // check block found 267 if ( base == 0 ) 268 { 269 lock_release( &heap[x][y].lock ); 270 giet_exit("\nERROR in remote_malloc() : no more space\n"); 271 } 272 273 // compute pointer in alloc[] array 274 unsigned offset = (base - heap[x][y].heap_base) / MIN_BLOCK_SIZE; 275 unsigned char* ptr = (unsigned char*)(heap[x][y].alloc_base + offset); 276 277 // check the alloc[] array 278 if ( *ptr != 0 ) 279 { 280 lock_release( &heap[x][y].lock ); 281 giet_exit("\nERROR in remote_malloc() : block already allocated ???\n"); 282 } 283 284 // update alloc_array 285 *ptr = requested_index; 290 286 291 287 // release the lock … … 293 289 294 290 #if GIET_DEBUG_USER_MALLOC 295 giet_shr_printf("\n[DEBUG USER_MALLOC] Malloc vaddr from Heap[%d][%d] = %x\n",296 x, y, base );291 giet_shr_printf("\n[DEBUG USER_MALLOC] allocated block from heap[%d][%d] : " 292 "base = %x / size = %x\n", x , y , base , size ); 297 293 display_free_array(x,y); 298 294 #endif … … 333 329 unsigned int size = 1<<size_index; 334 330 335 // compute companion_base and merged_base 336 unsigned int companion_base; // companion block base address 337 unsigned int merged_base; // merged block base address 338 if ( base % (size<<1) ) 331 // compute companion block and merged block base addresses 332 unsigned int companion_base; 333 unsigned int merged_base; 334 335 if ( (base & size) == 0 ) // the released block is aligned on (2*size) 339 336 { 340 337 companion_base = base + size; … … 352 349 unsigned int iter = heap->free[size_index]; 353 350 unsigned int prev = (unsigned int)&heap->free[size_index]; 354 while ( iter != 0)351 while ( iter ) 355 352 { 356 353 if ( iter == companion_base ) … … 359 356 break; 360 357 } 358 prev = iter; 361 359 iter = *(unsigned int*)iter; 362 prev = iter; 363 } 364 365 if ( found == 0 ) // Companion not found 366 { 367 // push the block in free[size_index] 360 } 361 362 if ( found == 0 ) // Companion not found => push in free[size_index] 363 { 368 364 *(unsigned int*)base = heap->free[size_index]; 369 365 heap->free[size_index] = base; … … 392 388 #endif 393 389 394 // get the lock protecting heap[x][y]395 lock_acquire( &heap[x][y].lock );396 397 390 // check ptr value 398 391 unsigned int base = (unsigned int)ptr; … … 403 396 } 404 397 398 // get the lock protecting heap[x][y] 399 lock_acquire( &heap[x][y].lock ); 400 405 401 // compute released block index in alloc[] array 406 402 unsigned index = (base - heap[x][y].heap_base ) / MIN_BLOCK_SIZE; … … 410 406 unsigned int size_index = (unsigned int)*pchar; 411 407 408 // check block allocation 409 if ( size_index == 0 ) 410 { 411 lock_release( &heap[x][y].lock ); 412 giet_exit("\nERROR in free() : released block not allocated ???\n"); 413 } 414 412 415 // check released block alignment 413 416 if ( base % (1 << size_index) ) 414 417 { 415 giet_exit(" ERROR in free() : released block not aligned");418 giet_exit("\nERROR in free() : released block not aligned\n"); 416 419 } 417 420 -
soft/giet_vm/giet_libs/malloc.h
r550 r588 14 14 // to MIN_BLOCK_SIZE (typically 128 bytes). 15 15 // - All free blocks are aligned. 16 // - They are pre-classed in NB_SIZES linked lists, where all blocks in the17 // samelist have the same size.16 // - They are pre-classed in NB_SIZES linked lists, where all blocks in a 17 // given list have the same size. 18 18 // - The NEXT pointer implementing those linked lists is written 19 19 // in the 4 first bytes of the block itself, using the unsigned int type. … … 40 40 // - This allocation policy has the nice following property: 41 41 // If the heap segment is aligned (the heap_base is a multiple of the 42 // heap_ base), all allocated blocks are aligned on the actual_size.42 // heap_size), all allocated blocks are aligned on the actual_size. 43 43 //////////////////////////////////////////////////////////////////////////////// 44 44 // Free policy: … … 52 52 // - The index in this array is computed from the allocated block base address: 53 53 // index = (block_base - heap_base) / MIN_BLOCK_SIZE 54 // - The alloc ated[] array is stored at the end of heap segment. This consume54 // - The alloc[] array is stored at the end of heap segment. This consume 55 55 // (1 / MIN_BLOCK_SIZE) of the total heap storage capacity. 56 56 //////////////////////////////////////////////////////////////////////////////// … … 73 73 // heap(x,y) descriptor (one per cluster) 74 74 //////////////////////////////////////////////////////////////////////////////// 75 75 76 typedef struct giet_heap_s 76 77 { 78 user_lock_t lock; // lock protecting exclusive access 77 79 unsigned int init; // initialised <=> value == HEAP_INITIALIZED 78 80 unsigned int x; // cluster X coordinate … … 82 84 unsigned int alloc_base; // alloc[] array base address 83 85 unsigned int alloc_size; // alloc[] array size (bytes) 84 user_lock_t lock; // lock protecting exclusive access85 86 unsigned int free[32]; // array of base addresses of free blocks 86 87 // (address of first block of a given size) -
soft/giet_vm/giet_libs/math/math_private.h
r581 r588 16 16 #define _MATH_PRIVATE_H_ 17 17 18 #include <stdint.h> 18 typedef unsigned int u_int32_t; 19 19 20 typedef uint32_t u_int32_t; 21 20 typedef int int32_t; 22 21 23 22 /* The original fdlibm code used statements like: -
soft/giet_vm/giet_libs/stdio.c
r581 r588 190 190 { 191 191 int val = va_arg( *args, int ); 192 if (modifiers != NO_MOD) goto return_error; // Modifiers have no meaning192 if (modifiers != NO_MOD) goto return_error; // Modifiers have no meaning 193 193 194 194 len = 1; … … 201 201 int val = va_arg( *args, int ); 202 202 203 if (modifiers == LL_MOD) goto return_error; // 64 bits not supported203 if (modifiers == LL_MOD) goto return_error; // 64 bits not supported 204 204 205 205 if (val < 0) … … 290 290 char* str = va_arg( *args, char* ); 291 291 292 if (modifiers != NO_MOD) goto return_error; // Modifiers have no meaning292 if (modifiers != NO_MOD) goto return_error; // Modifiers have no meaning 293 293 294 294 while (str[len]) … … 879 879 /////////////////////////////////////////////////////////////////////////////////// 880 880 881 /////////////////////////////////////////// 882 int giet_fat_open( const char* pathname, 883 unsigned int flags ) 884 { 885 int ret = sys_call( SYSCALL_FAT_OPEN, 886 (unsigned int)pathname, 887 flags, 888 0, 0 ); 889 if ( ret < 0 ) giet_exit("error in giet_fat_open()"); 890 return ret; 891 } 892 893 //////////////////////////////////// 894 void giet_fat_read( unsigned int fd, 881 ///////////////////////////////////////// 882 int giet_fat_open( char* pathname, 883 unsigned int flags ) 884 { 885 return sys_call( SYSCALL_FAT_OPEN, 886 (unsigned int)pathname, 887 flags, 888 0, 0 ); 889 } 890 891 ///////////////////////////////////////// 892 int giet_fat_close( unsigned int fd_id ) 893 { 894 return sys_call( SYSCALL_FAT_CLOSE, 895 fd_id, 896 0, 0, 0 ); 897 } 898 899 ///////////////////////////////////////////// 900 int giet_fat_file_info( unsigned int fd_id, 901 unsigned int* size, 902 unsigned int* offset ) 903 { 904 return sys_call( SYSCALL_FAT_FINFO, 905 fd_id, 906 (unsigned int)size, 907 (unsigned int)offset, 908 0 ); 909 } 910 911 /////////////////////////////////////// 912 int giet_fat_read( unsigned int fd_id, 913 void* buffer, 914 unsigned int count ) 915 { 916 return sys_call( SYSCALL_FAT_READ, 917 fd_id, 918 (unsigned int)buffer, 919 count, 920 0 ); 921 } 922 923 //////////////////////////////////////// 924 int giet_fat_write( unsigned int fd_id, 895 925 void* buffer, 896 unsigned int count, 897 unsigned int offset ) 898 { 899 if ( sys_call( SYSCALL_FAT_READ, 900 fd, 901 (unsigned int)buffer, 902 count, 903 offset ) != count ) giet_exit("ERROR in giet_fat_read()"); 904 } 905 906 ///////////////////////////////////// 907 void giet_fat_write( unsigned int fd, 908 void* buffer, 909 unsigned int count, 910 unsigned int offset ) 911 { 912 if ( sys_call( SYSCALL_FAT_WRITE, 913 fd, 914 (unsigned int)buffer, 915 count, 916 offset ) != count ) giet_exit("ERROR in giet_fat_write()"); 917 } 918 919 /* variant implementing the UNIX spec 920 /////////////////////////////////////////////////////////////////////////////////// 921 // This system call writes to a file identified by the "fd" file descriptor. 922 // - "buffer" is the source buffer virtual address (must be word aligned). 923 // - "count" is a number of bytes (must be multiple of 4). 924 // It uses the implicit "lseek" pointer in file descriptor. 925 /////////////////////////////////////////////////////////////////////////////////// 926 void giet_fat_write( unsigned int fd, 927 void* buffer, 928 unsigned int count ) // number of bytes 926 unsigned int count ) 929 927 { 930 928 return sys_call( SYSCALL_FAT_WRITE, 931 fd ,929 fd_id, 932 930 (unsigned int)buffer, 933 count, 0 );934 } 935 */ 936 937 ///////////////////////////////////// 938 void giet_fat_lseek( unsigned int fd, 931 count, 932 0 ); 933 } 934 935 //////////////////////////////////////// 936 int giet_fat_lseek( unsigned int fd_id, 939 937 unsigned int offset, 940 938 unsigned int whence ) 941 939 { 942 if ( sys_call( SYSCALL_FAT_LSEEK, 943 fd, 944 offset, 945 whence, 946 0 ) ) giet_exit("ERROR in giet_fat_lseek()"); 947 } 948 949 ////////////////////////////////////// 950 void giet_fat_fstat( unsigned int fd ) 951 { 952 if ( sys_call( SYSCALL_FAT_FSTAT, 953 fd, 954 0, 0, 0 ) ) giet_exit("ERROR in giet_fat_lseek()"); 940 return sys_call( SYSCALL_FAT_LSEEK, 941 fd_id, 942 offset, 943 whence, 944 0 ); 945 } 946 947 //////////////////////////////////////////// 948 int giet_fat_remove( char* pathname, 949 unsigned int should_be_dir ) 950 { 951 return sys_call( SYSCALL_FAT_REMOVE, 952 (unsigned int)pathname, 953 should_be_dir, 954 0, 0 ); 955 955 } 956 956 957 957 ///////////////////////////////////// 958 void giet_fat_close( unsigned int fd ) 959 { 960 if ( sys_call( SYSCALL_FAT_CLOSE, 961 fd, 962 0, 0, 0 ) ) giet_exit("ERROR in giet_fat_close()"); 963 } 964 958 int giet_fat_rename( char* old_path, 959 char* new_path ) 960 { 961 return sys_call( SYSCALL_FAT_RENAME, 962 (unsigned int)old_path, 963 (unsigned int)new_path, 964 0, 0 ); 965 } 966 967 //////////////////////////////////// 968 int giet_fat_mkdir( char* pathname ) 969 { 970 return sys_call( SYSCALL_FAT_MKDIR, 971 (unsigned int)pathname, 972 0, 0, 0 ); 973 } 974 975 ///////////////////////////////////// 976 int giet_fat_list( char* pathname ) 977 { 978 return sys_call( SYSCALL_FAT_LIST, 979 (unsigned int)pathname, 980 0, 0, 0 ); 981 } 965 982 966 983 -
soft/giet_vm/giet_libs/stdio.h
r558 r588 54 54 #define SYSCALL_FAT_WRITE 0x22 55 55 #define SYSCALL_FAT_LSEEK 0x23 56 #define SYSCALL_FAT_F STAT0x2456 #define SYSCALL_FAT_FINFO 0x24 57 57 #define SYSCALL_FAT_CLOSE 0x25 58 //0x2659 //0x2760 //0x2861 //0x2958 #define SYSCALL_FAT_REMOVE 0x26 59 #define SYSCALL_FAT_RENAME 0x27 60 #define SYSCALL_FAT_MKDIR 0x28 61 #define SYSCALL_FAT_LIST 0x29 62 62 // 0x2A 63 63 // 0x2B … … 83 83 #define SYSCALL_COPROC_RUN 0x3E 84 84 #define SYSCALL_COPROC_RELEASE 0x3F 85 86 //////////////////////////////////////////////////////////////////////////// 87 // These define must be synchronised vith values defined in fat32.h 88 //////////////////////////////////////////////////////////////////////////// 89 90 #define SEEK_SET 0 // argument for giet_fat_lseek() 91 #define SEEK_CUR 1 // argument for giet_fat_lseek 92 93 #define O_CREATE 0x20 // argument for giet_fat_open() 94 #define O_RDONLY 0x01 // argument for giet_fat_open() 85 95 86 96 //////////////////////////////////////////////////////////////////////////// … … 266 276 ////////////////////////////////////////////////////////////////////////// 267 277 268 extern int giet_fat_open( const char* pathname, 269 unsigned int flags ); 270 271 extern void giet_fat_read( unsigned int fd, 272 void* buffer, 273 unsigned int count, 274 unsigned int offset ); 275 276 extern void giet_fat_write( unsigned int fd, 277 void* buffer, 278 unsigned int count, 279 unsigned int offset ); 280 281 extern void giet_fat_lseek( unsigned int fd, 282 unsigned int offset, 283 unsigned int whence ); 284 285 extern void giet_fat_fstat( unsigned int fd ); 286 287 extern void giet_fat_close( unsigned int fd ); 278 extern int giet_fat_open( char* pathname, 279 unsigned int flags ); 280 281 extern int giet_fat_close( unsigned int fd_id ); 282 283 extern int giet_fat_file_info( unsigned int fd_id, 284 unsigned int* size, 285 unsigned int* offset ); 286 287 extern int giet_fat_read( unsigned int fd_id, 288 void* buffer, 289 unsigned int count ); 290 291 extern int giet_fat_write( unsigned int fd, 292 void* buffer, 293 unsigned int count ); 294 295 extern int giet_fat_lseek( unsigned int fd, 296 unsigned int offset, 297 unsigned int whence ); 298 299 extern int giet_fat_remove( char* pathname, 300 unsigned int should_be_dir ); 301 302 extern int giet_fat_rename( char* old_path, 303 char* new_path ); 304 305 extern int giet_fat_mkdir( char* pathname ); 306 307 extern int giet_fat_list( char* pathname ); 288 308 289 309 ////////////////////////////////////////////////////////////////////////// -
soft/giet_vm/giet_libs/user_barrier.c
r580 r588 35 35 unsigned int p; 36 36 giet_proc_xyp( &x, &y, &p ); 37 giet_shr_printf(" [DEBUG USER BARRIER] proc[%d,%d,%d] enters barrier_wait()\n",37 giet_shr_printf("\n[DEBUG USER BARRIER] proc[%d,%d,%d] enters barrier_wait()\n", 38 38 x, y, p ); 39 39 #endif … … 85 85 86 86 #if GIET_DEBUG_USER_BARRIER 87 giet_shr_printf(" [DEBUG USER BARRIER] proc[%d,%d,%d] exit barrier_wait()\n",87 giet_shr_printf("\n[DEBUG USER BARRIER] proc[%d,%d,%d] exit barrier_wait()\n", 88 88 x, y, p ); 89 89 #endif … … 126 126 127 127 #if GIET_DEBUG_USER_BARRIER 128 giet_shr_printf(" [DEBUG USER BARRIER] initialize sqt_node[%d][%d][%d] : arity = %d\n"128 giet_shr_printf("\n[DEBUG USER BARRIER] initialize sqt_node[%d][%d][%d] : arity = %d\n" 129 129 " parent = %x / child0 = %x / child1 = %x / child2 = %x / child3 = %x\n", 130 130 x, y, level, node->arity, … … 175 175 176 176 #if GIET_DEBUG_USER_BARRIER 177 giet_shr_printf(" [DEBUG USER BARRIER] initialize sqt_node[%d][%d][%d] : arity = %d\n"177 giet_shr_printf("\n[DEBUG USER BARRIER] initialize sqt_node[%d][%d][%d] : arity = %d\n" 178 178 " parent = %x / child0 = %x / child1 = %x / child0 = %x / child1 = %x\n", 179 179 x, y, level, node->arity, … … 248 248 249 249 #if GIET_DEBUG_USER_BARRIER 250 giet_shr_printf(" [DEBUG USER BARRIER] SQT node[%d][%d][%d] : vaddr = %x\n",250 giet_shr_printf("\n[DEBUG USER BARRIER] SQT node[%d][%d][%d] : vaddr = %x\n", 251 251 x, y, l, (unsigned int)barrier->node[x][y][l] ); 252 252 #endif -
soft/giet_vm/giet_libs/user_barrier.h
r501 r588 65 65 typedef struct giet_sqt_barrier_s 66 66 { 67 sqt_node_t* node[16][16][5]; // array of pointers on S BT nodes67 sqt_node_t* node[16][16][5]; // array of pointers on SQT nodes 68 68 } giet_sqt_barrier_t; 69 69
Note: See TracChangeset
for help on using the changeset viewer.