From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id EEC661F9FD for ; Sun, 7 Mar 2021 10:03:37 +0000 (UTC) Received: from localhost ([::1]:36378 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lIqG9-0003qU-5l for normalperson@yhbt.net; Sun, 07 Mar 2021 05:03:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51096) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lIqG6-0003qL-7T for bug-gnulib@gnu.org; Sun, 07 Mar 2021 05:03:34 -0500 Received: from mo4-p00-ob.smtp.rzone.de ([81.169.146.163]:24116) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lIqG2-0004YI-DE for bug-gnulib@gnu.org; Sun, 07 Mar 2021 05:03:33 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1615111408; cv=none; d=strato.com; s=strato-dkim-0002; b=MJmYNej4yzcML3uquM9lUksAV0AQcPJZV3e1oGk1Qw/S7VPSti07qTgEAM5flj+GsT mJcKxPmRflN73azim7kRn/yCMzcN8txl97+Rwir7wQqPu9pIJpZYeGjkdsYtK2onT3ry rjBVpXh3jAkty8pMHIqql0VChmFDyh5/uQx1GMncBZbyc2H2r702+jxkVMmGc9TU19pd ckRF082s3vpHwinYBWmiudHLmDKG9BuumjTfdLpW9XydBefWop69ZBtJ7RrhuPj9CjjG P//dYsEKpdBe9/3L0QhimxDuwvoNaIvjUDWQWbTtbrY4vqUs3Ti7UHStufGENpETLoBj VMww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1615111408; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=4InuWGsx6cEpaLAP1fl1fR84OULjChBlkDddXJuY8bc=; b=eeVd42uJzYUBK0XdYf+0wbiGGUvpIrLYMx/H85Zj0WeZRpXi/qEljXG7qfl+kefeMT 2+dLq6pDunjxY+mb1MfSv6oNBqc0czvWDFe/EP4qPPaC6pDPIkj7XdzYR55ybrojdFfx 7cwqUt6dCxqmfVfHOa3j3VTZTh2KGoJ4zTATr1+Cct16c2/Sjxw/vtshwKe2WpRGQO9Z aXHwfMQCdKiLOMpGVt2238zGgz8Y17ad1M8Sm7sOexjdfuM/tjZjBQ2U5gHkcCtwdxuD njtuf9BsCNXR/fAYywxc/hGI+3g1Bbr8GKx1Xk3JEO7EwiBsC9lXfJ4OS406iBdH9McH H23w== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1615111408; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=4InuWGsx6cEpaLAP1fl1fR84OULjChBlkDddXJuY8bc=; b=LnzXS+48rl6svEma0ZPiBv3lx8aF7hrjBc8MaO2An4e9SWaae8kPZMhrRPSBLDJOiZ 5dFD7dGHXDDskH1F+3eh3Ao//hxOFHZ20qScy9NyoSOWet8kJsLUbV8WQuhraH5Bsj4d 98QkfZ44t1/Zv6MxRSwN1BikSx9Wzr8Y+r1XlNB6AKJtHTQuKAi0Lf7I+Ri97IT08uxl HPYbKoROEKuLHycqyi5RaRzP2jaerS1tQmPorRitOxIJIAjrsZtz6Pwde50OibL10Ziv rhMo5rkg7cOpucivSjwI3c6EY6e91irWyFcvxWG/VYOwRZk52RltBMBqJ1Vx0Lclj3bW 206g== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOHqf3zZdW" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 47.20.3 DYNA|AUTH) with ESMTPSA id n0b11fx27A3RD1s (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve X9_62_prime256v1 with 256 ECDH bits, eq. 3072 bits RSA)) (Client did not present a certificate); Sun, 7 Mar 2021 11:03:27 +0100 (CET) From: Bruno Haible To: Paul Eggert Subject: Re: single-threaded optimizations Date: Sun, 07 Mar 2021 11:03:27 +0100 Message-ID: <2736735.YI3xTzsUAq@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-203-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: <2783771.9LmcWK8fO3@omega> References: <20210303002855.5819-1-eggert@cs.ucla.edu> <2783771.9LmcWK8fO3@omega> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart5441975.4gzixM8jqV" Content-Transfer-Encoding: 7Bit Received-SPF: none client-ip=81.169.146.163; envelope-from=bruno@clisp.org; helo=mo4-p00-ob.smtp.rzone.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bug-gnulib@gnu.org Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" This is a multi-part message in MIME format. --nextPart5441975.4gzixM8jqV Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" > > * We establish a new macro GNULIB_MBTOWC_SINGLE which means "assume that > > at most one thread invokes mbtowc-like functions". The mbtowc > > replacement uses this instead of using USE_UNLOCKED_IO. Tar can #define > > this new macro. > > I like this idea. The packages can then define or not define each such > macro individually. Implemented through the following series of patches. 2021-03-07 Bruno Haible Rename GNULIB_WCHAR_SINGLE to GNULIB_WCHAR_SINGLE_LOCALE. * lib/lc-charset-dispatch.c: Test GNULIB_WCHAR_SINGLE_LOCALE instead of GNULIB_WCHAR_SINGLE. * lib/wcwidth.c: Likewise. * tests/test-wcwidth.c: Likewise. * doc/multithread.texi: Document GNULIB_WCHAR_SINGLE_LOCALE instead of GNULIB_WCHAR_SINGLE. * NEWS: Document the change. 2021-03-06 Bruno Haible mbrtowc: Allow locking optimization independently of 'unlocked-io'. * lib/mbtowc-lock.h: Test GNULIB_MBRTOWC_SINGLE_THREAD instead of USE_UNLOCKED_IO. * doc/multithread.texi: Document GNULIB_MBRTOWC_SINGLE_THREAD. 2021-03-06 Bruno Haible regex: Allow locking optimization independently of 'unlocked-io'. * lib/regex_internal.h: Test GNULIB_REGEX_SINGLE_THREAD instead of USE_UNLOCKED_IO. * doc/multithread.texi: Document GNULIB_REGEX_SINGLE_THREAD. 2021-03-06 Bruno Haible exclude: Allow stdio optimization independently of 'unlocked-io'. * lib/exclude.c: Test GNULIB_EXCLUDE_SINGLE_THREAD instead of USE_UNLOCKED_IO. * modules/exclude (Depends-on): Add unlocked-io-internal. * doc/multithread.texi: Document GNULIB_EXCLUDE_SINGLE_THREAD. 2021-03-06 Bruno Haible readutmp: Optimize stdio accesses. * lib/readutmp.c: Include unlocked-io.h unconditionally. * modules/readutmp (Depends-on): Add unlocked-io-internal. 2021-03-06 Bruno Haible mountlist: Optimize stdio accesses. * lib/mountlist.c: Include unlocked-io.h unconditionally. * modules/mountlist (Depends-on): Add unlocked-io-internal. 2021-03-06 Bruno Haible getusershell: Optimize stdio accesses when possible. * lib/getusershell.c: Test GNULIB_GETUSERSHELL_SINGLE_THREAD instead of USE_UNLOCKED_IO. * modules/getusershell (Depends-on): Add unlocked-io-internal. * doc/multithread.texi: Document GNULIB_GETUSERSHELL_SINGLE_THREAD. 2021-03-06 Bruno Haible unlocked-io-internal: New module. * m4/unlocked-io.m4 (gl_FUNC_GLIBC_UNLOCKED_IO): Don't define USE_UNLOCKED_IO here. * modules/unlocked-io-internal: New file, based on modules/unlocked-io. * modules/unlocked-io (Description): Clarify. (Files, Depends-on): Just use the unlocked-io-internal module. (configure.ac): Define GNULIB_STDIO_SINGLE_THREAD and USE_UNLOCKED_IO here. * doc/multithread.texi: Clarify when the 'unlocked-io' module can be used. 2021-03-06 Bruno Haible posixtm: Remove unused includes. * lib/posixtm.c: Don't include , , unlocked-io.h. --nextPart5441975.4gzixM8jqV Content-Disposition: attachment; filename="0001-posixtm-Remove-unused-includes.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0001-posixtm-Remove-unused-includes.patch" >From 7ea7c3e27964aaf699ca737b11e2edea289f9ed2 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 7 Mar 2021 01:39:16 +0100 Subject: [PATCH 1/9] posixtm: Remove unused includes. * lib/posixtm.c: Don't include , , unlocked-io.h. --- ChangeLog | 5 +++++ lib/posixtm.c | 6 ------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5a100d7..cfa60e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2021-03-06 Bruno Haible + posixtm: Remove unused includes. + * lib/posixtm.c: Don't include , , unlocked-io.h. + +2021-03-06 Bruno Haible + dynarray: Add tests. * tests/test-dynarray.c: New file. * modules/dynarray-tests: New file. diff --git a/lib/posixtm.c b/lib/posixtm.c index dd89330..d142484 100644 --- a/lib/posixtm.c +++ b/lib/posixtm.c @@ -22,15 +22,9 @@ #include "posixtm.h" -#include #include -#include #include -#if USE_UNLOCKED_IO -# include "unlocked-io.h" -#endif - /* ISDIGIT differs from isdigit, as follows: - Its arg may be any int or unsigned int; it need not be an unsigned char or EOF. -- 2.7.4 --nextPart5441975.4gzixM8jqV Content-Disposition: attachment; filename="0002-unlocked-io-internal-New-module.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0002-unlocked-io-internal-New-module.patch" >From 212f0b69ab67a4d6230c2ab85e28c2f54b31060c Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 7 Mar 2021 01:58:10 +0100 Subject: [PATCH 2/9] unlocked-io-internal: New module. * m4/unlocked-io.m4 (gl_FUNC_GLIBC_UNLOCKED_IO): Don't define USE_UNLOCKED_IO here. * modules/unlocked-io-internal: New file, based on modules/unlocked-io. * modules/unlocked-io (Description): Clarify. (Files, Depends-on): Just use the unlocked-io-internal module. (configure.ac): Define GNULIB_STDIO_SINGLE_THREAD and USE_UNLOCKED_IO here. * doc/multithread.texi: Clarify when the 'unlocked-io' module can be used. --- ChangeLog | 13 +++++++++++++ doc/multithread.texi | 16 +++++++++++----- m4/unlocked-io.m4 | 7 +------ modules/unlocked-io | 19 ++++++++++++++----- modules/unlocked-io-internal | 24 ++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 16 deletions(-) create mode 100644 modules/unlocked-io-internal diff --git a/ChangeLog b/ChangeLog index cfa60e0..80d97a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2021-03-06 Bruno Haible + unlocked-io-internal: New module. + * m4/unlocked-io.m4 (gl_FUNC_GLIBC_UNLOCKED_IO): Don't define + USE_UNLOCKED_IO here. + * modules/unlocked-io-internal: New file, based on modules/unlocked-io. + * modules/unlocked-io (Description): Clarify. + (Files, Depends-on): Just use the unlocked-io-internal module. + (configure.ac): Define GNULIB_STDIO_SINGLE_THREAD and USE_UNLOCKED_IO + here. + * doc/multithread.texi: Clarify when the 'unlocked-io' module can be + used. + +2021-03-06 Bruno Haible + posixtm: Remove unused includes. * lib/posixtm.c: Don't include , , unlocked-io.h. diff --git a/doc/multithread.texi b/doc/multithread.texi index 9b1bc2e..7fe19a7 100644 --- a/doc/multithread.texi +++ b/doc/multithread.texi @@ -258,11 +258,17 @@ if (mt) gl_lock_lock (some_lock); if (mt) gl_lock_unlock (some_lock); @end smallexample @item -The @code{unlocked-io} module is applicable only if all the programs in your -package are single-threaded. It optimizes the operations on @code{FILE} -streams. You need extra code for this: include the @code{"unlocked-io.h"} -header file. Some Gnulib modules that do operations on @code{FILE} streams -have these preparations already included. +You may use the @code{unlocked-io} module if you want the @code{FILE} stream +functions @code{getc}, @code{putc}, etc.@: to use unlocked I/O if available, +throughout the package. Unlocked I/O can improve performance, sometimes +dramatically. But unlocked I/O is safe only in single-threaded programs, +as well as in multithreaded programs for which you can guarantee that +every @code{FILE} stream, including @code{stdin}, @code{stdout}, @code{stderr}, +is used only in a single thread. + +You need extra code for this optimization to be effective: include the +@code{"unlocked-io.h"} header file. Some Gnulib modules that do operations +on @code{FILE} streams have these preparations already included. @item You may define the C macro @code{GNULIB_WCHAR_SINGLE}, if all the programs in your package are single-threaded and won't change the locale after it has diff --git a/m4/unlocked-io.m4 b/m4/unlocked-io.m4 index a2dc8a1..b689020 100644 --- a/m4/unlocked-io.m4 +++ b/m4/unlocked-io.m4 @@ -1,4 +1,4 @@ -# unlocked-io.m4 serial 15 +# unlocked-io.m4 serial 16 # Copyright (C) 1998-2006, 2009-2021 Free Software Foundation, Inc. # @@ -16,11 +16,6 @@ dnl on Solaris 2.6). AC_DEFUN([gl_FUNC_GLIBC_UNLOCKED_IO], [ - AC_DEFINE([USE_UNLOCKED_IO], [1], - [Define to 1 if you want getc etc. to use unlocked I/O if available. - Unlocked I/O can improve performance in unithreaded apps, - but it is not safe for multithreaded apps.]) - dnl Persuade glibc and Solaris to declare dnl fgets_unlocked(), fputs_unlocked() etc. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) diff --git a/modules/unlocked-io b/modules/unlocked-io index 000fe32..2ed3417 100644 --- a/modules/unlocked-io +++ b/modules/unlocked-io @@ -1,15 +1,24 @@ Description: -Enable faster, non-thread-safe stdio functions if available. +Enable faster, non-thread-safe stdio functions if available, +globally throughout the package. Files: -lib/unlocked-io.h -m4/unlocked-io.m4 Depends-on: -extensions +unlocked-io-internal configure.ac: -gl_FUNC_GLIBC_UNLOCKED_IO +AC_DEFINE([GNULIB_STDIO_SINGLE_THREAD], [1], + [Define to 1 if you want the FILE stream functions getc, putc, etc. + to use unlocked I/O if available, throughout the package. + Unlocked I/O can improve performance, sometimes dramatically. + But unlocked I/O is safe only in single-threaded programs, + as well as in multithreaded programs for which you can guarantee that + every FILE stream, including stdin, stdout, stderr, is used only + in a single thread.]) + +AC_DEFINE([USE_UNLOCKED_IO], [GNULIB_STDIO_SINGLE_THREAD], + [An alias of GNULIB_STDIO_SINGLE_THREAD.]) Makefile.am: diff --git a/modules/unlocked-io-internal b/modules/unlocked-io-internal new file mode 100644 index 0000000..b78944c --- /dev/null +++ b/modules/unlocked-io-internal @@ -0,0 +1,24 @@ +Description: +Allow use of faster, non-thread-safe stdio functions if available, +in specific modules. + +Files: +lib/unlocked-io.h +m4/unlocked-io.m4 + +Depends-on: +extensions + +configure.ac: +gl_FUNC_GLIBC_UNLOCKED_IO + +Makefile.am: + +Include: +"unlocked-io.h" + +License: +GPL + +Maintainer: +Jim Meyering -- 2.7.4 --nextPart5441975.4gzixM8jqV Content-Disposition: attachment; filename="0003-getusershell-Optimize-stdio-accesses-when-possible.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0003-getusershell-Optimize-stdio-accesses-when-possible.patch" >From 92052c44910568ef6012584a344edcb736949d2c Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 7 Mar 2021 02:21:49 +0100 Subject: [PATCH 3/9] getusershell: Optimize stdio accesses when possible. * lib/getusershell.c: Test GNULIB_GETUSERSHELL_SINGLE_THREAD instead of USE_UNLOCKED_IO. * modules/getusershell (Depends-on): Add unlocked-io-internal. * doc/multithread.texi: Document GNULIB_GETUSERSHELL_SINGLE_THREAD. --- ChangeLog | 8 ++++++++ doc/multithread.texi | 4 ++++ lib/getusershell.c | 2 +- modules/getusershell | 5 +++-- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 80d97a0..d6e8d54 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2021-03-06 Bruno Haible + getusershell: Optimize stdio accesses when possible. + * lib/getusershell.c: Test GNULIB_GETUSERSHELL_SINGLE_THREAD instead of + USE_UNLOCKED_IO. + * modules/getusershell (Depends-on): Add unlocked-io-internal. + * doc/multithread.texi: Document GNULIB_GETUSERSHELL_SINGLE_THREAD. + +2021-03-06 Bruno Haible + unlocked-io-internal: New module. * m4/unlocked-io.m4 (gl_FUNC_GLIBC_UNLOCKED_IO): Don't define USE_UNLOCKED_IO here. diff --git a/doc/multithread.texi b/doc/multithread.texi index 7fe19a7..a63d3ee 100644 --- a/doc/multithread.texi +++ b/doc/multithread.texi @@ -274,4 +274,8 @@ You may define the C macro @code{GNULIB_WCHAR_SINGLE}, if all the programs in your package are single-threaded and won't change the locale after it has been initialized. This macro optimizes the functions @code{mbrtowc} and @code{wcwidth}. +@item +You may define the C macro @code{GNULIB_GETUSERSHELL_SINGLE_THREAD}, if all the +programs in your package invoke the functions @code{setusershell}, +@code{getusershell}, @code{endusershell} only from a single thread. @end itemize diff --git a/lib/getusershell.c b/lib/getusershell.c index 6ae9410..be8a068 100644 --- a/lib/getusershell.c +++ b/lib/getusershell.c @@ -39,7 +39,7 @@ #include "stdio--.h" #include "xalloc.h" -#if USE_UNLOCKED_IO +#if GNULIB_GETUSERSHELL_SINGLE_THREAD # include "unlocked-io.h" #endif diff --git a/modules/getusershell b/modules/getusershell index 26f99e5..ed2f30f 100644 --- a/modules/getusershell +++ b/modules/getusershell @@ -8,8 +8,9 @@ m4/getusershell.m4 Depends-on: unistd extensions -fopen-safer [test $HAVE_GETUSERSHELL = 0] -xalloc [test $HAVE_GETUSERSHELL = 0] +fopen-safer [test $HAVE_GETUSERSHELL = 0] +unlocked-io-internal [test $HAVE_GETUSERSHELL = 0] +xalloc [test $HAVE_GETUSERSHELL = 0] configure.ac: gl_FUNC_GETUSERSHELL -- 2.7.4 --nextPart5441975.4gzixM8jqV Content-Disposition: attachment; filename="0004-mountlist-Optimize-stdio-accesses.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0004-mountlist-Optimize-stdio-accesses.patch" >From 895c6f0664d19f754fe3905bae1bae83aee46bd0 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 7 Mar 2021 02:31:45 +0100 Subject: [PATCH 4/9] mountlist: Optimize stdio accesses. * lib/mountlist.c: Include unlocked-io.h unconditionally. * modules/mountlist (Depends-on): Add unlocked-io-internal. --- ChangeLog | 6 ++++++ lib/mountlist.c | 5 ++--- modules/mountlist | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index d6e8d54..1159ee8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2021-03-06 Bruno Haible + mountlist: Optimize stdio accesses. + * lib/mountlist.c: Include unlocked-io.h unconditionally. + * modules/mountlist (Depends-on): Add unlocked-io-internal. + +2021-03-06 Bruno Haible + getusershell: Optimize stdio accesses when possible. * lib/getusershell.c: Test GNULIB_GETUSERSHELL_SINGLE_THREAD instead of USE_UNLOCKED_IO. diff --git a/lib/mountlist.c b/lib/mountlist.c index fae5b60..27989d2 100644 --- a/lib/mountlist.c +++ b/lib/mountlist.c @@ -149,9 +149,8 @@ # define MNT_IGNORE(M) 0 #endif -#if USE_UNLOCKED_IO -# include "unlocked-io.h" -#endif +/* Each of the FILE streams in this file is only used in a single thread. */ +#include "unlocked-io.h" /* The results of opendir() in this file are not used with dirfd and fchdir, therefore save some unnecessary work in fchdir.c. */ diff --git a/modules/mountlist b/modules/mountlist index 7542048..8ec4793 100644 --- a/modules/mountlist +++ b/modules/mountlist @@ -11,6 +11,7 @@ Depends-on: fopen-gnu getline open +unlocked-io-internal stdbool stdint strstr-simple -- 2.7.4 --nextPart5441975.4gzixM8jqV Content-Disposition: attachment; filename="0005-readutmp-Optimize-stdio-accesses.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0005-readutmp-Optimize-stdio-accesses.patch" >From d26b0a2672f5adec9658ac606661b2f3b24c0336 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 7 Mar 2021 02:36:31 +0100 Subject: [PATCH 5/9] readutmp: Optimize stdio accesses. * lib/readutmp.c: Include unlocked-io.h unconditionally. * modules/readutmp (Depends-on): Add unlocked-io-internal. --- ChangeLog | 6 ++++++ lib/readutmp.c | 5 ++--- modules/readutmp | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1159ee8..47f6807 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2021-03-06 Bruno Haible + readutmp: Optimize stdio accesses. + * lib/readutmp.c: Include unlocked-io.h unconditionally. + * modules/readutmp (Depends-on): Add unlocked-io-internal. + +2021-03-06 Bruno Haible + mountlist: Optimize stdio accesses. * lib/mountlist.c: Include unlocked-io.h unconditionally. * modules/mountlist (Depends-on): Add unlocked-io-internal. diff --git a/lib/readutmp.c b/lib/readutmp.c index 26ad815..73db856 100644 --- a/lib/readutmp.c +++ b/lib/readutmp.c @@ -34,9 +34,8 @@ #include "xalloc.h" -#if USE_UNLOCKED_IO -# include "unlocked-io.h" -#endif +/* Each of the FILE streams in this file is only used in a single thread. */ +#include "unlocked-io.h" #if 8 <= __GNUC__ # pragma GCC diagnostic ignored "-Wsizeof-pointer-memaccess" diff --git a/modules/readutmp b/modules/readutmp index e88897c..18cdad1 100644 --- a/modules/readutmp +++ b/modules/readutmp @@ -12,6 +12,7 @@ xalloc stdbool stdint fopen-gnu +unlocked-io-internal configure.ac: gl_READUTMP -- 2.7.4 --nextPart5441975.4gzixM8jqV Content-Disposition: attachment; filename="0006-exclude-Allow-stdio-optimization-independently-of-un.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0006-exclude-Allow-stdio-optimization-independently-of-un.patch" >From f4bf3936b988eb65361e04b0ca3898681b787c58 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 7 Mar 2021 02:42:24 +0100 Subject: [PATCH 6/9] exclude: Allow stdio optimization independently of 'unlocked-io'. * lib/exclude.c: Test GNULIB_EXCLUDE_SINGLE_THREAD instead of USE_UNLOCKED_IO. * modules/exclude (Depends-on): Add unlocked-io-internal. * doc/multithread.texi: Document GNULIB_EXCLUDE_SINGLE_THREAD. --- ChangeLog | 8 ++++++++ doc/multithread.texi | 4 ++++ lib/exclude.c | 2 +- modules/exclude | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 47f6807..d2ffff0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2021-03-06 Bruno Haible + exclude: Allow stdio optimization independently of 'unlocked-io'. + * lib/exclude.c: Test GNULIB_EXCLUDE_SINGLE_THREAD instead of + USE_UNLOCKED_IO. + * modules/exclude (Depends-on): Add unlocked-io-internal. + * doc/multithread.texi: Document GNULIB_EXCLUDE_SINGLE_THREAD. + +2021-03-06 Bruno Haible + readutmp: Optimize stdio accesses. * lib/readutmp.c: Include unlocked-io.h unconditionally. * modules/readutmp (Depends-on): Add unlocked-io-internal. diff --git a/doc/multithread.texi b/doc/multithread.texi index a63d3ee..082ccb0 100644 --- a/doc/multithread.texi +++ b/doc/multithread.texi @@ -278,4 +278,8 @@ been initialized. This macro optimizes the functions @code{mbrtowc} and You may define the C macro @code{GNULIB_GETUSERSHELL_SINGLE_THREAD}, if all the programs in your package invoke the functions @code{setusershell}, @code{getusershell}, @code{endusershell} only from a single thread. +@item +You may define the C macro @code{GNULIB_EXCLUDE_SINGLE_THREAD}, if all the +programs in your package invoke the functions of the @code{exclude} module +only from a single thread. @end itemize diff --git a/lib/exclude.c b/lib/exclude.c index a9c4e68..4ef4e08 100644 --- a/lib/exclude.c +++ b/lib/exclude.c @@ -42,7 +42,7 @@ #include "verify.h" #include "filename.h" -#if USE_UNLOCKED_IO +#if GNULIB_EXCLUDE_SINGLE_THREAD # include "unlocked-io.h" #endif diff --git a/modules/exclude b/modules/exclude index 2529027..13871bd 100644 --- a/modules/exclude +++ b/modules/exclude @@ -14,6 +14,7 @@ mbscasecmp mbuiter regex stdbool +unlocked-io-internal verify xalloc -- 2.7.4 --nextPart5441975.4gzixM8jqV Content-Disposition: attachment; filename="0007-regex-Allow-locking-optimization-independently-of-un.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0007-regex-Allow-locking-optimization-independently-of-un.patch" >From ede75ad3eeeafe72d1af9de84897905edf76bd70 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 7 Mar 2021 02:47:03 +0100 Subject: [PATCH 7/9] regex: Allow locking optimization independently of 'unlocked-io'. * lib/regex_internal.h: Test GNULIB_REGEX_SINGLE_THREAD instead of USE_UNLOCKED_IO. * doc/multithread.texi: Document GNULIB_REGEX_SINGLE_THREAD. --- ChangeLog | 7 +++++++ doc/multithread.texi | 4 ++++ lib/regex_internal.h | 4 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index d2ffff0..f9bdb94 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2021-03-06 Bruno Haible + regex: Allow locking optimization independently of 'unlocked-io'. + * lib/regex_internal.h: Test GNULIB_REGEX_SINGLE_THREAD instead of + USE_UNLOCKED_IO. + * doc/multithread.texi: Document GNULIB_REGEX_SINGLE_THREAD. + +2021-03-06 Bruno Haible + exclude: Allow stdio optimization independently of 'unlocked-io'. * lib/exclude.c: Test GNULIB_EXCLUDE_SINGLE_THREAD instead of USE_UNLOCKED_IO. diff --git a/doc/multithread.texi b/doc/multithread.texi index 082ccb0..cb0c620 100644 --- a/doc/multithread.texi +++ b/doc/multithread.texi @@ -270,6 +270,10 @@ You need extra code for this optimization to be effective: include the @code{"unlocked-io.h"} header file. Some Gnulib modules that do operations on @code{FILE} streams have these preparations already included. @item +You may define the C macro @code{GNULIB_REGEX_SINGLE_THREAD}, if all the +programs in your package invoke the functions of the @code{regex} module +only from a single thread. +@item You may define the C macro @code{GNULIB_WCHAR_SINGLE}, if all the programs in your package are single-threaded and won't change the locale after it has been initialized. This macro optimizes the functions @code{mbrtowc} and diff --git a/lib/regex_internal.h b/lib/regex_internal.h index 4b0a3ef..1245e78 100644 --- a/lib/regex_internal.h +++ b/lib/regex_internal.h @@ -53,14 +53,14 @@ # define lock_fini(lock) ((void) 0) # define lock_lock(lock) __libc_lock_lock (lock) # define lock_unlock(lock) __libc_lock_unlock (lock) -#elif defined GNULIB_LOCK && !defined USE_UNLOCKED_IO +#elif defined GNULIB_LOCK && !defined GNULIB_REGEX_SINGLE_THREAD # include "glthread/lock.h" # define lock_define(name) gl_lock_define (, name) # define lock_init(lock) glthread_lock_init (&(lock)) # define lock_fini(lock) glthread_lock_destroy (&(lock)) # define lock_lock(lock) glthread_lock_lock (&(lock)) # define lock_unlock(lock) glthread_lock_unlock (&(lock)) -#elif defined GNULIB_PTHREAD && !defined USE_UNLOCKED_IO +#elif defined GNULIB_PTHREAD && !defined GNULIB_REGEX_SINGLE_THREAD # include # define lock_define(name) pthread_mutex_t name; # define lock_init(lock) pthread_mutex_init (&(lock), 0) -- 2.7.4 --nextPart5441975.4gzixM8jqV Content-Disposition: attachment; filename="0008-mbrtowc-Allow-locking-optimization-independently-of-.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0008-mbrtowc-Allow-locking-optimization-independently-of-.patch" >From cd057fa80c74dcf1d0a74290cb5ad6cdc3136428 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 7 Mar 2021 02:57:46 +0100 Subject: [PATCH 8/9] mbrtowc: Allow locking optimization independently of 'unlocked-io'. * lib/mbtowc-lock.h: Test GNULIB_MBRTOWC_SINGLE_THREAD instead of USE_UNLOCKED_IO. * doc/multithread.texi: Document GNULIB_MBRTOWC_SINGLE_THREAD. --- ChangeLog | 7 +++++++ doc/multithread.texi | 5 +++++ lib/mbtowc-lock.h | 4 +++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f9bdb94..80590b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2021-03-06 Bruno Haible + mbrtowc: Allow locking optimization independently of 'unlocked-io'. + * lib/mbtowc-lock.h: Test GNULIB_MBRTOWC_SINGLE_THREAD instead of + USE_UNLOCKED_IO. + * doc/multithread.texi: Document GNULIB_MBRTOWC_SINGLE_THREAD. + +2021-03-06 Bruno Haible + regex: Allow locking optimization independently of 'unlocked-io'. * lib/regex_internal.h: Test GNULIB_REGEX_SINGLE_THREAD instead of USE_UNLOCKED_IO. diff --git a/doc/multithread.texi b/doc/multithread.texi index cb0c620..b28d1de 100644 --- a/doc/multithread.texi +++ b/doc/multithread.texi @@ -274,6 +274,11 @@ You may define the C macro @code{GNULIB_REGEX_SINGLE_THREAD}, if all the programs in your package invoke the functions of the @code{regex} module only from a single thread. @item +You may define the C macro @code{GNULIB_MBRTOWC_SINGLE_THREAD}, if all the +programs in your package invoke the functions @code{mbrtowc}, @code{mbrtoc32}, +and the functions of the @code{regex} module only from a single thread. (The +@code{regex} module uses @code{mbrtowc} under the hood.) +@item You may define the C macro @code{GNULIB_WCHAR_SINGLE}, if all the programs in your package are single-threaded and won't change the locale after it has been initialized. This macro optimizes the functions @code{mbrtowc} and diff --git a/lib/mbtowc-lock.h b/lib/mbtowc-lock.h index b7c5ba8..3b6f5f9 100644 --- a/lib/mbtowc-lock.h +++ b/lib/mbtowc-lock.h @@ -32,7 +32,9 @@ mbtowc_unlocked (wchar_t *pwc, const char *p, size_t m) /* Prohibit renaming this symbol. */ #undef gl_get_mbtowc_lock -#ifdef USE_UNLOCKED_IO +#if GNULIB_MBRTOWC_SINGLE_THREAD + +/* All uses of this function are in a single thread. No locking needed. */ static int mbtowc_with_lock (wchar_t *pwc, const char *p, size_t m) -- 2.7.4 --nextPart5441975.4gzixM8jqV Content-Disposition: attachment; filename="0009-Rename-GNULIB_WCHAR_SINGLE-to-GNULIB_WCHAR_SINGLE_LO.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0009-Rename-GNULIB_WCHAR_SINGLE-to-GNULIB_WCHAR_SINGLE_LO.patch" >From 2a200f4eb4754823c5674580bb0b68a88fd35077 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 7 Mar 2021 10:45:58 +0100 Subject: [PATCH 9/9] Rename GNULIB_WCHAR_SINGLE to GNULIB_WCHAR_SINGLE_LOCALE. * lib/lc-charset-dispatch.c: Test GNULIB_WCHAR_SINGLE_LOCALE instead of GNULIB_WCHAR_SINGLE. * lib/wcwidth.c: Likewise. * tests/test-wcwidth.c: Likewise. * doc/multithread.texi: Document GNULIB_WCHAR_SINGLE_LOCALE instead of GNULIB_WCHAR_SINGLE. * NEWS: Document the change. --- ChangeLog | 11 +++++++++++ NEWS | 4 ++++ doc/multithread.texi | 13 ++++++++++--- lib/lc-charset-dispatch.c | 6 +++--- lib/wcwidth.c | 2 +- tests/test-wcwidth.c | 2 +- 6 files changed, 30 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 80590b1..8b5ed00 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2021-03-07 Bruno Haible + + Rename GNULIB_WCHAR_SINGLE to GNULIB_WCHAR_SINGLE_LOCALE. + * lib/lc-charset-dispatch.c: Test GNULIB_WCHAR_SINGLE_LOCALE instead of + GNULIB_WCHAR_SINGLE. + * lib/wcwidth.c: Likewise. + * tests/test-wcwidth.c: Likewise. + * doc/multithread.texi: Document GNULIB_WCHAR_SINGLE_LOCALE instead of + GNULIB_WCHAR_SINGLE. + * NEWS: Document the change. + 2021-03-06 Bruno Haible mbrtowc: Allow locking optimization independently of 'unlocked-io'. diff --git a/NEWS b/NEWS index 318055a..ba89881 100644 --- a/NEWS +++ b/NEWS @@ -60,6 +60,10 @@ User visible incompatible changes Date Modules Changes +2021-03-07 mbrtowc For single-locale optimizations, you now need to + mbrtoc32 define GNULIB_WCHAR_SINGLE_LOCALE instead of + wcwidth GNULIB_WCHAR_SINGLE. + 2021-02-28 parse-datetime The parse_datetime2 function has been moved to the new parse-datetime2 module, so that programs that need just parse_datetime need diff --git a/doc/multithread.texi b/doc/multithread.texi index b28d1de..eef724d 100644 --- a/doc/multithread.texi +++ b/doc/multithread.texi @@ -279,9 +279,16 @@ programs in your package invoke the functions @code{mbrtowc}, @code{mbrtoc32}, and the functions of the @code{regex} module only from a single thread. (The @code{regex} module uses @code{mbrtowc} under the hood.) @item -You may define the C macro @code{GNULIB_WCHAR_SINGLE}, if all the programs in -your package are single-threaded and won't change the locale after it has -been initialized. This macro optimizes the functions @code{mbrtowc} and +You may define the C macro @code{GNULIB_WCHAR_SINGLE_LOCALE}, if all the +programs in your package set the locale early and +@itemize +@item +don't change the locale after it has been initialized, and +@item +don't call locale sensitive functions (@code{mbrtowc}, @code{wcwidth}, etc.@:) +before the locale has been initialized. +@end itemize +This macro optimizes the functions @code{mbrtowc}, @code{mbrtoc32}, and @code{wcwidth}. @item You may define the C macro @code{GNULIB_GETUSERSHELL_SINGLE_THREAD}, if all the diff --git a/lib/lc-charset-dispatch.c b/lib/lc-charset-dispatch.c index 879f71a..5c63c4b 100644 --- a/lib/lc-charset-dispatch.c +++ b/lib/lc-charset-dispatch.c @@ -26,7 +26,7 @@ # include "localcharset.h" # include "streq.h" -# if GNULIB_WCHAR_SINGLE +# if GNULIB_WCHAR_SINGLE_LOCALE /* When we know that the locale does not change, provide a speedup by caching the value of locale_encoding_classification. */ # define locale_encoding_classification_cached locale_encoding_classification @@ -35,7 +35,7 @@ # define locale_encoding_classification_uncached locale_encoding_classification # endif -# if GNULIB_WCHAR_SINGLE +# if GNULIB_WCHAR_SINGLE_LOCALE static inline # endif enc_t @@ -59,7 +59,7 @@ locale_encoding_classification_uncached (void) return enc_other; } -# if GNULIB_WCHAR_SINGLE +# if GNULIB_WCHAR_SINGLE_LOCALE static int cached_locale_enc = -1; diff --git a/lib/wcwidth.c b/lib/wcwidth.c index 9009ebc..8d85082 100644 --- a/lib/wcwidth.c +++ b/lib/wcwidth.c @@ -34,7 +34,7 @@ is_locale_utf8 (void) return STREQ_OPT (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0); } -#if GNULIB_WCHAR_SINGLE +#if GNULIB_WCHAR_SINGLE_LOCALE /* When we know that the locale does not change, provide a speedup by caching the value of is_locale_utf8. */ static int cached_is_locale_utf8 = -1; diff --git a/tests/test-wcwidth.c b/tests/test-wcwidth.c index 16c6837..e5e3a54 100644 --- a/tests/test-wcwidth.c +++ b/tests/test-wcwidth.c @@ -35,7 +35,7 @@ main () { wchar_t wc; -#if !GNULIB_WCHAR_SINGLE +#if !GNULIB_WCHAR_SINGLE_LOCALE # ifdef C_CTYPE_ASCII /* Test width of ASCII characters. */ for (wc = 0x20; wc < 0x7F; wc++) -- 2.7.4 --nextPart5441975.4gzixM8jqV--