summaryrefslogtreecommitdiffstats
path: root/darwin/Platform.c
diff options
context:
space:
mode:
authorBenny Baumann <BenBE@geshi.org>2020-12-12 20:43:08 +0100
committerBenny Baumann <BenBE@geshi.org>2020-12-13 11:47:34 +0100
commitf32f0188cd140f965c5e02f7fb875116522c4b41 (patch)
tree5eeffc53cf9c7ad26f441e31df7df6a15e81fa9f /darwin/Platform.c
parente65cdf947cba77e143a31981295062f1aef6d494 (diff)
Correct timebase for non-x86 CPUs on Darwin
Fixes: #368
Diffstat (limited to 'darwin/Platform.c')
-rw-r--r--darwin/Platform.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/darwin/Platform.c b/darwin/Platform.c
index d22ba579..69cd32a4 100644
--- a/darwin/Platform.c
+++ b/darwin/Platform.c
@@ -6,6 +6,8 @@ Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text.
*/
+#include "config.h" // IWYU pragma: keep
+
#include "Platform.h"
#include <math.h>
@@ -32,6 +34,10 @@ in the source distribution for its full text.
#include "zfs/ZfsArcMeter.h"
#include "zfs/ZfsCompressedArcMeter.h"
+#ifdef HAVE_MACH_MACH_TIME_H
+#include <mach/mach_time.h>
+#endif
+
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_VIRT, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
@@ -135,8 +141,18 @@ const MeterClass* const Platform_meterTypes[] = {
int Platform_numberOfFields = 100;
+double Platform_timebaseToNS = 1.0;
+
void Platform_init(void) {
- /* no platform-specific setup needed */
+ // Check if we can determine the timebase used on this system.
+ // If the API is unavailable assume we get our timebase in nanoseconds.
+#ifdef HAVE_MACH_TIMEBASE_INFO
+ mach_timebase_info_data_t info;
+ mach_timebase_info(&info);
+ Platform_timebaseToNS = (double)info.numer / (double)info.denom;
+#else
+ Platform_timebaseToNS = 1.0;
+#endif
}
void Platform_done(void) {

© 2014-2024 Faster IT GmbH | imprint | privacy policy