From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/9434 Path: news.gmane.org!not-for-mail From: Nathan Zadoks Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH 2/2] add sched_getcpu vDSO support Date: Wed, 2 Mar 2016 17:26:27 +0100 Message-ID: <1456935987-24047-3-git-send-email-nathan@nathan7.eu> References: <20160302055542.GN9349@brightrain.aerifal.cx> <1456935987-24047-1-git-send-email-nathan@nathan7.eu> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1456936020 1008 80.91.229.3 (2 Mar 2016 16:27:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 2 Mar 2016 16:27:00 +0000 (UTC) Cc: Nathan Zadoks To: musl@lists.openwall.com Original-X-From: musl-return-9447-gllmg-musl=m.gmane.org@lists.openwall.com Wed Mar 02 17:27:00 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1ab9c3-0005uU-9m for gllmg-musl@m.gmane.org; Wed, 02 Mar 2016 17:26:59 +0100 Original-Received: (qmail 30039 invoked by uid 550); 2 Mar 2016 16:26:56 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 28604 invoked from network); 2 Mar 2016 16:26:47 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nathan7.eu; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=65zFSGz2PCSkbj+13pl9TrCl0o/xHhSal+oP2xgp0L4=; b=F3RZr6Rj25Xk+HhbYsm1TFR+nkXRRsL1EQmASV5XERE6lBjyOJMSXPOHGpdmrcrfX/ eUYnr+p+XK2lWOdfvhvoGgSXL3j6hb0xRFDiFWnJFdf96Q1+5bRUKNyMx4t7ZiLdd5EY /anNl/8IdNg+lmSxqw1VWEfGehSLZi2cIyXz8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=65zFSGz2PCSkbj+13pl9TrCl0o/xHhSal+oP2xgp0L4=; b=IQ4+TGLs6MtTy/GoQi3PJ4epBwIgytbBD8RXs6mBi0M47CpmDxeXkKlo5crzQky58k U5g0ket6Mahj4e9sSvphidO8VMIGpsN5Zkt+/i4VYBE/21c8Z8umE7m14hRnflkNWDsy nBsuLlyd8vBYwZZSwSUvN1ypHYXxke6A08fKwnihVP4vL0Ip/ptqUy/6R3x3tCvCmTAh A4xysa4v6Bc2D0UeXSCS7GRrvVGt8hnOfuDL95gqVgmhqMWRm+EM5WL36uIgq1+zgvNg ScjYm5MiK5yiKqIV+dDRuT2SwFAnwtwy90enqouJ/DPciqsi0G4BNb2SI/FnvZwe95Nh 6g+g== X-Gm-Message-State: AD7BkJIRh3g6ltwArGnioiip89FJifCqNB4NSwC7BfrDiA0DjBb41xZBv+1u7xdwTmvetQ== X-Received: by 10.28.150.148 with SMTP id y142mr839197wmd.55.1456935996413; Wed, 02 Mar 2016 08:26:36 -0800 (PST) X-Mailer: git-send-email 2.7.1 In-Reply-To: <1456935987-24047-1-git-send-email-nathan@nathan7.eu> Xref: news.gmane.org gmane.linux.lib.musl.general:9434 Archived-At: This brings the call to an actually usable speed. Quick unscientific benchmark: 14ns : 102ns :: vDSO : syscall --- arch/x86_64/syscall_arch.h | 2 ++ src/sched/sched_getcpu.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/arch/x86_64/syscall_arch.h b/arch/x86_64/syscall_arch.h index a7a7b5a..54e05ff 100644 --- a/arch/x86_64/syscall_arch.h +++ b/arch/x86_64/syscall_arch.h @@ -64,3 +64,5 @@ static __inline long __syscall6(long n, long a1, long a2, long a3, long a4, long #define VDSO_USEFUL #define VDSO_CGT_SYM "__vdso_clock_gettime" #define VDSO_CGT_VER "LINUX_2.6" +#define VDSO_GETCPU_SYM "__vdso_getcpu" +#define VDSO_GETCPU_VER "LINUX_2.6" diff --git a/src/sched/sched_getcpu.c b/src/sched/sched_getcpu.c index 760e4d5..e08cfdf 100644 --- a/src/sched/sched_getcpu.c +++ b/src/sched/sched_getcpu.c @@ -1,12 +1,43 @@ #define _GNU_SOURCE +#include #include #include "syscall.h" +#include "atomic.h" + +#ifdef VDSO_GETCPU_SYM + +void *__vdsosym(const char *, const char *); + +static void *volatile vdso_func; + +typedef long (*getcpu_f)(unsigned *, unsigned *, void *); + +static long getcpu_init(unsigned *cpu, unsigned *node, void *unused) +{ + void *p = __vdsosym(VDSO_GETCPU_VER, VDSO_GETCPU_SYM); + getcpu_f f = (getcpu_f)p; + a_cas_p(&vdso_func, (void *)getcpu_init, p); + return f ? f(cpu, node, unused) : -ENOSYS; +} + +static void *volatile vdso_func = (void *)getcpu_init; + +#endif int sched_getcpu(void) { int r; unsigned cpu; +#ifdef VDSO_GETCPU_SYM + getcpu_f f = (getcpu_f)vdso_func; + if (f) { + r = f(&cpu, 0, 0); + if (!r) return cpu; + if (r != -ENOSYS) return __syscall_ret(r); + } +#endif + r = __syscall(SYS_getcpu, &cpu, 0, 0); if (!r) return cpu; return __syscall_ret(r); -- 2.7.1