From patchwork Tue Sep 20 02:31:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongli Zhang X-Patchwork-Id: 9340871 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 C77F76022E for ; Tue, 20 Sep 2016 02:34:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B586129B90 for ; Tue, 20 Sep 2016 02:34:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A85AE29B92; Tue, 20 Sep 2016 02:34:26 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 181AA29B90 for ; Tue, 20 Sep 2016 02:34:26 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bmArG-0004PR-Ok; Tue, 20 Sep 2016 02:32:30 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bmArG-0004PF-4S for xen-devel@lists.xen.org; Tue, 20 Sep 2016 02:32:30 +0000 Received: from [85.158.139.211] by server-2.bemta-5.messagelabs.com id 37/54-03032-DBF90E75; Tue, 20 Sep 2016 02:32:29 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrMLMWRWlGSWpSXmKPExsUyZ7p8oO6e+Q/ CDZo+m1gs+biYxYHR4+ju30wBjFGsmXlJ+RUJrBm3t89nKmhUrDhx9BJbA+MkqS5GLg4hgclM EttWrWaDcL4xSvw+sYIJwtnIKDGxbSY7hNPNKLFw70Mgh5ODTUBHYtqBUywgtoiAtMS1z5cZQ YqYBbqYJF7c2wLUzsEhLBAuMeGUPojJIqAqsfNvEEg5r4CbxLvXy8FaJQTkJE4em8wKYRtLtL +9yDaBkWcBI8MqRvXi1KKy1CJdC72kosz0jJLcxMwcXUMDU73c1OLixPTUnMSkYr3k/NxNjED PMwDBDsaDzc6HGCU5mJREeeX4HoQL8SXlp1RmJBZnxBeV5qQWH2KU4eBQkuANnweUEyxKTU+t SMvMAYYgTFqCg0dJhNcBJM1bXJCYW5yZDpE6xagoJc7rDZIQAElklObBtcHC/hKjrJQwLyPQI UI8BalFuZklqPKvGMU5GJWEeVNBpvBk5pXATX8FtJgJaDFjz32QxSWJCCmpBsbttcuWLvjALS N2cK7P1/wfoalBTDqvpj48p3Xl1b6fpqkTrBK1X+8+83DzeoPrwZblDl85TW0Vuf3zV3m8C9u dY3xffcb6pWqTKhWzumS3bswujp6p23m97fT6A7e5f8R12hssd794ZrpQhqY5W6/pQo2PqqJT Qps2fTia/FD9lMuaO75/tN2VWIozEg21mIuKEwGEAzPBdgIAAA== X-Env-Sender: dongli.zhang@oracle.com X-Msg-Ref: server-13.tower-206.messagelabs.com!1474338747!44777607!1 X-Originating-IP: [156.151.31.81] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTU2LjE1MS4zMS44MSA9PiAyODgzMzk=\n X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 34355 invoked from network); 20 Sep 2016 02:32:28 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-13.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 20 Sep 2016 02:32:28 -0000 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u8K2WGHa027726 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Sep 2016 02:32:16 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id u8K2WEu9000381 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 20 Sep 2016 02:32:14 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u8K2WBhD017477; Tue, 20 Sep 2016 02:32:12 GMT Received: from linux.cn.oracle.com (/10.182.70.252) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 19 Sep 2016 19:32:11 -0700 From: Dongli Zhang To: xen-devel@lists.xen.org Date: Tue, 20 Sep 2016 10:31:03 +0800 Message-Id: <1474338664-5054-1-git-send-email-dongli.zhang@oracle.com> X-Mailer: git-send-email 1.9.1 X-Source-IP: aserv0022.oracle.com [141.146.126.234] Cc: sstabellini@kernel.org, wei.liu2@citrix.com, George.Dunlap@eu.citrix.com, jinsong.liu@alibaba-inc.com, dario.faggioli@citrix.com, ian.jackson@eu.citrix.com, tim@xen.org, jbeulich@suse.com, andrew.cooper3@citrix.com Subject: [Xen-devel] [PATCH v6 1/2] xen: replace tlbflush check and operation with inline functions X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch cleaned up the code by replacing complicated tlbflush check and operation with inline functions. We should use those inline functions to avoid the complicated tlbflush check and tlbflush operations when implementing TODOs left in commit a902c12ee45fc9389eb8fe54eeddaf267a555c58 (More efficient TLB-flush filtering in alloc_heap_pages()). "#include " is removed from xen/arch/x86/acpi/suspend.c to avoid the compiling error after we include "" to xen/include/xen/mm.h. Signed-off-by: Dongli Zhang Acked-by: Jan Beulich Acked-by: George Dunlap Reviewed-by: Dario Faggioli --- Changed since v5: * Move the if() and its body of tlbflush check into inline function. Changed since v4: * Wrap the filtered tlbflush mask operation as inline function (suggested by Jan). * Remove asm/flushtlb.h from suspend.c to avoid compiling error. Changed since v3: * Wrap the complicated tlbflush condition check as inline function (suggested by Dario). --- xen/arch/x86/acpi/suspend.c | 1 - xen/common/page_alloc.c | 19 ++----------------- xen/include/xen/mm.h | 29 +++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/xen/arch/x86/acpi/suspend.c b/xen/arch/x86/acpi/suspend.c index 1d8344c..d5c67ee 100644 --- a/xen/arch/x86/acpi/suspend.c +++ b/xen/arch/x86/acpi/suspend.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 18ff6cf..d7ca3a0 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -827,14 +827,7 @@ static struct page_info *alloc_heap_pages( BUG_ON(pg[i].count_info != PGC_state_free); pg[i].count_info = PGC_state_inuse; - if ( pg[i].u.free.need_tlbflush && - (pg[i].tlbflush_timestamp <= tlbflush_current_time()) && - (!need_tlbflush || - (pg[i].tlbflush_timestamp > tlbflush_timestamp)) ) - { - need_tlbflush = 1; - tlbflush_timestamp = pg[i].tlbflush_timestamp; - } + accumulate_tlbflush(&need_tlbflush, &pg[i], &tlbflush_timestamp); /* Initialise fields which have other uses for free pages. */ pg[i].u.inuse.type_info = 0; @@ -849,15 +842,7 @@ static struct page_info *alloc_heap_pages( spin_unlock(&heap_lock); if ( need_tlbflush ) - { - cpumask_t mask = cpu_online_map; - tlbflush_filter(mask, tlbflush_timestamp); - if ( !cpumask_empty(&mask) ) - { - perfc_incr(need_flush_tlb_flush); - flush_tlb_mask(&mask); - } - } + filtered_flush_tlb_mask(tlbflush_timestamp); return pg; } diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index f470e49..50db01d 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -51,6 +51,7 @@ #include #include #include +#include #include TYPE_SAFE(unsigned long, mfn); @@ -567,4 +568,32 @@ int prepare_ring_for_helper(struct domain *d, unsigned long gmfn, struct page_info **_page, void **_va); void destroy_ring_for_helper(void **_va, struct page_info *page); +#include + +static inline void accumulate_tlbflush(bool *need_tlbflush, + const struct page_info *page, + uint32_t *tlbflush_timestamp) +{ + if ( page->u.free.need_tlbflush && + page->tlbflush_timestamp <= tlbflush_current_time() && + (!*need_tlbflush || + page->tlbflush_timestamp > *tlbflush_timestamp) ) + { + *need_tlbflush = true; + *tlbflush_timestamp = page->tlbflush_timestamp; + } +} + +static inline void filtered_flush_tlb_mask(uint32_t tlbflush_timestamp) +{ + cpumask_t mask = cpu_online_map; + + tlbflush_filter(mask, tlbflush_timestamp); + if ( !cpumask_empty(&mask) ) + { + perfc_incr(need_flush_tlb_flush); + flush_tlb_mask(&mask); + } +} + #endif /* __XEN_MM_H__ */