2

Newbie here. I have a Dell Inspiron 3442 who suffers from the "CPU stuck at 800Mhz" problem. In Windows, I used to run ThrottleStop at every startup and disable BD PROCHOT... So I installed Ubuntu recently and learned to solve this problem with a set of commands in this answer:

https://askubuntu.com/a/1192949/1053161

Which are :

sudo cpufreq-set -c 0 -g performance
sudo cpufreq-set -c 1 -g performance
sudo cpufreq-set -c 2 -g performance
sudo cpufreq-set -c 3 -g performance
sudo modprobe msr
sudo wrmsr 0x1FC 17422

These completely solved my problem. Now I want to make a script that could be run automatically on startup / after login. What is the easiest way to accomplish this?

Thanks in advance!

Arthur Tabbal
  • 113
  • 2
  • 6
  • Welcome to AskUbuntu, you are very close to find the way. https://askubuntu.com/questions/1214255/startup-auto-execution-bash-script – Sadaharu Wakisaka Mar 13 '20 at 03:36
  • Thanks, guys! I found a couple of solutions but i'm not entirely sure which one is right in my case... I guess i'll have to try the one that looks simpler. Should I delete this question? – Arthur Tabbal Mar 13 '20 at 04:19
  • That's good to see a solution for the throttling issue. I had a dell and there was a problem with throttling when the laptop was unplugged and running on battery. I think there was a BIOS setting to prevent this. Also, I had to use a fully functioning Dell brand power adapter. The computer would throttle when a broken or off-brand power adapter was plugged in. – mchid Mar 13 '20 at 05:32

1 Answers1

3

Script should look like:

#!/bin/sh

# Prevent unset variable problems
set -u

# Change CPU setting
cpufreq-set -c 0 -g performance
cpufreq-set -c 1 -g performance
cpufreq-set -c 2 -g performance
cpufreq-set -c 3 -g performance
modprobe msr
wrmsr 0x1FC 17422

Save the script somewhere: /Path/to/script.sh

Open the root crontab using:

# crontab -u root -e

In it, add these lines:

# Set CPU frequency on reboot
@reboot /Path/to/script.sh

Save and exit.

Hope that helps!

jdrch
  • 110
  • 11
  • 2
    Two suggestions: using the full path for the executable `cpufreq` in scripts is good practice and can avoid problems; and `/opt/` is a good place to put scripts. – Kurankat Mar 13 '20 at 05:23
  • Ok, so I tried this method with the suggestions by @Kurankat. Oddly enough, I had to erase the full path and leave just `cpufreq` for the script to work on it's own. But it is as `/opt/` . So now the script works, but it's not running on reboot. I believe this has to do with the fact that all commands need `sudo` to work. How can I hardcode my password in the script so that it has the privileges to run? Or is it a bad idea ? Many thanks, guys ! – Arthur Tabbal Mar 13 '20 at 16:03
  • 2
    @Kurankat True. The reason I didn't put the full path is I was assuming `cpufreq` is installed somewhere on the machine's `$PATH`, and I didn't intend the script to be portable. But yes, you're quite technically correct. – jdrch Mar 13 '20 at 18:46
  • 2
    The only reason I mention it is because I've answered a couple of questions recently where commands in the user's `$PATH` somehow were not in the `$PATH` of the user that the script (or `CRON` job) was running as, causing problems. – Kurankat Mar 13 '20 at 21:49
  • @Kurankat I actually have had that happen to me before. For example, if you install `bash-it`, `bash-it update` won't work in the root crontab because `bash-it` isn't on root's `$PATH`. Has to be in the `$PATH` of user (whose shell it's installed in) @ArthurTabbal Just put the command in the root crontab and you should be fine. – jdrch Mar 14 '20 at 01:34
  • @jdrch I did it, wrote the `@reboot` line in crontab as you instructed... still, after the boot the cpus are running at 0.8ghz . Then if i run the script - which asks for my password -, they stop throttling and go back to performance mode with normal varying speed. Maybe it needs to run after the boot completes as opposed to on reboot? – Arthur Tabbal Mar 14 '20 at 15:15
  • 1
    How long does your desktop take to load after logging in? Try editing the `@reboot` crontab line to read `@reboot at +n minutes /Path/to/script.sh`. The `at` command is described [here](https://kb.iu.edu/d/aewo); the `n` in the code is how long it takes your desktop to load. That way you should be out of the boot woods once the script commands actually run. I'm totally guessing at this BTW haha. Let us know how it goes. – jdrch Mar 18 '20 at 19:18