All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Ingo Molnar <mingo@elte.hu>
Cc: Pekka Enberg <penberg@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Steven Rostedt <rostedt@goodmis.org>,
	Arjan van de Ven <arjan@linux.intel.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	linux-kernel@vger.kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Darren Hart <dvhart@linux.intel.com>,
	Arjan van de Ven <arjan@infradead.org>
Subject: Re: [patch] trace: Add user-space event tracing/injection
Date: Wed, 17 Nov 2010 13:29:54 +0100	[thread overview]
Message-ID: <1289996994.2109.731.camel@laptop> (raw)
In-Reply-To: <20101117120740.GA24972@elte.hu>

On Wed, 2010-11-17 at 13:07 +0100, Ingo Molnar wrote:

> Subject: trace: Add user-space event tracing/injection
> From: Ingo Molnar <mingo@elte.hu>
> Date: Wed Nov 17 10:11:53 CET 2010
> 
> This feature (suggested by Darren Hart and Pekka Engberg) allows user-space
> programs to print trace events in a very simple and self-contained way:
> 
>  #include <sys/prctl.h>
>  #include <string.h>
> 
>  #define PR_TASK_PERF_USER_TRACE 35
> 
>  int main(void)
>  {
>          char *msg = "Hello World!\n";
> 
>          prctl(PR_TASK_PERF_USER_TRACE, msg, strlen(msg));
> 
>          return 0;
>  }
> 
> These show up in 'trace' output as:
> 
>  $ trace report
>  #
>  # trace events of 'sleep 1':
>  #
>         testit/ 6006 ( 0.002 ms): <"Hello World!">
>         testit/ 6006 ( 0.002 ms): <"Hello World!">
> 
> Suggested-by: Darren Hart <dvhart@linux.intel.com>
> Suggested-by: Pekka Enberg <penberg@kernel.org>
> Signed-off-by: Ingo Molnar <mingo@elte.hu>

I really dislike abusing prctl(), I understand your reasons, but it
still sucks.

Also, the naming doesn't work, you've implemented a trace event, that's
got nothing to do with perf, so the PR_TASK_PERF_ prefix is incorrect.


> Index: linux/include/linux/prctl.h
> ===================================================================
> --- linux.orig/include/linux/prctl.h
> +++ linux/include/linux/prctl.h
> @@ -102,4 +102,6 @@
>  
>  #define PR_MCE_KILL_GET 34
>  
> +#define PR_TASK_PERF_USER_TRACE			35
> +
>  #endif /* _LINUX_PRCTL_H */
> Index: linux/include/trace/events/user.h
> ===================================================================
> --- /dev/null
> +++ linux/include/trace/events/user.h
> @@ -0,0 +1,32 @@
> +#undef TRACE_SYSTEM
> +#define TRACE_SYSTEM user
> +
> +#if !defined(_TRACE_USER_H) || defined(TRACE_HEADER_MULTI_READ)
> +#define _TRACE_USER_H_
> +
> +#include <linux/tracepoint.h>
> +#include <linux/ftrace.h>
> +
> +TRACE_EVENT(user,
> +
> +	TP_PROTO(const char *message),
> +
> +	TP_ARGS(message),
> +
> +	TP_STRUCT__entry(
> +		__string(	message, message);
> +	),
> +
> +	TP_fast_assign(
> +		__assign_str(message, message);
> +	),
> +
> +	TP_printk("user %s", __get_str(message))
> +);
> +
> +#undef NO_DEV
> +
> +#endif /* _TRACE_USER_H_ */
> +
> +/* This part must be outside protection */
> +#include <trace/define_trace.h>
> Index: linux/kernel/sys.c
> ===================================================================
> --- linux.orig/kernel/sys.c
> +++ linux/kernel/sys.c
> @@ -47,6 +47,11 @@
>  #include <asm/io.h>
>  #include <asm/unistd.h>
>  
> +#define MAX_USER_TRACE_SIZE 128
> +
> +#define CREATE_TRACE_POINTS
> +#include <trace/events/user.h>
> +
>  #ifndef SET_UNALIGN_CTL
>  # define SET_UNALIGN_CTL(a,b)	(-EINVAL)
>  #endif
> @@ -1681,6 +1686,24 @@ SYSCALL_DEFINE5(prctl, int, option, unsi
>  		case PR_TASK_PERF_EVENTS_ENABLE:
>  			error = perf_event_task_enable();
>  			break;
> +		/*
> +		 * Inject a trace event into the current tracing context:
> +		 */
> +		case PR_TASK_PERF_USER_TRACE:
> +		{
> +			void __user *uevent_ptr = (void *)arg2;
> +			char kstring[MAX_USER_TRACE_SIZE+1];
> +			unsigned long uevent_len = arg3;
> +
> +			if (uevent_len > MAX_USER_TRACE_SIZE)
> +				return -EINVAL;
> +			if (copy_from_user(kstring, uevent_ptr, uevent_len))
> +				return -EFAULT;
> +			kstring[uevent_len] = 0;
> +
> +			trace_user(kstring);
> +			return 0;
> +		}
>  		case PR_GET_TIMERSLACK:
>  			error = current->timer_slack_ns;
>  			break;


  parent reply	other threads:[~2010-11-17 12:30 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-16 21:04 [ANNOUNCE] New utility: 'trace' Thomas Gleixner
2010-11-16 21:27 ` Darren Hart
2010-11-16 21:59   ` Ingo Molnar
2010-11-16 22:03     ` Peter Zijlstra
2010-11-16 22:08       ` Ingo Molnar
2010-11-16 22:09       ` Darren Hart
2010-11-16 22:48         ` Darren Hart
2010-11-16 22:07     ` Darren Hart
2010-11-16 22:17   ` Frederic Weisbecker
2010-11-17  8:30     ` Ingo Molnar
2010-11-17 11:35       ` Peter Zijlstra
2010-11-17 12:53         ` Frederic Weisbecker
2010-11-17 13:02           ` Peter Zijlstra
2010-11-17 13:10             ` Ingo Molnar
2010-11-17 13:36               ` Peter Zijlstra
2010-11-17 13:43                 ` Frederic Weisbecker
2010-11-17 13:53                   ` Peter Zijlstra
2010-11-17 14:10                     ` Frederic Weisbecker
2010-11-17 15:02                       ` Steven Rostedt
2010-11-17 18:13                       ` Ted Ts'o
2010-11-17 18:29                         ` Frederic Weisbecker
2010-11-17 18:30                           ` Darren Hart
2010-11-17 16:49             ` Darren Hart
2010-11-18 23:23       ` Joe Perches
2010-11-16 21:35 ` Ingo Molnar
2010-11-17  1:37 ` Ted Ts'o
2010-11-17  1:47   ` Steven Rostedt
2010-11-17  3:16     ` Ted Ts'o
2010-11-17  3:34       ` Steven Rostedt
2010-11-17 19:00         ` Bob Copeland
2010-11-17 13:24   ` Ingo Molnar
2010-11-17 13:38     ` Peter Zijlstra
2010-11-17 14:00       ` Ingo Molnar
2010-11-17 14:11         ` Peter Zijlstra
2010-11-17 14:18           ` Peter Zijlstra
2010-11-17 14:37             ` Thomas Gleixner
2010-11-17 14:41               ` Peter Zijlstra
2010-11-17 15:41               ` Tom Zanussi
2010-11-17 15:55                 ` Avi Kivity
2010-11-17 15:58                   ` Thomas Gleixner
2010-11-17 16:20                     ` Avi Kivity
2010-11-17 15:59                   ` Peter Zijlstra
2010-11-17 16:08                     ` Avi Kivity
2010-11-17 15:10           ` Steven Rostedt
2010-11-17 15:43             ` Peter Zijlstra
2010-11-17 16:04               ` Steven Rostedt
2010-11-17 16:15               ` Steven Rostedt
2010-11-17 19:40                 ` Darren Hart
2010-11-17 18:23               ` Mathieu Desnoyers
2010-11-18  5:58                 ` Masami Hiramatsu
2010-11-18  6:00               ` Masami Hiramatsu
2010-11-17 15:33           ` Tom Zanussi
2010-11-17 18:36             ` Mathieu Desnoyers
2010-11-17 18:53               ` Tom Zanussi
2010-11-17 19:02                 ` Mathieu Desnoyers
2010-11-17 19:25                   ` Tom Zanussi
2010-11-17 19:25               ` Steven Rostedt
2010-11-17  9:49 ` Philipp Marek
     [not found] ` <4CE38C53.8090606@kernel.org>
2010-11-17 12:07   ` [patch] trace: Add user-space event tracing/injection Ingo Molnar
2010-11-17 12:17     ` Pekka Enberg
2010-11-17 12:30       ` Ingo Molnar
2010-11-17 12:33         ` Pekka Enberg
2010-11-17 12:42           ` Peter Zijlstra
2010-11-17 12:58             ` Ingo Molnar
2010-11-17 13:09               ` Peter Zijlstra
2010-11-17 13:36                 ` Ingo Molnar
2010-11-17 12:24     ` Ingo Molnar
2010-11-17 12:30       ` Pekka Enberg
2010-11-17 12:29     ` Peter Zijlstra [this message]
2010-11-17 12:37       ` Peter Zijlstra
2010-11-17 13:10       ` Frederic Weisbecker
2010-11-17 13:31         ` Peter Zijlstra
2010-11-17 13:33           ` Frederic Weisbecker
2010-11-18  1:18     ` Darren Hart
2010-11-18  8:55       ` Ingo Molnar
2010-11-18 16:25         ` hp
2010-11-18 18:56           ` Ingo Molnar
2010-11-18 19:13             ` AW: " Reichert, Hans-Peter
2010-11-18 17:06         ` Darren Hart
2010-11-17 12:47 ` [ANNOUNCE] New utility: 'trace' Török Edwin
2010-11-17 12:51   ` Peter Zijlstra
2010-11-17 13:05     ` Török Edwin
2010-11-17 13:10       ` Peter Zijlstra
2010-11-17 13:32   ` Frederic Weisbecker
2010-11-18  0:47 ` Ian Munsie
     [not found]   ` <20101118151141.GA3368@redhat.com>
2010-11-19  2:32     ` Ian Munsie
2010-11-19 15:23       ` Jason Baron
     [not found]       ` <4CECACF9.3080907@linux.vnet.ibm.com>
     [not found]         ` <4CFD7182.4060206@linux.vnet.ibm.com>
2010-12-07  4:03           ` PowerPC, ftrace: Add PPC raw syscall tracepoints & ftrace fixes Ian Munsie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1289996994.2109.731.camel@laptop \
    --to=peterz@infradead.org \
    --cc=acme@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=arjan@infradead.org \
    --cc=arjan@linux.intel.com \
    --cc=dvhart@linux.intel.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=penberg@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.