Author: rrs
Date: Fri Feb  4 13:50:30 2011
New Revision: 218269
URL: http://svn.freebsd.org/changeset/base/218269

Log:
  1) Fix cpu mapping per JB's suggestions
  2) Fix it so INIT's don't always end up on CPU0
  
  MFC after:    3 months

Modified:
  head/sys/netinet/sctp_input.c
  head/sys/netinet/sctp_pcb.c

Modified: head/sys/netinet/sctp_input.c
==============================================================================
--- head/sys/netinet/sctp_input.c       Fri Feb  4 13:40:02 2011        
(r218268)
+++ head/sys/netinet/sctp_input.c       Fri Feb  4 13:50:30 2011        
(r218269)
@@ -1,8 +1,7 @@
 /*-
  * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
- * Copyright (c) 2008-2011, by Randall Stewart, r...@lakerest.net and
- *                          Michael Tuexen, tue...@fh-muenster.de
- *                          All rights reserved.
+ * Copyright (c) 2008-2011, by Randall Stewart. All rights reserved.
+ * Copyright (c) 2008-2011, by Michael Tuexen. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -5928,6 +5927,10 @@ bad:
        return;
 }
 
+#if defined(__FreeBSD__) && defined(SCTP_MCORE_INPUT) && defined(SMP)
+extern int *sctp_cpuarry;
+
+#endif
 
 void
 sctp_input(struct mbuf *m, int off)
@@ -5937,8 +5940,9 @@ sctp_input(struct mbuf *m, int off)
        struct sctphdr *sh;
        int offset;
        int cpu_to_use;
+       uint32_t tag;
 
-       if (mp_maxid > 1) {
+       if (mp_ncpus > 1) {
                ip = mtod(m, struct ip *);
                offset = off + sizeof(*sh);
                if (SCTP_BUF_LEN(m) < offset) {
@@ -5949,7 +5953,19 @@ sctp_input(struct mbuf *m, int off)
                        ip = mtod(m, struct ip *);
                }
                sh = (struct sctphdr *)((caddr_t)ip + off);
-               cpu_to_use = ntohl(sh->v_tag) % mp_maxid;
+               if (sh->v_tag) {
+                       tag = htonl(sh->v_tag);
+               } else {
+                       /*
+                        * Distribute new INIT's to all CPU's don't just
+                        * pick on 0.
+                        */
+                       struct timeval tv;
+
+                       (void)SCTP_GETTIME_TIMEVAL(&tv);
+                       tag = (uint32_t) tv.tv_usec;
+               }
+               cpu_to_use = sctp_cpuarry[tag % mp_ncpus];
                sctp_queue_to_mcore(m, off, cpu_to_use);
                return;
        }

Modified: head/sys/netinet/sctp_pcb.c
==============================================================================
--- head/sys/netinet/sctp_pcb.c Fri Feb  4 13:40:02 2011        (r218268)
+++ head/sys/netinet/sctp_pcb.c Fri Feb  4 13:50:30 2011        (r218269)
@@ -1,8 +1,7 @@
 /*-
  * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
- * Copyright (c) 2008-2011, by Randall Stewart, r...@lakerest.net and
- *                          Michael Tuexen, tue...@fh-muenster.de
- *                          All rights reserved.
+ * Copyright (c) 2008-2011, by Randall Stewart. All rights reserved.
+ * Copyright (c) 2008-2011, by Michael Tuexen. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -5446,7 +5445,7 @@ static int sctp_scale_up_for_address = S
 
 #if defined(__FreeBSD__) && defined(SCTP_MCORE_INPUT) && defined(SMP)
 struct sctp_mcore_ctrl *sctp_mcore_workers = NULL;
-
+int *sctp_cpuarry = NULL;
 void
 sctp_queue_to_mcore(struct mbuf *m, int off, int cpu_to_use)
 {
@@ -5548,32 +5547,48 @@ skip_sleep:
 static void
 sctp_startup_mcore_threads(void)
 {
-       int i;
+       int i, cpu;
 
-       if (mp_maxid == 1)
+       if (mp_ncpus == 1)
                return;
 
+       if (sctp_mcore_workers != NULL) {
+               /*
+                * Already been here in some previous vnet?
+                */
+               return;
+       }
        SCTP_MALLOC(sctp_mcore_workers, struct sctp_mcore_ctrl *,
-           (mp_maxid * sizeof(struct sctp_mcore_ctrl)),
+           ((mp_maxid + 1) * sizeof(struct sctp_mcore_ctrl)),
            SCTP_M_MCORE);
        if (sctp_mcore_workers == NULL) {
                /* TSNH I hope */
                return;
        }
-       memset(sctp_mcore_workers, 0, (mp_maxid *
+       memset(sctp_mcore_workers, 0, ((mp_maxid + 1) *
            sizeof(struct sctp_mcore_ctrl)));
        /* Init the structures */
-       for (i = 0; i < mp_maxid; i++) {
+       for (i = 0; i <= mp_maxid; i++) {
                TAILQ_INIT(&sctp_mcore_workers[i].que);
                SCTP_MCORE_LOCK_INIT(&sctp_mcore_workers[i]);
                SCTP_MCORE_QLOCK_INIT(&sctp_mcore_workers[i]);
                sctp_mcore_workers[i].cpuid = i;
        }
+       if (sctp_cpuarry == NULL) {
+               SCTP_MALLOC(sctp_cpuarry, int *,
+                   (mp_ncpus * sizeof(int)),
+                   SCTP_M_MCORE);
+               i = 0;
+               CPU_FOREACH(cpu) {
+                       sctp_cpuarry[i] = cpu;
+                       i++;
+               }
+       }
        /* Now start them all */
-       for (i = 0; i < mp_maxid; i++) {
+       CPU_FOREACH(cpu) {
                (void)kproc_create(sctp_mcore_thread,
-                   (void *)&sctp_mcore_workers[i],
-                   &sctp_mcore_workers[i].thread_proc,
+                   (void *)&sctp_mcore_workers[cpu],
+                   &sctp_mcore_workers[cpu].thread_proc,
                    RFPROC,
                    SCTP_KTHREAD_PAGES,
                    SCTP_MCORE_NAME);
@@ -5605,12 +5620,12 @@ sctp_pcb_init()
 #endif
 #if defined(__FreeBSD__) && defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
        SCTP_MALLOC(SCTP_BASE_STATS, struct sctpstat *,
-           (mp_maxid * sizeof(struct sctpstat)),
+           ((mp_maxid + 1) * sizeof(struct sctpstat)),
            SCTP_M_MCORE);
 #endif
        (void)SCTP_GETTIME_TIMEVAL(&tv);
 #if defined(__FreeBSD__) && defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
-       bzero(SCTP_BASE_STATS, (sizeof(struct sctpstat) * mp_maxid));
+       bzero(SCTP_BASE_STATS, (sizeof(struct sctpstat) * (mp_maxid + 1)));
        SCTP_BASE_STATS[PCPU_GET(cpuid)].sctps_discontinuitytime.tv_sec = 
(uint32_t) tv.tv_sec;
        SCTP_BASE_STATS[PCPU_GET(cpuid)].sctps_discontinuitytime.tv_usec = 
(uint32_t) tv.tv_usec;
 #else
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to