From patchwork Mon Oct 31 13:10:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Halil Pasic X-Patchwork-Id: 9405453 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1465D60585 for ; Mon, 31 Oct 2016 13:11:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EFD5829238 for ; Mon, 31 Oct 2016 13:11:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E209B29268; Mon, 31 Oct 2016 13:11:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 3F00729238 for ; Mon, 31 Oct 2016 13:11:00 +0000 (UTC) Received: from localhost ([::1]:35539 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1CMd-0000uQ-Id for patchwork-qemu-devel@patchwork.kernel.org; Mon, 31 Oct 2016 09:10:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47108) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1CMC-0000sJ-CD for qemu-devel@nongnu.org; Mon, 31 Oct 2016 09:10:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c1CM9-0002qI-66 for qemu-devel@nongnu.org; Mon, 31 Oct 2016 09:10:32 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:34603 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c1CM9-0002qC-0c for qemu-devel@nongnu.org; Mon, 31 Oct 2016 09:10:29 -0400 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id u9VD8QK8043610 for ; Mon, 31 Oct 2016 09:10:28 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0b-001b2d01.pphosted.com with ESMTP id 26cndhs3g4-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 31 Oct 2016 09:10:28 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 31 Oct 2016 13:10:26 -0000 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 31 Oct 2016 13:10:23 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 3C17E1B08069; Mon, 31 Oct 2016 13:12:32 +0000 (GMT) Received: from d06av03.portsmouth.uk.ibm.com (d06av03.portsmouth.uk.ibm.com [9.149.37.213]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u9VDANZI15728932; Mon, 31 Oct 2016 13:10:23 GMT Received: from d06av03.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u9VDALxY030879; Mon, 31 Oct 2016 07:10:23 -0600 Received: from oc3836556865.ibm.com (dyn-9-152-224-92.boeblingen.de.ibm.com [9.152.224.92]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u9VDAKNk030874; Mon, 31 Oct 2016 07:10:20 -0600 To: Jianjun Duan , "Dr. David Alan Gilbert" References: <1477607317-27817-1-git-send-email-duanj@linux.vnet.ibm.com> <1477607317-27817-3-git-send-email-duanj@linux.vnet.ibm.com> <20161028190657.GB2173@work-vm> <0cd200a6-3ded-0e02-1b8b-fbbf5c0bee03@linux.vnet.ibm.com> From: Halil Pasic Date: Mon, 31 Oct 2016 14:10:20 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <0cd200a6-3ded-0e02-1b8b-fbbf5c0bee03@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16103113-0008-0000-0000-000002EA8B19 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16103113-0009-0000-0000-00001A8AB9AE Message-Id: <88bb646d-39aa-e439-4b30-2c38777a4b56@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-10-31_03:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1610310239 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.158.5 Subject: Re: [Qemu-devel] [QEMU PATCH v9 2/3] migration: migrate QTAILQ 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: veroniabahaa@gmail.com, peter.maydell@linaro.org, quintela@redhat.com, mst@redhat.com, mark.cave-ayland@ilande.co.uk, mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org, blauwirbel@gmail.com, dmitry@daynix.com, qemu-ppc@nongnu.org, kraxel@redhat.com, david@gibson.dropbear.id.au, pbonzini@redhat.com, amit.shah@redhat.com, kwolf@redhat.com, mreitz@redhat.com, leon.alrae@imgtec.com, aurelien@aurel32.net, rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP On 10/28/2016 09:46 PM, Jianjun Duan wrote: > > > On 10/28/2016 12:06 PM, Dr. David Alan Gilbert wrote: >> * Jianjun Duan (duanj@linux.vnet.ibm.com) wrote: >>> Currently we cannot directly transfer a QTAILQ instance because of the >>> limitation in the migration code. Here we introduce an approach to >>> transfer such structures. We created VMStateInfo vmstate_info_qtailq >>> for QTAILQ. Similar VMStateInfo can be created for other data structures >>> such as list. >>> >>> This approach will be used to transfer pending_events and ccs_list in spapr >>> state. >>> >>> We also create some macros in qemu/queue.h to access a QTAILQ using pointer >>> arithmetic. This ensures that we do not depend on the implementation >>> details about QTAILQ in the migration code. >>> >>> Signed-off-by: Jianjun Duan >>> --- >>> include/migration/vmstate.h | 20 ++++++++++++++ >>> include/qemu/queue.h | 61 +++++++++++++++++++++++++++++++++++++++++ >>> migration/trace-events | 4 +++ >>> migration/vmstate.c | 67 +++++++++++++++++++++++++++++++++++++++++++++ >>> 4 files changed, 152 insertions(+) >>> >>> diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h >>> index d0e37b5..318a6f1 100644 >>> --- a/include/migration/vmstate.h >>> +++ b/include/migration/vmstate.h >>> @@ -251,6 +251,7 @@ extern const VMStateInfo vmstate_info_timer; >>> extern const VMStateInfo vmstate_info_buffer; >>> extern const VMStateInfo vmstate_info_unused_buffer; >>> extern const VMStateInfo vmstate_info_bitmap; >>> +extern const VMStateInfo vmstate_info_qtailq; >>> >>> #define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0) >>> #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0) >>> @@ -662,6 +663,25 @@ extern const VMStateInfo vmstate_info_bitmap; >>> .offset = offsetof(_state, _field), \ >>> } >>> >>> +/* For QTAILQ that need customized handling. >>> + * Target QTAILQ needs be properly initialized. >>> + * _type: type of QTAILQ element >>> + * _next: name of QTAILQ entry field in QTAILQ element >>> + * _vmsd: VMSD for QTAILQ element >>> + * size: size of QTAILQ element >>> + * start: offset of QTAILQ entry in QTAILQ element >>> + */ >>> +#define VMSTATE_QTAILQ_V(_field, _state, _version, _vmsd, _type, _next) \ >>> +{ \ >>> + .name = (stringify(_field)), \ >>> + .version_id = (_version), \ >>> + .vmsd = &(_vmsd), \ >>> + .size = sizeof(_type), \ >>> + .info = &vmstate_info_qtailq, \ >>> + .offset = offsetof(_state, _field), \ >>> + .start = offsetof(_type, _next), \ >>> +} >>> + >>> /* _f : field name >>> _f_n : num of elements field_name >>> _n : num of elements >>> diff --git a/include/qemu/queue.h b/include/qemu/queue.h >>> index 342073f..16af127 100644 >>> --- a/include/qemu/queue.h >>> +++ b/include/qemu/queue.h >>> @@ -438,4 +438,65 @@ struct { \ >>> #define QTAILQ_PREV(elm, headname, field) \ >>> (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) >>> >>> +#define field_at_offset(base, offset, type) \ >>> + ((type) (((char *) (base)) + (offset))) >>> + >>> +typedef struct DUMB_Q_ENTRY DUMB_Q_ENTRY; >>> +typedef struct DUMB_Q DUMB_Q; >>> + >>> +struct DUMB_Q_ENTRY { >>> + QTAILQ_ENTRY(DUMB_Q_ENTRY) next; >>> +}; >>> + >>> +struct DUMB_Q { >>> + QTAILQ_HEAD(DUMB_Q_HEAD, DUMB_Q_ENTRY) head; >>> +}; >> >> OK, good we've got rid of the hard coded offsets; thanks! >> >>> +#define dumb_q ((DUMB_Q *) 0) >>> +#define dumb_qh ((typeof(dumb_q->head) *) 0) >>> +#define dumb_qe ((DUMB_Q_ENTRY *) 0) >> >> Note that 'dumb' and 'dummy' are completely different words; >> this is a dummy not a dumb. >> > OK. >>> +/* >>> + * Offsets of layout of a tail queue head. >>> + */ >>> +#define QTAILQ_FIRST_OFFSET ((size_t) &(QTAILQ_FIRST(dumb_qh))) >> >> Isn't that just offsetof(dumb_qh, tqh_first) ? > Yes. But I don't want to depend on the inside of the type if it is > possible. QTAILQ_FIRST is a defined access macro. > >> >>> +#define QTAILQ_LAST_OFFSET (offsetof(typeof(dumb_q->head), tqh_last)) >> >> Similarly isnt't that just offsetof(DUMB_Q_HEAD, tqh_last) ? >> > Similarly, DUMB_Q_HEAD may not be a type name in the future. > > Thanks, > Jianjun >>> +/* >>> + * Raw access of elements of a tail queue >>> + */ >>> +#define QTAILQ_RAW_FIRST(head) \ >>> + (*field_at_offset(head, QTAILQ_FIRST_OFFSET, void **)) >>> +#define QTAILQ_RAW_LAST(head) \ >>> + (*field_at_offset(head, QTAILQ_LAST_OFFSET, void ***)) >>> + >>> +/* >>> + * Offsets of layout of a tail queue element. >>> + */ >>> +#define QTAILQ_NEXT_OFFSET ((size_t) (&QTAILQ_NEXT(dumb_qe, next))) >>> +#define QTAILQ_PREV_OFFSET (offsetof(typeof(dumb_qe->next), tqe_prev)) >> >> Similar comments to the pair above. >> >> Dave >> P.S. I'm out next week, so please someone else jump in. >> [..] I think this got overly complicated. Here is a little patch on top of your stuff which gets rid of 15 lines and IMHO simplifies things quite a bit. What do you think? It is based on/inspired by Dave's proposal with the dummy stuff. Did not address the typos though. Cheers, Halil ----------------- 8< ---------------------------- From: Halil Pasic Date: Mon, 31 Oct 2016 13:53:31 +0100 Subject: [PATCH] fixup: simplify QTAILQ raw access macros Intended to be fixed up to [PATCH v9 2/3] migration: migrate QTAILQ. Signed-off-by: Halil Pasic --- include/qemu/queue.h | 33 +++++++++------------------------ 1 files changed, 9 insertions(+), 24 deletions(-) diff --git a/include/qemu/queue.h b/include/qemu/queue.h index 16af127..d67cb4e 100644 --- a/include/qemu/queue.h +++ b/include/qemu/queue.h @@ -441,33 +441,17 @@ struct { \ #define field_at_offset(base, offset, type) \ ((type) (((char *) (base)) + (offset))) -typedef struct DUMB_Q_ENTRY DUMB_Q_ENTRY; -typedef struct DUMB_Q DUMB_Q; - -struct DUMB_Q_ENTRY { - QTAILQ_ENTRY(DUMB_Q_ENTRY) next; -}; - -struct DUMB_Q { - QTAILQ_HEAD(DUMB_Q_HEAD, DUMB_Q_ENTRY) head; -}; - -#define dumb_q ((DUMB_Q *) 0) -#define dumb_qh ((typeof(dumb_q->head) *) 0) -#define dumb_qe ((DUMB_Q_ENTRY *) 0) - /* - * Offsets of layout of a tail queue head. + * Raw access helpers */ -#define QTAILQ_FIRST_OFFSET ((size_t) &(QTAILQ_FIRST(dumb_qh))) -#define QTAILQ_LAST_OFFSET (offsetof(typeof(dumb_q->head), tqh_last)) +typedef Q_TAILQ_HEAD(QTAILQRawHead, void,) QTAILQRawHead; +typedef Q_TAILQ_ENTRY(void,) QTAILQRawEntry; + /* * Raw access of elements of a tail queue */ -#define QTAILQ_RAW_FIRST(head) \ - (*field_at_offset(head, QTAILQ_FIRST_OFFSET, void **)) -#define QTAILQ_RAW_LAST(head) \ - (*field_at_offset(head, QTAILQ_LAST_OFFSET, void ***)) +#define QTAILQ_RAW_FIRST(head) (((QTAILQRawHead *)(head))->tqh_first) +#define QTAILQ_RAW_LAST(head) (((QTAILQRawHead *)(head))->tqh_last) /* * Offsets of layout of a tail queue element. @@ -479,9 +463,10 @@ struct DUMB_Q { * Raw access of elements of a tail entry */ #define QTAILQ_RAW_NEXT(elm, entry) \ - (*field_at_offset(elm, entry + QTAILQ_NEXT_OFFSET, void **)) + ((field_at_offset(elm, entry, QTAILQRawEntry *)->tqe_next)) #define QTAILQ_RAW_PREV(elm, entry) \ - (*field_at_offset(elm, entry + QTAILQ_PREV_OFFSET, void ***)) + (field_at_offset(elm, entry, QTAILQRawEntry *)->tqe_prev) + /* * Tail queue tranversal using pointer arithmetic. */