Skip to contentSkip to conversation

trace "exit to userspace" event

PATCH Applied Gleb Natapov 3 participants 9 messages Oct 24, 2010 – Nov 1, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 trace "exit to userspace" event

Add tracepoint for userspace exit.

---
ChangeLog:
v1->v2
log error case too.

include/trace/events/kvm.h +30 -0
index 9c2cc6a..c86f4e8 100644
@@ -6,6 +6,36 @@
 #undef TRACE_SYSTEM
 #define TRACE_SYSTEM kvm
 
+#define ERSN(x) { KVM_EXIT_##x, "KVM_EXIT_" #x }
+
+#define kvm_trace_exit_reason						\
+	ERSN(UNKNOWN), ERSN(EXCEPTION), ERSN(IO), ERSN(HYPERCALL),	\
+	ERSN(DEBUG), ERSN(HLT), ERSN(MMIO), ERSN(IRQ_WINDOW_OPEN),	\
+	ERSN(SHUTDOWN), ERSN(FAIL_ENTRY), ERSN(INTR), ERSN(SET_TPR),	\
+	ERSN(TPR_ACCESS), ERSN(S390_SIEIC), ERSN(S390_RESET), ERSN(DCR),\
+	ERSN(NMI), ERSN(INTERNAL_ERROR), ERSN(OSI)
+
+TRACE_EVENT(kvm_userspace_exit,
+	    TP_PROTO(__u32 reason, int errno),
+	    TP_ARGS(reason, errno),
+
+	TP_STRUCT__entry(
+		__field(	__u32,		reason		)
+		__field(	int,		errno		)
+	),
+
+	TP_fast_assign(
+		__entry->reason		= reason;
+		__entry->errno		= errno;
+	),
+
+	TP_printk("reason %s (%d)",
+		  __entry->errno < 0 ?
+		  (__entry->errno == -EINTR ? "restart" : "error") :
+		  __print_symbolic(__entry->reason, kvm_trace_exit_reason),
+		  __entry->errno < 0 ? -__entry->errno : __entry->reason)
+);
+
 #if defined(__KVM_HAVE_IOAPIC)
 TRACE_EVENT(kvm_set_irq,
 	TP_PROTO(unsigned int gsi, int level, int irq_source_id),
virt/kvm/kvm_main.c +1 -0
index 361ad1a..88c42ae 100644
@@ -1537,6 +1537,7 @@ static long kvm_vcpu_ioctl(struct file *filp,
 		if (arg)
 			goto out;
 		r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run);
+		trace_kvm_userspace_exit(vcpu->run->exit_reason, r);
 		break;
 	case KVM_GET_REGS: {
 		struct kvm_regs *kvm_regs;

--
Gleb.

#1 lore raw
Quoted 6 lines · Gleb Natapov

Add tracepoint for userspace exit.

include/trace/events/kvm.h +3 -0
+
+TRACE_EVENT(kvm_userspace_exit,
+	    TP_PROTO(__u32 reason, int errno),

include/trace/events/kvm.h line 29

Quoted 10 lines
include/trace/events/kvm.h +10 -0
+	    TP_ARGS(reason, errno),
+
+	TP_STRUCT__entry(
+		__field(	__u32,		reason		)
+		__field(	int,		errno		)
+	),
+
+	TP_fast_assign(
+		__entry->reason		= reason;
+		__entry->errno		= errno;

Shouldn't this be -errno?

Quoted 22 lines
include/trace/events/kvm.h +9 -0
+	),
+
+	TP_printk("reason %s (%d)",
+		  __entry->errno<  0 ?
+		  (__entry->errno == -EINTR ? "restart" : "error") :
+		  __print_symbolic(__entry->reason, kvm_trace_exit_reason),
+		  __entry->errno<  0 ? -__entry->errno : __entry->reason)
+);
+
  #if defined(__KVM_HAVE_IOAPIC)
  TRACE_EVENT(kvm_set_irq,
  	TP_PROTO(unsigned int gsi, int level, int irq_source_id),
virt/kvm/kvm_main.c +1 -0
index 361ad1a..88c42ae 100644
@@ -1537,6 +1537,7 @@ static long kvm_vcpu_ioctl(struct file *filp,
  		if (arg)
  			goto out;
  		r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run);
+		trace_kvm_userspace_exit(vcpu->run->exit_reason, r);
  		break;
Signature · 1 line
error compiling committee.c: too many arguments to function
#2 lore raw
Quoted 4 lines · Avi Kivity
Quoted 3 lines · Gleb Natapov

Add tracepoint for userspace exit.

Quoted 16 lines

include/trace/events/kvm.h line 29

Quoted 13 lines
include/trace/events/kvm.h +13 -0
+
+TRACE_EVENT(kvm_userspace_exit,
+	    TP_PROTO(__u32 reason, int errno),
+	    TP_ARGS(reason, errno),
+
+	TP_STRUCT__entry(
+		__field(	__u32,		reason		)
+		__field(	int,		errno		)
+	),
+
+	TP_fast_assign(
+		__entry->reason		= reason;
+		__entry->errno		= errno;

Shouldn't this be -errno?

I check for __entry->errno < 0 below to see if exit was due to an error.

Quoted 14 lines
Quoted 14 lines
include/trace/events/kvm.h +9 -0
+	),
+
+	TP_printk("reason %s (%d)",
+		  __entry->errno<  0 ?
+		  (__entry->errno == -EINTR ? "restart" : "error") :
+		  __print_symbolic(__entry->reason, kvm_trace_exit_reason),
+		  __entry->errno<  0 ? -__entry->errno : __entry->reason)
+);
+
 #if defined(__KVM_HAVE_IOAPIC)
 TRACE_EVENT(kvm_set_irq,
 	TP_PROTO(unsigned int gsi, int level, int irq_source_id),
virt/kvm/kvm_main.c +0 -0
index 361ad1a..88c42ae 100644
Quoted 11 lines
Quoted 8 lines
virt/kvm/kvm_main.c +1 -0
@@ -1537,6 +1537,7 @@ static long kvm_vcpu_ioctl(struct file *filp,
 		if (arg)
 			goto out;
 		r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run);
+		trace_kvm_userspace_exit(vcpu->run->exit_reason, r);
 		break;
Signature · 1 line
error compiling committee.c: too many arguments to function

--
Gleb.

#3 lore raw
Quoted 19 lines · Gleb Natapov
Quoted 18 lines · Avi Kivity
Quoted 16 lines · Gleb Natapov

Add tracepoint for userspace exit.

include/trace/events/kvm.h +13 -0
+
+TRACE_EVENT(kvm_userspace_exit,
+	    TP_PROTO(__u32 reason, int errno),
+	    TP_ARGS(reason, errno),
+
+	TP_STRUCT__entry(
+		__field(	__u32,		reason		)
+		__field(	int,		errno		)
+	),
+
+	TP_fast_assign(
+		__entry->reason		= reason;
+		__entry->errno		= errno;
Quoted 4 lines
Quoted 2 lines

Shouldn't this be -errno?

I check for __entry->errno< 0 below to see if exit was due to an error.

Then check for > 0. If a variable is named errno, it should work as an input to strerror() (or a __print_symbolic for errno).

Signature · 1 line
error compiling committee.c: too many arguments to function
#4 lore raw
Quoted 20 lines · Avi Kivity
Quoted 19 lines · Gleb Natapov
Quoted 18 lines · Avi Kivity
Quoted 16 lines · Gleb Natapov

Add tracepoint for userspace exit.

include/trace/events/kvm.h +13 -0
+
+TRACE_EVENT(kvm_userspace_exit,
+	    TP_PROTO(__u32 reason, int errno),
+	    TP_ARGS(reason, errno),
+
+	TP_STRUCT__entry(
+		__field(	__u32,		reason		)
+		__field(	int,		errno		)
+	),
+
+	TP_fast_assign(
+		__entry->reason		= reason;
+		__entry->errno		= errno;
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Shouldn't this be -errno?

I check for __entry->errno< 0 below to see if exit was due to an error.

Then check for > 0. If a variable is named errno, it should work as

Is it documented that kvm_arch_vcpu_ioctl_run() never returns positive value?

Quoted 2 lines

an input to strerror() (or a __print_symbolic for errno).

__print_symbolic for all errno will be rather long. Anyway I think ftrace is not proper place to check for syscall errors. The only error value that is interesting here is EINTR, all others will cause userspace to halt. The only things that errno accomplish here is that TP_printk string become less readable.

--
Gleb.

#6 lore raw
Quoted 11 lines · Marcelo Tosatti
Quoted 7 lines · Gleb Natapov

Add tracepoint for userspace exit.

---
ChangeLog:
v1->v2
log error case too.

Applied, thanks.

errno sign is still flipped, no?

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#7 lore raw
Quoted 10 lines · Avi Kivity
Quoted 9 lines · Marcelo Tosatti
Quoted 7 lines · Gleb Natapov

Add tracepoint for userspace exit.

---
ChangeLog:
v1->v2
log error case too.

Quoted 4 lines
Quoted 2 lines

Applied, thanks.

errno sign is still flipped, no?

No, kvm_arch_vcpu_ioctl_run return -errno on error.

#8 lore raw
Quoted 11 lines · Marcelo Tosatti
Quoted 10 lines · Avi Kivity
Quoted 9 lines · Marcelo Tosatti
Quoted 7 lines · Gleb Natapov

Add tracepoint for userspace exit.

---
ChangeLog:
v1->v2
log error case too.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Applied, thanks.

errno sign is still flipped, no?

No, kvm_arch_vcpu_ioctl_run return -errno on error.

It's true that this is how the kernel ABI is defined, but for a user errnos are positive.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.