cpuinfo icon indicating copy to clipboard operation
cpuinfo copied to clipboard

cache cpu info in a file at boot.

Open bunnitha opened this issue 1 year ago • 12 comments

Instrumented cpuinfo to read the populated cpu info data from cpuid.info file during initialization. Consumers of the library or OEMs can trigger a oneshot service - cpuinfo-svc - during device boot to link libcpuinfo and dump all cpu info related to processor, model, arch and isa capabilities into cpuid.info file. This arrangement will limit cpuid() intrinsic calls (which causes VMX events and performance overhead) to only once during init of libcpuinfo at boot by cpuinfo-svc.

Its little tricky to count the exact number of VM-Exits caused by CPUID calls. For this effect, we have written a script to run an Android (dummy) service that loads libcpuinfo - first in original version and next in modified version. libcpuinfo makes around 4 __cpuid() calls on each initialization. So, to amplify the effect, we have run the dummy service 1000 times and timed the total execution (4000 __cpuid() calls and 8000 VMX events) in nano second precision. This test shows that there is a reduction of approx. 0.6% in time to execute libcpuinfo.

Also, we attempted to record the KVM event statistics using perf tool. Perf records the stats during the execution of same script. The data shows that approx. 20,000 kvm_cpuid events reduced in modified libcpuinfo calls. We cannot assume that all the CPUID calls are contributed by our script. We are only making a safe assumption that the proportional reduction is affected by the modification we did. We had made all efforts to keep the test conditions similar in both cases.

Please find attached the excel sheet containing the test data. libcpuinfo_enhancement_test_data.xlsx

bunnitha avatar Sep 19 '24 08:09 bunnitha