Skip to content

Commit cda1c67

Browse files
jongwulikebreath
authored andcommitted
debug: enable kernel boot up time measurement
To measure kernel boot up time, reserved region in pl011 is used as trap MMIO region to record kernel boot timestamp. For now, we trap at 2 point: the first is nearly the first instruction of kernel start; the second is just before call the init bin for userspace. These 2 points can cover the whole kernel boot time. If there is no pl011, the first write is still there but the second won't happen. Signed-off-by: Jianyong Wu <[email protected]>
1 parent 44b63c0 commit cda1c67

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

arch/arm64/kernel/head.S

+16
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
* x28 create_idmap() callee preserved temp register
8787
*/
8888
SYM_CODE_START(primary_entry)
89+
bl trap_to_vmm
8990
bl preserve_boot_args
9091
bl init_kernel_el // w0=cpu_boot_mode
9192
mov x20, x0
@@ -109,6 +110,21 @@ SYM_CODE_START(primary_entry)
109110
b __primary_switch
110111
SYM_CODE_END(primary_entry)
111112

113+
/*
114+
* By writing to mmio region, trap to vmm to print timestamp,
115+
* but corrupt x7 and x8.
116+
* 0x9000f00 is debug region of pl011
117+
* 0x40 is the code specified in cloud hypervisor indicating the first debug
118+
* point of kernel.
119+
*/
120+
SYM_CODE_START(trap_to_vmm)
121+
movz x7, 0x0900, lsl 16
122+
add x7, x7, 0xf00
123+
mov x8, 0x40
124+
str w8, [x7]
125+
ret
126+
SYM_CODE_END(trap_to_vmm)
127+
112128
/*
113129
* Preserve the arguments passed by the bootloader in x0 .. x3
114130
*/

drivers/tty/serial/amba-pl011.c

+4
Original file line numberDiff line numberDiff line change
@@ -2730,6 +2730,10 @@ static int pl011_setup_port(struct device *dev, struct uart_amba_port *uap,
27302730
if (IS_ERR(base))
27312731
return PTR_ERR(base);
27322732

2733+
pl011_debug_addr = (char __iomem *)base;
2734+
pl011_debug_addr += UART011_IO_DEBUG;
2735+
has_pl011 = 1;
2736+
27332737
index = pl011_probe_dt_alias(index, dev);
27342738

27352739
uap->port.dev = dev;

include/linux/amba/serial.h

+12
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@
206206
#define UART01x_RSR_ANY (UART01x_RSR_OE|UART01x_RSR_BE|UART01x_RSR_PE|UART01x_RSR_FE)
207207
#define UART01x_FR_MODEM_ANY (UART01x_FR_DCD|UART01x_FR_DSR|UART01x_FR_CTS)
208208

209+
#define UART011_IO_DEBUG 0xf00 /* used for debug I/O port emulation in VM */
210+
209211
#ifndef __ASSEMBLY__
210212
struct amba_device; /* in uncompress this is included but amba/bus.h is not */
211213
struct amba_pl010_data {
@@ -225,4 +227,14 @@ struct amba_pl011_data {
225227
};
226228
#endif
227229

230+
extern char __iomem *pl011_debug_addr; /* save the pl011 debug mmio address, equal to base + UART011_IO_DEBUG */
231+
extern int has_pl011;
232+
#define DEBUG_TRAP_VAL_END_BOOT 0x41 /* debug point at the end of kernel boot */
233+
234+
/* wrapper of tricking pl011 debug */
235+
static inline void pl011_debug_trap(char val)
236+
{
237+
writeb_relaxed(val, pl011_debug_addr);
238+
}
239+
228240
#endif

init/main.c

+8
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
#include <linux/stackdepot.h>
103103
#include <linux/randomize_kstack.h>
104104
#include <net/net_namespace.h>
105+
#include <linux/amba/serial.h>
105106

106107
#include <asm/io.h>
107108
#include <asm/bugs.h>
@@ -114,6 +115,8 @@
114115

115116
#include <kunit/test.h>
116117

118+
char __iomem *pl011_debug_addr;
119+
int has_pl011 = 0;
117120
static int kernel_init(void *);
118121

119122
extern void init_IRQ(void);
@@ -1552,6 +1555,11 @@ static int __ref kernel_init(void *unused)
15521555
outb(0x41, 0x80);
15531556
#endif
15541557

1558+
#ifdef CONFIG_ARM64
1559+
if (has_pl011)
1560+
pl011_debug_trap(DEBUG_TRAP_VAL_END_BOOT);
1561+
#endif
1562+
15551563
if (ramdisk_execute_command) {
15561564
ret = run_init_process(ramdisk_execute_command);
15571565
if (!ret)

0 commit comments

Comments
 (0)