System: Ubuntu 14.04 Kernel 4.10.12
So I'm in the process of trying to understand how to use ftrace, but something I noticed is derailing me a bit:
available_filter_functions can be used to filter what's being traced to certain functions. But the function I'm trying to trace (in this case, KSM's main worker function ksm_do_scan) isn't showing up in the list.
Here is the list of available functions (filtered by ksm-functions):
root@test:/sys/kernel/debug/tracing# cat available_filter_functions | grep
ksm
ksm_memory_callback
break_ksm
unmerge_ksm_pages
get_ksm_page
try_to_merge_with_ksm_page
ksm_scan_thread (calls ksm_do_scan)
__ksm_enter
ksm_madvise
__ksm_exit
ksm_might_need_to_copy
rmap_walk_ksm
ksm_migrate_page
And here is what ksm_do_scan looks like:
static void ksm_do_scan(unsigned int scan_npages)
{
struct rmap_item *rmap_item;
struct page *uninitialized_var(page);
while (scan_npages-- && likely(!freezing(current))) {
cond_resched();
rmap_item = scan_get_next_rmap_item(&page);
if (!rmap_item)
return;
cmp_and_merge_page(page, rmap_item);
put_page(page);
}
}
I tested this on another system that had been setup with Kernel version 4.4.0-31, and ksm_do_scan() showed up on the list of available_filter_functions (even though it had the same code as the 4.10.12 version). So I figured it must have something to do with how The 4.10.12 Kernel was configured, but I'm not sure. All of recommended .config options that I've seen so far are enabled:
CONFIG_FUNCTION_TRACER=y
CONFIG_FUNCTION_GRAPH_TRACER=y
CONFIG_STACK_TRACER=y
CONFIG_DYNAMIC_FTRACE=y
Finally, I know that ftrace blacklists functions that are annotated with __init and __devinit because kernel init functions are loaded during initialization and removed when initialization is done, but ksm_do_scan doesn't contain either of those annotations.
Is there a specific way to write functions so that they are recognized by ftrace as available_filter_functions (that my be kernel version specific)?