Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4780104rdb; Tue, 12 Dec 2023 09:06:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+8qSoDx/VHQ9VPIl90MfjwckXqUpomifprEzUyRDL8mBCVA75Tz1NaUtHk1/4M6I6JHWH X-Received: by 2002:a17:90b:a4d:b0:28a:dc13:6411 with SMTP id gw13-20020a17090b0a4d00b0028adc136411mr64465pjb.42.1702400783680; Tue, 12 Dec 2023 09:06:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702400783; cv=none; d=google.com; s=arc-20160816; b=BvT9NBfiL1MTcZA0U6MwuQ9duC29cLzHhEch55Zt+RmhLogQDYD/HO9AFSjgtlOFqM JaIJFNTTWwknJJLTOTVYpIw77FM13vq99xMZ8pL/19oen3Egvo9TZdiVtVT/nFYuD/Bp bhPOraLNM4mmDL21oBTaUnLjenXmHpEpSw6mizktH8TnOduZb3ymVgtyd7VLsavRGOzF pc86nyB1owWHn3R9+q+vbrGOwefJH2PSjFz0mmtopfZsWNw/6fe/fzRu6YAZNuaU7PjU MVLzi+kiqIwuTxiY0Hwng4jiMQ/oZi0x3PD8+DTjaagZr/N8ycQ3SJPSqgBj0o4uxT24 z1/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :date:dkim-signature; bh=Yb396aKFrmXDBySgBnliEUcRESnxNJ3dzgc1iddiAhI=; fh=A2E0LtHfen5vzl6zi7oB6cYaIuZGWaj7krUTbI9Debk=; b=GXdK138WcNyNNZNddZmbxQyoYHldOJpWhoTkOOJ2zG04cP+CZbt3E/twtEp9WYerYE 8mX5vZzdawnlIcXEz7iq++1kVNZPt2RHyoVxpJL2Gbpqa46Psjwr7++MGsA3C9Y9YM3m qdQUa2DOg2hDK3hQGjQhkus4CONHkFwToQOqKIkFG2Mmz9hVlfFNbYBPt9RT8v93pGJC wqov43Pklh5pQgJ38RSt7N09my50SbZ6VtAbSmjUJIM0VzzOWjiuIrTsiV5/MMhhaBo/ qLwEPSpzhgVoeILsiNiGV5iVprtHFAztf+w0kyMOPelZeoBoBQzIXWWfY5/naytsBO0u AJPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=xubov7wakjac3b3avdvdckasam.protonmail header.b=XkbzSdxg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id d3-20020a17090ab30300b00286785e0bfesi9593039pjr.147.2023.12.12.09.06.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 09:06:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=xubov7wakjac3b3avdvdckasam.protonmail header.b=XkbzSdxg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id B03338082A47; Tue, 12 Dec 2023 09:05:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232911AbjLLRFZ (ORCPT + 99 others); Tue, 12 Dec 2023 12:05:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232817AbjLLRFX (ORCPT ); Tue, 12 Dec 2023 12:05:23 -0500 Received: from mail-40133.protonmail.ch (mail-40133.protonmail.ch [185.70.40.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2894CB7 for ; Tue, 12 Dec 2023 09:05:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=xubov7wakjac3b3avdvdckasam.protonmail; t=1702400727; x=1702659927; bh=Yb396aKFrmXDBySgBnliEUcRESnxNJ3dzgc1iddiAhI=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=XkbzSdxglIApKSopXr7ytzrpSmgREOq67HNN236/cXP6F3eGCx6so5jKpsit4NG9w o5TNdBpQT1ZK3hqY699HaBE505agu8o9DLNdZ93BWm1rZD6oRiFTtaXtMAhLX7laYB zecgtqmjw4tJj8WfM6aixl/xgXMyfZWuvPO+K7+qgnlOVApCRRLUfxwTqv+Tym6C/q Z90WxAM10CmCN4X/c6RIcZWpQ7CmjgzQLj7Soxawi+grihE6m0G7ti1f0xoKbdv7rw eNKeVqySR+iDTlWrkNOvVJlVhfsIhF013GZ4aHe++jCoN0ucD0yHs+zp0KtiRqXE71 jwk+X7J3MJKQQ== Date: Tue, 12 Dec 2023 17:05:09 +0000 To: Alice Ryhl From: Benno Lossin Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] rust: sync: add `CondVar::wait_timeout` Message-ID: <5IXvyecf8pjdrhCW-71mwHOHFXRdLiCQCwgeVjljGhAJZEegyRxLC3hRr2NZGoNM0HCihiCjdcas1Ib_oWC7y5u8HBAQkN0-8IS5JlwikCU=@proton.me> In-Reply-To: References: <20231206-rb-new-condvar-methods-v1-0-33a4cab7fdaa@google.com> <20231206-rb-new-condvar-methods-v1-2-33a4cab7fdaa@google.com> Feedback-ID: 71780778:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 12 Dec 2023 09:05:55 -0800 (PST) On 12/12/23 10:51, Alice Ryhl wrote: > On Fri, Dec 8, 2023 at 8:04=E2=80=AFPM Benno Lossin wrote: >> >> On 12/6/23 11:09, Alice Ryhl wrote: >>> + /// Atomically releases the given lock (whose ownership is proven = by the guard) and puts the >>> + /// thread to sleep. It wakes up when notified by [`CondVar::notif= y_one`] or >>> + /// [`CondVar::notify_all`], or when the thread receives a signal. >>> + /// >>> + /// Returns whether there is a signal pending. >>> + fn wait_internal_timeout( >>> + &self, >>> + wait_state: u32, >>> + guard: &mut Guard<'_, T, B>, >>> + timeout: u64, >>> + ) -> u64 >>> + where >>> + T: ?Sized, >>> + B: Backend, >>> + { >>> + let wait =3D Opaque::::uninit(); >>> + >>> + // SAFETY: `wait` points to valid memory. >>> + unsafe { bindings::init_wait(wait.get()) }; >>> + >>> + // SAFETY: Both `wait` and `wait_list` point to valid memory. >>> + unsafe { >>> + bindings::prepare_to_wait_exclusive(self.wait_list.get(), = wait.get(), wait_state as _) >> >> Does `.into()` work here? If for some reason the type here changes, we >> probably want to know about it. >=20 > I think we may be able to eliminate this cast by using c_int for the > integer type. Sounds good. >>> + }; >>> + >>> + // SAFETY: Switches to another thread. >>> + let timeout =3D >>> + guard.do_unlocked(|| unsafe { bindings::schedule_timeout(t= imeout as _) as _ }); >> >> Ditto. >=20 > Here, we're casting u64->long and then long->u64. How about this? >=20 > u64->long - Use timeout.try_into().unwrap_or(MAX_SCHEDULE_TIMEOUT), > since MAX_SCHEDULE_TIMEOUT is LONG_MAX. >=20 > long->u64 - This value is guaranteed to be less than the argument > passed to schedule_timeout. Use .into() for infallible cast. Also sounds good :) --=20 Cheers, Benno