Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 304964
b: refs/heads/master
c: bb27f55
h: refs/heads/master
v: v3
  • Loading branch information
Ingo Molnar committed May 21, 2012
1 parent b250fda commit ad42f5f
Show file tree
Hide file tree
Showing 8 changed files with 447 additions and 219 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 5e1c81d98a5621007824b49dde556fead5ff9c6c
refs/heads/master: bb27f55eb9405257a59c82550dbb0d684cc3a665
15 changes: 2 additions & 13 deletions trunk/arch/x86/kernel/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ static void run_sync(void)
local_irq_disable();
}

static void ftrace_replace_code(int enable)
void ftrace_replace_code(int enable)
{
struct ftrace_rec_iter *iter;
struct dyn_ftrace *rec;
Expand Down Expand Up @@ -493,18 +493,7 @@ void arch_ftrace_update_code(int command)
{
modifying_ftrace_code++;

if (command & FTRACE_UPDATE_CALLS)
ftrace_replace_code(1);
else if (command & FTRACE_DISABLE_CALLS)
ftrace_replace_code(0);

if (command & FTRACE_UPDATE_TRACE_FUNC)
ftrace_update_ftrace_func(ftrace_trace_function);

if (command & FTRACE_START_FUNC_RET)
ftrace_enable_ftrace_graph_caller();
else if (command & FTRACE_STOP_FUNC_RET)
ftrace_disable_ftrace_graph_caller();
ftrace_modify_all_code(command);

modifying_ftrace_code--;
}
Expand Down
2 changes: 1 addition & 1 deletion trunk/include/asm-generic/vmlinux.lds.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@
CPU_DISCARD(init.data) \
MEM_DISCARD(init.data) \
KERNEL_CTORS() \
*(.init.rodata) \
MCOUNT_REC() \
*(.init.rodata) \
FTRACE_EVENTS() \
TRACE_SYSCALLS() \
DEV_DISCARD(init.rodata) \
Expand Down
5 changes: 4 additions & 1 deletion trunk/include/linux/ftrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ struct dyn_ftrace *ftrace_rec_iter_record(struct ftrace_rec_iter *iter);
int ftrace_update_record(struct dyn_ftrace *rec, int enable);
int ftrace_test_record(struct dyn_ftrace *rec, int enable);
void ftrace_run_stop_machine(int command);
int ftrace_location(unsigned long ip);
unsigned long ftrace_location(unsigned long ip);

extern ftrace_func_t ftrace_trace_function;

Expand All @@ -314,11 +314,14 @@ ftrace_set_early_filter(struct ftrace_ops *ops, char *buf, int enable);
/* defined in arch */
extern int ftrace_ip_converted(unsigned long ip);
extern int ftrace_dyn_arch_init(void *data);
extern void ftrace_replace_code(int enable);
extern int ftrace_update_ftrace_func(ftrace_func_t func);
extern void ftrace_caller(void);
extern void ftrace_call(void);
extern void mcount_call(void);

void ftrace_modify_all_code(int command);

#ifndef FTRACE_ADDR
#define FTRACE_ADDR ((unsigned long)ftrace_caller)
#endif
Expand Down
1 change: 0 additions & 1 deletion trunk/kernel/trace/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ if FTRACE
config FUNCTION_TRACER
bool "Kernel Function Tracer"
depends on HAVE_FUNCTION_TRACER
select FRAME_POINTER if !ARM_UNWIND && !PPC && !S390 && !MICROBLAZE
select KALLSYMS
select GENERIC_TRACER
select CONTEXT_SWITCH_TRACER
Expand Down
198 changes: 107 additions & 91 deletions trunk/kernel/trace/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1383,44 +1383,73 @@ ftrace_ops_test(struct ftrace_ops *ops, unsigned long ip)

static int ftrace_cmp_recs(const void *a, const void *b)
{
const struct dyn_ftrace *reca = a;
const struct dyn_ftrace *recb = b;
const struct dyn_ftrace *key = a;
const struct dyn_ftrace *rec = b;

if (reca->ip > recb->ip)
return 1;
if (reca->ip < recb->ip)
if (key->flags < rec->ip)
return -1;
if (key->ip >= rec->ip + MCOUNT_INSN_SIZE)
return 1;
return 0;
}

/**
* ftrace_location - return true if the ip giving is a traced location
* @ip: the instruction pointer to check
*
* Returns 1 if @ip given is a pointer to a ftrace location.
* That is, the instruction that is either a NOP or call to
* the function tracer. It checks the ftrace internal tables to
* determine if the address belongs or not.
*/
int ftrace_location(unsigned long ip)
static unsigned long ftrace_location_range(unsigned long start, unsigned long end)
{
struct ftrace_page *pg;
struct dyn_ftrace *rec;
struct dyn_ftrace key;

key.ip = ip;
key.ip = start;
key.flags = end; /* overload flags, as it is unsigned long */

for (pg = ftrace_pages_start; pg; pg = pg->next) {
if (end < pg->records[0].ip ||
start >= (pg->records[pg->index - 1].ip + MCOUNT_INSN_SIZE))
continue;
rec = bsearch(&key, pg->records, pg->index,
sizeof(struct dyn_ftrace),
ftrace_cmp_recs);
if (rec)
return 1;
return rec->ip;
}

return 0;
}

/**
* ftrace_location - return true if the ip giving is a traced location
* @ip: the instruction pointer to check
*
* Returns rec->ip if @ip given is a pointer to a ftrace location.
* That is, the instruction that is either a NOP or call to
* the function tracer. It checks the ftrace internal tables to
* determine if the address belongs or not.
*/
unsigned long ftrace_location(unsigned long ip)
{
return ftrace_location_range(ip, ip);
}

/**
* ftrace_text_reserved - return true if range contains an ftrace location
* @start: start of range to search
* @end: end of range to search (inclusive). @end points to the last byte to check.
*
* Returns 1 if @start and @end contains a ftrace location.
* That is, the instruction that is either a NOP or call to
* the function tracer. It checks the ftrace internal tables to
* determine if the address belongs or not.
*/
int ftrace_text_reserved(void *start, void *end)
{
unsigned long ret;

ret = ftrace_location_range((unsigned long)start,
(unsigned long)end);

return (int)!!ret;
}

static void __ftrace_hash_rec_update(struct ftrace_ops *ops,
int filter_hash,
bool inc)
Expand Down Expand Up @@ -1520,35 +1549,6 @@ static void ftrace_hash_rec_enable(struct ftrace_ops *ops,
__ftrace_hash_rec_update(ops, filter_hash, 1);
}

static struct dyn_ftrace *ftrace_alloc_dyn_node(unsigned long ip)
{
if (ftrace_pages->index == ftrace_pages->size) {
/* We should have allocated enough */
if (WARN_ON(!ftrace_pages->next))
return NULL;
ftrace_pages = ftrace_pages->next;
}

return &ftrace_pages->records[ftrace_pages->index++];
}

static struct dyn_ftrace *
ftrace_record_ip(unsigned long ip)
{
struct dyn_ftrace *rec;

if (ftrace_disabled)
return NULL;

rec = ftrace_alloc_dyn_node(ip);
if (!rec)
return NULL;

rec->ip = ip;

return rec;
}

static void print_ip_ins(const char *fmt, unsigned char *p)
{
int i;
Expand Down Expand Up @@ -1598,21 +1598,6 @@ void ftrace_bug(int failed, unsigned long ip)
}
}


/* Return 1 if the address range is reserved for ftrace */
int ftrace_text_reserved(void *start, void *end)
{
struct dyn_ftrace *rec;
struct ftrace_page *pg;

do_for_each_ftrace_rec(pg, rec) {
if (rec->ip <= (unsigned long)end &&
rec->ip + MCOUNT_INSN_SIZE > (unsigned long)start)
return 1;
} while_for_each_ftrace_rec();
return 0;
}

static int ftrace_check_record(struct dyn_ftrace *rec, int enable, int update)
{
unsigned long flag = 0UL;
Expand Down Expand Up @@ -1698,7 +1683,7 @@ __ftrace_replace_code(struct dyn_ftrace *rec, int enable)
return -1; /* unknow ftrace bug */
}

static void ftrace_replace_code(int update)
void __weak ftrace_replace_code(int enable)
{
struct dyn_ftrace *rec;
struct ftrace_page *pg;
Expand All @@ -1708,7 +1693,7 @@ static void ftrace_replace_code(int update)
return;

do_for_each_ftrace_rec(pg, rec) {
failed = __ftrace_replace_code(rec, update);
failed = __ftrace_replace_code(rec, enable);
if (failed) {
ftrace_bug(failed, rec->ip);
/* Stop processing */
Expand Down Expand Up @@ -1826,22 +1811,27 @@ int __weak ftrace_arch_code_modify_post_process(void)
return 0;
}

static int __ftrace_modify_code(void *data)
void ftrace_modify_all_code(int command)
{
int *command = data;

if (*command & FTRACE_UPDATE_CALLS)
if (command & FTRACE_UPDATE_CALLS)
ftrace_replace_code(1);
else if (*command & FTRACE_DISABLE_CALLS)
else if (command & FTRACE_DISABLE_CALLS)
ftrace_replace_code(0);

if (*command & FTRACE_UPDATE_TRACE_FUNC)
if (command & FTRACE_UPDATE_TRACE_FUNC)
ftrace_update_ftrace_func(ftrace_trace_function);

if (*command & FTRACE_START_FUNC_RET)
if (command & FTRACE_START_FUNC_RET)
ftrace_enable_ftrace_graph_caller();
else if (*command & FTRACE_STOP_FUNC_RET)
else if (command & FTRACE_STOP_FUNC_RET)
ftrace_disable_ftrace_graph_caller();
}

static int __ftrace_modify_code(void *data)
{
int *command = data;

ftrace_modify_all_code(*command);

return 0;
}
Expand Down Expand Up @@ -3666,22 +3656,36 @@ static __init int ftrace_init_dyn_debugfs(struct dentry *d_tracer)
return 0;
}

static void ftrace_swap_recs(void *a, void *b, int size)
static int ftrace_cmp_ips(const void *a, const void *b)
{
const unsigned long *ipa = a;
const unsigned long *ipb = b;

if (*ipa > *ipb)
return 1;
if (*ipa < *ipb)
return -1;
return 0;
}

static void ftrace_swap_ips(void *a, void *b, int size)
{
struct dyn_ftrace *reca = a;
struct dyn_ftrace *recb = b;
struct dyn_ftrace t;
unsigned long *ipa = a;
unsigned long *ipb = b;
unsigned long t;

t = *reca;
*reca = *recb;
*recb = t;
t = *ipa;
*ipa = *ipb;
*ipb = t;
}

static int ftrace_process_locs(struct module *mod,
unsigned long *start,
unsigned long *end)
{
struct ftrace_page *start_pg;
struct ftrace_page *pg;
struct dyn_ftrace *rec;
unsigned long count;
unsigned long *p;
unsigned long addr;
Expand All @@ -3693,8 +3697,11 @@ static int ftrace_process_locs(struct module *mod,
if (!count)
return 0;

pg = ftrace_allocate_pages(count);
if (!pg)
sort(start, count, sizeof(*start),
ftrace_cmp_ips, ftrace_swap_ips);

start_pg = ftrace_allocate_pages(count);
if (!start_pg)
return -ENOMEM;

mutex_lock(&ftrace_lock);
Expand All @@ -3707,7 +3714,7 @@ static int ftrace_process_locs(struct module *mod,
if (!mod) {
WARN_ON(ftrace_pages || ftrace_pages_start);
/* First initialization */
ftrace_pages = ftrace_pages_start = pg;
ftrace_pages = ftrace_pages_start = start_pg;
} else {
if (!ftrace_pages)
goto out;
Expand All @@ -3718,11 +3725,11 @@ static int ftrace_process_locs(struct module *mod,
ftrace_pages = ftrace_pages->next;
}

ftrace_pages->next = pg;
ftrace_pages = pg;
ftrace_pages->next = start_pg;
}

p = start;
pg = start_pg;
while (p < end) {
addr = ftrace_call_adjust(*p++);
/*
Expand All @@ -3733,17 +3740,26 @@ static int ftrace_process_locs(struct module *mod,
*/
if (!addr)
continue;
if (!ftrace_record_ip(addr))
break;

if (pg->index == pg->size) {
/* We should have allocated enough */
if (WARN_ON(!pg->next))
break;
pg = pg->next;
}

rec = &pg->records[pg->index++];
rec->ip = addr;
}

/* These new locations need to be initialized */
ftrace_new_pgs = pg;
/* We should have used all pages */
WARN_ON(pg->next);

/* Make each individual set of pages sorted by ips */
for (; pg; pg = pg->next)
sort(pg->records, pg->index, sizeof(struct dyn_ftrace),
ftrace_cmp_recs, ftrace_swap_recs);
/* Assign the last page to ftrace_pages */
ftrace_pages = pg;

/* These new locations need to be initialized */
ftrace_new_pgs = start_pg;

/*
* We only need to disable interrupts on start up
Expand Down
Loading

0 comments on commit ad42f5f

Please sign in to comment.