History

bpf, trace: fetch current cpu only once

We currently have two invocations, which is unnecessary. Fetch it only once and use the smp_processor_id() variant, so we also get preemption checks along with it when DEBUG_PREEMPT is set.

Daniel Borkmann committed 10 years ago

Commit d7931331 parent 1ca1cc91 file · +3 −2Browse files

Unified · Split

kernel/trace/bpf_trace.c+3−2
@@ -233,6 +233,7 @@ static u64 bpf_perf_event_output(u64 r1, u64 r2, u64 flags, u64 r4, u64 size) · 232 unmodified lines
233 struct pt_regs *regs = (struct pt_regs *) (long) r1;233 struct pt_regs *regs = (struct pt_regs *) (long) r1;
234 struct bpf_map *map = (struct bpf_map *) (long) r2;234 struct bpf_map *map = (struct bpf_map *) (long) r2;
235 struct bpf_array *array = container_of(map, struct bpf_array, map);235 struct bpf_array *array = container_of(map, struct bpf_array, map);
236 unsigned int cpu = smp_processor_id();
236 u64 index = flags & BPF_F_INDEX_MASK;237 u64 index = flags & BPF_F_INDEX_MASK;
237 void *data = (void *) (long) r4;238 void *data = (void *) (long) r4;
238 struct perf_sample_data sample_data;239 struct perf_sample_data sample_data;
@@ -246,7 +247,7 @@ static u64 bpf_perf_event_output(u64 r1, u64 r2, u64 flags, u64 r4, u64 size) · 7 unmodified lines
246 if (unlikely(flags & ~(BPF_F_INDEX_MASK)))247 if (unlikely(flags & ~(BPF_F_INDEX_MASK)))
247 return -EINVAL;248 return -EINVAL;
248 if (index == BPF_F_CURRENT_CPU)249 if (index == BPF_F_CURRENT_CPU)
249 index = raw_smp_processor_id();250 index = cpu;
250 if (unlikely(index >= array->map.max_entries))251 if (unlikely(index >= array->map.max_entries))
251 return -E2BIG;252 return -E2BIG;
252 253
@@ -259,7 +260,7 @@ static u64 bpf_perf_event_output(u64 r1, u64 r2, u64 flags, u64 r4, u64 size) · 6 unmodified lines
259 event->attr.config != PERF_COUNT_SW_BPF_OUTPUT))260 event->attr.config != PERF_COUNT_SW_BPF_OUTPUT))
260 return -EINVAL;261 return -EINVAL;
261 262
262 if (unlikely(event->oncpu != smp_processor_id()))263 if (unlikely(event->oncpu != cpu))
263 return -EOPNOTSUPP;264 return -EOPNOTSUPP;
264 265
265 perf_sample_data_init(&sample_data, 0, 0);266 perf_sample_data_init(&sample_data, 0, 0);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t