Skip to content

Commit 9d15dbb

Browse files
mhiramatrostedt
authored andcommitted
tracing/boot: Add cpu_mask option support
Add ftrace.cpumask option support to boot-time tracing. This sets cpumask for each instance. - ftrace.[instance.INSTANCE.]cpumask = CPUMASK; Set the trace cpumask. Note that the CPUMASK should be a string which <tracefs>/tracing_cpumask can accepts. Link: http://lkml.kernel.org/r/157867243625.17873.13613922641273149372.stgit@devnote2 Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 4f712a4 commit 9d15dbb

2 files changed

Lines changed: 43 additions & 13 deletions

File tree

‎kernel/trace/trace.c‎

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4561,20 +4561,13 @@ tracing_cpumask_read(struct file *filp, char __user *ubuf,
45614561
return count;
45624562
}
45634563

4564-
static ssize_t
4565-
tracing_cpumask_write(struct file *filp, const char __user *ubuf,
4566-
size_t count, loff_t *ppos)
4564+
int tracing_set_cpumask(struct trace_array *tr,
4565+
cpumask_var_t tracing_cpumask_new)
45674566
{
4568-
struct trace_array *tr = file_inode(filp)->i_private;
4569-
cpumask_var_t tracing_cpumask_new;
4570-
int err, cpu;
4571-
4572-
if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL))
4573-
return -ENOMEM;
4567+
int cpu;
45744568

4575-
err = cpumask_parse_user(ubuf, count, tracing_cpumask_new);
4576-
if (err)
4577-
goto err_unlock;
4569+
if (!tr)
4570+
return -EINVAL;
45784571

45794572
local_irq_disable();
45804573
arch_spin_lock(&tr->max_lock);
@@ -4598,11 +4591,34 @@ tracing_cpumask_write(struct file *filp, const char __user *ubuf,
45984591
local_irq_enable();
45994592

46004593
cpumask_copy(tr->tracing_cpumask, tracing_cpumask_new);
4594+
4595+
return 0;
4596+
}
4597+
4598+
static ssize_t
4599+
tracing_cpumask_write(struct file *filp, const char __user *ubuf,
4600+
size_t count, loff_t *ppos)
4601+
{
4602+
struct trace_array *tr = file_inode(filp)->i_private;
4603+
cpumask_var_t tracing_cpumask_new;
4604+
int err;
4605+
4606+
if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL))
4607+
return -ENOMEM;
4608+
4609+
err = cpumask_parse_user(ubuf, count, tracing_cpumask_new);
4610+
if (err)
4611+
goto err_free;
4612+
4613+
err = tracing_set_cpumask(tr, tracing_cpumask_new);
4614+
if (err)
4615+
goto err_free;
4616+
46014617
free_cpumask_var(tracing_cpumask_new);
46024618

46034619
return count;
46044620

4605-
err_unlock:
4621+
err_free:
46064622
free_cpumask_var(tracing_cpumask_new);
46074623

46084624
return err;

‎kernel/trace/trace_boot.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ extern int trace_set_options(struct trace_array *tr, char *option);
1818
extern int tracing_set_tracer(struct trace_array *tr, const char *buf);
1919
extern ssize_t tracing_resize_ring_buffer(struct trace_array *tr,
2020
unsigned long size, int cpu_id);
21+
extern int tracing_set_cpumask(struct trace_array *tr,
22+
cpumask_var_t tracing_cpumask_new);
2123

2224
static void __init
2325
trace_boot_set_instance_options(struct trace_array *tr, struct xbc_node *node)
@@ -52,6 +54,18 @@ trace_boot_set_instance_options(struct trace_array *tr, struct xbc_node *node)
5254
if (tracing_resize_ring_buffer(tr, v, RING_BUFFER_ALL_CPUS) < 0)
5355
pr_err("Failed to resize trace buffer to %s\n", p);
5456
}
57+
58+
p = xbc_node_find_value(node, "cpumask", NULL);
59+
if (p && *p != '\0') {
60+
cpumask_var_t new_mask;
61+
62+
if (alloc_cpumask_var(&new_mask, GFP_KERNEL)) {
63+
if (cpumask_parse(p, new_mask) < 0 ||
64+
tracing_set_cpumask(tr, new_mask) < 0)
65+
pr_err("Failed to set new CPU mask %s\n", p);
66+
free_cpumask_var(new_mask);
67+
}
68+
}
5569
}
5670

5771
#ifdef CONFIG_EVENT_TRACING

0 commit comments

Comments
 (0)