2019-05-19 12:08:55 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* linux/kernel/profile.c
|
|
|
|
* Simple profiling. Manages a direct-mapped profile hit count buffer,
|
|
|
|
* with configurable resolution, support for restricting the cpus on
|
|
|
|
* which profiling is done, and switching between cpu time and
|
|
|
|
* schedule() calls via kernel command line parameters passed at boot.
|
|
|
|
*
|
|
|
|
* Scheduler profiling support, Arjan van de Ven and Ingo Molnar,
|
|
|
|
* Red Hat, July 2004
|
|
|
|
* Consolidation of architecture support code for profiling,
|
2012-12-06 09:39:54 +00:00
|
|
|
* Nadia Yvette Chambers, Oracle, July 2004
|
2005-04-16 22:20:36 +00:00
|
|
|
* Amortized hit count accounting via per-cpu open-addressed hashtables
|
2012-12-06 09:39:54 +00:00
|
|
|
* to resolve timer interrupt livelocks, Nadia Yvette Chambers,
|
|
|
|
* Oracle, 2004
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
2011-05-23 18:51:41 +00:00
|
|
|
#include <linux/export.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/profile.h>
|
2018-10-30 22:09:49 +00:00
|
|
|
#include <linux/memblock.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/notifier.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/cpumask.h>
|
|
|
|
#include <linux/cpu.h>
|
|
|
|
#include <linux/highmem.h>
|
2006-03-23 11:00:24 +00:00
|
|
|
#include <linux/mutex.h>
|
2008-10-16 05:01:46 +00:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/vmalloc.h>
|
2017-02-05 11:07:04 +00:00
|
|
|
#include <linux/sched/stat.h>
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/sections.h>
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
#include <asm/irq_regs.h>
|
Detach sched.h from mm.h
First thing mm.h does is including sched.h solely for can_do_mlock() inline
function which has "current" dereference inside. By dealing with can_do_mlock()
mm.h can be detached from sched.h which is good. See below, why.
This patch
a) removes unconditional inclusion of sched.h from mm.h
b) makes can_do_mlock() normal function in mm/mlock.c
c) exports can_do_mlock() to not break compilation
d) adds sched.h inclusions back to files that were getting it indirectly.
e) adds less bloated headers to some files (asm/signal.h, jiffies.h) that were
getting them indirectly
Net result is:
a) mm.h users would get less code to open, read, preprocess, parse, ... if
they don't need sched.h
b) sched.h stops being dependency for significant number of files:
on x86_64 allmodconfig touching sched.h results in recompile of 4083 files,
after patch it's only 3744 (-8.3%).
Cross-compile tested on
all arm defconfigs, all mips defconfigs, all powerpc defconfigs,
alpha alpha-up
arm
i386 i386-up i386-defconfig i386-allnoconfig
ia64 ia64-up
m68k
mips
parisc parisc-up
powerpc powerpc-up
s390 s390-up
sparc sparc-up
sparc64 sparc64-up
um-x86_64
x86_64 x86_64-up x86_64-defconfig x86_64-allnoconfig
as well as my two usual configs.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-20 21:22:52 +00:00
|
|
|
#include <asm/ptrace.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
struct profile_hit {
|
|
|
|
u32 pc, hits;
|
|
|
|
};
|
|
|
|
#define PROFILE_GRPSHIFT 3
|
|
|
|
#define PROFILE_GRPSZ (1 << PROFILE_GRPSHIFT)
|
|
|
|
#define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
|
|
|
|
#define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
|
|
|
|
|
|
|
|
static atomic_t *prof_buffer;
|
|
|
|
static unsigned long prof_len, prof_shift;
|
2007-01-11 07:15:38 +00:00
|
|
|
|
2006-12-07 04:37:24 +00:00
|
|
|
int prof_on __read_mostly;
|
2007-01-11 07:15:38 +00:00
|
|
|
EXPORT_SYMBOL_GPL(prof_on);
|
|
|
|
|
2008-12-31 23:42:27 +00:00
|
|
|
static cpumask_var_t prof_cpu_mask;
|
2016-03-22 21:27:26 +00:00
|
|
|
#if defined(CONFIG_SMP) && defined(CONFIG_PROC_FS)
|
2005-04-16 22:20:36 +00:00
|
|
|
static DEFINE_PER_CPU(struct profile_hit *[2], cpu_profile_hits);
|
|
|
|
static DEFINE_PER_CPU(int, cpu_profile_flip);
|
2006-03-23 11:00:24 +00:00
|
|
|
static DEFINE_MUTEX(profile_flip_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif /* CONFIG_SMP */
|
|
|
|
|
2008-10-16 05:01:46 +00:00
|
|
|
int profile_setup(char *str)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2014-06-06 21:37:30 +00:00
|
|
|
static const char schedstr[] = "schedule";
|
|
|
|
static const char sleepstr[] = "sleep";
|
|
|
|
static const char kvmstr[] = "kvm";
|
2005-04-16 22:20:36 +00:00
|
|
|
int par;
|
|
|
|
|
2006-12-07 04:37:24 +00:00
|
|
|
if (!strncmp(str, sleepstr, strlen(sleepstr))) {
|
2007-10-24 16:23:50 +00:00
|
|
|
#ifdef CONFIG_SCHEDSTATS
|
2016-02-05 09:08:36 +00:00
|
|
|
force_schedstat_enabled();
|
2006-12-07 04:37:24 +00:00
|
|
|
prof_on = SLEEP_PROFILING;
|
|
|
|
if (str[strlen(sleepstr)] == ',')
|
|
|
|
str += strlen(sleepstr) + 1;
|
|
|
|
if (get_option(&str, &par))
|
|
|
|
prof_shift = par;
|
2014-06-06 21:37:29 +00:00
|
|
|
pr_info("kernel sleep profiling enabled (shift: %ld)\n",
|
2006-12-07 04:37:24 +00:00
|
|
|
prof_shift);
|
2007-10-24 16:23:50 +00:00
|
|
|
#else
|
2014-06-06 21:37:29 +00:00
|
|
|
pr_warn("kernel sleep profiling requires CONFIG_SCHEDSTATS\n");
|
2007-10-24 16:23:50 +00:00
|
|
|
#endif /* CONFIG_SCHEDSTATS */
|
2007-01-06 00:36:29 +00:00
|
|
|
} else if (!strncmp(str, schedstr, strlen(schedstr))) {
|
2005-04-16 22:20:36 +00:00
|
|
|
prof_on = SCHED_PROFILING;
|
2005-05-17 04:53:58 +00:00
|
|
|
if (str[strlen(schedstr)] == ',')
|
|
|
|
str += strlen(schedstr) + 1;
|
|
|
|
if (get_option(&str, &par))
|
|
|
|
prof_shift = par;
|
2014-06-06 21:37:29 +00:00
|
|
|
pr_info("kernel schedule profiling enabled (shift: %ld)\n",
|
2005-05-17 04:53:58 +00:00
|
|
|
prof_shift);
|
2007-01-11 07:15:38 +00:00
|
|
|
} else if (!strncmp(str, kvmstr, strlen(kvmstr))) {
|
|
|
|
prof_on = KVM_PROFILING;
|
|
|
|
if (str[strlen(kvmstr)] == ',')
|
|
|
|
str += strlen(kvmstr) + 1;
|
|
|
|
if (get_option(&str, &par))
|
|
|
|
prof_shift = par;
|
2014-06-06 21:37:29 +00:00
|
|
|
pr_info("kernel KVM profiling enabled (shift: %ld)\n",
|
2007-01-11 07:15:38 +00:00
|
|
|
prof_shift);
|
2005-05-17 04:53:58 +00:00
|
|
|
} else if (get_option(&str, &par)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
prof_shift = par;
|
|
|
|
prof_on = CPU_PROFILING;
|
2014-06-06 21:37:29 +00:00
|
|
|
pr_info("kernel profiling enabled (shift: %ld)\n",
|
2005-04-16 22:20:36 +00:00
|
|
|
prof_shift);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("profile=", profile_setup);
|
|
|
|
|
|
|
|
|
2008-10-29 21:01:07 +00:00
|
|
|
int __ref profile_init(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-10-16 05:01:46 +00:00
|
|
|
int buffer_bytes;
|
2008-01-25 20:08:33 +00:00
|
|
|
if (!prof_on)
|
2008-10-16 05:01:46 +00:00
|
|
|
return 0;
|
2008-01-25 20:08:33 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* only text is profiled */
|
|
|
|
prof_len = (_etext - _stext) >> prof_shift;
|
2008-10-16 05:01:46 +00:00
|
|
|
buffer_bytes = prof_len*sizeof(atomic_t);
|
|
|
|
|
2008-12-31 23:42:27 +00:00
|
|
|
if (!alloc_cpumask_var(&prof_cpu_mask, GFP_KERNEL))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2009-02-09 19:20:50 +00:00
|
|
|
cpumask_copy(prof_cpu_mask, cpu_possible_mask);
|
|
|
|
|
2009-07-29 22:04:09 +00:00
|
|
|
prof_buffer = kzalloc(buffer_bytes, GFP_KERNEL|__GFP_NOWARN);
|
2008-10-16 05:01:46 +00:00
|
|
|
if (prof_buffer)
|
|
|
|
return 0;
|
|
|
|
|
2009-07-29 22:04:09 +00:00
|
|
|
prof_buffer = alloc_pages_exact(buffer_bytes,
|
|
|
|
GFP_KERNEL|__GFP_ZERO|__GFP_NOWARN);
|
2008-10-16 05:01:46 +00:00
|
|
|
if (prof_buffer)
|
|
|
|
return 0;
|
|
|
|
|
2010-10-30 19:56:26 +00:00
|
|
|
prof_buffer = vzalloc(buffer_bytes);
|
|
|
|
if (prof_buffer)
|
2008-10-16 05:01:46 +00:00
|
|
|
return 0;
|
|
|
|
|
2008-12-31 23:42:27 +00:00
|
|
|
free_cpumask_var(prof_cpu_mask);
|
2008-10-16 05:01:46 +00:00
|
|
|
return -ENOMEM;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Profile event notifications */
|
2008-01-25 20:08:33 +00:00
|
|
|
|
[PATCH] Notifier chain update: API changes
The kernel's implementation of notifier chains is unsafe. There is no
protection against entries being added to or removed from a chain while the
chain is in use. The issues were discussed in this thread:
http://marc.theaimsgroup.com/?l=linux-kernel&m=113018709002036&w=2
We noticed that notifier chains in the kernel fall into two basic usage
classes:
"Blocking" chains are always called from a process context
and the callout routines are allowed to sleep;
"Atomic" chains can be called from an atomic context and
the callout routines are not allowed to sleep.
We decided to codify this distinction and make it part of the API. Therefore
this set of patches introduces three new, parallel APIs: one for blocking
notifiers, one for atomic notifiers, and one for "raw" notifiers (which is
really just the old API under a new name). New kinds of data structures are
used for the heads of the chains, and new routines are defined for
registration, unregistration, and calling a chain. The three APIs are
explained in include/linux/notifier.h and their implementation is in
kernel/sys.c.
With atomic and blocking chains, the implementation guarantees that the chain
links will not be corrupted and that chain callers will not get messed up by
entries being added or removed. For raw chains the implementation provides no
guarantees at all; users of this API must provide their own protections. (The
idea was that situations may come up where the assumptions of the atomic and
blocking APIs are not appropriate, so it should be possible for users to
handle these things in their own way.)
There are some limitations, which should not be too hard to live with. For
atomic/blocking chains, registration and unregistration must always be done in
a process context since the chain is protected by a mutex/rwsem. Also, a
callout routine for a non-raw chain must not try to register or unregister
entries on its own chain. (This did happen in a couple of places and the code
had to be changed to avoid it.)
Since atomic chains may be called from within an NMI handler, they cannot use
spinlocks for synchronization. Instead we use RCU. The overhead falls almost
entirely in the unregister routine, which is okay since unregistration is much
less frequent that calling a chain.
Here is the list of chains that we adjusted and their classifications. None
of them use the raw API, so for the moment it is only a placeholder.
ATOMIC CHAINS
-------------
arch/i386/kernel/traps.c: i386die_chain
arch/ia64/kernel/traps.c: ia64die_chain
arch/powerpc/kernel/traps.c: powerpc_die_chain
arch/sparc64/kernel/traps.c: sparc64die_chain
arch/x86_64/kernel/traps.c: die_chain
drivers/char/ipmi/ipmi_si_intf.c: xaction_notifier_list
kernel/panic.c: panic_notifier_list
kernel/profile.c: task_free_notifier
net/bluetooth/hci_core.c: hci_notifier
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_chain
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_expect_chain
net/ipv6/addrconf.c: inet6addr_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_expect_chain
net/netlink/af_netlink.c: netlink_chain
BLOCKING CHAINS
---------------
arch/powerpc/platforms/pseries/reconfig.c: pSeries_reconfig_chain
arch/s390/kernel/process.c: idle_chain
arch/x86_64/kernel/process.c idle_notifier
drivers/base/memory.c: memory_chain
drivers/cpufreq/cpufreq.c cpufreq_policy_notifier_list
drivers/cpufreq/cpufreq.c cpufreq_transition_notifier_list
drivers/macintosh/adb.c: adb_client_list
drivers/macintosh/via-pmu.c sleep_notifier_list
drivers/macintosh/via-pmu68k.c sleep_notifier_list
drivers/macintosh/windfarm_core.c wf_client_list
drivers/usb/core/notify.c usb_notifier_list
drivers/video/fbmem.c fb_notifier_list
kernel/cpu.c cpu_chain
kernel/module.c module_notify_list
kernel/profile.c munmap_notifier
kernel/profile.c task_exit_notifier
kernel/sys.c reboot_notifier_list
net/core/dev.c netdev_chain
net/decnet/dn_dev.c: dnaddr_chain
net/ipv4/devinet.c: inetaddr_chain
It's possible that some of these classifications are wrong. If they are,
please let us know or submit a patch to fix them. Note that any chain that
gets called very frequently should be atomic, because the rwsem read-locking
used for blocking chains is very likely to incur cache misses on SMP systems.
(However, if the chain's callout routines may sleep then the chain cannot be
atomic.)
The patch set was written by Alan Stern and Chandra Seetharaman, incorporating
material written by Keith Owens and suggestions from Paul McKenney and Andrew
Morton.
[jes@sgi.com: restructure the notifier chain initialization macros]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Chandra Seetharaman <sekharan@us.ibm.com>
Signed-off-by: Jes Sorensen <jes@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-27 09:16:30 +00:00
|
|
|
static BLOCKING_NOTIFIER_HEAD(task_exit_notifier);
|
|
|
|
static ATOMIC_NOTIFIER_HEAD(task_free_notifier);
|
|
|
|
static BLOCKING_NOTIFIER_HEAD(munmap_notifier);
|
2008-01-25 20:08:33 +00:00
|
|
|
|
|
|
|
void profile_task_exit(struct task_struct *task)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
[PATCH] Notifier chain update: API changes
The kernel's implementation of notifier chains is unsafe. There is no
protection against entries being added to or removed from a chain while the
chain is in use. The issues were discussed in this thread:
http://marc.theaimsgroup.com/?l=linux-kernel&m=113018709002036&w=2
We noticed that notifier chains in the kernel fall into two basic usage
classes:
"Blocking" chains are always called from a process context
and the callout routines are allowed to sleep;
"Atomic" chains can be called from an atomic context and
the callout routines are not allowed to sleep.
We decided to codify this distinction and make it part of the API. Therefore
this set of patches introduces three new, parallel APIs: one for blocking
notifiers, one for atomic notifiers, and one for "raw" notifiers (which is
really just the old API under a new name). New kinds of data structures are
used for the heads of the chains, and new routines are defined for
registration, unregistration, and calling a chain. The three APIs are
explained in include/linux/notifier.h and their implementation is in
kernel/sys.c.
With atomic and blocking chains, the implementation guarantees that the chain
links will not be corrupted and that chain callers will not get messed up by
entries being added or removed. For raw chains the implementation provides no
guarantees at all; users of this API must provide their own protections. (The
idea was that situations may come up where the assumptions of the atomic and
blocking APIs are not appropriate, so it should be possible for users to
handle these things in their own way.)
There are some limitations, which should not be too hard to live with. For
atomic/blocking chains, registration and unregistration must always be done in
a process context since the chain is protected by a mutex/rwsem. Also, a
callout routine for a non-raw chain must not try to register or unregister
entries on its own chain. (This did happen in a couple of places and the code
had to be changed to avoid it.)
Since atomic chains may be called from within an NMI handler, they cannot use
spinlocks for synchronization. Instead we use RCU. The overhead falls almost
entirely in the unregister routine, which is okay since unregistration is much
less frequent that calling a chain.
Here is the list of chains that we adjusted and their classifications. None
of them use the raw API, so for the moment it is only a placeholder.
ATOMIC CHAINS
-------------
arch/i386/kernel/traps.c: i386die_chain
arch/ia64/kernel/traps.c: ia64die_chain
arch/powerpc/kernel/traps.c: powerpc_die_chain
arch/sparc64/kernel/traps.c: sparc64die_chain
arch/x86_64/kernel/traps.c: die_chain
drivers/char/ipmi/ipmi_si_intf.c: xaction_notifier_list
kernel/panic.c: panic_notifier_list
kernel/profile.c: task_free_notifier
net/bluetooth/hci_core.c: hci_notifier
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_chain
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_expect_chain
net/ipv6/addrconf.c: inet6addr_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_expect_chain
net/netlink/af_netlink.c: netlink_chain
BLOCKING CHAINS
---------------
arch/powerpc/platforms/pseries/reconfig.c: pSeries_reconfig_chain
arch/s390/kernel/process.c: idle_chain
arch/x86_64/kernel/process.c idle_notifier
drivers/base/memory.c: memory_chain
drivers/cpufreq/cpufreq.c cpufreq_policy_notifier_list
drivers/cpufreq/cpufreq.c cpufreq_transition_notifier_list
drivers/macintosh/adb.c: adb_client_list
drivers/macintosh/via-pmu.c sleep_notifier_list
drivers/macintosh/via-pmu68k.c sleep_notifier_list
drivers/macintosh/windfarm_core.c wf_client_list
drivers/usb/core/notify.c usb_notifier_list
drivers/video/fbmem.c fb_notifier_list
kernel/cpu.c cpu_chain
kernel/module.c module_notify_list
kernel/profile.c munmap_notifier
kernel/profile.c task_exit_notifier
kernel/sys.c reboot_notifier_list
net/core/dev.c netdev_chain
net/decnet/dn_dev.c: dnaddr_chain
net/ipv4/devinet.c: inetaddr_chain
It's possible that some of these classifications are wrong. If they are,
please let us know or submit a patch to fix them. Note that any chain that
gets called very frequently should be atomic, because the rwsem read-locking
used for blocking chains is very likely to incur cache misses on SMP systems.
(However, if the chain's callout routines may sleep then the chain cannot be
atomic.)
The patch set was written by Alan Stern and Chandra Seetharaman, incorporating
material written by Keith Owens and suggestions from Paul McKenney and Andrew
Morton.
[jes@sgi.com: restructure the notifier chain initialization macros]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Chandra Seetharaman <sekharan@us.ibm.com>
Signed-off-by: Jes Sorensen <jes@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-27 09:16:30 +00:00
|
|
|
blocking_notifier_call_chain(&task_exit_notifier, 0, task);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-01-25 20:08:33 +00:00
|
|
|
|
|
|
|
int profile_handoff_task(struct task_struct *task)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int ret;
|
[PATCH] Notifier chain update: API changes
The kernel's implementation of notifier chains is unsafe. There is no
protection against entries being added to or removed from a chain while the
chain is in use. The issues were discussed in this thread:
http://marc.theaimsgroup.com/?l=linux-kernel&m=113018709002036&w=2
We noticed that notifier chains in the kernel fall into two basic usage
classes:
"Blocking" chains are always called from a process context
and the callout routines are allowed to sleep;
"Atomic" chains can be called from an atomic context and
the callout routines are not allowed to sleep.
We decided to codify this distinction and make it part of the API. Therefore
this set of patches introduces three new, parallel APIs: one for blocking
notifiers, one for atomic notifiers, and one for "raw" notifiers (which is
really just the old API under a new name). New kinds of data structures are
used for the heads of the chains, and new routines are defined for
registration, unregistration, and calling a chain. The three APIs are
explained in include/linux/notifier.h and their implementation is in
kernel/sys.c.
With atomic and blocking chains, the implementation guarantees that the chain
links will not be corrupted and that chain callers will not get messed up by
entries being added or removed. For raw chains the implementation provides no
guarantees at all; users of this API must provide their own protections. (The
idea was that situations may come up where the assumptions of the atomic and
blocking APIs are not appropriate, so it should be possible for users to
handle these things in their own way.)
There are some limitations, which should not be too hard to live with. For
atomic/blocking chains, registration and unregistration must always be done in
a process context since the chain is protected by a mutex/rwsem. Also, a
callout routine for a non-raw chain must not try to register or unregister
entries on its own chain. (This did happen in a couple of places and the code
had to be changed to avoid it.)
Since atomic chains may be called from within an NMI handler, they cannot use
spinlocks for synchronization. Instead we use RCU. The overhead falls almost
entirely in the unregister routine, which is okay since unregistration is much
less frequent that calling a chain.
Here is the list of chains that we adjusted and their classifications. None
of them use the raw API, so for the moment it is only a placeholder.
ATOMIC CHAINS
-------------
arch/i386/kernel/traps.c: i386die_chain
arch/ia64/kernel/traps.c: ia64die_chain
arch/powerpc/kernel/traps.c: powerpc_die_chain
arch/sparc64/kernel/traps.c: sparc64die_chain
arch/x86_64/kernel/traps.c: die_chain
drivers/char/ipmi/ipmi_si_intf.c: xaction_notifier_list
kernel/panic.c: panic_notifier_list
kernel/profile.c: task_free_notifier
net/bluetooth/hci_core.c: hci_notifier
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_chain
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_expect_chain
net/ipv6/addrconf.c: inet6addr_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_expect_chain
net/netlink/af_netlink.c: netlink_chain
BLOCKING CHAINS
---------------
arch/powerpc/platforms/pseries/reconfig.c: pSeries_reconfig_chain
arch/s390/kernel/process.c: idle_chain
arch/x86_64/kernel/process.c idle_notifier
drivers/base/memory.c: memory_chain
drivers/cpufreq/cpufreq.c cpufreq_policy_notifier_list
drivers/cpufreq/cpufreq.c cpufreq_transition_notifier_list
drivers/macintosh/adb.c: adb_client_list
drivers/macintosh/via-pmu.c sleep_notifier_list
drivers/macintosh/via-pmu68k.c sleep_notifier_list
drivers/macintosh/windfarm_core.c wf_client_list
drivers/usb/core/notify.c usb_notifier_list
drivers/video/fbmem.c fb_notifier_list
kernel/cpu.c cpu_chain
kernel/module.c module_notify_list
kernel/profile.c munmap_notifier
kernel/profile.c task_exit_notifier
kernel/sys.c reboot_notifier_list
net/core/dev.c netdev_chain
net/decnet/dn_dev.c: dnaddr_chain
net/ipv4/devinet.c: inetaddr_chain
It's possible that some of these classifications are wrong. If they are,
please let us know or submit a patch to fix them. Note that any chain that
gets called very frequently should be atomic, because the rwsem read-locking
used for blocking chains is very likely to incur cache misses on SMP systems.
(However, if the chain's callout routines may sleep then the chain cannot be
atomic.)
The patch set was written by Alan Stern and Chandra Seetharaman, incorporating
material written by Keith Owens and suggestions from Paul McKenney and Andrew
Morton.
[jes@sgi.com: restructure the notifier chain initialization macros]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Chandra Seetharaman <sekharan@us.ibm.com>
Signed-off-by: Jes Sorensen <jes@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-27 09:16:30 +00:00
|
|
|
ret = atomic_notifier_call_chain(&task_free_notifier, 0, task);
|
2005-04-16 22:20:36 +00:00
|
|
|
return (ret == NOTIFY_OK) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void profile_munmap(unsigned long addr)
|
|
|
|
{
|
[PATCH] Notifier chain update: API changes
The kernel's implementation of notifier chains is unsafe. There is no
protection against entries being added to or removed from a chain while the
chain is in use. The issues were discussed in this thread:
http://marc.theaimsgroup.com/?l=linux-kernel&m=113018709002036&w=2
We noticed that notifier chains in the kernel fall into two basic usage
classes:
"Blocking" chains are always called from a process context
and the callout routines are allowed to sleep;
"Atomic" chains can be called from an atomic context and
the callout routines are not allowed to sleep.
We decided to codify this distinction and make it part of the API. Therefore
this set of patches introduces three new, parallel APIs: one for blocking
notifiers, one for atomic notifiers, and one for "raw" notifiers (which is
really just the old API under a new name). New kinds of data structures are
used for the heads of the chains, and new routines are defined for
registration, unregistration, and calling a chain. The three APIs are
explained in include/linux/notifier.h and their implementation is in
kernel/sys.c.
With atomic and blocking chains, the implementation guarantees that the chain
links will not be corrupted and that chain callers will not get messed up by
entries being added or removed. For raw chains the implementation provides no
guarantees at all; users of this API must provide their own protections. (The
idea was that situations may come up where the assumptions of the atomic and
blocking APIs are not appropriate, so it should be possible for users to
handle these things in their own way.)
There are some limitations, which should not be too hard to live with. For
atomic/blocking chains, registration and unregistration must always be done in
a process context since the chain is protected by a mutex/rwsem. Also, a
callout routine for a non-raw chain must not try to register or unregister
entries on its own chain. (This did happen in a couple of places and the code
had to be changed to avoid it.)
Since atomic chains may be called from within an NMI handler, they cannot use
spinlocks for synchronization. Instead we use RCU. The overhead falls almost
entirely in the unregister routine, which is okay since unregistration is much
less frequent that calling a chain.
Here is the list of chains that we adjusted and their classifications. None
of them use the raw API, so for the moment it is only a placeholder.
ATOMIC CHAINS
-------------
arch/i386/kernel/traps.c: i386die_chain
arch/ia64/kernel/traps.c: ia64die_chain
arch/powerpc/kernel/traps.c: powerpc_die_chain
arch/sparc64/kernel/traps.c: sparc64die_chain
arch/x86_64/kernel/traps.c: die_chain
drivers/char/ipmi/ipmi_si_intf.c: xaction_notifier_list
kernel/panic.c: panic_notifier_list
kernel/profile.c: task_free_notifier
net/bluetooth/hci_core.c: hci_notifier
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_chain
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_expect_chain
net/ipv6/addrconf.c: inet6addr_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_expect_chain
net/netlink/af_netlink.c: netlink_chain
BLOCKING CHAINS
---------------
arch/powerpc/platforms/pseries/reconfig.c: pSeries_reconfig_chain
arch/s390/kernel/process.c: idle_chain
arch/x86_64/kernel/process.c idle_notifier
drivers/base/memory.c: memory_chain
drivers/cpufreq/cpufreq.c cpufreq_policy_notifier_list
drivers/cpufreq/cpufreq.c cpufreq_transition_notifier_list
drivers/macintosh/adb.c: adb_client_list
drivers/macintosh/via-pmu.c sleep_notifier_list
drivers/macintosh/via-pmu68k.c sleep_notifier_list
drivers/macintosh/windfarm_core.c wf_client_list
drivers/usb/core/notify.c usb_notifier_list
drivers/video/fbmem.c fb_notifier_list
kernel/cpu.c cpu_chain
kernel/module.c module_notify_list
kernel/profile.c munmap_notifier
kernel/profile.c task_exit_notifier
kernel/sys.c reboot_notifier_list
net/core/dev.c netdev_chain
net/decnet/dn_dev.c: dnaddr_chain
net/ipv4/devinet.c: inetaddr_chain
It's possible that some of these classifications are wrong. If they are,
please let us know or submit a patch to fix them. Note that any chain that
gets called very frequently should be atomic, because the rwsem read-locking
used for blocking chains is very likely to incur cache misses on SMP systems.
(However, if the chain's callout routines may sleep then the chain cannot be
atomic.)
The patch set was written by Alan Stern and Chandra Seetharaman, incorporating
material written by Keith Owens and suggestions from Paul McKenney and Andrew
Morton.
[jes@sgi.com: restructure the notifier chain initialization macros]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Chandra Seetharaman <sekharan@us.ibm.com>
Signed-off-by: Jes Sorensen <jes@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-27 09:16:30 +00:00
|
|
|
blocking_notifier_call_chain(&munmap_notifier, 0, (void *)addr);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-01-25 20:08:33 +00:00
|
|
|
int task_handoff_register(struct notifier_block *n)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
[PATCH] Notifier chain update: API changes
The kernel's implementation of notifier chains is unsafe. There is no
protection against entries being added to or removed from a chain while the
chain is in use. The issues were discussed in this thread:
http://marc.theaimsgroup.com/?l=linux-kernel&m=113018709002036&w=2
We noticed that notifier chains in the kernel fall into two basic usage
classes:
"Blocking" chains are always called from a process context
and the callout routines are allowed to sleep;
"Atomic" chains can be called from an atomic context and
the callout routines are not allowed to sleep.
We decided to codify this distinction and make it part of the API. Therefore
this set of patches introduces three new, parallel APIs: one for blocking
notifiers, one for atomic notifiers, and one for "raw" notifiers (which is
really just the old API under a new name). New kinds of data structures are
used for the heads of the chains, and new routines are defined for
registration, unregistration, and calling a chain. The three APIs are
explained in include/linux/notifier.h and their implementation is in
kernel/sys.c.
With atomic and blocking chains, the implementation guarantees that the chain
links will not be corrupted and that chain callers will not get messed up by
entries being added or removed. For raw chains the implementation provides no
guarantees at all; users of this API must provide their own protections. (The
idea was that situations may come up where the assumptions of the atomic and
blocking APIs are not appropriate, so it should be possible for users to
handle these things in their own way.)
There are some limitations, which should not be too hard to live with. For
atomic/blocking chains, registration and unregistration must always be done in
a process context since the chain is protected by a mutex/rwsem. Also, a
callout routine for a non-raw chain must not try to register or unregister
entries on its own chain. (This did happen in a couple of places and the code
had to be changed to avoid it.)
Since atomic chains may be called from within an NMI handler, they cannot use
spinlocks for synchronization. Instead we use RCU. The overhead falls almost
entirely in the unregister routine, which is okay since unregistration is much
less frequent that calling a chain.
Here is the list of chains that we adjusted and their classifications. None
of them use the raw API, so for the moment it is only a placeholder.
ATOMIC CHAINS
-------------
arch/i386/kernel/traps.c: i386die_chain
arch/ia64/kernel/traps.c: ia64die_chain
arch/powerpc/kernel/traps.c: powerpc_die_chain
arch/sparc64/kernel/traps.c: sparc64die_chain
arch/x86_64/kernel/traps.c: die_chain
drivers/char/ipmi/ipmi_si_intf.c: xaction_notifier_list
kernel/panic.c: panic_notifier_list
kernel/profile.c: task_free_notifier
net/bluetooth/hci_core.c: hci_notifier
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_chain
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_expect_chain
net/ipv6/addrconf.c: inet6addr_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_expect_chain
net/netlink/af_netlink.c: netlink_chain
BLOCKING CHAINS
---------------
arch/powerpc/platforms/pseries/reconfig.c: pSeries_reconfig_chain
arch/s390/kernel/process.c: idle_chain
arch/x86_64/kernel/process.c idle_notifier
drivers/base/memory.c: memory_chain
drivers/cpufreq/cpufreq.c cpufreq_policy_notifier_list
drivers/cpufreq/cpufreq.c cpufreq_transition_notifier_list
drivers/macintosh/adb.c: adb_client_list
drivers/macintosh/via-pmu.c sleep_notifier_list
drivers/macintosh/via-pmu68k.c sleep_notifier_list
drivers/macintosh/windfarm_core.c wf_client_list
drivers/usb/core/notify.c usb_notifier_list
drivers/video/fbmem.c fb_notifier_list
kernel/cpu.c cpu_chain
kernel/module.c module_notify_list
kernel/profile.c munmap_notifier
kernel/profile.c task_exit_notifier
kernel/sys.c reboot_notifier_list
net/core/dev.c netdev_chain
net/decnet/dn_dev.c: dnaddr_chain
net/ipv4/devinet.c: inetaddr_chain
It's possible that some of these classifications are wrong. If they are,
please let us know or submit a patch to fix them. Note that any chain that
gets called very frequently should be atomic, because the rwsem read-locking
used for blocking chains is very likely to incur cache misses on SMP systems.
(However, if the chain's callout routines may sleep then the chain cannot be
atomic.)
The patch set was written by Alan Stern and Chandra Seetharaman, incorporating
material written by Keith Owens and suggestions from Paul McKenney and Andrew
Morton.
[jes@sgi.com: restructure the notifier chain initialization macros]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Chandra Seetharaman <sekharan@us.ibm.com>
Signed-off-by: Jes Sorensen <jes@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-27 09:16:30 +00:00
|
|
|
return atomic_notifier_chain_register(&task_free_notifier, n);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-01-25 20:08:33 +00:00
|
|
|
EXPORT_SYMBOL_GPL(task_handoff_register);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-01-25 20:08:33 +00:00
|
|
|
int task_handoff_unregister(struct notifier_block *n)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
[PATCH] Notifier chain update: API changes
The kernel's implementation of notifier chains is unsafe. There is no
protection against entries being added to or removed from a chain while the
chain is in use. The issues were discussed in this thread:
http://marc.theaimsgroup.com/?l=linux-kernel&m=113018709002036&w=2
We noticed that notifier chains in the kernel fall into two basic usage
classes:
"Blocking" chains are always called from a process context
and the callout routines are allowed to sleep;
"Atomic" chains can be called from an atomic context and
the callout routines are not allowed to sleep.
We decided to codify this distinction and make it part of the API. Therefore
this set of patches introduces three new, parallel APIs: one for blocking
notifiers, one for atomic notifiers, and one for "raw" notifiers (which is
really just the old API under a new name). New kinds of data structures are
used for the heads of the chains, and new routines are defined for
registration, unregistration, and calling a chain. The three APIs are
explained in include/linux/notifier.h and their implementation is in
kernel/sys.c.
With atomic and blocking chains, the implementation guarantees that the chain
links will not be corrupted and that chain callers will not get messed up by
entries being added or removed. For raw chains the implementation provides no
guarantees at all; users of this API must provide their own protections. (The
idea was that situations may come up where the assumptions of the atomic and
blocking APIs are not appropriate, so it should be possible for users to
handle these things in their own way.)
There are some limitations, which should not be too hard to live with. For
atomic/blocking chains, registration and unregistration must always be done in
a process context since the chain is protected by a mutex/rwsem. Also, a
callout routine for a non-raw chain must not try to register or unregister
entries on its own chain. (This did happen in a couple of places and the code
had to be changed to avoid it.)
Since atomic chains may be called from within an NMI handler, they cannot use
spinlocks for synchronization. Instead we use RCU. The overhead falls almost
entirely in the unregister routine, which is okay since unregistration is much
less frequent that calling a chain.
Here is the list of chains that we adjusted and their classifications. None
of them use the raw API, so for the moment it is only a placeholder.
ATOMIC CHAINS
-------------
arch/i386/kernel/traps.c: i386die_chain
arch/ia64/kernel/traps.c: ia64die_chain
arch/powerpc/kernel/traps.c: powerpc_die_chain
arch/sparc64/kernel/traps.c: sparc64die_chain
arch/x86_64/kernel/traps.c: die_chain
drivers/char/ipmi/ipmi_si_intf.c: xaction_notifier_list
kernel/panic.c: panic_notifier_list
kernel/profile.c: task_free_notifier
net/bluetooth/hci_core.c: hci_notifier
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_chain
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_expect_chain
net/ipv6/addrconf.c: inet6addr_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_expect_chain
net/netlink/af_netlink.c: netlink_chain
BLOCKING CHAINS
---------------
arch/powerpc/platforms/pseries/reconfig.c: pSeries_reconfig_chain
arch/s390/kernel/process.c: idle_chain
arch/x86_64/kernel/process.c idle_notifier
drivers/base/memory.c: memory_chain
drivers/cpufreq/cpufreq.c cpufreq_policy_notifier_list
drivers/cpufreq/cpufreq.c cpufreq_transition_notifier_list
drivers/macintosh/adb.c: adb_client_list
drivers/macintosh/via-pmu.c sleep_notifier_list
drivers/macintosh/via-pmu68k.c sleep_notifier_list
drivers/macintosh/windfarm_core.c wf_client_list
drivers/usb/core/notify.c usb_notifier_list
drivers/video/fbmem.c fb_notifier_list
kernel/cpu.c cpu_chain
kernel/module.c module_notify_list
kernel/profile.c munmap_notifier
kernel/profile.c task_exit_notifier
kernel/sys.c reboot_notifier_list
net/core/dev.c netdev_chain
net/decnet/dn_dev.c: dnaddr_chain
net/ipv4/devinet.c: inetaddr_chain
It's possible that some of these classifications are wrong. If they are,
please let us know or submit a patch to fix them. Note that any chain that
gets called very frequently should be atomic, because the rwsem read-locking
used for blocking chains is very likely to incur cache misses on SMP systems.
(However, if the chain's callout routines may sleep then the chain cannot be
atomic.)
The patch set was written by Alan Stern and Chandra Seetharaman, incorporating
material written by Keith Owens and suggestions from Paul McKenney and Andrew
Morton.
[jes@sgi.com: restructure the notifier chain initialization macros]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Chandra Seetharaman <sekharan@us.ibm.com>
Signed-off-by: Jes Sorensen <jes@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-27 09:16:30 +00:00
|
|
|
return atomic_notifier_chain_unregister(&task_free_notifier, n);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-01-25 20:08:33 +00:00
|
|
|
EXPORT_SYMBOL_GPL(task_handoff_unregister);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-01-25 20:08:33 +00:00
|
|
|
int profile_event_register(enum profile_type type, struct notifier_block *n)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int err = -EINVAL;
|
2008-01-25 20:08:33 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
switch (type) {
|
2008-01-25 20:08:33 +00:00
|
|
|
case PROFILE_TASK_EXIT:
|
|
|
|
err = blocking_notifier_chain_register(
|
|
|
|
&task_exit_notifier, n);
|
|
|
|
break;
|
|
|
|
case PROFILE_MUNMAP:
|
|
|
|
err = blocking_notifier_chain_register(
|
|
|
|
&munmap_notifier, n);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-01-25 20:08:33 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
}
|
2008-01-25 20:08:33 +00:00
|
|
|
EXPORT_SYMBOL_GPL(profile_event_register);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-01-25 20:08:33 +00:00
|
|
|
int profile_event_unregister(enum profile_type type, struct notifier_block *n)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int err = -EINVAL;
|
2008-01-25 20:08:33 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
switch (type) {
|
2008-01-25 20:08:33 +00:00
|
|
|
case PROFILE_TASK_EXIT:
|
|
|
|
err = blocking_notifier_chain_unregister(
|
|
|
|
&task_exit_notifier, n);
|
|
|
|
break;
|
|
|
|
case PROFILE_MUNMAP:
|
|
|
|
err = blocking_notifier_chain_unregister(
|
|
|
|
&munmap_notifier, n);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
2008-01-25 20:08:33 +00:00
|
|
|
EXPORT_SYMBOL_GPL(profile_event_unregister);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-03-22 21:27:26 +00:00
|
|
|
#if defined(CONFIG_SMP) && defined(CONFIG_PROC_FS)
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Each cpu has a pair of open-addressed hashtables for pending
|
|
|
|
* profile hits. read_profile() IPI's all cpus to request them
|
|
|
|
* to flip buffers and flushes their contents to prof_buffer itself.
|
|
|
|
* Flip requests are serialized by the profile_flip_mutex. The sole
|
|
|
|
* use of having a second hashtable is for avoiding cacheline
|
|
|
|
* contention that would otherwise happen during flushes of pending
|
|
|
|
* profile hits required for the accuracy of reported profile hits
|
|
|
|
* and so resurrect the interrupt livelock issue.
|
|
|
|
*
|
|
|
|
* The open-addressed hashtables are indexed by profile buffer slot
|
|
|
|
* and hold the number of pending hits to that profile buffer slot on
|
|
|
|
* a cpu in an entry. When the hashtable overflows, all pending hits
|
|
|
|
* are accounted to their corresponding profile buffer slots with
|
|
|
|
* atomic_add() and the hashtable emptied. As numerous pending hits
|
|
|
|
* may be accounted to a profile buffer slot in a hashtable entry,
|
|
|
|
* this amortizes a number of atomic profile buffer increments likely
|
|
|
|
* to be far larger than the number of entries in the hashtable,
|
|
|
|
* particularly given that the number of distinct profile buffer
|
|
|
|
* positions to which hits are accounted during short intervals (e.g.
|
|
|
|
* several seconds) is usually very small. Exclusion from buffer
|
|
|
|
* flipping is provided by interrupt disablement (note that for
|
2006-12-07 04:37:24 +00:00
|
|
|
* SCHED_PROFILING or SLEEP_PROFILING profile_hit() may be called from
|
|
|
|
* process context).
|
2005-04-16 22:20:36 +00:00
|
|
|
* The hash function is meant to be lightweight as opposed to strong,
|
|
|
|
* and was vaguely inspired by ppc64 firmware-supported inverted
|
|
|
|
* pagetable hash functions, but uses a full hashtable full of finite
|
|
|
|
* collision chains, not just pairs of them.
|
|
|
|
*
|
2012-12-06 09:39:54 +00:00
|
|
|
* -- nyc
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
static void __profile_flip_buffers(void *unused)
|
|
|
|
{
|
|
|
|
int cpu = smp_processor_id();
|
|
|
|
|
|
|
|
per_cpu(cpu_profile_flip, cpu) = !per_cpu(cpu_profile_flip, cpu);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void profile_flip_buffers(void)
|
|
|
|
{
|
|
|
|
int i, j, cpu;
|
|
|
|
|
2006-03-23 11:00:24 +00:00
|
|
|
mutex_lock(&profile_flip_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
j = per_cpu(cpu_profile_flip, get_cpu());
|
|
|
|
put_cpu();
|
2008-05-09 07:39:44 +00:00
|
|
|
on_each_cpu(__profile_flip_buffers, NULL, 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
for_each_online_cpu(cpu) {
|
|
|
|
struct profile_hit *hits = per_cpu(cpu_profile_hits, cpu)[j];
|
|
|
|
for (i = 0; i < NR_PROFILE_HIT; ++i) {
|
|
|
|
if (!hits[i].hits) {
|
|
|
|
if (hits[i].pc)
|
|
|
|
hits[i].pc = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
|
|
|
|
hits[i].hits = hits[i].pc = 0;
|
|
|
|
}
|
|
|
|
}
|
2006-03-23 11:00:24 +00:00
|
|
|
mutex_unlock(&profile_flip_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void profile_discard_flip_buffers(void)
|
|
|
|
{
|
|
|
|
int i, cpu;
|
|
|
|
|
2006-03-23 11:00:24 +00:00
|
|
|
mutex_lock(&profile_flip_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
i = per_cpu(cpu_profile_flip, get_cpu());
|
|
|
|
put_cpu();
|
2008-05-09 07:39:44 +00:00
|
|
|
on_each_cpu(__profile_flip_buffers, NULL, 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
for_each_online_cpu(cpu) {
|
|
|
|
struct profile_hit *hits = per_cpu(cpu_profile_hits, cpu)[i];
|
|
|
|
memset(hits, 0, NR_PROFILE_HIT*sizeof(struct profile_hit));
|
|
|
|
}
|
2006-03-23 11:00:24 +00:00
|
|
|
mutex_unlock(&profile_flip_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2011-05-26 23:26:00 +00:00
|
|
|
static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long primary, secondary, flags, pc = (unsigned long)__pc;
|
|
|
|
int i, j, cpu;
|
|
|
|
struct profile_hit *hits;
|
|
|
|
|
|
|
|
pc = min((pc - (unsigned long)_stext) >> prof_shift, prof_len - 1);
|
|
|
|
i = primary = (pc & (NR_PROFILE_GRP - 1)) << PROFILE_GRPSHIFT;
|
|
|
|
secondary = (~(pc << 1) & (NR_PROFILE_GRP - 1)) << PROFILE_GRPSHIFT;
|
|
|
|
cpu = get_cpu();
|
|
|
|
hits = per_cpu(cpu_profile_hits, cpu)[per_cpu(cpu_profile_flip, cpu)];
|
|
|
|
if (!hits) {
|
|
|
|
put_cpu();
|
|
|
|
return;
|
|
|
|
}
|
2006-12-07 04:37:24 +00:00
|
|
|
/*
|
|
|
|
* We buffer the global profiler buffer into a per-CPU
|
|
|
|
* queue and thus reduce the number of global (and possibly
|
|
|
|
* NUMA-alien) accesses. The write-queue is self-coalescing:
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
local_irq_save(flags);
|
|
|
|
do {
|
|
|
|
for (j = 0; j < PROFILE_GRPSZ; ++j) {
|
|
|
|
if (hits[i + j].pc == pc) {
|
2006-12-07 04:37:24 +00:00
|
|
|
hits[i + j].hits += nr_hits;
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
} else if (!hits[i + j].hits) {
|
|
|
|
hits[i + j].pc = pc;
|
2006-12-07 04:37:24 +00:00
|
|
|
hits[i + j].hits = nr_hits;
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i = (i + secondary) & (NR_PROFILE_HIT - 1);
|
|
|
|
} while (i != primary);
|
2006-12-07 04:37:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add the current hit(s) and flush the write-queue out
|
|
|
|
* to the global buffer:
|
|
|
|
*/
|
|
|
|
atomic_add(nr_hits, &prof_buffer[pc]);
|
2005-04-16 22:20:36 +00:00
|
|
|
for (i = 0; i < NR_PROFILE_HIT; ++i) {
|
|
|
|
atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
|
|
|
|
hits[i].pc = hits[i].hits = 0;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
local_irq_restore(flags);
|
|
|
|
put_cpu();
|
|
|
|
}
|
|
|
|
|
2016-07-13 17:16:59 +00:00
|
|
|
static int profile_dead_cpu(unsigned int cpu)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct page *page;
|
2016-07-13 17:16:59 +00:00
|
|
|
int i;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2019-12-05 00:50:50 +00:00
|
|
|
if (cpumask_available(prof_cpu_mask))
|
2016-07-13 17:16:59 +00:00
|
|
|
cpumask_clear_cpu(cpu, prof_cpu_mask);
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if (per_cpu(cpu_profile_hits, cpu)[i]) {
|
|
|
|
page = virt_to_page(per_cpu(cpu_profile_hits, cpu)[i]);
|
|
|
|
per_cpu(cpu_profile_hits, cpu)[i] = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
__free_page(page);
|
|
|
|
}
|
2016-07-13 17:16:59 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int profile_prepare_cpu(unsigned int cpu)
|
|
|
|
{
|
|
|
|
int i, node = cpu_to_mem(cpu);
|
|
|
|
struct page *page;
|
|
|
|
|
|
|
|
per_cpu(cpu_profile_flip, cpu) = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if (per_cpu(cpu_profile_hits, cpu)[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
page = __alloc_pages_node(node, GFP_KERNEL | __GFP_ZERO, 0);
|
|
|
|
if (!page) {
|
|
|
|
profile_dead_cpu(cpu);
|
|
|
|
return -ENOMEM;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2016-07-13 17:16:59 +00:00
|
|
|
per_cpu(cpu_profile_hits, cpu)[i] = page_address(page);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2016-07-13 17:16:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int profile_online_cpu(unsigned int cpu)
|
|
|
|
{
|
2019-12-05 00:50:50 +00:00
|
|
|
if (cpumask_available(prof_cpu_mask))
|
2016-07-13 17:16:59 +00:00
|
|
|
cpumask_set_cpu(cpu, prof_cpu_mask);
|
|
|
|
|
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2016-07-13 17:16:59 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#else /* !CONFIG_SMP */
|
|
|
|
#define profile_flip_buffers() do { } while (0)
|
|
|
|
#define profile_discard_flip_buffers() do { } while (0)
|
|
|
|
|
2011-05-26 23:26:00 +00:00
|
|
|
static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long pc;
|
|
|
|
pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
|
2006-12-07 04:37:24 +00:00
|
|
|
atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
#endif /* !CONFIG_SMP */
|
2011-05-26 23:26:00 +00:00
|
|
|
|
|
|
|
void profile_hits(int type, void *__pc, unsigned int nr_hits)
|
|
|
|
{
|
|
|
|
if (prof_on != type || !prof_buffer)
|
|
|
|
return;
|
|
|
|
do_profile_hits(type, __pc, nr_hits);
|
|
|
|
}
|
2007-01-23 04:40:33 +00:00
|
|
|
EXPORT_SYMBOL_GPL(profile_hits);
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
void profile_tick(int type)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
struct pt_regs *regs = get_irq_regs();
|
|
|
|
|
2019-12-05 00:50:50 +00:00
|
|
|
if (!user_mode(regs) && cpumask_available(prof_cpu_mask) &&
|
2008-12-31 23:42:27 +00:00
|
|
|
cpumask_test_cpu(smp_processor_id(), prof_cpu_mask))
|
2005-04-16 22:20:36 +00:00
|
|
|
profile_hit(type, (void *)profile_pc(regs));
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
#include <linux/proc_fs.h>
|
2009-09-18 19:57:09 +00:00
|
|
|
#include <linux/seq_file.h>
|
2016-12-24 19:46:01 +00:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-09-18 19:57:09 +00:00
|
|
|
static int prof_cpu_mask_proc_show(struct seq_file *m, void *v)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2015-02-13 22:38:13 +00:00
|
|
|
seq_printf(m, "%*pb\n", cpumask_pr_args(prof_cpu_mask));
|
2009-09-18 19:57:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int prof_cpu_mask_proc_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
return single_open(file, prof_cpu_mask_proc_show, NULL);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2009-09-18 19:57:09 +00:00
|
|
|
static ssize_t prof_cpu_mask_proc_write(struct file *file,
|
|
|
|
const char __user *buffer, size_t count, loff_t *pos)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-12-31 23:42:27 +00:00
|
|
|
cpumask_var_t new_value;
|
2009-09-18 19:57:09 +00:00
|
|
|
int err;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-04-01 05:58:23 +00:00
|
|
|
if (!zalloc_cpumask_var(&new_value, GFP_KERNEL))
|
2008-12-31 23:42:27 +00:00
|
|
|
return -ENOMEM;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-12-31 23:42:27 +00:00
|
|
|
err = cpumask_parse_user(buffer, count, new_value);
|
|
|
|
if (!err) {
|
2009-09-18 19:57:09 +00:00
|
|
|
cpumask_copy(prof_cpu_mask, new_value);
|
|
|
|
err = count;
|
2008-12-31 23:42:27 +00:00
|
|
|
}
|
|
|
|
free_cpumask_var(new_value);
|
|
|
|
return err;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 01:37:17 +00:00
|
|
|
static const struct proc_ops prof_cpu_mask_proc_ops = {
|
|
|
|
.proc_open = prof_cpu_mask_proc_open,
|
|
|
|
.proc_read = seq_read,
|
|
|
|
.proc_lseek = seq_lseek,
|
|
|
|
.proc_release = single_release,
|
|
|
|
.proc_write = prof_cpu_mask_proc_write,
|
2009-09-18 19:57:09 +00:00
|
|
|
};
|
|
|
|
|
2013-04-02 00:48:34 +00:00
|
|
|
void create_prof_cpu_mask(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
/* create /proc/irq/prof_cpu_mask */
|
2020-02-04 01:37:17 +00:00
|
|
|
proc_create("irq/prof_cpu_mask", 0600, NULL, &prof_cpu_mask_proc_ops);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function accesses profiling information. The returned data is
|
|
|
|
* binary: the sampling step and the actual contents of the profile
|
|
|
|
* buffer. Use of the program readprofile is recommended in order to
|
|
|
|
* get meaningful info out of these data.
|
|
|
|
*/
|
|
|
|
static ssize_t
|
|
|
|
read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
unsigned long p = *ppos;
|
|
|
|
ssize_t read;
|
2008-01-25 20:08:33 +00:00
|
|
|
char *pnt;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned int sample_step = 1 << prof_shift;
|
|
|
|
|
|
|
|
profile_flip_buffers();
|
|
|
|
if (p >= (prof_len+1)*sizeof(unsigned int))
|
|
|
|
return 0;
|
|
|
|
if (count > (prof_len+1)*sizeof(unsigned int) - p)
|
|
|
|
count = (prof_len+1)*sizeof(unsigned int) - p;
|
|
|
|
read = 0;
|
|
|
|
|
|
|
|
while (p < sizeof(unsigned int) && count > 0) {
|
2008-01-25 20:08:33 +00:00
|
|
|
if (put_user(*((char *)(&sample_step)+p), buf))
|
2006-12-07 04:36:37 +00:00
|
|
|
return -EFAULT;
|
2005-04-16 22:20:36 +00:00
|
|
|
buf++; p++; count--; read++;
|
|
|
|
}
|
|
|
|
pnt = (char *)prof_buffer + p - sizeof(atomic_t);
|
2008-01-25 20:08:33 +00:00
|
|
|
if (copy_to_user(buf, (void *)pnt, count))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EFAULT;
|
|
|
|
read += count;
|
|
|
|
*ppos += read;
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Writing to /proc/profile resets the counters
|
|
|
|
*
|
|
|
|
* Writing a 'profiling multiplier' value into it also re-sets the profiling
|
|
|
|
* interrupt frequency, on architectures that support this.
|
|
|
|
*/
|
|
|
|
static ssize_t write_profile(struct file *file, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SMP
|
2008-01-25 20:08:33 +00:00
|
|
|
extern int setup_profiling_timer(unsigned int multiplier);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (count == sizeof(int)) {
|
|
|
|
unsigned int multiplier;
|
|
|
|
|
|
|
|
if (copy_from_user(&multiplier, buf, sizeof(int)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (setup_profiling_timer(multiplier))
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
profile_discard_flip_buffers();
|
|
|
|
memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2020-02-04 01:37:17 +00:00
|
|
|
static const struct proc_ops profile_proc_ops = {
|
|
|
|
.proc_read = read_profile,
|
|
|
|
.proc_write = write_profile,
|
|
|
|
.proc_lseek = default_llseek,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2016-07-13 17:16:59 +00:00
|
|
|
int __ref create_proc_profile(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2016-07-13 17:16:59 +00:00
|
|
|
struct proc_dir_entry *entry;
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
enum cpuhp_state online_state;
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
|
2014-03-10 20:42:08 +00:00
|
|
|
int err = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (!prof_on)
|
|
|
|
return 0;
|
2016-07-13 17:16:59 +00:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
err = cpuhp_setup_state(CPUHP_PROFILE_PREPARE, "PROFILE_PREPARE",
|
|
|
|
profile_prepare_cpu, profile_dead_cpu);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "AP_PROFILE_ONLINE",
|
|
|
|
profile_online_cpu, NULL);
|
|
|
|
if (err < 0)
|
|
|
|
goto err_state_prep;
|
|
|
|
online_state = err;
|
|
|
|
err = 0;
|
|
|
|
#endif
|
2008-04-29 08:02:31 +00:00
|
|
|
entry = proc_create("profile", S_IWUSR | S_IRUGO,
|
2020-02-04 01:37:17 +00:00
|
|
|
NULL, &profile_proc_ops);
|
2008-01-25 20:08:33 +00:00
|
|
|
if (!entry)
|
2016-07-13 17:16:59 +00:00
|
|
|
goto err_state_onl;
|
2013-04-11 23:38:51 +00:00
|
|
|
proc_set_size(entry, (1 + prof_len) * sizeof(atomic_t));
|
2014-03-10 20:42:08 +00:00
|
|
|
|
2016-07-13 17:16:59 +00:00
|
|
|
return err;
|
|
|
|
err_state_onl:
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
cpuhp_remove_state(online_state);
|
|
|
|
err_state_prep:
|
|
|
|
cpuhp_remove_state(CPUHP_PROFILE_PREPARE);
|
|
|
|
#endif
|
2014-03-10 20:42:08 +00:00
|
|
|
return err;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2014-04-03 21:48:35 +00:00
|
|
|
subsys_initcall(create_proc_profile);
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif /* CONFIG_PROC_FS */
|