Changeset 630


Ignore:
Timestamp:
May 21, 2019, 6:00:06 PM (6 years ago)
Author:
alain
Message:

1) Fix a bug in the vfs_add_special_dentries() function:
The <.> and <..> dentries must not be created on IOC and on the mapper
for the VFS root directory.
2) Fix a bug in the hal_gpt_allocate_pt2 function, related to the
use of the TSAR_LOCKED attribute to avoid concurrent mapping of the PTD1.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/hal/tsar_mips32/core/hal_gpt.c

    r629 r630  
    318318
    319319/////////////////////////////////////////////////////////////////////////////////////////
    320 // This static function check that a PTE1 entry, in the PT1 of a possibly remote GPT,
    321 // identified by the <pte1_xp> argument is mapped. If this entry is not mapped,
    322 // it allocates a - local or remote - PT2, updates the PTE1 value in PT1, and
    323 // returns the PTE1 value in the <pte1> buffer.
    324 // It uses the TSR_MMU_LOCKED attribute in PTE1 to handle possible concurrent
    325 // mappings of the missing PTE1:
    326 // - If the PTE1 is unmapped and unlocked => it tries to atomically lock this PTE1,
    327 //   and map it if lock is successful.
    328 // - If the PTE1 is unmapped but locked => it poll the PTE1 value, unti the mapping
    329 //   is done by the other thread.
    330 // - If the PTE1 is already mapped => it does nothing
    331 // It returns an error if it cannot allocate memory fot a new PT2.
     320// This static function returns in the <ptd1_value> buffer the current value of
     321// the PT1 entry identified by the <pte1_xp> argument, that must contain a PTD1
     322// (i.e. a pointer on a PT2). If this PT1 entry is not mapped yet, it allocates a
     323// new PT2 and updates the PT1 entry, using the TSAR_MMU_LOCKED attribute in PT1
     324// entry, to handle possible concurrent mappings of the missing PTD1:
     325// 1) If the PT1 entry is unmapped, it tries to atomically lock this PTD1.
     326//    - if the atomic lock is successful it allocates a new PT1, and updates the PTD1.
     327//    - else, it simply waits, in a polling loop, the mapping done by another thread.
     328//    In both cases, returns the PTD1 value, when the mapping is completed.
     329// 2) If the PT1 entry is already mapped, it returns the PTD1 value, and does
     330//    nothing else.
    332331/////////////////////////////////////////////////////////////////////////////////////////
    333 static error_t hal_gpt_allocate_pt2( xptr_t     pte1_xp,
    334                                    uint32_t * pte1_value )
    335 {
    336     cxy_t      gpt_cxy;     // target GPT cluster = GET_CXY( pte1_xp );
    337     uint32_t   pte1;        // PTE1 value
     332static error_t hal_gpt_allocate_pt2( xptr_t     ptd1_xp,
     333                                     uint32_t * ptd1_value )
     334{
     335    cxy_t      gpt_cxy;     // target GPT cluster = GET_CXY( ptd1_xp );
     336    uint32_t   ptd1;        // PTD1 value
    338337    ppn_t      pt2_ppn;     // PPN of page containing the new PT2
    339338    bool_t     atomic;
     
    342341
    343342    // get GPT cluster identifier
    344     gpt_cxy = GET_CXY( pte1_xp );
    345 
    346     // get current pte1 value
    347     pte1 = hal_remote_l32( pte1_xp );
    348 
    349     if( ((pte1 & TSAR_PTE_MAPPED) == 0) &&   // PTE1 unmapped and unlocked
    350         ((pte1 & TSAR_PTE_LOCKED) == 0) )    // try to allocate a new PT2
     343    gpt_cxy = GET_CXY( ptd1_xp );
     344
     345    // get current ptd1 value
     346    ptd1 = hal_remote_l32( ptd1_xp );
     347
     348    if( (ptd1 & TSAR_PTE_MAPPED) == 0)    // PTD1 unmapped and unlocked
    351349        {
    352         // atomically lock the PTE1 to prevent concurrent PTE1 mappings
    353         atomic = hal_remote_atomic_cas( pte1_xp,
    354                                         pte1,
    355                                         pte1 | TSAR_PTE_LOCKED );
    356 
    357         if( atomic )  // PTE1 successfully locked
     350        // atomically lock the PTD1 to prevent concurrent PTD1 mappings
     351        atomic = hal_remote_atomic_cas( ptd1_xp,
     352                                        ptd1,
     353                                        ptd1 | TSAR_PTE_LOCKED );
     354
     355        if( atomic )  // PTD1 successfully locked
    358356                {
    359357            // allocate one physical page for PT2
     
    377375            pt2_ppn = ppm_page2ppn( page_xp );
    378376
    379             // build  PTE1 value
    380             pte1 = TSAR_PTE_MAPPED | TSAR_PTE_SMALL | pt2_ppn;
     377            // build  PTD1
     378            ptd1 = TSAR_PTE_MAPPED | TSAR_PTE_SMALL | pt2_ppn;
    381379
    382380            // set the PTD1 value in PT1
    383             hal_remote_s32( pte1_xp , pte1 );
     381            hal_remote_s32( ptd1_xp , ptd1 );
    384382            hal_fence();
    385383
     
    388386uint32_t   cycle = (uint32_t)hal_get_cycles();
    389387if( DEBUG_HAL_GPT_ALLOCATE_PT2 < cycle )
    390 printk("\n[%s] : thread[%x,%x] map PTE1 / cxy %x / ix1 %d / pt1 %x / ptd1 %x\n",
    391 __FUNCTION__, this->process->pid, this->trdid, gpt_cxy, ix1, pt1_ptr, pte1 );
     388printk("\n[%s] : thread[%x,%x] map PTD1 / cxy %x / ix1 %d / pt1 %x / ptd1 %x\n",
     389__FUNCTION__, this->process->pid, this->trdid, gpt_cxy, ix1, pt1_ptr, ptd1 );
    392390#endif
    393391        }
    394         else
     392        else         // PTD1 modified by another thread
    395393        {
    396             // poll PTE1 until mapped by another thread
    397             while( (pte1 & TSAR_PTE_MAPPED) == 0 )  pte1 = hal_remote_l32( pte1_xp );
     394            // poll PTD1 until mapped by another thread
     395            while( (ptd1 & TSAR_PTE_MAPPED) == 0 )  ptd1 = hal_remote_l32( ptd1_xp );
    398396        }
    399397    }
    400     else if( ((pte1 & TSAR_PTE_MAPPED) == 0) &&
    401              ((pte1 & TSAR_PTE_LOCKED) != 0) ) 
    402     {
    403         // poll PTE1 until mapped by another thread
    404         while( (pte1 & TSAR_PTE_MAPPED) == 0 )  pte1 = hal_remote_l32( pte1_xp );
    405         }
    406     else                                   // PTE1 mapped => just use it
     398    else                                   // PTD1 mapped => just use it
    407399    {
    408400
     
    411403uint32_t   cycle = (uint32_t)hal_get_cycles();
    412404if( DEBUG_HAL_GPT_ALLOCATE_PT2 < cycle )
    413 printk("\n[%s] : thread[%x,%x] PTE1 mapped / cxy %x / ix1 %d / pt1 %x / ptd1 %x\n",
    414 __FUNCTION__, this->process->pid, this->trdid, gpt_cxy, ix1, pt1_ptr, pte1 );
     405printk("\n[%s] : thread[%x,%x] PTD1 mapped / cxy %x / ix1 %d / pt1 %x / ptd1 %x\n",
     406__FUNCTION__, this->process->pid, this->trdid, gpt_cxy, ix1, pt1_ptr, ptd1 );
    415407#endif
    416408
    417409    }
    418410
    419     *pte1_value = pte1;
     411    *ptd1_value = ptd1;
    420412    return 0;
    421413
  • trunk/kernel/fs/fatfs.c

    r628 r630  
    14041404
    14051405#if (DEBUG_FATFS_ADD_DENTRY & 1)
     1406cycle = (uint32_t)hal_get_cycles();
    14061407if( DEBUG_FATFS_ADD_DENTRY < cycle )
    1407 printk("\n[%s] FSM step = %d / offset = %x / nb_lfn = %d\n",
    1408 __FUNCTION__, step, offset, nb_lfn );
     1408printk("\n[%s] FSM step = %d / offset = %x / nb_lfn = %d / cycle %d\n",
     1409__FUNCTION__, step, offset, nb_lfn, cycle );
    14091410#endif
    14101411
     
    15331534    } // exit while     
    15341535
     1536#if (DEBUG_FATFS_ADD_DENTRY & 1)
     1537cycle = (uint32_t)hal_get_cycles();
     1538if( DEBUG_FATFS_ADD_DENTRY < cycle )
     1539printk("\n[%s]  thread[%x,%x] before IOC access / cycle %d\n",
     1540__FUNCTION__, this->process->pid, this->trdid, cycle );
     1541#endif
     1542
    15351543    // copy the modified page to the IOC device
    15361544    fatfs_move_page( page_xp , IOC_SYNC_WRITE );   
  • trunk/kernel/fs/vfs.c

    r629 r630  
    29152915    fs_type    = hal_remote_l32( XPTR( child_cxy , &ctx_ptr->type ) );
    29162916
    2917     //////////////////////////// create <.>
     2917    //////////////////////////// create <.> dentry //////////////////////
    29182918    if( child_cxy == local_cxy )     
    29192919    {
     
    29412941
    29422942#if(DEBUG_VFS_ADD_SPECIAL & 1)
     2943cycle = (uint32_t)hal_get_cycles();
    29432944if( DEBUG_VFS_ADD_SPECIAL < cycle )
    2944 printk("\n[%s] thread[%x,%x] created dentry <.> (%x,%x)\n",
    2945 __FUNCTION__, this->process->pid, this->trdid, child_cxy, dentry_ptr );
     2945printk("\n[%s] thread[%x,%x] created dentry <.> (%x,%x) / cycle %d\n",
     2946__FUNCTION__, this->process->pid, this->trdid, child_cxy, dentry_ptr, cycle );
    29462947#endif
    29472948
     
    29692970
    29702971#if(DEBUG_VFS_ADD_SPECIAL & 1)
     2972cycle = (uint32_t)hal_get_cycles();
    29712973if( DEBUG_VFS_ADD_SPECIAL < cycle )
    2972 printk("\n[%s] thread[%x,%x] linked dentry <.> to parent and child inodes\n",
    2973 __FUNCTION__, this->process->pid, this->trdid );
     2974printk("\n[%s] thread[%x,%x] linked dentry <.> to parent and child inodes / cycle %d\n",
     2975__FUNCTION__, this->process->pid, this->trdid, cycle );
    29742976#endif
    29752977
    29762978    // introduce <.> dentry into child directory mapper
    2977     if( child_cxy == local_cxy )
    2978     {
    2979         error = vfs_fs_add_dentry( child_ptr,
    2980                                    dentry_ptr );
    2981     }
    2982     else
    2983     {
    2984         rpc_vfs_fs_add_dentry_client( child_cxy,
    2985                                       child_ptr,
    2986                                       dentry_ptr,
    2987                                       &error );
    2988     }
    2989     if( error )
    2990     {
    2991         printk("\n[ERROR] in %s : cannot introduce dentry <..> in mapper %x\n",
    2992         __FUNCTION__ );
    2993         return -1;
    2994     }
     2979    // only if the target directory is not the root VFS
     2980    if( child_xp != parent_xp )
     2981    {
     2982        if( child_cxy == local_cxy )
     2983        {
     2984            error = vfs_fs_add_dentry( child_ptr,
     2985                                       dentry_ptr );
     2986        }
     2987        else
     2988        {
     2989            rpc_vfs_fs_add_dentry_client( child_cxy,
     2990                                          child_ptr,
     2991                                          dentry_ptr,
     2992                                          &error );
     2993        }
     2994        if( error )
     2995        {
     2996            printk("\n[ERROR] in %s : cannot introduce dentry <..> in mapper %x\n",
     2997            __FUNCTION__ );
     2998            return -1;
     2999        }
    29953000
    29963001#if(DEBUG_VFS_ADD_SPECIAL & 1)
     3002cycle = (uint32_t)hal_get_cycles();
    29973003if( DEBUG_VFS_ADD_SPECIAL < cycle )
    2998 printk("\n[%s] thread[%x,%x] registered dentry <.> in child mapper\n",
    2999 __FUNCTION__, this->process->pid, this->trdid );
    3000 #endif
    3001 
    3002     ///////////////////////////// create <..> dentry
     3004printk("\n[%s] thread[%x,%x] registered dentry <.> in child mapper / cycle %d\n",
     3005__FUNCTION__, this->process->pid, this->trdid, cycle );
     3006#endif
     3007
     3008    }
     3009
     3010    ///////////////////////////// create <..> dentry ///////////////////////
    30033011    if( child_cxy == local_cxy )     
    30043012    {
     
    30263034
    30273035#if(DEBUG_VFS_ADD_SPECIAL & 1)
     3036cycle = (uint32_t)hal_get_cycles();
    30283037if( DEBUG_VFS_ADD_SPECIAL < cycle )
    3029 printk("\n[%s] thread[%x,%x] created dentry <..> (%x,%x)\n",
    3030 __FUNCTION__, this->process->pid, this->trdid, child_cxy, dentry_ptr );
     3038printk("\n[%s] thread[%x,%x] created dentry <..> (%x,%x) / cycle %d\n",
     3039__FUNCTION__, this->process->pid, this->trdid, child_cxy, dentry_ptr, cycle );
    30313040#endif
    30323041
     
    30533062
    30543063#if(DEBUG_VFS_ADD_SPECIAL & 1)
     3064cycle = (uint32_t)hal_get_cycles();
    30553065if( DEBUG_VFS_ADD_SPECIAL < cycle )
    3056 printk("\n[%s] thread[%x,%x] linked dentry <..> to parent and child inodes\n",
    3057 __FUNCTION__, this->process->pid, this->trdid );
     3066printk("\n[%s] thread[%x,%x] linked dentry <..> to parent and child inodes / cycle %d\n",
     3067__FUNCTION__, this->process->pid, this->trdid, cycle );
    30583068#endif
    30593069
    30603070    // introduce <..> dentry into child directory mapper
    3061     if( child_cxy == local_cxy )
    3062     {
    3063         error = vfs_fs_add_dentry( child_ptr,
    3064                                    dentry_ptr );
    3065     }
    3066     else
    3067     {
    3068         rpc_vfs_fs_add_dentry_client( child_cxy,
    3069                                       child_ptr,
    3070                                       dentry_ptr,
    3071                                       &error );
    3072     }
    3073     if( error )
    3074     {
    3075         printk("\n[ERROR] in %s : cannot introduce dentry <..> in mapper %x\n",
    3076         __FUNCTION__ );
    3077         return -1;
    3078     }
     3071    // only if the target directory is not the root VFS
     3072    if( child_xp != parent_xp )
     3073    {
     3074        if( child_cxy == local_cxy )
     3075        {
     3076            error = vfs_fs_add_dentry( child_ptr,
     3077                                       dentry_ptr );
     3078        }
     3079        else
     3080        {
     3081            rpc_vfs_fs_add_dentry_client( child_cxy,
     3082                                          child_ptr,
     3083                                          dentry_ptr,
     3084                                          &error );
     3085        }
     3086        if( error )
     3087        {
     3088            printk("\n[ERROR] in %s : cannot introduce dentry <..> in mapper %x\n",
     3089            __FUNCTION__ );
     3090            return -1;
     3091        }
    30793092
    30803093#if(DEBUG_VFS_ADD_SPECIAL & 1)
     3094cycle = (uint32_t)hal_get_cycles();
    30813095if( DEBUG_VFS_ADD_SPECIAL < cycle )
    3082 printk("\n[%s] thread[%x,%x] registered dentry <..> in child mapper\n",
    3083 __FUNCTION__, this->process->pid, this->trdid );
    3084 #endif
     3096printk("\n[%s] thread[%x,%x] registered dentry <..> in child mapper / cycle %d\n",
     3097__FUNCTION__, this->process->pid, this->trdid, cycle );
     3098#endif
     3099
     3100    }
    30853101
    30863102#if DEBUG_VFS_ADD_SPECIAL
  • trunk/kernel/kern/kernel_init.c

    r629 r630  
    11551155    thread_unblock( XPTR( local_cxy , thread ) , THREAD_BLOCKED_GLOBAL );
    11561156    core->scheduler.idle = thread;
    1157 
    1158 #if( DEBUG_KERNEL_INIT & 1 )
    1159 sched_display( core_lid );
    1160 #endif
    11611157
    11621158    // core[O] in cluster[0] creates the VFS root
  • trunk/kernel/kern/scheduler.c

    r629 r630  
    248248uint32_t cycle = (uint32_t)hal_get_cycles();
    249249if( DEBUG_SCHED_HANDLE_SIGNALS < cycle )
    250 printk("\n[%s] thread[%x,%x] on core[%x,%d] deleted (still %d threads) / cycle %d\n",
    251 __FUNCTION__, process->pid, thread->trdid, local_cxy, thread->core->lid, count, cycle );
     250printk("\n[%s] thread[%x,%x] on core[%x,%d] deleted / cycle %d\n",
     251__FUNCTION__, process->pid, thread->trdid, local_cxy, thread->core->lid, cycle );
    252252#endif
    253253
     
    259259uint32_t false_nr    = thread->info.false_pgfault_nr;
    260260uint32_t false_cost  = (false_nr == 0)  ? 0 : (thread->info.false_pgfault_cost / false_nr);
    261 printk("***** page faults for thread[%x,%x]\n"
     261printk("\n***** page faults for thread[%x,%x]\n"
    262262       "  - %d local  : %d cycles\n"
    263263       "  - %d global : %d cycles\n"
  • trunk/kernel/mm/vmm.c

    r629 r630  
    19781978        ref_ptr = GET_PTR( process->ref_xp );
    19791979
    1980         // private vseg or (local == reference) => access only the local GPT
     1980        /////////////// private vseg or (local == reference)
     1981        /////////////// => access only the local GPT
    19811982        if( (vseg->type == VSEG_TYPE_STACK) ||
    19821983            (vseg->type == VSEG_TYPE_CODE)  ||
     
    20282029        }   // end local GPT access
    20292030
    2030         // public vseg and (local != reference) => access ref GPT to update local GPT
     2031        /////////////////// public vseg and (local != reference)
     2032        /////////////////// => access ref GPT to update local GPT
    20312033        else                               
    20322034        {
     
    20352037
    20362038            // get current PPN and attributes from reference GPT
     2039            // without locking the PTE (in case of false page fault)
    20372040            hal_gpt_get_pte( ref_gpt_xp,
    20382041                             vpn,
  • trunk/params-hard.mk

    r629 r630  
    22
    33ARCH      = /users/alain/soc/tsar-trunk-svn-2013/platforms/tsar_generic_iob
    4 X_SIZE    = 4
    5 Y_SIZE    = 4
     4X_SIZE    = 2
     5Y_SIZE    = 2
    66NB_PROCS  = 1
    77NB_TTYS   = 2
  • trunk/user/fft/fft.c

    r629 r630  
    9191#define MODE                    COSIN           // DATA array initialisation mode
    9292#define CHECK                   0               
    93 #define DEBUG_MAIN              1               // trace main() function (detailed if odd)
     93#define DEBUG_MAIN              0               // trace main() function (detailed if odd)
    9494#define DEBUG_SLAVE             0               // trace slave() function (detailed if odd)
    9595#define DEBUG_FFT1D             0               // trace FFT1D() function (detailed if odd)
     
    404404    }
    405405
    406 
    407     // register sequencial initalisation completion cycle
     406    printf("\n[fft] main completes threads creation\n");
     407
    408408    get_cycle( &end_init_cycle );
     409
     410    // register sequencial time
    409411    init_time = (unsigned int)(end_init_cycle - start_init_cycle);
    410 
    411     printf("\n[fft] main completes threads creation\n");
    412412   
    413413    // main itself executes the slave() function
     
    510510    unsigned int max_sync = sync_time[0];
    511511
    512     for (tid = 1 ; tid < nthreads ; tid++)
     512    for (tid = 0 ; tid < nthreads ; tid++)
    513513    {
    514514        if (parallel_time[tid] > max_para)  max_para = parallel_time[tid];
     
    566566    MainNum = args->main_tid;
    567567
    568     // initialise instrumentation
    569568    get_cycle( &parallel_start );
    570569
     
    578577    pthread_barrier_wait( &barrier );
    579578    get_cycle( &barrier_stop );
    580     sync_time[MyNum] += (barrier_stop - barrier_start);
    581 
    582 // printf("\n[@@@] %s : thread %d exit first barrier / cycle %d\n",
    583 // __FUNCTION__, MyNum, (unsigned int)barrier_stop );
     579    sync_time[MyNum] += (unsigned int)(barrier_stop - barrier_start);
     580
     581#if DEBUG_SLAVE
     582printf("\n[@@@] %s : thread %d exit first barrier / cycle %d\n",
     583__FUNCTION__, MyNum, (unsigned int)barrier_stop );
     584#endif
    584585
    585586    // allocate and initialise local array upriv[]
     
    605606pthread_barrier_wait( &barrier );
    606607get_cycle( &barrier_stop );
    607 sync_time[MyNum] += (long)(barrier_stop - barrier_start);
     608sync_time[MyNum] += (unsigned int)(barrier_stop - barrier_start);
    608609FFT1D( -1 , data , trans , upriv , twid , MyNum , MyFirst , MyLast );
    609610#endif
    610611
    611     // register computation time
    612612    get_cycle( &parallel_stop );
    613     parallel_time[MyNum] = (parallel_stop - parallel_start);
     613
     614    // register parallel time
     615    parallel_time[MyNum] = (unsigned int)(parallel_stop - parallel_start);
    614616
    615617#if DEBUG_SLAVE
    616 printf("\n[fft] %s : thread %x exit / cycle %d\n", __FUNCTION__, MyNum, parallel_stop );
     618printf("\n[fft] %s : thread %x completes fft / p_start %d / p_stop %d\n",
     619__FUNCTION__, MyNum, (unsigned int)parallel_start, (unsigned int)parallel_stop );
     620int tid;
     621for (tid = 0 ; tid < nthreads ; tid++)
     622{
     623    printf("- tid %d : Sequencial %d / Parallel %d / Barrier %d\n",
     624    tid , init_time, parallel_time[tid], sync_time[tid] );
     625}
    617626#endif
    618627
     
    867876    pthread_barrier_wait( &barrier );
    868877    get_cycle( &barrier_stop );
    869     sync_time[MyNum] = (long)(barrier_stop - barrier_start);
     878    sync_time[MyNum] = (unsigned int)(barrier_stop - barrier_start);
    870879
    871880#if( DEBUG_FFT1D & 1 )
     
    897906#endif
    898907
    899     sync_time[MyNum] += (long)(barrier_stop - barrier_start);
     908    sync_time[MyNum] += (unsigned int)(barrier_stop - barrier_start);
    900909
    901910    // transpose tmp to x
     
    916925#endif
    917926
    918     sync_time[MyNum] += (long)(barrier_stop - barrier_start);
     927    sync_time[MyNum] += (unsigned int)(barrier_stop - barrier_start);
    919928
    920929    // do FFTs on rows of x and apply the scaling factor
     
    938947printf("\n[fft] %s : thread %d exit barrier after FFT on rows\n", __FUNCTION__, MyNum);
    939948#endif
    940     sync_time[MyNum] += (long)(barrier_stop - barrier_start);
     949    sync_time[MyNum] += (unsigned int)(barrier_stop - barrier_start);
    941950
    942951    // transpose x to tmp
     
    957966#endif
    958967
    959     sync_time[MyNum] += (long)(barrier_stop - barrier_start);
     968    sync_time[MyNum] += (unsigned int)(barrier_stop - barrier_start);
    960969    sync_time[MyNum] += (long)(barrier_stop - barrier_start);
    961970
  • trunk/user/ksh/ksh.c

    r629 r630  
    11791179
    11801180
    1181 /* 1. first direct command
     1181// 1. first direct command
    11821182if( sem_wait( &semaphore ) )
    11831183{
     
    11921192strcpy( cmd , "load bin/user/fft.elf" );
    11931193execute( cmd );
    1194 */
     1194//
    11951195
    11961196
Note: See TracChangeset for help on using the changeset viewer.