1f08c3bdfSopenharmony_ci/*
2f08c3bdfSopenharmony_ci *   Copyright (c) International Business Machines  Corp., 2001
3f08c3bdfSopenharmony_ci *
4f08c3bdfSopenharmony_ci *   This program is free software;  you can redistribute it and/or modify
5f08c3bdfSopenharmony_ci *   it under the terms of the GNU General Public License as published by
6f08c3bdfSopenharmony_ci *   the Free Software Foundation; either version 2 of the License, or
7f08c3bdfSopenharmony_ci *   (at your option) any later version.
8f08c3bdfSopenharmony_ci *
9f08c3bdfSopenharmony_ci *   This program is distributed in the hope that it will be useful,
10f08c3bdfSopenharmony_ci *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
11f08c3bdfSopenharmony_ci *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
12f08c3bdfSopenharmony_ci *   the GNU General Public License for more details.
13f08c3bdfSopenharmony_ci *
14f08c3bdfSopenharmony_ci *   You should have received a copy of the GNU General Public License
15f08c3bdfSopenharmony_ci *   along with this program;  if not, write to the Free Software
16f08c3bdfSopenharmony_ci *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17f08c3bdfSopenharmony_ci */
18f08c3bdfSopenharmony_ci/*---------------------------------------------------------------------+
19f08c3bdfSopenharmony_ci|                             sched_driver                             |
20f08c3bdfSopenharmony_ci| ==================================================================== |
21f08c3bdfSopenharmony_ci|                                                                      |
22f08c3bdfSopenharmony_ci| Description:  This program uses system calls to change the           |
23f08c3bdfSopenharmony_ci|               priorities of the throughput measurement testcases.    |
24f08c3bdfSopenharmony_ci|               When real-time is in effect, priorities 50 through 64  |
25f08c3bdfSopenharmony_ci|               are used.  (MAX_PRI and MIN_PRI)  When user-time       |
26f08c3bdfSopenharmony_ci|               (normal) is in effect, 0-14 (corresponding to nice()   |
27f08c3bdfSopenharmony_ci|               calls) is used.  The driver only keeps track of        |
28f08c3bdfSopenharmony_ci|               values from 50 to 64, and the testcases will scale     |
29f08c3bdfSopenharmony_ci|               them down to 0 to 14 when needed, to change the        |
30f08c3bdfSopenharmony_ci|               priority of a user-time process.                       |
31f08c3bdfSopenharmony_ci|                                                                      |
32f08c3bdfSopenharmony_ci| Algorithm:    o  Parse command line arguments                        |
33f08c3bdfSopenharmony_ci|               o  Set current priority                                |
34f08c3bdfSopenharmony_ci|               o  Calcucations (process slots, short/long term slots) |
35f08c3bdfSopenharmony_ci|               o  Perform throughput tests with high priority         |
36f08c3bdfSopenharmony_ci|               o  Start long-term testcases                           |
37f08c3bdfSopenharmony_ci|               o  While time remains                                  |
38f08c3bdfSopenharmony_ci|                  - Start short-term tests                            |
39f08c3bdfSopenharmony_ci|                  - Perform throughput tests with new priority        |
40f08c3bdfSopenharmony_ci|                  - Kill short-term tests                             |
41f08c3bdfSopenharmony_ci|                  - Increase priority                                 |
42f08c3bdfSopenharmony_ci|                                                                      |
43f08c3bdfSopenharmony_ci| Usage:        sched_driver [-s n] [-p n] [-t n] [-d] [-v]            |
44f08c3bdfSopenharmony_ci|                                                                      |
45f08c3bdfSopenharmony_ci|               where:                                                 |
46f08c3bdfSopenharmony_ci|                 -s n  stress percentage                              |
47f08c3bdfSopenharmony_ci|                 -p n  process slots                                  |
48f08c3bdfSopenharmony_ci|                 -t n  execution time in hours                        |
49f08c3bdfSopenharmony_ci|                 -d    enable debugging messages                      |
50f08c3bdfSopenharmony_ci|                 -v    Turn on verbose mode                           |
51f08c3bdfSopenharmony_ci|                                                                      |
52f08c3bdfSopenharmony_ci| Last update:   Ver. 1.15, 4/10/94 23:04:23                           |
53f08c3bdfSopenharmony_ci|                                                                      |
54f08c3bdfSopenharmony_ci| Change Activity                                                      |
55f08c3bdfSopenharmony_ci|                                                                      |
56f08c3bdfSopenharmony_ci|   Version  Date    Name  Reason                                      |
57f08c3bdfSopenharmony_ci|    0.1     072889  GEB   Initial draft                               |
58f08c3bdfSopenharmony_ci|    1.2     120793  JAT   Changes for AIX 4.1                         |
59f08c3bdfSopenharmony_ci|    1.3     041094  DJK   Rewrote protions...                         |
60f08c3bdfSopenharmony_ci|    1.4     010402  Manoj Iyer Ported to Linux                        |
61f08c3bdfSopenharmony_ci|                                                                      |
62f08c3bdfSopenharmony_ci+---------------------------------------------------------------------*/
63f08c3bdfSopenharmony_ci
64f08c3bdfSopenharmony_ci#include <sys/types.h>
65f08c3bdfSopenharmony_ci#include <unistd.h>
66f08c3bdfSopenharmony_ci#include <sys/wait.h>
67f08c3bdfSopenharmony_ci#include <string.h>
68f08c3bdfSopenharmony_ci#include <stdlib.h>
69f08c3bdfSopenharmony_ci#include <signal.h>
70f08c3bdfSopenharmony_ci#include <pwd.h>
71f08c3bdfSopenharmony_ci#include <time.h>
72f08c3bdfSopenharmony_ci#include <limits.h>
73f08c3bdfSopenharmony_ci#include "sched.h"
74f08c3bdfSopenharmony_ci
75f08c3bdfSopenharmony_ci/*
76f08c3bdfSopenharmony_ci * Defines:
77f08c3bdfSopenharmony_ci *
78f08c3bdfSopenharmony_ci * MAXPROCS: maximum number of processes
79f08c3bdfSopenharmony_ci *
80f08c3bdfSopenharmony_ci * PRIINC: priority step value
81f08c3bdfSopenharmony_ci *
82f08c3bdfSopenharmony_ci * MAX_PRI: highest priority to use
83f08c3bdfSopenharmony_ci *
84f08c3bdfSopenharmony_ci * MIN_PRI: lowest priority to use
85f08c3bdfSopenharmony_ci *
86f08c3bdfSopenharmony_ci * DEFAULT_STRESS_PERCENTAGE: stress percentage (process slot multiplier)
87f08c3bdfSopenharmony_ci *
88f08c3bdfSopenharmony_ci * DEFAULT_PROCESS_SLOTS: number of processes test driver will try and create
89f08c3bdfSopenharmony_ci *
90f08c3bdfSopenharmony_ci * DEFAULT_TIME: time (hours) for which this test driver will run
91f08c3bdfSopenharmony_ci *
92f08c3bdfSopenharmony_ci * USAGE: usage statement
93f08c3bdfSopenharmony_ci */
94f08c3bdfSopenharmony_ci#define MAXPROCS   100
95f08c3bdfSopenharmony_ci#define PRIINC     2
96f08c3bdfSopenharmony_ci#define MAX_PRI    55		/* was 50 */
97f08c3bdfSopenharmony_ci#define MIN_PRI    75		/* was 64 */
98f08c3bdfSopenharmony_ci#define DEFAULT_STRESS_PERCENTAGE	0.5
99f08c3bdfSopenharmony_ci#define DEFAULT_PROCESS_SLOTS		16
100f08c3bdfSopenharmony_ci#define DEFAULT_TIME			1.00
101f08c3bdfSopenharmony_ci#define USAGE "Usage:  %s  [-s n] [-p n] [-t n] [-d] [-v]              \n" \
102f08c3bdfSopenharmony_ci              "        -s n   stress percentage [0.0<n<1.0] (default 0.5) \n" \
103f08c3bdfSopenharmony_ci              "        -p n   process slots (default 16)                  \n" \
104f08c3bdfSopenharmony_ci              "        -t n   execution time in hours (default 1.0 hrs)   \n" \
105f08c3bdfSopenharmony_ci              "        -d     enable debugging messages                   \n" \
106f08c3bdfSopenharmony_ci              "        -v     Turn on verbose mode 	                  \n"
107f08c3bdfSopenharmony_ci
108f08c3bdfSopenharmony_ci/*
109f08c3bdfSopenharmony_ci * Global variables:
110f08c3bdfSopenharmony_ci *
111f08c3bdfSopenharmony_ci * stress_percent: stress percentage
112f08c3bdfSopenharmony_ci *
113f08c3bdfSopenharmony_ci * :
114f08c3bdfSopenharmony_ci *
115f08c3bdfSopenharmony_ci * execution_time: execution time in hours
116f08c3bdfSopenharmony_ci *
117f08c3bdfSopenharmony_ci * debug: (option flag) enables debugging messages
118f08c3bdfSopenharmony_ci */
119f08c3bdfSopenharmony_ciint numprocs,			/* number of process id's in table             */
120f08c3bdfSopenharmony_ci procs[MAXPROCS],		/* array of process id's for killing           */
121f08c3bdfSopenharmony_ci long_running,			/* number of long term testcases running       */
122f08c3bdfSopenharmony_ci short_running;			/* number of short term testcases running      */
123f08c3bdfSopenharmony_cifloat e4user,			/* previous elapsed seconds for tc 4-user      */
124f08c3bdfSopenharmony_ci e4real,			/* previous elapsed seconds for tc 4-real      */
125f08c3bdfSopenharmony_ci e5user,			/* previous elapsed seconds for tc 5-user      */
126f08c3bdfSopenharmony_ci e5real,			/* previous elapsed seconds for tc 5-real      */
127f08c3bdfSopenharmony_ci e6user0,			/* previous elapsed seconds for tc 6-user,nf   */
128f08c3bdfSopenharmony_ci e6real0,			/* previous elapsed seconds for tc 6-real,nf   */
129f08c3bdfSopenharmony_ci e6user1,			/* previous elapsed seconds for tc 6-user,f    */
130f08c3bdfSopenharmony_ci e6child;			/* previous elapsed seconds for tc 6-child     */
131f08c3bdfSopenharmony_cidouble stress_percent = DEFAULT_STRESS_PERCENTAGE;
132f08c3bdfSopenharmony_cidouble execution_time = DEFAULT_TIME;
133f08c3bdfSopenharmony_ciint process_slots = DEFAULT_PROCESS_SLOTS;
134f08c3bdfSopenharmony_ciint debug = 0;
135f08c3bdfSopenharmony_ci
136f08c3bdfSopenharmony_ci/*
137f08c3bdfSopenharmony_ci * Function prototypes
138f08c3bdfSopenharmony_ci */
139f08c3bdfSopenharmony_civoid startup(long);
140f08c3bdfSopenharmony_ciint start_testcase(char *, char *, char *, char *, char *, char *);
141f08c3bdfSopenharmony_ciint process_slots_in_use();
142f08c3bdfSopenharmony_ciint available_user_process_slots();
143f08c3bdfSopenharmony_cifloat measure_test(char *, char *, char *, char *, float *);
144f08c3bdfSopenharmony_civoid display_line(char *, int, int, float, float *, int);
145f08c3bdfSopenharmony_civoid perform_throughput_tests(int);
146f08c3bdfSopenharmony_civoid start_long_term_testcases(int, char *);
147f08c3bdfSopenharmony_civoid kill_short_term_testcases();
148f08c3bdfSopenharmony_civoid start_short_term_testcases(int, double, int);
149f08c3bdfSopenharmony_civoid finishup(long);
150f08c3bdfSopenharmony_civoid parse_args(int, char **);
151f08c3bdfSopenharmony_ci
152f08c3bdfSopenharmony_ci/*---------------------------------------------------------------------+
153f08c3bdfSopenharmony_ci|                               main ()                                |
154f08c3bdfSopenharmony_ci| ==================================================================== |
155f08c3bdfSopenharmony_ci|                                                                      |
156f08c3bdfSopenharmony_ci| Function:  Main program                                              |
157f08c3bdfSopenharmony_ci|                                                                      |
158f08c3bdfSopenharmony_ci+---------------------------------------------------------------------*/
159f08c3bdfSopenharmony_ciint main(int argc, char **argv)
160f08c3bdfSopenharmony_ci{
161f08c3bdfSopenharmony_ci	long runseconds,	/* number of seconds to run */
162f08c3bdfSopenharmony_ci	 start_time;		/* time at start of driver */
163f08c3bdfSopenharmony_ci	int current_priority,	/* current priority level for nice */
164f08c3bdfSopenharmony_ci	 workslots,		/* number of free workslots */
165f08c3bdfSopenharmony_ci	 long_term_slot_total,	/* workslots for long-term processes */
166f08c3bdfSopenharmony_ci	 short_term_slot_total;	/* workslots for short-term */
167f08c3bdfSopenharmony_ci
168f08c3bdfSopenharmony_ci	/*
169f08c3bdfSopenharmony_ci	 * Parse command line arguments & printer program header...
170f08c3bdfSopenharmony_ci	 */
171f08c3bdfSopenharmony_ci	parse_args(argc, argv);
172f08c3bdfSopenharmony_ci	printf("Scheduler Testsuite Program\n\n");
173f08c3bdfSopenharmony_ci	fflush(stdout);
174f08c3bdfSopenharmony_ci
175f08c3bdfSopenharmony_ci	/*
176f08c3bdfSopenharmony_ci	 * Calculate number of seconds to run, then print out start info
177f08c3bdfSopenharmony_ci	 */
178f08c3bdfSopenharmony_ci	runseconds = (long)(execution_time * 60.0 * 60.0);
179f08c3bdfSopenharmony_ci	start_time = time(NULL);
180f08c3bdfSopenharmony_ci
181f08c3bdfSopenharmony_ci	startup(start_time);
182f08c3bdfSopenharmony_ci
183f08c3bdfSopenharmony_ci	/*
184f08c3bdfSopenharmony_ci	 * Calculate available workslots, long-term, and short-term slots
185f08c3bdfSopenharmony_ci	 */
186f08c3bdfSopenharmony_ci	workslots = available_user_process_slots() * stress_percent;
187f08c3bdfSopenharmony_ci	long_term_slot_total = workslots / 2;
188f08c3bdfSopenharmony_ci	if (debug) {
189f08c3bdfSopenharmony_ci		printf("available slots:      %d\n",
190f08c3bdfSopenharmony_ci		       available_user_process_slots());
191f08c3bdfSopenharmony_ci		printf("workslots available:  %d\n", workslots);
192f08c3bdfSopenharmony_ci		printf("stress_percent:       %f\n", stress_percent);
193f08c3bdfSopenharmony_ci		printf("run-hours:            %f (hrs)\n", execution_time);
194f08c3bdfSopenharmony_ci		printf("runseconds:           %ld (sec)\n", runseconds);
195f08c3bdfSopenharmony_ci	}
196f08c3bdfSopenharmony_ci
197f08c3bdfSopenharmony_ci	/*
198f08c3bdfSopenharmony_ci	 * Run the first set of tests with an average priority
199f08c3bdfSopenharmony_ci	 */
200f08c3bdfSopenharmony_ci	perform_throughput_tests((MAX_PRI + MIN_PRI) / 2);
201f08c3bdfSopenharmony_ci	fflush(stdout);
202f08c3bdfSopenharmony_ci
203f08c3bdfSopenharmony_ci	/*
204f08c3bdfSopenharmony_ci	 * Start the long-term testcases running
205f08c3bdfSopenharmony_ci	 */
206f08c3bdfSopenharmony_ci	start_long_term_testcases(long_term_slot_total, argv[2]);
207f08c3bdfSopenharmony_ci	short_term_slot_total = workslots / 2;
208f08c3bdfSopenharmony_ci	fflush(stdout);
209f08c3bdfSopenharmony_ci
210f08c3bdfSopenharmony_ci	/*
211f08c3bdfSopenharmony_ci	 * Loop while there is still time
212f08c3bdfSopenharmony_ci	 */
213f08c3bdfSopenharmony_ci	current_priority = MAX_PRI;
214f08c3bdfSopenharmony_ci	while ((time(0) - start_time) < runseconds) {
215f08c3bdfSopenharmony_ci
216f08c3bdfSopenharmony_ci		if (debug)
217f08c3bdfSopenharmony_ci			printf("current priority: %d\n", current_priority);
218f08c3bdfSopenharmony_ci		if (debug)
219f08c3bdfSopenharmony_ci			printf("starting short term tests\n");
220f08c3bdfSopenharmony_ci
221f08c3bdfSopenharmony_ci		start_short_term_testcases(short_term_slot_total,
222f08c3bdfSopenharmony_ci					   stress_percent, current_priority);
223f08c3bdfSopenharmony_ci		fflush(stdout);
224f08c3bdfSopenharmony_ci
225f08c3bdfSopenharmony_ci		perform_throughput_tests(current_priority);
226f08c3bdfSopenharmony_ci		fflush(stdout);
227f08c3bdfSopenharmony_ci
228f08c3bdfSopenharmony_ci		if (debug)
229f08c3bdfSopenharmony_ci			printf("killing short term tests\n");
230f08c3bdfSopenharmony_ci
231f08c3bdfSopenharmony_ci		kill_short_term_testcases();
232f08c3bdfSopenharmony_ci		fflush(stdout);
233f08c3bdfSopenharmony_ci
234f08c3bdfSopenharmony_ci		if (current_priority + PRIINC > MIN_PRI)
235f08c3bdfSopenharmony_ci			current_priority = MAX_PRI;
236f08c3bdfSopenharmony_ci		else
237f08c3bdfSopenharmony_ci			current_priority += PRIINC;
238f08c3bdfSopenharmony_ci	}
239f08c3bdfSopenharmony_ci
240f08c3bdfSopenharmony_ci	/*
241f08c3bdfSopenharmony_ci	 * Exit with success...
242f08c3bdfSopenharmony_ci	 */
243f08c3bdfSopenharmony_ci	finishup(start_time);
244f08c3bdfSopenharmony_ci	printf("\nsuccessful!\n");
245f08c3bdfSopenharmony_ci	fflush(stdout);
246f08c3bdfSopenharmony_ci	return (0);
247f08c3bdfSopenharmony_ci}
248f08c3bdfSopenharmony_ci
249f08c3bdfSopenharmony_ci/*------------------------------ startup() ------------------------------*/
250f08c3bdfSopenharmony_ci/* This procedure opens the , and then outputs some starting	 *
251f08c3bdfSopenharmony_ci * information to the screen and .  It also initializes the	 *
252f08c3bdfSopenharmony_ci * process id list and other global variables.	 			 *
253f08c3bdfSopenharmony_ci *-----------------------------------------------------------------------*/
254f08c3bdfSopenharmony_civoid startup(long start_time)
255f08c3bdfSopenharmony_ci{
256f08c3bdfSopenharmony_ci	char tempbuffer[50];	/* temporary buffer to hold names */
257f08c3bdfSopenharmony_ci
258f08c3bdfSopenharmony_ci	/*
259f08c3bdfSopenharmony_ci	 * Now output some diagnostic information
260f08c3bdfSopenharmony_ci	 */
261f08c3bdfSopenharmony_ci	printf("start time    = %s\n", ctime(&start_time));
262f08c3bdfSopenharmony_ci
263f08c3bdfSopenharmony_ci	gethostname(tempbuffer, 40);
264f08c3bdfSopenharmony_ci	printf("host name     = %s\n", tempbuffer);
265f08c3bdfSopenharmony_ci
266f08c3bdfSopenharmony_ci	printf("user name     = %s\n", getpwuid(geteuid())->pw_name);
267f08c3bdfSopenharmony_ci
268f08c3bdfSopenharmony_ci	printf("test duration = %4.2f (hours)\n", execution_time);
269f08c3bdfSopenharmony_ci
270f08c3bdfSopenharmony_ci	printf("test stress   = %4.2f%%%%\n\n", 100 * stress_percent);
271f08c3bdfSopenharmony_ci
272f08c3bdfSopenharmony_ci	/*
273f08c3bdfSopenharmony_ci	 * Initialize the global variables
274f08c3bdfSopenharmony_ci	 */
275f08c3bdfSopenharmony_ci	numprocs = 0;
276f08c3bdfSopenharmony_ci	long_running = 0;
277f08c3bdfSopenharmony_ci	short_running = 0;
278f08c3bdfSopenharmony_ci	e4user = 0.0;
279f08c3bdfSopenharmony_ci	e4real = 0.0;
280f08c3bdfSopenharmony_ci	e5user = 0.0;
281f08c3bdfSopenharmony_ci	e5real = 0.0;
282f08c3bdfSopenharmony_ci	e6user0 = 0.0;
283f08c3bdfSopenharmony_ci	e6real0 = 0.0;
284f08c3bdfSopenharmony_ci	e6user1 = 0.0;
285f08c3bdfSopenharmony_ci	e6child = 0.0;
286f08c3bdfSopenharmony_ci}
287f08c3bdfSopenharmony_ci
288f08c3bdfSopenharmony_ci/*--------------------------- start_testcase() --------------------------*/
289f08c3bdfSopenharmony_ci/* This procedure will run a specified testcase by forking a process, and*
290f08c3bdfSopenharmony_ci * then running the testcase with it.  It will also store the process id *
291f08c3bdfSopenharmony_ci * number in the process id table.  The process id of the child process  *
292f08c3bdfSopenharmony_ci * is returned to the calling program.					 *
293f08c3bdfSopenharmony_ci *	name1     pathname of testcase to run			         *
294f08c3bdfSopenharmony_ci *	name2     filename of testcase to run			         *
295f08c3bdfSopenharmony_ci *	param1    parameters to pass to the testcase			 *
296f08c3bdfSopenharmony_ci *	param2 			         			         *
297f08c3bdfSopenharmony_ci *	param3 			         			         *
298f08c3bdfSopenharmony_ci *	param4    if sched_tc6:  fork flag:  0=false, 1=true             *
299f08c3bdfSopenharmony_ci *-----------------------------------------------------------------------*/
300f08c3bdfSopenharmony_ci
301f08c3bdfSopenharmony_ciint start_testcase(char *name1, char *name2, char *param1, char *param2,
302f08c3bdfSopenharmony_ci		   char *param3, char *param4)
303f08c3bdfSopenharmony_ci{
304f08c3bdfSopenharmony_ci	int pid,		/* pid of currently running process */
305f08c3bdfSopenharmony_ci	 pid_save;		/* saved pid of process */
306f08c3bdfSopenharmony_ci
307f08c3bdfSopenharmony_ci	/*
308f08c3bdfSopenharmony_ci	 * Fork a process that will run testcase and save the pid
309f08c3bdfSopenharmony_ci	 */
310f08c3bdfSopenharmony_ci	if (debug)
311f08c3bdfSopenharmony_ci		printf("test: %s %s p1[%s] p2[%s] p3[%s] p4[%s]\n",
312f08c3bdfSopenharmony_ci		       name1, name2, param1, param2, param3, param4);
313f08c3bdfSopenharmony_ci
314f08c3bdfSopenharmony_ci	pid_save = pid = fork();
315f08c3bdfSopenharmony_ci
316f08c3bdfSopenharmony_ci	/*
317f08c3bdfSopenharmony_ci	 * If the pid returned is -1, fork failed.  If the pid returned is
318f08c3bdfSopenharmony_ci	 * 0, then the process running is the child process, and we need
319f08c3bdfSopenharmony_ci	 * to do an 'execl' to run the testcase.  If the pid returned is
320f08c3bdfSopenharmony_ci	 * anything else, then the parent is running, and we return.
321f08c3bdfSopenharmony_ci	 */
322f08c3bdfSopenharmony_ci	switch (pid) {
323f08c3bdfSopenharmony_ci	case -1:
324f08c3bdfSopenharmony_ci		exit(-1);
325f08c3bdfSopenharmony_ci	case 0:
326f08c3bdfSopenharmony_ci		execl(name1, name2, param1, param2, param3, param4, NULL);
327f08c3bdfSopenharmony_ci		printf("ERROR: start_testcase():  execl failed.\n");
328f08c3bdfSopenharmony_ci		exit(-1);
329f08c3bdfSopenharmony_ci	default:
330f08c3bdfSopenharmony_ci		break;
331f08c3bdfSopenharmony_ci	}
332f08c3bdfSopenharmony_ci	if (debug)
333f08c3bdfSopenharmony_ci		printf("testcase %s started -- pid is %d\n", name2, pid_save);
334f08c3bdfSopenharmony_ci
335f08c3bdfSopenharmony_ci	/*
336f08c3bdfSopenharmony_ci	 * If the process just forked is for a short-term testcase, then
337f08c3bdfSopenharmony_ci	 * add the process id to the table.
338f08c3bdfSopenharmony_ci	 */
339f08c3bdfSopenharmony_ci	if (debug)
340f08c3bdfSopenharmony_ci		printf("new process: %s ", name2);
341f08c3bdfSopenharmony_ci	if (strstr(name2, "tc1") || strstr(name2, "tc3")) {
342f08c3bdfSopenharmony_ci		procs[numprocs] = pid_save;
343f08c3bdfSopenharmony_ci		numprocs++;
344f08c3bdfSopenharmony_ci		short_running++;
345f08c3bdfSopenharmony_ci		if (debug)
346f08c3bdfSopenharmony_ci			printf("(%d short term)", short_running);
347f08c3bdfSopenharmony_ci	}
348f08c3bdfSopenharmony_ci	if (strstr(name2, "tc0") || strstr(name2, "tc2")) {
349f08c3bdfSopenharmony_ci		long_running++;
350f08c3bdfSopenharmony_ci		if (debug)
351f08c3bdfSopenharmony_ci			printf("(%d long term)", long_running);
352f08c3bdfSopenharmony_ci	}
353f08c3bdfSopenharmony_ci	if (debug)
354f08c3bdfSopenharmony_ci		printf("\n");
355f08c3bdfSopenharmony_ci
356f08c3bdfSopenharmony_ci	return (pid_save);
357f08c3bdfSopenharmony_ci}
358f08c3bdfSopenharmony_ci
359f08c3bdfSopenharmony_ci/*------------------------- process_slots_in_use() ----------------------*/
360f08c3bdfSopenharmony_ci/* This function will return the number of process slots currently in use*
361f08c3bdfSopenharmony_ci * by executing the 'ps' command.					 *
362f08c3bdfSopenharmony_ci *-----------------------------------------------------------------------*/
363f08c3bdfSopenharmony_ciint process_slots_in_use()
364f08c3bdfSopenharmony_ci{
365f08c3bdfSopenharmony_ci	FILE *psfile;		/* temporary file to hold output of 'ps' command */
366f08c3bdfSopenharmony_ci	int usedslots;		/* holds the number of used process slots */
367f08c3bdfSopenharmony_ci
368f08c3bdfSopenharmony_ci	/*
369f08c3bdfSopenharmony_ci	 * Call the 'ps' command and write the number of process slots to a file
370f08c3bdfSopenharmony_ci	 */
371f08c3bdfSopenharmony_ci	if (system("ps -e | wc -l > ps.out") < 0)
372f08c3bdfSopenharmony_ci		sys_error("system failed", __FILE__, __LINE__);
373f08c3bdfSopenharmony_ci
374f08c3bdfSopenharmony_ci	/*
375f08c3bdfSopenharmony_ci	 * Open the output file
376f08c3bdfSopenharmony_ci	 */
377f08c3bdfSopenharmony_ci	if ((psfile = fopen("ps.out", "r")) == NULL) {
378f08c3bdfSopenharmony_ci		exit(-1);
379f08c3bdfSopenharmony_ci	}
380f08c3bdfSopenharmony_ci
381f08c3bdfSopenharmony_ci	/*
382f08c3bdfSopenharmony_ci	 * Read the number of process slots in use from the file
383f08c3bdfSopenharmony_ci	 */
384f08c3bdfSopenharmony_ci	fscanf(psfile, "%d", &usedslots);
385f08c3bdfSopenharmony_ci
386f08c3bdfSopenharmony_ci	/*
387f08c3bdfSopenharmony_ci	 * Close the output file
388f08c3bdfSopenharmony_ci	 */
389f08c3bdfSopenharmony_ci	if (fclose(psfile) == -1) {
390f08c3bdfSopenharmony_ci		exit(-1);
391f08c3bdfSopenharmony_ci	}
392f08c3bdfSopenharmony_ci
393f08c3bdfSopenharmony_ci	/*
394f08c3bdfSopenharmony_ci	 * Remove the output file
395f08c3bdfSopenharmony_ci	 */
396f08c3bdfSopenharmony_ci	if (system("/bin/rm ps.out") < 0)
397f08c3bdfSopenharmony_ci		sys_error("system failed", __FILE__, __LINE__);
398f08c3bdfSopenharmony_ci
399f08c3bdfSopenharmony_ci	return (usedslots - 1);
400f08c3bdfSopenharmony_ci}
401f08c3bdfSopenharmony_ci
402f08c3bdfSopenharmony_ci/*----------------------- available_user_process_slots() ----------------*/
403f08c3bdfSopenharmony_ci/* This function returns the total number of available user process slots*
404f08c3bdfSopenharmony_ci * by subtracting the process slots currently in use from the maximum	 *
405f08c3bdfSopenharmony_ci * possible process slots.						 *
406f08c3bdfSopenharmony_ci *-----------------------------------------------------------------------*/
407f08c3bdfSopenharmony_ciint available_user_process_slots()
408f08c3bdfSopenharmony_ci{
409f08c3bdfSopenharmony_ci	int num = process_slots_in_use();
410f08c3bdfSopenharmony_ci
411f08c3bdfSopenharmony_ci	return ((process_slots < num) ? process_slots : process_slots - num);
412f08c3bdfSopenharmony_ci}
413f08c3bdfSopenharmony_ci
414f08c3bdfSopenharmony_ci/*---------------------------- measure_test() ---------------------------*/
415f08c3bdfSopenharmony_ci/* This function executes a throughput measurement process and waits for *
416f08c3bdfSopenharmony_ci * that process to finish.  When finished, it reads the result from a 	 *
417f08c3bdfSopenharmony_ci * file and returns that result to the caller.  The file is then deleted.*
418f08c3bdfSopenharmony_ci * If sched_tc6 is called, then the second time is also read from the	 *
419f08c3bdfSopenharmony_ci * results file and returned to the caller.				 *
420f08c3bdfSopenharmony_ci *-----------------------------------------------------------------------*/
421f08c3bdfSopenharmony_cifloat measure_test(name, param1, param2, param3, t2)
422f08c3bdfSopenharmony_cichar *name,			/* filename of testcase to run */
423f08c3bdfSopenharmony_ci*param1,			/* user flag:  0=user, 1=real time */
424f08c3bdfSopenharmony_ci*param2,			/* priority to run the throughput test at */
425f08c3bdfSopenharmony_ci*param3;			/* if sched_tc6:  fork flag, 0=false, 1=true */
426f08c3bdfSopenharmony_cifloat *t2;			/* if sched_tc6:  second time returned from testcase */
427f08c3bdfSopenharmony_ci{
428f08c3bdfSopenharmony_ci	char temp[PATH_MAX],	/* holds pathname and returned floating number */
429f08c3bdfSopenharmony_ci	 t2asc[50];		/* holds second returned floating number */
430f08c3bdfSopenharmony_ci	int saved_pid;		/* process id of forked process */
431f08c3bdfSopenharmony_ci	FILE *datafile;		/* file pointer for temporary file */
432f08c3bdfSopenharmony_ci
433f08c3bdfSopenharmony_ci	/*
434f08c3bdfSopenharmony_ci	 * Create the path name to be passed to the start_testcase() function
435f08c3bdfSopenharmony_ci	 */
436f08c3bdfSopenharmony_ci	sprintf(temp, "./%s", name);
437f08c3bdfSopenharmony_ci
438f08c3bdfSopenharmony_ci	/*
439f08c3bdfSopenharmony_ci	 * Send all the parameters, and start the testcase
440f08c3bdfSopenharmony_ci	 */
441f08c3bdfSopenharmony_ci	saved_pid = start_testcase(temp, name, param1,
442f08c3bdfSopenharmony_ci				   "-lsch.measure", param2, param3);
443f08c3bdfSopenharmony_ci
444f08c3bdfSopenharmony_ci	/*
445f08c3bdfSopenharmony_ci	 * Wait for the testcase to finish
446f08c3bdfSopenharmony_ci	 */
447f08c3bdfSopenharmony_ci	if (debug)
448f08c3bdfSopenharmony_ci		printf("waiting on child %d\n", saved_pid);
449f08c3bdfSopenharmony_ci	while (wait(NULL) != saved_pid) ;
450f08c3bdfSopenharmony_ci
451f08c3bdfSopenharmony_ci	/*
452f08c3bdfSopenharmony_ci	 * Open the temporary file to get the returned number of seconds
453f08c3bdfSopenharmony_ci	 */
454f08c3bdfSopenharmony_ci
455f08c3bdfSopenharmony_ci	if ((datafile = fopen("sch.measure", "r")) == NULL) {
456f08c3bdfSopenharmony_ci		sys_error("cannot open sch.measure", __FILE__, __LINE__);
457f08c3bdfSopenharmony_ci	}
458f08c3bdfSopenharmony_ci
459f08c3bdfSopenharmony_ci	/*
460f08c3bdfSopenharmony_ci	 * Read the number of seconds
461f08c3bdfSopenharmony_ci	 */
462f08c3bdfSopenharmony_ci	fgets(temp, 50, datafile);
463f08c3bdfSopenharmony_ci	/*added by mpt
464f08c3bdfSopenharmony_ci	   printf("sched+driver: measure_test: number of seconds=%s\n",temp)
465f08c3bdfSopenharmony_ci	   *********** */
466f08c3bdfSopenharmony_ci
467f08c3bdfSopenharmony_ci	/*
468f08c3bdfSopenharmony_ci	 * If this is sched_tc6, then there is another number we must return
469f08c3bdfSopenharmony_ci	 */
470f08c3bdfSopenharmony_ci
471f08c3bdfSopenharmony_ci	if (strcmp(name, "sched_tc6") == 0) {
472f08c3bdfSopenharmony_ci		fgets(t2asc, 50, datafile);
473f08c3bdfSopenharmony_ci		*t2 = atof(t2asc);
474f08c3bdfSopenharmony_ci	}
475f08c3bdfSopenharmony_ci
476f08c3bdfSopenharmony_ci	/*
477f08c3bdfSopenharmony_ci	 * Close the temporary file
478f08c3bdfSopenharmony_ci	 */
479f08c3bdfSopenharmony_ci	if (fclose(datafile) != 0) {
480f08c3bdfSopenharmony_ci		exit(-1);
481f08c3bdfSopenharmony_ci	}
482f08c3bdfSopenharmony_ci
483f08c3bdfSopenharmony_ci	/*
484f08c3bdfSopenharmony_ci	 * Now try to remove the temporary file
485f08c3bdfSopenharmony_ci	 */
486f08c3bdfSopenharmony_ci	/*added by MPT
487f08c3bdfSopenharmony_ci	   printf("measure_test:  REMOVING sch.measure\n");
488f08c3bdfSopenharmony_ci	   fflush(stdout);
489f08c3bdfSopenharmony_ci	   if  (system ("rm sch.measure") < 0)
490f08c3bdfSopenharmony_ci	   sys_error ("system failed", __FILE__, __LINE__);
491f08c3bdfSopenharmony_ci	 */
492f08c3bdfSopenharmony_ci	return (atof(temp));
493f08c3bdfSopenharmony_ci}
494f08c3bdfSopenharmony_ci
495f08c3bdfSopenharmony_ci/*------------------------- display_line() ------------------------------*/
496f08c3bdfSopenharmony_ci/* This procedure displays a line of output given the results of a	 *
497f08c3bdfSopenharmony_ci * throughput test.  It displays the testcase name, the current priority *
498f08c3bdfSopenharmony_ci * level, the user/real time flag, and the elapsed time in seconds, as	 *
499f08c3bdfSopenharmony_ci * well as the percent change between the current and previous times.	 *
500f08c3bdfSopenharmony_ci * It then updates the previous elapsed time to be the current one.	 *
501f08c3bdfSopenharmony_ci *-----------------------------------------------------------------------*/
502f08c3bdfSopenharmony_civoid display_line(char *tcname, int pri, int f, float et, float *pet, int ff)
503f08c3bdfSopenharmony_ci{
504f08c3bdfSopenharmony_ci	static int display_header = 0;
505f08c3bdfSopenharmony_ci	float pc;		/* holds percent change */
506f08c3bdfSopenharmony_ci
507f08c3bdfSopenharmony_ci	/*
508f08c3bdfSopenharmony_ci	 * Print header every eight lines...
509f08c3bdfSopenharmony_ci	 */
510f08c3bdfSopenharmony_ci	if (display_header-- == 0) {
511f08c3bdfSopenharmony_ci		printf("\n  Test                Processes              "
512f08c3bdfSopenharmony_ci		       "  Time        Notes\n"
513f08c3bdfSopenharmony_ci		       "---------   ---------------------------   "
514f08c3bdfSopenharmony_ci		       "---------------  -------\n"
515f08c3bdfSopenharmony_ci		       "name        long  short  priority  mode   "
516f08c3bdfSopenharmony_ci		       "elapsed  %%%%delta\n\n");
517f08c3bdfSopenharmony_ci		display_header = 6;
518f08c3bdfSopenharmony_ci	}
519f08c3bdfSopenharmony_ci
520f08c3bdfSopenharmony_ci	/*
521f08c3bdfSopenharmony_ci	 * Calculate the percent change in time
522f08c3bdfSopenharmony_ci	 */
523f08c3bdfSopenharmony_ci	pc = (*pet == 0.0) ? 0.0 : 100.0 * ((et - *pet) / *pet) + 0.05;
524f08c3bdfSopenharmony_ci
525f08c3bdfSopenharmony_ci	printf("%-12s %2d    %2d      %2d      %4s   %06.4f  %+06.4f  %s\n",
526f08c3bdfSopenharmony_ci	       tcname, long_running, short_running, pri,
527f08c3bdfSopenharmony_ci	       (f == 0) ? "user" : "real", et, pc, (ff) ? "forked child" : " ");
528f08c3bdfSopenharmony_ci
529f08c3bdfSopenharmony_ci	fflush(stdout);
530f08c3bdfSopenharmony_ci
531f08c3bdfSopenharmony_ci	*pet = et;
532f08c3bdfSopenharmony_ci}
533f08c3bdfSopenharmony_ci
534f08c3bdfSopenharmony_ci/*------------------------- perform_throughput_tests() ------------------*/
535f08c3bdfSopenharmony_ci/* This procedure is called each time throughput tests are to be	 *
536f08c3bdfSopenharmony_ci * performed.  This procedure executes each of the throughput tests, and *
537f08c3bdfSopenharmony_ci * records the results of each to the .	 			 *
538f08c3bdfSopenharmony_ci *-----------------------------------------------------------------------*/
539f08c3bdfSopenharmony_civoid perform_throughput_tests(int current_priority)
540f08c3bdfSopenharmony_ci{
541f08c3bdfSopenharmony_ci	float esecs,		/* elapsed seconds returned from each testcase */
542f08c3bdfSopenharmony_ci	 esecs2,		/* elapsed seconds (second part) for sched_tc6 */
543f08c3bdfSopenharmony_ci	 pc;			/* percent change for sched_tc6 */
544f08c3bdfSopenharmony_ci	char pristr[10];	/* holds ascii value of priority as parameter */
545f08c3bdfSopenharmony_ci
546f08c3bdfSopenharmony_ci	sprintf(pristr, "-p%d", current_priority);
547f08c3bdfSopenharmony_ci
548f08c3bdfSopenharmony_ci#if defined(_IA64) && !defined(__64BIT__)
549f08c3bdfSopenharmony_ci	esecs =
550f08c3bdfSopenharmony_ci	    measure_test("sched_tc4.32", "-tvariable", pristr, NULL, &esecs2);
551f08c3bdfSopenharmony_ci	display_line("sched_tc4.32", current_priority, 0, esecs, &e4user, 2);
552f08c3bdfSopenharmony_ci	esecs = measure_test("sched_tc4.32", "-tfixed", pristr, NULL, &esecs2);
553f08c3bdfSopenharmony_ci	display_line("sched_tc4.32", current_priority, 1, esecs, &e4real, 2);
554f08c3bdfSopenharmony_ci	esecs =
555f08c3bdfSopenharmony_ci	    measure_test("sched_tc5.32", "-tvariable", pristr, NULL, &esecs2);
556f08c3bdfSopenharmony_ci	display_line("sched_tc5.32", current_priority, 0, esecs, &e5user, 2);
557f08c3bdfSopenharmony_ci	esecs = measure_test("sched_tc5.32", "-tfixed", pristr, NULL, &esecs2);
558f08c3bdfSopenharmony_ci	display_line("sched_tc5.32", current_priority, 1, esecs, &e5real, 2);
559f08c3bdfSopenharmony_ci	esecs =
560f08c3bdfSopenharmony_ci	    measure_test("sched_tc6.32", "-tvariable", pristr, " -d ", &esecs2);
561f08c3bdfSopenharmony_ci	display_line("sched_tc6.32", current_priority, 0, esecs, &e6user0, 0);
562f08c3bdfSopenharmony_ci	esecs =
563f08c3bdfSopenharmony_ci	    measure_test("sched_tc6.32", "-tfixed", pristr, " -d ", &esecs2);
564f08c3bdfSopenharmony_ci	display_line("sched_tc6.32", current_priority, 1, esecs, &e6real0, 0);
565f08c3bdfSopenharmony_ci	esecs =
566f08c3bdfSopenharmony_ci	    measure_test("sched_tc6.32", "-tvariable", pristr, " -df ",
567f08c3bdfSopenharmony_ci			 &esecs2);
568f08c3bdfSopenharmony_ci	display_line("sched_tc6.32", current_priority, 0, esecs, &e6user1, 1);
569f08c3bdfSopenharmony_ci#else
570f08c3bdfSopenharmony_ci	esecs = measure_test("sched_tc4", "-tvariable", pristr, NULL, &esecs2);
571f08c3bdfSopenharmony_ci	display_line("sched_tc4", current_priority, 0, esecs, &e4user, 2);
572f08c3bdfSopenharmony_ci	esecs = measure_test("sched_tc4", "-tfixed", pristr, NULL, &esecs2);
573f08c3bdfSopenharmony_ci	display_line("sched_tc4", current_priority, 1, esecs, &e4real, 2);
574f08c3bdfSopenharmony_ci	esecs = measure_test("sched_tc5", "-tvariable", pristr, NULL, &esecs2);
575f08c3bdfSopenharmony_ci	display_line("sched_tc5", current_priority, 0, esecs, &e5user, 2);
576f08c3bdfSopenharmony_ci	esecs = measure_test("sched_tc5", "-tfixed", pristr, NULL, &esecs2);
577f08c3bdfSopenharmony_ci	display_line("sched_tc5", current_priority, 1, esecs, &e5real, 2);
578f08c3bdfSopenharmony_ci	esecs =
579f08c3bdfSopenharmony_ci	    measure_test("sched_tc6", "-tvariable", pristr, " -d ", &esecs2);
580f08c3bdfSopenharmony_ci	display_line("sched_tc6", current_priority, 0, esecs, &e6user0, 0);
581f08c3bdfSopenharmony_ci	esecs = measure_test("sched_tc6", "-tfixed", pristr, " -d ", &esecs2);
582f08c3bdfSopenharmony_ci	display_line("sched_tc6", current_priority, 1, esecs, &e6real0, 0);
583f08c3bdfSopenharmony_ci	esecs =
584f08c3bdfSopenharmony_ci	    measure_test("sched_tc6", "-tvariable", pristr, " -df ", &esecs2);
585f08c3bdfSopenharmony_ci	display_line("sched_tc6", current_priority, 0, esecs, &e6user1, 1);
586f08c3bdfSopenharmony_ci#endif
587f08c3bdfSopenharmony_ci
588f08c3bdfSopenharmony_ci	/*
589f08c3bdfSopenharmony_ci	 * Manually build the display line for the second part of sched_tc6
590f08c3bdfSopenharmony_ci	 */
591f08c3bdfSopenharmony_ci
592f08c3bdfSopenharmony_ci	/*
593f08c3bdfSopenharmony_ci	 * Calculate the percent change in time
594f08c3bdfSopenharmony_ci	 */
595f08c3bdfSopenharmony_ci	pc = (e6child ==
596f08c3bdfSopenharmony_ci	      0.0) ? 0.0 : 100 * ((esecs2 - e6child) / e6child) + 0.05;
597f08c3bdfSopenharmony_ci	printf("%-12s forked child          %4s   %06.4f  %+06.4f\n",
598f08c3bdfSopenharmony_ci	       "sched_tc6", "real", esecs2, pc);
599f08c3bdfSopenharmony_ci	e6child = esecs2;
600f08c3bdfSopenharmony_ci}
601f08c3bdfSopenharmony_ci
602f08c3bdfSopenharmony_ci/*------------------------ start_long_term_testcases() ------------------*/
603f08c3bdfSopenharmony_ci/* This procedure takes the number of long-term process slots available, *
604f08c3bdfSopenharmony_ci * and executes the long term testcases.				 *
605f08c3bdfSopenharmony_ci *-----------------------------------------------------------------------*/
606f08c3bdfSopenharmony_civoid start_long_term_testcases(long_term_slot_total, execution_time)
607f08c3bdfSopenharmony_ciint long_term_slot_total;	/* total number of long-term slots */
608f08c3bdfSopenharmony_cichar *execution_time;		/* runtime hours to pass to each testcase */
609f08c3bdfSopenharmony_ci{
610f08c3bdfSopenharmony_ci	int i;
611f08c3bdfSopenharmony_ci
612f08c3bdfSopenharmony_ci	/*
613f08c3bdfSopenharmony_ci	 * Now use up the long_term_slot_total by starting testcases call
614f08c3bdfSopenharmony_ci	 * half with real-time flag '1' set, other half user flag '0'
615f08c3bdfSopenharmony_ci	 */
616f08c3bdfSopenharmony_ci	if (debug)
617f08c3bdfSopenharmony_ci		printf("long-term slots available:  %d\n",
618f08c3bdfSopenharmony_ci		       long_term_slot_total);
619f08c3bdfSopenharmony_ci
620f08c3bdfSopenharmony_ci	for (i = 0; i < (long_term_slot_total / 4); i++) {
621f08c3bdfSopenharmony_ci#if defined(_IA64) && !defined(__64BIT__)
622f08c3bdfSopenharmony_ci		start_testcase("./sched_tc0.32", "sched_tc0 -t", execution_time,
623f08c3bdfSopenharmony_ci			       " -p1", NULL, NULL);
624f08c3bdfSopenharmony_ci		start_testcase("./sched_tc2.32", "sched_tc2", execution_time,
625f08c3bdfSopenharmony_ci			       "1", NULL, NULL);
626f08c3bdfSopenharmony_ci		start_testcase("./sched_tc0.32", "sched_tc0 -t", execution_time,
627f08c3bdfSopenharmony_ci			       " -p0", NULL, NULL);
628f08c3bdfSopenharmony_ci		start_testcase("./sched_tc2.32", "sched_tc2", execution_time,
629f08c3bdfSopenharmony_ci			       "0", NULL, NULL);
630f08c3bdfSopenharmony_ci#else
631f08c3bdfSopenharmony_ci		start_testcase("./sched_tc0", "sched_tc0 -t", execution_time,
632f08c3bdfSopenharmony_ci			       " -p1", NULL, NULL);
633f08c3bdfSopenharmony_ci		start_testcase("./sched_tc2", "sched_tc2", execution_time, "1",
634f08c3bdfSopenharmony_ci			       NULL, NULL);
635f08c3bdfSopenharmony_ci		start_testcase("./sched_tc0", "sched_tc0 -t", execution_time,
636f08c3bdfSopenharmony_ci			       " -p0", NULL, NULL);
637f08c3bdfSopenharmony_ci		start_testcase("./sched_tc2", "sched_tc2", execution_time, "0",
638f08c3bdfSopenharmony_ci			       NULL, NULL);
639f08c3bdfSopenharmony_ci#endif
640f08c3bdfSopenharmony_ci	}
641f08c3bdfSopenharmony_ci}
642f08c3bdfSopenharmony_ci
643f08c3bdfSopenharmony_ci/*---------------------------------------------------------------------+
644f08c3bdfSopenharmony_ci|                     start_short_term_testcases ()                    |
645f08c3bdfSopenharmony_ci| ==================================================================== |
646f08c3bdfSopenharmony_ci|                                                                      |
647f08c3bdfSopenharmony_ci| Function:  Starts short term testcases (one for each process slot)   |
648f08c3bdfSopenharmony_ci|                                                                      |
649f08c3bdfSopenharmony_ci+---------------------------------------------------------------------*/
650f08c3bdfSopenharmony_civoid start_short_term_testcases(int short_term_slot_total,
651f08c3bdfSopenharmony_ci				double stress_percent, int pri)
652f08c3bdfSopenharmony_ci{
653f08c3bdfSopenharmony_ci	int i;
654f08c3bdfSopenharmony_ci	int short_term_slots;	/* number of slots to use */
655f08c3bdfSopenharmony_ci
656f08c3bdfSopenharmony_ci	/*
657f08c3bdfSopenharmony_ci	 * Set up the short_term_slot_total by starting testcases call
658f08c3bdfSopenharmony_ci	 * half with real-time flag '1' set, other half user flag '0'
659f08c3bdfSopenharmony_ci	 */
660f08c3bdfSopenharmony_ci	if (available_user_process_slots() < short_term_slot_total)
661f08c3bdfSopenharmony_ci		short_term_slots =
662f08c3bdfSopenharmony_ci		    available_user_process_slots() * stress_percent / 2;
663f08c3bdfSopenharmony_ci	else
664f08c3bdfSopenharmony_ci		short_term_slots = short_term_slot_total;
665f08c3bdfSopenharmony_ci
666f08c3bdfSopenharmony_ci	printf("\n<< Starting %d short-term testcases>> \n\n",
667f08c3bdfSopenharmony_ci	       short_term_slots);
668f08c3bdfSopenharmony_ci	if (debug)
669f08c3bdfSopenharmony_ci		printf("short-term slots available:  %d\n", short_term_slots);
670f08c3bdfSopenharmony_ci
671f08c3bdfSopenharmony_ci	for (i = 0; i < (short_term_slots / 4); i++) {
672f08c3bdfSopenharmony_ci#if defined(_IA64) && !defined(__64BIT__)
673f08c3bdfSopenharmony_ci		start_testcase("./sched_tc1.32", "sched_tc1", "1", NULL, NULL,
674f08c3bdfSopenharmony_ci			       NULL);
675f08c3bdfSopenharmony_ci		start_testcase("./sched_tc3.32", "sched_tc3", "1", NULL, NULL,
676f08c3bdfSopenharmony_ci			       NULL);
677f08c3bdfSopenharmony_ci		start_testcase("./sched_tc1.32", "sched_tc1", "0", NULL, NULL,
678f08c3bdfSopenharmony_ci			       NULL);
679f08c3bdfSopenharmony_ci		start_testcase("./sched_tc3.32", "sched_tc3", "0", NULL, NULL,
680f08c3bdfSopenharmony_ci			       NULL);
681f08c3bdfSopenharmony_ci#else
682f08c3bdfSopenharmony_ci		start_testcase("./sched_tc1", "sched_tc1", "1", NULL, NULL,
683f08c3bdfSopenharmony_ci			       NULL);
684f08c3bdfSopenharmony_ci		start_testcase("./sched_tc3", "sched_tc3", "1", NULL, NULL,
685f08c3bdfSopenharmony_ci			       NULL);
686f08c3bdfSopenharmony_ci		start_testcase("./sched_tc1", "sched_tc1", "0", NULL, NULL,
687f08c3bdfSopenharmony_ci			       NULL);
688f08c3bdfSopenharmony_ci		start_testcase("./sched_tc3", "sched_tc3", "0", NULL, NULL,
689f08c3bdfSopenharmony_ci			       NULL);
690f08c3bdfSopenharmony_ci#endif
691f08c3bdfSopenharmony_ci#if 0
692f08c3bdfSopenharmony_ci		perform_throughput_tests(pri);
693f08c3bdfSopenharmony_ci#endif
694f08c3bdfSopenharmony_ci	}
695f08c3bdfSopenharmony_ci}
696f08c3bdfSopenharmony_ci
697f08c3bdfSopenharmony_ci/*------------------------ kill_short_term_testcases() ------------------*/
698f08c3bdfSopenharmony_ci/* This procedure goes through the process id table, and sends each	 *
699f08c3bdfSopenharmony_ci * process id number found in the table a signal in order to terminate	 *
700f08c3bdfSopenharmony_ci * it.  The signal sent is SIGUSR1.  It also re-initializes the table.	 *
701f08c3bdfSopenharmony_ci *-----------------------------------------------------------------------*/
702f08c3bdfSopenharmony_civoid kill_short_term_testcases()
703f08c3bdfSopenharmony_ci{
704f08c3bdfSopenharmony_ci	int i;			/* loop counter to step through the list of process id's */
705f08c3bdfSopenharmony_ci
706f08c3bdfSopenharmony_ci	/*
707f08c3bdfSopenharmony_ci	 * Loop through the array of process id's one at a time, and
708f08c3bdfSopenharmony_ci	 * attempt to kill each one.  If kill fails, report error and
709f08c3bdfSopenharmony_ci	 * continue.
710f08c3bdfSopenharmony_ci	 */
711f08c3bdfSopenharmony_ci	if (debug)
712f08c3bdfSopenharmony_ci		printf("killing short-term processes...\n");
713f08c3bdfSopenharmony_ci	for (i = 0; i < numprocs; i++) {
714f08c3bdfSopenharmony_ci		if (debug)
715f08c3bdfSopenharmony_ci			printf("killing process [%d]\n", procs[i]);
716f08c3bdfSopenharmony_ci		kill(procs[i], SIGUSR1);
717f08c3bdfSopenharmony_ci	}
718f08c3bdfSopenharmony_ci
719f08c3bdfSopenharmony_ci	/*
720f08c3bdfSopenharmony_ci	 * Adjust the number of short_term_testcases
721f08c3bdfSopenharmony_ci	 */
722f08c3bdfSopenharmony_ci	short_running -= numprocs;
723f08c3bdfSopenharmony_ci
724f08c3bdfSopenharmony_ci	/*
725f08c3bdfSopenharmony_ci	 * Clear the table by setting number of entries to zero
726f08c3bdfSopenharmony_ci	 */
727f08c3bdfSopenharmony_ci	numprocs = 0;
728f08c3bdfSopenharmony_ci}
729f08c3bdfSopenharmony_ci
730f08c3bdfSopenharmony_ci/*----------------------------- finishup() ------------------------------*/
731f08c3bdfSopenharmony_ci/* This procedure closing information to the about ending	 *
732f08c3bdfSopenharmony_ci * times, elapsed times, etc.  This procedure then closes the file*
733f08c3bdfSopenharmony_ci *-----------------------------------------------------------------------*/
734f08c3bdfSopenharmony_civoid finishup(start_time)
735f08c3bdfSopenharmony_cilong start_time;		/* starting time to calculate elapsed time */
736f08c3bdfSopenharmony_ci{
737f08c3bdfSopenharmony_ci	long end_time;		/* time when program finished */
738f08c3bdfSopenharmony_ci
739f08c3bdfSopenharmony_ci	/*
740f08c3bdfSopenharmony_ci	 * Get the end time and calculate elapsed time; write all this out
741f08c3bdfSopenharmony_ci	 */
742f08c3bdfSopenharmony_ci	end_time = time(NULL);
743f08c3bdfSopenharmony_ci
744f08c3bdfSopenharmony_ci	printf("\nend time = %s\n", ctime(&end_time));
745f08c3bdfSopenharmony_ci
746f08c3bdfSopenharmony_ci	printf("elapsed time = %4.2f hours\n",
747f08c3bdfSopenharmony_ci	       ((end_time - start_time) / 3600.0));
748f08c3bdfSopenharmony_ci}
749f08c3bdfSopenharmony_ci
750f08c3bdfSopenharmony_ci/*---------------------------------------------------------------------+
751f08c3bdfSopenharmony_ci|                             parse_args ()                            |
752f08c3bdfSopenharmony_ci| ==================================================================== |
753f08c3bdfSopenharmony_ci|                                                                      |
754f08c3bdfSopenharmony_ci| Function:  Parse the command line arguments & initialize global      |
755f08c3bdfSopenharmony_ci|            variables.                                                |
756f08c3bdfSopenharmony_ci|                                                                      |
757f08c3bdfSopenharmony_ci| Updates:   (command line options)                                    |
758f08c3bdfSopenharmony_ci|                                                                      |
759f08c3bdfSopenharmony_ci|            [-s] size: shared memory segment size                     |
760f08c3bdfSopenharmony_ci|                                                                      |
761f08c3bdfSopenharmony_ci+---------------------------------------------------------------------*/
762f08c3bdfSopenharmony_civoid parse_args(int argc, char **argv)
763f08c3bdfSopenharmony_ci{
764f08c3bdfSopenharmony_ci	int opt;
765f08c3bdfSopenharmony_ci	int sflg = 0, pflg = 0, tflg = 0;
766f08c3bdfSopenharmony_ci	int errflag = 0;
767f08c3bdfSopenharmony_ci	char *program_name = *argv;
768f08c3bdfSopenharmony_ci	extern char *optarg;	/* Command line option */
769f08c3bdfSopenharmony_ci
770f08c3bdfSopenharmony_ci	/*
771f08c3bdfSopenharmony_ci	 * Parse command line options.
772f08c3bdfSopenharmony_ci	 */
773f08c3bdfSopenharmony_ci	while ((opt = getopt(argc, argv, "vs:p:t:l:d")) != EOF) {
774f08c3bdfSopenharmony_ci		switch (opt) {
775f08c3bdfSopenharmony_ci		case 's':	/* stress percentage */
776f08c3bdfSopenharmony_ci			sflg++;
777f08c3bdfSopenharmony_ci			stress_percent = atof(optarg);
778f08c3bdfSopenharmony_ci			break;
779f08c3bdfSopenharmony_ci		case 'p':	/* process slots */
780f08c3bdfSopenharmony_ci			pflg++;
781f08c3bdfSopenharmony_ci			process_slots = atof(optarg);
782f08c3bdfSopenharmony_ci			break;
783f08c3bdfSopenharmony_ci		case 't':	/* time (hours) */
784f08c3bdfSopenharmony_ci			tflg++;
785f08c3bdfSopenharmony_ci			execution_time = atof(optarg);
786f08c3bdfSopenharmony_ci			break;
787f08c3bdfSopenharmony_ci		case 'd':	/* Enable debugging messages */
788f08c3bdfSopenharmony_ci			debug++;
789f08c3bdfSopenharmony_ci			break;
790f08c3bdfSopenharmony_ci		case 'v':	/* Enable verbose mode=debug mode */
791f08c3bdfSopenharmony_ci			debug++;
792f08c3bdfSopenharmony_ci			break;
793f08c3bdfSopenharmony_ci		default:
794f08c3bdfSopenharmony_ci			errflag++;
795f08c3bdfSopenharmony_ci			break;
796f08c3bdfSopenharmony_ci		}
797f08c3bdfSopenharmony_ci	}
798f08c3bdfSopenharmony_ci
799f08c3bdfSopenharmony_ci	/*
800f08c3bdfSopenharmony_ci	 * Check percentage, execution time and process slots...
801f08c3bdfSopenharmony_ci	 */
802f08c3bdfSopenharmony_ci	if (sflg) {
803f08c3bdfSopenharmony_ci		if (stress_percent < 0.0 || stress_percent > 1.0)
804f08c3bdfSopenharmony_ci			errflag++;
805f08c3bdfSopenharmony_ci	}
806f08c3bdfSopenharmony_ci	if (pflg) {
807f08c3bdfSopenharmony_ci		if (process_slots < 0 || process_slots > MAXPROCS)
808f08c3bdfSopenharmony_ci			errflag++;
809f08c3bdfSopenharmony_ci	}
810f08c3bdfSopenharmony_ci	if (tflg) {
811f08c3bdfSopenharmony_ci		if (execution_time < 0.0 || execution_time > 100.0)
812f08c3bdfSopenharmony_ci			errflag++;
813f08c3bdfSopenharmony_ci	}
814f08c3bdfSopenharmony_ci	if (debug)
815f08c3bdfSopenharmony_ci		printf("\n(debugging messages enabled)\n\n");
816f08c3bdfSopenharmony_ci	if (errflag) {
817f08c3bdfSopenharmony_ci		fprintf(stderr, USAGE, program_name);
818f08c3bdfSopenharmony_ci		exit(2);
819f08c3bdfSopenharmony_ci	}
820f08c3bdfSopenharmony_ci}
821