Changeset 714 for soft/giet_vm/giet_kernel/sys_handler.c
- Timestamp:
- Oct 7, 2015, 12:02:48 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_kernel/sys_handler.c
r709 r714 95 95 extern static_scheduler_t* _schedulers[X_SIZE][Y_SIZE][NB_PROCS_MAX]; 96 96 97 // allocated in bdv_driver.c file 98 spin_lock_t _bdv_lock; 99 100 //////////////////////////////////////////////////////////////////////////////// 101 // Allocator protecting exclusive access to FBF by a single application. 102 // - The number of users in a given application should be set by a single 103 // thread using an _atomic_test_and_set(). 104 // - The allocator is atomically decremented by each user thread when 105 // the thread exit. 106 //////////////////////////////////////////////////////////////////////////////// 107 108 __attribute__((section(".kdata"))) 109 unsigned int _fbf_alloc = 0; 110 97 111 //////////////////////////////////////////////////////////////////////////////// 98 112 // Channel allocators for multi-channels peripherals … … 179 193 &_sys_xy_from_ptr, /* 0x03 */ 180 194 &_sys_ukn, /* 0x04 */ 181 &_sys_ ukn,/* 0x05 */182 &_sys_ ukn,/* 0x06 */195 &_sys_vseg_get_vbase, /* 0x05 */ 196 &_sys_vseg_get_length, /* 0x06 */ 183 197 &_sys_heap_info, /* 0x07 */ 184 &_sys_ vseg_get_vbase,/* 0x08 */185 &_sys_ vseg_get_length,/* 0x09 */198 &_sys_fbf_size, /* 0x08 */ 199 &_sys_fbf_alloc, /* 0x09 */ 186 200 &_sys_fbf_cma_alloc, /* 0x0A */ 187 201 &_sys_fbf_cma_init_buf, /* 0x0B */ … … 251 265 // This function is called by the _sys_exec_application function 252 266 // to reload all data segments contained in an application.elf file. 267 // File checking is minimal, because these segments have already 268 // been loaded by the boot code. 253 269 //////////////////////////////////////////////////////////////////////// 254 270 static unsigned int _load_writable_segments( mapping_vspace_t* vspace ) … … 262 278 unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); 263 279 if ( _get_proctime() > GIET_DEBUG_EXEC ) 264 _printf("\n[DEBUG EXEC] _load_writable_segments() : P[%d,%d,%d] " 265 "enters for %s\n", x , y , p , vspace->name ); 280 _printf("\n[DEBUG EXEC] _load_writable_segments() at cycle %d\n" 281 "P[%d,%d,%d] enters for %s\n", 282 _get_proctime() , x , y , p , vspace->name ); 266 283 #endif 267 284 … … 271 288 unsigned int vseg_id; // vseg index in mapping 272 289 char buf[4096]; // buffer to store one cluster 273 unsigned int fd = 0; // file descriptor 290 unsigned int fd = 0; // file descriptor 291 unsigned int found = 0; 274 292 275 293 // first scan on vsegs in vspace to find the .elf pathname … … 283 301 fd = _fat_open( vseg[vseg_id].binpath , O_RDONLY ); 284 302 if ( fd < 0 ) return 1; 285 break;286 303 287 304 #if GIET_DEBUG_EXEC 288 305 if ( _get_proctime() > GIET_DEBUG_EXEC ) 289 _printf("\n[DEBUG EXEC] _load_writable_segments() : P[%d,%d,%d] " 290 "open %s / fd = %d\n", x , y , p , vseg[vseg_id].binpath , fd ); 291 #endif 306 _printf("\n[DEBUG EXEC] _load_writable_segments() at cycle %d\n" 307 "P[%d,%d,%d] open %s / fd = %d\n", 308 _get_proctime() , x , y , p , vseg[vseg_id].binpath , fd ); 309 #endif 310 found = 1; 311 break; 312 292 313 } 293 314 } 294 315 316 // check .elf file found 317 if ( found == 0 ) 318 { 319 320 _printf("@@@ _load_writable_segments() : .elf not found\n"); 321 322 return 1; 323 } 324 295 325 // load Elf-Header into buffer from .elf file 296 326 if ( _fat_lseek( fd, 0, SEEK_SET ) < 0 ) 297 327 { 328 329 _printf("@@@ _load_writable_segments() : cannot seek\n"); 330 298 331 _fat_close( fd ); 299 332 return 1; 333 300 334 } 301 335 if ( _fat_read( fd, (unsigned int)buf, 4096, 0 ) < 0 ) 302 336 { 337 338 _printf("@@@ _load_writable_segments() : cannot read\n"); 339 303 340 _fat_close( fd ); 304 341 return 1; … … 307 344 #if GIET_DEBUG_EXEC 308 345 if ( _get_proctime() > GIET_DEBUG_EXEC ) 309 _printf("\n[DEBUG EXEC] _load_writable_segments() : P[%d,%d,%d] " 310 "loaded Elf-Header\n", x , y , p ); 346 _printf("\n[DEBUG EXEC] _load_writable_segments() at cycle %d\n" 347 "P[%d,%d,%d] loaded Elf-Header\n", 348 _get_proctime() , x , y , p ); 311 349 #endif 312 350 … … 330 368 #if GIET_DEBUG_EXEC 331 369 if ( _get_proctime() > GIET_DEBUG_EXEC ) 332 _printf("\n[DEBUG EXEC] _load_writable_segments() : P[%d,%d,%d] " 333 "loaded Program-Header-Table\n", x , y , p ); 370 _printf("\n[DEBUG EXEC] _load_writable_segments() at cycle %d\n" 371 "P[%d,%d,%d] loaded Program-Header-Table\n", 372 _get_proctime() , x , y , p ); 334 373 #endif 335 374 … … 384 423 #if GIET_DEBUG_EXEC 385 424 if ( _get_proctime() > GIET_DEBUG_EXEC ) 386 _printf("\n[DEBUG EXEC] _load_writable_segments() : P[%d,%d,%d] " 387 "loaded segment %x\n", x , y , p , vbase ); 425 _printf("\n[DEBUG EXEC] _load_writable_segments() at cycle %d\n" 426 "P[%d,%d,%d] loaded segment %x\n", 427 _get_proctime() , x , y , p , vbase ); 388 428 #endif 389 429 } … … 416 456 unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); 417 457 if ( _get_proctime() > GIET_DEBUG_EXEC ) 418 _printf("\n[DEBUG EXEC] _sys_exec_application() : P[%d,%d,%d] " 419 "enters for %s at cycle %d\n", x, y, p, name, _get_proctime() ); 458 _printf("\n[DEBUG EXEC] _sys_exec_application() at cycle %d\n" 459 "P[%d,%d,%d] enters for vspace %s\n", 460 _get_proctime() , x, y, p, name ); 420 461 #endif 421 462 … … 430 471 #if GIET_DEBUG_EXEC 431 472 if ( _get_proctime() > GIET_DEBUG_EXEC ) 432 _printf("\n[DEBUG EXEC] _sys_exec_application() : P[%d,%d,%d] " 433 "found vspace %s at cycle %d\n", x, y, p, name, _get_proctime() ); 473 _printf("\n[DEBUG EXEC] _sys_exec_application() at cycle %d\n" 474 "P[%d,%d,%d] found vspace %s\n", 475 _get_proctime() , x, y, p, name ); 434 476 #endif 435 477 // reload writable segments … … 438 480 _printf("[GIET ERROR] _sys_exec_application() : " 439 481 "can't load data segment for vspace %s\n", name ); 440 return GIET_SYSCALL_CANNOT_LOAD_DATA_SEGMENT;482 return SYSCALL_CANNOT_LOAD_DATA_SEGMENT; 441 483 } 442 484 443 485 #if GIET_DEBUG_EXEC 444 486 if ( _get_proctime() > GIET_DEBUG_EXEC ) 445 _printf("\n[DEBUG EXEC] _sys_exec_application() : P[%d,%d,%d] " 446 "load segments for vspace %s at cycle %d\n", x, y, p, name, _get_proctime() ); 487 _printf("\n[DEBUG EXEC] _sys_exec_application() at cycle %d\n" 488 "P[%d,%d,%d] loaded all writable segments for vspace %s\n", 489 _get_proctime() , x, y, p, name ); 447 490 #endif 448 491 // scan threads in vspace with three goals : … … 474 517 "thread %s already active in vspace %s\n", 475 518 thread[thread_id].name, name ); 476 return GIET_SYSCALL_THREAD_ALREADY_ACTIVE;519 return SYSCALL_THREAD_ALREADY_ACTIVE; 477 520 } 478 521 … … 499 542 #if GIET_DEBUG_EXEC 500 543 if ( _get_proctime() > GIET_DEBUG_EXEC ) 501 _printf("\n[DEBUG EXEC] _sys_exec_application() : P[%d,%d,%d]"502 " initialise thread %s at cycle %d\n",503 x, y, p, thread[thread_id].name, _get_proctime());504 #endif 505 } // end loop on vspacethreads544 _printf("\n[DEBUG EXEC] _sys_exec_application() at cycle %d\n" 545 "P[%d,%d,%d] initialise thread %s in vspace %s\n", 546 _get_proctime() , x, y, p, thread[thread_id].name , name ); 547 #endif 548 } // end loop on threads 506 549 507 550 // activate main thread … … 514 557 _printf("\n[GIET ERROR] in _sys_exec_application() : " 515 558 "main not found in vspace %s\n", name ); 516 return GIET_SYSCALL_MAIN_NOT_FOUND;559 return SYSCALL_MAIN_NOT_FOUND; 517 560 } 518 561 519 #if GIET_DEBUG_EXEC 520 if ( _get_proctime() > GIET_DEBUG_EXEC ) 521 _printf("\n[DEBUG EXEC] _sys_exec_application() : P[%d,%d,%d] " 522 "lauched %s at cycle %d\n", x, y, p, name, _get_proctime() ); 523 #endif 524 return GIET_SYSCALL_OK; 562 _printf("\n[GIET WARNING] application %s launched : %d threads\n", 563 name , max-min ); 564 565 return SYSCALL_OK; 525 566 } 526 567 } // end of loop on vspaces … … 529 570 _printf("\n[GIET ERROR] in _sys_exec_application() : " 530 571 "vspace %s not found\n", name ); 531 return GIET_SYSCALL_VSPACE_NOT_FOUND;572 return SYSCALL_VSPACE_NOT_FOUND; 532 573 533 574 } // end _sys_exec_application() … … 551 592 unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); 552 593 if ( _get_proctime() > GIET_DEBUG_EXEC ) 553 _printf("\n[DEBUG EXEC] _sys_kill_application() P[%d,%d,%d] " 554 "enters at cycle %d for %s\n", x, y, p, _get_proctime() , name ); 594 _printf("\n[DEBUG EXEC] _sys_kill_application() at cycle %d\n" 595 "P[%d,%d,%d] enters for vspace %s\n", 596 _get_proctime() , x , y , p , name ); 555 597 #endif 556 598 … … 560 602 _printf("\n[GIET ERROR] in _sys_kill_application() : " 561 603 "%s application cannot be killed\n", name ); 562 return GIET_SYSCALL_APPLI_CANNOT_BE_KILLED;604 return SYSCALL_APPLI_CANNOT_BE_KILLED; 563 605 } 564 606 … … 587 629 } 588 630 589 #if GIET_DEBUG_EXEC 590 if ( _get_proctime() > GIET_DEBUG_EXEC ) 591 _printf("\n[DEBUG EXEC] _sys_kill_application() P[%d,%d,%d] " 592 "kill %s at cycle %d\n", x, y, p, name, _get_proctime() ); 593 #endif 594 595 return GIET_SYSCALL_OK; 631 _printf("\n[GIET WARNING] application %s killed / %d threads\n", 632 name , max-min ); 633 634 return SYSCALL_OK; 596 635 } 597 636 } // en loop on vspaces … … 599 638 _printf("\n[GIET ERROR] in _sys_kill_application() : " 600 639 "application %s not found\n", name ); 601 return GIET_SYSCALL_VSPACE_NOT_FOUND;640 return SYSCALL_VSPACE_NOT_FOUND; 602 641 603 642 } // end _sys_kill_application() … … 605 644 606 645 607 ////////////////////////////// 608 int _sys_applications_status( )646 ////////////////////////////////////////// 647 int _sys_applications_status( char* name ) 609 648 { 610 649 mapping_header_t * header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; … … 613 652 mapping_cluster_t * cluster = _get_cluster_base(header); 614 653 615 unsigned int thread_id; 616 unsigned int vspace_id; 617 618 // scan allvspaces654 unsigned int thread_id; // thread index in mapping 655 unsigned int vspace_id; // vspace index in mapping 656 657 // scan vspaces 619 658 for( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) 620 659 { 621 _user_printf("\n*** vspace %s\n", vspace[vspace_id].name ); 622 623 // scan all threads in vspace 624 unsigned int min = vspace[vspace_id].thread_offset ; 625 unsigned int max = min + vspace[vspace_id].threads ; 626 for ( thread_id = min ; thread_id < max ; thread_id++ ) 660 if ( (name == NULL) || (_strcmp(vspace[vspace_id].name , name ) == 0) ) 627 661 { 628 unsigned int clusterid = thread[thread_id].clusterid; 629 unsigned int p = thread[thread_id].proclocid; 630 unsigned int x = cluster[clusterid].x; 631 unsigned int y = cluster[clusterid].y; 632 unsigned int ltid = thread[thread_id].ltid; 633 static_scheduler_t* psched = (static_scheduler_t*)_schedulers[x][y][p]; 634 unsigned int norun = psched->context[ltid].slot[CTX_NORUN_ID]; 635 unsigned int tty = psched->context[ltid].slot[CTX_TTY_ID]; 636 unsigned int current = psched->current; 637 638 if ( current == ltid ) 639 _user_printf(" - thread %s / P[%d,%d,%d] / ltid = %d / " 640 "TTY = %d / norun = %x : running\n", 641 thread[thread_id].name, x, y, p, ltid, tty, norun ); 642 else if ( norun == 0 ) 643 _user_printf(" - thread %s / P[%d,%d,%d] / ltid = %d / " 644 "TTY = %d / norun = %x : runable\n", 645 thread[thread_id].name, x, y, p, ltid, tty, norun); 646 else 647 _user_printf(" - thread %s / P[%d,%d,%d] / ltid = %d / " 648 "TTY = %d / norun = %x : blocked\n", 649 thread[thread_id].name, x, y, p, ltid, tty, norun); 662 _user_printf("\n*** vspace %s\n", vspace[vspace_id].name ); 663 664 // scan all threads in vspace 665 unsigned int min = vspace[vspace_id].thread_offset ; 666 unsigned int max = min + vspace[vspace_id].threads ; 667 for ( thread_id = min ; thread_id < max ; thread_id++ ) 668 { 669 unsigned int clusterid = thread[thread_id].clusterid; 670 unsigned int p = thread[thread_id].proclocid; 671 unsigned int x = cluster[clusterid].x; 672 unsigned int y = cluster[clusterid].y; 673 unsigned int ltid = thread[thread_id].ltid; 674 static_scheduler_t* psched = (static_scheduler_t*)_schedulers[x][y][p]; 675 unsigned int norun = psched->context[ltid].slot[CTX_NORUN_ID]; 676 unsigned int tty = psched->context[ltid].slot[CTX_TTY_ID]; 677 unsigned int current = psched->current; 678 679 if ( current == ltid ) 680 _user_printf(" - thread %s / P[%d,%d,%d] / ltid = %d / " 681 "TTY = %d / norun = %x : running\n", 682 thread[thread_id].name, x, y, p, ltid, tty, norun ); 683 else if ( norun == 0 ) 684 _user_printf(" - thread %s / P[%d,%d,%d] / ltid = %d / " 685 "TTY = %d / norun = %x : runable\n", 686 thread[thread_id].name, x, y, p, ltid, tty, norun); 687 else 688 _user_printf(" - thread %s / P[%d,%d,%d] / ltid = %d / " 689 "TTY = %d / norun = %x : blocked\n", 690 thread[thread_id].name, x, y, p, ltid, tty, norun); 691 } 650 692 } 651 693 } 652 694 _user_printf("\n"); 653 return GIET_SYSCALL_OK; 695 696 return SYSCALL_OK; 654 697 } // end _sys_applications_status() 655 698 … … 672 715 "attr argument not supported\n" ); 673 716 674 return GIET_SYSCALL_PTHREAD_ARGUMENT_NOT_SUPPORTED;717 return SYSCALL_PTHREAD_ARGUMENT_NOT_SUPPORTED; 675 718 } 676 719 … … 691 734 692 735 #if GIET_DEBUG_EXEC 736 unsigned int gpid = _get_procid(); 737 unsigned int cluster_xy = gpid >> P_WIDTH; 738 unsigned int p = gpid & ((1<<P_WIDTH)-1); 739 unsigned int x = cluster_xy >> Y_WIDTH; 740 unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); 693 741 if ( _get_proctime() > GIET_DEBUG_EXEC ) 694 _printf("\n[DEBUG EXEC] _sys_pthread_create() : enters at cycle %d"695 " for vspace %s / entry = %x\n",696 _get_proctime() , vspace[vspace_id].name , (unsigned int)function );742 _printf("\n[DEBUG EXEC] _sys_pthread_create() at cycle %d\n" 743 "P[%d,%d,%d] enters for vspace %s / entry = %x\n", 744 _get_proctime() , x , y , p , vspace[vspace_id].name , (unsigned int)function ); 697 745 #endif 698 746 … … 747 795 #if GIET_DEBUG_EXEC 748 796 if ( _get_proctime() > GIET_DEBUG_EXEC ) 749 _printf("\n[DEBUG EXEC] exit _sys_pthread_create() at cycle %d : thread %x launched\n", 750 _get_proctime() , trdid); 751 #endif 752 return GIET_SYSCALL_OK; 797 _printf("\n[DEBUG EXEC] _sys_pthread_create() at cycle %d\n" 798 "P[%d,%d,%d] exit : thread %x launched in vspace %s\n", 799 _get_proctime() , x , y , p , trdid , vspace[vspace_id].name ); 800 #endif 801 return SYSCALL_OK; 753 802 } 754 803 else // no matching thread found … … 758 807 (unsigned int)function , vspace[vspace_id].name ); 759 808 760 return GIET_SYSCALL_THREAD_NOT_FOUND;809 return SYSCALL_THREAD_NOT_FOUND; 761 810 } 762 811 … … 774 823 "ptr argument not supported, must be NULL\n" ); 775 824 776 return GIET_SYSCALL_PTHREAD_ARGUMENT_NOT_SUPPORTED; 777 } 778 825 return SYSCALL_PTHREAD_ARGUMENT_NOT_SUPPORTED; 826 } 827 828 // get calling thread vspace 829 unsigned int caller_vspace = _get_context_slot( CTX_VSID_ID ); 779 830 780 831 #if GIET_DEBUG_EXEC 832 unsigned int gpid = _get_procid(); 833 unsigned int cluster_xy = gpid >> P_WIDTH; 834 unsigned int p = gpid & ((1<<P_WIDTH)-1); 835 unsigned int x = cluster_xy >> Y_WIDTH; 836 unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); 781 837 if ( _get_proctime() > GIET_DEBUG_EXEC ) 782 _printf("\n[DEBUG EXEC] enters _sys_pthread_join() at cycle %d for thread %x\n", 783 _get_proctime() , trdid ); 784 #endif 785 838 _printf("\n[DEBUG EXEC] _sys_pthread_join() at cycle %d\n" 839 "P[%d,%d,%d] enters for thread %x in vspace %d\n", 840 _get_proctime() , x , y , p , trdid , caller_vspace ); 841 #endif 842 843 // get target thread indexes from trdid 844 unsigned int cx = (trdid>>24) & 0xFF; 845 unsigned int cy = (trdid>>16) & 0xFF; 846 unsigned int lpid = (trdid>>8 ) & 0xFF; 847 unsigned int ltid = (trdid ) & 0xFF; 848 849 // get target thread scheduler, vspace and registered trdid 850 static_scheduler_t* psched = _schedulers[cx][cy][lpid]; 851 unsigned int target_vspace = psched->context[ltid].slot[CTX_VSID_ID]; 852 unsigned int registered_trdid = psched->context[ltid].slot[CTX_TRDID_ID]; 853 854 // check trdid 855 if ( trdid != registered_trdid ) 856 { 857 _printf("\nerror in _sys_pthread_join() : " 858 "trdid = %x / registered_trdid = %x\n", 859 trdid , registered_trdid ); 860 861 return SYSCALL_UNCOHERENT_THREAD_CONTEXT; 862 } 863 864 // check calling thread and target thread in same vspace 865 if ( caller_vspace != target_vspace ) 866 { 867 _printf("\n[GIET ERROR] in _sys_pthread_join() : " 868 " calling thread and target thread not in same vspace\n"); 869 870 return SYSCALL_NOT_IN_SAME_VSPACE; 871 } 872 873 // get target thread state 874 unsigned int* pnorun = &psched->context[ltid].slot[CTX_NORUN_ID]; 875 876 asm volatile ( "2000: \n" 877 "move $11, %0 \n" /* $11 <= pnorun */ 878 "lw $11, 0($11) \n" /* $11 <= norun */ 879 "andi $11, $11, 1 \n" /* $11 <= norun & 0x1 */ 880 "beqz $11, 2000b \n" 881 : 882 : "r" (pnorun) 883 : "$11" ); 884 885 #if GIET_DEBUG_EXEC 886 if ( _get_proctime() > GIET_DEBUG_EXEC ) 887 _printf("\n[DEBUG EXEC] _sys_pthread_join() at cycle %d\n" 888 "P[%d,%d,%d] exit for thread %x in vspace %d\n", 889 _get_proctime() , x , y , p , trdid , caller_vspace ); 890 #endif 891 892 return SYSCALL_OK; 893 894 } // end _sys_pthread_join() 895 896 897 //////////////////////////////////////// 898 int _sys_pthread_kill( pthread_t trdid, 899 int signal ) 900 { 786 901 // get calling thread vspace 787 902 unsigned int caller_vspace = _get_context_slot( CTX_VSID_ID ); 903 904 #if GIET_DEBUG_EXEC 905 unsigned int gpid = _get_procid(); 906 unsigned int cluster_xy = gpid >> P_WIDTH; 907 unsigned int p = gpid & ((1<<P_WIDTH)-1); 908 unsigned int x = cluster_xy >> Y_WIDTH; 909 unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); 910 if ( _get_proctime() > GIET_DEBUG_EXEC ) 911 _printf("\n[DEBUG EXEC] _sys_pthread_kill() at cycle %d\n" 912 "P[%d,%d,%d] enters for thread %x in vspace %d\n", 913 _get_proctime() , x , y , p , trdid , caller_vspace ); 914 #endif 915 788 916 789 917 // get and check target thread indexes from trdid … … 794 922 795 923 // get target thread scheduler, vspace and registered trdid 796 static_scheduler_t* psched = _schedulers[cx][cy][lpid];797 unsigned int target_vspace = psched->context[ltid].slot[CTX_VSID_ID];924 static_scheduler_t* psched = _schedulers[cx][cy][lpid]; 925 unsigned int target_vspace = psched->context[ltid].slot[CTX_VSID_ID]; 798 926 unsigned int registered_trdid = psched->context[ltid].slot[CTX_TRDID_ID]; 799 927 … … 801 929 if ( trdid != registered_trdid ) 802 930 { 803 _printf("\nerror in _sys_pthread_join() : " 804 "trdid = %x / registered_trdid = %x\n", 805 trdid , registered_trdid ); 806 807 return GIET_SYSCALL_UNCOHERENT_THREAD_CONTEXT; 931 _printf("\n[GIET ERROR] in _sys_pthread_kill() : trdid = %x" 932 " / registered_trdid = %x\n", trdid , registered_trdid ); 933 return SYSCALL_UNCOHERENT_THREAD_CONTEXT; 808 934 } 809 935 … … 811 937 if ( caller_vspace != target_vspace ) 812 938 { 813 _printf("\n[GIET ERROR] in _sys_pthread_join() : "814 " calling thread and target thread not in same vspace\n");815 816 return GIET_SYSCALL_NOT_IN_SAME_VSPACE;817 }818 819 // get target thread state820 unsigned int* pnorun = &psched->context[ltid].slot[CTX_NORUN_ID];821 822 asm volatile ( "2000: \n"823 "move $11, %0 \n" /* $11 <= ptr */824 "lw $11, 0($11) \n" /* $11 <= M[ptr] */825 "andi $11, $11, 1 \n" /* $11 <= norun & 0x1 */826 "beqz $11, 2000b \n"827 :828 : "r" (pnorun)829 : "$11" );830 831 return GIET_SYSCALL_OK;832 833 } // end _sys_pthread_join()834 835 836 ////////////////////////////////////////837 int _sys_pthread_kill( pthread_t trdid,838 int signal )839 {840 // get calling thread vspace841 unsigned int caller_vspace = _get_context_slot( CTX_VSID_ID );842 843 // get and check target thread indexes from trdid844 unsigned int cx = (trdid>>24) & 0xFF;845 unsigned int cy = (trdid>>16) & 0xFF;846 unsigned int lpid = (trdid>>8 ) & 0xFF;847 unsigned int ltid = (trdid ) & 0xFF;848 849 // get target thread scheduler, vspace and registered trdid850 static_scheduler_t* psched = _schedulers[cx][cy][lpid];851 unsigned int target_vspace = psched->context[ltid].slot[CTX_VSID_ID];852 unsigned int registered_trdid = psched->context[ltid].slot[CTX_TRDID_ID];853 854 // check trdid855 if ( trdid != registered_trdid )856 {857 _printf("\n[GIET ERROR] in _sys_pthread_kill() : trdid = %x"858 " / registered_trdid = %x\n", trdid , registered_trdid );859 return GIET_SYSCALL_UNCOHERENT_THREAD_CONTEXT;860 }861 862 // check calling thread and target thread in same vspace863 if ( caller_vspace != target_vspace )864 {865 939 _printf("\n[GIET ERROR] in _sys_pthread_kill() : not in same vspace\n"); 866 return GIET_SYSCALL_NOT_IN_SAME_VSPACE;940 return SYSCALL_NOT_IN_SAME_VSPACE; 867 941 } 868 942 … … 873 947 } 874 948 875 return GIET_SYSCALL_OK; 949 #if GIET_DEBUG_EXEC 950 if ( _get_proctime() > GIET_DEBUG_EXEC ) 951 _printf("\n[DEBUG EXEC] _sys_pthread_kill() at cycle %d\n" 952 "P[%d,%d,%d] exit for thread %x in vspace %d\n", 953 _get_proctime() , x , y , p , trdid , caller_vspace ); 954 #endif 955 956 return SYSCALL_OK; 876 957 877 958 } // end _sys_pthread_kill() … … 881 962 int _sys_pthread_exit( void* string ) 882 963 { 883 unsigned int date = _get_proctime();884 885 964 mapping_header_t * header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; 886 965 mapping_vspace_t * vspace = _get_vspace_base(header); … … 893 972 if ( string == NULL ) 894 973 { 895 _printf("\n[GIET WARNING] Exit thread %x in vspace %s at cycle %d\n",896 trdid , vspace[vsid].name , date);974 _printf("\n[GIET WARNING] Exit thread %x in vspace %s\n", 975 trdid , vspace[vsid].name ); 897 976 } 898 977 else 899 978 { 900 _printf("\n[GIET WARNING] Exit thread %x in vspace %s at cycle %d\n"979 _printf("\n[GIET WARNING] Exit thread %x in vspace %s\n" 901 980 " Cause : %s\n\n", 902 trdid , vspace[vsid].name , date ,(char*) string );981 trdid , vspace[vsid].name , (char*) string ); 903 982 } 904 983 … … 915 994 _ctx_switch(); 916 995 917 return GIET_SYSCALL_OK;996 return SYSCALL_OK; 918 997 919 998 } // end _sys_pthread_exit() … … 928 1007 _it_restore( &save_sr ); 929 1008 930 return GIET_SYSCALL_OK;1009 return SYSCALL_OK; 931 1010 } 932 1011 … … 938 1017 939 1018 #if GIET_DEBUG_EXEC 1019 unsigned int gpid = _get_procid(); 1020 unsigned int cluster_xy = gpid >> P_WIDTH; 1021 unsigned int p = gpid & ((1<<P_WIDTH)-1); 1022 unsigned int x = cluster_xy >> Y_WIDTH; 1023 unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); 940 1024 if ( _get_proctime() > GIET_DEBUG_EXEC ) 941 _printf("\n[DEBUG EXEC] _sys_pthread_control() at cycle %d :"942 " enter for vspace %s / thread %s / command = %d\n",943 _get_proctime() , vspace_name, thread_name, command );1025 _printf("\n[DEBUG EXEC] _sys_pthread_control() at cycle %d\n" 1026 "P[%d,%d,%d] enter for vspace %s / thread %s / command = %d\n", 1027 _get_proctime() , x , y , p , vspace_name, thread_name, command ); 944 1028 #endif 945 1029 … … 964 1048 } 965 1049 966 if ( found == 0 ) return GIET_SYSCALL_VSPACE_NOT_FOUND;1050 if ( found == 0 ) return SYSCALL_VSPACE_NOT_FOUND; 967 1051 968 1052 // search thread name in vspace to get thread index: tid … … 980 1064 } 981 1065 982 if ( found == 0 ) return GIET_SYSCALL_THREAD_NOT_FOUND;983 984 // get t hread coordinates1066 if ( found == 0 ) return SYSCALL_THREAD_NOT_FOUND; 1067 1068 // get target thread coordinates 985 1069 unsigned int cid = thread[tid].clusterid; 986 unsigned int x= cluster[cid].x;987 unsigned int y= cluster[cid].y;988 unsigned int p= thread[tid].proclocid;1070 unsigned int cx = cluster[cid].x; 1071 unsigned int cy = cluster[cid].y; 1072 unsigned int cp = thread[tid].proclocid; 989 1073 unsigned int ltid = thread[tid].ltid; 990 1074 991 static_scheduler_t* psched = _schedulers[x][y][p]; 1075 // get target thread scheduler 1076 static_scheduler_t* psched = _schedulers[cx][cy][cp]; 992 1077 993 1078 // check trdid and vsid 994 unsigned int trdid = x<<24 | y<<16 |p<<8 | ltid;1079 unsigned int trdid = cx<<24 | cy<<16 | cp<<8 | ltid; 995 1080 if ( (psched->context[ltid].slot[CTX_TRDID_ID] != trdid) || 996 1081 (psched->context[ltid].slot[CTX_VSID_ID] != vsid) ) 997 return GIET_SYSCALL_UNCOHERENT_THREAD_CONTEXT; 1082 { 1083 return SYSCALL_UNCOHERENT_THREAD_CONTEXT; 1084 } 998 1085 999 1086 // execute command … … 1001 1088 { 1002 1089 _atomic_or ( &psched->context[ltid].slot[CTX_NORUN_ID], NORUN_MASK_THREAD ); 1003 return GIET_SYSCALL_OK;1090 return SYSCALL_OK; 1004 1091 } 1005 1092 else if ( command == THREAD_CMD_RESUME ) 1006 1093 { 1007 1094 _atomic_and( &psched->context[ltid].slot[CTX_NORUN_ID], ~NORUN_MASK_THREAD ); 1008 return GIET_SYSCALL_OK;1095 return SYSCALL_OK; 1009 1096 } 1010 1097 else if ( command == THREAD_CMD_CONTEXT ) … … 1046 1133 psched->context[ltid].slot[CTX_CMA_TX_ID], 1047 1134 psched->context[ltid].slot[CTX_CMA_FB_ID] ); 1048 return GIET_SYSCALL_OK;1135 return SYSCALL_OK; 1049 1136 } 1050 1137 else 1051 1138 { 1052 return GIET_SYSCALL_ILLEGAL_THREAD_COMMAND_TYPE;1139 return SYSCALL_ILLEGAL_THREAD_COMMAND_TYPE; 1053 1140 } 1054 1141 … … 1115 1202 1116 1203 #if GIET_DEBUG_COPROC 1117 _printf("\n[ GIET DEBUG COPROC] _sys_coproc_alloc() in cluster[%d,%d]\n"1118 " 1119 x , y, *coproc_info , cluster_xy );1120 #endif 1121 return GIET_SYSCALL_OK;1204 _printf("\n[DEBUG COPROC] _sys_coproc_alloc() at cycle %d\n" 1205 "coproc_info = %x / cluster_xy = %x\n", 1206 _get_proctime() , *coproc_info , cluster_xy ); 1207 #endif 1208 return SYSCALL_OK; 1122 1209 } 1123 1210 else 1124 1211 { 1125 _printf("\n[GIET_ERROR] in _sys_coproc_alloc(): no coprocessor"1126 " with type %d availablein cluster[%d,%d]\n",1212 _printf("\n[GIET_ERROR] in _sys_coproc_alloc(): " 1213 "no coprocessor with type %d in cluster[%d,%d]\n", 1127 1214 coproc_type , x , y ); 1128 return GIET_SYSCALL_COPROCESSOR_NOT_FOUND; 1215 1216 return SYSCALL_COPROCESSOR_NOT_FOUND; 1129 1217 } 1130 1218 } // end _sys_coproc_alloc() … … 1133 1221 int _sys_coproc_release( unsigned int coproc_reg_index ) 1134 1222 { 1135 // processor coordinates 1136 unsigned int procid = _get_procid(); 1137 unsigned int x = procid >> (Y_WIDTH + P_WIDTH); 1138 unsigned int y = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1); 1139 unsigned int p = procid & ((1<<P_WIDTH)-1); 1140 1223 // get thread trdid 1224 unsigned int trdid = _get_thread_trdid(); 1225 1141 1226 // get coprocessor coordinates 1142 1227 unsigned int cluster_xy = _get_context_slot( CTX_COPROC_ID ); 1228 1143 1229 if ( cluster_xy > 0xFF ) 1144 1230 { 1145 1231 _printf("\n[GIET_ERROR] in _sys_coproc_release(): " 1146 "no coprocessor allocated to thread running on P[%d,%d,%d]\n",1147 x , y , p ); 1148 return GIET_SYSCALL_COPROCESSOR_NOT_FOUND;1232 "no coprocessor allocated to thread %x\n", trdid ); 1233 1234 return SYSCALL_COPROCESSOR_NON_ALLOCATED; 1149 1235 } 1150 1236 … … 1171 1257 1172 1258 #if GIET_DEBUG_COPROC 1173 _printf("\n[ GIET DEBUG COPROC] _sys_coproc_release() in cluster[%d,%d]\n",1174 cx, cy );1175 #endif 1176 1177 return GIET_SYSCALL_OK;1259 _printf("\n[DEBUG COPROC] _sys_coproc_release() at cycle %d\n" 1260 "thread %x release coprocessor in cluster[%d,%d]\n", cx, cy ); 1261 #endif 1262 1263 return SYSCALL_OK; 1178 1264 } // end _sys_coproc_release() 1179 1265 … … 1182 1268 giet_coproc_channel_t* desc ) 1183 1269 { 1184 // processor coordinates 1185 unsigned int procid = _get_procid(); 1186 unsigned int x = procid >> (Y_WIDTH + P_WIDTH); 1187 unsigned int y = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1); 1188 unsigned int p = procid & ((1<<P_WIDTH)-1); 1189 1270 // get thread trdid 1271 unsigned int trdid = _get_thread_trdid(); 1272 1190 1273 // get coprocessor coordinates 1191 1274 unsigned int cluster_xy = _get_context_slot( CTX_COPROC_ID ); 1275 1192 1276 if ( cluster_xy > 0xFF ) 1193 1277 { 1194 1278 _printf("\n[GIET_ERROR] in _sys_coproc_channel_init(): " 1195 "no coprocessor allocated to thread running on P[%d,%d,%d]\n",1196 x , y , p ); 1197 return GIET_SYSCALL_COPROCESSOR_NOT_FOUND;1279 "no coprocessor allocated to thread %x\n", trdid ); 1280 1281 return SYSCALL_COPROCESSOR_NON_ALLOCATED; 1198 1282 } 1199 1283 … … 1205 1289 { 1206 1290 _printf("\n[GIET_ERROR] in _sys_coproc_channel_init(): " 1207 " illegal mode\n"); 1208 return GIET_SYSCALL_COPROCESSOR_ILLEGAL_MODE; 1291 "illegal mode\n"); 1292 1293 return SYSCALL_COPROCESSOR_ILLEGAL_MODE; 1209 1294 } 1210 1295 … … 1258 1343 1259 1344 #if GIET_DEBUG_COPROC 1260 _printf("\n[ GIET DEBUG COPROC] _sys_coproc_channel_init() for coproc[%d,%d]\n"1261 " channel =%d / mode = %d / buffer_size = %d\n"1345 _printf("\n[DEBUG COPROC] _sys_coproc_channel_init() at cycle %d\n" 1346 "cluster[%d,%d] / channel = %d / mode = %d / buffer_size = %d\n" 1262 1347 " buffer_paddr = %l / mwmr_paddr = %l / lock_paddr = %l\n", 1263 x , y , channel , mode , size ,1348 _get_proctime() , x , y , channel , mode , size , 1264 1349 buffer_paddr, mwmr_paddr, lock_paddr ); 1265 1350 #endif 1266 1351 1267 return GIET_SYSCALL_OK;1352 return SYSCALL_OK; 1268 1353 } // end _sys_coproc_channel_init() 1269 1354 … … 1271 1356 int _sys_coproc_run( unsigned int coproc_reg_index ) 1272 1357 { 1273 // processor coordinates 1274 unsigned int procid = _get_procid(); 1275 unsigned int x = procid >> (Y_WIDTH + P_WIDTH); 1276 unsigned int y = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1); 1277 unsigned int p = procid & ((1<<P_WIDTH)-1); 1278 1358 // get thread trdid 1359 unsigned int trdid = _get_thread_trdid(); 1360 1279 1361 // get coprocessor coordinates 1280 1362 unsigned int cluster_xy = _get_context_slot( CTX_COPROC_ID ); 1363 1281 1364 if ( cluster_xy > 0xFF ) 1282 1365 { 1283 1366 _printf("\n[GIET_ERROR] in _sys_coproc_run(): " 1284 "no coprocessor allocated to thread running on P[%d,%d,%d]\n",1285 x , y , p ); 1286 return -1111;1367 "no coprocessor allocated to thread %d\n", trdid ); 1368 1369 return SYSCALL_COPROCESSOR_NON_ALLOCATED; 1287 1370 } 1288 1371 … … 1308 1391 else if ( temp != mode ) 1309 1392 { 1310 _printf("\n[GIET_ERROR] P[%d,%d,%d] in _sys_coproc_run() for coprocessor[%d,%d]\n" 1311 " all channels don't have the same mode\n", x , y , p , cx , cy ); 1312 return -1111; 1393 _printf("\n[GIET_ERROR] in _sys_coproc_run(): " 1394 "channels don't have same mode in coprocessor[%d,%d]\n", cx , cy ); 1395 1396 return SYSCALL_COPROCESSOR_ILLEGAL_MODE; 1313 1397 } 1314 1398 } … … 1329 1413 #if GIET_DEBUG_COPROC 1330 1414 if ( mode == MODE_MWMR ) 1331 _printf("\n[GIET DEBUG COPROC] _sys_coproc_run() P[%d,%d,%d] starts coprocessor[%d,%d]\n" 1332 " MODE_MWMR at cycle %d\n", x , y , p , cx , cy , _get_proctime() ); 1415 _printf("\n[DEBUG COPROC] _sys_coproc_run() at cycle %d\n" 1416 "thread %x starts coprocessor[%d,%d] in MODE_MWMR\n", 1417 _get_proctime() , trdid , cx , cy ); 1333 1418 else 1334 _printf("\n[GIET DEBUG COPROC] _sys_coproc_run() P[%d,%d,%d] starts coprocessor[%d,%d]\n" 1335 " MODE_DMA_NO_IRQ at cycle %d\n", x , y , p , cx , cy , _get_proctime() ); 1336 #endif 1337 1338 return GIET_SYSCALL_OK; 1419 _printf("\n[DEBUG COPROC] _sys_coproc_run() at cycle %d\n" 1420 "thread %x starts coprocessor[%d,%d] in MODE_DMA_NO_IRQ\n", 1421 _get_proctime() , trdid , cx , cy ); 1422 #endif 1423 1424 return SYSCALL_OK; 1339 1425 } 1340 1426 /////////////////////////////////////////////////////////////////////////// 1341 1427 else // mode == MODE_DMA_IRQ => descheduling 1342 1428 { 1343 // set _coproc_trdid 1344 unsigned int ltid = _get_thread_ltid(); 1429 // set _coproc_trdid 1430 unsigned int gpid = _get_procid(); 1431 unsigned int x = gpid >> (Y_WIDTH+P_WIDTH); 1432 unsigned int y = (gpid >> P_WIDTH) & ((1<<Y_WIDTH)-1); 1433 unsigned int p = gpid & ((1<<P_WIDTH)-1); 1434 unsigned int ltid = _get_thread_ltid(); 1345 1435 _coproc_trdid[cluster_id] = (x<<24) + (y<<16) + (p<<8) + ltid; 1346 1436 … … 1358 1448 1359 1449 #if GIET_DEBUG_COPROC 1360 _printf("\n[GIET DEBUG COPROC] _sys_coproc_run() P[%d,%d,%d] starts coprocessor[%d,%d]\n" 1361 " MODE_DMA_IRQ at cycle %d\n", x , y , p , cx , cy , _get_proctime() ); 1450 _printf("\n[DEBUG COPROC] _sys_coproc_run() at cycle %d\n" 1451 "thread %x starts coprocessor[%d,%d] in MODE_DMA_IRQ\n", 1452 _get_proctime() , trdid , cx , cy ); 1362 1453 #endif 1363 1454 … … 1366 1457 1367 1458 #if GIET_DEBUG_COPROC 1368 _printf("\n[ GIET DEBUG COPROC] _sys_coproc_run() P[%d,%d,%d] resume\n"1369 " coprocessor[%d,%d] completion at cycle %d\n",1370 x , y , p , cx , cy , _get_proctime());1459 _printf("\n[DEBUG COPROC] _sys_coproc_run() at cycle %d\n" 1460 "thread %x resume after coprocessor[%d,%d] completion\n", 1461 _get_proctime() , trdid , cx , cy ); 1371 1462 #endif 1372 1463 … … 1382 1473 int _sys_coproc_completed() 1383 1474 { 1384 // processor coordinates 1385 unsigned int procid = _get_procid(); 1386 unsigned int x = procid >> (Y_WIDTH + P_WIDTH); 1387 unsigned int y = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1); 1388 unsigned int p = procid & ((1<<P_WIDTH)-1); 1389 1475 // get thread trdid 1476 unsigned int trdid = _get_thread_trdid(); 1477 1390 1478 // get coprocessor coordinates 1391 1479 unsigned int cluster_xy = _get_context_slot( CTX_COPROC_ID ); 1480 1392 1481 if ( cluster_xy > 0xFF ) 1393 1482 { 1394 1483 _printf("\n[GIET_ERROR] in _sys_coproc_completed(): " 1395 "no coprocessor allocated to thread running on P[%d,%d,%d]\n",1396 x , y , p ); 1397 return -1111;1484 "no coprocessor allocated to thread %x\n", trdid ); 1485 1486 return SYSCALL_COPROCESSOR_NON_ALLOCATED; 1398 1487 } 1399 1488 … … 1413 1502 unsigned int status; 1414 1503 1415 // get status for all channels, and signal allreported errors1504 // get status for all channels, and signal reported errors 1416 1505 for ( channel = 0 ; channel < (nb_to +nb_from) ; channel++ ) 1417 1506 { 1418 1507 do 1419 1508 { 1420 status = _mwr_get_channel_register( cluster_xy , channel , MWR_CHANNEL_STATUS ); 1509 status = _mwr_get_channel_register( cluster_xy, channel, 1510 MWR_CHANNEL_STATUS ); 1421 1511 if ( status == MWR_CHANNEL_ERROR_DATA ) 1422 1512 { 1423 _printf("\n[GIET_ERROR] in _sys_coproc_completed() "1424 " /channel %d / DATA_ERROR\n", channel );1513 _printf("\n[GIET_ERROR] in _sys_coproc_completed(): " 1514 "channel %d / DATA_ERROR\n", channel ); 1425 1515 error = 1; 1426 break;1427 1516 } 1428 1517 else if ( status == MWR_CHANNEL_ERROR_LOCK ) … … 1431 1520 " / channel %d / LOCK_ERROR\n", channel ); 1432 1521 error = 1; 1433 break;1434 1522 } 1435 1523 else if ( status == MWR_CHANNEL_ERROR_DESC ) … … 1438 1526 " / channel %d / DESC_ERROR\n", channel ); 1439 1527 error = 1; 1440 break;1441 1528 } 1442 } while ( status == MWR_CHANNEL_BUSY ); 1529 } 1530 while ( status == MWR_CHANNEL_BUSY ); 1443 1531 1444 1532 // reset channel 1445 _mwr_set_channel_register( cluster_xy , channel , MWR_CHANNEL_RUNNING , 0 ); 1533 _mwr_set_channel_register( cluster_xy, channel, 1534 MWR_CHANNEL_RUNNING , 0 ); 1446 1535 1447 1536 } // end for channels 1448 1537 1538 if ( error ) 1539 { 1540 return SYSCALL_COPROCESSOR_ILLEGAL_MODE; 1541 } 1542 else 1543 { 1544 1449 1545 #if GIET_DEBUG_COPROC 1450 _printf("\n[GIET DEBUG COPROC] _sys_coproc_completed() for coprocessor[%d,%d] error = %d\n", 1451 cx , cy , error ); 1452 #endif 1453 1454 return error; 1546 _printf("\n[DEBUG COPROC] _sys_coproc_completed() at cycle %d\n" 1547 "coprocessor[%d,%d] successfully completes operation for thread %d\n", 1548 cx , cy , trdid ); 1549 #endif 1550 return SYSCALL_OK; 1551 } 1455 1552 } 1456 1553 else // mode == MODE_MWMR or MODE_DMA_IRQ 1457 1554 { 1458 _printf("\n[GIET ERROR] sys_coproc_completed() should not be called for " 1459 "coprocessor[%d,%d] running in MODE_MWMR or MODE_DMA_IRQ\n", cx , cy ); 1460 return 1; 1555 _printf("\n[GIET ERROR] in sys_coproc_completed(): " 1556 "coprocessor[%d,%d] is not running in MODE_DMA_NO_IRQ\n", cx , cy ); 1557 1558 return SYSCALL_COPROCESSOR_ILLEGAL_MODE; 1461 1559 } 1462 1560 } // end _sys_coproc_completed() … … 1481 1579 _printf("\n[GIET_ERROR] in _sys_tty_alloc() : " 1482 1580 "TTY channel already allocated to thread %x\n", trdid ); 1483 return -1111;1581 return SYSCALL_CHANNEL_ALREADY_ALLOCATED; 1484 1582 } 1485 1583 … … 1504 1602 _printf("\n[GIET_ERROR] in _sys_tty_alloc() : " 1505 1603 "no TTY channel available for thread %x\n", trdid ); 1506 return -1111;1604 return SYSCALL_NO_CHANNEL_AVAILABLE; 1507 1605 } 1508 1606 … … 1546 1644 } 1547 1645 1548 return GIET_SYSCALL_OK;1646 return SYSCALL_OK; 1549 1647 } // end _sys_tty_alloc() 1550 1648 1551 1649 ////////////////////// 1552 int _sys_tty_release() // NOTE: not a syscall 1650 int _sys_tty_release() // NOTE: not a syscall: used by _ctx_kill_thread() 1553 1651 { 1554 1652 unsigned int channel = _get_context_slot( CTX_TTY_ID ); … … 1559 1657 _printf("\n[GIET_ERROR] in _sys_tty_release() : " 1560 1658 "TTY channel already released for thread %x\n", trdid ); 1561 return -1111; 1659 1660 return SYSCALL_CHANNEL_ALREADY_ALLOCATED; 1562 1661 } 1563 1662 … … 1574 1673 } 1575 1674 1576 return GIET_SYSCALL_OK;1675 return SYSCALL_OK; 1577 1676 } // end sys_tty_release() 1578 1677 … … 1586 1685 // compute and check tty channel 1587 1686 if( channel == 0xFFFFFFFF ) channel = _get_context_slot(CTX_TTY_ID); 1588 if( channel >= NB_TTY_CHANNELS ) return -1111; 1687 1688 if( channel >= NB_TTY_CHANNELS ) 1689 { 1690 _printf("\n[GIET_ERROR] in _sys_tty_write() : " 1691 "no TTY channel allocated for thread %x\n", _get_thread_trdid() ); 1692 1693 return SYSCALL_CHANNEL_NON_ALLOCATED; 1694 } 1589 1695 1590 1696 // write string to TTY channel … … 1612 1718 // compute and check tty channel 1613 1719 if( channel == 0xFFFFFFFF ) channel = _get_context_slot(CTX_TTY_ID); 1614 if( channel >= NB_TTY_CHANNELS ) return -1111; 1720 1721 if( channel >= NB_TTY_CHANNELS ) 1722 { 1723 _printf("\n[GIET_ERROR] in _sys_tty_read() : " 1724 "no TTY channel allocated for thread %x\n", _get_thread_trdid() ); 1725 1726 return SYSCALL_CHANNEL_NON_ALLOCATED; 1727 } 1615 1728 1616 1729 unsigned int save_sr; … … 1676 1789 _printf("\n[GIET_ERROR] in _sys_tim_alloc() : " 1677 1790 "TIMER channel already allocated to thread %x\n", trdid ); 1678 return -1111; 1791 1792 return SYSCALL_CHANNEL_ALREADY_ALLOCATED; 1679 1793 } 1680 1794 … … 1690 1804 _printf("\n[GIET_ERROR] in _sys_tim_alloc() : " 1691 1805 "no TIMER channel available for thread %x\n", trdid ); 1692 return -1111; 1806 1807 return SYSCALL_NO_CHANNEL_AVAILABLE; 1693 1808 } 1694 1809 … … 1707 1822 _set_context_slot( CTX_TIM_ID, channel ); 1708 1823 1709 return GIET_SYSCALL_OK;1824 return SYSCALL_OK; 1710 1825 1711 1826 #else 1712 1827 1713 _printf("\n[GIET ERROR] in _sys_tim_alloc() : NB_TIM_CHANNELS = 0\n"); 1714 return -1111; 1828 _printf("\n[GIET ERROR] in _sys_tim_alloc(): NB_TIM_CHANNELS == 0\n"); 1829 1830 return SYSCALL_NO_CHANNEL_AVAILABLE; 1715 1831 1716 1832 #endif … … 1719 1835 1720 1836 ////////////////////// 1721 int _sys_tim_release() // NOTE: not a syscall 1837 int _sys_tim_release() // NOTE: not a syscall: used by _ctx_kill_thread() 1722 1838 { 1723 1839 … … 1729 1845 { 1730 1846 unsigned int trdid = _get_thread_trdid(); 1731 _printf("\n[GIET_ERROR] in _sys_tim_release() 1847 _printf("\n[GIET_ERROR] in _sys_tim_release(): " 1732 1848 "TIMER channel already released for thread %x\n", trdid ); 1733 return -1111; 1849 1850 return SYSCALL_CHANNEL_ALREADY_ALLOCATED; 1734 1851 } 1735 1852 … … 1746 1863 } 1747 1864 1748 return GIET_SYSCALL_OK;1865 return SYSCALL_OK; 1749 1866 1750 1867 #else 1751 1868 1752 _printf("\n[GIET ERROR] in _sys_tim_release() : NB_TIM_CHANNELS = 0\n"); 1753 return -1111; 1869 _printf("\n[GIET ERROR] in _sys_tim_release(): NB_TIM_CHANNELS = 0\n"); 1870 1871 return SYSCALL_NO_CHANNEL_AVAILABLE; 1754 1872 1755 1873 #endif … … 1764 1882 // get timer index 1765 1883 unsigned int channel = _get_context_slot( CTX_TIM_ID ); 1884 1766 1885 if ( channel >= NB_TIM_CHANNELS ) 1767 1886 { 1768 _printf("\n[GIET_ERROR] in _sys_tim_start() : not enough TIM channels\n"); 1769 return -1111; 1887 _printf("\n[GIET_ERROR] in _sys_tim_start(): not enough TIM channels\n"); 1888 1889 return SYSCALL_NO_CHANNEL_AVAILABLE; 1770 1890 } 1771 1891 … … 1773 1893 _timer_start( channel, period ); 1774 1894 1775 return GIET_SYSCALL_OK;1895 return SYSCALL_OK; 1776 1896 1777 1897 #else 1778 1898 1779 1899 _printf("\n[GIET ERROR] in _sys_tim_start() : NB_TIM_CHANNELS = 0\n"); 1780 return -1111; 1900 1901 return SYSCALL_NO_CHANNEL_AVAILABLE; 1781 1902 1782 1903 #endif … … 1791 1912 // get timer index 1792 1913 unsigned int channel = _get_context_slot( CTX_TIM_ID ); 1914 1793 1915 if ( channel >= NB_TIM_CHANNELS ) 1794 1916 { 1795 1917 _printf("\n[GIET_ERROR] in _sys_tim_stop() : illegal timer index\n"); 1796 return -1111; 1918 1919 return SYSCALL_CHANNEL_NON_ALLOCATED; 1797 1920 } 1798 1921 … … 1800 1923 _timer_stop( channel ); 1801 1924 1802 return GIET_SYSCALL_OK;1925 return SYSCALL_OK; 1803 1926 1804 1927 #else 1805 1928 1806 1929 _printf("\n[GIET ERROR] in _sys_tim_stop() : NB_TIM_CHANNELS = 0\n"); 1807 return -1111; 1930 1931 return SYSCALL_NO_CHANNEL_AVAILABLE; 1808 1932 1809 1933 #endif … … 1838 1962 _printf("\n[GIET_ERROR] in _sys_nic_alloc() " 1839 1963 "xmax or ymax argument too large for thread %x\n", trdid ); 1840 return -1111; 1964 1965 return SYSCALL_ILLEGAL_XY_ARGUMENTS; 1841 1966 } 1842 1967 … … 1861 1986 _printf("\n[GIET_ERROR] in _sys_nic_alloc() : " 1862 1987 "no NIC channel available for thread %x\n", trdid ); 1863 return -1111; 1988 1989 return SYSCALL_NO_CHANNEL_AVAILABLE; 1864 1990 } 1865 1991 … … 1877 2003 if ( is_rx ) _nic_rx_channel_alloc[nic_channel] = 0; 1878 2004 else _nic_tx_channel_alloc[nic_channel] = 0; 1879 return -1111; 2005 2006 return SYSCALL_NO_CHANNEL_AVAILABLE; 1880 2007 } 1881 2008 1882 2009 #if GIET_DEBUG_NIC 1883 _printf("\n[ GIET DEBUG NIC] Thread %d enterssys_nic_alloc() at cycle %d\n"1884 " 1885 trdid , _get_proctime(), nic_channel , cma_channel );2010 _printf("\n[DEBUG NIC] sys_nic_alloc() at cycle %d\n" 2011 "thread %d get nic_channel = %d / cma_channel = %d\n", 2012 _get_proctime() , trdid , nic_channel , cma_channel ); 1886 2013 #endif 1887 2014 … … 1910 2037 _nic_rx_channel_alloc[nic_channel] = 0; 1911 2038 _cma_channel_alloc[cma_channel] = 0; 1912 return -1111; 2039 2040 return SYSCALL_CHANNEL_ALREADY_ALLOCATED; 1913 2041 } 1914 2042 else … … 1927 2055 _nic_tx_channel_alloc[nic_channel] = 0; 1928 2056 _cma_channel_alloc[cma_channel] = 0; 1929 return -1111; 2057 2058 return SYSCALL_CHANNEL_ALREADY_ALLOCATED; 1930 2059 } 1931 2060 else … … 1971 2100 { 1972 2101 _printf("\n[GIET_ERROR] in _sys_nic_alloc() : " 1973 "not enough kenel heap in cluster[%d,%d]\n", cx, cy ); 1974 return -1111; 2102 "not enough kernel heap in cluster[%d,%d]\n", cx, cy ); 2103 2104 return SYSCALL_OUT_OF_KERNEL_HEAP_MEMORY; 1975 2105 } 1976 2106 … … 1982 2112 { 1983 2113 _printf("\n[GIET ERROR] in _sys_nic_alloc() : " 1984 "container address of cluster[%d,%d] not aligned\n", cx, cy); 1985 return -1111; 2114 "container address in cluster[%d,%d] not aligned\n", cx, cy); 2115 2116 return SYSCALL_ADDRESS_NON_ALIGNED; 1986 2117 } 1987 2118 1988 2119 #if GIET_DEBUG_NIC 1989 _printf("\n[GIET DEBUG NIC] Task %d in _sys_nic_alloc()\n" 1990 " allocates in cluster[%d,%d]:\n" 1991 " - container vaddr = %x / paddr = %l\n", 1992 thread , cx , cy , vaddr, cont_paddr ); 2120 _printf("\n[DEBUG NIC] _sys_nic_alloc() at cycle %d\n" 2121 "thread %x allocates a container in cluster[%d,%d] / vaddr = %x / paddr = %l\n", 2122 -get_proctime() , trdid , cx , cy , vaddr, cont_paddr ); 1993 2123 #endif 1994 2124 … … 2001 2131 _printf("\n[GIET_ERROR] in _sys_nic_alloc() : " 2002 2132 "not enough kernel heap in cluster[%d,%d]\n", cx, cy ); 2003 return -1111; 2133 2134 return SYSCALL_OUT_OF_KERNEL_HEAP_MEMORY; 2004 2135 } 2005 2136 … … 2011 2142 { 2012 2143 _printf("\n[GIET ERROR] in _sys_nic_alloc() : " 2013 "status address of cluster[%d,%d] not aligned\n", cx, cy); 2014 return -1111; 2144 "status address in cluster[%d,%d] not aligned\n", cx, cy); 2145 2146 return SYSCALL_ADDRESS_NON_ALIGNED; 2015 2147 } 2016 2148 … … 2034 2166 2035 2167 #if GIET_DEBUG_NIC 2036 _printf("\n[ GIET DEBUG NIC] Task %d in _sys_nic_alloc()\n"2037 " - statusvaddr = %x / paddr = %l\n"2038 " Bufferdescriptor = %l\n",2039 thread, vaddr, sts_paddr,2168 _printf("\n[DEBUG NIC] _sys_nic_alloc() at cycle %d\n" 2169 "thread %x allocates a status in cluster[%d,%d] / vaddr = %x / paddr = %l\n" 2170 " descriptor = %l\n", 2171 _get_proctime() , trdid , cx , cy , vaddr, sts_paddr, 2040 2172 (unsigned long long)((sts_paddr & 0xFFFFFFFFULL) >> 6) + 2041 2173 (((cont_paddr & 0xFFFFFFFFFFFULL) >> 6) << 26) ); … … 2063 2195 2064 2196 #if GIET_DEBUG_NIC 2065 _printf("\n[ GIET DEBUG NIC] Task %d in _sys_nic_alloc() get kernel chbuf\n"2066 " 2067 thread , vaddr , ker_chbuf_pbase );2197 _printf("\n[DEBUG NIC] _sys_nic_alloc() at cycle %d\n" 2198 "thread %x initialise kernel chbuf / vaddr = %x / paddr = %l\n", 2199 _get_proctime() , trdid , vaddr , ker_chbuf_pbase ); 2068 2200 #endif 2069 2201 … … 2082 2214 2083 2215 #if GIET_DEBUG_NIC 2084 _printf("\n[GIET DEBUG NIC] Task %d in _sys_nic_alloc() get NIC chbuf : paddr = %l\n", 2085 thread , nic_chbuf_pbase ); 2216 _printf("\n[DEBUG NIC] _sys_nic_alloc() at cycle %d\n" 2217 "thread %x get NIC chbuf paddr = %l\n", 2218 _get_proctime() , trdid , nic_chbuf_pbase ); 2086 2219 #endif 2087 2220 … … 2110 2243 2111 2244 #if GIET_DEBUG_NIC 2112 _printf("\n[GIET DEBUG NIC] Task %d exit _sys_nic_alloc() at cycle %d\n", 2113 thread, _get_proctime() ); 2114 #endif 2115 2116 return GIET_SYSCALL_OK; 2245 _printf("\n[DEBUG NIC] _sys_nic_alloc() at cycle %d\n" 2246 "thread %x exit\n", 2247 _get_proctime() , trdid ); 2248 #endif 2249 2250 return SYSCALL_OK; 2117 2251 } // end _sys_nic_alloc() 2118 2252 2119 2253 2120 2254 ////////////////////////////////////////// 2121 int _sys_nic_release( unsigned int is_rx ) // NOTE: not a syscall 2255 int _sys_nic_release( unsigned int is_rx ) // NOTE: not a syscall: used by _ctx_kill_thread() 2122 2256 { 2123 2257 unsigned int trdid = _get_thread_trdid(); … … 2136 2270 _printf("\n[GIET ERROR] in _sys_nic_release() : " 2137 2271 "NIC_RX channel already released for thread %x\n", trdid ); 2138 return -1111; 2272 2273 return SYSCALL_CHANNEL_NON_ALLOCATED; 2139 2274 } 2140 2275 if ( (cma_channel >= NB_CMA_CHANNELS) ) … … 2142 2277 _printf("\n[GIET ERROR] in _sys_nic_release() : " 2143 2278 "CMA_RX channel already released for thread %x\n", trdid ); 2144 return -1111; 2279 2280 return SYSCALL_CHANNEL_NON_ALLOCATED; 2145 2281 } 2146 2282 … … 2166 2302 _printf("\n[GIET ERROR] in _sys_nic_release() : " 2167 2303 "NIC_TX channel already released for thread %x\n", trdid ); 2168 return -1111; 2304 2305 return SYSCALL_CHANNEL_NON_ALLOCATED; 2169 2306 } 2170 2307 if ( (cma_channel >= NB_CMA_CHANNELS) ) … … 2172 2309 _printf("\n[GIET ERROR] in _sys_nic_release() : " 2173 2310 "CMA_TX channel already released for thread %x\n", trdid ); 2174 return -1111; 2311 2312 return SYSCALL_CHANNEL_NON_ALLOCATED; 2175 2313 } 2176 2314 … … 2188 2326 } 2189 2327 2190 return GIET_SYSCALL_OK;2328 return SYSCALL_OK; 2191 2329 } // end sys_nic_release() 2192 2330 … … 2213 2351 2214 2352 #if GIET_DEBUG_NIC 2215 _printf("\n[ GIET DEBUG NIC] Thread %x in_sys_nic_start() at cycle %d\n"2216 " getNIC channel = %d / CMA channel = %d\n",2217 trdid, _get_proctime(), nic_channel, cma_channel );2353 _printf("\n[DEBUG NIC] _sys_nic_start() at cycle %d\n" 2354 "thread %x enter / NIC channel = %d / CMA channel = %d\n", 2355 _get_proctime() , trdid , nic_channel, cma_channel ); 2218 2356 #endif 2219 2357 … … 2241 2379 2242 2380 #if GIET_DEBUG_NIC 2243 _printf("\n[GIET DEBUG NIC] Task %d exit _sys_nic_start() at cycle %d\n", 2244 trdid , _get_proctime() ); 2245 #endif 2246 2247 return GIET_SYSCALL_OK; 2381 _printf("\n[DEBUG NIC] _sys_nic_start() at cycle %d\n" 2382 "thread %d exit\n", 2383 _get_proctime() , trdid ); 2384 #endif 2385 2386 return SYSCALL_OK; 2248 2387 } // end _sys_nic_start() 2249 2388 … … 2258 2397 2259 2398 #if GIET_DEBUG_NIC 2260 _printf("\n[GIET DEBUG NIC] Task %d enters _sys_nic_move() at cycle %d\n", 2261 trdid , _get_proctime() ); 2399 _printf("\n[DEBUG NIC] _sys_nic_move() at cycle %d\n", 2400 "thread %x enters\n", 2401 _get_proctime() , trdid ); 2262 2402 #endif 2263 2403 … … 2270 2410 { 2271 2411 _printf("\n[GIET_ERROR] in _sys_nic_move() : " 2272 "illegal NIC channel index for thread %x\n", trdid ); 2273 return -1111; 2412 "NIC channel non allocated for thread %x\n", trdid ); 2413 2414 return SYSCALL_CHANNEL_NON_ALLOCATED; 2274 2415 } 2275 2416 … … 2289 2430 2290 2431 // check processor coordinates / (xmax,ymax) 2291 if ( cx >= xmax ) 2292 { 2293 _printf("\n[GIET_ERROR] in _sys_nic_move() : processor X coordinate = %d" 2294 " / xmax = %d\n", cx , xmax ); 2295 return -1111; 2296 } 2297 if ( cy >= ymax ) 2298 { 2299 _printf("\n[GIET_ERROR] in _sys_nic_move() : processor Y coordinate = %d" 2300 " / ymax = %d\n", cy , ymax ); 2301 return -1111; 2432 if ( (cx >= xmax) || (cy >= ymax) ) 2433 { 2434 _printf("\n[GIET_ERROR] in _sys_nic_move(): " 2435 "processor coordinates [%d,%d] larger than (xmax,ymax) = [%d,%d]\n", 2436 cx , cy , xmax , ymax ); 2437 2438 return SYSCALL_ILLEGAL_XY_ARGUMENTS; 2302 2439 } 2303 2440 … … 2315 2452 if ( (flags & PTE_U) == 0 ) 2316 2453 { 2317 _printf("\n[GIET ERROR] in _sys_nic_tx_move() : illegal user buffer address\n"); 2318 return -1111; 2454 _printf("\n[GIET ERROR] in _sys_nic_tx_move() : " 2455 "buffer address non user accessible\n"); 2456 2457 return SYSCALL_ADDRESS_NON_USER_ACCESSIBLE; 2319 2458 } 2320 2459 2321 2460 #if GIET_DEBUG_NIC 2322 _printf("\n[GIET DEBUG NIC] Task %d in _sys_nic_move() get user buffer : paddr = %l\n", 2323 thread, usr_buf_paddr ); 2461 _printf("\n[DEBUG NIC] _sys_nic_move() at cycle %d\n" 2462 "thread %x get user buffer : paddr = %l\n", 2463 _get_proctime() , trdid , usr_buf_paddr ); 2324 2464 #endif 2325 2465 … … 2331 2471 2332 2472 #if GIET_DEBUG_NIC 2333 _printf("\n[ GIET DEBUG NIC] Task %d in _sys_nic_move() read ker_buf_desc %dat cycle %d\n"2334 " kernel buffer descriptor = %l\n",2335 thread, index, _get_proctime(), ker_buf_desc );2473 _printf("\n[DEBUG NIC] _sys_nic_move() at cycle %d\n" 2474 "thread %x get ker_buf_desc %d / paddr = %l\n", 2475 _get_proctime(), trdid , index , ker_buf_desc ); 2336 2476 #endif 2337 2477 … … 2344 2484 2345 2485 #if GIET_DEBUG_NIC 2346 _printf("\n[ GIET DEBUG NIC] Task %d in _sys_nic_move() read ker_buf_sts %dat cycle %d\n"2347 " paddr = %l / kernel bufferstatus = %x\n",2348 thread, index, _get_proctime(), ker_sts_paddr, ker_sts );2486 _printf("\n[DEBUG NIC] _sys_nic_move() at cycle %d\n" 2487 "thread %x get status %d / paddr = %l / status = %x\n", 2488 _get_proctime() , trdid , index , ker_sts_paddr, ker_sts ); 2349 2489 #endif 2350 2490 … … 2368 2508 NIC_CONTAINER_SIZE ); 2369 2509 #if GIET_DEBUG_NIC 2370 _printf("\n[ GIET DEBUG NIC] Task %d in _sys_nic_move() transfer kernel buffer %l\n"2371 " to user buffer %l at cycle %d\n",2372 thread , ker_buf_paddr , usr_buf_paddr , _get_proctime());2510 _printf("\n[DEBUG NIC] _sys_nic_move() at cycle %d\n" 2511 "thread %x transfer kernel buffer %l to user buffer %l\n", 2512 _get_proctime() , trdid , ker_buf_paddr , usr_buf_paddr ); 2373 2513 #endif 2374 2514 … … 2385 2525 2386 2526 #if GIET_DEBUG_NIC 2387 _printf("\n[ GIET DEBUG NIC] Task %d in _sys_nic_move() transfer"2388 " user buffer %l to kernel buffer %l at cycle %d\n",2389 thread , usr_buf_paddr , ker_buf_paddr , _get_proctime());2527 _printf("\n[DEBUG NIC] _sys_nic_move() at cycle %d\n" 2528 "thread %x transfer user buffer %l to kernel buffer %l\n", 2529 _get_proctime() , trdid , usr_buf_paddr , ker_buf_paddr ); 2390 2530 #endif 2391 2531 … … 2400 2540 2401 2541 #if GIET_DEBUG_NIC 2402 _printf("\n[GIET DEBUG NIC] Task %d get buffer %d and exit _sys_nic_move() at cycle %d\n", 2403 thread , index , _get_proctime() ); 2404 #endif 2405 2406 return GIET_SYSCALL_OK; 2542 _printf("\n[DEBUG NIC] _sys_nic_move() at cycle %d\n" 2543 "thread %x exit\n", 2544 _get_proctime() , trdid ); 2545 #endif 2546 2547 return SYSCALL_OK; 2407 2548 } // end _sys_nic_move() 2408 2549 … … 2432 2573 { 2433 2574 _printf("\n[GIET_ERROR] in _sys_nic_stop() : " 2434 "illegal NIC channel for thread %x\n", trdid ); 2435 return -1111; 2575 "NIC channel non allocated for thread %x\n", trdid ); 2576 2577 return SYSCALL_CHANNEL_NON_ALLOCATED; 2436 2578 } 2437 2579 if ( cma_channel >= NB_CMA_CHANNELS ) 2438 2580 { 2439 2581 _printf("\n[GIET_ERROR] in _sys_nic_stop() : " 2440 "illegal CMA channel for thread %x\n", trdid ); 2441 return -1111; 2582 "CMA channel non allocated for thread %x\n", trdid ); 2583 2584 return SYSCALL_CHANNEL_NON_ALLOCATED; 2442 2585 } 2443 2586 … … 2450 2593 { 2451 2594 status = _cma_get_register( cma_channel, CHBUF_STATUS ); 2452 } while ( status ); 2595 } 2596 while ( status ); 2453 2597 2454 2598 // desactivates the NIC channel 2455 2599 _nic_channel_stop( nic_channel, is_rx ); 2456 2600 2457 return GIET_SYSCALL_OK;2601 return SYSCALL_OK; 2458 2602 } // end _sys_nic_stop() 2459 2603 … … 2472 2616 { 2473 2617 _printf("\n[GIET_ERROR] in _sys_nic_clear() : " 2474 "illegal NIC channel for thread %x\n", trdid ); 2475 return -1111; 2618 "NIC channel non allocated for thread %x\n", trdid ); 2619 2620 return SYSCALL_CHANNEL_NON_ALLOCATED; 2476 2621 } 2477 2622 … … 2498 2643 _nic_set_global_register( NIC_G_NPKT_TX_DISPATCH_BROADCAST , 0 ); 2499 2644 } 2500 return GIET_SYSCALL_OK;2645 return SYSCALL_OK; 2501 2646 } // en _sys_nic_clear() 2502 2647 … … 2515 2660 { 2516 2661 _printf("\n[GIET_ERROR] in _sys_nic_stats() : " 2517 "illegal NIC channel for thread %x\n", trdid ); 2518 return -1111; 2662 "NIC channel non allocated for thread %x\n", trdid ); 2663 2664 return SYSCALL_CHANNEL_NON_ALLOCATED; 2519 2665 } 2520 2666 … … 2571 2717 broadcast ); 2572 2718 } 2573 return GIET_SYSCALL_OK;2719 return SYSCALL_OK; 2574 2720 } // end _sys_nic_stats() 2575 2721 … … 2579 2725 // FBF related syscall handlers 2580 2726 ///////////////////////////////////////////////////////////////////////////////////////// 2727 2728 ////////////////////////////////////// 2729 int _sys_fbf_size( unsigned int* width, 2730 unsigned int* height ) 2731 { 2732 if ( USE_FBF == 0 ) 2733 { 2734 *width = 0; 2735 *height = 0; 2736 } 2737 else 2738 { 2739 *width = FBUF_X_SIZE; 2740 *height = FBUF_Y_SIZE; 2741 } 2742 2743 return SYSCALL_OK; 2744 } 2745 2746 //////////////////// 2747 int _sys_fbf_alloc() 2748 { 2749 mapping_header_t *header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; 2750 mapping_vspace_t *vspace = _get_vspace_base(header); 2751 mapping_thread_t *thread = _get_thread_base(header); 2752 2753 // compute number of users 2754 unsigned int vsid = _get_context_slot(CTX_VSID_ID); 2755 unsigned int users = vspace[vsid].threads; 2756 2757 // access FBF allocator 2758 // register it in all threads contexts 2759 if ( _atomic_test_and_set( &_fbf_alloc , users ) == 0 ) // FBF available 2760 { 2761 unsigned int min = vspace[vsid].thread_offset; 2762 unsigned int max = min + users; 2763 unsigned int tid; 2764 for ( tid = min ; tid < max ; tid++ ) 2765 { 2766 unsigned int y_size = header->y_size; 2767 unsigned int cid = thread[tid].clusterid; 2768 unsigned int x = cid / y_size; 2769 unsigned int y = cid % y_size; 2770 unsigned int p = thread[tid].proclocid; 2771 unsigned int ltid = thread[tid].ltid; 2772 static_scheduler_t* psched = (static_scheduler_t*)_schedulers[x][y][p]; 2773 _atomic_or( &psched->context[ltid].slot[CTX_LOCKS_ID] , LOCKS_MASK_FBF ); 2774 } 2775 return SYSCALL_OK; 2776 } 2777 else // FBF already allocated 2778 { 2779 return SYSCALL_SHARED_PERIPHERAL_BUSY; 2780 } 2781 } 2782 2783 ////////////////////// 2784 int _sys_fbf_release() // not a syscall: used by _ctx_kill_thread() 2785 { 2786 // get calling thread scheduler, ltid and trdid 2787 static_scheduler_t* psched = _get_sched(); 2788 unsigned int ltid = _get_thread_ltid(); 2789 unsigned int trdid = _get_thread_trdid(); 2790 2791 if ( (psched->context[ltid].slot[CTX_LOCKS_ID] & LOCKS_MASK_FBF) == 0 ) 2792 { 2793 _printf("\n[GIET ERROR] in _sys_fbf_release() : " 2794 "FBF not allocated to thread %x\n", trdid ); 2795 2796 return SYSCALL_CHANNEL_NON_ALLOCATED; 2797 } 2798 2799 // decrement FBF allocator 2800 // reset the calling thread context 2801 _atomic_increment( &_fbf_alloc , 0xFFFFFFFF ); 2802 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FBF ); 2803 2804 return SYSCALL_OK; 2805 } 2581 2806 2582 2807 ///////////////////////////////////////////// … … 2585 2810 unsigned int length ) 2586 2811 { 2812 // get calling thread scheduler, ltid and trdid 2813 static_scheduler_t* psched = _get_sched(); 2814 unsigned int ltid = _get_thread_ltid(); 2815 unsigned int trdid = _get_thread_trdid(); 2816 2817 if ( (psched->context[ltid].slot[CTX_LOCKS_ID] & LOCKS_MASK_FBF) == 0 ) 2818 { 2819 _printf("\n[GIET ERROR] in _sys_fbf_release() : " 2820 "FBF not allocated to thread %x\n", trdid ); 2821 2822 return SYSCALL_CHANNEL_NON_ALLOCATED; 2823 } 2824 2587 2825 char* fbf_address = (char *)SEG_FBF_BASE + offset; 2588 2826 memcpy( fbf_address, buffer, length); 2589 2827 2590 return GIET_SYSCALL_OK;2828 return SYSCALL_OK; 2591 2829 } 2592 2830 … … 2596 2834 unsigned int length ) 2597 2835 { 2836 // get calling thread scheduler, ltid and trdid 2837 static_scheduler_t* psched = _get_sched(); 2838 unsigned int ltid = _get_thread_ltid(); 2839 unsigned int trdid = _get_thread_trdid(); 2840 2841 if ( (psched->context[ltid].slot[CTX_LOCKS_ID] & LOCKS_MASK_FBF) == 0 ) 2842 { 2843 _printf("\n[GIET ERROR] in _sys_fbf_release() : " 2844 "FBF not allocated to thread %x\n", trdid ); 2845 2846 return SYSCALL_CHANNEL_NON_ALLOCATED; 2847 } 2848 2598 2849 char* fbf_address = (char *)SEG_FBF_BASE + offset; 2599 2850 memcpy( buffer, fbf_address, length); 2600 2851 2601 return GIET_SYSCALL_OK;2852 return SYSCALL_OK; 2602 2853 } 2603 2854 … … 2611 2862 _printf("\n[GIET ERROR] in _sys_fbf_cma_alloc() : " 2612 2863 "CMA channel already allocated for thread %x\n", trdid ); 2613 return GIET_SYSCALL_OK; 2864 2865 return SYSCALL_CHANNEL_ALREADY_ALLOCATED; 2614 2866 } 2615 2867 … … 2624 2876 { 2625 2877 _printf("\n[GIET ERROR] in _sys_fbf_cma_alloc() : no CMA channel available\n"); 2626 return -1111; 2878 2879 return SYSCALL_NO_CHANNEL_AVAILABLE; 2627 2880 } 2628 2881 else 2629 2882 { 2630 2883 _set_context_slot( CTX_CMA_FB_ID, channel ); 2631 return GIET_SYSCALL_OK; 2884 2885 return SYSCALL_OK; 2632 2886 } 2633 2887 } // end sys_fbf_cma_alloc() … … 2642 2896 { 2643 2897 _printf("\n[GIET_ERROR] in _sys_fbf_cma_release() : " 2644 "CMA_FB channel already releasedifor thread %x\n", trdid ); 2645 return -1111; 2898 "CMA_FB channel already released for thread %x\n", trdid ); 2899 2900 return SYSCALL_CHANNEL_NON_ALLOCATED; 2646 2901 } 2647 2902 … … 2655 2910 _cma_channel_alloc[channel] = 0; 2656 2911 2657 return GIET_SYSCALL_OK;2912 return SYSCALL_OK; 2658 2913 } 2659 2914 … … 2664 2919 void* sts1_vaddr ) 2665 2920 { 2666 #if NB_CMA_CHANNELS > 02667 2668 2921 unsigned int vaddr; // virtual address 2669 2922 unsigned int flags; // for _v2p_translate() … … 2675 2928 unsigned long long sts1_paddr; // buffer 1 status physical address 2676 2929 2930 // get calling thread scheduler, ltid and trdid 2931 static_scheduler_t* psched = _get_sched(); 2932 unsigned int ltid = _get_thread_ltid(); 2933 unsigned int trdid = _get_thread_trdid(); 2934 2935 // check FBF allocated 2936 if ( (psched->context[ltid].slot[CTX_LOCKS_ID] & LOCKS_MASK_FBF) == 0 ) 2937 { 2938 _printf("\n[GIET ERROR] in _sys_fbf_cma_init_buf() : " 2939 "FBF not allocated to thread %x\n", trdid ); 2940 2941 return SYSCALL_CHANNEL_NON_ALLOCATED; 2942 } 2943 2677 2944 // get channel index 2678 2945 unsigned int channel = _get_context_slot( CTX_CMA_FB_ID ); … … 2680 2947 if ( channel >= NB_CMA_CHANNELS ) 2681 2948 { 2682 _printf("\n[GIET ERROR] in _sys_fbf_cma_init_buf() : CMA channel index too large\n"); 2683 return -1111; 2949 _printf("\n[GIET ERROR] in _sys_fbf_cma_init_buf() : " 2950 "CMA channel non allocated to thread %x\n", trdid ); 2951 2952 return SYSCALL_CHANNEL_NON_ALLOCATED; 2684 2953 } 2685 2954 2686 2955 #if GIET_DEBUG_FBF_CMA 2687 _printf("\n[FBF_CMA DEBUG] enters_sys_fbf_cma_init_buf()\n"2956 _printf("\n[FBF_CMA DEBUG] _sys_fbf_cma_init_buf()\n" 2688 2957 " - channel = %d\n" 2689 2958 " - buf0 vbase = %x\n" … … 2702 2971 ((unsigned int)buf1_vbase & 0x3F) ) 2703 2972 { 2704 _printf("\n[GIET ERROR] in _sys_fbf_cma_init_buf() : user buffer not aligned\n"); 2705 return -1111; 2973 _printf("\n[GIET ERROR] in _sys_fbf_cma_init_buf() : " 2974 "user buffer not aligned for thread %x\n", trdid ); 2975 2976 return SYSCALL_ADDRESS_NON_ALIGNED; 2706 2977 } 2707 2978 … … 2710 2981 ((unsigned int)sts1_vaddr & 0x3F) ) 2711 2982 { 2712 _printf("\n[GIET ERROR] in _sys_fbf_cma_init_buf() : user status not aligned\n"); 2713 return -1111; 2983 _printf("\n[GIET ERROR] in _sys_fbf_cma_init_buf() : " 2984 "user status not aligned for thread %x\n", trdid ); 2985 2986 return SYSCALL_ADDRESS_NON_ALIGNED; 2714 2987 } 2715 2988 … … 2729 3002 if ((flags & PTE_U) == 0) 2730 3003 { 2731 _printf("\n[GIET ERROR] in _sys_fbf_cma_init_buf() : buf0 not in user space\n"); 2732 return -1111; 3004 _printf("\n[GIET ERROR] in _sys_fbf_cma_init_buf() : " 3005 "buf0 not in user space for thread %x\n", trdid ); 3006 3007 return SYSCALL_ADDRESS_NON_USER_ACCESSIBLE; 2733 3008 } 2734 3009 … … 2737 3012 if ((flags & PTE_U) == 0) 2738 3013 { 2739 _printf("\n[GIET ERROR] in _sys_fbf_cma_init_buf() : sts0 not in user space\n"); 2740 return -1111; 3014 _printf("\n[GIET ERROR] in _sys_fbf_cma_init_buf() : " 3015 "sts0 not in user space for thread %x\n", trdid); 3016 3017 return SYSCALL_ADDRESS_NON_USER_ACCESSIBLE; 2741 3018 } 2742 3019 … … 2750 3027 if ((flags & PTE_U) == 0) 2751 3028 { 2752 _printf("\n[GIET ERROR] in _sys_fbf_cma_init_buf() : buf1 not in user space\n"); 2753 return -1111; 3029 _printf("\n[GIET ERROR] in _sys_fbf_cma_init_buf() : " 3030 "buf1 not in user space for thread %x\n", trdid ); 3031 3032 return SYSCALL_ADDRESS_NON_USER_ACCESSIBLE; 2754 3033 } 2755 3034 … … 2758 3037 if ((flags & PTE_U) == 0) 2759 3038 { 2760 _printf("\n[GIET ERROR] in _sys_fbf_cma_init_buf() : sts1 not in user space\n"); 2761 return -1111; 3039 _printf("\n[GIET ERROR] in _sys_fbf_cma_init_buf() : " 3040 "sts1 not in user space for thread %x\n", trdid); 3041 3042 return SYSCALL_ADDRESS_NON_USER_ACCESSIBLE; 2762 3043 } 2763 3044 … … 2787 3068 #endif 2788 3069 2789 return GIET_SYSCALL_OK; 2790 2791 #else 2792 2793 _printf("\n[GIET ERROR] in _sys_fbf_cma_init_buf() : NB_CMA_CHANNELS = 0\n"); 2794 return -1111; 2795 2796 #endif 3070 return SYSCALL_OK; 3071 2797 3072 } // end sys_fbf_cma_init_buf() 2798 3073 … … 2800 3075 int _sys_fbf_cma_start( unsigned int length ) 2801 3076 { 2802 #if NB_CMA_CHANNELS > 0 3077 // get calling thread scheduler, ltid and trdid 3078 static_scheduler_t* psched = _get_sched(); 3079 unsigned int ltid = _get_thread_ltid(); 3080 unsigned int trdid = _get_thread_trdid(); 3081 3082 // check FBF allocated 3083 if ( (psched->context[ltid].slot[CTX_LOCKS_ID] & LOCKS_MASK_FBF) == 0 ) 3084 { 3085 _printf("\n[GIET ERROR] in _sys_fbf_release() : " 3086 "FBF not allocated to thread %x\n", trdid ); 3087 3088 return SYSCALL_CHANNEL_NON_ALLOCATED; 3089 } 2803 3090 2804 3091 // get channel index … … 2807 3094 if ( channel >= NB_CMA_CHANNELS ) 2808 3095 { 2809 _printf("\n[GIET ERROR] in _fbf_cma_start() : CMA channel index too large\n"); 2810 return -1111; 3096 _printf("\n[GIET ERROR] in _fbf_cma_start() : " 3097 "CMA channel non allocated\n"); 3098 3099 return SYSCALL_CHANNEL_NON_ALLOCATED; 2811 3100 } 2812 3101 … … 2816 3105 ( _fbf_chbuf[channel].fbf_desc == 0x0ULL) ) 2817 3106 { 2818 _printf("\n[GIET ERROR] in _sys_fbf_cma_start() :\n"2819 "Buffer initialization has not been done\n"); 2820 return -1111;3107 _printf("\n[GIET ERROR] in _sys_fbf_cma_start(): initialization not done\n"); 3108 3109 return SYSCALL_MISSING_INITIALISATION; 2821 3110 } 2822 3111 … … 2847 3136 _cma_set_register( channel, CHBUF_RUN , 1 ); 2848 3137 2849 return GIET_SYSCALL_OK; 2850 2851 #else 2852 2853 _printf("\n[GIET ERROR] in _sys_fbf_cma_start() : NB_CMA_CHANNELS = 0\n"); 2854 return -1111; 2855 2856 #endif 3138 return SYSCALL_OK; 3139 2857 3140 } // end _sys_fbf_cma_start() 2858 3141 … … 2860 3143 int _sys_fbf_cma_display( unsigned int buffer_index ) 2861 3144 { 2862 #if NB_CMA_CHANNELS > 02863 2864 3145 volatile unsigned int full = 1; 3146 3147 // get calling thread scheduler, ltid and trdid 3148 static_scheduler_t* psched = _get_sched(); 3149 unsigned int ltid = _get_thread_ltid(); 3150 unsigned int trdid = _get_thread_trdid(); 3151 3152 // check FBF allocated 3153 if ( (psched->context[ltid].slot[CTX_LOCKS_ID] & LOCKS_MASK_FBF) == 0 ) 3154 { 3155 _printf("\n[GIET ERROR] in _sys_fbf_release() : " 3156 "FBF not allocated to thread %x\n", trdid ); 3157 3158 return SYSCALL_CHANNEL_NON_ALLOCATED; 3159 } 2865 3160 2866 3161 // get channel index … … 2870 3165 { 2871 3166 _printf("\n[GIET ERROR] in _sys_fbf_cma_display() : " 2872 "CMA channel index too large\n"); 2873 return -1111; 3167 "CMA channel non allocated\n"); 3168 3169 return SYSCALL_CHANNEL_NON_ALLOCATED; 2874 3170 } 2875 3171 … … 2951 3247 _mmc_sync( fbf_sts_paddr, 4 ); 2952 3248 2953 return GIET_SYSCALL_OK; 2954 2955 #else 2956 2957 _printf("\n[GIET ERROR] in _sys_fbf_cma_display() : no CMA channel allocated\n"); 2958 return -1111; 2959 2960 #endif 3249 return SYSCALL_OK; 3250 2961 3251 } // end _sys_fbf_cma_display() 2962 3252 … … 2964 3254 int _sys_fbf_cma_stop() 2965 3255 { 2966 #if NB_CMA_CHANNELS > 02967 2968 3256 // get channel index 2969 3257 unsigned int channel = _get_context_slot( CTX_CMA_FB_ID ); … … 2971 3259 if ( channel >= NB_CMA_CHANNELS ) 2972 3260 { 2973 _printf("\n[GIET ERROR] in _sys_fbf_cma_stop() : CMA channel index too large\n"); 2974 return -1111; 3261 _printf("\n[GIET ERROR] in _sys_fbf_cma_stop() : CMA channel non allocated\n"); 3262 3263 return SYSCALL_CHANNEL_NON_ALLOCATED; 2975 3264 } 2976 3265 … … 2978 3267 _cma_set_register( channel, CHBUF_RUN, 0 ); 2979 3268 2980 return GIET_SYSCALL_OK; 2981 2982 #else 2983 2984 _printf("\n[GIET ERROR] in _sys_fbf_cma_stop() : no CMA channel allocated\n"); 2985 return -1111; 2986 2987 #endif 3269 return SYSCALL_OK; 3270 2988 3271 } // end _sys_fbf_cma_stop() 2989 3272 … … 2997 3280 { 2998 3281 _printf("\n[GIET ERROR] Undefined System Call / EPC = %x\n", _get_epc() ); 2999 return GIET_SYSCALL_UNDEFINED_SYSTEM_CALL; 3282 3283 return SYSCALL_UNDEFINED_SYSTEM_CALL; 3000 3284 } 3001 3285 … … 3011 3295 *p = gpid & ((1<<P_WIDTH)-1); 3012 3296 3013 return GIET_SYSCALL_OK;3297 return SYSCALL_OK; 3014 3298 } 3015 3299 … … 3066 3350 *nprocs = 0; 3067 3351 } 3068 return GIET_SYSCALL_OK;3352 return SYSCALL_OK; 3069 3353 } 3070 3354 … … 3094 3378 { 3095 3379 *vbase = vseg[vseg_id].vbase; 3096 return GIET_SYSCALL_OK;3380 return SYSCALL_OK; 3097 3381 } 3098 3382 } 3099 3383 } 3100 3384 } 3101 return GIET_SYSCALL_VSEG_NOT_FOUND;3385 return SYSCALL_VSEG_NOT_FOUND; 3102 3386 } 3103 3387 … … 3127 3411 { 3128 3412 *length = vseg[vseg_id].length; 3129 return GIET_SYSCALL_OK;3413 return SYSCALL_OK; 3130 3414 } 3131 3415 } 3132 3416 } 3133 3417 } 3134 return GIET_SYSCALL_VSEG_NOT_FOUND;3418 return SYSCALL_VSEG_NOT_FOUND; 3135 3419 } 3136 3420 … … 3146 3430 *y = (paddr>>32) & 0xF; 3147 3431 3148 return GIET_SYSCALL_OK;3432 return SYSCALL_OK; 3149 3433 } 3150 3434 … … 3162 3446 _printf("\n[GIET ERROR] in _sys_heap_info() : " 3163 3447 "illegal (%d,%d) coordinates\n", x , y ); 3164 return GIET_SYSCALL_ILLEGAL_CLUSTER_COORDINATES;3448 return SYSCALL_ILLEGAL_CLUSTER_COORDINATES; 3165 3449 } 3166 3450 … … 3201 3485 _printf("error in _sys_heap_info() : no heap in cluster (%d,%d)\n", x , y ); 3202 3486 } 3203 return GIET_SYSCALL_OK;3487 return SYSCALL_OK; 3204 3488 } // end _sys_heap_info() 3205 3489
Note: See TracChangeset
for help on using the changeset viewer.