2012-03-16 02:09:15 +07:00
|
|
|
|
2012-06-15 13:31:39 +07:00
|
|
|
%option reentrant
|
|
|
|
%option bison-bridge
|
2012-03-16 02:09:15 +07:00
|
|
|
%option prefix="parse_events_"
|
2012-05-21 14:12:52 +07:00
|
|
|
%option stack
|
2015-04-23 02:10:17 +07:00
|
|
|
%option bison-locations
|
|
|
|
%option yylineno
|
2012-03-16 02:09:15 +07:00
|
|
|
|
|
|
|
%{
|
|
|
|
#include <errno.h>
|
|
|
|
#include "../perf.h"
|
|
|
|
#include "parse-events-bison.h"
|
2012-03-16 02:09:16 +07:00
|
|
|
#include "parse-events.h"
|
2012-03-16 02:09:15 +07:00
|
|
|
|
2012-06-15 13:31:39 +07:00
|
|
|
char *parse_events_get_text(yyscan_t yyscanner);
|
|
|
|
YYSTYPE *parse_events_get_lval(yyscan_t yyscanner);
|
|
|
|
|
|
|
|
static int __value(YYSTYPE *yylval, char *str, int base, int token)
|
2012-03-16 02:09:15 +07:00
|
|
|
{
|
2012-08-08 00:43:13 +07:00
|
|
|
u64 num;
|
2012-03-16 02:09:15 +07:00
|
|
|
|
|
|
|
errno = 0;
|
2012-08-08 00:43:13 +07:00
|
|
|
num = strtoull(str, NULL, base);
|
2012-03-16 02:09:15 +07:00
|
|
|
if (errno)
|
|
|
|
return PE_ERROR;
|
|
|
|
|
2012-06-15 13:31:39 +07:00
|
|
|
yylval->num = num;
|
2012-03-16 02:09:15 +07:00
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
2012-06-15 13:31:39 +07:00
|
|
|
static int value(yyscan_t scanner, int base)
|
2012-03-16 02:09:15 +07:00
|
|
|
{
|
2012-06-15 13:31:39 +07:00
|
|
|
YYSTYPE *yylval = parse_events_get_lval(scanner);
|
|
|
|
char *text = parse_events_get_text(scanner);
|
|
|
|
|
|
|
|
return __value(yylval, text, base, PE_VALUE);
|
2012-03-16 02:09:15 +07:00
|
|
|
}
|
|
|
|
|
2012-06-15 13:31:39 +07:00
|
|
|
static int raw(yyscan_t scanner)
|
2012-03-16 02:09:15 +07:00
|
|
|
{
|
2012-06-15 13:31:39 +07:00
|
|
|
YYSTYPE *yylval = parse_events_get_lval(scanner);
|
|
|
|
char *text = parse_events_get_text(scanner);
|
|
|
|
|
|
|
|
return __value(yylval, text + 1, 16, PE_RAW);
|
2012-03-16 02:09:15 +07:00
|
|
|
}
|
|
|
|
|
2012-06-15 13:31:39 +07:00
|
|
|
static int str(yyscan_t scanner, int token)
|
2012-03-16 02:09:15 +07:00
|
|
|
{
|
2012-06-15 13:31:39 +07:00
|
|
|
YYSTYPE *yylval = parse_events_get_lval(scanner);
|
|
|
|
char *text = parse_events_get_text(scanner);
|
|
|
|
|
|
|
|
yylval->str = strdup(text);
|
2012-03-16 02:09:15 +07:00
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
2015-04-23 02:10:17 +07:00
|
|
|
#define REWIND(__alloc) \
|
|
|
|
do { \
|
|
|
|
YYSTYPE *__yylval = parse_events_get_lval(yyscanner); \
|
|
|
|
char *text = parse_events_get_text(yyscanner); \
|
|
|
|
\
|
|
|
|
if (__alloc) \
|
|
|
|
__yylval->str = strdup(text); \
|
|
|
|
\
|
|
|
|
yycolumn -= strlen(text); \
|
|
|
|
yyless(0); \
|
|
|
|
} while (0)
|
|
|
|
|
2014-10-07 22:08:51 +07:00
|
|
|
static int pmu_str_check(yyscan_t scanner)
|
|
|
|
{
|
|
|
|
YYSTYPE *yylval = parse_events_get_lval(scanner);
|
|
|
|
char *text = parse_events_get_text(scanner);
|
|
|
|
|
|
|
|
yylval->str = strdup(text);
|
|
|
|
switch (perf_pmu__parse_check(text)) {
|
|
|
|
case PMU_EVENT_SYMBOL_PREFIX:
|
|
|
|
return PE_PMU_EVENT_PRE;
|
|
|
|
case PMU_EVENT_SYMBOL_SUFFIX:
|
|
|
|
return PE_PMU_EVENT_SUF;
|
|
|
|
case PMU_EVENT_SYMBOL:
|
|
|
|
return PE_KERNEL_PMU_EVENT;
|
|
|
|
default:
|
|
|
|
return PE_NAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-15 13:31:39 +07:00
|
|
|
static int sym(yyscan_t scanner, int type, int config)
|
2012-03-16 02:09:15 +07:00
|
|
|
{
|
2012-06-15 13:31:39 +07:00
|
|
|
YYSTYPE *yylval = parse_events_get_lval(scanner);
|
|
|
|
|
|
|
|
yylval->num = (type << 16) + config;
|
2012-07-04 05:00:43 +07:00
|
|
|
return type == PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW;
|
2012-03-16 02:09:15 +07:00
|
|
|
}
|
|
|
|
|
2012-06-15 13:31:39 +07:00
|
|
|
static int term(yyscan_t scanner, int type)
|
2012-03-16 02:09:16 +07:00
|
|
|
{
|
2012-06-15 13:31:39 +07:00
|
|
|
YYSTYPE *yylval = parse_events_get_lval(scanner);
|
|
|
|
|
|
|
|
yylval->num = type;
|
2012-03-16 02:09:16 +07:00
|
|
|
return PE_TERM;
|
|
|
|
}
|
|
|
|
|
2015-04-23 02:10:17 +07:00
|
|
|
#define YY_USER_ACTION \
|
|
|
|
do { \
|
|
|
|
yylloc->last_column = yylloc->first_column; \
|
|
|
|
yylloc->first_column = yycolumn; \
|
|
|
|
yycolumn += yyleng; \
|
|
|
|
} while (0);
|
|
|
|
|
2012-03-16 02:09:15 +07:00
|
|
|
%}
|
|
|
|
|
2012-05-21 14:12:52 +07:00
|
|
|
%x mem
|
2012-08-17 02:10:21 +07:00
|
|
|
%s config
|
|
|
|
%x event
|
|
|
|
|
|
|
|
group [^,{}/]*[{][^}]*[}][^,{}/]*
|
|
|
|
event_pmu [^,{}/]+[/][^/]*[/][^,{}/]*
|
|
|
|
event [^,{}/]+
|
2012-05-21 14:12:52 +07:00
|
|
|
|
2012-03-16 02:09:15 +07:00
|
|
|
num_dec [0-9]+
|
|
|
|
num_hex 0x[a-fA-F0-9]+
|
|
|
|
num_raw_hex [a-fA-F0-9]+
|
|
|
|
name [a-zA-Z_*?][a-zA-Z0-9_*?]*
|
2012-11-05 20:50:52 +07:00
|
|
|
name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?]*
|
perf tools: Add support for pinned modifier
This commit adds support for a new modifier "D", which requests that the
event, or group of events, be pinned to the PMU.
The "p" modifier is already taken for precise, and "P" may be used in
future to mean "fully precise".
So we use "D", which stands for pinneD - and looks like a padlock, or if
you're using the ":D" syntax perf smiles at you.
This is an oft-requested feature from our HW folks, who want to be able
to run a large number of events, but also want 100% accurate results for
instructions per cycle.
Comparison of results with and without pinning:
$ perf stat -e '{cycles,instructions}:D' -e cycles,instructions,...
79,590,480,683 cycles # 0.000 GHz
166,123,716,524 instructions # 2.09 insns per cycle
# 0.11 stalled cycles per insn
79,352,134,463 cycles # 0.000 GHz [11.11%]
165,178,301,818 instructions # 2.08 insns per cycle
# 0.11 stalled cycles per insn [11.13%]
As you can see although perf does a very good job of scaling the values
in the non-pinned case, there is some small discrepancy.
The patch is fairly straight forward, the one detail is that we need to
make sure we only request pinning for the group leader when we have a
group.
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Tested-by: Jiri Olsa <jolsa@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1375795686-4226-1-git-send-email-michael@ellerman.id.au
[ Use perf_evsel__is_group_leader instead of open coded equivalent, as
suggested by Jiri Olsa ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2013-08-06 20:28:05 +07:00
|
|
|
/* If you add a modifier you need to update check_modifier() */
|
2015-04-08 04:25:14 +07:00
|
|
|
modifier_event [ukhpGHSDI]+
|
2012-06-29 14:22:54 +07:00
|
|
|
modifier_bp [rwx]{1,3}
|
2012-03-16 02:09:15 +07:00
|
|
|
|
|
|
|
%%
|
2012-06-15 13:31:40 +07:00
|
|
|
|
|
|
|
%{
|
|
|
|
{
|
|
|
|
int start_token;
|
|
|
|
|
2012-08-17 02:10:21 +07:00
|
|
|
start_token = parse_events_get_extra(yyscanner);
|
|
|
|
|
|
|
|
if (start_token == PE_START_TERMS)
|
|
|
|
BEGIN(config);
|
|
|
|
else if (start_token == PE_START_EVENTS)
|
|
|
|
BEGIN(event);
|
|
|
|
|
2012-06-15 13:31:40 +07:00
|
|
|
if (start_token) {
|
|
|
|
parse_events_set_extra(NULL, yyscanner);
|
2015-04-23 02:10:17 +07:00
|
|
|
/*
|
|
|
|
* The flex parser does not init locations variable
|
|
|
|
* via the scan_string interface, so we need do the
|
|
|
|
* init in here.
|
|
|
|
*/
|
|
|
|
yycolumn = 0;
|
2012-06-15 13:31:40 +07:00
|
|
|
return start_token;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
%}
|
|
|
|
|
2012-08-17 02:10:21 +07:00
|
|
|
<event>{
|
|
|
|
|
|
|
|
{group} {
|
2015-04-23 02:10:17 +07:00
|
|
|
BEGIN(INITIAL);
|
|
|
|
REWIND(0);
|
2012-08-17 02:10:21 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
{event_pmu} |
|
|
|
|
{event} {
|
2015-04-23 02:10:17 +07:00
|
|
|
BEGIN(INITIAL);
|
|
|
|
REWIND(1);
|
2012-08-17 02:10:21 +07:00
|
|
|
return PE_EVENT_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
. |
|
|
|
|
<<EOF>> {
|
2015-04-23 02:10:17 +07:00
|
|
|
BEGIN(INITIAL);
|
|
|
|
REWIND(0);
|
2012-08-17 02:10:21 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-09-27 23:29:58 +07:00
|
|
|
<config>{
|
perf tools: Add term support for parse_events_error
Allowing event's term processing to report back error, like:
$ perf record -e 'cpu/even=0x1/' ls
event syntax error: 'cpu/even=0x1/'
\___ unknown term
valid terms: pc,any,inv,edge,cmask,event,in_tx,ldlat,umask,in_tx_cp,offcore_rsp,config,config1,config2,name,period,branch_type
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
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/1429729824-13932-7-git-send-email-jolsa@kernel.org
[ Renamed 'error' variables to 'err', not to clash with util.h error() ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-23 02:10:21 +07:00
|
|
|
/*
|
|
|
|
* Please update formats_error_string any time
|
|
|
|
* new static term is added.
|
|
|
|
*/
|
2013-09-27 23:29:58 +07:00
|
|
|
config { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG); }
|
|
|
|
config1 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG1); }
|
|
|
|
config2 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG2); }
|
|
|
|
name { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NAME); }
|
|
|
|
period { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD); }
|
|
|
|
branch_type { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE); }
|
|
|
|
, { return ','; }
|
|
|
|
"/" { BEGIN(INITIAL); return '/'; }
|
|
|
|
{name_minus} { return str(yyscanner, PE_NAME); }
|
|
|
|
}
|
|
|
|
|
|
|
|
<mem>{
|
|
|
|
{modifier_bp} { return str(yyscanner, PE_MODIFIER_BP); }
|
|
|
|
: { return ':'; }
|
2014-05-29 22:26:51 +07:00
|
|
|
"/" { return '/'; }
|
2013-09-27 23:29:58 +07:00
|
|
|
{num_dec} { return value(yyscanner, 10); }
|
|
|
|
{num_hex} { return value(yyscanner, 16); }
|
|
|
|
/*
|
|
|
|
* We need to separate 'mem:' scanner part, in order to get specific
|
|
|
|
* modifier bits parsed out. Otherwise we would need to handle PE_NAME
|
|
|
|
* and we'd need to parse it manually. During the escape from <mem>
|
|
|
|
* state we need to put the escaping char back, so we dont miss it.
|
|
|
|
*/
|
|
|
|
. { unput(*yytext); BEGIN(INITIAL); }
|
|
|
|
/*
|
|
|
|
* We destroy the scanner after reaching EOF,
|
|
|
|
* but anyway just to be sure get back to INIT state.
|
|
|
|
*/
|
|
|
|
<<EOF>> { BEGIN(INITIAL); }
|
|
|
|
}
|
|
|
|
|
2012-06-15 13:31:39 +07:00
|
|
|
cpu-cycles|cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES); }
|
|
|
|
stalled-cycles-frontend|idle-cycles-frontend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); }
|
|
|
|
stalled-cycles-backend|idle-cycles-backend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); }
|
|
|
|
instructions { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS); }
|
|
|
|
cache-references { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES); }
|
|
|
|
cache-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES); }
|
|
|
|
branch-instructions|branches { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); }
|
|
|
|
branch-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES); }
|
|
|
|
bus-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BUS_CYCLES); }
|
|
|
|
ref-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES); }
|
|
|
|
cpu-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK); }
|
|
|
|
task-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_TASK_CLOCK); }
|
|
|
|
page-faults|faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS); }
|
|
|
|
minor-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MIN); }
|
|
|
|
major-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MAJ); }
|
|
|
|
context-switches|cs { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CONTEXT_SWITCHES); }
|
|
|
|
cpu-migrations|migrations { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS); }
|
|
|
|
alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); }
|
|
|
|
emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); }
|
2013-09-01 01:50:52 +07:00
|
|
|
dummy { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY); }
|
2012-03-16 02:09:15 +07:00
|
|
|
|
2014-10-07 22:08:51 +07:00
|
|
|
/*
|
|
|
|
* We have to handle the kernel PMU event cycles-ct/cycles-t/mem-loads/mem-stores separately.
|
|
|
|
* Because the prefix cycles is mixed up with cpu-cycles.
|
|
|
|
* loads and stores are mixed up with cache event
|
|
|
|
*/
|
|
|
|
cycles-ct { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
|
|
|
|
cycles-t { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
|
|
|
|
mem-loads { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
|
|
|
|
mem-stores { return str(yyscanner, PE_KERNEL_PMU_EVENT); }
|
|
|
|
|
2012-03-16 02:09:15 +07:00
|
|
|
L1-dcache|l1-d|l1d|L1-data |
|
|
|
|
L1-icache|l1-i|l1i|L1-instruction |
|
|
|
|
LLC|L2 |
|
|
|
|
dTLB|d-tlb|Data-TLB |
|
|
|
|
iTLB|i-tlb|Instruction-TLB |
|
|
|
|
branch|branches|bpu|btb|bpc |
|
2012-06-15 13:31:39 +07:00
|
|
|
node { return str(yyscanner, PE_NAME_CACHE_TYPE); }
|
2012-03-16 02:09:15 +07:00
|
|
|
|
|
|
|
load|loads|read |
|
|
|
|
store|stores|write |
|
|
|
|
prefetch|prefetches |
|
|
|
|
speculative-read|speculative-load |
|
|
|
|
refs|Reference|ops|access |
|
2012-06-15 13:31:39 +07:00
|
|
|
misses|miss { return str(yyscanner, PE_NAME_CACHE_OP_RESULT); }
|
2012-03-16 02:09:15 +07:00
|
|
|
|
2012-05-21 14:12:52 +07:00
|
|
|
mem: { BEGIN(mem); return PE_PREFIX_MEM; }
|
2012-06-15 13:31:39 +07:00
|
|
|
r{num_raw_hex} { return raw(yyscanner); }
|
|
|
|
{num_dec} { return value(yyscanner, 10); }
|
|
|
|
{num_hex} { return value(yyscanner, 16); }
|
2012-03-16 02:09:15 +07:00
|
|
|
|
2012-06-15 13:31:39 +07:00
|
|
|
{modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); }
|
2014-10-07 22:08:51 +07:00
|
|
|
{name} { return pmu_str_check(yyscanner); }
|
2012-08-17 02:10:21 +07:00
|
|
|
"/" { BEGIN(config); return '/'; }
|
2012-03-16 02:09:15 +07:00
|
|
|
- { return '-'; }
|
2012-08-17 02:10:21 +07:00
|
|
|
, { BEGIN(event); return ','; }
|
2012-03-16 02:09:15 +07:00
|
|
|
: { return ':'; }
|
2012-08-17 02:10:21 +07:00
|
|
|
"{" { BEGIN(event); return '{'; }
|
2012-08-08 17:14:14 +07:00
|
|
|
"}" { return '}'; }
|
2012-03-16 02:09:15 +07:00
|
|
|
= { return '='; }
|
2012-07-04 05:00:39 +07:00
|
|
|
\n { }
|
2013-09-27 23:29:58 +07:00
|
|
|
. { }
|
2012-05-21 14:12:52 +07:00
|
|
|
|
2012-03-16 02:09:15 +07:00
|
|
|
%%
|
|
|
|
|
2012-09-11 05:15:03 +07:00
|
|
|
int parse_events_wrap(void *scanner __maybe_unused)
|
2012-03-16 02:09:15 +07:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|