summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2015-01-19 01:53:18 +0000
committerderaadt <deraadt@openbsd.org>2015-01-19 01:53:18 +0000
commit6ef341b3569bc8cc194eba807f0ff09c1bb022d1 (patch)
tree8940784b690b5ce3b102c75e60b7a109f3cabaa7
parentmove to <limits.h> universe (diff)
downloadwireguard-openbsd-6ef341b3569bc8cc194eba807f0ff09c1bb022d1.tar.xz
wireguard-openbsd-6ef341b3569bc8cc194eba807f0ff09c1bb022d1.zip
like in ps(1), fetch the FSCALE value using sysctl rather than using
the header version ok guenther
-rw-r--r--usr.bin/top/loadavg.h7
-rw-r--r--usr.bin/top/machine.c17
-rw-r--r--usr.bin/top/machine.h3
3 files changed, 24 insertions, 3 deletions
diff --git a/usr.bin/top/loadavg.h b/usr.bin/top/loadavg.h
index 0dffd40713a..af1b692a91c 100644
--- a/usr.bin/top/loadavg.h
+++ b/usr.bin/top/loadavg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: loadavg.h,v 1.3 2002/07/15 17:20:36 deraadt Exp $ */
+/* $OpenBSD: loadavg.h,v 1.4 2015/01/19 01:53:18 deraadt Exp $ */
/*
* Top users/processes display for Unix
@@ -56,6 +56,11 @@
# endif
#endif
+#ifdef __OpenBSD__
+#undef FSCALE
+#define FSCALE fscale /* fetched via sysctl(3) */
+#endif
+
#ifdef FSCALE
# define FIXED_LOADAVG FSCALE
# define FIXED_PCTCPU FSCALE
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index fc87693b614..88969f8ebd0 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: machine.c,v 1.81 2015/01/16 06:40:13 deraadt Exp $ */
+/* $OpenBSD: machine.c,v 1.82 2015/01/19 01:53:18 deraadt Exp $ */
/*-
* Copyright (c) 1994 Thorsten Lockert <tholo@sigmasoft.com>
@@ -138,10 +138,23 @@ static int pageshift; /* log base 2 of the pagesize */
#define pagetok(size) ((size) << pageshift)
int ncpu;
+int fscale;
unsigned int maxslp;
int
+getfscale(void)
+{
+ int mib[] = { CTL_KERN, KERN_FSCALE };
+ size_t size = sizeof(fscale);
+
+ if (sysctl(mib, sizeof(mib) / sizeof(mib[0]),
+ &fscale, &size, NULL, 0) < 0)
+ return (-1);
+ return fscale;
+}
+
+int
getncpu(void)
{
int mib[] = { CTL_HW, HW_NCPU };
@@ -163,6 +176,8 @@ machine_init(struct statics *statics)
ncpu = getncpu();
if (ncpu == -1)
return (-1);
+ if (getfscale() == -1)
+ return (-1);
cpu_states = calloc(ncpu, CPUSTATES * sizeof(int64_t));
if (cpu_states == NULL)
err(1, NULL);
diff --git a/usr.bin/top/machine.h b/usr.bin/top/machine.h
index 312d382101e..b1eb86ee90b 100644
--- a/usr.bin/top/machine.h
+++ b/usr.bin/top/machine.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: machine.h,v 1.18 2014/09/17 01:56:54 dlg Exp $ */
+/* $OpenBSD: machine.h,v 1.19 2015/01/19 01:53:18 deraadt Exp $ */
/*
* Top users/processes display for Unix
@@ -95,3 +95,4 @@ extern uid_t proc_owner(pid_t);
extern struct kinfo_proc *getprocs(int, int, int *);
int getncpu(void);
+int getfscale(void);