Skip to contentSkip to conversation

perf tool: Minor code clean ups

PATCH Applied Ian Rogers 2 participants 9 messages Feb 7 – Mar 14 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

cover perf tool: Minor code clean ups

Remove some unused functions, files, etc. Reduce scope of variables and functions. Constify arrays in perf.c.

Ian Rogers (5):
perf symbol: Reduce scope of elf__needs_adjust_symbols perf dump-insn: Remove dump-insn.c
perf tool: Constify the command and option arrays perf bpf_map: Remove unused code
perf record: Remove unused cpu-set-sched.h

 tools/perf/builtin-record.c     |  1 -
 tools/perf/builtin-trace.c      |  1 -
 tools/perf/perf.c               | 12 +++---
 tools/perf/util/Build           |  2 -
 tools/perf/util/bpf_map.c       | 70 ---------------------------------
 tools/perf/util/bpf_map.h       | 23 -----------
 tools/perf/util/cpu-set-sched.h | 50 -----------------------
 tools/perf/util/dump-insn.c     | 23 -----------
 tools/perf/util/symbol-elf.c    |  8 ++--
 tools/perf/util/symbol.h        |  1 -
 10 files changed, 10 insertions(+), 181 deletions(-)
 delete mode 100644 tools/perf/util/bpf_map.c
 delete mode 100644 tools/perf/util/bpf_map.h
 delete mode 100644 tools/perf/util/cpu-set-sched.h
 delete mode 100644 tools/perf/util/dump-insn.c
Signature · 1 line
2.53.0.239.g8d8fc8a987-goog
author reviewer
#1 lore raw

PATCH 1/5 perf symbol: Reduce scope of elf__needs_adjust_symbols

Function is only used by symsrc__init in symbol-elf.c, make static to reduce scope. Switch to not passing the argument by value but as a pointer.

---
 tools/perf/util/symbol-elf.c | 8 ++++----
 tools/perf/util/symbol.h     | 1 -
 2 files changed, 4 insertions(+), 5 deletions(-)
tools/perf/util/symbol-elf.c +4 -4
index 76912c62b6a0..d7582dbf379e 100644
@@ -1054,15 +1054,15 @@ void symsrc__destroy(struct symsrc *ss)
 	close(ss->fd);
 }
 
-bool elf__needs_adjust_symbols(GElf_Ehdr ehdr)
+static bool elf__needs_adjust_symbols(const GElf_Ehdr *ehdr)
 {
 	/*
 	 * Usually vmlinux is an ELF file with type ET_EXEC for most
 	 * architectures; except Arm64 kernel is linked with option
 	 * '-share', so need to check type ET_DYN.
 	 */
-	return ehdr.e_type == ET_EXEC || ehdr.e_type == ET_REL ||
-	       ehdr.e_type == ET_DYN;
+	return ehdr->e_type == ET_EXEC || ehdr->e_type == ET_REL ||
+	       ehdr->e_type == ET_DYN;
 }
 
 static Elf *read_gnu_debugdata(struct dso *dso, Elf *elf, const char *name, int *fd_ret)
@@ -1235,7 +1235,7 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
 	if (dso__kernel(dso) == DSO_SPACE__USER)
 		ss->adjust_symbols = true;
 	else
-		ss->adjust_symbols = elf__needs_adjust_symbols(ehdr);
+		ss->adjust_symbols = elf__needs_adjust_symbols(&ehdr);
 
 	ss->name   = strdup(name);
 	if (!ss->name) {
tools/perf/util/symbol.h +0 -1
index 3fb5d146d9b1..9aa0016937b7 100644
@@ -217,7 +217,6 @@ int setup_intlist(struct intlist **list, const char *list_str,
 		  const char *list_name);
 
 #ifdef HAVE_LIBELF_SUPPORT
-bool elf__needs_adjust_symbols(GElf_Ehdr ehdr);
 void arch__sym_update(struct symbol *s, GElf_Sym *sym);
 #endif
 
Signature · 1 line
2.53.0.239.g8d8fc8a987-goog
author reviewer
#2 lore raw

PATCH 2/5 perf dump-insn: Remove dump-insn.c

In reply to Ian Rogers

dump_insn and arch_is_uncond_branch are declared in intel-pt-insn-decoder.c which is unconditionally part of all perf builds. Don't declare weak versions of these symbols that will be unused.

---
 tools/perf/util/Build       |  1 -
 tools/perf/util/dump-insn.c | 23 -----------------------
 2 files changed, 24 deletions(-)
 delete mode 100644 tools/perf/util/dump-insn.c
tools/perf/util/Build +0 -1
index bcccad7487a9..89de23dec401 100644
@@ -149,7 +149,6 @@ endif
 perf-util-y += cs-etm-base.o
 
 perf-util-y += parse-branch-options.o
-perf-util-y += dump-insn.o
 perf-util-y += parse-regs-options.o
 perf-util-y += parse-sublevel-options.o
 perf-util-y += term.o
tools/perf/util/dump-insn.c deleted +0 -23
deleted file mode 100644
index c1cc0ade48d0..000000000000
@@ -1,23 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <linux/compiler.h>
-#include "dump-insn.h"
-
-/* Fallback code */
-
-__weak
-const char *dump_insn(struct perf_insn *x __maybe_unused,
-		      u64 ip __maybe_unused, u8 *inbuf __maybe_unused,
-		      int inlen __maybe_unused, int *lenp)
-{
-	if (lenp)
-		*lenp = 0;
-	return "?";
-}
-
-__weak
-int arch_is_uncond_branch(const unsigned char *buf __maybe_unused,
-		   size_t len __maybe_unused,
-		   int x86_64 __maybe_unused)
-{
-	return 0;
-}
Signature · 1 line
2.53.0.239.g8d8fc8a987-goog
author reviewer
#3 lore raw

PATCH 3/5 perf tool: Constify the command and option arrays

In reply to Ian Rogers

Reduce scope and capture immutability.

---
 tools/perf/perf.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/perf/perf.c +6 -6
index f475a8664ffc..1f51e8de6b1b 100644
@@ -48,7 +48,7 @@ struct cmd_struct {
 	int option;
 };
 
-static struct cmd_struct commands[] = {
+static const struct cmd_struct commands[] = {
 	{ "archive",	NULL,	0 },
 	{ "buildid-cache", cmd_buildid_cache, 0 },
 	{ "buildid-list", cmd_buildid_list, 0 },
@@ -178,7 +178,7 @@ static int set_debug_file(const char *path)
 	return 0;
 }
 
-struct option options[] = {
+static const struct option options[] = {
 	OPT_ARGUMENT("help", "help"),
 	OPT_ARGUMENT("version", "version"),
 	OPT_ARGUMENT("exec-path", "exec-path"),
@@ -280,7 +280,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 			unsigned int i;
 
 			for (i = 0; i < ARRAY_SIZE(commands); i++) {
-				struct cmd_struct *p = commands+i;
+				const struct cmd_struct *p = commands + i;
 				printf("%s ", p->cmd);
 			}
 			putchar('\n');
@@ -289,7 +289,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 			unsigned int i;
 
 			for (i = 0; i < ARRAY_SIZE(options)-1; i++) {
-				struct option *p = options+i;
+				const struct option *p = options + i;
 				printf("--%s ", p->long_name);
 			}
 			putchar('\n');
@@ -331,7 +331,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 #define RUN_SETUP	(1<<0)
 #define USE_PAGER	(1<<1)
 
-static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
+static int run_builtin(const struct cmd_struct *p, int argc, const char **argv)
 {
 	int status;
 	struct stat st;
@@ -390,7 +390,7 @@ static void handle_internal_command(int argc, const char **argv)
 	}
 
 	for (i = 0; i < ARRAY_SIZE(commands); i++) {
-		struct cmd_struct *p = commands+i;
+		const struct cmd_struct *p = commands+i;
 		if (p->fn == NULL)
 			continue;
 		if (strcmp(p->cmd, cmd))
Signature · 1 line
2.53.0.239.g8d8fc8a987-goog
author reviewer
#4 lore raw

PATCH 4/5 perf bpf_map: Remove unused code

In reply to Ian Rogers

bpf_map__fprintf is unused so delete it, the header file declaring it and the now unused static helper functions.

---
 tools/perf/builtin-trace.c |  1 -
 tools/perf/util/Build      |  1 -
 tools/perf/util/bpf_map.c  | 70 --------------------------------------
 tools/perf/util/bpf_map.h  | 23 -------------
 4 files changed, 95 deletions(-)
 delete mode 100644 tools/perf/util/bpf_map.c
 delete mode 100644 tools/perf/util/bpf_map.h
tools/perf/builtin-trace.c +0 -1
index 311d9da9896a..2aaa3ff452ac 100644
@@ -21,7 +21,6 @@
 #include <bpf/libbpf.h>
 #include <bpf/btf.h>
 #endif
-#include "util/bpf_map.h"
 #include "util/rlimit.h"
 #include "builtin.h"
 #include "util/cgroup.h"
tools/perf/util/Build +0 -1
index 89de23dec401..70cc91d00804 100644
@@ -170,7 +170,6 @@ perf-util-y += mutex.o
 perf-util-y += sharded_mutex.o
 perf-util-y += intel-tpebs.o
 
-perf-util-$(CONFIG_LIBBPF) += bpf_map.o
 perf-util-$(CONFIG_PERF_BPF_SKEL) += bpf_counter.o
 perf-util-$(CONFIG_PERF_BPF_SKEL) += bpf_counter_cgroup.o
 perf-util-$(CONFIG_PERF_BPF_SKEL) += bpf_ftrace.o
tools/perf/util/bpf_map.c deleted +0 -70

70 lines not on this page · raw message

tools/perf/util/bpf_map.h deleted +0 -23
deleted file mode 100644
index c2f7c13cba23..000000000000
@@ -1,23 +0,0 @@
-// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
-#ifndef __PERF_BPF_MAP_H
-#define __PERF_BPF_MAP_H 1
-
-#include <stdio.h>
-struct bpf_map;
-
-#ifdef HAVE_LIBBPF_SUPPORT
-
-int bpf_map__fprintf(struct bpf_map *map, FILE *fp);
-
-#else
-
-#include <linux/compiler.h>
-
-static inline int bpf_map__fprintf(struct bpf_map *map __maybe_unused, FILE *fp __maybe_unused)
-{
-	return 0;
-}
-
-#endif // HAVE_LIBBPF_SUPPORT
-
-#endif // __PERF_BPF_MAP_H
Signature · 1 line
2.53.0.239.g8d8fc8a987-goog
author reviewer
#5 lore raw

PATCH 5/5 perf record: Remove unused cpu-set-sched.h

In reply to Ian Rogers

Header file declares unused macros, so remove.

---
 tools/perf/builtin-record.c     |  1 -
 tools/perf/util/cpu-set-sched.h | 50 ---------------------------------
 2 files changed, 51 deletions(-)
 delete mode 100644 tools/perf/util/cpu-set-sched.h
tools/perf/builtin-record.c +0 -1
index 60d764068302..40917a0be238 100644
@@ -40,7 +40,6 @@
 #include "util/perf_api_probe.h"
 #include "util/trigger.h"
 #include "util/perf-hooks.h"
-#include "util/cpu-set-sched.h"
 #include "util/synthetic-events.h"
 #include "util/time-utils.h"
 #include "util/units.h"
tools/perf/util/cpu-set-sched.h deleted +0 -50

50 lines not on this page · raw message

Signature · 1 line
2.53.0.239.g8d8fc8a987-goog
author reviewer
#6 lore raw
In reply to Ian Rogers
Quoted 10 lines · Ian Rogers

Remove some unused functions, files, etc. Reduce scope of variables and functions. Constify arrays in perf.c.

Ian Rogers (5):
perf symbol: Reduce scope of elf__needs_adjust_symbols perf dump-insn: Remove dump-insn.c
perf tool: Constify the command and option arrays perf bpf_map: Remove unused code
perf record: Remove unused cpu-set-sched.h

Ping.

Thanks,
Ian

Quoted 19 lines
 tools/perf/builtin-record.c     |  1 -
 tools/perf/builtin-trace.c      |  1 -
 tools/perf/perf.c               | 12 +++---
 tools/perf/util/Build           |  2 -
 tools/perf/util/bpf_map.c       | 70 ---------------------------------
 tools/perf/util/bpf_map.h       | 23 -----------
 tools/perf/util/cpu-set-sched.h | 50 -----------------------
 tools/perf/util/dump-insn.c     | 23 -----------
 tools/perf/util/symbol-elf.c    |  8 ++--
 tools/perf/util/symbol.h        |  1 -
 10 files changed, 10 insertions(+), 181 deletions(-)
 delete mode 100644 tools/perf/util/bpf_map.c
 delete mode 100644 tools/perf/util/bpf_map.h
 delete mode 100644 tools/perf/util/cpu-set-sched.h
 delete mode 100644 tools/perf/util/dump-insn.c

--
2.53.0.239.g8d8fc8a987-goog

maintainer
#7 lore raw
Quoted 11 lines · Ian Rogers
Quoted 10 lines · Ian Rogers

Remove some unused functions, files, etc. Reduce scope of variables and functions. Constify arrays in perf.c.

Ian Rogers (5):
perf symbol: Reduce scope of elf__needs_adjust_symbols perf dump-insn: Remove dump-insn.c
perf tool: Constify the command and option arrays perf bpf_map: Remove unused code
perf record: Remove unused cpu-set-sched.h

Sorry for the delay. Looks fine to me.

I'll test and process them soon.

Thanks,
Namhyung

Quoted 19 lines
Quoted 19 lines
 tools/perf/builtin-record.c     |  1 -
 tools/perf/builtin-trace.c      |  1 -
 tools/perf/perf.c               | 12 +++---
 tools/perf/util/Build           |  2 -
 tools/perf/util/bpf_map.c       | 70 ---------------------------------
 tools/perf/util/bpf_map.h       | 23 -----------
 tools/perf/util/cpu-set-sched.h | 50 -----------------------
 tools/perf/util/dump-insn.c     | 23 -----------
 tools/perf/util/symbol-elf.c    |  8 ++--
 tools/perf/util/symbol.h        |  1 -
 10 files changed, 10 insertions(+), 181 deletions(-)
 delete mode 100644 tools/perf/util/bpf_map.c
 delete mode 100644 tools/perf/util/bpf_map.h
 delete mode 100644 tools/perf/util/cpu-set-sched.h
 delete mode 100644 tools/perf/util/dump-insn.c

--
2.53.0.239.g8d8fc8a987-goog

maintainer Applied
#8 lore raw
Quoted 13 lines · Namhyung Kim
Quoted 11 lines · Ian Rogers
Quoted 10 lines · Ian Rogers

Remove some unused functions, files, etc. Reduce scope of variables and functions. Constify arrays in perf.c.

Ian Rogers (5):
perf symbol: Reduce scope of elf__needs_adjust_symbols perf dump-insn: Remove dump-insn.c
perf tool: Constify the command and option arrays perf bpf_map: Remove unused code
perf record: Remove unused cpu-set-sched.h

Quoted 3 lines

Sorry for the delay. Looks fine to me.

I'll test and process them soon.

Applied to perf-tools-next, thanks!

Best regards,
Namhyung