This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: kernel read fault when accessing context variables
On Thu, 2010-07-08 at 22:42 +0200, Mark Wielaard wrote:
> On Thu, 2010-07-08 at 09:15 -0700, tonyg362 wrote:
> > Could you tell me if it works for you if you look at a line in sched.c where
> > prev is set (or near it), and not just at the beginning of the function? In
> > the meantime I will try using a gcc version as suggested by Frank. As for my
> > compiler I used 4.4.1 which I guess is the latest version available through
> > apt-get on Ubuntu 9.10. I would like to know if anybody can get this working
> > on Ubuntu 9.10 so I can know their setup.
>
> I looked a bit at the sources, and when I set the probe at line 42 of
> the function (if (likely(prev != next))) it seems to work fine:
>
> $ stap -e 'probe kernel.statement("schedule@kernel/sched.c+42")
> { ppid = $prev->tgid; npid = $next->tgid;
> printf("ppid:%d, npid:%d\n", ppid, npid) }'
> ppid:24737, npid:0
> ppid:0, npid:21431
> ppid:21431, npid:23130
> ppid:23130, npid:22989
> ppid:22989, npid:21431
> [...]
>
> If I set the probe earlier next isn't assigned yet in the function and I
> see what you are seeing:
>
> $ stap -e 'probe kernel.statement("schedule@kernel/sched.c+16")
> { ppid = $prev->tgid; npid = $next->tgid;
> printf("ppid:%d, npid:%d\n", ppid, npid) }'
> ERROR: kernel read fault at 0x0000129c29e10ec5 (addr) near identifier
> '$next' at <input>:1:83
>
> So it might actually be that in your case the probe is at a point where
> next isn't initialized yet?
Looking a bit more I see right after that line (+42) there is a call
into context_switch, which has a trace point "sched_switch" in it:
$ stap -L 'kernel.trace("sched_switch")'
kernel.trace("sched_switch") $rq:struct rq* $prev:struct task_struct*
$next:struct task_struct*
So, if you are interested in scheduler switches, then maybe this is more
robust:
$ stap -e 'probe kernel.trace("sched_switch")
{ ppid = $prev->tgid; npid = $next->tgid;
printf("ppid:%d, npid:%d\n", ppid, npid) }'
Cheers,
Mark