From aeaead20b8ddc92fd1dc0f4acbc7aeb2ce866b14 Mon Sep 17 00:00:00 2001
From: Peter Wemm <peter@FreeBSD.org>
Date: Thu, 31 Jul 2003 01:36:24 +0000
Subject: [PATCH] When ktracing context switches, make sure we record
 involuntary switches. Otherwise, when we get a evicted from the cpu, there is
 no record of it. This is not a default ktrace flag.

---
 sys/kern/subr_trap.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/sys/kern/subr_trap.c b/sys/kern/subr_trap.c
index 3c0a7604b0f9..05d250d395ee 100644
--- a/sys/kern/subr_trap.c
+++ b/sys/kern/subr_trap.c
@@ -40,6 +40,7 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#include "opt_ktrace.h"
 #include "opt_mac.h"
 #ifdef __i386__
 #include "opt_npx.h"
@@ -59,6 +60,11 @@ __FBSDID("$FreeBSD$");
 #include <sys/signalvar.h>
 #include <sys/systm.h>
 #include <sys/vmmeter.h>
+#ifdef KTRACE
+#include <sys/uio.h>
+#include <sys/ktrace.h>
+#endif
+
 #include <machine/cpu.h>
 #include <machine/pcb.h>
 
@@ -236,11 +242,19 @@ ast(struct trapframe *framep)
 		mac_thread_userret(td);
 #endif
 	if (flags & TDF_NEEDRESCHED) {
+#ifdef KTRACE
+		if (KTRPOINT(td, KTR_CSW))
+			ktrcsw(1, 0);
+#endif
 		mtx_lock_spin(&sched_lock);
 		sched_prio(td, kg->kg_user_pri);
 		p->p_stats->p_ru.ru_nivcsw++;
 		mi_switch();
 		mtx_unlock_spin(&sched_lock);
+#ifdef KTRACE
+		if (KTRPOINT(td, KTR_CSW))
+			ktrcsw(0, 0);
+#endif
 	}
 	if (flags & TDF_NEEDSIGCHK) {
 		PROC_LOCK(p);