From owner-freebsd-current@FreeBSD.ORG Tue Feb 19 18:51:42 2013 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 14F1D379 for ; Tue, 19 Feb 2013 18:51:42 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) by mx1.freebsd.org (Postfix) with ESMTP id 52E13E14 for ; Tue, 19 Feb 2013 18:51:41 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.6/8.14.6) with ESMTP id r1JIpUNn025696; Tue, 19 Feb 2013 20:51:30 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.7.4 kib.kiev.ua r1JIpUNn025696 Received: (from kostik@localhost) by tom.home (8.14.6/8.14.6/Submit) id r1JIpTiJ025695; Tue, 19 Feb 2013 20:51:29 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 19 Feb 2013 20:51:29 +0200 From: Konstantin Belousov To: Svatopluk Kraus Subject: Re: [patch] i386 pmap sysmaps_pcpu[] atomic access Message-ID: <20130219185129.GC2598@kib.kiev.ua> References: <20130218150809.GG2598@kib.kiev.ua> <20130218170957.GJ2598@kib.kiev.ua> <20130218203630.GO2598@kib.kiev.ua> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="6dGMKdYe2Ft9UtxE" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on tom.home Cc: freebsd-current@freebsd.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Feb 2013 18:51:42 -0000 --6dGMKdYe2Ft9UtxE Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Feb 18, 2013 at 11:18:16PM +0100, Svatopluk Kraus wrote: > On Mon, Feb 18, 2013 at 9:36 PM, Konstantin Belousov > wrote: > Well, I'm taking a part on porting FreeBSD to ARM11mpcore. UP case was > simple. SMP case is more complex and rather new for me. Recently, I > was solving a problem with PCPU stuff. For example, PCPU_GET is > implemented by one instruction on i386 arch. So, a need of atomicity > with respect to interrupts can be overlooked. On load-store archs, the > implementation which works in SMP case is not so simple. And what > works in UP case (single PCPU), not works in SMP case. Believe me, > mysterious and sporadic 'mutex not owned' assertions and others ones > caused by curthreads mess, it takes a while ... Note that PCPU_GET() is not needed to be atomic. The reason is that the code which uses its result would not be atomic (single-instruction or whatever, = see below). Thus, either the preemption should not matter since the action with the per-cpu data is advisory, as is in the case of i386 pmap you noted. or some external measures should be applied in advance to the containing region (which you proposed, by bracing with sched_pin()). Also, note that it is not interrupts but preemption which is concern. >=20 > After this, I took a look at how PCPU stuff is used in whole kernel > and found out mentioned here i386 pmap issue. So, my concern is > following: >=20 > 1. to verify my newly gained ideas how per CPU data should be used, > 2. to decide how to change my implementation of pmap on ARM11mpcore, > as it's based on i386 pmap, > 3. to make FreeBSD code better. >=20 > In the meanwhile, it looks that using data dedicated to one CPU on > another one is OK. However, I can't agree. At least, without comments, > it is misleading for anyone new in FreeBSD and makes code misty. >=20 > > Both threads in your description make useful progress, and computation > > proceeds correctly. >=20 > I thought, there is only one thread in my example. One thread running > on CPU1, but holding sysmaps dedicated to CPU0 instead of holding > sysmaps dedicated to CPU1. So, any thread running on CPU0 must wait > because the thread running on CPU1 is a thief. Futhermore, the idea > that a thread on CPU1 should hold data for CPU1 is not valid. So, > either some comment is missing in the code that it's OK or the using > of PCPU_GET(cpuid) is unneeded and some kind of free sysmaps list can > be used and it will serve better. What is wrong on almost all architectures except x86 is PCPU_ADD(), which is usually supposed by the MD code to be atomic in regard to _both_ interrupts and preemption. I said almost all, but in fact I am not aware of any architecture except x86 where it is right. And, RISCs with the load-link and store-conditional (ll/sc) primitives are well capable of doing the PCPU_ADD() correctly. You could look at the projects/counters branch, where single-instruction increment is used on x86 for dynamic per-cpu counters, and critical_enter() for other architectures. I might do some work for other arches, but the counters are correct but slower that it could be, on !x86. --6dGMKdYe2Ft9UtxE Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (FreeBSD) iQIcBAEBAgAGBQJRI8mxAAoJEJDCuSvBvK1B5koQAKa2FXuEJYXOp77FYXQqME1r b73a6IqZFz68RHwKVe66CLMqCWt3Ej+r8EoqQKbl9N3DbvEWWkNrJthSAEYZqT6q jcfMoJTI4qNhTPtuuRnY4mJYyFNAe74/aabIRSEJyzEGEPekJ2M7+K06drRPtD5Y PkqKavZwtPOgAgRDnEuMZcztNjsQbWFkAP15tpTfMyhFeDhpLZy+FFJ1Rus8aFKK lwqWXZK7+yBdNULi5XwgN3lb+Qu6e2thaDEh2psRKsfpwvrPc35jYlBftXQjYfUb rR5qDO6LgHxOEIpunAEo6CQsfH4LK69XhMeQgBELMRlNbkWcfyMr0+ussymvFm9X s6goFnlX9ajbEq/XkrlDDmkR5aKCVr8l6Y2j7o3zT6FESccBXMF4mLLo3KFnv0nM rAaonT+RIWzwXw6Y+zrY/rAjJ0pam6vxo5sazd3L9EEaiCfpCNmRNbmFr0k3ONP8 4PHPxVBrL3GCLG6uLeiWpTfw09S5UligzutcIf9C37QUPBAzTQNS52z9sgyR+F/E L78hp9TeWs89OHJKwKksYzgvT3c1huH4H97uKhv5U0jwt7cb+cmU+DCMNXT2CrCF qYttncg6WGpKn6wcrthZ5nTZBehw06ma1WFN5hjRJFNyGrLh5hNKSoUvHUOQFFjD wS47WRblh+H98bLPHECY =cqAF -----END PGP SIGNATURE----- --6dGMKdYe2Ft9UtxE--