Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf: Move arch specific code into separate arch directory

The perf userspace tool included some architecture specific code to map
registers from the DWARF register number into the names used by the regs
and stack access API.

This moves the architecture specific code out into a separate
arch/x86 directory along with the infrastructure required to use it.

Signed-off-by: Ian Munsie <imunsie@au.ibm.com>
Acked-by: Masami Hiramatsu <mhiramat@redhat.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>

authored by

Ian Munsie and committed by
Paul Mackerras
cd932c59 6eca8cc3

+119 -59
+30 -6
tools/perf/Makefile
··· 173 173 uname_P := $(shell sh -c 'uname -p 2>/dev/null || echo not') 174 174 uname_V := $(shell sh -c 'uname -v 2>/dev/null || echo not') 175 175 176 + ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \ 177 + -e s/arm.*/arm/ -e s/sa110/arm/ \ 178 + -e s/s390x/s390/ -e s/parisc64/parisc/ \ 179 + -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \ 180 + -e s/sh[234].*/sh/ ) 181 + 182 + # Additional ARCH settings for x86 183 + ifeq ($(ARCH),i386) 184 + ARCH := x86 185 + endif 186 + ifeq ($(ARCH),x86_64) 187 + ARCH := x86 188 + endif 189 + 176 190 # CFLAGS and LDFLAGS are for the users to override from the command line. 177 191 178 192 # ··· 299 285 # Those must not be GNU-specific; they are shared with perl/ which may 300 286 # be built by a different compiler. (Note that this is an artifact now 301 287 # but it still might be nice to keep that distinction.) 302 - BASIC_CFLAGS = -Iutil/include 288 + BASIC_CFLAGS = -Iutil/include -Iarch/$(ARCH)/include 303 289 BASIC_LDFLAGS = 304 290 305 291 # Guard against environment variables ··· 381 367 LIB_H += util/include/asm/swab.h 382 368 LIB_H += util/include/asm/system.h 383 369 LIB_H += util/include/asm/uaccess.h 370 + LIB_H += util/include/dwarf-regs.h 384 371 LIB_H += perf.h 385 372 LIB_H += util/cache.h 386 373 LIB_H += util/callchain.h ··· 502 487 -include config.mak.autogen 503 488 -include config.mak 504 489 490 + ifndef NO_DWARF 491 + ifneq ($(shell sh -c "(echo '\#include <dwarf.h>'; echo '\#include <libdw.h>'; echo 'int main(void) { Dwarf *dbg; dbg = dwarf_begin(0, DWARF_C_READ); return (long)dbg; }') | $(CC) -x c - $(ALL_CFLAGS) -I/usr/include/elfutils -ldw -lelf -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) 492 + msg := $(warning No libdw.h found or old libdw.h found, disables dwarf support. Please install elfutils-devel/elfutils-dev); 493 + NO_DWARF := 1 494 + endif # Dwarf support 495 + endif # NO_DWARF 496 + 497 + -include arch/$(ARCH)/Makefile 498 + 505 499 ifeq ($(uname_S),Darwin) 506 500 ifndef NO_FINK 507 501 ifeq ($(shell test -d /sw/lib && echo y),y) ··· 543 519 msg := $(error No libelf.h/libelf found, please install libelf-dev/elfutils-libelf-devel and glibc-dev[el]); 544 520 endif 545 521 546 - ifneq ($(shell sh -c "(echo '\#include <dwarf.h>'; echo '\#include <libdw.h>'; echo 'int main(void) { Dwarf *dbg; dbg = dwarf_begin(0, DWARF_C_READ); return (long)dbg; }') | $(CC) -x c - $(ALL_CFLAGS) -I/usr/include/elfutils -ldw -lelf -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) 547 - msg := $(warning No libdw.h found or old libdw.h found, disables dwarf support. Please install elfutils-devel/elfutils-dev); 548 - else 549 522 ifndef NO_DWARF 523 + ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined) 524 + msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled); 525 + else 550 526 BASIC_CFLAGS += -I/usr/include/elfutils -DDWARF_SUPPORT 551 527 EXTLIBS += -lelf -ldw 552 528 LIB_OBJS += $(OUTPUT)util/probe-finder.o 553 - endif 554 - endif 529 + endif # PERF_HAVE_DWARF_REGS 530 + endif # NO_DWARF 555 531 556 532 ifneq ($(shell sh -c "(echo '\#include <newt.h>'; echo 'int main(void) { newtInit(); newtCls(); return newtFinished(); }') | $(CC) -x c - $(ALL_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -lnewt -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) 557 533 msg := $(warning newt not found, disables TUI support. Please install newt-devel or libnewt-dev);
+4
tools/perf/arch/x86/Makefile
··· 1 + ifndef NO_DWARF 2 + PERF_HAVE_DWARF_REGS := 1 3 + LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o 4 + endif
+75
tools/perf/arch/x86/util/dwarf-regs.c
··· 1 + /* 2 + * dwarf-regs.c : Mapping of DWARF debug register numbers into register names. 3 + * Extracted from probe-finder.c 4 + * 5 + * Written by Masami Hiramatsu <mhiramat@redhat.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License as published by 9 + * the Free Software Foundation; either version 2 of the License, or 10 + * (at your option) any later version. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + * 17 + * You should have received a copy of the GNU General Public License 18 + * along with this program; if not, write to the Free Software 19 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 + * 21 + */ 22 + 23 + #include <libio.h> 24 + #include <dwarf-regs.h> 25 + 26 + /* 27 + * Generic dwarf analysis helpers 28 + */ 29 + 30 + #define X86_32_MAX_REGS 8 31 + const char *x86_32_regs_table[X86_32_MAX_REGS] = { 32 + "%ax", 33 + "%cx", 34 + "%dx", 35 + "%bx", 36 + "$stack", /* Stack address instead of %sp */ 37 + "%bp", 38 + "%si", 39 + "%di", 40 + }; 41 + 42 + #define X86_64_MAX_REGS 16 43 + const char *x86_64_regs_table[X86_64_MAX_REGS] = { 44 + "%ax", 45 + "%dx", 46 + "%cx", 47 + "%bx", 48 + "%si", 49 + "%di", 50 + "%bp", 51 + "%sp", 52 + "%r8", 53 + "%r9", 54 + "%r10", 55 + "%r11", 56 + "%r12", 57 + "%r13", 58 + "%r14", 59 + "%r15", 60 + }; 61 + 62 + /* TODO: switching by dwarf address size */ 63 + #ifdef __x86_64__ 64 + #define ARCH_MAX_REGS X86_64_MAX_REGS 65 + #define arch_regs_table x86_64_regs_table 66 + #else 67 + #define ARCH_MAX_REGS X86_32_MAX_REGS 68 + #define arch_regs_table x86_32_regs_table 69 + #endif 70 + 71 + /* Return architecture dependent register string (for kprobe-tracer) */ 72 + const char *get_arch_regstr(unsigned int n) 73 + { 74 + return (n <= ARCH_MAX_REGS) ? arch_regs_table[n] : NULL; 75 + }
+8
tools/perf/util/include/dwarf-regs.h
··· 1 + #ifndef _PERF_DWARF_REGS_H_ 2 + #define _PERF_DWARF_REGS_H_ 3 + 4 + #ifdef DWARF_SUPPORT 5 + const char *get_arch_regstr(unsigned int n); 6 + #endif 7 + 8 + #endif
+2 -53
tools/perf/util/probe-finder.c
··· 31 31 #include <string.h> 32 32 #include <stdarg.h> 33 33 #include <ctype.h> 34 + #include <dwarf-regs.h> 34 35 35 36 #include "string.h" 36 37 #include "event.h" ··· 39 38 #include "util.h" 40 39 #include "probe-finder.h" 41 40 42 - 43 - /* 44 - * Generic dwarf analysis helpers 45 - */ 46 - 47 - #define X86_32_MAX_REGS 8 48 - const char *x86_32_regs_table[X86_32_MAX_REGS] = { 49 - "%ax", 50 - "%cx", 51 - "%dx", 52 - "%bx", 53 - "$stack", /* Stack address instead of %sp */ 54 - "%bp", 55 - "%si", 56 - "%di", 57 - }; 58 - 59 - #define X86_64_MAX_REGS 16 60 - const char *x86_64_regs_table[X86_64_MAX_REGS] = { 61 - "%ax", 62 - "%dx", 63 - "%cx", 64 - "%bx", 65 - "%si", 66 - "%di", 67 - "%bp", 68 - "%sp", 69 - "%r8", 70 - "%r9", 71 - "%r10", 72 - "%r11", 73 - "%r12", 74 - "%r13", 75 - "%r14", 76 - "%r15", 77 - }; 78 - 79 - /* TODO: switching by dwarf address size */ 80 - #ifdef __x86_64__ 81 - #define ARCH_MAX_REGS X86_64_MAX_REGS 82 - #define arch_regs_table x86_64_regs_table 83 - #else 84 - #define ARCH_MAX_REGS X86_32_MAX_REGS 85 - #define arch_regs_table x86_32_regs_table 86 - #endif 87 - 88 41 /* Kprobe tracer basic type is up to u64 */ 89 42 #define MAX_BASIC_TYPE_BITS 64 90 - 91 - /* Return architecture dependent register string (for kprobe-tracer) */ 92 - static const char *get_arch_regstr(unsigned int n) 93 - { 94 - return (n <= ARCH_MAX_REGS) ? arch_regs_table[n] : NULL; 95 - } 96 43 97 44 /* 98 45 * Compare the tail of two strings. ··· 396 447 397 448 regs = get_arch_regstr(regn); 398 449 if (!regs) { 399 - pr_warning("%u exceeds max register number.\n", regn); 450 + pr_warning("Mapping for DWARF register number %u missing on this architecture.", regn); 400 451 return -ERANGE; 401 452 } 402 453