cpuset_sched_domains_check.c revision ec6edca7aa42b6affd989ef91b5897f96795e40f
1/******************************************************************************/
2/*                                                                            */
3/* Copyright (c) 2009 FUJITSU LIMITED                                         */
4/*                                                                            */
5/* This program 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; either version 2 of the License, or          */
8/* (at your option) any later version.                                        */
9/*                                                                            */
10/* This program is distributed in the hope that it will be useful,            */
11/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
12/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
13/* the GNU General Public License for more details.                           */
14/*                                                                            */
15/* You should have received a copy of the GNU General Public License          */
16/* along with this program;  if not, write to the Free Software               */
17/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA    */
18/*                                                                            */
19/* Author: Miao Xie <miaox@cn.fujitsu.com>                                    */
20/*                                                                            */
21/******************************************************************************/
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <sys/types.h>
27#include <dirent.h>
28#include <err.h>
29#include <errno.h>
30
31#include "test.h"
32
33#include "../cpuset_lib/bitmask.h"
34#include "../cpuset_lib/cpuset.h"
35#include "../cpuset_lib/common.h"
36#include "../cpuset_lib/cpuinfo.h"
37
38char *TCID = "cpuset_check_domains";
39int TST_TOTAL = 1;
40
41#ifdef HAVE_LINUX_MEMPOLICY_H
42
43/*
44 * check sched domains in system
45 *
46 * return 0  - sched domains is true
47 *        1  - sched domains is wrong, and print error info
48 *        -1 - other error
49 */
50void check_sched_domains(void)
51{
52	int i;
53	char buf1[128], buf2[128];
54	struct bitmask *alldomains = NULL;
55
56	/* get the bitmask's len */
57	if (!cpus_nbits) {
58		cpus_nbits = cpuset_cpus_nbits();
59		if (cpus_nbits <= 0) {
60			tst_resm(TFAIL, "get cpus nbits failed");
61			return;
62		}
63	}
64
65	if (getcpuinfo()) {
66		tst_resm(TFAIL, "getcpuinfo failed");
67		return;
68	}
69
70	if (partition_domains()) {
71		tst_resm(TFAIL, "partition domains failed.");
72		return;
73	}
74
75	alldomains = bitmask_alloc(cpus_nbits);
76	if (alldomains == NULL) {
77		tst_resm(TFAIL, "alloc alldomains space failed.");
78		return;
79	}
80
81	for (i = 0; i < ndomains; i++) {
82		unsigned int cpu;
83		bitmask_or(alldomains, alldomains, domains[i]);
84
85		for (cpu = bitmask_first(domains[i]);
86		     cpu < bitmask_nbits(domains[i]);
87		     cpu = bitmask_next(domains[i], cpu + 1)) {
88			if (bitmask_weight(domains[i]) == 1) {
89				if (cpus[cpu].sched_domain != NULL) {
90				    	bitmask_displaylist(buf1, sizeof(buf1),
91							domains[i]);
92					bitmask_displaylist(buf2, sizeof(buf2),
93							cpus[cpu].sched_domain);
94					tst_resm(TFAIL, "cpu%d's sched domain is not "
95							"NULL(Domain: %s, "
96							"CPU's Sched Domain: %s).",
97						cpu, buf1, buf2);
98					goto err;
99				}
100				break;
101			}
102			if (!bitmask_equal(domains[i],
103			    cpus[cpu].sched_domain)) {
104			    	bitmask_displaylist(buf1, sizeof(buf1),
105						domains[i]);
106				bitmask_displaylist(buf2, sizeof(buf2),
107				    cpus[cpu].sched_domain);
108				tst_resm(TFAIL, "cpu%d's sched domain is wrong"
109					"(Domain: %s, CPU's Sched Domain: %s).",
110					cpu, buf1, buf2);
111				goto err;
112			}
113		}
114	}
115
116	for (i = 0; i < ncpus; i++) {
117		if (bitmask_isbitset(alldomains, i))
118			continue;
119		if (cpus[i].sched_domain) {
120			tst_resm(TFAIL, "cpu%d has redundant sched domain", i);
121			goto err;
122		}
123	}
124
125	tst_resm(TPASS, "check_sched_domains passed");
126
127err:
128	bitmask_free(alldomains);
129}
130
131int main(void)
132{
133	check_sched_domains();
134	tst_exit();
135}
136
137#else
138int main(void)
139{
140	tst_resm(TCONF, "System doesn't have required mempolicy support");
141	tst_exit();
142}
143#endif
144