• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
18 /*                                                                            */
19 /* Author: Miao Xie <miaox@cn.fujitsu.com>                                    */
20 /*                                                                            */
21 /******************************************************************************/
22 
23 #include "config.h"
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <sys/types.h>
28 #include <dirent.h>
29 #include <err.h>
30 #include <errno.h>
31 
32 #include "test.h"
33 
34 #include "../cpuset_lib/bitmask.h"
35 #include "../cpuset_lib/cpuset.h"
36 #include "../cpuset_lib/common.h"
37 #include "../cpuset_lib/cpuinfo.h"
38 
39 char *TCID = "cpuset_check_domains";
40 int TST_TOTAL = 1;
41 
42 #ifdef HAVE_LINUX_MEMPOLICY_H
43 
44 /*
45  * check sched domains in system
46  *
47  * return 0  - sched domains is true
48  *        1  - sched domains is wrong, and print error info
49  *        -1 - other error
50  */
check_sched_domains(void)51 void check_sched_domains(void)
52 {
53 	int i;
54 	char buf1[128], buf2[128];
55 	struct bitmask *alldomains = NULL;
56 
57 	/* get the bitmask's len */
58 	if (!cpus_nbits) {
59 		cpus_nbits = cpuset_cpus_nbits();
60 		if (cpus_nbits <= 0) {
61 			tst_resm(TFAIL, "get cpus nbits failed");
62 			return;
63 		}
64 	}
65 
66 	if (getcpuinfo()) {
67 		tst_resm(TFAIL, "getcpuinfo failed");
68 		return;
69 	}
70 
71 	if (partition_domains()) {
72 		tst_resm(TFAIL, "partition domains failed.");
73 		return;
74 	}
75 
76 	alldomains = bitmask_alloc(cpus_nbits);
77 	if (alldomains == NULL) {
78 		tst_resm(TFAIL, "alloc alldomains space failed.");
79 		return;
80 	}
81 
82 	for (i = 0; i < ndomains; i++) {
83 		unsigned int cpu;
84 		bitmask_or(alldomains, alldomains, domains[i]);
85 
86 		for (cpu = bitmask_first(domains[i]);
87 		     cpu < bitmask_nbits(domains[i]);
88 		     cpu = bitmask_next(domains[i], cpu + 1)) {
89 			if (bitmask_weight(domains[i]) == 1) {
90 				if (cpus[cpu].sched_domain != NULL) {
91 					bitmask_displaylist(buf1, sizeof(buf1),
92 							    domains[i]);
93 					bitmask_displaylist(buf2, sizeof(buf2),
94 							    cpus[cpu].
95 							    sched_domain);
96 					tst_resm(TFAIL,
97 						 "cpu%d's sched domain is not "
98 						 "NULL(Domain: %s, "
99 						 "CPU's Sched Domain: %s).",
100 						 cpu, buf1, buf2);
101 					goto err;
102 				}
103 				break;
104 			}
105 			if (!bitmask_equal(domains[i], cpus[cpu].sched_domain)) {
106 				bitmask_displaylist(buf1, sizeof(buf1),
107 						    domains[i]);
108 				bitmask_displaylist(buf2, sizeof(buf2),
109 						    cpus[cpu].sched_domain);
110 				tst_resm(TFAIL, "cpu%d's sched domain is wrong"
111 					 "(Domain: %s, CPU's Sched Domain: %s).",
112 					 cpu, buf1, buf2);
113 				goto err;
114 			}
115 		}
116 	}
117 
118 	for (i = 0; i < ncpus; i++) {
119 		if (bitmask_isbitset(alldomains, i))
120 			continue;
121 		if (cpus[i].sched_domain) {
122 			tst_resm(TFAIL, "cpu%d has redundant sched domain", i);
123 			goto err;
124 		}
125 	}
126 
127 	tst_resm(TPASS, "check_sched_domains passed");
128 
129 err:
130 	bitmask_free(alldomains);
131 }
132 
main(void)133 int main(void)
134 {
135 	check_sched_domains();
136 	tst_exit();
137 }
138 
139 #else
main(void)140 int main(void)
141 {
142 	tst_brkm(TCONF, NULL,
143 		 "System doesn't have required mempolicy support");
144 }
145 #endif
146