[408] | 1 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // File : pmem.c |
---|
| 3 | // Date : 01/07/2012 |
---|
| 4 | // Author : alain greiner |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
| 6 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 7 | |
---|
| 8 | #include <utils.h> |
---|
| 9 | #include <pmem.h> |
---|
| 10 | #include <giet_config.h> |
---|
| 11 | |
---|
| 12 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 13 | // Global variable : array of physical memory allocators (one per cluster) |
---|
| 14 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 15 | |
---|
| 16 | extern pmem_alloc_t boot_pmem_alloc[X_SIZE][Y_SIZE]; |
---|
| 17 | |
---|
| 18 | //////////////////////////////////////// |
---|
| 19 | void _pmem_alloc_init( unsigned int x, |
---|
| 20 | unsigned int y, |
---|
| 21 | unsigned int base, |
---|
| 22 | unsigned int size ) |
---|
| 23 | { |
---|
| 24 | if ( (base & 0x1FFFFF) || (size & 0x1FFFFF) ) |
---|
| 25 | { |
---|
| 26 | _printf("\n[GIET ERROR] in _pmem_alloc_init() : " |
---|
| 27 | " pseg in cluster[%d][%d] not aligned on 2 Mbytes\n", x, y ); |
---|
| 28 | _exit(); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | pmem_alloc_t* p = &boot_pmem_alloc[x][y]; |
---|
| 32 | |
---|
| 33 | unsigned int bppi_min = base >> 21; |
---|
| 34 | unsigned int bppi_max = (base + size) >> 21; |
---|
| 35 | |
---|
| 36 | p->x = x; |
---|
| 37 | p->y = y; |
---|
| 38 | |
---|
| 39 | p->nxt_bppi = bppi_min; |
---|
| 40 | p->max_bppi = bppi_max; |
---|
| 41 | |
---|
| 42 | p->nxt_sppi = 0; |
---|
| 43 | p->max_sppi = 0; |
---|
| 44 | |
---|
| 45 | // first page reserved in cluster [0][0] |
---|
| 46 | if ( (x==0) && (y==0) ) p->nxt_bppi = p->nxt_bppi + 1; |
---|
| 47 | |
---|
| 48 | } // end pmem_alloc_init() |
---|
| 49 | |
---|
| 50 | ///////////////////////////////////////////// |
---|
| 51 | unsigned int _get_big_ppn( pmem_alloc_t* p, |
---|
| 52 | unsigned int n ) |
---|
| 53 | { |
---|
| 54 | unsigned int x = p->x; |
---|
| 55 | unsigned int y = p->y; |
---|
| 56 | unsigned int bpi = p->nxt_bppi; // bpi : BPPI of the first allocated big page |
---|
| 57 | |
---|
| 58 | if ( (bpi + n) > p->max_bppi ) |
---|
| 59 | { |
---|
| 60 | _printf("\n[GIET ERROR] in _get_big_ppn() : " |
---|
| 61 | " not enough big physical pages in cluster[%d][%d]", x, y ); |
---|
| 62 | _exit(); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | // update allocator state |
---|
| 66 | p->nxt_bppi = bpi + n; |
---|
| 67 | |
---|
| 68 | return (x << 24) + (y << 20) + (bpi << 9); |
---|
| 69 | |
---|
| 70 | } // end get_big_ppn() |
---|
| 71 | |
---|
| 72 | /////////////////////////////////////////////// |
---|
| 73 | unsigned int _get_small_ppn( pmem_alloc_t* p, |
---|
| 74 | unsigned int n ) |
---|
| 75 | { |
---|
| 76 | unsigned int x = p->x; |
---|
| 77 | unsigned int y = p->y; |
---|
| 78 | unsigned int spi = p->nxt_sppi; // spi : SPPI of the first allocated small page |
---|
| 79 | unsigned int bpi = p->spp_bppi; // bpi : BPPI of the first allocated small page |
---|
| 80 | |
---|
| 81 | // get a new big page if not enough contiguous small pages |
---|
| 82 | // in the big page currently used to allocate small pages |
---|
| 83 | if ( spi + n > p->max_sppi ) |
---|
| 84 | { |
---|
| 85 | if ( p->nxt_bppi + 1 > p->max_bppi ) |
---|
| 86 | { |
---|
| 87 | _printf("\n[GIET ERROR] in _get_small_ppn() : " |
---|
| 88 | " not enough big physical pages in cluster[%d][%d]", x, y ); |
---|
| 89 | _exit(); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | // update the allocator state for the new big page |
---|
| 93 | p->spp_bppi = p->nxt_bppi; |
---|
| 94 | p->nxt_bppi = p->nxt_bppi + 1; |
---|
| 95 | p->nxt_sppi = 0; |
---|
| 96 | p->max_sppi = 512; |
---|
| 97 | |
---|
| 98 | // set the spi and bpi values |
---|
| 99 | spi = p->nxt_sppi; |
---|
| 100 | bpi = p->spp_bppi; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | // update allocator state for the n small pages |
---|
| 104 | p->nxt_sppi = p->nxt_sppi + n; |
---|
| 105 | |
---|
| 106 | return (x << 24) + (y << 20) + (bpi << 9) + spi; |
---|
| 107 | |
---|
| 108 | } // end _get_small_ppn() |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | // Local Variables: |
---|
| 113 | // tab-width: 4 |
---|
| 114 | // c-basic-offset: 4 |
---|
| 115 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 116 | // indent-tabs-mode: nil |
---|
| 117 | // End: |
---|
| 118 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 119 | |
---|
| 120 | |
---|