From owner-p4-projects@FreeBSD.ORG Sat Jan 5 21:45:28 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 33AA316A418; Sat, 5 Jan 2008 21:45:28 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D46F316A473 for ; Sat, 5 Jan 2008 21:45:27 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id CE2B213C455 for ; Sat, 5 Jan 2008 21:45:27 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m05LjRQG033700 for ; Sat, 5 Jan 2008 21:45:27 GMT (envelope-from jb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m05LjRTL033696 for perforce@freebsd.org; Sat, 5 Jan 2008 21:45:27 GMT (envelope-from jb@freebsd.org) Date: Sat, 5 Jan 2008 21:45:27 GMT Message-Id: <200801052145.m05LjRTL033696@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jb@freebsd.org using -f From: John Birrell To: Perforce Change Reviews Cc: Subject: PERFORCE change 132584 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 05 Jan 2008 21:45:28 -0000 http://perforce.freebsd.org/chv.cgi?CH=132584 Change 132584 by jb@jb_freebsd1 on 2008/01/05 21:44:43 Implement DTrace's virtual time. Affected files ... .. //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_load.c#24 edit .. //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_unload.c#20 edit .. //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_vtime.c#3 edit .. //depot/projects/dtrace/src/sys/kern/sched_4bsd.c#29 edit .. //depot/projects/dtrace/src/sys/kern/sched_ule.c#22 edit .. //depot/projects/dtrace/src/sys/sys/dtrace_bsd.h#11 edit .. //depot/projects/dtrace/src/sys/sys/proc.h#29 edit Differences ... ==== //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_load.c#24 (text+ko) ==== @@ -50,10 +50,8 @@ /* Hook into the trap handler. */ dtrace_trap_func = dtrace_trap; -#ifdef DOODAD /* Hang our hook for thread switches. */ dtrace_vtime_switch_func = dtrace_vtime_switch; -#endif /* * XXX This is a short term hack to avoid having to comment ==== //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_unload.c#20 (text+ko) ==== @@ -163,10 +163,8 @@ * Reset our hook for thread switches, but ensure that vtime isn't * active first. */ -#ifdef DOODAD dtrace_vtime_active = 0; dtrace_vtime_switch_func = NULL; -#endif /* Unhook from the trap handler. */ dtrace_trap_func = NULL; ==== //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_vtime.c#3 (text+ko) ==== @@ -27,7 +27,6 @@ void dtrace_vtime_enable(void) { -#ifdef DOODAD dtrace_vtime_state_t state, nstate = 0; do { @@ -50,13 +49,11 @@ } while (dtrace_cas32((uint32_t *)&dtrace_vtime_active, state, nstate) != state); -#endif } void dtrace_vtime_disable(void) { -#ifdef DOODAD dtrace_vtime_state_t state, nstate = 0; do { @@ -79,34 +76,24 @@ } while (dtrace_cas32((uint32_t *)&dtrace_vtime_active, state, nstate) != state); -#endif } void dtrace_vtime_switch(kthread_t *next) { -#ifdef DOODAD dtrace_icookie_t cookie; hrtime_t ts; - if (tnf_tracing_active) { - tnf_thread_switch(next); - - if (dtrace_vtime_active == DTRACE_VTIME_INACTIVE_TNF) - return; - } - cookie = dtrace_interrupt_disable(); ts = dtrace_gethrtime(); - if (curthread->td_dtrace_start != 0) { - curthread->td_dtrace_vtime += ts - curthread->td_dtrace_start; - curthread->td_dtrace_start = 0; + if (curthread->t_dtrace_start != 0) { + curthread->t_dtrace_vtime += ts - curthread->t_dtrace_start; + curthread->t_dtrace_start = 0; } if (next != NULL) - next->td_dtrace_start = ts; + next->t_dtrace_start = ts; dtrace_interrupt_enable(cookie); -#endif } ==== //depot/projects/dtrace/src/sys/kern/sched_4bsd.c#29 (text+ko) ==== @@ -59,6 +59,10 @@ #include #endif +#ifdef KDTRACE_HOOKS +#include +#endif + /* * INVERSE_ESTCPU_WEIGHT is only suitable for statclock() frequencies in * the range 100-256 Hz (approximately). @@ -880,6 +884,16 @@ #endif /* I feel sleepy */ lock_profile_release_lock(&sched_lock.lock_object); +#ifdef KDTRACE + /* + * If DTrace has set the active vtime enum to anything + * other than INACTIVE (0), then it should have set the + * function to call. + */ + if (dtrace_vtime_active) + (*dtrace_vtime_switch_func)(newtd); +#endif + cpu_switch(td, newtd, td->td_lock); lock_profile_obtain_lock_success(&sched_lock.lock_object, 0, 0, __FILE__, __LINE__); ==== //depot/projects/dtrace/src/sys/kern/sched_ule.c#22 (text+ko) ==== @@ -68,6 +68,10 @@ #include #endif +#ifdef KDTRACE_HOOKS +#include +#endif + #include #include @@ -1896,6 +1900,17 @@ #endif lock_profile_release_lock(&TDQ_LOCKPTR(tdq)->lock_object); TDQ_LOCKPTR(tdq)->mtx_lock = (uintptr_t)newtd; + +#ifdef KDTRACE + /* + * If DTrace has set the active vtime enum to anything + * other than INACTIVE (0), then it should have set the + * function to call. + */ + if (dtrace_vtime_active) + (*dtrace_vtime_switch_func)(newtd); +#endif + cpu_switch(td, newtd, mtx); /* * We may return from cpu_switch on a different cpu. However, ==== //depot/projects/dtrace/src/sys/sys/dtrace_bsd.h#11 (text+ko) ==== @@ -33,6 +33,7 @@ /* Forward definitions: */ struct trapframe; +struct thread; /* * Cyclic clock function type definition used to hook the cyclic @@ -65,6 +66,12 @@ /* Global variable in trap.c */ extern dtrace_invop_func_t dtrace_invop_func; +/* Virtual time hook function type. */ +typedef void (*dtrace_vtime_switch_func_t)(struct thread *); + +extern int dtrace_vtime_active; +extern dtrace_vtime_switch_func_t dtrace_vtime_switch_func; + /* * Functions which allow the dtrace module to check that the kernel * hooks have been compiled with sufficient space for it's private ==== //depot/projects/dtrace/src/sys/sys/proc.h#29 (text+ko) ==== @@ -445,11 +445,6 @@ #define TD_SET_RUNQ(td) (td)->td_state = TDS_RUNQ #define TD_SET_CAN_RUN(td) (td)->td_state = TDS_CAN_RUN -typedef void (*dtrace_vtime_switch_func_t)(struct thread *); - -extern int dtrace_vtime_active; -extern dtrace_vtime_switch_func_t dtrace_vtime_switch_func; - /* * An upcall is used when returning to userland. If a thread does not have * an upcall on return to userland the thread exports its context and exits.