msgport: Add putport_oncpu; helps scheduling netisr locally for spin port
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Wed, 30 Oct 2013 13:50:55 +0000 (21:50 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Wed, 30 Oct 2013 14:19:23 +0000 (22:19 +0800)
commitc068fb592b4c6a5bb7a2d94a0c7869ee2a18b773
treee0fab4569242b532e5850d5dfbd7cd1096603b34
parent62734c132ceb7ad7474119de2557a523a12c5ffe
msgport: Add putport_oncpu; helps scheduling netisr locally for spin port

Background:
High rate (actually same rate as polling(4)) IPIs on random CPUs are
observed when polling(4) is enabled and there is virtually no network
activity.

After polling(4) activities are traced using ktr(9), it turns out that the
high rate IPIs are actually from the wakeup() on netisr's msgport.  Since
the sleep queue cpumask is indexed by the hash of ident, there are chances
that the netisr's msgport ident has the same hash value as other idents
that certain threads on other CPUs are waiting on.  If this ever happens
(well, it does happen), the netisr's msgport wakeup will trigger "wakeup"
IPIs to other CPUs.  However, these "wakeup" IPIs are actually useless,
since only netisr will wait on its msgport.

putport_oncpu() msgport method is added to call wakeup_mycpu() for spin
msgport, if we know that this port is only accessed by one thread on the
current CPU, e.g. polling(4).  This is also the case for other network
code, e.g.  syncache timeout, TCP timeout, fastforward flow cache timeout
etc.  However, these network code's running rate is too low to unveil the
extra "wakeup" IPIs problem.  lwkt_sendmsg_oncpu() is added as wrapper to
putport_oncpu() msgport method.

Currently, only polling(4) is using lwkt_sendmsg_oncpu().  Others will
be converted soon.
sys/kern/lwkt_msgport.c
sys/kern/lwkt_thread.c
sys/net/if.c
sys/net/if_poll.c
sys/net/netisr.c
sys/sys/msgport.h
sys/sys/msgport2.h
sys/sys/thread.h