Page 1 of 2

Emulation Station Battery optimization for RapberryPi Zero

Posted: Fri Apr 28, 2017 2:48 pm
by Hex
NOTE: This has been already implemented into the Retropie ES. Option is present in Settings>OtherSettings>PowerSaverModes


Binary Updated for Pi Zero and 1

While working on my GBZ build I noticed that my PiZero was heating quite a bit when emulation station was idle. So I sshed in and found that the ES was using 65% CPU on average doing nothing. I dug into the code and found the problem. The github fork link is below. It does not work well with video previews but my goal is to save power for the PiZero build. It helps a lot if you are running your build standalone, ie. not connected to wall socket.

My build : http://www.sudomod.com/forum/viewtopic.php?f=9&t=2851

Github ES repo : https://github.com/hex007/EmulationStation

Install from binary
I have attached the binary below. You can download and install on the Pi using:

Code: Select all

// Get Zip of binary
$ wget http://www.sudomod.com/forum/download/file.php?id=5772 -O es.zip

// Extract Zip
unzip es.zip

// Bkp original ES binary and replace with one downloaded
$ sudo mv "/opt/retropie/supplementary/emulationstation/emulationstation" "/opt/retropie/supplementary/emulationstation/emulationstation_bkp"
$ sudo cp "emulationstation" "/opt/retropie/supplementary/emulationstation/emulationstation"

// Reboot 
$ sudo reboot
Or if you prefer to build it
SSH into the pi or hook up a keyboard then to build on Pi :

Code: Select all

// note the pid of emulationstation
$ top
// press q to exit

//Kill emulation station using pid noted above
$ kill PID

// To build on pi zero we need more ram. Get root previleges to turn swap on
$ sudo su
// We define a way to increase the Swap space. Copy after "#" till the last "}" and paste into terminal
# function rpSwap() {
    local command=$1
    local swapfile="$__swapdir/swap"
    case $command in
        on)
            rpSwap off
            local memory=$(free -t -m | awk '/^Total:/{print $2}')
            local needed=$2
            local size=$((needed - memory))
            mkdir -p "$__swapdir/"
            if [[ $size -ge 0 ]]; then
                echo "Adding $size MB of additional swap"
                fallocate -l ${size}M "$swapfile"
                chmod 600 "$swapfile"
                mkswap "$swapfile"
                swapon "$swapfile"
            fi
            ;;
	off)
            echo "Removing additional swap"
            swapoff "$swapfile" 2>/dev/null
            rm -f "$swapfile"
            ;;
    esac
}
// Increase Swap space
# rpSwap on 512
// Exit from superuser shell
# exit

// Clone Repository
$ git clone --depth 1 --recurse-submodules https://github.com/hex007/EmulationStation

// Build EmulationStation
$ cd EmulationStation
$ cmake ./
$ make
// This will take a long time ~ 1.5-2 Hrs

// Once build is successful, bkp original ES binary and replace with one just built
$ sudo mv "/opt/retropie/supplementary/emulationstation/emulationstation" "/opt/retropie/supplimentary/emulationstation/emulationstation_bkp"
$ sudo cp "emulationstation" "/opt/retropie/supplementary/emulationstation/emulationstation"

// Reboot 
$ sudo reboot

Re: Emulation Station speedups for RapberryPi Zero

Posted: Mon May 01, 2017 10:03 am
by McGyver
I tried your updated version of emulationstation via zip file. My problem: after reboot emulationstation does not start up again! The retropie just boots into the command prompt. Any idea?

Re: Emulation Station speedups for RapberryPi Zero

Posted: Mon May 01, 2017 1:36 pm
by Hex
McGyver wrote:
Mon May 01, 2017 10:03 am
I tried your updated version of emulationstation via zip file. My problem: after reboot emulationstation does not start up again! The retropie just boots into the command prompt. Any idea?
Did you replace the binary properly?

You have to extract the binary from Zip file and substitute the original with the modded. If you can attach a keyboard then you can do this directly from the Pi.

Can you tell me what steps you took so I can help you out.

Re: Emulation Station speedups for RapberryPi Zero

Posted: Mon May 01, 2017 2:16 pm
by McGyver
Via Terminal connected on SSH I did:
1: wget http://www.sudomod.com/forum/download/file.php?id=5057 -O es.zip (download your zip)
2: unzip es.zip (unzip...)
3: sudo cp "emulationstation" "/opt/retropie/supplementary/emulationstation/emulationstation" (move your version over the original one)
4: sudo reboot (reboot)

After reboot, emulationstation didn`t start, just the command promt...

Re: Emulation Station speedups for RapberryPi Zero

Posted: Mon May 01, 2017 6:09 pm
by Hex
You have to kill the process for Emulationstation first and then copy the binary

Code: Select all

// Find EmulationStation PID using:
top
// note the PID and Press q to exit from top
kill PID
sudo cp ........................
Screenshot from 2017-05-01 17-07-56.png
Screenshot from 2017-05-01 17-07-56.png (98.48 KiB) Viewed 15314 times

Re: Emulation Station speedups for RapberryPi Zero

Posted: Wed May 03, 2017 1:26 pm
by McGyver
I stopped emulationstation by kill + PID. Same bad news: after replacing the original emulationstation to your one the Pi just boots into the console pi@retropie:~ $

Re: Emulation Station speedups for RapberryPi Zero

Posted: Wed May 03, 2017 4:02 pm
by Hex
Well at least you can restore it cleanly by reinstalling from binary.

Are you using Pi Zero/1 or 2/3??? The binary is only for PiZero or 1.

Also verify the md5
md5sum : 59d9aec4d5d524d525714d4f70c83cd5

Re: Emulation Station speedups for RapberryPi Zero

Posted: Thu May 04, 2017 2:05 am
by kendon
Make sure the file is executable:

Code: Select all

$ ls -l /opt/retropie/supplementary/emulationstation/emulationstation
-rwxr-xr-x 1 root root 4746728 Mar 16 20:41 /opt/retropie/supplementary/emulationstation/emulationstation
If the permissions (-rwxr-xr-x) look any different do:

Code: Select all

sudo chmod 755 /opt/retropie/supplementary/emulationstation/emulationstation

Re: Emulation Station speedups for RapberryPi Zero

Posted: Thu May 04, 2017 11:06 am
by Hex
kendon wrote:
Thu May 04, 2017 2:05 am
Make sure the file is executable:

Code: Select all

$ ls -l /opt/retropie/supplementary/emulationstation/emulationstation
-rwxr-xr-x 1 root root 4746728 Mar 16 20:41 /opt/retropie/supplementary/emulationstation/emulationstation
If the permissions (-rwxr-xr-x) look any different do:

Code: Select all

sudo chmod 755 /opt/retropie/supplementary/emulationstation/emulationstation
The file is executable by default. I tested it on stock RetroPie 4.2, so it should work.

Re: Emulation Station speedups for RapberryPi Zero

Posted: Thu May 04, 2017 11:38 am
by McGyver
Yes: the checksum from the downloaded file is different!
I struggled to install from source: honestly: your code formatting in the post is really hard to read. Hard so see the differences between your comments and necessary terminal commands...

Can you maybe upload the programm again with the good checksum? In github would be just fine...