vcgencmd, over/underclocking etc. mini-howto

The SARPi project forum. For anything and everything relating to Slackware ARM on a Raspberry Pi 1, 2, and 3. This forum is NOT a replacement or substitute for the Slackware (ARM) forums on Linux Questions website! Please try to seek help there first about any issues you may be experiencing, or question you might have, before posting on here.
User avatar
linicks
Registered user
Registered user
Posts: 126
Joined: Mon Oct 27 2014 - 20:26:01
Location: Pompey, England

vcgencmd, over/underclocking etc. mini-howto

Postby linicks » Sun Nov 16 2014 - 14:33:34

Now having time, I spent a few hours today investigating all of this on my Slack Pi.

Basically vcgencmd (and other tools) get installed into /opt/vc, which is what the Raspian OS uses via the GUI to config a few things.

This needs to be added to your $PATH so that user can run them:

edit /etc/profile and add /opt/vc/bin & /opt/vc/sbin to the path options there, i.e. for root:

Code: Select all

PATH=/usr/local/sbin:/opt/vc/bin:/opt/vc/sbin:/usr/sbin:/sbin:$PATH


Next vcgencmd will not run, as it cannot find the required libs, so add them:

Edit /etc/ld.so.conf thus:

Code: Select all

/lib
/usr/lib
/usr/local/lib
/usr/arm-slackware-linux-gnueabi/lib
/opt/vc/lib


and issue as root:

Code: Select all

ldconfig


to update the library paths.

Now vcgencmd should work:

Code: Select all

@slackpi:~# vcgencmd measure_temp
temp=44.4'C


Good stuff :)

Now for over/underclocking. Edit /boot/config.txt and add this (change to suit, and reboot required):

Code: Select all

force_turbo=0
arm_freq=800
arm_freq_min=600


force_turbo=0 means that the cpu will be clocked at arm_freq_min on idle, but will ramp up to arm_freq on load (works very well!). Be very careful of the figure used here, as you can fry your Pi - the above figures I use are pretty safe.

I also change the cpu governor from powersave to ondemand at boot time via this command in /etc/rc.d/rc.local

Code: Select all

cpufreq-set -c 0 -g ondemand


Here is a quick script to produce some stats:

Code: Select all

#!/bin/bash
# cpustatus
#
# Prints the current state of the CPU like temperature, voltage and speed.
# The temperature is reported in degrees Celsius (C) while
# the CPU speed is calculated in megahertz (MHz).

function convert_to_MHz {
let value=$1/1000
echo "$value"
}

function calculate_overvolts {
# We can safely ignore the integer
# part of the decimal argument
# since it's not realistic to run the Pi
# at voltages higher than 1.99 V
let overvolts=${1#*.}-20
echo "$overvolts"
}

temp=$(/opt/vc/bin/vcgencmd measure_temp)
temp=${temp:5:4}

volts=$(/opt/vc//bin/vcgencmd measure_volts)
volts=${volts:5:4}

if [ $volts != "1.20" ]; then
overvolts=$(calculate_overvolts $volts)
fi

minFreq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq)
minFreq=$(convert_to_MHz $minFreq)

maxFreq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq)
maxFreq=$(convert_to_MHz $maxFreq)

freq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)
freq=$(convert_to_MHz $freq)

governor=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)

echo "Temperature: $temp C"
echo -n "Voltage: $volts V"
[ $overvolts ] && echo " (+0.$overvolts overvolt)" || echo -e "\r"
echo "Min speed: $minFreq MHz"
echo "Max speed: $maxFreq MHz"
echo "Current speed: $freq MHz"
echo "Governor: $governor"

exit 0


This produces:

Code: Select all

Temperature: 44.4 C
Voltage: 1.20 V
Min speed: 600 MHz
Max speed: 800 MHz
Current speed: 600 MHz
Governor: ondemand


Hope that helps someone.

Nick

EDIT: P.S. I have added a link to your SlackPi howto from my Pi web site - click on the Raspberry icon :)
Last edited by linicks on Tue Nov 18 2014 - 20:11:22, edited 1 time in total.
https://linicks.net/

Q. What is the difference between a duck and an elephant?
A. You can't get down off an elephant.

User avatar
Exaga
FatDog Network Administrator
FatDog Network Administrator
Posts: 204
Joined: Wed Apr 18 2012 - 02:01:03
Location: England [UK]

Re: vcgencmd, over/underclocking etc. mini-howto

Postby Exaga » Tue Nov 18 2014 - 00:51:09

Thanks for this Nick. It's very interesting indeed. I'll be having fun with this when I find time at the weekend.

Thanks also for the link. :love:
Exaga

====
__ KEEP THE DOG ALIVE!!!
()'`; /
/\|` W00f W00f W00f
www.fatdog.eu

User avatar
linicks
Registered user
Registered user
Posts: 126
Joined: Mon Oct 27 2014 - 20:26:01
Location: Pompey, England

Re: vcgencmd, over/underclocking etc. mini-howto

Postby linicks » Tue Nov 18 2014 - 19:43:58

I forgot - a normal user may not have permissions to run /opt/vc/vcgencmd and query system/cpu.

I got around this (as httpd needs ro run it to populate my Slack Pi web server page) by doing:

Add user to groups video and plugdev.

Create a file /etc/udev/rules.d/99-input.rules and populate with:

Code: Select all

SUBSYSTEM=="vchiq", GROUP="video", MODE="0660"


After a reboot, normal user can use vcgencmd.

I am not sure which of the above fixes this, but the udev rules look favourite.

Nick
EDIT: Also forgot - if you use your Slack Pi 'headless' as I do (all done through ssh), then you can reduce GPU allocated memory to system memory. In the file /boot/config.txt add/change the gpu_mem value to:

Code: Select all

gpu_mem=16


16MB is the minimum value - mine was set to 32MB so this line releases 16MB for the system to use.

More details here:

http://elinux.org/RPi_config.txt
https://linicks.net/

Q. What is the difference between a duck and an elephant?
A. You can't get down off an elephant.

User avatar
linicks
Registered user
Registered user
Posts: 126
Joined: Mon Oct 27 2014 - 20:26:01
Location: Pompey, England

Re: vcgencmd, over/underclocking etc. mini-howto

Postby linicks » Sat Nov 22 2014 - 14:49:57

Slight update on this - reading up, underclocking the Pi can cause SD card corruption - so I have now changed cpu Hz thus:

Code: Select all

force_turbo=0
arm_freq=850
arm_freq_min=700


So, set base line to normal 700Hz, and upped overclock to 850Hz.

Nick
https://linicks.net/

Q. What is the difference between a duck and an elephant?
A. You can't get down off an elephant.

User avatar
br_Orion
Registered user
Registered user
Posts: 12
Joined: Thu May 29 2014 - 16:20:50

Re: vcgencmd, over/underclocking etc. mini-howto

Postby br_Orion » Fri Dec 05 2014 - 02:38:54

:D
So much good stuff!
The script worked flawlessly!
I am using the rpi just for file server until now, so i do not plan to change clock. Maybe the mem settings if needed in future.

User avatar
linicks
Registered user
Registered user
Posts: 126
Joined: Mon Oct 27 2014 - 20:26:01
Location: Pompey, England

Re: vcgencmd, over/underclocking etc. mini-howto

Postby linicks » Fri Dec 05 2014 - 17:22:20

Glad it works (of course it does, it's Slackware :) )

Don't forget to check your SD card in fstab as per my post here:

viewtopic.php?f=30&t=140

as if you are using it as a file server, lots of read/writes can be optimised.

I am currently runing my SlackPi as web server, NTPD server, DHCP server and DNS server (the last two from dnsmasq daemon).

It is performing flawlessly.

Nick
https://linicks.net/

Q. What is the difference between a duck and an elephant?
A. You can't get down off an elephant.

User avatar
br_Orion
Registered user
Registered user
Posts: 12
Joined: Thu May 29 2014 - 16:20:50

Re: vcgencmd, over/underclocking etc. mini-howto

Postby br_Orion » Mon Dec 08 2014 - 01:52:07

I did the nice treatment to my sd card too.
But i have only the /boot lying on sdcard, the / partition is under a sata drive:

Code: Select all

  GNU nano 2.3.5                                                 Arquivo: /etc/fstab                                                                                                           

/dev/sda2        swap             swap        defaults         0   0
/dev/sda1        /                ext4        defaults         1   0
/dev/mmcblk0p1   /boot            vfat        noatime,noauto,fmask=177,dmask=077 1   0
#/dev/cdrom      /mnt/cdrom       auto        noauto,owner,ro,comment=x-gvfs-show 0   0
/dev/fd0         /mnt/floppy      auto        noauto,owner     0   0
devpts           /dev/pts         devpts      gid=5,mode=620   0   0
proc             /proc            proc        defaults         0   0
tmpfs            /dev/shm         tmpfs       defaults         0   0

User avatar
linicks
Registered user
Registered user
Posts: 126
Joined: Mon Oct 27 2014 - 20:26:01
Location: Pompey, England

Re: vcgencmd, over/underclocking etc. mini-howto

Postby linicks » Tue Dec 09 2014 - 20:06:29

I use noatime on all my machines, it seems pretty good to do so anyway, and unless you are running stuff that needs atime, then you will know not to use it.

Nick
https://linicks.net/

Q. What is the difference between a duck and an elephant?
A. You can't get down off an elephant.

Return to “SARPi Project - Slackware ARM on a Raspberry Pi”

Who is online

Users browsing this forum: CommonCrawl [Bot] and 3 guests