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