From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by sourceware.org (Postfix) with ESMTPS id 0F0343858D20 for ; Thu, 28 Sep 2023 11:23:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0F0343858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=aculab.com Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-94-16gep9MhMWCHUX4uA_UWOw-1; Thu, 28 Sep 2023 12:22:56 +0100 X-MC-Unique: 16gep9MhMWCHUX4uA_UWOw-1 Received: from AcuMS.Aculab.com (10.202.163.6) by AcuMS.aculab.com (10.202.163.6) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Thu, 28 Sep 2023 12:22:55 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Thu, 28 Sep 2023 12:22:55 +0100 From: David Laight To: 'Peter Zijlstra' , Mathieu Desnoyers CC: "linux-kernel@vger.kernel.org" , "Thomas Gleixner" , "Paul E . McKenney" , Boqun Feng , "H . Peter Anvin" , "Paul Turner" , "linux-api@vger.kernel.org" , Christian Brauner , "Florian Weimer" , "carlos@redhat.com" , "Peter Oskolkov" , Alexander Mikhalitsyn , Chris Kennelly , Ingo Molnar , "Darren Hart" , Davidlohr Bueso , =?iso-8859-1?Q?Andr=E9_Almeida?= , "libc-alpha@sourceware.org" , Steven Rostedt , Jonathan Corbet , Noah Goldstein , Daniel Colascione , "longman@redhat.com" , Florian Weimer Subject: RE: [RFC PATCH v2 1/4] rseq: Add sched_state field to struct rseq Thread-Topic: [RFC PATCH v2 1/4] rseq: Add sched_state field to struct rseq Thread-Index: AQHZ8fgZ0Ykvpvbq8USYUjzds++7brAwFQDg Date: Thu, 28 Sep 2023 11:22:55 +0000 Message-ID: References: <20230529191416.53955-1-mathieu.desnoyers@efficios.com> <20230529191416.53955-2-mathieu.desnoyers@efficios.com> <20230928103926.GI9829@noisy.programming.kicks-ass.net> In-Reply-To: <20230928103926.GI9829@noisy.programming.kicks-ass.net> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Peter Zijlstra > Sent: 28 September 2023 11:39 >=20 > On Mon, May 29, 2023 at 03:14:13PM -0400, Mathieu Desnoyers wrote: > > Expose the "on-cpu" state for each thread through struct rseq to allow > > adaptative mutexes to decide more accurately between busy-waiting and > > calling sys_futex() to release the CPU, based on the on-cpu state of th= e > > mutex owner. Are you trying to avoid spinning when the owning process is sleeping? Or trying to avoid the system call when it will find that the futex is no longer held? The latter is really horribly detremental. > > > > It is only provided as an optimization hint, because there is no > > guarantee that the page containing this field is in the page cache, and > > therefore the scheduler may very well fail to clear the on-cpu state on > > preemption. This is expected to be rare though, and is resolved as soon > > as the task returns to user-space. > > > > The goal is to improve use-cases where the duration of the critical > > sections for a given lock follows a multi-modal distribution, preventin= g > > statistical guesses from doing a good job at choosing between busy-wait > > and futex wait behavior. >=20 > As always, are syscalls really *that* expensive? Why can't we busy wait > in the kernel instead? >=20 > I mean, sure, meltdown sucked, but most people should now be running > chips that are not affected by that particular horror show, no? IIRC 'page table separation' which is what makes system calls expensive is only a compile-time option. So is likely to be enabled on any 'distro' kernel. But a lot of other mitigations (eg RSB stuffing) are also pretty detrimenta= l. OTOH if you have a 'hot' userspace mutex you are going to lose whatever. All that needs to happen is for a ethernet interrupt to decide to discard completed transmits and refill the rx ring, and then for the softint code to free a load of stuff deferred by rcu while you've grabbed the mutex and no matter how short the user-space code path the mutex won't be released for absolutely ages. I had to change a load of code to use arrays and atomic increments to avoid delays acquiring mutex. =09David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)