From nobody Thu May 05 14:38:21 2022 X-Original-To: freebsd-drivers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id CCF9C1ACA910 for ; Thu, 5 May 2022 14:38:33 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-ua1-x930.google.com (mail-ua1-x930.google.com [IPv6:2607:f8b0:4864:20::930]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KvGXS66rVz3Jly for ; Thu, 5 May 2022 14:38:32 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-ua1-x930.google.com with SMTP id q4so1741571uas.0 for ; Thu, 05 May 2022 07:38:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=i6MqivIKEgq4EXwFg/psVgs3tKB7A8ioyAJzuVdVDNA=; b=JcpLaOyEJqupqe83/DsMqQmI2rzeT5CJtOqwwTyEGcAogQd+MMeQi2awlcFdHCbYk9 iFLyVifiUdd6P+mhJmqg3D1yb8TjZmhYLtujcnjOzF/mo53vr+rRJ+daZmMON+k84K4V AtZHJjYShQ5tWhpn8znHELtXD1fYj24qNVqQD6+qGocW5op0O6UvOqfehEDoHCsD8Nm2 K/RHq0KDgVGd2b+/c/5/wv6DexstApbYYm6ielg7pZiPAzduL5v1sr+O4sAQwe1OC3gd a0GnBodxIoD47aSvNj7ZatIxOKp7OcTeBofHKxh+Gp+3DnAlTeGbo9IyxI+K1UclDk6w HOvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=i6MqivIKEgq4EXwFg/psVgs3tKB7A8ioyAJzuVdVDNA=; b=NCaa6vZ6N7Ia0PrgY7oMqPN4YT1sgekTVoQ4YHE5xh0RDG/BYqRk2raGxvN5zJalRY Tf7vc3/BgQ0GEvCu1BRKAonzkrzpPKDv/c2xZpLo17a3Z6gcG8ptmtiY7uYcK3UQd4DM tTaeHWdJ0PQ0zE2RFmFy90zsEqKQkfCAJB3PsPkoyXTo+hTL9/3yZwIERPiFNCxPPJak H6OUbt/I3muBF5o7P80fPDNTCTUtoIJ40KWRbTGSJn0S2mz9aXORdEnVr210hWt9b+OQ HKfaYU4dLVSD7Ii+7PkhxwN1cMHN4/5cNQEaDhE9J7pFWltKmxtFv2BzM9AR7OAEzQ+y Cntg== X-Gm-Message-State: AOAM533nPIeq+jICSyTihvUOy9J/j2mgGwxPjP+eM7eE9k37S+D3vk6D aLvaUxYaj3sw7/2eMk8GhZVVwu0upP6BILRZyiTH4Q== X-Google-Smtp-Source: ABdhPJzzSK+Nli0sta9BNHthTJQS1X2dJhZcYh6aHSs+C+3UEsiKGfK5cXx2f91ETcDimP4vdI1M6uOeFjsGWUn+JVI= X-Received: by 2002:ab0:63d0:0:b0:365:1286:5266 with SMTP id i16-20020ab063d0000000b0036512865266mr8078965uap.2.1651761512054; Thu, 05 May 2022 07:38:32 -0700 (PDT) List-Id: Writing device drivers for FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-drivers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-drivers@freebsd.org MIME-Version: 1.0 References: <86ee7ca4-01c3-41dc-bbe0-5e8576fa7d62@www.fastmail.com> In-Reply-To: <86ee7ca4-01c3-41dc-bbe0-5e8576fa7d62@www.fastmail.com> From: Warner Losh Date: Thu, 5 May 2022 08:38:21 -0600 Message-ID: Subject: Re: What is timo from sleep(9) functions To: Farhan Khan Cc: freebsd-drivers@freebsd.org Content-Type: multipart/alternative; boundary="0000000000002e155f05de44b201" X-Rspamd-Queue-Id: 4KvGXS66rVz3Jly X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=bsdimp-com.20210112.gappssmtp.com header.s=20210112 header.b=JcpLaOyE; dmarc=none; spf=none (mx1.freebsd.org: domain of wlosh@bsdimp.com has no SPF policy when checking 2607:f8b0:4864:20::930) smtp.mailfrom=wlosh@bsdimp.com X-Spamd-Result: default: False [-3.00 / 15.00]; RCVD_TLS_ALL(0.00)[]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[bsdimp-com.20210112.gappssmtp.com:s=20210112]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; NEURAL_HAM_LONG(-1.00)[-0.999]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-drivers@freebsd.org]; DMARC_NA(0.00)[bsdimp.com]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[bsdimp-com.20210112.gappssmtp.com:+]; RCPT_COUNT_TWO(0.00)[2]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::930:from]; NEURAL_HAM_SHORT(-1.00)[-0.997]; MLMMJ_DEST(0.00)[freebsd-drivers]; FORGED_SENDER(0.30)[imp@bsdimp.com,wlosh@bsdimp.com]; R_SPF_NA(0.00)[no SPF record]; MIME_TRACE(0.00)[0:+,1:+,2:~]; RCVD_COUNT_TWO(0.00)[2]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; FROM_NEQ_ENVFROM(0.00)[imp@bsdimp.com,wlosh@bsdimp.com] X-ThisMailContainsUnwantedMimeParts: N --0000000000002e155f05de44b201 Content-Type: text/plain; charset="UTF-8" On Thu, May 5, 2022 at 7:50 AM Farhan Khan wrote: > Hi all, > > Hopefully simple question: > > What is the unit of the `int timeo` parameter in sleep(9)? Is it the > timeout in milliseconds? Or would 1 mean a second? > Related, what does the `hz` variable mean and why is it used? I see > instances of timo's in multiples of hz (ie, hz * 10). OpenGrok shows it > defined in a few different places and its not clear to me which it is. > The units are ticks. 1/hz seconds. There's other functions that let you sleep with other units (all the _sbt ones). The parameter timo specifies a timeout for the sleep. If timo is not 0, then the thread will sleep for at most timo / hz seconds. If the timeout expires, then the sleep function will return EWOULDBLOCK. Warner --0000000000002e155f05de44b201 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Thu, May 5, 2022 at 7:50 AM Farhan= Khan <farhan@farhan.codes> wrote:
Hi all,

<= div>Hopefully simple question:

What is the uni= t of the `int timeo` parameter in sleep(9)? Is it the timeout in millisecon= ds? Or would 1 mean a second?
Related, what does the `hz` var= iable mean and why is it used? I see instances of timo's in multiples o= f hz (ie, hz * 10). OpenGrok shows it defined in a few different places and= its not clear to me which it is.

The units are ticks. 1/hz seconds. There's other=C2=A0functions that= let you sleep with other units (all the _sbt ones).

=C2=A0 =C2=A0 =C2=A0The parameter timo specifies a timeout for the sleep= .=C2=A0 If timo is not 0,
=C2=A0 =C2=A0 =C2=A0then the thread will sleep= for at most timo / hz seconds.=C2=A0 If the timeout
=C2=A0 =C2=A0 =C2= =A0expires, then the sleep function will return EWOULDBLOCK.
=
Warner=C2=A0
--0000000000002e155f05de44b201--