Changeset 23 for trunk/kernel/kern
- Timestamp:
- Jun 18, 2017, 10:06:41 PM (8 years ago)
- Location:
- trunk/kernel/kern
- Files:
-
- 2 added
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/chdev.c
r16 r23 32 32 #include <rpc.h> 33 33 #include <chdev.h> 34 #include <devfs.h> 34 35 35 36 //////////////////////////////////////////// -
trunk/kernel/kern/chdev.h
r16 r23 41 41 * This file defines the kernel representation of a generic (i.e. implementation 42 42 * independant) Channel Device descriptor (in brief "chdev"). 43 * ALMOS-MKH supports multi-channels peripherals, and defines one separated descriptor44 * for each channel (and for each RX/TX direction for the NIC device).43 * ALMOS-MKH supports multi-channels peripherals, and defines one separated chdev 44 * descriptor for each channel (and for each RX/TX direction for the NIC device). 45 45 * Each chdev contains a waiting queue, registering the "client threads" requests, 46 46 * and an associated "server thread", handling these requests. … … 107 107 /****************************************************************************************** 108 108 * This structure defines a chdev descriptor. 109 * There is one chdev descriptor per channel.109 * For multi-channels device, there is one chdev descriptor per channel. 110 110 * This structure is NOT replicated, and can be located in any cluster. 111 111 * One kernel thread, in charge of handling the commands registered in the waiting queue … … 120 120 uint32_t channel; /*! channel index */ 121 121 bool_t is_rx; /*! relevant for NIC peripheral channels only */ 122 xptr_t base; /*! extended pointer on channel segment */ 122 xptr_t base; /*! extended pointer on channel segment paddr */ 123 char name[16]; /*! name (required by DEVFS) */ 123 124 124 125 dev_cmd_t * cmd; /*! local pointer on driver command function */ -
trunk/kernel/kern/cluster.c
r19 r23 4 4 * Author Ghassan Almaless (2008,2009,2010,2011,2012) 5 5 * Mohamed Lamine Karaoui (2015) 6 * Alain Greiner (2016 )6 * Alain Greiner (2016,2017) 7 7 * 8 8 * Copyright (c) UPMC Sorbonne Universites … … 49 49 /////////////////////////////////////////////////////////////////////////////////////////// 50 50 51 process_t process_zero; // allocated in kernel_init.c file51 extern process_t process_zero; // allocated in kernel_init.c file 52 52 53 53 … … 121 121 122 122 // initialise local_list in process manager 123 spinlock_init( &cluster->pmgr.local_lock);124 list_root_init( &cluster->pmgr.local_root);123 remote_spinlock_init( XPTR( local_cxy , &cluster->pmgr.local_lock ) ); 124 xlist_root_init( XPTR( local_cxy , &cluster->pmgr.local_root ) ); 125 125 cluster->pmgr.local_nr = 0; 126 126 … … 162 162 { 163 163 cluster_t * cluster = LOCAL_CLUSTER; 164 hal_atomic_ inc( &cluster->cores_in_kernel);164 hal_atomic_add( &cluster->cores_in_kernel , 1 ); 165 165 } 166 166 … … 169 169 { 170 170 cluster_t * cluster = LOCAL_CLUSTER; 171 hal_atomic_ dec( &cluster->cores_in_kernel);171 hal_atomic_add( &cluster->cores_in_kernel , -1 ); 172 172 } 173 173 … … 199 199 xptr_t cluster_get_reference_process_from_pid( pid_t pid ) 200 200 { 201 xptr_t xp; // extended pointer onprocess descriptor201 xptr_t ref_xp; // extended pointer on reference process descriptor 202 202 203 203 cluster_t * cluster = LOCAL_CLUSTER; … … 208 208 209 209 // Check valid PID 210 if( lpid >= CONFIG_MAX_PROCESS_PER_CLUSTER ) 211 { 212 printk("\n[PANIC] in %s : illegal PID\n", __FUNCTION__ ); 213 hal_core_sleep(); 214 } 210 if( lpid >= CONFIG_MAX_PROCESS_PER_CLUSTER ) return XPTR_NULL; 215 211 216 212 if( local_cxy == owner_cxy ) // local cluster is owner cluster 217 213 { 218 xp = cluster->pmgr.pref_tbl[lpid];214 ref_xp = cluster->pmgr.pref_tbl[lpid]; 219 215 } 220 216 else // use a remote_lwd to access owner cluster 221 217 { 222 xp = (xptr_t)hal_remote_lwd( XPTR( owner_cxy , &cluster->pmgr.pref_tbl[lpid] ) );223 } 224 225 return xp;218 ref_xp = (xptr_t)hal_remote_lwd( XPTR( owner_cxy , &cluster->pmgr.pref_tbl[lpid] ) ); 219 } 220 221 return ref_xp; 226 222 } 227 223 … … 303 299 process_t * cluster_get_local_process_from_pid( pid_t pid ) 304 300 { 305 process_t * ret = NULL; 306 list_entry_t * root = &LOCAL_CLUSTER->pmgr.local_root; 307 list_entry_t * iter; 308 process_t * process; 309 310 LIST_FOREACH( root , iter ) 311 { 312 process = LIST_ELEMENT( iter , process_t , local_list ); 313 if( process->pid == pid ) 301 xptr_t process_xp; 302 process_t * process_ptr; 303 xptr_t root_xp; 304 xptr_t iter_xp; 305 bool_t found; 306 307 found = false; 308 root_xp = XPTR( local_cxy , &LOCAL_CLUSTER->pmgr.local_root ); 309 310 XLIST_FOREACH( root_xp , iter_xp ) 311 { 312 process_xp = XLIST_ELEMENT( iter_xp , process_t , local_list ); 313 process_ptr = (process_t *)GET_PTR( process_xp ); 314 if( process_ptr->pid == pid ) 314 315 { 315 ret = process;316 found = true; 316 317 break; 317 318 } 318 319 } 319 return ret; 320 321 if (found ) return process_ptr; 322 else return NULL; 320 323 321 324 } // end cluster_get_local_process_from_pid() … … 327 330 328 331 // get lock protecting the process manager local list 329 spinlock_lock( &pm->local_lock ); 330 331 list_add_first( &pm->local_root , &process->local_list ); 332 remote_spinlock_lock( XPTR( local_cxy , &pm->local_lock ) ); 333 334 xlist_add_first( XPTR( local_cxy , &pm->local_root ), 335 XPTR( local_cxy , &process->local_list ) ); 332 336 pm->local_nr++; 333 337 334 338 // release lock protecting the process manager local list 335 spinlock_unlock( &pm->local_lock);339 remote_spinlock_unlock( XPTR( local_cxy , &pm->local_lock ) ); 336 340 } 337 341 … … 342 346 343 347 // get lock protecting the process manager local list 344 spinlock_lock( &pm->local_lock);345 346 list_unlink( &process->local_list);348 remote_spinlock_lock( XPTR( local_cxy , &pm->local_lock ) ); 349 350 xlist_unlink( XPTR( local_cxy , &process->local_list ) ); 347 351 pm->local_nr--; 348 352 349 353 // release lock protecting the process manager local list 350 spinlock_unlock( &pm->local_lock);354 remote_spinlock_unlock( XPTR( local_cxy , &pm->local_lock ) ); 351 355 } 352 356 -
trunk/kernel/kern/cluster.h
r19 r23 4 4 * authors Ghassan Almaless (2008,2009,2010,2011,2012) 5 5 * Mohamed Lamine Karaoui (2015) 6 * Alain Greiner (2016 )6 * Alain Greiner (2016,2017) 7 7 * 8 8 * Copyright (c) UPMC Sorbonne Universites … … 49 49 struct core_s; 50 50 struct process_s; 51 struct device_s;52 51 53 52 … … 56 55 * For any process P, the process descriptor is replicated in all clusters containing 57 56 * at least one thread of process P, but only the "reference" cluster descriptor contains 58 * the reference (complete) structures such as the GPT, the VSL, or the FDT. 59 * The "owner" cluster is in charge to allocate a lpid (local process index), 60 * for all process owned by a cluster K, and to register the "reference" cluster for 61 * all process owned by K. 57 * the reference (complete) GPT, VSL, and FDT structures. 58 * The "owner" cluster K is in charge to allocate a lpid (local process index), 59 * to the owned processes, and to register the "reference" cluster for these processes. 62 60 * 63 61 * Warning : the "owner" cluster, and the "reference" cluster can be different clusters. 64 62 * 65 63 * The process manager of a cluster K maintains three structures: 66 * 1) The pref_tbl[] is an array indexed by lpid , for all processes owned by cluster K.64 * 1) The pref_tbl[] is an array indexed by lpid. There is one entry per owned process. 67 65 * Each entry contains an extended pointer on the reference process descriptor. 66 * 68 67 * 2) The local_root is the root of the local list of process descriptors in cluster K. 69 68 * A process descriptor P is present in K, as soon as P has a thread in cluster K. 70 * 3) The copies_root[] array is indexed by lpid. Each entry contains the root of 71 * the xlist of copies for a given process owned by cluster K. 69 * 70 * 3) The copies_root[] array is indexed by lpid. There is one entry per owned process, 71 * and each each entry contains the root of the xlist of copies for this process. 72 72 ******************************************************************************************/ 73 73 … … 78 78 uint32_t pref_nr; /*! number of processes owned by cluster */ 79 79 80 list_entry_tlocal_root; /*! root of list of process in cluster */81 spinlock_tlocal_lock; /*! lock protecting access to local list */80 xlist_entry_t local_root; /*! root of list of process in cluster */ 81 remote_spinlock_t local_lock; /*! lock protecting access to local list */ 82 82 uint32_t local_nr; /*! number of process in cluster */ 83 83 … … 96 96 typedef struct cluster_s 97 97 { 98 spinlock_t kcm_lock; /*! local, protect creation of KCM allocators*/98 spinlock_t kcm_lock; /*! local, protect creation of KCM allocators */ 99 99 100 100 // global parameters 101 101 102 uint32_t paddr_width; /*! numer of bits in physical address*/103 uint32_t x_width; /*! number of bits to code x_size (can be 0)*/104 uint32_t y_width; /*! number of bits to code y_size (can be 0)*/105 uint32_t x_size; /*! number of clusters in a row (can be 1)*/106 uint32_t y_size; /*! number of clusters in a column (can be 1)*/107 cxy_t io_cxy; /*! io cluster identifier*/108 uint32_t dqdt_root_level; /*! index of root node in dqdt_tbl[]*/102 uint32_t paddr_width; /*! numer of bits in physical address */ 103 uint32_t x_width; /*! number of bits to code x_size (can be 0) */ 104 uint32_t y_width; /*! number of bits to code y_size (can be 0) */ 105 uint32_t x_size; /*! number of clusters in a row (can be 1) */ 106 uint32_t y_size; /*! number of clusters in a column (can be 1) */ 107 cxy_t io_cxy; /*! io cluster identifier */ 108 uint32_t dqdt_root_level; /*! index of root node in dqdt_tbl[] */ 109 109 110 110 // local parameters 111 111 112 uint32_t cores_nr; /*! number of cores in cluster*/113 uint32_t cores_in_kernel; /*! number of cores currently in kernel mode*/112 uint32_t cores_nr; /*! number of cores in cluster */ 113 uint32_t cores_in_kernel; /*! number of cores currently in kernel mode */ 114 114 115 115 core_t core_tbl[CONFIG_MAX_LOCAL_CORES]; /*! embedded cores */ 116 116 117 ppm_t ppm; /*! embedded kernel page manager*/118 khm_t khm; /*! embedded kernel heap manager*/119 kcm_t kcm; /*! embedded kernel cache manager (for KCMs)*/117 ppm_t ppm; /*! embedded kernel page manager */ 118 khm_t khm; /*! embedded kernel heap manager */ 119 kcm_t kcm; /*! embedded kernel cache manager (for KCMs) */ 120 120 121 121 kcm_t * kcm_tbl[KMEM_TYPES_NR]; /*! pointers on allocated KCMs */ 122 122 123 uint32_t ram_size; /*! physical memory size */ 124 uint32_t ram_base; /*! physical memory base (local address) */ 125 126 rpc_fifo_t rpc_fifo; /*! cluster RPC fifo (shared) */ 127 list_entry_t devlist; /*! root of list of devices in cluster */ 128 struct device_s * icu; /*! pointer on local XCU device */ 129 130 int32_t pages_var; /*! pages number increment from last update */ 131 int32_t threads_var; /*! threads number increment from last update */ 123 uint32_t ram_size; /*! physical memory size */ 124 uint32_t ram_base; /*! physical memory base (local address) */ 125 126 rpc_fifo_t rpc_fifo; /*! cluster RPC fifo (shared) */ 127 list_entry_t devlist; /*! root of list of devices in cluster */ 128 129 int32_t pages_var; /*! pages number increment from last DQQT update */ 130 int32_t threads_var; /*! threads number increment from last DQDT update */ 132 131 133 132 dqdt_node_t dqdt_tbl[CONFIG_MAX_DQDT_DEPTH]; /*! embedded DQDT nodes */ 134 133 135 pmgr_t pmgr; /*! embedded process manager*/134 pmgr_t pmgr; /*! embedded process manager */ 136 135 137 136 char name[CONFIG_SYSFS_NAME_LEN]; … … 192 191 /****************************************************************************************** 193 192 * This function returns an extended pointer on the reference process descriptor 194 * from the process PID. It can be called by any thread running in any cluster,195 * as it uses a RPC to the owner cluster if the current cluster is not the owner.193 * from the process PID. This PID can be be different from the calling thread process. 194 * It can be called by any thread running in any cluster, 196 195 ****************************************************************************************** 197 196 * @ pid : process identifier. 198 * @ return extended pointer on the reference process descriptor.197 * @ return extended pointer on reference process if success / return XPTR_NULL if error. 199 198 *****************************************************************************************/ 200 199 xptr_t cluster_get_reference_process_from_pid( pid_t pid ); -
trunk/kernel/kern/core.c
r19 r23 38 38 #include <core.h> 39 39 40 // TODO #include <sysfs.h>41 42 40 ///////////////////////////////// 43 41 void core_init( core_t * core, … … 100 98 //////////////////////////////////// 101 99 void core_get_time( core_t * core, 102 uint32_t * tm_ ms,100 uint32_t * tm_s, 103 101 uint32_t * tm_us ) 104 102 { -
trunk/kernel/kern/do_syscall.c
r16 r23 2 2 * do_syscall.c - architecture independant entry-point for system calls. 3 3 * 4 * A Uthor Alain Greiner (2016)4 * Author Alain Greiner (2016) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 31 31 32 32 ///////////////////////////////////////////////////////////////////////////////////////////// 33 // This array of pointers define the kernel functions for syscalls. 33 ///////////////////////////////////////////////////////////////////////////////////////////// 34 static inline int sys_undefined() 35 { 36 printk("\n[PANIC] in %s : undefined system call\n", __FUNCTION__ ); 37 hal_core_sleep(); 38 return 0; 39 } 40 41 ///////////////////////////////////////////////////////////////////////////////////////////// 42 // This array of pointers define the kernel functions implementing the syscalls. 34 43 // It must be kept consistent with the enum in syscalls.h 35 44 ///////////////////////////////////////////////////////////////////////////////////////////// … … 39 48 static const sys_func_t syscall_tbl[SYSCALLS_NR] = 40 49 { 41 sys_thread_exit, // 0 42 sys_mmap, // 1 43 sys_thread_create, // 2 44 sys_thread_join, // 3 45 sys_thread_detach, // 4 46 sys_thread_yield, // 5 47 sys_sem, // 6 48 sys_cond_var, // 7 49 sys_barrier, // 8 50 sys_rwlock, // 9 51 sys_thread_sleep, // 10 52 sys_thread_wakeup, // 11 53 sys_open, // 12 54 sys_creat, // 13 55 sys_read, // 14 56 sys_write, // 15 57 sys_lseek, // 16 58 sys_close, // 17 59 sys_unlink, // 18 60 sys_pipe, // 19 61 sys_chdir, // 20 62 sys_mkdir, // 21 63 sys_mkfifo, // 22 64 sys_opendir, // 23 65 sys_readdir, // 24 66 sys_closedir, // 25 67 sys_getcwd, // 26 68 sys_clock, // 27 69 sys_alarm, // 28 70 sys_dma_memcpy, // 29 71 sys_utls, // 30 72 sys_notAvailable, // 31 Reserved for sigreturn TODO ??? 73 sys_signal, // 32 74 sys_sigreturn_setup, // 33 75 sys_kill, // 34 76 sys_getpid, // 35 77 sys_fork, // 36 78 sys_exec, // 37 79 sys_thread_getattr, // 38 80 sys_ps, // 39 81 sys_madvise, // 40 82 sys_mcntl, // 41 83 sys_stat, // 42 84 sys_thread_migrate, // 43 85 sys_sbrk, // 44 86 sys_rmdir, // 45 87 sys_ftime, // 46 88 sys_chmod, // 47 89 sys_fsync, // 48 90 sys_gettimeofday, // 49 91 sys_times // 50 50 sys_thread_exit, // 0 51 sys_mmap, // 1 52 sys_thread_create, // 2 53 sys_thread_join, // 3 54 sys_thread_detach, // 4 55 sys_thread_yield, // 5 56 sys_sem, // 6 57 sys_condvar, // 7 58 sys_barrier, // 8 59 sys_mutex, // 9 60 sys_thread_sleep, // 10 61 sys_thread_wakeup, // 11 62 sys_open, // 12 63 sys_creat, // 13 64 sys_read, // 14 65 sys_write, // 15 66 sys_lseek, // 16 67 sys_close, // 17 68 sys_unlink, // 18 69 sys_pipe, // 19 70 sys_chdir, // 20 71 sys_mkdir, // 21 72 sys_mkfifo, // 22 73 sys_opendir, // 23 74 sys_readdir, // 24 75 sys_closedir, // 25 76 sys_getcwd, // 26 77 sys_clock, // 27 78 sys_alarm, // 28 79 sys_rmdir, // 29 80 sys_utls, // 30 81 sys_chmod, // 31 82 sys_signal, // 32 83 sys_gettimeofday, // 33 84 sys_kill, // 34 85 sys_getpid, // 35 86 sys_fork, // 36 87 sys_exec, // 37 88 sys_stat, // 38 89 sys_trace, // 39 92 90 }; 93 91 -
trunk/kernel/kern/dqdt.c
r19 r23 150 150 151 151 // set child[3] extended pointer (coordinates may overflow) 152 if ( (level > 0) && ((x + (1<<(level-1))) < x_size) && ((y + (1<<(level-1))) < y_size) ) 152 if ( (level > 0) && 153 ((x + (1<<(level-1))) < x_size) && 154 ((y + (1<<(level-1))) < y_size) ) 153 155 { 154 156 c_cxy = local_cxy + ((1<<(level-1))<<y_width) + (1<<(level-1)); -
trunk/kernel/kern/kernel_init.c
r19 r23 2 2 * kernel_init.c - kernel parallel initialization 3 3 * 4 * Authors : Alain Greiner (2016)5 * Mohamed Lamine Karaoui (2016)4 * Authors : Mohamed Lamine Karaoui (2015) 5 * Alain Greiner (2016,2017) 6 6 * 7 7 * Copyright (c) Sorbonne Universites … … 53 53 #include <vfs.h> 54 54 #include <soclib_tty.h> 55 56 // TODO #include <devfs.h> 55 #include <devfs.h> 56 57 57 // TODO #include <sysfs.h> 58 58 … … 601 601 // @ return 0 if success / return EINVAL if not found. 602 602 /////////////////////////////////////////////////////////////////////////////////////////// 603 static error_t core_get_identifiers( boot_info_t * info,604 uint32_t* lid,603 static error_t get_core_identifiers( boot_info_t * info, 604 lid_t * lid, 605 605 cxy_t * cxy, 606 606 gid_t * gid ) … … 637 637 void kernel_init( boot_info_t * info ) 638 638 { 639 uint32_tcore_lid = -1; // running core local index639 lid_t core_lid = -1; // running core local index 640 640 cxy_t core_cxy = -1; // running core cluster identifier 641 641 gid_t core_gid; // running core hardware identifier … … 646 646 647 647 // all cores get core identifiers 648 error = core_get_identifiers( info,648 error = get_core_identifiers( info, 649 649 &core_lid, 650 650 &core_cxy, … … 664 664 ///////////////////////////////////////////////////////////////////////////////// 665 665 666 kinit_dmsg("\n[INFO] %s : core[%x][%d] exit barrier 0 \n",667 __FUNCTION__ , core_cxy , core_lid );666 kinit_dmsg("\n[INFO] %s : core[%x][%d] exit barrier 0 at cycle %d\n", 667 __FUNCTION__ , core_cxy , core_lid , hal_time_stamp() ); 668 668 669 669 // all cores check core identifiers … … 675 675 hal_core_sleep(); 676 676 } 677 else678 {679 kinit_dmsg("\n[INFO] %s : core[%x][%d] enters at cycle %d / sp = %x\n",680 __FUNCTION__ , core_cxy , core_lid , hal_time_stamp() , hal_get_stack() );681 }682 677 683 678 // CP0 initializes the local cluster manager (cores and memory allocators) … … 691 686 __FUNCTION__ , local_cxy ); 692 687 hal_core_sleep(); 693 }694 else695 {696 kinit_dmsg("\n[INFO] %s : core[%x][%d] initialised cluster at cycle %d\n",697 __FUNCTION__ , core_cxy , core_lid , hal_time_stamp());698 688 } 699 689 } … … 706 696 ///////////////////////////////////////////////////////////////////////////////// 707 697 708 kinit_dmsg("\n[INFO] %s : core[%x][%d] exit barrier 1 \n",709 __FUNCTION__ , core_cxy , core_lid );698 kinit_dmsg("\n[INFO] %s : core[%x][%d] exit barrier 1 at cycle %d\n", 699 __FUNCTION__ , core_cxy , core_lid , hal_time_stamp() ); 710 700 711 701 // all cores get pointer on local cluster manager and on core descriptor … … 756 746 ///////////////////////////////////////////////////////////////////////////////// 757 747 758 kinit_dmsg("\n[INFO] %s : core[%x][%d] exit barrier 2 \n",759 __FUNCTION__ , core_cxy , core_lid );748 kinit_dmsg("\n[INFO] %s : core[%x][%d] exit barrier 2 at cycle %d\n", 749 __FUNCTION__ , core_cxy , core_lid , hal_time_stamp() ); 760 750 761 751 // all cores initialize the private idle thread descriptor … … 789 779 } 790 780 791 // TODO CP0 in IO cluster initialize VFS, devFS and sysFS 792 { 793 // devfs_root_init(); 794 // sysfs_root_init(); 795 // clusters_sysfs_register(); 796 // vfs_init(); 797 // sysconf_init(); 798 } 781 printk("\n bloup 0\n"); 782 783 // CP0 in all clusters initializes cooperatively VFS and DEVFS 784 if( (core_lid == 0) ) 785 { 786 xptr_t root_inode_xp; 787 788 // initialize root File System 789 if( CONFIG_VFS_ROOT_IS_FATFS ) 790 { 791 root_inode_xp = fatfs_init(); 792 } 793 else 794 { 795 printk("\n[PANIC] in %s : root FS must be FATFS\n", __FUNCTION__ ); 796 hal_core_sleep(); 797 } 798 799 if( root_inode_xp == XPTR_NULL ) 800 { 801 printk("\n[PANIC] in %s : core[%x][%d] cannot initialize file system\n", 802 __FUNCTION__ , local_cxy , core_lid ); 803 hal_core_sleep(); 804 } 805 806 printk("\n bloup 1\n"); 807 808 // mount the DEVFS File system 809 devfs_mount( root_inode_xp , "dev" ); 810 } 811 812 printk("\n bloup 2\n"); 799 813 800 814 // CP0 in I/O cluster print banner … … 811 825 ///////////////////////////////////////////////////////////////////////////////// 812 826 813 kinit_dmsg("\n[INFO] %s : core[%x][%d] exit barrier 3 \n",814 __FUNCTION__ , core_cxy , core_lid );827 kinit_dmsg("\n[INFO] %s : core[%x][%d] exit barrier 3 at cycle %d\n", 828 __FUNCTION__ , core_cxy , core_lid , hal_time_stamp() ); 815 829 816 830 // each core activates its private PTI IRQ -
trunk/kernel/kern/printk.c
r14 r23 37 37 extern chdev_t txt0_chdev; // allocated in kernel_init.c 38 38 39 ///////////////////////////////////// 40 uint32_t snprintf( char * string, 41 uint32_t length, 42 char * format, ... ) 43 { 44 45 #define TO_STREAM(x) do { string[ps] = (x); ps++; if(ps==length) return -1; } while(0); 46 47 va_list args; // printf arguments 48 uint32_t ps; // write pointer to the string buffer 49 50 ps = 0; 51 va_start( args , format ); 52 53 xprintf_text: 54 55 while ( *format != 0 ) 56 { 57 58 if (*format == '%') // copy argument to string 59 { 60 format++; 61 goto xprintf_arguments; 62 } 63 else // copy one char to string 64 { 65 TO_STREAM( *format ); 66 format++; 67 } 68 } 69 70 va_end( args ); 71 72 // add terminating NUL chracter 73 TO_STREAM( 0 ); 74 return ps; 75 76 xprintf_arguments: 77 78 { 79 char buf[30]; // buffer to display one number 80 char * pbuf; // pointer on first char to display 81 uint32_t len = 0; // number of char to display 82 static const char HexaTab[] = "0123456789ABCDEF"; 83 uint32_t i; 84 85 // Ignore fields width and precision 86 for ( ; (*format >= '0' && *format <= '9') || (*format == '.') ; format++ ); 87 88 switch (*format) 89 { 90 case ('c'): // char conversion 91 { 92 int val = va_arg( args, int ); 93 buf[0] = val; 94 pbuf = buf; 95 len = 1; 96 break; 97 } 98 case ('d'): // decimal signed integer 99 { 100 int val = va_arg( args, int ); 101 if (val < 0) 102 { 103 TO_STREAM( '-' ); 104 val = -val; 105 } 106 for(i = 0; i < 10; i++) 107 { 108 109 buf[9 - i] = HexaTab[val % 10]; 110 if (!(val /= 10)) break; 111 } 112 len = i + 1; 113 pbuf = &buf[9 - i]; 114 break; 115 } 116 case ('u'): // decimal unsigned integer 117 { 118 uint32_t val = va_arg( args, uint32_t ); 119 for(i = 0; i < 10; i++) 120 { 121 buf[9 - i] = HexaTab[val % 10]; 122 if (!(val /= 10)) break; 123 } 124 len = i + 1; 125 pbuf = &buf[9 - i]; 126 break; 127 } 128 case ('x'): // 32 bits hexadecimal 129 case ('l'): // 64 bits hexadecimal 130 { 131 uint32_t imax; 132 uint64_t val; 133 134 if ( *format == 'l' ) // 64 bits 135 { 136 val = va_arg( args, uint64_t); 137 imax = 16; 138 } 139 else // 32 bits 140 { 141 val = va_arg( args, uint32_t); 142 imax = 8; 143 } 144 145 TO_STREAM( '0' ); 146 TO_STREAM( 'x' ); 147 148 for(i = 0; i < imax; i++) 149 { 150 buf[(imax-1) - i] = HexaTab[val % 16]; 151 if (!(val /= 16)) break; 152 } 153 len = i + 1; 154 pbuf = &buf[(imax-1) - i]; 155 break; 156 } 157 case ('s'): /* string */ 158 { 159 char* str = va_arg( args, char* ); 160 while (str[len]) { len++; } 161 pbuf = str; 162 break; 163 } 164 default: // unsupported argument type 165 { 166 return -1; 167 } 168 } // end switch on argument type 169 170 format++; 171 172 // copy argument to string 173 for( i = 0 ; i < len ; i++ ) 174 { 175 TO_STREAM( pbuf[i] ); 176 } 177 178 goto xprintf_text; 179 } 180 } // end xprintf() 181 39 182 /////////////////////////////////////////////////////////////////////////////////// 40 183 // This static function is called by kernel_printf() to display a string on the … … 47 190 /////////////////////////////////////////////////////////////////////////////////// 48 191 // @ channel : TXT channel. 49 // @ busy : TXT device acces mode .192 // @ busy : TXT device acces mode (busy waiting if non zero). 50 193 // @ buf : buffer containing the characters. 51 194 // @ nc : number of characters. … … 66 209 ////////////////////////////////////////////////////////////////////////////////////// 67 210 // @ channel : channel index. 68 // @ busy : TXT device access mode .211 // @ busy : TXT device access mode (busy waiting if non zero). 69 212 // @ format : printf like format. 70 213 // @ args : format arguments. … … 267 410 } 268 411 412 269 413 // Local Variables: 270 414 // tab-width: 4 -
trunk/kernel/kern/printk.h
r16 r23 46 46 47 47 /********************************************************************************** 48 * This function build a formated string. 49 * The supported formats are defined below : 50 * %c : single character 51 * %d : signed decimal 32 bits integer 52 * %u : unsigned decimal 32 bits integer 53 * %x : hexadecimal 32 bits integer 54 * %l : hexadecimal 64 bits integer 55 * %s : NUL terminated character string 56 ********************************************************************************** 57 * @ string : pointer on target buffer (allocated by caller). 58 * @ length : target buffer length (number of bytes). 59 * @ format : format respecting the printf syntax. 60 * @ returns the string length (including NUL) if success / return -1 if error. 61 *********************************************************************************/ 62 uint32_t snprintf( char * string, 63 uint32_t length, 64 char * format, ... ); 65 66 /********************************************************************************** 48 67 * This function displays a formated string on the kernel terminal TXT0, 49 68 * using a busy waiting policy: It calls directly the relevant TXT driver, … … 52 71 * @ format : formated string. 53 72 *********************************************************************************/ 54 externvoid printk( char* format, ... );73 void printk( char* format, ... ); 55 74 56 75 /********************************************************************************** … … 62 81 * @ format : formated string. 63 82 *********************************************************************************/ 64 externvoid user_printk( char* format, ... );83 void user_printk( char* format, ... ); 65 84 66 85 /********************************************************************************** … … 211 230 #else 212 231 #define sched_dmsg(...) 232 #endif 233 234 #if CONFIG_SIGNAL_DEBUG 235 #define signal_dmsg(...) printk(__VA_ARGS__) 236 #else 237 #define signal_dmsg(...) 213 238 #endif 214 239 -
trunk/kernel/kern/process.c
r14 r23 4 4 * Authors Ghassan Almaless (2008,2009,2010,2011,2012) 5 5 * Mohamed Lamine Karaoui (2015) 6 * Alain Greiner (2016 )6 * Alain Greiner (2016,2017) 7 7 * 8 8 * Copyright (c) UPMC Sorbonne Universites … … 47 47 #include <process.h> 48 48 #include <elf.h> 49 #include <syscalls.h> 49 50 50 51 ////////////////////////////////////////////////////////////////////////////////////////// … … 103 104 pid_t ppid ) 104 105 { 105 // reset signal manager TODO [AG] 106 107 // reset the file descriptors array 106 // reset reference process vmm 107 vmm_init( process ); 108 109 // reset reference process file descriptors array 108 110 process_fd_init( process ); 109 111 110 // reset the process files structures and cd_lock112 // reset reference process files structures and cd_lock 111 113 process->vfs_root_xp = XPTR_NULL; 114 process->vfs_bin_xp = XPTR_NULL; 112 115 process->vfs_cwd_xp = XPTR_NULL; 113 process->vfs_bin_xp = XPTR_NULL; 114 115 spinlock_init( &process->cd_lock ); 116 remote_rwlock_init( XPTR( local_cxy , &process->cwd_lock ) ); 116 117 117 118 // reset children list root … … 119 120 process->children_nr = 0; 120 121 121 // reset semaphore list root122 // reset semaphore / mutex / barrier / condvar list roots 122 123 xlist_root_init( XPTR( local_cxy , &process->sem_root ) ); 123 process->sem_nr = 0; 124 xlist_root_init( XPTR( local_cxy , &process->mutex_root ) ); 125 xlist_root_init( XPTR( local_cxy , &process->barrier_root ) ); 126 xlist_root_init( XPTR( local_cxy , &process->condvar_root ) ); 127 remote_spinlock_init( XPTR( local_cxy , &process->sync_lock ) ); 124 128 125 129 // register new process in the parent children list … … 128 132 xlist_add_first( root , entry ); 129 133 130 // reset th_tbl[] array 134 // reset th_tbl[] array as empty 131 135 uint32_t i; 132 136 for( i = 0 ; i < CONFIG_THREAD_MAX_PER_CLUSTER ; i++ ) … … 137 141 spinlock_init( &process->th_lock ); 138 142 139 // reset process VMM140 memset( &process->vmm , 0 , sizeof(vmm_t) );141 142 143 // initialize PID and PPID 143 144 process->pid = pid; 144 145 process->ppid = ppid; 145 146 146 // set ref_xp field and is_ref flag 147 process->is_ref = true; 147 // set ref_xp field 148 148 process->ref_xp = XPTR( local_cxy , process ); 149 149 … … 153 153 // register new process descriptor in owner cluster manager copies_list 154 154 cluster_process_copies_link( process ); 155 156 // initalise signal manager TODO [AG] 155 157 156 158 hal_wbflush(); … … 162 164 xptr_t reference_process_xp ) 163 165 { 164 // replicate the remote process descriptor in new process descriptor 165 xptr_t local_process_xp = XPTR( local_cxy , local_process ); 166 hal_remote_memcpy( local_process_xp , reference_process_xp , sizeof(process_t) ); 167 168 // initalise signal manager TODO [AG] 169 170 // initialise file descriptors array TODO [AG] 171 172 // initialise process files structures TODO [AG] 173 174 // set the ref_xp field and clear the is_ref flag 166 // get reference process cluster and local pointer 167 cxy_t ref_cxy = GET_CXY( reference_process_xp ); 168 process_t * ref_ptr = (process_t *)GET_PTR( reference_process_xp ); 169 170 // reset local process vmm 171 vmm_init( local_process ); 172 173 // reset process file descriptors array 174 process_fd_init( local_process ); 175 176 // reset vfs_root_xp / vfs_bin_xp / vfs_cwd_xp fields 177 local_process->vfs_root_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->vfs_root_xp ) ); 178 local_process->vfs_bin_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->vfs_bin_xp ) ); 179 local_process->vfs_cwd_xp = XPTR_NULL; 180 181 // set the pid, ppid, ref_xp fields 182 local_process->pid = hal_remote_lw( XPTR( ref_cxy , &ref_ptr->pid ) ); 183 local_process->ppid = hal_remote_lw( XPTR( ref_cxy , &ref_ptr->ppid ) ); 175 184 local_process->ref_xp = reference_process_xp; 176 local_process->is_ref = false;177 185 178 186 // reset children list root (not used in a process descriptor copy) … … 185 193 // reset semaphores list root (not used in a process descriptor copy) 186 194 xlist_root_init( XPTR( local_cxy , &local_process->sem_root ) ); 187 local_process->sem_nr = 0; 188 189 // initialize th_tbl[] array as empty 195 xlist_root_init( XPTR( local_cxy , &local_process->mutex_root ) ); 196 xlist_root_init( XPTR( local_cxy , &local_process->barrier_root ) ); 197 xlist_root_init( XPTR( local_cxy , &local_process->condvar_root ) ); 198 199 // reset th_tbl[] array as empty 190 200 uint32_t i; 191 201 for( i = 0 ; i < CONFIG_THREAD_MAX_PER_CLUSTER ; i++ ) … … 196 206 spinlock_init( &local_process->th_lock ); 197 207 198 // initialise process VMM TODO [AG]199 200 208 // register new process descriptor in local cluster manager local_list 201 209 cluster_process_local_link( local_process ); … … 203 211 // register new process descriptor in owner cluster manager copies_list 204 212 cluster_process_copies_link( local_process ); 213 214 // initalise signal manager TODO [AG] 205 215 206 216 hal_wbflush(); … … 223 233 pmgr_t * pmgr = &LOCAL_CLUSTER->pmgr; 224 234 235 // get the lock protecting the list of local process descriptors 236 remote_spinlock_lock( XPTR( local_cxy , &pmgr->local_lock ) ); 237 225 238 // remove the process descriptor from local_list in local cluster manager 226 spinlock_lock( &pmgr->local_lock );227 239 xlist_unlink( XPTR( local_cxy , &process->local_list ) ); 228 spinlock_unlock( &pmgr->local_lock ); 240 241 // release the lock protecting the list of local process descriptors 242 remote_spinlock_unlock( XPTR( local_cxy , &pmgr->local_lock ) ); 229 243 230 244 // get extended pointer on copies_lock in owner cluster manager … … 243 257 // From this point, the process descriptor is unreachable 244 258 259 // close all open files and update dirty TODO [AG] 260 245 261 // release signal manager TODO [AG] 246 262 247 // delete all open file descriptors 248 process_fd_destroy( process ); 249 250 // Close bin file and decrease refcount for root and cwd 251 if( process->vfs_bin_xp != XPTR_NULL ) vfs_close( process->vfs_bin_xp , NULL ); 263 // Decrease refcount for bin file, root file and cwd file 264 vfs_file_count_down( process->vfs_bin_xp ); 252 265 vfs_file_count_down( process->vfs_root_xp ); 253 266 vfs_file_count_down( process->vfs_cwd_xp ); … … 325 338 326 339 327 328 329 330 340 /////////////////////////////////////////////// 331 341 process_t * process_get_local_copy( pid_t pid ) 332 342 { 333 343 error_t error; 334 bool_t found;335 list_entry_t * iter;336 p rocess_t * process; // pointer on local copy344 process_t * process_ptr; // local pointer on process 345 xptr_t process_xp; // extended pointer on process 346 pid_t process_pid; // process identifier 337 347 338 348 cluster_t * cluster = LOCAL_CLUSTER; 339 349 340 350 // get lock protecting local list of processes 341 spinlock_lock( &cluster->pmgr.local_lock);351 remote_spinlock_lock( XPTR( local_cxy , &cluster->pmgr.local_lock ) ); 342 352 343 353 // scan the local list of process descriptors to find the process 344 found = false; 345 LIST_FOREACH( &cluster->pmgr.local_root , iter ) 346 { 347 process = LIST_ELEMENT( iter , process_t , local_list ); 348 if( process->pid == pid ) 354 xptr_t iter; 355 bool_t found = false; 356 XLIST_FOREACH( XPTR( local_cxy , &cluster->pmgr.local_root ) , iter ) 357 { 358 process_xp = XLIST_ELEMENT( iter , process_t , local_list ); 359 process_ptr = (process_t *)GET_PTR( process_xp ); 360 process_pid = hal_remote_lw( XPTR( local_cxy , &process_ptr->pid ) ); 361 if( process_ptr->pid == pid ) 349 362 { 350 363 found = true; … … 354 367 355 368 // release lock protecting local list of processes 356 spinlock_unlock( &cluster->pmgr.local_lock);357 358 // allocate memory for a local process descriptor359 // and initialise it from reference if required369 remote_spinlock_unlock( XPTR( local_cxy , &cluster->pmgr.local_lock ) ); 370 371 // allocate memory for a new local process descriptor 372 // and initialise it from reference cluster if required 360 373 if( !found ) 361 374 { 362 375 // get extended pointer on reference process descriptor 363 xptr_t reference = cluster_get_reference_process_from_pid( pid ); 376 xptr_t ref_xp = cluster_get_reference_process_from_pid( pid ); 377 378 assert( (ref_xp != XPTR_NULL) , __FUNCTION__ , "illegal pid\n" ); 364 379 365 380 // allocate memory for local process descriptor 366 process = process_alloc();367 if( process == NULL ) return NULL;381 process_ptr = process_alloc(); 382 if( process_ptr == NULL ) return NULL; 368 383 369 384 // initialize local process descriptor copy 370 error = process_copy_init( process , reference);385 error = process_copy_init( process_ptr , ref_xp ); 371 386 if( error ) return NULL; 372 373 374 // register process in global copies_list 375 } 376 377 return process; 387 } 388 389 return process_ptr; 378 390 } // end process_get_local_copy() 379 391 … … 389 401 390 402 remote_spinlock_init( XPTR( local_cxy , &process->fd_array.lock ) ); 391 process->fd_array.max = CONFIG_PROCESS_FILE_MAX_NR; 392 process->fd_array.current 403 404 process->fd_array.current = 0; 393 405 394 406 // initialize array 395 for ( fd = 0 ; fd < process->fd_array.max; fd++ )407 for ( fd = 0 ; fd < CONFIG_PROCESS_FILE_MAX_NR ; fd++ ) 396 408 { 397 409 process->fd_array.array[fd] = XPTR_NULL; … … 399 411 } 400 412 401 ////////////////////////////////////////////// 402 void process_fd_destroy( process_t * process ) 403 { 404 uint32_t fd; 405 406 // loop on all open file descriptors to close all open files 407 for( fd = 0 ; fd < process->fd_array.max ; fd++ ) 408 { 409 xptr_t file_xp = process->fd_array.array[fd]; 410 if ( file_xp != XPTR_NULL ) vfs_close( file_xp , NULL ); 411 } 413 414 ////////////////////////////// 415 bool_t process_fd_array_full() 416 { 417 // get extended pointer on reference process 418 xptr_t ref_xp = CURRENT_THREAD->process->ref_xp; 419 420 // get reference process cluster and local pointer 421 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 422 cxy_t ref_cxy = GET_CXY( ref_xp ); 423 424 // get number of open file descriptors from reference fd_array 425 uint32_t current = hal_remote_lw( XPTR( ref_cxy , &ref_ptr->fd_array.current ) ); 426 427 return ( current >= CONFIG_PROCESS_FILE_MAX_NR ); 412 428 } 413 429 414 ///////////////////////////////////////////////////415 bool_t process_fd_array_full( process_t * process )416 {417 return ( process->fd_array.current >= process->fd_array.max);418 }419 420 430 ///////////////////////////////////////////////// 421 error_t process_fd_allocate( process_t * process, 422 xptr_t file_xp, 423 uint32_t * ret_fd ) 431 error_t process_fd_register( xptr_t file_xp, 432 uint32_t * file_id ) 424 433 { 425 434 bool_t found; 426 uint32_t fd; 427 428 remote_spinlock_lock( XPTR( local_cxy , &process->fd_array.lock ) ); 435 uint32_t id; 436 xptr_t xp; 437 438 // get extended pointer on reference process 439 xptr_t ref_xp = CURRENT_THREAD->process->ref_xp; 440 441 // get reference process cluster and local pointer 442 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 443 cxy_t ref_cxy = GET_CXY( ref_xp ); 444 445 // take lock protecting reference fd_array 446 remote_spinlock_lock( XPTR( ref_cxy , &ref_ptr->fd_array.lock ) ); 429 447 430 448 found = false; 431 449 432 for ( fd = 0; fd < process->fd_array.max; fd++ ) 433 { 434 if ( process->fd_array.array[fd] == XPTR_NULL ) 450 for ( id = 0; id < CONFIG_PROCESS_FILE_MAX_NR ; id++ ) 451 { 452 xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->fd_array.array[id] ) ); 453 if ( xp == XPTR_NULL ) 435 454 { 436 455 found = true; 437 process->fd_array.array[fd] = file_xp;438 process->fd_array.current++;439 * ret_fd = fd;456 hal_remote_swd( XPTR( ref_cxy , &ref_ptr->fd_array.array[id] ) , file_xp ); 457 hal_remote_atomic_add( XPTR( ref_cxy , &ref_ptr->fd_array.current ) , 1 ); 458 *file_id = id; 440 459 break; 441 460 } 442 461 } 443 462 444 remote_spinlock_unlock( XPTR( local_cxy , &process->fd_array.lock ) ); 463 // release lock protecting reference fd_array 464 remote_spinlock_unlock( XPTR( ref_cxy , &ref_ptr->fd_array.lock ) ); 445 465 446 466 if ( !found ) return EMFILE; 447 467 else return 0; 448 } 449 450 //////////////////////////////////////////////// 451 error_t process_fd_release( process_t * process, 452 uint32_t fd ) 453 { 454 if ( (fd < 0) || (fd > process->fd_array.max) ) return EBADF; 455 456 remote_spinlock_lock( XPTR( local_cxy , &process->fd_array.lock ) ); 457 458 process->fd_array.array[fd] = XPTR_NULL; 459 process->fd_array.current--; 460 461 remote_spinlock_unlock( XPTR( local_cxy , &process->fd_array.lock ) ); 462 463 return 0; 464 } 465 466 /////////////////////////////////////// 467 void process_fd_copy( fd_array_t * dst, 468 fd_array_t * src ) 469 { 470 uint32_t fd; 471 xptr_t entry; 472 473 remote_spinlock_lock( XPTR( local_cxy , &src->lock ) ); 474 475 // loop on all entries in source process fd_array 476 for( fd = 0 ; fd < src->max ; fd++ ) 477 { 478 entry = src->array[fd]; 479 480 if( entry != XPTR_NULL ) 481 { 482 // increment file descriptor ref count 483 vfs_file_count_up( entry ); 484 485 // copy entry in destination process fd_array 486 dst->array[fd] = entry; 487 } 488 } 489 490 // release lock on source process fd_array 491 remote_spinlock_unlock( XPTR( local_cxy , &src->lock ) ); 492 } 468 469 } // end process_fd_register() 470 471 //////////////////////////////////////////////// 472 xptr_t process_fd_get_xptr( process_t * process, 473 uint32_t file_id ) 474 { 475 xptr_t file_xp; 476 477 // access local copy of process descriptor 478 file_xp = process->fd_array.array[file_id]; 479 480 if( file_xp == XPTR_NULL ) 481 { 482 // get reference process cluster and local pointer 483 xptr_t ref_xp = process->ref_xp; 484 cxy_t ref_cxy = GET_CXY( ref_xp ); 485 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 486 487 // access reference process descriptor 488 file_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->fd_array.array[file_id] ) ); 489 490 // update local fd_array if found 491 if( file_xp != XPTR_NULL ) 492 { 493 process->fd_array.array[file_id] = file_xp; 494 } 495 } 496 497 return file_xp; 498 499 } // end process_fd_get_xptr() 493 500 494 501 /////////////////////////////////////////// … … 510 517 remote_spinlock_lock( XPTR( src_cxy , &src_ptr->lock ) ); 511 518 512 // get number of entries in fd_array513 uint32_t max = hal_remote_lw( XPTR( src_cxy , &src_ptr->max ) );514 515 519 // loop on all entries in source process fd_array 516 for( fd = 0 ; fd < max; fd++ )520 for( fd = 0 ; fd < CONFIG_PROCESS_FILE_MAX_NR ; fd++ ) 517 521 { 518 522 entry = (xptr_t)hal_remote_lwd( XPTR( src_cxy , &src_ptr->array[fd] ) ); … … 609 613 pid = exec_info->pid; 610 614 611 if( CXY_FROM_PID( pid ) != local_cxy ) 612 { 613 printk("\n[PANIC] in %s : illegal process PID %x in cluster %x\n", 614 __FUNCTION__ , pid , local_cxy ); 615 hal_core_sleep(); 616 } 615 assert( (CXY_FROM_PID( pid ) == local_cxy) , __FUNCTION__ , "illegal PID\n" ); 617 616 618 617 exec_dmsg("\n[INFO] %s enters in cluster %x for process %x / path = %s\n", … … 677 676 } 678 677 679 // create "stack" vseg descriptor for associated main thread680 vseg_t * stack_vseg = vmm_create_vseg( process,681 0, // base defined by VMM682 0, // size defined by VMM683 VSEG_TYPE_STACK );684 if( stack_vseg == NULL )685 {686 printk("\n[ERROR] in %s : cannot create stack vseg for process %x / path = %s\n",687 __FUNCTION__, pid , path );688 process_destroy( process );689 return error;690 }691 692 678 // select a core in cluster 693 679 lid = cluster_select_local_core(); … … 695 681 696 682 // initialize pthread attributes for main thread 697 attr.pid = pid; 698 attr.entry_func = (void*)process->vmm.entry_point; 699 attr.entry_args = exec_info->args_pointers; 700 attr.flags = PT_FLAG_DETACH; // main thread always detached 701 attr.cxy = local_cxy; 702 attr.lid = lid; 703 704 // create and initialise thread descriptor, link thread & process 705 error = thread_user_create( &thread, 683 attr.attributes = PT_ATTR_DETACH | PT_ATTR_CLUSTER_DEFINED | PT_ATTR_CORE_DEFINED; 684 attr.cxy = local_cxy; 685 attr.lid = lid; 686 687 // create and initialise thread descriptor 688 error = thread_user_create( pid, 689 (void *)process->vmm.entry_point, 690 exec_info->args_pointers, 706 691 &attr, 707 stack_vseg->min, 708 stack_vseg->max - stack_vseg->min ); 692 &thread ); 709 693 if( error ) 710 694 { … … 732 716 { 733 717 process_t * process_init; // process_init descriptor 734 thread_t * thread_init; // process_init main thread descriptor735 718 pid_t init_pid; // process_init pid 736 719 exec_info_t exec_info; // structure to be passed to process_make_exec() … … 779 762 process_zero.children_nr = 1; 780 763 781 // TODO open stdin / stdout / stderr pseudo-files 782 xptr_t stdin_xp; 783 xptr_t stdout_xp; 784 xptr_t stderr_xp; 785 786 // error1 = vfs_open( process_init->vfs_cwd_xp, NULL, VFS_O_RDONLY, &stdin_xp ); 787 // error2 = vfs_open( process_init->vfs_cwd_xp, NULL, VFS_O_WRONLY, &stdout_xp ); 788 // error3 = vfs_open( process_init->vfs_cwd_xp, NULL, VFS_O_WRONLY, &stderr_xp ); 764 // TODO create inodes for stdin / stdout / stderr pseudo-files 765 // these inodes should be created in the cluster containing the relevant TXT chdev 766 767 // open stdin / stdout / stderr pseudo-files 768 xptr_t stdin_xp; 769 xptr_t stdout_xp; 770 xptr_t stderr_xp; 771 uint32_t stdin_id; 772 uint32_t stdout_id; 773 uint32_t stderr_id; 774 775 error1 = vfs_open( XPTR_NULL, CONFIG_DEV_STDIN , O_RDONLY, 0, &stdin_xp , &stdin_id ); 776 error2 = vfs_open( XPTR_NULL, CONFIG_DEV_STDOUT, O_WRONLY, 0, &stdout_xp, &stdout_id ); 777 error3 = vfs_open( XPTR_NULL, CONFIG_DEV_STDERR, O_WRONLY, 0, &stderr_xp, &stderr_id ); 789 778 790 779 if( error1 || error2 || error3 ) 791 780 { 792 if( !error1 ) vfs_close( stdin_xp , NULL);793 if( !error2 ) vfs_close( stdout_xp , NULL);794 if( !error3 ) vfs_close( stderr_xp , NULL);781 if( !error1 ) vfs_close( stdin_xp , stdin_id ); 782 if( !error2 ) vfs_close( stdout_xp , stdout_id ); 783 if( !error3 ) vfs_close( stderr_xp , stderr_id ); 795 784 796 785 printk("\n[PANIC] in %s : cannot open stdin/stdout/stderr in cluster %x\n", … … 799 788 } 800 789 801 // register stdin / stdout / stderr in the fd_array 3 first slots 802 process_init->fd_array.array[0] = stdin_xp; 803 process_init->fd_array.array[1] = stdout_xp; 804 process_init->fd_array.array[2] = stderr_xp; 805 process_init->fd_array.current = 3; 790 // check stdin / stdout / stderr indexes 791 if( (stdin_id != 0) || (stdout_id != 1) || (stderr_id != 2) ) 792 { 793 printk("\n[PANIC] in %s : bad indexes for stdin/stdout/stderr in cluster %x\n", 794 __FUNCTION__ , local_cxy ); 795 hal_core_sleep(); 796 } 806 797 807 798 // initialize the exec_info structure -
trunk/kernel/kern/process.h
r14 r23 4 4 * Authors Ghassan Almaless (2008,2009,2010,2011,2012) 5 5 * Mohamed Lamine Karaoui (2015) 6 * Alain Greiner (2016 )6 * Alain Greiner (2016,2017) 7 7 * 8 8 * Copyright (c) UPMC Sorbonne Universites … … 54 54 55 55 /********************************************************************************************* 56 * These macros are used to compose or decompose global thread identifier (TRDID)57 * to or from cluster identifier / local thread index (CXY , LTID)58 ********************************************************************************************/59 60 #define LTID_FROM_TRDID( trdid ) (ltid_t)(trdid & 0x0000FFFF)61 #define CXY_FROM_TRDID( trdid ) (cxy_t)(trdid >> 16)62 #define TRDID( cxy , ltid ) (trdid_t)((cxy << 16) | ltid )63 64 /*********************************************************************************************65 56 * This structure defines an array of extended pointers on the open file descriptors 66 57 * for a given process. We use an extended pointer because the open file descriptor … … 68 59 * A free entry in this array contains the XPTR_NULL value. 69 60 * The array size is defined by a the CONFIG_PROCESS_FILE_MAX_NR parameter. 70 * All modifications (open/close) must be done by the reference cluster, and reported 61 * All modifications (open/close) in this structure must be done by the reference cluster, 62 * and reported in process copies. 71 63 ********************************************************************************************/ 72 64 … … 75 67 remote_spinlock_t lock; /*! lock protecting fd_array[] change. */ 76 68 uint32_t current; /*! current number of open files */ 77 uint32_t max; /*! max number of open files (can be increased) */78 69 xptr_t array[CONFIG_PROCESS_FILE_MAX_NR]; 79 70 } … … 88 79 * allocated to this cluster. 89 80 * The process descriptor for a PID process is replicated in all clusters containing 90 * at least one thread of the PID process, with some restrictions: 91 * - The list of registered vsegs, the page table (contained in vmm), and the fd_array[] 92 * are only complete in the reference process descriptor, other copies are read-only caches. 93 * - The following fields are NOT defined in copies other than the reference: 94 * children_root , children_list , children_nr , sig_mgr 81 * at least one thread of the PID process, with the following rules : 82 * 83 * 1) The <pid>, <ppid>, <ref_xp>, <vfs_root_xp>, <vfs_bin_xp> fields are defined 84 * in all process descriptor copies. 85 * 2) The <vfs_cwd_xp> and associated <cwd_lock>, that can be dynamically modified, 86 * are only defined in the reference process descriptor. 87 * 2) The <vmm>, containing the list of registered vsegs, and the page table, are only 88 * complete in the reference process cluster, other copies are read-only caches. 89 * 3) the <fd_array>, containing extended pointers on the open file descriptors, is only 90 * complete in the reference process cluster, other copies are read-only caches. 91 * 4) The <sem_root>, <mutex_root>, <barrier_root>, <condvar_root>, and the associated 92 * <sync_lock>, that are dynamically allocated, are only defined in the reference cluster. 93 * 5) The <children_root>, and <children_nr> fields are only defined in the reference 94 * cluster, and are undefined in other clusters. 95 * 6) The <brothers_list>, <local_list>, <copies_list>, <th_tbl>, <th_nr>, <th_lock> fields 96 * are defined in all process descriptors copies. 97 * 7) The <sig_mgr> field is only defined in the reference cluster. TODO 95 98 ********************************************************************************************/ 96 99 97 100 typedef struct process_s 98 101 { 99 vmm_t vmm; /*! embedded virtual memory manager */ 100 101 fd_array_t fd_array; /*! embedded file descriptors array */ 102 103 xptr_t vfs_root_xp; /*! extende pointer on current file system root */ 104 xptr_t vfs_cwd_xp; /*! extended pointer on current working directory */ 105 xptr_t vfs_bin_xp; /*! extended pointer on associate .elf file */ 106 107 spinlock_t cd_lock; /*! lock protecting working directory changes */ 102 vmm_t vmm; /*! embedded virtual memory manager */ 103 104 fd_array_t fd_array; /*! embedded open file descriptors array */ 105 106 xptr_t vfs_root_xp; /*! extende pointer on current VFS root inode */ 107 xptr_t vfs_bin_xp; /*! extended pointer on .elf file inode */ 108 pid_t pid; /*! process identifier */ 109 pid_t ppid; /*! parent process identifier */ 110 xptr_t ref_xp; /*! extended pointer on reference process */ 111 112 xptr_t vfs_cwd_xp; /*! extended pointer on current working dir inode */ 113 remote_rwlock_t cwd_lock; /*! lock protecting working directory changes */ 108 114 109 pid_t pid; /*! process identifier */ 110 pid_t ppid; /*! parent process identifier */ 111 bool_t is_ref; /*! this is the reference process if true */ 112 xptr_t ref_xp; /*! extended pointer on reference process */ 113 114 xlist_entry_t children_root; /*! root of the children process xlist */ 115 uint32_t children_nr; /*! number of children processes */ 116 117 xlist_entry_t brothers_list; /*! member of list of children of same parent */ 118 119 list_entry_t local_list; /*! member of list of process in same cluster */ 120 121 xlist_entry_t copies_list; /*! member of list of copies of same process */ 122 123 spinlock_t th_lock; /*! lock protecting th_tbl[] concurrent access */ 124 uint32_t th_nr; /*! number of threads in this cluster */ 125 115 xlist_entry_t children_root; /*! root of the children process xlist */ 116 uint32_t children_nr; /*! number of children processes */ 117 118 xlist_entry_t brothers_list; /*! member of list of children of same parent */ 119 xlist_entry_t local_list; /*! member of list of process in same cluster */ 120 xlist_entry_t copies_list; /*! member of list of copies of same process */ 121 122 spinlock_t th_lock; /*! lock protecting th_tbl[] concurrent access */ 123 uint32_t th_nr; /*! number of threads in this cluster */ 126 124 struct thread_s * th_tbl[CONFIG_THREAD_MAX_PER_CLUSTER]; /*! pointers on local threads */ 127 125 128 xlist_entry_t sem_root; /*! root of the process semaphores list */ 129 uint32_t sem_nr; /*! number of semaphores */ 130 131 sig_mgr_t sig_mgr; /*! embedded signal manager TODO [AG] */ 126 xlist_entry_t sem_root; /*! root of the process semaphore list */ 127 xlist_entry_t mutex_root; /*! root of the process mutex list */ 128 xlist_entry_t barrier_root; /*! root of the process barrier list */ 129 xlist_entry_t condvar_root; /*! root of the process condvar list */ 130 131 remote_spinlock_t sync_lock; /*! lock protecting sem,mutex,barrier,condvar lists */ 132 133 sig_mgr_t sig_mgr; /*! embedded signal manager TODO [AG] */ 132 134 } 133 135 process_t; … … 149 151 xptr_t vfs_bin_xp; /*! extended pointer on process .elf file */ 150 152 151 char path[ 256]; /*! pathname for .elf file*/153 char path[CONFIG_VFS_MAX_PATH_LENGTH]; /*! .elf file path */ 152 154 153 155 char ** args_pointers; /*! physical base address of array of pointers */ … … 162 164 exec_info_t; 163 165 164 /*********************************************************************************************165 * This macro returns a pointer on the process descriptor for the calling thread.166 ********************************************************************************************/167 168 #define CURRENT_PROCESS (hal_get_current_thread()->process)169 170 166 /*************** Process Descriptor Operations *****************************************/ 171 167 … … 204 200 * The PID value must have been defined previously by the owner cluster manager. 205 201 * The reference cluster can be different from the owner cluster. 206 * It set the pid / ppid / is_ref / pref /fields.202 * It set the pid / ppid / ref_xp fields. 207 203 * It registers this process descriptor in three lists: 208 204 * - the children_list in the parent process descriptor. … … 232 228 /********************************************************************************************* 233 229 * This function releases all memory allocated for a process descriptor in the local cluster, 234 * after releasing memory allocated for embedded substructures (fd_array, vmm, etc).230 * including memory allocated for embedded substructures (fd_array, vmm, etc). 235 231 * The local th_tbl[] array must be empty. 236 232 ********************************************************************************************* … … 255 251 * If this local copy does not exist yet, it is dynamically created, from the reference 256 252 * process descriptor, registered in the global copies_list, and registered in the local_list. 257 * This function is used by both thread_user_create() and thread_user_copy() functions.253 * This function is used by the thread_user_create() function. 258 254 ********************************************************************************************* 259 255 * @ pid : searched process identifier. … … 288 284 289 285 /********************************************************************************************* 290 * This function reset the file descriptor array for a given process: no open file.286 * This function initialises all entries of the local fd_array as empty. 291 287 ********************************************************************************************* 292 288 * @ process : pointer on the local process descriptor. … … 295 291 296 292 /********************************************************************************************* 297 * This function closes all open files and releases all file descriptors. 293 * This function uses as many remote accesses as required, to reset an entry in fd_array[], 294 * in all clusters containing a copy. The entry is identified by the <file_id> argument. 295 * This function must be executed by a thread running reference cluster, that contain 296 * the complete list of process descriptors copies. 298 297 ********************************************************************************************* 299 298 * @ process : pointer on the local process descriptor. 300 ********************************************************************************************/ 301 void process_fd_destroy( process_t * process ); 299 * @ file_id : file descriptor index in the fd_array. 300 ********************************************************************************************/ 301 void process_fd_remove( process_t * process, 302 uint32_t file_id ); 303 304 /********************************************************************************************* 305 * This function returns an extended pointer on a file descriptor identified by its index 306 * in fd_array. It can be called by any thread running in any cluster. 307 * It access first the local process descriptor. In case of local miss, it uses remote access 308 * to access the reference process descriptor. 309 * It updates the local fd_array when the file descriptor exist in reference cluster. 310 * The file descriptor refcount is not incremented. 311 ********************************************************************************************* 312 * @ process : pointer on the local process descriptor. 313 * @ file_id : file descriptor index in the fd_array. 314 * @ return extended pointer on file descriptor if success / return XPTR_NULL if not found. 315 ********************************************************************************************/ 316 xptr_t process_fd_get_xptr( process_t * process, 317 uint32_t file_id ); 302 318 303 319 /********************************************************************************************* 304 320 * This function checks the number of open files for a given process. 305 ********************************************************************************************* 306 * @ process : pointer on the local process descriptor. 321 * It can be called by any thread in any cluster, because it uses portable remote access 322 * primitives to access the reference process descriptor. 323 ********************************************************************************************* 307 324 * @ returns true if file descriptor array full. 308 325 ********************************************************************************************/ 309 bool_t process_fd_array_full( process_t * process ); 310 311 /********************************************************************************************* 312 * These functions allocates a slot in the fd_array for a given process, 313 * and returns the file descriptor index. 314 ********************************************************************************************* 315 * @ process : pointer on the local process descriptor. 316 * @ file : extended pointer on the file descriptor. 317 * @ fd : [out] file descriptor index 326 bool_t process_fd_array_full(); 327 328 /********************************************************************************************* 329 * This function allocates a free slot in the fd_array of the reference process, 330 * register the <file_xp> argument in the allocated slot, and return the slot index. 331 * It can be called by any thread in any cluster, because it uses portable remote access 332 * primitives to access the reference process descriptor. 333 ********************************************************************************************* 334 * @ file_xp : extended pointer on the file descriptor to be registered. 335 * @ file_id : [out] buffer for fd_array slot index. 318 336 * @ return 0 if success / return EMFILE if array full. 319 337 ********************************************************************************************/ 320 error_t process_fd_allocate( process_t * process, 321 xptr_t file_xp, 322 uint32_t * fd ); 323 324 /********************************************************************************************* 325 * This function releases an existing file descriptor from the process fd_array. 326 ********************************************************************************************* 327 * @ process : pointer on the local process descriptor. 328 * @ return 0 if success / return EBADF if illegal file descriptor. 329 ********************************************************************************************/ 330 error_t process_fd_release( process_t * process, 331 uint32_t fd ); 332 333 /********************************************************************************************* 334 * This function copies all non-zero entries from a local <src> fd_array, 335 * embedded in a process descriptor, to another local <dst_xp> fd_array, embedded 336 * in another process descriptor. 337 * It takes the remote lock protecting the <src> fd_array during the copy. 338 * For each involved file descriptor, the refcount is incremented. 339 ********************************************************************************************* 340 * @ dst : pointer on the destination fd_array_t. 341 * @ src : pointer on the source fd_array_t. 342 ********************************************************************************************/ 343 void process_fd_local_copy( fd_array_t * dst, 344 fd_array_t * src ); 338 error_t process_fd_register( xptr_t file_xp, 339 uint32_t * file_id ); 345 340 346 341 /********************************************************************************************* … … 358 353 359 354 355 360 356 /******************** Thread Related Operations *****************************************/ 361 357 -
trunk/kernel/kern/rpc.c
r16 r23 2 2 * rpc.c - RPC related operations implementation. 3 3 * 4 * Authors Mohamed Lamine Karaoui (2015) 5 * Alain Greiner (2016) 4 * Author Alain Greiner (2016,2017) 6 5 * 7 6 * Copyright (c) UPMC Sorbonne Universites … … 40 39 #include <vfs.h> 41 40 #include <fatfs.h> 41 #include <signal.h> 42 42 #include <dev_icu.h> 43 43 #include <rpc.h> … … 55 55 &rpc_thread_user_create_server, // 4 56 56 &rpc_thread_kernel_create_server, // 5 57 &rpc_ undefined,// 657 &rpc_signal_rise_server, // 6 58 58 &rpc_undefined, // 7 59 59 &rpc_undefined, // 8 … … 64 64 &rpc_vfs_dentry_create_server, // 12 65 65 &rpc_vfs_dentry_destroy_server, // 13 66 &rpc_ undefined,// 1467 &rpc_ undefined,// 1568 &rpc_ undefined,// 1666 &rpc_vfs_file_create_server, // 14 67 &rpc_vfs_file_destroy_server, // 15 68 &rpc_fatfs_get_cluster_server, // 16 69 69 &rpc_undefined, // 17 70 70 &rpc_undefined, // 18 … … 73 73 &rpc_vmm_get_ref_vseg_server, // 20 74 74 &rpc_vmm_get_pte_server, // 21 75 &rpc_ semaphore_alloc_server,// 2276 &rpc_ semaphore_free_server,// 2375 &rpc_kcm_alloc_server, // 22 76 &rpc_kcm_free_server, // 23 77 77 &rpc_mapper_move_server, // 24 78 78 &rpc_undefined, // 25 … … 81 81 &rpc_undefined, // 28 82 82 &rpc_undefined, // 29 83 84 &rpc_fatfs_get_cluster_server // 3085 83 }; 86 84 … … 93 91 94 92 ///////////////////////////////////////////////////////////////////////////////////////// 95 // 93 // [0] Marshaling functions attached to RPC_PMEM_GET_PAGES 96 94 ///////////////////////////////////////////////////////////////////////////////////////// 97 95 … … 150 148 151 149 ///////////////////////////////////////////////////////////////////////////////////////// 152 // 150 // [1] Marshaling functions attached to RPC_PROCESS_PID_ALLOC 153 151 ///////////////////////////////////////////////////////////////////////////////////////// 154 152 … … 207 205 208 206 ///////////////////////////////////////////////////////////////////////////////////////// 209 // 207 // [2] Marshaling functions attached to RPC_PROCESS_EXEC 210 208 ///////////////////////////////////////////////////////////////////////////////////////// 211 209 … … 265 263 266 264 ///////////////////////////////////////////////////////////////////////////////////////// 267 // 265 // [3] Marshaling functions attached to RPC_PROCESS_KILL 268 266 ///////////////////////////////////////////////////////////////////////////////////////// 269 267 … … 272 270 { 273 271 // only reference cluster can send this RPC 274 if( !process->is_ref)272 if( GET_CXY( process->ref_xp ) != local_cxy ) 275 273 { 276 274 printk("PANIC in %s : caller is not the reference process\n", __FUNCTION__ ); … … 334 332 335 333 ///////////////////////////////////////////////////////////////////////////////////////// 336 // 334 // [4] Marshaling functions attached to RPC_THREAD_USER_CREATE 337 335 ///////////////////////////////////////////////////////////////////////////////////////// 338 336 339 337 ///////////////////////////////////////////////////////// 340 338 void rpc_thread_user_create_client( cxy_t cxy, 339 pid_t pid, // in 340 void * start_func, // in 341 void * start_arg, // in 341 342 pthread_attr_t * attr, // in 342 343 xptr_t * thread_xp, // out … … 356 357 357 358 // set input arguments in RPC descriptor 358 rpc.args[0] = (uint64_t)(intptr_t)attr; 359 rpc.args[0] = (uint64_t)pid; 360 rpc.args[1] = (uint64_t)(intptr_t)start_func; 361 rpc.args[2] = (uint64_t)(intptr_t)start_arg; 362 rpc.args[3] = (uint64_t)(intptr_t)attr; 359 363 360 364 // register RPC request in remote RPC fifo … … 362 366 363 367 // get output arguments from RPC descriptor 364 *thread_xp = (xptr_t)rpc.args[ 1];365 *error = (error_t)rpc.args[ 2];368 *thread_xp = (xptr_t)rpc.args[4]; 369 *error = (error_t)rpc.args[5]; 366 370 } 367 371 … … 373 377 thread_t * thread_ptr; // local pointer on thread descriptor 374 378 xptr_t thread_xp; // extended pointer on thread descriptor 379 375 380 pid_t pid; // process identifier 376 process_t * process; // local pointer on process descriptor 377 vseg_t * vseg; // local pointer on stack vseg 378 379 error_t error = 0; 381 void * start_func; 382 void * start_arg; 383 error_t error; 380 384 381 385 // get client cluster identifier and pointer on RPC descriptor … … 384 388 385 389 // get pointer on attributes structure in client cluster from RPC descriptor 386 attr_ptr = (pthread_attr_t *)(intptr_t)hal_remote_lwd( XPTR(client_cxy , &desc->args[0]) ); 390 391 // get input arguments from RPC descriptor 392 pid = (pid_t) hal_remote_lwd(XPTR(client_cxy , &desc->args[0])); 393 start_func = (void *)(intptr_t) hal_remote_lwd(XPTR(client_cxy , &desc->args[1])); 394 start_arg = (void *)(intptr_t) hal_remote_lwd(XPTR(client_cxy , &desc->args[2])); 395 attr_ptr = (pthread_attr_t *)(intptr_t)hal_remote_lwd(XPTR(client_cxy , &desc->args[3])); 387 396 388 397 // makes a local copy of attributes structure … … 391 400 sizeof(pthread_attr_t) ); 392 401 393 if( attr_copy.cxy != local_cxy ) 394 { 395 printk("\n[PANIC] in %s : target cluster = %X / local_cluster = %x\n", 396 __FUNCTION__ , attr_copy.cxy , local_cxy ); 397 hal_core_sleep(); 398 } 399 400 // get local process descriptor 401 pid = attr_copy.pid; 402 process = cluster_get_local_process_from_pid( pid ); 403 404 if( process == NULL ) 405 { 406 printk("\n[ERROR] in %s : no process descriptor in cluster %x for pid = %x\n", 407 __FUNCTION__ , local_cxy , pid ); 408 error = ENOMEM; 409 410 } 411 412 // allocate a stack from local VMM 413 vseg = vmm_create_vseg( process, 414 0, 415 0, 416 VSEG_TYPE_STACK ); 417 if( vseg == NULL ) 418 { 419 printk("\n[ERROR] in %s : cannot create stack vseg in cluster %x for pid %x\n", 420 __FUNCTION__ , local_cxy , pid ); 421 error = ENOMEM; 422 } 423 424 // create thread in local cluster 425 if( thread_user_create( &thread_ptr, 426 &attr_copy, 427 vseg->min, 428 vseg->max - vseg->min ) ) error = ENOMEM; 429 402 assert( (attr_copy.cxy == local_cxy) , __FUNCTION__ , "bad target cluster\n" ); 403 404 // call kernel function 405 error = thread_user_create( pid, 406 start_func, 407 start_arg, 408 &attr_copy, 409 &thread_ptr ); 430 410 431 411 // set output arguments … … 436 416 437 417 ///////////////////////////////////////////////////////////////////////////////////////// 438 // 418 // [5] Marshaling functions attached to RPC_THREAD_KERNEL_CREATE 439 419 ///////////////////////////////////////////////////////////////////////////////////////// 440 420 … … 502 482 503 483 ///////////////////////////////////////////////////////////////////////////////////////// 504 // Marshaling functions attached to RPC_VFS_INODE_CREATE 484 // [6] Marshaling functions attached to RPC_SIGNAL_RISE 485 ///////////////////////////////////////////////////////////////////////////////////////// 486 487 ///////////////////////////////////////////// 488 void rpc_signal_rise_client( cxy_t cxy, 489 process_t * process, // in 490 uint32_t sig_id ) // in 491 { 492 // RPC must be remote 493 if( cxy == local_cxy ) 494 { 495 printk("PANIC in %s : target is not remote\n", __FUNCTION__ ); 496 hal_core_sleep(); 497 } 498 499 // initialise RPC descriptor header 500 rpc_desc_t rpc; 501 rpc.index = RPC_SIGNAL_RISE; 502 rpc.response = 1; 503 504 // set input arguments in RPC descriptor 505 rpc.args[0] = (uint64_t)(intptr_t)process; 506 rpc.args[1] = (uint64_t)sig_id; 507 508 // register RPC request in remote RPC fifo 509 rpc_send_sync( cxy , &rpc ); 510 } 511 512 //////////////////////////////////////// 513 void rpc_signal_rise_server( xptr_t xp ) 514 { 515 process_t * process; // local pointer on process descriptor 516 uint32_t sig_id; // signal index 517 518 // get client cluster identifier and pointer on RPC descriptor 519 cxy_t client_cxy = (cxy_t)GET_CXY( xp ); 520 rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); 521 522 // get attributes from RPC descriptor 523 process = (process_t *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); 524 sig_id = (uint32_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[1] ) ); 525 526 // call local kernel function 527 signal_rise( process , sig_id ); 528 } 529 530 ///////////////////////////////////////////////////////////////////////////////////////// 531 // [10] Marshaling functions attached to RPC_VFS_INODE_CREATE 505 532 ///////////////////////////////////////////////////////////////////////////////////////// 506 533 … … 508 535 void rpc_vfs_inode_create_client( cxy_t cxy, 509 536 xptr_t dentry_xp, // in 510 uint32_t type, // in 537 uint32_t fs_type, // in 538 uint32_t inode_type, // in 511 539 uint32_t attr, // in 512 uint32_t mode,// in540 uint32_t rights, // in 513 541 uint32_t uid, // in 514 542 uint32_t gid, // in … … 530 558 // set input arguments in RPC descriptor 531 559 rpc.args[0] = (uint64_t)dentry_xp; 532 rpc.args[1] = (uint64_t)type; 533 rpc.args[2] = (uint64_t)attr; 534 rpc.args[3] = (uint64_t)mode; 535 rpc.args[4] = (uint64_t)uid; 536 rpc.args[5] = (uint64_t)gid; 560 rpc.args[1] = (uint64_t)fs_type; 561 rpc.args[2] = (uint64_t)inode_type; 562 rpc.args[3] = (uint64_t)attr; 563 rpc.args[4] = (uint64_t)rights; 564 rpc.args[5] = (uint64_t)uid; 565 rpc.args[6] = (uint64_t)gid; 537 566 538 567 // register RPC request in remote RPC fifo (blocking function) … … 540 569 541 570 // get output values from RPC descriptor 542 *inode_xp = (xptr_t)rpc.args[ 6];543 *error = (error_t)rpc.args[ 7];571 *inode_xp = (xptr_t)rpc.args[7]; 572 *error = (error_t)rpc.args[8]; 544 573 } 545 574 … … 548 577 { 549 578 xptr_t dentry_xp; 550 uint32_t type; 579 uint32_t fs_type; 580 uint32_t inode_type; 551 581 uint32_t attr; 552 uint32_t mode;582 uint32_t rights; 553 583 uint32_t uid; 554 584 uint32_t gid; … … 561 591 562 592 // get input arguments from client rpc descriptor 563 dentry_xp = (xptr_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); 564 type = (uint32_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[1] ) ); 565 attr = (uint32_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[2] ) ); 566 mode = (uint32_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[3] ) ); 567 uid = (uid_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[4] ) ); 568 gid = (gid_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[5] ) ); 593 dentry_xp = (xptr_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); 594 fs_type = (uint32_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[1] ) ); 595 inode_type = (uint32_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[2] ) ); 596 attr = (uint32_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[3] ) ); 597 rights = (uint32_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[4] ) ); 598 uid = (uid_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[5] ) ); 599 gid = (gid_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[6] ) ); 569 600 570 601 // call local kernel function 571 602 error = vfs_inode_create( dentry_xp, 572 type, 603 fs_type, 604 inode_type, 573 605 attr, 574 mode,606 rights, 575 607 uid, 576 608 gid, … … 578 610 579 611 // set output arguments 580 hal_remote_swd( XPTR( client_cxy , &desc->args[ 6] ) , (uint64_t)inode_xp );581 hal_remote_swd( XPTR( client_cxy , &desc->args[ 7] ) , (uint64_t)error );582 } 583 584 ///////////////////////////////////////////////////////////////////////////////////////// 585 // 612 hal_remote_swd( XPTR( client_cxy , &desc->args[7] ) , (uint64_t)inode_xp ); 613 hal_remote_swd( XPTR( client_cxy , &desc->args[8] ) , (uint64_t)error ); 614 } 615 616 ///////////////////////////////////////////////////////////////////////////////////////// 617 // [11] Marshaling functions attached to RPC_VFS_INODE_DESTROY 586 618 ///////////////////////////////////////////////////////////////////////////////////////// 587 619 … … 626 658 627 659 ///////////////////////////////////////////////////////////////////////////////////////// 628 // 660 // [12] Marshaling functions attached to RPC_VFS_DENTRY_CREATE 629 661 ///////////////////////////////////////////////////////////////////////////////////////// 630 662 … … 701 733 702 734 ///////////////////////////////////////////////////////////////////////////////////////// 703 // 735 // [13] Marshaling functions attached to RPC_VFS_DENTRY_DESTROY 704 736 ///////////////////////////////////////////////////////////////////////////////////////// 705 737 … … 745 777 746 778 ///////////////////////////////////////////////////////////////////////////////////////// 747 // Marshaling functions attached to RPC_VMM_GET_REF_VSEG 779 // [14] Marshaling functions attached to RPC_VFS_FILE_CREATE 780 ///////////////////////////////////////////////////////////////////////////////////////// 781 782 ////////////////////////////////////////////////////////////// 783 void rpc_vfs_file_create_client( cxy_t cxy, 784 struct vfs_inode_s * inode, // in 785 uint32_t file_attr, // in 786 xptr_t * file_xp, // out 787 error_t * error ) // out 788 { 789 // RPC must be remote 790 if( cxy == local_cxy ) 791 { 792 printk("PANIC in %s : target cluster is not remote\n", __FUNCTION__ ); 793 hal_core_sleep(); 794 } 795 796 // initialise RPC descriptor header 797 rpc_desc_t rpc; 798 rpc.index = RPC_VFS_FILE_CREATE; 799 rpc.response = 1; 800 801 // set input arguments in RPC descriptor 802 rpc.args[0] = (uint64_t)(intptr_t)inode; 803 rpc.args[1] = (uint64_t)file_attr; 804 805 // register RPC request in remote RPC fifo (blocking function) 806 rpc_send_sync( cxy , &rpc ); 807 808 // get output values from RPC descriptor 809 *file_xp = (xptr_t)rpc.args[2]; 810 *error = (error_t)rpc.args[3]; 811 } 812 813 //////////////////////////////////////////// 814 void rpc_vfs_file_create_server( xptr_t xp ) 815 { 816 uint32_t file_attr; 817 vfs_inode_t * inode; 818 xptr_t file_xp; 819 error_t error; 820 821 // get client cluster identifier and pointer on RPC descriptor 822 cxy_t client_cxy = (cxy_t)GET_CXY( xp ); 823 rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); 824 825 // get arguments "file_attr" and "inode" from client RPC descriptor 826 inode = (vfs_inode_t *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); 827 file_attr = (uint32_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[1] ) ); 828 829 // call local kernel function 830 error = vfs_file_create( inode, 831 file_attr, 832 &file_xp ); 833 834 // set output arguments 835 hal_remote_swd( XPTR( client_cxy , &desc->args[2] ) , (uint64_t)file_xp ); 836 hal_remote_swd( XPTR( client_cxy , &desc->args[3] ) , (uint64_t)error ); 837 } 838 839 ///////////////////////////////////////////////////////////////////////////////////////// 840 // [15] Marshaling functions attached to RPC_VFS_FILE_DESTROY 841 ///////////////////////////////////////////////////////////////////////////////////////// 842 843 /////////////////////////////////////////////////// 844 void rpc_vfs_file_destroy_client( cxy_t cxy, 845 vfs_file_t * file ) 846 { 847 // RPC must be remote 848 if( cxy == local_cxy ) 849 { 850 printk("PANIC in %s : target cluster is not remote\n", __FUNCTION__ ); 851 hal_core_sleep(); 852 } 853 854 // initialise RPC descriptor header 855 rpc_desc_t rpc; 856 rpc.index = RPC_VFS_FILE_DESTROY; 857 rpc.response = 1; 858 859 // set input arguments in RPC descriptor 860 rpc.args[0] = (uint64_t)(intptr_t)file; 861 862 // register RPC request in remote RPC fifo (blocking function) 863 rpc_send_sync( cxy , &rpc ); 864 } 865 866 ///////////////////////////////////////////// 867 void rpc_vfs_file_destroy_server( xptr_t xp ) 868 { 869 vfs_file_t * file; 870 871 // get client cluster identifier and pointer on RPC descriptor 872 cxy_t client_cxy = (cxy_t)GET_CXY( xp ); 873 rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); 874 875 // get arguments "dentry" from client RPC descriptor 876 file = (vfs_file_t *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); 877 878 // call local kernel function 879 vfs_file_destroy( file ); 880 } 881 882 ///////////////////////////////////////////////////////////////////////////////////////// 883 // [16] Marshaling functions attached to RPC_FATFS_GET_CLUSTER 884 ///////////////////////////////////////////////////////////////////////////////////////// 885 886 ////////////////////////////////////////////////// 887 void rpc_fatfs_get_cluster_client( cxy_t cxy, 888 mapper_t * mapper, // in 889 uint32_t first, // in 890 uint32_t page, // in 891 uint32_t * cluster, // out 892 error_t * error ) // out 893 { 894 // RPC must be remote 895 if( cxy == local_cxy ) 896 { 897 printk("PANIC in %s : target is not remote\n", __FUNCTION__ ); 898 hal_core_sleep(); 899 } 900 901 // initialise RPC descriptor header 902 rpc_desc_t rpc; 903 rpc.index = RPC_FATFS_GET_CLUSTER; 904 rpc.response = 1; 905 906 // set input arguments in RPC descriptor 907 rpc.args[0] = (uint64_t)(intptr_t)mapper; 908 rpc.args[1] = (uint64_t)first; 909 rpc.args[2] = (uint64_t)page; 910 911 // register RPC request in remote RPC fifo 912 rpc_send_sync( cxy , &rpc ); 913 914 // get output argument from rpc descriptor 915 *cluster = (uint32_t)rpc.args[3]; 916 *error = (error_t)rpc.args[4]; 917 } 918 919 ////////////////////////////////////////////// 920 void rpc_fatfs_get_cluster_server( xptr_t xp ) 921 { 922 mapper_t * mapper; 923 uint32_t first; 924 uint32_t page; 925 uint32_t cluster; 926 error_t error; 927 928 // get client cluster identifier and pointer on RPC descriptor 929 cxy_t client_cxy = (cxy_t)GET_CXY( xp ); 930 rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); 931 932 // get input arguments 933 mapper = (mapper_t *)(intptr_t)hal_remote_lpt( XPTR( client_cxy , &desc->args[0] ) ); 934 first = (uint32_t) hal_remote_lw ( XPTR( client_cxy , &desc->args[1] ) ); 935 page = (uint32_t) hal_remote_lw ( XPTR( client_cxy , &desc->args[2] ) ); 936 937 // call the kernel function 938 error = fatfs_get_cluster( mapper , first , page , &cluster ); 939 940 // set output argument 941 hal_remote_swd( XPTR( client_cxy , &desc->args[3] ) , (uint64_t)cluster ); 942 hal_remote_swd( XPTR( client_cxy , &desc->args[4] ) , (uint64_t)error ); 943 } 944 945 ///////////////////////////////////////////////////////////////////////////////////////// 946 // [20] Marshaling functions attached to RPC_VMM_GET_REF_VSEG 748 947 ///////////////////////////////////////////////////////////////////////////////////////// 749 948 … … 804 1003 805 1004 ///////////////////////////////////////////////////////////////////////////////////////// 806 // 1005 // [21] Marshaling functions attached to RPC_VMM_GET_PTE 807 1006 ///////////////////////////////////////////////////////////////////////////////////////// 808 1007 … … 867 1066 868 1067 ///////////////////////////////////////////////////////////////////////////////////////// 869 // Marshaling functions attached to RPC_SEMAPHORE_ALLOC 870 ///////////////////////////////////////////////////////////////////////////////////////// 871 872 ////////////////////////////////////////////// 873 void rpc_semaphore_alloc_client( cxy_t cxy, 874 xptr_t * sem_xp ) // out 1068 // [22] Marshaling functions attached to RPC_KCM_ALLOC 1069 ///////////////////////////////////////////////////////////////////////////////////////// 1070 1071 ////////////////////////////////////////// 1072 void rpc_kcm_alloc_client( cxy_t cxy, 1073 uint32_t kmem_type, // in 1074 xptr_t * buf_xp ) // out 875 1075 { 876 1076 // RPC must be remote … … 886 1086 rpc.response = 1; 887 1087 1088 // set input arguments in RPC descriptor 1089 rpc.args[0] = (uint64_t)kmem_type; 1090 888 1091 // register RPC request in remote RPC fifo 889 1092 rpc_send_sync( cxy , &rpc ); 890 1093 891 1094 // get output arguments from RPC descriptor 892 * sem_xp = (xptr_t)rpc.args[0];893 } 894 895 ////////////////////////////////////// //////896 void rpc_ semaphore_alloc_server( xptr_t xp )1095 *buf_xp = (xptr_t)rpc.args[1]; 1096 } 1097 1098 ////////////////////////////////////// 1099 void rpc_kcm_alloc_server( xptr_t xp ) 897 1100 { 898 1101 // get client cluster identifier and pointer on RPC descriptor … … 900 1103 rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); 901 1104 902 // allocates memory for semaphore 1105 // get input argument "kmem_type" from client RPC descriptor 1106 uint32_t kmem_type = (uint32_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); 1107 1108 // allocates memory for kcm 903 1109 kmem_req_t req; 904 req.type = KMEM_SEM;1110 req.type = kmem_type; 905 1111 req.flags = AF_ZERO; 906 remote_sem_t * sem_ptr = kmem_alloc( &req );1112 void * buf_ptr = kmem_alloc( &req ); 907 1113 908 1114 // set output argument 909 xptr_t sem_xp = XPTR( local_cxy , sem_ptr );910 hal_remote_swd( XPTR( client_cxy , &desc->args[ 0] ) , (uint64_t)sem_xp );1115 xptr_t buf_xp = XPTR( local_cxy , buf_ptr ); 1116 hal_remote_swd( XPTR( client_cxy , &desc->args[1] ) , (uint64_t)buf_xp ); 911 1117 } 912 1118 913 1119 ///////////////////////////////////////////////////////////////////////////////////////// 914 // Marshaling functions attached to RPC_SEMAPHORE_FREE 915 ///////////////////////////////////////////////////////////////////////////////////////// 916 917 /////////////////////////////////////////////////// 918 void rpc_semaphore_free_client( cxy_t cxy, 919 remote_sem_t * sem ) // in 1120 // [23] Marshaling functions attached to RPC_KCM_FREE 1121 ///////////////////////////////////////////////////////////////////////////////////////// 1122 1123 ///////////////////////////////////////// 1124 void rpc_kcm_free_client( cxy_t cxy, 1125 void * buf, // in 1126 uint32_t kmem_type ) // in 920 1127 { 921 1128 // RPC must be remote … … 932 1139 933 1140 // set input arguments in RPC descriptor 934 rpc.args[0] = (uint64_t)(intptr_t)sem; 1141 rpc.args[0] = (uint64_t)(intptr_t)buf; 1142 rpc.args[1] = (uint64_t)kmem_type; 935 1143 936 1144 // register RPC request in remote RPC fifo … … 938 1146 } 939 1147 940 ///////////////////////////////////// //////941 void rpc_ semaphore_free_server( xptr_t xp )1148 ///////////////////////////////////// 1149 void rpc_kcm_free_server( xptr_t xp ) 942 1150 { 943 1151 // get client cluster identifier and pointer on RPC descriptor … … 945 1153 rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); 946 1154 947 // get input argument "sem_ptr" from client RPC descriptor 948 void * sem = (void *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); 1155 // get input arguments "buf" and "kmem_type" from client RPC descriptor 1156 void * buf = (void *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); 1157 uint32_t kmem_type = (uint32_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[1] ) ); 949 1158 950 1159 // releases memory 951 1160 kmem_req_t req; 952 req.type = KMEM_SEM;953 req.ptr = sem;954 kmem_free( &req);1161 req.type = kmem_type; 1162 req.ptr = buf; 1163 kmem_free( &req ); 955 1164 } 956 1165 957 1166 ///////////////////////////////////////////////////////////////////////////////////////// 958 // Marshaling functions attached to RPC_MAPPER_MOVE 959 ///////////////////////////////////////////////////////////////////////////////////////// 960 961 ////////////////////////////////////////////// 962 void rpc_mapper_move_client( cxy_t cxy, 963 mapper_t * mapper, // in 964 bool_t read, // in 965 uint32_t nb_frags, // in 966 fragment_t * frags, // in 967 error_t * error ) // out 968 { 969 // RPC must be remote 970 if( cxy == local_cxy ) 971 { 972 printk("PANIC in %s : target is not remote\n", __FUNCTION__ ); 1167 // [24] Marshaling functions attached to RPC_MAPPER_MOVE 1168 ///////////////////////////////////////////////////////////////////////////////////////// 1169 1170 /////////////////////////////////////////// 1171 void rpc_mapper_move_client( cxy_t cxy, 1172 mapper_t * mapper, // in 1173 uint32_t to_buffer, // in 1174 uint32_t file_offset, // in 1175 void * buffer, // in 1176 uint32_t size, // in 1177 error_t * error ) // out 1178 { 1179 // RPC must be remote 1180 if( cxy == local_cxy ) 1181 { 1182 printk("PANIC in %s : target cluster is not remote\n", __FUNCTION__ ); 973 1183 hal_core_sleep(); 974 1184 } … … 981 1191 // set input arguments in RPC descriptor 982 1192 rpc.args[0] = (uint64_t)(intptr_t)mapper; 983 rpc.args[1] = (uint64_t)read; 984 rpc.args[2] = (uint64_t)nb_frags; 985 rpc.args[3] = (uint64_t)(intptr_t)frags; 986 987 // register RPC request in remote RPC fifo 988 rpc_send_sync( cxy , &rpc ); 989 990 // get output argument from rpc descriptor 991 *error = (error_t)rpc.args[4]; 1193 rpc.args[1] = (uint64_t)to_buffer; 1194 rpc.args[2] = (uint64_t)file_offset; 1195 rpc.args[3] = (uint64_t)(intptr_t)buffer; 1196 rpc.args[4] = (uint64_t)size; 1197 1198 // register RPC request in remote RPC fifo (blocking function) 1199 rpc_send_sync( cxy , &rpc ); 1200 1201 // get output values from RPC descriptor 1202 *error = (error_t)rpc.args[5]; 992 1203 } 993 1204 … … 995 1206 void rpc_mapper_move_server( xptr_t xp ) 996 1207 { 997 mapper_t * mapper; 998 bool_t read; 999 uint32_t nb; 1000 void * frags; 1001 error_t error; 1002 1003 // get client cluster identifier and pointer on RPC descriptor 1004 cxy_t client_cxy = (cxy_t)GET_CXY( xp ); 1005 rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); 1006 1007 // get input arguments 1008 mapper = (mapper_t*)(intptr_t)hal_remote_lpt( XPTR( client_cxy , &desc->args[0] ) ); 1009 read = (bool_t) hal_remote_lw ( XPTR( client_cxy , &desc->args[1] ) ); 1010 nb = (uint32_t) hal_remote_lw ( XPTR( client_cxy , &desc->args[2] ) ); 1011 frags = (void*)(intptr_t) hal_remote_lpt( XPTR( client_cxy , &desc->args[3] ) ); 1012 1013 // call the mapper_move_fragments() function 1014 error = mapper_move_fragments( mapper , read , nb , XPTR( client_cxy , frags ) ); 1015 1016 // set output argument 1017 hal_remote_swd( XPTR( client_cxy , &desc->args[4] ) , (uint64_t)error ); 1018 } 1019 1020 ///////////////////////////////////////////////////////////////////////////////////////// 1021 // Marshaling functions attached to RPC_FATFS_GET_CLUSTER 1022 ///////////////////////////////////////////////////////////////////////////////////////// 1023 1024 ////////////////////////////////////////////////// 1025 void rpc_fatfs_get_cluster_client( cxy_t cxy, 1026 mapper_t * mapper, // in 1027 uint32_t first, // in 1028 uint32_t page, // in 1029 uint32_t * cluster, // out 1030 error_t * error ) // out 1031 { 1032 // RPC must be remote 1033 if( cxy == local_cxy ) 1034 { 1035 printk("PANIC in %s : target is not remote\n", __FUNCTION__ ); 1036 hal_core_sleep(); 1037 } 1038 1039 // initialise RPC descriptor header 1040 rpc_desc_t rpc; 1041 rpc.index = RPC_FATFS_GET_CLUSTER; 1042 rpc.response = 1; 1043 1044 // set input arguments in RPC descriptor 1045 rpc.args[0] = (uint64_t)(intptr_t)mapper; 1046 rpc.args[1] = (uint64_t)first; 1047 rpc.args[2] = (uint64_t)page; 1048 1049 // register RPC request in remote RPC fifo 1050 rpc_send_sync( cxy , &rpc ); 1051 1052 // get output argument from rpc descriptor 1053 *cluster = (uint32_t)rpc.args[3]; 1054 *error = (error_t)rpc.args[4]; 1055 } 1056 1057 ////////////////////////////////////////////// 1058 void rpc_fatfs_get_cluster_server( xptr_t xp ) 1059 { 1060 mapper_t * mapper; 1061 uint32_t first; 1062 uint32_t page; 1063 uint32_t cluster; 1064 error_t error; 1065 1066 // get client cluster identifier and pointer on RPC descriptor 1067 cxy_t client_cxy = (cxy_t)GET_CXY( xp ); 1068 rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); 1069 1070 // get input arguments 1071 mapper = (mapper_t*)(intptr_t)hal_remote_lpt( XPTR( client_cxy , &desc->args[0] ) ); 1072 first = (uint32_t) hal_remote_lw ( XPTR( client_cxy , &desc->args[1] ) ); 1073 page = (uint32_t) hal_remote_lw ( XPTR( client_cxy , &desc->args[2] ) ); 1074 1075 // call the kernel function 1076 error = fatfs_get_cluster( mapper , first , page , &cluster ); 1077 1078 // set output argument 1079 hal_remote_swd( XPTR( client_cxy , &desc->args[3] ) , (uint64_t)cluster ); 1080 hal_remote_swd( XPTR( client_cxy , &desc->args[4] ) , (uint64_t)error ); 1208 mapper_t * mapper; 1209 uint32_t to_buffer; 1210 uint32_t file_offset; 1211 void * buffer; 1212 uint32_t size; 1213 error_t error; 1214 1215 // get client cluster identifier and pointer on RPC descriptor 1216 cxy_t client_cxy = (cxy_t)GET_CXY( xp ); 1217 rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); 1218 1219 // get arguments from client RPC descriptor 1220 mapper = (mapper_t *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); 1221 to_buffer = hal_remote_lwd( XPTR( client_cxy , &desc->args[1] ) ); 1222 file_offset = hal_remote_lwd( XPTR( client_cxy , &desc->args[2] ) ); 1223 buffer = (void *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[3] ) ); 1224 size = hal_remote_lwd( XPTR( client_cxy , &desc->args[4] ) ); 1225 1226 // call local kernel function 1227 error = mapper_move( mapper, 1228 to_buffer, 1229 file_offset, 1230 buffer, 1231 size ); 1232 1233 // set output argument to client RPC descriptor 1234 hal_remote_swd( XPTR( client_cxy , &desc->args[5] ) , (uint64_t)error ); 1081 1235 } 1082 1236 -
trunk/kernel/kern/rpc.h
r16 r23 2 2 * rpc.h - RPC (Remote Procedure Call) operations definition. 3 3 * 4 * Authors Mohamed Karaoui (2015) 5 * Alain Greiner (2016) 4 * Author Alain Greiner (2016,2017) 6 5 * 7 6 * Copyright (c) UPMC Sorbonne Universites … … 43 42 struct vfs_inode_s; 44 43 struct vfs_dentry_s; 44 struct vfs_file_s; 45 45 struct thread_s; 46 46 struct mapper_s; … … 63 63 RPC_THREAD_USER_CREATE = 4, 64 64 RPC_THREAD_KERNEL_CREATE = 5, 65 RPC_SIGNAL_RISE = 6, 65 66 66 67 RPC_VFS_INODE_CREATE = 10, … … 68 69 RPC_VFS_DENTRY_CREATE = 12, 69 70 RPC_VFS_DENTRY_DESTROY = 13, 71 RPC_VFS_FILE_CREATE = 14, 72 RPC_VFS_FILE_DESTROY = 15, 73 RPC_FATFS_GET_CLUSTER = 16, 70 74 71 75 RPC_VMM_GET_REF_VSEG = 20, 72 76 RPC_VMM_GET_PTE = 21, 73 RPC_ SEMAPHORE_ALLOC= 22,74 RPC_ SEMAPHORE_FREE= 23,77 RPC_KCM_ALLOC = 22, 78 RPC_KCM_FREE = 23, 75 79 RPC_MAPPER_MOVE = 24, 76 80 77 RPC_FATFS_GET_CLUSTER = 30, 78 79 RPC_MAX_INDEX = 31, 81 RPC_MAX_INDEX = 30, 80 82 } 81 83 rpc_index_t; … … 96 98 rpc_index_t index; // index of requested RPC service 97 99 volatile uint32_t response; // response valid when 0 98 uint64_t args[ 8];// input/output arguments buffer100 uint64_t args[10]; // input/output arguments buffer 99 101 } 100 102 rpc_desc_t; … … 192 194 void __attribute__((noinline)) rpc_undefined(); 193 195 196 197 198 194 199 /**********************************************************************************/ 195 200 /******* Marshalling functions attached to the various RPCs ***********************/ … … 197 202 198 203 /*********************************************************************************** 199 * The RPC_PMEM_GET_PAGES allocates one or several pages in a remote cluster,204 * [0] The RPC_PMEM_GET_PAGES allocates one or several pages in a remote cluster, 200 205 * and returns the PPN of the first allocated page. 201 206 *********************************************************************************** … … 213 218 214 219 /*********************************************************************************** 215 * The RPC_PROCESS_PID_ALLOC allocates one new PID in a remote cluster, registers220 * [1] The RPC_PROCESS_PID_ALLOC allocates one new PID in a remote cluster, registers 216 221 * the new process in the remote cluster, and returns the PID, and an error code. 217 222 *********************************************************************************** … … 229 234 230 235 /*********************************************************************************** 231 * The RPC_PROCESS_EXEC creates a process descriptor copy, in a remote cluster236 * [2] The RPC_PROCESS_EXEC creates a process descriptor copy, in a remote cluster 232 237 * and initializes if from information found in the reference process descriptor. 233 238 * This remote cluster becomes the new reference cluster. … … 244 249 245 250 /*********************************************************************************** 246 * The RPC_PROCESS_KILL is actually a multicast RPC sent by the reference cluster251 * [3] The RPC_PROCESS_KILL is actually a multicast RPC sent by the reference cluster 247 252 * to other clusters containing a process descriptor copy, to destroy these copies. 248 253 *********************************************************************************** … … 254 259 255 260 /*********************************************************************************** 256 * The RPC_THREAD_USER_CREATE creates an user thread in the server cluster,257 * as specified by the pthread_attr_t argument. It returns the local pointer258 * on thethread descriptor in server cluster, and an error code.259 * It is called by the pthread_createsystem call.261 * [4] The RPC_THREAD_USER_CREATE creates an user thread in the server cluster, 262 * as specified by the arguments. It returns an extended pointer on the new 263 * thread descriptor in server cluster, and an error code. 264 * It is called by the sys_thread_create() system call. 260 265 *********************************************************************************** 261 266 * @ cxy : server cluster identifier. … … 265 270 **********************************************************************************/ 266 271 void rpc_thread_user_create_client( cxy_t cxy, 272 pid_t pid, 273 void * start_func, 274 void * start_arg, 267 275 struct pthread_attr_s * attr, 268 276 xptr_t * thread_xp, … … 272 280 273 281 /*********************************************************************************** 274 * The RPC_THREAD_KERNEL_CREATE creates a kernel thread in the server cluster,282 * [5] The RPC_THREAD_KERNEL_CREATE creates a kernel thread in the server cluster, 275 283 * as specified by the type, func and args arguments. It returns the local pointer 276 284 * on the thread descriptor in server cluster and an error code. 277 * It is used by the dev_init() function to cre tae the device server thread.285 * It is used by the dev_init() function to create the device server thread. 278 286 *********************************************************************************** 279 287 * @ cxy : server cluster identifier. … … 293 301 void rpc_thread_kernel_create_server( xptr_t xp ); 294 302 303 /*********************************************************************************** 304 * [6] The RPC_SIGNAL_RISE ask a target cluster to register a given signal in 305 * all threads descriptors of a given process. 306 * It is used by the sys_kill() function. 307 *********************************************************************************** 308 * @ cxy : server cluster identifier. 309 * @ process : [in] local pointer on target process descriptor in server. 310 * @ sig_id : [in] signal index. 311 **********************************************************************************/ 312 void rpc_signal_rise_client( cxy_t cxy, 313 struct process_s * process, 314 uint32_t sig_id ); 315 316 void rpc_signal_rise_server( xptr_t xp ); 317 295 318 /*********************************************************************************** 296 * The RPC_VFS_INODE_CREATE creates an inode and the associated mapper in a319 * [10] The RPC_VFS_INODE_CREATE creates an inode and the associated mapper in a 297 320 * remote cluster. The parent dentry must have been previously created. 298 321 * It returns an extended pointer on the created inode. 299 322 *********************************************************************************** 300 * @ cxy : server cluster identifier 301 * @ dentry_xp : [in] extended pointer on parent dentry. 302 * @ type : [in] file system type. 303 * @ attr : [in] TODO ??? 304 * @ mode : [in] access mode. 305 * @ uid : [in] user ID 306 * @ gid : [in] group ID 307 * @ inode_xp : [out] buffer for extended pointer on created inode. 308 * @ error : [out] error status (0 if success). 323 * @ cxy : server cluster identifier. 324 * @ dentry_xp : [in] extended pointer on parent dentry. 325 * @ fs_type : [in] file system type. 326 * @ inode_type : [in] file system type. 327 * @ attr : [in] inode attributes. 328 * @ rights : [in] access rights 329 * @ uid : [in] user ID 330 * @ gid : [in] group ID 331 * @ inode_xp : [out] buffer for extended pointer on created inode. 332 * @ error : [out] error status (0 if success). 309 333 **********************************************************************************/ 310 334 void rpc_vfs_inode_create_client( cxy_t cxy, 311 335 xptr_t dentry_xp, 312 uint32_t type, 336 uint32_t fs_type, 337 uint32_t inode_type, 313 338 uint32_t attr, 314 uint32_t mode,339 uint32_t rights, 315 340 uint32_t uid, 316 341 uint32_t gid, … … 321 346 322 347 /*********************************************************************************** 323 * The RPC_VFS_INODE_DESTROY releases memory allocated for an inode descriptor348 * [11] The RPC_VFS_INODE_DESTROY releases memory allocated for an inode descriptor 324 349 * and for the associated mapper in a remote cluster. 325 350 *********************************************************************************** … … 333 358 334 359 /*********************************************************************************** 335 * The RPC_VFS_DENTRY_CREATE creates a dentry in a remote cluster.360 * [12] The RPC_VFS_DENTRY_CREATE creates a dentry in a remote cluster. 336 361 * It returns an extended pointer on the created dentry. 337 362 *********************************************************************************** … … 353 378 354 379 /*********************************************************************************** 355 * The RPC_VFS_DENTRY_DESTROY releases memory allocated for an dentry descriptor380 * [13] The RPC_VFS_DENTRY_DESTROY releases memory allocated for an dentry descriptor 356 381 * in a remote cluster. 357 382 *********************************************************************************** … … 364 389 void rpc_vfs_dentry_destroy_server( xptr_t xp ); 365 390 366 367 368 369 /*********************************************************************************** 370 * The RPC_VMM_GET_REF_VSEG returns an extended pointer 391 /*********************************************************************************** 392 * [14] The RPC_VFS_FILE_CREATE creates a file descriptor in a remote cluster. 393 * It returns an extended pointer on the created file structure. 394 *********************************************************************************** 395 * @ cxy : server cluster identifier 396 * @ inode : [in] local pointer on parent inode. 397 * @ file_attr : [in] new file attributes. 398 * @ file_xp : [out] buffer for extended pointer on created file. 399 * @ error : [out] error status (0 if success). 400 **********************************************************************************/ 401 void rpc_vfs_file_create_client( cxy_t cxy, 402 struct vfs_inode_s * inode, 403 uint32_t file_attr, 404 xptr_t * file_xp, 405 error_t * error ); 406 407 void rpc_vfs_file_create_server( xptr_t xp ); 408 409 /*********************************************************************************** 410 * [15] The RPC_VFS_FILE_DESTROY releases memory allocated for a file descriptor 411 * in a remote cluster. 412 *********************************************************************************** 413 * @ cxy : server cluster identifier 414 * @ file : [in] local pointer on file. 415 **********************************************************************************/ 416 void rpc_vfs_file_destroy_client( cxy_t cxy, 417 struct vfs_file_s * file ); 418 419 void rpc_vfs_file_destroy_server( xptr_t xp ); 420 421 /*********************************************************************************** 422 * [16] The RPC_FATFS_GET_CLUSTER can be send by any thread running in a "client" 423 * cluster to scan the FAT mapper, stored in a remote "server" cluster, and get 424 * from the mapper the local pointer on a given page. 425 *********************************************************************************** 426 * @ cxy : server cluster identifier. 427 * @ mapper : [in] local pointer on FAT mapper. 428 * @ first : [in] FATFS cluster index allocated to first page of file. 429 * @ page : [in] page index in file. 430 * @ cluster : [out] local pointer on buffer for found FATFS cluster index. 431 * @ error : [out] local pointer on buffer for error code (in client cluster). 432 **********************************************************************************/ 433 void rpc_fatfs_get_cluster_client( cxy_t cxy, 434 struct mapper_s * mapper, 435 uint32_t first, 436 uint32_t page, 437 uint32_t * cluster, 438 error_t * error ); 439 440 void rpc_fatfs_get_cluster_server( xptr_t xp ); 441 442 /*********************************************************************************** 443 * [20] The RPC_VMM_GET_REF_VSEG returns an extended pointer 371 444 * on the vseg containing a given virtual address in a given process. 372 445 * The server cluster is supposed to be the reference cluster. … … 386 459 387 460 /*********************************************************************************** 388 * The RPC_VMM_GET_PTE returns in the "ppn" and "attr" arguments the PTE value461 * [21] The RPC_VMM_GET_PTE returns in the "ppn" and "attr" arguments the PTE value 389 462 * for a given VPN in a given process. 390 463 * The server cluster is supposed to be the reference cluster, and the vseg … … 410 483 411 484 /*********************************************************************************** 412 * The RPC_SEMAPHORE_ALLOC allocates memory for a semaphore in a remote cluster, 413 * and returns an extended pointer on the created semaphore. 414 It returns NULL if physical memory cannot be allocated. 415 *********************************************************************************** 416 * @ cxy : server cluster identifier. 417 * @ sem_xp : [out] buffer for extended pointer on semaphore. 418 **********************************************************************************/ 419 void rpc_semaphore_alloc_client( cxy_t cxy, 420 xptr_t * sem_xp ); 421 422 void rpc_semaphore_alloc_server( xptr_t xp ); 423 424 /*********************************************************************************** 425 * The RPC_SEMAPHORE_FREE releases memory allocated for a semaphore 485 * [22] The RPC_KCM_ALLOC allocates memory from a given KCM in a remote cluster, 486 * and returns an extended pointer on the allocated object. 487 It returns XPTR_NULL if physical memory cannot be allocated. 488 *********************************************************************************** 489 * @ cxy : server cluster identifier. 490 * @ kmem_type : [in] KCM object type (as defined in kmem.h). 491 * @ buf_xp : [out] buffer for extended pointer on allocated buffer. 492 **********************************************************************************/ 493 void rpc_kcm_alloc_client( cxy_t cxy, 494 uint32_t kmem_type, 495 xptr_t * buf_xp ); 496 497 void rpc_kcm_alloc_server( xptr_t xp ); 498 499 /*********************************************************************************** 500 * [23] The RPC_KCM_FREE releases memory allocated for a KCM object of a given type, 426 501 * in a remote cluster. 427 502 *********************************************************************************** 428 * @ cxy : server cluster identifier. 429 * @ sem : [in] local pointer on semaphore. 430 **********************************************************************************/ 431 void rpc_semaphore_free_client( cxy_t cxy, 432 struct remote_sem_s * sem ); 433 434 void rpc_semaphore_free_server( xptr_t xp ); 435 436 /*********************************************************************************** 437 * The RPC_MAPPER_MOVE can be send by any thread running in a "client" cluster 438 * to the "server" cluster containing the mapper of a given file. The service is 439 * to move data between the mapper and an user buffer. This user buffer is described 440 * as a set of fragments. Each fragment is contained in one single physical page. 441 * It is defined by four parameters : size / file_offset / ppn / page_offset, 442 * defined in the mapper.h file. The client thread is in charge of building 443 * the fragments array covering the user buffer. 444 * As each fragments can be stored in a different cluster, and this fragment can 445 * be stored in two successive pages in the radix tree, each fragment is moved 446 * using one or two different hal_remote_memcpy(). 447 *********************************************************************************** 448 * @ cxy : server cluster identifier. 449 * @ inode : [in] local pointer on inode (in server cluster). 450 * @ read : [in] mapper to buffer if true / buffer to mapper if false. 451 * @ nb_frags : [in] number of fragments in fragments array. 452 * @ frags : [in] local pointer on fragments array (in client cluster). 453 * @ error : [out] local pointer on buffer for error code (in client cluster). 454 **********************************************************************************/ 455 void rpc_mapper_move_client( cxy_t cxy, 456 struct mapper_s * mapper, 457 bool_t read, 458 uint32_t nb_frags, 459 struct fragment_s * frags, 460 error_t * error ); 503 * @ cxy : server cluster identifier. 504 * @ buf : [in] local pointer on allocated buffer. 505 * @ kmem_type : [in] KCM object type (as defined in kmem.h). 506 **********************************************************************************/ 507 void rpc_kcm_free_client( cxy_t cxy, 508 void * buf, 509 uint32_t kmem_type ); 510 511 void rpc_kcm_free_server( xptr_t xp ); 512 513 /*********************************************************************************** 514 * [24] The RPC_MAPPER_MOVE is called by the vfs_move() function. 515 * It allows a client thread to requires a remote mapper to move data to/from 516 * an user buffer, as specified by the arguments. 517 *********************************************************************************** 518 * @ cxy : server cluster identifier. 519 * @ mapper : [in] local pointer on mapper 520 * @ to_buffer : [in] move data from buffer to mapper if non zero. 521 * @ file_offset : [in] first byte to move in mapper 522 * @ buffer : [in] pointer on buffer in user space 523 * @ size : [in] number of bytes to move 524 * @ error : [out] error status (0 if success). 525 **********************************************************************************/ 526 void rpc_mapper_move_client( cxy_t cxy, 527 struct mapper_s * mapper, 528 uint32_t to_buffer, 529 uint32_t file_offset, 530 void * buffer, 531 uint32_t size, 532 error_t * error ); 461 533 462 534 void rpc_mapper_move_server( xptr_t xp ); 463 535 464 /*********************************************************************************** 465 * The RPC_FATFS_GET_CLUSTER can be send by any thread running in a "client" cluster 466 * to scan the FAT mapper, stored in a remote "server" cluster, and get the FATFS 467 * cluster index of a given page of a given file. 468 *********************************************************************************** 469 * @ cxy : server cluster identifier. 470 * @ mapper : [in] local pointer on FAT mapper. 471 * @ first : [in] FATFS cluster index allocated to first page of file. 472 * @ page : [in] page index in file. 473 * @ cluster : [out] local pointer on buffer for found FATFS cluster index. 474 * @ error : [out] local pointer on buffer for error code (in client cluster). 475 **********************************************************************************/ 476 void rpc_fatfs_get_cluster_client( cxy_t cxy, 477 struct mapper_s * mapper, 478 uint32_t first, 479 uint32_t page, 480 uint32_t * cluster, 481 error_t * error ); 482 483 void rpc_fatfs_get_cluster_server( xptr_t xp ); 536 537 484 538 485 539 #endif -
trunk/kernel/kern/signal.c
r5 r23 23 23 24 24 #include <hal_types.h> 25 #include <errno.h> 25 #include <hal_atomic.h> 26 #include <printk.h> 26 27 #include <thread.h> 27 #include <process.h> 28 #include <core.h> 28 #include <spinlock.h> 29 29 #include <signal.h> 30 31 ////////////////////////////////////// 32 void signal_rise( process_t * process, 33 uint32_t sig_id ) 34 { 35 // get the lock protecting the set of local threads 36 spinlock_lock( &process->th_lock ); 37 38 // loop on local threads 39 thread_t * thread; 40 uint32_t i; 41 for( i = 0 ; i < process->th_nr ; i++ ) 42 { 43 thread = process->th_tbl[i]; 44 hal_atomic_or( &thread->signals , (1 << sig_id) ); 45 46 signal_dmsg("\n[INFO] %s : thread %x in process %x received signal %d\n", 47 __FUNCTION__, thread->trdid , process->pid , sig_id ); 48 } 49 50 // release the lock 51 spinlock_unlock( &process->th_lock ); 52 53 } // end signal_rise() 54 55 /* 30 56 31 57 SIGNAL_HANDLER(kill_sigaction) 32 58 { 33 struct thread_s *this; 34 35 this = CURRENT_THREAD; 36 this->state = S_KERNEL; 59 thread_s * this = CURRENT_THREAD; 37 60 38 printk( INFO, "INFO: Recieved signal %d, pid %d, tid %x, core %d [ KILLED ]\n",61 printk("\n[INFO] %s : threadReceived signal %d, pid %d, tid %x, core %d [ KILLED ]\n", 39 62 sig, 40 63 this->process->pid, … … 45 68 } 46 69 47 /////////////////////////////////////////////// ///70 /////////////////////////////////////////////// 48 71 void signal_manager_init( process_t * process ) 49 72 { … … 53 76 } 54 77 55 ////////////////////////////////////// 56 void signal_rise( process_t * process, 57 uint32_t sig)78 79 ///////////////////////////////////// 80 void signal_notify( thread_t * this ) 58 81 { 59 thread_t * thread; 60 uint32_t i; 82 uint32_t sig_state; 83 uint32_t sig; 84 sig_mgr_t * sig_mgr; 85 uint32_t irq_state; 61 86 62 spinlock_lock( &process->th_lock ); 63 64 for( i = 0 ; i < process->th_nr ; i++ ) 65 { 66 thread = process->th_tbl[i]; 67 hal_atomic_or( &thread->signals , (1 << sig) ); 68 } 69 70 spinlock_unlock( &process->th_lock ); 71 72 sig_dmsg("\n[INFO] %s : %d threads have been signaled for process %d\n", 73 __FUNCTION__, process->th_nr , process->pid ); 74 75 } // end signal_rise() 76 77 /////////////////////////////////////////// 78 RPC_DECLARE( __signal_rise, \ 79 RPC_RET( RPC_RET_PTR(error_t, err)), \ 80 RPC_ARG( RPC_ARG_VAL(pid_t, pid), \ 81 RPC_ARG_VAL(uint32_t, sig)) \ 82 ) 83 { 84 process_t * process; 85 struct hnode_s *hnode; 86 87 /* Avoid killing process0 and init */ 88 /* FIXME: Zero should not be hard-coded but obtains with something like MAIN_KERN */ 89 if( ((pid == PID_MIN_GLOBAL) || (pid == PID_MIN_GLOBAL+1)) 90 && (current_cid == 0) ) 91 { 92 *err = EPERM; 93 sig_dmsg(1, "%s: can't kill process %u on cluster %u\n", \ 94 __FUNCTION__, PID_GET_LOCAL(pid), current_cid); 95 goto SYS_RISE_ERR_PID; 96 } 97 98 /* Step 1 : lock the process manager */ 99 processs_manager_lock(); 100 101 /* Step 2 : Get the process' address */ 102 /* Case 1 : current cluster is the anchor and the owner. */ 103 if ( PID_GET_CLUSTER(pid) == current_cid ) 104 { 105 sig_dmsg(1, "%s: process %u is in the processs manager array of cluster %u\n", \ 106 __FUNCTION__, pid, current_cid); 107 process = process_lookup(pid)->process; 108 109 } 110 else /* Case 2 : current cluster is not the anchor, so the struct 111 * process_s is in its hash table. 112 */ 113 { 114 sig_dmsg(1, "%s: process %u is in the processs manager hash table of cluster %u\n", \ 115 __FUNCTION__, pid, current_cid); 116 hnode = hfind(processs_manager_get_htable(), (void*)pid); 117 process = ( process_t*) container_of(hnode, \ 118 process_t, t_hnode); 119 } 120 121 /* Step 4 : check process' address */ 122 if ( process == NULL ) 123 { 124 *err = ESRCH; 125 goto SYS_RISE_ERR; 126 } 127 128 /* Step 5 : deliver signal */ 129 if((sig == SIGTERM) || (sig == SIGKILL)) 130 *err = signal_rise_all(process, sig); 131 else 132 *err = signal_rise_one(process, sig); 133 134 /* Step 6 : unlock processs manager */ 135 processs_manager_unlock(); 136 137 return; 138 139 SYS_RISE_ERR: 140 processs_manager_unlock(); 141 SYS_RISE_ERR_PID: 142 sig_dmsg(1, "%s: Cluster %u has not deliver signal %u to process %u (err %u)\n", \ 143 __FUNCTION__, current_cid, sig, err ); 144 145 return; 146 } 147 148 /////////////////////////////// 149 error_t sys_kill( pid_t pid, 150 uint32_t sig) 151 { 152 cxy_t owner_cxy; // process owner cluster 153 lpid_t owner_lpid; // local process identifier 154 xptr_t root_xp; // extended pointer on root of xlist of process copies 155 xptr_t lock_xp; // extended pointer on remote_spinlock protecting this list 156 xptr_t iter_xp; // iterator for process copies list 157 xptr_t process_xp; // local pointer on process copy 158 cxy_t process_cxy; // cluster of process copy 159 process_t * process_ptr; // local pointer on process copy 160 error_t error; 161 162 // get local pointer on local cluster manager 163 cluster_t * cluster = LOCAL_CLUSTER; 164 165 // get owner process cluster and lpid 166 owner_cxy = CXY_FROM_PID( pid ); 167 owner_lpid = LPID_FROM_PID( pid ); 168 169 // get extended pointers on copies root and lock 170 root_xp = XPTR( owner_cxy , &cluster->copies_root[lpid] ); 171 lock_xp = XPTR( owner_cxy , &cluster->copies_lock[lpid] ); 172 173 // take the lock protecting the copies 174 remote_spinlock_lock( lock_xp ); 175 176 // TODO the loop below sequencialize the RPCs 177 // they could be pipelined... 178 179 // traverse the list of copies 180 XLIST_FOREACH( root_xp , iter_xp ) 181 { 182 process_xp = XLIST_ELEMENT( iter_xp , process_t , copies_list ); 183 process_cxy = GET_CXY( process_xp ); 184 process_ptr = (process_t *)GET_PTR( process_xp ); 185 186 if( process_xy == local_cxy ) // process copy is local 187 { 188 error = signal_rise( process_ptr , sig ); 189 } 190 else // process copy is remote 191 { 192 rpc_signal_rise_client( process_cxy , process_ptr , sig ); 193 } 194 } 195 196 return 0; 197 } 198 199 //////////////////////////////////// 200 void signal_notify( thread_s * this) 201 { 202 register uint32_t sig_state; 203 register uint32_t sig; 204 register struct sig_mgr_s *sig_mgr; 205 uint32_t irq_state; 206 207 sig_state = this->info.sig_state & this->info.sig_mask; 87 sig_state = this->signals; 208 88 sig = 0; 209 89 … … 242 122 } 243 123 } 124 */ -
trunk/kernel/kern/signal.h
r16 r23 4 4 * Author Ghassan Almaless (2008,2009,2010,2011,2012) 5 5 * Mohamed Lamine Karaoui (2015) 6 * Alain Greiner (2016 )6 * Alain Greiner (2016,2017) 7 7 * 8 8 * Copyright (c) UPMC Sorbonne Universites … … 33 33 #define SIG_ERROR -1L 34 34 35 #define SIGHUP 1 /*! hangup */36 #define SIGINT 2 /*! interrupt */37 #define SIGQUIT 3 /*! quit */38 #define SIGILL 4 /*! illegal instruction (not reset when caught) */39 #define SIGTRAP 5 /*! trace trap (not reset when caught) */40 #define SIGIOT 6 /*! IOT instruction */41 #define SIGABRT 6 /*! used by abort, replace SIGIOT in the future */42 #define SIGEMT 7 /*! EMT instruction */43 #define SIGFPE 8 /*! floating point exception */44 #define SIGKILL 9 /*! kill (cannot be caught or ignored) */45 #define SIGBUS 10 /*! bus error */46 #define SIGSEGV 11 /*! segmentation violation */47 #define SIGSYS 12 /*! bad argument to system call */48 #define SIGPIPE 13 /*! write on a pipe with no one to read it */49 #define SIGALRM 14 /*! alarm clock */50 #define SIGTERM 15 /*! software termination signal from kill */51 #define SIGURG 16 /*! urgent condition on IO channel */52 #define SIGSTOP 17 /*! sendable stop signal not from tty */53 #define SIGTSTP 18 /*! stop signal from tty */54 #define SIGCONT 19 /*! continue a stopped process */55 #define SIGCHLD 20 /*! to parent on child stop or exit */56 #define SIGCLD 20 /*! System V name for SIGCHLD */57 #define SIGTTIN 21 /*! to readers pgrp upon background tty read */58 #define SIGTTOU 22 /*! like TTIN for output if (tp->t_local<OSTOP) */59 #define SIGIO 23 /*! input/output possible signal */60 #define SIGPOLL SIGIO /*! System V name for SIGIO */61 #define SIGXCPU 24 /*! exceeded CPU time limit */62 #define SIGXFSZ 25 /*! exceeded file size limit */63 #define SIGVTALRM 26 /*! virtual time alarm */64 #define SIGPROF 27 /*! profiling time alarm */65 #define SIGWINCH 28 /*! window changed */66 #define SIGLOST 29 /*! resource lost (eg, record-lock lost) */67 #define SIGUSR1 30 /*! user defined signal 1 */68 #define SIGUSR2 31 /*! user defined signal 2 */69 #define SIG_NR 32 /*! signal 0 implied */35 #define SIGHUP 1 /*! hangup */ 36 #define SIGINT 2 /*! interrupt */ 37 #define SIGQUIT 3 /*! quit */ 38 #define SIGILL 4 /*! illegal instruction (not reset when caught) */ 39 #define SIGTRAP 5 /*! trace trap (not reset when caught) */ 40 #define SIGIOT 6 /*! IOT instruction */ 41 #define SIGABRT 6 /*! used by abort, replace SIGIOT in the future */ 42 #define SIGEMT 7 /*! EMT instruction */ 43 #define SIGFPE 8 /*! floating point exception */ 44 #define SIGKILL 9 /*! kill (cannot be caught or ignored) */ 45 #define SIGBUS 10 /*! bus error */ 46 #define SIGSEGV 11 /*! segmentation violation */ 47 #define SIGSYS 12 /*! bad argument to system call */ 48 #define SIGPIPE 13 /*! write on a pipe with no one to read it */ 49 #define SIGALRM 14 /*! alarm clock */ 50 #define SIGTERM 15 /*! software termination signal from kill */ 51 #define SIGURG 16 /*! urgent condition on IO channel */ 52 #define SIGSTOP 17 /*! sendable stop signal not from tty */ 53 #define SIGTSTP 18 /*! stop signal from tty */ 54 #define SIGCONT 19 /*! continue a stopped process */ 55 #define SIGCHLD 20 /*! to parent on child stop or exit */ 56 #define SIGCLD 20 /*! System V name for SIGCHLD */ 57 #define SIGTTIN 21 /*! to readers pgrp upon background tty read */ 58 #define SIGTTOU 22 /*! like TTIN for output if (tp->t_local<OSTOP) */ 59 #define SIGIO 23 /*! input/output possible signal */ 60 #define SIGPOLL SIGIO /*! System V name for SIGIO */ 61 #define SIGXCPU 24 /*! exceeded CPU time limit */ 62 #define SIGXFSZ 25 /*! exceeded file size limit */ 63 #define SIGVTALRM 26 /*! virtual time alarm */ 64 #define SIGPROF 27 /*! profiling time alarm */ 65 #define SIGWINCH 28 /*! window changed */ 66 #define SIGLOST 29 /*! resource lost (eg, record-lock lost) */ 67 #define SIGUSR1 30 /*! user defined signal 1 */ 68 #define SIGUSR2 31 /*! user defined signal 2 */ 69 #define SIG_NR 32 /*! signal 0 implied */ 70 70 71 71 #define SIG_DEFAULT_MASK 0xFFEEFFFF … … 81 81 82 82 /******************************************************************************************* 83 * This structure ... 83 * This structure ... TODO 84 84 ******************************************************************************************/ 85 85 … … 104 104 105 105 /******************************************************************************************* 106 * This structure ... 106 * This structure ... TODO 107 107 ******************************************************************************************/ 108 108 … … 122 122 123 123 /******************************************************************************************* 124 * This structure TODO124 * This structure ... TODO 125 125 ******************************************************************************************/ 126 126 … … 132 132 sig_mgr_t; 133 133 134 135 134 /******************************************************************************************* 136 * This function TODO 137 ******************************************************************************************/ 138 int sys_signal ( uint32_t sig, 139 sa_handler_t * handler ); 140 141 /******************************************************************************************* 142 * This function TODO 135 * This function ... TODO 143 136 ******************************************************************************************/ 144 137 int sys_sigreturn_setup( void * sigreturn_func ); 145 138 146 /*******************************************************************************************147 * This function register the signal <sig> in the bit_vector of all threads of a given148 * process identified by its <pid>, in all clusters containing threads for this process.149 * It can be executed by any thread running in any cluster, as this function uses150 * remote access to traverse the list of process copies, and the RPC_RISE_SIGNAL151 * to deliver the signal to all involved clusters.152 * The list of process copies is rooted in the owner cluster.153 ******************************************************************************************/154 int sys_kill( pid_t pid,155 uint32_t sig );156 139 157 140 /******************************************************************************************* 158 * This function TODO141 * This function ... TODO 159 142 ******************************************************************************************/ 160 error_tsignal_manager_init( struct process_s * process );143 void signal_manager_init( struct process_s * process ); 161 144 162 145 /******************************************************************************************* … … 165 148 * It must be executed by a thread running in the same cluster as the target threads 166 149 * (can be a local thread or a RPC thread). 150 ******************************************************************************************* 151 * @ process : local pointer on local target process. 152 * @ sig_id : signal type. 167 153 ******************************************************************************************/ 168 error_tsignal_rise( struct process_s * process,169 uint32_t sig);154 void signal_rise( struct process_s * process, 155 uint32_t sig_id ); 170 156 171 157 /******************************************************************************************* -
trunk/kernel/kern/thread.c
r16 r23 3 3 * 4 4 * Author Ghassan Almaless (2008,2009,2010,2011,2012) 5 * Mohamed Lamine Karaoui (2015) 6 * Alain Greiner (2016) 5 * Alain Greiner (2016,2017) 7 6 * 8 7 * Copyright (c) UPMC Sorbonne Universites … … 74 73 static thread_t * thread_alloc() 75 74 { 76 page_t * page; 77 kmem_req_t req; 75 page_t * page; // pointer on page descriptor containing thread descriptor 76 kmem_req_t req; // kmem request 78 77 79 78 // allocates memory for thread descriptor + kernel stack … … 84 83 85 84 // return pointer on new thread descriptor 86 if( page == NULL ) 87 { 88 printk("\n[ERROR] in %s : no memory for thread descriptor\n", __FUNCTION__ ); 89 return NULL; 90 } 91 else 92 { 93 return (thread_t *)ppm_page2base( page ); 94 } 95 } // end thread_alloc() 85 if( page == NULL ) return NULL; 86 else return (thread_t *)ppm_page2base( page ); 87 } 88 89 ///////////////////////////////////////////////////////////////////////////////////// 90 // This static function releases the physical memory for a thread descriptor. 91 // It can be called by the three functions: 92 // - thread_user_create() 93 // - thread_user_fork() 94 // - thread_kernel_create() 95 ///////////////////////////////////////////////////////////////////////////////////// 96 // @ thread : pointer on thread descriptor. 97 ///////////////////////////////////////////////////////////////////////////////////// 98 static void thread_release( thread_t * thread ) 99 { 100 kmem_req_t req; 101 102 req.type = KMEM_PAGE; 103 req.ptr = ppm_base2page( thread ); 104 kmem_free( &req ); 105 } 96 106 97 107 ///////////////////////////////////////////////////////////////////////////////////// … … 194 204 195 205 ///////////////////////////////////////////////////////// 196 error_t thread_user_create( thread_t ** new_thread, 206 error_t thread_user_create( pid_t pid, 207 void * start_func, 208 void * start_arg, 197 209 pthread_attr_t * attr, 198 intptr_t u_stack_base, 199 uint32_t u_stack_size ) 210 thread_t ** new_thread ) 200 211 { 201 212 error_t error; … … 203 214 process_t * process; // pointer to local process descriptor 204 215 lid_t core_lid; // selected core local index 205 kmem_req_t req; // kmem request (for release) 206 207 thread_dmsg("\n[INFO] %s : enters\n", __FUNCTION__ ); 208 209 cluster_t * local_cluster = LOCAL_CLUSTER; 216 vseg_t * vseg; // stack vseg 217 218 thread_dmsg("\n[INFO] %s : enters for process %x\n", __FUNCTION__ , pid ); 219 220 // get process descriptor local copy 221 process = process_get_local_copy( pid ); 222 223 if( process == NULL ) 224 { 225 printk("\n[ERROR] in %s : cannot get process descriptor %x\n", 226 __FUNCTION__ , pid ); 227 return ENOMEM; 228 } 210 229 211 230 // select a target core in local cluster 212 if( attr-> flags & PT_FLAG_CORE_DEFINED ) core_lid = attr->lid;213 else core_lid = cluster_select_local_core();231 if( attr->attributes & PT_ATTR_CORE_DEFINED ) core_lid = attr->lid; 232 else core_lid = cluster_select_local_core(); 214 233 215 234 // check core local index 216 if( core_lid >= local_cluster->cores_nr ) return EINVAL; 217 218 // get process descriptor local copy 219 process = process_get_local_copy( attr->pid ); 220 if( process == NULL ) return ENOMEM; 235 if( core_lid >= LOCAL_CLUSTER->cores_nr ) 236 { 237 printk("\n[ERROR] in %s : illegal core index attribute = %d\n", 238 __FUNCTION__ , core_lid ); 239 240 return EINVAL; 241 } 242 243 // allocate a stack from local VMM 244 vseg = vmm_create_vseg( process, 0 , 0 , VSEG_TYPE_STACK ); 245 246 if( vseg == NULL ); 247 { 248 printk("\n[ERROR] in %s : cannot create stack vseg\n", __FUNCTION__ ); 249 return ENOMEM; 250 } 221 251 222 252 // allocates memory tor thread descriptor 223 253 thread = thread_alloc(); 224 254 225 if( thread == NULL ) return ENOMEM; 255 if( thread == NULL ) 256 { 257 printk("\n[ERROR] in %s : cannot create new thread\n", __FUNCTION__ ); 258 vmm_remove_vseg( vseg ); 259 return ENOMEM; 260 } 226 261 227 262 // initializes thread descriptor … … 229 264 process, 230 265 THREAD_USER, 231 attr->entry_func,232 attr->entry_args,266 start_func, 267 start_arg, 233 268 core_lid, 234 u_stack_base,235 u_stack_size);236 237 if( error ) // release allocated memory for thread descriptor238 { 239 req.type = KMEM_PAGE;240 req.ptr = ppm_base2page( thread);241 kmem_free( &req);269 vseg->min, 270 vseg->max - vseg->min ); 271 272 if( error ) 273 { 274 printk("\n[ERROR] in %s : cannot initialize new thread\n", __FUNCTION__ ); 275 vmm_remove_vseg( vseg ); 276 thread_release( thread ); 242 277 return EINVAL; 243 278 } … … 247 282 248 283 // set DETACHED flag if required 249 if( attr-> flags & PT_FLAG_DETACH ) thread->flags |= THREAD_FLAG_DETACHED;284 if( attr->attributes & PT_ATTR_DETACH ) thread->flags |= THREAD_FLAG_DETACHED; 250 285 251 286 // allocate & initialise CPU context 252 287 error = hal_cpu_context_create( thread ); 253 if( error ) return ENOMEM; 288 289 if( error ) 290 { 291 printk("\n[ERROR] in %s : cannot create CPU context\n", __FUNCTION__ ); 292 vmm_remove_vseg( vseg ); 293 thread_release( thread ); 294 return ENOMEM; 295 } 254 296 255 297 // allocate & initialise FPU context 256 298 error = hal_fpu_context_create( thread ); 257 if( error ) return ENOMEM; 258 299 300 if( error ) 301 { 302 printk("\n[ERROR] in %s : cannot create FPU context\n", __FUNCTION__ ); 303 vmm_remove_vseg( vseg ); 304 thread_release( thread ); 305 return ENOMEM; 306 } 307 259 308 thread_dmsg("\n[INFO] %s : exit / trdid = %x / process %x / core = %d\n", 260 309 __FUNCTION__ , thread->trdid , process->pid , core_lid ); … … 266 315 267 316 268 ///////////////////////////////////////////////// 269 error_t thread_user_fork( thread_t ** new_thread, 270 process_t * process, 271 intptr_t u_stack_base, 272 uint32_t u_stack_size ) 317 ////////////////////////////////////////////// 318 error_t thread_user_fork( process_t * process, 319 thread_t ** new_thread ) 273 320 { 274 321 error_t error; 275 322 thread_t * thread; // pointer on new thread descriptor 276 323 lid_t core_lid; // selected core local index 277 kmem_req_t req; // kmem request (for release)324 vseg_t * vseg; // stack vseg 278 325 279 326 thread_dmsg("\n[INFO] %s : enters\n", __FUNCTION__ ); 327 328 // allocate a stack from local VMM 329 vseg = vmm_create_vseg( process, 0 , 0 , VSEG_TYPE_STACK ); 330 331 if( vseg == NULL ); 332 { 333 printk("\n[ERROR] in %s : cannot create stack vseg\n", __FUNCTION__ ); 334 return ENOMEM; 335 } 280 336 281 337 // select a target core in local cluster … … 288 344 thread = thread_alloc(); 289 345 290 if( thread == NULL ) return ENOMEM; 346 if( thread == NULL ) 347 { 348 printk("\n[ERROR] in %s : cannot allocate new thread\n", __FUNCTION__ ); 349 vmm_remove_vseg( vseg ); 350 return ENOMEM; 351 } 291 352 292 353 // initializes thread descriptor … … 297 358 this->entry_args, 298 359 core_lid, 299 u_stack_base,300 u_stack_size);301 302 if( error ) // release allocated memory for thread descriptor303 { 304 req.type = KMEM_PAGE;305 req.ptr = ppm_base2page( thread);306 kmem_free( &req);360 vseg->min, 361 vseg->max - vseg->min ); 362 363 if( error ) 364 { 365 printk("\n[ERROR] in %s : cannot initialize new thread\n", __FUNCTION__ ); 366 vmm_remove_vseg( vseg ); 367 thread_release( thread ); 307 368 return EINVAL; 308 369 } … … 313 374 // allocate & initialise CPU context from calling thread 314 375 error = hal_cpu_context_copy( thread , this ); 315 if( error ) return ENOMEM; 376 377 if( error ) 378 { 379 printk("\n[ERROR] in %s : cannot create CPU context\n", __FUNCTION__ ); 380 vmm_remove_vseg( vseg ); 381 thread_release( thread ); 382 return ENOMEM; 383 } 316 384 317 385 // allocate & initialise FPU context from calling thread 318 386 error = hal_fpu_context_copy( thread , this ); 319 if( error ) return ENOMEM; 320 321 thread_dmsg("INFO : %s thread %x for process %x on core %d in cluster %x\n", 387 388 if( error ) 389 { 390 printk("\n[ERROR] in %s : cannot create CPU context\n", __FUNCTION__ ); 391 vmm_remove_vseg( vseg ); 392 thread_release( thread ); 393 return ENOMEM; 394 } 395 396 thread_dmsg("\n[INFO] %s : exit / thread %x for process %x on core %d in cluster %x\n", 322 397 __FUNCTION__, thread->trdid, process->pid, core_lid, local_cxy ); 323 398 … … 473 548 spinlock_unlock( &process->th_lock ); 474 549 550 // update local DQDT 551 dqdt_local_update_threads( -1 ); 552 475 553 // invalidate thread descriptor 476 554 thread->signature = 0; 477 555 478 556 // release memory for thread descriptor 479 kmem_req_t req; 480 req.type = KMEM_PAGE; 481 req.ptr = ppm_base2page( thread ); 482 kmem_free(&req); 557 thread_release( thread ); 483 558 484 559 tm_end = hal_time_stamp(); … … 706 781 707 782 //////////////////////////////////////////////// 708 void thread_signals_handle r( thread_t * thread )783 void thread_signals_handle( thread_t * thread ) 709 784 { 710 785 // TODO … … 712 787 } 713 788 714 789 ///////////////////////////////////// 790 xptr_t thread_get_xptr( pid_t pid, 791 trdid_t trdid ) 792 { 793 cxy_t target_cxy; // target thread cluster identifier 794 ltid_t target_thread_ltid; // target thread local index 795 thread_t * target_thread_ptr; // target thread local pointer 796 xptr_t target_process_xp; // extended pointer on target process descriptor 797 process_t * target_process_ptr; // local pointer on target process descriptor 798 pid_t target_process_pid; // target process identifier 799 xlist_entry_t root; // root of list of process in target cluster 800 xptr_t lock_xp; // extended pointer on lock protecting this list 801 802 // get target cluster identifier and local thread identifier 803 target_cxy = CXY_FROM_TRDID( trdid ); 804 target_thread_ltid = LTID_FROM_TRDID( trdid ); 805 806 // get root of list of process descriptors in target cluster 807 hal_remote_memcpy( XPTR( local_cxy , &root ), 808 XPTR( target_cxy , &LOCAL_CLUSTER->pmgr.local_root ), 809 sizeof(xlist_entry_t) ); 810 811 // get extended pointer on lock protecting the list of processes 812 lock_xp = XPTR( target_cxy , &LOCAL_CLUSTER->pmgr.local_lock ); 813 814 // take the lock protecting the list of processes in target cluster 815 remote_spinlock_lock( lock_xp ); 816 817 // loop on list of process in target cluster to find the PID process 818 xptr_t iter; 819 bool_t found = false; 820 XLIST_FOREACH( XPTR( target_cxy , &LOCAL_CLUSTER->pmgr.local_root ) , iter ) 821 { 822 target_process_xp = XLIST_ELEMENT( iter , process_t , local_list ); 823 target_process_ptr = (process_t *)GET_PTR( target_process_xp ); 824 target_process_pid = hal_remote_lw( XPTR( target_cxy , &target_process_ptr->pid ) ); 825 if( target_process_pid == pid ) 826 { 827 found = true; 828 break; 829 } 830 } 831 832 // release the lock protecting the list of processes in target cluster 833 remote_spinlock_unlock( lock_xp ); 834 835 // check target thread found 836 if( found == false ) 837 { 838 return XPTR_NULL; 839 } 840 841 // get target thread local pointer 842 xptr_t xp = XPTR( target_cxy , &target_process_ptr->th_tbl[target_thread_ltid] ); 843 target_thread_ptr = (thread_t *)hal_remote_lpt( xp ); 844 845 if( target_thread_ptr == NULL ) 846 { 847 return XPTR_NULL; 848 } 849 850 return XPTR( target_cxy , target_thread_ptr ); 851 852 } // end thread_get_xptr() 853 -
trunk/kernel/kern/thread.h
r16 r23 3 3 * 4 4 * Author Ghassan Almaless (2008,2009,2010,2011,2012) 5 * Mohamed Lamine Karaoui (2015)6 5 * Alain Greiner (2016) 7 6 * … … 43 42 44 43 /*************************************************************************************** 45 * This defines the various pthread_attr_t flags. 46 **************************************************************************************/ 47 48 #define PT_FLAG_DETACH 0x001 // user defined not joinable 49 #define PT_FLAG_CLUSTER_DEFINED 0x002 // user defined target cluster 50 #define PT_FLAG_CORE_DEFINED 0x004 // user defined core cluster 51 52 /*************************************************************************************** 53 * This structure defines the input argument of the pthread_create() system call. 54 * It contains all informations required to initialize an user thread, and is passed 55 * as input argument to the thread_user_create() function. 56 * It is partly set by the kernel, partly set by the user application itself, 57 * using the pthread_attr_***() functions. 44 * These macros are used to compose or decompose global thread identifier (TRDID) 45 * to or from cluster identifier / local thread index (CXY , LTID) 46 **************************************************************************************/ 47 48 #define LTID_FROM_TRDID( trdid ) (ltid_t)(trdid & 0x0000FFFF) 49 #define CXY_FROM_TRDID( trdid ) (cxy_t)(trdid >> 16) 50 #define TRDID( cxy , ltid ) (trdid_t)((cxy << 16) | ltid ) 51 52 /*************************************************************************************** 53 * This defines the various pthread_attr_t attributes bit-vector. 54 **************************************************************************************/ 55 56 /*************************************************************************************** 57 * This opaque structure contains the user defined attributes for an user thread. 58 * It is passed as input argument to the thread_user_create() function. 59 * It is set by the user application itself, using the pthread_attr_***() functions. 60 * The currently supported attributes are defined below. 58 61 **************************************************************************************/ 59 62 60 63 typedef struct pthread_attr_s 61 64 { 62 pid_t pid; /*! owner process identifier */ 63 void * entry_func; /*! pointer on entry function */ 64 void * entry_args; /*! pointer on entry function arguments */ 65 uint32_t flags; /*! pthread flags (entirely user specified) */ 66 cxy_t cxy; /*! target cluster (can be user specified) */ 67 lid_t lid; /*! target core (can be user specified) */ 65 uint32_t attributes; /*! user defined attributes bit vector */ 66 cxy_t cxy; /*! target cluster identifier */ 67 lid_t lid; /*! target core index */ 68 68 } 69 69 pthread_attr_t; 70 70 71 typedef enum 72 { 73 PT_ATTR_DETACH = 0x0001, /*! user defined not joinable */ 74 PT_ATTR_CLUSTER_DEFINED = 0x0002, /*! user defined target cluster */ 75 PT_ATTR_CORE_DEFINED = 0x0004, /*! user defined core index in cluster */ 76 } 77 pt_attributes_t; 71 78 72 79 /*************************************************************************************** … … 86 93 87 94 /*************************************************************************************** 88 * This defines the masks associated to the thread flags.95 * This defines the thread flags bit-vector. 89 96 **************************************************************************************/ 90 97 91 98 #define THREAD_FLAG_LOADABLE 0x0001 /*! This thread has not been executed yet */ 92 #define THREAD_FLAG_DETACHED 0x0002 /*! This user thread is detached from parent */ 99 #define THREAD_FLAG_DETACHED 0x0002 /*! This thread is detached from parent */ 100 #define THREAD_FLAG_JOIN 0x0004 /*! Parent thread made a join */ 101 #define THREAD_FLAG_EXIT 0x0008 /*! This thread made an exit */ 93 102 94 103 /*************************************************************************************** … … 102 111 **************************************************************************************/ 103 112 104 #define THREAD_BLOCKED_GLOBAL 0x0001 /*! thread global blocking*/113 #define THREAD_BLOCKED_GLOBAL 0x0001 /*! thread desactivated / wait activation */ 105 114 #define THREAD_BLOCKED_IO 0x0002 /*! thread wait IO operation completion */ 106 115 #define THREAD_BLOCKED_MAPPER 0x0004 /*! thread wait mapper */ 107 #define THREAD_BLOCKED_EXIT 0x0010 /*! thread requested exit */ 116 #define THREAD_BLOCKED_JOIN 0x0008 /*! thread blocked in join / wait exit */ 117 #define THREAD_BLOCKED_EXIT 0x0010 /*! thread blocked in exit / wait join i */ 108 118 #define THREAD_BLOCKED_KILL 0x0020 /*! thread received kill signal */ 109 119 #define THREAD_BLOCKED_SEM 0x0040 /*! thread wait semaphore */ 110 120 #define THREAD_BLOCKED_PAGE 0x0080 /*! thread wait page access */ 121 #define THREAD_BLOCKED_USERSYNC 0x0100 /*! thread wait POSIX (cond/mutex/barrier) */ 122 111 123 #define THREAD_BLOCKED_IDLE 0x1000 /*! thread RPC wait activation */ 112 124 #define THREAD_BLOCKED_DEV_QUEUE 0x2000 /*! thread DEV wait queue */ … … 141 153 * that is returned by the kernel to the user: 142 154 * - The TRDID 16 LSB bits contain the LTID (Local Thread Index). 143 * - The TRDID 16 MSB bits contain the owner cluster CXY.155 * - The TRDID 16 MSB bits contain the CXY of cluster containing the thread. 144 156 * - The LTID is used to index the th_tbl[] array in the local process descriptor. 145 157 * This TRDID is computed by the process_register_thread() function, when the user … … 155 167 void * fpu_context; /*! used for dynamic FPU allocation */ 156 168 157 uint32_t trdid; /*! thread index ( in THTBL) */169 uint32_t trdid; /*! thread index (cxy.ltid) */ 158 170 thread_type_t type; /*! thread type */ 159 171 uint32_t quantum; /*! number of clock ticks given to thread */ … … 162 174 core_t * core; /*! pointer to the owner core */ 163 175 process_t * process; /*! pointer on local process descriptor */ 164 176 xptr_t parent; /*! extended pointer on parent thread */ 177 178 void * exit_value; /*! exit_value used in case of join */ 179 165 180 uint32_t local_locks; /*! number of local locks owned by thread */ 166 181 list_entry_t locks_root; /*! root of local locks list */ 182 183 remote_spinlock_t * flags_lock; /*! lock protecting the flags */ 167 184 168 185 uint32_t remote_locks; /*! number of local locks owned by thread */ … … 182 199 183 200 error_t errno; /*! errno value set by last system call */ 201 uint32_t utls; /*! user thread local storage */ 184 202 185 203 bool_t fork_user; /*! user defined placement for next fork() */ … … 231 249 /*************************************************************************************** 232 250 * This function allocates memory for an user thread descriptor in the local cluster, 233 * and initializes it from information contained in the "attr" argument.234 * It is used by the pthread_create system call, the CPU context is initialised from235 * scratch, and the "loadable" field is set.236 * The new thread is attached to the core specified in the "attr"argument.237 * It is registered in the local process descriptor for the process specified in "attr".251 * and initializes it from information contained in the arguments. 252 * It is used by the "pthread_create" system call. 253 * The CPU context is initialised from scratch, and the "loadable" field is set. 254 * The new thread is attached to the core specified in the <attr> argument. 255 * It is registered in the local process descriptor specified by the <pid> argument. 238 256 * The thread descriptor pointer is returned to allow the parent thread to register it 239 257 * in its children list. 240 * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start. 241 *************************************************************************************** 242 * @ new_thread : address of buffer for new thread descriptor pointer. 258 * The THREAD_BLOCKED_GLOBAL bit is set => the thread must be activated to start. 259 *************************************************************************************** 260 * @ pid : process identifier. 261 * @ start_func : pointer on entry function. 262 * @ start_args : pointer on function argument (can be NULL). 243 263 * @ attr : pointer on pthread attributes descriptor. 244 * @ u_stack_base : actual user stack size. 245 * @ u_stack_size : actual user stack base. 264 * @ new_thread : [out] address of buffer for new thread descriptor pointer. 246 265 * @ returns 0 if success / returns ENOMEM if error. 247 266 **************************************************************************************/ 248 error_t thread_user_create( thread_t ** new_thread, 267 error_t thread_user_create( pid_t pid, 268 void * start_func, 269 void * start_arg, 249 270 pthread_attr_t * attr, 250 intptr_t u_stack_base, 251 uint32_t u_stack_size ); 271 thread_t ** new_thread ); 252 272 253 273 /*************************************************************************************** … … 261 281 * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start. 262 282 *************************************************************************************** 263 * @ new_thread : address of buffer for new thread descriptor pointer.264 283 * @ process : local pointer on owner process descriptor. 265 * @ u_stack_base : actual user stack size. 266 * @ u_stack_size : actual user stack base. 284 * @ new_thread : [out] address of buffer for new thread descriptor pointer. 267 285 * @ returns 0 if success / returns ENOMEM if error. 268 286 **************************************************************************************/ 269 error_t thread_user_fork( thread_t ** new_thread, 270 process_t * process, 271 intptr_t u_stack_base, 272 uint32_t u_stack_size ); 287 error_t thread_user_fork( process_t * process, 288 thread_t ** new_thread ); 273 289 274 290 /*************************************************************************************** … … 343 359 * This function removes an user thread from the parent thread global list 344 360 * of attached children threads. 345 * It does take the lock, as this function can be called by the child thread.346 * In this case, it uses the extended pointer on the parent thread contained347 * in the pthread_attr_t embedded in the child thread descriptor.348 361 *************************************************************************************** 349 362 * @ xp_parent : extended pointer on the parent thread descriptor. … … 352 365 void thread_child_parent_unlink( xptr_t xp_parent, 353 366 xptr_t xp_child ); 354 355 367 356 368 /*************************************************************************************** … … 475 487 void thread_signals_handle( thread_t * thread ); 476 488 489 /*************************************************************************************** 490 * This function returns the extended pointer on a thread descriptor identified 491 * by its thread identifier, and process identifier. 492 * It can be called by any thread running in any cluster. 493 *************************************************************************************** 494 * @ pid : process identifier. 495 * @ trdid : thread identifier. 496 * @ return the extended pointer if thread found / return XPTR_NULL if not found. 497 **************************************************************************************/ 498 xptr_t thread_get_xptr( pid_t pid, 499 trdid_t trdid ); 477 500 478 501 -
trunk/kernel/kern/time.h
r1 r23 1 1 /* 2 * time.h : thread time related management2 * time.h - Structure used by gettimeofday. 3 3 * 4 * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless 5 * Copyright (c) 2011,2012 UPMC Sorbonne Universites 4 * author Alain Greiner (2016,2017) 6 5 * 7 * This file is part of ALMOS-kernel.6 * Copyright (c) UPMC Sorbonne Universites 8 7 * 9 * ALMOS-kernel is free software; you can redistribute it and/or modify it 8 * This file is part of ALMOS-MKH. 9 * 10 * ALMOS-MKH is free software; you can redistribute it and/or modify it 10 11 * under the terms of the GNU General Public License as published by 11 12 * the Free Software Foundation; version 2.0 of the License. 12 13 * 13 * ALMOS- kernelis distributed in the hope that it will be useful, but14 * ALMOS-MKH is distributed in the hope that it will be useful, but 14 15 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU … … 17 18 * 18 19 * You should have received a copy of the GNU General Public License 19 * along with ALMOS- kernel; if not, write to the Free Software Foundation,20 * along with ALMOS-MKH; if not, write to the Free Software Foundation, 20 21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 22 */ … … 24 25 #define _TIME_H_ 25 26 26 #include <types.h> 27 #include <list.h> 28 #include <device.h> 27 #include <hal_types.h> 29 28 30 struct event_s;31 29 32 struct alarm_info_s30 struct timeval 33 31 { 34 uint_t signature; 35 36 /* Public members */ 37 struct event_s *event; 38 39 /* Private members */ 40 uint_t tm_wakeup; 41 struct list_entry list; 32 uint32_t tv_sec; /* secondes */ 33 uint32_t tv_usec; /* microsecondes */ 42 34 }; 43 35 44 struct alarm_s 45 { 46 struct list_entry wait_queue; 47 }; 48 49 50 struct timeb { 51 time_t time; 52 unsigned short millitm; 53 short timezone; 54 short dstflag; 55 }; 56 57 struct timeval { 58 clock_t tv_sec; /* secondes */ 59 clock_t tv_usec; /* microsecondes */ 60 }; 61 62 struct timezone { 36 struct timezone 37 { 63 38 int tz_minuteswest; /* minutes west of Greenwich */ 64 39 int tz_dsttime; /* type of DST correction */ 65 40 }; 66 41 67 68 struct tms69 {70 clock_t tms_utime; /* user time */71 clock_t tms_stime; /* system time */72 clock_t tms_cutime; /* user time of children */73 clock_t tms_cstime; /* system time of children */74 };75 76 77 error_t alarm_manager_init(struct alarm_s *alarm);78 error_t alarm_wait(struct alarm_info_s *info, uint_t msec);79 80 void alarm_clock(struct alarm_s *alarm, uint_t ticks_nr);81 82 int sys_clock (uint64_t *val);83 int sys_alarm (unsigned nb_sec);84 int sys_ftime (struct timeb *utime);85 int sys_times(struct tms *utms);86 int sys_gettimeofday(struct timeval *tv, struct timezone *tz);87 88 #if CONFIG_THREAD_TIME_STAT89 struct thread_s;90 inline void tm_sleep_compute(struct thread_s *thread);91 inline void tm_usr_compute(struct thread_s *thread);92 inline void tm_sys_compute(struct thread_s *thread);93 inline void tm_wait_compute(struct thread_s *thread);94 inline void tm_exit_compute(struct thread_s *thread);95 inline void tm_born_compute(struct thread_s *thread);96 inline void tm_create_compute(struct thread_s *thread);97 98 #else99 100 #define tm_sleep_compute(thread)101 #define tm_usr_compute(thread)102 #define tm_sys_compute(thread)103 #define tm_wait_compute(thread)104 #define tm_exit_compute(thread)105 #define tm_born_compute(thread)106 #define tm_create_compute(thread)107 108 #endif /* CONFIG_SCHED_STAT */109 110 42 #endif /* _TIME_H_ */
Note: See TracChangeset
for help on using the changeset viewer.