Changeset 440 for trunk/user
- Timestamp:
- May 3, 2018, 5:51:22 PM (7 years ago)
- Location:
- trunk/user
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/user/init/Makefile
r439 r440 4 4 5 5 -include ../../params-soft.mk 6 6 7 ifeq ($(ARCH_NAME),) 7 8 $(error Please define in ARCH_NAME parameter in params-soft.mk!) … … 10 11 OBJS = build/init.o 11 12 12 INCLUDES = -I. \13 -I../.. \14 -I$(LIBC_INCLUDE)/ \15 -I$(LIBPTHREAD_INCLUDE) \13 INCLUDES = -I. \ 14 -I../.. \ 15 -I$(LIBC_INCLUDE)/ \ 16 -I$(LIBPTHREAD_INCLUDE) 16 17 17 18 compile : dirs build/init.elf … … 28 29 29 30 clean: 30 rm -rf build/*.o build/*.elf build/*.o.txt31 rm -rf build/*.o build/*.elf build/*.txt 31 32 32 33 .PHONY: dirs clean -
trunk/user/init/init.c
r438 r440 7 7 // It uses the fork/exec syscalls to create N KSH child processes 8 8 // (one child process per user terminal). 9 // It includes the hard_config.h file to get th NB_TXT_CHANNELS parameter.10 //11 // TODO : Register the PIDs for all KSH[i] in a ksh_pid[] array.12 9 // Then calls the wait() function to block, and reactivate any child KSH process 13 10 // that has been deleted, using a new fork/exec. 11 // It includes the hard_config.h file to get th NB_TXT_CHANNELS parameter. 14 12 /////////////////////////////////////////////////////////////////////////////////////// 15 13 … … 19 17 #include <stdio.h> 20 18 #include <pthread.h> 19 20 #define DEBUG_INIT 1 21 22 // TODO make the cxy computation portable [AG] 23 #define CXY_FROM_XY( x , y ) ((x<<4) + y) 21 24 22 25 ////////// … … 43 46 { 44 47 // INIT display error message 45 snprintf( string , 64 , " INITcannot fork child[%d] => suicide" , i );48 snprintf( string , 64 , "[INIT] cannot fork child[%d] => suicide" , i ); 46 49 display_string( string ); 47 50 … … 58 61 // CHILD[i] display error message 59 62 snprintf( string , 64 , 60 " CHILD[%d] cannot exec KSH[%d] / ret_exec = %d" , i, i , ret_exec );63 "[INIT ERROR] CHILD[%d] cannot exec KSH / ret_exec = %d" , i , ret_exec ); 61 64 display_string( string ); 62 65 } … … 65 68 { 66 69 // INIT display CHILD[i] process PID 67 snprintf( string , 64 , " INITcreated KSH[%d] / pid = %x", i , ret_fork );70 snprintf( string , 64 , "[INIT] created KSH[%d] / pid = %x", i , ret_fork ); 68 71 display_string( string ); 69 72 … … 72 75 } 73 76 } 77 78 #if DEBUG_INIT 74 79 75 // INIT display processes and threads in clusters 0 & 1 76 display_cluster_processes( 0 ); 77 display_sched( 0 , 0 ); 78 display_cluster_processes( 1 ); 79 display_sched( 1 , 0 ); 80 unsigned int x_size; // number of clusters in a row 81 unsigned int y_size; // number of clusters in a column 82 unsigned int ncores; // number of cores per cluster 83 unsigned int x; // cluster x coordinate 84 unsigned int y; // cluster y coordinate 85 unsigned int cxy; // cluster identifier 86 unsigned int lid; // core local index 87 88 // get hardware config 89 get_config( &x_size , &y_size , &ncores ); 90 91 // INIT displays processes and threads in all clusters 92 for( x = 0 ; x < x_size ; x++ ) 93 { 94 for( y = 0 ; y < y_size ; y++ ) 95 { 96 cxy = CXY_FROM_XY( x , y ); 97 display_cluster_processes( cxy ); 98 for( lid = 0 ; lid < ncores ; lid++ ) 99 { 100 display_sched( cxy , lid ); 101 } 102 } 103 } 104 105 #endif 80 106 81 107 // This loop detects the termination of the KSH[i] processes, … … 89 115 { 90 116 // display string to report unexpected KSH process block 91 snprintf( string , 64 , " KSH process %x stopped => unblock it" , rcv_pid );117 snprintf( string , 64 , "[INIT] KSH process %x stopped => unblock it" , rcv_pid ); 92 118 display_string( string ); 93 119 94 // TODO : unblock KSH 120 // TODO : unblock KSH [AG] 95 121 96 122 } // end KSH stopped handling … … 99 125 { 100 126 // display string to report KSH process termination 101 snprintf( string , 64 , " KSH process %x terminated => recreate KSH", rcv_pid );127 snprintf( string , 64 , "[INIT] KSH process %x terminated => recreate", rcv_pid ); 102 128 display_string( string ); 103 129 … … 108 134 { 109 135 // INIT display error message 110 snprintf( string , 64 , " INITcannot fork child => suicide");136 snprintf( string , 64 , "[INIT ERROR] cannot fork child => suicide"); 111 137 display_string( string ); 112 138 … … 122 148 { 123 149 // CHILD display error message on TXT0 terminal 124 snprintf( string , 64 , " CHILD cannot exec KSH" );150 snprintf( string , 64 , "[INIT ERROR] CHILD cannot exec KSH" ); 125 151 display_string( string ); 126 152 } … … 129 155 { 130 156 // INIT display new CHILD process PID 131 snprintf( string , 64 , " INITforked CHILD / pid = %x", ret_fork );157 snprintf( string , 64 , "[INIT] forked CHILD / pid = %x", ret_fork ); 132 158 display_string( string ); 133 159 } 134 160 } // end KSH kill handling 135 161 136 // INIT wait a fixed delay 137 for( delay = 0 ; delay < 50000 ; delay++ ) asm volatile( "nop" ); 162 #if( DEBUG_INIT ) 138 163 139 // INIT display processes and threads in clusters 0 & 1 140 display_cluster_processes( 0 ); 141 display_sched( 0 , 0 ); 142 display_cluster_processes( 1 ); 143 display_sched( 1 , 0 ); 164 // INIT displays processes and threads in all clusters 165 for( x = 0 ; x < x_size ; x++ ) 166 { 167 for( y = 0 ; y < y_size ; y++ ) 168 { 169 cxy = CXY_FROM_XY( x , y ); 170 display_cluster_processes( cxy ); 171 for( lid = 0 ; lid < ncores ; lid++ ) 172 { 173 display_sched( cxy , lid ); 174 } 175 } 176 } 177 178 #endif 144 179 145 180 } // end while waiting KSH[i] termination -
trunk/user/ksh/Makefile
r439 r440 25 25 26 26 clean: 27 rm -rf build/*.o build/*.elf build/*. o.txt27 rm -rf build/*.o build/*.elf build/*.txt 28 28 29 29 .PHONY: dirs clean -
trunk/user/ksh/ksh.c
r437 r440 380 380 if( pid == 0 ) 381 381 { 382 printf(" error: ilegal pid format\n" );382 printf(" error: kernel process 0 cannot be killed\n" ); 383 383 } 384 384 385 385 if( kill( pid , SIGKILL ) ) 386 386 { 387 printf(" error: unable to kill process %x\n", pid );387 printf(" error: process %x cannot be killed\n", pid ); 388 388 } 389 389 } // end cmd_kill() … … 421 421 { 422 422 printf(" error: ksh process unable to fork\n"); 423 return; 423 424 } 424 425 else if (ret_fork == 0) // it is the CHILD process … … 433 434 { 434 435 printf(" error: new process unable to exec <%s>\n", pathname ); 435 exit(0);436 return; 436 437 } 437 438 } … … 445 446 if( rcv_pid == new_pid ) 446 447 { 447 printf("\n\n exit %s / status = %x\n\n", pathname, (status &0xFF) ); 448 printf("\n\n %s normal termination / status = %x\n\n", 449 pathname , (status &0xFF) ); 450 return; 448 451 } 449 452 else 450 453 { 451 printf("\n\n abnormal termination for %s \n\n", pathname ); 454 printf("\n\n %s abnormal termination / status = %x\n\n", 455 pathname , (status &0xFF) ); 456 return; 452 457 } 453 458 } 454 455 459 } // end cmd_load 456 460 … … 689 693 ptr = 0; 690 694 691 printf( " ~~~ shell ~~~\n\n" );695 printf( "\n\n~~~ shell ~~~\n\n" ); 692 696 693 697 // command buffer initialisation -
trunk/user/pgcd/Makefile
r439 r440 4 4 5 5 -include ../../params-soft.mk 6 6 7 ifeq ($(ARCH_NAME),) 7 8 $(error Please define in ARCH_NAME parameter in params-soft.mk!) … … 13 14 14 15 compile: dirs build/pgcd.elf 16 15 17 build/pgcd.elf : $(OBJS) pgcd.ld 16 18 $(LD) -o $@ -T pgcd.ld $(OBJS) -nostdlib -L$(LIBC) -lc … … 19 21 build/pgcd.o : pgcd.c 20 22 $(CC) $(INCLUDES) -L$(LIBC) $(CFLAGS) -c -o $@ $< 21 $(DU) -D $@ > $@.txt22 23 23 24 dirs: … … 25 26 26 27 clean: 27 rm -rf build/*.o build/*.elf build/*.o.txt28 rm -rf build/*.o build/*.elf build/*.txt 28 29 29 30 .PHONY: dirs clean -
trunk/user/sort/Makefile
r439 r440 4 4 5 5 -include ../../params-soft.mk 6 6 7 ifeq ($(ARCH_NAME),) 7 8 $(error Please define in ARCH_NAME parameter in params-soft.mk!) … … 13 14 14 15 compile: dirs build/sort.elf 16 15 17 build/sort.elf : $(OBJS) sort.ld 16 18 $(LD) -o $@ -T sort.ld $(OBJS) -nostdlib -L$(LIBC) -L$(LIBPTHREAD) -lc -lpthread … … 19 21 build/sort.o : sort.c 20 22 $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< 21 $(DU) -D $@ > $@.txt22 23 23 24 dirs: … … 25 26 26 27 clean: 27 rm -rf build/*.o build/*.elf build/*.o.txt28 rm -rf build/*.o build/*.elf build/*.txt 28 29 29 30 .PHONY: dirs clean -
trunk/user/sort/sort.c
r436 r440 27 27 #include <pthread.h> 28 28 29 #define ARRAY_LENGTH 0x100 // 256 values 30 #define VERBOSE 0 29 #define ARRAY_LENGTH 0x100 // 256 values 30 31 #define MAX_THREADS 1024 // 16 * 16 * 4 32 33 #define DISPLAY_ARRAY 0 34 #define DISPLAY_THREADS 1 31 35 32 36 /////////////////////////////////////////////////////// 33 37 // macros for fixed format cxy <=> (x,y) translation 38 // TODO these macros are only for TSAR architecture... 34 39 /////////////////////////////////////////////////////// 35 40 … … 61 66 pthread_barrier_t barrier; // synchronisation variables 62 67 68 pthread_attr_t attr[MAX_THREADS]; // thread attributes (one per thread) 69 args_t arg[MAX_THREADS]; // sort function arguments (one per thread) 63 70 64 71 //////////////////////////////////// … … 135 142 unsigned int i; 136 143 unsigned long long cycle; 144 unsigned int cxy; 145 unsigned int lid; 137 146 138 147 int * src_array = NULL; 139 148 int * dst_array = NULL; 149 150 // get core coordinates an date 151 get_core( &cxy , &lid ); 152 get_cycle( &cycle ); 140 153 141 154 unsigned int thread_uid = ptr->thread_uid; … … 143 156 unsigned int main_uid = ptr->main_uid; 144 157 158 printf("\n### core[%x,%d] enter sort : threads %d / thread_uid %x / main_uid %x / cycle %d\n", 159 cxy, lid, threads, thread_uid, main_uid, (int)cycle ); 160 161 while( 1 ) { asm volatile("nop"); } 162 145 163 unsigned int items = ARRAY_LENGTH / threads; 146 164 unsigned int stages = __builtin_ctz( threads ) + 1; 147 148 get_cycle( &cycle );149 printf("\n[SORT] thread[%d] enter at cycle %d\n", thread_uid , (unsigned int)cycle );150 151 printf("\n[SORT] thread[%d] / stage 0 start\n", thread_uid );152 165 153 166 bubbleSort( array0, items, items * thread_uid ); … … 157 170 ///////////////////////////////// 158 171 pthread_barrier_wait( &barrier ); 172 173 printf("\n[SORT] thread[%d] exit barrier\n", thread_uid ); 159 174 160 175 // the number of threads contributing to sort … … 220 235 pthread_t trdid; // kernel allocated thread index (unused) 221 236 pthread_barrierattr_t barrier_attr; // barrier attributes 222 pthread_attr_t attr[1024]; // thread attributes (one per thread)223 args_t arg[1024]; // sort function arguments (one per thread)224 237 225 238 // compute number of threads (one thread per proc) … … 251 264 252 265 get_cycle( &cycle ); 253 printf("\n [SORT] starts :%d threads / %d values / cycle %d\n",254 threads, ARRAY_LENGTH, (unsigned int)cycle );266 printf("\n\n[SORT] main starts on core[%x,%d] / %d threads / %d values / cycle %d\n", 267 main_cxy, main_lid, threads, ARRAY_LENGTH, (unsigned int)cycle ); 255 268 256 269 // Barrier initialization … … 265 278 266 279 get_cycle( &cycle ); 267 printf("\n[SORT] completes barrier init at cycle %d\n", (unsigned int)cycle );280 printf("\n[SORT] main completes barrier init at cycle %d\n", (unsigned int)cycle ); 268 281 269 282 // Array to sort initialization … … 273 286 } 274 287 275 #if VERBOSE288 #if DISPLAY_ARRAY 276 289 printf("\n*** array before sort\n"); 277 290 for( n=0; n<ARRAY_LENGTH; n++) printf("array[%d] = %d\n", n , array0[n] ); … … 279 292 280 293 get_cycle( &cycle ); 281 printf("\n[SORT] completes array init at cycle %d\n", (unsigned int)cycle );294 printf("\n[SORT] main completes array init at cycle %d\n", (unsigned int)cycle ); 282 295 283 296 // launch other threads to execute sort() function … … 303 316 if( thread_uid != main_uid ) 304 317 { 318 319 get_cycle( &cycle ); 320 printf("\n### main creates thread_uid %d / &sort_arg %x / cycle %d\n", 321 thread_uid, &arg[thread_uid], (unsigned int)cycle ); 322 305 323 if ( pthread_create( &trdid, // not used because no join 306 324 &attr[thread_uid], // thread attributes … … 308 326 &arg[thread_uid] ) ) // sort arguments 309 327 { 310 printf("\n[SORT ERROR] creating thread %x\n", thread_uid );328 printf("\n[SORT ERROR] main created thread %x \n", thread_uid ); 311 329 exit( 0 ); 312 330 } 331 } 313 332 314 } 315 } 316 } 317 } 318 319 get_cycle( &cycle ); 320 printf("\n[SORT] completes threads create at cycle %d\n", (unsigned int)cycle ); 321 322 // main run also the sort() function 333 #if DISPLAY_THREADS 334 display_sched( CXY_FROM_XY(x,y) , lid ); 335 #endif 336 } 337 } 338 } 339 340 get_cycle( &cycle ); 341 printf("\n[SORT] main completes threads create at cycle %d\n", (unsigned int)cycle ); 342 343 // main run also the sort() function 323 344 sort( &arg[main_uid] ); 324 345 … … 335 356 if ( res_array[n] > res_array[n+1] ) 336 357 { 358 printf("\n[SORT] array[%d] = %d > array[%d] = %d\n", 359 n , res_array[n] , n+1 , res_array[n+1] ); 337 360 success = 0; 338 361 break; … … 340 363 } 341 364 342 #if VERBOSE365 #if DISPLAY_ARRAY 343 366 printf("\n*** array after sort\n"); 344 367 for( n=0; n<ARRAY_LENGTH; n++) printf("array[%d] = %d\n", n , res_array[n] );
Note: See TracChangeset
for help on using the changeset viewer.