/* * Arbitrary large value chosen to be sufficiently large to minimize noise but * sufficiently small to complete quickly.
*/ staticunsignedint nr_function_calls = 100000;
module_param(nr_function_calls, uint, 0);
MODULE_PARM_DESC(nr_function_calls, "How many times to call the relevant tracee");
/* * The number of ops associated with a call site affects whether a tracer can * be called directly or whether it's necessary to go via the list func, which * can be significantly more expensive.
*/ staticunsignedint nr_ops_relevant = 1;
module_param(nr_ops_relevant, uint, 0);
MODULE_PARM_DESC(nr_ops_relevant, "How many ftrace_ops to associate with the relevant tracee");
/* * On architectures where all call sites share the same trampoline, having * tracers enabled for distinct functions can force the use of the list func * and incur overhead for all call sites.
*/ staticunsignedint nr_ops_irrelevant;
module_param(nr_ops_irrelevant, uint, 0);
MODULE_PARM_DESC(nr_ops_irrelevant, "How many ftrace_ops to associate with the irrelevant tracee");
/* * On architectures with DYNAMIC_FTRACE_WITH_REGS, saving the full pt_regs can * be more expensive than only saving the minimal necessary regs.
*/ staticbool save_regs;
module_param(save_regs, bool, 0);
MODULE_PARM_DESC(save_regs, "Register ops with FTRACE_OPS_FL_SAVE_REGS (save all registers in the trampoline)");
staticbool assist_recursion;
module_param(assist_recursion, bool, 0);
MODULE_PARM_DESC(assist_reursion, "Register ops with FTRACE_OPS_FL_RECURSION");
staticbool assist_rcu;
module_param(assist_rcu, bool, 0);
MODULE_PARM_DESC(assist_reursion, "Register ops with FTRACE_OPS_FL_RCU");
/* * By default, a trivial tracer is used which immediately returns to mimimize * overhead. Sometimes a consistency check using a more expensive tracer is * desireable.
*/ staticbool check_count;
module_param(check_count, bool, 0);
MODULE_PARM_DESC(check_count, "Check that tracers are called the expected number of times\n");
/* * Usually it's not interesting to leave the ops registered after the test * runs, but sometimes it can be useful to leave them registered so that they * can be inspected through the tracefs 'enabled_functions' file.
*/ staticbool persist;
module_param(persist, bool, 0);
MODULE_PARM_DESC(persist, "Successfully load module and leave ftrace ops registered after test completes\n");
/* * Marked as noinline to ensure that an out-of-line traceable copy is * generated by the compiler. * * The barrier() ensures the compiler won't elide calls by determining there * are no side-effects.
*/ static noinline void tracee_relevant(void)
{
barrier();
}
/* * Marked as noinline to ensure that an out-of-line traceable copy is * generated by the compiler. * * The barrier() ensures the compiler won't elide calls by determining there * are no side-effects.
*/ static noinline void tracee_irrelevant(void)
{
barrier();
}
ops = kcalloc(nr, sizeof(*ops), GFP_KERNEL); if (WARN_ON_ONCE(!ops)) return NULL;
for (unsignedint i = 0; i < nr; i++) {
ops[i].ops.func = func;
ops[i].ops.flags = flags;
WARN_ON_ONCE(ftrace_set_filter_ip(&ops[i].ops, (unsignedlong)tracee, 0, 0));
WARN_ON_ONCE(register_ftrace_function(&ops[i].ops));
}
return ops;
}
staticvoid ops_destroy(struct sample_ops *ops, int nr)
{ if (!ops) return;
for (unsignedint i = 0; i < nr; i++) {
WARN_ON_ONCE(unregister_ftrace_function(&ops[i].ops));
ftrace_free_filter(&ops[i].ops);
}
kfree(ops);
}
staticvoid ops_check(struct sample_ops *ops, int nr, unsignedint expected_count)
{ if (!ops || !check_count) return;
for (unsignedint i = 0; i < nr; i++) { if (ops->count == expected_count) continue;
pr_warn("Counter called %u times (expected %u)\n",
ops->count, expected_count);
}
}
/* * The benchmark completed sucessfully, but there's no reason to keep * the module around. Return an error do the user doesn't have to * manually unload the module.
*/ return -EINVAL;
}
module_init(ftrace_ops_sample_init);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.