multi-threading qemu · 2016-02-07 · tcg considerations tiny code generator (tcg) is the emulator...

14
Linux is a registered trademark of Linus Torvalds. Multi-threading QEMU or Ingo might be right.. sort of Anthony Liguori – [email protected] IBM Linux Technology Center Aug 2010

Upload: others

Post on 13-Jul-2020

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Multi-threading QEMU · 2016-02-07 · TCG Considerations Tiny Code Generator (TCG) is the emulator part of QEMU Cannot preserve atomicity of instructions – Due to design issues

Linux is a registered trademark of Linus Torvalds.

Multi-threading QEMUor Ingo might be right.. sort of

Anthony Liguori – [email protected]

IBM Linux Technology Center

Aug 2010

Page 2: Multi-threading QEMU · 2016-02-07 · TCG Considerations Tiny Code Generator (TCG) is the emulator part of QEMU Cannot preserve atomicity of instructions – Due to design issues

Ideal KVM Architecture

VCPU2Thread

VCPU3Thread

VCPU0Thread

VCPU1Thread DEV

DEVThread

DEVThread

Process

Design• One thread per-VCPU• Device models run concurrent in VCPU thread• Long running operations run in additional device thread

Goals• Maximize CPU affinity• Minimize PIO/MMIO latency

Page 3: Multi-threading QEMU · 2016-02-07 · TCG Considerations Tiny Code Generator (TCG) is the emulator part of QEMU Cannot preserve atomicity of instructions – Due to design issues

QEMU/KVM Architecture

VCPU2Thread

VCPU3Thread

VCPU0Thread

VCPU1Thread DEV

IOThread

Process

CurrThread

Design• One thread per-VCPU• One I/O thread• All threads run in lock step protected by qemu_mutex

Goals• Avoid rewriting QEMU• Find a TCG-compat design

Page 4: Multi-threading QEMU · 2016-02-07 · TCG Considerations Tiny Code Generator (TCG) is the emulator part of QEMU Cannot preserve atomicity of instructions – Due to design issues

TCG Considerations● Tiny Code Generator (TCG) is the emulator part

of QEMU● Cannot preserve atomicity of instructions

– Due to design issues– Due to architectural issues (PPC vs. x86)

● QEMU's single thread design is ideal for TCG

● Device models are unlikely to ever run in parallel with TCG emulation

Page 5: Multi-threading QEMU · 2016-02-07 · TCG Considerations Tiny Code Generator (TCG) is the emulator part of QEMU Cannot preserve atomicity of instructions – Due to design issues

Evolving QEMU● I/O thread gets our foot in the door● Reduce granularity of locking

– Push qemu_mutex out of kvm-all.c, exec.c, apic.c, …

● Add locking to common infrastructure– Push qemu_mutex out of vl.c, async.c,

block/*● Start adding device specific threads

Easy, right?

Page 6: Multi-threading QEMU · 2016-02-07 · TCG Considerations Tiny Code Generator (TCG) is the emulator part of QEMU Cannot preserve atomicity of instructions – Due to design issues

Worlds Colliding

KVM

TCG

Page 7: Multi-threading QEMU · 2016-02-07 · TCG Considerations Tiny Code Generator (TCG) is the emulator part of QEMU Cannot preserve atomicity of instructions – Due to design issues

Two different worlds

● Performance● Scalability● Reliability● External tooling

● Functionality over quality

● Performance doesn't matter

● All-in-one tool

KVM TCG

● We want to continue to share code● Supporting multiple use-cases and architectures

makes our code better● We struggle to accommodate both worlds

Page 8: Multi-threading QEMU · 2016-02-07 · TCG Considerations Tiny Code Generator (TCG) is the emulator part of QEMU Cannot preserve atomicity of instructions – Due to design issues

Time for a change● QEMU is bloated with lots of useful features● We struggle to scale in every possible way

● VNC server● virtual disk formats● network interconnects● generic transports● multi-architecture device mode● multi-architecture CPU emulation● ....

Page 9: Multi-threading QEMU · 2016-02-07 · TCG Considerations Tiny Code Generator (TCG) is the emulator part of QEMU Cannot preserve atomicity of instructions – Due to design issues

libqemu-*.so● Much of qemu would be better suited as

libraries maintained as separate projects● Let KVM develop a stand alone userspace that

fits it's architecture model● Multiple libraries to accommodate different

architectures– With different emphasis on quality/features

● Continue to share code when it make sense

● Open QEMU code base to a wider audience

Page 10: Multi-threading QEMU · 2016-02-07 · TCG Considerations Tiny Code Generator (TCG) is the emulator part of QEMU Cannot preserve atomicity of instructions – Due to design issues

QEMU 2.x

libqemu-block.so

libqemu-net.so

libqemu-vnc.so

libqemu-dm-pc.so

QEMU 2.x

qemu-img

qemu-nbd

qemu-io

qemu-next

Page 11: Multi-threading QEMU · 2016-02-07 · TCG Considerations Tiny Code Generator (TCG) is the emulator part of QEMU Cannot preserve atomicity of instructions – Due to design issues

libqemu-block.so● qemu-img is very popular outside of QEMU● Many tools have developed over the years with

a few making it into QEMU (qemu-nbd, qemu-io)

● These tools should be separate projects to allow other communities to contribute

● Patches on the list

Page 12: Multi-threading QEMU · 2016-02-07 · TCG Considerations Tiny Code Generator (TCG) is the emulator part of QEMU Cannot preserve atomicity of instructions – Due to design issues

libqemu-dm-pc.so● Fork internal device models

– Improve interfaces– Extensive unit tests

● As device models improve, we can replace the internal device models

● Experiment with radical to difficult problems– Migration– Versioning

● Some prototypes will be available soon

Page 13: Multi-threading QEMU · 2016-02-07 · TCG Considerations Tiny Code Generator (TCG) is the emulator part of QEMU Cannot preserve atomicity of instructions – Due to design issues

Other considerations● Major concerns of split

– KVM community ignores TCG; this is the point– QEMU has historically avoided dependencies

● Does fit general direction of QEMU– Single executable with pluggable CPU

translation

● Split will not be successful without major changes– Test driven development– Rely more on external code

Page 14: Multi-threading QEMU · 2016-02-07 · TCG Considerations Tiny Code Generator (TCG) is the emulator part of QEMU Cannot preserve atomicity of instructions – Due to design issues

Questions● Questions?