# Orange Pi Pro 5

## Concept

Well, it is a core value of Stallman in Open Source, in Cyberpunk to hack devices.
It was a time where computing and electronic where blurred.
Meaning that you'd get hardware doing the heavy lifting because it was way cheaper than general purpose computation.

So rather than having extensive code, that would take too much memory and would be too slow, you'd get the right ASIC, a custome chip that does the job.
And you will code in the way you tell the chip what to do next, like direct instruction.

Even a Graphics Processing Unit is now standardized as compute. You can do Graphics, you could do sound, you certainly run AI on it, scientific calculations.
At the time of the Neo Geo, you'd say "take this sprite here and put it here", and the processor would get directly the right pixel from the cartridge to put at the right place on the screen.
So... you could not say "draw a line", that did not exist in the Neo Geo. It was meant to draw sprites, excessively well for the time.

Dude, I have no idea what I am talking about.
It is entirely unrelated. So...

We are back in very interesting time. You can buy a computer like if it is not even a commodity but something out of a factory in China.
Except that it is what it is. And you get insane power, in relative terms (we'll talk about that), multi-core, 64-bits, 8GB of memory.

You can hack it to death, tune the kernel, swap component, piece togethers sensors, connect it to your network.
You can use it like a general purpose computer. Do some stuff, a bit slower.

### I am no peasant. I'm a writer!

So my goal is to play a wargame on a device on android I access through scrcpy and play with a mouse on my PC.
Always on, through a 1Gbps network. I want something that run nicely.

You need speed, but you sure do need predictability. When you click, it may take 10ms or 30ms, but I have to get a sense of rhythm, a tempo you can flow in.
I am not good at many things. But if you need to kill or burn things in a wargame, well I can't say I am good, but I do like it.

## The hardware

### So I decided for a Orange Pi Pro 5. And I got fucked.

![Orange pi pro 5](orangepi/orange_bare.jpg)

So everyone is like : the most powerful Single Board Computer (SBC).
And they test it with emulators, and it runs great!

Well the thing is... emulators are ridiculously optimized and a PS2 is old news.
So yeah, you get some power (パワー) if you do stuff that you don't need it for.
Well, it is not bad if you want an alternative to Rapsberry Pi because it is not available or more expensive.

But there is a caveat : the DVFS is trash.
Yeah, I know what you think...

What the fuck is DVFS?
Well, almost all CPU have a DVFS (Dynamic Voltage and Frequency Scaling).
You don't want to overload, you don't want to use more than you need.
You want the CPU to be fast when needed, calm when idle.

Nowadays, on ARM CPU like smartphones, voltage and frequency are regulated by a SCMI (System Control and Management Interface).
So you have a firmware or module, a piece of proprietary code.

If we look at the whole chain...

```
Android
  │
  ▼
Linux Kernel
  │
  ▼
DVFS
  │
  ├── OPP table
  ├── Clock driver
  └── Regulator driver
          │
          ▼
     SMCI + PLL
          │
          ▼
         CPU
```

And on this Orange Pi Pro 5... well it is garbage.
Everything is trash. The scheduler is not doing its job. The app will bounce between core, and even go to slow cores. The thermal throttling defaults at 40℃, so it gets sluggish fast. The voltage is shared among graphics, CPU, NPU (the AI oriented thing you will never use), the whole has no idea what is happening.

So you hack.

## Hacking

Well, you search for the docs, you try,

You add that in root :

```
echo "" > /data/adb/service.d/performance.sh
chmod +x
```

And then you start coding.
So let's be honest, there is a game I want to run, and the performances are crap.
And so I do so many things :

- I disabled some CPU core, to not loose power (パワー), reduce uncertainty
- I maxed out memory settings
- I reduce app bouncing across CPU cores
- I neutered the NPU for AI because die, Skynet
- I moved some fine grade options, trial and error
- I added more cache for the GPU, I/O
- I changed Linux scheduler and governor to stuck at my hard set values
- I compiled the game I use to ART, deterministic optimized build
- etc.

And here we are!

### That 233 lines of madness, you can check it [here](orangepi_code.md)

One example. The board has memory, I maximize it, it reduces stupid I/O.
Don't believe other people's choice. They want the board to survive. I want it to thrive.

```
# GPU shader cache : enable infinite cache per context
for ctx in /d/mali0/ctx/*; do
    if [ -f "$ctx/infinite_cache" ]; then
        write_if_exists "$ctx/infinite_cache" "Y"
    fi
done

# GPU memory pools : expand tiler heap limits
for ctx in /d/mali0/ctx/*; do
    if [ -f "$ctx/mem_pool_max_size" ]; then
        write_if_exists "$ctx/mem_pool_max_size" "65536"
    fi
    if [ -f "$ctx/lp_mem_pool_max_size" ]; then
        write_if_exists "$ctx/lp_mem_pool_max_size" "65536"
    fi
done
```

And then you need a box.

## Building the box

100円, 1$ transparent box to start with.

![Orange Box](orangepi/orange_box.jpg)

Slam some copper on the board.

![Heatsink orange](orangepi/orange_heatsink.jpg)

Assemblate!

![Orange assemblated](orangepi/orange_collage.jpg)

Put some plaster, paint it.

![Orange painting](orangepi/orange_casio.jpg)

And that's how I like it. No neon, humble.

![Orange finished](orangepi/orange_finished.jpg)

### And rusty. Like me.
