Jump to content

systemwide cpu-limiter for debugging [script, linux only, attached]


Recommended Posts

Hi there,

I’ve written a script that limits the available CPU cores and frequencies to user defined values.

Purpose is simulating a slow CPU for testing multithreading performance/mutex locking behaviour on those systems.

This script temporarily turns your high-performance 12core i7 CPU into a slow single-core or dual-core cpu (or whatever you specify)

by disabling cpu cores and limiting the minimum and maximum frequencies of the remaining cores

Disabling 5/6 cores of a 6-core CPU doesn’t exactly give the performance of a single-core CPU with same clock speed(since the multi-core CPU isn’t designed to run that way) but at least it should give some usable approximation.

The script is designed to run in another terminal window. After changing your system, it waits for the user to say "exit" by pressing [Return], and restores everything to the original values(re-enables disabled CPU cores and restores original min/max clock speeds).

It (temporarily) modifies your system, so it has to be run as root user(so check the script first before running it!)

I’ve written 2 variations:

cpu_limiter.sh is interactive and asks the user for input values. It tells you which values are available on your system and checks if the entered values are valid. (it’s not completely failsafe though)

cpu_limiter_plain.sh requires those values as parameters, calling it without any gives a short usage information and prints the available values on your system. This one does not check anything, but assumes you are calling it with correct/working values!

I tested both versions on my system, they are fully working(otherwise i would not have released it)

(my system: Kubuntu 12.10, AMD Phenom II X6 CPU(6 cores))

But I did NOT test what happens, if you feed the plain version with bad arguments(text strings, negative/very high numbers etc.)… just don’t do that! :wink2:

Download:

cpu_limiter.zip

Plaintext version(in the Spoiler):

  Reveal hidden contents

cpu_limiter.sh:

cpu_limiter_plain.sh

I hope that it will be useful for someone

Link to comment
Share on other sites

  On 13/01/2013 at 1:55 PM, quantumstate said:

Thanks, this sounds useful for testing the threaded stuff. Do you know roughly how dangerous would it be to feed bad values into the script?

I’ve written it for exactly this purpose :wink2:

I’ve tested it:(that happens with my AMD CPU, with vendors it should be the same)

  • you cannot disable cpu 0; trying to do so gives a file-not-found error
  • you cannot use too low values as clock speed; "bad argument"
  • you can use too high values as clock speed; nothing happens, it does not overclock, but simply uses your maximum cpu clock speed
    at least my system monitor told me that, be careful with this one
  • using minimum_frequency>maximum_frequency gives a "bad argument" error

so it should be safe to use, but i recommend using proper values (the script prints them out when calling it without arguments)

other than that:

if you really cut your cpu down, your system will get really slow!

I can reduce my cpu power from 6*2,8GHz to 1*800Mhz. You can feel the effect immediately :wink2:

with 1*800MHz, the rendering in 0ad(latest dev ppa build) completely freezes (but hey, music continues nicely!)

Edited by luziferius
Link to comment
Share on other sites

  On 14/01/2013 at 1:13 PM, luziferius said:
I can reduce my cpu power from 6*2,8GHz to 1*800Mhz. You can feel the effect immediately :wink2:

with 1*800MHz, the rendering in 0ad(latest dev ppa build) completely freezes (but hey, music continues nicely!)

Are you using the latest svn trunk? I was hoping the fixes in there made the music less obtrusive. If you are we can adjust the sleep parameters to tone it down even more.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...