xref: /aosp_15_r20/external/ltp/testcases/misc/math/fptests/fptest01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker  *
3*49cdfc7eSAndroid Build Coastguard Worker  *   Copyright (c) International Business Machines  Corp., 2002
4*49cdfc7eSAndroid Build Coastguard Worker  *
5*49cdfc7eSAndroid Build Coastguard Worker  *   This program is free software;  you can redistribute it and/or modify
6*49cdfc7eSAndroid Build Coastguard Worker  *   it under the terms of the GNU General Public License as published by
7*49cdfc7eSAndroid Build Coastguard Worker  *   the Free Software Foundation; either version 2 of the License, or
8*49cdfc7eSAndroid Build Coastguard Worker  *   (at your option) any later version.
9*49cdfc7eSAndroid Build Coastguard Worker  *
10*49cdfc7eSAndroid Build Coastguard Worker  *   This program is distributed in the hope that it will be useful,
11*49cdfc7eSAndroid Build Coastguard Worker  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12*49cdfc7eSAndroid Build Coastguard Worker  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13*49cdfc7eSAndroid Build Coastguard Worker  *   the GNU General Public License for more details.
14*49cdfc7eSAndroid Build Coastguard Worker  *
15*49cdfc7eSAndroid Build Coastguard Worker  *   You should have received a copy of the GNU General Public License
16*49cdfc7eSAndroid Build Coastguard Worker  *   along with this program;  if not, write to the Free Software
17*49cdfc7eSAndroid Build Coastguard Worker  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*49cdfc7eSAndroid Build Coastguard Worker  */
19*49cdfc7eSAndroid Build Coastguard Worker 
20*49cdfc7eSAndroid Build Coastguard Worker /* Group Bull & IBM Corporation */
21*49cdfc7eSAndroid Build Coastguard Worker /* 11/20/2002	Port to LTP	[email protected] */
22*49cdfc7eSAndroid Build Coastguard Worker /*                                               [email protected] */
23*49cdfc7eSAndroid Build Coastguard Worker /* IBM Corporation */
24*49cdfc7eSAndroid Build Coastguard Worker /* 06/30/2001	Port to Linux	[email protected] */
25*49cdfc7eSAndroid Build Coastguard Worker 
26*49cdfc7eSAndroid Build Coastguard Worker /*
27*49cdfc7eSAndroid Build Coastguard Worker  * fptest01.c -- Floating point test.
28*49cdfc7eSAndroid Build Coastguard Worker  *
29*49cdfc7eSAndroid Build Coastguard Worker  * It is taken from a benchmark called "barsim".
30*49cdfc7eSAndroid Build Coastguard Worker  *
31*49cdfc7eSAndroid Build Coastguard Worker  * If the computation arrives at the expected values this routine
32*49cdfc7eSAndroid Build Coastguard Worker  * prints a "passed" message and exits 0.  If an incorrect value is
33*49cdfc7eSAndroid Build Coastguard Worker  * computed a "failed" message is printed and the routine exits 1.
34*49cdfc7eSAndroid Build Coastguard Worker  */
35*49cdfc7eSAndroid Build Coastguard Worker 
36*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
37*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
38*49cdfc7eSAndroid Build Coastguard Worker #include <math.h>
39*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
40*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
41*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
42*49cdfc7eSAndroid Build Coastguard Worker #include <sys/stat.h>
43*49cdfc7eSAndroid Build Coastguard Worker #include <fcntl.h>
44*49cdfc7eSAndroid Build Coastguard Worker 
45*49cdfc7eSAndroid Build Coastguard Worker #define MAGIC1	1632.796126
46*49cdfc7eSAndroid Build Coastguard Worker #define DIFF1	0.001
47*49cdfc7eSAndroid Build Coastguard Worker #define MAGIC2	0.777807
48*49cdfc7eSAndroid Build Coastguard Worker #define DIFF2	0.001
49*49cdfc7eSAndroid Build Coastguard Worker #define EVENTMX	256
50*49cdfc7eSAndroid Build Coastguard Worker #define BIG 1.e50
51*49cdfc7eSAndroid Build Coastguard Worker #define FALSE 0
52*49cdfc7eSAndroid Build Coastguard Worker #define TRUE  1
53*49cdfc7eSAndroid Build Coastguard Worker #define TRYCRIT   1
54*49cdfc7eSAndroid Build Coastguard Worker #define ENTERCRIT 2
55*49cdfc7eSAndroid Build Coastguard Worker #define LEAVECRIT 3
56*49cdfc7eSAndroid Build Coastguard Worker #define ATBARRIER 4
57*49cdfc7eSAndroid Build Coastguard Worker #define ENTERWORK 5
58*49cdfc7eSAndroid Build Coastguard Worker #define LEAVEWORK 6
59*49cdfc7eSAndroid Build Coastguard Worker #define NULLEVENT 999
60*49cdfc7eSAndroid Build Coastguard Worker 
61*49cdfc7eSAndroid Build Coastguard Worker /** LTP Port **/
62*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
63*49cdfc7eSAndroid Build Coastguard Worker 
64*49cdfc7eSAndroid Build Coastguard Worker char *TCID = "fptest01";	/* Test program identifier.    */
65*49cdfc7eSAndroid Build Coastguard Worker int TST_TOTAL = 1;		/* Total number of test cases. */
66*49cdfc7eSAndroid Build Coastguard Worker /**************/
67*49cdfc7eSAndroid Build Coastguard Worker 
68*49cdfc7eSAndroid Build Coastguard Worker struct event {
69*49cdfc7eSAndroid Build Coastguard Worker 	int proc;
70*49cdfc7eSAndroid Build Coastguard Worker 	int type;
71*49cdfc7eSAndroid Build Coastguard Worker 	double time;
72*49cdfc7eSAndroid Build Coastguard Worker };
73*49cdfc7eSAndroid Build Coastguard Worker 
74*49cdfc7eSAndroid Build Coastguard Worker static int init(void);
75*49cdfc7eSAndroid Build Coastguard Worker static int doevent(struct event *);
76*49cdfc7eSAndroid Build Coastguard Worker static int term(void);
77*49cdfc7eSAndroid Build Coastguard Worker static int addevent(int, int, double);
78*49cdfc7eSAndroid Build Coastguard Worker 
79*49cdfc7eSAndroid Build Coastguard Worker static void gaussinit(double, double);
80*49cdfc7eSAndroid Build Coastguard Worker static double gauss(void);
81*49cdfc7eSAndroid Build Coastguard Worker 
82*49cdfc7eSAndroid Build Coastguard Worker struct event eventtab[EVENTMX];
83*49cdfc7eSAndroid Build Coastguard Worker struct event rtrevent;
84*49cdfc7eSAndroid Build Coastguard Worker int waiting[EVENTMX];		/* array of waiting processors */
85*49cdfc7eSAndroid Build Coastguard Worker int nwaiting;			/* number of waiting processors */
86*49cdfc7eSAndroid Build Coastguard Worker double global_time;		/* global clock */
87*49cdfc7eSAndroid Build Coastguard Worker double lsttime;			/* time used for editing */
88*49cdfc7eSAndroid Build Coastguard Worker double dtc, dts, alpha;		/* timing parameters */
89*49cdfc7eSAndroid Build Coastguard Worker int nproc;			/* number of processors */
90*49cdfc7eSAndroid Build Coastguard Worker int barcnt;			/* number of processors ATBARRIER */
91*49cdfc7eSAndroid Build Coastguard Worker int ncycle;			/* number of cycles completed */
92*49cdfc7eSAndroid Build Coastguard Worker int ncycmax;			/* number of cycles to run */
93*49cdfc7eSAndroid Build Coastguard Worker int critfree;			/* TRUE if critical section not occupied */
94*49cdfc7eSAndroid Build Coastguard Worker int gcount;			/* # calls to gauss */
95*49cdfc7eSAndroid Build Coastguard Worker 
96*49cdfc7eSAndroid Build Coastguard Worker static struct event *nextevent(void);
97*49cdfc7eSAndroid Build Coastguard Worker 
main(void)98*49cdfc7eSAndroid Build Coastguard Worker int main(void)
99*49cdfc7eSAndroid Build Coastguard Worker {
100*49cdfc7eSAndroid Build Coastguard Worker 	struct event *ev;
101*49cdfc7eSAndroid Build Coastguard Worker 
102*49cdfc7eSAndroid Build Coastguard Worker 	nproc = 128;
103*49cdfc7eSAndroid Build Coastguard Worker 	ncycmax = 10;
104*49cdfc7eSAndroid Build Coastguard Worker 	dtc = 0.01;
105*49cdfc7eSAndroid Build Coastguard Worker 	dts = 0.0;
106*49cdfc7eSAndroid Build Coastguard Worker 	alpha = 0.1;
107*49cdfc7eSAndroid Build Coastguard Worker 
108*49cdfc7eSAndroid Build Coastguard Worker 	init();
109*49cdfc7eSAndroid Build Coastguard Worker 
110*49cdfc7eSAndroid Build Coastguard Worker 	while ((ev = nextevent()) != NULL) {
111*49cdfc7eSAndroid Build Coastguard Worker 		doevent(ev);
112*49cdfc7eSAndroid Build Coastguard Worker 	}
113*49cdfc7eSAndroid Build Coastguard Worker 
114*49cdfc7eSAndroid Build Coastguard Worker 	term();
115*49cdfc7eSAndroid Build Coastguard Worker 	tst_resm(TPASS, "PASS");
116*49cdfc7eSAndroid Build Coastguard Worker 	tst_exit();
117*49cdfc7eSAndroid Build Coastguard Worker }
118*49cdfc7eSAndroid Build Coastguard Worker 
119*49cdfc7eSAndroid Build Coastguard Worker /*
120*49cdfc7eSAndroid Build Coastguard Worker 	initialize all processes to "entering work section"
121*49cdfc7eSAndroid Build Coastguard Worker */
init(void)122*49cdfc7eSAndroid Build Coastguard Worker static int init(void)
123*49cdfc7eSAndroid Build Coastguard Worker {
124*49cdfc7eSAndroid Build Coastguard Worker 	int p;
125*49cdfc7eSAndroid Build Coastguard Worker 	double dtw, dtwsig;
126*49cdfc7eSAndroid Build Coastguard Worker 
127*49cdfc7eSAndroid Build Coastguard Worker 	ncycle = 0;
128*49cdfc7eSAndroid Build Coastguard Worker 	global_time = 0;
129*49cdfc7eSAndroid Build Coastguard Worker 	lsttime = 0;
130*49cdfc7eSAndroid Build Coastguard Worker 	barcnt = 0;
131*49cdfc7eSAndroid Build Coastguard Worker 	nwaiting = 0;
132*49cdfc7eSAndroid Build Coastguard Worker 	critfree = TRUE;
133*49cdfc7eSAndroid Build Coastguard Worker 
134*49cdfc7eSAndroid Build Coastguard Worker 	dtw = 1. / nproc;	/* mean process work time */
135*49cdfc7eSAndroid Build Coastguard Worker 	dtwsig = dtw * alpha;	/* std deviation of work time */
136*49cdfc7eSAndroid Build Coastguard Worker 	gaussinit(dtw, dtwsig);
137*49cdfc7eSAndroid Build Coastguard Worker 
138*49cdfc7eSAndroid Build Coastguard Worker 	for (p = 1; p <= nproc; p++) {
139*49cdfc7eSAndroid Build Coastguard Worker 		eventtab[p].type = NULLEVENT;
140*49cdfc7eSAndroid Build Coastguard Worker 	}
141*49cdfc7eSAndroid Build Coastguard Worker 
142*49cdfc7eSAndroid Build Coastguard Worker 	for (p = 1; p <= nproc; p++) {
143*49cdfc7eSAndroid Build Coastguard Worker 		addevent(ENTERWORK, p, global_time);
144*49cdfc7eSAndroid Build Coastguard Worker 	}
145*49cdfc7eSAndroid Build Coastguard Worker 
146*49cdfc7eSAndroid Build Coastguard Worker 	return (0);
147*49cdfc7eSAndroid Build Coastguard Worker }
148*49cdfc7eSAndroid Build Coastguard Worker 
149*49cdfc7eSAndroid Build Coastguard Worker /*
150*49cdfc7eSAndroid Build Coastguard Worker 	print edit quantities
151*49cdfc7eSAndroid Build Coastguard Worker */
term(void)152*49cdfc7eSAndroid Build Coastguard Worker static int term(void)
153*49cdfc7eSAndroid Build Coastguard Worker {
154*49cdfc7eSAndroid Build Coastguard Worker 	double avgspd;
155*49cdfc7eSAndroid Build Coastguard Worker 	double t_total = 0.0;
156*49cdfc7eSAndroid Build Coastguard Worker 	double v;
157*49cdfc7eSAndroid Build Coastguard Worker 	int i;
158*49cdfc7eSAndroid Build Coastguard Worker 
159*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 0; i < nproc; i++)
160*49cdfc7eSAndroid Build Coastguard Worker 		t_total += eventtab[i].time;
161*49cdfc7eSAndroid Build Coastguard Worker 
162*49cdfc7eSAndroid Build Coastguard Worker 	avgspd = ncycle / global_time;
163*49cdfc7eSAndroid Build Coastguard Worker 
164*49cdfc7eSAndroid Build Coastguard Worker 	v = t_total - MAGIC1;
165*49cdfc7eSAndroid Build Coastguard Worker 	if (v < 0.0)
166*49cdfc7eSAndroid Build Coastguard Worker 		v *= -1.0;
167*49cdfc7eSAndroid Build Coastguard Worker 
168*49cdfc7eSAndroid Build Coastguard Worker 	if (v > DIFF1) {
169*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TFAIL, "FAIL");
170*49cdfc7eSAndroid Build Coastguard Worker 		v = t_total - MAGIC1;
171*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "t_total = %.15f\n", t_total);
172*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "expected  %.15f\n", MAGIC1);
173*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "diff = %.15f\n", v);
174*49cdfc7eSAndroid Build Coastguard Worker 		tst_exit();
175*49cdfc7eSAndroid Build Coastguard Worker 	}
176*49cdfc7eSAndroid Build Coastguard Worker 
177*49cdfc7eSAndroid Build Coastguard Worker 	v = avgspd - MAGIC2;
178*49cdfc7eSAndroid Build Coastguard Worker 	if (v < 0.0)
179*49cdfc7eSAndroid Build Coastguard Worker 		v *= -1.0;
180*49cdfc7eSAndroid Build Coastguard Worker 
181*49cdfc7eSAndroid Build Coastguard Worker 	if (v > DIFF2) {
182*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TFAIL, "FAIL");
183*49cdfc7eSAndroid Build Coastguard Worker 		v = avgspd - MAGIC2;
184*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "avgspd  = %.15f\n", avgspd);
185*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "expected  %.15f\n", MAGIC2);
186*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "diff = %.15f\n", v);
187*49cdfc7eSAndroid Build Coastguard Worker 		tst_exit();
188*49cdfc7eSAndroid Build Coastguard Worker 	}
189*49cdfc7eSAndroid Build Coastguard Worker 	return (0);
190*49cdfc7eSAndroid Build Coastguard Worker }
191*49cdfc7eSAndroid Build Coastguard Worker 
192*49cdfc7eSAndroid Build Coastguard Worker /*
193*49cdfc7eSAndroid Build Coastguard Worker 	add an event to the event queue
194*49cdfc7eSAndroid Build Coastguard Worker */
addevent(int type,int proc,double t)195*49cdfc7eSAndroid Build Coastguard Worker static int addevent(int type, int proc, double t)
196*49cdfc7eSAndroid Build Coastguard Worker {
197*49cdfc7eSAndroid Build Coastguard Worker 	int i;
198*49cdfc7eSAndroid Build Coastguard Worker 	int ok = FALSE;
199*49cdfc7eSAndroid Build Coastguard Worker 
200*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 1; i <= nproc; i++) {
201*49cdfc7eSAndroid Build Coastguard Worker 		if (eventtab[i].type == NULLEVENT) {
202*49cdfc7eSAndroid Build Coastguard Worker 			eventtab[i].type = type;
203*49cdfc7eSAndroid Build Coastguard Worker 			eventtab[i].proc = proc;
204*49cdfc7eSAndroid Build Coastguard Worker 			eventtab[i].time = t;
205*49cdfc7eSAndroid Build Coastguard Worker 			ok = TRUE;
206*49cdfc7eSAndroid Build Coastguard Worker 			break;
207*49cdfc7eSAndroid Build Coastguard Worker 		}
208*49cdfc7eSAndroid Build Coastguard Worker 	}
209*49cdfc7eSAndroid Build Coastguard Worker 	if (ok)
210*49cdfc7eSAndroid Build Coastguard Worker 		return (0);
211*49cdfc7eSAndroid Build Coastguard Worker 	else
212*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK, NULL, "No room for event");
213*49cdfc7eSAndroid Build Coastguard Worker 	return (0);
214*49cdfc7eSAndroid Build Coastguard Worker }
215*49cdfc7eSAndroid Build Coastguard Worker 
216*49cdfc7eSAndroid Build Coastguard Worker /*
217*49cdfc7eSAndroid Build Coastguard Worker 	get earliest event in event queue
218*49cdfc7eSAndroid Build Coastguard Worker */
nextevent(void)219*49cdfc7eSAndroid Build Coastguard Worker static struct event *nextevent(void)
220*49cdfc7eSAndroid Build Coastguard Worker {
221*49cdfc7eSAndroid Build Coastguard Worker 	double mintime = BIG;
222*49cdfc7eSAndroid Build Coastguard Worker 	int imin = 0;
223*49cdfc7eSAndroid Build Coastguard Worker 	int i;
224*49cdfc7eSAndroid Build Coastguard Worker 
225*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 1; i <= nproc; i++) {
226*49cdfc7eSAndroid Build Coastguard Worker 		if (eventtab[i].type != NULLEVENT && eventtab[i].time < mintime) {
227*49cdfc7eSAndroid Build Coastguard Worker 			imin = i;
228*49cdfc7eSAndroid Build Coastguard Worker 			mintime = eventtab[i].time;
229*49cdfc7eSAndroid Build Coastguard Worker 		}
230*49cdfc7eSAndroid Build Coastguard Worker 	}
231*49cdfc7eSAndroid Build Coastguard Worker 
232*49cdfc7eSAndroid Build Coastguard Worker 	if (imin) {
233*49cdfc7eSAndroid Build Coastguard Worker 		rtrevent.type = eventtab[imin].type;
234*49cdfc7eSAndroid Build Coastguard Worker 		rtrevent.proc = eventtab[imin].proc;
235*49cdfc7eSAndroid Build Coastguard Worker 		rtrevent.time = eventtab[imin].time;
236*49cdfc7eSAndroid Build Coastguard Worker 		eventtab[imin].type = NULLEVENT;
237*49cdfc7eSAndroid Build Coastguard Worker 		return (&rtrevent);
238*49cdfc7eSAndroid Build Coastguard Worker 	} else
239*49cdfc7eSAndroid Build Coastguard Worker 		return (NULL);
240*49cdfc7eSAndroid Build Coastguard Worker }
241*49cdfc7eSAndroid Build Coastguard Worker 
242*49cdfc7eSAndroid Build Coastguard Worker /*
243*49cdfc7eSAndroid Build Coastguard Worker 	add a processor to the waiting queue
244*49cdfc7eSAndroid Build Coastguard Worker */
addwaiting(int p)245*49cdfc7eSAndroid Build Coastguard Worker static int addwaiting(int p)
246*49cdfc7eSAndroid Build Coastguard Worker {
247*49cdfc7eSAndroid Build Coastguard Worker 	waiting[++nwaiting] = p;
248*49cdfc7eSAndroid Build Coastguard Worker 	return (0);
249*49cdfc7eSAndroid Build Coastguard Worker }
250*49cdfc7eSAndroid Build Coastguard Worker 
251*49cdfc7eSAndroid Build Coastguard Worker /*
252*49cdfc7eSAndroid Build Coastguard Worker 	remove the next processor from the waiting queue
253*49cdfc7eSAndroid Build Coastguard Worker */
getwaiting(void)254*49cdfc7eSAndroid Build Coastguard Worker static int getwaiting(void)
255*49cdfc7eSAndroid Build Coastguard Worker {
256*49cdfc7eSAndroid Build Coastguard Worker 	if (nwaiting)
257*49cdfc7eSAndroid Build Coastguard Worker 		return (waiting[nwaiting--]);
258*49cdfc7eSAndroid Build Coastguard Worker 	else
259*49cdfc7eSAndroid Build Coastguard Worker 		return (0);
260*49cdfc7eSAndroid Build Coastguard Worker }
261*49cdfc7eSAndroid Build Coastguard Worker 
dtcrit(void)262*49cdfc7eSAndroid Build Coastguard Worker static double dtcrit(void)
263*49cdfc7eSAndroid Build Coastguard Worker {
264*49cdfc7eSAndroid Build Coastguard Worker 	return (dtc);
265*49cdfc7eSAndroid Build Coastguard Worker }
266*49cdfc7eSAndroid Build Coastguard Worker 
dtspinoff(void)267*49cdfc7eSAndroid Build Coastguard Worker static double dtspinoff(void)
268*49cdfc7eSAndroid Build Coastguard Worker {
269*49cdfc7eSAndroid Build Coastguard Worker 	return (dts);
270*49cdfc7eSAndroid Build Coastguard Worker }
271*49cdfc7eSAndroid Build Coastguard Worker 
dtwork(void)272*49cdfc7eSAndroid Build Coastguard Worker static double dtwork(void)
273*49cdfc7eSAndroid Build Coastguard Worker {
274*49cdfc7eSAndroid Build Coastguard Worker 	return (gauss());
275*49cdfc7eSAndroid Build Coastguard Worker }
276*49cdfc7eSAndroid Build Coastguard Worker 
277*49cdfc7eSAndroid Build Coastguard Worker /*
278*49cdfc7eSAndroid Build Coastguard Worker 	take the action prescribed by 'ev', update the clock, and
279*49cdfc7eSAndroid Build Coastguard Worker 	generate any subsequent events
280*49cdfc7eSAndroid Build Coastguard Worker */
doevent(struct event * ev)281*49cdfc7eSAndroid Build Coastguard Worker static int doevent(struct event *ev)
282*49cdfc7eSAndroid Build Coastguard Worker {
283*49cdfc7eSAndroid Build Coastguard Worker 	double nxttime;
284*49cdfc7eSAndroid Build Coastguard Worker 	int i, p, proc;
285*49cdfc7eSAndroid Build Coastguard Worker 
286*49cdfc7eSAndroid Build Coastguard Worker 	global_time = ev->time;
287*49cdfc7eSAndroid Build Coastguard Worker 	proc = ev->proc;
288*49cdfc7eSAndroid Build Coastguard Worker 
289*49cdfc7eSAndroid Build Coastguard Worker 	switch (ev->type) {
290*49cdfc7eSAndroid Build Coastguard Worker 	case TRYCRIT:
291*49cdfc7eSAndroid Build Coastguard Worker 		if (critfree == TRUE)
292*49cdfc7eSAndroid Build Coastguard Worker 			addevent(ENTERCRIT, proc, global_time);
293*49cdfc7eSAndroid Build Coastguard Worker 		else
294*49cdfc7eSAndroid Build Coastguard Worker 			addwaiting(proc);
295*49cdfc7eSAndroid Build Coastguard Worker 		break;
296*49cdfc7eSAndroid Build Coastguard Worker 	case ENTERCRIT:
297*49cdfc7eSAndroid Build Coastguard Worker 		critfree = FALSE;
298*49cdfc7eSAndroid Build Coastguard Worker 		nxttime = global_time + dtcrit();
299*49cdfc7eSAndroid Build Coastguard Worker 		addevent(LEAVECRIT, proc, nxttime);
300*49cdfc7eSAndroid Build Coastguard Worker 		break;
301*49cdfc7eSAndroid Build Coastguard Worker 	case LEAVECRIT:
302*49cdfc7eSAndroid Build Coastguard Worker 		critfree = TRUE;
303*49cdfc7eSAndroid Build Coastguard Worker 		addevent(ATBARRIER, proc, global_time);
304*49cdfc7eSAndroid Build Coastguard Worker 		if ((p = getwaiting()) != 0) {
305*49cdfc7eSAndroid Build Coastguard Worker 			nxttime = global_time;
306*49cdfc7eSAndroid Build Coastguard Worker 			addevent(ENTERCRIT, p, nxttime);
307*49cdfc7eSAndroid Build Coastguard Worker 		}
308*49cdfc7eSAndroid Build Coastguard Worker 		break;
309*49cdfc7eSAndroid Build Coastguard Worker 	case ATBARRIER:
310*49cdfc7eSAndroid Build Coastguard Worker 		barcnt++;
311*49cdfc7eSAndroid Build Coastguard Worker 		if (barcnt == nproc) {
312*49cdfc7eSAndroid Build Coastguard Worker 			nxttime = global_time;
313*49cdfc7eSAndroid Build Coastguard Worker 			for (i = 1; i <= nproc; i++) {
314*49cdfc7eSAndroid Build Coastguard Worker 				nxttime += dtspinoff();
315*49cdfc7eSAndroid Build Coastguard Worker 				addevent(ENTERWORK, i, nxttime);
316*49cdfc7eSAndroid Build Coastguard Worker 			}
317*49cdfc7eSAndroid Build Coastguard Worker 			barcnt = 0;
318*49cdfc7eSAndroid Build Coastguard Worker 			ncycle++;
319*49cdfc7eSAndroid Build Coastguard Worker 		}
320*49cdfc7eSAndroid Build Coastguard Worker 		break;
321*49cdfc7eSAndroid Build Coastguard Worker 	case ENTERWORK:
322*49cdfc7eSAndroid Build Coastguard Worker 		nxttime = global_time + dtwork();
323*49cdfc7eSAndroid Build Coastguard Worker 		if (ncycle < ncycmax)
324*49cdfc7eSAndroid Build Coastguard Worker 			addevent(LEAVEWORK, proc, nxttime);
325*49cdfc7eSAndroid Build Coastguard Worker 		break;
326*49cdfc7eSAndroid Build Coastguard Worker 	case LEAVEWORK:
327*49cdfc7eSAndroid Build Coastguard Worker 		addevent(TRYCRIT, proc, global_time);
328*49cdfc7eSAndroid Build Coastguard Worker 		break;
329*49cdfc7eSAndroid Build Coastguard Worker 	default:
330*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK, NULL, "Illegal event");
331*49cdfc7eSAndroid Build Coastguard Worker 		break;
332*49cdfc7eSAndroid Build Coastguard Worker 	}
333*49cdfc7eSAndroid Build Coastguard Worker 	return (0);
334*49cdfc7eSAndroid Build Coastguard Worker }
335*49cdfc7eSAndroid Build Coastguard Worker 
336*49cdfc7eSAndroid Build Coastguard Worker static int alternator = 1;
337*49cdfc7eSAndroid Build Coastguard Worker static double mean;
338*49cdfc7eSAndroid Build Coastguard Worker static double stdev;
339*49cdfc7eSAndroid Build Coastguard Worker static double u1, u2;
340*49cdfc7eSAndroid Build Coastguard Worker static double twopi;
341*49cdfc7eSAndroid Build Coastguard Worker 
gaussinit(double m,double s)342*49cdfc7eSAndroid Build Coastguard Worker static void gaussinit(double m, double s)
343*49cdfc7eSAndroid Build Coastguard Worker {
344*49cdfc7eSAndroid Build Coastguard Worker 	mean = m;
345*49cdfc7eSAndroid Build Coastguard Worker 	stdev = s;
346*49cdfc7eSAndroid Build Coastguard Worker 	twopi = 2. * acos((double)-1.0);
347*49cdfc7eSAndroid Build Coastguard Worker 	u1 = twopi / 400.0;
348*49cdfc7eSAndroid Build Coastguard Worker 	u2 = twopi / 500.0;
349*49cdfc7eSAndroid Build Coastguard Worker }
350*49cdfc7eSAndroid Build Coastguard Worker 
gauss(void)351*49cdfc7eSAndroid Build Coastguard Worker static double gauss(void)
352*49cdfc7eSAndroid Build Coastguard Worker {
353*49cdfc7eSAndroid Build Coastguard Worker 	double x1, x2;
354*49cdfc7eSAndroid Build Coastguard Worker 
355*49cdfc7eSAndroid Build Coastguard Worker 	gcount++;
356*49cdfc7eSAndroid Build Coastguard Worker 
357*49cdfc7eSAndroid Build Coastguard Worker 	u1 += u2;
358*49cdfc7eSAndroid Build Coastguard Worker 	if (u1 > 0.99)
359*49cdfc7eSAndroid Build Coastguard Worker 		u1 = twopi / 500.0;
360*49cdfc7eSAndroid Build Coastguard Worker 	u2 += u1;
361*49cdfc7eSAndroid Build Coastguard Worker 	if (u2 > 0.99)
362*49cdfc7eSAndroid Build Coastguard Worker 		u2 = twopi / 400.0;
363*49cdfc7eSAndroid Build Coastguard Worker 
364*49cdfc7eSAndroid Build Coastguard Worker 	if (alternator == 1) {
365*49cdfc7eSAndroid Build Coastguard Worker 		alternator = -1;
366*49cdfc7eSAndroid Build Coastguard Worker 		x1 = sqrt(-2.0 * log(u1)) * cos(twopi * u2);
367*49cdfc7eSAndroid Build Coastguard Worker 		return (mean + stdev * x1);
368*49cdfc7eSAndroid Build Coastguard Worker 	} else {
369*49cdfc7eSAndroid Build Coastguard Worker 		alternator = 1;
370*49cdfc7eSAndroid Build Coastguard Worker 		x2 = sqrt(-2.0 * log(u1)) * sin(twopi * u2);
371*49cdfc7eSAndroid Build Coastguard Worker 		return (mean + stdev * x2);
372*49cdfc7eSAndroid Build Coastguard Worker 	}
373*49cdfc7eSAndroid Build Coastguard Worker }
374