From patchwork Tue Jul 5 04:42:49 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: 644462 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rkBGv2hcYz9s9G for ; Tue, 5 Jul 2016 14:48:38 +1000 (AEST) Received: from localhost ([::1]:51911 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKIHk-0001zw-D4 for incoming@patchwork.ozlabs.org; Tue, 05 Jul 2016 00:48:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53509) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKICa-0002TL-Iw for qemu-devel@nongnu.org; Tue, 05 Jul 2016 00:43:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKICX-0005oN-7V for qemu-devel@nongnu.org; Tue, 05 Jul 2016 00:43:16 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:22311 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKICX-0005nl-2A for qemu-devel@nongnu.org; Tue, 05 Jul 2016 00:43:13 -0400 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u654dRFT001626 for ; Tue, 5 Jul 2016 00:43:11 -0400 Received: from e28smtp02.in.ibm.com (e28smtp02.in.ibm.com [125.16.236.2]) by mx0b-001b2d01.pphosted.com with ESMTP id 23x7rvkdcn-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 05 Jul 2016 00:43:11 -0400 Received: from localhost by e28smtp02.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 5 Jul 2016 10:13:08 +0530 Received: from d28dlp03.in.ibm.com (9.184.220.128) by e28smtp02.in.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 5 Jul 2016 10:13:07 +0530 X-IBM-Helo: d28dlp03.in.ibm.com X-IBM-MailFrom: bharata@linux.vnet.ibm.com X-IBM-RcptTo: qemu-devel@nongnu.org;qemu-ppc@nongnu.org Received: from d28relay06.in.ibm.com (d28relay06.in.ibm.com [9.184.220.150]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id 295DD125805E; Tue, 5 Jul 2016 10:15:51 +0530 (IST) Received: from d28av04.in.ibm.com (d28av04.in.ibm.com [9.184.220.66]) by d28relay06.in.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u654h6A648758810; Tue, 5 Jul 2016 10:13:06 +0530 Received: from d28av04.in.ibm.com (localhost [127.0.0.1]) by d28av04.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u654h4RK010673; Tue, 5 Jul 2016 10:13:05 +0530 Received: from bharata.in.ibm.com ([9.79.220.157]) by d28av04.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u654h13E010628; Tue, 5 Jul 2016 10:13:03 +0530 From: Bharata B Rao To: qemu-devel@nongnu.org Date: Tue, 5 Jul 2016 10:12:49 +0530 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1467693772-7391-1-git-send-email-bharata@linux.vnet.ibm.com> References: <1467693772-7391-1-git-send-email-bharata@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16070504-0004-0000-0000-000002BBB1CE X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16070504-0005-0000-0000-00000DD5C864 Message-Id: <1467693772-7391-3-git-send-email-bharata@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-07-05_02:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1607050043 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [RFC PATCH v0 2/5] cpu: Optionally use arch_id instead of cpu_index in cpu vmstate_register() 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: nikunj@linux.vnet.ibm.com, Bharata B Rao , groug@kaod.org, qemu-ppc@nongnu.org, pbonzini@redhat.com, imammedo@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Introduce CPUState.prefer_arch_id_over_cpu_index and MachineClass.prefer_arch_id_over_cpu_index that allow target machines to optionally switch to using arch_id instead of cpu_index as instance_id in vmstate_register(). This will help allow successful migration in cases where holes are introduced in cpu_index range after CPU hot removals. Whether to use arch_id or cpu_index is based on machine type version and hence added MachineClass.prefer_arch_id_over_cpu_index. However the enforcement is via and during CPU creation and hence added CPUState.prefer_arch_id_over_cpu_index. So it becomes a two step process for the target to enable the use of arch_id: 1. Set MachineClass.prefer_arch_id_over_cpu_index. 2. Ensure CPUState.prefer_arch_id_over_cpu_index is set for all CPUs based on 1. above. Suggested-by: Igor Mammedov Signed-off-by: Bharata B Rao --- exec.c | 10 ++++++++-- include/hw/boards.h | 1 + include/qom/cpu.h | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index 8ce8e90..7cc1d06 100644 --- a/exec.c +++ b/exec.c @@ -616,15 +616,21 @@ static void cpu_release_index(CPUState *cpu) bitmap_clear(cpu_index_map, cpu->cpu_index, 1); } +/* + * TODO: cpu_index and instance_id are of type int while .get_arch_id()is + * of type int64_t. What is the consequence of changing instance_id to int64_t ? + */ static void cpu_vmstate_register(CPUState *cpu) { CPUClass *cc = CPU_GET_CLASS(cpu); + int instance_id = cpu->prefer_arch_id_over_cpu_index ? + cc->get_arch_id(cpu) : cpu->cpu_index; if (qdev_get_vmsd(DEVICE(cpu)) == NULL) { - vmstate_register(NULL, cpu->cpu_index, &vmstate_cpu_common, cpu); + vmstate_register(NULL, instance_id, &vmstate_cpu_common, cpu); } if (cc->vmsd != NULL) { - vmstate_register(NULL, cpu->cpu_index, cc->vmsd, cpu); + vmstate_register(NULL, instance_id, cc->vmsd, cpu); } } diff --git a/include/hw/boards.h b/include/hw/boards.h index 3ed6155..decabba 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -123,6 +123,7 @@ struct MachineClass { ram_addr_t default_ram_size; bool option_rom_has_mr; bool rom_file_has_mr; + bool prefer_arch_id_over_cpu_index; HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev); diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 32f3af3..1f1706e 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -273,6 +273,9 @@ struct qemu_work_item { * @kvm_fd: vCPU file descriptor for KVM. * @work_mutex: Lock to prevent multiple access to queued_work_*. * @queued_work_first: First asynchronous work pending. + * @prefer_arch_id_over_cpu_index: Set to enforce the use of + * CPUClass.get_arch_id() over cpu_index during vmstate registration + * and any other uses by target machine where arch_id is preferred. * * State of one CPU core or thread. */ @@ -360,6 +363,7 @@ struct CPUState { (absolute value) offset as small as possible. This reduces code size, especially for hosts without large memory offsets. */ uint32_t tcg_exit_req; + bool prefer_arch_id_over_cpu_index; }; QTAILQ_HEAD(CPUTailQ, CPUState);