]> rtime.felk.cvut.cz Git - jailhouse.git/commitdiff
inmates: x86: Add optional cache pollution to apic-demo
authorJan Kiszka <jan.kiszka@siemens.com>
Mon, 4 Jan 2016 10:31:49 +0000 (11:31 +0100)
committerJan Kiszka <jan.kiszka@siemens.com>
Sat, 9 Jan 2016 09:56:44 +0000 (10:56 +0100)
When "pollute_cache" is specified as command line parameter of the
apic-demo, the demo will fill each cache line with a pattern in each
measurement loop. Up to 512 KB of cache can be polluted this way.

This allows to test L3 cache partitioning features of recent Intel CPUs:
The cache pollution will dirty the L1 and L2 data caches so that the
next loop iteration will access L3. If that cache is shared, latencies
will rise as other cells use the cache as well.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
inmates/demos/x86/apic-demo.c

index 8df3bb5cc1d6b62d9291ffe80323df4768edfdf5..57f897536c55598ee40747b2817e1a532627f18e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Jailhouse, a Linux-based partitioning hypervisor
  *
- * Copyright (c) Siemens AG, 2013
+ * Copyright (c) Siemens AG, 2013-2016
  *
  * Authors:
  *  Jan Kiszka <jan.kiszka@siemens.com>
 
 #include <inmate.h>
 
+#define CMDLINE_BUFFER_SIZE    256
+CMDLINE_BUFFER(CMDLINE_BUFFER_SIZE);
+
+#define POLLUTE_CACHE_SIZE     (512 * 1024)
+
 #ifdef CONFIG_UART_OXPCIE952
 #define UART_BASE              0xe010
 #else
@@ -58,11 +63,26 @@ static void init_apic(void)
        asm volatile("sti");
 }
 
+static void pollute_cache(void)
+{
+       char *mem = (char *)HEAP_BASE;
+       unsigned long cpu_cache_line_size, ebx;
+       unsigned long n;
+
+       asm volatile("cpuid" : "=b" (ebx) : "a" (1)
+               : "rcx", "rdx", "memory");
+       cpu_cache_line_size = (ebx & 0xff00) >> 5;
+
+       for (n = 0; n < POLLUTE_CACHE_SIZE; n += cpu_cache_line_size)
+               mem[n] ^= 0xAA;
+}
+
 void inmate_main(void)
 {
        bool allow_terminate = false;
        bool terminate = false;
        unsigned long tsc_freq;
+       bool cache_pollution;
        unsigned int n;
 
        printk_uart_base = UART_BASE;
@@ -74,6 +94,10 @@ void inmate_main(void)
 
        comm_region->cell_state = JAILHOUSE_CELL_RUNNING_LOCKED;
 
+       cache_pollution = cmdline_parse_bool("pollute_cache");
+       if (cache_pollution)
+               printk("Cache pollution enabled\n");
+
        tsc_freq = tsc_init();
        printk("Calibrated TSC frequency: %lu.%03u kHz\n", tsc_freq / 1000,
               tsc_freq % 1000);
@@ -83,6 +107,9 @@ void inmate_main(void)
        while (!terminate) {
                asm volatile("hlt");
 
+               if (cache_pollution)
+                       pollute_cache();
+
                switch (comm_region->msg_to_cell) {
                case JAILHOUSE_MSG_SHUTDOWN_REQUEST:
                        if (!allow_terminate) {