Changeset 671
- Timestamp:
- Nov 19, 2020, 11:47:00 PM (4 years ago)
- Location:
- trunk/kernel/libk
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/elf.c
r657 r671 2 2 * elf.c - elf parser: find and map process CODE and DATA segments 3 3 * 4 * Authors Alain Greiner (2016,2017,2018,2019 )4 * Authors Alain Greiner (2016,2017,2018,2019,2020) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 43 43 static bool_t elf_isValidHeader(Elf_Ehdr *header) 44 44 { 45 if( (header->e_ident[EI_CLASS] == ELFCLASS)46 && (header->e_ident[EI_DATA] == ELFDATA2LSB)47 && (header->e_ident[EI_VERSION] == EV_CURRENT)48 && ((header->e_machine == EM_MIPS)||49 50 (header->e_machine == EM_X86_64))51 && (header->e_type == ET_EXEC))45 if( (header->e_ident[EI_CLASS] == ELFCLASS) && 46 (header->e_ident[EI_DATA] == ELFDATA2LSB) && 47 (header->e_ident[EI_VERSION] == EV_CURRENT) && 48 ( (header->e_machine == EM_MIPS) || 49 (header->e_machine == EM_MIPS_RS3_LE) || 50 (header->e_machine == EM_X86_64) ) && 51 (header->e_type == ET_EXEC) ) 52 52 return true; 53 53 … … 73 73 74 74 /////////////////////////////////////////////////////////////////////////////////////// 75 // This function loads the .elf header in the buffer allocated by the caller.75 // This static function loads the .elf header in the buffer allocated by the caller. 76 76 /////////////////////////////////////////////////////////////////////////////////////// 77 77 // @ file : extended pointer on the remote file descriptor. … … 171 171 // get .elf file descriptor cluster and local pointer 172 172 cxy_t file_cxy = GET_CXY( file_xp ); 173 vfs_file_t * file_ptr = (vfs_file_t *)GET_PTR( file_xp );173 vfs_file_t * file_ptr = GET_PTR( file_xp ); 174 174 175 175 // get local pointer on .elf file mapper … … 192 192 } 193 193 194 // update reference counter in file descriptor195 vfs_file_count_up( file_xp );196 197 194 #if DEBUG_ELF_LOAD 198 195 uint32_t cycle = (uint32_t)hal_get_cycles(); … … 200 197 if( DEBUG_ELF_LOAD < cycle ) 201 198 printk("\n[%s] thread[%x,%x] found %s vseg / base %x / size %x\n" 202 " file_size %x / file_offset %x / mapper _xp %l/ cycle %d\n",199 " file_size %x / file_offset %x / mapper[%x,%x] / cycle %d\n", 203 200 __FUNCTION__ , this->process->pid, this->trdid, 204 201 vseg_type_str(vseg->type) , vseg->min , vseg->max - vseg->min , 205 vseg->file_size , vseg->file_offset , vseg->mapper_xp, cycle ); 202 vseg->file_size , vseg->file_offset , 203 GET_CXY(vseg->mapper_xp), GET_PTR(vseg->mapper_xp), cycle ); 206 204 #endif 207 205 … … 225 223 226 224 // get file cluster and local pointer 227 cxy_t file_cxy = GET_CXY( file_xp ); 228 vfs_file_t * file_ptr = GET_PTR( file_xp ); 229 225 cxy_t file_cxy = GET_CXY( file_xp ); 226 vfs_file_t * file_ptr = GET_PTR( file_xp ); 227 228 // get inode pointer 229 vfs_inode_t * inode_ptr = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) ); 230 230 231 // get file name for error reporting and debug 231 vfs_inode_t * inode = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) ); 232 vfs_inode_get_name( XPTR( file_cxy , inode ) , name ); 232 vfs_inode_get_name( XPTR( file_cxy , inode_ptr ) , name ); 233 233 234 234 #if DEBUG_ELF_LOAD … … 252 252 #if (DEBUG_ELF_LOAD & 1) 253 253 if( DEBUG_ELF_LOAD < cycle ) 254 printk("\n[%s] loaded elf header for <%s>\n", __FUNCTION__ , name ); 254 printk("\n[%s] loaded elf header for <%s>\n" 255 " - size = %x\n" 256 " - version = %x\n" 257 " - entry = %x\n" 258 " - machine = %x\n" 259 " - offset = %x\n" 260 " - segnum = %x\n", 261 __FUNCTION__, name, 262 header.e_ehsize, 263 header.e_version, 264 header.e_entry, 265 header.e_machine, 266 header.e_phoff, 267 header.e_phnum ); 255 268 #endif 256 269 -
trunk/kernel/libk/elf.h
r625 r671 229 229 /**************************************************************************************** 230 230 * This function registers in the VSL of the process identified by the <process> 231 * argument the CODE and DATA vsegs defined in the .elf file descriptor <file_xp>.232 * The segmentsare not loaded in memory.233 * It also registers the process entry point in VMM.231 * argument the CODE and DATA vsegs defined in the .elf file identidied by the 232 * file descriptor <file_xp>. The segments themselve are not loaded in memory. 233 * It also registers the process entry point in the process VMM. 234 234 **************************************************************************************** 235 * @ file_xp : extended pointer on .elf file descriptor.235 * @ file_xp : extended pointer on the .elf file descriptor. 236 236 * @ process : local pointer on target process descriptor. 237 237 ***************************************************************************************/ -
trunk/kernel/libk/grdxt.c
r657 r671 82 82 uint32_t ix3; 83 83 84 assert( (rt != NULL) , "pointer on radix tree is NULL\n" );84 assert( __FUNCTION__, (rt != NULL) , "pointer on radix tree is NULL\n" ); 85 85 86 86 for( ix1=0 ; ix1 < (uint32_t)(1 << w1) ; ix1++ ) … … 136 136 137 137 // Check key value 138 assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );138 assert( __FUNCTION__, ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key ); 139 139 140 140 // compute indexes … … 202 202 203 203 // Check key value 204 assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );204 assert( __FUNCTION__, ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key ); 205 205 206 206 // compute indexes … … 244 244 245 245 // Check key value 246 assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );246 assert( __FUNCTION__, ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key ); 247 247 248 248 void ** ptr1 = rt->root; … … 284 284 285 285 // Check key value 286 assert( ((start_key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", start_key );286 assert( __FUNCTION__, ((start_key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", start_key ); 287 287 288 288 // compute max indexes … … 407 407 for( ix2=0 ; ix2 < (uint32_t)(1 << w2) ; ix2++ ) 408 408 { 409 // get ptr 2409 // get ptr3 410 410 ptr3 = hal_remote_lpt( XPTR( rt_cxy , &ptr2[ix2] ) ); 411 411 … … 470 470 471 471 // Check key value 472 assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );472 assert( __FUNCTION__, ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key ); 473 473 474 474 // compute indexes … … 585 585 586 586 // Check key value 587 assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );587 assert( __FUNCTION__, ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key ); 588 588 589 589 // compute indexes … … 628 628 629 629 // Check key value 630 assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );630 assert( __FUNCTION__, ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key ); 631 631 632 632 // compute indexes … … 678 678 679 679 // Check key value 680 assert( ((start_key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", start_key );680 assert( __FUNCTION__, ((start_key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", start_key ); 681 681 682 682 // compute min indexes … … 734 734 735 735 // check rt_xp 736 assert( (rt_xp != XPTR_NULL) , "pointer on radix tree is NULL\n" );736 assert( __FUNCTION__, (rt_xp != XPTR_NULL) , "pointer on radix tree is NULL\n" ); 737 737 738 738 // get cluster and local pointer on remote rt descriptor -
trunk/kernel/libk/grdxt.h
r657 r671 2 2 * grdxt.h - Three-levels Generic Radix-tree definition. 3 3 * 4 * Authors Alain Greiner (2016,2017,2018,2019,2019 )4 * Authors Alain Greiner (2016,2017,2018,2019,2019,2020) 5 5 * 6 6 * Copyright UPMC Sorbonne Universites -
trunk/kernel/libk/htab.c
r610 r671 104 104 else 105 105 { 106 assert( false , "undefined item type\n" );106 assert( __FUNCTION__, false , "undefined item type\n" ); 107 107 } 108 108 -
trunk/kernel/libk/list.h
r656 r671 3 3 * 4 4 * Authors Ghassan Almaless (2008,2009,2010,2011,2012) 5 * Alain Greiner (2016,2017,2018,2019 )5 * Alain Greiner (2016,2017,2018,2019,2020) 6 6 * 7 7 * Copyright (c) UPMC Sorbonne Universites … … 219 219 static inline void list_unlink( list_entry_t * entry ) 220 220 { 221 list_entry_t * pred; 222 list_entry_t * next; 223 224 pred = entry->pred; 225 next = entry->next; 221 list_entry_t * pred = entry->pred; 222 list_entry_t * next = entry->next; 226 223 227 224 pred->next = next; 228 225 next->pred = pred; 226 227 entry->next = NULL; 228 entry->pred = NULL; 229 229 } 230 230 … … 406 406 list_entry_t * entry ) 407 407 { 408 list_entry_t * pred; 409 list_entry_t * next; 410 411 pred = hal_remote_lpt( XPTR( cxy , &entry->pred ) ); 412 next = hal_remote_lpt( XPTR( cxy , &entry->next ) ); 408 list_entry_t * pred = hal_remote_lpt( XPTR( cxy , &entry->pred ) ); 409 list_entry_t * next = hal_remote_lpt( XPTR( cxy , &entry->next ) ); 413 410 414 411 hal_remote_spt( XPTR( cxy , &pred->next ) , next ); 415 412 hal_remote_spt( XPTR( cxy , &next->pred ) , pred ); 413 414 hal_remote_spt( XPTR( cxy , &entry->next ) , NULL ); 415 hal_remote_spt( XPTR( cxy , &entry->pred ) , NULL ); 416 416 } 417 417 -
trunk/kernel/libk/remote_barrier.c
r635 r671 478 478 479 479 // check x_size and y_size arguments 480 assert( (z <= 16) , "DQT mesh size larger than (16*16)\n");480 assert( __FUNCTION__, (z <= 16) , "DQT mesh size larger than (16*16)\n"); 481 481 482 482 // check size of an array of 5 DQT nodes 483 assert( (sizeof(dqt_node_t) * 5 <= 512 ), "array of DQT nodes larger than 512 bytes\n");483 assert( __FUNCTION__, (sizeof(dqt_node_t) * 5 <= 512 ), "array of DQT nodes larger than 512 bytes\n"); 484 484 485 485 // check size of DQT barrier descriptor 486 assert( (sizeof(dqt_barrier_t) <= 0x4000 ), "DQT barrier descriptor larger than 4 pages\n");486 assert( __FUNCTION__, (sizeof(dqt_barrier_t) <= 0x4000 ), "DQT barrier descriptor larger than 4 pages\n"); 487 487 488 488 // get pointer on client thread and process descriptors … … 767 767 void * buf = GET_PTR( buf_xp ); 768 768 769 assert( (cxy == GET_CXY(buf_xp)) , "bad extended pointer on dqt_nodes array\n" );769 assert( __FUNCTION__, (cxy == GET_CXY(buf_xp)) , "bad extended pointer on dqt_nodes array\n" ); 770 770 771 771 req.type = KMEM_KCM; -
trunk/kernel/libk/remote_buf.c
r666 r671 31 31 #include <remote_buf.h> 32 32 33 ///////////////////////////////////////////// 34 remote_buf_t * remote_buf_alloc( cxy_t cxy ) 35 { 36 kmem_req_t req; 37 38 req.type = KMEM_KCM; 39 req.order = bits_log2( sizeof(remote_buf_t) ); 40 req.flags = AF_ZERO; 41 return kmem_remote_alloc( cxy , &req ); 42 } 43 33 44 ///////////////////////////////////////// 34 45 error_t remote_buf_init( xptr_t buf_xp, 35 uint32_t size ) 36 { 46 uint32_t order ) 47 { 48 49 assert( __FUNCTION__ , (buf_xp != XPTR_NULL) , "buf_xp cannot be NULL" ); 50 assert( __FUNCTION__ , (order < 32) , "order cannot be larger than 31" ); 51 37 52 kmem_req_t req; 38 53 uint8_t * data; … … 42 57 43 58 // allocate the data buffer 44 if( size == 0 ) 45 { 46 data = NULL; 47 } 48 else if( size >= CONFIG_PPM_PAGE_SIZE ) 59 if( order >= CONFIG_PPM_PAGE_SHIFT ) // use KMEM_PPM 49 60 { 50 61 req.type = KMEM_PPM; 51 req.order = bits_log2( size >> CONFIG_PPM_PAGE_SHIFT );62 req.order = order - CONFIG_PPM_PAGE_SHIFT; 52 63 req.flags = AF_NONE; 53 64 data = kmem_remote_alloc( buf_cxy , &req ); … … 55 66 if( data == NULL ) return -1; 56 67 } 57 else 68 else // use KMEM_KCM 58 69 { 59 70 req.type = KMEM_KCM; 60 req.order = bits_log2( size );71 req.order = order; 61 72 req.flags = AF_NONE; 62 73 data = kmem_remote_alloc( buf_cxy , &req ); … … 66 77 67 78 // initialize buffer descriptor 68 hal_remote_s32( XPTR( buf_cxy , &buf_ptr-> size ) , size);69 hal_remote_s32( XPTR( buf_cxy , &buf_ptr-> ptw) , 0 );70 hal_remote_s32( XPTR( buf_cxy , &buf_ptr-> ptr) , 0 );71 hal_remote_s32( XPTR( buf_cxy , &buf_ptr->sts ) , 0 );72 hal_remote_spt( XPTR( buf_cxy , &buf_ptr->data ) , data );79 hal_remote_s32( XPTR( buf_cxy , &buf_ptr->order ) , order ); 80 hal_remote_s32( XPTR( buf_cxy , &buf_ptr->wid ) , 0 ); 81 hal_remote_s32( XPTR( buf_cxy , &buf_ptr->rid ) , 0 ); 82 hal_remote_s32( XPTR( buf_cxy , &buf_ptr->sts ) , 0 ); 83 hal_remote_spt( XPTR( buf_cxy , &buf_ptr->data ) , data ); 73 84 74 85 return 0; 75 86 76 87 } // end remote_buf_init() 88 89 ////////////////////////////////////////////// 90 void remote_buf_release_data( xptr_t buf_xp ) 91 { 92 kmem_req_t req; 93 94 assert( __FUNCTION__ , (buf_xp != XPTR_NULL) , "buf_xp cannot be NULL" ); 95 96 remote_buf_t * buf_ptr = GET_PTR( buf_xp ); 97 cxy_t buf_cxy = GET_CXY( buf_xp ); 98 99 // gets data buffer local pointer and order 100 uint32_t order = hal_remote_l32( XPTR( buf_cxy , &buf_ptr->order )); 101 char * data_ptr = hal_remote_lpt( XPTR( buf_cxy , &buf_ptr->data )); 102 103 // release memory allocated for data buffer if required 104 if( data_ptr != NULL ) 105 { 106 if( order >= CONFIG_PPM_PAGE_SHIFT ) // use KMEM_PPM 107 { 108 req.type = KMEM_PPM; 109 req.ptr = data_ptr; 110 kmem_remote_free( buf_cxy , &req ); 111 } 112 else // use KMEM_KCM 113 { 114 req.type = KMEM_KCM; 115 req.ptr = data_ptr; 116 kmem_remote_free( buf_cxy , &req ); 117 } 118 } 119 } // end remote_buf_release_data() 77 120 78 121 ///////////////////////////////////////// 79 122 void remote_buf_destroy( xptr_t buf_xp ) 80 123 { 124 125 assert( __FUNCTION__ , (buf_xp != XPTR_NULL) , "buf_xp cannot be NULL" ); 126 81 127 kmem_req_t req; 82 128 … … 84 130 cxy_t buf_cxy = GET_CXY( buf_xp ); 85 131 86 uint32_t size = hal_remote_l32( XPTR( buf_cxy , &buf_ptr->size )); 87 88 // release memory allocated to data buffer if required 89 if( size == 0 ) 90 { 91 return; 92 } 93 else if( size >= CONFIG_PPM_PAGE_SIZE ) 94 { 95 req.type = KMEM_PPM; 96 req.ptr = hal_remote_lpt( XPTR( buf_cxy , &buf_ptr->data ) ); 97 kmem_remote_free( buf_cxy , &req ); 98 } 99 else 100 { 101 req.type = KMEM_KCM; 102 req.ptr = hal_remote_lpt( XPTR( buf_cxy , &buf_ptr->data ) ); 103 kmem_remote_free( buf_cxy , &req ); 104 } 105 } 132 // release data buffer 133 remote_buf_release_data( buf_xp ); 134 135 // release remote_buf descriptor 136 req.type = KMEM_KCM; 137 req.ptr = buf_ptr; 138 kmem_remote_free( buf_cxy , &req ); 139 140 } // end remote_buf_destroy() 106 141 107 142 ///////////////////////////////////////// 108 143 void remote_buf_reset( xptr_t buf_xp ) 109 144 { 110 remote_buf_t * buf_ptr = GET_PTR( buf_xp ); 111 cxy_t buf_cxy = GET_CXY( buf_xp ); 112 113 hal_remote_s32( XPTR( buf_cxy , &buf_ptr->ptw ) , 0 ); 114 hal_remote_s32( XPTR( buf_cxy , &buf_ptr->ptr ) , 0 ); 145 146 assert( __FUNCTION__ , (buf_xp != XPTR_NULL) , "buf_xp cannot be NULL" ); 147 148 remote_buf_t * buf_ptr = GET_PTR( buf_xp ); 149 cxy_t buf_cxy = GET_CXY( buf_xp ); 150 151 hal_remote_s32( XPTR( buf_cxy , &buf_ptr->wid ) , 0 ); 152 hal_remote_s32( XPTR( buf_cxy , &buf_ptr->rid ) , 0 ); 115 153 hal_remote_s32( XPTR( buf_cxy , &buf_ptr->sts ) , 0 ); 116 154 } … … 121 159 uint32_t nbytes ) 122 160 { 161 162 assert( __FUNCTION__ , (buf_xp != XPTR_NULL) , "buf_xp cannot be NULL" ); 163 123 164 remote_buf_t * buf_ptr = GET_PTR( buf_xp ); 124 165 cxy_t buf_cxy = GET_CXY( buf_xp ); 125 166 126 167 // build relevant extended pointers 127 xptr_t sts_xp = XPTR( buf_cxy , &buf_ptr->sts );128 xptr_t ptr_xp = XPTR( buf_cxy , &buf_ptr->ptr);129 xptr_t size_xp = XPTR( buf_cxy , &buf_ptr->size);130 xptr_t data_xp = XPTR( buf_cxy , &buf_ptr->data );168 xptr_t sts_xp = XPTR( buf_cxy , &buf_ptr->sts ); 169 xptr_t rid_xp = XPTR( buf_cxy , &buf_ptr->rid ); 170 xptr_t order_xp = XPTR( buf_cxy , &buf_ptr->order ); 171 xptr_t data_xp = XPTR( buf_cxy , &buf_ptr->data ); 131 172 132 173 // get relevant infos from remote buffer descriptor 133 174 uint32_t sts = hal_remote_l32( sts_xp ); 134 uint32_t ptr = hal_remote_l32( ptr_xp );135 uint32_t size = hal_remote_l32( size_xp );175 uint32_t rid = hal_remote_l32( rid_xp ); 176 uint32_t order = hal_remote_l32( order_xp ); 136 177 uint8_t * data = hal_remote_lpt( data_xp ); 178 179 uint32_t size = 1 << order; 180 uint32_t mask = size - 1; 137 181 138 182 // check enough bytes in buffer … … 140 184 141 185 // move nbytes 142 if( ( ptr+ nbytes) <= size) // no wrap around => one move186 if( (rid + nbytes) <= size) // no wrap around => one move 143 187 { 144 188 hal_copy_to_uspace( u_buf, 145 XPTR( buf_cxy , data + ptr),189 XPTR( buf_cxy , data + rid ), 146 190 nbytes ); 147 191 } 148 192 else // wrap around => two moves 149 193 { 150 uint32_t bytes_1 = size - ptr;194 uint32_t bytes_1 = size - rid; 151 195 uint32_t bytes_2 = nbytes - bytes_1; 152 196 153 197 hal_copy_to_uspace( u_buf, 154 XPTR( buf_cxy , data + ptr),198 XPTR( buf_cxy , data + rid ), 155 199 bytes_1 ); 156 200 … … 160 204 } 161 205 162 // update ptrin buffer descriptor163 hal_remote_s32( ptr_xp , (ptr + nbytes) % size);206 // update rid in buffer descriptor 207 hal_remote_s32( rid_xp , (rid + nbytes) & mask ); 164 208 165 209 // atomically update sts … … 175 219 uint32_t nbytes ) 176 220 { 221 222 assert( __FUNCTION__ , (buf_xp != XPTR_NULL) , "buf_xp cannot be NULL" ); 223 177 224 remote_buf_t * buf_ptr = GET_PTR( buf_xp ); 178 225 cxy_t buf_cxy = GET_CXY( buf_xp ); 179 226 180 227 // build relevant extended pointers 181 xptr_t sts_xp = XPTR( buf_cxy , &buf_ptr->sts );182 xptr_t ptr_xp = XPTR( buf_cxy , &buf_ptr->ptr);183 xptr_t size_xp = XPTR( buf_cxy , &buf_ptr->size);184 xptr_t data_xp = XPTR( buf_cxy , &buf_ptr->data );228 xptr_t sts_xp = XPTR( buf_cxy , &buf_ptr->sts ); 229 xptr_t rid_xp = XPTR( buf_cxy , &buf_ptr->rid ); 230 xptr_t order_xp = XPTR( buf_cxy , &buf_ptr->order ); 231 xptr_t data_xp = XPTR( buf_cxy , &buf_ptr->data ); 185 232 186 233 // get relevant infos from remote buffer descriptor 187 234 uint32_t sts = hal_remote_l32( sts_xp ); 188 uint32_t ptr = hal_remote_l32( ptr_xp );189 uint32_t size = hal_remote_l32( size_xp );235 uint32_t rid = hal_remote_l32( rid_xp ); 236 uint32_t order = hal_remote_l32( order_xp ); 190 237 uint8_t * data = hal_remote_lpt( data_xp ); 238 239 uint32_t size = 1 << order; 240 uint32_t mask = size - 1; 191 241 192 242 // check enough bytes in buffer … … 194 244 195 245 // move nbytes 196 if( ( ptr+ nbytes) <= size) // no wrap around => one move246 if( (rid + nbytes) <= size) // no wrap around => one move 197 247 { 198 248 hal_remote_memcpy( XPTR( local_cxy , k_buf ), 199 XPTR( buf_cxy , data + ptr),249 XPTR( buf_cxy , data + rid ), 200 250 nbytes ); 201 251 } 202 252 else // wrap around => two moves 203 253 { 204 uint32_t bytes_1 = size - ptr;254 uint32_t bytes_1 = size - rid; 205 255 uint32_t bytes_2 = nbytes - bytes_1; 206 256 207 257 hal_remote_memcpy( XPTR( local_cxy , k_buf ), 208 XPTR( buf_cxy , data + ptr),258 XPTR( buf_cxy , data + rid ), 209 259 bytes_1 ); 210 260 … … 214 264 } 215 265 216 // update ptrin buffer descriptor217 hal_remote_s32( ptr_xp , (ptr + nbytes) % size);266 // update rid in buffer descriptor 267 hal_remote_s32( rid_xp , (rid + nbytes) & mask ); 218 268 219 269 // atomically update sts … … 222 272 return 0; 223 273 224 } // end remote_buf_get_to_ user()274 } // end remote_buf_get_to_kernel() 225 275 226 276 /////////////////////////////////////////////////// … … 229 279 uint32_t nbytes ) 230 280 { 281 282 assert( __FUNCTION__ , (buf_xp != XPTR_NULL) , "buf_xp cannot be NULL" ); 283 231 284 remote_buf_t * buf_ptr = GET_PTR( buf_xp ); 232 285 cxy_t buf_cxy = GET_CXY( buf_xp ); 233 286 234 287 // build relevant extended pointers 235 xptr_t sts_xp = XPTR( buf_cxy , &buf_ptr->sts );236 xptr_t ptw_xp = XPTR( buf_cxy , &buf_ptr->ptw);237 xptr_t size_xp = XPTR( buf_cxy , &buf_ptr->size);238 xptr_t data_xp = XPTR( buf_cxy , &buf_ptr->data );288 xptr_t sts_xp = XPTR( buf_cxy , &buf_ptr->sts ); 289 xptr_t wid_xp = XPTR( buf_cxy , &buf_ptr->wid ); 290 xptr_t order_xp = XPTR( buf_cxy , &buf_ptr->order ); 291 xptr_t data_xp = XPTR( buf_cxy , &buf_ptr->data ); 239 292 240 293 // get relevant infos from remote buffer descriptor 241 294 uint32_t sts = hal_remote_l32( sts_xp ); 242 uint32_t ptw = hal_remote_l32( ptw_xp );243 uint32_t size = hal_remote_l32( size_xp );295 uint32_t wid = hal_remote_l32( wid_xp ); 296 uint32_t order = hal_remote_l32( order_xp ); 244 297 uint8_t * data = hal_remote_lpt( data_xp ); 298 299 uint32_t size = 1 << order; 300 uint32_t mask = size - 1; 245 301 246 302 // check enough space in buffer … … 248 304 249 305 // move nbytes 250 if( ( ptw+ nbytes) <= size) // no wrap around => one move251 { 252 hal_copy_from_uspace( XPTR( buf_cxy , data + ptw),306 if( (wid + nbytes) <= size) // no wrap around => one move 307 { 308 hal_copy_from_uspace( XPTR( buf_cxy , data + wid ), 253 309 u_buf, 254 310 nbytes ); … … 256 312 else // wrap around => two moves 257 313 { 258 uint32_t bytes_1 = size - ptw;314 uint32_t bytes_1 = size - wid; 259 315 uint32_t bytes_2 = nbytes - bytes_1; 260 316 261 hal_copy_from_uspace( XPTR( buf_cxy , data + ptw),317 hal_copy_from_uspace( XPTR( buf_cxy , data + wid ), 262 318 u_buf, 263 319 bytes_1 ); … … 268 324 } 269 325 270 // update ptwin buffer descriptor271 hal_remote_s32( ptw_xp , (ptw + nbytes) % size);326 // update wid in buffer descriptor 327 hal_remote_s32( wid_xp , (wid + nbytes) & mask ); 272 328 273 329 // atomically update sts … … 283 339 uint32_t nbytes ) 284 340 { 341 342 assert( __FUNCTION__ , (buf_xp != XPTR_NULL) , "buf_xp cannot be NULL" ); 343 285 344 remote_buf_t * buf_ptr = GET_PTR( buf_xp ); 286 345 cxy_t buf_cxy = GET_CXY( buf_xp ); 287 346 288 347 // build relevant extended pointers 289 xptr_t sts_xp = XPTR( buf_cxy , &buf_ptr->sts );290 xptr_t ptw_xp = XPTR( buf_cxy , &buf_ptr->ptw);291 xptr_t size_xp = XPTR( buf_cxy , &buf_ptr->size);292 xptr_t data_xp = XPTR( buf_cxy , &buf_ptr->data );348 xptr_t sts_xp = XPTR( buf_cxy , &buf_ptr->sts ); 349 xptr_t wid_xp = XPTR( buf_cxy , &buf_ptr->wid ); 350 xptr_t order_xp = XPTR( buf_cxy , &buf_ptr->order ); 351 xptr_t data_xp = XPTR( buf_cxy , &buf_ptr->data ); 293 352 294 353 // get relevant infos from remote buffer descriptor 295 354 uint32_t sts = hal_remote_l32( sts_xp ); 296 uint32_t ptw = hal_remote_l32( ptw_xp );297 uint32_t size = hal_remote_l32( size_xp );355 uint32_t wid = hal_remote_l32( wid_xp ); 356 uint32_t order = hal_remote_l32( order_xp ); 298 357 uint8_t * data = hal_remote_lpt( data_xp ); 358 359 uint32_t size = 1 << order; 360 uint32_t mask = size - 1; 299 361 300 362 // check enough space in buffer … … 302 364 303 365 // move nbytes 304 if( ( ptw+ nbytes) <= size) // no wrap around => one move305 { 306 hal_remote_memcpy( XPTR( buf_cxy , data + ptw),366 if( (wid + nbytes) <= size) // no wrap around => one move 367 { 368 hal_remote_memcpy( XPTR( buf_cxy , data + wid ), 307 369 XPTR( local_cxy , k_buf ), 308 370 nbytes ); … … 310 372 else // wrap around => two moves 311 373 { 312 uint32_t bytes_1 = size - ptw;374 uint32_t bytes_1 = size - wid; 313 375 uint32_t bytes_2 = nbytes - bytes_1; 314 376 315 hal_remote_memcpy( XPTR( buf_cxy , data + ptw),377 hal_remote_memcpy( XPTR( buf_cxy , data + wid ), 316 378 XPTR( local_cxy , k_buf ), 317 379 bytes_1 ); … … 322 384 } 323 385 324 // update ptwin buffer descriptor325 hal_remote_s32( ptw_xp , (ptw + nbytes) % size);386 // update wid in buffer descriptor 387 hal_remote_s32( wid_xp , (wid + nbytes) & mask ); 326 388 327 389 // atomically update sts -
trunk/kernel/libk/remote_buf.h
r666 r671 32 32 * This structure and the associated access functions define a remotely accessible, 33 33 * kernel buffer, handled as a single-reader & single-writer FIFO. 34 * This kernel buffer is implementes as an array of bytes , whose size is35 * dynamically defined by an argument of the "remote_buf_init()" function.34 * This kernel buffer is implementes as an array of bytes. The size must be a power 35 * of 2, dynamically defined by an argument of the "remote_buf_init()" function. 36 36 * The "put()" and "get()" functions defined below move the content of another 37 37 * buffer (can be in kernel or in user space) to/from this circular kernel buffer. 38 38 * This structure is NOT protected by a lock, as the only shared variable is the 39 39 * "sts" variable, that is updated by the hal_remote_atomic_add() primitive. 40 * It is used to implement the three socket buffers (rx_buf / r2tq / crqq).41 * - the "ptw" field defines the first empty slot (for write).42 * - the "ptr" field defines the first non empty slot (for read).43 * - the "sts" field defines the total number of non empty slots.40 * 41 * - It is used to implement the three socket buffers (rx_buf / r2tq / crqq). 42 * - It is also used to implement the inter-process communications channels 43 * based on named "fifos", or unamed "pipes". 44 44 ***********************************************************************************/ 45 45 46 46 typedef struct remote_buf_s 47 47 { 48 uint32_t size; /*! number of slots in data buffer*/49 uint32_t ptw; /*! first empty slot index */50 uint32_t ptr; /*! first non-empty slot index */48 uint32_t order; /*! ln2( size of data buffer in bytes) */ 49 uint32_t rid; /*! first empty slot index */ 50 uint32_t wid; /*! first non-empty slot index */ 51 51 uint32_t sts; /*! current number of non empty slots */ 52 52 uint8_t * data; /*! local pointer on local data buffer */ … … 55 55 56 56 /************************************************************************************ 57 * This function allocates memory for a remote_buf descriptor in cluster 58 * defined by the <cxy> argument, and return a local pointer on this descriptor. 59 ************************************************************************************ 60 * @ cxy : target cluster identifier. 61 * @ return local pointer on remote_buf descriptor. 62 ***********************************************************************************/ 63 remote_buf_t * remote_buf_alloc( cxy_t cxy ); 64 65 /************************************************************************************ 57 66 * This function initializes a remote_buf descriptor identified by the <buf_xp> 58 * argument. It allocates memory for the data, as defined by the < size> argument,67 * argument. It allocates memory for the data, as defined by the <order> argument, 59 68 * and initializes the buffer as empty. It must be called by a local thread. 60 * No memory is allocated if <size> value is 0.69 * The <order> value cannot be larger than 31. 61 70 ************************************************************************************ 62 71 * @ buf_xp : [in] extended pointer on buffer descriptor. 63 * @ size : [in] number of bytes in buffer / no memory allocated when null.64 * @ return 0 if success / return -1 if memory failure .72 * @ order : [in] ln2( number of bytes in buffer) / must be in [0,31]. 73 * @ return 0 if success / return -1 if memory failure or illegal order. 65 74 ***********************************************************************************/ 66 75 error_t remote_buf_init( xptr_t buf_xp, 67 uint32_t size);76 uint32_t order ); 68 77 69 78 /************************************************************************************ 70 * This function releases memory allocated for the data buffer of a remote-buf 71 * descriptor identified by the <buf_xp> argument. 72 * It must be called by a local thread. 79 * This function releases memory allocated for the data buffer of an embedded 80 * remote-buf descriptor identified by the <buf_xp> argument, when the "data" 81 * pointer is not NULL. It does nothing if the data buffer was not allocated. 82 * WARNING : do NOT use this function for a dynamically allocated remote_buf. 83 ************************************************************************************ 84 * @ buf_xp : [in] extended pointer on buffer descriptor. 85 ***********************************************************************************/ 86 void remote_buf_release_data( xptr_t buf_xp ); 87 88 /************************************************************************************ 89 * This function releases both the memory allocated for the data buffer, and the 90 * memory allocated for the remote_buf descriptor, for a remote-buf identified 91 * by the <buf_xp> argument. 92 * WARNING : do NOT use this function an embedded remote_buf. 73 93 ************************************************************************************ 74 94 * @ buf_xp : [in] extended pointer on buffer descriptor. -
trunk/kernel/libk/remote_sem.c
r635 r671 188 188 189 189 // check calling thread can yield 190 assert( (this->busylocks == 0),190 assert( __FUNCTION__, (this->busylocks == 0), 191 191 "cannot yield : busylocks = %d\n", this->busylocks ); 192 192 -
trunk/kernel/libk/user_dir.c
r641 r671 124 124 125 125 // check dirent size 126 assert( ( sizeof(struct dirent) == 64), "sizeof(dirent) must be 64\n");126 assert( __FUNCTION__, ( sizeof(struct dirent) == 64), "sizeof(dirent) must be 64\n"); 127 127 128 128 // compute number of dirent per page … … 253 253 254 254 // check vseg size 255 assert( (total_pages == hal_remote_l32( XPTR( ref_cxy , &vseg->vpn_size ) ) ),255 assert( __FUNCTION__, (total_pages == hal_remote_l32( XPTR( ref_cxy , &vseg->vpn_size ) ) ), 256 256 "unconsistent vseg size for dirent array " ); 257 257 … … 324 324 325 325 // check number of pages 326 assert( (page_id == total_pages) , "unconsistent pages number\n" );326 assert( __FUNCTION__, (page_id == total_pages) , "unconsistent pages number\n" ); 327 327 328 328 // initialise user_dir_t structure -
trunk/kernel/libk/xhtab.c
r657 r671 2 2 * xhtab.c - Remote access embedded hash table implementation. 3 3 * 4 * Author Alain Greiner (2016,2017,2018,2019 )4 * Author Alain Greiner (2016,2017,2018,2019,2020) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 36 36 /////////////////////////////////////////////////////////////////////////////////////////// 37 37 // Item type specific functions (four functions for each item type). 38 // Example below is for <vfs_dentry_t> where the identifier is the dentry name.38 // Example below is for <vfs_dentry_t> type where the identifier is the dentry name. 39 39 /////////////////////////////////////////////////////////////////////////////////////////// 40 40 … … 147 147 else 148 148 { 149 assert( false , "illegal item type\n" );149 assert( __FUNCTION__, false , "illegal item type\n" ); 150 150 } 151 151 … … 285 285 286 286 /////////////////////////////////////// 287 bool_t xhtab_remove( xptr_t xhtab_xp,288 void * key,289 xptr_t xlist_entry_xp )287 error_t xhtab_remove( xptr_t xhtab_xp, 288 void * key, 289 xptr_t xlist_entry_xp ) 290 290 { 291 291 xptr_t item_xp; … … 316 316 remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) ); 317 317 318 return false;318 return -1; 319 319 } 320 320 else // remove item if found … … 329 329 remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) ); 330 330 331 return true;331 return 0; 332 332 } 333 333 } // end xhtab_remove() -
trunk/kernel/libk/xhtab.h
r657 r671 61 61 /////////////////////////////////////////////////////////////////////////////////////////// 62 62 63 #define XHASHTAB_SIZE 128// number of subsets63 #define XHASHTAB_SIZE 32 // number of subsets 64 64 65 65 /****************************************************************************************** … … 118 118 * @ key : local pointer on item identifier. 119 119 * @ xlist_xp : extended pointer on xlist_entry_t embedded in item to be registered. 120 * @ return 0 if success / return EINVALif item already registered.120 * @ return 0 if success / return -1 if item already registered. 121 121 *****************************************************************************************/ 122 122 error_t xhtab_insert( xptr_t xhtab_xp, … … 130 130 * @ key : local pointer on item identifier. 131 131 * @ xlist_xp : extended pointer on xlist_entry embedded in item to be removed. 132 * @ return 0 if item found / return falseif item not found.132 * @ return 0 if item found / return -1 if item not found. 133 133 *****************************************************************************************/ 134 bool_t xhtab_remove( xptr_t xhtab_xp,135 void * key,136 xptr_t xlist_entry_xp );134 error_t xhtab_remove( xptr_t xhtab_xp, 135 void * key, 136 xptr_t xlist_entry_xp ); 137 137 138 138 /****************************************************************************************** -
trunk/kernel/libk/xlist.h
r666 r671 264 264 /*************************************************************************** 265 265 * This function removes an entry from an extended double linked list. 266 * Two extended pointers must be modified.267 266 * The memory allocated to the removed entry is not released. 268 267 *************************************************************************** … … 280 279 xptr_t pred = entry.pred; 281 280 282 // update pred.next <= next281 // update pred.next & next.pred 283 282 hal_remote_s64( pred , (uint64_t)next ); 284 285 // update next.pred <= pred286 283 hal_remote_s64( next + sizeof(xptr_t) , (uint64_t)pred ); 284 285 // reset the removed entry itself 286 hal_remote_s64( xp , XPTR_NULL ); 287 hal_remote_s64( xp + sizeof(xptr_t) , XPTR_NULL ); 287 288 } 288 289
Note: See TracChangeset
for help on using the changeset viewer.