Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp999267img; Fri, 22 Mar 2019 13:14:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqxGcwoAM3WQTb6FvQz57WCO/Jbuk7nRBqly/j014kMkq/dinptPrHJCwQjrfz/a1ZkHTg0v X-Received: by 2002:a17:902:7b8c:: with SMTP id w12mr11437303pll.153.1553285688925; Fri, 22 Mar 2019 13:14:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553285688; cv=none; d=google.com; s=arc-20160816; b=sAk9ZL1LtHPIn2TEHEQZgiAth2LC96u5gD5uRDpikBk4mYRsbL6ecyLKX7LdhwByky OZ2wm7RAKbh+hpiwjC6VAcEQq0Y3Sv22qeoIGHfebVKZs03pRt5Y3AhLttSK7HgCUvZR sEOf42UjTlTPhSkafhLBQBfDCHd2Loq6TpA4DhGtwEJoLMSvUnWScVdQyOgN7T+BJPXP t+NRSgeS6vt4azrYiVhFiKZ6oiRzCCpkLzd7G0H970NRtKboHIJzCsPOx6HuNMPav0/1 tJjYks0cXF5zZikCjYIgzgJgoqJJNgUEoNoLUc9Gg+ONqqN8iT/2j5vcvJnACWkefL4k F0Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=3GVlQtUkOBzM0wtGS5EMCR1UzhxBjccrlpb4vEqZEkU=; b=IyXXtGzED0YnitUrkDHUNFM2Tgkw/SpYQVKdAh26lcy9hJgXX9wUGMkHGutqp6h6kk FFEvQ++cpjFQq8KdAx14MdzsB0FTeaPbxMDMqAtsIf1NAhjevoEh1tm2RXmVOV2oxFh+ 2rDHI8sDMrCVL7S/JIsm7DvevPognz3fny9O8LWUYjgRLz6OxSqNWa3bnqaUh7n/rxwv x3RSRSDxcIyDu6Z5xSslA9ynNPc83XJ0GRKeHcGbouyjD+UwM0724tnGwVMyOOgOKS+2 1EoCixk82gdPZK3nUXPVxKX8PSV6G0UTcRyAc/8RgsOQYKXUdm8A+WSyLA79SJpVlcaR LYpA== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w16si7649817plq.173.2019.03.22.13.14.33; Fri, 22 Mar 2019 13:14:48 -0700 (PDT) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726910AbfCVUN7 (ORCPT + 99 others); Fri, 22 Mar 2019 16:13:59 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:35342 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726093AbfCVUN6 (ORCPT ); Fri, 22 Mar 2019 16:13:58 -0400 Received: by mail-qk1-f194.google.com with SMTP id z13so2004382qki.2 for ; Fri, 22 Mar 2019 13:13:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=3GVlQtUkOBzM0wtGS5EMCR1UzhxBjccrlpb4vEqZEkU=; b=m5HBWVT1I+8uCJp8o8inPJRaFAxT5N9XejSgHG5ZZoGtfESbUsip4lE3dGbk5cUr0u ZlzaWXmBqmzHhuYU1ZDLtBNbvKx1qlW+1L69L+DzGQjAIxo9LnBvTcdz9Ucc/mRyxdPE +iPy2q1OUus+HbrgKZOExIG3drQ4dWWVNRdzUCNXr4C69cMFidvRZObrzRHJhnWrtzBN Xfr/QZFhdlVae95A/g7AkRdl9YubD9hi+F8LYI2WPJfdX2wjAIikGRcHBKV5r5XnBntW d7a+WFAUhhLNzNHQRb0sRqY1cKcXDLZEHsZV0viV2dH/yMBJOyAEcJFFHeN5vVWAvQ3Z tcEg== X-Gm-Message-State: APjAAAXC78ue6r18Q9zjaJCkzUcnx11rLBpfbe01vn81r5sfT2U3u1qC NHRMejB7L9r6GwFj3zmcmqcJmA== X-Received: by 2002:ae9:f509:: with SMTP id o9mr9198639qkg.133.1553285637702; Fri, 22 Mar 2019 13:13:57 -0700 (PDT) Received: from [10.150.73.190] (178.sub-174-227-146.myvzw.com. [174.227.146.178]) by smtp.gmail.com with ESMTPSA id 92sm5508111qtc.97.2019.03.22.13.13.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Mar 2019 13:13:57 -0700 (PDT) Subject: Re: [PATCH 2/4] glibc: sched_getcpu(): use rseq cpu_id TLS on Linux To: Mathieu Desnoyers , Carlos O'Donell Cc: Florian Weimer , Joseph Myers , Szabolcs Nagy , libc-alpha@sourceware.org, Thomas Gleixner , Ben Maurer , Peter Zijlstra , "Paul E. McKenney" , Boqun Feng , Will Deacon , Dave Watson , Paul Turner , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org References: <20190212194253.1951-1-mathieu.desnoyers@efficios.com> <20190212194253.1951-3-mathieu.desnoyers@efficios.com> From: Carlos O'Donell Message-ID: Date: Fri, 22 Mar 2019 16:13:52 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.3 MIME-Version: 1.0 In-Reply-To: <20190212194253.1951-3-mathieu.desnoyers@efficios.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/12/19 2:42 PM, Mathieu Desnoyers wrote: > When available, use the cpu_id field from __rseq_abi on Linux to > implement sched_getcpu(). Fall-back on the vgetcpu vDSO if unavailable. > > Benchmarks: > > x86-64: Intel E5-2630 v3@2.40GHz, 16-core, hyperthreading This patch looks good to me for master, but is blocked on patch 1/4 being reworked. Reviewed-by: Carlos O'Donell > glibc sched_getcpu(): 13.7 ns (baseline) > glibc sched_getcpu() using rseq: 2.5 ns (speedup: 5.5x) > inline load cpuid from __rseq_abi TLS: 0.8 ns (speedup: 17.1x) > > Signed-off-by: Mathieu Desnoyers > CC: Carlos O'Donell > CC: Florian Weimer > CC: Joseph Myers > CC: Szabolcs Nagy > CC: Thomas Gleixner > CC: Ben Maurer > CC: Peter Zijlstra > CC: "Paul E. McKenney" > CC: Boqun Feng > CC: Will Deacon > CC: Dave Watson > CC: Paul Turner > CC: libc-alpha@sourceware.org > CC: linux-kernel@vger.kernel.org > CC: linux-api@vger.kernel.org > --- > sysdeps/unix/sysv/linux/sched_getcpu.c | 25 +++++++++++++++++++++++-- > 1 file changed, 23 insertions(+), 2 deletions(-) > > diff --git a/sysdeps/unix/sysv/linux/sched_getcpu.c b/sysdeps/unix/sysv/linux/sched_getcpu.c > index fb0d317f83..8bfb03778b 100644 > --- a/sysdeps/unix/sysv/linux/sched_getcpu.c > +++ b/sysdeps/unix/sysv/linux/sched_getcpu.c > @@ -24,8 +24,8 @@ > #endif > #include > > -int > -sched_getcpu (void) > +static int > +vsyscall_sched_getcpu (void) OK. > { > #ifdef __NR_getcpu > unsigned int cpu; > @@ -37,3 +37,24 @@ sched_getcpu (void) > return -1; > #endif > } > + > +#ifdef __NR_rseq > +#include > + > +extern __attribute__ ((tls_model ("initial-exec"))) > +__thread volatile struct rseq __rseq_abi; OK. > + > +int > +sched_getcpu (void) > +{ > + int cpu_id = __rseq_abi.cpu_id; > + > + return cpu_id >= 0 ? cpu_id : vsyscall_sched_getcpu (); OK. Impressive :-) > +} > +#else > +int > +sched_getcpu (void) > +{ > + return vsyscall_sched_getcpu (); OK. > +} > +#endif > -- Cheers, Carlos.