Changeset 244 for soft


Ignore:
Timestamp:
Jun 6, 2013, 5:39:18 PM (11 years ago)
Author:
brejon
Message:
  • Update malloc (remote free)
  • bugfix in spin_lock (bad register used in asm inline)
  • memo/Makefile clean rule : added "-f" option to rm command
  • main Makefile :
    • added spin_lock.o in dhrystone object files
    • added rules to compile spin_lock
Location:
soft/giet_vm
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/Makefile

    r241 r244  
    4343                 build/libs/utils.o \
    4444                 build/libs/string.o \
     45                 build/libs/spin_lock.o \
    4546                 build/libs/malloc.o
    4647
     
    151152        $(CC) $(CFLAGS) $(INCLUDE) -c -o $@ $<
    152153
     154build/libs/spin_lock.o: libs/spin_lock.c libs/spin_lock.h
     155        $(CC) $(CFLAGS) $(INCLUDE) -c -o $@ $<
     156
    153157### clean
    154158clean:
  • soft/giet_vm/libs/malloc.c

    r239 r244  
    66heap_ll * _heap_head[NB_TASKS_MAX];
    77
    8 unsigned int _heap_base[NB_TASKS_MAX];
    9 unsigned int _heap_length[NB_TASKS_MAX];
     8heap_ll * _remote_free_list[NB_TASKS_MAX] = { 0 };
     9giet_lock_t lock_rf_list[NB_TASKS_MAX] = { {"toto",0} };
     10
     11unsigned int _heap_base[NB_TASKS_MAX] = { -1 };
     12unsigned int _heap_length[NB_TASKS_MAX] = { -1 };
    1013
    1114int _first_malloc[NB_TASKS_MAX] = { 0 };
     
    1518
    1619#elif MALLOC_SELECTED == 2
    17     heap_ll * _prev_next_last_allocted[NB_TASKS_MAX] = { 0 };
     20heap_ll * _prev_next_last_allocted[NB_TASKS_MAX] = { 0 };
    1821#else
    19     #define MAX_SIZE_POW2_TAB 28
    20     #define GET_TAB_INDEX(size) (size == 0x00000008) ? 0 :\
    21                             (size <= 0x00000010) ? 1 :\
    22                             (size <= 0x00000020) ? 2 :\
    23                             (size <= 0x00000040) ? 3 :\
    24                             (size <= 0x00000080) ? 4 :\
    25                             (size <= 0x00000100) ? 5 :\
    26                             (size <= 0x00000200) ? 6 :\
    27                             (size <= 0x00000400) ? 7 :\
    28                             (size <= 0x00000800) ? 8 :\
    29                             (size <= 0x00001000) ? 9 :\
    30                             (size <= 0x00002000) ? 10 :\
    31                             (size <= 0x00004000) ? 11 :\
    32                             (size <= 0x00008000) ? 12 :\
    33                             (size <= 0x00010000) ? 13 :\
    34                             (size <= 0x00020000) ? 14 :\
    35                             (size <= 0x00040000) ? 15 :\
    36                             (size <= 0x00080000) ? 16 :\
    37                             (size <= 0x00100000) ? 17 :\
    38                             (size <= 0x00200000) ? 18 :\
    39                             (size <= 0x00400000) ? 19 :\
    40                             (size <= 0x00800000) ? 20 :\
    41                             (size <= 0x01000000) ? 21 :\
    42                             (size <= 0x02000000) ? 22 :\
    43                             (size <= 0x04000000) ? 23 :\
    44                             (size <= 0x08000000) ? 24 :\
    45                             (size <= 0x10000000) ? 25 :\
    46                             (size <= 0x20000000) ? 26 :\
    47                                                    27
    48 
    49     heap_ll * _pow2tab[NB_TASKS_MAX][MAX_SIZE_POW2_TAB] = {{ 0 }};
     22#define MAX_SIZE_POW2_TAB 28
     23#define GET_TAB_INDEX(size)                (size == 0x00000008) ? 0 :\
     24                                            (size <= 0x00000010) ? 1 :\
     25                                            (size <= 0x00000020) ? 2 :\
     26                                            (size <= 0x00000040) ? 3 :\
     27                                            (size <= 0x00000080) ? 4 :\
     28                                            (size <= 0x00000100) ? 5 :\
     29                                            (size <= 0x00000200) ? 6 :\
     30                                            (size <= 0x00000400) ? 7 :\
     31                                            (size <= 0x00000800) ? 8 :\
     32                                            (size <= 0x00001000) ? 9 :\
     33                                            (size <= 0x00002000) ? 10 :\
     34                                            (size <= 0x00004000) ? 11 :\
     35                                            (size <= 0x00008000) ? 12 :\
     36                                            (size <= 0x00010000) ? 13 :\
     37                                            (size <= 0x00020000) ? 14 :\
     38                                            (size <= 0x00040000) ? 15 :\
     39                                            (size <= 0x00080000) ? 16 :\
     40                                            (size <= 0x00100000) ? 17 :\
     41                                            (size <= 0x00200000) ? 18 :\
     42                                            (size <= 0x00400000) ? 19 :\
     43                                            (size <= 0x00800000) ? 20 :\
     44                                            (size <= 0x01000000) ? 21 :\
     45                                            (size <= 0x02000000) ? 22 :\
     46                                            (size <= 0x04000000) ? 23 :\
     47                                            (size <= 0x08000000) ? 24 :\
     48                                            (size <= 0x10000000) ? 25 :\
     49                                            (size <= 0x20000000) ? 26 :\
     50                                                                   27
     51
     52heap_ll * _pow2tab[NB_TASKS_MAX][MAX_SIZE_POW2_TAB] = {{ 0 }};
    5053#endif
    5154
    52 /* Todo: meilleure gestion des printf
    53 //#if DEBUG_MALLOC == 1
    54 unsigned int debug_level = 2;
    55 #elif DEBUG_MALLOC == 0
    56 
    57 #define giet_printf(level, ...)                 \
    58 ({                                           \
    59 if (debug_level < level) {              \
    60 giet_tty_printf(__VA_ARGS__);       \
    61 }                                       \
    62 })
    63 */
     55
     56#if DEBUG_MALLOC == 1             
     57#define giet_printf(...)                \
     58    ({                                      \
     59     giet_tty_printf(__VA_ARGS__);       \
     60     })                                 
     61#else
     62#define giet_printf(...) ({   })
     63#endif
     64
    6465
    6566
    6667#if MALLOC_SELECTED == 1
    67 
     68/*########################################################################*/
     69/**************************************************************************/
     70/**********                     WORST-FIT                       ***********/
     71/**************************************************************************/
     72/*########################################################################*/
    6873heap_ll *get_prev_fit_chunk(unsigned int size) {
    6974    int task_id = giet_global_task_id();
     75    int check_remote_free_list = 0;
     76after_remote_list_check :
    7077    if (_heap_head[task_id] == 0x0) {
     78        if(check_remote_free_list == 0)
     79        {
     80            heap_ll * poped_block;
     81            heap_ll * head_of_rf;
     82            check_remote_free_list = 1;
     83
     84            head_of_rf = pop_ptr();
     85
     86            while((poped_block = pop_remote_free_list(&head_of_rf)) != 0x0)
     87            {
     88                update_chunk_list((unsigned int)poped_block, poped_block->chunk_length);
     89            }
     90            goto after_remote_list_check;
     91        }
    7192        return ((heap_ll *) 0x01);
    7293    }
     
    87108        ptr_to_chunk_list = ptr_to_chunk_list->next;
    88109    }
    89     if (found == 1) {
     110    if (found == 1)
     111    {
    90112        return prev_tmp; // case when prev_tmp == 0x0 is handled in the calling function
    91113    }
    92     else {
     114    else
     115    {
     116        if(check_remote_free_list == 0)
     117        {
     118            heap_ll * poped_block;
     119            heap_ll * head_of_rf;
     120            check_remote_free_list = 1;
     121
     122            head_of_rf = pop_ptr();
     123
     124            while((poped_block = pop_remote_free_list(&head_of_rf)) != 0x0)
     125            {
     126                update_chunk_list((unsigned int)poped_block, poped_block->chunk_length);
     127            }
     128            goto after_remote_list_check;
     129        }
    93130        return (heap_ll *) 0x1;
    94131    }
     
    100137    int task_id = giet_global_task_id();
    101138
    102 #if DEBUG_MALLOC == 1
    103     giet_tty_printf("############ MALLOC ############\n\n");
    104 #endif
     139    giet_printf("############ MALLOC ############\n\n");
    105140    if (size == 0) {
    106 #if DEBUG_MALLOC == 1
    107         giet_tty_printf(" SIZE = 0 \n");
    108 #endif
     141
     142        giet_printf(" SIZE = 0 \n");
    109143        return 0x0;
    110144    }
     
    115149
    116150        if (_heap_length[task_id] == 0) {
    117             giet_tty_printf("*** Error: Malloc called in task %d while no heap was defined.\n", task_id);
     151            giet_printf("*** Error: Malloc called in task %d and no heap was defined.\n", task_id);
    118152            return 0x0;
    119153        }
     
    133167
    134168
    135 #if DEBUG_MALLOC == 1
    136     giet_tty_printf("Looking for size : %d\n", size_align + 4);
    137 #endif
     169
     170    giet_printf("Looking for size : %d\n", size_align + 4);
    138171    /****** Get prev victim from the chunks list ******/
    139172    heap_ll *victim;
     
    171204        heap_ll * tmp_chunk = victim;
    172205        victim = (heap_ll *) (((unsigned int) victim) + (size_align + 4));
    173 #if DEBUG_MALLOC == 1
    174         giet_tty_printf("NEXT CHUNK is at @ : 0x%x + 0x%x = 0x%x\n",
     206
     207        giet_printf("NEXT CHUNK is at @ : 0x%x + 0x%x = 0x%x\n",
    175208                (unsigned int) tmp_chunk,
    176209                (unsigned int) ((size_align + 4) / 4),
    177210                (unsigned int) victim);
    178 #endif
    179211
    180212        victim->chunk_length = tmp_chunk->chunk_length - (size_align + 4);
     
    190222    /****** Write Overhead ******/
    191223    *((unsigned int *) victim_vbase) = size_align;      // writing overhead on the first word
    192 #if DEBUG_MALLOC == 1
    193     giet_tty_printf("BLOCK SUCCESSFULLY ALLOCATED at @ 0x%x user will write at @ 0x%x\n\n"\
     224
     225    giet_printf("BLOCK SUCCESSFULLY ALLOCATED at @ 0x%x user will write at @ 0x%x\n\n"\
    194226            ,(unsigned int)(victim_vbase),(unsigned int) (victim_vbase + 4));
    195 #endif
    196227    return (unsigned int *) (victim_vbase + 4);
    197228}
     
    210241        ((heap_ll *) block_base)->next = 0x0;
    211242        _heap_head[task_id] = ((heap_ll *) block_base);
    212 #if DEBUG_MALLOC == 1
    213         giet_tty_printf("****** NEW BLOCK ******\n"
     243
     244        giet_printf("****** NEW BLOCK ******\n"
    214245                "@ : %x\n"
    215246                "Length : %d o\n"
     
    217248                block_base,
    218249                (unsigned int) (((heap_ll *) block_base)->chunk_length));
    219 #endif
    220250        return;
    221251    }
     
    232262        /*  [.....|ptr|block|.....] */
    233263        if ((unsigned int) (ptr_to_chunk_list) + chunk_length == block_base) {
    234 #if DEBUG_MALLOC == 1
    235             giet_tty_printf("****** BLOCK MERGED ******\n"
     264
     265            giet_printf("****** BLOCK MERGED ******\n"
    236266                    "CHUNK : %x of size %d o\n"
    237267                    "merged with \n"
     
    241271                    ptr_to_chunk_list->chunk_length, block_base,
    242272                    block_length);
    243 #endif
    244273
    245274            /* update the size */
     
    264293            block_base = (unsigned int) ptr_to_chunk_list;
    265294            block_length = ptr_to_chunk_list->chunk_length;
    266 #if DEBUG_MALLOC == 1
    267             giet_tty_printf("****** NEW BLOCK ******\n"
     295
     296            giet_printf("****** NEW BLOCK ******\n"
    268297                    "@ : %x\n"
    269298                    "Length : %d o\n"
     
    271300                    (unsigned int) ptr_to_chunk_list,
    272301                    (unsigned int) (ptr_to_chunk_list->chunk_length));
    273 #endif
    274302            prev_block_base = prev;
    275303            prev = ptr_to_chunk_list;
     
    281309        /*  [......|block|ptr|.....] */
    282310        if (block_base + block_length == (unsigned int) ptr_to_chunk_list) {
    283 #if DEBUG_MALLOC == 1
    284             giet_tty_printf("****** BLOCK MERGED ******\n"
     311
     312            giet_printf("****** BLOCK MERGED ******\n"
    285313                    "BLOCK : %x of size %d o\n"
    286314                    "merged with \n"
     
    290318                    (unsigned int) ptr_to_chunk_list,
    291319                    ptr_to_chunk_list->chunk_length);
    292 #endif
    293320
    294321            /* update the size */
     
    316343            ptr_to_chunk_list = ((heap_ll *) block_base);
    317344            block_length = ptr_to_chunk_list->chunk_length;
    318 #if DEBUG_MALLOC == 1
    319             giet_tty_printf("****** NEW BLOCK ******\n"
     345
     346            giet_printf("****** NEW BLOCK ******\n"
    320347                    "@ : %x\n"
    321348                    "Length : %d o\n"
     
    323350                    (unsigned int) ptr_to_chunk_list,
    324351                    (unsigned int) (ptr_to_chunk_list->chunk_length));
    325 #endif
    326352            prev_block_base = prev;
    327353            block_merged = 1;
     
    339365    ((heap_ll *) block_base)->next = 0x0;
    340366    prev->next = ((heap_ll *) block_base);
    341 #if DEBUG_MALLOC == 1
    342     giet_tty_printf("****** NEW BLOCK ******\n"
     367
     368    giet_printf("****** NEW BLOCK ******\n"
    343369            "@ : %x\n"
    344370            "Length : %d o\n"
     
    346372            block_base,
    347373            (unsigned int) (((heap_ll *) block_base)->chunk_length));
    348 #endif
    349374    return;
    350375
     
    352377
    353378
    354 static void print_all_heap(void) {
    355     int task_id = giet_global_task_id();
    356     heap_ll * ptr_to_chunk_list = _heap_head[task_id];
    357     giet_tty_printf("################### PRINT ALL HEAP ######################\n");
    358     while (ptr_to_chunk_list != 0x0) {
    359         giet_tty_printf("CHUNK at @ : %x\n"
    360                 "OVERHEAD : %d\n"
    361                 "NEXT : %x\n\n",
    362                 (unsigned int) ptr_to_chunk_list,
    363                 ptr_to_chunk_list->chunk_length,
    364                 (unsigned int) ptr_to_chunk_list->next);
    365         ptr_to_chunk_list = ptr_to_chunk_list->next;
    366     }
    367     giet_tty_printf("#########################################################\n");
    368 }
    369 
    370 
    371 /* Warning: the division doesn't seem to work well in the giet/soclib ? */
    372 static void frag(int turn) {
    373     int task_id = giet_global_task_id();
    374     int nb_blocks = 0;
    375     int size = 0;
    376     heap_ll * ptr_to_chunk;
    377     ptr_to_chunk = _heap_head[task_id];
    378     while(ptr_to_chunk != 0x0) {
    379         size += ptr_to_chunk->chunk_length;
    380         nb_blocks += 1;
    381         ptr_to_chunk = ptr_to_chunk->next;
    382     }
    383     if (size != 0) {
    384         giet_tty_printf("%.3f\t%d\n", size / ((double) nb_blocks), turn);
    385     }
    386 }
    387 
    388 // End WORST_FIT
     379
     380/*########################################################################*/
     381/**************************************************************************/
     382/**********                 END WORST-FIT                       ***********/
     383/**************************************************************************/
     384/*########################################################################*/
    389385#elif MALLOC_SELECTED == 2 // Next Fit
     386/*########################################################################*/
     387/**************************************************************************/
     388/**********                   NEXT-FIT                          ***********/
     389/**************************************************************************/
     390/*########################################################################*/
    390391
    391392heap_ll * get_prev_fit_chunk(unsigned int size) {
    392393    int task_id = giet_global_task_id();
     394    int check_remote_free_list = 0;
     395after_remote_list_check_n : //n for next_fit
    393396    if (_heap_head[task_id] == 0x0) {
     397        if(check_remote_free_list == 0)
     398        {
     399            heap_ll * poped_block;
     400            heap_ll * head_of_rf;
     401            check_remote_free_list = 1;
     402
     403            head_of_rf = pop_ptr();
     404
     405            while((poped_block = pop_remote_free_list(&head_of_rf)) != 0x0)
     406            {
     407                update_chunk_list((unsigned int)poped_block, poped_block->chunk_length);
     408            }
     409            goto after_remote_list_check_n;
     410        }
    394411        return ((heap_ll *) 0x1);
    395412    }
     
    421438        ptr_to_chunk_list = ptr_to_chunk_list->next;
    422439    } while (ptr_to_chunk_list != tmp_turn);
     440    if(check_remote_free_list == 0)
     441    {
     442        heap_ll * poped_block;
     443        heap_ll * head_of_rf;
     444        check_remote_free_list = 1;
     445
     446        head_of_rf = pop_ptr();
     447
     448        while((poped_block = pop_remote_free_list(&head_of_rf)) != 0x0)
     449        {
     450            update_chunk_list((unsigned int)poped_block, poped_block->chunk_length);
     451        }
     452        goto after_remote_list_check_n;
     453    }
    423454
    424455    return (heap_ll *) 0x1;
     
    429460
    430461    int task_id = giet_global_task_id();
    431 #if DEBUG_MALLOC == 1
    432     giet_tty_giet_tty_printf("############ MALLOC ############\n\n");
    433 #endif
     462
     463    giet_printf("############ MALLOC ############\n\n");
    434464    if (size == 0) {
    435 #if DEBUG_MALLOC == 1
    436         giet_tty_giet_tty_printf(" SIZE = 0 \n");
    437 #endif
     465
     466        giet_printf(" SIZE = 0 \n");
    438467        return 0x0;
    439468    }
     
    444473
    445474        if (_heap_length[task_id] == 0) {
    446             giet_tty_printf("*** Error: Malloc called in task %d while no heap was defined.\n", task_id);
     475            giet_printf("*** Error: Malloc called in task %d while no heap was defined.\n", task_id);
    447476            return 0x0;
    448477        }
     
    464493
    465494
    466 #if DEBUG_MALLOC == 1
    467     giet_tty_giet_tty_printf("Looking for size : %d\n", size_align + 4);
    468 #endif
     495
     496    giet_printf("Looking for size : %d\n", size_align + 4);
    469497    /****** Get prev victim from the chunks list ******/
    470498    heap_ll *victim;
     
    528556        heap_ll * tmp_chunk = victim;
    529557        victim = (heap_ll *) (((unsigned int) victim) + (size_align + 4));
    530 #if DEBUG_MALLOC == 1
    531         giet_tty_giet_tty_printf("NEXT CHUNK is at @ : 0x%x + 0x%x = 0x%x\n",
     558
     559        giet_printf("NEXT CHUNK is at @ : 0x%x + 0x%x = 0x%x\n",
    532560                (unsigned int) tmp_chunk,
    533561                (unsigned int) ((size_align + 4) / 4),
    534562                (unsigned int) victim);
    535 #endif
    536563
    537564        victim->chunk_length = tmp_chunk->chunk_length - (size_align + 4);
     
    559586    /****** Write Overhead ******/
    560587    *((unsigned int *) victim_vbase) = size_align;      // writing overhead on the first word
    561 #if DEBUG_MALLOC == 1
    562     giet_tty_giet_tty_printf("BLOCK SUCCESSFULLY ALLOCATED at @ 0x%x user will write at @ 0x%x\n\n"\
     588
     589    giet_printf("BLOCK SUCCESSFULLY ALLOCATED at @ 0x%x user will write at @ 0x%x\n\n"\
    563590            ,(unsigned int)(victim_vbase),(unsigned int )(victim_vbase + 4));
    564 #endif
    565591    return (unsigned int *) (victim_vbase + 4);
    566592}
     
    579605        ((heap_ll *) block_base)->next = 0x0;
    580606        _heap_head[task_id] = ((heap_ll *) block_base);
    581 #if DEBUG_MALLOC == 1
    582         giet_tty_giet_tty_printf("****** NEW BLOCK ******\n"
     607
     608        giet_printf("****** NEW BLOCK ******\n"
    583609                "@ : %x\n"
    584610                "Length : %d o\n"
     
    586612                block_base,
    587613                (unsigned int) (((heap_ll *) block_base)->chunk_length));
    588 #endif
    589614        return;
    590615    }
     
    600625        /*  [.....|ptr|block|.....] */
    601626        if ((unsigned int) (ptr_to_chunk_list) + chunk_length == block_base) {
    602 #if DEBUG_MALLOC == 1
    603             giet_tty_giet_tty_printf("****** BLOCK MERGED ******\n"
     627
     628            giet_printf("****** BLOCK MERGED ******\n"
    604629                    "CHUNK : %x of size %d o\n"
    605630                    "merged with \n"
     
    609634                    ptr_to_chunk_list->chunk_length, block_base,
    610635                    block_length);
    611 #endif
    612636            if (_prev_next_last_allocted[task_id] == ptr_to_chunk_list) {
    613637                _prev_next_last_allocted[task_id] = ptr_to_chunk_list->next;
     
    636660            block_base = (unsigned int) ptr_to_chunk_list;
    637661            block_length = ptr_to_chunk_list->chunk_length;
    638 #if DEBUG_MALLOC == 1
    639             giet_tty_giet_tty_printf("****** NEW BLOCK ******\n"
     662
     663            giet_printf("****** NEW BLOCK ******\n"
    640664                    "@ : %x\n"
    641665                    "Length : %d o\n"
     
    643667                    (unsigned int) ptr_to_chunk_list,
    644668                    (unsigned int) (ptr_to_chunk_list->chunk_length));
    645 #endif
    646669            prev_block_base = prev;
    647670            prev = ptr_to_chunk_list;
     
    653676        /*  [......|block|ptr|.....] */
    654677        if (block_base + block_length == (unsigned int) ptr_to_chunk_list) {
    655 #if DEBUG_MALLOC == 1
    656             giet_tty_giet_tty_printf("****** BLOCK MERGED ******\n"
     678
     679            giet_printf("****** BLOCK MERGED ******\n"
    657680                    "BLOCK : %x of size %d o\n"
    658681                    "merged with \n"
     
    662685                    (unsigned int) ptr_to_chunk_list,
    663686                    ptr_to_chunk_list->chunk_length);
    664 #endif
    665687
    666688            if (_prev_next_last_allocted[task_id] == ptr_to_chunk_list) {
     
    698720            ptr_to_chunk_list = ((heap_ll *) block_base);
    699721            block_length = ptr_to_chunk_list->chunk_length;
    700 #if DEBUG_MALLOC == 1
    701             giet_tty_giet_tty_printf("****** NEW BLOCK ******\n"
     722
     723            giet_printf("****** NEW BLOCK ******\n"
    702724                    "@ : %x\n"
    703725                    "Length : %d o\n"
     
    705727                    (unsigned int) ptr_to_chunk_list,
    706728                    (unsigned int) (ptr_to_chunk_list->chunk_length));
    707 #endif
    708729            prev_block_base = prev;
    709730            block_merged = 1;
     
    725746    prev->next = ((heap_ll *) block_base);
    726747
    727 #if DEBUG_MALLOC == 1
    728     giet_tty_giet_tty_printf("****** NEW BLOCK ******\n"
     748
     749    giet_printf("****** NEW BLOCK ******\n"
    729750            "@ : %x\n"
    730751            "Length : %d o\n"
     
    732753            block_base,
    733754            (unsigned int) (((heap_ll *) block_base)->chunk_length));
    734 #endif
    735755    return;
    736756}
    737757
    738758
    739 void print_all_heap(void) {
    740     int task_id = giet_global_task_id();
    741     heap_ll * ptr_to_chunk_list = _heap_head[task_id];
    742     giet_tty_printf("################### PRINT ALL HEAP ######################\n");
    743     while (ptr_to_chunk_list != 0x0) {
    744         giet_tty_printf("CHUNK at @ : %x\n"
    745                 "OVERHEAD : %d\n"
    746                 "NEXT : %x\n\n",
    747                 (unsigned int) ptr_to_chunk_list,
    748                 ptr_to_chunk_list->chunk_length,
    749                 (unsigned int) ptr_to_chunk_list->next);
    750         ptr_to_chunk_list = ptr_to_chunk_list->next;
    751     }
    752     giet_tty_printf("#########################################################\n");
    753 }
    754 
    755 
    756 void frag(int turn) {
    757     int task_id = giet_global_task_id();
    758     int nb_blocks = 0;
    759     int size = 0;
    760     heap_ll * ptr_to_chunk;
    761     ptr_to_chunk = _heap_head[task_id];
    762     while (ptr_to_chunk != 0x0) {
    763         size += ptr_to_chunk->chunk_length;
    764         nb_blocks += 1;
    765         ptr_to_chunk = ptr_to_chunk->next;
    766     }
    767     //   assert(size != 0 || nb_blocks == 0);
    768     if (size != 0) {
    769         giet_tty_printf("%.3f\t%d\n", size / ((double) nb_blocks), turn);
    770     }
    771 }
    772 
    773 
    774 
     759
     760/*########################################################################*/
     761/**************************************************************************/
     762/**********                 END NEXT-FIT                        ***********/
     763/**************************************************************************/
     764/*########################################################################*/
    775765
    776766#else // Default case : New Fit
     767
     768/*########################################################################*/
     769/**************************************************************************/
     770/**********                    CLOSE-FIT                        ***********/
     771/**************************************************************************/
     772/*########################################################################*/
    777773
    778774
    779775int get_prev_fit_chunk(unsigned int size) {
    780776    int task_id = giet_global_task_id();
    781     int index = GET_TAB_INDEX(size);
     777    int check_remote_free_list = 0;
     778    int index;
     779after_remote_list_check_c : //c for close fit
     780    index = GET_TAB_INDEX(size);
    782781    while (index != MAX_SIZE_POW2_TAB) {
    783782        if (_pow2tab[task_id][index] != 0x0) {
     
    786785        index++;
    787786    }
     787
     788    if(check_remote_free_list == 0)
     789    {
     790        heap_ll * poped_block;
     791        heap_ll * head_of_rf;
     792        check_remote_free_list = 1;
     793
     794        head_of_rf = pop_ptr();
     795
     796        while((poped_block = pop_remote_free_list(&head_of_rf)) != 0x0)
     797        {
     798            update_chunk_list((unsigned int)poped_block, poped_block->chunk_length);
     799        }
     800        goto after_remote_list_check_c;
     801    }
     802
    788803    return -1;
    789804}
     
    793808void * malloc(unsigned int size) {
    794809    int task_id = giet_global_task_id();
    795 #if DEBUG_MALLOC == 1
    796     giet_tty_printf("############ MALLOC ############\n\n");
    797 #endif
     810
     811    giet_printf("############ MALLOC ############\n\n");
    798812    if(size == 0) {
    799 #if DEBUG_MALLOC == 1
    800         giet_tty_printf(" SIZE = 0 \n");
    801 #endif
     813
     814        giet_printf(" SIZE = 0 \n");
    802815        return 0x0;
    803816    }
    804817    if (size > 0x20000000) {
    805 #if DEBUG_MALLOC == 1
    806         giet_tty_printf("ERROR max size = %d\n",0x20000000);
    807 #endif
     818
     819        giet_printf("ERROR max size = %d\n",0x20000000);
    808820        return 0x0;
    809821    }
     
    817829
    818830        if (_heap_length[task_id] == 0) {
    819             giet_tty_printf("*** Error: Malloc called in task %d while no heap was defined.\n", task_id);
     831            giet_printf("*** Error: Malloc called in task %d while no heap was defined.\n", task_id);
    820832            return 0x0;
    821833        }
     
    838850    }
    839851
    840 #if DEBUG_MALLOC == 1
    841     giet_tty_printf("Looking for size : %d %d = %d\n", size_align, 4,size_align+4);
    842 #endif
     852
     853    giet_printf("Looking for size : %d %d = %d\n", size_align, 4,size_align+4);
    843854
    844855
     
    871882        _pow2tab[task_id][new_index] = new_chunk;
    872883
    873 #if DEBUG_MALLOC == 1
    874         giet_tty_printf("NEXT CHUNK is at @ : 0x%x + 0x%x = 0x%x : @ of size over the block : %x\n",
     884
     885        giet_printf("NEXT CHUNK is at @ : 0x%x + 0x%x = 0x%x : @ of size over the block : %x\n",
    875886                (unsigned int) victim,
    876887                (unsigned int) ((size_align + 4) / 4),
    877888                (unsigned int) new_chunk,
    878889                ((unsigned int) new_chunk + new_chunk->chunk_length) - 4);
    879 #endif
    880890    }
    881891
    882892    /****** Write Overhead ******/
    883893    *((unsigned int *) victim_vbase) = size_align;      // writing overhead on the first word
    884 #if DEBUG_MALLOC == 1
    885     giet_tty_printf("BLOCK SUCCESSFULLY ALLOCATED at @ 0x%x user will write at @ 0x%x\n\n",\
     894
     895    giet_printf("BLOCK SUCCESSFULLY ALLOCATED at @ 0x%x user will write at @ 0x%x\n\n",\
    886896            (unsigned int)(victim_vbase), (unsigned int ) (victim_vbase + 4));
    887 #endif
    888897
    889898    return (unsigned int *) (victim_vbase + 4);
     
    910919    if (block_base - 4 >= _heap_base[task_id]) {
    911920
    912 #if DEBUG_MALLOC == 1
    913         giet_tty_printf("############# LEFT MERGE #############\n\n");
    914 #endif
     921
     922        giet_printf("############# LEFT MERGE #############\n\n");
    915923        left_block_size = *((unsigned int *) (block_base - 4));
    916924        left_block_index = GET_TAB_INDEX(left_block_size);
     
    920928
    921929    if ((block_base + block_length) <= (_heap_base[task_id] + _heap_length[task_id]) - 8) {
    922 #if DEBUG_MALLOC == 1
    923         giet_tty_printf("############# RIGHT MERGE #############\n\n");
    924 #endif
     930
     931        giet_printf("############# RIGHT MERGE #############\n\n");
    925932        right_block_size = ((heap_ll *)(block_base + block_length))->chunk_length;
    926933        right_block_index = GET_TAB_INDEX(right_block_size);
     
    929936    }
    930937
    931 #if DEBUG_MALLOC == 1
    932     giet_tty_printf("############# END PREP MERGE #############\n\n");
    933 #endif
     938
     939    giet_printf("############# END PREP MERGE #############\n\n");
    934940
    935941    heap_ll * ptr_to_chunk = 0x0;
     
    10121018    _pow2tab[task_id][new_index] = new_addr;
    10131019
     1020    giet_printf("########################  UPDT SUCCESS ######################\n");
     1021
    10141022    return;
    10151023}
    10161024
    10171025
    1018 static void print_all_heap(void) {
     1026
     1027
     1028/*########################################################################*/
     1029/**************************************************************************/
     1030/**********                 END CLOSE-FIT                       ***********/
     1031/**************************************************************************/
     1032/*########################################################################*/
     1033
     1034#endif // New Fit
     1035
     1036heap_ll * pop_remote_free_list(heap_ll ** head)
     1037{
     1038
     1039    heap_ll * poped_block;
     1040
     1041    if (*head == 0x0)
     1042    {
     1043        giet_printf(" no block to pop\n");
     1044        return 0x0;
     1045    }
     1046    else
     1047    {
     1048        poped_block = *head;
     1049        *head = (*head)->next;
     1050
     1051        giet_printf(" : @%x, size : %x\n", poped_block, poped_block->chunk_length);
     1052    }
     1053
     1054    return poped_block;
     1055}
     1056
     1057heap_ll * pop_ptr(void)
     1058{
    10191059    int task_id = giet_global_task_id();
     1060    heap_ll * head_of_rf_list;
     1061    giet_printf(" -- POP lock acquire -- for %d : @ : %x\n", task_id, &lock_rf_list[task_id]);
     1062    lock_acquire(&lock_rf_list[task_id]);
     1063    giet_printf(" -- POP lock acquired --\n");
     1064
     1065    head_of_rf_list = _remote_free_list[task_id];
     1066    _remote_free_list[task_id] = 0x0;
     1067
     1068    lock_release(&lock_rf_list[task_id]);
     1069    return head_of_rf_list;
     1070
     1071}
     1072
     1073void insert_in_remote_free_list(unsigned int remote_owner_id, unsigned int block_base, unsigned int block_length)
     1074{
     1075
     1076    giet_printf("############### INSERT \n");
     1077    ((heap_ll *)block_base)->chunk_length = block_length;
     1078
     1079    giet_printf(" -- INSERT lock acquire -- for %d : @ : %x\n", remote_owner_id, &lock_rf_list[remote_owner_id]);
     1080    lock_acquire(&lock_rf_list[remote_owner_id]);
     1081
     1082    giet_printf(" -- INSERT lock acquired -- \n");
     1083
     1084    // insertion en début de liste
     1085    giet_printf("  in remote_owner %d ...\n", remote_owner_id);
     1086    if (_remote_free_list[remote_owner_id] == 0x0)
     1087    {
     1088        ((heap_ll *)block_base)->next = 0x0;
     1089    }
     1090    else
     1091    {
     1092        ((heap_ll *)block_base)->next = _remote_free_list[remote_owner_id];
     1093    }
     1094    _remote_free_list[remote_owner_id] = ((heap_ll *)block_base);
     1095
     1096    giet_printf("  : OK\n\n");
     1097    giet_printf(" new head : %x : of size : %x, with next : %x\n", _remote_free_list[remote_owner_id], _remote_free_list[remote_owner_id]->chunk_length, _remote_free_list[remote_owner_id]->next);
     1098
     1099    lock_release(&lock_rf_list[remote_owner_id]);
     1100
     1101    return;
     1102}
     1103
     1104void free(void * ptr) {
    10201105    int i = 0;
    1021     int nb_blocks = 0;
    1022     heap_ll * ptr_to_chunk_list;
    1023     giet_tty_printf("################### PRINT ALL HEAP ######################\n");
    1024     while (i != MAX_SIZE_POW2_TAB) {
    1025         ptr_to_chunk_list = _pow2tab[task_id][i];
    1026 
    1027         if (ptr_to_chunk_list != 0x0) {
    1028             giet_tty_printf("###################### %d ####################\n", i);
    1029         }
    1030         while (ptr_to_chunk_list != 0x0) {
    1031             giet_tty_printf("CHUNK at @ : %x\n"
    1032                     "OVERHEAD : %d\n"
    1033                     "NEXT : %x\n\n",
    1034                     (unsigned int) ptr_to_chunk_list,
    1035                     ptr_to_chunk_list->chunk_length,
    1036                     (unsigned int) ptr_to_chunk_list->next);
    1037             ptr_to_chunk_list = ptr_to_chunk_list->next;
    1038             nb_blocks++;
     1106    while (i != NB_TASKS_MAX)
     1107    {
     1108        if( _heap_base[i] == -1)
     1109        {
     1110            continue;
     1111        }
     1112        if ((unsigned int)ptr > _heap_base[i] && (unsigned int)ptr < _heap_base[i] + _heap_length[i])
     1113        {
     1114            break;
    10391115        }
    10401116        i++;
    10411117    }
    1042     giet_tty_printf("####################### ##%d## ##########################\n", nb_blocks);
    1043 }
    1044 
    1045 
    1046 static void frag(int turn) {
    1047     int task_id = giet_global_task_id();
    1048     int i = 0;
    1049     int nb_blocks = 0;
    1050     int size = 0;
    1051     heap_ll * ptr_to_chunk;
    1052     while (i != MAX_SIZE_POW2_TAB) {
    1053         ptr_to_chunk = _pow2tab[task_id][i];
    1054         while (ptr_to_chunk != 0x0) {
    1055             size += ptr_to_chunk->chunk_length;
    1056             nb_blocks += 1;
    1057             ptr_to_chunk = ptr_to_chunk->next;
    1058         }
    1059         i++;
    1060     }
    1061     if (size != 0) {
    1062         giet_tty_printf("%.3f\t%d\n",size / ((double) nb_blocks), turn);
    1063     }
    1064 }
    1065 
    1066 
    1067 
    1068 #endif // New Fit
    1069 
    1070 
    1071 void free(void * ptr) {
     1118
    10721119    int task_id = giet_global_task_id();
    10731120    unsigned int * to_free = ptr;
    1074     unsigned int heapB = _heap_base[task_id];
    1075     unsigned int heapL = _heap_length[task_id];
     1121    unsigned int heapB;
     1122    unsigned int heapL;
    10761123    unsigned int overhead;
    10771124    unsigned int block_base;
    10781125    unsigned int block_length;
    1079 
    1080 #if DEBUG_MALLOC == 1
    1081     giet_tty_printf("############# FREE  #############\n\n");
    1082 #endif
     1126    unsigned int remote_free_needed;
     1127    unsigned int remote_owner_id;
     1128    if (i == task_id)
     1129    {
     1130
     1131        giet_printf("############# FREE  #############\n\n");
     1132        remote_free_needed = 0;
     1133        remote_owner_id = -1;
     1134        heapB = _heap_base[task_id];
     1135        heapL = _heap_length[task_id];
     1136    }
     1137    else
     1138    {
     1139
     1140        giet_printf("############# REMOTE FREE  #############\n\n");
     1141        remote_free_needed = 1;
     1142        remote_owner_id = i;
     1143        heapB = _heap_base[remote_owner_id];
     1144        heapL = _heap_length[remote_owner_id];
     1145    }
     1146
     1147
    10831148    /****** CHECK PTR ******/
    10841149    if (to_free == 0x0) {
    1085 #if DEBUG_MALLOC == 1
    1086         giet_tty_printf("free == 0x0\n");
    1087 #endif
     1150
     1151        giet_printf("free == 0x0\n");
    10881152        return;
    10891153    }
    10901154    // check alignement of ptr
    10911155    if (((unsigned int) to_free) % 4 != 0) {
    1092 #if DEBUG_MALLOC == 1
    1093         giet_tty_printf("allignement of ptr  %x = %d\n", (unsigned int) to_free, (unsigned int) to_free % 4);
    1094 #endif
     1156
     1157        giet_printf("allignement of ptr  %x = %d\n", (unsigned int) to_free, (unsigned int) to_free % 4);
    10951158        return;
    10961159    }
    10971160    // check if the @ of ptr matches the range of the heap
    10981161    if (!((unsigned int) to_free >= heapB && (unsigned int) to_free < heapB + heapL)) {
    1099 #if DEBUG_MALLOC == 1
    1100         giet_tty_printf("check if it matches the range of the heap\n");
    1101 #endif
     1162
     1163        giet_printf("check if it matches the range of the heap\n");
    11021164        return;
    11031165    }
     
    11071169    // check alignement of overhead
    11081170    if (overhead % 4 != 0) {
    1109 #if DEBUG_MALLOC == 1
    1110         giet_tty_printf("check alignement of overhead\n");
    1111 #endif
     1171
     1172        giet_printf("check alignement of overhead\n");
    11121173        return;
    11131174    }
    11141175    // check if (overhead + to_free) matches the range of the heap
    11151176    if ((((unsigned int) (to_free) + overhead) - 4) > heapB + heapL) {
    1116 #if DEBUG_MALLOC == 1
    1117         giet_tty_printf ("check if (overhead + to_free) matches the range of the heap\n");
    1118 #endif
     1177
     1178        giet_printf ("check if (overhead + to_free) matches the range of the heap\n");
    11191179        return;
    11201180    }
     
    11231183    block_length = overhead + 4;
    11241184
    1125 #if DEBUG_MALLOC == 1
    1126     giet_tty_printf("############# UPDATE CL :  FREE %x of size %d #############\n\n",block_base, block_length);
    1127 #endif
    1128     update_chunk_list(block_base, block_length);
    1129 
    1130 #if DEBUG_MALLOC == 1
    1131     giet_tty_printf("BLOCK SUCCESSFULLY FREED\n\n");
    1132 #endif
     1185    if (remote_free_needed == 0)
     1186    {
     1187
     1188        giet_printf("############# UPDATE CL :  FREE %x of size %d #############\n\n",block_base, block_length);
     1189        update_chunk_list(block_base, block_length);
     1190    }
     1191    else
     1192    {
     1193
     1194        giet_printf("############# INSERT IN RF %d :  FREE %x of size %d #############\n\n", remote_owner_id, block_base, block_length);
     1195        insert_in_remote_free_list(remote_owner_id, block_base, block_length);
     1196    }
     1197
     1198
     1199    giet_printf("BLOCK SUCCESSFULLY FREED\n\n");
    11331200
    11341201    return;
  • soft/giet_vm/libs/malloc.h

    r233 r244  
    88#ifndef _MALLOC_H_
    99#define _MALLOC_H_
     10//#define DEBUG_MALLOC 1
    1011
    1112#include "giet_config.h"
     13#include "spin_lock.h"
    1214
    1315//#define MALLOC_SELECTED 2
  • soft/giet_vm/libs/malloc_private.h

    r233 r244  
    1515} heap_ll;
    1616
     17void insert_in_remote_free_list(unsigned int remote_owner_id, unsigned int block_base, unsigned int block_length);
     18heap_ll * pop_remote_free_list(heap_ll ** head);
     19heap_ll * pop_ptr(void);
     20void update_chunk_list(unsigned int block_base, unsigned int block_length);
     21
    1722#if MALLOC_SELECTED == 1 || MALLOC_SELECTED == 2
    18 static heap_ll * get_prev_fit_chunk(unsigned int size);
     23    static heap_ll * get_prev_fit_chunk(unsigned int size);
    1924#else
    20 int get_prev_fit_chunk(unsigned int size);
     25    int get_prev_fit_chunk(unsigned int size);
    2126#endif
    2227
    23 static void print_all_heap(void);
    24 static void frag(int turn);
    2528
    2629#endif
  • soft/giet_vm/libs/spin_lock.c

    r228 r244  
    3232
    3333    asm volatile (
    34             "giet_lock_try:                 \n"
    35             "ll   $2,    0(%0)              \n" /* $2 <= lock current value */
     34            "move $16, %0                   \n"
     35            "giet_lock_try :                \n"
     36            "ll   $2,    0($16)             \n" /* $2 <= lock current value */
    3637            "bnez $2,    giet_lock_delay    \n" /* retry if lock already taken */
    3738            "li   $3,    1                  \n" /* $3 <= argument for sc */
    38             "sc   $3,    0(%0)              \n" /* try to get lock */
     39            "sc   $3,    0($16)             \n" /* try to get lock */
    3940            "bnez $3,    giet_lock_ok       \n" /* exit if atomic */
    4041
     
    5354            :
    5455            :"r"(plock)
    55             :"$2", "$3", "$4");
     56            :"$2", "$3", "$4", "$16");
    5657}
    5758
  • soft/giet_vm/memo/Makefile

    r210 r244  
    1818
    1919clean:
    20         rm *.x
     20        rm -f *.x
  • soft/giet_vm/xml/mapping_info.h

    r238 r244  
    101101///////////////////////////////
    102102
    103 typedef struct mapping_header_s
     103typedef struct __attribute__((packed))  mapping_header_s
    104104{
    105105    unsigned int signature;          // must contain MAPPING_SIGNATURE
     
    138138
    139139////////////////////////////////
    140 typedef struct mapping_cluster_s
     140typedef struct __attribute__((packed))  mapping_cluster_s
    141141{
    142142    unsigned int psegs;          // number of psegs in cluster
     
    155155
    156156/////////////////////////////
    157 typedef struct mapping_pseg_s 
     157typedef struct __attribute__((packed))  mapping_pseg_s 
    158158{
    159159    char         name[32];       // pseg name (unique in a cluster)
     
    167167
    168168///////////////////////////////
    169 typedef struct mapping_vspace_s
     169typedef struct __attribute__((packed))  mapping_vspace_s
    170170{
    171171    char         name[32];       // virtual space name
     
    181181
    182182/////////////////////////////
    183 typedef struct mapping_vseg_s
     183typedef struct __attribute__((packed))  mapping_vseg_s
    184184{
    185185    char         name[32];       // vseg name (unique in vspace)
     
    196196
    197197/////////////////////////////
    198 typedef struct mapping_task_s
     198typedef struct __attribute__((packed))  mapping_task_s
    199199{
    200200    char         name[32];       // task name (unique in vspace)
     
    214214
    215215/////////////////////////////
    216 typedef struct mapping_vobj_s
     216typedef struct __attribute__((packed))  mapping_vobj_s
    217217{
    218218    char         name[32];       // vobj name (unique in a vspace)
     
    228228
    229229/////////////////////////////
    230 typedef struct mapping_proc_s
     230typedef struct __attribute__((packed))  mapping_proc_s
    231231{
    232232    unsigned int irqs;           // number of IRQs allocated to processor
     
    236236
    237237/////////////////////////////
    238 typedef struct mapping_irq_s
     238typedef struct __attribute__((packed))  mapping_irq_s
    239239{
    240240    unsigned int type;           // 0 => HW_IRQ  / 1 => SW_IRQ
     
    246246
    247247///////////////////////////////
    248 typedef struct mapping_coproc_s
     248typedef struct __attribute__((packed))  mapping_coproc_s
    249249{
    250250    char         name[32];       // coprocessor name
     
    256256
    257257////////////////////////////////
    258 typedef struct mapping_cp_port_s
     258typedef struct __attribute__((packed))  mapping_cp_port_s
    259259{
    260260    unsigned int direction;      // TO_COPROC == 0 / FROM_COPROC == 1
     
    265265
    266266///////////////////////////////
    267 typedef struct mapping_periph_s
     267typedef struct __attribute__((packed))  mapping_periph_s
    268268{
    269269    unsigned int type;           // IOC / TTY / TIM / DMA / FBF / NIC / IOB
Note: See TracChangeset for help on using the changeset viewer.