From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 4BB735A026D for ; Sun, 7 Jan 2024 06:23:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1704605028; bh=mjWsShOjBt5HylsGttqA2XRaCVO9HK0vFYuVPK0k7mk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZjlKFd9MxIh3b1JygXC2Mxk2ly0s4PBHDRky5ErEW6PNEBNg8cMlD7TC8O+TB3d/F zGGnWEn+T7vGRxTkTE8WZLhE9drRDUtdiO/AxSTD0wo0gEG0UXnJyyo8oaS58hmhEr Rrtm7lqhhWy9NZ1s2TSv+DJPHqaZgqpFcGs5EBnMq/h/jSUlsrBHdjpjIMsx7sje1v igPqLnVQaqn25m+hSQIrCTmX6kTUeoZKmCiyYr6iHxL8xDW0QrGTwEIH759q7q725I jUDVh+BEwRu3f70zkR22FJml9euxGV44vcTsOen5DKg3tetDnbWIWtoMfEOHTbuA2l uq+1FhCfAZxsg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4T75Fw00MFz4wdD; Sun, 7 Jan 2024 16:23:47 +1100 (AEDT) Date: Sun, 7 Jan 2024 16:23:42 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v3 10/13] flow: Move flow_count from context structure to a global Message-ID: References: <20231221061549.976358-1-david@gibson.dropbear.id.au> <20231221061549.976358-11-david@gibson.dropbear.id.au> <20231228192459.312cc508@elisabeth> <20240102191335.413b2b04@elisabeth> <20240103080834.24fa0a7a@elisabeth> <20240105085513.5eadf3fc@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="gBPMkZLSmJopw/Xh" Content-Disposition: inline In-Reply-To: <20240105085513.5eadf3fc@elisabeth> Message-ID-Hash: 3WJUF4LDTZHZIYGOHZTM62PDSEM3DJSJ X-Message-ID-Hash: 3WJUF4LDTZHZIYGOHZTM62PDSEM3DJSJ X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --gBPMkZLSmJopw/Xh Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 05, 2024 at 08:55:13AM +0100, Stefano Brivio wrote: > On Thu, 4 Jan 2024 20:51:19 +1100 > David Gibson wrote: >=20 > > On Wed, Jan 03, 2024 at 08:08:34AM +0100, Stefano Brivio wrote: > > > On Wed, 3 Jan 2024 14:54:27 +1100 > > > David Gibson wrote: > > > =20 > > > > I'm not sure where to get the actual text of the standards =20 > > >=20 > > > Let me answer this first: one (the?) trick is to use so-called final > > > drafts, which are made freely available (same as working drafts) by t= he > > > Working Group. > > >=20 > > > Those are not the same as the standards, but differences from the fin= al > > > draft are also published... and they are usually not substantial. > > >=20 > > > This is _very_ informative: > > > https://stackoverflow.com/questions/81656/where-do-i-find-the-curre= nt-c-or-c-standard-documents =20 > >=20 > > Ah, thanks. > >=20 > > > Wikipedia also has the links, by the way. Anyway, in practice: > > >=20 > > > - C11: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf > > > - C99: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf > > > - C89: > > > https://web.archive.org/web/20200909074736if_/https://www.pdf-archi= ve.com/2014/10/02/ansi-iso-9899-1990-1/ansi-iso-9899-1990-1.pdf > > > =20 > > > > On Tue, Jan 02, 2024 at 07:13:35PM +0100, Stefano Brivio wrote: =20 > > > > > On Sun, 31 Dec 2023 16:58:39 +1100 > > > > > David Gibson wrote: > > > > > =20 > > > > > > On Thu, Dec 28, 2023 at 07:25:18PM +0100, Stefano Brivio wrote:= =20 > > > > > > > On Thu, 21 Dec 2023 17:15:46 +1100 > > > > > > > David Gibson wrote: > > > > > > > =20 > > > > > > > > In general, the passt code is a bit haphazard about what's = a true global > > > > > > > > variable and what's in the quasi-global 'context structure'= =2E The > > > > > > > > flow_count field is one such example: it's in the context s= tructure, > > > > > > > > although it's really part of the same data structure as flo= wtab[], which > > > > > > > > is a genuine global. =20 > > > > > > >=20 > > > > > > > Well, the reason is that flow_tab[FLOW_MAX] might be problema= tically > > > > > > > too big to live on the stack, unlike flow_count. > > > > > > >=20 > > > > > > > But anyway, as far as thoughts of multithreading are concerne= d, both > > > > > > > should probably be global. And sure, it's more consistent thi= s way. > > > > > > > =20 > > > > > > > > Move flow_count to be a regular global to match. For now i= t needs to be > > > > > > > > public, rather than static, but we expect to be able to cha= nge that in > > > > > > > > future. =20 > > > > > > >=20 > > > > > > > If it's not static, it should be initialised, and that's not = done here. =20 > > > > > >=20 > > > > > > Uh... what? "static" here is meaning module-global rather than > > > > > > global-global, which has no bearing on initialisation. AFAIK g= lobals > > > > > > are zero-initialised whether they're static or not. =20 > > > > >=20 > > > > > ...and to my utter surprise, I just discovered that if you talk C= 11, > > > > > you're right. From the N1570 draft (ISO/IEC 9899:201x), Section 6= =2E7.9 > > > > > "Initialization", clause 10: > > > > >=20 > > > > > If an object that has automatic storage duration is not initial= ized > > > > > explicitly, its value is indeterminate. If an object that has s= tatic > > > > > or thread storage duration is not initialized explicitly, then: > > > > >=20 > > > > > [...] > > > > >=20 > > > > > =E2=80=94 if it has arithmetic type, it is initialized to (posi= tive or > > > > > unsigned) zero; > > > > >=20 > > > > > And 'flow_count' has thread storage duration. =20 > > > >=20 > > > > No.. I don't think it does. AFAICT only thread-local variables have > > > > thread storage duration. As a global flow_count will have static > > > > storage duration, even without the static keyword. =20 > > >=20 > > > So, C11 defines static storage duration here: > > >=20 > > > 6.2.4 Storage durations of objects > > >=20 > > > [...] > > >=20 > > > 3 An object whose identifier is declared without the storage-class > > > specifier _Thread_local, and either with external or internal linka= ge > > > or with the storage-class specifier static, has static storage > > > duration. Its lifetime is the entire execution of the program and i= ts > > > stored value is initialized only once, prior to program startup. > > >=20 > > > do we have any linkage here? I would have said no -- but, going back > > > to C99 for this, "6.2.2 Linkages of identifiers": > > >=20 > > > 5 [...] If the declaration of an identifier for an object has file > > > scope and no storage-class specifier, its linkage is external. > > >=20 > > > which supports your paragraph below. =20 > >=20 > > Right. > >=20 > > > By the way, C11 now says: > > >=20 > > > 6.11.2 Linkages of identifiers > > >=20 > > > 1 Declaring an identifier with internal linkage at file scope witho= ut > > > the static storage-class specifier is an obsolescent feature =20 > >=20 > > Ok. I'm not even sure how you would do that. >=20 > By doing what I *thought* you were doing (see below): "int x" at file > scope (outside functions), no static, no extern declaration, nothing. Oh, ok. Even without that, I think the behaviour has to be the same. Plain "int x" at file scope is a public variable, and a linked module could "extern" it, even if that extern isn't visible while we're compiling this module. > > > > > In C99, however (draft > > > > > N1256), Section 6.7.8 "Initialization", clause 10: > > > > >=20 > > > > > If an object that has automatic storage duration is not initial= ized > > > > > explicitly, its value is indeterminate. If an object that has s= tatic > > > > > storage duration is not initialized explicitly, then: > > > > >=20 > > > > > [...] > > > > >=20 > > > > > note the missing "or thread storage duration". > > > > >=20 > > > > > C89, the one I was actually basing my observation on, says, at 3.= 5.7 > > > > > "Initialization": > > > > >=20 > > > > > If an object that has static storage duration is not initialized > > > > > explicitly, it is initialized implicitly as if every member tha= t has > > > > > arithmetic type were assigned 0 and every member that has point= er type > > > > > were assigned a null pointer constant. If an object that has > > > > > automatic storage duration is not initialized explicitly, its v= alue is > > > > > indeterminate. > > > > >=20 > > > > > so... um. We won't go back to C99. But to me, and maybe others, n= ot > > > > > having a "=3D 0;" for a "global" means pretty much that we don't = rely on > > > > > any particular initial value. =20 > > > >=20 > > > > Again, I'm pretty sure that's not true, even for C99 and C89. AIUI, > > > > 'static' locals and *all* globals have "static storage diration". > > > >=20 > > > > I'm not sure where to get the actual text of the standards but see = for > > > > example > > > >=20 > > > > https://en.cppreference.com/w/c/language/static_storage_duration > > > >=20 > > > > Here 'flow_count' has external linkage, thus satisfying the conditi= ons > > > > for static storage duration. =20 > > >=20 > > > Right. Well, for C99 and C11 at least. For C89 things are slightly > > > different: > > >=20 > > > 6.1.2.4 Storage durations of objects > > >=20 > > > [...] > > >=20 > > > An object whose identifier is declared with external or internal > > > linkage. or with the storage-class specifier static has static stor= age > > > duration. > > >=20 > > > [...] > > >=20 > > > An object whose identifier is declared with no linkage and without = the > > > storage-class specifier static has automatic storage duration. > > >=20 > > > You might say it has external linkage. But it was not *declared with* > > > external linkage -- it just happens to have it (C89 and C99 don't > > > differ here). =20 > >=20 > > Hrm. We do have: > > extern unsigned flow_first_free; > > in flow_table.h. Does that cound as declaring with external linkage? >=20 > Gosh, sorry... yes, it also counts as me completely missing it. >=20 > > > > Fwiw, I'm pretty sure the kernel has relied on zero-initialization = of > > > > non-static globals for many years. =20 > > >=20 > > > True, and the opposite is even considered as a style issue since 2007, > > > commit f0a594c1c74f ("update checkpatch.pl to version 0.08"). I also > > > found a discussion similar to this one: > > > https://lore.kernel.org/all/20201102184147.GA42288@localhost/#r > > >=20 > > > Anyway... a couple of years before that, it must have been a gcc vers= ion > > > in the late 2.x, I actually hit an issue with it. Was it a compiler > > > issue, or the correct interpretation of C89? Or maybe something on the > > > lines of: > > > https://www.thegoodpenguin.co.uk/blog/u-boot-relocation-bss-hang/ = =20 > >=20 > > If it was an embedded setup, that last one is certainly possible. > > Zeroing the BSS is typically the loader's job, and I've certainly seen > > loader implementations - particularly in embedded firmware - that got > > this wrong. >=20 > Embedded setup, yes, but in a Linux kernel (early 2.4.x). No 'extern' > there, though. Right. Depending on platform, the kernel sometimes has a loader for a later stage so does need to clear BSS. Or it might need to as a workaround for a broken firmware loader. I'm pretty sure I've also seem Linux bugs on some embedded platforms that involved failing to clear the BSS. --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --gBPMkZLSmJopw/Xh Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmWaNV0ACgkQzQJF27ox 2GddvA//WWfNa5azD5/4vXOyIov2WK8hYpBZvDNmhun89LoRRVzNd6oqYs0s2s6Q XGX1hq3rriYyvhRuvFrKjPXeOrnGy2Is0rLxaFLy0PR21F9JRPqHwIwUXpFU/SCk gfOtOq0pc+WCIEG1ZgBUBQ8u+wwGC0gNIVc5lYUyXoDHaYT46rZvIhLr2FvbUfVt xXHUCVyl+9lm8WvfxZ6siWG3sBBhZ2+EjjZSOcVrM1AfwpehPVDwhlpXtE9LtNFR nArCOc9Mwmopa8euDL6M9sNuuj/CgeCJJa2F8JLt96BCbdcZtXYJKv+KkGzUM3K2 AgOWBfny2/GAHZWiOWHx/qzGol/PgJ4Xv9aPzD4MluNup+TTnXTsTWuY7EadylmU NH92f9k7LZVugfo9We9D35AFdApeQxku3olYi5y3cjy+B3Xmk8dJBCAAE7tKEgW2 9D/6oBFav1bvzVCLlvNQj9jWwOFFMibPnNQ0hHkZSBEQIANWU+YmgbYfyVQVbF+K drZPQLpQ9qRjKElwlcTkD2Jg1GQI2IstKI0kbOvtZNcAk5uPcXlY7fUovIKFs9u9 AZzzC8pbX6fgIi6gq3ROOCrqR7tY3p73LpoAfUCYuJKv+bW4bWPLiDAY8VWM0uyV tg/31eYzze2dWo91nlXE3E6CSxtKMb9BA/aHekQSG65YU7hD6RA= =uIaa -----END PGP SIGNATURE----- --gBPMkZLSmJopw/Xh--