You are not logged in.

#1 2011-03-29 16:03:23

masteryod
Member
Registered: 2010-05-19
Posts: 433

bash script to slow down cpu for old game

hi, I'm trying to play some old windows game via wine, with default cpu frequency the game is to fast, If i set frequency around 1GHz game acts as it should, so I want to make desktop shortcut to automate process and I doesn't really know how to write script that will set lower cpu frequency and launch the game and after quiting the game it will reset the cpu policy.... any help is appreciate

sorry for my english wink

Offline

#2 2011-03-29 17:11:57

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: bash script to slow down cpu for old game

Offline

#3 2011-03-30 12:44:23

masteryod
Member
Registered: 2010-05-19
Posts: 433

Re: bash script to slow down cpu for old game

Thanks but schedtool with CPUSPEED option seems not to work (there is no such thing in its man page) ;/
But game definitly work well with cpu frequency set to 1GHZ, is there other tool to set cpu frequency than cpufreq-util? If not I could use some script but im to lame in bash to write myself, it would go something like that

sudo cpufreq-set -f 1000MHz
wine mygame.exe
if game ends set default governor/performance   <- don't know how to achieve this step

Offline

#4 2011-03-30 17:11:05

Arpione
Member
From: Pécs, Hungary
Registered: 2010-09-13
Posts: 31

Re: bash script to slow down cpu for old game

How many cores does your CPU have? I had similar problems under Windows on a dualcore laptop. I used a program which limits the game to 1 core. On Arch you can disable the cores by running

echo 0 > /sys/devices/system/cpu/cpuX/online

(replace X with number) as root for all cores except cpu0. To enable them run

echo 1 > /sys/devices/system/cpu/cpuX/online

Offline

#5 2011-03-30 23:04:20

dodo3773
Member
Registered: 2011-03-17
Posts: 814

Re: bash script to slow down cpu for old game

masteryod wrote:

Thanks but schedtool with CPUSPEED option seems not to work (there is no such thing in its man page) ;/
But game definitly work well with cpu frequency set to 1GHZ, is there other tool to set cpu frequency than cpufreq-util? If not I could use some script but im to lame in bash to write myself, it would go something like that

sudo cpufreq-set -f 1000MHz
wine mygame.exe
if game ends set default governor/performance   <- don't know how to achieve this step

If the process name is "cpufreq" (check your System Monitor, top, pstree, etc.. ) and cpufreq is system wide then it should look something like this

#! /bin/bash

sudo cpufreq-set -f 1000MHz &
wine mygame.exe &&
pkill cpufreq

exit

As long as killing the cpufreq process restores the original speed of your cpu it should work. Let me know.

Offline

#6 2011-03-30 23:12:40

masteryod
Member
Registered: 2010-05-19
Posts: 433

Re: bash script to slow down cpu for old game

https://wiki.archlinux.org/index.php/CP … cy_Scaling

cpufreq is more like a "switch" so it have to be "pressed" to change cpu policy, killing it won't help

Offline

#7 2011-03-30 23:26:58

dodo3773
Member
Registered: 2011-03-17
Posts: 814

Re: bash script to slow down cpu for old game

masteryod wrote:

https://wiki.archlinux.org/index.php/CP … cy_Scaling

cpufreq is more like a "switch" so it have to be "pressed" to change cpu policy, killing it won't help

So, how do you switch it back to default? Would you have to "sudo cpufreq-set -f defaultvalueMHz" to get back to where you want? Are you sure that killing the process will not take your cpu speed back to where it was?

Offline

#8 2011-03-31 13:39:15

masteryod
Member
Registered: 2010-05-19
Posts: 433

Re: bash script to slow down cpu for old game

dodo3773 wrote:

So, how do you switch it back to default? Would you have to "sudo cpufreq-set -f defaultvalueMHz" to get back to where you want? Are you sure that killing the process will not take your cpu speed back to where it was?

Yep, something like that, usualy I use performance or powersave governor e.g. cpufreq-set -g performance

Case can be closed if noone have idea how to write that script, I was trying to make linux based pc for my two nephews (web & games) but as long as there are some great native games for linux it's just pain in the ass or most of the cases undoable to play new windows-only titles (and there is also matter of graphic drivers performance...) so they are stuck with "windblows" for now, personaly don't mind to change cpu policy before some gaming so script is not necessary for me wink

thanks for help anyway Archers

Last edited by masteryod (2011-03-31 13:39:32)

Offline

#9 2011-03-31 15:02:31

redden0t8
Member
Registered: 2011-01-27
Posts: 42

Re: bash script to slow down cpu for old game

A quick tutorial on setting CPU frequency:
Any commands starting with $ can be run by any user, ones starting with a # must be done as root

To check your current governor:
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

To change your governor to allow manual frequency setting:
# echo "userspace" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

To check your current frequency:
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq

To check what frequency your processor allows:
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies

To set a frequency:
# echo "1000" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
of course, replace 1000 with the frequency you want!

To restore your previous governor:
# echo "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
of course, replace ondemand with the governor you were originally running!

There is no need to restore the original frequency, the governor will take care of that.

If you're using cpufrequtils, on the other hand, it will interfere with the above and you'll have to disable it first
# /etc/rc.d/cpufreq stop

Then when done, re-enable it again
# /etc/rc.d/cpufreq start

A sample shell script without cpufrequtils:

#!/bin/sh
echo "userspace" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo "1000" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
su -c "[i]command to launch your game[/i]" [i]username[/i]
echo "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

A sample shell script with cpufrequtils:

#!/bin/sh
/etc/rc.d/cpufreq stop
echo "1000" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
su -c "[i]command to launch your game[/i]" [i]username[/i]
/etc/rc.d/cpufreq start

Both need to be run as root.

Warning 1: I haven't had the chance to test either script, but in principle they should work.
Warning 2: Both scripts assume your game doesn't disconnect itself from the terminal.  If it does, you'll need to split the scripts into two (one to slow down the cpu, another to speed it up).

If the above works for you, it is possible to make it more convenient using sudo.

Offline

Board footer

Powered by FluxBB