From nobody Mon May 02 21:05:57 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 614211AC2147 for ; Mon, 2 May 2022 21:05:59 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KsbGv1PZ4z4tRn; Mon, 2 May 2022 21:05:59 +0000 (UTC) (envelope-from jhb@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651525559; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PtLGh9XYWxqPFmNMI8mr8p/AeXgXoR4KFA4PiLnMiRU=; b=OSHWPmJD6bPqf4M9MX0D248x6eU/zZwlCNI+dGFMsNHBZjHkVIh7GSOdohX2UKiorR6Lty XfK+fFC15nXZBqUU4vYwXprgSbnaEzAaKcUTx8I/B5yy3/2HUmXiF9MB5mu8Bj8HZun2cM dSCtJg9niG88HDFHFPM9sU/z1VibXRl8lj7SnWb1XhV4Eudk/6+cq6Pze+FG20MKX9mcBw TKom7tiYrZ22rCB/mVcSTV6dswSU3sm81rPGtMqdE5OTR8Wus15Ogjku8kmFD8Cz4PRBtP bbivVqVi5lyws5HQUB22VkCrUDaP2Fsjj44a2nHFGE9qQlAeZv4OBxALJemoPw== Received: from [10.0.1.4] (ralph.baldwin.cx [66.234.199.215]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id C0113DD4C; Mon, 2 May 2022 21:05:58 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Message-ID: <200b4f6d-b533-042c-a411-1c100ed0b48b@FreeBSD.org> Date: Mon, 2 May 2022 14:05:57 -0700 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 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: Why mtx_sleep returning EWOUNDBLOCK? Content-Language: en-US To: Farhan Khan , freebsd-drivers@freebsd.org References: <706b2fc4-ce74-8716-d5c6-092d69c9c0fc@farhan.codes> From: John Baldwin In-Reply-To: <706b2fc4-ce74-8716-d5c6-092d69c9c0fc@farhan.codes> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651525559; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PtLGh9XYWxqPFmNMI8mr8p/AeXgXoR4KFA4PiLnMiRU=; b=V+RDk0UCxt/FEzt8JNXn4t8BIu/rjLWbW1nysnrqkjcj0up1jtnMLcWnsUPJ4hYZ0TGBEm r7DUqU8L8EOSXLXXnVAHl+k1EDwhLWePgsE0d8aILlFohSJtYWc+BLBhXzEYajFAKlO70j /jbTGuYr54zIIT3tCRm9rsrv9Q/VIRJ77x88NA9VYyxCsA6Wu656lARdkDyl26oFza7nDl sdmLq5G5Oia6W1Llj36ED8qNkxOmJvP7oLL8ZQsogrSSGdwhPjIToXnRSAW3AXqvJfEHP6 84yspqh5jt9O6D9D8iSa0YW6HTxZkNanFOjpy9gAhk7G+RYQ1Hlndj14tXnDMw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1651525559; a=rsa-sha256; cv=none; b=fcvmWuOyVoc4W58jtLxI9+gsZl6FeT06193z50I0wvkqtnv8wXHeto50dq6GuPGo9Ac7nA xh0tqX97spefpcETqEzYo6ZX6IQidrsrTdCpNJUvFU8BAzYVWaYzwZAmksrn1mNsUjwJNL atrL0qCyGyLUX5WQSK88eyAXqKIcJvWD5E/frULLxr6ewCKkNV9H1g+cYFaVGqtTJMMvo+ ITMpdJpdQa+ux3uc6dKTUZ4Iq18ROIbgpA5MEh83+Q8f/mDiz+BYTWBjTBrmBK0PwtY+qx 8Pd0didqy54DGnttvw8vprvPADGpSArqr9dwcAdldCtgnI1eFwwBGbNnEPvbHA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N On 3/13/22 1:02 PM, Farhan Khan wrote: > Hi all, > > Summary: I am running mtx_sleep() but getting an EWOUNDBLOCK response > code and do not understand why. > > I am looking at port code from the OpenBSD side to FreeBSD. I am > assuming that tsleep_nsec()'s equivalent on FreeBSD is mtx_sleep(). To > that end, I am running mtx_sleep as this: > > mtx_lock(&(sc)->sc_mtx); > error = mtx_sleep(sc, &sc->sc_mtx, 0 , "athnfw", hz); > mtx_unlock(&(sc)->sc_mtx); > > However, the error code returns a EWOUNDBLOCK. I would expect this to be > 0. From reading the man page for sleep(9), this means "A non-zero > timeout was specified and the timeout". But if I slept for 1 hz, isn't > that exactly what I want and thus it should return 0 (no error)? > > The OpenBSD line in question is: > > error = tsleep_nsec(&usc->wait_msg_id, 0, "athnfw", SEC_TO_NSEC(1)); > > Perhaps there is something I am not understanding here? Please advise. > Thanks! error == 0 means you were awakened by an explicit wakeup() rather than a timeout (EWOULDBLOCK). If we returned 0 for timeouts the caller would have no way to determine if a timeout had occurred or not. If you as the caller don't view timeouts as fatal, you can explicitly map EWOULDBLOCK to 0. -- John Baldwin