forked from Minki/linux
20ebc4a649
Commitf4a2aade68
("perf tests powerpc: Fix branch stack sampling test to include sanity check for branch filter") added a skip if certain branch options aren't available. But the change added both -b (--branch-any) and --branch-filter options at the same time, which will always result in a failure on any platform because the arguments can't be used together. Fix this by removing -b (--branch-any) and leaving --branch-filter which already specifies 'any'. Also add warning messages to the test and perf tool. Output on x86 before this fix: $ sudo ./perf test branch 108: Check branch stack sampling : Skip After: $ sudo ./perf test branch 108: Check branch stack sampling : Ok Fixes:f4a2aade68
("perf tests powerpc: Fix branch stack sampling test to include sanity check for branch filter") Signed-off-by: James Clark <james.clark@arm.com> Tested-by: Athira Jajeev <atrajeev@linux.vnet.ibm.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Anshuman.Khandual@arm.com Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20221028121913.745307-1-james.clark@arm.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
112 lines
2.4 KiB
C
112 lines
2.4 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include "util/debug.h"
|
|
#include "util/event.h"
|
|
#include <subcmd/parse-options.h>
|
|
#include "util/parse-branch-options.h"
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#define BRANCH_OPT(n, m) \
|
|
{ .name = n, .mode = (m) }
|
|
|
|
#define BRANCH_END { .name = NULL }
|
|
|
|
struct branch_mode {
|
|
const char *name;
|
|
int mode;
|
|
};
|
|
|
|
static const struct branch_mode branch_modes[] = {
|
|
BRANCH_OPT("u", PERF_SAMPLE_BRANCH_USER),
|
|
BRANCH_OPT("k", PERF_SAMPLE_BRANCH_KERNEL),
|
|
BRANCH_OPT("hv", PERF_SAMPLE_BRANCH_HV),
|
|
BRANCH_OPT("any", PERF_SAMPLE_BRANCH_ANY),
|
|
BRANCH_OPT("any_call", PERF_SAMPLE_BRANCH_ANY_CALL),
|
|
BRANCH_OPT("any_ret", PERF_SAMPLE_BRANCH_ANY_RETURN),
|
|
BRANCH_OPT("ind_call", PERF_SAMPLE_BRANCH_IND_CALL),
|
|
BRANCH_OPT("abort_tx", PERF_SAMPLE_BRANCH_ABORT_TX),
|
|
BRANCH_OPT("in_tx", PERF_SAMPLE_BRANCH_IN_TX),
|
|
BRANCH_OPT("no_tx", PERF_SAMPLE_BRANCH_NO_TX),
|
|
BRANCH_OPT("cond", PERF_SAMPLE_BRANCH_COND),
|
|
BRANCH_OPT("ind_jmp", PERF_SAMPLE_BRANCH_IND_JUMP),
|
|
BRANCH_OPT("call", PERF_SAMPLE_BRANCH_CALL),
|
|
BRANCH_OPT("save_type", PERF_SAMPLE_BRANCH_TYPE_SAVE),
|
|
BRANCH_OPT("stack", PERF_SAMPLE_BRANCH_CALL_STACK),
|
|
BRANCH_OPT("priv", PERF_SAMPLE_BRANCH_PRIV_SAVE),
|
|
BRANCH_END
|
|
};
|
|
|
|
int parse_branch_str(const char *str, __u64 *mode)
|
|
{
|
|
#define ONLY_PLM \
|
|
(PERF_SAMPLE_BRANCH_USER |\
|
|
PERF_SAMPLE_BRANCH_KERNEL |\
|
|
PERF_SAMPLE_BRANCH_HV)
|
|
|
|
int ret = 0;
|
|
char *p, *s;
|
|
char *os = NULL;
|
|
const struct branch_mode *br;
|
|
|
|
if (str == NULL) {
|
|
*mode = PERF_SAMPLE_BRANCH_ANY;
|
|
return 0;
|
|
}
|
|
|
|
/* because str is read-only */
|
|
s = os = strdup(str);
|
|
if (!s)
|
|
return -1;
|
|
|
|
for (;;) {
|
|
p = strchr(s, ',');
|
|
if (p)
|
|
*p = '\0';
|
|
|
|
for (br = branch_modes; br->name; br++) {
|
|
if (!strcasecmp(s, br->name))
|
|
break;
|
|
}
|
|
if (!br->name) {
|
|
ret = -1;
|
|
pr_warning("unknown branch filter %s,"
|
|
" check man page\n", s);
|
|
goto error;
|
|
}
|
|
|
|
*mode |= br->mode;
|
|
|
|
if (!p)
|
|
break;
|
|
|
|
s = p + 1;
|
|
}
|
|
|
|
/* default to any branch */
|
|
if ((*mode & ~ONLY_PLM) == 0) {
|
|
*mode = PERF_SAMPLE_BRANCH_ANY;
|
|
}
|
|
error:
|
|
free(os);
|
|
return ret;
|
|
}
|
|
|
|
int
|
|
parse_branch_stack(const struct option *opt, const char *str, int unset)
|
|
{
|
|
__u64 *mode = (__u64 *)opt->value;
|
|
|
|
if (unset)
|
|
return 0;
|
|
|
|
/*
|
|
* cannot set it twice, -b + --branch-filter for instance
|
|
*/
|
|
if (*mode) {
|
|
pr_err("Error: Can't use --branch-any (-b) with --branch-filter (-j).\n");
|
|
return -1;
|
|
}
|
|
|
|
return parse_branch_str(str, mode);
|
|
}
|