Skip to content

Commit bf88e24

Browse files
mgcaodbkinder
authored andcommitted
DOC: add main vcpu API & data structure into HLD.
add main vcpu API and data structure for doc auto-generated info into HLD. Tracked-On: #1595 Signed-off-by: Minggui Cao <minggui.cao@intel.com>
1 parent c885011 commit bf88e24

File tree

2 files changed

+53
-145
lines changed

2 files changed

+53
-145
lines changed

doc/acrn.doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,10 +798,10 @@ INPUT = custom-doxygen/mainpage.md \
798798
../hypervisor/include/common/hypercall.h \
799799
../hypervisor/include/public/acrn_common.h \
800800
../hypervisor/include/public/acrn_hv_defs.h \
801+
../hypervisor/include/arch/x86/guest/vcpu.h \
801802
../hypervisor/arch/x86/trusty.c \
802803
../devicemodel/include/virtio.h
803804

804-
805805
# This tag can be used to specify the character encoding of the source files
806806
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
807807
# libiconv (or the iconv built into libc) for the transcoding. See the libiconv

doc/developer-guides/hld/hv-cpu-virt.rst

Lines changed: 52 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,8 @@ The VHM will respond to the ioctl:
125125
The hypercall ``HC_CREATE_VCPU`` is handled in the hypervisor with
126126
the parameter:
127127

128-
.. code-block:: c
129-
130-
struct acrn_create_vcpu {
131-
/** the virtual CPU ID for the VCPU created */
132-
uint16_t vcpu_id;
133-
/** the physical CPU ID for the VCPU created */
134-
uint16_t pcpu_id;
135-
} __attribute__((aligned(8)));
128+
.. doxygenstruct:: acrn_create_vcpu
129+
:project: Project ACRN
136130

137131
CPU assignment management in HV
138132
===============================
@@ -187,43 +181,26 @@ the major states are:
187181

188182
ACRN vCPU state transitions
189183

190-
This table shows the functions which drive the state machine of the vCPU
184+
Following functions are used to drive the state machine of the vCPU
191185
lifecycle:
192186

193-
.. list-table::
194-
:widths: 20 80
195-
:header-rows: 1
196-
197-
* - **Function**
198-
- **Description**
199-
200-
* - create_vcpu
201-
- Creates/allocates a vCPU instance, with initialization for its
202-
vcpu_id, vpid, vmcs, vlapic, etc. It sets the init vCPU state
203-
to VCPU_INIT.
204-
205-
* - schedule_vcpu
206-
- Adds a vCPU into the run queue and make a reschedule request for it.
207-
It sets the vCPU state to VCPU_RUNNING.
187+
.. doxygenfunction:: create_vcpu
188+
:project: Project ACRN
208189

209-
* - pause_vcpu
210-
- Change a vCPU state to VCPU_PAUSED or VCPU_ZOMBIE, and make a
211-
reschedule request for it.
190+
.. doxygenfunction:: schedule_vcpu
191+
:project: Project ACRN
212192

213-
* - resume_vcpu
214-
- Change a vCPU state to VCPU_RUNNING, and make a reschedule request
215-
for it.
193+
.. doxygenfunction:: pause_vcpu
194+
:project: Project ACRN
216195

217-
* - reset_vcpu
218-
- Reset all fields in a vCPU instance, the vCPU state is reset to
219-
VCPU_INIT.
196+
.. doxygenfunction:: resume_vcpu
197+
:project: Project ACRN
220198

221-
* - destroy_vcpu
222-
- Destroy/free a vCPU instance.
199+
.. doxygenfunction:: reset_vcpu
200+
:project: Project ACRN
223201

224-
* - start/run_vcpu
225-
- An interface in vCPU thread to implement VM entry and VM exit.
226-
A CPU switches between VMX root mode and non-root mode based on it.
202+
.. doxygenfunction:: run_vcpu
203+
:project: Project ACRN
227204

228205

229206
vCPU Scheduling
@@ -322,37 +299,8 @@ vCPU Run Context
322299
During a vCPU switch between root and non-root mode, the run context of
323300
the vCPU is saved and restored using this structure:
324301

325-
.. code-block:: c
326-
327-
struct run_context {
328-
/* Contains the guest register set.
329-
* NOTE: This must be the first element in the structure, so that
330-
* the offsets in vmx_asm.S match
331-
*/
332-
union {
333-
struct cpu_gp_regs regs;
334-
uint64_t longs[NUM_GPRS];
335-
} guest_cpu_regs;
336-
337-
/* The guests CR registers 0, 2, 3 and 4. */
338-
uint64_t cr0;
339-
340-
/* CPU_CONTEXT_OFFSET_CR2 =
341-
* offsetof(struct run_context, cr2) = 136
342-
*/
343-
uint64_t cr2;
344-
uint64_t cr4;
345-
346-
uint64_t rip;
347-
uint64_t rflags;
348-
349-
/* CPU_CONTEXT_OFFSET_IA32_SPEC_CTRL =
350-
* offsetof(struct run_context, ia32_spec_ctrl) = 168
351-
*/
352-
uint64_t ia32_spec_ctrl;
353-
uint64_t ia32_efer;
354-
};
355-
302+
.. doxygenstruct:: run_context
303+
:project: Project ACRN
356304

357305
The vCPU handles runtime context saving by three different
358306
categories:
@@ -385,54 +333,53 @@ categories:
385333

386334
For the first two categories above, ACRN provides these get/set APIs:
387335

388-
.. list-table::
389-
:widths: 30 70
390-
:header-rows: 1
336+
.. doxygenfunction:: vcpu_get_gpreg
337+
:project: Project ACRN
391338

392-
* - **APIs**
393-
- **Desc**
339+
.. doxygenfunction:: vcpu_set_gpreg
340+
:project: Project ACRN
394341

395-
* - vcpu_get_gpreg
396-
- Get target vCPU's general purpose registers value in run_context
342+
.. doxygenfunction:: vcpu_get_rip
343+
:project: Project ACRN
397344

398-
* - vcpu_set_gpreg
399-
- Set target vCPU's general purpose registers value in run_context
345+
.. doxygenfunction:: vcpu_set_rip
346+
:project: Project ACRN
400347

401-
* - vcpu_get_rip
402-
- Get & cache target vCPU's RIP in run_context
348+
.. doxygenfunction:: vcpu_get_rsp
349+
:project: Project ACRN
403350

404-
* - vcpu_set_rip
405-
- Update target vCPU's RIP in run_context
351+
.. doxygenfunction:: vcpu_set_rsp
352+
:project: Project ACRN
406353

407-
* - vcpu_get_rsp
408-
- Get & cache target vCPU's RSP in run_context
354+
.. doxygenfunction:: vcpu_get_efer
355+
:project: Project ACRN
409356

410-
* - vcpu_set_rsp
411-
- Update target vCPU's RSP in run_context
357+
.. doxygenfunction:: vcpu_set_efer
358+
:project: Project ACRN
412359

413-
* - vcpu_get_efer
414-
- Get & cache target vCPU's EFER in run_context
360+
.. doxygenfunction:: vcpu_get_rflags
361+
:project: Project ACRN
415362

416-
* - vcpu_set_efer
417-
- Update target vCPU's EFER in run_context
363+
.. doxygenfunction:: vcpu_set_rflags
364+
:project: Project ACRN
418365

419-
* - vcpu_get_rflags
420-
- Get & cache target vCPU's RFLAGS in run_context
366+
.. doxygenfunction:: vcpu_get_cr0
367+
:project: Project ACRN
421368

422-
* - vcpu_set_rflags
423-
- Update target vCPU's RFLAGS in run_context
369+
.. doxygenfunction:: vcpu_set_cr0
370+
:project: Project ACRN
424371

425-
* - vcpu_get_cr2
426-
- Get target vCPU's CR2 register value in run_context
372+
.. doxygenfunction:: vcpu_get_cr2
373+
:project: Project ACRN
427374

428-
* - vcpu_set_cr2
429-
- Set target vCPU's CR2 register value in run_context
375+
.. doxygenfunction:: vcpu_set_cr2
376+
:project: Project ACRN
430377

431-
* - vcpu_get_cr0/4
432-
- Get & cache target vCPU's CR0/4 register in run_context
378+
.. doxygenfunction:: vcpu_get_cr4
379+
:project: Project ACRN
433380

434-
* - vcpu_set_cr0/4
435-
- Update target vCPU's CR0/4 register in run_context
381+
.. doxygenfunction:: vcpu_set_cr4
382+
:project: Project ACRN
436383

437384

438385
VM Exit Handlers
@@ -646,49 +593,10 @@ For a guest vCPU's state initialization:
646593
- UOS BSP: DM context initialization through hypercall
647594

648595
- If it's AP, then it will always start from real mode, and the start
649-
vector will always come from vlapic INIT-SIPI emulation. So there
650-
is no need for *boot_ctx*. Instead we use a static guest state setting
651-
pre-defined for real mode.
652-
653-
.. code-block:: c
654-
655-
struct acrn_vcpu_state {
656-
struct acrn_gp_regs gprs;
657-
struct acrn_dt_desc gdt;
658-
uint64_t rip;
659-
uint64_t cs_base;
660-
uint64_t cr0;
661-
uint64_t cr4;
662-
uint64_t reserved_64[4];
663-
664-
uint32_t cs_ar;
665-
uint32_t reserved_32[4];
666-
667-
/* don't change the order of following sel */
668-
uint16_t cs_sel;
669-
uint16_t ss_sel;
670-
uint16_t ds_sel;
671-
uint16_t es_sel;
672-
uint16_t fs_sel;
673-
uint16_t gs_sel;
674-
675-
uint16_t reserved_16[4];
676-
};
677-
678-
struct boot_ctx {
679-
struct acrn_vcpu_state vcpu_state;
680-
struct acrn_dt_desc idt;
681-
uint64_t cr3;
682-
uint64_t ia32_efer;
683-
uint64_t rflags;
684-
685-
void *rsdp;
686-
void *ap_trampoline_buf;
687-
688-
uint16_t ldt_sel;
689-
uint16_t tr_sel;
690-
}__attribute__((aligned(8)));
596+
vector will always come from vlapic INIT-SIPI emulation.
691597

598+
.. doxygenstruct:: acrn_vcpu_regs
599+
:project: Project ACRN
692600

693601
.. list-table::
694602
:widths: 20 40 10 30

0 commit comments

Comments
 (0)