Ignore:
Timestamp:
Feb 12, 2013, 6:33:31 PM (12 years ago)
Author:
meunier
Message:

Added support for memspaces and const.
Added an interrupt masking to the "giet_context_switch" syscall
Corrected two bugs in boot/boot_init.c (one minor and one regarding barriers initialization)
Reformatted the code in all files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/libs/barrier.c

    r165 r228  
    1515
    1616///////////////////////////////////////////////////////////////////////////////////
    17 //      barrier_init()
     17//     barrier_init()
    1818// This function makes a cooperative initialisation of the barrier:
    1919// several tasks try to initialize the barrier, but the initialisation
    2020// is done by only one task, using LL/SC instructions.
    2121///////////////////////////////////////////////////////////////////////////////////
    22 void barrier_init( giet_barrier_t*      barrier,
    23                    unsigned int         value )
    24 {
    25     unsigned int* pinit  = (unsigned int*)&barrier->init;
    26     unsigned int* pcount = (unsigned int*)&barrier->count;
     22void barrier_init( giet_barrier_t * barrier, unsigned int value) {
     23    unsigned int * pinit  = (unsigned int *) &barrier->init;
     24    unsigned int * pcount = (unsigned int *) &barrier->count;
    2725
    2826    // parallel initialisation using atomic instructions LL/SC
     
    3028    // no output
    3129    asm volatile ("_barrier_init_test:                  \n"
    32                   "ll   $2,     0(%0)                   \n" /* read initial value */
    33                   "bnez $2,     _barrier_init_done      \n"
    34                   "move $3,     %2                      \n"
    35                   "sc   $3,     0(%0)                   \n" /* write initial value */
    36                   "beqz $3,     _barrier_init_test      \n"
    37                   "move $3,     %2                      \n"
    38                   "sw   $3,     0(%1)                   \n" /* write count */
    39                   "_barrier_init_done:                  \n"
    40                   :: "r"(pinit), "r"(pcount), "r"(value)
    41                   : "$2", "$3");
     30            "ll   $2,     0(%0)                   \n" /* read initial value */
     31            "bnez $2,     _barrier_init_done      \n"
     32            "move $3,     %2                      \n"
     33            "sc   $3,     0(%0)                   \n" /* write initial value */
     34            "beqz $3,     _barrier_init_test      \n"
     35            "move $3,     %2                      \n"
     36            "sw   $3,     0(%1)                   \n" /* write count */
     37            "_barrier_init_done:                  \n"
     38            :
     39            : "r"(pinit), "r"(pcount), "r"(value)
     40            : "$2", "$3");
    4241}
     42
     43
    4344///////////////////////////////////////////////////////////////////////////////////
    44 //      barrier_wait()
     45//    barrier_wait()
    4546// This blocking function uses LL/SC to decrement the barrier's counter.
    4647// Then, it uses a busy_waiting mechanism if it is not the last.
    4748// (because the GIET does not support dynamic task scheduling/descheduling)
    4849///////////////////////////////////////////////////////////////////////////////////
    49 void barrier_wait( giet_barrier_t* barrier )
    50 {
    51     unsigned int* pcount  = (unsigned int*)&barrier->count;
     50void barrier_wait(giet_barrier_t * barrier) {
     51    unsigned int * pcount  = (unsigned int *) &barrier->count;
    5252    unsigned int maxcount = barrier->init;
    5353    unsigned int count;
     
    5757    // - output : counter value
    5858    asm volatile ("_barrier_decrement:          \n"
    59                   "ll   %0, 0(%1)               \n"
    60                   "addi $3, %0,     -1          \n"
    61                   "sc   $3, 0(%1)               \n"
    62                   "beqz $3, _barrier_decrement  \n"
    63                   : "=&r"(count)
    64                   : "r"(pcount)
    65                   : "$2", "$3");
     59            "ll   %0, 0(%1)               \n"
     60            "addi $3, %0,     -1          \n"
     61            "sc   $3, 0(%1)               \n"
     62            "beqz $3, _barrier_decrement  \n"
     63            : "=&r"(count)
     64            : "r"(pcount)
     65            : "$2", "$3");
    6666
    6767    // the last task re-initializes the barrier counter to the max value,
    6868    // waking up all other waiting tasks
    6969
    70     if (count == 1)             // last task
    71     {
     70    if (count == 1) {
     71        // last task
    7272        *pcount = maxcount;
    7373    }
    74     else                        // other tasks busy-wait
    75     {
     74    else {
     75        // other tasks busy-wait
    7676        while (*pcount != maxcount) asm volatile ("nop");
    7777    }
    7878}
    7979
     80// Local Variables:
     81// tab-width: 4
     82// c-basic-offset: 4
     83// c-file-offsets:((innamespace . 0)(inline-open . 0))
     84// indent-tabs-mode: nil
     85// End:
     86// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     87
Note: See TracChangeset for help on using the changeset viewer.