dect
/
linux-2.6
Archived
13
0
Fork 0
This repository has been archived on 2022-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
linux-2.6/arch
Paul Mackerras a63eaf34ae perf_counter: Dynamically allocate tasks' perf_counter_context struct
This replaces the struct perf_counter_context in the task_struct with
a pointer to a dynamically allocated perf_counter_context struct.  The
main reason for doing is this is to allow us to transfer a
perf_counter_context from one task to another when we do lazy PMU
switching in a later patch.

This has a few side-benefits: the task_struct becomes a little smaller,
we save some memory because only tasks that have perf_counters attached
get a perf_counter_context allocated for them, and we can remove the
inclusion of <linux/perf_counter.h> in sched.h, meaning that we don't
end up recompiling nearly everything whenever perf_counter.h changes.

The perf_counter_context structures are reference-counted and freed
when the last reference is dropped.  A context can have references
from its task and the counters on its task.  Counters can outlive the
task so it is possible that a context will be freed well after its
task has exited.

Contexts are allocated on fork if the parent had a context, or
otherwise the first time that a per-task counter is created on a task.
In the latter case, we set the context pointer in the task struct
locklessly using an atomic compare-and-exchange operation in case we
raced with some other task in creating a context for the subject task.

This also removes the task pointer from the perf_counter struct.  The
task pointer was not used anywhere and would make it harder to move a
context from one task to another.  Anything that needed to know which
task a counter was attached to was already using counter->ctx->task.

The __perf_counter_init_context function moves up in perf_counter.c
so that it can be called from find_get_context, and now initializes
the refcount, but is otherwise unchanged.

We were potentially calling list_del_counter twice: once from
__perf_counter_exit_task when the task exits and once from
__perf_counter_remove_from_context when the counter's fd gets closed.
This adds a check in list_del_counter so it doesn't do anything if
the counter has already been removed from the lists.

Since perf_counter_task_sched_in doesn't do anything if the task doesn't
have a context, and leaves cpuctx->task_ctx = NULL, this adds code to
__perf_install_in_context to set cpuctx->task_ctx if necessary, i.e. in
the case where the current task adds the first counter to itself and
thus creates a context for itself.

This also adds similar code to __perf_counter_enable to handle a
similar situation which can arise when the counters have been disabled
using prctl; that also leaves cpuctx->task_ctx = NULL.

[ Impact: refactor counter context management to prepare for new feature ]

Signed-off-by: Paul Mackerras <paulus@samba.org>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <18966.10075.781053.231153@cargo.ozlabs.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-05-22 12:18:19 +02:00
..
alpha alpha: unbreak percpu again 2009-05-12 14:11:35 -07:00
arm Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6 2009-05-15 08:06:56 -07:00
avr32 avr32: drop unused CLEAN_FILES 2009-05-01 10:54:00 +02:00
blackfin clocksource: pass clocksource to read() callback 2009-04-21 13:41:47 -07:00
cris CRISv32: Fix typo compile error in ARTPEC-3 gpio driver. 2009-04-28 19:08:10 +02:00
frv FRV: Use __INIT macro instead of .text.init. 2009-04-27 19:46:30 -07:00
h8300 Get rid of final remnants of include/asm-$(ARCH) 2009-04-17 09:59:27 -07:00
ia64 [IA64] xen_domu_defconfig: fix build issues/warnings 2009-05-05 11:43:13 -07:00
m32r m32r: use __stringify() macro in assembler.h 2009-05-02 22:38:21 +09:00
m68k m68k: arch/m68k/kernel/sun3-head.S needs <linux/init.h> 2009-04-28 16:07:18 -07:00
m68knommu Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/gerg/m68knommu 2009-04-24 08:45:53 -07:00
microblaze Merge branch 'fixes-for-linus' of git://git.monstr.eu/linux-2.6-microblaze 2009-05-08 16:24:25 -07:00
mips MIPS: Sibyte: Fix locking in set_irq_affinity 2009-05-14 13:50:30 +01:00
mn10300 mn10300: convert to use __HEAD and HEAD_TEXT macros. 2009-04-26 09:20:38 -07:00
parisc Merge git://git.kernel.org/pub/scm/linux/kernel/git/kyle/parisc-2.6 2009-04-03 09:52:04 -07:00
powerpc perf_counter: powerpc: initialize cpuhw pointer before use 2009-05-18 07:38:42 +02:00
s390 s390: convert to use __HEAD and HEAD_TEXT macros. 2009-04-26 09:20:39 -07:00
sh sh: Use __INIT macro instead of .text.init. 2009-04-27 19:51:58 -07:00
sparc sparc: cleanup references to deprecated .text.init* sections. 2009-04-27 19:51:58 -07:00
um uml: kill a kconfig warning 2009-04-21 13:41:50 -07:00
x86 perf_counter: Dynamically allocate tasks' perf_counter_context struct 2009-05-22 12:18:19 +02:00
xtensa xtensa: Fix linker script to include .literal sections 2009-05-11 23:40:33 -07:00
.gitignore
Kconfig mutex: have non-spinning mutexes on s390 by default 2009-04-09 19:28:24 +02:00