EDIT: Ubuntu (mate) 20.04, intel_pstate driver. Computer is I am using a razer blade stealth ultrabook (early 2019), with intel core i7 i7-8565U.
I am encountering odd behavior (extreme slowdown) while on battery power only, even when I have set TLP to AC mode. The problem is made much worse if I set cpufrequtils to performance mode (espeically if I multithread)!
We'll start with the single threaded case (i.e. only main thread). I am running a cascade of OPENCV filters (Gaussian blurs etc.) on video frames from file or from webcam. It does not matter if I load all the frames into memory first (i.e. it's not disk or device I/O problem). Below are listed the processing time for a single loop (one frame). This is not complex code. Basically, it is doing:
Filter filters[400]
while( cap.read(frame) )
{
for( int i=0; i<400; ++i )
{
filters[i].dofilter(frame);
}
}
where filters[i].dofilter is just call to e.g. cv::GaussianBlur, resize(), etc, with the destination cv::Mat pre-allocated (I am not doing any additional allocations)
This is using CPU only (i.e. it's not using OPENCV transparent openCL or anything).
SINGLE THREAD
AC + powersave: 71 msec (variance 70.5-71.5)
AC + performance: 67 msec (variance 66.5-67.5)
BAT + powersave: 95 msec (variance 84.0-115.0) *1
BAT + performance: 104 msec (variance 76.0-202.0) *2
1* Note: spikes to 110+ about every 5 sec
2* Note: most ~96, with few spikes low to 80s and high to 120s
Method: 10 runs of each condition for 60 seconds (about 600 frames each times 10 runs = 6000), randomly ordered (so that heat, battery voltage, etc. does not confound).
I use the same input frame for every loop (in other words, it is not due to different image content that it is processing each time). It is literally processing the exact same input every time step. I can see the per-frame processing times change immediately if I unplug or plug in the AC adapter or set powersave/performance using cpufrequtils.
I am at a complete loss.
I am using a razer blade stealth ultrabook, with intel core i7 i7-8565U. Ubuntu (mate) 20.04, intel_pstate driver.
So, I have 3 specific questions:
1) What the hell is happening?
2) How to set TLP (kernel params?) to force it to behave as if on AC (surely the battery can provide enough to run a cpu/memory bound single-core program as fast as it does when on AC)? It's not even doing that much!
3) Is there any secret/weird settings that happen on battery power. Especially relating to multithreading? The problem is highly parallelizable -- there are basically 8 independent chains of filters that I can run in parallel. Usually I do this. When I do this on AC it goes like this:
MULTITHREAD (8 threads)
AC + powersave: 28.6 msec (variance 26.8-31.1)
AC + performance: 28.8 msec (variance 26.6-31.2)
BAT + powersave: 39 msec (variance 36.0-64.0) *3
BAT + performance: 176 msec (variance 39.0-202.0) *4
3* Note: this is very tame compared to if I run with webcam -- then it spikes heavily between 40 and 90
4* Note: will update at 40 msec for a few frames, then go to 180 msec for a long time, then burst at 40 for a few.
The software is multithreaded via a thread pool. I have checked the locking, and no time is spent waiting for locks even in the extreme multithreaded case (this is actually where I spent the most time because I thought it was the issue originally...). I get similar results with 2~8 threads. Gets slower on battery with more threads (especially in performance mode), and faster on AC with more threads.
EDIT: problem happens even if I disable TLP. I have not tried switching to old acpi frequency governer yet (think that would work?)
EDIT 2: When in single thread mode, htop shows only a single CPU core pegged (i.e. it is not using openmp or something to vectorize and use more cores).