From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/9415 Path: news.gmane.org!not-for-mail From: Nathan Zadoks Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] add sched_getcpu Date: Mon, 29 Feb 2016 21:49:34 +0100 Message-ID: <1456778974-8825-1-git-send-email-nathan@nathan7.eu> References: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1456779013 11068 80.91.229.3 (29 Feb 2016 20:50:13 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 29 Feb 2016 20:50:13 +0000 (UTC) Cc: Nathan Zadoks To: musl@lists.openwall.com Original-X-From: musl-return-9428-gllmg-musl=m.gmane.org@lists.openwall.com Mon Feb 29 21:50:06 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 1aaUlW-0008B0-SZ for gllmg-musl@m.gmane.org; Mon, 29 Feb 2016 21:50:02 +0100 Original-Received: (qmail 28330 invoked by uid 550); 29 Feb 2016 20:50:00 -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 28288 invoked from network); 29 Feb 2016 20:49:56 -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=QgAp4S9YSICV+XULV8DndTjsuh6zpz/v5XETHtf4pJ8=; b=bEoFIWcPza+a7brWV026JWfPnxNihGRL2Va75xWJNWKaxcCxcdng5RZEFGaty6EIIV t3mt1pAUQXhzJHhyGGvq2IERURhRREkSPQY8lB4v8d90h+7y3vs9QdzKqcfFvoTgOeNc UtYBEm5upz+JsmhMWCU6Zqf00ukTfk/Z+mzdg= 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=QgAp4S9YSICV+XULV8DndTjsuh6zpz/v5XETHtf4pJ8=; b=FBm4n/pgfPwjdvqYLLD9BJrNV0zck32TugLJzbyJ+7uwoGs6a9VTyLf9D+q9TYlGCY v8IFmC8k0GSygKBc5WTBadle33Hpi4LIpJuiH25kFMzJz65i3GcTvKIMt8UufHkaYf/m V1QlbKGARhcP7I9on290AUYnHRcGbkbeGX/BMsEqT0TLtgwdP8nztM7wEKRNmDl/8Efc CArlSKOw6b/IUUntXnUZEr9fjyjFVGhZuyt9zg9C4zfcdVOSJA/73YRjfCkNu7iEPswC l28yd1NFxiF0x12DQsR5YWu8dw8nuay2WOF1LjJG3kf1qvIc+P2lRYRA8eZbT18UCfyk n9+A== X-Gm-Message-State: AD7BkJIKuroWEtCrhsiTU8p7vhBtdi3FNX//u1tyJs8QfMg9UvDWGJogjBYNlC5zu5vywg== X-Received: by 10.28.126.205 with SMTP id z196mr12771417wmc.44.1456778984930; Mon, 29 Feb 2016 12:49:44 -0800 (PST) X-Mailer: git-send-email 2.7.1 In-Reply-To: Xref: news.gmane.org gmane.linux.lib.musl.general:9415 Archived-At: This is a GNU extension, but a fairly minor one, for a system call that otherwise has no libc wrapper. Adding it was discussed previously, without any objections: http://www.openwall.com/lists/musl/2015/05/08/24 --- include/sched.h | 3 +++ src/sched/sched_getcpu.c | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 src/sched/sched_getcpu.c diff --git a/include/sched.h b/include/sched.h index 3e34a72..17f5e06 100644 --- a/include/sched.h +++ b/include/sched.h @@ -76,6 +76,9 @@ void free(void *); typedef struct cpu_set_t { unsigned long __bits[128/sizeof(long)]; } cpu_set_t; int __sched_cpucount(size_t, const cpu_set_t *); +#ifdef _GNU_SOURCE +int sched_getcpu(void); +#endif int sched_getaffinity(pid_t, size_t, cpu_set_t *); int sched_setaffinity(pid_t, size_t, const cpu_set_t *); diff --git a/src/sched/sched_getcpu.c b/src/sched/sched_getcpu.c new file mode 100644 index 0000000..f34d84a --- /dev/null +++ b/src/sched/sched_getcpu.c @@ -0,0 +1,11 @@ +#define _GNU_SOURCE +#include +#include +#include "syscall.h" + +int sched_getcpu(void) +{ + int c, s; + s = __syscall(SYS_getcpu, &c, NULL, NULL); + return __syscall_ret((s == 0) ? c : s); +} -- 2.7.1