summaryrefslogtreecommitdiff
path: root/sysutils/x86info/files/patch-cpuid.c
blob: e2444f6b54d57345b8393f8edac16bce26b02bac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
--- cpuid.c.orig	2008-12-16 22:09:47.000000000 +0300
+++ cpuid.c	2008-12-30 22:36:09.000000000 +0300
@@ -23,8 +23,15 @@
 #include <sched.h>
 
 #if defined(__FreeBSD__)
+# include <sys/param.h>
 # include <sys/ioctl.h>
-# include <cpu.h>
+# if __FreeBSD_version < 800042
+#  define CPUDEV "/dev/cpu%d"
+#  include <cpu.h>
+# else
+#  define CPUDEV "/dev/cpuctl%d"
+#  include <sys/cpuctl.h>
+# endif
 #endif
 
 #include "x86info.h"
@@ -33,7 +40,9 @@
 	unsigned int *eax, unsigned int *ebx,
 	unsigned int *ecx, unsigned int *edx)
 {
+#if defined(__linux__)
 	cpu_set_t set;
+#endif
 	unsigned int a = 0, b = 0, c = 0, d = 0;
 
 	if (eax != NULL)
@@ -45,11 +54,13 @@
 	if (edx != NULL)
 		d = *edx;
 
+#if defined(__linux__)
 	if (sched_getaffinity(getpid(), sizeof(set), &set) == 0) {
 		CPU_ZERO(&set);
 		CPU_SET(cpunr, &set);
 		sched_setaffinity(getpid(), sizeof(set), &set);
 	}
+#endif
 
 	asm("cpuid"
 		: "=a" (a),
@@ -79,7 +90,11 @@
 	char cpuname[20];
 	unsigned char buffer[16];
 	int fh;
+#if __FreeBSD_version < 800042
 	cpu_cpuid_args_t args;
+#else
+	cpuctl_cpuid_args_t args;
+#endif
 
 	if (nodriver == 1) {
 		native_cpuid(CPU_number, idx, eax,ebx,ecx,edx);
@@ -88,10 +103,14 @@
 
 	args.level = idx;
 	/* Ok, use the /dev/CPU interface in preference to the _up code. */
-	(void)snprintf(cpuname,18, "/dev/cpu%d", CPU_number);
+	(void)snprintf(cpuname,18, CPUDEV, CPU_number);
 	fh = open(cpuname, O_RDONLY);
 	if (fh != -1) {
+#if __FreeBSD_version < 800042
 		if (ioctl(fh, CPU_CPUID, &args) != 0) {
+#else
+		if (ioctl(fh, CPUCTL_CPUID, &args) != 0) {
+#endif
 			perror(cpuname);
 			exit(EXIT_FAILURE);
 		}
@@ -106,8 +125,6 @@
 	} else {
 		/* Something went wrong, just do UP and hope for the best. */
 		nodriver = 1;
-		if (!silent && nrCPUs != 1)
-			perror(cpuname);
 		used_UP = 1;
 		native_cpuid(CPU_number, idx, eax,ebx,ecx,edx);
 		return;
@@ -154,7 +171,7 @@
 	fh = open(cpuname, O_RDONLY);
 	if (fh != -1) {
 #ifndef S_SPLINT_S
-		lseek64(fh, (off64_t)idx, SEEK_CUR);
+		lseek(fh, (off_t)idx, SEEK_CUR);
 #endif
 		if (read(fh, &buffer[0], CPUID_CHUNK_SIZE) == -1) {
 			perror(cpuname);