Skip to content

Commit ea70b4d

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 <[email protected]>
1 parent 1802b70 commit ea70b4d

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
@@ -83,6 +83,7 @@
8383
* x21 primary_entry() .. start_kernel() FDT pointer passed at boot in x0
8484
*/
8585
SYM_CODE_START(primary_entry)
86+
bl trap_to_vmm
8687
bl record_mmu_state
8788
bl preserve_boot_args
8889

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

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

drivers/tty/serial/amba-pl011.c

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

2824+
pl011_debug_addr = (char __iomem *)base;
2825+
pl011_debug_addr += UART011_IO_DEBUG;
2826+
has_pl011 = 1;
2827+
28242828
index = pl011_probe_dt_alias(index, dev);
28252829

28262830
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
@@ -105,6 +105,7 @@
105105
#include <linux/pidfs.h>
106106
#include <linux/ptdump.h>
107107
#include <net/net_namespace.h>
108+
#include <linux/amba/serial.h>
108109

109110
#include <asm/io.h>
110111
#include <asm/setup.h>
@@ -116,6 +117,8 @@
116117

117118
#include <kunit/test.h>
118119

120+
char __iomem *pl011_debug_addr;
121+
int has_pl011 = 0;
119122
static int kernel_init(void *);
120123

121124
/*
@@ -1504,6 +1507,11 @@ static int __ref kernel_init(void *unused)
15041507
outb(0x41, 0x80);
15051508
#endif
15061509

1510+
#ifdef CONFIG_ARM64
1511+
if (has_pl011)
1512+
pl011_debug_trap(DEBUG_TRAP_VAL_END_BOOT);
1513+
#endif
1514+
15071515
if (ramdisk_execute_command) {
15081516
ret = run_init_process(ramdisk_execute_command);
15091517
if (!ret)

0 commit comments

Comments
 (0)