Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3583406rwd; Mon, 29 May 2023 13:07:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5l9OSRew52NuqUYENvo8EOPEhE66+SRqZRPm9UEDQy4CmW+9aGmdoM9twmBT+UoxRkMZLP X-Received: by 2002:a05:6a00:c8d:b0:649:dd0d:69d1 with SMTP id a13-20020a056a000c8d00b00649dd0d69d1mr784803pfv.31.1685390836554; Mon, 29 May 2023 13:07:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685390836; cv=none; d=google.com; s=arc-20160816; b=OeDBxrMsk0hWnlh8oc5pmLJDorVl3dubA2XMEJlo+nluBGIAFZBVMA7t1TsWf+aA0B moIrCqQ3XU0Z+Z5wXBNLAALhXubeWdLhqhsjKxCAmvVkf0mLohSY2pFFkXL4uT34ER1K pvNVMMgjfUvweNoHjjMKqYjqPlxXMlenj1kxtA7ajn64W2zJ4U+1St1y8YVyKDMRIJvL TzoUBrsKsoF9BKHiLRM/aFhr6K+C2mZRaobOq0jf6w/yGmxGbdfp27w4wc3cXOam22X+ iOB+LuV0m8myHCuINQTiwgpyLtvexreX89WZadlZes7cwI3fvhLd1N75F/iNQeUIkoVP iSuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=0fXthF/2ascCghBZLDPZ883tlfN4yJLCLyV0TRiGRzU=; b=XDzM1XuxbG/zq3ir+qjiU3P4NWKWpRvvEGTV1Jz1nQi0SGh81Aqtqt9KSp8uPmnwiu Ixuns47x162mpNFkTniNq1XLRM0zXPKj6WaD0lmz6NZQXeyuNv+EaH83uAsgZOcA1xtO 4Y+QrCmTjlgfHJxIsjo3fK/ImThFhDNZKq08VCD16XpjzLz7kfeFFDAcwt88H+mIQGw+ rhdHq1KRDX18wVlX8lUNLRBIrryn0p1fGw4WrpL+GnDN47oaktT+9qhUK4G6o8jaUmv/ mwcrrZQIocRNmghSJNUV6CbfhIZR6oYiJjI0dGbBCn+k+yoh7K3CVoXt7JkIMlKARYAe q48w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=qKqixCkA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a185-20020a624dc2000000b0063b8f0a6f51si418683pfb.117.2023.05.29.13.07.01; Mon, 29 May 2023 13:07:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=qKqixCkA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229651AbjE2Tsz (ORCPT + 99 others); Mon, 29 May 2023 15:48:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbjE2Tsx (ORCPT ); Mon, 29 May 2023 15:48:53 -0400 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB2B7E3; Mon, 29 May 2023 12:48:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1685389720; bh=5Mv2iDY3/+/X26c7+oJN7S46E47FDbIxA4JnvM9t6LA=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=qKqixCkAmWIZJ9ueg9iXOFyyyfKXkToaxYQMR+WimJXBFlbMcwJuEg+tmoKI945V/ mhJsQKx2+spbbY875mXg3wdgD8FXxk1bu6lUNEB+e3J9yvuolZLaiNwBNmdf3RBkeJ BzD9jSp3prSUR0xoR30cSVbOwVKr73F9l7+ElQcx+rtwbHfPZCul1aFmnZf3FSH8FE 6U2UsMFuDNKS56jUbBmF4RAQ20wsqomYBc+HXP4pYFmDhY2fNs2zAVYZzA6obWsff5 NG8fCnmKYzx9K+yyIl/U+E373NqF63Z5zoiUl1SLV6xLIwjgvr88WG21kDJOpsqxEk e8txGroYFlKyQ== Received: from [172.16.0.134] (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4QVR0m1cVFz15tr; Mon, 29 May 2023 15:48:40 -0400 (EDT) Message-ID: <2c421e36-a749-7dc3-3562-7a8cf256df3c@efficios.com> Date: Mon, 29 May 2023 15:48:44 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [RFC PATCH v2 1/4] rseq: Add sched_state field to struct rseq To: Florian Weimer Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Thomas Gleixner , "Paul E . McKenney" , Boqun Feng , "H . Peter Anvin" , Paul Turner , linux-api@vger.kernel.org, Christian Brauner , David.Laight@ACULAB.COM, carlos@redhat.com, Peter Oskolkov , Alexander Mikhalitsyn , Chris Kennelly , Ingo Molnar , Darren Hart , Davidlohr Bueso , =?UTF-8?Q?Andr=c3=a9_Almeida?= , libc-alpha@sourceware.org, Steven Rostedt , Jonathan Corbet , Noah Goldstein , Daniel Colascione , longman@redhat.com References: <20230529191416.53955-1-mathieu.desnoyers@efficios.com> <20230529191416.53955-2-mathieu.desnoyers@efficios.com> <87wn0r6id9.fsf@oldenburg.str.redhat.com> Content-Language: en-US From: Mathieu Desnoyers In-Reply-To: <87wn0r6id9.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On 5/29/23 15:35, Florian Weimer wrote: > * Mathieu Desnoyers: > >> +/* >> + * rseq_sched_state should be aligned on the cache line size. >> + */ >> +struct rseq_sched_state { >> + /* >> + * Version of this structure. Populated by the kernel, read by >> + * user-space. >> + */ >> + __u32 version; >> + /* >> + * The state is updated by the kernel. Read by user-space with >> + * single-copy atomicity semantics. This field can be read by any >> + * userspace thread. Aligned on 32-bit. Contains a bitmask of enum >> + * rseq_sched_state_flags. This field is provided as a hint by the >> + * scheduler, and requires that the page holding this state is >> + * faulted-in for the state update to be performed by the scheduler. >> + */ >> + __u32 state; >> + /* >> + * Thread ID associated with the thread registering this structure. >> + * Initialized by user-space before registration. >> + */ >> + __u32 tid; >> +}; > > How does the version handshake protocol in practice? Given that this > user-allocated? Good point, I must admit that I have not thought this specific version protocol through. :) As you say, userspace is responsible for allocation, and the kernel is responsible for implementing features. Let's first see if we can get away with embedding these fields in struct rseq. > > 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 ? > > The TID field would be useful in its own right. Indeed, good point. While we are there, I wonder if we should use the thread_pointer() as lock identifier, or if the address of struct rseq is fine ? Thanks, Mathieu > > Thanks, > Florian > -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com