• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***************************************************************************
2                           HTinterrupt.c  -  description
3                              -------------------
4     email                : sonic,zhang@intel.com
5  ***************************************************************************/
6 
7 /***************************************************************************
8  *                                                                         *
9  *   This program is free software; you can redistribute it and/or modify  *
10  *   it under the terms of the GNU General Public License as published by  *
11  *   the Free Software Foundation; either version 2 of the License, or     *
12  *   (at your option) any later version.                                   *
13  *                                                                         *
14  ***************************************************************************/
15 #include "ht_utils.h"
16 #include <unistd.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include "test.h"
21 
22 char *TCID = "ht_interrupt";
23 int TST_TOTAL = 1;
24 
25 #define INTERRUPT_NAME	"/proc/interrupts"
26 
HT_InterruptDistribution()27 int HT_InterruptDistribution()
28 {
29 	FILE *pFile;
30 	int ci[32], cj[32];
31 	int cpucount, i;
32 	int cmax, cmin, d;
33 
34 	tst_resm(TINFO, "Get interrupts distribution with HT.");
35 
36 	if ((cpucount = get_cpu_count()) <= 0) {
37 		return 0;
38 	}
39 
40 	if ((pFile = fopen(INTERRUPT_NAME, "r")) == NULL) {
41 		return 0;
42 	}
43 
44 	fgets(buf, 255, pFile);
45 	fscanf(pFile, "%s %d %d %d %d %d %d %d %d \
46 %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \
47 %d %d %d %d %d %d %d %d", buf, ci, ci + 1, ci + 2, ci + 3, ci + 4, ci + 5, ci + 6, ci + 7, ci + 8, ci + 9, ci + 10, ci + 11, ci + 12, ci + 13, ci + 14, ci + 15, ci + 16, ci + 17, ci + 18, ci + 19, ci + 20, ci + 21, ci + 22, ci + 23, ci + 24, ci + 25, ci + 26, ci + 27, ci + 28, ci + 29, ci + 30, ci + 31);
48 
49 	fclose(pFile);
50 
51 	for (i = 0; i < 10; i++) {
52 		sleep(1);
53 		printf(".");
54 	}
55 
56 	if ((pFile = fopen(INTERRUPT_NAME, "r")) == NULL) {
57 		return 0;
58 	}
59 
60 	fgets(buf, 255, pFile);
61 	fscanf(pFile, "%s %d %d %d %d %d %d %d %d \
62 %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \
63 %d %d %d %d %d %d %d %d", buf, cj, cj + 1, cj + 2, cj + 3, cj + 4, cj + 5, cj + 6, cj + 7, cj + 8, cj + 9, cj + 10, cj + 11, cj + 12, cj + 13, cj + 14, cj + 15, cj + 16, cj + 17, cj + 18, cj + 19, cj + 20, cj + 21, cj + 22, cj + 23, cj + 24, cj + 25, cj + 26, cj + 27, cj + 28, cj + 29, cj + 30, cj + 31);
64 
65 	fclose(pFile);
66 
67 	printf("\n\n");
68 	printf("Timer interrupt counts per CPU:\n");
69 	d = cj[0] - ci[0];
70 	printf("%d ", d);
71 	cmax = cmin = d;
72 	for (i = 1; i < cpucount; i++) {
73 		d = cj[i] - ci[i];
74 		printf("%d ", d);
75 		if (cmax < d)
76 			cmax = d;
77 		if (cmin > d)
78 			cmin = d;
79 	}
80 
81 	printf("\n\n");
82 	printf("max value: %d\n", cmax);
83 	printf("min value: %d\n", cmin);
84 	printf("\n");
85 
86 	if (cmin == 0 || cmax / cmin > 10) {
87 		return 0;
88 	} else {
89 		return 1;
90 	}
91 }
92 
93 // return 0 means Pass, return 1 means Fail.
main(int argc,char * argv[])94 int main(int argc, char *argv[])
95 {
96 	tst_resm(TINFO, "Begin: HyperThreading Interrupt");
97 
98 #if (!defined __i386__ && !defined __x86_64__)
99 	tst_brkm(TCONF, NULL,
100 		 "This test suite can only execute on x86 architecture.");
101 #else
102 	if (!check_ht_capability()) {
103 		if (HT_InterruptDistribution())
104 			tst_resm(TPASS,
105 				 "Interrupt distribution is balanceable.");
106 		else
107 			tst_resm(TFAIL,
108 				 "Interrupt distribution is not balanceable.");
109 	} else {
110 		tst_brkm(TCONF, NULL, "HT is not enabled or not supported.");
111 	}
112 #endif
113 
114 	tst_resm(TINFO, "End: HyperThreading Interrupt");
115 
116 	tst_exit();
117 }
118