Ignore:
Timestamp:
Jul 27, 2017, 12:23:29 AM (4 years ago)
Author:
alain
Message:

1) Introduce independant command fields for the various devices in the thread descriptor.
2) Introduce a new dev_pic_enable_ipi() function in the generic PIC device
3) Fix two bugs identified by Maxime in the scheduler initialisation, and in the sched_select().
4) fix several bugs in the TSAR hal_kentry.S.
5) Introduce a third kgiet segment (besides kdata and kcode) in the TSAR bootloader.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/rpc.c

    r265 r279  
    101101    assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n");
    102102
     103    rpc_dmsg("\n[INFO] %s : enter\n", __FUNCTION__ );
     104
    103105    // initialise RPC descriptor header
    104106    rpc_desc_t  rpc;
     
    115117    *error  = (error_t)rpc.args[0];     
    116118    *ppn    = (uint32_t)rpc.args[1];
     119
     120    rpc_dmsg("\n[INFO] %s : completed\n", __FUNCTION__ );
    117121}
    118122
     
    153157    assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n");
    154158
     159    rpc_dmsg("\n[INFO] %s : enter\n", __FUNCTION__ );
     160
    155161    // initialise RPC descriptor header
    156162    rpc_desc_t  rpc;
     
    167173    *pid    = (pid_t)rpc.args[1];
    168174    *error  = (error_t)rpc.args[2];     
     175
     176    rpc_dmsg("\n[INFO] %s : completed\n", __FUNCTION__ );
    169177}
    170178
     
    204212    assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n");
    205213
     214    rpc_dmsg("\n[INFO] %s : enter\n", __FUNCTION__ );
     215
    206216    // initialise RPC descriptor header
    207217    rpc_desc_t  rpc;
     
    217227    // get output arguments from RPC descriptor
    218228    *error  = (error_t)rpc.args[1];     
     229
     230    rpc_dmsg("\n[INFO] %s : completed\n", __FUNCTION__ );
    219231}
    220232
     
    256268    assert( (GET_CXY( process->ref_xp ) == local_cxy) , __FUNCTION__ ,
    257269            "caller must be reference process cluster\n");
     270
     271    rpc_dmsg("\n[INFO] %s : enter\n", __FUNCTION__ );
    258272
    259273    // get local process index in reference cluster
     
    282296        if( target_cxy != local_cxy ) rpc_send_sync( target_cxy , &rpc );
    283297    }
     298
     299    rpc_dmsg("\n[INFO] %s : completed\n", __FUNCTION__ );
    284300
    285301
     
    327343    assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n");
    328344
     345    rpc_dmsg("\n[INFO] %s : enter\n", __FUNCTION__ );
     346
    329347    // initialise RPC descriptor header
    330348    rpc_desc_t  rpc;
     
    344362    *thread_xp = (xptr_t)rpc.args[4];
    345363    *error     = (error_t)rpc.args[5];
     364
     365    rpc_dmsg("\n[INFO] %s : completed\n", __FUNCTION__ );
    346366}
    347367
     
    405425    assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n");
    406426
     427    rpc_dmsg("\n[INFO] %s : enter\n", __FUNCTION__ );
     428
    407429    // initialise RPC descriptor header
    408430    rpc_desc_t  rpc;
     
    421443    *thread_xp = (xptr_t)rpc.args[3];
    422444    *error     = (error_t)rpc.args[4];
     445
     446    rpc_dmsg("\n[INFO] %s : completed\n", __FUNCTION__ );
    423447}
    424448
     
    463487    assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n");
    464488
     489    rpc_dmsg("\n[INFO] %s : enter\n", __FUNCTION__ );
     490
    465491    // initialise RPC descriptor header
    466492    rpc_desc_t  rpc;
     
    474500    // register RPC request in remote RPC fifo
    475501    rpc_send_sync( cxy , &rpc );
     502
     503    rpc_dmsg("\n[INFO] %s : completed\n", __FUNCTION__ );
    476504}
    477505
     
    513541    assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n");
    514542
     543    rpc_dmsg("\n[INFO] %s : enter\n", __FUNCTION__ );
     544
    515545    // initialise RPC descriptor header
    516546    rpc_desc_t  rpc;
     
    534564    *inode_xp = (xptr_t)rpc.args[8];
    535565    *error    = (error_t)rpc.args[9];
     566
     567    rpc_dmsg("\n[INFO] %s : completed\n", __FUNCTION__ );
    536568}
    537569
     
    590622    assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n");
    591623
     624    rpc_dmsg("\n[INFO] %s : enter\n", __FUNCTION__ );
     625
    592626    // initialise RPC descriptor header
    593627    rpc_desc_t  rpc;
     
    600634    // register RPC request in remote RPC fifo (blocking function)
    601635    rpc_send_sync( cxy , &rpc );
     636
     637    rpc_dmsg("\n[INFO] %s : completed\n", __FUNCTION__ );
    602638}
    603639
     
    632668    assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n");
    633669
     670    rpc_dmsg("\n[INFO] %s : enter\n", __FUNCTION__ );
     671
    634672    // initialise RPC descriptor header
    635673    rpc_desc_t  rpc;
     
    648686    *dentry_xp = (xptr_t)rpc.args[3];
    649687    *error     = (error_t)rpc.args[4];
     688
     689    rpc_dmsg("\n[INFO] %s : completed\n", __FUNCTION__ );
    650690}
    651691
     
    695735    assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n");
    696736
     737    rpc_dmsg("\n[INFO] %s : enter\n", __FUNCTION__ );
     738
    697739    // initialise RPC descriptor header
    698740    rpc_desc_t  rpc;
     
    705747    // register RPC request in remote RPC fifo (blocking function)
    706748    rpc_send_sync( cxy , &rpc );
     749
     750    rpc_dmsg("\n[INFO] %s : completed\n", __FUNCTION__ );
    707751}
    708752
     
    737781    assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n");
    738782
     783    rpc_dmsg("\n[INFO] %s : enter\n", __FUNCTION__ );
     784
    739785    // initialise RPC descriptor header
    740786    rpc_desc_t  rpc;
     
    752798    *file_xp = (xptr_t)rpc.args[2];
    753799    *error   = (error_t)rpc.args[3];
     800
     801    rpc_dmsg("\n[INFO] %s : completed\n", __FUNCTION__ );
    754802}
    755803
     
    790838    assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n");
    791839
     840    rpc_dmsg("\n[INFO] %s : enter\n", __FUNCTION__ );
     841
    792842    // initialise RPC descriptor header
    793843    rpc_desc_t  rpc;
     
    800850    // register RPC request in remote RPC fifo (blocking function)
    801851    rpc_send_sync( cxy , &rpc );
     852
     853    rpc_dmsg("\n[INFO] %s : completed\n", __FUNCTION__ );
    802854}
    803855
     
    831883    assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n");
    832884
     885    rpc_dmsg("\n[INFO] %s : enter\n", __FUNCTION__ );
     886
    833887    // initialise RPC descriptor header
    834888    rpc_desc_t  rpc;
     
    846900    // get output values from RPC descriptor
    847901    *error   = (error_t)rpc.args[3];
     902
     903    rpc_dmsg("\n[INFO] %s : completed\n", __FUNCTION__ );
    848904}
    849905
     
    889945    assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n");
    890946
     947    rpc_dmsg("\n[INFO] %s : enter\n", __FUNCTION__ );
     948
    891949    // initialise RPC descriptor header
    892950    rpc_desc_t  rpc;
     
    902960    // get output values from RPC descriptor
    903961    *error   = (error_t)rpc.args[1];
     962
     963    rpc_dmsg("\n[INFO] %s : completed\n", __FUNCTION__ );
    904964}
    905965
     
    938998    assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n");
    939999
     1000    rpc_dmsg("\n[INFO] %s : enter\n", __FUNCTION__ );
     1001
    9401002    // initialise RPC descriptor header
    9411003    rpc_desc_t  rpc;
     
    9541016    *cluster = (uint32_t)rpc.args[3];
    9551017    *error   = (error_t)rpc.args[4];
     1018
     1019    rpc_dmsg("\n[INFO] %s : completed\n", __FUNCTION__ );
    9561020}
    9571021
     
    9941058    assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n");
    9951059
     1060    rpc_dmsg("\n[INFO] %s : enter\n", __FUNCTION__ );
     1061
    9961062    // initialise RPC descriptor header
    9971063    rpc_desc_t  rpc;
     
    10081074    // get output argument from rpc descriptor
    10091075    *vseg_xp = rpc.args[2];
     1076
     1077    rpc_dmsg("\n[INFO] %s : completed\n", __FUNCTION__ );
    10101078}
    10111079
     
    10501118    assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n");
    10511119
     1120    rpc_dmsg("\n[INFO] %s : enter\n", __FUNCTION__ );
     1121
    10521122    // initialise RPC descriptor header
    10531123    rpc_desc_t  rpc;
     
    10661136    *ppn   = (ppn_t)rpc.args[3];
    10671137    *error = (error_t)rpc.args[4];
     1138
     1139    rpc_dmsg("\n[INFO] %s : completed\n", __FUNCTION__ );
    10681140}
    10691141
     
    11051177    assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n");
    11061178
     1179    rpc_dmsg("\n[INFO] %s : enter\n", __FUNCTION__ );
     1180
    11071181    // initialise RPC descriptor header
    11081182    rpc_desc_t  rpc;
     
    11181192    // get output arguments from RPC descriptor
    11191193    *buf_xp = (xptr_t)rpc.args[1];
     1194
     1195    rpc_dmsg("\n[INFO] %s : completed\n", __FUNCTION__ );
    11201196}
    11211197
     
    11521228    assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n");
    11531229
     1230    rpc_dmsg("\n[INFO] %s : enter\n", __FUNCTION__ );
     1231
    11541232    // initialise RPC descriptor header
    11551233    rpc_desc_t  rpc;
     
    11631241    // register RPC request in remote RPC fifo
    11641242    rpc_send_sync( cxy , &rpc );
     1243
     1244    rpc_dmsg("\n[INFO] %s : completed\n", __FUNCTION__ );
    11651245}
    11661246
     
    11991279    assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n");
    12001280
     1281    rpc_dmsg("\n[INFO] %s : enter\n", __FUNCTION__ );
     1282
    12011283    // initialise RPC descriptor header
    12021284    rpc_desc_t  rpc;
     
    12171299    // get output values from RPC descriptor
    12181300    *error     = (error_t)rpc.args[6];
     1301
     1302    rpc_dmsg("\n[INFO] %s : completed\n", __FUNCTION__ );
    12191303}
    12201304
     
    12621346                    rpc_desc_t * rpc )
    12631347{
    1264         thread_t * this = CURRENT_THREAD;
    12651348    uint32_t   cores;
    12661349    error_t    error;
     
    12681351    reg_t      sr_save;
    12691352
    1270     // get client CPU and cluster coordinates
    1271     cxy_t      client_cxy = local_cxy;   
    1272     lid_t      client_lid = CURRENT_CORE->lid;
     1353    thread_t * this = CURRENT_THREAD;
     1354
     1355    rpc_dmsg("\n[INFO] %s : enter / client_cxy = %x / server_cxy = %x\n",
     1356             __FUNCTION__ , local_cxy , server_cxy );
    12731357
    12741358    // allocate and initialise an extended pointer on the RPC descriptor
    1275         xptr_t   xp = XPTR( client_cxy , rpc );
    1276 
    1277     // get local pointer on rpc_fifo in remote cluster with the
    1278     // assumption that addresses are identical in all clusters
     1359        xptr_t   desc_xp = XPTR( local_cxy , rpc );
     1360
     1361    // get local pointer on rpc_fifo in remote cluster, with the
     1362    // assumption that rpc_fifo pddresses are identical in all clusters
    12791363    rpc_fifo_t * rf = &LOCAL_CLUSTER->rpc_fifo;
    12801364
     
    12841368    {
    12851369        error = remote_fifo_put_item( XPTR( server_cxy , &rf->fifo ),
    1286                                       (uint64_t *)&xp,
     1370                                      (uint64_t )desc_xp,
    12871371                                      &first );
    12881372
    12891373            if ( error )
    12901374        {
    1291             printk("\n[WARNING] %s : core %d in cluster %x cannot post RPC to cluster %x\n",
    1292                    __FUNCTION__ , client_lid , client_cxy , server_cxy );
     1375            printk("\n[WARNING] %s : cluster %x cannot post RPC to cluster %x\n",
     1376                   __FUNCTION__ , local_cxy , server_cxy );
     1377
    12931378            if( thread_can_yield() ) sched_yield();
     1379        }
     1380        else
     1381        {
    12941382        }
    12951383    }
    12961384    while( error );
    12971385 
    1298     rpc_dmsg("\n[INFO] %s on core %d in cluster %x sent RPC %p to cluster %x\n",
    1299               __FUNCTION__ , client_lid , client_cxy , rpc , server_cxy );
     1386    rpc_dmsg("\n[INFO] %s : RPC registered / client_cxy = %x / server_cxy = %x\n",
     1387             __FUNCTION__ , local_cxy , server_cxy , first );
    13001388       
    1301     // send IPI if this is the first RPC in remote FIFO
    1302     // and no CPU is in kernel mode in server cluster.
    1303     // the selected CPU in server has the same lid as the client CPU.
     1389    // send IPI to remote CP0, if this is the first RPC in remote FIFO,
     1390    // and there is no CPU is in kernel mode in server cluster.
    13041391        if( first )
    13051392        {
     
    13091396                if( cores == 0 ) // no core in kernel mode in server
    13101397                {
    1311                     dev_pic_send_ipi( server_cxy , client_lid );
    1312 
    1313                     rpc_dmsg("\n[INFO] %s : core %d in cluster %x send IPI to core %d in cluster %x\n",
    1314                       __FUNCTION__, client_lid , client_cxy , client_lid , server_cxy );
     1398                    dev_pic_send_ipi( server_cxy , 0 );
     1399
     1400                    rpc_dmsg("\n[INFO] %s : IPI sent / client_cxy = %x / server_cxy = %x\n",
     1401                     __FUNCTION__, local_cxy , server_cxy );
    13151402        }
    13161403        }
    13171404
    1318         // activate preemption to allow incoming RPC and avoid deadlock
     1405        // enable IRQs to allow incoming RPC and avoid deadlock
    13191406        if( this->type == THREAD_RPC ) hal_enable_irq( &sr_save );
    13201407
    1321     // the sending thread poll the response slot until RPC completed
     1408    // the server thread poll the response slot until RPC completed
     1409    // TODO this could be replaced by a descheduling policy... [AG]
    13221410        while( 1 )
    13231411    {
     
    13251413    }
    13261414
    1327     // restore preemption
     1415    // restore IRQs
    13281416        if( this->type == THREAD_RPC ) hal_restore_irq( sr_save );
     1417
     1418    rpc_dmsg("\n[INFO] %s : completed / client_cxy = %x / server_cxy = %x\n",
     1419             __FUNCTION__ , local_cxy , server_cxy );
    13291420
    13301421}  // end rpc_send_sync()
     
    13441435}
    13451436
    1346 ////////////////////////////////////////////////
    1347 error_t rpc_execute_all( rpc_fifo_t * rpc_fifo )
     1437/////////////////////////////////////////////
     1438void rpc_execute_all( rpc_fifo_t * rpc_fifo )
    13481439{
    13491440        xptr_t         xp;             // extended pointer on RPC descriptor
     
    13531444    rpc_desc_t   * desc;           // pointer on RPC descriptor
    13541445    uint32_t       index;          // RPC index
    1355     uint32_t       expected;       // number of expected responses
    13561446    cxy_t          client_cxy;     // client cluster identifier
    13571447        error_t        error;
     
    13701460                if ( error == 0 )  // One RPC request successfully extracted from RPC_FIFO
    13711461        {
    1372             rpc_dmsg("\n[INFO] %s : RPC_THREAD %x on core %x in cluster %x handles RPC %d\n"
     1462            rpc_dmsg("\n[INFO] %s : RPC_THREAD %x on core %x in cluster %x handles RPC %d\n",
    13731463                                     __FUNCTION__ , this->trdid , core->lid , local_cxy , count );
    13741464
     
    13771467            desc       = (rpc_desc_t *)GET_PTR( xp );
    13781468
    1379             // get rpc index and expected responses from RPC descriptor
     1469            // get rpc index from RPC descriptor
    13801470                index     = hal_remote_lw( XPTR( client_cxy , &desc->index ) );
    1381                 expected  = hal_remote_lw( XPTR( client_cxy , &desc->response ) );
    13821471
    13831472            // call the relevant server function
     
    13881477
    13891478            // notify RPC completion as required
    1390             if( expected == 1 ) hal_remote_sw( XPTR(client_cxy,&desc->response) , 0 );
    1391             if( expected >  1 ) hal_remote_atomic_add( XPTR(client_cxy,&desc->response) , -1 );
     1479            hal_remote_atomic_add( XPTR(client_cxy,&desc->response) , -1 );
    13921480                }
    13931481       
     
    14001488            (count > CONFIG_RPC_PENDING_MAX) ) break;
    14011489        }
    1402     while( 1 )
    1403 
    1404         rpc_dmsg("\n[INFO] %s running on core %d in cluster %x exit\n"
    1405               __FUNCTION__ , CURRENT_CORE->lid , local_cxy );
    1406                
     1490    while( 1 );
     1491
    14071492    // update RPC_FIFO global counter
    14081493        rpc_fifo->count += count;
    14091494
    1410         return 0;
    14111495}  // end rpc_execute_all()
    14121496
     
    14221506    reg_t         sr_save;
    14231507
     1508   
    14241509        this   = CURRENT_THREAD;
    14251510    core   = this->core;
     
    14271512    found  = false;
    14281513
    1429     // calling thread must be the RPC_FIFO owner
    1430     if( this->trdid != rpc_fifo->owner )
    1431     {
    1432         printk("\n[PANIC] in %s : calling thread is not RPC_FIFO owner\n", __FUNCTION__ );
    1433         hal_core_sleep();
    1434     }
     1514    assert( (this->trdid == rpc_fifo->owner) , __FUNCTION__ ,
     1515          "calling thread is not RPC_FIFO owner\n" );
    14351516
    14361517    // makes the calling thread not preemptable
     
    14431524    {
    14441525        thread = LIST_ELEMENT( iter , thread_t , sched_list );
    1445         if( (thread->type == THREAD_RPC) && (thread->blocked ==  THREAD_BLOCKED_IDLE ) )
     1526        if( (thread->type == THREAD_RPC) && (thread->blocked == THREAD_BLOCKED_IDLE ) )
    14461527        {
    14471528            found = true;
     
    14531534    {
    14541535        thread->blocked = 0;
     1536
     1537        rpc_dmsg("\n[INFO] %s : activate RPC thread %x on core %x in cluster %x at cycle %d\n",
     1538                          __FUNCTION__ , thread , core->gid , local_cxy , hal_get_cycles() );
    14551539    }
    14561540    else                           // create a new RPC thread
     
    14691553        }
    14701554
    1471         rpc_dmsg("\n[INFO] %s creates RPC thread %x on core %x in cluster %x at cycle %d\n",
     1555        rpc_dmsg("\n[INFO] %s : create RPC thread %x on core %x in cluster %x at cycle %d\n",
    14721556                          __FUNCTION__ , thread , core->gid , local_cxy , hal_get_cycles() );
    14731557
    14741558        // update core descriptor counter 
    1475             hal_atomic_add( &core->rpc_threads , 1 );
     1559            hal_atomic_add( &LOCAL_CLUSTER->rpc_threads , 1 );
    14761560    }
    14771561
    14781562    // update owner in rpc_fifo
    14791563    rpc_fifo->owner = thread->trdid;
    1480 
    1481     rpc_dmsg ("\n[INFO] %s activates RPC thread %x on core %x in cluster %x at cycle %d\n",
    1482                       __FUNCTION__ , thread , core->gid , local_cxy , hal_get_cycles() );
    14831564
    14841565    // current thread deschedules / RPC thread start execution
     
    15061587    }
    15071588
    1508         // calling thread tries to take the light lock,
    1509     // and activates an RPC thread if success
     1589        // try to take the light lock, and activates an RPC thread if success
    15101590    if( hal_atomic_test_set( &rpc_fifo->owner , this->trdid ) )
    15111591        {
     
    15431623
    15441624    // this infinite loop is not preemptable
    1545     // the RPC thread deschedule when the RPC_FIFO is empty
     1625    // the RPC thread deschedule only when the RPC_FIFO is empty
    15461626        while(1)
    15471627        {
     
    15611641
    15621642
    1563         // suicide if too much RPC threads for this core
    1564                 if( this->core->rpc_threads > CONFIG_RPC_THREADS_MAX )
     1643        //  block and deschedule or sucide
     1644                if( LOCAL_CLUSTER->rpc_threads >= CONFIG_RPC_THREADS_MAX )
    15651645                {
    15661646            rpc_dmsg("\n[INFO] RPC thread %x suicide on core %d in cluster %x at cycle %d\n",
     
    15681648
    15691649            // update core descriptor counter
    1570                 hal_atomic_add( &this->core->rpc_threads , -1 );
     1650                hal_atomic_add( &LOCAL_CLUSTER->rpc_threads , -1 );
    15711651
    15721652            // suicide
    15731653                        thread_exit();
    15741654                }
    1575 
    1576         // block and deschedule
    1577         rpc_dmsg("\n[INFO] RPC thread %x deschedule on core %d in cluster %x at cycle %d\n",
    1578                               this->trdid , this->core->lid , local_cxy , hal_get_cycles() );
    1579 
    1580                 thread_block( this , THREAD_BLOCKED_IDLE );
    1581         sched_yield();
    1582 
    1583                 rpc_dmsg("\n[INFO] RPC thread %x wake up on core %d in cluster %x at cycle %d\n",
    1584                               this->trdid , this->core->lid , local_cxy , hal_get_cycles() );
    1585         }
     1655        else
     1656        {
     1657            rpc_dmsg("\n[INFO] RPC thread %x blocks on core %d in cluster %x at cycle %d\n",
     1658                                 this->trdid , this->core->lid , local_cxy , hal_get_cycles() );
     1659
     1660                     thread_block( this , THREAD_BLOCKED_IDLE );
     1661             sched_yield();
     1662
     1663                     rpc_dmsg("\n[INFO] RPC thread %x wake up on core %d in cluster %x at cycle %d\n",
     1664                          this->trdid , this->core->lid , local_cxy , hal_get_cycles() );
     1665        }
     1666        } // end while
    15861667} // end rpc_thread_func()
    15871668
Note: See TracChangeset for help on using the changeset viewer.