mem_block.h 7.07 KB
Newer Older
1 2 3 4 5
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

22 23 24 25 26 27 28 29 30 31 32 33
/***************************************************************************
                          mem_block.h  -  description
                             -------------------
  AUTHOR  : Lionel GAUTHIER
  COMPANY : EURECOM
  EMAIL   : Lionel.Gauthier@eurecom.fr


 ***************************************************************************/
#ifndef __MEM_BLOCK_H__
#    define __MEM_BLOCK_H__

34
#include <stdint.h>
laurent's avatar
laurent committed
35 36 37 38
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
39
#include "openair2/COMMON/platform_constants.h"
40 41
//-----------------------------------------------------------------------------

42
typedef struct mem_block_t {
43 44
  struct mem_block_t *next;
  struct mem_block_t *previous;
laurent's avatar
laurent committed
45
  size_t size;
46
  unsigned char pool_id;
47
  unsigned char *data;
48
} mem_block_t;
49 50 51

//-----------------------------------------------------------------------------

52 53 54 55 56 57 58 59 60 61 62
void        *pool_buffer_init (void);
void        *pool_buffer_clean (void *arg);
void         free_mem_block (mem_block_t * leP, const char* caller);
mem_block_t* get_free_mem_block (uint32_t sizeP, const char* caller);
mem_block_t *get_free_copy_mem_block (void);
mem_block_t *get_free_copy_mem_block_up (void);
mem_block_t *copy_mem_block (mem_block_t * leP, mem_block_t * destP);
void         display_mem_load (void);

void         check_mem_area (void);
void        check_free_mem_block (mem_block_t * leP);
63
#    define MEM_SCALE MAX_MOBILES_PER_ENB
64 65
// definition of the size of the allocated memory area
#    define MEM_MNGT_MB0_BLOCK_SIZE     64
66
// 64
67 68 69 70
#    define MEM_MNGT_MB0_NB_BLOCKS      4096 * MEM_SCALE
#    define MEM_MNGT_POOL_ID0           0

#    define MEM_MNGT_MB1_BLOCK_SIZE     MEM_MNGT_MB0_BLOCK_SIZE*2
71
// 128
72 73 74 75
#    define MEM_MNGT_MB1_NB_BLOCKS      4096 * MEM_SCALE
#    define MEM_MNGT_POOL_ID1           1

#    define MEM_MNGT_MB2_BLOCK_SIZE     MEM_MNGT_MB0_BLOCK_SIZE*4
76
// 256
77 78 79 80
#    define MEM_MNGT_MB2_NB_BLOCKS      2048 * MEM_SCALE
#    define MEM_MNGT_POOL_ID2           2

#    define MEM_MNGT_MB3_BLOCK_SIZE     MEM_MNGT_MB0_BLOCK_SIZE*8
81
// 512
82 83 84 85
#    define MEM_MNGT_MB3_NB_BLOCKS      2048 * MEM_SCALE
#    define MEM_MNGT_POOL_ID3           3

#    define MEM_MNGT_MB4_BLOCK_SIZE     MEM_MNGT_MB0_BLOCK_SIZE*16
86
// 1024
87
#    define MEM_MNGT_MB4_NB_BLOCKS      1024 * MEM_SCALE
88 89 90
#    define MEM_MNGT_POOL_ID4           4

#    define MEM_MNGT_MB5_BLOCK_SIZE     MEM_MNGT_MB0_BLOCK_SIZE*32
91
// 2048
92
#    define MEM_MNGT_MB5_NB_BLOCKS      1024 * MEM_SCALE // LG WAS 1024
93 94 95
#    define MEM_MNGT_POOL_ID5           5

#    define MEM_MNGT_MB6_BLOCK_SIZE     MEM_MNGT_MB0_BLOCK_SIZE*64
96
// 4096
97
#    define MEM_MNGT_MB6_NB_BLOCKS      1024 * MEM_SCALE  // LG WAS 256
98 99 100
#    define MEM_MNGT_POOL_ID6           6

#    define MEM_MNGT_MB7_BLOCK_SIZE     MEM_MNGT_MB0_BLOCK_SIZE*128
101
// 8192
102 103 104 105 106 107 108 109 110
#    define MEM_MNGT_MB7_NB_BLOCKS      64* MEM_SCALE   // LG WAS 32
#    define MEM_MNGT_POOL_ID7           7

#    define MEM_MNGT_MB8_BLOCK_SIZE     MEM_MNGT_MB0_BLOCK_SIZE*256

#ifdef JUMBO_FRAMES
#    define MEM_MNGT_MB8_NB_BLOCKS      256 * MEM_SCALE
#else
#    define MEM_MNGT_MB8_NB_BLOCKS      16 * MEM_SCALE
111
// 16384
112 113 114 115
#endif
#    define MEM_MNGT_POOL_ID8           8

#    define MEM_MNGT_MB9_BLOCK_SIZE     MEM_MNGT_MB0_BLOCK_SIZE*512
116
// 32768
117 118 119 120
#    define MEM_MNGT_MB9_NB_BLOCKS      8 * MEM_SCALE
#    define MEM_MNGT_POOL_ID9           9

#    define MEM_MNGT_MB10_BLOCK_SIZE    MEM_MNGT_MB0_BLOCK_SIZE*1024
121
// 65536
122 123 124 125
#    define MEM_MNGT_MB10_NB_BLOCKS     0 * MEM_SCALE
#    define MEM_MNGT_POOL_ID10          10

#    define MEM_MNGT_MB11_BLOCK_SIZE    MEM_MNGT_MB0_BLOCK_SIZE*2048
126
// 131072
127 128 129 130
#    define MEM_MNGT_MB11_NB_BLOCKS     0 * MEM_SCALE
#    define MEM_MNGT_POOL_ID11          11

#    define MEM_MNGT_MB12_BLOCK_SIZE    MEM_MNGT_MB0_BLOCK_SIZE*4096
131
// 262144
132 133 134 135 136 137 138 139
#    define MEM_MNGT_MB12_NB_BLOCKS     32 * MEM_SCALE
#    define MEM_MNGT_POOL_ID12          12


#    define MEM_MNGT_MBCOPY_NB_BLOCKS   1024
#    define MEM_MNGT_NB_ELEMENTS        MEM_MNGT_MB0_NB_BLOCKS + MEM_MNGT_MB1_NB_BLOCKS + MEM_MNGT_MB2_NB_BLOCKS + MEM_MNGT_MB3_NB_BLOCKS + MEM_MNGT_MB4_NB_BLOCKS + MEM_MNGT_MB5_NB_BLOCKS + MEM_MNGT_MB6_NB_BLOCKS + MEM_MNGT_MB7_NB_BLOCKS + MEM_MNGT_MB8_NB_BLOCKS + MEM_MNGT_MB9_NB_BLOCKS + MEM_MNGT_MB10_NB_BLOCKS + MEM_MNGT_MB11_NB_BLOCKS + MEM_MNGT_MB12_NB_BLOCKS + MEM_MNGT_MBCOPY_NB_BLOCKS
#    define MEM_MNGT_POOL_ID_COPY        13

140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
#define LIST_NAME_MAX_CHAR 32


typedef struct {
  struct mem_block_t *head;
  struct mem_block_t *tail;
  int                nb_elements;
  char               name[LIST_NAME_MAX_CHAR];
} list2_t;
//-----------------------------------------------------------------------------
typedef struct {
  struct mem_block_t *head;
  struct mem_block_t *tail;
  int                nb_elements;
  char               name[LIST_NAME_MAX_CHAR];
} list_t;

157 158


159
typedef struct {
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
  //-----------------------------------------------------------
  // basic memory management
  //-----------------------------------------------------------
  char              mem_pool0[MEM_MNGT_MB0_NB_BLOCKS][MEM_MNGT_MB0_BLOCK_SIZE];
  char              mem_pool1[MEM_MNGT_MB1_NB_BLOCKS][MEM_MNGT_MB1_BLOCK_SIZE];
  char              mem_pool2[MEM_MNGT_MB2_NB_BLOCKS][MEM_MNGT_MB2_BLOCK_SIZE];
  char              mem_pool3[MEM_MNGT_MB3_NB_BLOCKS][MEM_MNGT_MB3_BLOCK_SIZE];
  char              mem_pool4[MEM_MNGT_MB4_NB_BLOCKS][MEM_MNGT_MB4_BLOCK_SIZE];
  char              mem_pool5[MEM_MNGT_MB5_NB_BLOCKS][MEM_MNGT_MB5_BLOCK_SIZE];
  char              mem_pool6[MEM_MNGT_MB6_NB_BLOCKS][MEM_MNGT_MB6_BLOCK_SIZE];
  char              mem_pool7[MEM_MNGT_MB7_NB_BLOCKS][MEM_MNGT_MB7_BLOCK_SIZE];
  char              mem_pool8[MEM_MNGT_MB8_NB_BLOCKS][MEM_MNGT_MB8_BLOCK_SIZE];
  char              mem_pool9[MEM_MNGT_MB9_NB_BLOCKS][MEM_MNGT_MB9_BLOCK_SIZE];
  char              mem_pool10[MEM_MNGT_MB10_NB_BLOCKS][MEM_MNGT_MB10_BLOCK_SIZE];
  char              mem_pool11[MEM_MNGT_MB11_NB_BLOCKS][MEM_MNGT_MB11_BLOCK_SIZE];
  char              mem_pool12[MEM_MNGT_MB12_NB_BLOCKS][MEM_MNGT_MB12_BLOCK_SIZE];
  mem_block_t     mem_blocks[MEM_MNGT_NB_ELEMENTS];
  list_t          mem_lists[14];

179
} mem_pool;
180

laurent's avatar
laurent committed
181 182
mem_pool  *memBlockVar;
#define mem_block_var (*memBlockVar)
183

laurent's avatar
laurent committed
184 185 186
#ifdef __cplusplus
}
#endif
187
#endif