@@ -227,6 +227,7 @@ enum hist_field_flags {
227
227
HIST_FIELD_FL_VAR = 1 << 12 ,
228
228
HIST_FIELD_FL_EXPR = 1 << 13 ,
229
229
HIST_FIELD_FL_VAR_REF = 1 << 14 ,
230
+ HIST_FIELD_FL_CPU = 1 << 15 ,
230
231
};
231
232
232
233
struct var_defs {
@@ -1164,6 +1165,16 @@ static u64 hist_field_timestamp(struct hist_field *hist_field,
1164
1165
return ts ;
1165
1166
}
1166
1167
1168
+ static u64 hist_field_cpu (struct hist_field * hist_field ,
1169
+ struct tracing_map_elt * elt ,
1170
+ struct ring_buffer_event * rbe ,
1171
+ void * event )
1172
+ {
1173
+ int cpu = smp_processor_id ();
1174
+
1175
+ return cpu ;
1176
+ }
1177
+
1167
1178
static struct hist_field *
1168
1179
check_field_for_var_ref (struct hist_field * hist_field ,
1169
1180
struct hist_trigger_data * var_data ,
@@ -1602,6 +1613,8 @@ static const char *hist_field_name(struct hist_field *field,
1602
1613
field_name = hist_field_name (field -> operands [0 ], ++ level );
1603
1614
else if (field -> flags & HIST_FIELD_FL_TIMESTAMP )
1604
1615
field_name = "common_timestamp" ;
1616
+ else if (field -> flags & HIST_FIELD_FL_CPU )
1617
+ field_name = "cpu" ;
1605
1618
else if (field -> flags & HIST_FIELD_FL_EXPR ||
1606
1619
field -> flags & HIST_FIELD_FL_VAR_REF ) {
1607
1620
if (field -> system ) {
@@ -2109,6 +2122,15 @@ static struct hist_field *create_hist_field(struct hist_trigger_data *hist_data,
2109
2122
goto out ;
2110
2123
}
2111
2124
2125
+ if (flags & HIST_FIELD_FL_CPU ) {
2126
+ hist_field -> fn = hist_field_cpu ;
2127
+ hist_field -> size = sizeof (int );
2128
+ hist_field -> type = kstrdup ("unsigned int" , GFP_KERNEL );
2129
+ if (!hist_field -> type )
2130
+ goto free ;
2131
+ goto out ;
2132
+ }
2133
+
2112
2134
if (WARN_ON_ONCE (!field ))
2113
2135
goto out ;
2114
2136
@@ -2345,7 +2367,9 @@ parse_field(struct hist_trigger_data *hist_data, struct trace_event_file *file,
2345
2367
hist_data -> enable_timestamps = true;
2346
2368
if (* flags & HIST_FIELD_FL_TIMESTAMP_USECS )
2347
2369
hist_data -> attrs -> ts_in_usecs = true;
2348
- } else {
2370
+ } else if (strcmp (field_name , "cpu" ) == 0 )
2371
+ * flags |= HIST_FIELD_FL_CPU ;
2372
+ else {
2349
2373
field = trace_find_event_field (file -> event_call , field_name );
2350
2374
if (!field || !field -> size ) {
2351
2375
field = ERR_PTR (- EINVAL );
@@ -4619,6 +4643,8 @@ static void hist_field_print(struct seq_file *m, struct hist_field *hist_field)
4619
4643
4620
4644
if (hist_field -> flags & HIST_FIELD_FL_TIMESTAMP )
4621
4645
seq_puts (m , "common_timestamp" );
4646
+ else if (hist_field -> flags & HIST_FIELD_FL_CPU )
4647
+ seq_puts (m , "cpu" );
4622
4648
else if (field_name ) {
4623
4649
if (hist_field -> flags & HIST_FIELD_FL_VAR_REF )
4624
4650
seq_putc (m , '$' );
0 commit comments