Any experience with using cpupower in a script?

This post is about my debating if I should use ‘cpupower’ in a script.

I have a bash shell script that stabilizes video files using FFmpeg’s vidstab filters and creates a side-by-side comparison with the original video. It does this in 3 phases.

  • Phase-1: uses ffmpeg’s vidstabdetect (which I have attempted to tmpfs optimize) to create vector movement files from frame to frame. This is very CPU intensive. It saves the vector file for use in the next phase.

  • Phase-2: creates (with ffmpeg) a stabilized video using vidstabtransform with the vector file (tmpfs optimized). This is more GPU intensive. It saves the stabilized video in this phase.

  • Phase-3. creates side-by-side comparison of original and stabilized videos. This is GPU intensive.

I previously sped up Phase-2 and Phase-3 a lot with Intel’s qsv … and to a lessor extent for phase-1 and phase-2 use of tmpfs. :+1:

However I am still (to a small extent - lol ! :rofl: ) able to learn new things, and today on my LEAP-15.6 PC I observed an update for an app called cpupower.

Now , I have a ‘resolution’ for openSUSE self improvement, that i am trying to follow, which is every time I have a software update, I try to research a small amount the app being updated, so I can learn more.

Naturally, I was curious about cpupower.

I read the ‘performance’ setting of cpupower ‘might’ speed up performance (although I suspect if it heats up my PC’s CPU too much, it won’t do anything as the PC firmware (?) will slow down the CPU to reduce high temperatures). Still, I am thinking it may be worth a shot to try for phase-1 (only) where the CPU is the processing bottleneck.

So I am considering, maybe to test, at the start of phase-1 of the script, sending the command (which will require me to enter the root password):

sudo cpupower frequency-set -g performance

and then at the end of phase-1, the CPU phase, send the command (to go back to default):

sudo cpupower frequency-set -g powersave

The script will need to prompt me for a password at the appropriate time.

I thought to post this idea here, in case any on our forum have experience with cpupower in other contexts, that would suggest such is a good idea, bad idea, or something curious to try and simply test vs different length videos (where some of my videos to stabilize are only 10 to 20 seconds and others are a few minutes long).

Just as tips:

  • use some git service for easier development
  • Write functions to get file(s), command parameter values, the root password etc
  • Call the functions from the script as needed, this per phase
  • Use zenity or kdialog for user interaction with the script.

As an example, that includes asking for root password when required: Files · master · Gertjan Lettink a.k.a. Knurpht / pihole-installer · GitLab

EDIT: Consider the link as just some template for bash + zenity. After giving it the right permissions, creating a .desktop file, you can use script from the desktop

I did a quick check, and as I thought might be the case, running with cpupower set to performance is actually slower than cpupower set to powersave.

The ‘powersave’, when running a cpu intensive process (ffmpeg to create the frame-by-frame vector files to stabilize a video) is by about .75 seconds faster for a ~96 second processing time. ie about 0.8% faster than the ‘performance’.

I ran this test on a rather old Intel Core i7-4770 cpu PC (running LEAP-15.6) that has Intel Xeon E3-1200 v3/4th Gen Core Processor Integrated Graphics. However as noted, phase one is CPU intensive and does not access the GPU.

Results of my test (where I ran a script to stabilize the identical video). This is only the results of the 1st phase. I did not test the 2nd nor third.

So first I ran my script with default (after a fresh boot) settings (but stopped the processing after the 1st phase):

This is with the default boot settings for the PC’s CPU.

DEFAULT
==========
FFmpeg Video Stabilization Timing Report - Fri Sep  5 04:59:31 PM +07 2025
Input file: DSCN0291.mp4
Output basename: DSCN0291
tmpfs optimization: ENABLED (/dev/shm/videostab_/dev/shm1757066371)
=========================================
Phase 1 (Create vector movement file): 95.801005576 seconds

compare the above (default settings on my LEAP-15.6 desktop) to ‘performance’ setting (ie I sent the command):

sudo cpupower frequency-set -g performance

and that gave this for performance setting

FFmpeg Video Stabilization Timing Report - Fri Sep  5 05:03:17 PM +07 2025
Input file: DSCN0291.mp4
Output basename: DSCN0291
tmpfs optimization: ENABLED (/dev/shm/videostab_/dev/shm1757066597)
=========================================
Phase 1 (Create vector movement file): 96.559895247 seconds

and just to double check I sent this command:

sudo cpupower frequency-set -g powersave

and obtained this output for powersave settings:

FFmpeg Video Stabilization Timing Report - Fri Sep  5 05:11:31 PM +07 2025
Input file: DSCN0291.mp4
Output basename: DSCN0291
tmpfs optimization: ENABLED (/dev/shm/videostab_/dev/shm1757067091)
=========================================
Phase 1 (Create vector movement file): 95.485962306 seconds

So it takes 95.485962306 seconds seconds to generate the frame by frame vector files for the video when in ‘powersave’ compared to taking 96.559895247 seconds in ‘performance’.

Maybe my desktop needs better cooling !! but its so very very old, its not long for this world. I use my newer faster laptop PC most of the time.

Speaking of which, I may repeat this test on my much newer laptop.
.

@oldcpu Tuned and profiles would be better?

When I used Conky I would use cpupower and Mperf data to get the CPU frequency.

1 Like

I played with cpupower on my Lenovo X1 Carbon Generation-9 laptop, which has

  • an SSD and a 11th Gen Intel Core i7-1165G7 cpu
  • w/Intel TigerLake-LP GT2 - Iris Xe Graphics.
  • an SSD which is a Samsung PM9A1 (OEM) with almost identical specs to a retail Samsung 980 PRO (the PM91A is a bit slower in write speed of ~850K vs ~1000K of the 980 PRO)

The test on my laptop was with a 15-second video of a speed boat bouncing up and down in the water (very far away, zoomed in with my Nikon CoolPix P950 camera) as seen from my condo balcony. The video resolution is 3840x2160 30fps video, which is fairly high, and that explains the relatively slow frames per second processing speed.

For this test, I had one setting applied for all three phases of the script. Recall:

  1. phase-1 is CPU intensive (creates vector files)
  2. phase-2 is GPU intensive (creates stabilized video)
  3. phase-3 is a bit of a mix, much more GPU intensive than CPU (compares the videos), where it uses lots of read/write to the SSD

For phase-2 and 3, where applicable ‘qsv’ functionality using the TigerLake GPU is used.

The test 15-second video is a pretty short video, but given the processing speeds varied by 3 fps to 6 fps, each test run takes a bit of time to process with the script - so it takes some time (and I don’t want to use my PC while the test is running).

Still I may retry this test with a much longer video to confirm the results. And I may < unsure > create a version of the script that changes cpupower between powersave and performance.

Here is the timing with powersave applied to cpupower (I summarize below so no need to dive into it in detail):

FFmpeg Video Stabilization Timing Report - Sat Sep  6 10:33:54 AM +07 2025
Input file: DSCN0291.mp4
Output basename: DSCN0291
tmpfs optimization: ENABLED (/dev/shm/videostab_/dev/shm1757129634)
=========================================
Phase 1 (Create vector movement file): 85.592151683 seconds
Phase 2 (Stabilize video): 96.251811204 seconds
Phase 3 (Create side-by-side comparison): 12.372959698 seconds
=========================================
Total processing time: 194.216922585 seconds

and here is the timing with performance setting applied to cpupower (again - I summarize below so no need to dive into it in detail): :

FFmpeg Video Stabilization Timing Report - Sat Sep  6 10:39:10 AM +07 2025
Input file: DSCN0291.mp4
Output basename: DSCN0291
tmpfs optimization: ENABLED (/dev/shm/videostab_/dev/shm1757129950)
=========================================
Phase 1 (Create vector movement file): 83.077026295 seconds
Phase 2 (Stabilize video): 103.577754561 seconds
Phase 3 (Create side-by-side comparison): 12.725946825 seconds
=========================================
Total processing time: 199.380727681 seconds

The results were interesting to me.

With this laptop, overall, using performance was slower overall than powersave. Except for the CPU intensive part were ‘performance’ was slightly faster. When the ffmpeg processing started using the GPU extensively, ‘powersave’ was better.

  • phase-1 : ‘powersave’ 85.6 seconds vs 83.1 seconds for ‘performance’
  • phase-2 : ‘powersave’ 96.3 seconds vs 103.6 seconds for ‘performance’
  • phase-3 : ‘powersave’ 12.37 seconds vs 12.72 secconds for ‘performance’
  • OVERALL : ‘powersave’ 194.2 seconds vs 199.4 seconds for ‘performance’

So that suggests there may be a benefit for me tuning my script, to apply ‘performance’ for phase-1, but revert to ‘powersave’ for phase-3.

One thing I found that was ‘tricky’ to spot in the output, was when sending a command (to assess which setting is in place) was I could not initially spot where it stated which cpupower setting was applied.

Note for “performance” setting:


oldcpu@lenovo:~/Pictures/july/2025-07-03> cpupower frequency-info
analyzing CPU 4:
  driver: intel_pstate
  CPUs which run at the same hardware frequency: 4
  CPUs which need to have their frequency coordinated by software: 4
  maximum transition latency:  Cannot determine or is not supported.
  hardware limits: 400 MHz - 4.70 GHz
  available cpufreq governors: performance powersave
  current policy: frequency should be within 400 MHz and 4.70 GHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
  current CPU frequency: Unable to call hardware
  current CPU frequency: 400 MHz (asserted by call to kernel)
  boost state support:
    Supported: yes
    Active: yes
oldcpu@lenovo:~/Pictures/july/2025-07-03>

Eventually I spotted the line:
The governor "powersave" may decide which speed to use
… ie 'powersave is applied.

Now compare that to the entry with Performance in place:

oldcpu@lenovo:~/Pictures/july/2025-07-03> cpupower frequency-info
analyzing CPU 0:
  driver: intel_pstate
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency:  Cannot determine or is not supported.
  hardware limits: 400 MHz - 4.70 GHz
  available cpufreq governors: performance powersave
  current policy: frequency should be within 400 MHz and 4.70 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency: Unable to call hardware
  current CPU frequency: 400 MHz (asserted by call to kernel)
  boost state support:
    Supported: yes
    Active: yes
oldcpu@lenovo:~/Pictures/july/2025-07-03>

Note in particular the line:
The governor "performance" may decide which speed to use
i.e. ‘performance’ setting is applied.

i missed that at first when looking for what was the setting !!

But later i found an easier way to check:

First with performance setting applied:

oldcpu@lenovo:~/Pictures/july/2025-07-03> cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
performance
performance
performance
performance
performance
performance
performance
performance
oldcpu@lenovo:~/Pictures/july/2025-07-03>

and then next with powersave setting applied:

oldcpu@lenovo:~/Pictures/july/2025-07-03> cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
powersave
powersave
powersave
powersave
powersave
powersave
powersave
powersave
oldcpu@lenovo:~/Pictures/july/2025-07-03>

I likely will first test against a very long video, before I go changing my script.
.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.