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