Skip to content

Commit c9b951c

Browse files
Jiri Olsaacmel
authored andcommitted
perf callchain: Separate perf_reg_value function in perf_regs object
Making perf_reg_value function global (formely reg_value), because it's going to be used globaly across all code providing the dwarf post unwind feature. Changing its prototype to be generic: -int reg_value(unw_word_t *valp, struct regs_dump *regs, int id) +int perf_reg_value(u64 *valp, struct regs_dump *regs, int id); Changing the valp type from libunwind specific 'unw_word_t' to u64. Signed-off-by: Jiri Olsa <jolsa@redhat.com> Acked-by: Jean Pihet <jean.pihet@linaro.org> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jean Pihet <jean.pihet@linaro.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1389098853-14466-13-git-send-email-jolsa@redhat.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 9ff125d commit c9b951c

4 files changed

Lines changed: 45 additions & 26 deletions

File tree

‎tools/perf/Makefile.perf‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ ifeq ($(NO_PERF_REGS),0)
538538
ifeq ($(ARCH),x86)
539539
LIB_H += arch/x86/include/perf_regs.h
540540
endif
541+
LIB_OBJS += $(OUTPUT)util/perf_regs.o
541542
endif
542543

543544
ifndef NO_LIBNUMA

‎tools/perf/util/perf_regs.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <errno.h>
2+
#include "perf_regs.h"
3+
4+
int perf_reg_value(u64 *valp, struct regs_dump *regs, int id)
5+
{
6+
int i, idx = 0;
7+
u64 mask = regs->mask;
8+
9+
if (!(mask & (1 << id)))
10+
return -EINVAL;
11+
12+
for (i = 0; i < id; i++) {
13+
if (mask & (1 << i))
14+
idx++;
15+
}
16+
17+
*valp = regs->regs[idx];
18+
return 0;
19+
}

‎tools/perf/util/perf_regs.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
#ifndef __PERF_REGS_H
22
#define __PERF_REGS_H
33

4+
#include "types.h"
5+
#include "event.h"
6+
47
#ifdef HAVE_PERF_REGS_SUPPORT
58
#include <perf_regs.h>
9+
10+
int perf_reg_value(u64 *valp, struct regs_dump *regs, int id);
11+
612
#else
713
#define PERF_REGS_MASK 0
814

915
static inline const char *perf_reg_name(int id __maybe_unused)
1016
{
1117
return NULL;
1218
}
19+
20+
static inline int perf_reg_value(u64 *valp __maybe_unused,
21+
struct regs_dump *regs __maybe_unused,
22+
int id __maybe_unused)
23+
{
24+
return 0;
25+
}
1326
#endif /* HAVE_PERF_REGS_SUPPORT */
1427
#endif /* __PERF_REGS_H */

‎tools/perf/util/unwind-libunwind.c‎

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -390,30 +390,13 @@ static int access_dso_mem(struct unwind_info *ui, unw_word_t addr,
390390
return !(size == sizeof(*data));
391391
}
392392

393-
static int reg_value(unw_word_t *valp, struct regs_dump *regs, int id)
394-
{
395-
int i, idx = 0;
396-
u64 mask = regs->mask;
397-
398-
if (!(mask & (1 << id)))
399-
return -EINVAL;
400-
401-
for (i = 0; i < id; i++) {
402-
if (mask & (1 << i))
403-
idx++;
404-
}
405-
406-
*valp = regs->regs[idx];
407-
return 0;
408-
}
409-
410393
static int access_mem(unw_addr_space_t __maybe_unused as,
411394
unw_word_t addr, unw_word_t *valp,
412395
int __write, void *arg)
413396
{
414397
struct unwind_info *ui = arg;
415398
struct stack_dump *stack = &ui->sample->user_stack;
416-
unw_word_t start, end;
399+
u64 start, end;
417400
int offset;
418401
int ret;
419402

@@ -423,7 +406,7 @@ static int access_mem(unw_addr_space_t __maybe_unused as,
423406
return 0;
424407
}
425408

426-
ret = reg_value(&start, &ui->sample->user_regs, PERF_REG_SP);
409+
ret = perf_reg_value(&start, &ui->sample->user_regs, PERF_REG_SP);
427410
if (ret)
428411
return ret;
429412

@@ -436,8 +419,9 @@ static int access_mem(unw_addr_space_t __maybe_unused as,
436419
if (addr < start || addr + sizeof(unw_word_t) >= end) {
437420
ret = access_dso_mem(ui, addr, valp);
438421
if (ret) {
439-
pr_debug("unwind: access_mem %p not inside range %p-%p\n",
440-
(void *)addr, (void *)start, (void *)end);
422+
pr_debug("unwind: access_mem %p not inside range"
423+
" 0x%" PRIx64 "-0x%" PRIx64 "\n",
424+
(void *) addr, start, end);
441425
*valp = 0;
442426
return ret;
443427
}
@@ -446,8 +430,8 @@ static int access_mem(unw_addr_space_t __maybe_unused as,
446430

447431
offset = addr - start;
448432
*valp = *(unw_word_t *)&stack->data[offset];
449-
pr_debug("unwind: access_mem addr %p, val %lx, offset %d\n",
450-
(void *)addr, (unsigned long)*valp, offset);
433+
pr_debug("unwind: access_mem addr %p val %lx, offset %d\n",
434+
(void *) addr, (unsigned long)*valp, offset);
451435
return 0;
452436
}
453437

@@ -457,6 +441,7 @@ static int access_reg(unw_addr_space_t __maybe_unused as,
457441
{
458442
struct unwind_info *ui = arg;
459443
int id, ret;
444+
u64 val;
460445

461446
/* Don't support write, I suspect we don't need it. */
462447
if (__write) {
@@ -473,12 +458,13 @@ static int access_reg(unw_addr_space_t __maybe_unused as,
473458
if (id < 0)
474459
return -EINVAL;
475460

476-
ret = reg_value(valp, &ui->sample->user_regs, id);
461+
ret = perf_reg_value(&val, &ui->sample->user_regs, id);
477462
if (ret) {
478463
pr_err("unwind: can't read reg %d\n", regnum);
479464
return ret;
480465
}
481466

467+
*valp = (unw_word_t) val;
482468
pr_debug("unwind: reg %d, val %lx\n", regnum, (unsigned long)*valp);
483469
return 0;
484470
}
@@ -572,7 +558,7 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
572558
struct machine *machine, struct thread *thread,
573559
struct perf_sample *data, int max_stack)
574560
{
575-
unw_word_t ip;
561+
u64 ip;
576562
struct unwind_info ui = {
577563
.sample = data,
578564
.thread = thread,
@@ -583,7 +569,7 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
583569
if (!data->user_regs.regs)
584570
return -EINVAL;
585571

586-
ret = reg_value(&ip, &data->user_regs, PERF_REG_IP);
572+
ret = perf_reg_value(&ip, &data->user_regs, PERF_REG_IP);
587573
if (ret)
588574
return ret;
589575

0 commit comments

Comments
 (0)