]> Cypherpunks repositories - gostls13.git/commitdiff
internal/sysinfo: implement CPUName on bsd systems
authorRuss Cox <rsc@golang.org>
Thu, 17 Aug 2023 19:44:20 +0000 (15:44 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 28 Mar 2024 14:40:31 +0000 (14:40 +0000)
sysctl machdep.cpu.brand_string seems to be standard
across the BSDs. There does not seem to be a standard
way to get the CPU frequency.

Change-Id: Ic986d6c81dd54e1b84544317f2a53ce16801319b
Reviewed-on: https://go-review.googlesource.com/c/go/+/520636
Auto-Submit: Russ Cox <rsc@golang.org>
TryBot-Bypass: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/internal/sysinfo/cpuinfo_bsd.go [new file with mode: 0644]
src/internal/sysinfo/cpuinfo_stub.go
src/internal/sysinfo/export_test.go [new file with mode: 0644]
src/internal/sysinfo/sysinfo_test.go [new file with mode: 0644]

diff --git a/src/internal/sysinfo/cpuinfo_bsd.go b/src/internal/sysinfo/cpuinfo_bsd.go
new file mode 100644 (file)
index 0000000..2c04c8f
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright 2023 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build darwin || freebsd || netbsd || openbsd
+
+package sysinfo
+
+import "syscall"
+
+func osCpuInfoName() string {
+       cpu, _ := syscall.Sysctl("machdep.cpu.brand_string")
+       return cpu
+}
index 5dcfed1137f1aa3c621c361e66ba51b78a08fb0c..273166ee61ceac582f98abdeccb19a9001dff845 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build !linux
+//go:build !(darwin || freebsd || linux || netbsd || openbsd)
 
 package sysinfo
 
diff --git a/src/internal/sysinfo/export_test.go b/src/internal/sysinfo/export_test.go
new file mode 100644 (file)
index 0000000..1c668d9
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2023 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package sysinfo
+
+var XosCpuInfoName = osCpuInfoName
diff --git a/src/internal/sysinfo/sysinfo_test.go b/src/internal/sysinfo/sysinfo_test.go
new file mode 100644 (file)
index 0000000..c2f1dd2
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2023 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package sysinfo_test
+
+import (
+       . "internal/sysinfo"
+       "testing"
+)
+
+func TestCPUName(t *testing.T) {
+       t.Logf("CPUName: %s", CPUName())
+       t.Logf("osCpuInfoName: %s", XosCpuInfoName())
+}