From owner-svn-src-head@FreeBSD.ORG Fri Feb 4 13:50:31 2011 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1D0B5106564A; Fri, 4 Feb 2011 13:50:31 +0000 (UTC) (envelope-from rrs@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 007AB8FC0A; Fri, 4 Feb 2011 13:50:31 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p14DoU0D085532; Fri, 4 Feb 2011 13:50:30 GMT (envelope-from rrs@svn.freebsd.org) Received: (from rrs@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p14DoUIu085529; Fri, 4 Feb 2011 13:50:30 GMT (envelope-from rrs@svn.freebsd.org) Message-Id: <201102041350.p14DoUIu085529@svn.freebsd.org> From: Randall Stewart Date: Fri, 4 Feb 2011 13:50:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r218269 - head/sys/netinet X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Feb 2011 13:50:31 -0000 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, rrs@lakerest.net and - * Michael Tuexen, tuexen@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, rrs@lakerest.net and - * Michael Tuexen, tuexen@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