Saturday 8 September 2018

Computer Performance Troubleshooting Guide

This guide is intended for troubleshooting general performance/crashing problems. Look for your observed symptoms, then follow the suggested component troubleshooting guides.
Most of the diagnosis/repair options are very safe; italic steps should potentially be performed with a knowledgeable friend.

Symptoms

  • Launching programs is slow
    • Disk issues
    • CPU issues
    • RAM issues (insufficient)
  • System briefly hangs; alt-tabbing/window dragging/switching is slow
    • RAM issues (insufficient)
    • CPU issues
  • Online Game rubberbanding/delays
    • Network issues (latency)
    • VSync (on can cause input lag)
  • Game FPS very low
    • CPU issues
    • GPU issues
  • Game FPS unstable
    • If its particularly bad when 'loading' new areas/levels/models, Disk issues
    • RAM issues
    • CPU/GPU throttling
  • System hangs + Blue Screens
    • RAM issues (corrupt)
    • OS/Driver issues
  • Power Loss (immediate shutdown)
    • Overheating issues (common in laptops)
    • Bad Battery and/or Power Supply
  • Game Crashing on Startup
    • Can be display setting issues, if your setup has changed (ie. went from a 1080p monitor/tv to a smaller one) and the game's settings are still trying the old too-big resolution, try finding its settings file and renaming it
  • Game Crashing during Loading
    • Game corruption? (try Steam's 'Verify Game Content', or reinstalling)
    • Mods?
    • GPU may not have enough VRAM, try lowering Texture quality
    • RAM issues
    • Or lots of game-specific problems
  • Game Crashing during Gameplay
    • RAM issues
    • Lots of game-specific problems

Components

CPU

Responsible for most general processing.

Identifying your Card: Windows -> System Information -> System Summary -> Processor (ie. "Intel Core i5-4590 CPU @ 3.30GHZ"). Intel model names are like i3-3320, where i3/i5/i7/i9 are broad market segments (i7's have lots of cores/overclocking potential, i3's are much cheaper but can be fine), the 3xxx is the generation, and the x320 is the relative model. AMD model names are like FX-8350, where 8xxx is the generation, and x350 is the relative model. Its difficult comparing CPUs of different generations or models based on name alone, so always consult Passmark's CPU Benchmark list, though generally newer cards beat previous generations of the same model.

Common Issues:
  • Utilization/Background Tasks. Modern cpus have 2-8+ Cores. Many applications can only utilize 1-2 cores, though some may use all available cores. In a 4 core system, with a game using 2 cores, you should expect to see 50-55% CPU utilization in Task Manager (25% + 25% + small background tasks including music/Chrome), which is fine. If your game can utilize all your cores (ie. you see 95%+ utilization) , you should minimize background processes. See OS guide.
  • Overheating. Typical operating temperature under load is 35-70c, with 70-80+ leading to performance throttling. Use programs like OCCT (see Appendix guide) or CPU-Z/Speedfan to further diagnose. Solutions: open the case (if its a laptop: google "<laptop model> disassembly guide") and remove dust from all fans/heatsinks (using compressed CO2). Improve case airflow, replace broken/underperforming fans, carefully reseat the cpu heatsink's thermal paste, or buy a larger non-standard heatsink.
  • CPU too old. Modern games can run poorly on 5-8+ year old cpus. Passmark's CPU Benchmark list shows the CPUMark score for tons of chips, compare yours with your game's minimum requirements score, and see if its maybe time for an upgrade.

GPU/Graphics Card

Responsible for Rendering/Visuals, including video playback, displaying application windows, and rendering game graphics. $80-350

Identifying your Card: Windows -> System Information -> Components -> Display -> Name (ie. "Radeon RX 470". Models are either Nvidia/Geforce (ie. GTX 660, 960, 1070, etc. The last two digits are relative pricepoint, ie. x60 < x70 < x80 < x90, the first portion is generation, so a 960 is the same gen as a 980 but lower-end), AMD/Radeon (ie. RX 5xx, RX 4xx, R9 270, HD 4870. Their naming is very inconsistent, but vaguely follows Nvidia's pattern), or Intel/Integrated (mostly laptops)

Common Issues:
  • Outdated Graphics Drivers. Updates come out monthly, if its been over a year (or your test game is very new), you probably need to update. Google "AMD Drivers" or "Nvidia Drivers", click the first link, enter your approximate card, and download the latest ~300mb drivers package. Run the resulting self-extracting exe, and then run the fancy branded installer inside, typically checking the "Clean install" tickbox. Restart afterwards.
  • Overheating. Typical operating temperature under load is 35-70c, with 70-80+ leading to performance throttling. Use programs like OCCT (see Appendix guide) or GPU-Z/Speedfan to further diagnose. Solutions: open the case (if its a laptop: google "<laptop model> disassembly guide") and remove dust from all fans/heatsinks (using compressed CO2). Improve case airflow, replace broken/underperforming fans.
  • Using integrated/onboard graphics. Some systems, primarily laptops or "APU" CPU's, have a weak low-power graphics option in addition to the high performance dedicated graphics card. On desktops, ensure your monitors are plugged in to the graphics card video outs, not the Motherboard's. On laptops, check your graphics driver settings (which are sometimes per-application) to ensure the graphics card is being used.
  • Running SLI/Dual cards. Several games have incompatibility issues with multi-card systems, try forcing the game to only use one card via Radeon/Nvidia settings.
  • Running 120/144hz monitors. Games can have incompatibility issues with these high-fps monitors, try forcing them to 60hz via Windows Display settings.
  • Card too old. Modern games can run poorly on 3-7+ year old cards. Passmark's Videocard Benchmark list shows the G3D Mark score for tons of cards, compare your card with your game's minimum requirements card's score, and see if its maybe time for an upgrade.

RAM/System Memory

Responsible for retaining loaded data while the power's on. Modern OS's tend to fill 90% of your RAM with preloaded data that 'might' be requested, which can obscure how much is actually being used. Win10's Task Manager -> Resource Monitor -> Memory tab shows 'In Use' distinct from 'Standby' and (actually empty) 'Free'. If your 'In Use' starts to exceed 80%, you'll start heavily relying on slower Page File/virtual memory stored on Disk. 'Hard Faults/sec' indicates when an app expects data to be in RAM, but it has to wait for it to be slowly fetched from Disk.

Identifying your amount of memory: Windows -> System Information -> System Summary -> Total Physical Memory (in GB). Also noteworthy is Page File Space, which is slow backup memory stored on Disk.

Common Issues:
  • Insufficient. Modern games use 4-8gb, the OS uses 1-2gb, and Chrome can use 1-4gb, so ideally you'll have 8-16gb. 
  • Corrupt RAM. On Win10, run 'Windows Memory Diagnostic' (scheduled on next boot). For a more in-depth check, run MemTest86, which usually comes included with any Ubuntu install USB. If MemTest doesn't find anything wrong, your RAM is probably ok. Otherwise, buy new RAM; you may want to isolate which stick is bad by removing all-but-one at a time.

SSD/Hard Drive/Disk

Solid State Drives are more expensive per GB than spinning platter Hard Drives, but offer 3-8x faster linear reads, and 100-300x faster random access (0.1ms vs 20ms). Generally, larger HDD's are newer and denser than smaller HDDs, which generally makes them faster. Moving your OS to an SSD will significantly speedup loading times in general, and moving frequently opened games will speed their loading further.

OS/Software

todo

PSU/Power Supply

todo

Appendix

OCCT Quick Guide (CPU/GPU benchmarking tool)

Download the Free, amusingly USSR themed Benchmarking tool. In the right side 'Monitoring' window you can see a CPU Usage graph (ie. task manager's), a temperature graph (cpu + gpu + possibly other additional sensors/individual CPU cores), and a Frequency graph (over/under clocking). You can either launch your own load (ie. run a game) with OCCT in the background, or run one of its benchmarks (CPU: OCCT or GPU: 3D). Run it for a minute or 3, then turn it off, and observe the graphs.

  • Temperature should start at 35-50c, and climb under load to a stable temperature of 50-65c (you'll hear the fans work a bit harder). Removing the load should cause the temperature to rapidly drop, returning to its initial level within a few minutes.
  • Frequencies may remain stable (+- 5%), or may jump from an initial low "power saving" level to a high load level (for a "3.30GHz CPU", that'll show around 3300MHz). If they're staying low, or jumping significantly under load, something (temperature? driver settings?) is throttling/underclocking it.


Monday 17 April 2017

Make Grub root your boot: Full Disk Encryption edition

You try to boot up your Linux machine, and hit an unfriendly Grub recovery console.

Oh no! Grub tends to fall over for a variety of reasons, including:
  • You recently updated your kernel (apt-get upgrade listed some linux-headers-* packages), and something didn't complete properly
  • You recently updated your kernel, and your proprietary nvidia/amd graphics drivers aren't playing nicely with it
  • /boot/grub/grub.conf got corrupted somehow
  • Your partitions/hdd's have changed
  • Grub thought you weren't sufficiently respecting it
In any case, there are generally two approaches to resolution:

Manually Boot

grub.cfg is basically just a "stable" set of boot commands, which generally boil down to
root='(hd0,1)'
linux /vmlinuz-3.19.0-32-generic root=/dev/sda2 ro quiet
initrd /initrd.img-3.19.0-32-generic
boot
root= sets what the current grub cli considers the boot root partition to be.
ls
Should list out all your devices. Try setting root='(a listed device)', and then try
ls /
If you have a separate /boot/ partition (ie. if your main root is encrypted), you should see a list of vmlinuz's and initrd.img's.
If your /boot/ is on your main root partition, you should see /bin, /sbin, /boot, /var, etc. There'll be vmlinuz's in /boot/*.
If you're seeing neither, try another device.


To find the right vmlinuz (Linux Kernel executable), you'll probably want the newest version you can see in ls / or ls /boot/ .

To find the right linux root=/path , you'll want to figure out which /dev/ device points at your typical / (with /bin, /sbin, /var, etc).
lsblk may help.
In a typical setup, this might be /dev/sda1
If your main root is encrypted, this might be something like /dev/mapper/nvme0n1p6_crypt . If you don't know and proceed with the wrong one, you'll probably be prompted to unlock your encrypted drive and then fallback to a busybox shell - at which point ls /dev/mapper/ should be able to list them.

For the initrd path (initial ramdisk), make sure to use the same version as your vmlinuz (kernel)!

Once you've booted, be sure to run
sudo update-grub
which should self-fix issues. If you notice in the resulting list of vmlinuz's and initrd's that the most recent one isn't a pair (you have a linuz-3.19.0-36 but no initrd.img-3.19.0-36), you'll want to reinstall that linux-image, ie
sudo aptitude reinstall linux-image-3.19.0-32-generic

Fix Grub using a Live USB

Boot up using any modernish version of Linux's live (ramdisk) mode, and try
sudo grub-install /dev/sda2
lsblk may help determine which drive to use. If you'd like to look around,
mkdir /mnt/somedrive && sudo mount /dev/sda2 /mnt/somedrive
may allow you to ls -l and such to confirm you have the right drive.
If your drive is encrypted, you may have to decrypt it first, and then it'll be named something like /dev/mapper/nvme0n1p6_crypt . I haven't had to do this yet, so I don't have further suggestions.

Sunday 2 March 2014

Crosscompiling a C based SDL2 Game

So, you want to develop SDL2 games in C on Linux, and would like to crosscompile them games for Windows too (since compiling natively in Windows sucks).

Here's a very basic hello world that proves you've got SDL2 and SDL_image working:
#include <stdio.h>
#include <SDL.h>

int main(int argc, char *argv[]) {
    if(SDL_Init(SDL_INIT_EVERYTHING) != 0) {
        fprintf(stderr, "SDL Init failed: %s\n", SDL_GetError());
        return 1;
    }
    SDL_Window *window = SDL_CreateWindow("Hello World", SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED, 640, 480, 0);
    int flags=IMG_INIT_JPG|IMG_INIT_PNG;
    if(IMG_Init(flags)&flags != flags) {
        fprintf(stderr, "IMG_Init failed: %s\n", IMG_GetError());
        return 1;
    }
    SDL_Delay(3000);
    SDL_DestroyWindow(window);
    SDL_Quit();

    return 0;
}

Get your Compilers

Get a Linux C compiler:
sudo apt-get install build-essential
For cross-compiling to Windows (both x86 and x64):
sudo apt-get install gcc-mingw32

Target ArchitectureC Compiler BinaryDirectory containing /lib /include
Linux Nativegcc/usr/
Windows x86i686-w64-mingw32-gcc/usr/i686-w64-mingw32/
Windows x64x86_64-w64-mingw32-gcc/usr/x86_64-w64-mingw32/

Get SDL2 for Linux

If you're on an Ubuntu >= saucy, on x86/x64, its easy to get SDL2:
sudo apt-get install libsdl2-2.0-0 libsdl2-dev libsdl2-image-2.0-0 libsdl2-mixer-2.0-0 libsdl2-mixer-dev libsdl2-image-dev
(if you're on ARM, you'll probably have issues compiling libsdl2-image's dependencies, and its not in the main repositories yet)

Get SDL2 for Windows (in Linux)

Crosscompiling SDL2 itself didn't work out well, so download the SDL2-devel-2.0.1-mingw archive.
Also download the SDL2_image-devel-2.0.0-mingw.tar.gz
Extract both of these to:
/usr/x86_64-w64-mingw32/

Building the Game

A Makefile will drastically simplify the development process, heres an example Makefile:
EXECUTABLE=game
SOURCES=test.c
EXTRALIBS=-lSDL2_image

#Linux build settings
CC=gcc
CFLAGS:=$(shell sdl2-config --cflags)
LIBS=$(shell sdl2-config --libs) $(EXTRALIBS)

#Windows build settings
win32: WINFOLDER:=/usr/x86_64-w64-mingw32/
win32: CC:=x86_64-w64-mingw32-gcc
win32: EXECUTABLE:=$(EXECUTABLE).exe
win32: CFLAGS:=-I$(WINFOLDER)include/SDL2 -Dmain=SDL_main
win32: LIBS=-L$(WINFOLDER)lib -lmingw32 -lSDL2main -lSDL2 -mwindows $(EXTRALIBS)

all: gcc_$(EXECUTABLE)
warn: CFLAGS += -Wall
warn: all
win32: all
run: all
        ./$(EXECUTABLE)
compile: headers
        $(CC) $(CFLAGS) -o $(EXECUTABLE) $(SOURCES) $(LIBS)
Linux build: make
Linux build & run if no errors: make run
Windows build: make win32

Troubleshooting

(Windows)  "The application was unable to start correctly: 0xc000007b"

Might have a 32bit/64bit issue. Check that your SDL2.dll, SDL2_image.dll, libjpeg-9.dll, and your game executable are all the same architecture.

(Building) "fatal error: SDL2.h: No such file or directory"

SDL2 isn't installed in a place gcc is currently looking. The example Makefile looks in /usr/include/, and apt-get should be installing it there. make install might not.

(Building) "undefined reference to `IMG_Init'"

You're missing the gcc argument -lSDL2_image

(Building) " error: ‘IMG_INIT_JPG’ undeclared (first use in this function)"

Your source file is missing #include <SDL2/SDL_image.h>