Changeset 573 for trunk


Ignore:
Timestamp:
Oct 5, 2018, 12:21:52 AM (6 years ago)
Author:
alain
Message:

Cosmetic.

Location:
trunk/libs
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/libs/libalmosmkh/almosmkh.c

    r478 r573  
    3232#include <mman.h>
    3333
     34#define  MALLOC_DEBUG    0
     35 
    3436/////////////     Non standard system calls    /////////////////////////////////
    3537
     
    216218}
    217219
    218 /////////////////
     220///////////////////////
    219221int display_vfs( void )
    220222{
     
    231233}
    232234
    233 //////////////////////////////////
     235///////////////////////////////
    234236int trace( unsigned int active,
    235237           unsigned int cxy,
     
    242244}
    243245
    244 //////////////////
     246////////////////////////
    245247int display_dqdt( void )
    246248{
     
    249251}
    250252
    251 ///////////
     253/////////////////
    252254void idbg( void )
    253255{
     
    327329///////////////    non standard malloc functions    //////////////////////////
    328330
    329 #define  MALLOC_DEBUG  0
    330  
    331331/////////////////////////////////////////////////////////////////////////////////////////
    332332// Global variable defining the allocator array (one per cluster)
     
    377377////////////////////////////////////////////////////////////////////////////////////////////
    378378
    379 #if 0
     379#if MALLOC_DEBUG
    380380static void display_free_array( unsigned int cxy )
    381381{
     
    487487    }
    488488
    489     // DEPRECATED: we don't reset the alloc_size array
     489    // DEPRECATED: we don't reset the alloc_base array
    490490    // because we don't want to allocate the physical memory
    491491    // when the heap is created  [AG]
     
    591591                      unsigned int cxy )
    592592{
     593    int error;
    593594
    594595#if MALLOC_DEBUG
     
    631632
    632633    // take the lock protecting access to store[cxy]
    633     pthread_mutex_lock( &store[cxy].mutex );
     634    error = pthread_mutex_lock( &store[cxy].mutex );
     635
     636    if( error )
     637    {
     638        printf("\n[ERROR] in %s : cannot take the lock protecting store in cluster %x\n",
     639        __FUNCTION__ , cxy );
     640        return NULL;
     641    }
    634642
    635643    // call the recursive function get_block
     
    651659    unsigned char * ptr    = (unsigned char*)(store[cxy].alloc_base + offset);
    652660
    653     // DEPRECATED : we don't check the alloc[] array,
    654     // because it has not been initialised, to avoid
    655     // physical memory allocation at heap creation [AG]
     661    // DEPRECATED : we cannot check the alloc[] array,
     662    // because it has not been initialised by store_init,
     663    // to avoid physical memory allocation at heap creation [AG]
    656664    // if ( *ptr != 0 )
    657665    // {
  • trunk/libs/libpthread/pthread.c

    r477 r573  
    3131#include <syscalls_numbers.h>
    3232
    33 #define PTHREAD_MUTEX_DEBUG     0
    34 #define PTHREAD_BARRIER_DEBUG   1
     33#define PTHREAD_BARRIER_DEBUG   0
    3534
    3635////////////////////////////////////////////////////////////////////////////////////////////
     
    307306        if ( node->parent != NULL )  sqt_barrier_decrement( node->parent );
    308307
    309         // reset the current node
    310         node->sense = expected;
    311         node->count = node->arity;
    312 
    313308#if PTHREAD_BARRIER_DEBUG
    314309printf("\n[BARRIER] %s : core[%x,%d] reset SQT barrier node %x :\n"
     
    317312node->level , node->arity , node->sense , node->count );
    318313#endif
     314        // reset the current node
     315        node->sense = expected;
     316        node->count = node->arity;
     317
    319318        return;
    320319    }
     
    374373    }
    375374
    376     mutex->current = 0;
    377     mutex->free    = 0;
    378 
    379 #if PTHEAD_MUTEX_DEBUG
    380 unsigned int cxy;
    381 unsigned int lid;
    382 get_core( &cxy , &lid );
    383 printf("\n[MUTEX DEBUG] %s : core[%x,%d] initializes mutex %x\n",
    384 __FUNCTION__, cxy, lid, mutex );
    385 #endif
    386 
    387     return 0;
     375    return hal_user_syscall( SYS_MUTEX,
     376                             (reg_t)mutex,
     377                             MUTEX_INIT,
     378                             0, 0 );
     379}
     380
     381////////////////////////////////////////////////////
     382int pthread_mutex_destroy( pthread_mutex_t * mutex )
     383{
     384    return hal_user_syscall( SYS_MUTEX,
     385                             (reg_t)mutex,
     386                             MUTEX_DESTROY,
     387                             0, 0 );
    388388}
    389389
     
    391391int pthread_mutex_lock( pthread_mutex_t * mutex )
    392392{
    393     unsigned int          ticket;
    394 
    395     // get next free ticket
    396     ticket = (unsigned int)hal_user_atomic_add( (int *)&mutex->free, 1 );
    397 
    398 #if PTHREAD_MUTEX_DEBUG
    399 unsigned int cxy;
    400 unsigned int lid;
    401 get_core( &cxy , &lid );
    402 printf("\n[MUTEX DEBUG] %s : core[%x,%d] get ticket %d\n",
    403 " / mutex = %x / current = %d / free = %d\n",
    404 __FUNCTION__, cxy, lid, ticket, mutex, mutex->current, mutex->free );
    405 #endif
    406 
    407     // poll the current index
    408     while( 1 )
    409     {
    410         if( mutex->current == ticket) break;
    411     }
    412                
    413 #if PTHREAD_MUTEX_DEBUG
    414 printf("\n[MUTEX DEBUG] %s : core[%x,%d] get mutex %x / current = %d / free = %d\n",
    415 __FUNCTION__, cxy, lid, mutex, mutex->current, mutex->free );
    416 #endif
    417 
    418     return 0;
     393    return hal_user_syscall( SYS_MUTEX,
     394                             (reg_t)mutex,
     395                             MUTEX_LOCK,
     396                             0, 0 );
    419397}
    420398
     
    422400int pthread_mutex_trylock( pthread_mutex_t * mutex )
    423401{
    424     unsigned int          ticket;
    425 
    426     // get next free ticket
    427     ticket = (unsigned int)hal_user_atomic_add( (int *)&mutex->free, 1 );
    428 
    429 #if PTHREAD_MUTEX_DEBUG
    430 unsigned int    cxy;
    431 unsigned int    lid;
    432 get_core( &cxy, &lid );
    433 printf("\n[MUTEX DEBUG] %s : core[%x,%d] get ticket = %d"
    434 " / mutex = %x / current = %d / free = %d\n",
    435 __FUNCTION__, cxy, lid, ticket, mutex, mutex->current, mutex->free );
    436 #endif
    437 
    438     // test ticket
    439     if( ticket == mutex->current ) return 0;       // success
    440     else                           return -1;      // failure
     402    return hal_user_syscall( SYS_MUTEX,
     403                             (reg_t)mutex,
     404                             MUTEX_TRYLOCK,
     405                             0, 0 );
    441406}
    442407   
     
    444409int pthread_mutex_unlock( pthread_mutex_t * mutex )
    445410{
    446     hal_user_fence();
    447 
    448     mutex->current = mutex->current + 1;
    449 
    450 #if PTHREAD_MUTEX_DEBUG
    451 unsigned int    cxy;
    452 unsigned int    lid;
    453 get_core( &cxy , &lid );
    454 printf("\n[MUTEX_DEBUG] %s : core[%x,%d] releases mutex %x"
    455 " / current = %d / free = %d\n",
    456 __FUNCTION__, cxy, lid, mutex, mutex->current, mutex->free );
    457 #endif
    458 
    459     return 0;
    460 }
     411    return hal_user_syscall( SYS_MUTEX,
     412                             (reg_t)mutex,
     413                             MUTEX_UNLOCK,
     414                             0, 0 );
     415}
     416
     417////////////////////////////////////////////////////////////////////////////////////////////
     418//                               Condition variable
     419////////////////////////////////////////////////////////////////////////////////////////////
     420
     421///////////////////////////////////////////////
     422int pthread_cond_init( pthread_cond_t     * cond,
     423                       pthread_condattr_t * attr )
     424{
     425    if( attr )
     426    {
     427        printf("[ERROR] in %s ; <attr> argument must be NULL\n", __FUNCTION__ );
     428        return -1;
     429    }
     430
     431   return hal_user_syscall( SYS_CONDVAR,
     432                             (reg_t)cond,
     433                             CONDVAR_INIT,
     434                             0, 0 );
     435}
     436
     437/////////////////////////////////////////////////
     438int pthread_cond_destroy( pthread_cond_t * cond )
     439{
     440    return hal_user_syscall( SYS_CONDVAR,
     441                             (reg_t)cond,
     442                             CONDVAR_DESTROY,
     443                             0, 0 );
     444}
     445
     446//////////////////////////////////////////////
     447int pthread_cond_wait( pthread_cond_t  * cond,
     448                       pthread_mutex_t * mutex )
     449{
     450    return hal_user_syscall( SYS_CONDVAR,
     451                             (reg_t)cond,
     452                             CONDVAR_WAIT,
     453                             (reg_t)mutex,
     454                             0 );
     455}
     456
     457////////////////////////////////////////////////
     458int pthread_cond_signal( pthread_cond_t * cond )
     459{
     460    return hal_user_syscall( SYS_CONDVAR,
     461                             (reg_t)cond,
     462                             CONDVAR_SIGNAL,
     463                             0, 0 );
     464}
     465
     466///////////////////////////////////////////////////
     467int pthread_cond_broadcast( pthread_cond_t * cond )
     468{
     469    return hal_user_syscall( SYS_CONDVAR,
     470                             (reg_t)cond,
     471                             CONDVAR_BROADCAST,
     472                             0, 0 );
     473}
     474
     475
     476
     477
    461478
    462479
  • trunk/libs/libpthread/pthread.h

    r477 r573  
    22 * pthread.h - User level <pthread> library definition.
    33 *
    4  * Author     Alain Greiner (2016,2017)
     4 * Author     Alain Greiner (2016,2017,2018)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    2626
    2727//////////////////////////////////////////////////////////////////////////////////////////////
    28 //             POSIX Threads related functions (including barriers and mutexes)
     28//             POSIX thread related functions
     29//
     30//  This include the thread creation/destruction, as well as the synchronisations:
     31//  barriers, mutexes, and condition variables.
    2932//////////////////////////////////////////////////////////////////////////////////////////////
    3033
     
    7275 * pointer available to any successful pthread_join() with the terminating thread.
    7376 *********************************************************************************************
    74  * @ exit_vallue  : [in] pointer to be returned to parent thread if thead is attached.
     77 * @ exit_vallue  : [in] pointer to be returned to parent thread if thread is attached.
    7578 * @ return 0 if success / return -1 if failure.
    7679 ********************************************************************************************/
     
    8588int pthread_yield( void );
    8689
    87 //////////////////////////////////////////////////////////////////////////////////////////////
    88 //                 POSIX Barriers related functions
     90
     91//////////////////////////////////////////////////////////////////////////////////////////////
     92//                 POSIX barrier related functions
    8993//
    9094// These functions are implemented in user space. Only the pthread_barrier_init() function
    91 // uses syscalls to build the distributed quad-tree infrastructure.
     95// uses system calls to build the distributed quad-tree infrastructure.
    9296//////////////////////////////////////////////////////////////////////////////////////////////
    9397
     
    100104 *   . The involved clusters form a mesh [x_size * y_size]
    101105 *   . The lower left involved cluster is cluster(0,0) 
    102  *   . The number of threads in a cluster is the same in all clusters.
     106 *   . The number of threads per cluster is the same in all clusters.
    103107 *
    104108 * Implementation note:
     
    183187
    184188//////////////////////////////////////////////////////////////////////////////////////////////
    185 //                      POSIX Mutexes
    186 //
    187 // These functions are implemented in user space, and do not use syscalls.
    188 // This implementation uses a ticket based policy to enforce fairness.
    189 //////////////////////////////////////////////////////////////////////////////////////////////
    190 
    191 typedef struct pthread_mutex_s
    192 {
    193     volatile unsigned int current;   /*! current index                                      */
    194     volatile unsigned int free;      /*! next free ticket index                             */
    195 }
    196 pthread_mutex_t;
    197 
    198 typedef struct pthread_mutexattr_s
    199 {
    200     int          bloup;              /*! unused                                             */
    201 }
    202 pthread_mutexattr_t;
     189//                      POSIX mutex related functions
     190//////////////////////////////////////////////////////////////////////////////////////////////
    203191
    204192/*********************************************************************************************
     
    231219
    232220/*********************************************************************************************
     221 * This function unlocks the mutex identified by the <mutex> argument.
     222 *********************************************************************************************
     223 * @ mutex     : pointer on mutex in user space.
     224 * @ return 0 if success / return -1 if failure.
     225 ********************************************************************************************/
     226int pthread_mutex_unlock( pthread_mutex_t * mutex );
     227
     228/*********************************************************************************************
    233229 * This function tries to lock the mutex identified by the <mutex> argument,
    234230 * but don't block if the mutex is locked by another thread, including the current thread.
     
    239235int pthread_mutex_trylock( pthread_mutex_t * mutex );
    240236
    241 /*********************************************************************************************
    242  * This function unlocks the mutex identified by the <mutex> argument.
    243  *********************************************************************************************
    244  * @ mutex     : pointer on mutex in user space.
    245  * @ return 0 if success / return -1 if failure.
    246  ********************************************************************************************/
    247 int pthread_mutex_unlock( pthread_mutex_t * mutex );
     237
     238//////////////////////////////////////////////////////////////////////////////////////////////
     239//                      POSIX condvar related functions
     240//////////////////////////////////////////////////////////////////////////////////////////////
     241
     242/*********************************************************************************************
     243 * This function initializes a condition variable identified by the <cond> argument.
     244 * WARNING: the <attr> argument is not supported and must be NULL.
     245 *********************************************************************************************
     246 * @ cond   : [in] pointer on condition in user space.
     247 * @ attr   : [in] pointer on condition attribute (must be NULL).
     248 * @ return 0 if success / return -1 if failure.
     249 ********************************************************************************************/
     250int pthread_cond_init( pthread_cond_t     * cond,
     251                       pthread_condattr_t * attr );
     252
     253/*********************************************************************************************
     254 * This function atomically unlocks the <mutex> and blocks the calling thread on the
     255 * condition specified by the <cond> argument.  The thread unblocks only after another
     256 * thread calls the pthread_cond_signal() or pthread_cond_broadcast() functions with the
     257 * same condition variable.  The mutex must be locked before calling this function,
     258 * otherwise the behavior is undefined. Before the pthread_cond_wait() function returns
     259 * to the calling function, it re-acquires the <mutex>.
     260 *********************************************************************************************
     261 * @ cond      : pointer on condition in user space.
     262 * @ mutex     : pointer on mutex in user space.
     263 * @ return 0 if success / return -1 if failure.
     264 ********************************************************************************************/
     265int pthread_cond_wait( pthread_cond_t  * cond,
     266                       pthread_mutex_t * mutex );
     267
     268/*********************************************************************************************
     269 * This function unblocks one thread blocked on condition specified by the <cond> argument.
     270 *********************************************************************************************
     271 * @ cond      : pointer on condition in user space.
     272 * @ return 0 if success / return -1 if failure.
     273 ********************************************************************************************/
     274int pthread_cond_signal( pthread_cond_t * cond );
     275
     276/*********************************************************************************************
     277 * This function unblocks all threads blocked on condition specified by the <cond> argument.
     278 *********************************************************************************************
     279 * @ cond      : pointer on condition in user space.
     280 * @ return 0 if success / return -1 if failure.
     281 ********************************************************************************************/
     282int pthread_cond_broadcast( pthread_cond_t * cond );
     283
     284/*********************************************************************************************
     285 * This function delete the condition variable specified by the <cond> argument.
     286 *********************************************************************************************
     287 * @ cond      : pointer on condition in user space.
     288 * @ return 0 if success / return -1 if failure.
     289 ********************************************************************************************/
     290int pthread_cond_destroy( pthread_cond_t * cond );
     291
    248292
    249293
  • trunk/libs/libsemaphore/semaphore.c

    r469 r573  
    11/*
    2  * pthread.c - User leve <semaphore> library implementation.
     2 * pthread.c - User level <semaphore> library implementation.
    33 *
    44 * Author     Alain Greiner (2016,2017,2018)
  • trunk/libs/libsemaphore/semaphore.h

    r469 r573  
    22 * pthread.h - User level <semaphore> library definition.
    33 *
    4  * Author     Alain Greiner (2016,2017)
     4 * Author     Alain Greiner (2016,2017,2018)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    3333/*********************************************************************************************
    3434 * This function initializes an unnamed semaphore.
    35  * Process shared semaphores are not supported in this implementation.
    3635 * Initializing a semaphore that has already been initialized results in undefined behavior.
    3736 *********************************************************************************************
     
    4645
    4746/*********************************************************************************************
    48  * This blocking function locks a semaphore. It decrements the semaphore pointed to by <sem>.
     47 * This blocking function takes a semaphore. It decrements the semaphore pointed to by <sem>.
    4948 * If the semaphore's value is greater than zero, then the decrement proceeds, and the
    50  * function returns immediately. If the semaphore currently has the value zero, then the call
    51  * blocks until it becomes possible to perform the decrement.
     49 * function returns immediately. If the semaphore currently has the value zero, the calling
     50 * thread registers in the associated waiting queue, blocks and deschedules.
     51 * It will be unblocked by another thread when it becomes possible to perform the decrement.
    5252 *********************************************************************************************
    5353 * @ sem         : [in]  pointer on semaphore.
     
    5757
    5858/*********************************************************************************************
    59  * This function unlocks a semaphore. It increments the semaphore pointed to by <sem>.
     59 * This function releases a semaphore. It increments the semaphore pointed to by <sem>.
    6060 * If the semaphore's value consequently becomes greater than zero, then another thread
    61  * blocked in a sem_wait() call will be woken up and proceed to lock the semaphore.
     61 * blocked in a sem_wait() call will be woken up to try to take the semaphore.
    6262 *********************************************************************************************
    6363 * @ sem         : [in]  pointer on semaphore.
  • trunk/libs/mini-libc/stdio.c

    r476 r573  
    4646    unsigned int ps = 0;    // write index to the string buffer
    4747
    48 #define TO_STREAM(x) do { string[ps] = (x); ps++; if(ps==length) return -1; } while(0);
     48#define TO_STREAM(x) do { string[ps] = (x); ps++; if(ps==length) return 0xFFFFFFFF; } while(0);
    4949
    5050xprintf_text:
     
    246246            default:       // unsupported argument type
    247247            {
    248                 return -1;
     248                return 0xFFFFFFFF;
    249249            }
    250250        }  // end switch on  argument type
     
    273273    va_end( args );
    274274
    275     if ( count == -1 )
     275    if ( count == 0xFFFFFFFF )
    276276    {
    277277        display_string( "printf : xprintf failure" );
     
    386386    va_end( args );
    387387
    388     if ( count == -1 )
     388    if ( count == 0xFFFFFFFF )
    389389    {
    390390        display_string( "fprintf : xprintf failure" );
Note: See TracChangeset for help on using the changeset viewer.