timer.cc (9881:638e865d70c6) timer.cc (10073:2360411a16be)
1/*
2 * Copyright (c) 2012 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 26 unchanged lines hidden (view full) ---

35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 * Authors: Andreas Sandberg
38 */
39
40#include <algorithm>
41#include <csignal>
42#include <ctime>
1/*
2 * Copyright (c) 2012 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 26 unchanged lines hidden (view full) ---

35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 * Authors: Andreas Sandberg
38 */
39
40#include <algorithm>
41#include <csignal>
42#include <ctime>
43#include <unistd.h>
44#include <sys/syscall.h>
43
44#include "base/misc.hh"
45#include "base/trace.hh"
46#include "cpu/kvm/timer.hh"
47#include "debug/KvmTimer.hh"
48
45
46#include "base/misc.hh"
47#include "base/trace.hh"
48#include "cpu/kvm/timer.hh"
49#include "debug/KvmTimer.hh"
50
51/* According to timer_create(2), the value SIGEV_THREAD_ID can be used
52 * to specify which thread a timer signal gets delivered to. According
53 * to the man page, the member sigev_notify_thread is used to specify
54 * the TID. This member is currently not defined by default in
55 * siginfo.h on x86, so we define it here as a workaround.
56 */
57#ifndef sigev_notify_thread_id
58#define sigev_notify_thread_id _sigev_un._tid
59#endif
60
61static pid_t
62gettid()
63{
64 return syscall(__NR_gettid);
65}
66
49/**
50 * Minimum number of cycles that a host can spend in a KVM call (used
51 * to calculate the resolution of some timers).
52 *
53 * The value of this constant is a bit arbitrary, but in practice, we
54 * can't really do anything useful in less than ~1000 cycles.
55 */
56static const uint64_t MIN_HOST_CYCLES = 1000;
57
58PosixKvmTimer::PosixKvmTimer(int signo, clockid_t clockID,
59 float hostFactor, Tick hostFreq)
60 : BaseKvmTimer(signo, hostFactor, hostFreq),
61 clockID(clockID)
62{
63 struct sigevent sev;
64
67/**
68 * Minimum number of cycles that a host can spend in a KVM call (used
69 * to calculate the resolution of some timers).
70 *
71 * The value of this constant is a bit arbitrary, but in practice, we
72 * can't really do anything useful in less than ~1000 cycles.
73 */
74static const uint64_t MIN_HOST_CYCLES = 1000;
75
76PosixKvmTimer::PosixKvmTimer(int signo, clockid_t clockID,
77 float hostFactor, Tick hostFreq)
78 : BaseKvmTimer(signo, hostFactor, hostFreq),
79 clockID(clockID)
80{
81 struct sigevent sev;
82
65 // TODO: We should request signal delivery to thread instead of
66 // the process here. Unfortunately this seems to be broken, or at
67 // least not work as specified in the man page.
68 sev.sigev_notify = SIGEV_SIGNAL;
83 sev.sigev_notify = SIGEV_THREAD_ID;
69 sev.sigev_signo = signo;
84 sev.sigev_signo = signo;
85 sev.sigev_notify_thread_id = gettid();
70 sev.sigev_value.sival_ptr = NULL;
71
72 while (timer_create(clockID, &sev, &timer) == -1) {
73 if (errno != EAGAIN)
74 panic("timer_create: %i", errno);
75 }
76}
77

--- 95 unchanged lines hidden ---
86 sev.sigev_value.sival_ptr = NULL;
87
88 while (timer_create(clockID, &sev, &timer) == -1) {
89 if (errno != EAGAIN)
90 panic("timer_create: %i", errno);
91 }
92}
93

--- 95 unchanged lines hidden ---