Lines 1-5
Link Here
|
1 |
--- ./helper_functions.c.orig 2012-09-11 08:15:54.000000000 +0200 |
1 |
--- ./helper_functions.c.orig 2012-09-11 08:15:54.000000000 +0200 |
2 |
+++ ./helper_functions.c 2012-12-11 14:41:28.000000000 +0100 |
2 |
+++ ./helper_functions.c 2015-04-05 20:52:59.850869370 +0200 |
3 |
@@ -30,6 +30,11 @@ |
3 |
@@ -30,6 +30,11 @@ |
4 |
#include <inttypes.h> |
4 |
#include <inttypes.h> |
5 |
#include <sys/types.h> |
5 |
#include <sys/types.h> |
Lines 27-33
Link Here
|
27 |
int Get_Bits_Value(unsigned long val,int highbit, int lowbit){ |
27 |
int Get_Bits_Value(unsigned long val,int highbit, int lowbit){ |
28 |
unsigned long data = val; |
28 |
unsigned long data = val; |
29 |
int bits = highbit - lowbit + 1; |
29 |
int bits = highbit - lowbit + 1; |
30 |
@@ -234,7 +247,7 @@ |
30 |
@@ -92,14 +105,22 @@ |
|
|
31 |
static inline void cpuid (unsigned int info, unsigned int *eax, unsigned int *ebx, |
32 |
unsigned int *ecx, unsigned int *edx) |
33 |
{ |
34 |
- unsigned int _eax = info, _ebx, _ecx, _edx; |
35 |
- asm volatile ("mov %%ebx, %%edi;" // save ebx (for PIC) |
36 |
- "cpuid;" |
37 |
- "mov %%ebx, %%esi;" // pass to caller |
38 |
- "mov %%edi, %%ebx;" // restore ebx |
39 |
- :"+a" (_eax), "=S" (_ebx), "=c" (_ecx), "=d" (_edx) |
40 |
- : /* inputs: eax is handled above */ |
41 |
- :"edi" /* clobbers: we hit edi directly */); |
42 |
+ unsigned int _eax, _ebx, _ecx, _edx; |
43 |
+ asm volatile ( |
44 |
+#ifdef __i386__ |
45 |
+ "pushl %%ebx\n" // save ebx (for PIC) |
46 |
+#else // __x86_64__ |
47 |
+ "pushq %%rbx\n" // save rbx (for PIC) |
48 |
+#endif |
49 |
+ "cpuid\n" |
50 |
+ "mov %%ebx, %1\n" // pass to caller |
51 |
+#ifdef __i386__ |
52 |
+ "popl %%ebx\n" // restore ebx |
53 |
+#else // __x86_64__ |
54 |
+ "popq %%rbx\n" // restore rbx |
55 |
+#endif |
56 |
+ :"=a" (_eax), "=r" (_ebx), "=c" (_ecx), "=d" (_edx) |
57 |
+ :"0" (info)); |
58 |
if (eax) *eax = _eax; |
59 |
if (ebx) *ebx = _ebx; |
60 |
if (ecx) *ecx = _ecx; |
61 |
@@ -234,7 +255,7 @@ |
31 |
int bits; |
62 |
int bits; |
32 |
*error_indx =0; |
63 |
*error_indx =0; |
33 |
|
64 |
|
Lines 36-42
Link Here
|
36 |
fd = open (msr_file_name, O_RDONLY); |
67 |
fd = open (msr_file_name, O_RDONLY); |
37 |
if (fd < 0) |
68 |
if (fd < 0) |
38 |
{ |
69 |
{ |
39 |
@@ -255,11 +268,21 @@ |
70 |
@@ -255,11 +276,21 @@ |
40 |
} |
71 |
} |
41 |
} |
72 |
} |
42 |
|
73 |
|
Lines 58-64
Link Here
|
58 |
|
89 |
|
59 |
close (fd); |
90 |
close (fd); |
60 |
|
91 |
|
61 |
@@ -287,7 +310,7 @@ |
92 |
@@ -287,7 +318,7 @@ |
62 |
int fd; |
93 |
int fd; |
63 |
char msr_file_name[64]; |
94 |
char msr_file_name[64]; |
64 |
|
95 |
|
Lines 67-73
Link Here
|
67 |
fd = open (msr_file_name, O_WRONLY); |
98 |
fd = open (msr_file_name, O_WRONLY); |
68 |
if (fd < 0) |
99 |
if (fd < 0) |
69 |
{ |
100 |
{ |
70 |
@@ -304,11 +327,21 @@ |
101 |
@@ -304,11 +335,21 @@ |
71 |
} |
102 |
} |
72 |
} |
103 |
} |
73 |
|
104 |
|
Lines 89-95
Link Here
|
89 |
close(fd); |
120 |
close(fd); |
90 |
return(1); |
121 |
return(1); |
91 |
} |
122 |
} |
92 |
@@ -487,10 +520,10 @@ |
123 |
@@ -487,10 +528,10 @@ |
93 |
void Test_Or_Make_MSR_DEVICE_FILES() |
124 |
void Test_Or_Make_MSR_DEVICE_FILES() |
94 |
{ |
125 |
{ |
95 |
//test if the msr file exists |
126 |
//test if the msr file exists |
Lines 103-109
Link Here
|
103 |
{ |
134 |
{ |
104 |
//a system mght have been set with msr allowable to be written |
135 |
//a system mght have been set with msr allowable to be written |
105 |
//by a normal user so... |
136 |
//by a normal user so... |
106 |
@@ -505,6 +538,7 @@ |
137 |
@@ -505,6 +546,7 @@ |
107 |
printf ("i7z DEBUG: msr device files DONOT exist, trying out a makedev script\n"); |
138 |
printf ("i7z DEBUG: msr device files DONOT exist, trying out a makedev script\n"); |
108 |
if (geteuid () == 0) |
139 |
if (geteuid () == 0) |
109 |
{ |
140 |
{ |
Lines 111-117
Link Here
|
111 |
//Try the Makedev script |
142 |
//Try the Makedev script |
112 |
//sourced from MAKEDEV-cpuid-msr script in msr-tools |
143 |
//sourced from MAKEDEV-cpuid-msr script in msr-tools |
113 |
system ("msr_major=202; \ |
144 |
system ("msr_major=202; \ |
114 |
@@ -519,6 +553,9 @@ |
145 |
@@ -519,6 +561,9 @@ |
115 |
"); |
146 |
"); |
116 |
printf ("i7z DEBUG: modprobbing for msr\n"); |
147 |
printf ("i7z DEBUG: modprobbing for msr\n"); |
117 |
system ("modprobe msr"); |
148 |
system ("modprobe msr"); |
Lines 121-127
Link Here
|
121 |
} else { |
152 |
} else { |
122 |
printf ("i7z DEBUG: You DONOT have root privileges, mknod to create device entries won't work out\n"); |
153 |
printf ("i7z DEBUG: You DONOT have root privileges, mknod to create device entries won't work out\n"); |
123 |
printf ("i7z DEBUG: A solution is to run this program as root\n"); |
154 |
printf ("i7z DEBUG: A solution is to run this program as root\n"); |
124 |
@@ -526,6 +563,7 @@ |
155 |
@@ -526,6 +571,7 @@ |
125 |
} |
156 |
} |
126 |
} |
157 |
} |
127 |
} |
158 |
} |
Lines 129-135
Link Here
|
129 |
double cpufreq_info() |
160 |
double cpufreq_info() |
130 |
{ |
161 |
{ |
131 |
//CPUINFO is wrong for i7 but correct for the number of physical and logical cores present |
162 |
//CPUINFO is wrong for i7 but correct for the number of physical and logical cores present |
132 |
@@ -543,6 +581,21 @@ |
163 |
@@ -543,6 +589,21 @@ |
133 |
fclose (tmp_file); |
164 |
fclose (tmp_file); |
134 |
return atof(tmp_str); |
165 |
return atof(tmp_str); |
135 |
} |
166 |
} |
Lines 151-157
Link Here
|
151 |
|
182 |
|
152 |
int check_and_return_processor(char*strinfo) |
183 |
int check_and_return_processor(char*strinfo) |
153 |
{ |
184 |
{ |
154 |
@@ -669,6 +722,7 @@ |
185 |
@@ -669,6 +730,7 @@ |
155 |
printf("Socket-%d [num of cpus %d physical %d logical %d] %s\n",socket->socket_num,socket->max_cpu,socket->num_physical_cores,socket->num_logical_cores,socket_list); |
186 |
printf("Socket-%d [num of cpus %d physical %d logical %d] %s\n",socket->socket_num,socket->max_cpu,socket->num_physical_cores,socket->num_logical_cores,socket_list); |
156 |
} |
187 |
} |
157 |
|
188 |
|
Lines 159-165
Link Here
|
159 |
void construct_CPU_Heirarchy_info(struct cpu_heirarchy_info* chi) |
190 |
void construct_CPU_Heirarchy_info(struct cpu_heirarchy_info* chi) |
160 |
{ |
191 |
{ |
161 |
FILE *fp = fopen("/proc/cpuinfo","r"); |
192 |
FILE *fp = fopen("/proc/cpuinfo","r"); |
162 |
@@ -715,7 +769,51 @@ |
193 |
@@ -715,7 +777,51 @@ |
163 |
chi->max_online_cpu = it_processor_num+1; |
194 |
chi->max_online_cpu = it_processor_num+1; |
164 |
fclose(fp); |
195 |
fclose(fp); |
165 |
} |
196 |
} |