Changeset 619 for trunk/kernel/syscalls/sys_barrier.c
- Timestamp:
- Feb 12, 2019, 1:15:47 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_barrier.c
r581 r619 24 24 #include <hal_kernel_types.h> 25 25 #include <hal_special.h> 26 #include <hal_uspace.h> 26 27 #include <errno.h> 27 28 #include <thread.h> … … 43 44 44 45 ////////////////////////////////// 45 int sys_barrier( void *vaddr,46 int sys_barrier( intptr_t vaddr, 46 47 uint32_t operation, 47 uint32_t count ) 48 uint32_t count, 49 intptr_t attr ) 48 50 { 49 error_t error; 50 vseg_t * vseg; 51 52 thread_t * this = CURRENT_THREAD; 53 process_t * process = this->process; 51 error_t error; 52 vseg_t * vseg; 53 pthread_barrierattr_t k_attr; 54 55 thread_t * this = CURRENT_THREAD; 56 process_t * process = this->process; 54 57 55 58 #if DEBUG_SYS_BARRIER … … 58 61 tm_start = hal_get_cycles(); 59 62 if( DEBUG_SYS_BARRIER < tm_start ) 60 printk("\n[ DBG] %s : thread %x in process %x enterfor %s / count %d / cycle %d\n",61 __FUNCTION__, this->trdid, process->pid, sys_barrier_op_str(operation), count,63 printk("\n[%s] thread[%x,%x] enters for %s / count %d / cycle %d\n", 64 __FUNCTION__, process->pid, this->trdid, sys_barrier_op_str(operation), count, 62 65 (uint32_t)tm_start ); 63 66 #endif 64 67 65 68 // check vaddr in user vspace 66 error = vmm_get_vseg( process , (intptr_t)vaddr , &vseg ); 67 69 error = vmm_get_vseg( process , vaddr , &vseg ); 68 70 if( error ) 69 71 { … … 71 73 #if DEBUG_SYSCALLS_ERROR 72 74 printk("\n[ERROR] in %s : unmapped barrier %x / thread %x / process %x\n", 73 __FUNCTION__ , (intptr_t)vaddr , this->trdid , process->pid );75 __FUNCTION__ , vaddr , this->trdid , process->pid ); 74 76 vmm_display( process , false ); 75 77 #endif … … 84 86 case BARRIER_INIT: 85 87 { 86 error = remote_barrier_create( (intptr_t)vaddr , count ); 87 88 if( attr != 0 ) // QDT barrier required 89 { 90 error = vmm_get_vseg( process , attr , &vseg ); 91 if( error ) 92 { 93 94 #if DEBUG_SYSCALLS_ERROR 95 printk("\n[ERROR] in %s : unmapped barrier attributes %x / thread %x / process %x\n", 96 __FUNCTION__ , attr , this->trdid , process->pid ); 97 vmm_display( process , false ); 98 #endif 99 this->errno = EINVAL; 100 return -1; 101 } 102 103 // copy barrier attributes into kernel space 104 hal_copy_from_uspace( &k_attr , (void*)attr , sizeof(pthread_barrierattr_t) ); 105 106 if ( count != k_attr.x_size * k_attr.y_size *k_attr.nthreads ) 107 { 108 109 #if DEBUG_SYSCALLS_ERROR 110 printk("\n[ERROR] in %s : wrong arguments / count %d / x_size %d / y_size %d / nthreads %x\n", 111 __FUNCTION__, count, k_attr.x_size, k_attr.y_size, k_attr.nthreads ); 112 #endif 113 this->errno = EINVAL; 114 return -1; 115 } 116 117 118 // call relevant system function 119 error = generic_barrier_create( vaddr , count , &k_attr ); 120 } 121 else // simple barrier required 122 { 123 error = generic_barrier_create( vaddr , count , NULL ); 124 } 125 88 126 if( error ) 89 127 { … … 91 129 #if DEBUG_SYSCALLS_ERROR 92 130 printk("\n[ERROR] in %s : cannot create barrier %x / thread %x / process %x\n", 93 __FUNCTION__ , (intptr_t)vaddr , this->trdid , process->pid );131 __FUNCTION__ , vaddr , this->trdid , process->pid ); 94 132 #endif 95 this->errno = error;133 this->errno = ENOMEM; 96 134 return -1; 97 135 } … … 101 139 case BARRIER_WAIT: 102 140 { 103 xptr_t barrier_xp = remote_barrier_from_ident( (intptr_t)vaddr );141 xptr_t barrier_xp = generic_barrier_from_ident( vaddr ); 104 142 105 143 if( barrier_xp == XPTR_NULL ) // user error … … 115 153 else // success 116 154 { 117 remote_barrier_wait( barrier_xp );155 generic_barrier_wait( barrier_xp ); 118 156 } 119 157 break; … … 122 160 case BARRIER_DESTROY: 123 161 { 124 xptr_t barrier_xp = remote_barrier_from_ident( (intptr_t)vaddr );162 xptr_t barrier_xp = generic_barrier_from_ident( vaddr ); 125 163 126 164 if( barrier_xp == XPTR_NULL ) // user error … … 136 174 else // success 137 175 { 138 remote_barrier_destroy( barrier_xp );176 generic_barrier_destroy( barrier_xp ); 139 177 } 140 178 break; … … 149 187 tm_end = hal_get_cycles(); 150 188 if( DEBUG_SYS_BARRIER < tm_end ) 151 printk("\n[ DBG] %s : thread %x in process %xexit for %s / cost %d / cycle %d\n",152 __FUNCTION__, this->trdid, process->pid, sys_barrier_op_str(operation),189 printk("\n[%s] thread[%x,%x] exit for %s / cost %d / cycle %d\n", 190 __FUNCTION__, process->pid, this->trdid, sys_barrier_op_str(operation), 153 191 (uint32_t)(tm_end - tm_start), (uint32_t)tm_end ); 154 192 #endif
Note: See TracChangeset
for help on using the changeset viewer.