-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ebpf: Update CPU freq calculation to improve performance #427
Conversation
72173e4
to
13c9ddb
Compare
312f811
to
c911626
Compare
Example of the CPU frequency in the log: For the processes CPU frequency:
For the node CPU frequency
|
the tracepoint doesn't work on my setup. To narrow down the scenarios, @marceloamaral can you try the following and see if you can capture any cpu frequency data? # perf list 'power:cpu_frequency'
List of pre-defined events (to be used in -e):
power:cpu_frequency [Tracepoint event]
# perf record -e power:cpu_frequency -a sleep 10
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 1.943 MB perf.data ]
# perf script |
@marceloamaral Since we have per core CPU cycles reading from PMU, we can convert the cycles into frequency |
@rootfs
I think I cannot see it because this tracing is disabled for perf.
But the BPF code can get the CPU frequency. Can you try to run the code of this PR? |
Yes if we can get the reference cycles. But the limitation of using cycles is that an environment that does not have PMU will not collect the frequency. |
@marceloamaral the frequency is always 0 with the patch on my physical machine [root@rhel kepler]# patch -p1 < 427.diff
patching file bpfassets/perf_event/perf_event.c
patching file pkg/bpfassets/attacher/bcc_attacher.go
patching file pkg/bpfassets/attacher/bcc_attacher_stub.go
patching file pkg/bpfassets/perf_event_bindata.go
patching file pkg/collector/container_hc_collector.go
patching file pkg/collector/metric/container_metric.go
patching file pkg/collector/metric/utils.go
patching file pkg/collector/metric/utils_test.go
patching file pkg/collector/metric_collector.go
patching file pkg/collector/node_energy_collector.go
patching file pkg/collector/prometheus_collector.go
patching file pkg/power/acpi/acpi.go
[root@rhel kepler]# make _build_local
gofmt -e -d -s -l -w pkg/ cmd/
[root@rhel kepler]# echo 1 > /sys/kernel/debug/tracing/events/power/cpu_frequency/enable
[root@rhel kepler]# _output/bin/_/kepler -v 5 2>&1 |grep avg
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00
avgFreq: 0.00 |
@rootfs I found the problem that cpu frequency is 0.
But note that, when the governor policy is set to performance, it does not mean that the cpu frequency does not change.
I will continue investigate how to implement this via BPF |
I figured out how to calculate CPU frequency using hardware counters. There are some differences in the CPU frequency measured by the 3 approaches that we have.
The I will update this PR to use |
1ebd75c
to
74d306a
Compare
@rootfs It finally worked. The main challenge was to add support for hardware counter with multiplexing, the Why do we need to normalize the counters:
Therefore, normalizing here means de-extrapolating the results to expose the actual values. Also note that the documentation suggests always using
|
I have also fixed the cpu time collection.
The old code was updating the cpu time with the func |
tested on my setup, the magnitude of frequency stats looks a bit off
|
74d306a
to
3beead8
Compare
3beead8
to
6cb3b07
Compare
Signed-off-by: Marcelo Amaral <[email protected]>
Signed-off-by: Marcelo Amaral <[email protected]>
Signed-off-by: Marcelo Amaral <[email protected]>
6cb3b07
to
ba931d3
Compare
The frequency is in KHZ, the metrics label needs a update. @marceloamaral would you follow up with another PR? Thanks. |
This PR introduces a 2.4X performance improvement for Kepler regarding the CPU profiling.
We have been discussing the performance regression of Kepler in #365, with further analysis in #391.
The performance analysis showed that garbage collector was the source of the performance degradation.
After some evaluation, we identified that the functions calculating and collection the CPU frequency were some of the most expensive calls.
To improve the performance, this PR first removes the function that calculates the CPU frequency per container and implements it using BPF.
Second, the node CPU frequency is also collected by BPF, but when BPF is not available, Kepler can still collect it by reading kernel files. Although, it is a very expensive operation.
Before the update, the pprof CPU profiling was showing a total of 4.89s of CPU utilization.
After the update, the pprof CPU profiling was showing a total of 1.96s of CPU utilization.
In summary: