Ignore:
Timestamp:
Apr 26, 2017, 2:11:56 PM (7 years ago)
Author:
alain
Message:

Introduce the chdev_t structure in place of the device_t structure.

File:
1 edited

Legend:

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

    r1 r5  
    88 * Copyright (c) UPMC Sorbonne Universites
    99 *
    10  * This file is part of ALMOS-MKH..
     10 * This file is part of ALMOS-MKH.
    1111 *
    12  * ALMOS-MKH. is free software; you can redistribute it and/or modify it
     12 * ALMOS-MKH is free software; you can redistribute it and/or modify it
    1313 * under the terms of the GNU General Public License as published by
    1414 * the Free Software Foundation; version 2.0 of the License.
    1515 *
    16  * ALMOS-MKH. is distributed in the hope that it will be useful, but
     16 * ALMOS-MKH is distributed in the hope that it will be useful, but
    1717 * WITHOUT ANY WARRANTY; without even the implied warranty of
    1818 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     
    2020 *
    2121 * You should have received a copy of the GNU General Public License
    22  * along with ALMOS-MKH.; if not, write to the Free Software Foundation,
     22 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
    2323 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
    2424 */
     
    6262};
    6363
     64//////////////////////////////////////////////////////////////////////////////////////
     65// This static function returns a printable string for the thread type.
     66//////////////////////////////////////////////////////////////////////////////////////
     67char * thread_type_str( uint32_t type )
     68{
     69    if     ( type == THREAD_USER   ) return "THREAD_USER";
     70    else if( type == THREAD_RPC    ) return "THREAD_RPC";
     71    else if( type == THREAD_DEV    ) return "THREAD_DEV";
     72    else if( type == THREAD_KERNEL ) return "THREAD_KERNEL";
     73    else if( type == THREAD_IDLE   ) return "THREAD_IDLE";
     74    else                             return "undefined";
     75}
     76
    6477/////////////////////////////////////////////////////////////////////////////////////
    6578// This static function makes the actual allocation and initialisation for a thread
     
    7689// @ core_lid   : target core local index.
    7790/////////////////////////////////////////////////////////////////////////////////////
    78 static error_t __thread_create( thread_t     ** new_thread,
    79                                 process_t     * process,
    80                                 thread_type_t   type,
    81                                 void          * func,
    82                                 void          * args,
    83                                 lid_t           core_lid,
    84                                 intptr_t        u_stack_base,
    85                                 uint32_t        u_stack_size )
     91static error_t thread_create( thread_t     ** new_thread,
     92                              process_t     * process,
     93                              thread_type_t   type,
     94                              void          * func,
     95                              void          * args,
     96                              lid_t           core_lid,
     97                              intptr_t        u_stack_base,
     98                              uint32_t        u_stack_size )
    8699{
    87100    error_t        error;
     
    171184    *new_thread = thread;
    172185        return 0;
    173 } // end __thread_create()
     186} // end thread_create()
    174187
    175188
     
    185198    lid_t          core_lid;     // selected core local index
    186199
     200    thread_dmsg("\n[INFO] %s : enters\n",
     201                __FUNCTION__ );
     202
    187203        cluster_t    * local_cluster = LOCAL_CLUSTER;
    188204
     
    199215
    200216    // make allocation / initialisation
    201     error = __thread_create( &thread,
    202                              process,
    203                              THREAD_USER,
    204                              attr->entry_func,
    205                              attr->entry_args,
    206                              core_lid,
    207                              u_stack_base,
    208                              u_stack_size );
     217    error = thread_create( &thread,
     218                           process,
     219                           THREAD_USER,
     220                           attr->entry_func,
     221                           attr->entry_args,
     222                           core_lid,
     223                           u_stack_base,
     224                           u_stack_size );
    209225    if( error ) return ENOMEM;
    210226
     
    220236    error = hal_fpu_context_create( thread );
    221237    if( error ) return ENOMEM;
    222 
    223     thread_dmsg("INFO : %s thread %x for process %x on core %d in cluster %x\n",
    224                  __FUNCTION__, thread->trdid, process->pid, core_lid, local_cluster->cxy );
     238 
     239    thread_dmsg("\n[INFO] %s : exit / trdid = %x / process %x / core = %d\n",
     240                __FUNCTION__ , thread->trdid , process->pid , core_lid );
    225241
    226242    *new_thread = thread;
     
    239255    lid_t          core_lid;     // selected core local index
    240256
     257    thread_dmsg("\n[INFO] %s : enters\n",
     258                __FUNCTION__ );
     259
    241260    // select a target core in local cluster
    242261    core_lid = cluster_select_local_core();
     
    246265
    247266    // make allocation / initialisation
    248     error = __thread_create( &new,
    249                              process,
    250                              THREAD_USER,
    251                              this->entry_func,
    252                              this->entry_args,
    253                              core_lid,
    254                              u_stack_base,
    255                              u_stack_size );
     267    error = thread_create( &new,
     268                           process,
     269                           THREAD_USER,
     270                           this->entry_func,
     271                           this->entry_args,
     272                           core_lid,
     273                           u_stack_base,
     274                           u_stack_size );
    256275    if( error ) return ENOMEM;
    257276
     
    268287
    269288    thread_dmsg("INFO : %s thread %x for process %x on core %d in cluster %x\n",
    270                  __FUNCTION__, new->trdid, process->pid, core_lid, local_cluster->cxy );
     289                 __FUNCTION__, new->trdid, process->pid, core_lid, local_cxy );
    271290
    272291    *new_thread = new;
    273292        return 0;
     293
    274294} // end thread_user_fork()
    275295
     
    286306        thread_t     * new;        // pointer on new thread descriptor
    287307
    288     cluster_t    * local_cluster = LOCAL_CLUSTER;
    289 
    290     // check type argument
    291     if( (type != THREAD_KERNEL) && (type != THREAD_RPC) &&
    292         (type != THREAD_IDLE) && (type != THREAD_DEV) )
    293     {
    294         printk("ERROR : %s received an illegal thread type\n", __FUNCTION__ );
    295         hal_core_sleep();
    296     }
    297 
    298     // check core local index
    299     if( core_lid >= local_cluster->cores_nr )
    300     {
    301         printk("ERROR : %s received an illegal core_lid\n", __FUNCTION__ );
    302         hal_core_sleep();
    303     }
     308    thread_dmsg("\n[INFO] %s : enters for %s in cluster %x\n",
     309                __FUNCTION__ , thread_type_str( type ) , local_cxy );
     310
     311    assert( ( (type == THREAD_KERNEL) || (type == THREAD_RPC) ||
     312              (type == THREAD_IDLE)   || (type == THREAD_DEV) ) ,
     313              __FUNCTION__ , "illegal thread type" );
     314
     315    assert( (core_lid < LOCAL_CLUSTER->cores_nr) ,
     316            __FUNCTION__ , "illegal core_lid" );
    304317
    305318    // make allocation / initialisation
    306     error = __thread_create( &new,
    307                              &process_zero,
    308                              type,
    309                              func,
    310                              args,
    311                              core_lid,
    312                              0 , 0 );  // no user stack for a kernel thread
     319    error = thread_create( &new,
     320                           &process_zero,
     321                           type,
     322                           func,
     323                           args,
     324                           core_lid,
     325                           0 , 0 );  // no user stack for a kernel thread
    313326    if( error )
    314327    {
    315         printk("ERROR : %s cannot create thread\n", __FUNCTION__ );
    316         hal_core_sleep();
     328        printk("\n[ERROR] in %s : cannot create thread\n", __FUNCTION__ );
     329        return ENOMEM;
    317330    }
    318331
     
    320333        hal_cpu_context_create( new );
    321334
    322     thread_dmsg("INFO : %s thread %x in cluster %x on core %d\n",
    323                  __FUNCTION__ , new->trdid , local_cluster->cxy , core_lid );
     335    thread_dmsg("\n[INFO] %s : sucessfully exit / trdid = %x / core = %d\n",
     336                 __FUNCTION__ , new->trdid , core_lid );
    324337
    325338    *new_thread = new;
    326339        return 0;
     340
    327341} // end thread_kernel_create()
    328342
     
    341355    core_t     * core       = thread->core;
    342356
    343     if( thread->children_nr )
    344     {
    345         printk("\n[PANIC] in %s : thread %x for process %x on core %d in cluster %x"
    346                " has still attached children\n",
    347                __FUNCTION__, thread->trdid, process->pid, core->lid, local_cxy );
    348         hal_core_sleep();
    349     }
    350 
    351     if( (thread->local_locks != 0) || (thread->remote_locks != 0) )
    352     {
    353         printk("\n[PANIC] in %s : thread %x for process %x on core %d in cluster %x"
    354                " did not released all locks\n",
    355                __FUNCTION__, thread->trdid, process->pid, core->lid, local_cxy );
    356         hal_core_sleep();
    357     }
     357    thread_dmsg("\n[INFO] %s : enters for thread %x in process %x / type = %s\n",
     358                __FUNCTION__ , thread->trdid , process->pid , thread_type_str( thread->type ) );
     359
     360    assert( (thread->children_nr == 0) , __FUNCTION__ , "still attached children" );
     361
     362    assert( (thread->local_locks == 0) , __FUNCTION__ , "all local locks not released" );
    358363   
     364    assert( (thread->remote_locks == 0) , __FUNCTION__ , "all remote locks not released" );
     365
    359366        tm_start = hal_time_stamp();
    360367
     
    402409        tm_end = hal_time_stamp();
    403410
    404         thread_dmsg("INFO : %s destroy thread %x for process %x on core %d in cluster %x\n"
    405                  " / duration = %d / page_faults = %d / ticks = %d\n",
    406                        __FUNCTION__, trdid , pid , core_lid , local_cxy ,
    407                        tm_end - tm_start , pgfaults , ticks );
     411        thread_dmsg("\n[INFO] %s : exit for thread %x in process %x / duration = %d\n",
     412                       __FUNCTION__, thread->trdid , process->pid , tm_end - tm_start );
    408413
    409414}  // end thread_destroy()
     
    592597    while( 1 )
    593598    {
    594         thread_dmsg("INFO : core %d in cluster %x goes to sleeping state at cycle\n",
    595                      core->lid , cluster->cxy, hal_time_stamp() );
     599        thread_dmsg("\n[INFO] %s : core %d in cluster %x goes to sleeping state at cycle\n",
     600                    __FUNCTION__ , core->lid , local_cxy , hal_time_stamp() );
    596601
    597602        // force core to sleeping state
    598603        hal_core_sleep();
    599604
    600         thread_dmsg("INFO : core %d in cluster %x wake up at cycle %d\n",
    601                      core->lid , cluster->cxy, hal_time_stamp() );
     605        thread_dmsg("\n[INFO] %s : core %d in cluster %x wake up at cycle %d\n",
     606                    __FUNCTION__ , core->lid , local_cxy , hal_time_stamp() );
    602607
    603608        // force scheduling at wake-up
Note: See TracChangeset for help on using the changeset viewer.