Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8627631imu; Tue, 4 Dec 2018 11:22:51 -0800 (PST) X-Google-Smtp-Source: AFSGD/WrDQmQG2bIhvtNbmO/z4NAM+l6QBLGXfb+wEZRKk0sQPd9Tg11hOMifwuwRnrQbH7nYXTt X-Received: by 2002:a17:902:5601:: with SMTP id h1mr21727499pli.160.1543951371632; Tue, 04 Dec 2018 11:22:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543951371; cv=none; d=google.com; s=arc-20160816; b=IDrDZgK+LAebeqihOggy//OuBIwaOFWilBiOrrMF+i9h51hPPHIm0Xo5dud9kXyH6L djCBsz72VdZjz2rTBL8IS+VcRWFABLJH1CrU2/LgrjYzPpvPf8xc1mfPLLVMY6BhLX6D IVGfCGSUFsgF5GtQ5L1hnZYpJUWBH/Z71AdMRbQTwv6CPrlHlDZO5M9rMdOlU/P8/brw q5sV49RlP+/V+BIoVE4Al+ygM2SKuXoWMcJSE8ttojZgSus/AjzfQCA1aUrJnuvSIinm pc/VPvnZFAnI3ugs041gVEEEIiQK3e+W8/6qPZcy6a++2VNzDW/BoyOfl1/sRLseqLh/ DGUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=emmEvvmvg4LpJ76voI4pvfqiprYl4MAXxEB0bZnS5JQ=; b=oINdyT4PAmZG03s5hLmYsWqQYWkAZR2N2oy324VUDyv4rRwssfrpDStluAxTAUO9eN kFE5DVi1PSZtbzRwc/46316MXssLlXXVLGZI80z72ApBM3NpN3Zxa6+elnki3bzaofQy txfOs6L3rnbjqJyYMThQ8dE8dgBioK9AIOwVZ4drTuQE4vfXMAQsu6dSrY1o/bBkbscM c3keXnqky9rbhtk46KtkbRxfczc6FCliAJ8KjEBb+eWXnSt4LfZdCOJYFQatazzlBQy9 BLgRwLhyDdwsYUntPf0XHrpVIeP40xHePbliGDw6sQdrqY4QVT+N5+M5iuhbYgRNkXWL JIWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=IOYy0yXG; 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=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q13si14451605pgj.86.2018.12.04.11.22.36; Tue, 04 Dec 2018 11:22:51 -0800 (PST) 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; dkim=pass header.i=@efficios.com header.s=default header.b=IOYy0yXG; 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=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726179AbeLDTV7 (ORCPT + 99 others); Tue, 4 Dec 2018 14:21:59 -0500 Received: from mail.efficios.com ([167.114.142.138]:55998 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725841AbeLDTV7 (ORCPT ); Tue, 4 Dec 2018 14:21:59 -0500 Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 8570D9E527; Tue, 4 Dec 2018 14:21:57 -0500 (EST) Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id voCoZgA-2l_C; Tue, 4 Dec 2018 14:21:56 -0500 (EST) Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 14F6D9E50F; Tue, 4 Dec 2018 14:21:56 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 14F6D9E50F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1543951316; bh=emmEvvmvg4LpJ76voI4pvfqiprYl4MAXxEB0bZnS5JQ=; h=From:To:Date:Message-Id; b=IOYy0yXGSuOIzVvzCDlLiGd/QbJlrZh/zYReiOmzMC7TTD8jSRx1lwHA2TY61QEdl HuyIYtOGfuyrzaEL2DhcrWHziwST81GrbrFqb9KH1/kYdUMjdG+fYENILklN252LwS J9eieTJW83UJf43ZkoDyHw33+jooTWl7Oj8qd9FlfRvobXA1VzsgCjC8X3IDbq/52c VeZAZe8IyAYlAWzfFu/aPVzeQAY3Y8ok2v2UDH1cEXjtTO/ewy2gRCRi+aso1ySYD3 KyDT1CKUc/lh6SU+KDSKhp8bxMplmbSv8rWnI399wS2SywnQxcacHOnqGpSzNHzy8Q lX8zFXWEddk/Q== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id CqFzBECGyR1j; Tue, 4 Dec 2018 14:21:56 -0500 (EST) Received: from localhost.localdomain (192-222-157-41.qc.cable.ebox.net [192.222.157.41]) by mail.efficios.com (Postfix) with ESMTPSA id BA2CF9E501; Tue, 4 Dec 2018 14:21:55 -0500 (EST) From: Mathieu Desnoyers To: Carlos O'Donell Cc: Florian Weimer , Joseph Myers , Szabolcs Nagy , libc-alpha@sourceware.org, Mathieu Desnoyers , 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 Subject: [RFC PATCH glibc 2/4] glibc: sched_getcpu(): use rseq cpu_id TLS on Linux Date: Tue, 4 Dec 2018 14:21:39 -0500 Message-Id: <20181204192141.4684-2-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181204192141.4684-1-mathieu.desnoyers@efficios.com> References: <20181204192141.4684-1-mathieu.desnoyers@efficios.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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 b69eeda15c..37fda59d36 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) { #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; + +int +sched_getcpu (void) +{ + int cpu_id = __rseq_abi.cpu_id; + + return cpu_id >= 0 ? cpu_id : vsyscall_sched_getcpu (); +} +#else +int +sched_getcpu (void) +{ + return vsyscall_sched_getcpu (); +} +#endif -- 2.17.1