PERFORCE change 97438 for review

John Birrell jb at FreeBSD.org
Fri May 19 01:27:50 UTC 2006


http://perforce.freebsd.org/chv.cgi?CH=97438

Change 97438 by jb at 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 ...


More information about the p4-projects mailing list