Skip to content

Commit f8b40f6

Browse files
authored
Merge pull request #9 from jongwu/bench-arm
Debug: enable kernel boot up time measurement
2 parents cc6c5f4 + 00377a5 commit f8b40f6

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

arch/arm64/kernel/head.S

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
* x24 __primary_switch() .. relocate_kernel() current RELR displacement
9090
*/
9191
SYM_CODE_START(primary_entry)
92+
bl trap_to_vmm
9293
bl preserve_boot_args
9394
bl init_kernel_el // w0=cpu_boot_mode
9495
adrp x23, __PHYS_OFFSET
@@ -105,6 +106,21 @@ SYM_CODE_START(primary_entry)
105106
b __primary_switch
106107
SYM_CODE_END(primary_entry)
107108

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

drivers/tty/serial/amba-pl011.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444

4545
#include "amba-pl011.h"
4646

47+
char __iomem *pl011_debug_addr;
48+
4749
#define UART_NR 14
4850

4951
#define SERIAL_AMBA_MAJOR 204
@@ -2752,6 +2754,9 @@ static int pl011_setup_port(struct device *dev, struct uart_amba_port *uap,
27522754
if (IS_ERR(base))
27532755
return PTR_ERR(base);
27542756

2757+
pl011_debug_addr = (char __iomem *)base;
2758+
pl011_debug_addr += UART011_IO_DEBUG;
2759+
27552760
index = pl011_probe_dt_alias(index, dev);
27562761

27572762
uap->old_cr = 0;

include/linux/amba/serial.h

Lines changed: 11 additions & 0 deletions
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,13 @@ 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+
#define DEBUG_TRAP_VAL_END_BOOT 0x41 /* debug point at the end of kernel boot */
232+
233+
/* wrapper of tricking pl011 debug */
234+
static inline void pl011_debug_trap(char val)
235+
{
236+
writeb_relaxed(val, pl011_debug_addr);
237+
}
238+
228239
#endif

init/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
#include <linux/kcsan.h>
101101
#include <linux/init_syscalls.h>
102102
#include <linux/stackdepot.h>
103+
#include <linux/amba/serial.h>
103104

104105
#include <asm/io.h>
105106
#include <asm/bugs.h>
@@ -1536,6 +1537,10 @@ static int __ref kernel_init(void *unused)
15361537
outb(0x41, 0x80);
15371538
#endif
15381539

1540+
#ifdef CONFIG_ARM64
1541+
pl011_debug_trap(DEBUG_TRAP_VAL_END_BOOT);
1542+
#endif
1543+
15391544
if (ramdisk_execute_command) {
15401545
ret = run_init_process(ramdisk_execute_command);
15411546
if (!ret)

0 commit comments

Comments
 (0)