Commit Graph

26 Commits

Author SHA1 Message Date
Omar Polo 73f9c8dfd5 avoid cgo for cpu_openbsd
Even thought OpenBSD often breaks the ABI compatibility and doesn't make
*any* promise of "stability", this project aims to be "pure go" so avoid
doing inter-op at the cost of artificially reducing the number of
supported architectures down to amd64 and i386.

To add support for another architecture (e.g. arm), add another file
cpu_openbsd_${arch}.go like done for 386 and amd64.  The fields are
declared as `long' in C, so pick the appropriate size when declaring the
struct.
2022-02-24 15:05:18 +01:00
Omar Polo 3c3c017f23 avoid copying kernCPUStats 2022-02-08 11:41:54 +00:00
Omar Polo 57d5711d44 refactor TimesWithContext
don't make assumptions on which CPUs are online and wich aren't based
on hw.smt and hw.ncpuonline.  Rather, use KERN_CPUSTATS to get the CPU
statistics, which includes a flag field that can tell us if that CPU
is online or not.
2022-02-06 23:47:17 +00:00
Omar Polo 16cc7d7d73 improve sysctl parsing: use native byte order
We can't use unix.Sysctl* for some sysctls, so we're on our own with
converting data from C arrays.

Don't assume that the byte order is little endian but do the right
thing.  Moreover, there's a little distinction in the sizes reported
by KERN_CPTIME (long[cpustates]) and KERN_CPTIME2
(u_int64_t[cpustates]) so account for that too.
2022-02-06 23:47:17 +00:00
Omar Polo 73db061652 some typos + rename smt to smtEnabled for readability 2022-02-06 23:47:17 +00:00
Omar Polo 9203029aae drop compatibilty with OpenBSD < 6.4
6.3 was EOL'd more than three years ago!
2022-02-06 23:47:16 +00:00
mmorel-35 1e6b445a8a gofumpt 2021-12-22 21:54:41 +00:00
shirou 0969c9436b delete v2 directory, move v3 to top #1078 2021-11-30 23:47:59 +00:00
Tobias Klauser ee12f66e4d cpu, v3/cpu: use sysconf package instead of exec'ing getconf
Currently, ClocksPerSec is determined by exec'ing getconf in func init,
i.e. on startup of every program importing the package. getconf might
not be present on some systems or is not executable by the current user.
To avoid this hard to control dependency, use the
github.com/tklauser/go-sysconf package which implements sysconf(3)
entirely in Go without cgo. The package is supported on all platforms
currently supported by the cpu and v3/cpu package of gopsutil.
2021-02-19 12:20:10 +01:00
Tobias Klauser 548c500117 Use unix.SysctlUin32("hw.ncpuonline") on OpenBSD
Use SysctlUvmexp from golang.org/x/sys/unix to avoid having to simplify
the implementation of cpu.InfoWithContext

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2020-09-01 11:22:28 +02:00
shirou 4b629897d2
Merge pull request #647 from omar-polo/master
[OpenBSD][CPU] fix per-cpu
2019-06-01 10:24:59 +09:00
Segflow 86c7289ccc Fix: use filename in exec.LookPath instead of full path
exec.LookPath searches for the file in the $PATH, which mean giving it an absolute path is against it's own purposes.
2019-05-05 20:45:07 +01:00
Omar Polo 3cbb0873de
int32 is enough -- don't waste space 2019-05-02 12:24:16 +02:00
Omar Polo 53ce014b14
handle EOPNOTSUPP when checking for hw.smt
if hw.smt is not applicable for the current platform (e.g. i386),
pretend it's enabled
2019-03-19 20:06:12 +01:00
Omar Polo c28fe78291
forget to take addr 2019-03-18 19:58:50 +01:00
Omar Polo 932f2f6049
Fix cpu stats when hw.smt is enabled
When hw.smt is enabled, and it's enabled by default from 6.4, the
number of cpus given by `runtime.NumCPU()` is half of the total: only
the cpuN with N = 0,2,4,... are used by the system. We need to detect
that and ask for the correct stats.
2019-03-16 12:26:03 +01:00
Omar Polo 12d92847cf
Get hw.ncpuonline without unix.SysctlUint32
unix.Sysctl always return an error when asking for hw.ncpuonline, so
revert to a direct unix.Syscall6 to get the cpu count.
2019-03-13 11:03:17 +01:00
Omar Polo c2c7893509
fix logic error + little refactor
Fix: get cptime of n-th cpu when `percpu` instead of the average.

While there, rearrange the last if statement to make the code a bit
more homogeneous.
2019-03-12 21:29:10 +01:00
Lomanic c0ca431bf1 [cpu][linux] Add support for logical arg in Counts #640 #628 2019-03-03 14:44:21 +01:00
Antoine Jacoutot 67297c8791 cpu: prefer cpuonline on OpenBSD
This gives us the value of actual online CPUs (as opposed to the
found ones which may not be able active).
2019-01-02 17:10:02 +01:00
Antoine Jacoutot 7276e963eb cpu: implement Mhz and Cores
Adapted from the FreeBSD code.
Successfully tested with Nomad.
2019-01-02 17:06:46 +01:00
Lomanic 5f8353c741 [cpu][openbsd] Fix #621, define CPU states according to OpenBSD version 2018-12-29 15:24:52 +01:00
shirou 4c73494c78 Add WithContext functions. 2017-12-31 15:25:49 +09:00
Sean Chittenden 635b971c0e
Move from the `syscall` package to the `golang.org/x/sys/{unix,windows}` 2017-06-02 13:51:00 -07:00
Cameron Sparr a213bf5e6d
run go fmt ./... 2017-02-01 23:05:29 +00:00
Marco Pfatschbacher b4846b445b Add support for OpenBSD/amd64
This code is based on the FreeBSD version
and implements roughly the same feature set.
2016-11-24 22:30:29 +01:00