What is TCG?
Tiny Code Generator (QEMU)
TCG (Tiny Code Generator) is the part of QEMU that emulates a processor in software, translating a guest's instructions into the host's as they run.
When a virtual machine's processor architecture matches the host's, a hypervisor can run the guest's code directly on the real CPU with hardware help (KVM on Linux, Apple's Hypervisor framework on a Mac), and it runs at close to native speed. When the architectures differ, as with an x86 VM on an ARM Mac, that isn't possible. TCG reads the guest's machine code a block at a time, translates each block into an intermediate form and then into native code for the host, and caches the result so a hot loop is translated only once. Everything the guest does, from its kernel to its device drivers, goes through this translation.
The result is completely real but noticeably slow. A VyOS router running under TCG on an M-series Mac takes minutes to boot, and a configuration commit takes tens of seconds instead of one or two. Multi-processor guests (-smp 2 and up) can use several host threads with -accel tcg,thread=multi, but in practice a single emulated CPU has proved the most stable for router VMs. TCG is different from the user-mode emulation (QEMU's or Rosetta's) that runs individual x86 programs in containers through binfmt_misc: that translates one program, not a whole machine. The Apple Silicon lab guide runs VyOS this way, inside a container, alongside native routers.
Lessons that use TCG
- Building a network lab on an Apple Silicon MacTeaches this term · Beginner · 45 min
Run real network labs on an M-series Mac: native FRR and Linux containers, x86-only images through Rosetta, and full x86 VyOS VMs under QEMU in Docker, with the pitfalls that stop most people and a starter lab that mixes all three.