blob: f8968158ea1d3fb54652034c62884ae48bc62cc9 [file] [log] [blame]
Daniel Lezcano70ce00b2011-07-26 14:38:59 +02001/*******************************************************************************
Daniel Lezcano35fb1722011-10-03 13:56:11 +02002 * PM-QA validation test suite for the power management on Linux
Daniel Lezcano70ce00b2011-07-26 14:38:59 +02003 *
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 Lezcano137c4f02012-07-12 10:52:02 +020038volatile sig_atomic_t intr = 0;
Daniel Lezcano70ce00b2011-07-26 14:38:59 +020039
40void sigalarm(int sig)
41{
Daniel Lezcano137c4f02012-07-12 10:52:02 +020042 intr = 1;
Daniel Lezcano70ce00b2011-07-26 14:38:59 +020043}
44
45int 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(&reg, 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(&reg, 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 Lezcano137c4f02012-07-12 10:52:02 +0200100 for (counter = 0, intr = 0; !intr ; counter++);
Daniel Lezcano70ce00b2011-07-26 14:38:59 +0200101
102 alarm(1);
Daniel Lezcano137c4f02012-07-12 10:52:02 +0200103 for (counter = 0, intr = 0; !intr ; counter++);
Daniel Lezcano70ce00b2011-07-26 14:38:59 +0200104
105 printf("%ld\n", counter);
106
107 return 0;
108}