[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] linux-2.6.18: widen use of (and introduce further) MULTI_* helpers


  • To: "xen-devel" <xen-devel@xxxxxxxxxxxxx>
  • From: "Jan Beulich" <JBeulich@xxxxxxxx>
  • Date: Thu, 31 May 2012 16:04:06 +0100
  • Delivery-date: Thu, 31 May 2012 15:04:17 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xen.org>

This includes folding an MMU update and a grant table operation into a
multicall in gnttab_copy_grant_page()

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- a/drivers/xen/core/gnttab.c
+++ b/drivers/xen/core/gnttab.c
@@ -607,13 +607,9 @@ static void gnttab_page_free(struct page
 int gnttab_copy_grant_page(grant_ref_t ref, struct page **pagep)
 {
        struct gnttab_unmap_and_replace unmap;
-       mmu_update_t mmu;
-       struct page *page;
-       struct page *new_page;
-       void *new_addr;
-       void *addr;
-       paddr_t pfn;
-       maddr_t mfn;
+       struct page *page, *new_page;
+       void *addr, *new_addr;
+       unsigned long pfn;
        maddr_t new_mfn;
        int err;
 
@@ -631,7 +627,6 @@ int gnttab_copy_grant_page(grant_ref_t r
        copy_page(new_addr, addr);
 
        pfn = page_to_pfn(page);
-       mfn = pfn_to_mfn(pfn);
        new_mfn = virt_to_mfn(new_addr);
 
        write_seqlock(&gnttab_dma_lock);
@@ -647,27 +642,32 @@ int gnttab_copy_grant_page(grant_ref_t r
                goto out;
        }
 
-       if (!xen_feature(XENFEAT_auto_translated_physmap))
-               set_phys_to_machine(pfn, new_mfn);
-
        gnttab_set_replace_op(&unmap, (unsigned long)addr,
                              (unsigned long)new_addr, ref);
 
-       err = HYPERVISOR_grant_table_op(GNTTABOP_unmap_and_replace,
-                                       &unmap, 1);
-       BUG_ON(err);
-       BUG_ON(unmap.status != GNTST_okay);
-
-       write_sequnlock(&gnttab_dma_lock);
-
        if (!xen_feature(XENFEAT_auto_translated_physmap)) {
+               multicall_entry_t mc[2];
+               mmu_update_t mmu;
+
+               set_phys_to_machine(pfn, new_mfn);
                set_phys_to_machine(page_to_pfn(new_page), INVALID_P2M_ENTRY);
 
+               MULTI_grant_table_op(&mc[0], GNTTABOP_unmap_and_replace,
+                                    &unmap, 1);
+
                mmu.ptr = (new_mfn << PAGE_SHIFT) | MMU_MACHPHYS_UPDATE;
                mmu.val = pfn;
-               err = HYPERVISOR_mmu_update(&mmu, 1, NULL, DOMID_SELF);
-               BUG_ON(err);
-       }
+               MULTI_mmu_update(&mc[1], &mmu, 1, NULL, DOMID_SELF);
+
+               err = HYPERVISOR_multicall_check(mc, 2, NULL);
+       } else
+               err = HYPERVISOR_grant_table_op(GNTTABOP_unmap_and_replace,
+                                               &unmap, 1);
+
+       BUG_ON(err);
+       BUG_ON(unmap.status != GNTST_okay);
+
+       write_sequnlock(&gnttab_dma_lock);
 
        new_page->mapping = page->mapping;
        new_page->index = page->index;
--- a/drivers/xen/netback/netback.c
+++ b/drivers/xen/netback/netback.c
@@ -644,29 +644,21 @@ static void net_rx_action(unsigned long 
                BUG_ON(mcl[-1].op != __HYPERVISOR_update_va_mapping);
                mcl[-1].args[MULTI_UVMFLAGS_INDEX] = UVMF_TLB_FLUSH|UVMF_ALL;
 
-               mcl->op = __HYPERVISOR_mmu_update;
-               mcl->args[0] = (unsigned long)rx_mmu;
-               mcl->args[1] = npo.mmu_prod;
-               mcl->args[2] = 0;
-               mcl->args[3] = DOMID_SELF;
+               MULTI_mmu_update(mcl, rx_mmu, npo.mmu_prod, 0, DOMID_SELF);
        }
 
        if (npo.trans_prod) {
                BUG_ON(npo.trans_prod > ARRAY_SIZE(grant_trans_op));
-               mcl = npo.mcl + npo.mcl_prod++;
-               mcl->op = __HYPERVISOR_grant_table_op;
-               mcl->args[0] = GNTTABOP_transfer;
-               mcl->args[1] = (unsigned long)grant_trans_op;
-               mcl->args[2] = npo.trans_prod;
+               MULTI_grant_table_op(npo.mcl + npo.mcl_prod++,
+                                    GNTTABOP_transfer, grant_trans_op,
+                                    npo.trans_prod);
        }
 
        if (npo.copy_prod) {
                BUG_ON(npo.copy_prod > ARRAY_SIZE(grant_copy_op));
-               mcl = npo.mcl + npo.mcl_prod++;
-               mcl->op = __HYPERVISOR_grant_table_op;
-               mcl->args[0] = GNTTABOP_copy;
-               mcl->args[1] = (unsigned long)grant_copy_op;
-               mcl->args[2] = npo.copy_prod;
+               MULTI_grant_table_op(npo.mcl + npo.mcl_prod++,
+                                    GNTTABOP_copy, grant_copy_op,
+                                    npo.copy_prod);
        }
 
        /* Nothing to do? */
--- a/drivers/xen/netfront/netfront.c
+++ b/drivers/xen/netfront/netfront.c
@@ -841,9 +841,9 @@ no_skb:
                                UVMF_TLB_FLUSH|UVMF_ALL;
 
                        /* Give away a batch of pages. */
-                       np->rx_mcl[i].op = __HYPERVISOR_memory_op;
-                       np->rx_mcl[i].args[0] = XENMEM_decrease_reservation;
-                       np->rx_mcl[i].args[1] = (unsigned long)&reservation;
+                       MULTI_memory_op(np->rx_mcl + i,
+                                       XENMEM_decrease_reservation,
+                                       &reservation);
 
                        /* Zap PTEs and give away pages in one big
                         * multicall. */
@@ -1326,7 +1326,6 @@ static int netif_poll(struct net_device 
        struct netif_rx_response *rx = &rinfo.rx;
        struct netif_extra_info *extras = rinfo.extras;
        RING_IDX i, rp;
-       struct multicall_entry *mcl;
        int work_done, budget, more_to_do = 1, accel_more_to_do = 1;
        struct sk_buff_head rxq;
        struct sk_buff_head errq;
@@ -1453,12 +1452,9 @@ err:     
 
                /* Do all the remapping work and M2P updates. */
                if (!xen_feature(XENFEAT_auto_translated_physmap)) {
-                       mcl = np->rx_mcl + pages_flipped;
-                       mcl->op = __HYPERVISOR_mmu_update;
-                       mcl->args[0] = (unsigned long)np->rx_mmu;
-                       mcl->args[1] = pages_flipped;
-                       mcl->args[2] = 0;
-                       mcl->args[3] = DOMID_SELF;
+                       MULTI_mmu_update(np->rx_mcl + pages_flipped,
+                                        np->rx_mmu, pages_flipped, 0,
+                                        DOMID_SELF);
                        err = HYPERVISOR_multicall_check(np->rx_mcl,
                                                         pages_flipped + 1,
                                                         NULL);
@@ -1623,14 +1619,10 @@ static void netif_release_rx_bufs_flip(s
 
                if (!xen_feature(XENFEAT_auto_translated_physmap)) {
                        /* Do all the remapping work and M2P updates. */
-                       mcl->op = __HYPERVISOR_mmu_update;
-                       mcl->args[0] = (unsigned long)np->rx_mmu;
-                       mcl->args[1] = mmu - np->rx_mmu;
-                       mcl->args[2] = 0;
-                       mcl->args[3] = DOMID_SELF;
-                       mcl++;
+                       MULTI_mmu_update(mcl, np->rx_mmu, mmu - np->rx_mmu,
+                                        0, DOMID_SELF);
                        rc = HYPERVISOR_multicall_check(
-                               np->rx_mcl, mcl - np->rx_mcl, NULL);
+                               np->rx_mcl, mcl + 1 - np->rx_mcl, NULL);
                        BUG_ON(rc);
                }
        }
--- a/include/asm-i386/mach-xen/asm/hypervisor.h
+++ b/include/asm-i386/mach-xen/asm/hypervisor.h
@@ -243,6 +243,26 @@ MULTI_update_va_mapping(
 }
 
 static inline void
+MULTI_mmu_update(multicall_entry_t *mcl, mmu_update_t *req,
+                unsigned int count, unsigned int *success_count,
+                domid_t domid)
+{
+    mcl->op = __HYPERVISOR_mmu_update;
+    mcl->args[0] = (unsigned long)req;
+    mcl->args[1] = count;
+    mcl->args[2] = (unsigned long)success_count;
+    mcl->args[3] = domid;
+}
+
+static inline void
+MULTI_memory_op(multicall_entry_t *mcl, unsigned int cmd, void *arg)
+{
+       mcl->op = __HYPERVISOR_memory_op;
+       mcl->args[0] = cmd;
+       mcl->args[1] = (unsigned long)arg;
+}
+
+static inline void
 MULTI_grant_table_op(multicall_entry_t *mcl, unsigned int cmd,
                     void *uop, unsigned int count)
 {
@@ -255,8 +275,15 @@ MULTI_grant_table_op(multicall_entry_t *
 #else /* !defined(CONFIG_XEN) */
 
 /* Multicalls not supported for HVM guests. */
-#define MULTI_update_va_mapping(a,b,c,d) ((void)0)
-#define MULTI_grant_table_op(a,b,c,d) ((void)0)
+static inline void MULTI_bug(multicall_entry_t *mcl, ...)
+{
+       BUG_ON(mcl);
+}
+
+#define MULTI_update_va_mapping        MULTI_bug
+#define MULTI_mmu_update       MULTI_bug
+#define MULTI_memory_op                MULTI_bug
+#define MULTI_grant_table_op   MULTI_bug
 
 #endif
 


Attachment: xen-multi-ops.patch
Description: Text document

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.