blob: 12e82c0fa15f34f3a2a8ae67047c5002ad6363df [file] [log] [blame]
Daniel Lezcano912d4cd2011-07-26 14:39:00 +02001/*******************************************************************************
2 * PM-QA validation test suite for the power management on ARM
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
38int main(int argc, char *argv[])
39{
40 regex_t reg;
41 const char *regex = "cpu[0-9].*";
42 char **aargv = NULL;
43 regmatch_t m[1];
44 cpu_set_t cpuset;
45 int i;
46
47 if (argc == 1) {
48 fprintf(stderr, "%s <cpuN> [cpuM] ... \n", argv[0]);
49 return 1;
50 }
51
52 aargv = &argv[1];
53
54 if (regcomp(&reg, regex, 0)) {
55 fprintf(stderr, "failed to compile the regex\n");
56 return 1;
57 }
58
59 CPU_ZERO(&cpuset);
60
61 for (i = 0; i < (argc - 1); i++) {
62
63 char *aux;
64 int cpu;
65
66 if (regexec(&reg, aargv[i], 1, m, 0)) {
67 fprintf(stderr, "'%s' parameter not recognized, " \
68 "should be cpu[0-9]\n", aargv[i]);
69 return 1;
70 }
71
72 aux = aargv[i] + 3;
73 cpu = atoi(aux);
74
75 CPU_SET(cpu, &cpuset);
76 }
77
78 if (sched_setaffinity(0, sizeof(cpuset), &cpuset)) {
79 perror("sched_setaffinity");
80 return 1;
81 }
82
83 if (setpriority(PRIO_PROCESS, 0, -20) < 0) {
84 perror("setpriority");
85 return 1;
86 }
87
88 for (;;);
89
90 return 0;
91}