Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 121166
b: refs/heads/master
c: 1d926f2
h: refs/heads/master
v: v3
  • Loading branch information
Will Newton authored and Ingo Molnar committed Nov 23, 2008
1 parent 49cb660 commit fc46021
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 120 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: 0429149fb5e01edc410648591c19095d2074ee00
refs/heads/master: 1d926f2756392c6909f60e0c9fe2a09d5462e376
20 changes: 7 additions & 13 deletions trunk/include/asm-generic/vmlinux.lds.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,16 @@
#endif

#ifdef CONFIG_TRACE_BRANCH_PROFILING
#define LIKELY_PROFILE() VMLINUX_SYMBOL(__start_annotated_branch_profile) = .; \
*(_ftrace_annotated_branch) \
VMLINUX_SYMBOL(__stop_annotated_branch_profile) = .;
#define LIKELY_PROFILE() VMLINUX_SYMBOL(__start_likely_profile) = .; \
*(_ftrace_likely) \
VMLINUX_SYMBOL(__stop_likely_profile) = .; \
VMLINUX_SYMBOL(__start_unlikely_profile) = .; \
*(_ftrace_unlikely) \
VMLINUX_SYMBOL(__stop_unlikely_profile) = .;
#else
#define LIKELY_PROFILE()
#endif

#ifdef CONFIG_PROFILE_ALL_BRANCHES
#define BRANCH_PROFILE() VMLINUX_SYMBOL(__start_branch_profile) = .; \
*(_ftrace_branch) \
VMLINUX_SYMBOL(__stop_branch_profile) = .;
#else
#define BRANCH_PROFILE()
#endif

/* .data section */
#define DATA_DATA \
*(.data) \
Expand All @@ -80,8 +75,7 @@
VMLINUX_SYMBOL(__start___tracepoints) = .; \
*(__tracepoints) \
VMLINUX_SYMBOL(__stop___tracepoints) = .; \
LIKELY_PROFILE() \
BRANCH_PROFILE()
LIKELY_PROFILE()

#define RO_DATA(align) \
. = ALIGN((align)); \
Expand Down
64 changes: 23 additions & 41 deletions trunk/include/linux/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,8 @@ struct ftrace_branch_data {
const char *func;
const char *file;
unsigned line;
union {
struct {
unsigned long correct;
unsigned long incorrect;
};
struct {
unsigned long miss;
unsigned long hit;
};
};
unsigned long correct;
unsigned long incorrect;
};

/*
Expand All @@ -85,18 +77,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
#define likely_notrace(x) __builtin_expect(!!(x), 1)
#define unlikely_notrace(x) __builtin_expect(!!(x), 0)

#define __branch_check__(x, expect) ({ \
#define likely_check(x) ({ \
int ______r; \
static struct ftrace_branch_data \
__attribute__((__aligned__(4))) \
__attribute__((section("_ftrace_annotated_branch"))) \
__attribute__((section("_ftrace_likely"))) \
______f = { \
.func = __func__, \
.file = __FILE__, \
.line = __LINE__, \
}; \
______f.line = __LINE__; \
______r = likely_notrace(x); \
ftrace_likely_update(&______f, ______r, expect); \
ftrace_likely_update(&______f, ______r, 1); \
______r; \
})
#define unlikely_check(x) ({ \
int ______r; \
static struct ftrace_branch_data \
__attribute__((__aligned__(4))) \
__attribute__((section("_ftrace_unlikely"))) \
______f = { \
.func = __func__, \
.file = __FILE__, \
.line = __LINE__, \
}; \
______f.line = __LINE__; \
______r = unlikely_notrace(x); \
ftrace_likely_update(&______f, ______r, 0); \
______r; \
})

Expand All @@ -106,37 +114,11 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
* written by Daniel Walker.
*/
# ifndef likely
# define likely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 1))
# define likely(x) (__builtin_constant_p(x) ? !!(x) : likely_check(x))
# endif
# ifndef unlikely
# define unlikely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 0))
# define unlikely(x) (__builtin_constant_p(x) ? !!(x) : unlikely_check(x))
# endif

#ifdef CONFIG_PROFILE_ALL_BRANCHES
/*
* "Define 'is'", Bill Clinton
* "Define 'if'", Steven Rostedt
*/
#define if(cond) if (__builtin_constant_p((cond)) ? !!(cond) : \
({ \
int ______r; \
static struct ftrace_branch_data \
__attribute__((__aligned__(4))) \
__attribute__((section("_ftrace_branch"))) \
______f = { \
.func = __func__, \
.file = __FILE__, \
.line = __LINE__, \
}; \
______r = !!(cond); \
if (______r) \
______f.hit++; \
else \
______f.miss++; \
______r; \
}))
#endif /* CONFIG_PROFILE_ALL_BRANCHES */

#else
# define likely(x) __builtin_expect(!!(x), 1)
# define unlikely(x) __builtin_expect(!!(x), 0)
Expand Down
2 changes: 1 addition & 1 deletion trunk/init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ int do_one_initcall(initcall_t fn)
disable_boot_trace();
rettime = ktime_get();
delta = ktime_sub(rettime, calltime);
ret.duration = (unsigned long long) delta.tv64 >> 10;
ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10;
trace_boot_ret(&ret, fn);
printk("initcall %pF returned %d after %Ld usecs\n", fn,
ret.result, ret.duration);
Expand Down
19 changes: 2 additions & 17 deletions trunk/kernel/trace/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -166,29 +166,14 @@ config TRACE_BRANCH_PROFILING
This tracer profiles all the the likely and unlikely macros
in the kernel. It will display the results in:

/debugfs/tracing/profile_annotated_branch
/debugfs/tracing/profile_likely
/debugfs/tracing/profile_unlikely

Note: this will add a significant overhead, only turn this
on if you need to profile the system's use of these macros.

Say N if unsure.

config PROFILE_ALL_BRANCHES
bool "Profile all if conditionals"
depends on TRACE_BRANCH_PROFILING
help
This tracer profiles all branch conditions. Every if ()
taken in the kernel is recorded whether it hit or miss.
The results will be displayed in:

/debugfs/tracing/profile_branch

This configuration, when enabled, will impose a great overhead
on the system. This should only be enabled when the system
is to be analyzed

Say N if unsure.

config TRACING_BRANCHES
bool
help
Expand Down
74 changes: 27 additions & 47 deletions trunk/kernel/trace/trace_branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,12 @@ EXPORT_SYMBOL(ftrace_likely_update);
struct ftrace_pointer {
void *start;
void *stop;
int hit;
};

static void *
t_next(struct seq_file *m, void *v, loff_t *pos)
{
const struct ftrace_pointer *f = m->private;
struct ftrace_pointer *f = m->private;
struct ftrace_branch_data *p = v;

(*pos)++;
Expand Down Expand Up @@ -224,17 +223,13 @@ static void t_stop(struct seq_file *m, void *p)

static int t_show(struct seq_file *m, void *v)
{
const struct ftrace_pointer *fp = m->private;
struct ftrace_branch_data *p = v;
const char *f;
long percent;
unsigned long percent;

if (v == (void *)1) {
if (fp->hit)
seq_printf(m, " miss hit %% ");
else
seq_printf(m, " correct incorrect %% ");
seq_printf(m, " Function "
seq_printf(m, " correct incorrect %% "
" Function "
" File Line\n"
" ------- --------- - "
" -------- "
Expand All @@ -248,20 +243,13 @@ static int t_show(struct seq_file *m, void *v)
f--;
f++;

/*
* The miss is overlayed on correct, and hit on incorrect.
*/
if (p->correct) {
percent = p->incorrect * 100;
percent /= p->correct + p->incorrect;
} else
percent = p->incorrect ? 100 : -1;
percent = p->incorrect ? 100 : 0;

seq_printf(m, "%8lu %8lu ", p->correct, p->incorrect);
if (percent < 0)
seq_printf(m, " X ");
else
seq_printf(m, "%3ld ", percent);
seq_printf(m, "%8lu %8lu %3lu ", p->correct, p->incorrect, percent);
seq_printf(m, "%-30.30s %-20.20s %d\n", p->func, f, p->line);
return 0;
}
Expand All @@ -273,7 +261,7 @@ static struct seq_operations tracing_likely_seq_ops = {
.show = t_show,
};

static int tracing_branch_open(struct inode *inode, struct file *file)
static int tracing_likely_open(struct inode *inode, struct file *file)
{
int ret;

Expand All @@ -286,30 +274,25 @@ static int tracing_branch_open(struct inode *inode, struct file *file)
return ret;
}

static const struct file_operations tracing_branch_fops = {
.open = tracing_branch_open,
static struct file_operations tracing_likely_fops = {
.open = tracing_likely_open,
.read = seq_read,
.llseek = seq_lseek,
};

#ifdef CONFIG_PROFILE_ALL_BRANCHES
extern unsigned long __start_branch_profile[];
extern unsigned long __stop_branch_profile[];
extern unsigned long __start_likely_profile[];
extern unsigned long __stop_likely_profile[];
extern unsigned long __start_unlikely_profile[];
extern unsigned long __stop_unlikely_profile[];

static const struct ftrace_pointer ftrace_branch_pos = {
.start = __start_branch_profile,
.stop = __stop_branch_profile,
.hit = 1,
static struct ftrace_pointer ftrace_likely_pos = {
.start = __start_likely_profile,
.stop = __stop_likely_profile,
};

#endif /* CONFIG_PROFILE_ALL_BRANCHES */

extern unsigned long __start_annotated_branch_profile[];
extern unsigned long __stop_annotated_branch_profile[];

static const struct ftrace_pointer ftrace_annotated_branch_pos = {
.start = __start_annotated_branch_profile,
.stop = __stop_annotated_branch_profile,
static struct ftrace_pointer ftrace_unlikely_pos = {
.start = __start_unlikely_profile,
.stop = __stop_unlikely_profile,
};

static __init int ftrace_branch_init(void)
Expand All @@ -319,21 +302,18 @@ static __init int ftrace_branch_init(void)

d_tracer = tracing_init_dentry();

entry = debugfs_create_file("profile_annotated_branch", 0444, d_tracer,
(void *)&ftrace_annotated_branch_pos,
&tracing_branch_fops);
entry = debugfs_create_file("profile_likely", 0444, d_tracer,
&ftrace_likely_pos,
&tracing_likely_fops);
if (!entry)
pr_warning("Could not create debugfs "
"'profile_annotatet_branch' entry\n");
pr_warning("Could not create debugfs 'profile_likely' entry\n");

#ifdef CONFIG_PROFILE_ALL_BRANCHES
entry = debugfs_create_file("profile_branch", 0444, d_tracer,
(void *)&ftrace_branch_pos,
&tracing_branch_fops);
entry = debugfs_create_file("profile_unlikely", 0444, d_tracer,
&ftrace_unlikely_pos,
&tracing_likely_fops);
if (!entry)
pr_warning("Could not create debugfs"
" 'profile_branch' entry\n");
#endif
" 'profile_unlikely' entry\n");

return 0;
}
Expand Down

0 comments on commit fc46021

Please sign in to comment.