Daniel Lezcano | 70ce00b | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 1 | /******************************************************************************* |
Daniel Lezcano | 35fb172 | 2011-10-03 13:56:11 +0200 | [diff] [blame] | 2 | * PM-QA validation test suite for the power management on Linux |
Daniel Lezcano | 70ce00b | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2011, Linaro Limited. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version 2 |
| 9 | * of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | * |
| 20 | * Contributors: |
| 21 | * Daniel Lezcano <daniel.lezcano@linaro.org> (IBM Corporation) |
| 22 | * - initial API and implementation |
| 23 | * |
| 24 | *******************************************************************************/ |
| 25 | |
| 26 | #define _GNU_SOURCE |
| 27 | #include <sched.h> |
| 28 | #include <stdio.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <stdbool.h> |
| 31 | #include <signal.h> |
| 32 | #include <unistd.h> |
| 33 | #include <regex.h> |
| 34 | #include <sys/types.h> |
| 35 | #include <sys/time.h> |
| 36 | #include <sys/resource.h> |
| 37 | |
Daniel Lezcano | 137c4f0 | 2012-07-12 10:52:02 +0200 | [diff] [blame] | 38 | volatile sig_atomic_t intr = 0; |
Daniel Lezcano | 70ce00b | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 39 | |
| 40 | void sigalarm(int sig) |
| 41 | { |
Daniel Lezcano | 137c4f0 | 2012-07-12 10:52:02 +0200 | [diff] [blame] | 42 | intr = 1; |
Daniel Lezcano | 70ce00b | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | int main(int argc, char *argv[]) |
| 46 | { |
| 47 | regex_t reg; |
| 48 | const char *regex = "cpu[0-9].*"; |
| 49 | char **aargv = NULL; |
| 50 | regmatch_t m[1]; |
| 51 | cpu_set_t cpuset; |
| 52 | long counter = 0; |
| 53 | int i; |
| 54 | |
| 55 | if (argc == 1) { |
| 56 | fprintf(stderr, "%s <cpuN> [cpuM] ... \n", argv[0]); |
| 57 | return 1; |
| 58 | } |
| 59 | |
| 60 | aargv = &argv[1]; |
| 61 | |
| 62 | if (regcomp(®, regex, 0)) { |
| 63 | fprintf(stderr, "failed to compile the regex\n"); |
| 64 | return 1; |
| 65 | } |
| 66 | |
| 67 | CPU_ZERO(&cpuset); |
| 68 | |
| 69 | for (i = 0; i < (argc - 1); i++) { |
| 70 | |
| 71 | char *aux; |
| 72 | int cpu; |
| 73 | |
| 74 | if (regexec(®, aargv[i], 1, m, 0)) { |
| 75 | fprintf(stderr, "'%s' parameter not recognized, " \ |
| 76 | "should be cpu[0-9]\n", aargv[i]); |
| 77 | return 1; |
| 78 | } |
| 79 | |
| 80 | aux = aargv[i] + 3; |
| 81 | cpu = atoi(aux); |
| 82 | |
| 83 | CPU_SET(cpu, &cpuset); |
| 84 | } |
| 85 | |
| 86 | if (sched_setaffinity(0, sizeof(cpuset), &cpuset)) { |
| 87 | perror("sched_setaffinity"); |
| 88 | return 1; |
| 89 | } |
| 90 | |
| 91 | if (setpriority(PRIO_PROCESS, 0, -20) < 0) { |
| 92 | perror("setpriority"); |
| 93 | return 1; |
| 94 | } |
| 95 | |
| 96 | signal(SIGALRM, sigalarm); |
| 97 | |
| 98 | /* warmup */ |
| 99 | alarm(1); |
Daniel Lezcano | 137c4f0 | 2012-07-12 10:52:02 +0200 | [diff] [blame] | 100 | for (counter = 0, intr = 0; !intr ; counter++); |
Daniel Lezcano | 70ce00b | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 101 | |
| 102 | alarm(1); |
Daniel Lezcano | 137c4f0 | 2012-07-12 10:52:02 +0200 | [diff] [blame] | 103 | for (counter = 0, intr = 0; !intr ; counter++); |
Daniel Lezcano | 70ce00b | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 104 | |
| 105 | printf("%ld\n", counter); |
| 106 | |
| 107 | return 0; |
| 108 | } |