Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2310282rdh; Tue, 26 Sep 2023 21:09:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGak27h6es13UccDZM2ABTvHSEQOA9TcYAPRrfregY9e3eA0/vb3/+gQt3kAwLA0tqhLJs5 X-Received: by 2002:a05:6a20:244d:b0:15d:b243:6131 with SMTP id t13-20020a056a20244d00b0015db2436131mr883158pzc.44.1695787756992; Tue, 26 Sep 2023 21:09:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695787756; cv=none; d=google.com; s=arc-20160816; b=IAPg385AkMCKv8TcYKQOegBHOYR1794wRhqYaiP9oRtSfiG1QKE0peE/rvJJ+ntAFw drSspQW9dBPQ3Qel8OCuA3a8YyHotL13ed8QY2dMrd8OC3GXc5fHbb3aQbP4qPs2iezC mSc5sA0vP9aez7T9VZCbvHLUXnw0mLQKsFeVYYeixt8bZa5QPiz0fOjp8wEYmR9ZwuW5 ohniQvtfELJKFVvTyqDlsz3W5lBzkB12xaq906XAaKCkUXCWknB0qKko93uIpIZCsXAp pciFQRZt0hv7rjQbYL99wIRb7eBpY4bsjqvUKL69+FkKg4VPcC8xgOKjccMhsPZ4Pk0Q DwbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=xrypDOHQ7EnWLT1fAC4mj+J/Ny7QwGyNqoMoBzWEChA=; fh=XJxOFGgANgqIYXRssxX3IPLCbfNcCQG8AUfLxtcvbFA=; b=HxC+4e2gMKBsGvWKDuxeDCAwIrSmD0lSaaLAYpqngyGzhsnIdsds6lgeOmSl9v/gTC 4UjBJxOwXzdERiXD+kSOik86jky+HXfO07brGaaYU7l06C5uYLqGPjTSKzsU9nP38HR0 VGyI8laAnHyq+5ETlX2bxmVHUqAFMIhavXAcqj86tiNBjE6xT5neAdl6Vj+KY3mxhzXE 6g1qEl0I74Zgw1RaJMviEAk4aqkaSEfsIajMBoNK74LZ552kjqwQSQg4pMcrlk4brgXG ybVgrLb16kKSvzdokNnsJMGp86CXc87aw5NMPbv5f1WTwtBwY4sSwGTChIo2WKzvZLdK M49Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="qz/8NKvG"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id w10-20020a17090aea0a00b00278f81e54cdsi1167423pjy.19.2023.09.26.21.09.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 21:09:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="qz/8NKvG"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 6F57480BC105; Tue, 26 Sep 2023 13:52:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233344AbjIZUwh (ORCPT + 99 others); Tue, 26 Sep 2023 16:52:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232698AbjIZUwf (ORCPT ); Tue, 26 Sep 2023 16:52:35 -0400 Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 755EC120 for ; Tue, 26 Sep 2023 13:52:28 -0700 (PDT) Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-322d2acf4abso6364618f8f.0 for ; Tue, 26 Sep 2023 13:52:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695761547; x=1696366347; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xrypDOHQ7EnWLT1fAC4mj+J/Ny7QwGyNqoMoBzWEChA=; b=qz/8NKvGkybGhqCFZBHy2QOWUDiatqVuQzbEOQGhwf/uf6vRjGCT069ftKn55Ne3do HmcPIihWscn9WK89fuGIrLkDxGaDDUPq/woote2ARyyV/dXu3wzQTu9GB4pwGTX7+oGF AYcckj9arQQLrNM+hABMwvK9cBfduO3t2oYuyB1vBQ5K4YrjHnPDfHsUAecuQsehB1ph w8xkZMwcSWf08cIcmD1ZpwqfYu04lG3F4AHRFYONPdAKI5hpeCT000B2YaDBpZpFDK2M 9ucxzfQKpAfQgK1XO4DtN+Jc646MTLczngtbpg7BpxRQRcwIXxD5j4dmgErgd8Sd/KH1 PHMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695761547; x=1696366347; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xrypDOHQ7EnWLT1fAC4mj+J/Ny7QwGyNqoMoBzWEChA=; b=o/A94zaTlQ4U445NaPSeAENon80M1hC0u+M5GCP7EUwXnk25WhsKcju3wRi/hKV3uJ mh0Afj53wVuoFjoNlzYamh75K2fTbULWygS+Oc/GPfQV+fOzYLeW4Z2oZYvyN0ctCh2u 9a+42X/Jc3wTp0bY+NDLT8qYWXjvfDewNXtg7jfWbRKCuL5Z+a2Ly1xhxP7pCMkaK2HQ UTsMkr4NmYqdZfVhTH7vVLg7O8aaF37gfUbFnOVjlJwwljO0OaDwvUJpLy0HMqWW++0c GWe48g6a4GBgvRuXeU4trFalb+jnpC/yUQhVLmTNsA4/I7D8/UCtp6Ss8KQ3NF3F0GIP xNcA== X-Gm-Message-State: AOJu0YyQMfgRWDTUNDqDLwSYR3kZ8OZ5nwES4bUUroYHoX44nFxjd96c miC5dbmyBlmylRcQE/7iCs5L5Ry+VIlX X-Received: from dvyukov-desk.muc.corp.google.com ([2a00:79e0:9c:201:2a5f:6690:fe14:d69a]) (user=dvyukov job=sendgmr) by 2002:a5d:4b90:0:b0:321:a6b5:b50e with SMTP id b16-20020a5d4b90000000b00321a6b5b50emr57461wrt.11.1695761546817; Tue, 26 Sep 2023 13:52:26 -0700 (PDT) Date: Tue, 26 Sep 2023 22:52:15 +0200 In-Reply-To: <2c421e36-a749-7dc3-3562-7a8cf256df3c@efficios.com> Mime-Version: 1.0 References: <2c421e36-a749-7dc3-3562-7a8cf256df3c@efficios.com> X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Message-ID: <20230926205215.472650-1-dvyukov@google.com> Subject: Re: [RFC PATCH v2 1/4] rseq: Add sched_state field to struct rseq From: Dmitry Vyukov To: mathieu.desnoyers@efficios.com Cc: David.Laight@ACULAB.COM, alexander@mihalicyn.com, andrealmeid@igalia.com, boqun.feng@gmail.com, brauner@kernel.org, carlos@redhat.com, ckennelly@google.com, corbet@lwn.net, dancol@google.com, dave@stgolabs.net, dvhart@infradead.org, fweimer@redhat.com, goldstein.w.n@gmail.com, hpa@zytor.com, libc-alpha@sourceware.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, longman@redhat.com, mingo@redhat.com, paulmck@kernel.org, peterz@infradead.org, pjt@google.com, posk@posk.io, rostedt@goodmis.org, tglx@linutronix.de Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Tue, 26 Sep 2023 13:52:36 -0700 (PDT) >> I don't see why we can't stick this directly into struct rseq because >> it's all public anyway. > > The motivation for moving this to a different cache line is to handle > the prior comment from Boqun, who is concerned that busy-waiting > repeatedly loading a field from struct rseq will cause false-sharing and > make other stores to that cache line slower, especially stores to > rseq_cs to begin rseq critical sections, thus slightly increasing the > overhead of rseq critical sections taken while mutexes are held. > > If we want to embed this field into struct rseq with its own cache line, > then we need to add a lot of padding, which is inconvenient. > > That being said, perhaps this is premature optimization, what do you think ? Hi Mathieu, Florian, This is exciting! I thought the motivation for moving rseq_sched_state out of struct rseq is lifetime management problem. I assume when a thread locks a mutex, it stores pointer to rseq_sched_state in the mutex state for other threads to poll. So the waiting thread would do something along the following lines: rseq_sched_state* state = __atomic_load_n(mutex->sched_state, __ATOMIC_RELAXED); if (state && !(state->state & RSEQ_SCHED_STATE_FLAG_ON_CPU)) futex_wait(); Now if the state is struct rseq, which is stored in TLS, then the owning thread can unlock the mutex, exit and unmap TLS in between. Consequently, load of state->state will cause a paging fault. And we do want rseq in TLS to save 1 indirection. If rseq_sched_state is separated from struct rseq, then it can be allocated in type stable memory that is never unmapped. What am I missing here? However, if we can store this state in struct rseq, then an alternative interface would for the kernel to do: rseq->cpu_id = -1; to denote that the thread is not running on any CPU. I think it kinda makes sense, rseq->cpu_id is the thread's current CPU, and -1 naturally means "not running at all". And we already store -1 right after init, so it shouldn't be a surprising value.