NetBSD Problem Report #58184

From www@netbsd.org  Sun Apr 21 19:18:01 2024
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id A2C5F1A9238
	for <gnats-bugs@gnats.NetBSD.org>; Sun, 21 Apr 2024 19:18:01 +0000 (UTC)
Message-Id: <20240421191759.D4D6A1A923B@mollari.NetBSD.org>
Date: Sun, 21 Apr 2024 19:17:59 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: usleep persnicketiness is maybe not worth it
X-Send-Pr-Version: www-1.0

>Number:         58184
>Category:       lib
>Synopsis:       usleep persnicketiness is maybe not worth it
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    jdolecek
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Apr 21 19:20:00 +0000 2024
>Closed-Date:    Wed May 01 18:19:20 +0000 2024
>Last-Modified:  Wed May 01 18:19:20 +0000 2024
>Originator:     Taylor R Campbell
>Release:        current, 10, 9, 8
>Organization:
The NetUSleep IBusywait Foundation
>Environment:
>Description:
Our usleep(3) implementation is persnickety about adhering to the letter of the former POSIX specification -- obsolescent 20 years ago in 2004, and removed from POSIX since then:

> int usleep(useconds_t useconds);
> ...
> The useconds argument shall be less than one million.
> ...
> ERRORS
> ...
>    [EINVAL]
>       The time interval specified one million or more microseconds. 

https://pubs.opengroup.org/onlinepubs/009696899/functions/usleep.html

     54 	if (useconds >= 1000000) {
     55 		errno = EINVAL;
     56 		return (-1);
     57 	}

https://nxr.netbsd.org/xref/src/lib/libc/gen/usleep.c?r=1.20#54

This requires somewhat silly workarounds like the following sqlite3 commit:

https://www.sqlite.org/src/info/1f5ed852f25515bb

Maybe in the days of the SUSv2 in 1997 before usleep was marked obsolescent in POSIX, this was worthwhile.  But today, it's not even in POSIX at all.  Today, nobody expects the Spanish usleepition -- and since nobody bothers to check for usleep failure, instead of leading to noisy portability issue reports, it mostly leads to confusing failure modes like accidental busy-waits and generally poor performance on NetBSD for no obvious reason:

https://sqlite.org/forum/forumpost/7e50ced6a6
https://chaos.social/@dentangle/112309276051122420
>How-To-Repeat:
call usleep(1000000)
>Fix:
revert usleep.c rev. 1.16 (mostly)

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: lib-bug-people->jdolecek
Responsible-Changed-By: jdolecek@NetBSD.org
Responsible-Changed-When: Mon, 22 Apr 2024 21:04:23 +0000
Responsible-Changed-Why:
Committed change to allow values >= 1000000.


State-Changed-From-To: open->pending-pullups
State-Changed-By: jdolecek@NetBSD.org
State-Changed-When: Mon, 22 Apr 2024 21:04:23 +0000
State-Changed-Why:
Change committed, waiting for build round then I'll request pullup to -10


From: "Jaromir Dolecek" <jdolecek@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58184 CVS commit: src/lib/libc/gen
Date: Mon, 22 Apr 2024 21:02:18 +0000

 Module Name:	src
 Committed By:	jdolecek
 Date:		Mon Apr 22 21:02:18 UTC 2024

 Modified Files:
 	src/lib/libc/gen: usleep.3 usleep.c

 Log Message:
 allow usleep(3) with useconds >= 1000000

 update manpage to mention this interface is obsolete, remove
 EINVAL from the ERRORS and mention EINTR instead.

 PR lib/58184 by Taylor R Campbell


 To generate a diff of this commit:
 cvs rdiff -u -r1.19 -r1.20 src/lib/libc/gen/usleep.3
 cvs rdiff -u -r1.20 -r1.21 src/lib/libc/gen/usleep.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58184 CVS commit: [netbsd-10] src/lib/libc/gen
Date: Sun, 28 Apr 2024 13:23:20 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Sun Apr 28 13:23:20 UTC 2024

 Modified Files:
 	src/lib/libc/gen [netbsd-10]: usleep.3 usleep.c

 Log Message:
 Pull up following revision(s) (requested by jdolecek in ticket #678):

 	lib/libc/gen/usleep.c: revision 1.21
 	lib/libc/gen/usleep.3: revision 1.20
 	lib/libc/gen/usleep.3: revision 1.21

 allow usleep(3) with useconds >= 1000000

 update manpage to mention this interface is obsolete, remove
 EINVAL from the ERRORS and mention EINTR instead.

 PR lib/58184 by Taylor R Campbell

 it's nanosleep(2), not nanosleep(3)


 To generate a diff of this commit:
 cvs rdiff -u -r1.19 -r1.19.56.1 src/lib/libc/gen/usleep.3
 cvs rdiff -u -r1.20 -r1.20.42.1 src/lib/libc/gen/usleep.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: pending-pullups->closed
State-Changed-By: jdolecek@NetBSD.org
State-Changed-When: Wed, 01 May 2024 18:19:20 +0000
State-Changed-Why:
Change pulled up to -10


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.