Imported Upstream version 20090930
[ltp-debian.git] / testcases / kernel / sched / hyperthreading / ht_interrupt / HTinterrupt.c
bloba09fffd0dae7bd564c7ec2dc5f5266659da9bc93
1 /***************************************************************************
2 HTinterrupt.c - description
3 -------------------
4 email : sonic,zhang@intel.com
5 ***************************************************************************/
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 "HTutils.h"
16 #include <unistd.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include "test.h"
22 char *TCID = "ht_interrupt";
23 int TST_TOTAL = 1;
25 #define INTERRUPT_NAME "/proc/interrupts"
27 int HT_InterruptDistribution()
29 FILE *pFile;
30 int ci[32],cj[32];
31 int cpucount, i;
32 int cmax, cmin, d;
34 tst_resm(TINFO, "Get interrupts distribution with HT.");
36 if((cpucount=get_cpu_count())<=0)
38 return 0;
41 if((pFile=fopen(INTERRUPT_NAME, "r"))==NULL)
43 return 0;
46 fgets(buf, 255, pFile);
47 fscanf(pFile, "%s %d %d %d %d %d %d %d %d \
48 %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \
49 %d %d %d %d %d %d %d %d", buf, ci, ci+1, ci+2, ci+3,
50 ci+4, ci+5, ci+6, ci+7, ci+8, ci+9, ci+10, ci+11,
51 ci+12, ci+13, ci+14, ci+15, ci+16, ci+17, ci+18, ci+19,
52 ci+20, ci+21, ci+22, ci+23, ci+24, ci+25, ci+26, ci+27,
53 ci+28, ci+29, ci+30, ci+31);
55 fclose(pFile);
57 for(i=0;i<10;i++)
59 sleep(1);
60 printf(".");
63 if((pFile=fopen(INTERRUPT_NAME, "r"))==NULL)
65 return 0;
68 fgets(buf, 255, pFile);
69 fscanf(pFile, "%s %d %d %d %d %d %d %d %d \
70 %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \
71 %d %d %d %d %d %d %d %d", buf, cj, cj+1, cj+2, cj+3,
72 cj+4, cj+5, cj+6, cj+7, cj+8, cj+9, cj+10, cj+11,
73 cj+12, cj+13, cj+14, cj+15, cj+16, cj+17, cj+18, cj+19,
74 cj+20, cj+21, cj+22, cj+23, cj+24, cj+25, cj+26, cj+27,
75 cj+28, cj+29, cj+30, cj+31);
77 fclose(pFile);
79 printf("\n\n");
80 printf("Timer interrupt counts per CPU:\n");
81 d=cj[0]-ci[0];
82 printf("%d ", d);
83 cmax=cmin=d;
84 for(i=1;i<cpucount;i++)
86 d=cj[i]-ci[i];
87 printf("%d ", d);
88 if(cmax<d)
89 cmax=d;
90 if(cmin>d)
91 cmin=d;
94 printf("\n\n");
95 printf("max value: %d\n", cmax);
96 printf("min value: %d\n", cmin);
97 printf("\n");
99 if(cmin==0 || cmax/cmin>10)
101 return 0;
103 else
105 return 1;
109 // return 0 means Pass, return 1 means Fail.
110 int main(int argc, char *argv[])
112 tst_resm(TINFO, "Begin: HyperThreading Interrupt");
114 #ifndef __i386__
115 tst_brkm(TCONF, NULL, "This test suite can only execute on i386 architecture.");
116 #else
117 if (!check_ht_capability())
119 if(HT_InterruptDistribution())
120 tst_resm(TPASS, "Interrupt distribution is balanceable.");
121 else
122 tst_resm(TFAIL, "Interrupt distribution is not balanceable.");
124 else
126 tst_brkm(TCONF, NULL, "HT is not enabled or not supported.");
128 #endif
130 tst_resm(TINFO, "End: HyperThreading Interrupt");
132 return 0;