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