Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | %option prefix="perf_bpf_filter_" %option noyywrap %{ #include <stdio.h> #include <stdlib.h> #include <linux/perf_event.h> #include "bpf-filter.h" #include "bpf-filter-bison.h" static int sample(unsigned long sample_flag) { perf_bpf_filter_lval.sample.type = sample_flag; perf_bpf_filter_lval.sample.part = 0; return BFT_SAMPLE; } static int sample_part(unsigned long sample_flag, int part) { perf_bpf_filter_lval.sample.type = sample_flag; perf_bpf_filter_lval.sample.part = part; return BFT_SAMPLE; } static int operator(enum perf_bpf_filter_op op) { perf_bpf_filter_lval.op = op; return BFT_OP; } static int value(int base) { long num; errno = 0; num = strtoul(perf_bpf_filter_text, NULL, base); if (errno) return BFT_ERROR; perf_bpf_filter_lval.num = num; return BFT_NUM; } static int constant(int val) { perf_bpf_filter_lval.num = val; return BFT_NUM; } static int error(const char *str) { printf("perf_bpf_filter: Unexpected filter %s: %s\n", str, perf_bpf_filter_text); return BFT_ERROR; } %} num_dec [0-9]+ num_hex 0[Xx][0-9a-fA-F]+ space [ \t]+ ident [_a-zA-Z][_a-zA-Z0-9]+ %% {num_dec} { return value(10); } {num_hex} { return value(16); } {space} { } ip { return sample(PERF_SAMPLE_IP); } id { return sample(PERF_SAMPLE_ID); } tid { return sample(PERF_SAMPLE_TID); } pid { return sample_part(PERF_SAMPLE_TID, 1); } cpu { return sample(PERF_SAMPLE_CPU); } time { return sample(PERF_SAMPLE_TIME); } addr { return sample(PERF_SAMPLE_ADDR); } period { return sample(PERF_SAMPLE_PERIOD); } txn { return sample(PERF_SAMPLE_TRANSACTION); } weight { return sample(PERF_SAMPLE_WEIGHT); } weight1 { return sample_part(PERF_SAMPLE_WEIGHT_STRUCT, 1); } weight2 { return sample_part(PERF_SAMPLE_WEIGHT_STRUCT, 2); } weight3 { return sample_part(PERF_SAMPLE_WEIGHT_STRUCT, 3); } ins_lat { return sample_part(PERF_SAMPLE_WEIGHT_STRUCT, 2); } /* alias for weight2 */ p_stage_cyc { return sample_part(PERF_SAMPLE_WEIGHT_STRUCT, 3); } /* alias for weight3 */ retire_lat { return sample_part(PERF_SAMPLE_WEIGHT_STRUCT, 3); } /* alias for weight3 */ phys_addr { return sample(PERF_SAMPLE_PHYS_ADDR); } code_pgsz { return sample(PERF_SAMPLE_CODE_PAGE_SIZE); } data_pgsz { return sample(PERF_SAMPLE_DATA_PAGE_SIZE); } mem_op { return sample_part(PERF_SAMPLE_DATA_SRC, 1); } mem_lvlnum { return sample_part(PERF_SAMPLE_DATA_SRC, 2); } mem_lvl { return sample_part(PERF_SAMPLE_DATA_SRC, 2); } /* alias for mem_lvlnum */ mem_snoop { return sample_part(PERF_SAMPLE_DATA_SRC, 3); } /* include snoopx */ mem_remote { return sample_part(PERF_SAMPLE_DATA_SRC, 4); } mem_lock { return sample_part(PERF_SAMPLE_DATA_SRC, 5); } mem_dtlb { return sample_part(PERF_SAMPLE_DATA_SRC, 6); } mem_blk { return sample_part(PERF_SAMPLE_DATA_SRC, 7); } mem_hops { return sample_part(PERF_SAMPLE_DATA_SRC, 8); } "==" { return operator(PBF_OP_EQ); } "!=" { return operator(PBF_OP_NEQ); } ">" { return operator(PBF_OP_GT); } "<" { return operator(PBF_OP_LT); } ">=" { return operator(PBF_OP_GE); } "<=" { return operator(PBF_OP_LE); } "&" { return operator(PBF_OP_AND); } na { return constant(PERF_MEM_OP_NA); } load { return constant(PERF_MEM_OP_LOAD); } store { return constant(PERF_MEM_OP_STORE); } pfetch { return constant(PERF_MEM_OP_PFETCH); } exec { return constant(PERF_MEM_OP_EXEC); } l1 { return constant(PERF_MEM_LVLNUM_L1); } l2 { return constant(PERF_MEM_LVLNUM_L2); } l3 { return constant(PERF_MEM_LVLNUM_L3); } l4 { return constant(PERF_MEM_LVLNUM_L4); } cxl { return constant(PERF_MEM_LVLNUM_CXL); } io { return constant(PERF_MEM_LVLNUM_IO); } any_cache { return constant(PERF_MEM_LVLNUM_ANY_CACHE); } lfb { return constant(PERF_MEM_LVLNUM_LFB); } ram { return constant(PERF_MEM_LVLNUM_RAM); } pmem { return constant(PERF_MEM_LVLNUM_PMEM); } none { return constant(PERF_MEM_SNOOP_NONE); } hit { return constant(PERF_MEM_SNOOP_HIT); } miss { return constant(PERF_MEM_SNOOP_MISS); } hitm { return constant(PERF_MEM_SNOOP_HITM); } fwd { return constant(PERF_MEM_SNOOPX_FWD); } peer { return constant(PERF_MEM_SNOOPX_PEER); } remote { return constant(PERF_MEM_REMOTE_REMOTE); } locked { return constant(PERF_MEM_LOCK_LOCKED); } l1_hit { return constant(PERF_MEM_TLB_L1 | PERF_MEM_TLB_HIT); } l1_miss { return constant(PERF_MEM_TLB_L1 | PERF_MEM_TLB_MISS); } l2_hit { return constant(PERF_MEM_TLB_L2 | PERF_MEM_TLB_HIT); } l2_miss { return constant(PERF_MEM_TLB_L2 | PERF_MEM_TLB_MISS); } any_hit { return constant(PERF_MEM_TLB_HIT); } any_miss { return constant(PERF_MEM_TLB_MISS); } walk { return constant(PERF_MEM_TLB_WK); } os { return constant(PERF_MEM_TLB_OS); } fault { return constant(PERF_MEM_TLB_OS); } /* alias for os */ by_data { return constant(PERF_MEM_BLK_DATA); } by_addr { return constant(PERF_MEM_BLK_ADDR); } hops0 { return constant(PERF_MEM_HOPS_0); } hops1 { return constant(PERF_MEM_HOPS_1); } hops2 { return constant(PERF_MEM_HOPS_2); } hops3 { return constant(PERF_MEM_HOPS_3); } "," { return ','; } "||" { return BFT_LOGICAL_OR; } {ident} { return error("ident"); } . { return error("input"); } %% |