> For the complete documentation index, see [llms.txt](https://richardweiyang-2.gitbook.io/understanding_qemu/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://richardweiyang-2.gitbook.io/understanding_qemu/00-vcpu/01-type_cpu.md).

# TYPE\_CPU

Qemu中所有CPU类型都有一个父类TYPE\_CPU。所以研究这个结构是开展后续研究的基础。

## 继承关系

按照老规矩，我们还是先看一下类型的继承层次关系。

```
  TYPE_OBJECT
  +-------------------------------+
  |class_init                     | = object_class_init
  |                               |
  |instance_size                  | = sizeof(Object)
  +-------------------------------+


  TYPE_DEVICE
  +-------------------------------+
  |class_size                     | = sizeof(DeviceClass)
  |class_init                     | = device_class_init
  |                               |
  |instance_size                  | = sizeof(Object)
  |instance_init                  | = device_initfn
  |instance_finalize              | = device_finalize
  |                               |
  |realize                        | = cpu_common_realizefn
  +-------------------------------+


  TYPE_CPU
  +-------------------------------+
  |class_size                     | = sizeof(CPUClass)
  |class_init                     | = cpu_class_init
  |                               |
  |instance_size                  | = sizeof(CPUState)
  |instance_init                  | = cpu_common_initfn
  |instance_finalize              | = cpu_common_finalize
  +-------------------------------+
```

可以看到，TYPE\_CPU是TYPE\_DEVICE的子类，也就是CPU类型的初始化遵从[Device类型初始化的方法](/understanding_qemu/00-devices/04-deviceclass_instance.md)。

大家可以看到realize函数也被我着重标出了。

## 初始化

针对TYPE\_CPU，我们能看到的初始化过程就是普通的类型初始化的流程，以及Device类型realize时所做的工作。

具体的工作流程将根据不同的CPU类型而有所不同，还需要按照不同的CPU和Machine类型来处理。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://richardweiyang-2.gitbook.io/understanding_qemu/00-vcpu/01-type_cpu.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
