Changeset 676
- Timestamp:
- Nov 20, 2020, 12:11:35 AM (4 years ago)
- Location:
- trunk/user
- Files:
-
- 4 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/user/convol/convol.c
r659 r676 8 8 // per core, and uses the POSIX threads API. 9 9 // 10 // The main() function can be launched on any processor P[x,y,l]. 11 // It makes the initialisations, launch (N-1) threads to run the execute() function 12 // on the (N-1) other processors than P[x,y,l], call himself the execute() function, 13 // and finally call the instrument() function to display instrumentation results 14 // when the parallel execution is completed. 10 // The input image is read from a file and the output image is saved to another file. 11 // 12 // - number of clusters containing processors must be power of 2 no larger than 256. 13 // - number of processors per cluster must be power of 2 no larger than 4. 14 // - number of working threads is the number of cores availables in the hardware 15 // architecture : nthreads = nclusters * ncores. 15 16 // 16 17 // The convolution kernel is defined in the execute() function. 17 18 // It can be factored in two independant line and column convolution products. 18 // The five buffers containing the image are distributed in clusters.19 // For the philips image, it is a [201]*[35] pixels rectangle, and the.20 //21 // The (1024 * 1024) pixels image is read from a file (2 bytes per pixel).22 19 // 23 // - number of clusters containing processors must be power of 2 no larger than 256. 24 // - number of processors per cluster must be power of 2 no larger than 4. 20 // The main() function can be launched on any processor. 21 // - It checks software requirements versus the hardware resources. 22 // - It open & maps the input file to a global <image_in> buffer. 23 // - it open & maps the output file to another global <image_out> buffer. 24 // - it open the instrumentation file. 25 // - it creates & activates two FBF windows to display input & output images. 26 // - it launches other threads to run in parallel the execute() function. 27 // - it saves the instrumentation results on disk. 28 // - it closes the input, output, & instrumentation files. 29 // - it deletes the FBF input & output windows. 25 30 // 26 // The number N of working threads is always defined by the number of cores availables 27 // in the architecture, but this application supports three placement modes. 31 // The execute() function is executed in parallel by all threads. These threads are 32 // working on 5 arrays of distributed buffers, indexed by the cluster index [cid]. 33 // - A[cid]: contain the distributed initial image (NL/NCLUSTERS lines per cluster). 34 // - B[cid]: is the result of horizontal filter, then transpose B <= Trsp(HF(A) 35 // - C[cid]: is the result of vertical image, then transpose : c <= Trsp(VF(B) 36 // - D[cid]: is the the difference between A and FH(A) : D <= A - FH(A) 37 // - Z[cid]: contain the distributed final image Z <= C + D 38 // 39 // It can be split in four phases separated by synchronisation barriers: 40 // 1. Initialisation: 41 // Allocates the 5 A[cid],B[cid],C[cid],D[cid],Z[cid] buffers, initialise A[cid] 42 // from the <image_in> buffer, and display the initial image on FBF if rquired. 43 // 2. Horizontal Filter: 44 // Set B[cid] and D[cid] from A[cid]. Read data accesses are local, write data 45 // accesses are remote, to implement the transpose. 46 // 3. Vertical Filter: 47 // Set C[cid] from B[cid]. Read data accesses are local, write data accesses 48 // are remote, to implement the transpose. 49 // 4. Save results: 50 // Set the Z[cid] from C[cid] and D[cid]. All read and write access are local. 51 // Move the final image (Z[cid] buffer) to the <image_out> buffer. 52 // 53 // This application supports three placement modes, implemented in the main() function. 28 54 // In all modes, the working threads are identified by the [tid] continuous index 29 55 // in range [0, NTHREADS-1], and defines how the lines are shared amongst the threads. 30 56 // This continuous index can always be decomposed in two continuous sub-indexes: 31 // tid == cid * ncores+ lid, where cid is in [0,NCLUSTERS-1] and lid in [0,NCORES-1].57 // tid == cid * NCORES + lid, where cid is in [0,NCLUSTERS-1] and lid in [0,NCORES-1]. 32 58 // 33 59 // - NO_PLACEMENT: the main thread is itsef a working thread. The (N_1) other working … … 38 64 // but has tid = 0 (i.e. cid = 0 & tid = 0). 39 65 // 40 // - EXPLICIT_PLACEMENT: the main thread is again a working thread, but the placement of66 // - EXPLICIT_PLACEMENT: the main thread is again a working thread, but the placement 41 67 // of the threads on the cores is explicitely controled by the main thread to have 42 68 // exactly one working thread per core, and the [cxy][lpid] core coordinates for a given … … 46 72 // - PARALLEL_PLACEMENT: the main thread is not anymore a working thread, and uses the 47 73 // non standard pthread_parallel_create() function to avoid the costly sequencial 48 // loops for pthread_create() and pthread_join(). It garant yone working thread74 // loops for pthread_create() and pthread_join(). It garanties one working thread 49 75 // per core, and the same relation between the thread[tid] and the core[cxy][lpid]. 50 76 // … … 65 91 66 92 #define VERBOSE_MAIN 1 67 #define VERBOSE_EXEC 093 #define VERBOSE_EXEC 1 68 94 #define SUPER_VERBOSE 0 69 95 … … 74 100 #define THREADS_MAX (X_MAX * Y_MAX * CORES_MAX) 75 101 76 #define IMAGE_IN_PATH "misc/philips_1024_2.raw" 77 #define IMAGE_IN_PIXEL_SIZE 2 // 2 bytes per pixel 78 79 #define IMAGE_OUT_PATH "misc/philips_after_1O24.raw" 80 #define IMAGE_OUT_PIXEL_SIZE 1 // 1 bytes per pixel 81 82 #define FBF_TYPE 420 83 #define NL 1024 84 #define NP 1024 85 #define NB_PIXELS (NP * NL) 102 #define IMAGE_TYPE 420 // pixel encoding type 103 #define INPUT_IMAGE_PATH "misc/couple_512.raw" // default image_in 104 #define OUTPUT_IMAGE_PATH "misc/couple_conv_512.raw" // default image_out 105 #define NL 512 // default nlines 106 #define NP 512 // default npixels 86 107 87 108 #define NO_PLACEMENT 0 … … 89 110 #define PARALLEL_PLACEMENT 1 90 111 112 #define INTERACTIVE_MODE 0 91 113 #define USE_DQT_BARRIER 1 92 114 #define INITIAL_DISPLAY_ENABLE 1 … … 116 138 unsigned int V_BEG[CLUSTERS_MAX][CORES_MAX] = {{ 0 }}; 117 139 unsigned int V_END[CLUSTERS_MAX][CORES_MAX] = {{ 0 }}; 118 unsigned int D_BEG[CLUSTERS_MAX][CORES_MAX] = {{ 0 }};119 unsigned int D_END[CLUSTERS_MAX][CORES_MAX] = {{ 0 }};140 unsigned int F_BEG[CLUSTERS_MAX][CORES_MAX] = {{ 0 }}; 141 unsigned int F_END[CLUSTERS_MAX][CORES_MAX] = {{ 0 }}; 120 142 121 143 // pointer on buffer containing the input image, maped by the main to the input file … … 128 150 unsigned int THREAD_EXIT_SUCCESS = 0; 129 151 unsigned int THREAD_EXIT_FAILURE = 1; 152 153 // pointer and identifier for FBF windows 154 void * in_win_buf; 155 int in_wid; 156 void * out_win_buf; 157 int out_wid; 130 158 131 159 // synchronization barrier … … 137 165 unsigned int ncores; // number of processors per cluster 138 166 167 // main thread continuous index 168 unsigned int tid_main; 169 139 170 // arrays of pointers on distributed buffers in all clusters 140 unsigned short* GA[CLUSTERS_MAX];171 unsigned char * GA[CLUSTERS_MAX]; 141 172 int * GB[CLUSTERS_MAX]; 142 173 int * GC[CLUSTERS_MAX]; … … 153 184 pthread_parallel_work_args_t exec_args[THREADS_MAX]; 154 185 155 // main thread continuous index 156 unsigned int tid_main; 186 // image features 187 unsigned int image_nl; 188 unsigned int image_np; 189 char input_image_path[128]; 190 char output_image_path[128]; 157 191 158 192 ///////////////////////////////////////////////////////////////////////////////////// … … 166 200 ///////////////// 167 201 void main( void ) 202 ///////////////// 168 203 { 169 204 unsigned long long start_cycle; … … 222 257 unsigned int nthreads = nclusters * ncores; 223 258 259 // get input and output images pathnames and size 260 if( INTERACTIVE_MODE ) 261 { 262 // get image size 263 printf("\n[convol] image nlines : "); 264 get_uint32( &image_nl ); 265 266 printf("\n[convol] image npixels : "); 267 get_uint32( &image_np ); 268 269 printf("\n[convol] input image path : "); 270 get_string( input_image_path , 128 ); 271 272 printf("[convol] output image path : "); 273 get_string( output_image_path , 128 ); 274 } 275 else 276 { 277 image_nl = NL; 278 image_np = NP; 279 strcpy( input_image_path , INPUT_IMAGE_PATH ); 280 strcpy( output_image_path , OUTPUT_IMAGE_PATH ); 281 } 282 224 283 // main thread get FBF size and type 225 unsignedint fbf_width;226 unsignedint fbf_height;227 unsignedint fbf_type;284 int fbf_width; 285 int fbf_height; 286 int fbf_type; 228 287 fbf_get_config( &fbf_width , &fbf_height , &fbf_type ); 229 288 230 if( (fbf_width != NP) || (fbf_height != NL) || (fbf_type != FBF_TYPE) ) 231 { 232 printf("\n[convol error] image does not fit FBF size or type\n"); 233 exit( 0 ); 234 } 235 236 if( nthreads > NL ) 237 { 238 printf("\n[convol error] number of threads larger than number of lines\n"); 289 if( ((unsigned int)fbf_width < image_np) || 290 ((unsigned int)fbf_height < image_nl) || 291 (fbf_type != IMAGE_TYPE) ) 292 { 293 printf("\n[convol error] image not acceptable\n" 294 "FBF width = %d / npixels = %d\n" 295 "FBF height = %d / nlines = %d\n" 296 "FBF type = %d / expected = %d\n", 297 fbf_width, image_np, fbf_height, image_nl, fbf_type, IMAGE_TYPE ); 298 exit( 0 ); 299 } 300 301 if( nthreads > image_nl ) 302 { 303 printf("\n[convol error] nthreads (%d] larger than nlines (%d)\n", 304 nthreads , image_nl ); 239 305 exit( 0 ); 240 306 } … … 248 314 // build instrumentation file name 249 315 if( USE_DQT_BARRIER ) 250 snprintf( instru_name , 32 , " conv_dqt_no_place_%d_%d", x_size * y_size , ncores );316 snprintf( instru_name , 32 , "dqt_no_place_%d_%d", x_size * y_size , ncores ); 251 317 else 252 snprintf( instru_name , 32 , " conv_smp_no_place_%d_%d", x_size * y_size , ncores );318 snprintf( instru_name , 32 , "smp_no_place_%d_%d", x_size * y_size , ncores ); 253 319 } 254 320 … … 260 326 // build instrumentation file name 261 327 if( USE_DQT_BARRIER ) 262 snprintf( instru_name , 32 , " conv_dqt_explicit_%d_%d", x_size * y_size , ncores );328 snprintf( instru_name , 32 , "dqt_explicit_%d_%d", x_size * y_size , ncores ); 263 329 else 264 snprintf( instru_name , 32 , " conv_smp_explicit_%d_%d", x_size * y_size , ncores );330 snprintf( instru_name , 32 , "smp_explicit_%d_%d", x_size * y_size , ncores ); 265 331 } 266 332 … … 272 338 // build instrumentation file name 273 339 if( USE_DQT_BARRIER ) 274 snprintf( instru_name , 32 , " conv_dqt_parallel_%d_%d", x_size * y_size , ncores );340 snprintf( instru_name , 32 , "dqt_parallel_%d_%d", x_size * y_size , ncores ); 275 341 else 276 snprintf( instru_name , 32 , " conv_smp_parallel_%d_%d", x_size * y_size , ncores );342 snprintf( instru_name , 32 , "smp_parallel_%d_%d", x_size * y_size , ncores ); 277 343 } 278 344 279 345 // open instrumentation file 280 snprintf( instru_path , 64 , "/home/ %s", instru_name );346 snprintf( instru_path , 64 , "/home/convol/%s", instru_name ); 281 347 FILE * f_instru = fopen( instru_path , NULL ); 282 348 if ( f_instru == NULL ) … … 289 355 printf("\n[convol] main on core[%x,%d] open instrumentation file %s\n", 290 356 cxy_main, lid_main, instru_path ); 357 #endif 358 359 // main create an FBF window for input image 360 in_wid = fbf_create_window( 0, // l_zero 361 0, // p_zero 362 image_nl, // lines 363 image_np, // pixels 364 &in_win_buf ); 365 if( in_wid < 0 ) 366 { 367 printf("\n[transpose error] cannot open FBF window for %s\n", 368 input_image_path); 369 exit( 0 ); 370 } 371 372 // activate window 373 error = fbf_active_window( in_wid , 1 ); 374 375 if( error ) 376 { 377 printf("\n[transpose error] cannot activate window for %s\n", 378 input_image_path ); 379 exit( 0 ); 380 } 381 382 #if VERBOSE_MAIN 383 printf("\n[convol] main on core[%x,%d] created FBF window (wid %d) for <%s>\n", 384 cxy_main, lid_main, in_wid, input_image_path ); 385 #endif 386 387 // main create an FBF window for output image 388 out_wid = fbf_create_window( 0, // l_zero 389 image_np, // p_zero 390 image_nl, // lines 391 image_np, // pixels 392 &out_win_buf ); 393 if( out_wid < 0 ) 394 { 395 printf("\n[transpose error] cannot create FBF window for %s\n", 396 output_image_path); 397 exit( 0 ); 398 } 399 400 // activate window 401 error = fbf_active_window( out_wid , 1 ); 402 403 if( error ) 404 { 405 printf("\n[transpose error] cannot activate window for %s\n", 406 output_image_path ); 407 exit( 0 ); 408 } 409 410 #if VERBOSE_MAIN 411 printf("\n[convol] main on core[%x,%d] created FBF window (wid %d) for <%s>\n", 412 cxy_main, lid_main, out_wid, output_image_path ); 291 413 #endif 292 414 … … 312 434 313 435 #if VERBOSE_MAIN 314 printf("\n[convol] main on core[%x,%d] complete sbarrier init\n",436 printf("\n[convol] main on core[%x,%d] completed barrier init\n", 315 437 cxy_main, lid_main ); 316 438 #endif 317 439 318 440 // main open input file 319 int fd_in = open( IMAGE_IN_PATH, O_RDONLY , 0 );441 int fd_in = open( input_image_path , O_RDONLY , 0 ); 320 442 321 443 if ( fd_in < 0 ) 322 444 { 323 printf("\n[convol error] cannot open input file <%s>\n", IMAGE_IN_PATH ); 324 exit( 0 ); 325 } 326 327 #if VERBOSE_MAIN 328 printf("\n[convol] main on core[%x,%d] open file <%s>\n", 329 cxy_main, lid_main, IMAGE_IN_PATH ); 330 #endif 331 332 // main thread map image_in buffer to input file 445 printf("\n[convol error] cannot open input file <%s>\n", input_image_path ); 446 exit( 0 ); 447 } 448 449 // main thread map input file to image_in buffer 333 450 image_in = (unsigned char *)mmap( NULL, 334 NB_PIXELS * IMAGE_IN_PIXEL_SIZE,451 image_np * image_nl, 335 452 PROT_READ, 336 453 MAP_FILE | MAP_SHARED, … … 339 456 if ( image_in == NULL ) 340 457 { 341 printf("\n[convol error] main cannot map buffer to file %s\n", IMAGE_IN_PATH);458 printf("\n[convol error] main cannot map buffer to file %s\n", input_image_path ); 342 459 exit( 0 ); 343 460 } 344 461 345 462 #if VERBOSE_MAIN 346 printf("\n[convol] main on core[%x,%x] map buffer to file <%s>\n",347 cxy_main, lid_main, IMAGE_IN_PATH);463 printf("\n[convol] main on core[%x,%x] map <image_in> buffer to file <%s>\n", 464 cxy_main, lid_main, input_image_path ); 348 465 #endif 349 466 350 467 // main thread open output file 351 int fd_out = open( IMAGE_OUT_PATH, O_CREAT , 0 );468 int fd_out = open( output_image_path , O_CREAT , 0 ); 352 469 353 470 if ( fd_out < 0 ) 354 471 { 355 printf("\n[convol error] main cannot open file %s\n", IMAGE_OUT_PATH ); 356 exit( 0 ); 357 } 358 359 #if VERBOSE_MAIN 360 printf("\n[convol] main on core[%x,%d] open file <%s>\n", 361 cxy_main, lid_main, IMAGE_OUT_PATH ); 362 #endif 472 printf("\n[convol error] main cannot open file %s\n", output_image_path ); 473 exit( 0 ); 474 } 363 475 364 476 // main thread map image_out buffer to output file 365 477 image_out = (unsigned char *)mmap( NULL, 366 NB_PIXELS + IMAGE_OUT_PIXEL_SIZE,478 image_np * image_nl, 367 479 PROT_WRITE, 368 480 MAP_FILE | MAP_SHARED, … … 371 483 if ( image_out == NULL ) 372 484 { 373 printf("\n[convol error] main cannot map buffer to file %s\n", IMAGE_OUT_PATH);485 printf("\n[convol error] main cannot map buffer to file %s\n", output_image_path ); 374 486 exit( 0 ); 375 487 } 376 488 377 489 #if VERBOSE_MAIN 378 printf("\n[convol] main on core[%x,%x] map buffer to file <%s>\n",379 cxy_main, lid_main, IMAGE_OUT_PATH);490 printf("\n[convol] main on core[%x,%x] map <image_out> buffer to file <%s>\n", 491 cxy_main, lid_main, output_image_path ); 380 492 #endif 381 493 … … 389 501 { 390 502 // the tid value for the main thread is always 0 391 // main thread creates newthreads with tid in [1,nthreads-1]503 // main thread creates other threads with tid in [1,nthreads-1] 392 504 unsigned int tid; 393 505 for ( tid = 0 ; tid < nthreads ; tid++ ) … … 587 699 #endif 588 700 701 // ask confirm for exit 702 if( INTERACTIVE_MODE ) 703 { 704 char byte; 705 printf("\n[convol] press any key to to delete FBF windows and exit\n"); 706 getc( &byte ); 707 } 708 709 // main thread delete FBF windows 710 fbf_delete_window( in_wid ); 711 fbf_delete_window( out_wid ); 712 713 #if VERBOSE_MAIN 714 printf("\n[convol] main deleted FBF windows\n" ); 715 #endif 716 589 717 // main thread suicide 590 718 exit( 0 ); … … 597 725 598 726 727 728 729 730 599 731 ////////////////////////////////// 600 732 void * execute( void * arguments ) 601 733 ////////////////////////////////// 602 734 { 603 735 unsigned long long date; … … 628 760 // thread [cid][lid] indexes, and the core coordinates [cxy][lpid] 629 761 630 // get thread abstract identifiers 762 // get thread abstract identifiers[cid,lid] from tid 631 763 unsigned int tid = args->tid; 632 764 unsigned int cid = tid / ncores; … … 642 774 #endif 643 775 644 // build total number of threads andclusters from global variables776 // compute nthreads and nclusters from global variables 645 777 unsigned int nclusters = x_size * y_size; 646 778 unsigned int nthreads = nclusters * ncores; … … 652 784 unsigned int z; // vertical filter index 653 785 654 unsigned int lines_per_thread = NL / nthreads; 655 unsigned int lines_per_cluster = NL / nclusters; 656 unsigned int pixels_per_thread = NP / nthreads; 657 unsigned int pixels_per_cluster = NP / nclusters; 658 659 // compute number of pixels stored in one abstract cluster cid 660 unsigned int local_pixels = NL * NP / nclusters; 661 662 unsigned int first, last; 786 unsigned int lines_per_thread = image_nl / nthreads; 787 unsigned int lines_per_cluster = image_nl / nclusters; 788 unsigned int pixels_per_thread = image_np / nthreads; 789 unsigned int pixels_per_cluster = image_np / nclusters; 790 791 // compute number of pixels stored in one cluster 792 unsigned int local_pixels = image_nl * image_np / nclusters; 663 793 664 794 get_cycle( &date ); 665 795 START[cid][lid] = (unsigned int)date; 666 796 667 // Each thread[cid][0] allocates 5 local buffers,797 // Each thread[cid][0] allocates 5 buffers local cluster cid 668 798 // and registers these 5 pointers in the global arrays 669 799 if ( lid == 0 ) 670 800 { 671 GA[cid] = malloc( local_pixels * sizeof( unsigned short) );801 GA[cid] = malloc( local_pixels * sizeof( unsigned char ) ); 672 802 GB[cid] = malloc( local_pixels * sizeof( int ) ); 673 803 GC[cid] = malloc( local_pixels * sizeof( int ) ); … … 675 805 GZ[cid] = malloc( local_pixels * sizeof( unsigned char ) ); 676 806 677 if( (GA[cid] == NULL) || (GB[cid] == NULL) || (GC[cid] == NULL) || 678 (GD[cid] == NULL) || (GZ[cid] == NULL) ) 807 if( (GA[cid] == NULL) || 808 (GB[cid] == NULL) || 809 (GC[cid] == NULL) || 810 (GD[cid] == NULL) || 811 (GZ[cid] == NULL) ) 679 812 { 680 813 printf("\n[convol error] thread[%d] cannot allocate buf_in\n", tid ); … … 684 817 #if VERBOSE_EXEC 685 818 get_cycle( &date ); 686 printf( 819 printf("\n[convol] exec[%d] on core[%x,%d] allocated shared buffers / cycle %d\n" 687 820 " GA %x / GB %x / GC %x / GD %x / GZ %x\n", 688 821 tid, cxy , lpid, (unsigned int)date, GA[cid], GB[cid], GC[cid], GD[cid], GZ[cid] ); … … 694 827 pthread_barrier_wait( &barrier ); 695 828 696 // Each thread[ cid,lid] allocate and initialisein its private stack829 // Each thread[tid] allocates and initialises in its private stack 697 830 // a copy of the arrays of pointers on the distributed buffers. 698 unsigned short* A[CLUSTERS_MAX];831 unsigned char * A[CLUSTERS_MAX]; 699 832 int * B[CLUSTERS_MAX]; 700 833 int * C[CLUSTERS_MAX]; … … 711 844 } 712 845 713 // Each thread[cid,0] access the file containing the input image, to load 714 // the local A[cid] buffer. Other threads are waiting on the barrier. 715 if ( lid==0 ) 716 { 717 unsigned int size = local_pixels * sizeof( unsigned short ); 718 unsigned int offset = size * cid; 719 720 memcpy( A[cid], 721 image_in + offset, 722 size ); 846 unsigned int npixels = image_np * lines_per_thread; // pixels moved by any thread 847 unsigned int g_offset = npixels * tid; // offset in global buffer for tid 848 unsigned int l_offset = npixels * lid; // offset in local buffer for tid 849 850 // min and max line indexes handled by thread[tid] for a global buffer 851 unsigned int global_lmin = tid * lines_per_thread; 852 unsigned int global_lmax = global_lmin + lines_per_thread; 853 854 // min and max line indexes handled by thread[tid] for a local buffer 855 unsigned int local_lmin = lid * lines_per_thread; 856 unsigned int local_lmax = local_lmin + lines_per_thread; 857 858 // pmin and pmax pixel indexes handled by thread[tid] in a column 859 unsigned int column_pmin = tid * pixels_per_thread; 860 unsigned int column_pmax = column_pmin + pixels_per_thread; 861 862 // Each thread[tid] copy npixels from image_in buffer to local A[cid] buffer 863 memcpy( A[cid] + l_offset, 864 image_in + g_offset, 865 npixels ); 723 866 724 867 #if VERBOSE_EXEC … … 728 871 #endif 729 872 730 } 731 732 // Optionnal parallel display of the initial image stored in A[c] buffers. 733 // Eah thread[cid,lid] displays (NL/nthreads) lines. 734 873 // Optionnal parallel display for the initial image 735 874 if ( INITIAL_DISPLAY_ENABLE ) 736 875 { 737 unsigned int line; 738 unsigned int offset = lines_per_thread * lid; 739 740 for ( l = 0 ; l < lines_per_thread ; l++ ) 741 { 742 line = offset + l; 743 744 // copy TA[cid] to TZ[cid] 745 for ( p = 0 ; p < NP ; p++ ) 746 { 747 TZ(cid, line, p) = (unsigned char)(TA(cid, line, p) >> 8); 748 } 749 750 // display one line to frame buffer 751 if (fbf_write( &TZ(cid, line, 0), // first pixel in TZ 752 NP, // number of bytes 753 NP*(l + (tid * lines_per_thread)))) // offset in FBF 754 { 755 printf("\n[convol error] in %s : thread[%d] cannot access FBF\n", 756 __FUNCTION__ , tid ); 757 pthread_exit( &THREAD_EXIT_FAILURE ); 758 } 876 // each thread[tid] copy npixels from A[cid] to in_win_buf buffer 877 memcpy( in_win_buf + g_offset, 878 A[cid] + l_offset, 879 npixels ); 880 881 // refresh the FBF window 882 if( fbf_refresh_window( in_wid , global_lmin , global_lmax ) ) 883 { 884 printf("\n[convol error] in %s : thread[%d] cannot access FBF\n", 885 __FUNCTION__ , tid ); 886 pthread_exit( &THREAD_EXIT_FAILURE ); 759 887 } 760 888 … … 771 899 //////////////////////////////////////////////////////////// 772 900 // parallel horizontal filter : 773 // B <= convol(FH(A))901 // B <= Transpose(FH(A)) 774 902 // D <= A - FH(A) 775 // Each thread computes ( NL/nthreads) lines.903 // Each thread computes (image_nl/nthreads) lines. 776 904 // The image must be extended : 777 905 // if (z<0) TA(cid,l,z) == TA(cid,l,0) 778 // if (z> NP-1) TA(cid,l,z) == TA(cid,l,NP-1)906 // if (z>image_np-1) TA(cid,l,z) == TA(cid,l,image_np-1) 779 907 //////////////////////////////////////////////////////////// 780 908 … … 782 910 H_BEG[cid][lid] = (unsigned int)date; 783 911 784 // l = absolute line index / p = absolute pixel index 785 // first & last define which lines are handled by a given thread 786 787 first = tid * lines_per_thread; 788 last = first + lines_per_thread; 789 790 for (l = first; l < last; l++) 912 // l = global line index / p = absolute pixel index 913 914 for (l = global_lmin; l < global_lmax; l++) 791 915 { 792 916 // src_c and src_l are the cluster index and the line index for A & D … … 814 938 TD(src_c, src_l, p) = (int) TA(src_c, src_l, p) - sum_p / hnorm; 815 939 } 816 // second domain : from (hrange+1) to ( NP-hrange-1)817 for (p = hrange + 1; p < NP- hrange; p++)940 // second domain : from (hrange+1) to (image_np-hrange-1) 941 for (p = hrange + 1; p < image_np - hrange; p++) 818 942 { 819 943 // dst_c and dst_p are the cluster index and the pixel index for B … … 825 949 TD(src_c, src_l, p) = (int) TA(src_c, src_l, p) - sum_p / hnorm; 826 950 } 827 // third domain : from ( NP-hrange) to (NP-1)828 for (p = NP - hrange; p < NP; p++)951 // third domain : from (image_np-hrange) to (image_np-1) 952 for (p = image_np - hrange; p < image_np; p++) 829 953 { 830 954 // dst_c and dst_p are the cluster index and the pixel index for B 831 955 int dst_c = p / pixels_per_cluster; 832 956 int dst_p = p % pixels_per_cluster; 833 sum_p = sum_p + (int) TA(src_c, src_l, NP- 1)957 sum_p = sum_p + (int) TA(src_c, src_l, image_np - 1) 834 958 - (int) TA(src_c, src_l, p - hrange - 1); 835 959 TB(dst_c, dst_p, l) = sum_p / hnorm; … … 858 982 /////////////////////////////////////////////////////////////// 859 983 // parallel vertical filter : 860 // C <= transpose(FV(B))861 // Each thread computes ( NP/nthreads) columns984 // C <= Transpose(FV(B)) 985 // Each thread computes (image_np/nthreads) columns 862 986 // The image must be extended : 863 987 // if (l<0) TB(cid,p,l) == TB(cid,p,0) 864 // if (l> NL-1) TB(cid,p,l) == TB(cid,p,NL-1)988 // if (l>image_nl-1) TB(cid,p,l) == TB(cid,p,image_nl-1) 865 989 /////////////////////////////////////////////////////////////// 866 990 … … 868 992 V_BEG[cid][lid] = (unsigned int)date; 869 993 870 // l = absolute line index / p = absolute pixel index 871 // first & last define which pixels are handled by a given thread 872 873 first = tid * pixels_per_thread; 874 last = first + pixels_per_thread; 875 876 for (p = first; p < last; p++) 994 // l = global line index / p = pixel index in column 995 996 for (p = column_pmin; p < column_pmax ; p++) 877 997 { 878 998 // src_c and src_p are the cluster index and the pixel index for B … … 883 1003 884 1004 // We use the specific values of the vertical ep-filter 885 // To minimize the number of tests, the NLlines are split in three domains1005 // To minimize the number of tests, the image_nl lines are split in three domains 886 1006 887 1007 // first domain : explicit computation for the first 18 values … … 899 1019 } 900 1020 // second domain 901 for (l = 18; l < NL- 17; l++)1021 for (l = 18; l < image_nl - 17; l++) 902 1022 { 903 1023 // dst_c and dst_l are the cluster index and the line index for C … … 919 1039 } 920 1040 // third domain 921 for (l = NL - 17; l < NL; l++)1041 for (l = image_nl - 17; l < image_nl; l++) 922 1042 { 923 1043 // dst_c and dst_l are the cluster index and the line index for C … … 925 1045 int dst_l = l % lines_per_cluster; 926 1046 927 sum_l = sum_l + TB(src_c, src_p, min(l + 4, NL- 1))928 + TB(src_c, src_p, min(l + 8, NL- 1))929 + TB(src_c, src_p, min(l + 11, NL- 1))930 + TB(src_c, src_p, min(l + 15, NL- 1))931 + TB(src_c, src_p, min(l + 17, NL- 1))1047 sum_l = sum_l + TB(src_c, src_p, min(l + 4, image_nl - 1)) 1048 + TB(src_c, src_p, min(l + 8, image_nl - 1)) 1049 + TB(src_c, src_p, min(l + 11, image_nl - 1)) 1050 + TB(src_c, src_p, min(l + 15, image_nl - 1)) 1051 + TB(src_c, src_p, min(l + 17, image_nl - 1)) 932 1052 - TB(src_c, src_p, l - 5) 933 1053 - TB(src_c, src_p, l - 9) … … 958 1078 pthread_barrier_wait( &barrier ); 959 1079 960 // Optional parallel display of the final image Z <= D + C 961 // Eah thread[x,y,p] displays (NL/nthreads) lines. 962 1080 /////////////////////////////////////////////////////////////// 1081 // build final image in local Z buffer from C & D local buffers 1082 // store it in output image file, and display it on FBF. 1083 // Z <= C + D 1084 /////////////////////////////////////////////////////////////// 1085 1086 get_cycle( &date ); 1087 F_BEG[cid][lid] = (unsigned int)date; 1088 1089 // Each thread[tid] set local buffer Z[cid] from local buffers C[cid] & D[cid] 1090 1091 for( l = local_lmin ; l < local_lmax ; l++ ) 1092 { 1093 for( p = 0 ; p < image_np ; p++ ) 1094 { 1095 TZ(cid,l,p) = TC(cid,l,p) + TD(cid,l,p); 1096 } 1097 } 1098 1099 // Each thread[tid] copy npixels from Z[cid] buffer to image_out buffer 1100 memcpy( image_out + g_offset, 1101 Z[cid] + l_offset, 1102 npixels ); 1103 1104 // Optional parallel display of the final image 963 1105 if ( FINAL_DISPLAY_ENABLE ) 964 1106 { 965 get_cycle( &date ); 966 D_BEG[cid][lid] = (unsigned int)date; 967 968 unsigned int line; 969 unsigned int offset = lines_per_thread * lid; 970 971 for ( l = 0 ; l < lines_per_thread ; l++ ) 972 { 973 line = offset + l; 974 975 for ( p = 0 ; p < NP ; p++ ) 976 { 977 TZ(cid, line, p) = 978 (unsigned char)( (TD(cid, line, p) + 979 TC(cid, line, p) ) >> 8 ); 980 } 981 982 if (fbf_write( &TZ(cid, line, 0), // first pixel in TZ 983 NP, // number of bytes 984 NP*(l + (tid * lines_per_thread)))) // offset in FBF 985 { 986 printf("\n[convol error] thread[%d] cannot access FBF\n", tid ); 987 pthread_exit( &THREAD_EXIT_FAILURE ); 988 } 989 } 990 991 get_cycle( &date ); 992 D_END[cid][lid] = (unsigned int)date; 993 994 #if VERBOSE_EXEC 1107 // each thread[tid] copy npixels from Z[cid] to out_win_buf buffer 1108 memcpy( out_win_buf + g_offset, 1109 Z[cid] + l_offset, 1110 npixels ); 1111 1112 // refresh the FBF window 1113 if( fbf_refresh_window( out_wid , global_lmin , global_lmax ) ) 1114 { 1115 printf("\n[convol error] in %s : thread[%d] cannot access FBF\n", 1116 __FUNCTION__ , tid ); 1117 pthread_exit( &THREAD_EXIT_FAILURE ); 1118 } 1119 1120 #if VERBOSE_EXEC 995 1121 get_cycle( &date ); 996 1122 printf( "\n[convol] exec[%d] on core[%x,%d] completed final display / cycle %d\n", 997 tid , cxy , l id , (unsigned int)date );1123 tid , cxy , lpid , (unsigned int)date ); 998 1124 #endif 999 1125 … … 1010 1136 } 1011 1137 1138 get_cycle( &date ); 1139 F_END[cid][lid] = (unsigned int)date; 1140 1012 1141 // thread termination depends on the placement policy 1013 1142 if( PARALLEL_PLACEMENT ) … … 1031 1160 1032 1161 } // end execute() 1162 1163 1164 1033 1165 1034 1166 … … 1057 1189 unsigned int max_v_end = 0; 1058 1190 1059 unsigned int min_ d_beg = 0xFFFFFFFF;1060 unsigned int max_ d_beg = 0;1061 1062 unsigned int min_ d_end = 0xFFFFFFFF;1063 unsigned int max_ d_end = 0;1191 unsigned int min_f_beg = 0xFFFFFFFF; 1192 unsigned int max_f_beg = 0; 1193 1194 unsigned int min_f_end = 0xFFFFFFFF; 1195 unsigned int max_f_end = 0; 1064 1196 1065 1197 for (cc = 0; cc < nclusters; cc++) … … 1082 1214 if (V_END[cc][pp] > max_v_end) max_v_end = V_END[cc][pp]; 1083 1215 1084 if ( D_BEG[cc][pp] < min_d_beg) min_d_beg = D_BEG[cc][pp];1085 if ( D_BEG[cc][pp] > max_d_beg) max_d_beg = D_BEG[cc][pp];1086 1087 if ( D_END[cc][pp] < min_d_end) min_d_end = D_END[cc][pp];1088 if ( D_END[cc][pp] > max_d_end) max_d_end = D_END[cc][pp];1216 if (F_BEG[cc][pp] < min_f_beg) min_f_beg = F_BEG[cc][pp]; 1217 if (F_BEG[cc][pp] > max_f_beg) max_f_beg = F_BEG[cc][pp]; 1218 1219 if (F_END[cc][pp] < min_f_end) min_f_end = F_END[cc][pp]; 1220 if (F_END[cc][pp] > max_f_end) max_f_end = F_END[cc][pp]; 1089 1221 } 1090 1222 } … … 1109 1241 1110 1242 printf(" - D_BEG : min = %d / max = %d / med = %d / delta = %d\n", 1111 min_ d_beg, max_d_beg, (min_d_beg+max_d_beg)/2, max_d_beg-min_d_beg);1243 min_f_beg, max_f_beg, (min_f_beg+max_f_beg)/2, max_f_beg-min_f_beg); 1112 1244 1113 1245 printf(" - D_END : min = %d / max = %d / med = %d / delta = %d\n", 1114 min_ d_end, max_d_end, (min_d_end+max_d_end)/2, max_d_end-min_d_end);1246 min_f_end, max_f_end, (min_f_end+max_f_end)/2, max_f_end-min_f_end); 1115 1247 1116 1248 printf( "\n General Scenario (Kcycles)\n" ); … … 1119 1251 printf( " - BARRIER HORI/VERT = %d\n", (min_v_beg - max_h_end)/1000 ); 1120 1252 printf( " - V_FILTER = %d\n", (max_v_end - min_v_beg)/1000 ); 1121 printf( " - BARRIER VERT/DISP = %d\n", (min_ d_beg - max_v_end)/1000 );1122 printf( " - DISPLAY = %d\n", (max_ d_end - min_d_beg)/1000 );1253 printf( " - BARRIER VERT/DISP = %d\n", (min_f_beg - max_v_end)/1000 ); 1254 printf( " - DISPLAY = %d\n", (max_f_end - min_f_beg)/1000 ); 1123 1255 printf( " \nSEQUENCIAL = %d / PARALLEL = %d\n", 1124 1256 SEQUENCIAL_TIME/1000, PARALLEL_TIME/1000 ); … … 1143 1275 1144 1276 fprintf( f , " - D_BEG : min = %d / max = %d / med = %d / delta = %d\n", 1145 min_ d_beg, max_d_beg, (min_d_beg+max_d_beg)/2, max_d_beg-min_d_beg);1277 min_f_beg, max_f_beg, (min_f_beg+max_f_beg)/2, max_f_beg-min_f_beg); 1146 1278 1147 1279 fprintf( f , " - D_END : min = %d / max = %d / med = %d / delta = %d\n", 1148 min_ d_end, max_d_end, (min_d_end+max_d_end)/2, max_d_end-min_d_end);1280 min_f_end, max_f_end, (min_f_end+max_f_end)/2, max_f_end-min_f_end); 1149 1281 1150 1282 fprintf( f , "\n General Scenario (Kcycles)\n" ); … … 1153 1285 fprintf( f , " - BARRIER HORI/VERT = %d\n", (min_v_beg - max_h_end)/1000 ); 1154 1286 fprintf( f , " - V_FILTER = %d\n", (max_v_end - min_v_beg)/1000 ); 1155 fprintf( f , " - BARRIER VERT/DISP = %d\n", (min_ d_beg - max_v_end)/1000 );1156 fprintf( f , " - DISPLAY = %d\n", (max_d_end - min_d_beg)/1000 );1287 fprintf( f , " - BARRIER VERT/DISP = %d\n", (min_f_beg - max_v_end)/1000 ); 1288 fprintf( f , " - SAVE = %d\n", (max_f_end - min_f_beg)/1000 ); 1157 1289 fprintf( f , " \nSEQUENCIAL = %d / PARALLEL = %d\n", 1158 1290 SEQUENCIAL_TIME/1000, PARALLEL_TIME/1000 ); -
trunk/user/display/display.c
r657 r676 4 4 // author : Alain Greiner 5 5 /////////////////////////////////////////////////////////////////////////////////////// 6 // This file describes the single thread "display" application .7 // It uses the external chained buffer DMA to display a stream8 // of images on the frame buffer.6 // This file describes the single thread "display" application that simply 7 // open a file containing a raw image stored on disk, ans distplay it on the 8 // Frame Buffer without using the ALMOS-MKH windows manager. 9 9 /////////////////////////////////////////////////////////////////////////////////////// 10 10 … … 15 15 #include <almosmkh.h> 16 16 17 #define PATH_ MAX_LENGHT 12817 #define PATH_NAME "misc/images_128.ram" 18 18 19 19 #define FBF_TYPE 420 … … 80 80 } 81 81 82 // check pixel encoding type 82 83 if( fbf_type != FBF_TYPE ) 83 84 { … … 87 88 } 88 89 89 // get pathname for input file90 while( 1 )91 {92 printf("\n[display] path = ");93 94 error = get_string( pathname , PATH_MAX_LENGHT );95 96 if ( error ) printf("\n[display error] cannot get path for input file\n" );97 else break;98 }99 100 90 // open file 101 int fd = open( pathname , O_RDONLY , 0 ); 102 91 int fd = open( PATH_NAME , O_RDONLY , 0 ); 103 92 if( fd < 0 ) 104 93 { -
trunk/user/init/init.c
r659 r676 20 20 #include <shared_syscalls.h> 21 21 22 #define DEBUG_PROCESS_INIT 122 #define DEBUG_PROCESS_INIT 0 23 23 24 24 //////////////// … … 36 36 #endif 37 37 38 // get Number of TXT channels from hard configuration38 // get number of TXT channels from hard configuration 39 39 hard_config_t config; 40 40 41 get_config( &config ); 41 42 42 43 unsigned int txt_channels = config.txt_channels; 43 unsigned int x_size = config.x_size;44 unsigned int y_size = config.y_size;45 unsigned int ncores = config.ncores;46 44 47 45 // check number of TXT channels … … 49 47 { 50 48 snprintf( string , 64 , 51 "\n[init ERROR] number of TXT channels must be larger than 1 \n");49 "\n[init ERROR] number of TXT channels must be larger than 1"); 52 50 display_string( string ); 53 51 exit( EXIT_FAILURE ); … … 64 62 // INIT display error message 65 63 snprintf( string , 64 , 66 " [init ERROR] cannot fork child[%d] => suicide" , i );64 "\n[init ERROR] cannot fork child[%d] => suicide" , i ); 67 65 display_string( string ); 68 66 … … 72 70 else if( ret_fork == 0 ) // we are in CHILD[i] process 73 71 { 72 73 #if DEBUG_PROCESS_INIT 74 snprintf( string , 64 , 75 "\n[init] CHILD[%d] process forked / call execve", i ); 76 display_string( string ); 77 #endif 74 78 // CHILD[i] process exec process KSH[i] 75 79 ret_exec = execve( "/bin/user/ksh.elf" , NULL , NULL ); … … 79 83 // CHILD[i] display error message 80 84 snprintf( string , 64 , 81 " [init ERROR] CHILD[%d] cannot exec KSH / ret_exec = %d" , i , ret_exec);85 "\n[init ERROR] CHILD[%d] cannot exec KSH" , i ); 82 86 display_string( string ); 83 87 … … 90 94 // INIT display CHILD[i] process PID 91 95 snprintf( string , 64 , 92 " [init] (pid 0x1) createdksh[%d] (pid %x)", i , ret_fork );96 "\n[init] (pid 0x1) create ksh[%d] (pid %x)", i , ret_fork ); 93 97 display_string( string ); 94 98 … … 104 108 unsigned int cxy; // cluster identifier 105 109 unsigned int lid; // core local index 110 111 unsigned int x_size = config.x_size; 112 unsigned int y_size = config.y_size; 113 unsigned int ncores = config.ncores; 106 114 107 115 // INIT displays processes and threads in all clusters -
trunk/user/kleenex/kleenex.c
r660 r676 19 19 #include <almosmkh.h> 20 20 21 #define IN_FILENAME "misc/philips_1024 _2.raw"22 #define OUT_FILENAME "misc/philips_1024. raw"21 #define IN_FILENAME "misc/philips_1024.raw" 22 #define OUT_FILENAME "misc/philips_1024.new" 23 23 #define FBF_TYPE 420 24 24 #define NPIXELS 1024 … … 31 31 int fd_out; 32 32 33 unsigned intfbf_width;34 unsigned intfbf_height;35 unsigned intfbf_type;33 int fbf_width; 34 int fbf_height; 35 int fbf_type; 36 36 37 37 int line; … … 42 42 unsigned long long start_cycle; 43 43 44 unsigned short buf_in[NPIXELS * NLINES * 2]; 45 // unsigned char buf_in[NPIXELS * NLINES]; 44 unsigned char buf_in[NPIXELS * NLINES]; 46 45 unsigned char buf_out[NPIXELS * NLINES]; 47 46 48 47 struct stat st; 49 48 50 int size_in = NPIXELS * NLINES * 2; 51 // int size_in = NPIXELS * NLINES; 49 int size_in = NPIXELS * NLINES; 52 50 int size_out = NPIXELS * NLINES; 53 51 … … 111 109 { 112 110 unsigned int index = (line*NPIXELS) + pixel; 113 buf_out[index] = (unsigned char)(buf_in[index]>>8); 114 // buf_out[index] = buf_in[index]; 111 buf_out[index] = buf_in[index]; 115 112 } 116 113 } -
trunk/user/ksh/ksh.c
r659 r676 58 58 59 59 #define DEBUG_MAIN 0 60 #define DEBUG_INTER 061 60 #define DEBUG_EXECUTE 0 62 61 #define DEBUG_CMD_CAT 0 … … 105 104 pthread_t trdid; // interactive thread identifier 106 105 106 char cmd[CMD_MAX_SIZE]; // buffer for one command 107 108 char elf_path[PATH_MAX_SIZE]; // pathname for cmd_load command 109 107 110 char pathname[PATH_MAX_SIZE]; // pathname for a file 108 111 109 char pathnew[PATH_MAX_SIZE]; // used by the rename command112 char pathnew[PATH_MAX_SIZE]; // used by the cmd_rename command 110 113 111 char string[ 128]; // used by snprintf() for debug114 char string[256]; // used by snprintf() for debug 112 115 113 116 ////////////////////////////////////////////////////////////////////////////////////////// … … 124 127 125 128 #if DEBUG_CMD_CAT 126 snprintf( string , 128 , "[ksh] %s enters" , __FUNCTION__); 127 display_string( string ); 129 printf("\n[ksh] %s enters" , __FUNCTION__); 128 130 #endif 129 131 … … 139 141 140 142 #if DEBUG_CMD_CAT 141 snprintf( string , 128 , "[ksh] %s : after strcpy" , __FUNCTION__ ); 142 display_string( string ); 143 printf("\n[ksh] %s : after strcpy" , __FUNCTION__ ); 143 144 #endif 144 145 … … 154 155 155 156 #if DEBUG_CMD_CAT 156 snprintf( string , 128 , "[ksh] %s : file %s open", __FUNCTION__, pathname ); 157 display_string( string ); 157 printf("\n[ksh] %s : file %s open", __FUNCTION__, pathname ); 158 158 #endif 159 159 … … 181 181 182 182 #if DEBUG_CMD_CAT 183 snprintf( string , 128 , "[ksh] %s : size = %d", 184 __FUNCTION__, size ); 185 display_string( string ); 183 printf("\n[ksh] %s : size = %d", __FUNCTION__, size ); 186 184 #endif 187 185 … … 208 206 209 207 #if DEBUG_CMD_CAT 210 snprintf( string , 128 , "[ksh] %s : mapped file %d to buffer %x", 211 __FUNCTION__, fd , buf ); 212 display_string( string ); 208 printf("\n[ksh] %s : mapped file %d to buffer %x", __FUNCTION__, fd , buf ); 213 209 #endif 214 210 … … 223 219 224 220 #if DEBUG_CMD_CAT 225 snprintf( string , 128 , "[ksh] %s : unmapped file %d from buffer %x", 226 __FUNCTION__, fd , buf ); 227 display_string( string ); 221 printf("\n[ksh] %s : unmapped file %d from buffer %x", __FUNCTION__, fd , buf ); 228 222 #endif 229 223 … … 273 267 274 268 #if DEBUG_CMD_CP 275 snprintf( string , 128 , "[ksh] enter %s" , __FUNCTION__); 276 display_string( string ); 269 printf("\n[ksh] enter %s" , __FUNCTION__); 277 270 #endif 278 271 … … 297 290 298 291 #if DEBUG_CMD_CP 299 snprintf( string , 128 , "[ksh] %s : file %s open", __FUNCTION__, argv[1] ); 300 display_string( string ); 292 printf("\n[ksh] %s : file %s open", __FUNCTION__, argv[1] ); 301 293 #endif 302 294 … … 310 302 311 303 #if DEBUG_CMD_CP 312 snprintf( string , 128 , "[ksh] %s : got stats for %s", __FUNCTION__, argv[1] ); 313 display_string( string ); 304 printf("\n[ksh] %s : got stats for %s", __FUNCTION__, argv[1] ); 314 305 #endif 315 306 … … 335 326 336 327 #if DEBUG_CMD_CP 337 snprintf( string , 128 , "[ksh] %s : file %s open", __FUNCTION__, argv[2] ); 338 display_string( string ); 328 printf("\n[ksh] %s : file %s open", __FUNCTION__, argv[2] ); 339 329 #endif 340 330 … … 346 336 347 337 #if DEBUG_CMD_CP 348 snprintf( string , 128 , "[ksh] %s : got stats for %s", __FUNCTION__, argv[2] ); 349 display_string( string ); 338 printf("\n[ksh] %s : got stats for %s", __FUNCTION__, argv[2] ); 350 339 #endif 351 340 … … 370 359 371 360 #if DEBUG_CMD_CP 372 snprintf( string , 128 , "[ksh] %s : read %d bytes from %s", __FUNCTION__, len, argv[1] ); 373 display_string( string ); 361 printf("\n[ksh] %s : read %d bytes from %s", __FUNCTION__, len, argv[1] ); 374 362 #endif 375 363 … … 382 370 383 371 #if DEBUG_CMD_CP 384 snprintf( string , 128 , "[ksh] %s : write %d bytes to %s", __FUNCTION__, len, argv[2] ); 385 display_string( string ); 372 printf("\n[ksh] %s : write %d bytes to %s", __FUNCTION__, len, argv[2] ); 386 373 #endif 387 374 … … 416 403 " display fat min nslots\n" 417 404 " display fat cxy 0\n" 418 " display socket pid fdid\n" ); 405 " display socket pid fdid\n" 406 " display fd pid\n" 407 " display fbf pid\n" ); 419 408 } 420 409 //////////////////////////////////// … … 578 567 } 579 568 } 580 ///////////////////////////////////////// //569 ///////////////////////////////////////// 581 570 else if( strcmp( argv[1] , "fat" ) == 0 ) 582 571 { … … 596 585 } 597 586 } 598 /////////////////////////////////////////// 587 //////////////////////////////////////////// 599 588 else if( strcmp( argv[1] , "socket" ) == 0 ) 600 589 { … … 614 603 } 615 604 } 605 //////////////////////////////////////// 606 else if( strcmp( argv[1] , "fd" ) == 0 ) 607 { 608 if( argc != 3 ) 609 { 610 printf(" usage: display fd pid\n"); 611 } 612 else 613 { 614 unsigned int pid = atoi(argv[2]); 615 616 if( display_fd_array( pid ) ) 617 { 618 printf(" error: cannot found process %x\n", pid ); 619 } 620 } 621 } 622 //////////////////////////////////////// 623 else if( strcmp( argv[1] , "fbf" ) == 0 ) 624 { 625 if( argc != 3 ) 626 { 627 printf(" usage: display fbf pid\n" 628 " display fbf 0 (all processes)"); 629 } 630 else 631 { 632 unsigned int pid = atoi(argv[2]); 633 634 if( display_fbf_windows( pid ) ) 635 { 636 printf(" error: cannot found process %x\n", pid ); 637 } 638 } 639 } 616 640 //// 617 641 else … … 632 656 if (argc != 2) 633 657 { 634 printf(" usage: %s pid\n", argv[0]);658 printf(" usage: fg pid\n"); 635 659 } 636 660 else … … 658 682 unsigned int i; 659 683 660 if (argc != 1)661 { 662 printf(" usage: %s\n", argv[0]);684 if( (argc != 1) || (argv[0] == NULL) ) 685 { 686 printf(" usage: help\n"); 663 687 } 664 688 else … … 676 700 } // end cmd_help() 677 701 702 ///////////////////////////////////////////////// 703 static void cmd_history( int argc , char **argv ) 704 { 705 unsigned int i; 706 707 if( (argc != 1) || (argv[0] == NULL) ) 708 { 709 printf(" usage: history\n"); 710 } 711 else 712 { 713 printf("--- registered commands ---\n"); 714 for (i = 0; i < LOG_DEPTH; i++) 715 { 716 printf(" - %d\t: %s\n", i, &log_entries[i].buf); 717 } 718 } 719 720 // release semaphore to get next command 721 sem_post( &semaphore ); 722 723 } // end cmd_history() 724 678 725 ////////////////////////////////////////////// 679 726 static void cmd_kill( int argc , char **argv ) … … 683 730 if (argc != 2) 684 731 { 685 printf(" usage: %spid\n", argv[0]);732 printf(" usage: kill pid\n", argv[0]); 686 733 } 687 734 else … … 710 757 int ret_fork; // return value from fork 711 758 int ret_exec; // return value from exec 712 unsigned int ksh_pid; // KSH process PID759 unsigned int cmd_ok; // command arguments acceptable 713 760 unsigned int background; // background execution if non zero 714 unsigned int placement; // placement specified if non zero 715 unsigned int cxy; // target cluster if placement specified 761 unsigned int place; // user placement if non zero 762 char * arg[5]; // array of pointers on main thread arguments 763 unsigned int args_nr; // number of aruments in this array 764 765 char undef[] = { "undefined" }; 766 767 // arguments analysis of argv[] array that contains at most 8 strings: 768 // - the two first arguments ("cmd_type" & "elf_path") are mandatory 769 // - the six next ("-pcxy","arg0","arg1","arg2","arg3","&") are optional 770 771 // analyse the optional arguments 772 if( argc == 2 ) // no optional arguments 773 { 774 cmd_ok = 1; 775 background = 0; 776 place = 0; 777 arg[0] = undef; 778 arg[1] = undef; 779 arg[2] = undef; 780 arg[3] = undef; 781 args_nr = 0; 782 } 783 else if( ((argc >= 4) && (argc <= 8)) && 784 (argv[2][0] == '-') && (argv[2][1] == 'p') && 785 (strcmp(argv[argc-1] , "&" ) == 0) ) // background, place, 0 to 4 args 786 { 787 cmd_ok = 1; 788 background = 1; 789 place = 0xFF000000 | atoi( argv[2] + 2 ); 790 arg[0] = (argc > 4) ? argv[3] : undef; 791 arg[1] = (argc > 5) ? argv[4] : undef; 792 arg[2] = (argc > 6) ? argv[5] : undef; 793 arg[3] = (argc > 7) ? argv[6] : undef; 794 args_nr = argc - 4; 795 } 796 else if( ((argc >= 3) && (argc <= 7)) && 797 (argv[2][0] == '-') && (argv[2][1] == 'p') && 798 (strcmp(argv[argc-1] , "&" ) != 0) ) // place, no background, 0 to 4 args 799 { 800 cmd_ok = 1; 801 background = 0; 802 place = 0xFF000000 | atoi( argv[2] + 2 ); 803 arg[0] = (argc > 3) ? argv[3] : undef; 804 arg[1] = (argc > 4) ? argv[4] : undef; 805 arg[2] = (argc > 5) ? argv[5] : undef; 806 arg[3] = (argc > 6) ? argv[6] : undef; 807 args_nr = argc - 3; 808 } 809 else if( ((argc >=3) && (argc <= 7)) && 810 ((argv[2][0] != '-') || (argv[2][1] != 'p')) && 811 (strcmp(argv[argc-1] , "&" ) == 0) ) // no place, background, 0 to 4 args 812 { 813 cmd_ok = 1; 814 background = 1; 815 place = 0; 816 arg[0] = (argc > 3) ? argv[2] : undef; 817 arg[1] = (argc > 4) ? argv[3] : undef; 818 arg[2] = (argc > 5) ? argv[4] : undef; 819 arg[3] = (argc > 6) ? argv[5] : undef; 820 args_nr = argc - 3; 821 } 822 else if( (argc >= 3) && (argc <= 6 ) ) // no place, no background, 0 to 4 args 823 { 824 cmd_ok = 1; 825 background = 0; 826 place = 0; 827 arg[0] = (argc > 2) ? argv[2] : undef; 828 arg[1] = (argc > 3) ? argv[3] : undef; 829 arg[2] = (argc > 4) ? argv[4] : undef; 830 arg[3] = (argc > 5) ? argv[5] : undef; 831 args_nr = argc - 2; 832 } 833 else // illegal optional arguments 834 { 835 cmd_ok = 0; 836 background = 0; 837 place = 0; 838 arg[0] = undef; 839 arg[1] = undef; 840 arg[2] = undef; 841 arg[3] = undef; 842 args_nr = 0; 843 } 844 845 // check syntax errors 846 if( cmd_ok == 0 ) 847 { 848 printf(" usage: load elf_path [-pcxy] [arg0] [arg1] [arg2] [arg3] [&]\n"); 849 850 // release semaphore to get next command 851 sem_post( &semaphore ); 852 853 return; 854 } 855 856 // get elf_path 857 strcpy( elf_path , argv[1] ); 716 858 717 859 #if DEBUG_CMD_LOAD 718 snprintf( string , 128 , "[ksh] enter %s" , __FUNCTION__); 719 display_string( string ); 720 #endif 721 722 if( (argc < 2) || (argc > 4) ) 723 { 724 printf(" usage: %s pathname [cxy] [&]\n", argv[0] ); 725 } 726 else 727 { 728 strcpy( pathname , argv[1] ); 729 730 if( argc == 2 ) 731 { 732 background = 0; 733 placement = 0; 734 cxy = 0; 735 } 736 else if( argc == 3 ) 737 { 738 if( (argv[2][0] == '&') && (argv[2][1] == 0) ) 739 { 740 background = 1; 741 placement = 0; 742 cxy = 0; 743 } 744 else 745 { 746 background = 0; 747 placement = 1; 748 cxy = atoi( argv[2] ); 749 } 750 } 751 else // argc == 4 752 { 753 background = ( (argv[3][0] == '&') && (argv[3][1] == 0) ); 754 placement = 1; 755 cxy = atoi( argv[2] ); 756 } 757 758 // get KSH process PID 759 ksh_pid = getpid(); 860 printf("\n[ksh] %s : path <%s> / place %x / args_nr %d / bg %d\n" 861 " arg0 %s / arg1 %s / arg2 %s / arg3 %s\n", 862 __FUNCTION__, elf_path , place , args_nr , background , arg[0] , arg[1] , arg[2] , arg[3] ); 863 #endif 864 865 // set NULL pointers in args[] array 866 if ( arg[0] == undef ) arg[0] = NULL; 867 else if( arg[1] == undef ) arg[1] = NULL; 868 else if( arg[2] == undef ) arg[2] = NULL; 869 else if( arg[3] == undef ) arg[3] = NULL; 870 else arg[4] = NULL; 871 872 // set target cluster if required 873 if( place ) place_fork( place & 0xFFFF ); 874 875 // KSH process fork CHILD process 876 ret_fork = fork(); 877 878 if ( ret_fork < 0 ) // it is a failure reported to KSH 879 { 880 printf(" error: ksh process unable to fork\n"); 881 } 882 else if (ret_fork == 0) // it is the CHILD process 883 { 760 884 761 885 #if DEBUG_CMD_LOAD 762 snprintf( string , 128 , "[ksh] %s : <%s> / bg %d / place %d / cxy %x", 763 __FUNCTION__, argv[1], background, placement, cxy ); 764 display_string( string ); 765 #endif 766 767 // set target cluster if required 768 if( placement ) place_fork( cxy ); 769 770 // KSH process fork CHILD process 771 ret_fork = fork(); 772 773 if ( ret_fork < 0 ) // it is a failure reported to KSH 774 { 775 printf(" error: ksh process unable to fork\n"); 776 } 777 else if (ret_fork == 0) // it is the CHILD process 778 { 886 printf("\n[ksh] %s : child (pid %x) after fork, before exec\n", 887 __FUNCTION__ , getpid() ); 888 #endif 889 890 // CHILD process exec NEW process 891 ret_exec = execve( elf_path , arg , NULL ); 779 892 780 893 #if DEBUG_CMD_LOAD 781 snprintf( string , 128 , "[ksh] %s : child (%x) after fork, before exec", 782 __FUNCTION__ , getpid() ); 783 display_string( string ); 784 #endif 785 786 // CHILD process exec NEW process 787 ret_exec = execve( pathname , NULL , NULL ); 894 printf("\n[ksh] %s : child (pid %x) after exec / ret_exec %x\n", 895 __FUNCTION__, getpid(), ret_exec ); 896 #endif 897 898 // this is only executed in case of exec failure 899 if( ret_exec ) 900 { 901 printf(" error: child process unable to exec <%s>\n", pathname ); 902 exit( 0 ); 903 } 904 } 905 else // it is the KSH process : ret_fork is the new process PID 906 { 788 907 789 908 #if DEBUG_CMD_LOAD 790 snprintf( string , 128 , "[ksh] %s : child (%x) after exec / ret_exec %x", 791 __FUNCTION__ , getpid(), ret_exec ); 792 display_string( string ); 793 #endif 794 795 // this is only executed in case of exec failure 796 if( ret_exec ) 797 { 798 printf(" error: child process unable to exec <%s>\n", pathname ); 799 exit( 0 ); 800 } 801 } 802 else // it is the KSH process : ret_fork is the new process PID 803 { 804 805 #if DEBUG_CMD_LOAD 806 snprintf( string , 128 , "[ksh] %s : ksh (%x) after fork / ret_fork %x", 807 __FUNCTION__, getpid(), ret_fork ); 808 display_string( string ); 809 #endif 810 // when the new process is launched in background, the KSH process 811 // takes the TXT ownership, and release the semaphore to get the next command. 812 // Otherwise, the child process keep the TXT ownership, and the semaphore will 813 // be released by the KSH main thread when the child process exit 814 815 if( background ) // KSH must keep TXT ownership 816 { 817 // get back the TXT ownership 818 fg( ksh_pid ); 819 820 // release semaphore to get next command 821 sem_post( &semaphore ); 822 } 909 printf("\n[ksh] %s : ksh (pid %x) after fork / ret_fork %x\n", 910 __FUNCTION__, getpid(), ret_fork ); 911 #endif 912 // when the new process is launched in background, the KSH process 913 // takes the TXT ownership, and releases the semaphore to get the next command. 914 // Otherwise, the child process keep the TXT ownership, and the semaphore will 915 // be released by the KSH main thread when the child process exit 916 917 if( background ) // KSH must keep TXT ownership 918 { 919 // KSH get back the TXT ownership 920 fg( getpid() ); 921 922 // release semaphore to get next command 923 sem_post( &semaphore ); 823 924 } 824 925 } 825 926 } // end cmd_load 826 827 /////////////////////////////////////////////828 static void cmd_log( int argc , char **argv )829 {830 unsigned int i;831 832 if (argc != 1)833 {834 printf(" usage: %s\n", argv[0], argc );835 }836 else837 {838 printf("--- registered commands ---\n");839 for (i = 0; i < LOG_DEPTH; i++)840 {841 printf(" - %d\t: %s\n", i, &log_entries[i].buf);842 }843 }844 845 // release semaphore to get next command846 sem_post( &semaphore );847 848 } // end cmd_log()849 850 927 851 928 //////////////////////////////////////////// … … 856 933 857 934 #if DEBUG_CMD_LS 858 snprintf( string , 128 , "[ksh] enter %s" , __FUNCTION__); 859 display_string( string ); 935 printf("\n[ksh] enter %s" , __FUNCTION__); 860 936 #endif 861 937 … … 876 952 877 953 #if DEBUG_CMD_LS 878 snprintf( string , 128 , "[ksh] %s : directory <%s> open / DIR %x", 879 __FUNCTION__, pathname , dir ); 880 display_string( string ); 954 printf("\n[ksh] %s : directory <%s> open / DIR %x", __FUNCTION__, pathname , dir ); 881 955 #endif 882 956 … … 899 973 900 974 #if DEBUG_CMD_LS 901 snprintf( string , 128 , "[ksh] %s : directory <%s> closed", 902 __FUNCTION__, pathname ); 903 display_string( string ); 975 printf("\n[ksh] %s : directory <%s> closed", __FUNCTION__, pathname ); 904 976 #endif 905 977 … … 964 1036 965 1037 #if DEBUG_CMD_PS 966 snprintf( string , 128 , "[ksh] enter %s" , __FUNCTION__); 967 display_string( string ); 968 #endif 969 970 if (argc != 1) 971 { 972 printf(" usage: %s\n", argv[0]); 1038 printf("\n[ksh] enter %s" , __FUNCTION__); 1039 #endif 1040 1041 if( (argc != 1) || (argv[0] == NULL) ) 1042 { 1043 printf(" usage: ps\n"); 973 1044 } 974 1045 else … … 987 1058 988 1059 #if DEBUG_CMD_PS 989 snprintf( string , 128 , "\n[ksh] %s : call display_cluster_process()", __FUNCTION__ ); 990 display_string( string ); 1060 printf("\n[ksh] %s : call display_cluster_process()", __FUNCTION__ ); 991 1061 #endif 992 1062 … … 1005 1075 static void cmd_pwd( int argc , char **argv ) 1006 1076 { 1007 if (argc != 1)1008 { 1009 printf(" usage: %s\n", argv[0]);1077 if( (argc != 1) || (argv[0] == NULL) ) 1078 { 1079 printf(" usage: pwd\n"); 1010 1080 } 1011 1081 else … … 1031 1101 if (argc != 2) 1032 1102 { 1033 printf(" usage: %s pathname\n", argv[0]);1103 printf(" usage: rm pathname\n"); 1034 1104 } 1035 1105 else … … 1056 1126 if (argc != 2) 1057 1127 { 1058 printf(" usage: %s pathname\n", argv[0]);1128 printf(" usage: stat pathname\n"); 1059 1129 } 1060 1130 else … … 1084 1154 static void cmd_rmdir( int argc , char **argv ) 1085 1155 { 1086 // same as cmd_rm() 1087 cmd_rm (argc , argv ); 1088 } 1156 if (argc != 2) 1157 { 1158 printf(" usage: rmdir pathname\n"); 1159 } 1160 else 1161 { 1162 strcpy( pathname , argv[1] ); 1163 1164 if ( unlink( pathname ) ) 1165 { 1166 printf(" error: unable to remove <%s>\n", pathname ); 1167 } 1168 } 1169 1170 // release semaphore to get next command 1171 sem_post( &semaphore ); 1172 1173 } // end cmd_rmdir() 1089 1174 1090 1175 /////////////////////////////////////////////// … … 1153 1238 { "load", "load an user application", cmd_load }, 1154 1239 { "help", "list available commands", cmd_help }, 1240 { "history", "list registered commands", cmd_history }, 1155 1241 { "kill", "kill a process (all threads)", cmd_kill }, 1156 { "log", "list registered commands", cmd_log },1157 1242 { "ls", "list directory entries", cmd_ls }, 1158 1243 { "mkdir", "create a new directory", cmd_mkdir }, … … 1179 1264 1180 1265 #if DEBUG_EXECUTE 1181 snprintf( string , 128 , "[ksh] enter %s for command <%s>" , __FUNCTION__ , buf ); 1182 display_string( string ); 1183 #endif 1184 1185 // build argc/argv 1266 printf("\n[ksh] enter %s for command <%s>" , __FUNCTION__ , buf ); 1267 #endif 1268 1269 // build argc/argv : 1270 // arg[0] is the command type 1271 // - other arg[i] are the command arguments 1272 1186 1273 for (i = 0; i < len; i++) 1187 1274 { … … 1209 1296 1210 1297 #if DEBUG_EXECUTE 1211 snprintf( string , 128 , "\n[ksh] in %s : argc = %d / arg0 = %s / arg1 = %s", 1212 __FUNCTION__ , argc , argv[0], argv[1] ); 1298 printf("\n[ksh] in %s : argc = %d / type = %s", __FUNCTION__ , argc , argv[0] ); 1213 1299 #endif 1214 1300 … … 1245 1331 unsigned int state; // escape sequence state 1246 1332 1247 char cmd[CMD_MAX_SIZE]; // buffer for one command1248 1333 1249 1334 /* direct command to help debug 1250 1335 1251 int pid = getpid(); 1252 1253 if( pid == 3 ) 1336 if( getpid() == 2 ) 1254 1337 { 1255 1338 if( sem_wait( &semaphore ) ) … … 1260 1343 else 1261 1344 { 1262 strcpy( cmd , "load bin/user/ tcp_server.elf" );1345 strcpy( cmd , "load bin/user/chat.elf 0" ); 1263 1346 printf("[ksh] %s\n", cmd ); 1264 1347 execute( cmd ); 1265 1348 } 1266 1349 } 1267 else if( getpid() == 4 ) 1350 1351 else if( getpid() == 3 ) 1268 1352 { 1269 1353 if( sem_wait( &semaphore ) ) … … 1274 1358 else 1275 1359 { 1276 strcpy( cmd , "load bin/user/ tcp_client.elf" );1360 strcpy( cmd , "load bin/user/chat.elf 1" ); 1277 1361 printf("[ksh] %s\n", cmd ); 1278 1362 execute( cmd ); … … 1281 1365 1282 1366 */ 1283 1284 1367 1285 1368 enum fsm_states … … 1318 1401 state = NORMAL; 1319 1402 end_command = 0; 1320 1321 #if DEBUG_INTER1322 snprintf( string , 128 , "[ksh] %s : request a new command", __FUNCTION__ );1323 display_string( string );1324 #endif1325 1403 1326 1404 // internal loop on characters in one command … … 1349 1427 cmd[count] = 0; 1350 1428 count++; 1351 #if DEBUG_INTER 1352 snprintf( string , 128 , "[ksh] %s : get command <%s>", __FUNCTION__, cmd ); 1353 display_string( string ); 1354 #endif 1429 1355 1430 // register command in log_entries[] array 1356 1431 strncpy( log_entries[ptw].buf , cmd , count ); … … 1359 1434 ptr = ptw; 1360 1435 1361 #if DEBUG_INTER1362 snprintf( string , 128 , "[ksh] %s : execute <%s>", __FUNCTION__, cmd );1363 display_string( string );1364 #endif1365 1436 // echo character 1366 1437 putchar( c ); … … 1479 1550 } // end internal while loop on characters 1480 1551 1481 #if DEBUG_INTER1482 snprintf( string , 128 , "\n[ksh] %s : complete <%s> command", __FUNCTION__, cmd );1483 display_string( string );1484 #endif1485 1486 1552 // block interactive thread if KSH loose TXT ownership 1487 1553 if ( sem_wait( &semaphore ) ) … … 1518 1584 1519 1585 #if DEBUG_MAIN 1520 snprintf( string , 128 , "\n[ksh] main thread started on core[%x,%d]", cxy , lid ); 1521 display_string( string ); 1586 printf("\n[ksh] main started on core[%x,%d]", cxy , lid ); 1522 1587 #endif 1523 1588 … … 1530 1595 1531 1596 #if DEBUG_MAIN 1532 snprintf( string , 128 , "\n[ksh] main initialized semaphore" ); 1533 display_string( string ); 1597 printf("\n[ksh] main initialized semaphore" ); 1534 1598 #endif 1535 1599 … … 1544 1608 NULL ); 1545 1609 #if DEBUG_MAIN 1546 snprintf( string , 128 , "\n[ksh] main thread launched interactive thread %x", trdid ); 1547 display_string( string ); 1610 printf("\n[ksh] main thread launched interactive thread %x", trdid ); 1548 1611 #endif 1549 1612 -
trunk/user/sort/sort.c
r659 r676 54 54 #include <hal_macros.h> 55 55 56 #define ARRAY_LENGTH 2048// number of items56 #define ARRAY_LENGTH 64 // number of items 57 57 #define MAX_THREADS 1024 // 16 * 16 * 4 58 58 -
trunk/user/tcp_client/tcp_client.c
r660 r676 39 39 size = get_string( buffer , BUF_SIZE ); 40 40 41 /*42 strcpy( buffer , "blip\n" );43 printf("%s", buffer );44 size = 5;45 46 if( send( fdid , buffer , size , 0 ) != size )47 {48 printf("\n[server] chat error : cannotl sent message\n");49 return;50 }51 */52 53 41 // exit chat function when local message is the "exit" string 54 42 if( strncmp( "exit" , buffer , 4 ) == 0 ) 55 43 { 44 printf("\n[tcp_client stop] local message is <exit> => return to main\n" ); 56 45 return; 57 46 } … … 62 51 if( nbytes != size ) 63 52 { 64 printf("\n[ server] send error => chatreturn to main\n");53 printf("\n[tcp_client error] cannot send => return to main\n"); 65 54 return; 66 55 } … … 70 59 71 60 // receive server message 72 nbytes = recv ( fdid, buffer, BUF_SIZE, 0 );61 nbytes = recv( fdid , buffer , BUF_SIZE , 0 ); 73 62 74 63 if( nbytes < 0 ) 75 64 { 76 printf("\n\n[ server] receive error=> return to main\n" );65 printf("\n\n[tcp_client error] cannot receive => return to main\n" ); 77 66 return; 78 67 } 79 68 else if( nbytes == 0 ) 80 69 { 81 printf("\n\n[ server] receive EOF => return to main\n" );70 printf("\n\n[tcp_client stop] receive EOF => return to main\n" ); 82 71 return; 83 72 } … … 105 94 // get start cycle 106 95 get_cycle( &start_cycle ); 107 printf("\n[ client] starts at cycle %d\n", (unsigned int)start_cycle );96 printf("\n[tcp_client] starts at cycle %d\n", (unsigned int)start_cycle ); 108 97 109 98 pid = getpid(); … … 116 105 if( fdid < 0 ) 117 106 { 118 printf("\n[ client error] cannot create socket\n");107 printf("\n[tcp_client error] cannot create socket\n"); 119 108 exit( 0 ); 120 109 } 121 110 else 122 111 { 123 printf("\n[ client] created socket[%x,%d]\n", pid, fdid );112 printf("\n[tcp_client] created socket[%x,%d]\n", pid, fdid ); 124 113 } 125 114 … … 134 123 if( error ) 135 124 { 136 printf("\n[ client error] bind failure on socketi[%x,%d]\n", pid, fdid );125 printf("\n[tcp_client error] bind failure on socketi[%x,%d]\n", pid, fdid ); 137 126 exit( 0 ); 138 127 } 139 128 140 printf("\n[ client] socket[%x,%d] bound : [%x,%x]\n",129 printf("\n[tcp_client] socket[%x,%d] bound : [%x,%x]\n", 141 130 pid, fdid, client_sin.sin_addr, (unsigned int)client_sin.sin_port ); 142 131 … … 151 140 if( error ) 152 141 { 153 printf("\n[ client error] connect failure on socket[%x,%d]\n", pid, fdid );142 printf("\n[tcp_client error] connect failure on socket[%x,%d]\n", pid, fdid ); 154 143 exit( 0 ); 155 144 } 156 145 157 printf("\n[ client] socket[%x,%d] connected to server [%x,%x]\n",146 printf("\n[tcp_client] socket[%x,%d] connected to server [%x,%x]\n", 158 147 pid, fdid, server_sin.sin_addr, server_sin.sin_port ); 159 148 … … 164 153 close( fdid ); 165 154 166 printf("\n[ client] closed socket[%x,%d]\n", pid, fdid );155 printf("\n[tcp_client] closed socket[%x,%d]\n", pid, fdid ); 167 156 168 157 exit(0); -
trunk/user/tcp_server/tcp_server.c
r668 r676 40 40 if( nbytes < 0 ) 41 41 { 42 printf("\n\n[ server] receive error=> return to main\n" );42 printf("\n\n[tcp_server error] cannot receive => return to main\n" ); 43 43 return; 44 44 } 45 45 else if( nbytes == 0 ) 46 46 { 47 printf("\n\n[ server] receiveEOF => return to main\n" );47 printf("\n\n[tcp_server stop] received EOF => return to main\n" ); 48 48 return; 49 49 } … … 61 61 if( strncmp( "exit" , buffer , 4 ) == 0 ) 62 62 { 63 printf("\n[tcp_server stop] local message is <exit> => return to main\n" ); 63 64 return; 64 65 } … … 69 70 if( nbytes != size ) 70 71 { 71 printf("\n[ server] send error => chatreturn to main\n" );72 printf("\n[tcp_server error] cannot send => return to main\n" ); 72 73 return; 73 74 } … … 97 98 pid = getpid(); 98 99 99 printf("\n[ server] starts at cycle %d\n",100 printf("\n[tcp_server] starts at cycle %d\n", 100 101 (unsigned int)start_cycle ); 101 102 … … 107 108 if( listen_fdid < 0 ) 108 109 { 109 printf("\n[ server error] cannot create socket\n");110 printf("\n[tcp_server error] cannot create socket\n"); 110 111 exit( 0 ); 111 112 } 112 113 else 113 114 { 114 printf("\n[ server] created socket[%x,%d]\n", pid, listen_fdid );115 printf("\n[tcp_server] created socket[%x,%d]\n", pid, listen_fdid ); 115 116 } 116 117 … … 125 126 if( error ) 126 127 { 127 printf("\n[ server error] bind failure for socket[%x,%d]\n",128 printf("\n[tcp_server error] bind failure for socket[%x,%d]\n", 128 129 pid, listen_fdid ); 129 130 exit( 0 ); 130 131 } 131 132 132 printf("\n[ server] listening socket[%x,%d] bound : [%x,%x]\n",133 printf("\n[tcp_server] listening socket[%x,%d] bound : [%x,%x]\n", 133 134 pid, listen_fdid, server_sin.sin_addr, server_sin.sin_port ); 134 135 … … 138 139 if( error ) 139 140 { 140 printf("\n[ server error] listen failure for socket[%x,%d]\n",141 printf("\n[tcp_server error] listen failure for socket[%x,%d]\n", 141 142 pid, listen_fdid ); 142 143 exit( 0 ); 143 144 } 144 145 145 printf("\n[ server] listening socket[%x,%d] waiting connection request\n",146 printf("\n[tcp_server] listening socket[%x,%d] waiting connection request\n", 146 147 pid, listen_fdid ); 147 148 … … 153 154 if( chat_fdid < 0 ) 154 155 { 155 printf("\n[ server error] accept failure on socket[%x,%d]\n",156 printf("\n[tcp_server error] accept failure on socket[%x,%d]\n", 156 157 pid, listen_fdid ); 157 158 exit( 0 ); 158 159 } 159 160 160 printf("\n[ server] chat socket[%x,%d] accepted client [%x,%x]\n",161 printf("\n[tcp_server] chat socket[%x,%d] accepted client [%x,%x]\n", 161 162 pid, chat_fdid , client_sin.sin_addr , client_sin.sin_port ); 162 163 … … 168 169 close( listen_fdid ); 169 170 170 printf("\n[ server] closed both <listen> & <chat> sockets\n" );171 printf("\n[tcp_server] closed both <listen> & <chat> sockets\n" ); 171 172 172 173 exit(0); -
trunk/user/transpose/transpose.c
r659 r676 56 56 // local buf_in[cid] buffer, and write pixels to all remote // buf_out[cid] buffers. 57 57 // 58 // - The image must fit the frame buffer size, that must be power of 2.58 // - The image must have [nlines = npixels = IMAGE_SIZE], and cannot exceed the FBF size. 59 59 // - The number of clusters must be a power of 2 no larger than 256. 60 60 // - The number of cores per cluster must be a power of 2 no larger than 4. … … 80 80 81 81 #define IMAGE_TYPE 420 // pixel encoding type 82 83 //#define IMAGE_SIZE 128 // image size 84 //#define INPUT_FILE_PATH "/misc/images_128.raw" // input file pathname 85 //#define OUTPUT_FILE_PATH "/misc/transposed_128.raw" // output file pathname 86 87 //#define IMAGE_SIZE 256 // image size 88 //#define INPUT_FILE_PATH "/misc/lena_256.raw" // input file pathname 89 #//define OUTPUT_FILE_PATH "/misc/transposed_256.raw" // output file pathname 90 91 //#define IMAGE_SIZE 512 // image size 92 //#define INPUT_FILE_PATH "/misc/couple_512.raw" // input file pathname 93 //#define OUTPUT_FILE_PATH "/misc/transposed_512.raw" // output file pathname 94 95 #define IMAGE_SIZE 1024 // image size 96 #define INPUT_FILE_PATH "/misc/philips_1024.raw" // input file pathname 97 #define OUTPUT_FILE_PATH "/misc/transposed_1024.raw" // output file pathname 98 99 #define SAVE_RESULT_FILE 0 // save result image on disk 82 #define IMAGE_SIZE 256 // default image size 83 #define INPUT_IMAGE_PATH "/misc/lena_256.raw" // default input image pathname 84 #define OUTPUT_IMAGE_PATH "/misc/lena_trsp_256.raw" // default output image pathname 85 86 #define SAVE_RESULT_FILE 1 // save result image on disk 100 87 #define USE_DQT_BARRIER 0 // quad-tree barrier if non zero 101 88 … … 108 95 #define VERBOSE_EXEC 1 // exec function print comments 109 96 97 #define INTERACTIVE_MODE 1 110 98 111 99 /////////////////////////////////////////////////////// … … 140 128 unsigned char * buf_out[CLUSTERS_MAX]; 141 129 142 // pointer and identifier for dynamically allocated FBF window 143 void * win_buf; 144 int wid; 130 // pointer and identifier for FBF windows 131 void * in_win_buf; 132 int in_wid; 133 void * out_win_buf; 134 int out_wid; 145 135 146 136 // synchronisation barrier (all working threads) … … 167 157 // array of thread attributes / indexed by [tid] 168 158 pthread_attr_t exec_attr[THREADS_MAX]; 159 160 // image features 161 unsigned int image_size; 162 char input_image_path[128]; 163 char output_image_path[128]; 169 164 170 165 //////////////////////////////////////////////////////////////// … … 234 229 unsigned int nthreads = nclusters * ncores; 235 230 236 if( nthreads > IMAGE_SIZE ) 237 { 238 printf("\n[transpose error] number of threads larger than number of lines\n"); 239 exit( 0 ); 231 // get input and output images path and size 232 if( INTERACTIVE_MODE ) 233 { 234 printf("\n - image size : "); 235 get_uint32( &image_size ); 236 237 printf("\n - input image path : "); 238 get_string( input_image_path , 128 ); 239 240 printf(" - output image path : "); 241 get_string( output_image_path , 128 ); 242 } 243 else 244 { 245 image_size = IMAGE_SIZE; 246 strcpy( input_image_path , INPUT_IMAGE_PATH ); 247 strcpy( input_image_path , OUTPUT_IMAGE_PATH ); 240 248 } 241 249 242 250 // get FBF size and type 243 unsignedint fbf_width;244 unsignedint fbf_height;245 unsignedint fbf_type;251 int fbf_width; 252 int fbf_height; 253 int fbf_type; 246 254 fbf_get_config( &fbf_width , &fbf_height , &fbf_type ); 247 255 248 if( (fbf_width < IMAGE_SIZE) || (fbf_height < IMAGE_SIZE) || (fbf_type != IMAGE_TYPE) ) 249 { 250 printf("\n[transpose error] image does not fit FBF size or type\n"); 256 // check image 257 if( nthreads > image_size ) 258 { 259 printf("\n[transpose error] nthreads (%d) larger than image size (%d)\n", 260 nthreads , image_size ); 261 exit( 0 ); 262 } 263 264 if( ((unsigned int)fbf_width < image_size) || 265 ((unsigned int)fbf_height < image_size) || 266 (fbf_type != IMAGE_TYPE) ) 267 { 268 printf("\n[transpose error] image not acceptable\n" 269 "FBF width = %d / npixels = %d\n" 270 "FBF height = %d / nlines = %d\n" 271 "FBF type = %d / expected = %d\n", 272 fbf_width, image_size, fbf_height, image_size, fbf_type, IMAGE_TYPE ); 251 273 exit( 0 ); 252 274 } 253 275 254 276 // define total number of pixels 255 int npixels = IMAGE_SIZE * IMAGE_SIZE;277 int npixels = image_size * image_size; 256 278 257 279 // define instrumentation file name … … 259 281 { 260 282 printf("\n[transpose] %d cluster(s) / %d core(s) / <%s> / PID %x / NO_PLACE\n", 261 nclusters, ncores, INPUT_FILE_PATH, getpid() );283 nclusters, ncores, input_image_path, getpid() ); 262 284 263 285 // build instrumentation file name 264 286 if( USE_DQT_BARRIER ) 265 287 snprintf( filename , 32 , "trsp_dqt_no_place_%d_%d_%d", 266 IMAGE_SIZE, x_size * y_size , ncores );288 image_size , x_size * y_size , ncores ); 267 289 else 268 290 snprintf( filename , 32 , "trsp_smp_no_place_%d_%d_%d", 269 IMAGE_SIZE, x_size * y_size , ncores );291 image_size , x_size * y_size , ncores ); 270 292 } 271 293 … … 273 295 { 274 296 printf("\n[transpose] %d cluster(s) / %d core(s) / <%s> / PID %x / EXPLICIT\n", 275 nclusters, ncores, INPUT_FILE_PATH, getpid() );297 nclusters, ncores, input_image_path, getpid() ); 276 298 277 299 // build instrumentation file name 278 300 if( USE_DQT_BARRIER ) 279 301 snprintf( filename , 32 , "trsp_dqt_explicit_%d_%d_%d", 280 IMAGE_SIZE, x_size * y_size , ncores );302 image_size , x_size * y_size , ncores ); 281 303 else 282 304 snprintf( filename , 32 , "trsp_smp_explicit_%d_%d_%d", 283 IMAGE_SIZE, x_size * y_size , ncores );305 image_size , x_size * y_size , ncores ); 284 306 } 285 307 … … 287 309 { 288 310 printf("\n[transpose] %d cluster(s) / %d core(s) / <%s> / PID %x / PARALLEL\n", 289 nclusters, ncores, INPUT_FILE_PATH, getpid() );311 nclusters, ncores, input_image_path, getpid() ); 290 312 291 313 // build instrumentation file name 292 314 if( USE_DQT_BARRIER ) 293 315 snprintf( filename , 32 , "trsp_dqt_parallel_%d_%d_%d", 294 IMAGE_SIZE, x_size * y_size , ncores );316 image_size , x_size * y_size , ncores ); 295 317 else 296 318 snprintf( filename , 32 , "trsp_smp_parallel_%d_%d_%d", 297 IMAGE_SIZE , x_size * y_size , ncores ); 298 } 299 300 // open a window in FBF 301 wid = fbf_create_window( 0, // l_zero 302 0, // p_zero 303 IMAGE_SIZE, // lines 304 IMAGE_SIZE, // pixels 305 &win_buf ); 306 if( wid < 0) 307 { 308 printf("\n[transpose error] cannot open FBF window\n"); 319 image_size , x_size * y_size , ncores ); 320 } 321 322 // create an FBF window for input image 323 in_wid = fbf_create_window( 0, // l_zero 324 0, // p_zero 325 image_size, // lines 326 image_size, // pixels 327 &in_win_buf ); // pointer on buffer in user space 328 if( in_wid < 0) 329 { 330 printf("\n[transpose error] cannot create window for %s\n", input_image_path ); 331 exit( 0 ); 332 } 333 334 // activate window 335 error = fbf_active_window( in_wid , 1 ); 336 337 if( error ) 338 { 339 printf("\n[transpose error] cannot activate window for %s\n", input_image_path ); 309 340 exit( 0 ); 310 341 } 311 342 312 343 #if VERBOSE_MAIN 313 printf("\n[transpose] main on core[%x,%d] created FBF window %d / buffer %x\n", 314 cxy_main, lid_main, wid , win_buf ); 344 printf("\n[transpose] main on core[%x,%d] created window for %s / wid %d / buf %x\n", 345 cxy_main, lid_main, input_image_path, in_wid , in_win_buf ); 346 #endif 347 348 // create an FBF window for output image 349 out_wid = fbf_create_window( image_size, // l_zero 350 image_size, // p_zero 351 image_size, // lines 352 image_size, // pixels 353 &out_win_buf ); // pointer on buffer in user space 354 if( out_wid < 0) 355 { 356 printf("\n[transpose error] cannot create window for %s\n", output_image_path ); 357 exit( 0 ); 358 } 359 360 // activate window 361 error = fbf_active_window( out_wid , 1 ); 362 363 if( error ) 364 { 365 printf("\n[transpose error] cannot activate window for %s\n", output_image_path ); 366 exit( 0 ); 367 } 368 369 #if VERBOSE_MAIN 370 printf("\n[transpose] main on core[%x,%d] created window for %s / wid %d / buf %x\n", 371 cxy_main, lid_main, output_image_path, out_wid , out_win_buf ); 315 372 #endif 316 373 … … 356 413 357 414 // open input file 358 int fd_in = open( INPUT_FILE_PATH, O_RDONLY , 0 );415 int fd_in = open( input_image_path , O_RDONLY , 0 ); 359 416 360 417 if ( fd_in < 0 ) 361 418 { 362 printf("\n[transpose error] main cannot open file %s\n", INPUT_FILE_PATH);419 printf("\n[transpose error] main cannot open file %s\n", input_image_path ); 363 420 exit( 0 ); 364 421 } 365 422 366 423 #if VERBOSE_MAIN 367 printf("\n[transpose] main open file <%s> / fd = %d\n", INPUT_FILE_PATH, fd_in );424 printf("\n[transpose] main open file <%s> / fd = %d\n", input_image_path , fd_in ); 368 425 #endif 369 426 370 427 // open output file 371 int fd_out = open( OUTPUT_FILE_PATH, O_CREAT , 0 );428 int fd_out = open( output_image_path , O_CREAT , 0 ); 372 429 373 430 if ( fd_out < 0 ) 374 431 { 375 printf("\n[transpose error] main cannot open file %s\n", OUTPUT_FILE_PATH);432 printf("\n[transpose error] main cannot open file %s\n", output_image_path ); 376 433 exit( 0 ); 377 434 } … … 385 442 386 443 #if VERBOSE_MAIN 387 printf("\n[transpose] main moved file <%s> to buf_in\n", INPUT_FILE_PATH);444 printf("\n[transpose] main moved file <%s> to buf_in\n", input_image_path ); 388 445 #endif 389 446 … … 621 678 #endif 622 679 623 // delete FBF window 624 if( fbf_delete_window( wid ) ) 680 // delete FBF windows 681 if( fbf_delete_window( in_wid ) ) 682 if( fbf_delete_window( out_wid ) ) 625 683 { 626 684 printf("\n[transpose error] main cannot delete FBF window\n"); 627 685 exit( 0 ); 628 686 } 687 688 #if VERBOSE_MAIN 689 printf("\n[transpose] main deleted FBF windows\n"); 690 #endif 629 691 630 692 // main thread suicide … … 634 696 635 697 } // end main() 698 699 700 701 636 702 637 703 … … 646 712 int error; 647 713 648 unsigned char * wbuf = win_buf;649 650 714 pthread_parallel_work_args_t * args = (pthread_parallel_work_args_t *)arguments; 651 715 … … 678 742 679 743 // compute total number of pixels per image 680 unsigned int npixels = IMAGE_SIZE * IMAGE_SIZE;744 unsigned int npixels = image_size * image_size; 681 745 682 746 // compute total number of threads and clusters … … 689 753 690 754 // compute first and last line per thread 691 unsigned int lines_per_cid = pixels_per_cid / IMAGE_SIZE;692 unsigned int lines_per_lid = pixels_per_lid / IMAGE_SIZE;755 unsigned int lines_per_cid = pixels_per_cid / image_size; 756 unsigned int lines_per_lid = pixels_per_lid / image_size; 693 757 694 758 unsigned int line_first = (cid * lines_per_cid) + (lid * lines_per_lid); … … 751 815 752 816 // all local threads copy part of buf_in[cid] to FBF window for display 753 memcpy( wbuf + (cid * pixels_per_cid) + (lid * pixels_per_lid),817 memcpy( in_win_buf + (cid * pixels_per_cid) + (lid * pixels_per_lid), 754 818 buf_in[cid] + (lid * pixels_per_lid), 755 819 pixels_per_lid ); … … 760 824 #endif 761 825 762 // retresh window763 error = fbf_refresh_window( wid , line_first , line_last );826 // all threads contribute to input window refresh 827 error = fbf_refresh_window( in_wid , line_first , line_last ); 764 828 765 829 if( error ) … … 785 849 // (l,p) are the absolute pixel coordinates in the dest image 786 850 787 unsigned int nlt = IMAGE_SIZE/ nthreads; // number of lines per thread788 unsigned int nlc = IMAGE_SIZE/ nclusters; // number of lines per cluster851 unsigned int nlt = image_size / nthreads; // number of lines per thread 852 unsigned int nlc = image_size / nclusters; // number of lines per cluster 789 853 790 854 unsigned int src_cid; … … 802 866 { 803 867 // loop on pixels in one line (one pixel per iteration) 804 for ( p = 0 ; p < IMAGE_SIZE; p++ )868 for ( p = 0 ; p < image_size ; p++ ) 805 869 { 806 870 // read one byte from local buf_in 807 871 src_cid = l / nlc; 808 src_index = (l % nlc) * IMAGE_SIZE+ p;872 src_index = (l % nlc) * image_size + p; 809 873 810 874 byte = buf_in[src_cid][src_index]; … … 812 876 // write one byte to remote buf_out 813 877 dst_cid = p / nlc; 814 dst_index = (p % nlc) * IMAGE_SIZE+ l;878 dst_index = (p % nlc) * image_size + l; 815 879 816 880 buf_out[dst_cid][dst_index] = byte; … … 834 898 835 899 // each local threads copy part of buf_out[cid] to FBF window for display 836 memcpy( wbuf + (cid * pixels_per_cid) + (lid * pixels_per_lid),900 memcpy( out_win_buf + (cid * pixels_per_cid) + (lid * pixels_per_lid), 837 901 buf_out[cid] + (lid * pixels_per_lid), 838 902 pixels_per_lid ); … … 843 907 #endif 844 908 845 // refresh window846 error = fbf_refresh_window( wid , line_first , line_last );909 // each thread contributes to output window refresh 910 error = fbf_refresh_window( out_wid , line_first , line_last ); 847 911 848 912 if( error )
Note: See TracChangeset
for help on using the changeset viewer.