Ignore:
Timestamp:
Jun 25, 2014, 2:19:37 PM (10 years ago)
Author:
cfuguet
Message:

giet_vm optimizations:

  • Several modifications in GIET_VM in order to support compilation with GCC optimizations (-O2) activated.
  • Adding missing volatile in some global variables.
  • Using ioread and iowrite utility functions in peripheral drivers which prevent GCC to remove writes or reads in hardware memory mapped registers.
  • Code refactoring of stdio printf functions. Now, shr_printf and tty_printf function reuse the same function body. The only difference is that shr_printf wraps printf function call with TTY get lock and release lock.
Location:
soft/giet_vm/giet_drivers
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_drivers/dma_driver.c

    r343 r345  
    3232#include <vmem.h>
    3333#include <utils.h>
     34#include <io.h>
    3435
    3536#if !defined(X_SIZE)
     
    6162#endif
    6263
    63 extern unsigned int _ptabs_vaddr[];
     64extern volatile unsigned int _ptabs_vaddr[];
     65
     66///////////////////////////////////////////////////////////////////////////////
     67// This low level function returns the value contained in register "index"
     68// in the DMA component contained in cluster "cluster_xy"
     69///////////////////////////////////////////////////////////////////////////////
     70static
     71unsigned int _dma_get_register( unsigned int cluster_xy, // cluster index
     72                                unsigned int channel_id, // channel index
     73                                unsigned int index )     // register index
     74{
     75    unsigned int vaddr =
     76        SEG_DMA_BASE +
     77        (cluster_xy * PERI_CLUSTER_INCREMENT) +
     78        (channel_id * DMA_SPAN) +
     79        (index << 2);
     80
     81    return ioread32( (void*)vaddr );
     82}
     83
     84///////////////////////////////////////////////////////////////////////////////
     85// This low level function sets a new value in register "index"
     86// in the DMA component contained in cluster "cluster_xy"
     87///////////////////////////////////////////////////////////////////////////////
     88static
     89void _dma_set_register( unsigned int cluster_xy,       // cluster index
     90                        unsigned int channel_id,       // channel index
     91                        unsigned int index,            // register index
     92                        unsigned int value )           // value to be written
     93{
     94    unsigned int vaddr =
     95        SEG_DMA_BASE +
     96        (cluster_xy * PERI_CLUSTER_INCREMENT) +
     97        (channel_id * DMA_SPAN) +
     98        (index << 2);
     99
     100    iowrite32( (void*)vaddr, value );
     101}
    64102
    65103//////////////////////////////////////////////////////////////////////////////////
     
    81119    if (channel_id >= NB_DMA_CHANNELS)  return 1;
    82120
    83     // compute DMA base address
    84     unsigned int* dma_address = (unsigned int*) ( SEG_DMA_BASE +
    85                                 (cluster_xy * PERI_CLUSTER_INCREMENT) );
    86 
    87121    // disable interrupt for selected channel
    88     dma_address[channel_id * DMA_SPAN + DMA_IRQ_DISABLE] = 1;           
     122    _dma_set_register(cluster_xy, channel_id, DMA_IRQ_DISABLE, 1);
    89123    return 0;
    90124#else
     
    109143    if (channel_id >= NB_DMA_CHANNELS)  return 1;
    110144
    111     // compute DMA base address
    112     unsigned int* dma_address = (unsigned int*) ( SEG_DMA_BASE +
    113                                 (cluster_xy * PERI_CLUSTER_INCREMENT) );
    114 
    115145    // reset selected channel
    116     dma_address[channel_id * DMA_SPAN + DMA_RESET] = 0;           
     146    _dma_set_register(cluster_xy, channel_id, DMA_RESET, 0);
    117147    return 0;
    118148#else
     
    136166    if (channel_id >= NB_DMA_CHANNELS)  return 1;
    137167
    138     // compute DMA base address
    139     unsigned int * dma_address = (unsigned int *) ( SEG_DMA_BASE +
    140                                  (cluster_xy * PERI_CLUSTER_INCREMENT) );
    141 
    142168    // get selected channel status
    143     return dma_address[channel_id * DMA_SPAN + DMA_LEN];
     169    return _dma_get_register(cluster_xy, channel_id, DMA_LEN);
    144170#else
    145171    return DMA_IDLE;
     
    160186#if NB_DMA_CHANNELS > 0
    161187
    162     // compute DMA base address
    163     unsigned int * dma_address = (unsigned int *) ( SEG_DMA_BASE +
    164                                  (cluster_xy * PERI_CLUSTER_INCREMENT) );
    165 
    166188    // selected channel configuration and lauching
    167     dma_address[channel_id * DMA_SPAN + DMA_SRC]     = (unsigned int)(src_paddr);
    168     dma_address[channel_id * DMA_SPAN + DMA_SRC_EXT] = (unsigned int)(src_paddr>>32);
    169     dma_address[channel_id * DMA_SPAN + DMA_DST]     = (unsigned int)(dst_paddr);
    170     dma_address[channel_id * DMA_SPAN + DMA_DST_EXT] = (unsigned int)(dst_paddr>>32);
    171     dma_address[channel_id * DMA_SPAN + DMA_LEN]     = (unsigned int)size;
     189    _dma_set_register(cluster_xy, channel_id, DMA_SRC,
     190            (unsigned int)(src_paddr));
     191    _dma_set_register(cluster_xy, channel_id, DMA_SRC_EXT,
     192            (unsigned int)(src_paddr>>32));
     193    _dma_set_register(cluster_xy, channel_id, DMA_DST,
     194            (unsigned int)(dst_paddr));
     195    _dma_set_register(cluster_xy, channel_id, DMA_DST_EXT,
     196            (unsigned int)(dst_paddr>>32));
     197    _dma_set_register(cluster_xy, channel_id, DMA_LEN,
     198            (unsigned int)size);
    172199
    173200#endif
     
    312339
    313340    // get vspace page table pointer
    314     unsigned int pt =  _ptabs_vaddr[vspace_id];
     341    unsigned int pt = _ptabs_vaddr[vspace_id];
    315342
    316343    // get src_paddr buffer physical addresse
  • soft/giet_vm/giet_drivers/fbf_driver.c

    r320 r345  
    6464    char* fbf_address = (char *)SEG_FBF_BASE + offset;
    6565
    66     _memcpy( fbf_address, buffer, length);
     66    memcpy( fbf_address, buffer, length);
    6767
    6868    return 0;
     
    8181    char* fbf_address = (char *)SEG_FBF_BASE + offset;
    8282
    83     _memcpy( buffer, fbf_address, length);
     83    memcpy( buffer, fbf_address, length);
    8484
    8585    return 0;
  • soft/giet_vm/giet_drivers/mmc_driver.c

    r333 r345  
    2121#include <tty_driver.h>
    2222#include <utils.h>
     23#include <io.h>
    2324
    2425#if !defined(X_SIZE)
     
    4647#endif
    4748
     49///////////////////////////////////////////////////////////////////////////////
     50// This low level function returns the value contained in register "index"
     51// in the MMC component contained in cluster "cluster_xy"
     52///////////////////////////////////////////////////////////////////////////////
     53static
     54unsigned int _mmc_get_register( unsigned int cluster_xy, // cluster index
     55                                unsigned int func,       // function index
     56                                unsigned int index )     // register index
     57{
     58    unsigned int vaddr =
     59        SEG_MMC_BASE +
     60        (cluster_xy * PERI_CLUSTER_INCREMENT) +
     61        (MMC_REG(func, index) << 2);
     62
     63    return ioread32( (void*)vaddr );
     64}
     65
     66///////////////////////////////////////////////////////////////////////////////
     67// This low level function sets a new value in register "index"
     68// in the MMC component contained in cluster "cluster_xy"
     69///////////////////////////////////////////////////////////////////////////////
     70static
     71void _mmc_set_register( unsigned int cluster_xy,       // cluster index
     72                        unsigned int func,             // func index
     73                        unsigned int index,            // register index
     74                        unsigned int value )           // value to be written
     75{
     76    unsigned int vaddr =
     77        SEG_MMC_BASE +
     78        (cluster_xy * PERI_CLUSTER_INCREMENT) +
     79        (MMC_REG(func, index) << 2);
     80       
     81    iowrite32( (void*)vaddr, value );
     82}
     83
    4884///////////////////////////////////////////////////////////////////////////////////
    4985// This function invalidates all cache lines covering a memory buffer defined
     
    67103    }
    68104
    69     unsigned int* mmc_address = (unsigned int*)( SEG_MMC_BASE +
    70                                 (cluster_xy * PERI_CLUSTER_INCREMENT) );
    71 
    72105    // get the hard lock protecting exclusive access to MEMC
    73     while ( mmc_address[MEMC_LOCK] ) { asm volatile("nop"); }
     106    while ( _mmc_get_register(cluster_xy, 0, MEMC_LOCK) );
    74107
    75108    // write inval arguments
    76     mmc_address[MEMC_ADDR_LO]    = (unsigned int)buf_paddr;
    77     mmc_address[MEMC_ADDR_HI]    = (unsigned int)(buf_paddr>>32);
    78     mmc_address[MEMC_BUF_LENGTH] = buf_length;
    79     mmc_address[MEMC_CMD_TYPE]   = MEMC_CMD_INVAL;
     109    _mmc_set_register(cluster_xy, 0, MEMC_ADDR_LO   , (unsigned int)buf_paddr);
     110    _mmc_set_register(cluster_xy, 0, MEMC_ADDR_HI   , (unsigned int)(buf_paddr>>32));
     111    _mmc_set_register(cluster_xy, 0, MEMC_BUF_LENGTH, buf_length);
     112    _mmc_set_register(cluster_xy, 0, MEMC_CMD_TYPE  , MEMC_CMD_INVAL);
    80113
    81114    // release the lock
    82     mmc_address[MEMC_LOCK] = 0;
     115    _mmc_set_register(cluster_xy, 0, MEMC_LOCK, 0);
    83116}
    84117///////////////////////////////////////////////////////////////////////////////////
     
    103136    }
    104137
    105     unsigned int* mmc_address = (unsigned int*)( SEG_MMC_BASE +
    106                                 (cluster_xy * PERI_CLUSTER_INCREMENT) );
    107 
    108138    // get the hard lock protecting exclusive access to MEMC
    109     while ( mmc_address[MEMC_LOCK] ) { asm volatile("nop"); }
     139    while ( _mmc_get_register(cluster_xy, 0, MEMC_LOCK) );
    110140
    111141    // write inval arguments
    112     mmc_address[MEMC_ADDR_LO]    = (unsigned int)buf_paddr;
    113     mmc_address[MEMC_ADDR_HI]    = (unsigned int)(buf_paddr>>32);
    114     mmc_address[MEMC_BUF_LENGTH] = buf_length;
    115     mmc_address[MEMC_CMD_TYPE]   = MEMC_CMD_SYNC;
     142    _mmc_set_register(cluster_xy, 0, MEMC_ADDR_LO   , (unsigned int)buf_paddr);
     143    _mmc_set_register(cluster_xy, 0, MEMC_ADDR_HI   , (unsigned int)(buf_paddr>>32));
     144    _mmc_set_register(cluster_xy, 0, MEMC_BUF_LENGTH, buf_length);
     145    _mmc_set_register(cluster_xy, 0, MEMC_CMD_TYPE  , MEMC_CMD_SYNC);
    116146
    117     // release the lock protecting MEMC
    118     mmc_address[MEMC_LOCK] = 0;
     147    // release the lock
     148    _mmc_set_register(cluster_xy, 0, MEMC_LOCK, 0);
    119149}
    120150
  • soft/giet_vm/giet_drivers/mmc_driver.h

    r297 r345  
    2929};
    3030
     31#define MMC_REG(func,idx) ((func<<7)|idx)
     32
    3133///////////////////////////////////////////////////////////////////////////////////
    3234// MEMC access functions (for TSAR architecture)
  • soft/giet_vm/giet_drivers/sim_driver.c

    r320 r345  
    3333                                 unsigned int * retval)
    3434{
    35     unsigned int* sim_helper_address = (unsigned int*)&seg_sim_base;
     35    volatile unsigned int* sim_helper_address = (unsigned int*)&seg_sim_base;
    3636   
    3737    if (register_index == SIMHELPER_SC_STOP         ||
  • soft/giet_vm/giet_drivers/tty_driver.c

    r333 r345  
    5353
    5454in_unckdata volatile unsigned int _tty_rx_full[NB_TTY_CHANNELS]
    55                                      = { [0 ... NB_TTY_CHANNELS - 1] = 0 };
    56 
    57 in_kdata unsigned int _tty_lock[NB_TTY_CHANNELS]
    58                         = { [0 ... NB_TTY_CHANNELS - 1] = 0 };
     55    = { [0 ... NB_TTY_CHANNELS - 1] = 0 };
     56
     57in_unckdata unsigned int _tty_lock[NB_TTY_CHANNELS]
     58    = { [0 ... NB_TTY_CHANNELS - 1] = 0 };
    5959
    6060//////////////////////////////////////////////////////////////////////////////
  • soft/giet_vm/giet_drivers/xcu_driver.c

    r333 r345  
    1616#include <mapping_info.h>
    1717#include <utils.h>
     18#include <io.h>
    1819
    1920#if !defined(X_SIZE)
     
    4950#endif
    5051
     52///////////////////////////////////////////////////////////////////////////////
     53// This low level function returns the value contained in register "index"
     54// in the XCU component contained in cluster "cluster_xy"
     55///////////////////////////////////////////////////////////////////////////////
     56static
     57unsigned int _xcu_get_register( unsigned int cluster_xy, // cluster index
     58                                unsigned int func,       // function index
     59                                unsigned int index )     // register index
     60{
     61    unsigned int vaddr =
     62        SEG_XCU_BASE +
     63        (cluster_xy * PERI_CLUSTER_INCREMENT) +
     64        (XCU_REG(func, index) << 2);
     65
     66    return ioread32( (void*)vaddr );
     67}
     68
     69///////////////////////////////////////////////////////////////////////////////
     70// This low level function sets a new value in register "index"
     71// in the XCU component contained in cluster "cluster_xy"
     72///////////////////////////////////////////////////////////////////////////////
     73static
     74void _xcu_set_register( unsigned int cluster_xy,       // cluster index
     75                        unsigned int func,             // func index
     76                        unsigned int index,            // register index
     77                        unsigned int value )           // value to be written
     78{
     79    unsigned int vaddr =
     80        SEG_XCU_BASE +
     81        (cluster_xy * PERI_CLUSTER_INCREMENT) +
     82        (XCU_REG(func, index) << 2);
     83       
     84    iowrite32( (void*)vaddr, value );
     85}
    5186
    5287////////////////////////////////////////////////////////////////////////////////
     
    68103    if (channel >= (NB_PROCS_MAX * IRQ_PER_PROCESSOR)) _exit();
    69104
    70     unsigned int* xcu_address = (unsigned int *) ( SEG_XCU_BASE +
    71                                 (cluster_xy * PERI_CLUSTER_INCREMENT) );
    72 
    73     unsigned int func;
     105    unsigned int func = 0;
    74106    if      (irq_type == IRQ_TYPE_PTI) func = XCU_MSK_PTI_ENABLE;
    75107    else if (irq_type == IRQ_TYPE_WTI) func = XCU_MSK_WTI_ENABLE;
     
    81113    }
    82114
    83     xcu_address[XCU_REG(func,channel)] = value;
     115    _xcu_set_register(cluster_xy, func, channel, value);
    84116
    85117#else
     
    110142    if (channel >= (NB_PROCS_MAX * IRQ_PER_PROCESSOR)) _exit();
    111143
    112     unsigned int* xcu_address = (unsigned int *) ( SEG_XCU_BASE +
    113                                 (cluster_xy * PERI_CLUSTER_INCREMENT) );
    114 
    115     unsigned int prio = xcu_address[XCU_REG(XCU_PRIO,channel)];
     144    unsigned int prio = _xcu_get_register(cluster_xy, XCU_PRIO, channel);
    116145    unsigned int pti_ok = (prio & 0x00000001);
    117146    unsigned int hwi_ok = (prio & 0x00000002);
     
    162191    if (wti_index >= 32)           _exit();
    163192
    164     unsigned int* xcu_address = (unsigned int *) ( SEG_XCU_BASE +
    165                                 (cluster_xy * PERI_CLUSTER_INCREMENT) );
    166 
    167     xcu_address[XCU_REG(XCU_WTI_REG,wti_index)] = wdata;
     193    _xcu_set_register(cluster_xy, XCU_WTI_REG, wti_index, wdata);
    168194
    169195#else
     
    191217    if (wti_index >= 32)           _exit();
    192218 
    193     unsigned int* xcu_address = (unsigned int *) ( SEG_XCU_BASE +
    194                                 (cluster_xy * PERI_CLUSTER_INCREMENT) );
    195 
    196     *value = xcu_address[XCU_REG(XCU_WTI_REG, wti_index)];
     219    *value = _xcu_get_register(cluster_xy, XCU_WTI_REG, wti_index);
    197220
    198221#else
     
    215238    if (wti_index >= 32)           _exit();
    216239 
    217     unsigned int xcu_address = (unsigned int)SEG_XCU_BASE;
    218     *address = xcu_address + (XCU_REG(XCU_WTI_REG, wti_index)<<2);
     240    *address = SEG_XCU_BASE + (XCU_REG(XCU_WTI_REG, wti_index)<<2);
    219241
    220242#else
     
    239261    if (y >= Y_SIZE)             _exit();
    240262
    241     unsigned int* xcu_address = (unsigned int *) ( SEG_XCU_BASE +
    242                                 (cluster_xy * PERI_CLUSTER_INCREMENT) );
    243 
    244     xcu_address[XCU_REG(XCU_PTI_PER, pti_index)] = period;
     263    _xcu_set_register(cluster_xy, XCU_PTI_PER, pti_index, period);
    245264
    246265#else
     
    264283    if (y >= Y_SIZE)             _exit();
    265284
    266     unsigned int* xcu_address = (unsigned int *) ( SEG_XCU_BASE +
    267                                 (cluster_xy * PERI_CLUSTER_INCREMENT) );
    268 
    269     xcu_address[XCU_REG(XCU_PTI_PER, pti_index)] = 0;
     285    _xcu_set_register(cluster_xy, XCU_PTI_PER, pti_index, 0);
    270286
    271287#else
     
    291307    if (y >= Y_SIZE)             _exit();
    292308
    293     unsigned int* xcu_address = (unsigned int *) ( SEG_XCU_BASE +
    294                                 (cluster_xy * PERI_CLUSTER_INCREMENT) );
    295 
    296309    // This return value is not used / avoid a compilation warning.
    297     return xcu_address[XCU_REG(XCU_PTI_ACK, pti_index)];
     310    return _xcu_get_register(cluster_xy, XCU_PTI_ACK, pti_index);
    298311
    299312#else
     
    322335    if (y >= Y_SIZE)             _exit();
    323336
    324     unsigned int* xcu_address = (unsigned int *) ( SEG_XCU_BASE +
    325                                 (cluster_xy * PERI_CLUSTER_INCREMENT) );
    326 
    327     unsigned int period = xcu_address[XCU_REG(XCU_PTI_PER, pti_index)];
     337    unsigned int per = _xcu_get_register(cluster_xy, XCU_PTI_PER, pti_index);
    328338
    329339    // we write 0 first because if the timer is currently running,
    330340    // the corresponding timer counter is not reset
    331     xcu_address[XCU_REG(XCU_PTI_PER, pti_index)] = 0;
    332     xcu_address[XCU_REG(XCU_PTI_PER, pti_index)] = period;
     341    _xcu_set_register(cluster_xy, XCU_PTI_PER, pti_index, 0);
     342    _xcu_set_register(cluster_xy, XCU_PTI_PER, pti_index, per);
    333343
    334344#else
Note: See TracChangeset for help on using the changeset viewer.