From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30527 invoked by alias); 16 Feb 2007 01:51:27 -0000 Received: (qmail 30518 invoked by uid 22791); 16 Feb 2007 01:51:26 -0000 X-Spam-Status: No, hits=-0.1 required=5.0 tests=BAYES_00,UNPARSEABLE_RELAY X-Spam-Check-By: sourceware.org Received: from agminet01.oracle.com (HELO agminet01.oracle.com) (141.146.126.228) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 16 Feb 2007 01:51:19 +0000 Received: from rgmgw2.us.oracle.com (rgmgw2.us.oracle.com [138.1.186.111]) by agminet01.oracle.com (Switch-3.2.4/Switch-3.1.7) with ESMTP id l1G1noPd031756; Thu, 15 Feb 2007 19:49:50 -0600 Received: from rcsmt250.oracle.com (rcsmt250.oracle.com [148.87.90.195]) by rgmgw2.us.oracle.com (Switch-3.2.4/Switch-3.1.7) with ESMTP id l1G1nnw6002943; Thu, 15 Feb 2007 18:49:49 -0700 Received: from ca-server1.us.oracle.com by rcsmt250.oracle.com with ESMTP id 2453725311171590490; Thu, 15 Feb 2007 18:48:10 -0700 Date: Fri, 16 Feb 2007 01:51:00 -0000 From: Randy Dunlap To: Mathieu Desnoyers Cc: Andrew Morton , linux-kernel@vger.kernel.org, Christoph Hellwig , Ingo Molnar , systemtap@sources.redhat.com, ltt-dev@shafik.org Subject: Re: [PATCH] Linux Kernel Markers Documentation Message-Id: <20070215174500.2b1b3bb9.randy.dunlap@oracle.com> In-Reply-To: <20070216013348.GC12736@Krystal> References: <1171224207118-git-send-email-mathieu.desnoyers@polymtl.ca> <20070214231201.20918c6b.akpm@linux-foundation.org> <20070216013348.GC12736@Krystal> Organization: Oracle Linux Eng. X-Mailer: Sylpheed 2.3.1 (GTK+ 2.8.10; x86_64-unknown-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: AAAAAQAAAAI= X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-Whitelist: TRUE Mailing-List: contact systemtap-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: systemtap-owner@sourceware.org X-SW-Source: 2007-q1/txt/msg00353.txt.bz2 On Thu, 15 Feb 2007 20:33:48 -0500 Mathieu Desnoyers wrote: > Linux Kernel Markers - Documentation > > Here is some documentation explaining what is/how to use the Linux > Kernel Markers. > > Signed-off-by: Mathieu Desnoyers > > --- /dev/null > +++ b/Documentation/marker.txt > @@ -0,0 +1,130 @@ > + Using the Linux Kernel Markers > + > + Mathieu Desnoyers > + > + > + This document discusses the purpose of markers. It shows some usage > +examples of the Linux Kernel Markers : how to insert markers within the kernel > +and how to connect probes to a marker. Finally, it has some probe module > +examples. This is what connects to a marker. > + > + > +* Purpose of markers > + > +You can put markers at important locations in the code. They act as > +lightweight hooks that can pass an arbitrary number of parameters, > +described in a printk-like format string, to a function whenever the marker > +code is reached. > + > +They can be used for tracing (LTTng, LKET over SystemTAP), overall performance > +accounting (SystemTAP). They could also be used to implement > +efficient hooks for SELinux or any other subsystem the would have this that > +kind of need. > + > +Using the markers for system audit (SELinux) would require to pass a > +variable by address that would be later checked by the marked routine. > + > + > +* Usage > + > +MARK(subsystem_event, "%d %s %p[struct task_struct]", > + someint, somestring, current); > +Where : > +- Subsystem is the name of your subsystem. > +- event is the name of the event to mark. so is the MARK() supposed to be: MARK(subsystem, event, ... Please make the 2 doc. lines above match the parameters... or the parameters match the text. > +- "%d %s %p[struct task_struct]" is the formatted string for (printk-style). > +- someint is an integer. > +- somestring is a char pointer. > +- current is a pointer to a struct task_struct. > + > +The expression %p[struct task_struct] is a suggested marker definition > +standard that could eventually be used for pointer type checking in > +sparse. The brackets contain the type to which the pointer refer. refers. > + > +The marker mechanism supports multiple instances of the same marker. > +Markers can be put in inline functions, inlined static functions and > +unrolled loops. > + > +Note : It is safe to put markers within preempt-safe code : preempt_enable() > +will not call the scheduler due to the tests in preempt_schedule(). > + > + > +* Optimization for a given architecture > + > +You will find, in asm-*/marker.h, optimisations for given architectures > +(currently i386 and powerpc). They use a load immediate instead of a data read, > +which saves a data cache hit, but also requires cross CPU code modification. In > +order to support embedded systems which use read-only memory for their code, the > +optimization can be disabled through menu options. > + > + > +* Probe example > + > +------------------------------ CUT ------------------------------------- > +/* probe-example.c > + * > + * Loads a function at a marker call site. > + * > + * (C) Copyright 2007 Mathieu Desnoyers > + * > + * This file is released under the GPLv2. > + * See the file COPYING for more details. > + */ > + > +#include > +#include > + > +#define SUBSYSTEM_EVENT_FORMAT "%d %s %p[struct task_struct]" Is SUBSYSTEM_EVENT_FORMAT used implicitly below? or elsewhere? > +void probe_subsystem_event(const char *format, ...) > +{ > + va_list ap; > + /* Declare args */ > + unsigned int value; > + const char *mystr; > + struct task_struct *task; > + > + /* Assign args */ > + va_start(ap, format); > + value = va_arg(ap, typeof(value)); > + mystr = va_arg(ap, typeof(mystr)); > + task = va_arg(ap, typeof(task)); > + > + /* Call tracer */ > + trace_subsystem_event(value, mystr, task); > + > + /* Or call printk */ > + vprintk(format, ap); > + > + /* or count, check rights... */ > + > + va_end(ap); > +} > + > +static int __init probe_init(void) > +{ > + int result; > + result = marker_set_probe("subsystem_event", > + FS_CLOSE_FORMAT, > + probe_fs_close); Do FS_CLOSE_FORMAT and probe_fs_close() need to be defined here? I.e., is this a complete example? > + if (!result) > + goto cleanup; > + return 0; > + > +cleanup: > + marker_remove_probe(probe_subsystem_event); > + return -EPERM; > +} > + > +static void __exit probe_fini(void) > +{ > + marker_remove_probe(probe_subsystem_event); > +} > + > +module_init(probe_init); > +module_exit(probe_fini); > + > +MODULE_LICENSE("GPL"); > +MODULE_AUTHOR("Mathieu Desnoyers"); > +MODULE_DESCRIPTION("SUBSYSTEM Probe"); > +------------------------------ CUT ------------------------------------- --- ~Randy *** Remember to use Documentation/SubmitChecklist when testing your code ***