From patchwork Thu May 12 03:48:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharata B Rao X-Patchwork-Id: 9076551 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C7461BF29F for ; Thu, 12 May 2016 03:49:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 11E63201DD for ; Thu, 12 May 2016 03:49:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 381E6201D3 for ; Thu, 12 May 2016 03:49:21 +0000 (UTC) Received: from localhost ([::1]:55226 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0hcm-0005Nu-BK for patchwork-qemu-devel@patchwork.kernel.org; Wed, 11 May 2016 23:49:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45886) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0hcN-0004x4-8l for qemu-devel@nongnu.org; Wed, 11 May 2016 23:48:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b0hcH-0002No-4f for qemu-devel@nongnu.org; Wed, 11 May 2016 23:48:55 -0400 Received: from e28smtp05.in.ibm.com ([125.16.236.5]:52195) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0hcG-0002M5-FS for qemu-devel@nongnu.org; Wed, 11 May 2016 23:48:49 -0400 Received: from localhost by e28smtp05.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 12 May 2016 09:18:45 +0530 Received: from d28dlp01.in.ibm.com (9.184.220.126) by e28smtp05.in.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 12 May 2016 09:18:43 +0530 X-IBM-Helo: d28dlp01.in.ibm.com X-IBM-MailFrom: bharata@linux.vnet.ibm.com X-IBM-RcptTo: qemu-devel@nongnu.org;qemu-ppc@nongnu.org Received: from d28relay08.in.ibm.com (d28relay08.in.ibm.com [9.184.220.159]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id 62CD9E005A; Thu, 12 May 2016 09:21:49 +0530 (IST) Received: from d28av05.in.ibm.com (d28av05.in.ibm.com [9.184.220.67]) by d28relay08.in.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u4C3mgks21561482; Thu, 12 May 2016 09:18:42 +0530 Received: from d28av05.in.ibm.com (localhost [127.0.0.1]) by d28av05.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u4C3mcIQ014022; Thu, 12 May 2016 09:18:41 +0530 Received: from bharata.in.ibm.com ([9.124.35.211]) by d28av05.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u4C3mVWQ013715; Thu, 12 May 2016 09:18:37 +0530 From: Bharata B Rao To: qemu-devel@nongnu.org Date: Thu, 12 May 2016 09:18:14 +0530 Message-Id: <1463024905-28401-5-git-send-email-bharata@linux.vnet.ibm.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1463024905-28401-1-git-send-email-bharata@linux.vnet.ibm.com> References: <1463024905-28401-1-git-send-email-bharata@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16051203-0017-0000-0000-00001EC11B57 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 125.16.236.5 Subject: [Qemu-devel] [for-2.7 PATCH v3 04/15] cpu: Add a sync version of cpu_remove() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mjrosato@linux.vnet.ibm.com, thuth@redhat.com, pkrempa@redhat.com, ehabkost@redhat.com, aik@ozlabs.ru, Bharata B Rao , armbru@redhat.com, agraf@suse.de, borntraeger@de.ibm.com, qemu-ppc@nongnu.org, pbonzini@redhat.com, imammedo@redhat.com, mdroth@linux.vnet.ibm.com, afaerber@suse.de, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This sync API will be used by the CPU hotplug code to wait for the CPU to completely get removed before flagging the failure to the device_add command. Sync version of this call is needed to correctly recover from CPU realization failures when ->plug() handler fails. Signed-off-by: Bharata B Rao Reviewed-by: David Gibson Acked-by: Paolo Bonzini --- cpus.c | 12 ++++++++++++ include/qom/cpu.h | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/cpus.c b/cpus.c index 3e7eada..0a6ae44 100644 --- a/cpus.c +++ b/cpus.c @@ -1082,6 +1082,8 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) } while (!cpu->unplug || cpu_can_run(cpu)); qemu_kvm_destroy_vcpu(cpu); + cpu->created = false; + qemu_cond_signal(&qemu_cpu_cond); qemu_mutex_unlock_iothread(); return NULL; } @@ -1182,6 +1184,8 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) } if (remove_cpu) { qemu_tcg_destroy_vcpu(remove_cpu); + cpu->created = false; + qemu_cond_signal(&qemu_cpu_cond); remove_cpu = NULL; } } @@ -1347,6 +1351,14 @@ void cpu_remove(CPUState *cpu) qemu_cpu_kick(cpu); } +void cpu_remove_sync(CPUState *cpu) +{ + cpu_remove(cpu); + while (cpu->created) { + qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex); + } +} + /* For temporary buffers for forming a name */ #define VCPU_THREAD_NAME_SIZE 16 diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 911bc9f..9c544f6 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -763,6 +763,14 @@ void cpu_resume(CPUState *cpu); */ void cpu_remove(CPUState *cpu); + /** + * cpu_remove_sync: + * @cpu: The CPU to remove. + * + * Requests the CPU to be removed and waits till it is removed. + */ +void cpu_remove_sync(CPUState *cpu); + /** * qemu_init_vcpu: * @cpu: The vCPU to initialize.