Ignore:
Timestamp:
Dec 12, 2014, 5:00:43 PM (10 years ago)
Author:
alain
Message:

Adding a new step in the kernel_init() procedure:
Processor[0][0][0] initialises the distributed kernel heap
allocators, and the distributed lock protecting TTY0.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_kernel/kernel_init.c

    r459 r467  
    1212#include <utils.h>
    1313#include <tty0.h>
     14#include <kernel_malloc.h>
    1415#include <fat32.h>
    1516#include <xcu_driver.h>
     
    6061#endif
    6162
     63#if !defined(NB_TTY_CHANNELS)
     64# error: You must define NB_TTY_CHANNELS in the hard_config.h file
     65#endif
     66
     67#if (NB_TTY_CHANNELS < 1)
     68# error: NB_TTY_CHANNELS cannot be smaller than 1
     69#endif
     70
     71
     72
     73///////////////////////////////////////////////////////////////////////////////////
     74// Ditributed kernel heap descriptors array (for dynamic memory allocation)
     75///////////////////////////////////////////////////////////////////////////////////
     76
     77kernel_heap_t  kernel_heap[X_SIZE][Y_SIZE];
     78
    6279///////////////////////////////////////////////////////////////////////////////////
    6380// FAT internal representation for kernel code
    6481///////////////////////////////////////////////////////////////////////////////////
    6582
    66 __attribute__((section (".kdata")))
    67 fat32_fs_t fat __attribute__((aligned(512)));
     83fat32_fs_t     fat      __attribute__((aligned(512)));
    6884
    6985///////////////////////////////////////////////////////////////////////////////////
     
    7187///////////////////////////////////////////////////////////////////////////////////
    7288
    73 __attribute__((section (".kdata")))
    7489volatile unsigned int _ptabs_vaddr[GIET_NB_VSPACE_MAX];    // virtual addresses
    75 
    76 __attribute__((section (".kdata")))       
    7790volatile unsigned int _ptabs_ptprs[GIET_NB_VSPACE_MAX];    // physical addresses >> 13
    7891
    7992///////////////////////////////////////////////////////////////////////////////////
    80 // array of pointers on the schedulers (physical addresses)
    81 ///////////////////////////////////////////////////////////////////////////////////
    82 
    83 __attribute__((section (".kdata")))
    84 volatile static_scheduler_t* _schedulers[X_SIZE][Y_SIZE][NB_PROCS_MAX];
     93// Array of pointers on the schedulers (physical addresses)
     94///////////////////////////////////////////////////////////////////////////////////
     95
     96volatile static_scheduler_t*    _schedulers[X_SIZE][Y_SIZE][NB_PROCS_MAX];
    8597
    8698////////////////////////////////////////////////////////////////////////////////////
     
    88100////////////////////////////////////////////////////////////////////////////////////
    89101
    90 __attribute__((section (".kdata")))
    91102volatile unsigned int kernel_init_barrier = 0;
    92103
     104////////////////////////////////////////////////////////////////////////////////////
     105// Global variables for TTY/kernel communications
     106////////////////////////////////////////////////////////////////////////////////////
     107
     108sbt_lock_t     _tty_tx_lock[NB_TTY_CHANNELS]  __attribute__((aligned(64)));
     109
     110unsigned int   _tty_rx_buf[NB_TTY_CHANNELS];
     111unsigned int   _tty_rx_full[NB_TTY_CHANNELS];
     112
     113
     114
     115
     116
     117///////////////////////////////////////////////////////////////////////////////////
     118// This kernel_init() function completes the kernel initialisation in 7 steps:
     119// All processors execute this code, but this is done sequencially.
     120// - step 0 : Initialise fat, heap descriptors, and tty locks
     121// - step 1 : Initialise scheduler pointers array
     122// - step 2 : Initialise PTAB pointers arrays
     123// - step 3 : Initialise private XCU masks
     124// - step 4 :
     125// - step 5 :
     126// - step 6 :
    93127///////////////////////////////////////////////////////////////////////////////////
    94128__attribute__((section (".kinit"))) void kernel_init()
    95129{
    96130    // gpid : hardware processor index (fixed format: X_WIDTH|Y_WIDTH|P_WIDTH)
    97     // p : local processor id in a cluster ( p < NB_PROCS_MAX)
    98     // cpid : "continuous" processor index = (((x * Y_SIZE + y) * NB_PROCS_MAX) + p
     131    // p    : local processor id in a cluster ( p < NB_PROCS_MAX)
     132    // cpid : continuous processor index = (((x * Y_SIZE + y) * NB_PROCS_MAX) + p
    99133
    100134    unsigned int gpid       = _get_procid();
     
    105139    unsigned int cpid       = ((( x * Y_SIZE) + y) * NB_PROCS_MAX) + p;
    106140
    107 
    108141    // This initialisation is done sequencially by each processor
    109142    while( cpid != kernel_init_barrier ) asm volatile ( "nop" );
    110143
    111     // Step 0 : Processor[0,0,0] initialises the kernel FAT
    112     if ( gpid == 0 ) _fat_init( IOC_BOOT_MODE );
     144    // Step 0 : P[0,0,0] initialises the kernel FAT
     145    //          and the distributed kernel_heap descriptors array.
     146    if ( gpid == 0 )
     147    {
     148        _heap_init();
     149       
     150#if GIET_DEBUG_INIT
     151_nolock_printf("\n[DEBUG KERNEL_INIT] P[%d,%d,%d] completes kernel HEAP init\n", x, y, p );
     152#endif
     153        unsigned int channel;
     154        for ( channel = 0 ; channel < NB_TTY_CHANNELS ; channel++ )
     155        {
     156            _sbt_lock_init( &_tty_tx_lock[channel] );
     157        }
     158
     159#if GIET_DEBUG_INIT
     160_nolock_printf("\n[DEBUG KERNEL_INIT] P[%d,%d,%d] completes TTY locks init\n", x, y, p );
     161#endif
     162
     163        _fat_init( IOC_BOOT_MODE );
     164
     165#if GIET_DEBUG_INIT
     166_nolock_printf("\n[DEBUG KERNEL_INIT] P[%d,%d,%d] completes kernel FAT init\n", x, y, p );
     167#endif
     168
     169    }
    113170
    114171    // Step 1 : each processor get its scheduler virtual address from CP0_SCHED register
     
    121178
    122179#if GIET_DEBUG_INIT
    123 _printf("\n[GIET DEBUG INIT] Processor[%d,%d,%d] starts kernel init\n"
    124         " - scheduler vbase = %x\n"
    125         " - tasks           = %d\n",
    126         x, y, p, (unsigned int)psched, tasks );
     180_nolock_printf("\n[DEBUG KERNEL_INIT] P[%d,%d,%d] initialises SCHED array\n"
     181               " - scheduler vbase = %x\n"
     182               " - tasks           = %d\n",
     183               x, y, p, (unsigned int)psched, tasks );
    127184#endif
    128185
     
    148205
    149206#if GIET_DEBUG_INIT
    150 _printf("\n[GIET DEBUG INIT] Processor[%d,%d,%d] contributes to PTABS arrays\n"
     207_nolock_printf("\n[DEBUG KERNEL_INIT] P[%d,%d,%d] initialises PTABS arrays\n"
    151208        " - ptabs_vaddr[%d] = %x / ptpr_paddr[%d] = %l\n",
    152209        x, y, p, 
     
    167224
    168225#if GIET_DEBUG_INIT
    169 _printf("\n[GIET DEBUG INIT] Processor[%d,%d,%d] updates context for task %d\n"
    170         " - ctx_epc   = %x\n"
    171         " - ctx_ra    = %x\n",
    172         x, y, p, ltid,
    173         _get_task_slot( x, y, p, ltid, CTX_EPC_ID ),
    174         _get_task_slot( x, y, p, ltid, CTX_RA_ID ) );
     226_nolock_printf("\n[DEBUG KERNEL_INIT] P[%d,%d,%d] updates context for task %d\n"
     227               " - ctx_epc   = %x\n"
     228               " - ctx_ra    = %x\n",
     229               x, y, p, ltid,
     230               _get_task_slot( x, y, p, ltid, CTX_EPC_ID ),
     231               _get_task_slot( x, y, p, ltid, CTX_RA_ID ) );
    175232#endif
    176233
     
    202259
    203260#if GIET_DEBUG_INIT
    204 _printf("\n[GIET DEBUG INIT] Processor[%d,%d,%d] sets XCU masks\n"
    205         " - XCU HWI_MASK = %x\n"
    206         " - XCU WTI_MASK = %x\n"
    207         " - XCU PTI_MASK = %x\n",
    208         x, y, p, hwi_mask, wti_mask, pti_mask );
     261_nolock_printf("\n[DEBUG KERNEL_INIT] P[%d,%d,%d] sets XCU masks\n"
     262               " - XCU HWI_MASK = %x\n"
     263               " - XCU WTI_MASK = %x\n"
     264               " - XCU PTI_MASK = %x\n",
     265               x, y, p, hwi_mask, wti_mask, pti_mask );
    209266#endif
    210267
     
    221278        if (isr_switch_index == 0xFFFFFFFF)
    222279        {
    223             _printf("\n[GIET ERROR] ISR_TICK not found for processor[%d,%d,%d]\n",
    224                     x, y, p );
     280            _nolock_printf("\n[GIET ERROR] ISR_TICK not found for processor[%d,%d,%d]\n",
     281                           x, y, p );
    225282            _exit();
    226283        }
     
    232289
    233290#if GIET_DEBUG_INIT
    234 _printf("\n[GIET DEBUG INIT] Processor[%d,%d,%d] starts TICK timer\n",
    235         x, y, p );
     291_nolock_printf("\n[DEBUG KERNEL_INIT] P[%d,%d,%d] starts TICK timer\n",
     292               x, y, p );
    236293#endif
    237294
     
    249306
    250307#if GIET_DEBUG_INIT
    251 _printf("\n[GIET DEBUG INIT] Processor[%d,%d,%d] initializes IDLE task\n"
    252         " - stack_base = %x\n"
    253         " - stack_size = 0x1000\n",
    254         x, y, p, pstack - 0x1000 );
     308_nolock_printf("\n[DEBUG KERNEL_INIT] P[%d,%d,%d] initializes IDLE task\n"
     309               " - stack_base = %x\n"
     310               " - stack_size = 0x1000\n",
     311               x, y, p, pstack - 0x1000 );
    255312#endif
    256313
     
    265322        ltid = IDLE_TASK_INDEX;
    266323
    267         _printf("\n[GIET WARNING] No task allocated to processor[%d,%d,%d]\n",
    268                 x, y, p );
     324        _nolock_printf("\n[GIET WARNING] No task allocated to processor[%d,%d,%d]\n",
     325                       x, y, p );
    269326    }
    270327    else
     
    279336
    280337#if GIET_DEBUG_INIT
    281 _printf("\n[GIET DEBUG INIT] Processor[%d,%d,%d] reach barrier at cycle %d\n",
    282         x, y, p, _get_proctime() );
     338_nolock_printf("\n[DEBUG KERNEL_INIT] P[%d,%d,%d] reach barrier at cycle %d\n",
     339               x, y, p, _get_proctime() );
    283340#endif
    284341
     
    290347
    291348#if GIET_DEBUG_INIT
    292 _printf("\n[GIET DEBUG INIT] Processor[%d,%d,%d] initializes registers at cycle %d\n"
     349_printf("\n[DEBUG KERNEL_INIT] P[%d,%d,%d] initializes registers at cycle %d\n"
    293350        " - sp   = %x\n"
    294351        " - sr   = %x\n"
Note: See TracChangeset for help on using the changeset viewer.