linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [patch] Simple Topology API v0.3 (2/2)
@ 2002-08-22 19:15 Matthew Dobson
  2002-08-22 19:24 ` [Lse-tech] " Christoph Hellwig
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Dobson @ 2002-08-22 19:15 UTC (permalink / raw)
  To: Andrew Morton, Linus Torvalds, linux-kernel, linux-mm
  Cc: Martin Bligh, Andrea Arcangeli, Michael Hohnbaum, lse-tech

[-- Attachment #1: Type: text/plain, Size: 452 bytes --]

Andrew, Linus, et al:
	Here's the latest version of the Simple Topology API.  I've broken the patches 
into a solely in-kernel portion, and a portion that exposes the API to 
userspace via syscalls and prctl.  This patch (part 2) is the userspace part. I 
hope that the smaller versions of these patches will draw more feedback, 
comments, flames, etc.  Other than that, the patch remains relatively unchanged 
from the last posting.

Cheers!

-Matt



[-- Attachment #2: simple_topo-v0.3-userspace-2.5.31.patch --]
[-- Type: text/plain, Size: 8925 bytes --]

diff -Nur linux-2.5.27-vanilla/arch/i386/kernel/entry.S linux-2.5.27-api/arch/i386/kernel/entry.S
--- linux-2.5.27-vanilla/arch/i386/kernel/entry.S	Sat Jul 20 12:11:11 2002
+++ linux-2.5.27-api/arch/i386/kernel/entry.S	Wed Jul 24 17:33:41 2002
@@ -753,6 +753,7 @@
 	.long sys_sched_setaffinity
 	.long sys_sched_getaffinity
 	.long sys_set_thread_area
+	.long sys_check_topology
 
 	.rept NR_syscalls-(.-sys_call_table)/4
 		.long sys_ni_syscall
diff -Nur linux-2.5.27-vanilla/include/asm-i386/unistd.h linux-2.5.27-api/include/asm-i386/unistd.h
--- linux-2.5.27-vanilla/include/asm-i386/unistd.h	Sat Jul 20 12:11:26 2002
+++ linux-2.5.27-api/include/asm-i386/unistd.h	Wed Jul 24 17:33:41 2002
@@ -248,6 +248,7 @@
 #define __NR_sched_setaffinity	241
 #define __NR_sched_getaffinity	242
 #define __NR_set_thread_area	243
+#define __NR_check_topology	244
 
 /* user-visible error numbers are in the range -1 - -124: see <asm-i386/errno.h> */
 
diff -Nur linux-2.5.27-vanilla/include/linux/prctl.h linux-2.5.27-api/include/linux/prctl.h
--- linux-2.5.27-vanilla/include/linux/prctl.h	Sat Jul 20 12:11:22 2002
+++ linux-2.5.27-api/include/linux/prctl.h	Wed Jul 24 17:33:41 2002
@@ -26,4 +26,8 @@
 # define PR_FPEMU_NOPRINT	1	/* silently emulate fp operations accesses */
 # define PR_FPEMU_SIGFPE	2	/* don't emulate fp operations, send SIGFPE instead */
 
+/* Get CPU/Node */
+#define PR_GET_CURR_CPU		11
+#define PR_GET_CURR_NODE    	12
+
 #endif /* _LINUX_PRCTL_H */
diff -Nur linux-2.5.27-vanilla/include/linux/topology.h linux-2.5.27-api/include/linux/topology.h
--- linux-2.5.27-vanilla/include/linux/topology.h	Wed Dec 31 16:00:00 1969
+++ linux-2.5.27-api/include/linux/topology.h	Wed Jul 24 17:33:41 2002
@@ -0,0 +1,46 @@
+/*
+ * linux/include/linux/topology.h
+ *
+ * Written by: Matthew Dobson, IBM Corporation
+ *
+ * Copyright (C) 2002, IBM Corp.
+ *
+ * All rights reserved.          
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ * NON INFRINGEMENT.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Send feedback to <colpatch@us.ibm.com>
+ */
+#ifndef _LINUX_TOPOLOGY_H
+#define _LINUX_TOPOLOGY_H
+
+/* For topology conversion functions */
+#define CPU_TO_NODE		1
+#define MEMBLK_TO_NODE      	2
+#define NODE_TO_NODE		3
+#define NODE_TO_CPU		4
+#define NODE_TO_MEMBLK      	5
+
+/* Prototypes */
+int cpu_to_node(int);
+int memblk_to_node(int);
+int node_to_node(int);
+int node_to_cpu(int);
+int node_to_memblk(int);
+int get_curr_cpu(void);
+int get_curr_node(void);
+
+#endif /* _LINUX_TOPOLOGY_H */
diff -Nur linux-2.5.27-vanilla/kernel/Makefile linux-2.5.27-api/kernel/Makefile
--- linux-2.5.27-vanilla/kernel/Makefile	Sat Jul 20 12:11:10 2002
+++ linux-2.5.27-api/kernel/Makefile	Wed Jul 24 17:33:41 2002
@@ -15,7 +15,8 @@
 obj-y     = sched.o fork.o exec_domain.o panic.o printk.o \
 	    module.o exit.o itimer.o time.o softirq.o resource.o \
 	    sysctl.o capability.o ptrace.o timer.o user.o \
-	    signal.o sys.o kmod.o context.o futex.o platform.o
+	    signal.o sys.o kmod.o context.o futex.o platform.o \
+	    topology.o
 
 obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
 obj-$(CONFIG_SMP) += cpu.o
diff -Nur linux-2.5.27-vanilla/kernel/sys.c linux-2.5.27-api/kernel/sys.c
--- linux-2.5.27-vanilla/kernel/sys.c	Sat Jul 20 12:11:07 2002
+++ linux-2.5.27-api/kernel/sys.c	Wed Jul 24 17:33:41 2002
@@ -20,6 +20,7 @@
 #include <linux/device.h>
 #include <linux/times.h>
 #include <linux/security.h>
+#include <linux/topology.h>
 
 #include <asm/uaccess.h>
 #include <asm/io.h>
@@ -1236,6 +1237,31 @@
 	mask = xchg(&current->fs->umask, mask & S_IRWXUGO);
 	return mask;
 }
+
+asmlinkage long sys_check_topology(int convert_type, int to_convert)
+{
+	int ret = 0;
+
+	switch (convert_type) {
+		case CPU_TO_NODE:
+			ret = cpu_to_node(to_convert);
+			break;
+		case MEMBLK_TO_NODE:
+			ret = memblk_to_node(to_convert);
+			break;
+		case NODE_TO_NODE:
+			ret = node_to_node(to_convert);
+			break;
+		case NODE_TO_CPU:
+			ret = node_to_cpu(to_convert);
+			break;
+		case NODE_TO_MEMBLK:
+			ret = node_to_memblk(to_convert);
+			break;
+	}
+
+	return (long)ret;
+}
     
 asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
 			  unsigned long arg4, unsigned long arg5)
@@ -1295,6 +1321,12 @@
 			}
 			current->keep_capabilities = arg2;
 			break;
+		case PR_GET_CURR_CPU:
+			error = get_curr_cpu();
+			break;
+		case PR_GET_CURR_NODE:
+			error = get_curr_node();
+			break;
 		default:
 			error = -EINVAL;
 			break;
diff -Nur linux-2.5.27-vanilla/kernel/topology.c linux-2.5.27-api/kernel/topology.c
--- linux-2.5.27-vanilla/kernel/topology.c	Wed Dec 31 16:00:00 1969
+++ linux-2.5.27-api/kernel/topology.c	Wed Jul 24 17:33:41 2002
@@ -0,0 +1,127 @@
+/*
+ * linux/kernel/topology.c
+ *
+ * Written by: Matthew Dobson, IBM Corporation
+ *
+ * Copyright (C) 2002, IBM Corp.
+ *
+ * All rights reserved.          
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ * NON INFRINGEMENT.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Send feedback to <colpatch@us.ibm.com>
+ */
+#include <linux/kernel.h>
+#include <linux/unistd.h>
+#include <linux/config.h>
+#include <linux/sched.h>
+#include <linux/mmzone.h>
+#include <linux/errno.h>
+#include <linux/smp.h>
+
+/*
+ * cpu_to_node(cpu): Returns the number of the most specific Node 
+ * containing CPU 'cpu'.
+ */
+inline int cpu_to_node(int cpu)
+{
+	if (cpu == -1)     /* return highest numbered node */
+		return (numnodes - 1);
+
+	if ((cpu < 0) || (cpu >= NR_CPUS) ||
+	    (!(cpu_online_map & (1 << cpu))))   /* invalid cpu # */
+		return -ENODEV;
+
+	return _cpu_to_node(cpu);
+}
+
+/*
+ * memblk_to_node(memblk): Returns the number of the most specific Node 
+ * containing Memory Block 'memblk'.
+ */
+inline int memblk_to_node(int memblk)
+{
+	if (memblk == -1)  /* return highest numbered node */
+		return (numnodes - 1);
+
+	if ((memblk < 0) || (memblk >= NR_MEMBLKS) ||
+	    (!(memblk_online_map & (1 << memblk))))   /* invalid memblk # */
+		return -ENODEV;
+
+	return _memblk_to_node(memblk);
+}
+
+/*
+ * node_to_node(nid): Returns the number of the of the most specific Node that
+ * encompasses Node 'nid'.  Some may call this the parent Node of 'nid'.
+ */
+int node_to_node(int nid)
+{
+	if ((nid < 0) || (nid >= numnodes))   /* invalid node # */
+		return -ENODEV;
+
+	return _node_to_node(nid);
+}
+
+/*
+ * node_to_cpu(nid): Returns the lowest numbered CPU on Node 'nid'
+ */
+inline int node_to_cpu(int nid)
+{
+	if (nid == -1)  /* return highest numbered cpu */
+		return (num_online_cpus() - 1);
+
+	if ((nid < 0) || (nid >= numnodes))   /* invalid node # */
+		return -ENODEV;
+
+	return _node_to_cpu(nid);
+}
+
+/*
+ * node_to_memblk(nid): Returns the lowest numbered MemBlk on Node 'nid'
+ */
+inline int node_to_memblk(int nid)
+{
+	if (nid == -1)  /* return highest numbered memblk */
+		return (num_online_memblks() - 1);
+
+	if ((nid < 0) || (nid >= numnodes))   /* invalid node # */
+		return -ENODEV;
+
+	return _node_to_memblk(nid);
+}
+
+/*
+ * get_curr_cpu(): Returns the currently executing CPU number.
+ * For now, this has only mild usefulness, as this information could
+ * change on the return from syscall (which automatically calls schedule()).
+ * Due to this, the data could be stale by the time it gets back to the user.
+ * It will have to do, until a better method is found.
+ */
+inline int get_curr_cpu(void)
+{
+	return smp_processor_id();
+}
+
+/*
+ * get_curr_node(): Returns the number of the Node containing 
+ * the currently executing CPU.  Subject to the same caveat
+ * as the get_curr_cpu() call.
+ */
+inline int get_curr_node(void)
+{
+	return cpu_to_node(get_curr_cpu());
+}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Lse-tech] [patch] Simple Topology API v0.3 (2/2)
  2002-08-22 19:15 [patch] Simple Topology API v0.3 (2/2) Matthew Dobson
@ 2002-08-22 19:24 ` Christoph Hellwig
  2002-08-22 20:45   ` Matthew Dobson
  0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2002-08-22 19:24 UTC (permalink / raw)
  To: Matthew Dobson
  Cc: Andrew Morton, Linus Torvalds, linux-kernel, linux-mm,
	Martin Bligh, Andrea Arcangeli, Michael Hohnbaum, lse-tech

On Thu, Aug 22, 2002 at 12:15:07PM -0700, Matthew Dobson wrote:
> diff -Nur linux-2.5.27-vanilla/kernel/sys.c linux-2.5.27-api/kernel/sys.c
> --- linux-2.5.27-vanilla/kernel/sys.c	Sat Jul 20 12:11:07 2002
> +++ linux-2.5.27-api/kernel/sys.c	Wed Jul 24 17:33:41 2002
> @@ -20,6 +20,7 @@
>  #include <linux/device.h>
>  #include <linux/times.h>
>  #include <linux/security.h>
> +#include <linux/topology.h>
>  
>  #include <asm/uaccess.h>
>  #include <asm/io.h>
> @@ -1236,6 +1237,31 @@
>  	mask = xchg(&current->fs->umask, mask & S_IRWXUGO);
>  	return mask;
>  }
> +
> +asmlinkage long sys_check_topology(int convert_type, int to_convert)
> +{
> +	int ret = 0;
> +
> +	switch (convert_type) {
> +		case CPU_TO_NODE:
> +			ret = cpu_to_node(to_convert);
> +			break;
> +		case MEMBLK_TO_NODE:
> +			ret = memblk_to_node(to_convert);
> +			break;
> +		case NODE_TO_NODE:
> +			ret = node_to_node(to_convert);
> +			break;
> +		case NODE_TO_CPU:
> +			ret = node_to_cpu(to_convert);
> +			break;
> +		case NODE_TO_MEMBLK:
> +			ret = node_to_memblk(to_convert);
> +			break;
> +	}
> +
> +	return (long)ret;
> +}

You don't consider this a proper syscall API, do you?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Lse-tech] [patch] Simple Topology API v0.3 (2/2)
  2002-08-22 19:24 ` [Lse-tech] " Christoph Hellwig
@ 2002-08-22 20:45   ` Matthew Dobson
  0 siblings, 0 replies; 3+ messages in thread
From: Matthew Dobson @ 2002-08-22 20:45 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Andrew Morton, Linus Torvalds, linux-kernel, linux-mm,
	Martin Bligh, Andrea Arcangeli, Michael Hohnbaum, lse-tech

Christoph,
	I've had some comments/flames about that...  One of the better suggestions that 
I've heard so far is to change it to a /proc interface.  I'll probably do that 
today and resent the userspace patch.  If you (or anyone) has better 
suggestions, I'm definitely all ears (or eyes, I suppose ;)!

Cheers!

-Matt

Christoph Hellwig wrote:
> On Thu, Aug 22, 2002 at 12:15:07PM -0700, Matthew Dobson wrote:
> 
>>diff -Nur linux-2.5.27-vanilla/kernel/sys.c linux-2.5.27-api/kernel/sys.c
>>--- linux-2.5.27-vanilla/kernel/sys.c	Sat Jul 20 12:11:07 2002
>>+++ linux-2.5.27-api/kernel/sys.c	Wed Jul 24 17:33:41 2002
>>@@ -20,6 +20,7 @@
>> #include <linux/device.h>
>> #include <linux/times.h>
>> #include <linux/security.h>
>>+#include <linux/topology.h>
>> 
>> #include <asm/uaccess.h>
>> #include <asm/io.h>
>>@@ -1236,6 +1237,31 @@
>> 	mask = xchg(&current->fs->umask, mask & S_IRWXUGO);
>> 	return mask;
>> }
>>+
>>+asmlinkage long sys_check_topology(int convert_type, int to_convert)
>>+{
>>+	int ret = 0;
>>+
>>+	switch (convert_type) {
>>+		case CPU_TO_NODE:
>>+			ret = cpu_to_node(to_convert);
>>+			break;
>>+		case MEMBLK_TO_NODE:
>>+			ret = memblk_to_node(to_convert);
>>+			break;
>>+		case NODE_TO_NODE:
>>+			ret = node_to_node(to_convert);
>>+			break;
>>+		case NODE_TO_CPU:
>>+			ret = node_to_cpu(to_convert);
>>+			break;
>>+		case NODE_TO_MEMBLK:
>>+			ret = node_to_memblk(to_convert);
>>+			break;
>>+	}
>>+
>>+	return (long)ret;
>>+}
> 
> 
> You don't consider this a proper syscall API, do you?
> 
> 


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-08-22 20:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-22 19:15 [patch] Simple Topology API v0.3 (2/2) Matthew Dobson
2002-08-22 19:24 ` [Lse-tech] " Christoph Hellwig
2002-08-22 20:45   ` Matthew Dobson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox