I ran the kernel's cleanpatch on pi_stress.c to clean-up whitespace problems --- src/pi_tests/pi_stress.c | 87 ++++++++++++++++++++++----------------------- 1 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/pi_tests/pi_stress.c b/src/pi_tests/pi_stress.c index ae5571a..c6b9175 100644 --- a/src/pi_tests/pi_stress.c +++ b/src/pi_tests/pi_stress.c @@ -1,8 +1,8 @@ /* pi_stress - Priority Inheritance stress test - + Copyright (C) 2006, 2007 Clark Williams <williams@xxxxxxxxxx> - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -19,25 +19,25 @@ USA */ /* This program stress tests pthreads priority inheritance mutexes - + The logic is built upon the state machine that performs the "classic_pi" deadlock scenario. A state machine or "inversion group" is a group of three threads as described below. The basic premise here is to set up a deadlock scenario and confirm that PI mutexes resolve the situation. Three worker threads will be created from the - main thread: low, medium and high priority threads that use SCHED_FIFO as + main thread: low, medium and high priority threads that use SCHED_FIFO as their scheduling policy. The low priority thread claims a mutex and then - starts "working". The medium priority thread starts and preempts the low + starts "working". The medium priority thread starts and preempts the low priority thread. Then the high priority thread runs and attempts to claim - the mutex owned by the low priority thread. Without priority inheritance, - this will deadlock the program. With priority inheritance, the low priority + the mutex owned by the low priority thread. Without priority inheritance, + this will deadlock the program. With priority inheritance, the low priority thread receives a priority boost, finishes it's "work" and releases the mutex, which allows the high priority thread to run and finish and then the medium - priority thread finishes. + priority thread finishes. + + That's the theory, anyway... - That's the theory, anyway... - CW - 2006 */ #include <stdio.h> @@ -59,13 +59,13 @@ const char *version = "pi_stress v" VERSION_STRING " (" __DATE__ " " __TIME__ ")"; // conversions -#define USEC_PER_SEC 1000000 -#define NSEC_PER_SEC 1000000000 +#define USEC_PER_SEC 1000000 +#define NSEC_PER_SEC 1000000000 #define USEC_TO_NSEC(u) ((u) * 1000) -#define USEC_TO_SEC(u) ((u) / USEC_PER_SEC) +#define USEC_TO_SEC(u) ((u) / USEC_PER_SEC) #define NSEC_TO_USEC(n) ((n) / 1000) -#define SEC_TO_NSEC(s) ((s) * NSEC_PER_SEC) -#define SEC_TO_USEC(s) ((s) * USEC_PER_SEC) +#define SEC_TO_NSEC(s) ((s) * NSEC_PER_SEC) +#define SEC_TO_USEC(s) ((s) * USEC_PER_SEC) /* test timeout */ #define TIMEOUT 2 @@ -86,7 +86,7 @@ const char *version = "pi_stress v" VERSION_STRING " (" __DATE__ " " __TIME__ ") // cursor control #define UP_ONE "\033[1A" -#define DOWN_ONE "\033[1B" +#define DOWN_ONE "\033[1B" // the length of the test // default is infinite @@ -98,7 +98,7 @@ time_t start, finish; // the number of groups to create int ngroups = 0; -// the number of times a group causes a priority inversion situation +// the number of times a group causes a priority inversion situation // default to infinite int inversions = -1; @@ -296,7 +296,7 @@ main (int argc, char **argv) // set up CPU affinity masks if (set_cpu_affinity(&test_cpu_mask, &admin_cpu_mask)) return FAILURE; - + nthreads = ngroups * NUM_TEST_THREADS + NUM_ADMIN_THREADS; /* set up our ready barrier */ @@ -316,7 +316,7 @@ main (int argc, char **argv) for (i = 0; i < ngroups; i++) { groups[i].id = i; groups[i].cpu = core++; - if (core >= num_processors) + if (core >= num_processors) core = 0; if (create_group(&groups[i]) != SUCCESS) return FAILURE; @@ -382,7 +382,7 @@ setup_thread_attr(pthread_attr_t *attr, int prio, cpu_set_t *mask, int schedpoli } status = pthread_attr_setschedpolicy(attr, schedpolicy); if (status) { - error("setup_thread_attr: setting attribute policy to %s: 0x%x\n", + error("setup_thread_attr: setting attribute policy to %s: 0x%x\n", schedpolicy == SCHED_FIFO ? "SCHED_FIFO" : "SCHED_RR", status); return FAILURE; } @@ -450,12 +450,12 @@ set_cpu_affinity(cpu_set_t *test_mask, cpu_set_t *admin_mask) CPU_ZERO(test_mask); for (i = admin_proc+1; i < num_processors; i++) CPU_SET(i, test_mask); - + if (admin_proc+1 == num_processors -1) info("Test threads running on processor: %ld\n", num_processors-1); else - info("Test threads running on processors: %d-%d\n", + info("Test threads running on processors: %d-%d\n", admin_proc+1, (int)num_processors-1); return SUCCESS; @@ -493,7 +493,7 @@ watchdog_check(void) g->watchdog_hits = 0; } return failures ? FAILURE : SUCCESS; -} +} int pending_interrupt(void) @@ -504,10 +504,10 @@ pending_interrupt(void) error("from sigpending: %s\n", strerror(errno)); return 0; } - + return interrupted = sigismember(&pending, SIGINT); } - + static inline void tsnorm(struct timespec *ts) { while (ts->tv_nsec >= NSEC_PER_SEC) { @@ -581,10 +581,10 @@ reporter(void *arg) set_shutdown_flag(); break; } - + // clear watchdog counters watchdog_clear(); - + } debug("reporter: finished\n"); set_shutdown_flag(); @@ -699,7 +699,7 @@ low_priority(void *arg) debug("low_priority[%d]: unlocking mutex\n", p->id); pthread_mutex_unlock(&p->mutex); - // finish state + // finish state debug("low_priority[%d]: entering finish wait\n", p->id); status = pthread_barrier_wait(&p->finish_barrier); if (status && status != PTHREAD_BARRIER_SERIAL_THREAD) { @@ -805,7 +805,7 @@ med_priority(void *arg) if (have_errors == 0) { status = pthread_barrier_wait(&all_threads_done); if (status && status != PTHREAD_BARRIER_SERIAL_THREAD) { - error("med_priority[%d]: pthread_barrier_wait(all_threads_done): %x", + error("med_priority[%d]: pthread_barrier_wait(all_threads_done): %x", p->id, status); return NULL; } @@ -917,7 +917,7 @@ high_priority(void *arg) p->id, status); return NULL; } - } + } // exit debug("high_priority[%d]: exiting\n", p->id); return NULL; @@ -945,7 +945,7 @@ info(char *fmt, ...) } } -void +void debug(char *fmt, ...) { if (debugging) { @@ -956,7 +956,7 @@ debug(char *fmt, ...) va_end(ap); } } - + void usage(void) { @@ -1050,7 +1050,7 @@ initialize_group(struct group_parameters *group) } /* set priority inheritance attribute for mutex */ - status = pthread_mutexattr_setprotocol(&mutex_attr, + status = pthread_mutexattr_setprotocol(&mutex_attr, PTHREAD_PRIO_INHERIT); if (status) { error("setting mutex attribute policy: %s\n", strerror(status)); @@ -1101,7 +1101,7 @@ initialize_group(struct group_parameters *group) } return SUCCESS; -} +} // setup and create a groups threads int create_group(struct group_parameters *group) @@ -1126,9 +1126,9 @@ create_group(struct group_parameters *group) debug("creating low priority thread\n"); if (setup_thread_attr(&thread_attr, LOW_PRIO(), &mask, policy)) return FAILURE; - status = pthread_create(&group->low_tid, - &thread_attr, - low_priority, + status = pthread_create(&group->low_tid, + &thread_attr, + low_priority, group); if (status != 0) { error("creating low_priority thread: %s\n", strerror(status)); @@ -1140,8 +1140,8 @@ create_group(struct group_parameters *group) if (setup_thread_attr(&thread_attr, MED_PRIO(), &mask, policy)) return FAILURE; status = pthread_create(&group->med_tid, - &thread_attr, - med_priority, + &thread_attr, + med_priority, group); if (status != 0) { error("creating med_priority thread: %s\n", strerror(status)); @@ -1153,8 +1153,8 @@ create_group(struct group_parameters *group) if (setup_thread_attr(&thread_attr, HIGH_PRIO(), &mask, policy)) return FAILURE; status = pthread_create(&group->high_tid, - &thread_attr, - high_priority, + &thread_attr, + high_priority, group); if (status != 0) { error("creating high_priority thread: %s\n", strerror(status)); @@ -1242,7 +1242,7 @@ void banner(void) printf("Number of inversions per group: unlimited\n"); else printf("Number of inversions per group: %d\n", inversions); - printf("Test threads using scheduler policy: %s\n", + printf("Test threads using scheduler policy: %s\n", policy == SCHED_FIFO ? "SCHED_FIFO" : "SCHED_RR"); printf(" Admin thread priority: %d\n", MAIN_PRIO()); printf("%d groups of 3 threads will be created\n", ngroups); @@ -1256,7 +1256,7 @@ void summary(void) { time_t interval = finish - start; struct tm *t = gmtime(&interval); - + printf("Total inversion performed: %lu\n", total_inversions()); printf("Test Duration: %d days, %d hours, %d minutes, %d seconds\n", t->tm_yday, t->tm_hour, t->tm_min, t->tm_sec); @@ -1276,4 +1276,3 @@ barrier_init(pthread_barrier_t *b, const pthread_barrierattr_t *attr, return SUCCESS; } - -- 1.6.0.6 -- To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html