1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
/*******************************************************************
* File: omTables.c
* Purpose: program which generates omTables.inc
* Author: obachman (Olaf Bachmann)
* Created: 11/99
*******************************************************************/
#ifndef MH_TABLES_C
#define MH_TABLES_C
#define _POSIX_SOURCE 1
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include "omConfig.h"
#include "omDerivedConfig.h"
#include "omStructs.h"
#include "omAllocPrivate.h"
/* Specify the minimal number of blocks which should go into a bin */
#if SIZEOF_SYSTEM_PAGE > 4096
#define MIN_BIN_BLOCKS 8
#define INCR_FACTOR 2
#else
#define MIN_BIN_BLOCKS 4
#define INCR_FACTOR 1
#endif
#define OM_MAX_BLOCK_SIZE ((SIZEOF_OM_BIN_PAGE / MIN_BIN_BLOCKS) & ~(SIZEOF_STRICT_ALIGNMENT - 1))
/* Specify sizes of static bins */
#ifdef OM_ALIGN_8
size_t om_BinSize [SIZEOF_OM_BIN_PAGE / MIN_BIN_BLOCKS] =
{ 8, 16, 24, 32,
40, 48, 56, 64, 72,
80, 96, 112, 128, 144,
160, 192, 224,
((SIZEOF_OM_BIN_PAGE / (MIN_BIN_BLOCKS + INCR_FACTOR*9)) / 8)*8,
((SIZEOF_OM_BIN_PAGE / (MIN_BIN_BLOCKS + INCR_FACTOR*6)) / 8)*8,
((SIZEOF_OM_BIN_PAGE / (MIN_BIN_BLOCKS + INCR_FACTOR*4)) / 8)*8,
((SIZEOF_OM_BIN_PAGE / (MIN_BIN_BLOCKS + INCR_FACTOR*2)) / 8)*8,
((SIZEOF_OM_BIN_PAGE / (MIN_BIN_BLOCKS + INCR_FACTOR)) / 8)*8,
OM_MAX_BLOCK_SIZE};
#else /* ! OM_ALIGN_8 */
size_t om_BinSize [SIZEOF_OM_BIN_PAGE / MIN_BIN_BLOCKS] =
{ 8, 12, 16, 20,
24, 28, 32,
40, 48, 56, 64,
80, 96, 112, 128,
160, 192, 224,
((SIZEOF_OM_BIN_PAGE / (MIN_BIN_BLOCKS + INCR_FACTOR*9)) / SIZEOF_STRICT_ALIGNMENT)*SIZEOF_STRICT_ALIGNMENT,
((SIZEOF_OM_BIN_PAGE / (MIN_BIN_BLOCKS + INCR_FACTOR*6)) / SIZEOF_STRICT_ALIGNMENT)*SIZEOF_STRICT_ALIGNMENT,
((SIZEOF_OM_BIN_PAGE / (MIN_BIN_BLOCKS + INCR_FACTOR*4)) / SIZEOF_STRICT_ALIGNMENT)*SIZEOF_STRICT_ALIGNMENT,
((SIZEOF_OM_BIN_PAGE / (MIN_BIN_BLOCKS + INCR_FACTOR*2)) / SIZEOF_STRICT_ALIGNMENT)*SIZEOF_STRICT_ALIGNMENT,
((SIZEOF_OM_BIN_PAGE / (MIN_BIN_BLOCKS + INCR_FACTOR)) / SIZEOF_STRICT_ALIGNMENT)*SIZEOF_STRICT_ALIGNMENT,
OM_MAX_BLOCK_SIZE};
#endif /* OM_ALIGN_8 */
void OutputSize2Bin(size_t *binSize, size_t max_block_size, int track)
{
long i, j;
printf("omBin om_Size2%sBin[/*%ld*/] = {\n",
(track? "Track" : ""), (long)(max_block_size / SIZEOF_OM_ALIGNMENT));
i=0;
j=SIZEOF_OM_ALIGNMENT;
while (j < max_block_size)
{
printf("&om_Static%sBin[%ld], /* %ld */ \n", (track? "Track" : ""), i, j);
if (binSize[i] == j) i++;
j += SIZEOF_OM_ALIGNMENT;
}
printf("&om_Static%sBin[%ld] /* %ld */};\n\n", (track? "Track" : ""), i, j);
}
void OutputSize2AlignedBin(size_t *binSize, size_t max_block_size, int track)
{
long i, j;
if (OM_MAX_BLOCK_SIZE % 8 != 0)
{
fprintf(stderr, "OM_MAX_BLOCK_SIZE == %d not divisible by 8\n", OM_MAX_BLOCK_SIZE);fflush(stdout);
_exit(1);
}
printf("omBin om_Size2%sBin[/*%ld*/] = {\n",
(track ? "Track" : "Aligned"), (long)(max_block_size / SIZEOF_OM_ALIGNMENT));
i=0;
while (binSize[i] % SIZEOF_STRICT_ALIGNMENT != 0) i++;
j=SIZEOF_OM_ALIGNMENT;
while (j < max_block_size)
{
printf("&om_Static%sBin[%ld], /* %ld */ \n", (track ? "Track" : ""), i, j);
if (binSize[i] == j)
{
i++;
while (binSize[i] % SIZEOF_STRICT_ALIGNMENT != 0) i++;
}
j += SIZEOF_OM_ALIGNMENT;
}
printf("&om_Static%sBin[%ld] /* %ld */};\n\n", (track ? "Track" : ""), i, j);
}
void OutputStaticBin(size_t *binSize, int max_bin_index, int track)
{
long i;
printf("omBin_t om_Static%sBin[/*%d*/] = {\n", (track ? "Track" : ""), max_bin_index+1);
for (i=0; i< max_bin_index; i++)
{
printf("{om_ZeroPage, NULL, NULL, %ld, %ld, 0},\n",
(long)(binSize[i] / SIZEOF_LONG),
(long)(SIZEOF_OM_BIN_PAGE/binSize[i]));
}
printf("{om_ZeroPage, NULL, NULL, %ld, %ld, 0}\n};\n\n",
(long)(binSize[i] / SIZEOF_LONG),
(long)(SIZEOF_OM_BIN_PAGE/binSize[i]));
}
int GetMaxBlockThreshold()
{
int i;
for (i=SIZEOF_OM_ALIGNMENT; i < OM_MAX_BLOCK_SIZE; i += SIZEOF_OM_ALIGNMENT)
{
if ((SIZEOF_OM_BIN_PAGE/i) == SIZEOF_OM_BIN_PAGE/(i + SIZEOF_OM_ALIGNMENT))
return i;
}
/* should never get here */
printf("error");fflush(stdout);
_exit(1);
}
void CreateDenseBins()
{
size_t size, align_size = SIZEOF_OM_ALIGNMENT;
int i = 1;
#ifdef OM_ALIGNMENT_NEEDS_WORK
int n = GetMaxBlockThreshold();
#endif
size = align_size;
om_BinSize[0] = align_size;
i = 1;
while (size < OM_MAX_BLOCK_SIZE)
{
size += align_size;
#ifdef OM_ALIGNMENT_NEEDS_WORK
if (size >= n && align_size != SIZEOF_STRICT_ALIGNMENT)
{
align_size = SIZEOF_STRICT_ALIGNMENT;
size= OM_STRICT_ALIGN_SIZE(size);
}
#endif
om_BinSize[i] = size;
if ((SIZEOF_OM_BIN_PAGE / (size + align_size)) < (SIZEOF_OM_BIN_PAGE /size))
{
i++;
}
}
}
int main(int argc, char* argv[])
{
int max_bin_index = 0;
/* determine max_bin_index */
#ifdef OM_HAVE_DENSE_BIN_DISTRIBUTION
CreateDenseBins();
#endif
for(;;)
{
max_bin_index++;
if (om_BinSize[max_bin_index] == OM_MAX_BLOCK_SIZE) break;
}
if (argc > 1)
{
/* output what goes into omTables.h */
printf(
"#ifndef OM_TABLES_H\n"
"#define OM_TABLES_H\n"
"#define OM_MAX_BLOCK_SIZE %d\n"
"#define OM_MAX_BIN_INDEX %d\n"
"#define OM_SIZEOF_UNIQUE_MAX_BLOCK_THRESHOLD %d\n"
"#endif /* OM_TABLES_H */\n"
, OM_MAX_BLOCK_SIZE, max_bin_index, GetMaxBlockThreshold());
return 0;
}
printf(
"#ifndef OM_TABLES_INC\n"
"#define OM_TABLES_INC\n"
);
/* Output om_StaticBin */
OutputStaticBin(om_BinSize, max_bin_index, 0);
/* Output om_Size2Bin */
OutputSize2Bin(om_BinSize, OM_MAX_BLOCK_SIZE, 0);
#ifdef OM_ALIGNMENT_NEEDS_WORK
OutputSize2AlignedBin(om_BinSize, OM_MAX_BLOCK_SIZE, 0);
#endif
printf("\n#ifdef OM_HAVE_TRACK\n");
/* Output om_StaticBin */
OutputStaticBin(om_BinSize, max_bin_index, 1);
/* Output om_Size2Bin */
#ifdef OM_ALIGNMENT_NEEDS_WORK
OutputSize2AlignedBin(om_BinSize, OM_MAX_BLOCK_SIZE, 1);
#else
OutputSize2Bin(om_BinSize, OM_MAX_BLOCK_SIZE, 1);
#endif
printf("\n#endif /* OM_HAVE_TRACK */\n");
printf("\n#endif /* OM_TABLES_INC */\n");
return 0;
}
#endif /* MH_TABLES_C */
|