Quick & Simplistic Explanation of Multi Core Processors

Lately I’ve been delving into the C programming language. Coming from a higher-level perspective (PHP, Javascript, Python), I’ve never had the need to focus on the nitty-gritty of things like memory management. However, the direction I’m going in now – Blockchain and Crypto-Currencies – necessitates a greater of understanding of core machine / data concepts, and indeed, to build a sophisticated blockchain with its own application language, rather than extending existing architecture (ie. Ethereum via Solidity), requires a fine-grain application of code. Hence my interest in C.

With the fading of Moore’s Law, no longer do we find ourselves cramming ever-more circuits onto ever-shrinking micro-chips. Physics dictates that Moore’s law had to come to an end at some point – shrinking things can only go so far. One workaround is multi-core processors. Yes, these have been around for a long time. But what are they?

First, let’s briefly discuss a few concepts:

Bus:
A bus transfers data between components. ie. There is an input / output bus to transfer data from your keyboard to the system. A memory bus might transfer data from main memory to the CPU.

Main memory:
Temporary data storage. Holds programs and data while CPU executes program.

Register:
The CPU contains a Register, which stores data. The register is the smallest, but also the fastest data source in the system.

Cache:
Caches on a CPU store and process data. They are faster than main memory, but slower than the register. They have more storage space than the register, but less than main memory. The CPU contains typically 3 cache levels – L1, L2, L3.

CPU:
Processes instructions from main memory. The CPU contains a Register, which stores data. The register is the smallest, but also the fastest data source in the system. The CPU Program Counter points at data addresses in main memory, which contains instructions. Simply, the Program Counter points at a single address in main memory, processes the instruction, and then points at the next instruction, like a very fast set of switches, one by one.

Concurrent operations using a single-core system are an illusion. The illusion of concurrency is achieved by very rapid switching of individual instructions, and sharing of resources. Say for example, you run two programs at once. Instructions from these programs only ever run one-at-a-time on a single-processor. Blinding-fast switching between execution processes – the industry term is Context Switching – allows for the illusion of concurrent operation.

A multi-core processor is essentially multiple processors packed onto a single chip. With multiple-processor true concurrent operation can be achieved. No longer are we restricted to single-processor context switching.

More than that, theoretically faster operations can be achieved, not just due to reduced requirement for context-switching, but due to implementation of individual cache and register data transfer.

The following diagram of a dual core processor serves as a simplified illustration of the process. As you can see, the data from main memory goes through the shared L3 cache, and is siphoned into each core for processing. Because there are two cores, concurrent processing is possible in the registers, L1 cache, and L2 cache.

Simple Dual Core Processor & Memory Diagram

Hopefully you’ll now have a vague idea as to why it is important to understand memory management, especially in the context of something like blockchain programming. The ability to control where in memory the data exists and is processed allows for faster and more secure systems, and since blockchain applications typically deal with finances, this speed and security are crucial. Moreover, since blockchain is essentially a very inefficient and bloated shared decentralized database, using a low level language like C makes for a leaner system.