A dedicated unikernel for microservices

Monday, November 02, 2020

ToroKernel becomes ToroMicroVM

Hello! I just merged the work to support microvm in Toro. This work has started at the beginning of May'20 (end of lock-down in France) and has almost finished couple of days ago (still in lock-down). This work removes the support for legacy devices,e.g., 8259, pic, CMOS, changes the bootloader among other features. The use of microvm together with other technologies like virtiofs and vsocket has simplified the code of the kernel. For example, the stack TCP/IP has been removed and only VSocket is supported. Also, the buffer-cache has been removed from the VFS. The VFS thus becomes just a wrapper for the virtiofs driver. The drivers for emulated devices have been also removed, e.g., e1000, ne2000. I have also removed drivers like virtio-net and virtio-block, which are currently not used. This results in a minimalist unikernel that focuses on virtiofs and vsocket, i.e., ToroMicroVM. I did a refactoring of the VirtIO driver by putting the code that is independent from the devices into VirtIO.pas. This eases the adding of new virtio-drivers and eliminates code duplication. Currently, the kernel has ~ 13KLoC, which is about 6KLoC less than Torokernel (~19KLoC). User can still use the old ToroKernel by just checking out the tag ToroKernel. In the future, I may simply fork the project and renamed ToroMicroVM. 

Matias


Sunday, August 16, 2020

Debugging by using QEMU trace-events

Hello folks! In this post, I am going to talk a bit about QEMU trace-events. I found this mechanism during the development of a virtio driver. Roughly speaking, trace-events are generated by different components of QEMU like the virtio queues, the ioapic, lapics, etc. To enable it, you have to compile QEMU with the following option:

--enable-trace-backends=simple

Then, you have to add the following line to command-line:

-trace events=./events

The file named events contains a list of events that we are interesting to observe. For example, this is mine:

apic_*

ioapic_*

virtio_*

In my case, I am interested in checking if irqs are correctly acknowledged. To see this, I get all the events related with apic, ioapic and virtio. To output the logs in a file, I have to get QEMU monitor and first do 'trace-file on' and second 'trace-file flush'. I am not sure why this is not automatically done. You end up getting a file named 'trace-PID' in which PID is the corresponding PID of the QEMU process. To read this file, you have just to run the following python script:

python3 ~/qemulast/scripts/simpletrace.py ~/qemulast/build/trace-events-all trace-30572   

You will get something like:

virtio_mmio_read 131.447 pid=2451 offset=0x60

virtio_mmio_write_offset 141.046 pid=2451 offset=0x64 value=0x1

virtio_mmio_setting_irq 8.345 pid=2451 level=0x0

ioapic_set_irq 4.359 pid=2451 vector=0xc level=0x0

ioapic_eoi_broadcast 29.005 pid=2451 vector=0x2c

ioapic_clear_remote_irr 1.683 pid=2451 n=0xc vector=0x2c

In this example, we can see that when an IRQ is captured, the handler reads the status register and writes it to ack the irq. Then, the virtio sets the irq level at 0x0. The handler ends up by sending the EOI to the LAPIC. You can find more information about trace-events at: 

https://git.qemu.org/?p=qemu.git;a=blob_plain;f=docs/devel/tracing.txt;hb=HEAD.

http://blog.vmsplice.net/2011/02/observability-using-qemu-tracing.html

http://blog.vmsplice.net/2011/03/how-to-write-trace-analysis-scripts-for.html

Saturday, June 27, 2020

Status of the port of Toro to microvm

Since May I am working on porting TORO to the new microvm machine, which is a simplified QEMU machine with a reduced device model and an improved booting time, among others very interesting features (see https://github.com/qemu/qemu/blob/master/docs/microvm.rst). For Toro, I am interested in removing all the support for legacy hardware and to have virtio-vsocket and virtio-fs working on this kind of machine. I splitted the work into the following items:
1. Compile Toro as a PVH kernel and support PVH configuration during booting
  - Issue #390
  - Issue #391
2. Add support for multicore by identifying cores on the MP table.
  - Issue #392
3. Add support for LAPIC and IOAPIC
 - Issue #395
4. Use KVM clock to get current time
- Issue #366
5. Add mmio transport layer for virtio-vsocket
- Issue #403
6. Add mmio transport layer for virtio-fs
- Issue #404
Work items from 1 to 4 are already implemented. These were tasks that removed support for legacy hardware like 8259 and the CMOS. IRQs are now handled by the LAPIC and the IOAPIC. The issues 5 and 6 mainly add support for the virtio-mmio transport layer for these drivers. The detection of mmio devices is simpler than by using PCI. The information about virtio-devices is passed in the kernel command line. The driver has to parse the kernel command line and gets the base address and the irq base. The driver for virtio-vsocket has been already ported. I am currently working on porting the driver for virtio-fs. I hope this work is finished in about a month. Stay tuned! 

Matias E. Vara Larsen