From patchwork Tue Nov 6 12:20:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 10670247 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F3E8C13A4 for ; Tue, 6 Nov 2018 12:22:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4C3D2A3D1 for ; Tue, 6 Nov 2018 12:22:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D84722A3F6; Tue, 6 Nov 2018 12:22:05 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable 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 86EE02A3D1 for ; Tue, 6 Nov 2018 12:22:05 +0000 (UTC) Received: from localhost ([::1]:40666 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gK0Mu-0003mh-LN for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Nov 2018 07:22:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43319) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gK0LZ-0002mR-4Z for qemu-devel@nongnu.org; Tue, 06 Nov 2018 07:20:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gK0LV-0001c1-Dj for qemu-devel@nongnu.org; Tue, 06 Nov 2018 07:20:41 -0500 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]:36290) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gK0LT-0001XW-MH for qemu-devel@nongnu.org; Tue, 06 Nov 2018 07:20:36 -0500 Received: by mail-pl1-x62a.google.com with SMTP id w24-v6so6133996plq.3 for ; Tue, 06 Nov 2018 04:20:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ooj19jq71V11Zi5HetnC26XyEjIGc265F+GyfKemw0k=; b=VnFMgKBUsa4on0BHyqEovAtqDClHAXiNxQOlGREIZerxMNRyNJE9HmP/DLPL/m0uQh 03VhhneOhjOJqxmzjOWjWHbGwJdC3pmkYXnvGp6ZUsBQo/+QwsGNVwqCEC7OooWaRRyp EciBvD8wBhBwJl+3nXemaUb02IZBuof/YF01fAMxV5m/CyiwRQGxkXwdPWZ5B+FxRHKK seRqQmne4RNdCXncY1vF1i04MMizOCbaGoXE0CCXTUbIiDE05p8V1+IMdWNd9Kmh900i UhisQdlNCu6eb72FSf0/0QodWoFdkr0VOqONg9txpBlrazIHqDEPYU1il1nZCFeeo93g YsHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ooj19jq71V11Zi5HetnC26XyEjIGc265F+GyfKemw0k=; b=EWZBGDGSwXpmOl+iwSsjUktHFAf+1HFE5VTcdRoube4xl0dl1rIH4b2u+3YuHQt96x jZhHTy2ZALz1VTO6ZjBsjbCi9kMWt8NibxmSbljQ9SSW32SKhlisNcC26aXnSFfJjNE0 JBsP9TVQr8pCXm9iNy+zYZbpnU5jB/ySelX479BIDa/8ShNbLne/S67hEhOBkKhGUB68 7z0FE8pCn+R6xEOISDskJZt1ayCfvY0NfaMCQL15ziYF8uYgX1osP7pTlhm6YVtgBf0q b8jQE0jKicuSiXwOU4RII3E3j8prJniTsZEwFDZTRXxN/g3udcnSQKHbsbs+tuRie2/r 6DSA== X-Gm-Message-State: AGRZ1gIo6nzaIMKRl6ItgXFEtN8KdM3Jf6OtfH0buVhdezK9cuFk9sh1 buN6/oNXpYbjlTaQXZZcxGQ= X-Google-Smtp-Source: AJdET5fn1lq59ABvFFYNJd8j9P1HL3vs3SuWe/s4OkVlVdmL6RBn4k/YI/EjQAcdeR2JVINfKRmLew== X-Received: by 2002:a17:902:64c1:: with SMTP id y1-v6mr26240201pli.210.1541506833189; Tue, 06 Nov 2018 04:20:33 -0800 (PST) Received: from localhost.localdomain ([203.205.141.52]) by smtp.gmail.com with ESMTPSA id v4-v6sm19050021pff.9.2018.11.06.04.20.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Nov 2018 04:20:32 -0800 (PST) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Tue, 6 Nov 2018 20:20:20 +0800 Message-Id: <20181106122025.3487-1-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.5 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::62a Subject: [Qemu-devel] [PATCH v2 0/5] migration: improve multithreads 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: kvm@vger.kernel.org, quintela@redhat.com, Xiao Guangrong , qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com, wei.w.wang@intel.com, cota@braap.org, jiang.biao2@zte.com.cn Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Xiao Guangrong Changelog in v2: These changes are based on Paolo's suggestion: 1) rename the lockless multithreads model to threaded workqueue 2) hugely improve the internal design, that make all the request be a large array, properly partition it, assign requests to threads respectively and use bitmaps to sync up threads and the submitter, after that ptr_ring and spinlock are dropped 3) introduce event wait for the submitter These changes are based on Emilio's review: 4) make more detailed description for threaded workqueue 5) add a benchmark for threaded workqueue The previous version can be found at https://marc.info/?l=kvm&m=153968821910007&w=2 There's the simple performance measurement comparing these two versions, the environment is the same as we listed in the previous version. Use 8 threads to compress the data in the source QEMU - with compress-wait-thread = off total time busy-ratio -------------------------------------------------- v1 125066 0.38 v2 120444 0.35 - with compress-wait-thread = on total time busy-ratio -------------------------------------------------- v1 164426 0 v2 142609 0 The v2 win slightly. Xiao Guangrong (5): bitops: introduce change_bit_atomic util: introduce threaded workqueue migration: use threaded workqueue for compression migration: use threaded workqueue for decompression tests: add threaded-workqueue-bench include/qemu/bitops.h | 13 + include/qemu/threaded-workqueue.h | 94 +++++++ migration/ram.c | 538 ++++++++++++++------------------------ tests/Makefile.include | 5 +- tests/threaded-workqueue-bench.c | 256 ++++++++++++++++++ util/Makefile.objs | 1 + util/threaded-workqueue.c | 466 +++++++++++++++++++++++++++++++++ 7 files changed, 1030 insertions(+), 343 deletions(-) create mode 100644 include/qemu/threaded-workqueue.h create mode 100644 tests/threaded-workqueue-bench.c create mode 100644 util/threaded-workqueue.c