Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3293777rdh; Thu, 28 Sep 2023 07:53:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQeO7EkZ26Nk/ctMCMHDK3Ety+iJsLH0SkLpiNJye6PMmpBY26wpLzcdnG9H9RJW0uiR7R X-Received: by 2002:a17:903:1212:b0:1bc:e6a:205f with SMTP id l18-20020a170903121200b001bc0e6a205fmr1608989plh.20.1695912813011; Thu, 28 Sep 2023 07:53:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695912812; cv=none; d=google.com; s=arc-20160816; b=BG5pPGZffsXyhGrq4EvRjnlE10pEUkhVkGPoGvwjw24POeC+HqQMO1Ju69V0c25fya m5gtVWQFTQ+jbO4ZrYyHF4FaZ6Bz7WOwSRyh27nFnGGqfeLs5/UxM90Oid6i3fKF7r8k 7vhyEKEm2xbaJgTYiI7KKX4R06E+j1/adyvgfDQmJ5BzPgbkVo3kdEUvuz9lR/iCSlvf A66YXTB9ji2DQhrMYFRWPa4+qiL3vgeOaFc+hudnEaTCFo6sVa6sb8C2YX47lCfEP2lA cUEZsyzgKKOy3VE9crSrzAZpSld5G/oB2dEEs75/qr6U0vzuTX2fO4YJMge0jwWArlW8 8Vdg== 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 :references:in-reply-to:message-id:subject:cc:to:from:date; bh=6BHOYqCJTyH9bGwdCQRiRnluhQgSxEfq3fvlDepxp2Q=; fh=WigH5fDLEz1VdJwUEoSI81RG+7eJORgatTkKyNVed6M=; b=ijvUvKcbLqBXSvZmFOsD7NSEON2qrK4QBVsh6jcOtk3xRSdnjy3NIhtSNLpqsCNwmx kwooF18snJwo6ibmwjuRyjAsfVVSjjnsZGiTn5Nu3XH4I5eYtVOpVYtx+jesdo/rlZGx cc9gYp2gleT+o6z5FRbB4g32kVJqcb/z7PCgkylaa3iLFWBQ+903++B8mlttXzDe7b89 1RvEE+Po+z5Lko+3OqLo/A/u9Le0L9M2blE7JauLWUIKK98xnmCIdymwBUTOeYYhWfE5 iw3u09u0Ns2b7qOZc6P/60wvDDoi9JknZ748dFN+UmpniElPQuZZh7yn4kIgqvvvb74d iwTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id ay6-20020a1709028b8600b001c465e1e219si17845846plb.30.2023.09.28.07.53.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 07:53:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id B9B3C80941E6; Thu, 28 Sep 2023 07:43:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230207AbjI1Ond (ORCPT + 99 others); Thu, 28 Sep 2023 10:43:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229605AbjI1Onb (ORCPT ); Thu, 28 Sep 2023 10:43:31 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02BE9F9; Thu, 28 Sep 2023 07:43:30 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B98C8C433C8; Thu, 28 Sep 2023 14:43:24 +0000 (UTC) Date: Thu, 28 Sep 2023 10:43:21 -0400 From: Steven Rostedt To: Peter Zijlstra Cc: Mathieu Desnoyers , 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 , David.Laight@aculab.com, carlos@redhat.com, Peter Oskolkov , Alexander Mikhalitsyn , Chris Kennelly , Ingo Molnar , Darren Hart , Davidlohr Bueso , =?UTF-8?B?QW5kcsOp?= Almeida , libc-alpha@sourceware.org, 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 Message-ID: <20230928104321.490782a7@rorschach.local.home> In-Reply-To: <20230928103926.GI9829@noisy.programming.kicks-ass.net> References: <20230529191416.53955-1-mathieu.desnoyers@efficios.com> <20230529191416.53955-2-mathieu.desnoyers@efficios.com> <20230928103926.GI9829@noisy.programming.kicks-ass.net> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Thu, 28 Sep 2023 07:43:37 -0700 (PDT) On Thu, 28 Sep 2023 12:39:26 +0200 Peter Zijlstra wrote: > As always, are syscalls really *that* expensive? Why can't we busy wait > in the kernel instead? Yes syscalls are that expensive. Several years ago I had a good talk with Robert Haas (one of the PostgreSQL maintainers) at Linux Plumbers, and I asked him if they used futexes. His answer was "no". He told me how they did several benchmarks and it was a huge performance hit (and this was before Spectre/Meltdown made things much worse). He explained to me that most locks are taken just to flip a few bits. Going into the kernel and coming back was orders of magnitude longer than the critical sections. By going into the kernel, it caused a ripple effect and lead to even more contention. There answer was to implement their locking completely in user space without any help from the kernel. This is when I thought that having an adaptive spinner that could get hints from the kernel via memory mapping would be extremely useful. The obvious problem with their implementation is that if the owner is sleeping, there's no point in spinning. Worse, the owner may even be waiting for the spinner to get off the CPU before it can run again. But according to Robert, the gain in the general performance greatly outweighed the few times this happened in practice. But still, if userspace could figure out if the owner is running on another CPU or not, to act just like the adaptive mutexes in the kernel, that would prevent the problem of a spinner keeping the owner from running. -- Steve