diff options
| author | Doug Ledford <dledford@redhat.com> | 2012-05-31 19:26:37 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-31 20:49:31 -0400 |
| commit | 7820b0715b6fb1378fab41b27fb7aa3950852cb7 (patch) | |
| tree | f5720d49643717253c6c427fab45300ba4818bdf /tools/testing/selftests/mqueue | |
| parent | 113289cc086f80f28acd06f160a7c6423cdd4191 (diff) | |
tools/selftests: add mq_perf_tests
Add the mq_perf_tests tool I used when creating my mq performance patch.
Also add a local .gitignore to keep the binaries from showing up in git
status output.
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Doug Ledford <dledford@redhat.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Manfred Spraul <manfred@colorfullife.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'tools/testing/selftests/mqueue')
| -rw-r--r-- | tools/testing/selftests/mqueue/.gitignore | 2 | ||||
| -rw-r--r-- | tools/testing/selftests/mqueue/Makefile | 4 | ||||
| -rw-r--r-- | tools/testing/selftests/mqueue/mq_perf_tests.c | 741 |
3 files changed, 746 insertions, 1 deletions
diff --git a/tools/testing/selftests/mqueue/.gitignore b/tools/testing/selftests/mqueue/.gitignore new file mode 100644 index 000000000000..d8d42377205a --- /dev/null +++ b/tools/testing/selftests/mqueue/.gitignore | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | mq_open_tests | ||
| 2 | mq_perf_tests | ||
diff --git a/tools/testing/selftests/mqueue/Makefile b/tools/testing/selftests/mqueue/Makefile index bd74142a173f..54c0aad2b47c 100644 --- a/tools/testing/selftests/mqueue/Makefile +++ b/tools/testing/selftests/mqueue/Makefile | |||
| @@ -1,8 +1,10 @@ | |||
| 1 | all: | 1 | all: |
| 2 | gcc -O2 -lrt mq_open_tests.c -o mq_open_tests | 2 | gcc -O2 -lrt mq_open_tests.c -o mq_open_tests |
| 3 | gcc -O2 -lrt -lpthread -lpopt -o mq_perf_tests mq_perf_tests.c | ||
| 3 | 4 | ||
| 4 | run_tests: | 5 | run_tests: |
| 5 | ./mq_open_tests /test1 | 6 | ./mq_open_tests /test1 |
| 7 | ./mq_perf_tests | ||
| 6 | 8 | ||
| 7 | clean: | 9 | clean: |
| 8 | rm -f mq_open_tests | 10 | rm -f mq_open_tests mq_perf_tests |
diff --git a/tools/testing/selftests/mqueue/mq_perf_tests.c b/tools/testing/selftests/mqueue/mq_perf_tests.c new file mode 100644 index 000000000000..2fadd4b97045 --- /dev/null +++ b/tools/testing/selftests/mqueue/mq_perf_tests.c | |||
| @@ -0,0 +1,741 @@ | |||
| 1 | /* | ||
| 2 | * This application is Copyright 2012 Red Hat, Inc. | ||
| 3 | * Doug Ledford <dledford@redhat.com> | ||
| 4 | * | ||
| 5 | * mq_perf_tests is free software: you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation, version 3. | ||
| 8 | * | ||
| 9 | * mq_perf_tests 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 the | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * For the full text of the license, see <http://www.gnu.org/licenses/>. | ||
| 15 | * | ||
| 16 | * mq_perf_tests.c | ||
| 17 | * Tests various types of message queue workloads, concentrating on those | ||
| 18 | * situations that invole large message sizes, large message queue depths, | ||
| 19 | * or both, and reports back useful metrics about kernel message queue | ||
| 20 | * performance. | ||
| 21 | * | ||
| 22 | */ | ||
| 23 | #define _GNU_SOURCE | ||
| 24 | #include <stdio.h> | ||
| 25 | #include <stdlib.h> | ||
| 26 | #include <unistd.h> | ||
| 27 | #include <fcntl.h> | ||
| 28 | #include <string.h> | ||
| 29 | #include <limits.h> | ||
| 30 | #include <errno.h> | ||
| 31 | #include <signal.h> | ||
| 32 | #include <pthread.h> | ||
| 33 | #include <sched.h> | ||
| 34 | #include <sys/types.h> | ||
| 35 | #include <sys/time.h> | ||
| 36 | #include <sys/resource.h> | ||
| 37 | #include <sys/stat.h> | ||
| 38 | #include <mqueue.h> | ||
| 39 | #include <popt.h> | ||
| 40 | |||
| 41 | static char *usage = | ||
| 42 | "Usage:\n" | ||
| 43 | " %s [-c #[,#..] -f] path\n" | ||
| 44 | "\n" | ||
| 45 | " -c # Skip most tests and go straight to a high queue depth test\n" | ||
| 46 | " and then run that test continuously (useful for running at\n" | ||
| 47 | " the same time as some other workload to see how much the\n" | ||
| 48 | " cache thrashing caused by adding messages to a very deep\n" | ||
| 49 | " queue impacts the performance of other programs). The number\n" | ||
| 50 | " indicates which CPU core we should bind the process to during\n" | ||
| 51 | " the run. If you have more than one physical CPU, then you\n" | ||
| 52 | " will need one copy per physical CPU package, and you should\n" | ||
| 53 | " specify the CPU cores to pin ourself to via a comma separated\n" | ||
| 54 | " list of CPU values.\n" | ||
| 55 | " -f Only usable with continuous mode. Pin ourself to the CPUs\n" | ||
| 56 | " as requested, then instead of looping doing a high mq\n" | ||
| 57 | " workload, just busy loop. This will allow us to lock up a\n" | ||
| 58 | " single CPU just like we normally would, but without actually\n" | ||
| 59 | " thrashing the CPU cache. This is to make it easier to get\n" | ||
| 60 | " comparable numbers from some other workload running on the\n" | ||
| 61 | " other CPUs. One set of numbers with # CPUs locked up running\n" | ||
| 62 | " an mq workload, and another set of numbers with those same\n" | ||
| 63 | " CPUs locked away from the test workload, but not doing\n" | ||
| 64 | " anything to trash the cache like the mq workload might.\n" | ||
| 65 | " path Path name of the message queue to create\n" | ||
| 66 | "\n" | ||
| 67 | " Note: this program must be run as root in order to enable all tests\n" | ||
| 68 | "\n"; | ||
| 69 | |||
| 70 | char *MAX_MSGS = "/proc/sys/fs/mqueue/msg_max"; | ||
| 71 | char *MAX_MSGSIZE = "/proc/sys/fs/mqueue/msgsize_max"; | ||
| 72 | |||
| 73 | #define min(a, b) ((a) < (b) ? (a) : (b)) | ||
| 74 | #define MAX_CPUS 64 | ||
| 75 | char *cpu_option_string; | ||
| 76 | int cpus_to_pin[MAX_CPUS]; | ||
| 77 | int num_cpus_to_pin; | ||
| 78 | pthread_t cpu_threads[MAX_CPUS]; | ||
| 79 | pthread_t main_thread; | ||
| 80 | cpu_set_t *cpu_set; | ||
| 81 | int cpu_set_size; | ||
| 82 | int cpus_online; | ||
| 83 | |||
| 84 | #define MSG_SIZE 16 | ||
| 85 | #define TEST1_LOOPS 10000000 | ||
| 86 | #define TEST2_LOOPS 100000 | ||
| 87 | int continuous_mode; | ||
| 88 | int continuous_mode_fake; | ||
| 89 | |||
| 90 | struct rlimit saved_limits, cur_limits; | ||
| 91 | int saved_max_msgs, saved_max_msgsize; | ||
| 92 | int cur_max_msgs, cur_max_msgsize; | ||
| 93 | FILE *max_msgs, *max_msgsize; | ||
| 94 | int cur_nice; | ||
| 95 | char *queue_path = "/mq_perf_tests"; | ||
| 96 | mqd_t queue = -1; | ||
| 97 | struct mq_attr result; | ||
| 98 | int mq_prio_max; | ||
| 99 | |||
| 100 | const struct poptOption options[] = { | ||
| 101 | { | ||
| 102 | .longName = "continuous", | ||
| 103 | .shortName = 'c', | ||
| 104 | .argInfo = POPT_ARG_STRING, | ||
| 105 | .arg = &cpu_option_string, | ||
| 106 | .val = 'c', | ||
| 107 | .descrip = "Run continuous tests at a high queue depth in " | ||
| 108 | "order to test the effects of cache thrashing on " | ||
| 109 | "other tasks on the system. This test is intended " | ||
| 110 | "to be run on one core of each physical CPU while " | ||
| 111 | "some other CPU intensive task is run on all the other " | ||
| 112 | "cores of that same physical CPU and the other task " | ||
| 113 | "is timed. It is assumed that the process of adding " | ||
| 114 | "messages to the message queue in a tight loop will " | ||
| 115 | "impact that other task to some degree. Once the " | ||
| 116 | "tests are performed in this way, you should then " | ||
| 117 | "re-run the tests using fake mode in order to check " | ||
| 118 | "the difference in time required to perform the CPU " | ||
| 119 | "intensive task", | ||
| 120 | .argDescrip = "cpu[,cpu]", | ||
| 121 | }, | ||
| 122 | { | ||
| 123 | .longName = "fake", | ||
| 124 | .shortName = 'f', | ||
| 125 | .argInfo = POPT_ARG_NONE, | ||
| 126 | .arg = &continuous_mode_fake, | ||
| 127 | .val = 0, | ||
| 128 | .descrip = "Tie up the CPUs that we would normally tie up in" | ||
| 129 | "continuous mode, but don't actually do any mq stuff, " | ||
| 130 | "just keep the CPU busy so it can't be used to process " | ||
| 131 | "system level tasks as this would free up resources on " | ||
| 132 | "the other CPU cores and skew the comparison between " | ||
| 133 | "the no-mqueue work and mqueue work tests", | ||
| 134 | .argDescrip = NULL, | ||
| 135 | }, | ||
| 136 | { | ||
| 137 | .longName = "path", | ||
| 138 | .shortName = 'p', | ||
| 139 | .argInfo = POPT_ARG_STRING | POPT_ARGFLAG_SHOW_DEFAULT, | ||
| 140 | .arg = &queue_path, | ||
| 141 | .val = 'p', | ||
| 142 | .descrip = "The name of the path to use in the mqueue " | ||
| 143 | "filesystem for our tests", | ||
| 144 | .argDescrip = "pathname", | ||
| 145 | }, | ||
| 146 | POPT_AUTOHELP | ||
| 147 | POPT_TABLEEND | ||
| 148 | }; | ||
| 149 | |||
| 150 | static inline void __set(FILE *stream, int value, char *err_msg); | ||
| 151 | void shutdown(int exit_val, char *err_cause, int line_no); | ||
