skip to Main Content

I need this for some stress testing with my CPU. It uses Linux-Debian/Ubuntu OS and I was wondering if there’s any way that I could put it under load until it reaches a certain temperature.

Are there any commands, packages or bash scripts for this?

Any help is appreciated!

2

Answers


  1. Download Prime95 from here or use any other CPU-Stress test that works under Debian/Ubuntu.

    Get the following package:

    sudo apt-get install lm-sensors
    

    Start the sensors in terminal and update continously:

    watch sensors
    

    Now start Prime95 or your preferred stress-test and you can see cpu-temp inside terminal. Stop Stress test if cpu-temp exceeds your desired temperature. (modern cpu’s are lowering clockspeed or shutting down automatically before damage from overheating is taken)

    OR (automatically stopping at a user-specified temp)

    Get the following packages:

    sudo apt-get install lm-sensors
    sudo apt-get install stress
    

    store the following code as bashfile i.e. stresstest.sh and run it with sh /path/to/stresstest.sh

    #!/bin/bash
    sensors=/usr/bin/sensors
    
    read_temp() {
        # get max Packagetemp from lm-sensors
        ${sensors} | grep 'Package' | awk '{print int($4)}'
    }
    
    echo 'Maximum CPU-Temperature:'
    # insert tjMax manually
    read tjMax
    
    echo 'Workers for testing:'
    # more workers cause higher load on the cpu
    read workers
    
    echo 'starting stress-test.'
    
    pckgMax=$( read_temp )
    while [ $tjMax -gt $pckgMax ]
    do
        # update Packagetemp
        pckgMax=$( read_temp )
        # do 10sec stress-test
        # if you discover high temperature overhead, try lowering the --timeout
        stress --cpu ${workers} --timeout 10
    done
    
    echo 'reached tjMax.'
    echo 'stopping stress-test.'
    # kill this script and all running sub-processes
    kill -- -0
    
    Login or Signup to reply.
  2. I don’t know of an existing software package (other than prime95 for max heating), but it’s relatively easy to create loops with differing amounts of heat, like awk 'BEGIN{for(i=0;i<100000000;i++){}}' keeps a CPU busy for a while making some heat.

    See How to write x86 assembly code to check the effect of temperature on the performance of the processor for some suggestions on creating loops that heat the CPU more vs. less.

    To hit a target temperature, you’ll need to write some code to implement control loop that reads the temperature (and the direction it’s trending) and adjusts the load by starting/stopping threads, or changing up how power-intensive each thread is. Without this feedback, you won’t consistently hit a given CPU temperature; the actual temperature for an fixed workload will depend on ambient temp, how dusty your heat-sink is, and how the BIOS manages your fan speeds, etc.

    Perhaps your CPU-heating threads could branch on a global atomic variable in an outer loop, so you can change what work they do by changing a variable. e.g. 2 FMAs per clock, 1 FMA per clock, FMAs bottlenecked by latency (so 1 per 4 clocks), or just integer work, or a loop just running pause instructions, so it does the minimum. Or 256-bit vs. 128-bit vs. scalar.

    Perhaps also changing your EPP setting (on Intel Skylake or newer) with sudo sh -c 'for i in /sys/devices/system/cpu/cpufreq/policy[0-9]*/energy_performance_preference;do echo performance > "$i";done' or balance_performance or balance_power (emphasize power-saving); these may affect what turbo clock speeds your CPU chooses to run at.

    Read the temperature with lm-sensors, or by reading from the "coretemp" kernel driver directly on modern x86 hardware, e.g. /sys/class/hwmon/hwmon3/temp1_input reads as 36000 for 36 degrees C.

    $ grep . /sys/class/hwmon/hwmon3/*
    /sys/class/hwmon/hwmon3/name:coretemp
    
    /sys/class/hwmon/hwmon3/temp1_input:36000
    /sys/class/hwmon/hwmon3/temp1_label:Package id 0
    
    /sys/class/hwmon/hwmon3/temp2_input:35000
    /sys/class/hwmon/hwmon3/temp2_label:Core 0
    
    /sys/class/hwmon/hwmon3/temp5_input:33000
    /sys/class/hwmon/hwmon3/temp5_label:Core 3
    

    I’m not sure if the temperature is available directly to user-space without the kernel’s help, e.g. via CPUID, on Intel or AMD.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search