From c4a44c163df791ec3f42075e587685fa7e5b031d Mon Sep 17 00:00:00 2001 From: Clark Williams Date: Fri, 9 May 2008 13:28:50 -0500 Subject: [PATCH] added mlockall option Signed-off-by: Clark Williams --- .gitignore | 4 ++++ src/cyclictest/cyclictest.c | 18 +++++++++++++++++- src/pi_tests/pi_stress.c | 18 ++++++++++++++++++ src/signaltest/signaltest.c | 16 +++++++++++++++- 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index fd84086..f09d8dc 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,7 @@ releases BUILD RPMS SRPMS +classic_pi +pi_stress +cyclictest +signaltest diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c index 9223549..cf9b7c6 100644 --- a/src/cyclictest/cyclictest.c +++ b/src/cyclictest/cyclictest.c @@ -30,6 +30,7 @@ #include #include #include +#include #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) @@ -119,6 +120,7 @@ static int ftrace = 0; static int kernelversion; static int verbose = 0; static int oscope_reduction = 1; +static int lockall = 0; /* Backup of kernel variables that we modify */ static struct kvars { @@ -478,6 +480,7 @@ static void display_help(void) "-s --system use sys_nanosleep and sys_setitimer\n" "-t --threads one thread per available processor\n" "-t NUM --threads=NUM number of threads: without -t default=1\n" + "-m --mlockall lock current and future memory allocations\n" "-v --verbose output values on stdout for statistics\n" " format: n:c:v n=tasknum c=count v=value in us\n"); exit(0); @@ -531,11 +534,12 @@ static void process_options (int argc, char *argv[]) {"relative", no_argument, NULL, 'r'}, {"system", no_argument, NULL, 's'}, {"threads", optional_argument, NULL, 't'}, + {"mlockall", no_argument, NULL, 'm' }, {"verbose", no_argument, NULL, 'v'}, {"help", no_argument, NULL, '?'}, {NULL, 0, NULL, 0} }; - int c = getopt_long (argc, argv, "a::b:c:d:fi:l:no:p:qrst::v", + int c = getopt_long (argc, argv, "a::b:c:d:fi:l:no:p:qrsmt::v", long_options, &option_index); if (c == -1) break; @@ -566,6 +570,7 @@ static void process_options (int argc, char *argv[]) num_threads = max_cpus; break; case 'v': verbose = 1; break; + case 'm': lockall = 1; break; case '?': error = 1; break; } } @@ -696,6 +701,13 @@ int main(int argc, char **argv) process_options(argc, argv); + /* lock all memory (prevent paging) */ + if (lockall) + if (mlockall(MCL_CURRENT|MCL_FUTURE) == -1) { + perror("mlockall"); + goto out; + } + kernelversion = check_kernel(); if (kernelversion == KV_NOT_26) @@ -809,6 +821,10 @@ int main(int argc, char **argv) free(par); out: + /* unlock everything */ + if (lockall) + munlockall(); + /* Be a nice program, cleanup */ if (kernelversion != KV_26_CURR) restorekernvars(); diff --git a/src/pi_tests/pi_stress.c b/src/pi_tests/pi_stress.c index a0599ad..052c476 100644 --- a/src/pi_tests/pi_stress.c +++ b/src/pi_tests/pi_stress.c @@ -51,6 +51,7 @@ #include #include #include +#include #include #include @@ -128,6 +129,9 @@ int have_errors = 0; // force running on one cpu int uniprocessor = 0; +// lock all memory +int lockall = 0; + // command line options struct option options [] = { { "duration", required_argument, NULL, 't' }, @@ -141,6 +145,7 @@ struct option options [] = { { "prompt", no_argument, NULL, 'p'}, { "debug", no_argument, NULL, 'd'}, { "version", no_argument, NULL, 'V'}, + { "mlockall", no_argument, NULL, 'm'}, { "help", no_argument, NULL, 'h'}, { NULL, 0, NULL, 0}, }; @@ -234,6 +239,13 @@ main (int argc, char **argv) /* process command line arguments */ process_command_line(argc, argv); + /* lock memory */ + if (lockall) + if (mlockall(MCL_CURRENT|MCL_FUTURE) == -1) { + error("mlockall failed\n"); + return FAILURE; + } + // boost main's priority (so we keep running) :) prio_min = sched_get_priority_min(policy); thread_param.sched_priority = MAIN_PRIO(); @@ -328,6 +340,8 @@ main (int argc, char **argv) } finish = time(NULL); summary(); + if (lockall) + munlockall(); exit(retval); } @@ -852,6 +866,7 @@ usage(void) printf("\t--rr\t\t- use SCHED_RR for test threads [SCHED_FIFO]\n"); printf("\t--prompt\t- prompt before starting the test\n"); printf("\t--uniprocessor\t- force all threads to run on one processor\n"); + printf("\t--mlockall\t- lock current and future memory\n"); printf("\t--debug\t\t- turn on debug prints\n"); printf("\t--version\t- print version number on output\n"); printf("\t--help\t\t- print this message\n"); @@ -1083,6 +1098,9 @@ process_command_line(int argc, char **argv) case 'u': uniprocessor = 1; break; + case 'm': + lockall = 1; + break; } } } diff --git a/src/signaltest/signaltest.c b/src/signaltest/signaltest.c index 963cc38..eef7d6e 100644 --- a/src/signaltest/signaltest.c +++ b/src/signaltest/signaltest.c @@ -25,6 +25,7 @@ #include #include #include +#include #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) @@ -207,6 +208,7 @@ static void display_help(void) "-p PRIO --prio=PRIO priority of highest prio thread\n" "-q --quiet print only a summary on exit\n" "-t NUM --threads=NUM number of threads: default=2\n" + "-m --mlockall lock current and future memory allocations\n" "-v --verbose output values on stdout for statistics\n" " format: n:c:v n=tasknum c=count v=value in us\n"); exit(0); @@ -217,6 +219,7 @@ static int num_threads = 2; static int max_cycles; static int verbose; static int quiet; +static int lockall = 0; /* Process commandline options */ static void process_options (int argc, char *argv[]) @@ -235,7 +238,7 @@ static void process_options (int argc, char *argv[]) {"help", no_argument, NULL, '?'}, {NULL, 0, NULL, 0} }; - int c = getopt_long (argc, argv, "b:c:d:i:l:np:qrst:v", + int c = getopt_long (argc, argv, "b:c:d:i:l:np:qrsmt:v", long_options, &option_index); if (c == -1) break; @@ -245,6 +248,7 @@ static void process_options (int argc, char *argv[]) case 'p': priority = atoi(optarg); break; case 'q': quiet = 1; break; case 't': num_threads = atoi(optarg); break; + case 'm': lockall = 1; break; case 'v': verbose = 1; break; case '?': error = 1; break; } @@ -317,6 +321,13 @@ int main(int argc, char **argv) process_options(argc, argv); + /* lock all memory (prevent paging) */ + if (lockall) + if (mlockall(MCL_CURRENT|MCL_FUTURE) == -1) { + perror("mlockall"); + goto out; + } + check_kernel(); sigemptyset(&sigset); @@ -417,5 +428,8 @@ int main(int argc, char **argv) outpar: free(par); out: + if (lockall) + munlockall(); + exit(ret); } -- 1.5.4.5