Skip to content

Commit

Permalink
perf tools: Use __maybe_used for unused variables
Browse files Browse the repository at this point in the history
perf defines both __used and __unused variables to use for marking
unused variables. The variable __used is defined to
__attribute__((__unused__)), which contradicts the kernel definition to
__attribute__((__used__)) for new gcc versions. On Android, __used is
also defined in system headers and this leads to warnings like: warning:
'__used__' attribute ignored

__unused is not defined in the kernel and is not a standard definition.
If __unused is included everywhere instead of __used, this leads to
conflicts with glibc headers, since glibc has a variables with this name
in its headers.

The best approach is to use __maybe_unused, the definition used in the
kernel for __attribute__((unused)). In this way there is only one
definition in perf sources (instead of 2 definitions that point to the
same thing: __used and __unused) and it works on both Linux and Android.
This patch simply replaces all instances of __used and __unused with
__maybe_unused.

Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Acked-by: Pekka Enberg <penberg@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1347315303-29906-7-git-send-email-irina.tirdea@intel.com
[ committer note: fixed up conflict with a116e05 in builtin-sched.c ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
itirdea authored and acmel committed Sep 11, 2012
1 parent 7dbf4dc commit 1d037ca
Show file tree
Hide file tree
Showing 76 changed files with 498 additions and 418 deletions.
8 changes: 5 additions & 3 deletions tools/lib/traceevent/event-parse.c
Expand Up @@ -1824,7 +1824,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
} }


static enum event_type static enum event_type
process_entry(struct event_format *event __unused, struct print_arg *arg, process_entry(struct event_format *event __maybe_unused, struct print_arg *arg,
char **tok) char **tok)
{ {
enum event_type type; enum event_type type;
Expand Down Expand Up @@ -2458,7 +2458,8 @@ process_paren(struct event_format *event, struct print_arg *arg, char **tok)




static enum event_type static enum event_type
process_str(struct event_format *event __unused, struct print_arg *arg, char **tok) process_str(struct event_format *event __maybe_unused, struct print_arg *arg,
char **tok)
{ {
enum event_type type; enum event_type type;
char *token; char *token;
Expand Down Expand Up @@ -3653,7 +3654,8 @@ static void free_args(struct print_arg *args)
} }


static char * static char *
get_bprint_format(void *data, int size __unused, struct event_format *event) get_bprint_format(void *data, int size __maybe_unused,
struct event_format *event)
{ {
struct pevent *pevent = event->pevent; struct pevent *pevent = event->pevent;
unsigned long long addr; unsigned long long addr;
Expand Down
4 changes: 2 additions & 2 deletions tools/lib/traceevent/event-parse.h
Expand Up @@ -24,8 +24,8 @@
#include <stdarg.h> #include <stdarg.h>
#include <regex.h> #include <regex.h>


#ifndef __unused #ifndef __maybe_unused
#define __unused __attribute__ ((unused)) #define __maybe_unused __attribute__((unused))
#endif #endif


/* ----------------------- trace_seq ----------------------- */ /* ----------------------- trace_seq ----------------------- */
Expand Down
3 changes: 2 additions & 1 deletion tools/perf/bench/bench.h
Expand Up @@ -3,7 +3,8 @@


extern int bench_sched_messaging(int argc, const char **argv, const char *prefix); extern int bench_sched_messaging(int argc, const char **argv, const char *prefix);
extern int bench_sched_pipe(int argc, const char **argv, const char *prefix); extern int bench_sched_pipe(int argc, const char **argv, const char *prefix);
extern int bench_mem_memcpy(int argc, const char **argv, const char *prefix __used); extern int bench_mem_memcpy(int argc, const char **argv,
const char *prefix __maybe_unused);
extern int bench_mem_memset(int argc, const char **argv, const char *prefix); extern int bench_mem_memset(int argc, const char **argv, const char *prefix);


#define BENCH_FORMAT_DEFAULT_STR "default" #define BENCH_FORMAT_DEFAULT_STR "default"
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/bench/mem-memcpy.c
Expand Up @@ -177,7 +177,7 @@ static double do_memcpy_gettimeofday(memcpy_t fn, size_t len, bool prefault)
} while (0) } while (0)


int bench_mem_memcpy(int argc, const char **argv, int bench_mem_memcpy(int argc, const char **argv,
const char *prefix __used) const char *prefix __maybe_unused)
{ {
int i; int i;
size_t len; size_t len;
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/bench/mem-memset.c
Expand Up @@ -171,7 +171,7 @@ static double do_memset_gettimeofday(memset_t fn, size_t len, bool prefault)
} while (0) } while (0)


int bench_mem_memset(int argc, const char **argv, int bench_mem_memset(int argc, const char **argv,
const char *prefix __used) const char *prefix __maybe_unused)
{ {
int i; int i;
size_t len; size_t len;
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/bench/sched-messaging.c
Expand Up @@ -267,7 +267,7 @@ static const char * const bench_sched_message_usage[] = {
}; };


int bench_sched_messaging(int argc, const char **argv, int bench_sched_messaging(int argc, const char **argv,
const char *prefix __used) const char *prefix __maybe_unused)
{ {
unsigned int i, total_children; unsigned int i, total_children;
struct timeval start, stop, diff; struct timeval start, stop, diff;
Expand Down
6 changes: 3 additions & 3 deletions tools/perf/bench/sched-pipe.c
Expand Up @@ -43,7 +43,7 @@ static const char * const bench_sched_pipe_usage[] = {
}; };


int bench_sched_pipe(int argc, const char **argv, int bench_sched_pipe(int argc, const char **argv,
const char *prefix __used) const char *prefix __maybe_unused)
{ {
int pipe_1[2], pipe_2[2]; int pipe_1[2], pipe_2[2];
int m = 0, i; int m = 0, i;
Expand All @@ -55,8 +55,8 @@ int bench_sched_pipe(int argc, const char **argv,
* discarding returned value of read(), write() * discarding returned value of read(), write()
* causes error in building environment for perf * causes error in building environment for perf
*/ */
int __used ret, wait_stat; int __maybe_unused ret, wait_stat;
pid_t pid, retpid __used; pid_t pid, retpid __maybe_unused;


argc = parse_options(argc, argv, options, argc = parse_options(argc, argv, options,
bench_sched_pipe_usage, 0); bench_sched_pipe_usage, 0);
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-annotate.c
Expand Up @@ -239,7 +239,7 @@ static const char * const annotate_usage[] = {
NULL NULL
}; };


int cmd_annotate(int argc, const char **argv, const char *prefix __used) int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
{ {
struct perf_annotate annotate = { struct perf_annotate annotate = {
.tool = { .tool = {
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-bench.c
Expand Up @@ -173,7 +173,7 @@ static void all_subsystem(void)
all_suite(&subsystems[i]); all_suite(&subsystems[i]);
} }


int cmd_bench(int argc, const char **argv, const char *prefix __used) int cmd_bench(int argc, const char **argv, const char *prefix __maybe_unused)
{ {
int i, j, status = 0; int i, j, status = 0;


Expand Down
7 changes: 4 additions & 3 deletions tools/perf/builtin-buildid-cache.c
Expand Up @@ -51,8 +51,8 @@ static int build_id_cache__add_file(const char *filename, const char *debugdir)
return err; return err;
} }


static int build_id_cache__remove_file(const char *filename __used, static int build_id_cache__remove_file(const char *filename __maybe_unused,
const char *debugdir __used) const char *debugdir __maybe_unused)
{ {
u8 build_id[BUILD_ID_SIZE]; u8 build_id[BUILD_ID_SIZE];
char sbuild_id[BUILD_ID_SIZE * 2 + 1]; char sbuild_id[BUILD_ID_SIZE * 2 + 1];
Expand Down Expand Up @@ -120,7 +120,8 @@ static int __cmd_buildid_cache(void)
return 0; return 0;
} }


int cmd_buildid_cache(int argc, const char **argv, const char *prefix __used) int cmd_buildid_cache(int argc, const char **argv,
const char *prefix __maybe_unused)
{ {
argc = parse_options(argc, argv, buildid_cache_options, argc = parse_options(argc, argv, buildid_cache_options,
buildid_cache_usage, 0); buildid_cache_usage, 0);
Expand Down
3 changes: 2 additions & 1 deletion tools/perf/builtin-buildid-list.c
Expand Up @@ -103,7 +103,8 @@ static int __cmd_buildid_list(void)
return perf_session__list_build_ids(); return perf_session__list_build_ids();
} }


int cmd_buildid_list(int argc, const char **argv, const char *prefix __used) int cmd_buildid_list(int argc, const char **argv,
const char *prefix __maybe_unused)
{ {
argc = parse_options(argc, argv, options, buildid_list_usage, 0); argc = parse_options(argc, argv, options, buildid_list_usage, 0);
setup_pager(); setup_pager();
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/builtin-diff.c
Expand Up @@ -33,7 +33,7 @@ static int hists__add_entry(struct hists *self,
return -ENOMEM; return -ENOMEM;
} }


static int diff__process_sample_event(struct perf_tool *tool __used, static int diff__process_sample_event(struct perf_tool *tool __maybe_unused,
union perf_event *event, union perf_event *event,
struct perf_sample *sample, struct perf_sample *sample,
struct perf_evsel *evsel, struct perf_evsel *evsel,
Expand Down Expand Up @@ -242,7 +242,7 @@ static const struct option options[] = {
OPT_END() OPT_END()
}; };


int cmd_diff(int argc, const char **argv, const char *prefix __used) int cmd_diff(int argc, const char **argv, const char *prefix __maybe_unused)
{ {
sort_order = diff__default_sort_order; sort_order = diff__default_sort_order;
argc = parse_options(argc, argv, options, diff_usage, 0); argc = parse_options(argc, argv, options, diff_usage, 0);
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-evlist.c
Expand Up @@ -113,7 +113,7 @@ static const char * const evlist_usage[] = {
NULL NULL
}; };


int cmd_evlist(int argc, const char **argv, const char *prefix __used) int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused)
{ {
struct perf_attr_details details = { .verbose = false, }; struct perf_attr_details details = { .verbose = false, };
const char *input_name = NULL; const char *input_name = NULL;
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-help.c
Expand Up @@ -426,7 +426,7 @@ static int show_html_page(const char *perf_cmd)
return 0; return 0;
} }


int cmd_help(int argc, const char **argv, const char *prefix __used) int cmd_help(int argc, const char **argv, const char *prefix __maybe_unused)
{ {
const char *alias; const char *alias;
int rc = 0; int rc = 0;
Expand Down
24 changes: 13 additions & 11 deletions tools/perf/builtin-inject.c
Expand Up @@ -17,9 +17,9 @@
static char const *input_name = "-"; static char const *input_name = "-";
static bool inject_build_ids; static bool inject_build_ids;


static int perf_event__repipe_synth(struct perf_tool *tool __used, static int perf_event__repipe_synth(struct perf_tool *tool __maybe_unused,
union perf_event *event, union perf_event *event,
struct machine *machine __used) struct machine *machine __maybe_unused)
{ {
uint32_t size; uint32_t size;
void *buf = event; void *buf = event;
Expand All @@ -40,7 +40,8 @@ static int perf_event__repipe_synth(struct perf_tool *tool __used,


static int perf_event__repipe_op2_synth(struct perf_tool *tool, static int perf_event__repipe_op2_synth(struct perf_tool *tool,
union perf_event *event, union perf_event *event,
struct perf_session *session __used) struct perf_session *session
__maybe_unused)
{ {
return perf_event__repipe_synth(tool, event, NULL); return perf_event__repipe_synth(tool, event, NULL);
} }
Expand All @@ -52,13 +53,14 @@ static int perf_event__repipe_event_type_synth(struct perf_tool *tool,
} }


static int perf_event__repipe_tracing_data_synth(union perf_event *event, static int perf_event__repipe_tracing_data_synth(union perf_event *event,
struct perf_session *session __used) struct perf_session *session
__maybe_unused)
{ {
return perf_event__repipe_synth(NULL, event, NULL); return perf_event__repipe_synth(NULL, event, NULL);
} }


static int perf_event__repipe_attr(union perf_event *event, static int perf_event__repipe_attr(union perf_event *event,
struct perf_evlist **pevlist __used) struct perf_evlist **pevlist __maybe_unused)
{ {
int ret; int ret;
ret = perf_event__process_attr(event, pevlist); ret = perf_event__process_attr(event, pevlist);
Expand All @@ -70,16 +72,16 @@ static int perf_event__repipe_attr(union perf_event *event,


static int perf_event__repipe(struct perf_tool *tool, static int perf_event__repipe(struct perf_tool *tool,
union perf_event *event, union perf_event *event,
struct perf_sample *sample __used, struct perf_sample *sample __maybe_unused,
struct machine *machine) struct machine *machine)
{ {
return perf_event__repipe_synth(tool, event, machine); return perf_event__repipe_synth(tool, event, machine);
} }


static int perf_event__repipe_sample(struct perf_tool *tool, static int perf_event__repipe_sample(struct perf_tool *tool,
union perf_event *event, union perf_event *event,
struct perf_sample *sample __used, struct perf_sample *sample __maybe_unused,
struct perf_evsel *evsel __used, struct perf_evsel *evsel __maybe_unused,
struct machine *machine) struct machine *machine)
{ {
return perf_event__repipe_synth(tool, event, machine); return perf_event__repipe_synth(tool, event, machine);
Expand Down Expand Up @@ -163,7 +165,7 @@ static int dso__inject_build_id(struct dso *self, struct perf_tool *tool,
static int perf_event__inject_buildid(struct perf_tool *tool, static int perf_event__inject_buildid(struct perf_tool *tool,
union perf_event *event, union perf_event *event,
struct perf_sample *sample, struct perf_sample *sample,
struct perf_evsel *evsel __used, struct perf_evsel *evsel __maybe_unused,
struct machine *machine) struct machine *machine)
{ {
struct addr_location al; struct addr_location al;
Expand Down Expand Up @@ -224,7 +226,7 @@ struct perf_tool perf_inject = {


extern volatile int session_done; extern volatile int session_done;


static void sig_handler(int sig __attribute__((__unused__))) static void sig_handler(int sig __maybe_unused)
{ {
session_done = 1; session_done = 1;
} }
Expand Down Expand Up @@ -267,7 +269,7 @@ static const struct option options[] = {
OPT_END() OPT_END()
}; };


int cmd_inject(int argc, const char **argv, const char *prefix __used) int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
{ {
argc = parse_options(argc, argv, options, report_usage, 0); argc = parse_options(argc, argv, options, report_usage, 0);


Expand Down
22 changes: 12 additions & 10 deletions tools/perf/builtin-kmem.c
Expand Up @@ -320,7 +320,7 @@ static int perf_evsel__process_kmem_event(struct perf_evsel *evsel,
return 0; return 0;
} }


static int process_sample_event(struct perf_tool *tool __used, static int process_sample_event(struct perf_tool *tool __maybe_unused,
union perf_event *event, union perf_event *event,
struct perf_sample *sample, struct perf_sample *sample,
struct perf_evsel *evsel, struct perf_evsel *evsel,
Expand Down Expand Up @@ -672,8 +672,8 @@ static int setup_sorting(struct list_head *sort_list, const char *arg)
return 0; return 0;
} }


static int parse_sort_opt(const struct option *opt __used, static int parse_sort_opt(const struct option *opt __maybe_unused,
const char *arg, int unset __used) const char *arg, int unset __maybe_unused)
{ {
if (!arg) if (!arg)
return -1; return -1;
Expand All @@ -686,22 +686,24 @@ static int parse_sort_opt(const struct option *opt __used,
return 0; return 0;
} }


static int parse_caller_opt(const struct option *opt __used, static int parse_caller_opt(const struct option *opt __maybe_unused,
const char *arg __used, int unset __used) const char *arg __maybe_unused,
int unset __maybe_unused)
{ {
caller_flag = (alloc_flag + 1); caller_flag = (alloc_flag + 1);
return 0; return 0;
} }


static int parse_alloc_opt(const struct option *opt __used, static int parse_alloc_opt(const struct option *opt __maybe_unused,
const char *arg __used, int unset __used) const char *arg __maybe_unused,
int unset __maybe_unused)
{ {
alloc_flag = (caller_flag + 1); alloc_flag = (caller_flag + 1);
return 0; return 0;
} }


static int parse_line_opt(const struct option *opt __used, static int parse_line_opt(const struct option *opt __maybe_unused,
const char *arg, int unset __used) const char *arg, int unset __maybe_unused)
{ {
int lines; int lines;


Expand Down Expand Up @@ -771,7 +773,7 @@ static int __cmd_record(int argc, const char **argv)
return cmd_record(i, rec_argv, NULL); return cmd_record(i, rec_argv, NULL);
} }


int cmd_kmem(int argc, const char **argv, const char *prefix __used) int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
{ {
argc = parse_options(argc, argv, kmem_options, kmem_usage, 0); argc = parse_options(argc, argv, kmem_options, kmem_usage, 0);


Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-kvm.c
Expand Up @@ -102,7 +102,7 @@ static int __cmd_buildid_list(int argc, const char **argv)
return cmd_buildid_list(i, rec_argv, NULL); return cmd_buildid_list(i, rec_argv, NULL);
} }


int cmd_kvm(int argc, const char **argv, const char *prefix __used) int cmd_kvm(int argc, const char **argv, const char *prefix __maybe_unused)
{ {
perf_host = 0; perf_host = 0;
perf_guest = 1; perf_guest = 1;
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-list.c
Expand Up @@ -14,7 +14,7 @@
#include "util/parse-events.h" #include "util/parse-events.h"
#include "util/cache.h" #include "util/cache.h"


int cmd_list(int argc, const char **argv, const char *prefix __used) int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
{ {
setup_pager(); setup_pager();


Expand Down
4 changes: 2 additions & 2 deletions tools/perf/builtin-lock.c
Expand Up @@ -870,7 +870,7 @@ static int dump_info(void)
return rc; return rc;
} }


static int process_sample_event(struct perf_tool *tool __used, static int process_sample_event(struct perf_tool *tool __maybe_unused,
union perf_event *event, union perf_event *event,
struct perf_sample *sample, struct perf_sample *sample,
struct perf_evsel *evsel, struct perf_evsel *evsel,
Expand Down Expand Up @@ -1020,7 +1020,7 @@ static int __cmd_record(int argc, const char **argv)
return cmd_record(i, rec_argv, NULL); return cmd_record(i, rec_argv, NULL);
} }


int cmd_lock(int argc, const char **argv, const char *prefix __used) int cmd_lock(int argc, const char **argv, const char *prefix __maybe_unused)
{ {
unsigned int i; unsigned int i;
int rc = 0; int rc = 0;
Expand Down

0 comments on commit 1d037ca

Please sign in to comment.