Skip to content

Commit 01b28c8

Browse files
taoyuhongdbkinder
authored andcommitted
doc: Add tutorial about how to use CAT on UP2
Tracked-On: #2462 Signed-off-by: Tao Yuhong <yuhong.tao@intel.com>
1 parent 79582b9 commit 01b28c8

File tree

3 files changed

+164
-0
lines changed

3 files changed

+164
-0
lines changed

doc/tutorials/images/acrn_cat_hld.png

57.4 KB
Loading
21.2 KB
Loading

doc/tutorials/using_cat_on_up2.rst

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
.. _using_cat_up2:
2+
3+
Using CAT on UP2
4+
################
5+
6+
The UP Squared board `(UP2) <https://up-board.org/upsquared/specifications/>`_
7+
is an x86 maker board based on the Intel Apollo Lake platform and supports
8+
Cache Allocation Technology (CAT). With this feature, the usage of cache can be
9+
restricted to each VM. ACRN hypervisor can do that by giving each VM a cache mask,
10+
so that the VM will not evict the masked cache lines, as shown in :numref:
11+
`cache-mask-vm`:
12+
13+
.. figure:: images/using_cat_up2.png
14+
:align: center
15+
:name: cache-mask-vm
16+
17+
Cache usage with Cache Mask
18+
19+
20+
CAT Support on ACRN
21+
*******************
22+
23+
As described at `Intel (R) 64 and IA-32 Architectures Software Developer’s Manual
24+
<https://software.intel.com/en-us/download/intel-64-and-ia-32-architectures-sdm-combined-volumes-3a-3b-3c-and-3d-system-programming-guide>`_,
25+
chapter 17.19, volume 3. There are 3 steps to use CAT:
26+
27+
1. Detect the CAT capability.
28+
2. Setup cache mask array MSRs, which is referred to as Class of Service (CLOS) array.
29+
3. Select one of the CLOS array for the CPU, that will be the cache mask of the CPU.
30+
31+
ACRN integrates the usage of CAT into VM configuration. The CLOS array must be defined
32+
in the board config source code, and the VM needs to specify which CLOS to use in its VM
33+
config data. If the platform supports CAT, the CLOS array will be written to the CLOS MSRs
34+
at CPU init time, and the VM will set CLOS for VCPU at VM launch time.
35+
The details are shown in :numref:`acrn-cat-hld`:
36+
37+
.. figure:: images/acrn_cat_hld.png
38+
:align: center
39+
:name: acrn-cat-hld
40+
41+
CAT Support on ACRN
42+
43+
Tuning CAT in HV debug shell
44+
############################
45+
46+
From the ACRN HV debug shell, you can use ``cpuid``, ``wrmsr/rdmsr`` debug commands to
47+
enumerate CAT capability and tune CAT parameters. You can use the UP2 board's serial port
48+
for the HV shell (refer to :ref:`getting-started-up2` for setup instructions).
49+
50+
#. Check CAT ability with ``cupid``. First run ``cpuid 0x10 0x0``, the return value ebx[bit 2]
51+
reports the L2 CAT is supported. Then run ``cpuid 0x10 0x2`` to query L2 CAT capability,
52+
the return value eax[bit 4:0] reports the cache mask has 8 bit, and edx[bit 15:0] reports 4 CLOS are
53+
supported, as shown below:
54+
55+
.. code-block:: none
56+
57+
ACRN:\>cpuid 0x10 0x0
58+
cpuid leaf: 0x10, subleaf: 0x0, 0x0:0x4:0x0:0x0
59+
60+
ACRN:\>cpuid 0x10 0x2
61+
cpuid leaf: 0x10, subleaf: 0x2, 0x7:0x0:0x0:0x3
62+
63+
#. Check PCPU IDs of each VM, the ``vcpu_list`` shows that VM0 is running on PCPU0,
64+
and VM1 is running on PCPU1:
65+
66+
.. code-block:: none
67+
68+
ACRN:\>vcpu_list
69+
70+
VM ID PCPU ID VCPU ID VCPU ROLE VCPU STATE
71+
===== ======= ======= ========= ==========
72+
0 0 0 PRIMARY Running
73+
1 1 0 PRIMARY Running
74+
75+
#. Set CLOS with ``wrmsr <reg_num> <value>``, we want VM1 to use the lower 6 ways of cache,
76+
so CLOS0 is set to 0xc0 for the upper 2 ways, and CLOS1 is set to 0x3f for the lower
77+
6 ways:
78+
79+
.. code-block:: none
80+
81+
ACRN:\>wrmsr -p1 0xd10 0xc0
82+
ACRN:\>wrmsr -p1 0xd11 0x3f
83+
84+
#. Attach COS1 to PCPU1. Because MSR IA32_PQR_ASSOC [bit 63:32], we'll write 0x100000000
85+
to it to use CLOS1
86+
87+
.. code-block:: none
88+
89+
ACRN:\>wrmsr –p1 0xc8f 0x100000000
90+
91+
Configure CAT for VM with VM Configuration
92+
##########################################
93+
94+
#. CAT on ACRN can be enabled and configured by modifying source code, so the first
95+
step is to clone the ACRN source code (if you haven't already):
96+
97+
.. code-block:: none
98+
99+
$ git clone https://github.com/projectacrn/acrn-hypervisor.git
100+
$ cd acrn-hypervisor/
101+
102+
#. The predefined cache masks can be found at
103+
``hypervisor/arch/x86/configs/$(CONFIG_BOARD)/board.c``, for UP2 board, that is
104+
``hypervisor/arch/x86/configs/apl-up2/board.c``, you can change the mask values,
105+
but note that the CLOS mask must have continuous bits, or a #GP fault can be triggered.
106+
107+
.. code-block:: none
108+
:emphasize-lines: 3,7,11,15
109+
110+
struct platform_clos_info platform_clos_array[4] = {
111+
{
112+
.clos_mask = 0xff,
113+
.msr_index = MSR_IA32_L2_MASK_0,
114+
},
115+
{
116+
.clos_mask = 0xff,
117+
.msr_index = MSR_IA32_L2_MASK_1,
118+
},
119+
{
120+
.clos_mask = 0xff,
121+
.msr_index = MSR_IA32_L2_MASK_2,
122+
},
123+
{
124+
.clos_mask = 0xff,
125+
.msr_index = MSR_IA32_L2_MASK_3,
126+
},
127+
};
128+
129+
#. Set up CLOS in the VM config. If you want a VM to use one of the CLOSs, you need to find its
130+
configuration data and modify it. We will take SOS on sharing mode as an example. Its
131+
configuration data can be found at ``hypervisor/arch/x86/configs/vm_config.c``
132+
133+
.. code-block:: none
134+
:emphasize-lines: 5,6
135+
136+
struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] __aligned(PAGE_SIZE) = {
137+
{
138+
.type = SOS_VM,
139+
.name = SOS_VM_CONFIG_NAME,
140+
.guest_flags = SOS_VM_CONFIG_GUEST_FLAGS | CLOS_REQUIRED,
141+
.clos = 1,
142+
.memory = {
143+
.start_hpa = 0x0UL,
144+
.size = CONFIG_SOS_RAM_SIZE,
145+
},
146+
.os_config = {
147+
.name = SOS_VM_CONFIG_OS_NAME,
148+
},
149+
},
150+
};
151+
152+
#. Build the ACRN hypervisor and copy the artifact ``acrn.efi`` to the
153+
``/boot/EFI/acrn`` directory, see :ref:`getting-started-building` for building instructions.
154+
155+
.. code-block:: none
156+
157+
$ make hypervisor BOARD=apl-up2 FIRMWARE=uefi
158+
...
159+
160+
# these operations are done on UP2 board
161+
$ mount /dev/mmcblk0p0 /boot
162+
$ scp <acrn.efi-at-your-compile-PC> /boot/EFI/acrn
163+
164+
#. Restart the UP2 board

0 commit comments

Comments
 (0)