Date: Thu, 5 Mar 2009 10:04:36 -0500 From: John Baldwin <jhb@freebsd.org> To: Kip Macy <kmacy@freebsd.org> Cc: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: Re: svn commit: r189374 - user/kmacy/HEAD_fast_net_merge/sys/netinet Message-ID: <200903051004.36626.jhb@freebsd.org> In-Reply-To: <3c1674c90903041520o145b0c42uc1dd2d41870432e6@mail.gmail.com> References: <200903042122.n24LMdO3053650@svn.freebsd.org> <200903041759.31535.jhb@freebsd.org> <3c1674c90903041520o145b0c42uc1dd2d41870432e6@mail.gmail.com>
index | next in thread | previous in thread | raw e-mail
On Wednesday 04 March 2009 6:20:55 pm Kip Macy wrote:
> Do we have any mechanism for handling sparse cpuids?
> If so I can do modulo the number of active cpus and then taking that
> value as an index. If not its a bit of an academic observation.
>
> -Kip
The rest of the kernel is careful to handle sparse cpuids already. You can
use CPU_ABSENT() to see if a CPU is present or not. You cound pre-populate a
table during boot if you wished by doing something like:
int active_cpus[MAXCPU];
sysinit_foo()
{
int i, cpu;
i = 0;
for (cpu = 0; cpu <= mp_maxid; cpu++) {
if (CPU_ABSENT(cpu)
continue;
active_cpus[i] = cpu;
i++;
}
KASSERT(i == mp_ncpu, ("bad juju"));
}
Then you could use (active_cpus[flowid & mp_ncpu]) as a CPU. Eventually when
we support removing and adding CPUs at runtime (or disabling/enabling them at
runtime) there will be eventhandlers that you can hook to adjust your
active_cpus array.
> On Wed, Mar 4, 2009 at 2:59 PM, John Baldwin <jhb@freebsd.org> wrote:
> > On Wednesday 04 March 2009 4:22:39 pm Kip Macy wrote:
> >> Author: kmacy
> >> Date: Wed Mar 4 21:22:39 2009
> >> New Revision: 189374
> >> URL: http://svn.freebsd.org/changeset/base/189374
> >>
> >> Log:
> >> Use per-cpu callouts for tcp_timer
> >> 186694, 187660
> >>
> >> 186694:
> >> - convert tcp_timer_activate over to using
> >> per-cpu callouts
> >> - don't acquire the tcbinfo lock exclusively
> >> in tcp_timer_rexmt unless needed for tcp_drop
> >>
> >> 187660:
> >> - mp_maxid may not be valid ensure that we
> >> re-schedule on cpuid less than or equal to
> >> the current one for tcp callouts
> >>
> >> Modified:
> >> user/kmacy/HEAD_fast_net_merge/sys/netinet/tcp_timer.c
> >>
> >> Modified: user/kmacy/HEAD_fast_net_merge/sys/netinet/tcp_timer.c
> >>
> >
==============================================================================
> >> --- user/kmacy/HEAD_fast_net_merge/sys/netinet/tcp_timer.c Wed Mar 4
> > 21:04:52 2009 (r189373)
> >> +++ user/kmacy/HEAD_fast_net_merge/sys/netinet/tcp_timer.c Wed Mar 4
> > 21:22:39 2009 (r189374)
> >> @@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$");
> >> #include <sys/mbuf.h>
> >> #include <sys/mutex.h>
> >> #include <sys/protosw.h>
> >> +#include <sys/smp.h>
> >> #include <sys/socket.h>
> >> #include <sys/socketvar.h>
> >> #include <sys/sysctl.h>
> >> @@ -118,6 +119,8 @@ int tcp_maxpersistidle;
> >> /* max idle time in persist */
> >> int tcp_maxidle;
> >>
> >> +#define INP_CPU(inp) min(curcpu, ((inp)->inp_flowid % mp_maxid))
> >
> > This is not really safe. CPU ID's may be sparse. The only guarantees you
> > have are that 0 is the boot CPU, and that all valid CPU IDs are in the
range
> > [0 .. mp_maxid] (inclusive). Thus, you could have a system that only has
> > CPUs 0 and 3 and if you are on CPU 3 and flowid is 5, then this will
choose
> > min(3, 5 % 3) == min(3, 2) == 2 which is an invalid CPU.
> >
> > --
> > John Baldwin
> >
>
--
John Baldwin
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200903051004.36626.jhb>
