All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Naohiro Aota <naota@elisp.net>,
	Peter Zijlstra <peterz@infradead.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	David Ahern <dsahern@gmail.com>,
	namhyung@kernel.org, Jiri Olsa <jolsa@redhat.com>,
	Ingo Molnar <mingo@kernel.org>
Subject: Re: [PATCH perf/core v2 1/5] perf-probe: Fix to handle aliased symbols in glibc
Date: Fri, 6 Mar 2015 15:02:26 -0300	[thread overview]
Message-ID: <20150306180226.GB5187@kernel.org> (raw)
In-Reply-To: <20150306175919.GA5187@kernel.org>

Em Fri, Mar 06, 2015 at 02:59:19PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Mar 06, 2015 at 04:31:20PM +0900, Masami Hiramatsu escreveu:
> > Fix perf probe to handle aliased symbols correctly in glibc.
> > In the glibc, several symbols are defined as an alias of
> > __libc_XXX, e.g. malloc is an alias of __libc_malloc.
> > In such cases, dwarf has no subroutine instances of the
> > alias functions (e.g. no "malloc" instance), but the map
> > has that symbol and its address.
> > Thus, if we search the alieased symbol in debuginfo, we
> > always fail to find it, but it is in the map.
> > 
> > To solve this problem, this fails back to address-based
> > alternative search, which searches the symbol in the map,
> > translates its address to alternative (correct) function
> > name by using debuginfo, and retry to find the alternative
> > function point from debuginfo.
> > 
> > This adds fail-back process to --vars, --lines and --add
> > options. So, now you can use those on malloc@libc :)
> 
> --vars and --add works, but not --lines:

Ok, it works after applying 2/5, so it was just me confused by the above
statement, that a fallback was added that would make --lines work, it
works, but not with this patch, the next one is needed.

Anyway, works now, I'm happy, thanks!

- Arnaldo
 
> [root@ssdandy ~]# perf probe -x /usr/lib64/libc-2.17.so -V malloc
> Available variables at malloc
>         @<__libc_malloc+96>
>                 size_t  bytes
> 
> [root@ssdandy ~]# perf probe -x /usr/lib64/libc-2.17.so -L malloc
> Specified source line is not found.
>   Error: Failed to show lines.
> [root@ssdandy ~]# 
> 
> [root@ssdandy ~]# perf probe -x /usr/lib64/libc-2.17.so -a "malloc
> bytes"
> Added new event:
>   probe_libc:malloc    (on malloc in /usr/lib64/libc-2.17.so with bytes)
> 
> You can now use it in all perf tools, such as:
> 
> 	perf record -e probe_libc:malloc -aR sleep 1
> 
> [root@ssdandy ~]#
> 
> [root@ssdandy ~]# cat /t/events/probe_libc/malloc/format 
> name: malloc
> ID: 1921
> format:
> 	field:unsigned short common_type;	offset:0;	size:2;	signed:0;
> 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;
> 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;
> 	field:int common_pid;	offset:4;	size:4;	signed:1;
> 
> 	field:unsigned long __probe_ip;	offset:8;	size:8;	signed:0;
> 	field:u64 bytes;	offset:16;	size:8;	signed:0;
> 
> print fmt: "(%lx) bytes=0x%Lx", REC->__probe_ip, REC->bytes
> [root@ssdandy ~]# 
> 
> Works for the aliased symbol, anyway, applying as it makes progress.
> 
> [root@ssdandy ~]# perf probe -x /usr/lib64/libc-2.17.so -L __libc_malloc
> <__libc_malloc@/usr/src/debug/glibc-2.17-c758a686/malloc/malloc.c:0>
>       0  __libc_malloc(size_t bytes)
>       1  {
>            mstate ar_ptr;
>            void *victim;
>          
>            __malloc_ptr_t (*hook) (size_t, const __malloc_ptr_t)
>       6      = force_reg (__malloc_hook);
>       7    if (__builtin_expect (hook != NULL, 0))
>       8      return (*hook)(bytes, RETURN_ADDRESS (0));
>          
>      10    arena_lookup(ar_ptr);
>          
>      12    arena_lock(ar_ptr, bytes);
>      13    if(!ar_ptr)
>      14      return 0;
>      15    victim = _int_malloc(ar_ptr, bytes);
>      16    if(!victim) {
>      17      LIBC_PROBE (memory_malloc_retry, 1, bytes);
>      18      ar_ptr = arena_get_retry(ar_ptr, bytes);
>      19      if (__builtin_expect(ar_ptr != NULL, 1)) {
>      20        victim = _int_malloc(ar_ptr, bytes);
>      21        (void)mutex_unlock(&ar_ptr->mutex);
>              }
>            } else
>      24      (void)mutex_unlock(&ar_ptr->mutex);
>            assert(!victim || chunk_is_mmapped(mem2chunk(victim)) ||
>                  ar_ptr == arena_for_chunk(mem2chunk(victim)));
>            return victim;
>      28  }
>          libc_hidden_def(__libc_malloc)
>          
>          void
> 
> [root@ssdandy ~]#

  reply	other threads:[~2015-03-06 18:02 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-06  7:31 [PATCH perf/core v2 0/5] perf-probe: improve glibc support Masami Hiramatsu
2015-03-06  7:31 ` [PATCH perf/core v2 1/5] perf-probe: Fix to handle aliased symbols in glibc Masami Hiramatsu
2015-03-06 17:59   ` Arnaldo Carvalho de Melo
2015-03-06 18:02     ` Arnaldo Carvalho de Melo [this message]
2015-03-14  7:02   ` [tip:perf/core] perf probe: " tip-bot for Masami Hiramatsu
2015-03-06  7:31 ` [PATCH perf/core v2 2/5] perf-probe: Fix --line " Masami Hiramatsu
2015-03-14  7:02   ` [tip:perf/core] perf probe: " tip-bot for Masami Hiramatsu
2015-03-06  7:31 ` [PATCH perf/core v2 3/5] Revert "perf probe: Fix to fall back to find probe point in symbols" Masami Hiramatsu
2015-03-14  7:03   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2015-03-06  7:31 ` [PATCH perf/core v2 4/5] perf symbols: Allow symbol alias when loading map for symbol name Masami Hiramatsu
2015-03-06 18:06   ` Arnaldo Carvalho de Melo
2015-03-06 18:26     ` Arnaldo Carvalho de Melo
2015-03-06 18:32       ` Arnaldo Carvalho de Melo
2015-03-14  7:03   ` [tip:perf/core] " tip-bot for Namhyung Kim
2015-03-06  7:31 ` [PATCH perf/core v2 5/5] perf probe: Allow weak symbols to be probed Masami Hiramatsu
2015-03-14  7:03   ` [tip:perf/core] " tip-bot for Namhyung Kim
2015-03-06 18:45 ` [PATCH perf/core v2 0/5] perf-probe: improve glibc support Arnaldo Carvalho de Melo

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=20150306180226.GB5187@kernel.org \
    --to=acme@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=naota@elisp.net \
    --cc=peterz@infradead.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.