Skip to content

Commit e645535

Browse files
committed
tracing: Add option to use memmapped memory for trace boot instance
Add an option to the trace_instance kernel command line parameter that allows it to use the reserved memory from memmap boot parameter. memmap=12M$0x284500000 trace_instance=boot_mapped@0x284500000:12M The above will reserves 12 megs at the physical address 0x284500000. The second parameter will create a "boot_mapped" instance and use the memory reserved as the memory for the ring buffer. That will create an instance called "boot_mapped": /sys/kernel/tracing/instances/boot_mapped Note, because the ring buffer is using a defined memory ranged, it will act just like a memory mapped ring buffer. It will not have a snapshot buffer, as it can't swap out the buffer. The snapshot files as well as any tracers that uses a snapshot will not be present in the boot_mapped instance. Link: https://lkml.kernel.org/r/[email protected] Cc: [email protected] Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Vincent Donnefort <[email protected]> Cc: Joel Fernandes <[email protected]> Cc: Daniel Bristot de Oliveira <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Vineeth Pillai <[email protected]> Cc: Youssef Esmat <[email protected]> Cc: Beau Belgrave <[email protected]> Cc: Alexander Graf <[email protected]> Cc: Baoquan He <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: "Paul E. McKenney" <[email protected]> Cc: David Howells <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Tony Luck <[email protected]> Cc: Guenter Roeck <[email protected]> Cc: Ross Zwisler <[email protected]> Cc: Kees Cook <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 5f3b6e8 commit e645535

File tree

2 files changed

+78
-6
lines changed

2 files changed

+78
-6
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6754,6 +6754,15 @@
67546754
the same thing would happen if it was left off). The irq_handler_entry
67556755
event, and all events under the "initcall" system.
67566756

6757+
If memory has been reserved (see memmap for x86), the instance
6758+
can use that memory:
6759+
6760+
memmap=12M$0x284500000 trace_instance=boot_map@0x284500000:12M
6761+
6762+
The above will create a "boot_map" instance that uses the physical
6763+
memory at 0x284500000 that is 12Megs. The per CPU buffers of that
6764+
instance will be split up accordingly.
6765+
67576766
trace_options=[option-list]
67586767
[FTRACE] Enable or disable tracer options at boot.
67596768
The option-list is a comma delimited list of options

kernel/trace/trace.c

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9504,6 +9504,31 @@ static int instance_mkdir(const char *name)
95049504
return ret;
95059505
}
95069506

9507+
static u64 map_pages(u64 start, u64 size)
9508+
{
9509+
struct page **pages;
9510+
phys_addr_t page_start;
9511+
unsigned int page_count;
9512+
unsigned int i;
9513+
void *vaddr;
9514+
9515+
page_count = DIV_ROUND_UP(size, PAGE_SIZE);
9516+
9517+
page_start = start;
9518+
pages = kmalloc_array(page_count, sizeof(struct page *), GFP_KERNEL);
9519+
if (!pages)
9520+
return 0;
9521+
9522+
for (i = 0; i < page_count; i++) {
9523+
phys_addr_t addr = page_start + i * PAGE_SIZE;
9524+
pages[i] = pfn_to_page(addr >> PAGE_SHIFT);
9525+
}
9526+
vaddr = vmap(pages, page_count, VM_MAP, PAGE_KERNEL);
9527+
kfree(pages);
9528+
9529+
return (u64)(unsigned long)vaddr;
9530+
}
9531+
95079532
/**
95089533
* trace_array_get_by_name - Create/Lookup a trace array, given its name.
95099534
* @name: The name of the trace array to be looked up/created.
@@ -10350,6 +10375,7 @@ __init static void enable_instances(void)
1035010375
{
1035110376
struct trace_array *tr;
1035210377
char *curr_str;
10378+
char *name;
1035310379
char *str;
1035410380
char *tok;
1035510381

@@ -10358,19 +10384,56 @@ __init static void enable_instances(void)
1035810384
str = boot_instance_info;
1035910385

1036010386
while ((curr_str = strsep(&str, "\t"))) {
10387+
unsigned long start = 0;
10388+
unsigned long size = 0;
10389+
unsigned long addr = 0;
1036110390

1036210391
tok = strsep(&curr_str, ",");
10392+
name = strsep(&tok, "@");
10393+
if (tok) {
10394+
start = memparse(tok, &tok);
10395+
if (!start) {
10396+
pr_warn("Tracing: Invalid boot instance address for %s\n",
10397+
name);
10398+
continue;
10399+
}
10400+
}
1036310401

10364-
if (IS_ENABLED(CONFIG_TRACER_MAX_TRACE))
10365-
do_allocate_snapshot(tok);
10402+
if (start) {
10403+
if (*tok != ':') {
10404+
pr_warn("Tracing: No size specified for instance %s\n", name);
10405+
continue;
10406+
}
10407+
tok++;
10408+
size = memparse(tok, &tok);
10409+
if (!size) {
10410+
pr_warn("Tracing: Invalid boot instance size for %s\n",
10411+
name);
10412+
continue;
10413+
}
10414+
addr = map_pages(start, size);
10415+
if (addr) {
10416+
pr_info("Tracing: mapped boot instance %s at physical memory 0x%lx of size 0x%lx\n",
10417+
name, start, size);
10418+
} else {
10419+
pr_warn("Tracing: Failed to map boot instance %s\n", name);
10420+
continue;
10421+
}
10422+
} else {
10423+
/* Only non mapped buffers have snapshot buffers */
10424+
if (IS_ENABLED(CONFIG_TRACER_MAX_TRACE))
10425+
do_allocate_snapshot(name);
10426+
}
1036610427

10367-
tr = trace_array_get_by_name(tok, NULL);
10428+
tr = trace_array_create_systems(name, NULL, addr, size);
1036810429
if (!tr) {
10369-
pr_warn("Failed to create instance buffer %s\n", curr_str);
10430+
pr_warn("Tracing: Failed to create instance buffer %s\n", curr_str);
1037010431
continue;
1037110432
}
10372-
/* Allow user space to delete it */
10373-
trace_array_put(tr);
10433+
10434+
/* Only allow non mapped buffers to be deleted */
10435+
if (!start)
10436+
trace_array_put(tr);
1037410437

1037510438
while ((tok = strsep(&curr_str, ","))) {
1037610439
early_enable_events(tr, tok, true);

0 commit comments

Comments
 (0)