1*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************
2*49cdfc7eSAndroid Build Coastguard Worker *
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright © International Business Machines Corp., 2006, 2008
4*49cdfc7eSAndroid Build Coastguard Worker *
5*49cdfc7eSAndroid Build Coastguard Worker * This program is free software; you can redistribute it and/or modify
6*49cdfc7eSAndroid Build Coastguard Worker * it under the terms of the GNU General Public License as published by
7*49cdfc7eSAndroid Build Coastguard Worker * the Free Software Foundation; either version 2 of the License, or
8*49cdfc7eSAndroid Build Coastguard Worker * (at your option) any later version.
9*49cdfc7eSAndroid Build Coastguard Worker *
10*49cdfc7eSAndroid Build Coastguard Worker * This program is distributed in the hope that it will be useful,
11*49cdfc7eSAndroid Build Coastguard Worker * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*49cdfc7eSAndroid Build Coastguard Worker * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13*49cdfc7eSAndroid Build Coastguard Worker * the GNU General Public License for more details.
14*49cdfc7eSAndroid Build Coastguard Worker *
15*49cdfc7eSAndroid Build Coastguard Worker * You should have received a copy of the GNU General Public License
16*49cdfc7eSAndroid Build Coastguard Worker * along with this program; if not, write to the Free Software
17*49cdfc7eSAndroid Build Coastguard Worker * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*49cdfc7eSAndroid Build Coastguard Worker *
19*49cdfc7eSAndroid Build Coastguard Worker * NAME
20*49cdfc7eSAndroid Build Coastguard Worker * testpi-7.c
21*49cdfc7eSAndroid Build Coastguard Worker *
22*49cdfc7eSAndroid Build Coastguard Worker * DESCRIPTION
23*49cdfc7eSAndroid Build Coastguard Worker * measure the latency involved with PI boosting.
24*49cdfc7eSAndroid Build Coastguard Worker *
25*49cdfc7eSAndroid Build Coastguard Worker *
26*49cdfc7eSAndroid Build Coastguard Worker * USAGE:
27*49cdfc7eSAndroid Build Coastguard Worker * Use run_auto.sh script in current directory to build and run test.
28*49cdfc7eSAndroid Build Coastguard Worker *
29*49cdfc7eSAndroid Build Coastguard Worker * AUTHOR
30*49cdfc7eSAndroid Build Coastguard Worker * Darren Hart <[email protected]>
31*49cdfc7eSAndroid Build Coastguard Worker *
32*49cdfc7eSAndroid Build Coastguard Worker * HISTORY
33*49cdfc7eSAndroid Build Coastguard Worker * 2006-May-3: Initial version by Darren Hart <[email protected]>
34*49cdfc7eSAndroid Build Coastguard Worker * 2006-May-4: Timing fixes reported by Vernon Mauery <[email protected]>
35*49cdfc7eSAndroid Build Coastguard Worker * 2006-May-4: Made the med prio threads RT by Darren Hart <[email protected]>
36*49cdfc7eSAndroid Build Coastguard Worker * 2006-May-5: Modified to use flagging by Vernon Mauery <[email protected]>
37*49cdfc7eSAndroid Build Coastguard Worker *
38*49cdfc7eSAndroid Build Coastguard Worker *****************************************************************************/
39*49cdfc7eSAndroid Build Coastguard Worker
40*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
41*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
42*49cdfc7eSAndroid Build Coastguard Worker #include <math.h>
43*49cdfc7eSAndroid Build Coastguard Worker #include <librttest.h>
44*49cdfc7eSAndroid Build Coastguard Worker
45*49cdfc7eSAndroid Build Coastguard Worker #define HIGH_PRIO 15
46*49cdfc7eSAndroid Build Coastguard Worker #define MED_PRIO 10
47*49cdfc7eSAndroid Build Coastguard Worker #define LOW_PRIO 5
48*49cdfc7eSAndroid Build Coastguard Worker
49*49cdfc7eSAndroid Build Coastguard Worker #define ITERATIONS 100
50*49cdfc7eSAndroid Build Coastguard Worker
51*49cdfc7eSAndroid Build Coastguard Worker #define MED_WORK_MS 20
52*49cdfc7eSAndroid Build Coastguard Worker #define NS_PER_MS 1000000
53*49cdfc7eSAndroid Build Coastguard Worker
54*49cdfc7eSAndroid Build Coastguard Worker static int use_flag_mutex;
55*49cdfc7eSAndroid Build Coastguard Worker static int max_delay_us;
56*49cdfc7eSAndroid Build Coastguard Worker static int max_drop2grab_us;
57*49cdfc7eSAndroid Build Coastguard Worker
58*49cdfc7eSAndroid Build Coastguard Worker static pthread_mutex_t pi_mutex;
59*49cdfc7eSAndroid Build Coastguard Worker
60*49cdfc7eSAndroid Build Coastguard Worker // flagging details
61*49cdfc7eSAndroid Build Coastguard Worker typedef enum {
62*49cdfc7eSAndroid Build Coastguard Worker LOW_START_CYCLE = 1, // 1
63*49cdfc7eSAndroid Build Coastguard Worker MED_START_WORK, // 2
64*49cdfc7eSAndroid Build Coastguard Worker HIGH_GRAB_MUTEX, // 3
65*49cdfc7eSAndroid Build Coastguard Worker LOW_DROP_MUTEX, // 4
66*49cdfc7eSAndroid Build Coastguard Worker END_OF_CYCLE, // 5
67*49cdfc7eSAndroid Build Coastguard Worker END_OF_GAME // 6
68*49cdfc7eSAndroid Build Coastguard Worker } phase_t;
69*49cdfc7eSAndroid Build Coastguard Worker
70*49cdfc7eSAndroid Build Coastguard Worker static volatile phase_t phase_flag = END_OF_CYCLE;
71*49cdfc7eSAndroid Build Coastguard Worker
72*49cdfc7eSAndroid Build Coastguard Worker static pthread_mutex_t flag_mutex;
73*49cdfc7eSAndroid Build Coastguard Worker
74*49cdfc7eSAndroid Build Coastguard Worker int med_threads = 0;
75*49cdfc7eSAndroid Build Coastguard Worker long iterations = ITERATIONS;
76*49cdfc7eSAndroid Build Coastguard Worker
usage(void)77*49cdfc7eSAndroid Build Coastguard Worker void usage(void)
78*49cdfc7eSAndroid Build Coastguard Worker {
79*49cdfc7eSAndroid Build Coastguard Worker rt_help();
80*49cdfc7eSAndroid Build Coastguard Worker printf("testpi-7 specific options:\n");
81*49cdfc7eSAndroid Build Coastguard Worker printf(" -i# #: number of iterations\n");
82*49cdfc7eSAndroid Build Coastguard Worker printf(" -f #: Use flag mutex\n");
83*49cdfc7eSAndroid Build Coastguard Worker printf(" -x# #:number of mid priority threads\n");
84*49cdfc7eSAndroid Build Coastguard Worker }
85*49cdfc7eSAndroid Build Coastguard Worker
parse_args(int c,char * v)86*49cdfc7eSAndroid Build Coastguard Worker int parse_args(int c, char *v)
87*49cdfc7eSAndroid Build Coastguard Worker {
88*49cdfc7eSAndroid Build Coastguard Worker int handled = 1;
89*49cdfc7eSAndroid Build Coastguard Worker switch (c) {
90*49cdfc7eSAndroid Build Coastguard Worker case 'f':
91*49cdfc7eSAndroid Build Coastguard Worker use_flag_mutex = 0;
92*49cdfc7eSAndroid Build Coastguard Worker break;
93*49cdfc7eSAndroid Build Coastguard Worker case 'h':
94*49cdfc7eSAndroid Build Coastguard Worker usage();
95*49cdfc7eSAndroid Build Coastguard Worker exit(0);
96*49cdfc7eSAndroid Build Coastguard Worker case 'i':
97*49cdfc7eSAndroid Build Coastguard Worker iterations = atoi(v);
98*49cdfc7eSAndroid Build Coastguard Worker break;
99*49cdfc7eSAndroid Build Coastguard Worker case 'x':
100*49cdfc7eSAndroid Build Coastguard Worker med_threads = atoi(v);
101*49cdfc7eSAndroid Build Coastguard Worker break;
102*49cdfc7eSAndroid Build Coastguard Worker default:
103*49cdfc7eSAndroid Build Coastguard Worker handled = 0;
104*49cdfc7eSAndroid Build Coastguard Worker break;
105*49cdfc7eSAndroid Build Coastguard Worker }
106*49cdfc7eSAndroid Build Coastguard Worker return handled;
107*49cdfc7eSAndroid Build Coastguard Worker }
108*49cdfc7eSAndroid Build Coastguard Worker
_read_flag(const char * s,int l)109*49cdfc7eSAndroid Build Coastguard Worker phase_t _read_flag(const char *s, int l)
110*49cdfc7eSAndroid Build Coastguard Worker {
111*49cdfc7eSAndroid Build Coastguard Worker phase_t ret;
112*49cdfc7eSAndroid Build Coastguard Worker if (use_flag_mutex)
113*49cdfc7eSAndroid Build Coastguard Worker pthread_mutex_lock(&flag_mutex);
114*49cdfc7eSAndroid Build Coastguard Worker ret = phase_flag;
115*49cdfc7eSAndroid Build Coastguard Worker debug(DBG_DEBUG, "%s:%d: read_flag = %s (%d)\n", s, l,
116*49cdfc7eSAndroid Build Coastguard Worker (ret == LOW_START_CYCLE ? "LOW_START_CYCLE" : ret ==
117*49cdfc7eSAndroid Build Coastguard Worker MED_START_WORK ? "MED_START_WORK" : ret ==
118*49cdfc7eSAndroid Build Coastguard Worker HIGH_GRAB_MUTEX ? "HIGH_GRAB_MUTEX" : ret ==
119*49cdfc7eSAndroid Build Coastguard Worker LOW_DROP_MUTEX ? "LOW_DROP_MUTEX" : ret ==
120*49cdfc7eSAndroid Build Coastguard Worker END_OF_CYCLE ? "END_OF_CYCLE" : "ERROR"), ret);
121*49cdfc7eSAndroid Build Coastguard Worker //debug(DBG_DEBUG, "%s:%d: read_flag = %d\n", s, l, ret);
122*49cdfc7eSAndroid Build Coastguard Worker if (use_flag_mutex)
123*49cdfc7eSAndroid Build Coastguard Worker pthread_mutex_unlock(&flag_mutex);
124*49cdfc7eSAndroid Build Coastguard Worker return ret;
125*49cdfc7eSAndroid Build Coastguard Worker }
126*49cdfc7eSAndroid Build Coastguard Worker
_write_flag(const char * s,int l,phase_t new_flag)127*49cdfc7eSAndroid Build Coastguard Worker void _write_flag(const char *s, int l, phase_t new_flag)
128*49cdfc7eSAndroid Build Coastguard Worker {
129*49cdfc7eSAndroid Build Coastguard Worker if (use_flag_mutex)
130*49cdfc7eSAndroid Build Coastguard Worker pthread_mutex_lock(&flag_mutex);
131*49cdfc7eSAndroid Build Coastguard Worker if (phase_flag != END_OF_GAME) {
132*49cdfc7eSAndroid Build Coastguard Worker if (new_flag != phase_flag && new_flag != (phase_flag + 1)
133*49cdfc7eSAndroid Build Coastguard Worker && !(new_flag == LOW_START_CYCLE
134*49cdfc7eSAndroid Build Coastguard Worker && phase_flag == END_OF_CYCLE))
135*49cdfc7eSAndroid Build Coastguard Worker printf("YOU'RE HOSED: new_flag=%d, phase_flag=%d\n",
136*49cdfc7eSAndroid Build Coastguard Worker new_flag, phase_flag);
137*49cdfc7eSAndroid Build Coastguard Worker phase_flag = new_flag;
138*49cdfc7eSAndroid Build Coastguard Worker debug(DBG_DEBUG, "phase_flag: %s set it to %d\n", s,
139*49cdfc7eSAndroid Build Coastguard Worker phase_flag);
140*49cdfc7eSAndroid Build Coastguard Worker debug(DBG_DEBUG, "%s:%d: write_flag = %s (%d)\n", s, l,
141*49cdfc7eSAndroid Build Coastguard Worker (new_flag ==
142*49cdfc7eSAndroid Build Coastguard Worker LOW_START_CYCLE ? "LOW_START_CYCLE" : new_flag ==
143*49cdfc7eSAndroid Build Coastguard Worker MED_START_WORK ? "MED_START_WORK" : new_flag ==
144*49cdfc7eSAndroid Build Coastguard Worker HIGH_GRAB_MUTEX ? "HIGH_GRAB_MUTEX" : new_flag ==
145*49cdfc7eSAndroid Build Coastguard Worker LOW_DROP_MUTEX ? "LOW_DROP_MUTEX" : new_flag ==
146*49cdfc7eSAndroid Build Coastguard Worker END_OF_CYCLE ? "END_OF_CYCLE" : "ERROR"), new_flag);
147*49cdfc7eSAndroid Build Coastguard Worker //debug(DBG_DEBUG, "%s:%d: write_flag = %d\n", s, l, new_flag);
148*49cdfc7eSAndroid Build Coastguard Worker }
149*49cdfc7eSAndroid Build Coastguard Worker if (use_flag_mutex)
150*49cdfc7eSAndroid Build Coastguard Worker pthread_mutex_unlock(&flag_mutex);
151*49cdfc7eSAndroid Build Coastguard Worker }
152*49cdfc7eSAndroid Build Coastguard Worker
153*49cdfc7eSAndroid Build Coastguard Worker #define read_flag(A) _read_flag(__FUNCTION__,__LINE__)
154*49cdfc7eSAndroid Build Coastguard Worker #define write_flag(A) _write_flag(__FUNCTION__,__LINE__,A)
155*49cdfc7eSAndroid Build Coastguard Worker
156*49cdfc7eSAndroid Build Coastguard Worker #define while_not_flag(A,B) while (read_flag() != (A) && !thread_quit(B))
157*49cdfc7eSAndroid Build Coastguard Worker
158*49cdfc7eSAndroid Build Coastguard Worker static nsec_t low_drop_time;
low_prio_rt_thread(void * arg)159*49cdfc7eSAndroid Build Coastguard Worker void *low_prio_rt_thread(void *arg)
160*49cdfc7eSAndroid Build Coastguard Worker {
161*49cdfc7eSAndroid Build Coastguard Worker struct thread *t = (struct thread *)arg;
162*49cdfc7eSAndroid Build Coastguard Worker while (!thread_quit(t)) {
163*49cdfc7eSAndroid Build Coastguard Worker while_not_flag(LOW_START_CYCLE, t)
164*49cdfc7eSAndroid Build Coastguard Worker rt_nanosleep(1 * NS_PER_MS);
165*49cdfc7eSAndroid Build Coastguard Worker debug(DBG_INFO, "low try mutex\n");
166*49cdfc7eSAndroid Build Coastguard Worker pthread_mutex_lock(&pi_mutex);
167*49cdfc7eSAndroid Build Coastguard Worker debug(DBG_INFO, "low grab mutex\n");
168*49cdfc7eSAndroid Build Coastguard Worker write_flag(MED_START_WORK);
169*49cdfc7eSAndroid Build Coastguard Worker rt_nanosleep(1 * NS_PER_MS);
170*49cdfc7eSAndroid Build Coastguard Worker while_not_flag(LOW_DROP_MUTEX, t) {
171*49cdfc7eSAndroid Build Coastguard Worker //printf("!"); fflush(NULL);
172*49cdfc7eSAndroid Build Coastguard Worker rt_nanosleep(1);
173*49cdfc7eSAndroid Build Coastguard Worker }
174*49cdfc7eSAndroid Build Coastguard Worker debug(DBG_INFO, "low drop mutex\n");
175*49cdfc7eSAndroid Build Coastguard Worker low_drop_time = rt_gettime();
176*49cdfc7eSAndroid Build Coastguard Worker pthread_mutex_unlock(&pi_mutex);
177*49cdfc7eSAndroid Build Coastguard Worker while_not_flag(END_OF_CYCLE, t) {
178*49cdfc7eSAndroid Build Coastguard Worker //printf("@"); fflush(NULL);
179*49cdfc7eSAndroid Build Coastguard Worker rt_nanosleep(1 * NS_PER_MS);
180*49cdfc7eSAndroid Build Coastguard Worker }
181*49cdfc7eSAndroid Build Coastguard Worker }
182*49cdfc7eSAndroid Build Coastguard Worker debug(DBG_INFO, "low prio thread finished (flags=%#x)\n", t->flags);
183*49cdfc7eSAndroid Build Coastguard Worker return NULL;
184*49cdfc7eSAndroid Build Coastguard Worker }
185*49cdfc7eSAndroid Build Coastguard Worker
med_prio_thread(void * arg)186*49cdfc7eSAndroid Build Coastguard Worker void *med_prio_thread(void *arg)
187*49cdfc7eSAndroid Build Coastguard Worker {
188*49cdfc7eSAndroid Build Coastguard Worker static atomic_t m_flag = { 0 };
189*49cdfc7eSAndroid Build Coastguard Worker struct thread *t = (struct thread *)arg;
190*49cdfc7eSAndroid Build Coastguard Worker #define MP "\t\t\t"
191*49cdfc7eSAndroid Build Coastguard Worker while (!thread_quit(t)) {
192*49cdfc7eSAndroid Build Coastguard Worker int i_am_the_one;
193*49cdfc7eSAndroid Build Coastguard Worker phase_t f;
194*49cdfc7eSAndroid Build Coastguard Worker while_not_flag(MED_START_WORK, t) {
195*49cdfc7eSAndroid Build Coastguard Worker //printf("."); fflush(NULL);
196*49cdfc7eSAndroid Build Coastguard Worker rt_nanosleep(1 * NS_PER_MS);
197*49cdfc7eSAndroid Build Coastguard Worker }
198*49cdfc7eSAndroid Build Coastguard Worker if ((i_am_the_one = atomic_inc(&m_flag)) == 1) {
199*49cdfc7eSAndroid Build Coastguard Worker debug(DBG_INFO, MP "thread %d writing flag\n", t->id);
200*49cdfc7eSAndroid Build Coastguard Worker write_flag(HIGH_GRAB_MUTEX);
201*49cdfc7eSAndroid Build Coastguard Worker }
202*49cdfc7eSAndroid Build Coastguard Worker
203*49cdfc7eSAndroid Build Coastguard Worker debug(DBG_DEBUG, MP "ready to start work\n");
204*49cdfc7eSAndroid Build Coastguard Worker write_flag(HIGH_GRAB_MUTEX);
205*49cdfc7eSAndroid Build Coastguard Worker while (((f = read_flag()) == HIGH_GRAB_MUTEX
206*49cdfc7eSAndroid Build Coastguard Worker || f == LOW_DROP_MUTEX) && !thread_quit(t)) {
207*49cdfc7eSAndroid Build Coastguard Worker busy_work_ms(MED_WORK_MS);
208*49cdfc7eSAndroid Build Coastguard Worker //printf("-"); fflush(NULL);
209*49cdfc7eSAndroid Build Coastguard Worker }
210*49cdfc7eSAndroid Build Coastguard Worker debug(DBG_DEBUG, MP "done working -- time to sleep\n");
211*49cdfc7eSAndroid Build Coastguard Worker if (i_am_the_one == 1) {
212*49cdfc7eSAndroid Build Coastguard Worker debug(DBG_INFO, MP "thread %d resetting m_flag\n",
213*49cdfc7eSAndroid Build Coastguard Worker t->id);
214*49cdfc7eSAndroid Build Coastguard Worker atomic_set(0, &m_flag);
215*49cdfc7eSAndroid Build Coastguard Worker }
216*49cdfc7eSAndroid Build Coastguard Worker }
217*49cdfc7eSAndroid Build Coastguard Worker debug(DBG_INFO, "med prio thread finished\n");
218*49cdfc7eSAndroid Build Coastguard Worker return NULL;
219*49cdfc7eSAndroid Build Coastguard Worker #undef MP
220*49cdfc7eSAndroid Build Coastguard Worker }
221*49cdfc7eSAndroid Build Coastguard Worker
high_prio_rt_thread(void * arg)222*49cdfc7eSAndroid Build Coastguard Worker void *high_prio_rt_thread(void *arg)
223*49cdfc7eSAndroid Build Coastguard Worker {
224*49cdfc7eSAndroid Build Coastguard Worker int delta_us;
225*49cdfc7eSAndroid Build Coastguard Worker int i;
226*49cdfc7eSAndroid Build Coastguard Worker nsec_t start, now;
227*49cdfc7eSAndroid Build Coastguard Worker struct thread *t = (struct thread *)arg;
228*49cdfc7eSAndroid Build Coastguard Worker long iterations = (long)t->arg;
229*49cdfc7eSAndroid Build Coastguard Worker
230*49cdfc7eSAndroid Build Coastguard Worker #define HP "\t\t\t\t\t"
231*49cdfc7eSAndroid Build Coastguard Worker for (i = 0; i < iterations; i++) {
232*49cdfc7eSAndroid Build Coastguard Worker debug(DBG_INFO, "Staring iteration %d\n", i);
233*49cdfc7eSAndroid Build Coastguard Worker write_flag(LOW_START_CYCLE);
234*49cdfc7eSAndroid Build Coastguard Worker while_not_flag(HIGH_GRAB_MUTEX, t) {
235*49cdfc7eSAndroid Build Coastguard Worker //printf("a"); fflush(NULL);
236*49cdfc7eSAndroid Build Coastguard Worker rt_nanosleep(10 * NS_PER_MS);
237*49cdfc7eSAndroid Build Coastguard Worker }
238*49cdfc7eSAndroid Build Coastguard Worker debug(DBG_INFO, HP "high try mutex\n");
239*49cdfc7eSAndroid Build Coastguard Worker write_flag(LOW_DROP_MUTEX);
240*49cdfc7eSAndroid Build Coastguard Worker start = rt_gettime();
241*49cdfc7eSAndroid Build Coastguard Worker pthread_mutex_lock(&pi_mutex);
242*49cdfc7eSAndroid Build Coastguard Worker now = rt_gettime();
243*49cdfc7eSAndroid Build Coastguard Worker debug(DBG_INFO, HP "high grab mutex\n");
244*49cdfc7eSAndroid Build Coastguard Worker write_flag(END_OF_CYCLE);
245*49cdfc7eSAndroid Build Coastguard Worker debug(DBG_INFO, HP "high drop mutex\n");
246*49cdfc7eSAndroid Build Coastguard Worker delta_us = (now - start) / NS_PER_US;
247*49cdfc7eSAndroid Build Coastguard Worker if (delta_us > max_delay_us)
248*49cdfc7eSAndroid Build Coastguard Worker max_delay_us = delta_us;
249*49cdfc7eSAndroid Build Coastguard Worker debug(DBG_WARN, "high prio delay time: %d us\n", delta_us);
250*49cdfc7eSAndroid Build Coastguard Worker delta_us = (now - low_drop_time) / NS_PER_US;
251*49cdfc7eSAndroid Build Coastguard Worker if (delta_us > max_drop2grab_us)
252*49cdfc7eSAndroid Build Coastguard Worker max_drop2grab_us = delta_us;
253*49cdfc7eSAndroid Build Coastguard Worker debug(DBG_WARN, "low drop to high grab time: %d us\n",
254*49cdfc7eSAndroid Build Coastguard Worker delta_us);
255*49cdfc7eSAndroid Build Coastguard Worker pthread_mutex_unlock(&pi_mutex);
256*49cdfc7eSAndroid Build Coastguard Worker rt_nanosleep(10 * NS_PER_MS);
257*49cdfc7eSAndroid Build Coastguard Worker }
258*49cdfc7eSAndroid Build Coastguard Worker all_threads_quit();
259*49cdfc7eSAndroid Build Coastguard Worker write_flag(END_OF_GAME);
260*49cdfc7eSAndroid Build Coastguard Worker debug(DBG_INFO, HP "high prio done\n");
261*49cdfc7eSAndroid Build Coastguard Worker #undef HP
262*49cdfc7eSAndroid Build Coastguard Worker return NULL;
263*49cdfc7eSAndroid Build Coastguard Worker }
264*49cdfc7eSAndroid Build Coastguard Worker
main(int argc,char * argv[])265*49cdfc7eSAndroid Build Coastguard Worker int main(int argc, char *argv[])
266*49cdfc7eSAndroid Build Coastguard Worker {
267*49cdfc7eSAndroid Build Coastguard Worker int i, numcpus;
268*49cdfc7eSAndroid Build Coastguard Worker setup();
269*49cdfc7eSAndroid Build Coastguard Worker
270*49cdfc7eSAndroid Build Coastguard Worker rt_init("hfi:x:", parse_args, argc, argv);
271*49cdfc7eSAndroid Build Coastguard Worker
272*49cdfc7eSAndroid Build Coastguard Worker if (!med_threads) {
273*49cdfc7eSAndroid Build Coastguard Worker printf
274*49cdfc7eSAndroid Build Coastguard Worker ("This test requires that at least NRCPUS medium priority threads run\n");
275*49cdfc7eSAndroid Build Coastguard Worker printf
276*49cdfc7eSAndroid Build Coastguard Worker ("If it is run bound to a single CPU, you can specify -x 1\n");
277*49cdfc7eSAndroid Build Coastguard Worker printf("No User input , using default value for NRCPUS");
278*49cdfc7eSAndroid Build Coastguard Worker numcpus = sysconf(_SC_NPROCESSORS_ONLN);
279*49cdfc7eSAndroid Build Coastguard Worker med_threads = numcpus;
280*49cdfc7eSAndroid Build Coastguard Worker }
281*49cdfc7eSAndroid Build Coastguard Worker printf(" flag mutex: %s\n", use_flag_mutex ? "enabled" : "disabled");
282*49cdfc7eSAndroid Build Coastguard Worker printf(" iterations: %ld\n", iterations);
283*49cdfc7eSAndroid Build Coastguard Worker printf("med threads: %d\n", med_threads);
284*49cdfc7eSAndroid Build Coastguard Worker
285*49cdfc7eSAndroid Build Coastguard Worker signal(SIGINT, cleanup);
286*49cdfc7eSAndroid Build Coastguard Worker signal(SIGQUIT, cleanup);
287*49cdfc7eSAndroid Build Coastguard Worker signal(SIGTERM, cleanup);
288*49cdfc7eSAndroid Build Coastguard Worker
289*49cdfc7eSAndroid Build Coastguard Worker max_delay_us = 0;
290*49cdfc7eSAndroid Build Coastguard Worker max_drop2grab_us = 0;
291*49cdfc7eSAndroid Build Coastguard Worker
292*49cdfc7eSAndroid Build Coastguard Worker init_pi_mutex(&pi_mutex);
293*49cdfc7eSAndroid Build Coastguard Worker
294*49cdfc7eSAndroid Build Coastguard Worker create_fifo_thread(low_prio_rt_thread, NULL, LOW_PRIO);
295*49cdfc7eSAndroid Build Coastguard Worker create_fifo_thread(high_prio_rt_thread, (void *)iterations, HIGH_PRIO);
296*49cdfc7eSAndroid Build Coastguard Worker for (i = 0; i < med_threads; i++) {
297*49cdfc7eSAndroid Build Coastguard Worker create_fifo_thread(med_prio_thread, NULL, MED_PRIO);
298*49cdfc7eSAndroid Build Coastguard Worker }
299*49cdfc7eSAndroid Build Coastguard Worker
300*49cdfc7eSAndroid Build Coastguard Worker while (phase_flag != END_OF_GAME)
301*49cdfc7eSAndroid Build Coastguard Worker usleep(100);
302*49cdfc7eSAndroid Build Coastguard Worker join_threads();
303*49cdfc7eSAndroid Build Coastguard Worker cleanup(0);
304*49cdfc7eSAndroid Build Coastguard Worker
305*49cdfc7eSAndroid Build Coastguard Worker printf("High priority lock aquisition maximum delay: %dus\n",
306*49cdfc7eSAndroid Build Coastguard Worker max_delay_us);
307*49cdfc7eSAndroid Build Coastguard Worker printf
308*49cdfc7eSAndroid Build Coastguard Worker ("Low priority lock drop to high priority acqusistion time: %dus\n",
309*49cdfc7eSAndroid Build Coastguard Worker max_drop2grab_us);
310*49cdfc7eSAndroid Build Coastguard Worker printf("\n");
311*49cdfc7eSAndroid Build Coastguard Worker
312*49cdfc7eSAndroid Build Coastguard Worker return 0;
313*49cdfc7eSAndroid Build Coastguard Worker }
314