From owner-p4-projects@FreeBSD.ORG Fri May 19 01:27:50 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id F30E016A51A; Fri, 19 May 2006 01:27:49 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B746B16A516 for ; Fri, 19 May 2006 01:27:49 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4C53243D78 for ; Fri, 19 May 2006 01:27:40 +0000 (GMT) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k4J1RDEb037778 for ; Fri, 19 May 2006 01:27:13 GMT (envelope-from jb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k4J1RDYS037769 for perforce@freebsd.org; Fri, 19 May 2006 01:27:13 GMT (envelope-from jb@freebsd.org) Date: Fri, 19 May 2006 01:27:13 GMT Message-Id: <200605190127.k4J1RDYS037769@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 97438 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: Fri, 19 May 2006 01:27:50 -0000 http://perforce.freebsd.org/chv.cgi?CH=97438 Change 97438 by jb@jb_freebsd2 on 2006/05/19 01:26:52 Add the backend for Statically Defined Tracing (SDT). This is infrastructure which isn't optional, unlike other kernel DTrace support. The reason for this is that a third-party module author needs to be able to build one module which may contain SDT probes that can be fired by DTrace, but the same module must be able to load into a kernel which has no DTrace support compiled in. This complexity comes to us thanks to Sun's CDDL. The code here is not based on Sun's code at all, so this is under the BSD license. The SDT probe registration process is driven via SYSINIT/SYSUNINIT hooks which call functions in this backend to add the SDT reference to the global list here. SDT probes are created using the SDT_PROBE() macro which takes the 'module', 'function' and 'name' arguments which are ultimately used by the DTrace 'sdt' provider for the probe name: sdt:module:function:name The SDT_PROBE() macro defines a static 'sdt_ref' structure named according to the probe. SDT_PROBE() also adds 'sdt_probe_start' and 'sdt_probe_end' labels to the generated code which are looked up when the probe is registered. The purpose of these labels is to define the location where the real probe code is when it is enabled. To disable the probe, the probe instructions are changed on the fly to cause a relative jump to the end label. The probe registration process involves locating the start and end labels, saving the required number of instructions after the start label and choosing the replacement instructions that cause the jump when disabled. On i386, two bytes are required. This assumes that the number of instructions between the start and end labels is less than 127 so that a signed 8-bit offset will be enough. The probe registration is complete when the label addresses are saved, the enable/disable instructions determined, the probe disabled and finally the 'sdt_ref' added to the global list. On i386, the runtime penalty for having SDT_PROBE()s sprinkled throughout the code is the number of clock cycles for the jmp (which is likely to be 3?) when the probe is disabled. When the probe is enabled, the penalty is whatever the probe does. It's important to remember that the probe shouldn't be dereferencing fields in structures -- DTrace is quite capable of doing that in it's D-language. I'll illustrate this by adding some probes to other parts of the kernel code later. Stay tuned. Affected files ... .. //depot/projects/dtrace/src/sys/kern/kern_sdt.c#1 add .. //depot/projects/dtrace/src/sys/sys/sdt.h#1 add Differences ...