Lines 1-111
Link Here
|
1 |
--- cpuid.c.orig 2011-09-15 15:43:00.000000000 -0700 |
|
|
2 |
+++ cpuid.c 2011-09-15 15:43:08.000000000 -0700 |
3 |
@@ -23,8 +23,16 @@ |
4 |
#include <sched.h> |
5 |
|
6 |
#if defined(__FreeBSD__) |
7 |
+# include <sys/param.h> |
8 |
+# include <sys/cpuset.h> |
9 |
# include <sys/ioctl.h> |
10 |
-# include <cpu.h> |
11 |
+# if __FreeBSD_version < 701102 |
12 |
+# define CPUDEV "/dev/cpu%d" |
13 |
+# include <cpu.h> |
14 |
+# else |
15 |
+# define CPUDEV "/dev/cpuctl%d" |
16 |
+# include <sys/cpuctl.h> |
17 |
+# endif |
18 |
#endif |
19 |
|
20 |
#include "x86info.h" |
21 |
@@ -45,7 +53,11 @@ |
22 |
unsigned int *eax, unsigned int *ebx, |
23 |
unsigned int *ecx, unsigned int *edx) |
24 |
{ |
25 |
+#if defined(__FreeBSD__) |
26 |
+ cpuset_t set, tmp_set; |
27 |
+#else |
28 |
cpu_set_t set, tmp_set; |
29 |
+#endif |
30 |
unsigned int a = 0, b = 0, c = 0, d = 0; |
31 |
int ret; |
32 |
|
33 |
@@ -58,15 +70,25 @@ |
34 |
if (edx != NULL) |
35 |
d = *edx; |
36 |
|
37 |
+#if defined(__FreeBSD__) |
38 |
+ ret = cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, |
39 |
+ -1, sizeof(set), &set); |
40 |
+#else |
41 |
ret = sched_getaffinity(getpid(), sizeof(set), &set); |
42 |
+#endif |
43 |
if (ret) |
44 |
return ret; |
45 |
|
46 |
/* man CPU_SET(3): To duplicate a CPU set, use memcpy(3) */ |
47 |
- memcpy(&tmp_set, &set, sizeof(cpu_set_t)); |
48 |
+ memcpy(&tmp_set, &set, sizeof(tmp_set)); |
49 |
CPU_ZERO(&set); |
50 |
CPU_SET(cpunr, &set); |
51 |
+#if defined(__FreeBSD__) |
52 |
+ ret = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, |
53 |
+ -1, sizeof(set), &set); |
54 |
+#else |
55 |
ret = sched_setaffinity(getpid(), sizeof(set), &set); |
56 |
+#endif |
57 |
if (ret) |
58 |
return ret; |
59 |
|
60 |
@@ -87,7 +109,12 @@ |
61 |
*edx = d; |
62 |
|
63 |
/* Restore initial sched affinity */ |
64 |
+#if defined(__FreeBSD__) |
65 |
+ ret = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, |
66 |
+ -1, sizeof(tmp_set), &tmp_set); |
67 |
+#else |
68 |
ret = sched_setaffinity(getpid(), sizeof(tmp_set), &tmp_set); |
69 |
+#endif |
70 |
if (ret) |
71 |
return ret; |
72 |
return 0; |
73 |
@@ -104,9 +131,12 @@ |
74 |
{ |
75 |
static int nodriver=0; |
76 |
char cpuname[20]; |
77 |
- unsigned char buffer[16]; |
78 |
int fh; |
79 |
+#if __FreeBSD_version < 701102 |
80 |
cpu_cpuid_args_t args; |
81 |
+#else |
82 |
+ cpuctl_cpuid_args_t args; |
83 |
+#endif |
84 |
|
85 |
if (nodriver == 1) { |
86 |
if (native_cpuid(CPU_number, idx, eax,ebx,ecx,edx)) |
87 |
@@ -116,10 +146,14 @@ |
88 |
|
89 |
args.level = idx; |
90 |
/* Ok, use the /dev/CPU interface in preference to the _up code. */ |
91 |
- (void)snprintf(cpuname,18, "/dev/cpu%d", CPU_number); |
92 |
+ (void)snprintf(cpuname,18, CPUDEV, CPU_number); |
93 |
fh = open(cpuname, O_RDONLY); |
94 |
if (fh != -1) { |
95 |
+#if __FreeBSD_version < 701102 |
96 |
if (ioctl(fh, CPU_CPUID, &args) != 0) { |
97 |
+#else |
98 |
+ if (ioctl(fh, CPUCTL_CPUID, &args) != 0) { |
99 |
+#endif |
100 |
perror(cpuname); |
101 |
exit(EXIT_FAILURE); |
102 |
} |
103 |
@@ -134,8 +168,6 @@ |
104 |
} else { |
105 |
/* Something went wrong, just do UP and hope for the best. */ |
106 |
nodriver = 1; |
107 |
- if (nrCPUs != 1) |
108 |
- perror(cpuname); |
109 |
if (native_cpuid(CPU_number, idx, eax,ebx,ecx,edx)) |
110 |
printf("%s", NATIVE_CPUID_FAILED_MSG); |
111 |
|