diff options
author | Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com> | 2008-07-14 08:00:01 -0400 |
---|---|---|
committer | Avi Kivity <avi@qumranet.com> | 2008-10-15 04:15:15 -0400 |
commit | 3f7f95c65ef6a89472a28da1b9436eaeee288831 (patch) | |
tree | d453af46dceb3fcce512a110573cd2e8e4341cfa | |
parent | e32c8f2c0720fb21c6f4a5f6ccbebdadc878f707 (diff) |
KVM: kvmtrace: replace get_cycles with ktime_get v3
The current kvmtrace code uses get_cycles() while the interpretation would be
easier using using nanoseconds. ktime_get() should give at least the same
accuracy as get_cycles on all architectures (even better on 32bit archs) but
at a better unit (e.g. comparable between hosts with different frequencies.
[avi: avoid ktime_t in public header]
Signed-off-by: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
-rw-r--r-- | include/linux/kvm.h | 6 | ||||
-rw-r--r-- | virt/kvm/kvm_trace.c | 19 |
2 files changed, 13 insertions, 12 deletions
diff --git a/include/linux/kvm.h b/include/linux/kvm.h index 8a16b083df2e..5d08f11bb27f 100644 --- a/include/linux/kvm.h +++ b/include/linux/kvm.h | |||
@@ -322,12 +322,12 @@ struct kvm_trace_rec { | |||
322 | __u32 vcpu_id; | 322 | __u32 vcpu_id; |
323 | union { | 323 | union { |
324 | struct { | 324 | struct { |
325 | __u64 cycle_u64; | 325 | __u64 timestamp; |
326 | __u32 extra_u32[KVM_TRC_EXTRA_MAX]; | 326 | __u32 extra_u32[KVM_TRC_EXTRA_MAX]; |
327 | } __attribute__((packed)) cycle; | 327 | } __attribute__((packed)) timestamp; |
328 | struct { | 328 | struct { |
329 | __u32 extra_u32[KVM_TRC_EXTRA_MAX]; | 329 | __u32 extra_u32[KVM_TRC_EXTRA_MAX]; |
330 | } nocycle; | 330 | } notimestamp; |
331 | } u; | 331 | } u; |
332 | }; | 332 | }; |
333 | 333 | ||
diff --git a/virt/kvm/kvm_trace.c b/virt/kvm/kvm_trace.c index 9acb78b3cc9f..41dcc845f78c 100644 --- a/virt/kvm/kvm_trace.c +++ b/virt/kvm/kvm_trace.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/module.h> | 17 | #include <linux/module.h> |
18 | #include <linux/relay.h> | 18 | #include <linux/relay.h> |
19 | #include <linux/debugfs.h> | 19 | #include <linux/debugfs.h> |
20 | #include <linux/ktime.h> | ||
20 | 21 | ||
21 | #include <linux/kvm_host.h> | 22 | #include <linux/kvm_host.h> |
22 | 23 | ||
@@ -35,16 +36,16 @@ static struct kvm_trace *kvm_trace; | |||
35 | struct kvm_trace_probe { | 36 | struct kvm_trace_probe { |
36 | const char *name; | 37 | const char *name; |
37 | const char *format; | 38 | const char *format; |
38 | u32 cycle_in; | 39 | u32 timestamp_in; |
39 | marker_probe_func *probe_func; | 40 | marker_probe_func *probe_func; |
40 | }; | 41 | }; |
41 | 42 | ||
42 | static inline int calc_rec_size(int cycle, int extra) | 43 | static inline int calc_rec_size(int timestamp, int extra) |
43 | { | 44 | { |
44 | int rec_size = KVM_TRC_HEAD_SIZE; | 45 | int rec_size = KVM_TRC_HEAD_SIZE; |
45 | 46 | ||
46 | rec_size += extra; | 47 | rec_size += extra; |
47 | return cycle ? rec_size += KVM_TRC_CYCLE_SIZE : rec_size; | 48 | return timestamp ? rec_size += KVM_TRC_CYCLE_SIZE : rec_size; |
48 | } | 49 | } |
49 | 50 | ||
50 | static void kvm_add_trace(void *probe_private, void *call_data, | 51 | static void kvm_add_trace(void *probe_private, void *call_data, |
@@ -69,20 +70,20 @@ static void kvm_add_trace(void *probe_private, void *call_data, | |||
69 | WARN_ON(!(extra <= KVM_TRC_EXTRA_MAX)); | 70 | WARN_ON(!(extra <= KVM_TRC_EXTRA_MAX)); |
70 | extra = min_t(u32, extra, KVM_TRC_EXTRA_MAX); | 71 | extra = min_t(u32, extra, KVM_TRC_EXTRA_MAX); |
71 | 72 | ||
72 | rec.rec_val |= TRACE_REC_TCS(p->cycle_in) | 73 | rec.rec_val |= TRACE_REC_TCS(p->timestamp_in) |
73 | | TRACE_REC_NUM_DATA_ARGS(extra); | 74 | | TRACE_REC_NUM_DATA_ARGS(extra); |
74 | 75 | ||
75 | if (p->cycle_in) { | 76 | if (p->timestamp_in) { |
76 | rec.u.cycle.cycle_u64 = get_cycles(); | 77 | rec.u.timestamp.timestamp = ktime_to_ns(ktime_get()); |
77 | 78 | ||
78 | for (i = 0; i < extra; i++) | 79 | for (i = 0; i < extra; i++) |
79 | rec.u.cycle.extra_u32[i] = va_arg(*args, u32); | 80 | rec.u.timestamp.extra_u32[i] = va_arg(*args, u32); |
80 | } else { | 81 | } else { |
81 | for (i = 0; i < extra; i++) | 82 | for (i = 0; i < extra; i++) |
82 | rec.u.nocycle.extra_u32[i] = va_arg(*args, u32); | 83 | rec.u.notimestamp.extra_u32[i] = va_arg(*args, u32); |
83 | } | 84 | } |
84 | 85 | ||
85 | size = calc_rec_size(p->cycle_in, extra * sizeof(u32)); | 86 | size = calc_rec_size(p->timestamp_in, extra * sizeof(u32)); |
86 | relay_write(kt->rchan, &rec, size); | 87 | relay_write(kt->rchan, &rec, size); |
87 | } | 88 | } |
88 | 89 | ||