Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: (163 commits) tracing: Fix compile issue for trace_sched_wakeup.c [S390] hardirq: remove pointless header file includes [IA64] Move local_softirq_pending() definition perf, powerpc: Fix power_pmu_event_init to not use event->ctx ftrace: Remove recursion between recordmcount and scripts/mod/empty jump_label: Add COND_STMT(), reducer wrappery perf: Optimize sw events perf: Use jump_labels to optimize the scheduler hooks jump_label: Add atomic_t interface jump_label: Use more consistent naming perf, hw_breakpoint: Fix crash in hw_breakpoint creation perf: Find task before event alloc perf: Fix task refcount bugs perf: Fix group moving irq_work: Add generic hardirq context callbacks perf_events: Fix transaction recovery in group_sched_in() perf_events: Fix bogus AMD64 generic TLB events perf_events: Fix bogus context time tracking tracing: Remove parent recording in latency tracer graph options tracing: Use one prologue for the preempt irqs off tracer function tracers ...
This commit is contained in:
+3
-1
@@ -10,7 +10,7 @@ obj-y = sched.o fork.o exec_domain.o panic.o printk.o \
|
||||
kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
|
||||
hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \
|
||||
notifier.o ksysfs.o pm_qos_params.o sched_clock.o cred.o \
|
||||
async.o range.o
|
||||
async.o range.o jump_label.o
|
||||
obj-$(CONFIG_HAVE_EARLY_RES) += early_res.o
|
||||
obj-y += groups.o
|
||||
|
||||
@@ -23,6 +23,7 @@ CFLAGS_REMOVE_rtmutex-debug.o = -pg
|
||||
CFLAGS_REMOVE_cgroup-debug.o = -pg
|
||||
CFLAGS_REMOVE_sched_clock.o = -pg
|
||||
CFLAGS_REMOVE_perf_event.o = -pg
|
||||
CFLAGS_REMOVE_irq_work.o = -pg
|
||||
endif
|
||||
|
||||
obj-$(CONFIG_FREEZER) += freezer.o
|
||||
@@ -101,6 +102,7 @@ obj-$(CONFIG_TRACING) += trace/
|
||||
obj-$(CONFIG_X86_DS) += trace/
|
||||
obj-$(CONFIG_RING_BUFFER) += trace/
|
||||
obj-$(CONFIG_SMP) += sched_cpupri.o
|
||||
obj-$(CONFIG_IRQ_WORK) += irq_work.o
|
||||
obj-$(CONFIG_PERF_EVENTS) += perf_event.o
|
||||
obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
|
||||
obj-$(CONFIG_USER_RETURN_NOTIFIER) += user-return-notifier.o
|
||||
|
||||
+1
-3
@@ -149,9 +149,7 @@ static void delayed_put_task_struct(struct rcu_head *rhp)
|
||||
{
|
||||
struct task_struct *tsk = container_of(rhp, struct task_struct, rcu);
|
||||
|
||||
#ifdef CONFIG_PERF_EVENTS
|
||||
WARN_ON_ONCE(tsk->perf_event_ctxp);
|
||||
#endif
|
||||
perf_event_delayed_put(tsk);
|
||||
trace_sched_process_free(tsk);
|
||||
put_task_struct(tsk);
|
||||
}
|
||||
|
||||
+63
-12
@@ -113,12 +113,12 @@ static unsigned int max_task_bp_pinned(int cpu, enum bp_type_idx type)
|
||||
*/
|
||||
static int task_bp_pinned(struct perf_event *bp, enum bp_type_idx type)
|
||||
{
|
||||
struct perf_event_context *ctx = bp->ctx;
|
||||
struct task_struct *tsk = bp->hw.bp_target;
|
||||
struct perf_event *iter;
|
||||
int count = 0;
|
||||
|
||||
list_for_each_entry(iter, &bp_task_head, hw.bp_list) {
|
||||
if (iter->ctx == ctx && find_slot_idx(iter) == type)
|
||||
if (iter->hw.bp_target == tsk && find_slot_idx(iter) == type)
|
||||
count += hw_breakpoint_weight(iter);
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ fetch_bp_busy_slots(struct bp_busy_slots *slots, struct perf_event *bp,
|
||||
enum bp_type_idx type)
|
||||
{
|
||||
int cpu = bp->cpu;
|
||||
struct task_struct *tsk = bp->ctx->task;
|
||||
struct task_struct *tsk = bp->hw.bp_target;
|
||||
|
||||
if (cpu >= 0) {
|
||||
slots->pinned = per_cpu(nr_cpu_bp_pinned[type], cpu);
|
||||
@@ -213,7 +213,7 @@ toggle_bp_slot(struct perf_event *bp, bool enable, enum bp_type_idx type,
|
||||
int weight)
|
||||
{
|
||||
int cpu = bp->cpu;
|
||||
struct task_struct *tsk = bp->ctx->task;
|
||||
struct task_struct *tsk = bp->hw.bp_target;
|
||||
|
||||
/* Pinned counter cpu profiling */
|
||||
if (!tsk) {
|
||||
@@ -433,8 +433,7 @@ register_user_hw_breakpoint(struct perf_event_attr *attr,
|
||||
perf_overflow_handler_t triggered,
|
||||
struct task_struct *tsk)
|
||||
{
|
||||
return perf_event_create_kernel_counter(attr, -1, task_pid_vnr(tsk),
|
||||
triggered);
|
||||
return perf_event_create_kernel_counter(attr, -1, tsk, triggered);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(register_user_hw_breakpoint);
|
||||
|
||||
@@ -516,7 +515,7 @@ register_wide_hw_breakpoint(struct perf_event_attr *attr,
|
||||
get_online_cpus();
|
||||
for_each_online_cpu(cpu) {
|
||||
pevent = per_cpu_ptr(cpu_events, cpu);
|
||||
bp = perf_event_create_kernel_counter(attr, cpu, -1, triggered);
|
||||
bp = perf_event_create_kernel_counter(attr, cpu, NULL, triggered);
|
||||
|
||||
*pevent = bp;
|
||||
|
||||
@@ -566,6 +565,61 @@ static struct notifier_block hw_breakpoint_exceptions_nb = {
|
||||
.priority = 0x7fffffff
|
||||
};
|
||||
|
||||
static void bp_perf_event_destroy(struct perf_event *event)
|
||||
{
|
||||
release_bp_slot(event);
|
||||
}
|
||||
|
||||
static int hw_breakpoint_event_init(struct perf_event *bp)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (bp->attr.type != PERF_TYPE_BREAKPOINT)
|
||||
return -ENOENT;
|
||||
|
||||
err = register_perf_hw_breakpoint(bp);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
bp->destroy = bp_perf_event_destroy;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int hw_breakpoint_add(struct perf_event *bp, int flags)
|
||||
{
|
||||
if (!(flags & PERF_EF_START))
|
||||
bp->hw.state = PERF_HES_STOPPED;
|
||||
|
||||
return arch_install_hw_breakpoint(bp);
|
||||
}
|
||||
|
||||
static void hw_breakpoint_del(struct perf_event *bp, int flags)
|
||||
{
|
||||
arch_uninstall_hw_breakpoint(bp);
|
||||
}
|
||||
|
||||
static void hw_breakpoint_start(struct perf_event *bp, int flags)
|
||||
{
|
||||
bp->hw.state = 0;
|
||||
}
|
||||
|
||||
static void hw_breakpoint_stop(struct perf_event *bp, int flags)
|
||||
{
|
||||
bp->hw.state = PERF_HES_STOPPED;
|
||||
}
|
||||
|
||||
static struct pmu perf_breakpoint = {
|
||||
.task_ctx_nr = perf_sw_context, /* could eventually get its own */
|
||||
|
||||
.event_init = hw_breakpoint_event_init,
|
||||
.add = hw_breakpoint_add,
|
||||
.del = hw_breakpoint_del,
|
||||
.start = hw_breakpoint_start,
|
||||
.stop = hw_breakpoint_stop,
|
||||
.read = hw_breakpoint_pmu_read,
|
||||
};
|
||||
|
||||
static int __init init_hw_breakpoint(void)
|
||||
{
|
||||
unsigned int **task_bp_pinned;
|
||||
@@ -587,6 +641,8 @@ static int __init init_hw_breakpoint(void)
|
||||
|
||||
constraints_initialized = 1;
|
||||
|
||||
perf_pmu_register(&perf_breakpoint);
|
||||
|
||||
return register_die_notifier(&hw_breakpoint_exceptions_nb);
|
||||
|
||||
err_alloc:
|
||||
@@ -602,8 +658,3 @@ static int __init init_hw_breakpoint(void)
|
||||
core_initcall(init_hw_breakpoint);
|
||||
|
||||
|
||||
struct pmu perf_ops_bp = {
|
||||
.enable = arch_install_hw_breakpoint,
|
||||
.disable = arch_uninstall_hw_breakpoint,
|
||||
.read = hw_breakpoint_pmu_read,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Red Hat, Inc., Peter Zijlstra <pzijlstr@redhat.com>
|
||||
*
|
||||
* Provides a framework for enqueueing and running callbacks from hardirq
|
||||
* context. The enqueueing is NMI-safe.
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/irq_work.h>
|
||||
#include <linux/hardirq.h>
|
||||
|
||||
/*
|
||||
* An entry can be in one of four states:
|
||||
*
|
||||
* free NULL, 0 -> {claimed} : free to be used
|
||||
* claimed NULL, 3 -> {pending} : claimed to be enqueued
|
||||
* pending next, 3 -> {busy} : queued, pending callback
|
||||
* busy NULL, 2 -> {free, claimed} : callback in progress, can be claimed
|
||||
*
|
||||
* We use the lower two bits of the next pointer to keep PENDING and BUSY
|
||||
* flags.
|
||||
*/
|
||||
|
||||
#define IRQ_WORK_PENDING 1UL
|
||||
#define IRQ_WORK_BUSY 2UL
|
||||
#define IRQ_WORK_FLAGS 3UL
|
||||
|
||||
static inline bool irq_work_is_set(struct irq_work *entry, int flags)
|
||||
{
|
||||
return (unsigned long)entry->next & flags;
|
||||
}
|
||||
|
||||
static inline struct irq_work *irq_work_next(struct irq_work *entry)
|
||||
{
|
||||
unsigned long next = (unsigned long)entry->next;
|
||||
next &= ~IRQ_WORK_FLAGS;
|
||||
return (struct irq_work *)next;
|
||||
}
|
||||
|
||||
static inline struct irq_work *next_flags(struct irq_work *entry, int flags)
|
||||
{
|
||||
unsigned long next = (unsigned long)entry;
|
||||
next |= flags;
|
||||
return (struct irq_work *)next;
|
||||
}
|
||||
|
||||
static DEFINE_PER_CPU(struct irq_work *, irq_work_list);
|
||||
|
||||
/*
|
||||
* Claim the entry so that no one else will poke at it.
|
||||
*/
|
||||
static bool irq_work_claim(struct irq_work *entry)
|
||||
{
|
||||
struct irq_work *next, *nflags;
|
||||
|
||||
do {
|
||||
next = entry->next;
|
||||
if ((unsigned long)next & IRQ_WORK_PENDING)
|
||||
return false;
|
||||
nflags = next_flags(next, IRQ_WORK_FLAGS);
|
||||
} while (cmpxchg(&entry->next, next, nflags) != next);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void __weak arch_irq_work_raise(void)
|
||||
{
|
||||
/*
|
||||
* Lame architectures will get the timer tick callback
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
* Queue the entry and raise the IPI if needed.
|
||||
*/
|
||||
static void __irq_work_queue(struct irq_work *entry)
|
||||
{
|
||||
struct irq_work **head, *next;
|
||||
|
||||
head = &get_cpu_var(irq_work_list);
|
||||
|
||||
do {
|
||||
next = *head;
|
||||
/* Can assign non-atomic because we keep the flags set. */
|
||||
entry->next = next_flags(next, IRQ_WORK_FLAGS);
|
||||
} while (cmpxchg(head, next, entry) != next);
|
||||
|
||||
/* The list was empty, raise self-interrupt to start processing. */
|
||||
if (!irq_work_next(entry))
|
||||
arch_irq_work_raise();
|
||||
|
||||
put_cpu_var(irq_work_list);
|
||||
}
|
||||
|
||||
/*
|
||||
* Enqueue the irq_work @entry, returns true on success, failure when the
|
||||
* @entry was already enqueued by someone else.
|
||||
*
|
||||
* Can be re-enqueued while the callback is still in progress.
|
||||
*/
|
||||
bool irq_work_queue(struct irq_work *entry)
|
||||
{
|
||||
if (!irq_work_claim(entry)) {
|
||||
/*
|
||||
* Already enqueued, can't do!
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
__irq_work_queue(entry);
|
||||
return true;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(irq_work_queue);
|
||||
|
||||
/*
|
||||
* Run the irq_work entries on this cpu. Requires to be ran from hardirq
|
||||
* context with local IRQs disabled.
|
||||
*/
|
||||
void irq_work_run(void)
|
||||
{
|
||||
struct irq_work *list, **head;
|
||||
|
||||
head = &__get_cpu_var(irq_work_list);
|
||||
if (*head == NULL)
|
||||
return;
|
||||
|
||||
BUG_ON(!in_irq());
|
||||
BUG_ON(!irqs_disabled());
|
||||
|
||||
list = xchg(head, NULL);
|
||||
while (list != NULL) {
|
||||
struct irq_work *entry = list;
|
||||
|
||||
list = irq_work_next(list);
|
||||
|
||||
/*
|
||||
* Clear the PENDING bit, after this point the @entry
|
||||
* can be re-used.
|
||||
*/
|
||||
entry->next = next_flags(NULL, IRQ_WORK_BUSY);
|
||||
entry->func(entry);
|
||||
/*
|
||||
* Clear the BUSY bit and return to the free state if
|
||||
* no-one else claimed it meanwhile.
|
||||
*/
|
||||
cmpxchg(&entry->next, next_flags(NULL, IRQ_WORK_BUSY), NULL);
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(irq_work_run);
|
||||
|
||||
/*
|
||||
* Synchronize against the irq_work @entry, ensures the entry is not
|
||||
* currently in use.
|
||||
*/
|
||||
void irq_work_sync(struct irq_work *entry)
|
||||
{
|
||||
WARN_ON_ONCE(irqs_disabled());
|
||||
|
||||
while (irq_work_is_set(entry, IRQ_WORK_BUSY))
|
||||
cpu_relax();
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(irq_work_sync);
|
||||
@@ -0,0 +1,429 @@
|
||||
/*
|
||||
* jump label support
|
||||
*
|
||||
* Copyright (C) 2009 Jason Baron <jbaron@redhat.com>
|
||||
*
|
||||
*/
|
||||
#include <linux/jump_label.h>
|
||||
#include <linux/memory.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/jhash.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/sort.h>
|
||||
#include <linux/err.h>
|
||||
|
||||
#ifdef HAVE_JUMP_LABEL
|
||||
|
||||
#define JUMP_LABEL_HASH_BITS 6
|
||||
#define JUMP_LABEL_TABLE_SIZE (1 << JUMP_LABEL_HASH_BITS)
|
||||
static struct hlist_head jump_label_table[JUMP_LABEL_TABLE_SIZE];
|
||||
|
||||
/* mutex to protect coming/going of the the jump_label table */
|
||||
static DEFINE_MUTEX(jump_label_mutex);
|
||||
|
||||
struct jump_label_entry {
|
||||
struct hlist_node hlist;
|
||||
struct jump_entry *table;
|
||||
int nr_entries;
|
||||
/* hang modules off here */
|
||||
struct hlist_head modules;
|
||||
unsigned long key;
|
||||
};
|
||||
|
||||
struct jump_label_module_entry {
|
||||
struct hlist_node hlist;
|
||||
struct jump_entry *table;
|
||||
int nr_entries;
|
||||
struct module *mod;
|
||||
};
|
||||
|
||||
static int jump_label_cmp(const void *a, const void *b)
|
||||
{
|
||||
const struct jump_entry *jea = a;
|
||||
const struct jump_entry *jeb = b;
|
||||
|
||||
if (jea->key < jeb->key)
|
||||
return -1;
|
||||
|
||||
if (jea->key > jeb->key)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
sort_jump_label_entries(struct jump_entry *start, struct jump_entry *stop)
|
||||
{
|
||||
unsigned long size;
|
||||
|
||||
size = (((unsigned long)stop - (unsigned long)start)
|
||||
/ sizeof(struct jump_entry));
|
||||
sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
|
||||
}
|
||||
|
||||
static struct jump_label_entry *get_jump_label_entry(jump_label_t key)
|
||||
{
|
||||
struct hlist_head *head;
|
||||
struct hlist_node *node;
|
||||
struct jump_label_entry *e;
|
||||
u32 hash = jhash((void *)&key, sizeof(jump_label_t), 0);
|
||||
|
||||
head = &jump_label_table[hash & (JUMP_LABEL_TABLE_SIZE - 1)];
|
||||
hlist_for_each_entry(e, node, head, hlist) {
|
||||
if (key == e->key)
|
||||
return e;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct jump_label_entry *
|
||||
add_jump_label_entry(jump_label_t key, int nr_entries, struct jump_entry *table)
|
||||
{
|
||||
struct hlist_head *head;
|
||||
struct jump_label_entry *e;
|
||||
u32 hash;
|
||||
|
||||
e = get_jump_label_entry(key);
|
||||
if (e)
|
||||
return ERR_PTR(-EEXIST);
|
||||
|
||||
e = kmalloc(sizeof(struct jump_label_entry), GFP_KERNEL);
|
||||
if (!e)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
hash = jhash((void *)&key, sizeof(jump_label_t), 0);
|
||||
head = &jump_label_table[hash & (JUMP_LABEL_TABLE_SIZE - 1)];
|
||||
e->key = key;
|
||||
e->table = table;
|
||||
e->nr_entries = nr_entries;
|
||||
INIT_HLIST_HEAD(&(e->modules));
|
||||
hlist_add_head(&e->hlist, head);
|
||||
return e;
|
||||
}
|
||||
|
||||
static int
|
||||
build_jump_label_hashtable(struct jump_entry *start, struct jump_entry *stop)
|
||||
{
|
||||
struct jump_entry *iter, *iter_begin;
|
||||
struct jump_label_entry *entry;
|
||||
int count;
|
||||
|
||||
sort_jump_label_entries(start, stop);
|
||||
iter = start;
|
||||
while (iter < stop) {
|
||||
entry = get_jump_label_entry(iter->key);
|
||||
if (!entry) {
|
||||
iter_begin = iter;
|
||||
count = 0;
|
||||
while ((iter < stop) &&
|
||||
(iter->key == iter_begin->key)) {
|
||||
iter++;
|
||||
count++;
|
||||
}
|
||||
entry = add_jump_label_entry(iter_begin->key,
|
||||
count, iter_begin);
|
||||
if (IS_ERR(entry))
|
||||
return PTR_ERR(entry);
|
||||
} else {
|
||||
WARN_ONCE(1, KERN_ERR "build_jump_hashtable: unexpected entry!\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***
|
||||
* jump_label_update - update jump label text
|
||||
* @key - key value associated with a a jump label
|
||||
* @type - enum set to JUMP_LABEL_ENABLE or JUMP_LABEL_DISABLE
|
||||
*
|
||||
* Will enable/disable the jump for jump label @key, depending on the
|
||||
* value of @type.
|
||||
*
|
||||
*/
|
||||
|
||||
void jump_label_update(unsigned long key, enum jump_label_type type)
|
||||
{
|
||||
struct jump_entry *iter;
|
||||
struct jump_label_entry *entry;
|
||||
struct hlist_node *module_node;
|
||||
struct jump_label_module_entry *e_module;
|
||||
int count;
|
||||
|
||||
mutex_lock(&jump_label_mutex);
|
||||
entry = get_jump_label_entry((jump_label_t)key);
|
||||
if (entry) {
|
||||
count = entry->nr_entries;
|
||||
iter = entry->table;
|
||||
while (count--) {
|
||||
if (kernel_text_address(iter->code))
|
||||
arch_jump_label_transform(iter, type);
|
||||
iter++;
|
||||
}
|
||||
/* eanble/disable jump labels in modules */
|
||||
hlist_for_each_entry(e_module, module_node, &(entry->modules),
|
||||
hlist) {
|
||||
count = e_module->nr_entries;
|
||||
iter = e_module->table;
|
||||
while (count--) {
|
||||
if (kernel_text_address(iter->code))
|
||||
arch_jump_label_transform(iter, type);
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
mutex_unlock(&jump_label_mutex);
|
||||
}
|
||||
|
||||
static int addr_conflict(struct jump_entry *entry, void *start, void *end)
|
||||
{
|
||||
if (entry->code <= (unsigned long)end &&
|
||||
entry->code + JUMP_LABEL_NOP_SIZE > (unsigned long)start)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MODULES
|
||||
|
||||
static int module_conflict(void *start, void *end)
|
||||
{
|
||||
struct hlist_head *head;
|
||||
struct hlist_node *node, *node_next, *module_node, *module_node_next;
|
||||
struct jump_label_entry *e;
|
||||
struct jump_label_module_entry *e_module;
|
||||
struct jump_entry *iter;
|
||||
int i, count;
|
||||
int conflict = 0;
|
||||
|
||||
for (i = 0; i < JUMP_LABEL_TABLE_SIZE; i++) {
|
||||
head = &jump_label_table[i];
|
||||
hlist_for_each_entry_safe(e, node, node_next, head, hlist) {
|
||||
hlist_for_each_entry_safe(e_module, module_node,
|
||||
module_node_next,
|
||||
&(e->modules), hlist) {
|
||||
count = e_module->nr_entries;
|
||||
iter = e_module->table;
|
||||
while (count--) {
|
||||
if (addr_conflict(iter, start, end)) {
|
||||
conflict = 1;
|
||||
goto out;
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
out:
|
||||
return conflict;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/***
|
||||
* jump_label_text_reserved - check if addr range is reserved
|
||||
* @start: start text addr
|
||||
* @end: end text addr
|
||||
*
|
||||
* checks if the text addr located between @start and @end
|
||||
* overlaps with any of the jump label patch addresses. Code
|
||||
* that wants to modify kernel text should first verify that
|
||||
* it does not overlap with any of the jump label addresses.
|
||||
*
|
||||
* returns 1 if there is an overlap, 0 otherwise
|
||||
*/
|
||||
int jump_label_text_reserved(void *start, void *end)
|
||||
{
|
||||
struct jump_entry *iter;
|
||||
struct jump_entry *iter_start = __start___jump_table;
|
||||
struct jump_entry *iter_stop = __start___jump_table;
|
||||
int conflict = 0;
|
||||
|
||||
mutex_lock(&jump_label_mutex);
|
||||
iter = iter_start;
|
||||
while (iter < iter_stop) {
|
||||
if (addr_conflict(iter, start, end)) {
|
||||
conflict = 1;
|
||||
goto out;
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
|
||||
/* now check modules */
|
||||
#ifdef CONFIG_MODULES
|
||||
conflict = module_conflict(start, end);
|
||||
#endif
|
||||
out:
|
||||
mutex_unlock(&jump_label_mutex);
|
||||
return conflict;
|
||||
}
|
||||
|
||||
static __init int init_jump_label(void)
|
||||
{
|
||||
int ret;
|
||||
struct jump_entry *iter_start = __start___jump_table;
|
||||
struct jump_entry *iter_stop = __stop___jump_table;
|
||||
struct jump_entry *iter;
|
||||
|
||||
mutex_lock(&jump_label_mutex);
|
||||
ret = build_jump_label_hashtable(__start___jump_table,
|
||||
__stop___jump_table);
|
||||
iter = iter_start;
|
||||
while (iter < iter_stop) {
|
||||
arch_jump_label_text_poke_early(iter->code);
|
||||
iter++;
|
||||
}
|
||||
mutex_unlock(&jump_label_mutex);
|
||||
return ret;
|
||||
}
|
||||
early_initcall(init_jump_label);
|
||||
|
||||
#ifdef CONFIG_MODULES
|
||||
|
||||
static struct jump_label_module_entry *
|
||||
add_jump_label_module_entry(struct jump_label_entry *entry,
|
||||
struct jump_entry *iter_begin,
|
||||
int count, struct module *mod)
|
||||
{
|
||||
struct jump_label_module_entry *e;
|
||||
|
||||
e = kmalloc(sizeof(struct jump_label_module_entry), GFP_KERNEL);
|
||||
if (!e)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
e->mod = mod;
|
||||
e->nr_entries = count;
|
||||
e->table = iter_begin;
|
||||
hlist_add_head(&e->hlist, &entry->modules);
|
||||
return e;
|
||||
}
|
||||
|
||||
static int add_jump_label_module(struct module *mod)
|
||||
{
|
||||
struct jump_entry *iter, *iter_begin;
|
||||
struct jump_label_entry *entry;
|
||||
struct jump_label_module_entry *module_entry;
|
||||
int count;
|
||||
|
||||
/* if the module doesn't have jump label entries, just return */
|
||||
if (!mod->num_jump_entries)
|
||||
return 0;
|
||||
|
||||
sort_jump_label_entries(mod->jump_entries,
|
||||
mod->jump_entries + mod->num_jump_entries);
|
||||
iter = mod->jump_entries;
|
||||
while (iter < mod->jump_entries + mod->num_jump_entries) {
|
||||
entry = get_jump_label_entry(iter->key);
|
||||
iter_begin = iter;
|
||||
count = 0;
|
||||
while ((iter < mod->jump_entries + mod->num_jump_entries) &&
|
||||
(iter->key == iter_begin->key)) {
|
||||
iter++;
|
||||
count++;
|
||||
}
|
||||
if (!entry) {
|
||||
entry = add_jump_label_entry(iter_begin->key, 0, NULL);
|
||||
if (IS_ERR(entry))
|
||||
return PTR_ERR(entry);
|
||||
}
|
||||
module_entry = add_jump_label_module_entry(entry, iter_begin,
|
||||
count, mod);
|
||||
if (IS_ERR(module_entry))
|
||||
return PTR_ERR(module_entry);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void remove_jump_label_module(struct module *mod)
|
||||
{
|
||||
struct hlist_head *head;
|
||||
struct hlist_node *node, *node_next, *module_node, *module_node_next;
|
||||
struct jump_label_entry *e;
|
||||
struct jump_label_module_entry *e_module;
|
||||
int i;
|
||||
|
||||
/* if the module doesn't have jump label entries, just return */
|
||||
if (!mod->num_jump_entries)
|
||||
return;
|
||||
|
||||
for (i = 0; i < JUMP_LABEL_TABLE_SIZE; i++) {
|
||||
head = &jump_label_table[i];
|
||||
hlist_for_each_entry_safe(e, node, node_next, head, hlist) {
|
||||
hlist_for_each_entry_safe(e_module, module_node,
|
||||
module_node_next,
|
||||
&(e->modules), hlist) {
|
||||
if (e_module->mod == mod) {
|
||||
hlist_del(&e_module->hlist);
|
||||
kfree(e_module);
|
||||
}
|
||||
}
|
||||
if (hlist_empty(&e->modules) && (e->nr_entries == 0)) {
|
||||
hlist_del(&e->hlist);
|
||||
kfree(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
jump_label_module_notify(struct notifier_block *self, unsigned long val,
|
||||
void *data)
|
||||
{
|
||||
struct module *mod = data;
|
||||
int ret = 0;
|
||||
|
||||
switch (val) {
|
||||
case MODULE_STATE_COMING:
|
||||
mutex_lock(&jump_label_mutex);
|
||||
ret = add_jump_label_module(mod);
|
||||
if (ret)
|
||||
remove_jump_label_module(mod);
|
||||
mutex_unlock(&jump_label_mutex);
|
||||
break;
|
||||
case MODULE_STATE_GOING:
|
||||
mutex_lock(&jump_label_mutex);
|
||||
remove_jump_label_module(mod);
|
||||
mutex_unlock(&jump_label_mutex);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/***
|
||||
* apply_jump_label_nops - patch module jump labels with arch_get_jump_label_nop()
|
||||
* @mod: module to patch
|
||||
*
|
||||
* Allow for run-time selection of the optimal nops. Before the module
|
||||
* loads patch these with arch_get_jump_label_nop(), which is specified by
|
||||
* the arch specific jump label code.
|
||||
*/
|
||||
void jump_label_apply_nops(struct module *mod)
|
||||
{
|
||||
struct jump_entry *iter;
|
||||
|
||||
/* if the module doesn't have jump label entries, just return */
|
||||
if (!mod->num_jump_entries)
|
||||
return;
|
||||
|
||||
iter = mod->jump_entries;
|
||||
while (iter < mod->jump_entries + mod->num_jump_entries) {
|
||||
arch_jump_label_text_poke_early(iter->code);
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
|
||||
struct notifier_block jump_label_module_nb = {
|
||||
.notifier_call = jump_label_module_notify,
|
||||
.priority = 0,
|
||||
};
|
||||
|
||||
static __init int init_jump_label_module(void)
|
||||
{
|
||||
return register_module_notifier(&jump_label_module_nb);
|
||||
}
|
||||
early_initcall(init_jump_label_module);
|
||||
|
||||
#endif /* CONFIG_MODULES */
|
||||
|
||||
#endif
|
||||
+17
-9
@@ -47,6 +47,7 @@
|
||||
#include <linux/memory.h>
|
||||
#include <linux/ftrace.h>
|
||||
#include <linux/cpu.h>
|
||||
#include <linux/jump_label.h>
|
||||
|
||||
#include <asm-generic/sections.h>
|
||||
#include <asm/cacheflush.h>
|
||||
@@ -399,7 +400,7 @@ static inline int kprobe_optready(struct kprobe *p)
|
||||
* Return an optimized kprobe whose optimizing code replaces
|
||||
* instructions including addr (exclude breakpoint).
|
||||
*/
|
||||
struct kprobe *__kprobes get_optimized_kprobe(unsigned long addr)
|
||||
static struct kprobe *__kprobes get_optimized_kprobe(unsigned long addr)
|
||||
{
|
||||
int i;
|
||||
struct kprobe *p = NULL;
|
||||
@@ -831,6 +832,7 @@ void __kprobes recycle_rp_inst(struct kretprobe_instance *ri,
|
||||
|
||||
void __kprobes kretprobe_hash_lock(struct task_struct *tsk,
|
||||
struct hlist_head **head, unsigned long *flags)
|
||||
__acquires(hlist_lock)
|
||||
{
|
||||
unsigned long hash = hash_ptr(tsk, KPROBE_HASH_BITS);
|
||||
spinlock_t *hlist_lock;
|
||||
@@ -842,6 +844,7 @@ void __kprobes kretprobe_hash_lock(struct task_struct *tsk,
|
||||
|
||||
static void __kprobes kretprobe_table_lock(unsigned long hash,
|
||||
unsigned long *flags)
|
||||
__acquires(hlist_lock)
|
||||
{
|
||||
spinlock_t *hlist_lock = kretprobe_table_lock_ptr(hash);
|
||||
spin_lock_irqsave(hlist_lock, *flags);
|
||||
@@ -849,6 +852,7 @@ static void __kprobes kretprobe_table_lock(unsigned long hash,
|
||||
|
||||
void __kprobes kretprobe_hash_unlock(struct task_struct *tsk,
|
||||
unsigned long *flags)
|
||||
__releases(hlist_lock)
|
||||
{
|
||||
unsigned long hash = hash_ptr(tsk, KPROBE_HASH_BITS);
|
||||
spinlock_t *hlist_lock;
|
||||
@@ -857,7 +861,9 @@ void __kprobes kretprobe_hash_unlock(struct task_struct *tsk,
|
||||
spin_unlock_irqrestore(hlist_lock, *flags);
|
||||
}
|
||||
|
||||
void __kprobes kretprobe_table_unlock(unsigned long hash, unsigned long *flags)
|
||||
static void __kprobes kretprobe_table_unlock(unsigned long hash,
|
||||
unsigned long *flags)
|
||||
__releases(hlist_lock)
|
||||
{
|
||||
spinlock_t *hlist_lock = kretprobe_table_lock_ptr(hash);
|
||||
spin_unlock_irqrestore(hlist_lock, *flags);
|
||||
@@ -1141,7 +1147,8 @@ int __kprobes register_kprobe(struct kprobe *p)
|
||||
preempt_disable();
|
||||
if (!kernel_text_address((unsigned long) p->addr) ||
|
||||
in_kprobes_functions((unsigned long) p->addr) ||
|
||||
ftrace_text_reserved(p->addr, p->addr)) {
|
||||
ftrace_text_reserved(p->addr, p->addr) ||
|
||||
jump_label_text_reserved(p->addr, p->addr)) {
|
||||
preempt_enable();
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -1339,18 +1346,19 @@ int __kprobes register_jprobes(struct jprobe **jps, int num)
|
||||
if (num <= 0)
|
||||
return -EINVAL;
|
||||
for (i = 0; i < num; i++) {
|
||||
unsigned long addr;
|
||||
unsigned long addr, offset;
|
||||
jp = jps[i];
|
||||
addr = arch_deref_entry_point(jp->entry);
|
||||
|
||||
if (!kernel_text_address(addr))
|
||||
ret = -EINVAL;
|
||||
else {
|
||||
/* Todo: Verify probepoint is a function entry point */
|
||||
/* Verify probepoint is a function entry point */
|
||||
if (kallsyms_lookup_size_offset(addr, NULL, &offset) &&
|
||||
offset == 0) {
|
||||
jp->kp.pre_handler = setjmp_pre_handler;
|
||||
jp->kp.break_handler = longjmp_break_handler;
|
||||
ret = register_kprobe(&jp->kp);
|
||||
}
|
||||
} else
|
||||
ret = -EINVAL;
|
||||
|
||||
if (ret < 0) {
|
||||
if (i > 0)
|
||||
unregister_jprobes(jps, i);
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
#include <linux/async.h>
|
||||
#include <linux/percpu.h>
|
||||
#include <linux/kmemleak.h>
|
||||
#include <linux/jump_label.h>
|
||||
|
||||
#define CREATE_TRACE_POINTS
|
||||
#include <trace/events/module.h>
|
||||
@@ -2309,6 +2310,11 @@ static void find_module_sections(struct module *mod, struct load_info *info)
|
||||
sizeof(*mod->tracepoints),
|
||||
&mod->num_tracepoints);
|
||||
#endif
|
||||
#ifdef HAVE_JUMP_LABEL
|
||||
mod->jump_entries = section_objs(info, "__jump_table",
|
||||
sizeof(*mod->jump_entries),
|
||||
&mod->num_jump_entries);
|
||||
#endif
|
||||
#ifdef CONFIG_EVENT_TRACING
|
||||
mod->trace_events = section_objs(info, "_ftrace_events",
|
||||
sizeof(*mod->trace_events),
|
||||
|
||||
+1530
-1088
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -3584,7 +3584,7 @@ void scheduler_tick(void)
|
||||
curr->sched_class->task_tick(rq, curr, 0);
|
||||
raw_spin_unlock(&rq->lock);
|
||||
|
||||
perf_event_task_tick(curr);
|
||||
perf_event_task_tick();
|
||||
|
||||
#ifdef CONFIG_SMP
|
||||
rq->idle_at_tick = idle_cpu(cpu);
|
||||
|
||||
@@ -115,7 +115,9 @@ static int test_kprobes(void)
|
||||
int ret;
|
||||
struct kprobe *kps[2] = {&kp, &kp2};
|
||||
|
||||
kp.addr = 0; /* addr should be cleard for reusing kprobe. */
|
||||
/* addr and flags should be cleard for reusing kprobe. */
|
||||
kp.addr = NULL;
|
||||
kp.flags = 0;
|
||||
ret = register_kprobes(kps, 2);
|
||||
if (ret < 0) {
|
||||
printk(KERN_ERR "Kprobe smoke test failed: "
|
||||
@@ -210,7 +212,9 @@ static int test_jprobes(void)
|
||||
int ret;
|
||||
struct jprobe *jps[2] = {&jp, &jp2};
|
||||
|
||||
jp.kp.addr = 0; /* addr should be cleard for reusing kprobe. */
|
||||
/* addr and flags should be cleard for reusing kprobe. */
|
||||
jp.kp.addr = NULL;
|
||||
jp.kp.flags = 0;
|
||||
ret = register_jprobes(jps, 2);
|
||||
if (ret < 0) {
|
||||
printk(KERN_ERR "Kprobe smoke test failed: "
|
||||
@@ -323,7 +327,9 @@ static int test_kretprobes(void)
|
||||
int ret;
|
||||
struct kretprobe *rps[2] = {&rp, &rp2};
|
||||
|
||||
rp.kp.addr = 0; /* addr should be cleard for reusing kprobe. */
|
||||
/* addr and flags should be cleard for reusing kprobe. */
|
||||
rp.kp.addr = NULL;
|
||||
rp.kp.flags = 0;
|
||||
ret = register_kretprobes(rps, 2);
|
||||
if (ret < 0) {
|
||||
printk(KERN_ERR "Kprobe smoke test failed: "
|
||||
|
||||
+5
-2
@@ -37,7 +37,7 @@
|
||||
#include <linux/delay.h>
|
||||
#include <linux/tick.h>
|
||||
#include <linux/kallsyms.h>
|
||||
#include <linux/perf_event.h>
|
||||
#include <linux/irq_work.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
@@ -1279,7 +1279,10 @@ void update_process_times(int user_tick)
|
||||
run_local_timers();
|
||||
rcu_check_callbacks(cpu, user_tick);
|
||||
printk_tick();
|
||||
perf_event_do_pending();
|
||||
#ifdef CONFIG_IRQ_WORK
|
||||
if (in_irq())
|
||||
irq_work_run();
|
||||
#endif
|
||||
scheduler_tick();
|
||||
run_posix_cpu_timers(p);
|
||||
}
|
||||
|
||||
@@ -49,6 +49,11 @@ config HAVE_SYSCALL_TRACEPOINTS
|
||||
help
|
||||
See Documentation/trace/ftrace-design.txt
|
||||
|
||||
config HAVE_C_RECORDMCOUNT
|
||||
bool
|
||||
help
|
||||
C version of recordmcount available?
|
||||
|
||||
config TRACER_MAX_TRACE
|
||||
bool
|
||||
|
||||
|
||||
+82
-45
@@ -884,10 +884,8 @@ enum {
|
||||
FTRACE_ENABLE_CALLS = (1 << 0),
|
||||
FTRACE_DISABLE_CALLS = (1 << 1),
|
||||
FTRACE_UPDATE_TRACE_FUNC = (1 << 2),
|
||||
FTRACE_ENABLE_MCOUNT = (1 << 3),
|
||||
FTRACE_DISABLE_MCOUNT = (1 << 4),
|
||||
FTRACE_START_FUNC_RET = (1 << 5),
|
||||
FTRACE_STOP_FUNC_RET = (1 << 6),
|
||||
FTRACE_START_FUNC_RET = (1 << 3),
|
||||
FTRACE_STOP_FUNC_RET = (1 << 4),
|
||||
};
|
||||
|
||||
static int ftrace_filtered;
|
||||
@@ -1226,8 +1224,6 @@ static void ftrace_shutdown(int command)
|
||||
|
||||
static void ftrace_startup_sysctl(void)
|
||||
{
|
||||
int command = FTRACE_ENABLE_MCOUNT;
|
||||
|
||||
if (unlikely(ftrace_disabled))
|
||||
return;
|
||||
|
||||
@@ -1235,23 +1231,17 @@ static void ftrace_startup_sysctl(void)
|
||||
saved_ftrace_func = NULL;
|
||||
/* ftrace_start_up is true if we want ftrace running */
|
||||
if (ftrace_start_up)
|
||||
command |= FTRACE_ENABLE_CALLS;
|
||||
|
||||
ftrace_run_update_code(command);
|
||||
ftrace_run_update_code(FTRACE_ENABLE_CALLS);
|
||||
}
|
||||
|
||||
static void ftrace_shutdown_sysctl(void)
|
||||
{
|
||||
int command = FTRACE_DISABLE_MCOUNT;
|
||||
|
||||
if (unlikely(ftrace_disabled))
|
||||
return;
|
||||
|
||||
/* ftrace_start_up is true if ftrace is running */
|
||||
if (ftrace_start_up)
|
||||
command |= FTRACE_DISABLE_CALLS;
|
||||
|
||||
ftrace_run_update_code(command);
|
||||
ftrace_run_update_code(FTRACE_DISABLE_CALLS);
|
||||
}
|
||||
|
||||
static cycle_t ftrace_update_time;
|
||||
@@ -1368,24 +1358,29 @@ enum {
|
||||
#define FTRACE_BUFF_MAX (KSYM_SYMBOL_LEN+4) /* room for wildcards */
|
||||
|
||||
struct ftrace_iterator {
|
||||
struct ftrace_page *pg;
|
||||
int hidx;
|
||||
int idx;
|
||||
unsigned flags;
|
||||
struct trace_parser parser;
|
||||
loff_t pos;
|
||||
loff_t func_pos;
|
||||
struct ftrace_page *pg;
|
||||
struct dyn_ftrace *func;
|
||||
struct ftrace_func_probe *probe;
|
||||
struct trace_parser parser;
|
||||
int hidx;
|
||||
int idx;
|
||||
unsigned flags;
|
||||
};
|
||||
|
||||
static void *
|
||||
t_hash_next(struct seq_file *m, void *v, loff_t *pos)
|
||||
t_hash_next(struct seq_file *m, loff_t *pos)
|
||||
{
|
||||
struct ftrace_iterator *iter = m->private;
|
||||
struct hlist_node *hnd = v;
|
||||
struct hlist_node *hnd = NULL;
|
||||
struct hlist_head *hhd;
|
||||
|
||||
WARN_ON(!(iter->flags & FTRACE_ITER_HASH));
|
||||
|
||||
(*pos)++;
|
||||
iter->pos = *pos;
|
||||
|
||||
if (iter->probe)
|
||||
hnd = &iter->probe->node;
|
||||
retry:
|
||||
if (iter->hidx >= FTRACE_FUNC_HASHSIZE)
|
||||
return NULL;
|
||||
@@ -1408,7 +1403,12 @@ t_hash_next(struct seq_file *m, void *v, loff_t *pos)
|
||||
}
|
||||
}
|
||||
|
||||
return hnd;
|
||||
if (WARN_ON_ONCE(!hnd))
|
||||
return NULL;
|
||||
|
||||
iter->probe = hlist_entry(hnd, struct ftrace_func_probe, node);
|
||||
|
||||
return iter;
|
||||
}
|
||||
|
||||
static void *t_hash_start(struct seq_file *m, loff_t *pos)
|
||||
@@ -1417,26 +1417,32 @@ static void *t_hash_start(struct seq_file *m, loff_t *pos)
|
||||
void *p = NULL;
|
||||
loff_t l;
|
||||
|
||||
if (!(iter->flags & FTRACE_ITER_HASH))
|
||||
*pos = 0;
|
||||
|
||||
iter->flags |= FTRACE_ITER_HASH;
|
||||
if (iter->func_pos > *pos)
|
||||
return NULL;
|
||||
|
||||
iter->hidx = 0;
|
||||
for (l = 0; l <= *pos; ) {
|
||||
p = t_hash_next(m, p, &l);
|
||||
for (l = 0; l <= (*pos - iter->func_pos); ) {
|
||||
p = t_hash_next(m, &l);
|
||||
if (!p)
|
||||
break;
|
||||
}
|
||||
return p;
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
/* Only set this if we have an item */
|
||||
iter->flags |= FTRACE_ITER_HASH;
|
||||
|
||||
return iter;
|
||||
}
|
||||
|
||||
static int t_hash_show(struct seq_file *m, void *v)
|
||||
static int
|
||||
t_hash_show(struct seq_file *m, struct ftrace_iterator *iter)
|
||||
{
|
||||
struct ftrace_func_probe *rec;
|
||||
struct hlist_node *hnd = v;
|
||||
|
||||
rec = hlist_entry(hnd, struct ftrace_func_probe, node);
|
||||
rec = iter->probe;
|
||||
if (WARN_ON_ONCE(!rec))
|
||||
return -EIO;
|
||||
|
||||
if (rec->ops->print)
|
||||
return rec->ops->print(m, rec->ip, rec->ops, rec->data);
|
||||
@@ -1457,12 +1463,13 @@ t_next(struct seq_file *m, void *v, loff_t *pos)
|
||||
struct dyn_ftrace *rec = NULL;
|
||||
|
||||
if (iter->flags & FTRACE_ITER_HASH)
|
||||
return t_hash_next(m, v, pos);
|
||||
return t_hash_next(m, pos);
|
||||
|
||||
(*pos)++;
|
||||
iter->pos = *pos;
|
||||
|
||||
if (iter->flags & FTRACE_ITER_PRINTALL)
|
||||
return NULL;
|
||||
return t_hash_start(m, pos);
|
||||
|
||||
retry:
|
||||
if (iter->idx >= iter->pg->index) {
|
||||
@@ -1491,7 +1498,20 @@ t_next(struct seq_file *m, void *v, loff_t *pos)
|
||||
}
|
||||
}
|
||||
|
||||
return rec;
|
||||
if (!rec)
|
||||
return t_hash_start(m, pos);
|
||||
|
||||
iter->func_pos = *pos;
|
||||
iter->func = rec;
|
||||
|
||||
return iter;
|
||||
}
|
||||
|
||||
static void reset_iter_read(struct ftrace_iterator *iter)
|
||||
{
|
||||
iter->pos = 0;
|
||||
iter->func_pos = 0;
|
||||
iter->flags &= ~(FTRACE_ITER_PRINTALL & FTRACE_ITER_HASH);
|
||||
}
|
||||
|
||||
static void *t_start(struct seq_file *m, loff_t *pos)
|
||||
@@ -1501,6 +1521,12 @@ static void *t_start(struct seq_file *m, loff_t *pos)
|
||||
loff_t l;
|
||||
|
||||
mutex_lock(&ftrace_lock);
|
||||
/*
|
||||
* If an lseek was done, then reset and start from beginning.
|
||||
*/
|
||||
if (*pos < iter->pos)
|
||||
reset_iter_read(iter);
|
||||
|
||||
/*
|
||||
* For set_ftrace_filter reading, if we have the filter
|
||||
* off, we can short cut and just print out that all
|
||||
@@ -1518,6 +1544,11 @@ static void *t_start(struct seq_file *m, loff_t *pos)
|
||||
if (iter->flags & FTRACE_ITER_HASH)
|
||||
return t_hash_start(m, pos);
|
||||
|
||||
/*
|
||||
* Unfortunately, we need to restart at ftrace_pages_start
|
||||
* every time we let go of the ftrace_mutex. This is because
|
||||
* those pointers can change without the lock.
|
||||
*/
|
||||
iter->pg = ftrace_pages_start;
|
||||
iter->idx = 0;
|
||||
for (l = 0; l <= *pos; ) {
|
||||
@@ -1526,10 +1557,14 @@ static void *t_start(struct seq_file *m, loff_t *pos)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!p && iter->flags & FTRACE_ITER_FILTER)
|
||||
return t_hash_start(m, pos);
|
||||
if (!p) {
|
||||
if (iter->flags & FTRACE_ITER_FILTER)
|
||||
return t_hash_start(m, pos);
|
||||
|
||||
return p;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return iter;
|
||||
}
|
||||
|
||||
static void t_stop(struct seq_file *m, void *p)
|
||||
@@ -1540,16 +1575,18 @@ static void t_stop(struct seq_file *m, void *p)
|
||||
static int t_show(struct seq_file *m, void *v)
|
||||
{
|
||||
struct ftrace_iterator *iter = m->private;
|
||||
struct dyn_ftrace *rec = v;
|
||||
struct dyn_ftrace *rec;
|
||||
|
||||
if (iter->flags & FTRACE_ITER_HASH)
|
||||
return t_hash_show(m, v);
|
||||
return t_hash_show(m, iter);
|
||||
|
||||
if (iter->flags & FTRACE_ITER_PRINTALL) {
|
||||
seq_printf(m, "#### all functions enabled ####\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
rec = iter->func;
|
||||
|
||||
if (!rec)
|
||||
return 0;
|
||||
|
||||
@@ -1601,8 +1638,8 @@ ftrace_failures_open(struct inode *inode, struct file *file)
|
||||
|
||||
ret = ftrace_avail_open(inode, file);
|
||||
if (!ret) {
|
||||
m = (struct seq_file *)file->private_data;
|
||||
iter = (struct ftrace_iterator *)m->private;
|
||||
m = file->private_data;
|
||||
iter = m->private;
|
||||
iter->flags = FTRACE_ITER_FAILURES;
|
||||
}
|
||||
|
||||
@@ -2418,7 +2455,7 @@ static const struct file_operations ftrace_filter_fops = {
|
||||
.open = ftrace_filter_open,
|
||||
.read = seq_read,
|
||||
.write = ftrace_filter_write,
|
||||
.llseek = no_llseek,
|
||||
.llseek = ftrace_regex_lseek,
|
||||
.release = ftrace_filter_release,
|
||||
};
|
||||
|
||||
|
||||
@@ -2606,6 +2606,19 @@ void ring_buffer_record_enable_cpu(struct ring_buffer *buffer, int cpu)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(ring_buffer_record_enable_cpu);
|
||||
|
||||
/*
|
||||
* The total entries in the ring buffer is the running counter
|
||||
* of entries entered into the ring buffer, minus the sum of
|
||||
* the entries read from the ring buffer and the number of
|
||||
* entries that were overwritten.
|
||||
*/
|
||||
static inline unsigned long
|
||||
rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
|
||||
{
|
||||
return local_read(&cpu_buffer->entries) -
|
||||
(local_read(&cpu_buffer->overrun) + cpu_buffer->read);
|
||||
}
|
||||
|
||||
/**
|
||||
* ring_buffer_entries_cpu - get the number of entries in a cpu buffer
|
||||
* @buffer: The ring buffer
|
||||
@@ -2614,16 +2627,13 @@ EXPORT_SYMBOL_GPL(ring_buffer_record_enable_cpu);
|
||||
unsigned long ring_buffer_entries_cpu(struct ring_buffer *buffer, int cpu)
|
||||
{
|
||||
struct ring_buffer_per_cpu *cpu_buffer;
|
||||
unsigned long ret;
|
||||
|
||||
if (!cpumask_test_cpu(cpu, buffer->cpumask))
|
||||
return 0;
|
||||
|
||||
cpu_buffer = buffer->buffers[cpu];
|
||||
ret = (local_read(&cpu_buffer->entries) - local_read(&cpu_buffer->overrun))
|
||||
- cpu_buffer->read;
|
||||
|
||||
return ret;
|
||||
return rb_num_of_entries(cpu_buffer);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(ring_buffer_entries_cpu);
|
||||
|
||||
@@ -2684,8 +2694,7 @@ unsigned long ring_buffer_entries(struct ring_buffer *buffer)
|
||||
/* if you care about this being correct, lock the buffer */
|
||||
for_each_buffer_cpu(buffer, cpu) {
|
||||
cpu_buffer = buffer->buffers[cpu];
|
||||
entries += (local_read(&cpu_buffer->entries) -
|
||||
local_read(&cpu_buffer->overrun)) - cpu_buffer->read;
|
||||
entries += rb_num_of_entries(cpu_buffer);
|
||||
}
|
||||
|
||||
return entries;
|
||||
|
||||
@@ -2196,7 +2196,7 @@ int tracing_open_generic(struct inode *inode, struct file *filp)
|
||||
|
||||
static int tracing_release(struct inode *inode, struct file *file)
|
||||
{
|
||||
struct seq_file *m = (struct seq_file *)file->private_data;
|
||||
struct seq_file *m = file->private_data;
|
||||
struct trace_iterator *iter;
|
||||
int cpu;
|
||||
|
||||
|
||||
@@ -343,6 +343,10 @@ void trace_function(struct trace_array *tr,
|
||||
unsigned long ip,
|
||||
unsigned long parent_ip,
|
||||
unsigned long flags, int pc);
|
||||
void trace_graph_function(struct trace_array *tr,
|
||||
unsigned long ip,
|
||||
unsigned long parent_ip,
|
||||
unsigned long flags, int pc);
|
||||
void trace_default_header(struct seq_file *m);
|
||||
void print_trace_header(struct seq_file *m, struct trace_iterator *iter);
|
||||
int trace_empty(struct trace_iterator *iter);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <linux/kprobes.h>
|
||||
#include "trace.h"
|
||||
|
||||
static char *perf_trace_buf[4];
|
||||
static char __percpu *perf_trace_buf[PERF_NR_CONTEXTS];
|
||||
|
||||
/*
|
||||
* Force it to be aligned to unsigned long to avoid misaligned accesses
|
||||
@@ -24,7 +24,7 @@ static int total_ref_count;
|
||||
static int perf_trace_event_init(struct ftrace_event_call *tp_event,
|
||||
struct perf_event *p_event)
|
||||
{
|
||||
struct hlist_head *list;
|
||||
struct hlist_head __percpu *list;
|
||||
int ret = -ENOMEM;
|
||||
int cpu;
|
||||
|
||||
@@ -42,11 +42,11 @@ static int perf_trace_event_init(struct ftrace_event_call *tp_event,
|
||||
tp_event->perf_events = list;
|
||||
|
||||
if (!total_ref_count) {
|
||||
char *buf;
|
||||
char __percpu *buf;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
buf = (char *)alloc_percpu(perf_trace_t);
|
||||
for (i = 0; i < PERF_NR_CONTEXTS; i++) {
|
||||
buf = (char __percpu *)alloc_percpu(perf_trace_t);
|
||||
if (!buf)
|
||||
goto fail;
|
||||
|
||||
@@ -65,7 +65,7 @@ fail:
|
||||
if (!total_ref_count) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (i = 0; i < PERF_NR_CONTEXTS; i++) {
|
||||
free_percpu(perf_trace_buf[i]);
|
||||
perf_trace_buf[i] = NULL;
|
||||
}
|
||||
@@ -101,22 +101,26 @@ int perf_trace_init(struct perf_event *p_event)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int perf_trace_enable(struct perf_event *p_event)
|
||||
int perf_trace_add(struct perf_event *p_event, int flags)
|
||||
{
|
||||
struct ftrace_event_call *tp_event = p_event->tp_event;
|
||||
struct hlist_head __percpu *pcpu_list;
|
||||
struct hlist_head *list;
|
||||
|
||||
list = tp_event->perf_events;
|
||||
if (WARN_ON_ONCE(!list))
|
||||
pcpu_list = tp_event->perf_events;
|
||||
if (WARN_ON_ONCE(!pcpu_list))
|
||||
return -EINVAL;
|
||||
|
||||
list = this_cpu_ptr(list);
|
||||
if (!(flags & PERF_EF_START))
|
||||
p_event->hw.state = PERF_HES_STOPPED;
|
||||
|
||||
list = this_cpu_ptr(pcpu_list);
|
||||
hlist_add_head_rcu(&p_event->hlist_entry, list);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void perf_trace_disable(struct perf_event *p_event)
|
||||
void perf_trace_del(struct perf_event *p_event, int flags)
|
||||
{
|
||||
hlist_del_rcu(&p_event->hlist_entry);
|
||||
}
|
||||
@@ -142,7 +146,7 @@ void perf_trace_destroy(struct perf_event *p_event)
|
||||
tp_event->perf_events = NULL;
|
||||
|
||||
if (!--total_ref_count) {
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (i = 0; i < PERF_NR_CONTEXTS; i++) {
|
||||
free_percpu(perf_trace_buf[i]);
|
||||
perf_trace_buf[i] = NULL;
|
||||
}
|
||||
|
||||
+18
-37
@@ -600,21 +600,29 @@ out:
|
||||
|
||||
enum {
|
||||
FORMAT_HEADER = 1,
|
||||
FORMAT_PRINTFMT = 2,
|
||||
FORMAT_FIELD_SEPERATOR = 2,
|
||||
FORMAT_PRINTFMT = 3,
|
||||
};
|
||||
|
||||
static void *f_next(struct seq_file *m, void *v, loff_t *pos)
|
||||
{
|
||||
struct ftrace_event_call *call = m->private;
|
||||
struct ftrace_event_field *field;
|
||||
struct list_head *head;
|
||||
struct list_head *common_head = &ftrace_common_fields;
|
||||
struct list_head *head = trace_get_fields(call);
|
||||
|
||||
(*pos)++;
|
||||
|
||||
switch ((unsigned long)v) {
|
||||
case FORMAT_HEADER:
|
||||
head = &ftrace_common_fields;
|
||||
if (unlikely(list_empty(common_head)))
|
||||
return NULL;
|
||||
|
||||
field = list_entry(common_head->prev,
|
||||
struct ftrace_event_field, link);
|
||||
return field;
|
||||
|
||||
case FORMAT_FIELD_SEPERATOR:
|
||||
if (unlikely(list_empty(head)))
|
||||
return NULL;
|
||||
|
||||
@@ -626,31 +634,10 @@ static void *f_next(struct seq_file *m, void *v, loff_t *pos)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
head = trace_get_fields(call);
|
||||
|
||||
/*
|
||||
* To separate common fields from event fields, the
|
||||
* LSB is set on the first event field. Clear it in case.
|
||||
*/
|
||||
v = (void *)((unsigned long)v & ~1L);
|
||||
|
||||
field = v;
|
||||
/*
|
||||
* If this is a common field, and at the end of the list, then
|
||||
* continue with main list.
|
||||
*/
|
||||
if (field->link.prev == &ftrace_common_fields) {
|
||||
if (unlikely(list_empty(head)))
|
||||
return NULL;
|
||||
field = list_entry(head->prev, struct ftrace_event_field, link);
|
||||
/* Set the LSB to notify f_show to print an extra newline */
|
||||
field = (struct ftrace_event_field *)
|
||||
((unsigned long)field | 1);
|
||||
return field;
|
||||
}
|
||||
|
||||
/* If we are done tell f_show to print the format */
|
||||
if (field->link.prev == head)
|
||||
if (field->link.prev == common_head)
|
||||
return (void *)FORMAT_FIELD_SEPERATOR;
|
||||
else if (field->link.prev == head)
|
||||
return (void *)FORMAT_PRINTFMT;
|
||||
|
||||
field = list_entry(field->link.prev, struct ftrace_event_field, link);
|
||||
@@ -688,22 +675,16 @@ static int f_show(struct seq_file *m, void *v)
|
||||
seq_printf(m, "format:\n");
|
||||
return 0;
|
||||
|
||||
case FORMAT_FIELD_SEPERATOR:
|
||||
seq_putc(m, '\n');
|
||||
return 0;
|
||||
|
||||
case FORMAT_PRINTFMT:
|
||||
seq_printf(m, "\nprint fmt: %s\n",
|
||||
call->print_fmt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* To separate common fields from event fields, the
|
||||
* LSB is set on the first event field. Clear it and
|
||||
* print a newline if it is set.
|
||||
*/
|
||||
if ((unsigned long)v & 1) {
|
||||
seq_putc(m, '\n');
|
||||
v = (void *)((unsigned long)v & ~1L);
|
||||
}
|
||||
|
||||
field = v;
|
||||
|
||||
/*
|
||||
|
||||
@@ -15,15 +15,19 @@
|
||||
#include "trace.h"
|
||||
#include "trace_output.h"
|
||||
|
||||
/* When set, irq functions will be ignored */
|
||||
static int ftrace_graph_skip_irqs;
|
||||
|
||||
struct fgraph_cpu_data {
|
||||
pid_t last_pid;
|
||||
int depth;
|
||||
int depth_irq;
|
||||
int ignore;
|
||||
unsigned long enter_funcs[FTRACE_RETFUNC_DEPTH];
|
||||
};
|
||||
|
||||
struct fgraph_data {
|
||||
struct fgraph_cpu_data *cpu_data;
|
||||
struct fgraph_cpu_data __percpu *cpu_data;
|
||||
|
||||
/* Place to preserve last processed entry. */
|
||||
struct ftrace_graph_ent_entry ent;
|
||||
@@ -41,6 +45,7 @@ struct fgraph_data {
|
||||
#define TRACE_GRAPH_PRINT_PROC 0x8
|
||||
#define TRACE_GRAPH_PRINT_DURATION 0x10
|
||||
#define TRACE_GRAPH_PRINT_ABS_TIME 0x20
|
||||
#define TRACE_GRAPH_PRINT_IRQS 0x40
|
||||
|
||||
static struct tracer_opt trace_opts[] = {
|
||||
/* Display overruns? (for self-debug purpose) */
|
||||
@@ -55,13 +60,15 @@ static struct tracer_opt trace_opts[] = {
|
||||
{ TRACER_OPT(funcgraph-duration, TRACE_GRAPH_PRINT_DURATION) },
|
||||
/* Display absolute time of an entry */
|
||||
{ TRACER_OPT(funcgraph-abstime, TRACE_GRAPH_PRINT_ABS_TIME) },
|
||||
/* Display interrupts */
|
||||
{ TRACER_OPT(funcgraph-irqs, TRACE_GRAPH_PRINT_IRQS) },
|
||||
{ } /* Empty entry */
|
||||
};
|
||||
|
||||
static struct tracer_flags tracer_flags = {
|
||||
/* Don't display overruns and proc by default */
|
||||
.val = TRACE_GRAPH_PRINT_CPU | TRACE_GRAPH_PRINT_OVERHEAD |
|
||||
TRACE_GRAPH_PRINT_DURATION,
|
||||
TRACE_GRAPH_PRINT_DURATION | TRACE_GRAPH_PRINT_IRQS,
|
||||
.opts = trace_opts
|
||||
};
|
||||
|
||||
@@ -204,6 +211,14 @@ int __trace_graph_entry(struct trace_array *tr,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline int ftrace_graph_ignore_irqs(void)
|
||||
{
|
||||
if (!ftrace_graph_skip_irqs)
|
||||
return 0;
|
||||
|
||||
return in_irq();
|
||||
}
|
||||
|
||||
int trace_graph_entry(struct ftrace_graph_ent *trace)
|
||||
{
|
||||
struct trace_array *tr = graph_array;
|
||||
@@ -218,7 +233,8 @@ int trace_graph_entry(struct ftrace_graph_ent *trace)
|
||||
return 0;
|
||||
|
||||
/* trace it when it is-nested-in or is a function enabled. */
|
||||
if (!(trace->depth || ftrace_graph_addr(trace->func)))
|
||||
if (!(trace->depth || ftrace_graph_addr(trace->func)) ||
|
||||
ftrace_graph_ignore_irqs())
|
||||
return 0;
|
||||
|
||||
local_irq_save(flags);
|
||||
@@ -246,6 +262,34 @@ int trace_graph_thresh_entry(struct ftrace_graph_ent *trace)
|
||||
return trace_graph_entry(trace);
|
||||
}
|
||||
|
||||
static void
|
||||
__trace_graph_function(struct trace_array *tr,
|
||||
unsigned long ip, unsigned long flags, int pc)
|
||||
{
|
||||
u64 time = trace_clock_local();
|
||||
struct ftrace_graph_ent ent = {
|
||||
.func = ip,
|
||||
.depth = 0,
|
||||
};
|
||||
struct ftrace_graph_ret ret = {
|
||||
.func = ip,
|
||||
.depth = 0,
|
||||
.calltime = time,
|
||||
.rettime = time,
|
||||
};
|
||||
|
||||
__trace_graph_entry(tr, &ent, flags, pc);
|
||||
__trace_graph_return(tr, &ret, flags, pc);
|
||||
}
|
||||
|
||||
void
|
||||
trace_graph_function(struct trace_array *tr,
|
||||
unsigned long ip, unsigned long parent_ip,
|
||||
unsigned long flags, int pc)
|
||||
{
|
||||
__trace_graph_function(tr, ip, flags, pc);
|
||||
}
|
||||
|
||||
void __trace_graph_return(struct trace_array *tr,
|
||||
struct ftrace_graph_ret *trace,
|
||||
unsigned long flags,
|
||||
@@ -649,8 +693,9 @@ trace_print_graph_duration(unsigned long long duration, struct trace_seq *s)
|
||||
|
||||
/* Print nsecs (we don't want to exceed 7 numbers) */
|
||||
if (len < 7) {
|
||||
snprintf(nsecs_str, min(sizeof(nsecs_str), 8UL - len), "%03lu",
|
||||
nsecs_rem);
|
||||
size_t slen = min_t(size_t, sizeof(nsecs_str), 8UL - len);
|
||||
|
||||
snprintf(nsecs_str, slen, "%03lu", nsecs_rem);
|
||||
ret = trace_seq_printf(s, ".%s", nsecs_str);
|
||||
if (!ret)
|
||||
return TRACE_TYPE_PARTIAL_LINE;
|
||||
@@ -855,6 +900,108 @@ print_graph_prologue(struct trace_iterator *iter, struct trace_seq *s,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Entry check for irq code
|
||||
*
|
||||
* returns 1 if
|
||||
* - we are inside irq code
|
||||
* - we just extered irq code
|
||||
*
|
||||
* retunns 0 if
|
||||
* - funcgraph-interrupts option is set
|
||||
* - we are not inside irq code
|
||||
*/
|
||||
static int
|
||||
check_irq_entry(struct trace_iterator *iter, u32 flags,
|
||||
unsigned long addr, int depth)
|
||||
{
|
||||
int cpu = iter->cpu;
|
||||
int *depth_irq;
|
||||
struct fgraph_data *data = iter->private;
|
||||
|
||||
/*
|
||||
* If we are either displaying irqs, or we got called as
|
||||
* a graph event and private data does not exist,
|
||||
* then we bypass the irq check.
|
||||
*/
|
||||
if ((flags & TRACE_GRAPH_PRINT_IRQS) ||
|
||||
(!data))
|
||||
return 0;
|
||||
|
||||
depth_irq = &(per_cpu_ptr(data->cpu_data, cpu)->depth_irq);
|
||||
|
||||
/*
|
||||
* We are inside the irq code
|
||||
*/
|
||||
if (*depth_irq >= 0)
|
||||
return 1;
|
||||
|
||||
if ((addr < (unsigned long)__irqentry_text_start) ||
|
||||
(addr >= (unsigned long)__irqentry_text_end))
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* We are entering irq code.
|
||||
*/
|
||||
*depth_irq = depth;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return check for irq code
|
||||
*
|
||||
* returns 1 if
|
||||
* - we are inside irq code
|
||||
* - we just left irq code
|
||||
*
|
||||
* returns 0 if
|
||||
* - funcgraph-interrupts option is set
|
||||
* - we are not inside irq code
|
||||
*/
|
||||
static int
|
||||
check_irq_return(struct trace_iterator *iter, u32 flags, int depth)
|
||||
{
|
||||
int cpu = iter->cpu;
|
||||
int *depth_irq;
|
||||
struct fgraph_data *data = iter->private;
|
||||
|
||||
/*
|
||||
* If we are either displaying irqs, or we got called as
|
||||
* a graph event and private data does not exist,
|
||||
* then we bypass the irq check.
|
||||
*/
|
||||
if ((flags & TRACE_GRAPH_PRINT_IRQS) ||
|
||||
(!data))
|
||||
return 0;
|
||||
|
||||
depth_irq = &(per_cpu_ptr(data->cpu_data, cpu)->depth_irq);
|
||||
|
||||
/*
|
||||
* We are not inside the irq code.
|
||||
*/
|
||||
if (*depth_irq == -1)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* We are inside the irq code, and this is returning entry.
|
||||
* Let's not trace it and clear the entry depth, since
|
||||
* we are out of irq code.
|
||||
*
|
||||
* This condition ensures that we 'leave the irq code' once
|
||||
* we are out of the entry depth. Thus protecting us from
|
||||
* the RETURN entry loss.
|
||||
*/
|
||||
if (*depth_irq >= depth) {
|
||||
*depth_irq = -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* We are inside the irq code, and this is not the entry.
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
static enum print_line_t
|
||||
print_graph_entry(struct ftrace_graph_ent_entry *field, struct trace_seq *s,
|
||||
struct trace_iterator *iter, u32 flags)
|
||||
@@ -865,6 +1012,9 @@ print_graph_entry(struct ftrace_graph_ent_entry *field, struct trace_seq *s,
|
||||
static enum print_line_t ret;
|
||||
int cpu = iter->cpu;
|
||||
|
||||
if (check_irq_entry(iter, flags, call->func, call->depth))
|
||||
return TRACE_TYPE_HANDLED;
|
||||
|
||||
if (print_graph_prologue(iter, s, TRACE_GRAPH_ENT, call->func, flags))
|
||||
return TRACE_TYPE_PARTIAL_LINE;
|
||||
|
||||
@@ -902,6 +1052,9 @@ print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s,
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
if (check_irq_return(iter, flags, trace->depth))
|
||||
return TRACE_TYPE_HANDLED;
|
||||
|
||||
if (data) {
|
||||
struct fgraph_cpu_data *cpu_data;
|
||||
int cpu = iter->cpu;
|
||||
@@ -1054,7 +1207,7 @@ print_graph_comment(struct trace_seq *s, struct trace_entry *ent,
|
||||
|
||||
|
||||
enum print_line_t
|
||||
print_graph_function_flags(struct trace_iterator *iter, u32 flags)
|
||||
__print_graph_function_flags(struct trace_iterator *iter, u32 flags)
|
||||
{
|
||||
struct ftrace_graph_ent_entry *field;
|
||||
struct fgraph_data *data = iter->private;
|
||||
@@ -1117,7 +1270,18 @@ print_graph_function_flags(struct trace_iterator *iter, u32 flags)
|
||||
static enum print_line_t
|
||||
print_graph_function(struct trace_iterator *iter)
|
||||
{
|
||||
return print_graph_function_flags(iter, tracer_flags.val);
|
||||
return __print_graph_function_flags(iter, tracer_flags.val);
|
||||
}
|
||||
|
||||
enum print_line_t print_graph_function_flags(struct trace_iterator *iter,
|
||||
u32 flags)
|
||||
{
|
||||
if (trace_flags & TRACE_ITER_LATENCY_FMT)
|
||||
flags |= TRACE_GRAPH_PRINT_DURATION;
|
||||
else
|
||||
flags |= TRACE_GRAPH_PRINT_ABS_TIME;
|
||||
|
||||
return __print_graph_function_flags(iter, flags);
|
||||
}
|
||||
|
||||
static enum print_line_t
|
||||
@@ -1149,7 +1313,7 @@ static void print_lat_header(struct seq_file *s, u32 flags)
|
||||
seq_printf(s, "#%.*s|||| / \n", size, spaces);
|
||||
}
|
||||
|
||||
void print_graph_headers_flags(struct seq_file *s, u32 flags)
|
||||
static void __print_graph_headers_flags(struct seq_file *s, u32 flags)
|
||||
{
|
||||
int lat = trace_flags & TRACE_ITER_LATENCY_FMT;
|
||||
|
||||
@@ -1190,6 +1354,23 @@ void print_graph_headers(struct seq_file *s)
|
||||
print_graph_headers_flags(s, tracer_flags.val);
|
||||
}
|
||||
|
||||
void print_graph_headers_flags(struct seq_file *s, u32 flags)
|
||||
{
|
||||
struct trace_iterator *iter = s->private;
|
||||
|
||||
if (trace_flags & TRACE_ITER_LATENCY_FMT) {
|
||||
/* print nothing if the buffers are empty */
|
||||
if (trace_empty(iter))
|
||||
return;
|
||||
|
||||
print_trace_header(s, iter);
|
||||
flags |= TRACE_GRAPH_PRINT_DURATION;
|
||||
} else
|
||||
flags |= TRACE_GRAPH_PRINT_ABS_TIME;
|
||||
|
||||
__print_graph_headers_flags(s, flags);
|
||||
}
|
||||
|
||||
void graph_trace_open(struct trace_iterator *iter)
|
||||
{
|
||||
/* pid and depth on the last trace processed */
|
||||
@@ -1210,9 +1391,12 @@ void graph_trace_open(struct trace_iterator *iter)
|
||||
pid_t *pid = &(per_cpu_ptr(data->cpu_data, cpu)->last_pid);
|
||||
int *depth = &(per_cpu_ptr(data->cpu_data, cpu)->depth);
|
||||
int *ignore = &(per_cpu_ptr(data->cpu_data, cpu)->ignore);
|
||||
int *depth_irq = &(per_cpu_ptr(data->cpu_data, cpu)->depth_irq);
|
||||
|
||||
*pid = -1;
|
||||
*depth = 0;
|
||||
*ignore = 0;
|
||||
*depth_irq = -1;
|
||||
}
|
||||
|
||||
iter->private = data;
|
||||
@@ -1235,6 +1419,14 @@ void graph_trace_close(struct trace_iterator *iter)
|
||||
}
|
||||
}
|
||||
|
||||
static int func_graph_set_flag(u32 old_flags, u32 bit, int set)
|
||||
{
|
||||
if (bit == TRACE_GRAPH_PRINT_IRQS)
|
||||
ftrace_graph_skip_irqs = !set;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct trace_event_functions graph_functions = {
|
||||
.trace = print_graph_function_event,
|
||||
};
|
||||
@@ -1261,6 +1453,7 @@ static struct tracer graph_trace __read_mostly = {
|
||||
.print_line = print_graph_function,
|
||||
.print_header = print_graph_headers,
|
||||
.flags = &tracer_flags,
|
||||
.set_flag = func_graph_set_flag,
|
||||
#ifdef CONFIG_FTRACE_SELFTEST
|
||||
.selftest = trace_selftest_startup_function_graph,
|
||||
#endif
|
||||
|
||||
@@ -87,14 +87,22 @@ static __cacheline_aligned_in_smp unsigned long max_sequence;
|
||||
|
||||
#ifdef CONFIG_FUNCTION_TRACER
|
||||
/*
|
||||
* irqsoff uses its own tracer function to keep the overhead down:
|
||||
* Prologue for the preempt and irqs off function tracers.
|
||||
*
|
||||
* Returns 1 if it is OK to continue, and data->disabled is
|
||||
* incremented.
|
||||
* 0 if the trace is to be ignored, and data->disabled
|
||||
* is kept the same.
|
||||
*
|
||||
* Note, this function is also used outside this ifdef but
|
||||
* inside the #ifdef of the function graph tracer below.
|
||||
* This is OK, since the function graph tracer is
|
||||
* dependent on the function tracer.
|
||||
*/
|
||||
static void
|
||||
irqsoff_tracer_call(unsigned long ip, unsigned long parent_ip)
|
||||
static int func_prolog_dec(struct trace_array *tr,
|
||||
struct trace_array_cpu **data,
|
||||
unsigned long *flags)
|
||||
{
|
||||
struct trace_array *tr = irqsoff_trace;
|
||||
struct trace_array_cpu *data;
|
||||
unsigned long flags;
|
||||
long disabled;
|
||||
int cpu;
|
||||
|
||||
@@ -106,18 +114,38 @@ irqsoff_tracer_call(unsigned long ip, unsigned long parent_ip)
|
||||
*/
|
||||
cpu = raw_smp_processor_id();
|
||||
if (likely(!per_cpu(tracing_cpu, cpu)))
|
||||
return;
|
||||
return 0;
|
||||
|
||||
local_save_flags(flags);
|
||||
local_save_flags(*flags);
|
||||
/* slight chance to get a false positive on tracing_cpu */
|
||||
if (!irqs_disabled_flags(flags))
|
||||
return;
|
||||
if (!irqs_disabled_flags(*flags))
|
||||
return 0;
|
||||
|
||||
data = tr->data[cpu];
|
||||
disabled = atomic_inc_return(&data->disabled);
|
||||
*data = tr->data[cpu];
|
||||
disabled = atomic_inc_return(&(*data)->disabled);
|
||||
|
||||
if (likely(disabled == 1))
|
||||
trace_function(tr, ip, parent_ip, flags, preempt_count());
|
||||
return 1;
|
||||
|
||||
atomic_dec(&(*data)->disabled);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* irqsoff uses its own tracer function to keep the overhead down:
|
||||
*/
|
||||
static void
|
||||
irqsoff_tracer_call(unsigned long ip, unsigned long parent_ip)
|
||||
{
|
||||
struct trace_array *tr = irqsoff_trace;
|
||||
struct trace_array_cpu *data;
|
||||
unsigned long flags;
|
||||
|
||||
if (!func_prolog_dec(tr, &data, &flags))
|
||||
return;
|
||||
|
||||
trace_function(tr, ip, parent_ip, flags, preempt_count());
|
||||
|
||||
atomic_dec(&data->disabled);
|
||||
}
|
||||
@@ -155,30 +183,16 @@ static int irqsoff_graph_entry(struct ftrace_graph_ent *trace)
|
||||
struct trace_array *tr = irqsoff_trace;
|
||||
struct trace_array_cpu *data;
|
||||
unsigned long flags;
|
||||
long disabled;
|
||||
int ret;
|
||||
int cpu;
|
||||
int pc;
|
||||
|
||||
cpu = raw_smp_processor_id();
|
||||
if (likely(!per_cpu(tracing_cpu, cpu)))
|
||||
if (!func_prolog_dec(tr, &data, &flags))
|
||||
return 0;
|
||||
|
||||
local_save_flags(flags);
|
||||
/* slight chance to get a false positive on tracing_cpu */
|
||||
if (!irqs_disabled_flags(flags))
|
||||
return 0;
|
||||
|
||||
data = tr->data[cpu];
|
||||
disabled = atomic_inc_return(&data->disabled);
|
||||
|
||||
if (likely(disabled == 1)) {
|
||||
pc = preempt_count();
|
||||
ret = __trace_graph_entry(tr, trace, flags, pc);
|
||||
} else
|
||||
ret = 0;
|
||||
|
||||
pc = preempt_count();
|
||||
ret = __trace_graph_entry(tr, trace, flags, pc);
|
||||
atomic_dec(&data->disabled);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -187,27 +201,13 @@ static void irqsoff_graph_return(struct ftrace_graph_ret *trace)
|
||||
struct trace_array *tr = irqsoff_trace;
|
||||
struct trace_array_cpu *data;
|
||||
unsigned long flags;
|
||||
long disabled;
|
||||
int cpu;
|
||||
int pc;
|
||||
|
||||
cpu = raw_smp_processor_id();
|
||||
if (likely(!per_cpu(tracing_cpu, cpu)))
|
||||
if (!func_prolog_dec(tr, &data, &flags))
|
||||
return;
|
||||
|
||||
local_save_flags(flags);
|
||||
/* slight chance to get a false positive on tracing_cpu */
|
||||
if (!irqs_disabled_flags(flags))
|
||||
return;
|
||||
|
||||
data = tr->data[cpu];
|
||||
disabled = atomic_inc_return(&data->disabled);
|
||||
|
||||
if (likely(disabled == 1)) {
|
||||
pc = preempt_count();
|
||||
__trace_graph_return(tr, trace, flags, pc);
|
||||
}
|
||||
|
||||
pc = preempt_count();
|
||||
__trace_graph_return(tr, trace, flags, pc);
|
||||
atomic_dec(&data->disabled);
|
||||
}
|
||||
|
||||
@@ -229,75 +229,33 @@ static void irqsoff_trace_close(struct trace_iterator *iter)
|
||||
|
||||
static enum print_line_t irqsoff_print_line(struct trace_iterator *iter)
|
||||
{
|
||||
u32 flags = GRAPH_TRACER_FLAGS;
|
||||
|
||||
if (trace_flags & TRACE_ITER_LATENCY_FMT)
|
||||
flags |= TRACE_GRAPH_PRINT_DURATION;
|
||||
else
|
||||
flags |= TRACE_GRAPH_PRINT_ABS_TIME;
|
||||
|
||||
/*
|
||||
* In graph mode call the graph tracer output function,
|
||||
* otherwise go with the TRACE_FN event handler
|
||||
*/
|
||||
if (is_graph())
|
||||
return print_graph_function_flags(iter, flags);
|
||||
return print_graph_function_flags(iter, GRAPH_TRACER_FLAGS);
|
||||
|
||||
return TRACE_TYPE_UNHANDLED;
|
||||
}
|
||||
|
||||
static void irqsoff_print_header(struct seq_file *s)
|
||||
{
|
||||
if (is_graph()) {
|
||||
struct trace_iterator *iter = s->private;
|
||||
u32 flags = GRAPH_TRACER_FLAGS;
|
||||
|
||||
if (trace_flags & TRACE_ITER_LATENCY_FMT) {
|
||||
/* print nothing if the buffers are empty */
|
||||
if (trace_empty(iter))
|
||||
return;
|
||||
|
||||
print_trace_header(s, iter);
|
||||
flags |= TRACE_GRAPH_PRINT_DURATION;
|
||||
} else
|
||||
flags |= TRACE_GRAPH_PRINT_ABS_TIME;
|
||||
|
||||
print_graph_headers_flags(s, flags);
|
||||
} else
|
||||
if (is_graph())
|
||||
print_graph_headers_flags(s, GRAPH_TRACER_FLAGS);
|
||||
else
|
||||
trace_default_header(s);
|
||||
}
|
||||
|
||||
static void
|
||||
trace_graph_function(struct trace_array *tr,
|
||||
unsigned long ip, unsigned long flags, int pc)
|
||||
{
|
||||
u64 time = trace_clock_local();
|
||||
struct ftrace_graph_ent ent = {
|
||||
.func = ip,
|
||||
.depth = 0,
|
||||
};
|
||||
struct ftrace_graph_ret ret = {
|
||||
.func = ip,
|
||||
.depth = 0,
|
||||
.calltime = time,
|
||||
.rettime = time,
|
||||
};
|
||||
|
||||
__trace_graph_entry(tr, &ent, flags, pc);
|
||||
__trace_graph_return(tr, &ret, flags, pc);
|
||||
}
|
||||
|
||||
static void
|
||||
__trace_function(struct trace_array *tr,
|
||||
unsigned long ip, unsigned long parent_ip,
|
||||
unsigned long flags, int pc)
|
||||
{
|
||||
if (!is_graph())
|
||||
if (is_graph())
|
||||
trace_graph_function(tr, ip, parent_ip, flags, pc);
|
||||
else
|
||||
trace_function(tr, ip, parent_ip, flags, pc);
|
||||
else {
|
||||
trace_graph_function(tr, parent_ip, flags, pc);
|
||||
trace_graph_function(tr, ip, flags, pc);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@@ -31,13 +31,81 @@ static int wakeup_rt;
|
||||
static arch_spinlock_t wakeup_lock =
|
||||
(arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED;
|
||||
|
||||
static void wakeup_reset(struct trace_array *tr);
|
||||
static void __wakeup_reset(struct trace_array *tr);
|
||||
static int wakeup_graph_entry(struct ftrace_graph_ent *trace);
|
||||
static void wakeup_graph_return(struct ftrace_graph_ret *trace);
|
||||
|
||||
static int save_lat_flag;
|
||||
|
||||
#define TRACE_DISPLAY_GRAPH 1
|
||||
|
||||
static struct tracer_opt trace_opts[] = {
|
||||
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
|
||||
/* display latency trace as call graph */
|
||||
{ TRACER_OPT(display-graph, TRACE_DISPLAY_GRAPH) },
|
||||
#endif
|
||||
{ } /* Empty entry */
|
||||
};
|
||||
|
||||
static struct tracer_flags tracer_flags = {
|
||||
.val = 0,
|
||||
.opts = trace_opts,
|
||||
};
|
||||
|
||||
#define is_graph() (tracer_flags.val & TRACE_DISPLAY_GRAPH)
|
||||
|
||||
#ifdef CONFIG_FUNCTION_TRACER
|
||||
|
||||
/*
|
||||
* irqsoff uses its own tracer function to keep the overhead down:
|
||||
* Prologue for the wakeup function tracers.
|
||||
*
|
||||
* Returns 1 if it is OK to continue, and preemption
|
||||
* is disabled and data->disabled is incremented.
|
||||
* 0 if the trace is to be ignored, and preemption
|
||||
* is not disabled and data->disabled is
|
||||
* kept the same.
|
||||
*
|
||||
* Note, this function is also used outside this ifdef but
|
||||
* inside the #ifdef of the function graph tracer below.
|
||||
* This is OK, since the function graph tracer is
|
||||
* dependent on the function tracer.
|
||||
*/
|
||||
static int
|
||||
func_prolog_preempt_disable(struct trace_array *tr,
|
||||
struct trace_array_cpu **data,
|
||||
int *pc)
|
||||
{
|
||||
long disabled;
|
||||
int cpu;
|
||||
|
||||
if (likely(!wakeup_task))
|
||||
return 0;
|
||||
|
||||
*pc = preempt_count();
|
||||
preempt_disable_notrace();
|
||||
|
||||
cpu = raw_smp_processor_id();
|
||||
if (cpu != wakeup_current_cpu)
|
||||
goto out_enable;
|
||||
|
||||
*data = tr->data[cpu];
|
||||
disabled = atomic_inc_return(&(*data)->disabled);
|
||||
if (unlikely(disabled != 1))
|
||||
goto out;
|
||||
|
||||
return 1;
|
||||
|
||||
out:
|
||||
atomic_dec(&(*data)->disabled);
|
||||
|
||||
out_enable:
|
||||
preempt_enable_notrace();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* wakeup uses its own tracer function to keep the overhead down:
|
||||
*/
|
||||
static void
|
||||
wakeup_tracer_call(unsigned long ip, unsigned long parent_ip)
|
||||
@@ -45,34 +113,16 @@ wakeup_tracer_call(unsigned long ip, unsigned long parent_ip)
|
||||
struct trace_array *tr = wakeup_trace;
|
||||
struct trace_array_cpu *data;
|
||||
unsigned long flags;
|
||||
long disabled;
|
||||
int cpu;
|
||||
int pc;
|
||||
|
||||
if (likely(!wakeup_task))
|
||||
if (!func_prolog_preempt_disable(tr, &data, &pc))
|
||||
return;
|
||||
|
||||
pc = preempt_count();
|
||||
preempt_disable_notrace();
|
||||
|
||||
cpu = raw_smp_processor_id();
|
||||
if (cpu != wakeup_current_cpu)
|
||||
goto out_enable;
|
||||
|
||||
data = tr->data[cpu];
|
||||
disabled = atomic_inc_return(&data->disabled);
|
||||
if (unlikely(disabled != 1))
|
||||
goto out;
|
||||
|
||||
local_irq_save(flags);
|
||||
|
||||
trace_function(tr, ip, parent_ip, flags, pc);
|
||||
|
||||
local_irq_restore(flags);
|
||||
|
||||
out:
|
||||
atomic_dec(&data->disabled);
|
||||
out_enable:
|
||||
preempt_enable_notrace();
|
||||
}
|
||||
|
||||
@@ -82,6 +132,156 @@ static struct ftrace_ops trace_ops __read_mostly =
|
||||
};
|
||||
#endif /* CONFIG_FUNCTION_TRACER */
|
||||
|
||||
static int start_func_tracer(int graph)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!graph)
|
||||
ret = register_ftrace_function(&trace_ops);
|
||||
else
|
||||
ret = register_ftrace_graph(&wakeup_graph_return,
|
||||
&wakeup_graph_entry);
|
||||
|
||||
if (!ret && tracing_is_enabled())
|
||||
tracer_enabled = 1;
|
||||
else
|
||||
tracer_enabled = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void stop_func_tracer(int graph)
|
||||
{
|
||||
tracer_enabled = 0;
|
||||
|
||||
if (!graph)
|
||||
unregister_ftrace_function(&trace_ops);
|
||||
else
|
||||
unregister_ftrace_graph();
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
|
||||
static int wakeup_set_flag(u32 old_flags, u32 bit, int set)
|
||||
{
|
||||
|
||||
if (!(bit & TRACE_DISPLAY_GRAPH))
|
||||
return -EINVAL;
|
||||
|
||||
if (!(is_graph() ^ set))
|
||||
return 0;
|
||||
|
||||
stop_func_tracer(!set);
|
||||
|
||||
wakeup_reset(wakeup_trace);
|
||||
tracing_max_latency = 0;
|
||||
|
||||
return start_func_tracer(set);
|
||||
}
|
||||
|
||||
static int wakeup_graph_entry(struct ftrace_graph_ent *trace)
|
||||
{
|
||||
struct trace_array *tr = wakeup_trace;
|
||||
struct trace_array_cpu *data;
|
||||
unsigned long flags;
|
||||
int pc, ret = 0;
|
||||
|
||||
if (!func_prolog_preempt_disable(tr, &data, &pc))
|
||||
return 0;
|
||||
|
||||
local_save_flags(flags);
|
||||
ret = __trace_graph_entry(tr, trace, flags, pc);
|
||||
atomic_dec(&data->disabled);
|
||||
preempt_enable_notrace();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void wakeup_graph_return(struct ftrace_graph_ret *trace)
|
||||
{
|
||||
struct trace_array *tr = wakeup_trace;
|
||||
struct trace_array_cpu *data;
|
||||
unsigned long flags;
|
||||
int pc;
|
||||
|
||||
if (!func_prolog_preempt_disable(tr, &data, &pc))
|
||||
return;
|
||||
|
||||
local_save_flags(flags);
|
||||
__trace_graph_return(tr, trace, flags, pc);
|
||||
atomic_dec(&data->disabled);
|
||||
|
||||
preempt_enable_notrace();
|
||||
return;
|
||||
}
|
||||
|
||||
static void wakeup_trace_open(struct trace_iterator *iter)
|
||||
{
|
||||
if (is_graph())
|
||||
graph_trace_open(iter);
|
||||
}
|
||||
|
||||
static void wakeup_trace_close(struct trace_iterator *iter)
|
||||
{
|
||||
if (iter->private)
|
||||
graph_trace_close(iter);
|
||||
}
|
||||
|
||||
#define GRAPH_TRACER_FLAGS (TRACE_GRAPH_PRINT_PROC)
|
||||
|
||||
static enum print_line_t wakeup_print_line(struct trace_iterator *iter)
|
||||
{
|
||||
/*
|
||||
* In graph mode call the graph tracer output function,
|
||||
* otherwise go with the TRACE_FN event handler
|
||||
*/
|
||||
if (is_graph())
|
||||
return print_graph_function_flags(iter, GRAPH_TRACER_FLAGS);
|
||||
|
||||
return TRACE_TYPE_UNHANDLED;
|
||||
}
|
||||
|
||||
static void wakeup_print_header(struct seq_file *s)
|
||||
{
|
||||
if (is_graph())
|
||||
print_graph_headers_flags(s, GRAPH_TRACER_FLAGS);
|
||||
else
|
||||
trace_default_header(s);
|
||||
}
|
||||
|
||||
static void
|
||||
__trace_function(struct trace_array *tr,
|
||||
unsigned long ip, unsigned long parent_ip,
|
||||
unsigned long flags, int pc)
|
||||
{
|
||||
if (is_graph())
|
||||
trace_graph_function(tr, ip, parent_ip, flags, pc);
|
||||
else
|
||||
trace_function(tr, ip, parent_ip, flags, pc);
|
||||
}
|
||||
#else
|
||||
#define __trace_function trace_function
|
||||
|
||||
static int wakeup_set_flag(u32 old_flags, u32 bit, int set)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static int wakeup_graph_entry(struct ftrace_graph_ent *trace)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static enum print_line_t wakeup_print_line(struct trace_iterator *iter)
|
||||
{
|
||||
return TRACE_TYPE_UNHANDLED;
|
||||
}
|
||||
|
||||
static void wakeup_graph_return(struct ftrace_graph_ret *trace) { }
|
||||
static void wakeup_print_header(struct seq_file *s) { }
|
||||
static void wakeup_trace_open(struct trace_iterator *iter) { }
|
||||
static void wakeup_trace_close(struct trace_iterator *iter) { }
|
||||
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
|
||||
|
||||
/*
|
||||
* Should this new latency be reported/recorded?
|
||||
*/
|
||||
@@ -152,7 +352,7 @@ probe_wakeup_sched_switch(void *ignore,
|
||||
/* The task we are waiting for is waking up */
|
||||
data = wakeup_trace->data[wakeup_cpu];
|
||||
|
||||
trace_function(wakeup_trace, CALLER_ADDR0, CALLER_ADDR1, flags, pc);
|
||||
__trace_function(wakeup_trace, CALLER_ADDR0, CALLER_ADDR1, flags, pc);
|
||||
tracing_sched_switch_trace(wakeup_trace, prev, next, flags, pc);
|
||||
|
||||
T0 = data->preempt_timestamp;
|
||||
@@ -252,7 +452,7 @@ probe_wakeup(void *ignore, struct task_struct *p, int success)
|
||||
* is not called by an assembly function (where as schedule is)
|
||||
* it should be safe to use it here.
|
||||
*/
|
||||
trace_function(wakeup_trace, CALLER_ADDR1, CALLER_ADDR2, flags, pc);
|
||||
__trace_function(wakeup_trace, CALLER_ADDR1, CALLER_ADDR2, flags, pc);
|
||||
|
||||
out_locked:
|
||||
arch_spin_unlock(&wakeup_lock);
|
||||
@@ -303,12 +503,8 @@ static void start_wakeup_tracer(struct trace_array *tr)
|
||||
*/
|
||||
smp_wmb();
|
||||
|
||||
register_ftrace_function(&trace_ops);
|
||||
|
||||
if (tracing_is_enabled())
|
||||
tracer_enabled = 1;
|
||||
else
|
||||
tracer_enabled = 0;
|
||||
if (start_func_tracer(is_graph()))
|
||||
printk(KERN_ERR "failed to start wakeup tracer\n");
|
||||
|
||||
return;
|
||||
fail_deprobe_wake_new:
|
||||
@@ -320,7 +516,7 @@ fail_deprobe:
|
||||
static void stop_wakeup_tracer(struct trace_array *tr)
|
||||
{
|
||||
tracer_enabled = 0;
|
||||
unregister_ftrace_function(&trace_ops);
|
||||
stop_func_tracer(is_graph());
|
||||
unregister_trace_sched_switch(probe_wakeup_sched_switch, NULL);
|
||||
unregister_trace_sched_wakeup_new(probe_wakeup, NULL);
|
||||
unregister_trace_sched_wakeup(probe_wakeup, NULL);
|
||||
@@ -379,9 +575,15 @@ static struct tracer wakeup_tracer __read_mostly =
|
||||
.start = wakeup_tracer_start,
|
||||
.stop = wakeup_tracer_stop,
|
||||
.print_max = 1,
|
||||
.print_header = wakeup_print_header,
|
||||
.print_line = wakeup_print_line,
|
||||
.flags = &tracer_flags,
|
||||
.set_flag = wakeup_set_flag,
|
||||
#ifdef CONFIG_FTRACE_SELFTEST
|
||||
.selftest = trace_selftest_startup_wakeup,
|
||||
#endif
|
||||
.open = wakeup_trace_open,
|
||||
.close = wakeup_trace_close,
|
||||
.use_max_tr = 1,
|
||||
};
|
||||
|
||||
@@ -394,9 +596,15 @@ static struct tracer wakeup_rt_tracer __read_mostly =
|
||||
.stop = wakeup_tracer_stop,
|
||||
.wait_pipe = poll_wait_pipe,
|
||||
.print_max = 1,
|
||||
.print_header = wakeup_print_header,
|
||||
.print_line = wakeup_print_line,
|
||||
.flags = &tracer_flags,
|
||||
.set_flag = wakeup_set_flag,
|
||||
#ifdef CONFIG_FTRACE_SELFTEST
|
||||
.selftest = trace_selftest_startup_wakeup,
|
||||
#endif
|
||||
.open = wakeup_trace_open,
|
||||
.close = wakeup_trace_close,
|
||||
.use_max_tr = 1,
|
||||
};
|
||||
|
||||
|
||||
@@ -263,6 +263,11 @@ int __init trace_workqueue_early_init(void)
|
||||
{
|
||||
int ret, cpu;
|
||||
|
||||
for_each_possible_cpu(cpu) {
|
||||
spin_lock_init(&workqueue_cpu_stat(cpu)->lock);
|
||||
INIT_LIST_HEAD(&workqueue_cpu_stat(cpu)->list);
|
||||
}
|
||||
|
||||
ret = register_trace_workqueue_insertion(probe_workqueue_insertion, NULL);
|
||||
if (ret)
|
||||
goto out;
|
||||
@@ -279,11 +284,6 @@ int __init trace_workqueue_early_init(void)
|
||||
if (ret)
|
||||
goto no_creation;
|
||||
|
||||
for_each_possible_cpu(cpu) {
|
||||
spin_lock_init(&workqueue_cpu_stat(cpu)->lock);
|
||||
INIT_LIST_HEAD(&workqueue_cpu_stat(cpu)->list);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
no_creation:
|
||||
|
||||
+12
-2
@@ -25,6 +25,7 @@
|
||||
#include <linux/err.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/jump_label.h>
|
||||
|
||||
extern struct tracepoint __start___tracepoints[];
|
||||
extern struct tracepoint __stop___tracepoints[];
|
||||
@@ -263,7 +264,13 @@ static void set_tracepoint(struct tracepoint_entry **entry,
|
||||
* is used.
|
||||
*/
|
||||
rcu_assign_pointer(elem->funcs, (*entry)->funcs);
|
||||
elem->state = active;
|
||||
if (!elem->state && active) {
|
||||
jump_label_enable(&elem->state);
|
||||
elem->state = active;
|
||||
} else if (elem->state && !active) {
|
||||
jump_label_disable(&elem->state);
|
||||
elem->state = active;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -277,7 +284,10 @@ static void disable_tracepoint(struct tracepoint *elem)
|
||||
if (elem->unregfunc && elem->state)
|
||||
elem->unregfunc();
|
||||
|
||||
elem->state = 0;
|
||||
if (elem->state) {
|
||||
jump_label_disable(&elem->state);
|
||||
elem->state = 0;
|
||||
}
|
||||
rcu_assign_pointer(elem->funcs, NULL);
|
||||
}
|
||||
|
||||
|
||||
+15
-26
@@ -43,7 +43,6 @@ static DEFINE_PER_CPU(unsigned long, hrtimer_interrupts_saved);
|
||||
static DEFINE_PER_CPU(struct perf_event *, watchdog_ev);
|
||||
#endif
|
||||
|
||||
static int __read_mostly did_panic;
|
||||
static int __initdata no_watchdog;
|
||||
|
||||
|
||||
@@ -187,18 +186,6 @@ static int is_softlockup(unsigned long touch_ts)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
watchdog_panic(struct notifier_block *this, unsigned long event, void *ptr)
|
||||
{
|
||||
did_panic = 1;
|
||||
|
||||
return NOTIFY_DONE;
|
||||
}
|
||||
|
||||
static struct notifier_block panic_block = {
|
||||
.notifier_call = watchdog_panic,
|
||||
};
|
||||
|
||||
#ifdef CONFIG_HARDLOCKUP_DETECTOR
|
||||
static struct perf_event_attr wd_hw_attr = {
|
||||
.type = PERF_TYPE_HARDWARE,
|
||||
@@ -371,14 +358,14 @@ static int watchdog_nmi_enable(int cpu)
|
||||
/* Try to register using hardware perf events */
|
||||
wd_attr = &wd_hw_attr;
|
||||
wd_attr->sample_period = hw_nmi_get_sample_period();
|
||||
event = perf_event_create_kernel_counter(wd_attr, cpu, -1, watchdog_overflow_callback);
|
||||
event = perf_event_create_kernel_counter(wd_attr, cpu, NULL, watchdog_overflow_callback);
|
||||
if (!IS_ERR(event)) {
|
||||
printk(KERN_INFO "NMI watchdog enabled, takes one hw-pmu counter.\n");
|
||||
goto out_save;
|
||||
}
|
||||
|
||||
printk(KERN_ERR "NMI watchdog failed to create perf event on cpu%i: %p\n", cpu, event);
|
||||
return -1;
|
||||
return PTR_ERR(event);
|
||||
|
||||
/* success path */
|
||||
out_save:
|
||||
@@ -422,17 +409,19 @@ static int watchdog_prepare_cpu(int cpu)
|
||||
static int watchdog_enable(int cpu)
|
||||
{
|
||||
struct task_struct *p = per_cpu(softlockup_watchdog, cpu);
|
||||
int err;
|
||||
|
||||
/* enable the perf event */
|
||||
if (watchdog_nmi_enable(cpu) != 0)
|
||||
return -1;
|
||||
err = watchdog_nmi_enable(cpu);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/* create the watchdog thread */
|
||||
if (!p) {
|
||||
p = kthread_create(watchdog, (void *)(unsigned long)cpu, "watchdog/%d", cpu);
|
||||
if (IS_ERR(p)) {
|
||||
printk(KERN_ERR "softlockup watchdog for %i failed\n", cpu);
|
||||
return -1;
|
||||
return PTR_ERR(p);
|
||||
}
|
||||
kthread_bind(p, cpu);
|
||||
per_cpu(watchdog_touch_ts, cpu) = 0;
|
||||
@@ -484,6 +473,9 @@ static void watchdog_disable_all_cpus(void)
|
||||
{
|
||||
int cpu;
|
||||
|
||||
if (no_watchdog)
|
||||
return;
|
||||
|
||||
for_each_online_cpu(cpu)
|
||||
watchdog_disable(cpu);
|
||||
|
||||
@@ -526,17 +518,16 @@ static int __cpuinit
|
||||
cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
|
||||
{
|
||||
int hotcpu = (unsigned long)hcpu;
|
||||
int err = 0;
|
||||
|
||||
switch (action) {
|
||||
case CPU_UP_PREPARE:
|
||||
case CPU_UP_PREPARE_FROZEN:
|
||||
if (watchdog_prepare_cpu(hotcpu))
|
||||
return NOTIFY_BAD;
|
||||
err = watchdog_prepare_cpu(hotcpu);
|
||||
break;
|
||||
case CPU_ONLINE:
|
||||
case CPU_ONLINE_FROZEN:
|
||||
if (watchdog_enable(hotcpu))
|
||||
return NOTIFY_BAD;
|
||||
err = watchdog_enable(hotcpu);
|
||||
break;
|
||||
#ifdef CONFIG_HOTPLUG_CPU
|
||||
case CPU_UP_CANCELED:
|
||||
@@ -549,7 +540,7 @@ cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
|
||||
break;
|
||||
#endif /* CONFIG_HOTPLUG_CPU */
|
||||
}
|
||||
return NOTIFY_OK;
|
||||
return notifier_from_errno(err);
|
||||
}
|
||||
|
||||
static struct notifier_block __cpuinitdata cpu_nfb = {
|
||||
@@ -565,13 +556,11 @@ static int __init spawn_watchdog_task(void)
|
||||
return 0;
|
||||
|
||||
err = cpu_callback(&cpu_nfb, CPU_UP_PREPARE, cpu);
|
||||
WARN_ON(err == NOTIFY_BAD);
|
||||
WARN_ON(notifier_to_errno(err));
|
||||
|
||||
cpu_callback(&cpu_nfb, CPU_ONLINE, cpu);
|
||||
register_cpu_notifier(&cpu_nfb);
|
||||
|
||||
atomic_notifier_chain_register(&panic_notifier_list, &panic_block);
|
||||
|
||||
return 0;
|
||||
}
|
||||
early_initcall(spawn_watchdog_task);
|
||||
|
||||
Reference in New Issue
Block a user