source: soft/giet_vm/router/main.c @ 411

Last change on this file since 411 was 345, checked in by cfuguet, 10 years ago

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.
File size: 3.2 KB
RevLine 
[191]1#include "stdio.h"
2#include "mwmr_channel.h"
3#include "mapping_info.h"
[295]4#include "hard_config.h"
[191]5
[345]6#if NB_TTY_CHANNELS == 1
7#  define printf(...) giet_shr_printf(__VA_ARGS__)
8#else
9#  define printf(...) giet_tty_printf(__VA_ARGS__)
10#endif
11
[295]12#define NMAX 50
[191]13
14/////////////////////////////////////////////
15__attribute__ ((constructor)) void producer()
16{
17
18    unsigned int        n;
19    unsigned int        buf;
20    mwmr_channel_t*     mwmr;
21
[295]22    unsigned int    procid     = giet_procid();
23    unsigned int    cluster_xy = procid/NB_PROCS_MAX;
24    unsigned int    lpid       = procid%NB_PROCS_MAX;
25    unsigned int    x          = cluster_xy >> Y_WIDTH;
26    unsigned int    y          = cluster_xy & ((1<<Y_WIDTH)-1);
[191]27
[345]28    printf( "*** Starting task producer on processor[%d,%d,%d] at cycle %d\n\n", 
29             x, y, lpid, giet_proctime() );
[191]30
[295]31    giet_vobj_get_vbase( "router" , 
32                         "mwmr_in", 
33                         (void*)&mwmr );
34
[264]35    // main loop : display token value = source index
[191]36    for(n = 0 ; n < NMAX ; n++) 
37    { 
38        buf = n;
39        mwmr_write( mwmr, &buf , 1 );
[345]40        printf( "transmitted value : %d\n", buf);
[191]41    }
42
[295]43    giet_exit( "Producer task completed");
[191]44
45} // end producer()
46
47/////////////////////////////////////////////
48__attribute__ ((constructor)) void consumer()
49{
50    unsigned int        n;
51    unsigned int        buf;
52    mwmr_channel_t*     mwmr;
53
[295]54    unsigned int    procid     = giet_procid();
55    unsigned int    cluster_xy = procid/NB_PROCS_MAX;
56    unsigned int    lpid       = procid%NB_PROCS_MAX;
57    unsigned int    x          = cluster_xy >> Y_WIDTH;
58    unsigned int    y          = cluster_xy & ((1<<Y_WIDTH)-1);
[191]59
[345]60    printf( "*** Starting task consumer on processor[%d,%d,%d] at cycle %d\n\n", 
61             x, y, lpid, giet_proctime() );
[191]62
[295]63    giet_vobj_get_vbase( "router" , 
64                         "mwmr_out", 
65                         (void*)&mwmr );
66
[191]67    // main loop : display token arrival index and value
68    for(n = 0 ; n < NMAX ; n++ ) 
69    { 
70        mwmr_read( mwmr, &buf , 1 );
[345]71        printf( "received token %d / value = %d\n", n  , buf);
[191]72    }
73
[295]74    giet_exit( "Consumer task completed");
[191]75
76} // end consumer()
77
78///////////////////////////////////////////
79__attribute__ ((constructor)) void router()
80{
[264]81    unsigned int        buf;
[295]82    unsigned int        n;
[191]83    unsigned int        tempo;
84    mwmr_channel_t*     mwmr_in ;
85    mwmr_channel_t* mwmr_out ;
86
[295]87    unsigned int    procid     = giet_procid();
88    unsigned int    cluster_xy = procid/NB_PROCS_MAX;
89    unsigned int    lpid       = procid%NB_PROCS_MAX;
90    unsigned int    x          = cluster_xy >> Y_WIDTH;
91    unsigned int    y          = cluster_xy & ((1<<Y_WIDTH)-1);
[191]92
[345]93    printf( "*** Starting task router on processor[%d,%d,%d] at cycle %d\n\n", 
94             x, y, lpid, giet_proctime() );
[191]95
[295]96    giet_vobj_get_vbase( "router" , 
97                         "mwmr_out", 
98                         (void*)&mwmr_out );
[191]99
[295]100    giet_vobj_get_vbase( "router" , 
101                         "mwmr_in", 
102                         (void*)&mwmr_in );
[191]103    // main loop
104    while(1)
105    {
[264]106        mwmr_read( mwmr_in , &buf , 1 );
[191]107        tempo = giet_rand() >> 6;
[295]108        for ( n = 0 ; n < tempo ; n++ ) asm volatile ("");
[345]109        printf( "token value : %d / temporisation = %d\n", buf, tempo);
[264]110        mwmr_write( mwmr_out, &buf , 1 );
[191]111    }
112}
Note: See TracBrowser for help on using the repository browser.