Skip to content

Commit 6e85551

Browse files
jongwurbradford
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 <jianyong.wu@arm.com>
1 parent 35f589d commit 6e85551

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

arch/arm64/kernel/head.S

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
* x21 primary_entry() .. start_kernel() FDT pointer passed at boot in x0
8383
*/
8484
SYM_CODE_START(primary_entry)
85+
bl trap_to_vmm
8586
bl record_mmu_state
8687
bl preserve_boot_args
8788

@@ -163,6 +164,21 @@ CPU_BE( tbz x19, #SCTLR_ELx_EE_SHIFT, 1f )
163164
ret
164165
SYM_CODE_END(record_mmu_state)
165166

167+
/*
168+
* By writing to mmio region, trap to vmm to print timestamp,
169+
* but corrupt x7 and x8.
170+
* 0x9000f00 is debug region of pl011
171+
* 0x40 is the code specified in cloud hypervisor indicating the first debug
172+
* point of kernel.
173+
*/
174+
SYM_CODE_START(trap_to_vmm)
175+
movz x7, 0x0900, lsl 16
176+
add x7, x7, 0xf00
177+
mov x8, 0x40
178+
str w8, [x7]
179+
ret
180+
SYM_CODE_END(trap_to_vmm)
181+
166182
/*
167183
* Preserve the arguments passed by the bootloader in x0 .. x3
168184
*/

drivers/tty/serial/amba-pl011.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,6 +2709,10 @@ static int pl011_setup_port(struct device *dev, struct uart_amba_port *uap,
27092709
if (IS_ERR(base))
27102710
return PTR_ERR(base);
27112711

2712+
pl011_debug_addr = (char __iomem *)base;
2713+
pl011_debug_addr += UART011_IO_DEBUG;
2714+
has_pl011 = 1;
2715+
27122716
index = pl011_probe_dt_alias(index, dev);
27132717

27142718
uap->port.dev = dev;

include/linux/amba/serial.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@
215215
#define UART01x_RSR_ANY (UART01x_RSR_OE | UART01x_RSR_BE | UART01x_RSR_PE | UART01x_RSR_FE)
216216
#define UART01x_FR_MODEM_ANY (UART01x_FR_DCD | UART01x_FR_DSR | UART01x_FR_CTS)
217217

218+
#define UART011_IO_DEBUG 0xf00 /* used for debug I/O port emulation in VM */
219+
218220
#ifndef __ASSEMBLY__
219221
struct amba_device; /* in uncompress this is included but amba/bus.h is not */
220222
struct amba_pl010_data {
@@ -234,4 +236,14 @@ struct amba_pl011_data {
234236
};
235237
#endif
236238

239+
extern char __iomem *pl011_debug_addr; /* save the pl011 debug mmio address, equal to base + UART011_IO_DEBUG */
240+
extern int has_pl011;
241+
#define DEBUG_TRAP_VAL_END_BOOT 0x41 /* debug point at the end of kernel boot */
242+
243+
/* wrapper of tricking pl011 debug */
244+
static inline void pl011_debug_trap(char val)
245+
{
246+
writeb_relaxed(val, pl011_debug_addr);
247+
}
248+
237249
#endif

init/main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
#include <linux/pidfs.h>
104104
#include <linux/ptdump.h>
105105
#include <net/net_namespace.h>
106+
#include <linux/amba/serial.h>
106107

107108
#include <asm/io.h>
108109
#include <asm/setup.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
/*
@@ -1499,6 +1502,11 @@ static int __ref kernel_init(void *unused)
14991502
outb(0x41, 0x80);
15001503
#endif
15011504

1505+
#ifdef CONFIG_ARM64
1506+
if (has_pl011)
1507+
pl011_debug_trap(DEBUG_TRAP_VAL_END_BOOT);
1508+
#endif
1509+
15021510
if (ramdisk_execute_command) {
15031511
ret = run_init_process(ramdisk_execute_command);
15041512
if (!ret)

0 commit comments

Comments
 (0)