From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 894BAC433B4 for ; Wed, 12 May 2021 05:34:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6BA7261940 for ; Wed, 12 May 2021 05:34:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230145AbhELFfJ (ORCPT ); Wed, 12 May 2021 01:35:09 -0400 Received: from wtarreau.pck.nerim.net ([62.212.114.60]:52969 "EHLO 1wt.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230017AbhELFfI (ORCPT ); Wed, 12 May 2021 01:35:08 -0400 Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 14C5Xual020758; Wed, 12 May 2021 07:33:56 +0200 Date: Wed, 12 May 2021 07:33:56 +0200 From: Willy Tarreau To: Mark Brown Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH] tools/nolibc: Implement msleep() Message-ID: <20210512053356.GA20749@1wt.eu> References: <20210511110159.57286-1-broonie@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210511110159.57286-1-broonie@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Mark, On Tue, May 11, 2021 at 12:01:59PM +0100, Mark Brown wrote: > +static __attribute__((unused)) > +void msleep(unsigned int msecs) > +{ > + struct timeval my_timeval = { 0, msecs * 1000 }; > + > + sys_select(0, 0, 0, 0, &my_timeval); > +} > + Just a quick question, is there any reason for not keeping most of the precision like this and allow applications to use it beyond 4294 seconds like this ? struct timeval my_timeval = { msecs / 1000, (msecs % 1000) * 1000 }; Another thing that comes to my mind is that sleep() returns the remaining number of seconds if the syscall was interrupted, and I think it could be very useful in small tests programs to do the same at the subsecond level in simple scheduling loops for example. Copying what we're doing in sleep() we could have this: if (sys_select(0, 0, 0, 0, &my_timeval) < 0) return my_timeval.tv_sec * 1000 + (my_timeval.tv_usec + 999) / 1000; else return 0; And since that's an inline function it will be optimized away if the result is not used anyway, resulting in the same code as the void version in this case. What do you think ? Thanks! Willy