]> xenbits.xensource.com Git - people/ssmith/nc2-2.6.27.git/commitdiff
Pre-allocate a pool of grant references and pull from them, rather
authorSteven Smith <ssmith@weybridge.uk.xensource.com>
Wed, 24 Jun 2009 13:23:25 +0000 (14:23 +0100)
committerSteven Smith <ssmith@weybridge.uk.xensource.com>
Tue, 30 Jun 2009 12:02:15 +0000 (13:02 +0100)
than pulling from the main pool for every packet.

drivers/xen/core/gnttab.c
drivers/xen/netchannel2/rscb.c
drivers/xen/netchannel2/util.c
include/xen/gnttab.h

index 044a8761dbb9ce98f4fa1cde02ef0049e3fc62de..ba1433a5a395a8315ac26aed7b62f4a6f29ed839 100644 (file)
@@ -522,6 +522,41 @@ void gnttab_free_grant_references(grant_ref_t head)
 }
 EXPORT_SYMBOL_GPL(gnttab_free_grant_references);
 
+int gnttab_suballoc_grant_references(u16 count, grant_ref_t *old_head,
+                                     grant_ref_t *new_head)
+{
+        grant_ref_t cursor;
+        unsigned nr_allocated;
+
+        *new_head = cursor = *old_head;
+        if (cursor == GNTTAB_LIST_END)
+                return -ENOSPC;
+        nr_allocated = 1;
+        while (nr_allocated < count) {
+                cursor = gnttab_entry(cursor);
+                if (cursor == GNTTAB_LIST_END)
+                        return -ENOSPC;
+                nr_allocated++;
+        }
+        *old_head = gnttab_entry(cursor);
+        gnttab_entry(cursor) = GNTTAB_LIST_END;
+        return 0;
+}
+EXPORT_SYMBOL_GPL(gnttab_suballoc_grant_references);
+
+void gnttab_subfree_grant_references(grant_ref_t head, grant_ref_t *pool)
+{
+        grant_ref_t cursor;
+
+        for (cursor = head;
+             gnttab_entry(cursor) != GNTTAB_LIST_END;
+             cursor = gnttab_entry(cursor))
+                ;
+        gnttab_entry(cursor) = *pool;
+        *pool = head;
+}
+EXPORT_SYMBOL_GPL(gnttab_subfree_grant_references);
+
 int gnttab_alloc_grant_references(u16 count, grant_ref_t *head)
 {
        int h = get_free_entries(count);
index 038086c8f29ef1a7d435030a3b5011fde72da3c8..2130d3a233ed290022413b2081b6441e5a9805b1 100644 (file)
@@ -315,7 +315,9 @@ int prepare_xmit_allocate_grant(struct netchannel2_ring_pair *ncrp,
         }
 
         /* Grab the grant references. */
-        err = gnttab_alloc_grant_references(skb_co->nr_fragments, &gref_pool);
+        err = gnttab_suballoc_grant_references(skb_co->nr_fragments,
+                                               &ncrp->gref_pool,
+                                               &gref_pool);
         if (err < 0) {
                 release_txp_slot(ncrp, skb);
                 /* Leave skb_co->nr_fragments set, so that we don't
index edef7f6bb8acc9872bafe0b7286b487a2deebe6d..d6b985f36dd0b4117228940aaf9052fcb49fb3b2 100644 (file)
@@ -336,7 +336,7 @@ void release_tx_packet(struct netchannel2_ring_pair *ncrp,
                         while (!nc2_end_foreign_access_ref(gref, 1)) {
                                 cpu_relax();
                         }
-                        gnttab_free_grant_reference(gref);
+                        gnttab_release_grant_reference(&ncrp->gref_pool, gref);
                 }
         } else if (skb_co->type == NC2_PACKET_TYPE_receiver_map) {
                 while (1) {
@@ -348,11 +348,13 @@ void release_tx_packet(struct netchannel2_ring_pair *ncrp,
                         if (r == 0) {
                                 printk(KERN_WARNING "Failed to end remote access to packet memory.\n");
                         } else {
-                                gnttab_free_grant_reference(gref);
+                                gnttab_release_grant_reference(&ncrp->gref_pool,
+                                                               gref);
                         }
                 }
         } else if (skb_co->gref_pool != 0) {
-                gnttab_free_grant_references(skb_co->gref_pool);
+                gnttab_subfree_grant_references(skb_co->gref_pool,
+                                                &ncrp->gref_pool);
         }
 
         if (tp != NULL)
index a5277357e78f944524ed5d590c7332dfea882094..bb9f020a5ba4da6ae725f2e0a385150f931cc68f 100644 (file)
@@ -94,10 +94,15 @@ int gnttab_query_foreign_access(grant_ref_t ref);
  */
 int gnttab_alloc_grant_references(u16 count, grant_ref_t *pprivate_head);
 
+int gnttab_suballoc_grant_references(u16 count, grant_ref_t *old_head,
+                                     grant_ref_t *new_head);
+
 void gnttab_free_grant_reference(grant_ref_t ref);
 
 void gnttab_free_grant_references(grant_ref_t head);
 
+void gnttab_subfree_grant_references(grant_ref_t head, grant_ref_t *pool);
+
 int gnttab_empty_grant_references(const grant_ref_t *pprivate_head);
 
 int gnttab_claim_grant_reference(grant_ref_t *pprivate_head);