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>
|
|
|
|
#include <linux/bootmem.h>
|
|
|
|
#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>
|
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;
|
2005-04-16 22:20:36 +00:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
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
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/*
|
|
|
|
* 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();
|
|
|
|
}
|
|
|
|
|
2013-06-19 18:53:51 +00:00
|
|
|
static int profile_cpu_callback(struct notifier_block *info,
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long action, void *__cpu)
|
|
|
|
{
|
|
|
|
int node, cpu = (unsigned long)__cpu;
|
|
|
|
struct page *page;
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
case CPU_UP_PREPARE:
|
2007-05-09 09:35:10 +00:00
|
|
|
case CPU_UP_PREPARE_FROZEN:
|
2010-05-26 21:45:04 +00:00
|
|
|
node = cpu_to_mem(cpu);
|
2005-04-16 22:20:36 +00:00
|
|
|
per_cpu(cpu_profile_flip, cpu) = 0;
|
|
|
|
if (!per_cpu(cpu_profile_hits, cpu)[1]) {
|
mm: rename alloc_pages_exact_node() to __alloc_pages_node()
alloc_pages_exact_node() was introduced in commit 6484eb3e2a81 ("page
allocator: do not check NUMA node ID when the caller knows the node is
valid") as an optimized variant of alloc_pages_node(), that doesn't
fallback to current node for nid == NUMA_NO_NODE. Unfortunately the
name of the function can easily suggest that the allocation is
restricted to the given node and fails otherwise. In truth, the node is
only preferred, unless __GFP_THISNODE is passed among the gfp flags.
The misleading name has lead to mistakes in the past, see for example
commits 5265047ac301 ("mm, thp: really limit transparent hugepage
allocation to local node") and b360edb43f8e ("mm, mempolicy:
migrate_to_node should only migrate to node").
Another issue with the name is that there's a family of
alloc_pages_exact*() functions where 'exact' means exact size (instead
of page order), which leads to more confusion.
To prevent further mistakes, this patch effectively renames
alloc_pages_exact_node() to __alloc_pages_node() to better convey that
it's an optimized variant of alloc_pages_node() not intended for general
usage. Both functions get described in comments.
It has been also considered to really provide a convenience function for
allocations restricted to a node, but the major opinion seems to be that
__GFP_THISNODE already provides that functionality and we shouldn't
duplicate the API needlessly. The number of users would be small
anyway.
Existing callers of alloc_pages_exact_node() are simply converted to
call __alloc_pages_node(), with the exception of sba_alloc_coherent()
which open-codes the check for NUMA_NO_NODE, so it is converted to use
alloc_pages_node() instead. This means it no longer performs some
VM_BUG_ON checks, and since the current check for nid in
alloc_pages_node() uses a 'nid < 0' comparison (which includes
NUMA_NO_NODE), it may hide wrong values which would be previously
exposed.
Both differences will be rectified by the next patch.
To sum up, this patch makes no functional changes, except temporarily
hiding potentially buggy callers. Restricting the checks in
alloc_pages_node() is left for the next patch which can in turn expose
more existing buggy callers.
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Robin Holt <robinmholt@gmail.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Acked-by: Christoph Lameter <cl@linux.com>
Acked-by: Michael Ellerman <mpe@ellerman.id.au>
Cc: Mel Gorman <mgorman@suse.de>
Cc: David Rientjes <rientjes@google.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Gleb Natapov <gleb@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Cliff Whickman <cpw@sgi.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-09-08 22:03:50 +00:00
|
|
|
page = __alloc_pages_node(node,
|
2007-10-16 08:25:34 +00:00
|
|
|
GFP_KERNEL | __GFP_ZERO,
|
2006-09-26 06:31:45 +00:00
|
|
|
0);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!page)
|
2010-05-26 21:43:32 +00:00
|
|
|
return notifier_from_errno(-ENOMEM);
|
2005-04-16 22:20:36 +00:00
|
|
|
per_cpu(cpu_profile_hits, cpu)[1] = page_address(page);
|
|
|
|
}
|
|
|
|
if (!per_cpu(cpu_profile_hits, cpu)[0]) {
|
mm: rename alloc_pages_exact_node() to __alloc_pages_node()
alloc_pages_exact_node() was introduced in commit 6484eb3e2a81 ("page
allocator: do not check NUMA node ID when the caller knows the node is
valid") as an optimized variant of alloc_pages_node(), that doesn't
fallback to current node for nid == NUMA_NO_NODE. Unfortunately the
name of the function can easily suggest that the allocation is
restricted to the given node and fails otherwise. In truth, the node is
only preferred, unless __GFP_THISNODE is passed among the gfp flags.
The misleading name has lead to mistakes in the past, see for example
commits 5265047ac301 ("mm, thp: really limit transparent hugepage
allocation to local node") and b360edb43f8e ("mm, mempolicy:
migrate_to_node should only migrate to node").
Another issue with the name is that there's a family of
alloc_pages_exact*() functions where 'exact' means exact size (instead
of page order), which leads to more confusion.
To prevent further mistakes, this patch effectively renames
alloc_pages_exact_node() to __alloc_pages_node() to better convey that
it's an optimized variant of alloc_pages_node() not intended for general
usage. Both functions get described in comments.
It has been also considered to really provide a convenience function for
allocations restricted to a node, but the major opinion seems to be that
__GFP_THISNODE already provides that functionality and we shouldn't
duplicate the API needlessly. The number of users would be small
anyway.
Existing callers of alloc_pages_exact_node() are simply converted to
call __alloc_pages_node(), with the exception of sba_alloc_coherent()
which open-codes the check for NUMA_NO_NODE, so it is converted to use
alloc_pages_node() instead. This means it no longer performs some
VM_BUG_ON checks, and since the current check for nid in
alloc_pages_node() uses a 'nid < 0' comparison (which includes
NUMA_NO_NODE), it may hide wrong values which would be previously
exposed.
Both differences will be rectified by the next patch.
To sum up, this patch makes no functional changes, except temporarily
hiding potentially buggy callers. Restricting the checks in
alloc_pages_node() is left for the next patch which can in turn expose
more existing buggy callers.
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Robin Holt <robinmholt@gmail.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Acked-by: Christoph Lameter <cl@linux.com>
Acked-by: Michael Ellerman <mpe@ellerman.id.au>
Cc: Mel Gorman <mgorman@suse.de>
Cc: David Rientjes <rientjes@google.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Gleb Natapov <gleb@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Cliff Whickman <cpw@sgi.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-09-08 22:03:50 +00:00
|
|
|
page = __alloc_pages_node(node,
|
2007-10-16 08:25:34 +00:00
|
|
|
GFP_KERNEL | __GFP_ZERO,
|
2006-09-26 06:31:45 +00:00
|
|
|
0);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!page)
|
|
|
|
goto out_free;
|
|
|
|
per_cpu(cpu_profile_hits, cpu)[0] = page_address(page);
|
|
|
|
}
|
|
|
|
break;
|
2008-01-25 20:08:33 +00:00
|
|
|
out_free:
|
2005-04-16 22:20:36 +00:00
|
|
|
page = virt_to_page(per_cpu(cpu_profile_hits, cpu)[1]);
|
|
|
|
per_cpu(cpu_profile_hits, cpu)[1] = NULL;
|
|
|
|
__free_page(page);
|
2010-05-26 21:43:32 +00:00
|
|
|
return notifier_from_errno(-ENOMEM);
|
2005-04-16 22:20:36 +00:00
|
|
|
case CPU_ONLINE:
|
2007-05-09 09:35:10 +00:00
|
|
|
case CPU_ONLINE_FROZEN:
|
2008-12-31 23:42:27 +00:00
|
|
|
if (prof_cpu_mask != NULL)
|
|
|
|
cpumask_set_cpu(cpu, prof_cpu_mask);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
case CPU_UP_CANCELED:
|
2007-05-09 09:35:10 +00:00
|
|
|
case CPU_UP_CANCELED_FROZEN:
|
2005-04-16 22:20:36 +00:00
|
|
|
case CPU_DEAD:
|
2007-05-09 09:35:10 +00:00
|
|
|
case CPU_DEAD_FROZEN:
|
2008-12-31 23:42:27 +00:00
|
|
|
if (prof_cpu_mask != NULL)
|
|
|
|
cpumask_clear_cpu(cpu, prof_cpu_mask);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (per_cpu(cpu_profile_hits, cpu)[0]) {
|
|
|
|
page = virt_to_page(per_cpu(cpu_profile_hits, cpu)[0]);
|
|
|
|
per_cpu(cpu_profile_hits, cpu)[0] = NULL;
|
|
|
|
__free_page(page);
|
|
|
|
}
|
|
|
|
if (per_cpu(cpu_profile_hits, cpu)[1]) {
|
|
|
|
page = virt_to_page(per_cpu(cpu_profile_hits, cpu)[1]);
|
|
|
|
per_cpu(cpu_profile_hits, cpu)[1] = NULL;
|
|
|
|
__free_page(page);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NOTIFY_OK;
|
|
|
|
}
|
|
|
|
#else /* !CONFIG_SMP */
|
|
|
|
#define profile_flip_buffers() do { } while (0)
|
|
|
|
#define profile_discard_flip_buffers() do { } while (0)
|
2006-12-07 04:38:17 +00:00
|
|
|
#define profile_cpu_callback NULL
|
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 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();
|
|
|
|
|
2008-12-31 23:42:27 +00:00
|
|
|
if (!user_mode(regs) && prof_cpu_mask != NULL &&
|
|
|
|
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>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/uaccess.h>
|
|
|
|
|
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
|
|
|
|
2008-12-31 23:42:27 +00:00
|
|
|
if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-09-18 19:57:09 +00:00
|
|
|
static const struct file_operations prof_cpu_mask_proc_fops = {
|
|
|
|
.open = prof_cpu_mask_proc_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = single_release,
|
|
|
|
.write = prof_cpu_mask_proc_write,
|
|
|
|
};
|
|
|
|
|
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 */
|
2013-04-02 00:48:34 +00:00
|
|
|
proc_create("irq/prof_cpu_mask", 0600, NULL, &prof_cpu_mask_proc_fops);
|
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;
|
|
|
|
}
|
|
|
|
|
2006-12-07 04:40:36 +00:00
|
|
|
static const struct file_operations proc_profile_operations = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.read = read_profile,
|
|
|
|
.write = write_profile,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-15 16:52:59 +00:00
|
|
|
.llseek = default_llseek,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
2008-11-19 06:20:10 +00:00
|
|
|
static void profile_nop(void *unused)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-10-16 05:01:46 +00:00
|
|
|
static int create_hash_tables(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
for_each_online_cpu(cpu) {
|
2010-05-26 21:45:04 +00:00
|
|
|
int node = cpu_to_mem(cpu);
|
2005-04-16 22:20:36 +00:00
|
|
|
struct page *page;
|
|
|
|
|
mm: rename alloc_pages_exact_node() to __alloc_pages_node()
alloc_pages_exact_node() was introduced in commit 6484eb3e2a81 ("page
allocator: do not check NUMA node ID when the caller knows the node is
valid") as an optimized variant of alloc_pages_node(), that doesn't
fallback to current node for nid == NUMA_NO_NODE. Unfortunately the
name of the function can easily suggest that the allocation is
restricted to the given node and fails otherwise. In truth, the node is
only preferred, unless __GFP_THISNODE is passed among the gfp flags.
The misleading name has lead to mistakes in the past, see for example
commits 5265047ac301 ("mm, thp: really limit transparent hugepage
allocation to local node") and b360edb43f8e ("mm, mempolicy:
migrate_to_node should only migrate to node").
Another issue with the name is that there's a family of
alloc_pages_exact*() functions where 'exact' means exact size (instead
of page order), which leads to more confusion.
To prevent further mistakes, this patch effectively renames
alloc_pages_exact_node() to __alloc_pages_node() to better convey that
it's an optimized variant of alloc_pages_node() not intended for general
usage. Both functions get described in comments.
It has been also considered to really provide a convenience function for
allocations restricted to a node, but the major opinion seems to be that
__GFP_THISNODE already provides that functionality and we shouldn't
duplicate the API needlessly. The number of users would be small
anyway.
Existing callers of alloc_pages_exact_node() are simply converted to
call __alloc_pages_node(), with the exception of sba_alloc_coherent()
which open-codes the check for NUMA_NO_NODE, so it is converted to use
alloc_pages_node() instead. This means it no longer performs some
VM_BUG_ON checks, and since the current check for nid in
alloc_pages_node() uses a 'nid < 0' comparison (which includes
NUMA_NO_NODE), it may hide wrong values which would be previously
exposed.
Both differences will be rectified by the next patch.
To sum up, this patch makes no functional changes, except temporarily
hiding potentially buggy callers. Restricting the checks in
alloc_pages_node() is left for the next patch which can in turn expose
more existing buggy callers.
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Robin Holt <robinmholt@gmail.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Acked-by: Christoph Lameter <cl@linux.com>
Acked-by: Michael Ellerman <mpe@ellerman.id.au>
Cc: Mel Gorman <mgorman@suse.de>
Cc: David Rientjes <rientjes@google.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Gleb Natapov <gleb@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Cliff Whickman <cpw@sgi.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-09-08 22:03:50 +00:00
|
|
|
page = __alloc_pages_node(node,
|
2014-03-10 22:49:43 +00:00
|
|
|
GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE,
|
2006-09-26 06:31:45 +00:00
|
|
|
0);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!page)
|
|
|
|
goto out_cleanup;
|
|
|
|
per_cpu(cpu_profile_hits, cpu)[1]
|
|
|
|
= (struct profile_hit *)page_address(page);
|
mm: rename alloc_pages_exact_node() to __alloc_pages_node()
alloc_pages_exact_node() was introduced in commit 6484eb3e2a81 ("page
allocator: do not check NUMA node ID when the caller knows the node is
valid") as an optimized variant of alloc_pages_node(), that doesn't
fallback to current node for nid == NUMA_NO_NODE. Unfortunately the
name of the function can easily suggest that the allocation is
restricted to the given node and fails otherwise. In truth, the node is
only preferred, unless __GFP_THISNODE is passed among the gfp flags.
The misleading name has lead to mistakes in the past, see for example
commits 5265047ac301 ("mm, thp: really limit transparent hugepage
allocation to local node") and b360edb43f8e ("mm, mempolicy:
migrate_to_node should only migrate to node").
Another issue with the name is that there's a family of
alloc_pages_exact*() functions where 'exact' means exact size (instead
of page order), which leads to more confusion.
To prevent further mistakes, this patch effectively renames
alloc_pages_exact_node() to __alloc_pages_node() to better convey that
it's an optimized variant of alloc_pages_node() not intended for general
usage. Both functions get described in comments.
It has been also considered to really provide a convenience function for
allocations restricted to a node, but the major opinion seems to be that
__GFP_THISNODE already provides that functionality and we shouldn't
duplicate the API needlessly. The number of users would be small
anyway.
Existing callers of alloc_pages_exact_node() are simply converted to
call __alloc_pages_node(), with the exception of sba_alloc_coherent()
which open-codes the check for NUMA_NO_NODE, so it is converted to use
alloc_pages_node() instead. This means it no longer performs some
VM_BUG_ON checks, and since the current check for nid in
alloc_pages_node() uses a 'nid < 0' comparison (which includes
NUMA_NO_NODE), it may hide wrong values which would be previously
exposed.
Both differences will be rectified by the next patch.
To sum up, this patch makes no functional changes, except temporarily
hiding potentially buggy callers. Restricting the checks in
alloc_pages_node() is left for the next patch which can in turn expose
more existing buggy callers.
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Robin Holt <robinmholt@gmail.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Acked-by: Christoph Lameter <cl@linux.com>
Acked-by: Michael Ellerman <mpe@ellerman.id.au>
Cc: Mel Gorman <mgorman@suse.de>
Cc: David Rientjes <rientjes@google.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Gleb Natapov <gleb@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Cliff Whickman <cpw@sgi.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-09-08 22:03:50 +00:00
|
|
|
page = __alloc_pages_node(node,
|
2014-03-10 22:49:43 +00:00
|
|
|
GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE,
|
2006-09-26 06:31:45 +00:00
|
|
|
0);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!page)
|
|
|
|
goto out_cleanup;
|
|
|
|
per_cpu(cpu_profile_hits, cpu)[0]
|
|
|
|
= (struct profile_hit *)page_address(page);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
out_cleanup:
|
|
|
|
prof_on = 0;
|
2005-05-01 15:58:47 +00:00
|
|
|
smp_mb();
|
2008-05-09 07:39:44 +00:00
|
|
|
on_each_cpu(profile_nop, NULL, 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
for_each_online_cpu(cpu) {
|
|
|
|
struct page *page;
|
|
|
|
|
|
|
|
if (per_cpu(cpu_profile_hits, cpu)[0]) {
|
|
|
|
page = virt_to_page(per_cpu(cpu_profile_hits, cpu)[0]);
|
|
|
|
per_cpu(cpu_profile_hits, cpu)[0] = NULL;
|
|
|
|
__free_page(page);
|
|
|
|
}
|
|
|
|
if (per_cpu(cpu_profile_hits, cpu)[1]) {
|
|
|
|
page = virt_to_page(per_cpu(cpu_profile_hits, cpu)[1]);
|
|
|
|
per_cpu(cpu_profile_hits, cpu)[1] = NULL;
|
|
|
|
__free_page(page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define create_hash_tables() ({ 0; })
|
|
|
|
#endif
|
|
|
|
|
2008-11-22 17:36:44 +00:00
|
|
|
int __ref create_proc_profile(void) /* false positive from hotcpu_notifier */
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct proc_dir_entry *entry;
|
2014-03-10 20:42:08 +00:00
|
|
|
int err = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (!prof_on)
|
|
|
|
return 0;
|
2014-03-10 20:42:08 +00:00
|
|
|
|
|
|
|
cpu_notifier_register_begin();
|
|
|
|
|
|
|
|
if (create_hash_tables()) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2008-04-29 08:02:31 +00:00
|
|
|
entry = proc_create("profile", S_IWUSR | S_IRUGO,
|
|
|
|
NULL, &proc_profile_operations);
|
2008-01-25 20:08:33 +00:00
|
|
|
if (!entry)
|
2014-03-10 20:42:08 +00:00
|
|
|
goto out;
|
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
|
|
|
__hotcpu_notifier(profile_cpu_callback, 0);
|
|
|
|
|
|
|
|
out:
|
|
|
|
cpu_notifier_register_done();
|
|
|
|
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 */
|