linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] oprofile: hotplug cpu fix
@ 2008-10-15 18:09 Chris J Arges
  2008-10-17  9:04 ` Robert Richter
  0 siblings, 1 reply; 2+ messages in thread
From: Chris J Arges @ 2008-10-15 18:09 UTC (permalink / raw)
  To: oprofile-list, linux-kernel; +Cc: Robert Richter, Maynard Johnson

[-- Attachment #1: Type: text/plain, Size: 1431 bytes --]

This patch addresses crashes when hotplugging cpus while profiling.
I used the following script to test :

    #!/bin/bash
    startup()
    {
      opcontrol --init
      opcontrol --vmlinux=/boot/vmlinux
      opcontrol --reset
      opcontrol  --start
      opcontrol --dump
    }
    shutdown()
    {
      opcontrol --dump
      opcontrol -h
    }
    startup
    echo 0 > /sys/devices/system/cpu/cpu2/online
    echo 0 > /sys/devices/system/cpu/cpu1/online
    shutdown
    startup
    echo 1 > /sys/devices/system/cpu/cpu2/online
    echo 1 > /sys/devices/system/cpu/cpu1/online
    shutdown
    startup
    echo 0 > /sys/devices/system/cpu/cpu2/online
    shutdown
    startup
    echo 1 > /sys/devices/system/cpu/cpu2/online
    echo 0 > /sys/devices/system/cpu/cpu2/online
    shutdown
    echo 1 > /sys/devices/system/cpu/cpu2/online

Without the patch on my Power machine (ppc970mp) I get the following error:

    Vector: 300 (Data Access) at [c000000276143950]
    pc: d0000000000366e8: .add_event_entry+0x60/0xb0 [oprofile]
    lr: d000000000035e60: .sync_buffer+0x68/0x4ac [oprofile]

Without the patch on my x86 (Core 2 Duo) machine:

    mutex_lock +0x8/0x20
    sync_buffer +0x29/0x3e0
    wq_sync_buffer +0x0/0x70

Since I'm guessing hotplugging cpus and using oprofile is not a common 
occurrence, this patch is just a do-no-harm fix, instead
of a full solution with a hotplug callback, etc.

Thanks,
--chris


[-- Attachment #2: 0001-oprofile-hotplug-cpu-fix.patch --]
[-- Type: text/x-patch, Size: 1710 bytes --]

>From 60f07301d3c387a0405becccbdc0cfb7e99ecf39 Mon Sep 17 00:00:00 2001
From: Chris J Arges <arges@linux.vnet.ibm.com>
Date: Wed, 15 Oct 2008 11:03:39 -0500
Subject: [PATCH] oprofile: hotplug cpu fix
 This patch addresses problems when hotplugging cpus while profiling.
 Instead of allocating only online cpus, all possible cpu buffers are
 allocated, which allows cpus to be onlined during operation. If a cpu is
 offlined before profiling is shutdown wq_sync_buffer checks for this
 condition then cancels this work and does not sync this buffer.

---
 drivers/oprofile/cpu_buffer.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/oprofile/cpu_buffer.c b/drivers/oprofile/cpu_buffer.c
index e1bd5a9..8bb030b 100644
--- a/drivers/oprofile/cpu_buffer.c
+++ b/drivers/oprofile/cpu_buffer.c
@@ -39,7 +39,7 @@ void free_cpu_buffers(void)
 {
 	int i;
  
-	for_each_online_cpu(i) {
+	for_each_possible_cpu(i) {
 		vfree(per_cpu(cpu_buffer, i).buffer);
 		per_cpu(cpu_buffer, i).buffer = NULL;
 	}
@@ -51,7 +51,7 @@ int alloc_cpu_buffers(void)
  
 	unsigned long buffer_size = fs_cpu_buffer_size;
  
-	for_each_online_cpu(i) {
+	for_each_possible_cpu(i) {
 		struct oprofile_cpu_buffer *b = &per_cpu(cpu_buffer, i);
  
 		b->buffer = vmalloc_node(sizeof(struct op_sample) * buffer_size,
@@ -368,6 +368,11 @@ static void wq_sync_buffer(struct work_struct *work)
 	if (b->cpu != smp_processor_id()) {
 		printk(KERN_DEBUG "WQ on CPU%d, prefer CPU%d\n",
 		       smp_processor_id(), b->cpu);
+
+		if (!cpu_online(b->cpu)) {
+			cancel_delayed_work(&b->work);
+			return;
+		}
 	}
 	sync_buffer(b->cpu);
 
-- 
1.5.4.5

Signed-off-by: Chris J Arges <arges@linux.vnet.ibm.com>




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] oprofile: hotplug cpu fix
  2008-10-15 18:09 [PATCH] oprofile: hotplug cpu fix Chris J Arges
@ 2008-10-17  9:04 ` Robert Richter
  0 siblings, 0 replies; 2+ messages in thread
From: Robert Richter @ 2008-10-17  9:04 UTC (permalink / raw)
  To: Chris J Arges; +Cc: oprofile-list, linux-kernel, Maynard Johnson, Ingo Molnar

On 15.10.08 12:09:45, Chris J Arges wrote:
> From 60f07301d3c387a0405becccbdc0cfb7e99ecf39 Mon Sep 17 00:00:00 2001
> From: Chris J Arges <arges@linux.vnet.ibm.com>
> Date: Wed, 15 Oct 2008 11:03:39 -0500
> Subject: [PATCH] oprofile: hotplug cpu fix
>  This patch addresses problems when hotplugging cpus while profiling.
>  Instead of allocating only online cpus, all possible cpu buffers are
>  allocated, which allows cpus to be onlined during operation. If a cpu is
>  offlined before profiling is shutdown wq_sync_buffer checks for this
>  condition then cancels this work and does not sync this buffer.
> 

Applied to oprofile/oprofile-for-tip. Thanks, Chris.

-Robert

-- 
Advanced Micro Devices, Inc.
Operating System Research Center
email: robert.richter@amd.com


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-10-17  9:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-15 18:09 [PATCH] oprofile: hotplug cpu fix Chris J Arges
2008-10-17  9:04 ` Robert Richter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).