Author: adrian
Date: Tue May 27 08:06:20 2014
New Revision: 266737
URL: http://svnweb.freebsd.org/changeset/base/266737

Log:
  The users of RSS shouldn't be directly concerned about hash -> CPU ID
  mappings.  Instead, they should be first mapping to an RSS bucket and
  then querying the RSS bucket -> CPU ID mapping to figure out the target
  CPU.
  
  When (if?) RSS rebalancing is implemented or some other (non round-robin)
  distribution of work from buckets to CPU IDs, various bits of code - both
  userland and kernel - will need to know how this mapping works.
  
  So, to support this:
  
  * Add a new function rss_m2bucket() - this maps an mbuf to a given bucket.
    Anything which is currently doing hash -> CPU work may instead wish to
    do hash -> bucket, and then query the bucket->cpuid map for which
    CPU it belongs on.  Or, map it to a bucket, then re-pin that bucket ->
    CPU during a rebalance operation.
  
  * For userland applications which wish to exploit affinity to RSS buckets,
    the bucket -> CPU ID mapping is now available via a sysctl.
    net.inet.rss.bucket_mapping lists the bucket to CPU ID mapping via
    a list of bucket:cpu pairs.

Modified:
  head/sys/netinet/in_rss.c
  head/sys/netinet/in_rss.h

Modified: head/sys/netinet/in_rss.c
==============================================================================
--- head/sys/netinet/in_rss.c   Tue May 27 07:16:43 2014        (r266736)
+++ head/sys/netinet/in_rss.c   Tue May 27 08:06:20 2014        (r266737)
@@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/kernel.h>
 #include <sys/smp.h>
 #include <sys/sysctl.h>
+#include <sys/sbuf.h>
 
 #include <net/if.h>
 #include <net/if_var.h>
@@ -425,6 +426,24 @@ rss_hash2cpuid(uint32_t hash_val, uint32
 }
 
 /*
+ * Query the RSS bucket associated with the given hash value and
+ * type.
+ */
+int
+rss_hash2bucket(uint32_t hash_val, uint32_t hash_type, uint32_t *bucket_id)
+{
+
+       switch (hash_type) {
+       case M_HASHTYPE_RSS_IPV4:
+       case M_HASHTYPE_RSS_TCP_IPV4:
+               *bucket_id = rss_getbucket(hash_val);
+               return (0);
+       default:
+               return (-1);
+       }
+}
+
+/*
  * netisr CPU affinity lookup routine for use by protocols.
  */
 struct mbuf *
@@ -436,6 +455,16 @@ rss_m2cpuid(struct mbuf *m, uintptr_t so
        return (m);
 }
 
+int
+rss_m2bucket(struct mbuf *m, uint32_t *bucket_id)
+{
+
+       M_ASSERTPKTHDR(m);
+
+       return(rss_hash2bucket(m->m_pkthdr.flowid, M_HASHTYPE_GET(m),
+           bucket_id));
+}
+
 /*
  * Query the RSS hash algorithm.
  */
@@ -512,3 +541,31 @@ sysctl_rss_key(SYSCTL_HANDLER_ARGS)
 SYSCTL_PROC(_net_inet_rss, OID_AUTO, key,
     CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0, sysctl_rss_key,
     "", "RSS keying material");
+
+static int
+sysctl_rss_bucket_mapping(SYSCTL_HANDLER_ARGS)
+{
+       struct sbuf *sb;
+       int error;
+       int i;
+
+       error = 0;
+       error = sysctl_wire_old_buffer(req, 0);
+       if (error != 0)
+               return (error);
+       sb = sbuf_new_for_sysctl(NULL, NULL, 512, req);
+       if (sb == NULL)
+               return (ENOMEM);
+       for (i = 0; i < rss_buckets; i++) {
+               sbuf_printf(sb, "%s%d:%d", i == 0 ? "" : " ",
+                   i,
+                   rss_getcpu(i));
+       }
+       error = sbuf_finish(sb);
+       sbuf_delete(sb);
+
+       return (error);
+}
+SYSCTL_PROC(_net_inet_rss, OID_AUTO, bucket_mapping,
+    CTLTYPE_STRING | CTLFLAG_RD, NULL, 0,
+    sysctl_rss_bucket_mapping, "", "RSS bucket -> CPU mapping");

Modified: head/sys/netinet/in_rss.h
==============================================================================
--- head/sys/netinet/in_rss.h   Tue May 27 07:16:43 2014        (r266736)
+++ head/sys/netinet/in_rss.h   Tue May 27 08:06:20 2014        (r266737)
@@ -91,5 +91,8 @@ uint32_t      rss_hash_ip6_2tuple(struct in6_
  */
 struct mbuf    *rss_m2cpuid(struct mbuf *m, uintptr_t source, u_int *cpuid);
 u_int          rss_hash2cpuid(uint32_t hash_val, uint32_t hash_type);
+int            rss_hash2bucket(uint32_t hash_val, uint32_t hash_type,
+               uint32_t *bucket_id);
+int            rss_m2bucket(struct mbuf *m, uint32_t *bucket_id);
 
 #endif /* !_NETINET_IN_RSS_H_ */
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to