mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
To: =?iso-8859-1?Q?Fr=E9d=E9ric_Weisbecker_=3Cfweisbec=40gmail=2Ecom=3E?=@thinktux.in.ibm.com
Cc: "Kok, Auke" <auke-jan.h.kok@intel.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	powertop ml <power@bughost.org>,
	Arjan van de Ven <arjan@linux.intel.com>,
	Ingo Molnar <mingo@elte.hu>,
	srostedt@redhat.com,
	Arnaldo Carvalho de Melo <acme@ghostprotocols.net>,
	"Frank Ch. Eigler" <fche@redhat.com>,
	Neil Horman <nhorman@tuxdriver.com>,
	Roland McGrath <roland@redhat.com>
Subject: Re: [PATCH] tracer for sys_open() - sreadahead
Date: Wed, 28 Jan 2009 22:30:09 +0530	[thread overview]
Message-ID: <20090128170009.GB5365@in.ibm.com> (raw)
In-Reply-To: <c62985530901280621k54a47515g952cd29444a6054e@mail.gmail.com>

On Wed, Jan 28, 2009 at 03:21:24PM +0100, Frédéric Weisbecker wrote:
> 2009/1/28 Ananth N Mavinakayanahalli <ananth@in.ibm.com>:
> > On Tue, Jan 27, 2009 at 11:43:05PM +0100, Frederic Weisbecker wrote:
> >> On Tue, Jan 27, 2009 at 12:08:04PM -0800, Kok, Auke wrote:

...

> > Here is something I did sometime ago that uses utrace. It is per task
> > doesn't use ftrace and is just intended as a prototype. It traces both
> > syscalls and returns.
> >
> > ---
> >
> > Here is the beginnings of a simple utrace based strace. Right now, one
> > needs to invoke this program with a 'insmod <modname> tid=<tid>'.
> >
> > The output looks something like this:
> > [267352.641112] Attached to 32604 => 0xd8f60090
> > [267353.981046] 2
> > [267353.981085] 197 0x1 0xbff8cd84 0x86cff4 0x86d4c0 0x86d4c0 0xbff8cd50a = 0
> > [267353.981097] 192 0x0 0x1000 0x3 0x22 0xffffffff 0x0 = b7f8d000
> > [267353.981124] 4 0x1 0xb7f8d000 0xd 0xd 0xb7f8d000 0xbff8cda8 = d
> > [267353.981174] 4 0x1 0xb7f8d000 0x3 0x3 0xb7f8d000 0xbff8c7dc = 3
> > [267353.981209] 252 0x0 0x0 0x86e0d0 0x0 0x86b274 0xbff8cee8 =
> > [267353.981215] Task 32604 exited
> > [267355.460180] Cannot find PID 32604
> >
> > I know strace does a pretty print, but this is a quick and dirty
> > prototype.
> > ---
> >
> > #include <linux/module.h>
> > #include <linux/utrace.h>
> > #include <linux/err.h>
> > #include <asm/syscall.h>
> >
> > MODULE_DESCRIPTION("syscall trace");
> > MODULE_LICENSE("GPL");
> >
> > static int target_tid;
> >
> > module_param_named(tid, target_tid, int, 0);
> >
> > static u32 task_syscall_entry(u32 action, struct utrace_attached_engine *engine,
> >                struct task_struct *task, struct pt_regs *regs)
> > {
> >        long callno;
> >        unsigned long args[6];
> >
> >        callno = syscall_get_nr(task, regs);
> >        syscall_get_arguments(task, regs, 0, 6, args);
> >
> >        printk(KERN_INFO "%ld 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx = ",
> >                callno, args[0], args[1], args[2], args[3], args[4], args[5]);
> >        return UTRACE_RESUME;
> > }
> >
> > static u32 task_syscall_exit(u32 action, struct utrace_attached_engine *engine,
> >                struct task_struct *task, struct pt_regs *regs)
> > {
> >        long retval = syscall_get_return_value(task, regs);
> >        printk("%lx\n", retval);
> >        return UTRACE_RESUME;
> > }
> >
> > static u32 task_exit(enum utrace_resume_action action,
> >                struct utrace_attached_engine *engine, struct task_struct *task,
> >                long orig_code, long *code)
> > {
> >        printk("\n");
> >        printk(KERN_INFO "Task %d exited\n", target_tid);
> >        return UTRACE_DETACH;
> > }
> >
> > static const struct utrace_engine_ops syscall_ops =
> > {
> >        .report_syscall_entry = task_syscall_entry,
> >        .report_syscall_exit = task_syscall_exit,
> >        .report_exit = task_exit,
> > };
> >
> > static int __init strace_init(void)
> > {
> >        struct pid *pid;
> >        int ret = 0;
> >        struct task_struct *target;
> >        struct utrace_attached_engine *engine;
> >
> >        pid = find_get_pid(target_tid);
> >        if (pid == NULL) {
> >                printk(KERN_ERR "Cannot find PID %d\n", target_tid);
> >                ret = -ESRCH;
> >                goto out;
> >        }
> >
> >        engine = utrace_attach_pid(pid, UTRACE_ATTACH_CREATE, &syscall_ops, 0);
> >        if (IS_ERR(engine)) {
> >                printk(KERN_ERR "utrace_attach_pid: %ld\n", PTR_ERR(engine));
> >                ret = -EINVAL;
> >                goto out;
> >        } else if (engine == NULL) {
> >                printk(KERN_ERR "utrace_attach_pid => NULL\n");
> >                ret = -EINVAL;
> >                goto out;
> >        } else
> >                printk(KERN_INFO "Attached to %d => 0x%p\n",
> >                                target_tid, engine);
> >
> >        /*
> >         * If utrace_attach_pid() succeeded above, we are sure the target
> >         * is valid here
> >         */
> >        target = pid_task(pid, PIDTYPE_PID);
> >        put_pid(pid);
> >
> >        ret = utrace_set_events(target, engine, UTRACE_EVENT_SYSCALL |
> >                        UTRACE_EVENT(EXIT));
> >        if (ret)
> >                printk(KERN_ERR "utrace_set_events returned %d\n", ret);
> >
> > out:
> >        return ret;
> > }
> >
> > static void __exit strace_exit(void)
> > {
> >        int ret = 0;
> >        struct pid *pid;
> >        struct utrace_attached_engine *engine;
> >        struct task_struct *target;
> >
> >        pid = find_get_pid(target_tid);
> >        if (pid == NULL) {
> >                printk(KERN_ERR "Cannot find PID %d\n", target_tid);
> >                return;
> >        }
> >
> >        target = pid_task(pid, PIDTYPE_PID);
> >        put_pid(pid);
> >        engine = utrace_attach_task(target, UTRACE_ATTACH_MATCH_OPS,
> >                        &syscall_ops, 0);
> >        if (IS_ERR(engine))
> >                printk(KERN_ERR "Can't find self: %ld\n", PTR_ERR(engine));
> >        else if (engine == NULL)
> >                printk(KERN_ERR "Can't find self: no match\n");
> >        else {
> >                printk(KERN_INFO "Trying detach 0x%p from %d\n",
> >                                engine, target_tid);
> >                ret = utrace_control(target, engine, UTRACE_DETACH);
> >                if (ret)
> >                        printk(KERN_ERR "utrace_control returned %d\n",
> >                                        ret);
> >        }
> > }
> >
> > module_init(strace_init);
> > module_exit(strace_exit);
> >
> 
> 
> This is a very convenient Api. I would be glad to use it with ftrace.
> But, what is it's status currently? Some projects to merge it?

Its currently available as a git tree:
git://git.kernel.org/pub/scm/linux/kernel/git/frob/linux-2.6-utrace.git

There is work going on to merge it upstream. Roland McGrath will be able
to better answer when. However, one of the biggest requirements to merge
it is an in-kernel user. Hopefully Frank's prototype and/or an ftrace
integration of the above snippet should be incentive to push for some
in-tree users :-)

Ananth

  reply	other threads:[~2009-01-28 17:00 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-27 20:08 Kok, Auke
2009-01-27 20:51 ` Arnaldo Carvalho de Melo
2009-01-27 21:14   ` Frederic Weisbecker
2009-01-28 22:05     ` Kok, Auke
2009-01-29  0:45       ` Arnaldo Carvalho de Melo
2009-01-29 13:39         ` Frédéric Weisbecker
2009-01-29 13:40           ` Frédéric Weisbecker
2009-01-27 22:43 ` Frederic Weisbecker
2009-01-27 22:50   ` Frederic Weisbecker
2009-01-29 14:04     ` Ingo Molnar
2009-01-29 14:29       ` Frédéric Weisbecker
2009-01-29 14:31         ` Ingo Molnar
2009-01-29 14:40           ` Frédéric Weisbecker
2009-01-29 14:48             ` Frédéric Weisbecker
2009-01-29 15:09             ` Ingo Molnar
2009-01-29 15:17               ` Frédéric Weisbecker
2009-01-29 15:34               ` Frédéric Weisbecker
2009-01-29 15:53                 ` Frank Ch. Eigler
2009-01-28  0:43   ` Frank Ch. Eigler
2009-01-28 13:58     ` Frédéric Weisbecker
2009-01-28 14:29       ` Arnaldo Carvalho de Melo
2009-01-28  9:38   ` Ananth N Mavinakayanahalli
2009-01-28 14:21     ` Frédéric Weisbecker
2009-01-28 17:00       ` Ananth N Mavinakayanahalli [this message]
2009-01-28 17:15         ` Frédéric Weisbecker
2009-01-28 22:19   ` Kok, Auke
2009-01-30 20:22 ` Pavel Machek
2009-02-03 13:32   ` Ingo Molnar
2009-02-05 14:44     ` Harald Hoyer
2009-02-05 15:07       ` Bill Nottingham
2009-02-05 15:14         ` Arjan van de Ven
2009-02-05 15:24           ` Bill Nottingham
2009-02-05 15:47             ` Arjan van de Ven
2009-02-06 23:18               ` Corrado Zoccolo
2009-02-09 13:13       ` Karel Zak
2009-02-09 13:23         ` Harald Hoyer
2009-02-09 13:54           ` Karel Zak
2009-02-11 10:44             ` Harald Hoyer

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=20090128170009.GB5365@in.ibm.com \
    --to=ananth@in.ibm.com \
    --cc==?iso-8859-1?Q?Fr=E9d=E9ric_Weisbecker_=3Cfweisbec=40gmail=2Ecom=3E?=@thinktux.in.ibm.com \
    --cc=acme@ghostprotocols.net \
    --cc=arjan@linux.intel.com \
    --cc=auke-jan.h.kok@intel.com \
    --cc=fche@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=nhorman@tuxdriver.com \
    --cc=power@bughost.org \
    --cc=roland@redhat.com \
    --cc=srostedt@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®