| 1 |
.. SPDX-License-Identifier: CC-BY-4.0 |
| 2 |
|
| 3 |
Xen cache coloring user guide |
| 4 |
============================= |
| 5 |
|
| 6 |
The cache coloring support in Xen allows to reserve Last Level Cache (LLC) |
| 7 |
partitions for Dom0, DomUs and Xen itself. Currently only ARM64 is supported. |
| 8 |
Cache coloring realizes per-set cache partitioning in software and is applicable |
| 9 |
to shared LLCs as implemented in Cortex-A53, Cortex-A72 and similar CPUs. |
| 10 |
|
| 11 |
To compile LLC coloring support set ``CONFIG_LLC_COLORING=y``. |
| 12 |
|
| 13 |
If needed, change the maximum number of colors with |
| 14 |
``CONFIG_LLC_COLORS_ORDER=<n>``. |
| 15 |
|
| 16 |
If needed, change the buddy allocator reserved size with |
| 17 |
``CONFIG_BUDDY_ALLOCATOR_SIZE=<n>``. |
| 18 |
|
| 19 |
Runtime configuration is done via `Command line parameters`_. |
| 20 |
For DomUs follow `DomUs configuration`_. |
| 21 |
|
| 22 |
Background |
| 23 |
********** |
| 24 |
|
| 25 |
Cache hierarchy of a modern multi-core CPU typically has first levels dedicated |
| 26 |
to each core (hence using multiple cache units), while the last level is shared |
| 27 |
among all of them. Such configuration implies that memory operations on one |
| 28 |
core (e.g. running a DomU) are able to generate interference on another core |
| 29 |
(e.g. hosting another DomU). Cache coloring realizes per-set cache-partitioning |
| 30 |
in software and mitigates this, guaranteeing more predictable performances for |
| 31 |
memory accesses. |
| 32 |
Software-based cache coloring is particularly useful in those situations where |
| 33 |
no hardware mechanisms (e.g., DSU-based way partitioning) are available to |
| 34 |
partition caches. This is the case for e.g., Cortex-A53, A57 and A72 CPUs that |
| 35 |
feature a L2 LLC cache shared among all cores. |
| 36 |
|
| 37 |
The key concept underlying cache coloring is a fragmentation of the memory |
| 38 |
space into a set of sub-spaces called colors that are mapped to disjoint cache |
| 39 |
partitions. Technically, the whole memory space is first divided into a number |
| 40 |
of subsequent regions. Then each region is in turn divided into a number of |
| 41 |
subsequent sub-colors. The generic i-th color is then obtained by all the |
| 42 |
i-th sub-colors in each region. |
| 43 |
|
| 44 |
:: |
| 45 |
|
| 46 |
Region j Region j+1 |
| 47 |
..................... ............ |
| 48 |
. . . |
| 49 |
. . |
| 50 |
_ _ _______________ _ _____________________ _ _ |
| 51 |
| | | | | | | |
| 52 |
| c_0 | c_1 | | c_n | c_0 | c_1 | |
| 53 |
_ _ _|_____|_____|_ _ _|_____|_____|_____|_ _ _ |
| 54 |
: : |
| 55 |
: :... ... . |
| 56 |
: color 0 |
| 57 |
:........................... ... . |
| 58 |
: |
| 59 |
. . ..................................: |
| 60 |
|
| 61 |
How colors are actually defined depends on the function that maps memory to |
| 62 |
cache lines. In case of physically-indexed, physically-tagged caches with linear |
| 63 |
mapping, the set index is found by extracting some contiguous bits from the |
| 64 |
physical address. This allows colors to be defined as shown in figure: they |
| 65 |
appear in memory as subsequent blocks of equal size and repeats themselves after |
| 66 |
``n`` different colors, where ``n`` is the total number of colors. |
| 67 |
|
| 68 |
If some kind of bit shuffling appears in the mapping function, then colors |
| 69 |
assume a different layout in memory. Those kind of caches aren't supported by |
| 70 |
the current implementation. |
| 71 |
|
| 72 |
**Note**: Finding the exact cache mapping function can be a really difficult |
| 73 |
task since it's not always documented in the CPU manual. As said Cortex-A53, A57 |
| 74 |
and A72 are known to work with the current implementation. |
| 75 |
|
| 76 |
How to compute the number of colors |
| 77 |
################################### |
| 78 |
|
| 79 |
Given the linear mapping from physical memory to cache lines for granted, the |
| 80 |
number of available colors for a specific platform is computed using three |
| 81 |
parameters: |
| 82 |
|
| 83 |
- the size of the LLC. |
| 84 |
- the number of the LLC ways. |
| 85 |
- the page size used by Xen. |
| 86 |
|
| 87 |
The first two parameters can be found in the processor manual, while the third |
| 88 |
one is the minimum mapping granularity. Dividing the cache size by the number of |
| 89 |
its ways we obtain the size of a way. Dividing this number by the page size, |
| 90 |
the number of total cache colors is found. So for example an Arm Cortex-A53 |
| 91 |
with a 16-ways associative 1 MiB LLC can isolate up to 16 colors when pages are |
| 92 |
4 KiB in size. |
| 93 |
|
| 94 |
Effective colors assignment |
| 95 |
########################### |
| 96 |
|
| 97 |
When assigning colors, if one wants to avoid cache interference between two |
| 98 |
domains, different colors needs to be used for their memory. |
| 99 |
|
| 100 |
Command line parameters |
| 101 |
*********************** |
| 102 |
|
| 103 |
Specific documentation is available at `docs/misc/xen-command-line.pandoc`. |
| 104 |
|
| 105 |
+----------------------+-------------------------------+ |
| 106 |
| **Parameter** | **Description** | |
| 107 |
+----------------------+-------------------------------+ |
| 108 |
| ``llc-coloring`` | Enable coloring at runtime | |
| 109 |
+----------------------+-------------------------------+ |
| 110 |
| ``llc-size`` | Set the LLC size | |
| 111 |
+----------------------+-------------------------------+ |
| 112 |
| ``llc-nr-ways`` | Set the LLC number of ways | |
| 113 |
+----------------------+-------------------------------+ |
| 114 |
| ``dom0-llc-colors`` | Dom0 color configuration | |
| 115 |
+----------------------+-------------------------------+ |
| 116 |
| ``buddy-alloc-size`` | Buddy allocator reserved size | |
| 117 |
+----------------------+-------------------------------+ |
| 118 |
| ``xen-llc-colors`` | Xen color configuration | |
| 119 |
+----------------------+-------------------------------+ |
| 120 |
|
| 121 |
Colors selection format |
| 122 |
*********************** |
| 123 |
|
| 124 |
Regardless of the memory pool that has to be colored (Xen, Dom0/DomUs), |
| 125 |
the color selection can be expressed using the same syntax. In particular a |
| 126 |
comma-separated list of colors or ranges of colors is used. |
| 127 |
Ranges are hyphen-separated intervals (such as `0-4`) and are inclusive on both |
| 128 |
sides. |
| 129 |
|
| 130 |
Note that: |
| 131 |
|
| 132 |
- no spaces are allowed between values. |
| 133 |
- no overlapping ranges or duplicated colors are allowed. |
| 134 |
- values must be written in ascending order. |
| 135 |
|
| 136 |
Examples: |
| 137 |
|
| 138 |
+-------------------+-----------------------------+ |
| 139 |
| **Configuration** | **Actual selection** | |
| 140 |
+-------------------+-----------------------------+ |
| 141 |
| 1-2,5-8 | [1, 2, 5, 6, 7, 8] | |
| 142 |
+-------------------+-----------------------------+ |
| 143 |
| 4-8,10,11,12 | [4, 5, 6, 7, 8, 10, 11, 12] | |
| 144 |
+-------------------+-----------------------------+ |
| 145 |
| 0 | [0] | |
| 146 |
+-------------------+-----------------------------+ |
| 147 |
|
| 148 |
Auto-probing of LLC specs |
| 149 |
######################### |
| 150 |
|
| 151 |
LLC size and number of ways are probed automatically by default. |
| 152 |
|
| 153 |
In the Arm implementation, this is done by inspecting the CLIDR_EL1 register. |
| 154 |
This means that other system caches that aren't visible there are ignored. |
| 155 |
|
| 156 |
LLC specs can be manually set via the above command line parameters. This |
| 157 |
bypasses any auto-probing and it's used to overcome failing situations, such as |
| 158 |
flawed probing logic, or for debugging/testing purposes. |
| 159 |
|
| 160 |
DomUs configuration |
| 161 |
******************* |
| 162 |
|
| 163 |
DomUs colors can be set either in the ``xl`` configuration file (documentation |
| 164 |
at `docs/man/xl.cfg.pod.5.in`) or via Device Tree (documentation at |
| 165 |
`docs/misc/arm/device-tree/booting.txt`) using the ``llc-colors`` option. |
| 166 |
For example: |
| 167 |
|
| 168 |
:: |
| 169 |
|
| 170 |
xen,xen-bootargs = "console=dtuart dtuart=serial0 dom0_mem=1G dom0_max_vcpus=1 sched=null llc-coloring=on dom0-llc-colors=2-6"; |
| 171 |
xen,dom0-bootargs "console=hvc0 earlycon=xen earlyprintk=xen root=/dev/ram0" |
| 172 |
|
| 173 |
dom0 { |
| 174 |
compatible = "xen,linux-zimage" "xen,multiboot-module"; |
| 175 |
reg = <0x0 0x1000000 0x0 15858176>; |
| 176 |
}; |
| 177 |
|
| 178 |
dom0-ramdisk { |
| 179 |
compatible = "xen,linux-initrd" "xen,multiboot-module"; |
| 180 |
reg = <0x0 0x2000000 0x0 20638062>; |
| 181 |
}; |
| 182 |
|
| 183 |
domU0 { |
| 184 |
#address-cells = <0x1>; |
| 185 |
#size-cells = <0x1>; |
| 186 |
compatible = "xen,domain"; |
| 187 |
memory = <0x0 0x40000>; |
| 188 |
llc-colors = "4-8,10,11,12"; |
| 189 |
cpus = <0x1>; |
| 190 |
vpl011 = <0x1>; |
| 191 |
|
| 192 |
module@2000000 { |
| 193 |
compatible = "multiboot,kernel", "multiboot,module"; |
| 194 |
reg = <0x2000000 0xffffff>; |
| 195 |
bootargs = "console=ttyAMA0"; |
| 196 |
}; |
| 197 |
|
| 198 |
module@30000000 { |
| 199 |
compatible = "multiboot,ramdisk", "multiboot,module"; |
| 200 |
reg = <0x3000000 0xffffff>; |
| 201 |
}; |
| 202 |
}; |
| 203 |
|
| 204 |
**Note:** If no color configuration is provided for a domain, the default one, |
| 205 |
which corresponds to all available colors is used instead. |
| 206 |
|
| 207 |
Colored allocator and buddy allocator |
| 208 |
************************************* |
| 209 |
|
| 210 |
The colored allocator distributes pages based on color configurations of |
| 211 |
domains so that each domains only gets pages of its own colors. |
| 212 |
The colored allocator is meant as an alternative to the buddy allocator because |
| 213 |
its allocation policy is by definition incompatible with the generic one. Since |
| 214 |
the Xen heap is not colored yet, we need to support the coexistence of the two |
| 215 |
allocators and some memory must be left for the buddy one. Buddy memory |
| 216 |
reservation is configured via Kconfig or via command-line. |
| 217 |
|
| 218 |
Known issues and limitations |
| 219 |
**************************** |
| 220 |
|
| 221 |
"xen,static-mem" isn't supported when coloring is enabled |
| 222 |
######################################################### |
| 223 |
|
| 224 |
In the domain configuration, "xen,static-mem" allows memory to be statically |
| 225 |
allocated to the domain. This isn't possible when LLC coloring is enabled, |
| 226 |
because that memory can't be guaranteed to use only colors assigned to the |
| 227 |
domain. |
| 228 |
|
| 229 |
Cache coloring is intended only for embedded systems |
| 230 |
#################################################### |
| 231 |
|
| 232 |
The current implementation aims to satisfy the need of predictability in |
| 233 |
embedded systems with small amount of memory to be managed in a colored way. |
| 234 |
Given that, some shortcuts are taken in the development. Expect worse |
| 235 |
performances on larger systems. |
| 236 |
|
| 237 |
Colored allocator can only make use of order-0 pages |
| 238 |
#################################################### |
| 239 |
|
| 240 |
The cache coloring technique relies on memory mappings and on the smallest |
| 241 |
mapping granularity to achieve the maximum number of colors (cache partitions) |
| 242 |
possible. This granularity is what is normally called a page and, in Xen |
| 243 |
terminology, the order-0 page is the smallest one. The fairly simple |
| 244 |
colored allocator currently implemented, makes use only of such pages. |
| 245 |
It must be said that a more complex one could, in theory, adopt higher order |
| 246 |
pages if the colors selection contained adjacent colors. Two subsequent colors, |
| 247 |
for example, can be represented by an order-1 page, four colors correspond to |
| 248 |
an order-2 page, etc. |