From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/9400 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 17:49:32 +0100 Message-ID: <1456764572-18648-1-git-send-email-nathan@nathan7.eu> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1456764600 22933 80.91.229.3 (29 Feb 2016 16:50:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 29 Feb 2016 16:50:00 +0000 (UTC) Cc: Nathan Zadoks To: musl@lists.openwall.com Original-X-From: musl-return-9413-gllmg-musl=m.gmane.org@lists.openwall.com Mon Feb 29 17:49:54 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 1aaR16-0002YQ-Nl for gllmg-musl@m.gmane.org; Mon, 29 Feb 2016 17:49:52 +0100 Original-Received: (qmail 21872 invoked by uid 550); 29 Feb 2016 16:49:50 -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 21831 invoked from network); 29 Feb 2016 16:49:46 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nathan7.eu; s=google; h=from:to:cc:subject:date:message-id; bh=7G54lXECkwcbwlK9lfDmZ7pi5ymmxwBNTQ75yRMAygs=; b=OdtCaxUqK1sIlWLkWYiie/TXhe/f2kuUkrg3Y1X7hYfeLVUJ6hOBjZEgH9RH8WDvli /YI/5N1Rpa1G3mpOpcWwLithh5dxAiHCSR/FgsNRcQiGwo7xlCy5uBK8vCKjPnW/uNdy q6OilTNWqYW+gJQ++DrkvmE0+xG230WiRaE6s= 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; bh=7G54lXECkwcbwlK9lfDmZ7pi5ymmxwBNTQ75yRMAygs=; b=iJyeNnNhhwG0KplfW+h2bPAEOMlUmRWCZG5+IIi/NCk6Jin+Qr9xDG8dfgOeYt9vjw XL2LEVXp6/IJSyqMRnTExqpJdrvKZyrexPpiu4tvH8gTseXmMt8B/fXDVJPln6XVMbjy 67+xZDc/y4+DU4yDo/MFHw43SuczIAtmDkgjJuDwp+WXJIq4NaMc0r/ojZik/ZsAqmxv YCpcfZ0eBQgCIeOtusLE9VcIv8AtHfQGanSHURPek//f/QBcogjUd66Iwqecuf5sskXe b84WF2rdD3BDqCSarxQDPNBZ4tWijZhDS2J01QAP23jqc7mfe/L4nxo4Ki8rsNp0zIoo neKg== X-Gm-Message-State: AD7BkJLfZGp3qAQ4dqyiLiqHRBuQkpjzXEWl4752uBR5CONKa8VdVOGTHK2ao6RCg7Za2A== X-Received: by 10.28.126.8 with SMTP id z8mr6651292wmc.77.1456764575497; Mon, 29 Feb 2016 08:49:35 -0800 (PST) X-Mailer: git-send-email 2.7.1 Xref: news.gmane.org gmane.linux.lib.musl.general:9400 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 | 8 ++++++++ 2 files changed, 11 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..a5f8ea7 --- /dev/null +++ b/src/sched/sched_getcpu.c @@ -0,0 +1,8 @@ +#define _GNU_SOURCE +#include + +static int sched_getcpu(void) { + int c, s; + s = syscall(SYS_getcpu, &c, NULL, NULL); + return (s == 0) ? c : s; +} -- 2.7.1