Skip to main content

Make Flash Video Run Smoothly With Ondemand CPU Frequency Scaling

system configuration video flash hardware

Watching streaming video in Linux can be frustrating. The Flash web browser process (npviewer.bin) consumes a lot of processor time and it significantly raises the cpu temperature.

I could live with Flash’s piggishness if it delivered good video. Unfortunately, Flash seems to stutter when you use CPU “on demand” frequency scaling to cut power consumption. On my desktop PC with an AMD BE-2400 dual core, I couldn’t get Firefox in Ubuntu 9.04 (64-bit) to stream an ESPN3 sports broadcast without missing half the action.

I found a good solution in this blog article. The default ondemand scaling threshold in Ubuntu is 95. This means that if your CPU is running at less than full power, it won’t jump to the next speed until it’s 95% busy. By setting a lower threshold than 95, you can force the CPU to scale up under moderate usage. Changing the threshold to a lower value like 40 completely fixed my problem.

I took the commands documented in the article and made the cputhresh script shown below. It pokes the proper values into the processor settings. I run it selectively when I need to watch a Flash broadcast. For example:

  • cputhresh set sets threshold to 40
  • cputhresh set NN sets threshold to NN, where NN is any number between 20 and 95
  • cputhresh reset resets threshold back to 95
!/bin/sh

# cputhresh utility, adapted from:
# http://allredb.wordpress.com/2009/05/07/speed-up-flash-and-firefox-in-ubuntu-jaunty-904
# Sets ondemand cpu threshold lower than default
# in order to scale up CPU to fater speeds when running Flash under Firefox

case "$1" in
    set)
        if [ "$2" ] && [ "$2" -ge 20 ] && [ "$2" -le 95 ]; then
            INDEX="$2"
        else
            INDEX=40
        fi
        for CPU_THRESHOLD in /sys/devices/system/cpu/cpu*/cpufreq/ondemand/up_threshold
        do
            [ -f $CPU_THRESHOLD ] || continue
            echo -n $INDEX > $CPU_THRESHOLD
            cat $CPU_THRESHOLD
        done
        ;;
    reset)
        for CPU_THRESHOLD in /sys/devices/system/cpu/cpu*/cpufreq/ondemand/up_threshold
        do
            [ -f $CPU_THRESHOLD ] || continue
            echo -n 95 > $CPU_THRESHOLD
            cat $CPU_THRESHOLD
        done
        ;;
    show)
        for CPU_THRESHOLD in /sys/devices/system/cpu/cpu*/cpufreq/ondemand/up_threshold
        do
            [ -f $CPU_THRESHOLD ] || continue
            cat $CPU_THRESHOLD
        done
        ;;
    *)
        echo "Usage: $0 set|reset|show" >&2
        exit 3
        ;;
esac

Instead of this script, you could also just switch to using the “performance” frequency scaling setting. However, the advantage of bumping the threshold is that you’re retaining the power saving advantages of ondemand frequency scaling.

Related

Installing a Local DNS Server Behind a Hardware Router
networking router dns hardware sysadmin
There’s not much work to installing and using a typical hardware router.
Firefly: A Music Server For Mixed Marriages
multimedia audio music
For sharing your family’s music collection, it’s hard to beat the simplicity of the Firefly music server.
Tracks: a To-Do List for Getting Things Done
server apps task management
David Allen’s Getting Things Done struck a chord with compulsive organizers as well as people struggling to bring order to their lives.