| @@ -1,46 +1,56 @@ | | | @@ -1,46 +1,56 @@ |
1 | $NetBSD: patch-CPU.xs,v 1.1 2014/08/13 20:20:23 wiz Exp $ | | 1 | $NetBSD: patch-CPU.xs,v 1.2 2020/10/28 12:04:02 nia Exp $ |
2 | | | 2 | |
3 | Add NetBSD support. | | 3 | Add NetBSD support. |
4 | https://rt.cpan.org/Public/Bug/Display.html?id=98004 | | 4 | https://rt.cpan.org/Public/Bug/Display.html?id=98004 |
5 | | | 5 | |
6 | --- CPU.xs.orig 2013-11-27 22:40:07.000000000 +0000 | | 6 | --- CPU.xs.orig 2013-11-27 22:40:07.000000000 +0000 |
7 | +++ CPU.xs | | 7 | +++ CPU.xs |
8 | @@ -40,7 +40,7 @@ | | 8 | @@ -40,7 +40,7 @@ |
9 | #define _have_cpu_clock | | 9 | #define _have_cpu_clock |
10 | #define _have_cpu_type | | 10 | #define _have_cpu_type |
11 | #endif | | 11 | #endif |
12 | -#ifdef __FreeBSD__ | | 12 | -#ifdef __FreeBSD__ |
13 | +#if defined(__FreeBSD__) || defined(__NetBSD__) | | 13 | +#if defined(__FreeBSD__) || defined(__NetBSD__) |
14 | #include <sys/sysctl.h> | | 14 | #include <sys/sysctl.h> |
15 | #define _have_cpu_type | | 15 | #define _have_cpu_type |
16 | #define _have_cpu_clock | | 16 | #define _have_cpu_clock |
17 | @@ -345,6 +345,17 @@ CODE: | | 17 | @@ -345,6 +345,27 @@ CODE: |
18 | size_t len = sizeof(clock); | | 18 | size_t len = sizeof(clock); |
19 | sysctlbyname("hw.clockrate", &clock, &len, NULL, 0); | | 19 | sysctlbyname("hw.clockrate", &clock, &len, NULL, 0); |
20 | #endif | | 20 | #endif |
21 | +#ifdef __NetBSD__ | | 21 | +#ifdef __NetBSD__ |
22 | + size_t len = sizeof(clock); | | 22 | + size_t len = sizeof(clock); |
23 | + char const *name; | | 23 | + char const *name; |
24 | + | | 24 | + |
25 | + if (sysctlbyname("machdep.powernow.frequency.current", NULL, &len, NULL, 0) == 0) | | 25 | + if (sysctlbyname("machdep.powernow.frequency.current", NULL, &len, NULL, 0) == 0) |
26 | + name = "machdep.powernow.frequency.current"; | | 26 | + name = "machdep.powernow.frequency.current"; |
27 | + else if (sysctlbyname("machdep.est.frequency.current", NULL, &len, NULL, 0) == 0) | | 27 | + else if (sysctlbyname("machdep.est.frequency.current", NULL, &len, NULL, 0) == 0) |
28 | + name = "machdep.est.frequency.current"; | | 28 | + name = "machdep.est.frequency.current"; |
| | | 29 | + else if (sysctlbyname("machdep.loongson.frequency.current", NULL, &len, NULL, 0) == 0) |
| | | 30 | + name = "machdep.loongson.frequency.current"; |
| | | 31 | + else if (sysctlbyname("machdep.intrepid.frequency.current", NULL, &len, NULL, 0) == 0) |
| | | 32 | + name = "machdep.intrepid.frequency.current"; |
| | | 33 | + else if (sysctlbyname("machdep.cpufreq.cpu0.current", NULL, &len, NULL, 0) == 0) |
| | | 34 | + name = "machdep.cpufreq.cpu0.current"; |
| | | 35 | + else if (sysctlbyname("machdep.cpu.frequency.current", NULL, &len, NULL, 0) == 0) |
| | | 36 | + name = "machdep.cpu.frequency.current"; |
| | | 37 | + else if (sysctlbyname("machdep.frequency.current", NULL, &len, NULL, 0) == 0) |
| | | 38 | + name = "machdep.frequency.current"; |
29 | + | | 39 | + |
30 | + sysctlbyname(name, &clock, &len, NULL, 0); | | 40 | + sysctlbyname(name, &clock, &len, NULL, 0); |
31 | +#endif | | 41 | +#endif |
32 | #ifdef WINDOWS | | 42 | #ifdef WINDOWS |
33 | char *clock_str = malloc(MAX_IDENT_SIZE); | | 43 | char *clock_str = malloc(MAX_IDENT_SIZE); |
34 | /*!! untested !!*/ | | 44 | /*!! untested !!*/ |
35 | @@ -394,6 +405,11 @@ CODE: | | 45 | @@ -394,6 +415,11 @@ CODE: |
36 | size_t len = MAX_IDENT_SIZE; | | 46 | size_t len = MAX_IDENT_SIZE; |
37 | sysctlbyname("hw.model", value, &len, NULL, 0); | | 47 | sysctlbyname("hw.model", value, &len, NULL, 0); |
38 | #endif | | 48 | #endif |
39 | +#ifdef __NetBSD__ | | 49 | +#ifdef __NetBSD__ |
40 | + value = malloc(MAX_IDENT_SIZE); | | 50 | + value = malloc(MAX_IDENT_SIZE); |
41 | + size_t len = MAX_IDENT_SIZE; | | 51 | + size_t len = MAX_IDENT_SIZE; |
42 | + sysctlbyname("hw.model", value, &len, NULL, 0); | | 52 | + sysctlbyname("hw.model", value, &len, NULL, 0); |
43 | +#endif | | 53 | +#endif |
44 | #ifdef __linux__ | | 54 | #ifdef __linux__ |
45 | #if defined __s390__ || defined __s390x__ | | 55 | #if defined __s390__ || defined __s390x__ |
46 | value = processor_machine_field (proc_cpuinfo_field ("processor") ); | | 56 | value = processor_machine_field (proc_cpuinfo_field ("processor") ); |