Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Mar 2005 16:55:25 +0300
From:      dima <_pppp@mail.ru>
To:        Gleb Smirnoff <glebius@FreeBSD.org>
Cc:        ru@FreeBSD.org
Subject:   Re[2]: Giant-free polling [PATCH]
Message-ID:  <E1D9kbt-000FAj-00._pppp-mail-ru@f22.mail.ru>
In-Reply-To: <20050311110234.GA87255@cell.sick.ru>

next in thread | previous in thread | raw e-mail | index | archive | help

------T4Mc1hoV-B6SDJqxFbvhAdRDo:1110549325
Content-Type: text/plain; charset=koi8-r
Content-Transfer-Encoding: 8bit

>   Collegues,
> 
> On Tue, Mar 01, 2005 at 04:29:49PM -0800, Luigi Rizzo wrote:
> L> [cc-ing net@freebsd.org to get more opinions]
> 
> this good, that you have CC'ed net@, otherwise we would continue
> working in parallel without collaboration.

It's a pity you didn't read the complete thread,
thus the original version of my patch isn't valid anymore.

> 
> Here is attached patch made in a collaboration by ru, pjd and me.

I thought about using list also, but considered it to bring
too much overhead to the code. The original idea of handling arrays
seems to be very elegant.

> 
> We use separate mutex for polling, and we drop it before calling the
> poll handler to avoid LOR and contention on this mutex.

The recent version of the patch uses sx lock to protect pr[] and
the array of per-interface mutexes iface_locks[].
So, all CPUs can poll different interfaces at the same time now.
See the complete thread for details.

> 
> We have definite evidence that now idle_poll and ISR poll can run
> in parallel: if we remove PRF_RUNNING flag check, we got panics
> because poll handlers of many drivers (e.g. if_em) are not reentrable.
> 
> I think this patch is a step forward in direction of parallel polling
> on SMP, since we now have two polling instances (ISR + idle) working
> in parallel.

I also mentioned that poll_idle() isn't called from anywhere in the kernel.
Thus we have only 2 possible sources for polling: hardclock (per-CPU) and traps.
The polling code in trap handler should also be changed a bit to check for
the trap's source.

I attach the most recent version of the patch.
The only difference is locking in ether_poll_register() suggested by Luigi.

> 
> -- 
> Totus tuus, Glebius.
> GLEBIUS-RIPN GLEB-RIPE


------T4Mc1hoV-B6SDJqxFbvhAdRDo:1110549325
Content-Type: application/octet-stream; name="kern_poll.patch"
Content-Disposition: attachment; filename="kern_poll.patch"
Content-Transfer-Encoding: base64

LS0tIG9yaWcva2Vybl9wb2xsLmMJVGh1IEZlYiAxNyAxNzoxMTowNSAyMDA1CisrKyBrZXJuX3Bv
bGwuYwlGcmkgTWFyICA0IDE3OjAzOjMzIDIwMDUKQEAgLTQxLDEyICs0MSwxNyBAQAogI2luY2x1
ZGUgPHN5cy9yZXNvdXJjZXZhci5oPgogI2luY2x1ZGUgPHN5cy9rdGhyZWFkLmg+CiAKKyNpbmNs
dWRlIDxzeXMvbG9jay5oPgkJCS8qIGZvciBzeCg5KQkJCSovCisjaW5jbHVkZSA8c3lzL3N4Lmg+
CisKICNpZmRlZiBTTVAKICNpZm5kZWYgQ09NUElMSU5HX0xJTlQKICNlcnJvciBERVZJQ0VfUE9M
TElORyBpcyBub3QgY29tcGF0aWJsZSB3aXRoIFNNUAogI2VuZGlmCiAjZW5kaWYKIAorc3RydWN0
IHN4IHBvbGxpbmdfbG9jazsKKwogc3RhdGljIHZvaWQgbmV0aXNyX3BvbGwodm9pZCk7CQkvKiB0
aGUgdHdvIG5ldGlzciBoYW5kbGVycyAgICAgICovCiBzdGF0aWMgdm9pZCBuZXRpc3JfcG9sbG1v
cmUodm9pZCk7CiAKQEAgLTE4Miw2ICsxODcsNyBAQAogfTsKIAogc3RhdGljIHN0cnVjdCBwb2xs
cmVjIHByW1BPTExfTElTVF9MRU5dOworc3RydWN0IG10eCBpZmFjZV9sb2Nrc1tQT0xMX0xJU1Rf
TEVOXTsKIAogc3RhdGljIHZvaWQKIGluaXRfZGV2aWNlX3BvbGwodm9pZCkKQEAgLTE4OSw2ICsx
OTUsNyBAQAogCiAJbmV0aXNyX3JlZ2lzdGVyKE5FVElTUl9QT0xMLCAobmV0aXNyX3QgKiluZXRp
c3JfcG9sbCwgTlVMTCwgMCk7CiAJbmV0aXNyX3JlZ2lzdGVyKE5FVElTUl9QT0xMTU9SRSwgKG5l
dGlzcl90ICopbmV0aXNyX3BvbG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QpOworCXN4X3h1bmxvY2so
ICZwb2xsaW5nX2xvY2sgKTsKIAlyZXR1cm4gMTsKIH0KIApAQCAtNTAxLDEwICs1MzIsMTAgQEAK
IAlmb3IgKDs7KSB7CiAJCWlmIChwb2xsX2luX2lkbGVfbG9vcCAmJiBwb2xsX2hhbmRsZXJzID4g
MCkgewogCQkJaWRsZXBvbGxfc2xlZXBpbmcgPSAwOwotCQkJbXR4X2xvY2soJkdpYW50KTsKKwkJ
CS8qIG10eF9sb2NrKCZHaWFudCk7ICovCiAJCQlldGhlcl9wb2xsKHBvbGxfZWFjaF9idXJzdCk7
Ci0JCQltdHhfdW5sb2NrKCZHaWFudCk7Ci0JCQltdHhfYXNzZXJ0KCZHaWFudCwgTUFfTk9UT1dO
RUQpOworCQkJLyogbXR4X3VubG9jaygmR2lhbnQpOworCQkJbXR4X2Fzc2VydCgmR2lhbnQsIE1B
X05PVE9XTkVEKTsgKi8KIAkJCW10eF9sb2NrX3NwaW4oJnNjaGVkX2xvY2spOwogCQkJbWlfc3dp
dGNoKFNXX1ZPTCwgTlVMTCk7CiAJCQltdHhfdW5sb2NrX3NwaW4oJnNjaGVkX2xvY2spOwo=

------T4Mc1hoV-B6SDJqxFbvhAdRDo:1110549325--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E1D9kbt-000FAj-00._pppp-mail-ru>