linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jens Axboe <jens.axboe-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
To: Mark Lord <lkml-gsilrlXbHYg@public.gmane.org>
Cc: linux-arch-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	npiggin-l3A5Bk7waGM@public.gmane.org,
	torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org
Subject: Re: [PATCH 1/11] Add generic helpers for arch IPI function calls
Date: Thu, 24 Apr 2008 12:59:08 +0200	[thread overview]
Message-ID: <20080424105908.GW12774@kernel.dk> (raw)
In-Reply-To: <480F4BD9.8090003-gsilrlXbHYg@public.gmane.org>

On Wed, Apr 23 2008, Mark Lord wrote:
> Jens Axboe wrote:
> >On Wed, Apr 23 2008, Mark Lord wrote:
> >..
> >>The second bug, is that for the halt case at least,
> >>nobody waits for the other CPU to actually halt
> >>before continuing.. so we sometimes enter the shutdown
> >>code while other CPUs are still active.
> >>
> >>This causes some machines to hang at shutdown,
> >>unless CPU_HOTPLUG is configured and takes them offline
> >>before we get here.
> >
> >I'm guessing there's a reason it doesn't pass '1' as the last argument,
> >because that would fix that issue?
> ..
> 
> Undoubtedly -- perhaps the called CPU halts, and therefore cannot reply.  :)

Uhm yes, I guess stop_this_cpu() does exactly what the name implies :-)

> But some kind of pre-halt ack, perhaps plus a short delay by the caller
> after receipt of the ack, would probably suffice to kill that bug.
> 
> But I really haven't studied this code enough to know,
> other than that it historically has been a sticky area
> to poke around in.

Something like this will close the window to right up until the point
where the other CPUs have 'almost' called halt().

diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
index 5398385..94ec9bf 100644
--- a/arch/x86/kernel/smp.c
+++ b/arch/x86/kernel/smp.c
@@ -155,8 +155,9 @@ static void stop_this_cpu(void *dummy)
 	/*
 	 * Remove this CPU:
 	 */
-	cpu_clear(smp_processor_id(), cpu_online_map);
 	disable_local_APIC();
+	cpu_clear(smp_processor_id(), cpu_online_map);
+	smp_wmb();
 	if (hlt_works(smp_processor_id()))
 		for (;;) halt();
 	for (;;);
@@ -175,6 +176,12 @@ static void native_smp_send_stop(void)
 
 	local_irq_save(flags);
 	smp_call_function(stop_this_cpu, NULL, 0, 0);
+
+	while (cpus_weight(cpu_online_map) > 1) {
+		cpu_relax();
+		smp_rmb();
+	}
+
 	disable_local_APIC();
 	local_irq_restore(flags);
 }

-- 
Jens Axboe

WARNING: multiple messages have this Message-ID (diff)
From: Jens Axboe <jens.axboe@oracle.com>
To: Mark Lord <lkml@rtr.ca>
Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org,
	npiggin@suse.de, torvalds@linux-foundation.org
Subject: Re: [PATCH 1/11] Add generic helpers for arch IPI function calls
Date: Thu, 24 Apr 2008 12:59:08 +0200	[thread overview]
Message-ID: <20080424105908.GW12774@kernel.dk> (raw)
Message-ID: <20080424105908.bHyOSk2hpnE__Y220OYHWrAmuT1CwljQPxGqJTlsUm8@z> (raw)
In-Reply-To: <480F4BD9.8090003@rtr.ca>

On Wed, Apr 23 2008, Mark Lord wrote:
> Jens Axboe wrote:
> >On Wed, Apr 23 2008, Mark Lord wrote:
> >..
> >>The second bug, is that for the halt case at least,
> >>nobody waits for the other CPU to actually halt
> >>before continuing.. so we sometimes enter the shutdown
> >>code while other CPUs are still active.
> >>
> >>This causes some machines to hang at shutdown,
> >>unless CPU_HOTPLUG is configured and takes them offline
> >>before we get here.
> >
> >I'm guessing there's a reason it doesn't pass '1' as the last argument,
> >because that would fix that issue?
> ..
> 
> Undoubtedly -- perhaps the called CPU halts, and therefore cannot reply.  :)

Uhm yes, I guess stop_this_cpu() does exactly what the name implies :-)

> But some kind of pre-halt ack, perhaps plus a short delay by the caller
> after receipt of the ack, would probably suffice to kill that bug.
> 
> But I really haven't studied this code enough to know,
> other than that it historically has been a sticky area
> to poke around in.

Something like this will close the window to right up until the point
where the other CPUs have 'almost' called halt().

diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
index 5398385..94ec9bf 100644
--- a/arch/x86/kernel/smp.c
+++ b/arch/x86/kernel/smp.c
@@ -155,8 +155,9 @@ static void stop_this_cpu(void *dummy)
 	/*
 	 * Remove this CPU:
 	 */
-	cpu_clear(smp_processor_id(), cpu_online_map);
 	disable_local_APIC();
+	cpu_clear(smp_processor_id(), cpu_online_map);
+	smp_wmb();
 	if (hlt_works(smp_processor_id()))
 		for (;;) halt();
 	for (;;);
@@ -175,6 +176,12 @@ static void native_smp_send_stop(void)
 
 	local_irq_save(flags);
 	smp_call_function(stop_this_cpu, NULL, 0, 0);
+
+	while (cpus_weight(cpu_online_map) > 1) {
+		cpu_relax();
+		smp_rmb();
+	}
+
 	disable_local_APIC();
 	local_irq_restore(flags);
 }

-- 
Jens Axboe


  parent reply	other threads:[~2008-04-24 10:59 UTC|newest]

Thread overview: 167+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-22  7:57 [PATCH 0/11] Generic smp_call_function() and friends Jens Axboe
2008-04-22  7:57 ` Jens Axboe
     [not found] ` <1208851058-8500-1-git-send-email-jens.axboe-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2008-04-22  7:57   ` [PATCH 1/11] Add generic helpers for arch IPI function calls Jens Axboe
2008-04-22  7:57     ` Jens Axboe
     [not found]     ` <1208851058-8500-2-git-send-email-jens.axboe-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2008-04-22  9:16       ` Avi Kivity
2008-04-22  9:16         ` Avi Kivity
     [not found]         ` <480DACDD.7040108-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2008-04-22  9:22           ` Jens Axboe
2008-04-22  9:22             ` Jens Axboe
     [not found]             ` <20080422092230.GW12774-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2008-04-22 11:14               ` Jens Axboe
2008-04-22 11:14                 ` Jens Axboe
2008-04-22 13:00                 ` Peter Zijlstra
2008-04-22 13:00                   ` Peter Zijlstra
2008-04-22 14:25                   ` Jens Axboe
2008-04-22 14:25                     ` Jens Axboe
     [not found]                     ` <20080422142543.GG12774-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2008-04-22 14:38                       ` Avi Kivity
2008-04-22 14:38                         ` Avi Kivity
     [not found]                         ` <480DF861.6000705-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2008-04-22 14:43                           ` Peter Zijlstra
2008-04-22 14:43                             ` Peter Zijlstra
2008-04-22 14:47                             ` Avi Kivity
2008-04-22 14:47                               ` Avi Kivity
2008-04-22 14:53                         ` Jens Axboe
2008-04-22 14:53                           ` Jens Axboe
2008-04-22 14:43       ` Linus Torvalds
2008-04-22 14:43         ` Linus Torvalds
     [not found]         ` <alpine.LFD.1.10.0804220735350.2779-5CScLwifNT1QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
2008-04-22 14:51           ` Jens Axboe
2008-04-22 14:51             ` Jens Axboe
2008-04-22 15:01             ` Linus Torvalds
2008-04-22 15:01               ` Linus Torvalds
2008-04-22 16:49               ` Jens Axboe
2008-04-22 16:49                 ` Jens Axboe
     [not found]                 ` <20080422164947.GN12774-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2008-04-22 17:04                   ` Jens Axboe
2008-04-22 17:04                     ` Jens Axboe
     [not found]                     ` <20080422170405.GO12774-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2008-04-22 17:13                       ` Jens Axboe
2008-04-22 17:13                         ` Jens Axboe
     [not found]                         ` <20080422171324.GP12774-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2008-04-22 17:29                           ` Linus Torvalds
2008-04-22 17:29                             ` Linus Torvalds
     [not found]                             ` <alpine.LFD.1.10.0804221027210.2779-5CScLwifNT1QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
2008-04-22 18:23                               ` Jens Axboe
2008-04-22 18:23                                 ` Jens Axboe
     [not found]                                 ` <20080422182337.GQ12774-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2008-04-22 18:39                                   ` Linus Torvalds
2008-04-22 18:39                                     ` Linus Torvalds
2008-04-22 14:58           ` Linus Torvalds
2008-04-22 14:58             ` Linus Torvalds
     [not found]             ` <alpine.LFD.1.10.0804220749450.2779-5CScLwifNT1QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
2008-04-22 15:07               ` Jens Axboe
2008-04-22 15:07                 ` Jens Axboe
2008-04-22 23:12       ` Mark Lord
2008-04-22 23:12         ` Mark Lord
     [not found]         ` <480E70ED.3030701-gsilrlXbHYg@public.gmane.org>
2008-04-23  7:24           ` Jens Axboe
2008-04-23  7:24             ` Jens Axboe
     [not found]             ` <20080423072432.GX12774-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2008-04-23 13:42               ` Mark Lord
2008-04-23 13:42                 ` Mark Lord
     [not found]                 ` <480F3CBC.60305-gsilrlXbHYg@public.gmane.org>
2008-04-23 13:51                   ` Jens Axboe
2008-04-23 13:51                     ` Jens Axboe
2008-04-23 14:46                     ` Mark Lord
2008-04-23 14:46                       ` Mark Lord
     [not found]                       ` <480F4BD9.8090003-gsilrlXbHYg@public.gmane.org>
2008-04-24 10:59                         ` Jens Axboe [this message]
2008-04-24 10:59                           ` Jens Axboe
     [not found]                           ` <20080424105908.GW12774-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2008-04-24 12:44                             ` Mark Lord
2008-04-24 12:44                               ` Mark Lord
     [not found]                               ` <481080A0.9050804-gsilrlXbHYg@public.gmane.org>
2008-04-24 21:30                                 ` Rafael J. Wysocki
2008-04-24 21:30                                   ` Rafael J. Wysocki
2008-04-25 11:08                                 ` Pavel Machek
2008-04-25 11:08                                   ` Pavel Machek
2008-04-26  8:04                             ` Pavel Machek
2008-04-26  8:04                               ` Pavel Machek
2008-04-28 15:13                               ` Mark Lord
2008-04-28 15:13                                 ` Mark Lord
2008-05-01 16:23                                 ` Pavel Machek
2008-04-22  7:57   ` [PATCH 2/11] x86: convert to generic helpers for " Jens Axboe
2008-04-22  7:57     ` Jens Axboe
     [not found]     ` <1208851058-8500-3-git-send-email-jens.axboe-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2008-04-22  8:38       ` Sam Ravnborg
2008-04-22  8:38         ` Sam Ravnborg
     [not found]         ` <20080422083810.GA23540-QabhHTsIXMSnlFQ6Q1D1Y0B+6BGkLq7r@public.gmane.org>
2008-04-22  8:43           ` Jens Axboe
2008-04-22  8:43             ` Jens Axboe
     [not found]             ` <20080422084315.GT12774-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2008-04-22 11:15               ` Jens Axboe
2008-04-22 11:15                 ` Jens Axboe
2008-04-22  8:47       ` Ingo Molnar
2008-04-22  8:47         ` Ingo Molnar
     [not found]         ` <20080422084738.GB2388-X9Un+BFzKDI@public.gmane.org>
2008-04-22  8:48           ` Jacek Luczak
2008-04-22  8:48             ` Jacek Luczak
     [not found]             ` <480DA670.4060707-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2008-04-22  8:56               ` Jens Axboe
2008-04-22  8:56                 ` Jens Axboe
     [not found]                 ` <20080422085629.GV12774-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2008-04-22  9:04                   ` Jacek Luczak
2008-04-22  9:04                     ` Jacek Luczak
2008-04-22  8:52           ` Jens Axboe
2008-04-22  8:52             ` Jens Axboe
2008-04-26  8:59           ` Jeremy Fitzhardinge
2008-04-26  8:59             ` Jeremy Fitzhardinge
2008-04-22  7:57   ` [PATCH 3/11] powerpc: " Jens Axboe
2008-04-22  7:57     ` Jens Axboe
     [not found]     ` <1208851058-8500-4-git-send-email-jens.axboe-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2008-04-22 12:03       ` Paul Mackerras
2008-04-22 12:03         ` Paul Mackerras
     [not found]         ` <18445.54284.194023.553595-UYQwCShxghk5kJ7NmlRacFaTQe2KTcn/@public.gmane.org>
2008-04-22 12:13           ` Jens Axboe
2008-04-22 12:13             ` Jens Axboe
     [not found]             ` <20080422121315.GE12774-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2008-04-22 12:42               ` Paul Mackerras
2008-04-22 12:42                 ` Paul Mackerras
     [not found]                 ` <18445.56653.957832.720681-UYQwCShxghk5kJ7NmlRacFaTQe2KTcn/@public.gmane.org>
2008-04-22 18:51                   ` Jens Axboe
2008-04-22 18:51                     ` Jens Axboe
2008-04-22  7:57   ` [PATCH 4/11] ia64: " Jens Axboe
2008-04-22  7:57     ` Jens Axboe
2008-04-22  7:57   ` [PATCH 5/11] alpha: " Jens Axboe
2008-04-22  7:57     ` Jens Axboe
2008-04-22  7:57   ` [PATCH 6/11] arm: " Jens Axboe
2008-04-22  7:57     ` Jens Axboe
2008-04-22 15:00     ` Catalin Marinas
2008-04-22 15:00       ` Catalin Marinas
     [not found]       ` <1208876447.31997.30.camel-hhZApKj8DF/YkXV2EHHjLW3o5bpOHsLO@public.gmane.org>
2008-04-22 18:43         ` Jens Axboe
2008-04-22 18:43           ` Jens Axboe
2008-04-22  7:57   ` [PATCH 7/11] m32r: " Jens Axboe
2008-04-22  7:57     ` Jens Axboe
2008-04-22  7:57   ` [PATCH 8/11] mips: " Jens Axboe
2008-04-22  7:57     ` Jens Axboe
2008-04-22  7:57   ` [PATCH 9/11] parisc: " Jens Axboe
2008-04-22  7:57     ` Jens Axboe
     [not found]     ` <1208851058-8500-10-git-send-email-jens.axboe-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2008-04-22 14:09       ` Kyle McMartin
2008-04-22 14:09         ` Kyle McMartin
     [not found]         ` <20080422140914.GD19802-EK4dZfYtfFRW/gs8oUvUg/d9D2ou9A/h@public.gmane.org>
2008-04-22 14:27           ` Jens Axboe
2008-04-22 14:27             ` Jens Axboe
     [not found]             ` <20080422142738.GH12774-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2008-04-22 14:30               ` Kyle McMartin
2008-04-22 14:30                 ` Kyle McMartin
     [not found]                 ` <20080422143016.GE19802-EK4dZfYtfFRW/gs8oUvUg/d9D2ou9A/h@public.gmane.org>
2008-04-22 14:49                   ` Jens Axboe
2008-04-22 14:49                     ` Jens Axboe
2008-04-22  7:57   ` [PATCH 10/11] sh: " Jens Axboe
2008-04-22  7:57     ` Jens Axboe
2008-04-22  7:57   ` [PATCH 11/11] s390: " Jens Axboe
2008-04-22  7:57     ` Jens Axboe
     [not found]     ` <1208851058-8500-12-git-send-email-jens.axboe-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2008-04-22  8:04       ` Martin Schwidefsky
2008-04-22  8:04         ` Martin Schwidefsky
2008-04-22  8:07         ` Jens Axboe
2008-04-22  8:07           ` Jens Axboe
2008-04-22  7:57   ` Jens Axboe
2008-04-22  7:57     ` Jens Axboe
2008-04-22  8:48   ` [PATCH 0/11] Generic smp_call_function() and friends Peter Zijlstra
2008-04-22  8:48     ` Peter Zijlstra
  -- strict thread matches above, loose matches on Subject: below --
2008-04-22 18:50 [PATCH 0/11] Generic smp_call_function() #2 Jens Axboe
     [not found] ` <1208890227-24808-1-git-send-email-jens.axboe-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2008-04-22 18:50   ` [PATCH 1/11] Add generic helpers for arch IPI function calls Jens Axboe
2008-04-22 18:50     ` Jens Axboe
     [not found]     ` <1208890227-24808-2-git-send-email-jens.axboe-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2008-04-22 20:17       ` Peter Zijlstra
2008-04-22 20:17         ` Peter Zijlstra
2008-04-23  6:07         ` Jens Axboe
2008-04-23  6:07           ` Jens Axboe
     [not found]           ` <20080423060725.GT12774-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2008-04-23  6:32             ` Peter Zijlstra
2008-04-23  6:32               ` Peter Zijlstra
2008-04-23  7:49               ` Jens Axboe
2008-04-23  7:49                 ` Jens Axboe
     [not found]                 ` <20080423074933.GB12774-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2008-04-23  7:50                   ` Peter Zijlstra
2008-04-23  7:50                     ` Peter Zijlstra
2008-04-24 22:01       ` Russell King
2008-04-24 22:01         ` Russell King
     [not found]         ` <20080424220157.GA26179-f404yB8NqCZvn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2008-04-25  7:18           ` Jens Axboe
2008-04-25  7:18             ` Jens Axboe
     [not found]             ` <20080425071823.GF12774-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2008-04-26  6:28               ` Jeremy Fitzhardinge
2008-04-26  6:28                 ` Jeremy Fitzhardinge
     [not found]                 ` <4812CB99.1070600-TSDbQ3PG+2Y@public.gmane.org>
2008-04-28  7:38                   ` Jes Sorensen
2008-04-28  7:38                     ` Jes Sorensen
2008-04-26  6:11       ` Andrew Morton
2008-04-26  6:11         ` Andrew Morton
     [not found]         ` <20080425231100.b93a1601.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2008-04-26 14:13           ` James Bottomley
2008-04-26 14:13             ` James Bottomley
2008-04-27  0:58           ` Paul E. McKenney
2008-04-27  0:58             ` Paul E. McKenney
     [not found]             ` <20080427005816.GB21687-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2008-04-27 10:36               ` Jens Axboe
2008-04-27 10:36                 ` Jens Axboe
2008-04-27 10:30           ` Jens Axboe
2008-04-27 10:30             ` Jens Axboe
     [not found]         ` <1209219236.3113.6.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2008-04-28 14:25           ` David Howells
2008-04-28 14:25             ` David Howells
     [not found]             ` <18470.1209392727-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2008-04-28 14:43               ` James Bottomley
2008-04-28 14:43                 ` James Bottomley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080424105908.GW12774@kernel.dk \
    --to=jens.axboe-qhclzuegtsvqt0dzr+alfa@public.gmane.org \
    --cc=linux-arch-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=lkml-gsilrlXbHYg@public.gmane.org \
    --cc=npiggin-l3A5Bk7waGM@public.gmane.org \
    --cc=torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).