* Error when using @container_of
@ 2019-04-22 10:01 Giovanni Gherdovich
2019-04-25 8:13 ` Giovanni Gherdovich
0 siblings, 1 reply; 2+ messages in thread
From: Giovanni Gherdovich @ 2019-04-22 10:01 UTC (permalink / raw)
To: systemtap
Hello,
when I use the macro @container_of in systemtap I'm getting an error I don't
understand.
This is my tapset:
#!/root/systemtap-latest/bin/stap
probe kernel.function("__update_load_avg_se") {
printf("%x\n", @container_of($se, "struct task_struct", se));
exit();
}
and this is the error:
# ./repro.stp
semantic error: 'struct task_struct' (./include/linux/sched.h:602) is being
accessed instead of a member such as '->acct_rss_mem1': operator '@cast' at
/root/systemtap-latest/share/systemtap/tapset/container_of.stpm:2:5
source: @cast(@ptr - @offsetof(@type, @member), @type)
^
in expansion of macro: operator '@container_of' at ./repro.stp:4:17
source: printf("%x\n", @container_of($se, "struct task_struct", se));
^
Pass 2: analysis failed. [man error::pass2]
What I'm trying to do here is to get an object of type sched_entity (the
target variable $se which is a parameter of the function
__update_load_avg_se()) and from there grab the task_struct that contains said
sched_entity. If the sched_entity in question is actually a task (and not a
group), this operation should make sense; for example the inlined function
task_of() from kernel/sched/fair.c does exactly that.
I'm using a v5.0 kernel and the latest systemtap from the git repo:
# /root/systemtap-latest/bin/stap --version
Systemtap translator/driver (version 4.1/0.168, commit release-4.0-187-g288c53892665 + changes)
Copyright (C) 2005-2019 Red Hat, Inc. and others
This is free software; see the source for copying conditions.
tested kernel versions: 2.6.18 ... 5.1-rc2
enabled features: BPF PYTHON2 LIBXML2 NLS READLINE
Regards,
Giovanni Gherdovich
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Error when using @container_of
2019-04-22 10:01 Error when using @container_of Giovanni Gherdovich
@ 2019-04-25 8:13 ` Giovanni Gherdovich
0 siblings, 0 replies; 2+ messages in thread
From: Giovanni Gherdovich @ 2019-04-25 8:13 UTC (permalink / raw)
To: systemtap
On Mon, 2019-04-22 at 12:06 +0200, Giovanni Gherdovich wrote:
> Hello,
>
> when I use the macro @container_of in systemtap I'm getting an error I don't
> understand.
>
> This is my tapset:
>
> #!/root/systemtap-latest/bin/stap
>
> probe kernel.function("__update_load_avg_se") {
> printf("%x\n", @container_of($se, "struct task_struct", se));
> exit();
> }
>
> and this is the error:
>
> # ./repro.stp
> semantic error: 'struct task_struct' (./include/linux/sched.h:602) is being
> accessed instead of a member such as '->acct_rss_mem1': operator '@cast' at
> /root/systemtap-latest/share/systemtap/tapset/container_of.stpm:2:5
>
> source: @cast(@ptr - @offsetof(@type, @member), @type)
> ^
> in expansion of macro: operator '@container_of' at ./repro.stp:4:17
> source: printf("%x\n", @container_of($se, "struct task_struct", se));
> ^
>
> Pass 2: analysis failed. [man error::pass2]
Hi again,
I'm posting here for future reference: I've been explained that my mistake was
to not use the address-of operator '&' after @container_of. Since my original
goal was to get the PID of a sched entity, the snipped above can be fixed
with:
probe kernel.function("__update_load_avg_se") {
p = &@container_of($se, "struct task_struct", se);
printf("pid: %d\n", p->pid);
exit();
}
or even by chaining a field access with -> without using '&' like:
probe kernel.function("__update_load_avg_se") {
printf("pid: %d\n", @container_of($se, "struct task_struct", se)->pid);
exit();
}
In hindsight I should say that the error message makes perfect sense: "you're
accessing the struct itself, you should access a field instead!". What I missed
is that I had to take the address of the struct.
Regards,
Giovanni Gherdovich
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-04-25 8:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-22 10:01 Error when using @container_of Giovanni Gherdovich
2019-04-25 8:13 ` Giovanni Gherdovich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).