Ignore:
Timestamp:
Oct 1, 2015, 4:20:46 PM (9 years ago)
Author:
alain
Message:

Major release: Change the task model to implement the POSIX threads API.

  • The shell "exec" and "kill" commands can be used to activate/de-activate the applications.
  • The "pause", "resume", and "context" commands can be used to stop, restart, a single thtead or to display the thread context.

This version has been tested on the following multi-threaded applications,
that have been modified to use the POSIX threads:

  • classif
  • convol
  • transpose
  • gameoflife
  • raycast
Location:
soft/giet_vm/giet_common
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_common/kernel_locks.c

    r632 r709  
    7070        : "r" (ptr), "r" (mask)
    7171        : "$10", "$11", "$12", "memory" );
     72}
     73
     74/////////////////////////////////////////////////////
     75unsigned int _atomic_test_and_set( unsigned int* ptr,
     76                                   unsigned int  value )
     77{
     78    unsigned int ret = 1;
     79
     80    asm volatile (
     81        "ori  %0,    $0,     1         \n"   /* default : ret <= 1       */
     82        "move $10,   %1                \n"   /* $10 <= ptr               */
     83        "move $11,   %2                \n"   /* $11 <= value             */
     84        "ll   $12,   0($10)            \n"   /* $12 <= *ptr              */
     85        "bne  $12,   $0,     1515f     \n"   /* return 1 if non zero     */
     86        "sc   $11,   0($10)            \n"   /* *ptr <= $12              */
     87        "beqz $11,           1515f     \n"   /* return 1 if failure      */
     88        "ori  %0,    $0,     0         \n"   /* success : ret <= 0       */
     89        "1515:                         \n"   
     90        : "=r" (ret)
     91        : "r" (ptr), "r" (value)
     92        : "$10", "$11", "$12", "memory" );
     93
     94    return ret;
    7295}
    7396
  • soft/giet_vm/giet_common/kernel_locks.h

    r632 r709  
    2020
    2121extern unsigned int _atomic_increment( unsigned int* ptr,
    22                                        int  increment );
     22                                       int           increment );
    2323
    2424extern void _atomic_or( unsigned int* ptr,
     
    2727extern void _atomic_and( unsigned int* ptr,
    2828                         unsigned int  mask );
     29
     30extern unsigned int _atomic_test_and_set( unsigned int* ptr,
     31                                          unsigned int  value );
    2932
    3033//////////////////////////////////////////////////////////////////////////////
  • soft/giet_vm/giet_common/mips32_registers.h

    r399 r709  
    11/********************************************************************************/
    2 /*    File : mips32_registers.h                        */
    3 /*    Author : Alain Greiner                            */
    4 /*    Date : 26/03/2012                            */
     2/*    File : mips32_registers.h                                                 */
     3/*    Author : Alain Greiner                                                    */
     4/*    Date : 26/03/2012                                                         */
    55/********************************************************************************/
    6 /*     We define mnemonics for MIPS32 registers                          */
     6/*     We define mnemonics for MIPS32 registers                                 */
    77/********************************************************************************/
    88
  • soft/giet_vm/giet_common/tty0.c

    r594 r709  
    1212#include <stdarg.h>
    1313#include <tty_driver.h>
     14#include <ctx_handler.h>
    1415#include <utils.h>
    1516#include <kernel_locks.h>
     
    3031spin_lock_t          _tty0_spin_lock  __attribute__((aligned(64)));
    3132
    32 //////////////////////////////////////////////
    33 unsigned int _tty0_write( char*        buffer,
    34                           unsigned int nbytes )
     33/////////////////////////////////////////////////////
     34unsigned int _tty_channel_write( unsigned int channel,
     35                                 char*        buffer,
     36                                 unsigned int nbytes )
    3537{
    3638    unsigned int n;
     
    4042    {
    4143        // test TTY_TX buffer full
    42         if ( (_tty_get_register( 0, TTY_STATUS ) & 0x2) ) // buffer full
     44        if ( (_tty_get_register( channel , TTY_STATUS ) & 0x2) ) // buffer full
    4345        {
    4446            // retry if full
    4547            for( k = 0 ; k < 10000 ; k++ )
    4648            {
    47                 if ( (_tty_get_register( 0, TTY_STATUS ) & 0x2) == 0) break;
     49                if ( (_tty_get_register( channel , TTY_STATUS ) & 0x2) == 0) break;
    4850            }
    4951            // return error if full after 10000 retry
     
    5254
    5355        // write one byte
    54         if (buffer[n] == '\n') _tty_set_register( 0, TTY_WRITE, (unsigned int)'\r' );
    55         _tty_set_register( 0, TTY_WRITE, (unsigned int)buffer[n] );
     56        if (buffer[n] == '\n') _tty_set_register( channel, TTY_WRITE, (unsigned int)'\r' );
     57        _tty_set_register( channel, TTY_WRITE, (unsigned int)buffer[n] );
    5658    }
    5759    return 0;
     
    6567    while ( string[n] > 0 ) n++;
    6668
    67     _tty0_write( string, n );
     69    _tty_channel_write( 0, string, n );
    6870}
    6971
     
    8486        val = val >> 4;
    8587    }
    86     _tty0_write( buf, 10 );
     88    _tty_channel_write( 0, buf, 10 );
    8789}
    8890
     
    102104        val = val >> 4;
    103105    }
    104     _tty0_write( buf, 18 );
     106    _tty_channel_write( 0, buf, 18 );
    105107}
    106108
     
    126128        val /= 10;
    127129    }
    128     _tty0_write( &buf[first], 10 - first );
     130    _tty_channel_write( 0, &buf[first], 10 - first );
    129131}
    130132
     
    140142
    141143//////////////////////////////////////////////////////////
    142 static void _kernel_printf( char * format, va_list* args )
     144static void _kernel_printf( unsigned int channel,
     145                            char *       format,
     146                            va_list*     args )
    143147{
    144148
     
    151155        if (i)
    152156        {
    153             if ( _tty0_write( format, i ) ) goto return_error;
     157            if ( _tty_channel_write( channel, format, i ) ) goto return_error;
    154158            format += i;
    155159        }
     
    188192                {
    189193                    val = -val;
    190                     if ( _tty0_write( "-" , 1 ) ) goto return_error;
     194                    if ( _tty_channel_write( channel, "-" , 1 ) ) goto return_error;
    191195                }
    192196                for(i = 0; i < 10; i++)
     
    214218            {
    215219                unsigned int val = va_arg( *args , unsigned int );
    216                 if ( _tty0_write( "0x" , 2 ) ) goto return_error;
     220                if ( _tty_channel_write( channel, "0x" , 2 ) ) goto return_error;
    217221                for(i = 0; i < 8; i++)
    218222                {
     
    227231            {
    228232                unsigned int val = va_arg( *args , unsigned int );
    229                 if ( _tty0_write( "0x" , 2 ) ) goto return_error;
     233                if ( _tty_channel_write( channel, "0x" , 2 ) ) goto return_error;
    230234                for(i = 0; i < 8; i++)
    231235                {
     
    240244            {
    241245                unsigned long long val = va_arg( *args , unsigned long long );
    242                 if ( _tty0_write( "0x" , 2 ) ) goto return_error;
     246                if ( _tty_channel_write( channel, "0x" , 2 ) ) goto return_error;
    243247                for(i = 0; i < 16; i++)
    244248                {
     
    264268        }
    265269
    266         if ( _tty0_write( pbuf, len ) ) goto return_error;
     270        if ( _tty_channel_write( channel, pbuf, len ) ) goto return_error;
    267271       
    268272        goto printf_text;
     
    284288        _putd( lpid );
    285289        _puts("]\n");
    286 
    287290        _exit();
    288291    }
     
    294297    va_list   args;
    295298
     299    // call kernel_printf
    296300    va_start( args , format );
    297     _kernel_printf( format , &args );
     301    _kernel_printf( 0, format , &args );
    298302    va_end( args );
    299303}
     304
    300305////////////////////////////////
    301306void _printf( char* format, ...)
     
    309314    else                   _sqt_lock_acquire( &_tty0_sqt_lock );
    310315
     316    // call kernel_printf
    311317    va_start( args , format );
    312     _kernel_printf( format , &args );
     318    _kernel_printf( 0, format , &args );
    313319    va_end( args );
    314320
     
    318324    _it_restore( &save_sr );
    319325}
     326
     327/////////////////////////////////////
     328void _user_printf( char* format, ...)
     329{
     330    va_list   args;
     331
     332    // get calling thread TYY channel
     333    unsigned int channel = _get_context_slot( CTX_TTY_ID );
     334    if( channel >= NB_TTY_CHANNELS )
     335    {
     336        _puts("\n[GIET ERROR] in _user_printf() : no TTY allocated for thread ");
     337        _putx( _get_thread_trdid() );
     338        _puts("\n");
     339        _exit();
     340    }
     341
     342    // call kernel_printf
     343    va_start( args , format );
     344    _kernel_printf( channel, format , &args );
     345    va_end( args );
     346}
     347
    320348
    321349
  • soft/giet_vm/giet_common/tty0.h

    r466 r709  
    1414
    1515///////////////////////////////////////////////////////////////////////////////////
    16 //       Access functions to kernel terminal TTY0
     16//       Access functions to kernel terminal TTY0 (or calling thread TTY)
    1717///////////////////////////////////////////////////////////////////////////////////
    1818
     
    2727extern void         _getc( char* byte );       
    2828
     29extern void         _printf( char* format, ... );
     30
    2931extern void         _nolock_printf( char* format, ... );
    3032
    31 extern void         _printf( char* format, ... );
     33extern void         _user_printf( char* format, ... );
    3234
    3335#endif
  • soft/giet_vm/giet_common/utils.c

    r618 r709  
    1616#include <ctx_handler.h>
    1717
    18 // This variable is allocated in the boot.c file or in kernel_init.c file
    19 extern static_scheduler_t* _schedulers[X_SIZE][Y_SIZE][NB_PROCS_MAX];
     18// This variable is allocated in boot.c file or in kernel_init.c file
     19extern static_scheduler_t*  _schedulers[X_SIZE][Y_SIZE][NB_PROCS_MAX];
    2020
    2121///////////////////////////////////////////////////////////////////////////
     
    2323///////////////////////////////////////////////////////////////////////////
    2424
    25 /////////////////////////
    26 unsigned int _get_sched()
     25////////////////////////////////
     26static_scheduler_t* _get_sched()
    2727{
    2828    unsigned int ret;
    2929    asm volatile( "mfc0      %0,     $4,2    \n"
    3030                  : "=r"(ret) );
    31     return ret;
     31
     32    return (static_scheduler_t*)ret;
    3233}
    3334///////////////////////
     
    411412
    412413////////////////////////////////////////////////////////////////////////////
    413 //           Scheduler and tasks context access functions
     414//           Scheduler and threads context access functions
    414415////////////////////////////////////////////////////////////////////////////
    415416
    416417
    417 ///////////////////////////////////
    418 unsigned int _get_current_task_id()
    419 {
    420     static_scheduler_t * psched = (static_scheduler_t *) _get_sched();
    421     return (unsigned int) (psched->current);
     418///////////////////////////////
     419unsigned int _get_thread_ltid()
     420{
     421    static_scheduler_t* psched = (static_scheduler_t *) _get_sched();
     422    return psched->current;
     423}
     424
     425////////////////////////////////
     426unsigned int _get_thread_trdid()
     427{
     428    static_scheduler_t* psched  = (static_scheduler_t *) _get_sched();
     429    unsigned int        current = psched->current;
     430    return psched->context[current].slot[CTX_TRDID_ID];
     431}
     432
     433//////////////////////////////////////////////
     434unsigned int _get_thread_slot( unsigned int x,
     435                               unsigned int y,
     436                               unsigned int p,
     437                               unsigned int ltid,
     438                               unsigned int slotid )
     439{
     440    static_scheduler_t* psched  = (static_scheduler_t*)_schedulers[x][y][p];
     441    return psched->context[ltid].slot[slotid];
     442}
     443
     444//////////////////////////////////////
     445void _set_thread_slot( unsigned int x,
     446                       unsigned int y,
     447                       unsigned int p,
     448                       unsigned int ltid,
     449                       unsigned int slotid,
     450                       unsigned int value )
     451{
     452    static_scheduler_t* psched  = (static_scheduler_t*)_schedulers[x][y][p];
     453    psched->context[ltid].slot[slotid] = value;
     454}
     455
     456/////////////////////////////////////////////////////
     457unsigned int _get_context_slot( unsigned int slotid )
     458{
     459    static_scheduler_t* psched  = (static_scheduler_t*)_get_sched();
     460    unsigned int        ltid    = psched->current;
     461    return psched->context[ltid].slot[slotid];
    422462}
    423463
    424464////////////////////////////////////////////
    425 unsigned int _get_task_slot( unsigned int x,
    426                              unsigned int y,
    427                              unsigned int p,
    428                              unsigned int ltid,
    429                              unsigned int slot )
    430 {
    431     static_scheduler_t* psched  = (static_scheduler_t*)_schedulers[x][y][p];
    432     return psched->context[ltid][slot];
    433 }
    434 
    435 ////////////////////////////////////
    436 void _set_task_slot( unsigned int x,
    437                      unsigned int y,
    438                      unsigned int p,
    439                      unsigned int ltid,
    440                      unsigned int slot,
    441                      unsigned int value )
    442 {
    443     static_scheduler_t* psched  = (static_scheduler_t*)_schedulers[x][y][p];
    444     psched->context[ltid][slot] = value;
    445 }
    446 
    447 ///////////////////////////////////////////////////
    448 unsigned int _get_context_slot( unsigned int slot )
     465void _set_context_slot( unsigned int slotid,
     466                        unsigned int value )
    449467{
    450468    static_scheduler_t* psched  = (static_scheduler_t*)_get_sched();
    451     unsigned int        task_id = psched->current;
    452     return psched->context[task_id][slot];
    453 }
    454 
    455 ///////////////////////////////////////////
    456 void _set_context_slot( unsigned int slot,
    457                        unsigned int value )
    458 {
    459     static_scheduler_t* psched  = (static_scheduler_t*)_get_sched();
    460     unsigned int        task_id = psched->current;
    461     psched->context[task_id][slot] = value;
     469    unsigned int        ltid    = psched->current;
     470    psched->context[ltid].slot[slotid] = value;
    462471}
    463472
     
    496505            MAPPING_VSPACE_SIZE * header->vspaces);
    497506}
    498 //////////////////////////////////////////////////////////
    499 mapping_task_t * _get_task_base(mapping_header_t * header)
    500 {
    501     return (mapping_task_t *) ((char *) header +
     507//////////////////////////////////////////////////////////////
     508mapping_thread_t * _get_thread_base(mapping_header_t * header)
     509{
     510    return (mapping_thread_t *) ((char *) header +
    502511            MAPPING_HEADER_SIZE +
    503512            MAPPING_CLUSTER_SIZE * X_SIZE * Y_SIZE +
     
    515524            MAPPING_VSPACE_SIZE * header->vspaces +
    516525            MAPPING_VSEG_SIZE * header->vsegs +
    517             MAPPING_TASK_SIZE * header->tasks);
     526            MAPPING_THREAD_SIZE * header->threads);
    518527}
    519528///////////////////////////////////////////////////////
     
    526535            MAPPING_VSPACE_SIZE * header->vspaces +
    527536            MAPPING_VSEG_SIZE * header->vsegs +
    528             MAPPING_TASK_SIZE * header->tasks +
     537            MAPPING_THREAD_SIZE * header->threads +
    529538            MAPPING_PROC_SIZE * header->procs);
    530539}
     
    538547            MAPPING_VSPACE_SIZE * header->vspaces +
    539548            MAPPING_VSEG_SIZE * header->vsegs +
    540             MAPPING_TASK_SIZE * header->tasks +
     549            MAPPING_THREAD_SIZE * header->threads +
    541550            MAPPING_PROC_SIZE * header->procs +
    542551            MAPPING_IRQ_SIZE * header->irqs);
  • soft/giet_vm/giet_common/utils.h

    r618 r709  
    1414
    1515#include <mapping_info.h>
     16#include <ctx_handler.h>
    1617
    1718//////////////////////////////////////////////////////////////////////////////////
     
    4142///////////////////////////////////////////////////////////////////////////
    4243
    43 extern unsigned int _get_sched(void);
     44extern static_scheduler_t* _get_sched(void);
    4445
    4546extern unsigned int _get_epc(void);
     
    105106
    106107///////////////////////////////////////////////////////////////////////////
    107 //       Scheduler and task context access functions
     108//       Scheduler and thread context access functions
    108109///////////////////////////////////////////////////////////////////////////
    109110
    110 extern unsigned int _get_current_task_id(void);
     111extern unsigned int _get_thread_ltid(void);
    111112
    112 extern unsigned int _get_task_slot( unsigned int x,
    113                                     unsigned int y,
    114                                     unsigned int p,
    115                                     unsigned int ltid,
    116                                     unsigned int slot );
     113extern unsigned int _get_thread_trdid(void);
    117114
    118 extern void         _set_task_slot( unsigned int x,
    119                                     unsigned int y,
    120                                     unsigned int p,
    121                                     unsigned int ltid,
    122                                     unsigned int slot,
    123                                     unsigned int value );
     115extern unsigned int _get_thread_slot( unsigned int x,
     116                                      unsigned int y,
     117                                      unsigned int p,
     118                                      unsigned int ltid,
     119                                      unsigned int slot );
     120
     121extern void         _set_thread_slot( unsigned int x,
     122                                      unsigned int y,
     123                                      unsigned int p,
     124                                      unsigned int ltid,
     125                                      unsigned int slot,
     126                                      unsigned int value );
    124127
    125128extern unsigned int _get_context_slot( unsigned int slot );
     
    136139extern mapping_vspace_t *   _get_vspace_base(mapping_header_t* header);
    137140extern mapping_vseg_t *     _get_vseg_base(mapping_header_t* header);
    138 extern mapping_task_t *     _get_task_base(mapping_header_t* header);
     141extern mapping_thread_t *   _get_thread_base(mapping_header_t* header);
    139142extern mapping_proc_t *     _get_proc_base(mapping_header_t* header);
    140143extern mapping_irq_t *      _get_irq_base(mapping_header_t* header);
Note: See TracChangeset for help on using the changeset viewer.