Full Analysis of QEMU Source Code 12 - Introduction to QOM (1)

Continued from the previous article: QEMU source code full analysis 11 - define a QEMU module (3)

References for the content of this article:

"Interesting Talk about Linux Operating System " —— Liu Chao, Geek Time

" QEMU /KVM" source code analysis and application - Li Qiang, Machinery Industry Press

Thank you very much!

The type_init function was analyzed in depth a few times ago, and finally a concept was introduced by the type_register_internal function: QOM. This article describes it in detail.

As mentioned last time, the full name of QOM is QEMU Object Model. As the name suggests, this is an abstraction layer over QEMU objects. Generally speaking, an object is a concept in object-oriented programming languages ​​such as C++ and Java. Object-oriented ideas include encapsulation, inheritance, and polymorphism, which can better organize and design programs in large-scale projects. Although both the Linux kernel and QEMU are C language projects, it can be seen from the code that they are full of object-oriented ideas. The embodiment of this idea in QEMU is QOM.

QEMU's code is full of objects, especially device simulations, such as network cards, graphics cards, sound cards, serial ports, etc., are abstracted through objects. QOM basically realizes the characteristics of inheritance, encapsulation and polymorphism in C language. For example, a network card is a class whose parent class is a PCI device class, and the parent class of this PCI device class is a device class, which means inheritance. Through QOM, QEMU can abstract and manage various resources in it (referring to QEMU) (such as device creation, configuration, and destruction in device simulation). QOM is also used for the abstraction of various backend components (such as MemoryRegion, Machine, etc.). It is no exaggeration to say that QOM is all over the QEMU code.

To understand QOM, you first need to understand the difference between types and objects. A type represents a category, and an object represents a specific object of that category. For example, if "-device edu,id-edu1, -device edu,id=edu2" is specified in the QEMU command line, edu itself is a category (or a class), and edu1 and edu2 are created by the class. two objects. The whole operation of QOM includes three parts, namely type registration, type initialization and object initialization. The functions involved in the three parts are shown in the figure:

The registration of types is the functions mentioned in the previous articles, and the remaining parts will be mentioned one by one later.

For an in-depth and detailed analysis of all aspects involved in QOM, please read the next (several) chapters.

Guess you like

Origin blog.csdn.net/phmatthaus/article/details/131943825