Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3413627ybf; Tue, 3 Mar 2020 05:39:13 -0800 (PST) X-Google-Smtp-Source: ADFU+vsojJVgMo9afm/AuCCj6nW7aae8SSELw99mOJNhzIx6OREHF4J0ZVbXhqt6LOB+nS1suWuN X-Received: by 2002:aca:4b57:: with SMTP id y84mr2533171oia.16.1583242752587; Tue, 03 Mar 2020 05:39:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583242752; cv=none; d=google.com; s=arc-20160816; b=uRAWgeMJWeIowJzJ6RLz8FdXCuRFulJm1eh7MfFK24+78kbkFeEIqWa4j6Fcg+M0lw /nJEQ5T1jWEpPcs760wHng4FnLtplrlGu47PM1emXHX4ilS9qnAruQWiN1H+q158a2sq ShBGp5Q8efUnui/ABL5VILbC6s51Q1GmGMNQz/AiX1g5C9u1gnCRA4kUrnITOYAaz5ni D+Z8sW8Y2WgGZRdN9fZInmB0XwBTmraVf5B7SuPuvpo6M5iH3fbWpgsm4ZPNYkXaO3nG rsOLVk0n5oV6iMeAMSTtwmSWffPNDSmjlza9IfJnHEq21z4tRcXb2pNliyJnkeIqlX+9 rr7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=lm1J5n5+hScBLK9U43/eb/xDYPs2lcB12KKqXk5s7Z4=; b=CiUON1gn28RNku5OSWAoGCHmCZD15JRhbnLsm8XgoV1yj2YBlCOCcTRICqIg97E7yz KVLHRLJwpkU1Y4owAky23XR10Ben2qWPMBlIFozH7gVs3QCaH1xC0EAQ5FfOtAwFizPw MXQJGDWu8sZjm9+RhduPwbjtfE6FgK/uG66xlLEvLYVh2p9hRPsLn/XCSVsFnZ5onvDT LrgUTrI8Mw1HuYzgus8dR37wRInStqBwc4vD5FCP4ieDoqtLyt6pcDPi2YBUwE3ftk6e tX6vGUuTPzdCa7IVd4bPw3N6YO4Q0ut8Txu9L3lw8LwDJjzoEWtPybWNStbmDnTHXljd wsWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=APHzxd1V; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l1si910040oib.263.2020.03.03.05.39.00; Tue, 03 Mar 2020 05:39:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=APHzxd1V; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729311AbgCCNWP (ORCPT + 99 others); Tue, 3 Mar 2020 08:22:15 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:49160 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728398AbgCCNWP (ORCPT ); Tue, 3 Mar 2020 08:22:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=lm1J5n5+hScBLK9U43/eb/xDYPs2lcB12KKqXk5s7Z4=; b=APHzxd1VPHRwDBmvnXDJ0inO2d 84Aq511ks8CXnnAYNce3jHkai6v1hWnBLyJtWSEk9BRM5Zc1QFl1kqY7EQDRUusPzey5MaU5NK7XS HKyaPCLZZZhjWbZfOxbmsbRlr6vwkM6Uer11AigZDjX37lG+HDqJE3PSZ/cxDsNcoBB1pvvbAzlS5 SXMWFj0ctj6ImQnixJpfC/IfZKJwwFtjHhH//jSed5jzAnlsRiTCOVhNJExhvKCje7Q4Y4JR23rj8 KaTc7Qw9ZVaAQspH0obkzlY5FwvR/67ec2+xzAahAZOqOeTClJ7IU6jXN0l22KNR+Ctaxooay+za1 8cALbTRg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1j97Ug-0006Jh-4i; Tue, 03 Mar 2020 13:21:54 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id CFC6E3013A4; Tue, 3 Mar 2020 14:19:52 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id E99B0210C2866; Tue, 3 Mar 2020 14:21:50 +0100 (CET) Date: Tue, 3 Mar 2020 14:21:50 +0100 From: Peter Zijlstra To: Florian Weimer Cc: "Pierre-Loup A. Griffais" , Thomas Gleixner , =?iso-8859-1?Q?Andr=E9?= Almeida , linux-kernel@vger.kernel.org, kernel@collabora.com, krisman@collabora.com, shuah@kernel.org, linux-kselftest@vger.kernel.org, rostedt@goodmis.org, ryao@gentoo.org, dvhart@infradead.org, mingo@redhat.com, z.figura12@gmail.com, steven@valvesoftware.com, steven@liquorix.net, malteskarupke@web.de, carlos@redhat.com, adhemerval.zanella@linaro.org, libc-alpha@sourceware.org Subject: Re: 'simple' futex interface [Was: [PATCH v3 1/4] futex: Implement mechanism to wait on any of several futexes] Message-ID: <20200303132150.GD2596@hirez.programming.kicks-ass.net> References: <20200213214525.183689-1-andrealmeid@collabora.com> <20200213214525.183689-2-andrealmeid@collabora.com> <20200228190717.GM18400@hirez.programming.kicks-ass.net> <20200228194958.GO14946@hirez.programming.kicks-ass.net> <87tv3aflqm.fsf@nanos.tec.linutronix.de> <967d5047-2cb6-d6d8-6107-edb99a4c9696@valvesoftware.com> <87o8thg031.fsf@nanos.tec.linutronix.de> <20200303120050.GC2596@hirez.programming.kicks-ass.net> <87pndth9ur.fsf@oldenburg2.str.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87pndth9ur.fsf@oldenburg2.str.redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 03, 2020 at 02:00:12PM +0100, Florian Weimer wrote: > * Peter Zijlstra: > > > So how about we introduce new syscalls: > > > > sys_futex_wait(void *uaddr, unsigned long val, unsigned long flags, ktime_t *timo); > > > > struct futex_wait { > > void *uaddr; > > unsigned long val; > > unsigned long flags; > > }; > > sys_futex_waitv(struct futex_wait *waiters, unsigned int nr_waiters, > > unsigned long flags, ktime_t *timo); > > > > sys_futex_wake(void *uaddr, unsigned int nr, unsigned long flags); > > > > sys_futex_cmp_requeue(void *uaddr1, void *uaddr2, unsigned int nr_wake, > > unsigned int nr_requeue, unsigned long cmpval, unsigned long flags); > > > > Where flags: > > > > - has 2 bits for size: 8,16,32,64 > > - has 2 more bits for size (requeue) ?? > > - has ... bits for clocks > > - has private/shared > > - has numa > > What's the actual type of *uaddr? Does it vary by size (which I assume > is in bits?)? Are there alignment constraints? Yeah, u8, u16, u32, u64 depending on the size specified in flags. Naturally aligned. > These system calls seemed to be type-polymorphic still, which is > problematic for defining a really nice C interface. I would really like > to have a strongly typed interface for this, with a nice struct futex > wrapper type (even if it means that we need four of them). You mean like: futex_wait1(u8 *,...) futex_wait2(u16 *,...) futex_wait4(u32 *,...) etc.. ? I suppose making it 16 or so syscalls (more if we want WAKE_OP or requeue across size) is a bit daft, so yeah, sucks. > Will all architectures support all sizes? If not, how do we probe which > size/flags combinations are supported? Up to the native word size (long), IOW ILP32 will not support u64. Overlapping futexes are expressly forbidden, that is: { u32 var; void *addr = &var; } P0() { futex_wait4(addr,...); } P1() { futex_wait1(addr+1,...); } Will have one of them return something bad. > > For NUMA I propose that when NUMA_FLAG is set, uaddr-4 will be 'int > > node_id', with the following semantics: > > > > - on WAIT, node_id is read and when 0 <= node_id <= nr_nodes, is > > directly used to index into per-node hash-tables. When -1, it is > > replaced by the current node_id and an smp_mb() is issued before we > > load and compare the @uaddr. > > > > - on WAKE/REQUEUE, it is an immediate index. > > Does this mean the first waiter determines the NUMA index, and all > future waiters use the same chain even if they are on different nodes? Every new waiter could (re)set node_id, after all, when its not actually waiting, nobody cares what's in that field. > I think documenting this as a node index would be a mistake. It could > be an arbitrary hint for locating the corresponding kernel data > structures. Nah, it allows explicit placement, after all, we have set_mempolicy() and sched_setaffinity() and all the other NUMA crud so that programs that think they know what they're doing, can do explicit placement. > > Any invalid value with result in EINVAL. > > Using uaddr-4 is slightly tricky with a 64-bit futex value, due to the > need to maintain alignment and avoid padding. Yes, but it works, unlike uaddr+4 :-) Also, 1 and 2 byte futexes and NUMA_FLAG are incompatible due to this, but I feel short futexes and NUMA don't really make sense anyway, the only reason to use a short futex is to save space, so you don't want another 4 bytes for numa on top of that anyway.