1 | /*********************************************************************** |
---|
2 | |
---|
3 | COPYRIGHT |
---|
4 | |
---|
5 | The following is a notice of limited availability of the code and |
---|
6 | Government license and disclaimer which must be included in the |
---|
7 | prologue of the code and in all source listings of the code. |
---|
8 | |
---|
9 | Copyright notice |
---|
10 | (c) 1977 University of Chicago |
---|
11 | |
---|
12 | Permission is hereby granted to use, reproduce, prepare |
---|
13 | derivative works, and to redistribute to others at no charge. If |
---|
14 | you distribute a copy or copies of the Software, or you modify a |
---|
15 | copy or copies of the Software or any portion of it, thus forming |
---|
16 | a work based on the Software and make and/or distribute copies of |
---|
17 | such work, you must meet the following conditions: |
---|
18 | |
---|
19 | a) If you make a copy of the Software (modified or verbatim) |
---|
20 | it must include the copyright notice and Government |
---|
21 | license and disclaimer. |
---|
22 | |
---|
23 | b) You must cause the modified Software to carry prominent |
---|
24 | notices stating that you changed specified portions of |
---|
25 | the Software. |
---|
26 | |
---|
27 | This software was authored by: |
---|
28 | |
---|
29 | Argonne National Laboratory |
---|
30 | J. Michalakes: (630) 252-6646; email: michalak@mcs.anl.gov |
---|
31 | Mathematics and Computer Science Division |
---|
32 | Argonne National Laboratory, Argonne, IL 60439 |
---|
33 | |
---|
34 | ARGONNE NATIONAL LABORATORY (ANL), WITH FACILITIES IN THE STATES |
---|
35 | OF ILLINOIS AND IDAHO, IS OWNED BY THE UNITED STATES GOVERNMENT, |
---|
36 | AND OPERATED BY THE UNIVERSITY OF CHICAGO UNDER PROVISION OF A |
---|
37 | CONTRACT WITH THE DEPARTMENT OF ENERGY. |
---|
38 | |
---|
39 | GOVERNMENT LICENSE AND DISCLAIMER |
---|
40 | |
---|
41 | This computer code material was prepared, in part, as an account |
---|
42 | of work sponsored by an agency of the United States Government. |
---|
43 | The Government is granted for itself and others acting on its |
---|
44 | behalf a paid-up, nonexclusive, irrevocable worldwide license in |
---|
45 | this data to reproduce, prepare derivative works, distribute |
---|
46 | copies to the public, perform publicly and display publicly, and |
---|
47 | to permit others to do so. NEITHER THE UNITED STATES GOVERNMENT |
---|
48 | NOR ANY AGENCY THEREOF, NOR THE UNIVERSITY OF CHICAGO, NOR ANY OF |
---|
49 | THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR |
---|
50 | ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, |
---|
51 | COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, |
---|
52 | PRODUCT, OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD |
---|
53 | NOT INFRINGE PRIVATELY OWNED RIGHTS. |
---|
54 | |
---|
55 | ***************************************************************************/ |
---|
56 | |
---|
57 | #if 0 |
---|
58 | #define PADIT /* add page at beginning and end of allocation */ |
---|
59 | #endif |
---|
60 | #if 0 |
---|
61 | # define BASE_MALLOC fence_malloc |
---|
62 | # define BASE_FREE fence_free |
---|
63 | #else |
---|
64 | # define BASE_MALLOC malloc |
---|
65 | # define BASE_FREE free |
---|
66 | #endif |
---|
67 | |
---|
68 | #include <stdio.h> |
---|
69 | #include <stdlib.h> |
---|
70 | #include <malloc.h> |
---|
71 | #ifdef T3D |
---|
72 | #include <errno.h> |
---|
73 | #endif |
---|
74 | #include "mpi.h" |
---|
75 | #include "rsl_lite.h" |
---|
76 | |
---|
77 | /* |
---|
78 | extern int EF_ALIGNMENT; |
---|
79 | extern int EF_PROTECT_BELOW; |
---|
80 | extern int EF_PROTECT_FREE; |
---|
81 | */ |
---|
82 | |
---|
83 | /* define STUG to enable tracking of allocs and frees (performance and space penalty) */ |
---|
84 | #ifdef STUG |
---|
85 | #define MAXSTUG 1000000 |
---|
86 | struct stugtype { |
---|
87 | char * ddr ; |
---|
88 | int sz ; |
---|
89 | } stug[MAXSTUG] ; |
---|
90 | static int stugfirst =1 ; |
---|
91 | int outy = 0 ; |
---|
92 | int nouty = 0 ; |
---|
93 | int maxstug = 0 ; |
---|
94 | int maxouty = 0 ; |
---|
95 | int bbb ; |
---|
96 | #endif |
---|
97 | |
---|
98 | |
---|
99 | static char zero_length_storage[] = "" ; |
---|
100 | |
---|
101 | #if !(defined(vpp) || defined(vpp2) || defined(SUN) || defined(XT3_Catamount)) |
---|
102 | static struct mallinfo minf ; |
---|
103 | #endif |
---|
104 | |
---|
105 | static char *last_f ; |
---|
106 | static int last_l ; |
---|
107 | static int last_s ; |
---|
108 | |
---|
109 | #ifdef O2K |
---|
110 | static struct mallinfo mallinfo() {} ; |
---|
111 | #endif |
---|
112 | |
---|
113 | void * rsl_malloc(f,l,s) |
---|
114 | char * f ; |
---|
115 | int l, s ; |
---|
116 | { |
---|
117 | char mess[128] ; |
---|
118 | void *retval ; |
---|
119 | int s2, tries ; |
---|
120 | |
---|
121 | /* |
---|
122 | EF_PROTECT_BELOW = 0 ; |
---|
123 | EF_PROTECT_FREE = 1 ; |
---|
124 | */ |
---|
125 | |
---|
126 | #ifdef STUG |
---|
127 | if ( stugfirst == 1 ) { |
---|
128 | stugfirst = 0 ; |
---|
129 | for ( bbb = 0 ; bbb < MAXSTUG ; bbb++ ) { |
---|
130 | stug[bbb].ddr = 0L ; |
---|
131 | stug[bbb].sz = 0 ; |
---|
132 | } |
---|
133 | } |
---|
134 | #endif |
---|
135 | |
---|
136 | if ( s == 0 ) |
---|
137 | { |
---|
138 | retval = (void *) zero_length_storage ; |
---|
139 | } |
---|
140 | else |
---|
141 | { |
---|
142 | #ifdef PADIT |
---|
143 | s2 = s + 1024 ; |
---|
144 | #else |
---|
145 | s2 = s ; |
---|
146 | #endif |
---|
147 | tries = 0 ; |
---|
148 | while ((retval=(void *)BASE_MALLOC(s2))==(void *)NULL) |
---|
149 | { |
---|
150 | tries++ ; |
---|
151 | sprintf(mess, |
---|
152 | "rsl_malloc failed allocating %d bytes, called %s, line %d, try %d\n", |
---|
153 | s,f,l,tries) ; |
---|
154 | perror(mess) ; |
---|
155 | #if !(defined(vpp) || defined(vpp2) || defined(SUN) || defined(XT3_Catamount)) |
---|
156 | minf = mallinfo() ; |
---|
157 | fprintf(stderr,"mallinfo: arena %d\n",minf.arena) ; |
---|
158 | fprintf(stderr,"mallinfo: ordblks %d\n",minf.ordblks) ; |
---|
159 | fprintf(stderr,"mallinfo: smblks %d\n",minf.smblks) ; |
---|
160 | fprintf(stderr,"mallinfo: hblks %d\n",minf.hblks) ; |
---|
161 | fprintf(stderr,"mallinfo: hblkhd %d\n",minf.hblkhd) ; |
---|
162 | fprintf(stderr,"mallinfo: usmblks %d\n",minf.usmblks) ; |
---|
163 | fprintf(stderr,"mallinfo: fsmblks %d\n",minf.fsmblks) ; |
---|
164 | fprintf(stderr,"mallinfo: uordblks %d\n",minf.uordblks) ; |
---|
165 | fprintf(stderr,"mallinfo: fordblks %d\n",minf.fordblks) ; |
---|
166 | fprintf(stderr,"mallinfo: keepcost %d\n",minf.keepcost) ; |
---|
167 | #ifdef SUNINFO |
---|
168 | fprintf(stderr,"mallinfo: mkfast %d\n",minf.mkfast) ; |
---|
169 | fprintf(stderr,"mallinfo: nblks %d\n",minf.nblks) ; |
---|
170 | fprintf(stderr,"mallinfo: grain %d\n",minf.grain) ; |
---|
171 | fprintf(stderr,"mallinfo: uordbytes %d\n",minf.uordbytes) ; |
---|
172 | fprintf(stderr,"mallinfo: allocated %d\n",minf.allocated) ; |
---|
173 | fprintf(stderr,"mallinfo: treeoverhead %d\n",minf.treeoverhead) ; |
---|
174 | #endif |
---|
175 | #endif |
---|
176 | if ( tries >= 2 ) |
---|
177 | { |
---|
178 | system("lsps -a") ; |
---|
179 | sleep(1) ; |
---|
180 | } |
---|
181 | if ( tries >= 3 ) |
---|
182 | { |
---|
183 | system("lsps -a") ; |
---|
184 | RSL_FATAL(2) ; |
---|
185 | } |
---|
186 | } |
---|
187 | } |
---|
188 | #if !(defined(vpp)||defined(vpp2)) || defined(sx) || defined(alphavector) |
---|
189 | if ( s > 0 ) |
---|
190 | bzero( retval, s2 ) ; /* return zero'd storage always */ |
---|
191 | #else |
---|
192 | if ( s > 0 ) |
---|
193 | { int l, lb ; |
---|
194 | l = s2/sizeof(int) ; |
---|
195 | lb = l*sizeof(int) ; |
---|
196 | vizero_( retval, &l ) ; |
---|
197 | l = s2-lb ; |
---|
198 | vbzero_( retval+lb, &l ) ; /* return zero'd storage always */ |
---|
199 | } |
---|
200 | #endif |
---|
201 | |
---|
202 | #ifdef PADIT |
---|
203 | retval = retval + 512 ; |
---|
204 | #endif |
---|
205 | |
---|
206 | #ifdef STUG |
---|
207 | for ( bbb = 0 ; bbb < MAXSTUG ; bbb++ ) |
---|
208 | { |
---|
209 | if ( stug[bbb].ddr == 0 ) break ; |
---|
210 | } |
---|
211 | if ( bbb < MAXSTUG ) { |
---|
212 | stug[bbb].ddr = retval ; |
---|
213 | stug[bbb].sz = s ; |
---|
214 | outy += stug[bbb].sz ; |
---|
215 | /* fprintf(stderr,"+ %10d. %08x %10d %10d\n", bbb, stug[bbb].ddr, stug[bbb].sz, outy ) ; */ |
---|
216 | nouty ++ ; |
---|
217 | if ( nouty > maxstug ) maxstug = nouty ; |
---|
218 | if ( outy > maxouty ) maxouty = outy ; |
---|
219 | }else{ |
---|
220 | fprintf(stderr,"stug full %d\n",bbb) ; |
---|
221 | RSL_FATAL(2) ; |
---|
222 | } |
---|
223 | #endif |
---|
224 | return(retval) ; |
---|
225 | } |
---|
226 | |
---|
227 | rsl_free( p ) |
---|
228 | char * p ; |
---|
229 | { |
---|
230 | if ( p == zero_length_storage ) return ; /* fix from ANU */ |
---|
231 | |
---|
232 | #ifdef STUG |
---|
233 | for ( bbb = 0 ; bbb < MAXSTUG ; bbb++ ) |
---|
234 | { |
---|
235 | if ( stug[bbb].ddr == p ) { |
---|
236 | outy -= stug[bbb].sz ; |
---|
237 | /* fprintf(stderr,"- %10d. %08x %10d %10d\n", bbb, stug[bbb].ddr, stug[bbb].sz, outy ) ; */ |
---|
238 | nouty -- ; |
---|
239 | stug[bbb].ddr = 0L ; |
---|
240 | break ; |
---|
241 | } |
---|
242 | } |
---|
243 | #endif |
---|
244 | |
---|
245 | #ifdef PADIT |
---|
246 | BASE_FREE ( p-512 ) ; |
---|
247 | #else |
---|
248 | BASE_FREE ( p ) ; |
---|
249 | #endif |
---|
250 | p = NULL ; |
---|
251 | } |
---|
252 | |
---|
253 | |
---|