summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2014-03-11 14:24:24 +0100
committerClifford Wolf <clifford@clifford.at>2014-03-11 14:24:24 +0100
commit91704a78531bec2e3eea3ddf90eaedb28e1d696d (patch)
treea3817eb12cebb9e9adc0f2375eda59ddb2d9004a /kernel
parent9992026a8d4482abd8fbae8cb246a87cbbbde364 (diff)
Merged a few fixes for non-posix systems from github.com/Siesh1oo/yosys
(see https://github.com/cliffordwolf/yosys/pull/28)
Diffstat (limited to 'kernel')
-rw-r--r--kernel/driver.cc1
-rw-r--r--kernel/log.h16
-rw-r--r--kernel/register.cc1
3 files changed, 18 insertions, 0 deletions
diff --git a/kernel/driver.cc b/kernel/driver.cc
index 00a61ec0..ce95cad4 100644
--- a/kernel/driver.cc
+++ b/kernel/driver.cc
@@ -24,6 +24,7 @@
#include <unistd.h>
#include <libgen.h>
#include <dlfcn.h>
+#include <errno.h>
#include <algorithm>
diff --git a/kernel/log.h b/kernel/log.h
index c4c03352..fbc3c1c3 100644
--- a/kernel/log.h
+++ b/kernel/log.h
@@ -23,6 +23,8 @@
#include "kernel/rtlil.h"
#include <stdio.h>
#include <time.h>
+#include <sys/time.h>
+#include <sys/resource.h>
#include <vector>
extern std::vector<FILE*> log_files;
@@ -65,9 +67,23 @@ struct PerformanceTimer
}
static int64_t query() {
+#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0)
struct timespec ts;
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
return int64_t(ts.tv_sec)*1000000000 + ts.tv_nsec;
+#elif defined(RUSAGE_SELF)
+ struct rusage rusage;
+ int64_t t;
+ if (getrusage(RUSAGE_SELF, &rusage) == -1) {
+ log_cmd_error("getrusage failed!\n");
+ log_abort();
+ }
+ t = 1000000000ULL * (int64_t) rusage.ru_utime.tv_sec + (int64_t) rusage.ru_utime.tv_usec * 1000ULL;
+ t += 1000000000ULL * (int64_t) rusage.ru_stime.tv_sec + (int64_t) rusage.ru_stime.tv_usec * 1000ULL;
+ return t;
+#else
+ #error Dont know how to measure per-process CPU time. Need alternative method (times()/clocks()/gettimeofday()?).
+#endif
}
void reset() {
diff --git a/kernel/register.cc b/kernel/register.cc
index ee14ffba..ab5cba11 100644
--- a/kernel/register.cc
+++ b/kernel/register.cc
@@ -23,6 +23,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
+#include <errno.h>
using namespace REGISTER_INTERN;
#define MAX_REG_COUNT 1000