Patch for 2.2.10 (Quelle surprise!)

Alex Buell (alex.buell@tahallah.demon.co.uk)
Sat, 3 Jul 1999 19:20:11 +0100 (BST)


Here's a patch that implements a new syscall on the i386 architecture
along with a small test program. I'd love to hear your opinions on this.

Basically it just returns a structure filled out with processor
information a la 'cat /proc/cpuinfo', except that this is done via a
syscall - no more horrid /proc parsing.

--cut-here--
diff -uNr linux-2.2.10/.version linux-2.2.10-aib/.version
--- linux-2.2.10/.version Sat Jun 26 01:23:12 1999
+++ linux-2.2.10-aib/.version Sat Jul 3 18:49:09 1999
@@ -1 +1 @@
-35
+53
diff -uNr linux-2.2.10/Makefile linux-2.2.10-aib/Makefile
--- linux-2.2.10/Makefile Mon Jun 14 20:56:24 1999
+++ linux-2.2.10-aib/Makefile Sat Jul 3 17:59:21 1999
@@ -1,7 +1,7 @@
VERSION = 2
PATCHLEVEL = 2
SUBLEVEL = 10
-EXTRAVERSION =
+EXTRAVERSION = aib

ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)

diff -uNr linux-2.2.10/arch/i386/kernel/.depend linux-2.2.10-aib/arch/i386/kernel/.depend
--- linux-2.2.10/arch/i386/kernel/.depend Sat Jun 26 00:46:59 1999
+++ linux-2.2.10-aib/arch/i386/kernel/.depend Sat Jul 3 18:00:43 1999
@@ -84,6 +84,12 @@
$(wildcard /usr/src/linux/include/config/smp.h) \
$(wildcard /usr/src/linux/include/config/mca.h) \
$(wildcard /usr/src/linux/include/config/vt.h)
+info.o: \
+ /usr/src/linux/include/linux/kernel.h \
+ /usr/src/linux/include/linux/mm.h \
+ /usr/src/linux/include/linux/unistd.h \
+ /usr/src/linux/include/asm/processor.h \
+ /usr/src/linux/include/asm/uaccess.h
init_task.o: \
/usr/src/linux/include/linux/mm.h \
/usr/src/linux/include/linux/sched.h \
diff -uNr linux-2.2.10/arch/i386/kernel/Makefile linux-2.2.10-aib/arch/i386/kernel/Makefile
--- linux-2.2.10/arch/i386/kernel/Makefile Wed Jan 20 18:18:53 1999
+++ linux-2.2.10-aib/arch/i386/kernel/Makefile Sat Jul 3 02:41:45 1999
@@ -14,7 +14,7 @@

O_TARGET := kernel.o
O_OBJS := process.o signal.o entry.o traps.o irq.o vm86.o \
- ptrace.o ioport.o ldt.o setup.o time.o sys_i386.o
+ ptrace.o ioport.o ldt.o setup.o time.o sys_i386.o info.o
OX_OBJS := i386_ksyms.o
MX_OBJS :=

diff -uNr linux-2.2.10/arch/i386/kernel/entry.S linux-2.2.10-aib/arch/i386/kernel/entry.S
--- linux-2.2.10/arch/i386/kernel/entry.S Wed May 12 18:08:52 1999
+++ linux-2.2.10-aib/arch/i386/kernel/entry.S Sat Jul 3 02:45:42 1999
@@ -562,6 +562,7 @@
.long SYMBOL_NAME(sys_ni_syscall) /* streams1 */
.long SYMBOL_NAME(sys_ni_syscall) /* streams2 */
.long SYMBOL_NAME(sys_vfork) /* 190 */
+ .long SYMBOL_NAME(sys_cpuinfo) /* 191 Added by AIB 19990703 */

/*
* NOTE!! This doesn't have to be exact - we just have
@@ -569,6 +570,7 @@
* entries. Don't panic if you notice that this hasn't
* been shrunk every time we add a new system call.
*/
- .rept NR_syscalls-190
+
+ .rept NR_syscalls-191 /* Was 190, changed by AIB 19990703 */
.long SYMBOL_NAME(sys_ni_syscall)
.endr
diff -uNr linux-2.2.10/arch/i386/kernel/info.c linux-2.2.10-aib/arch/i386/kernel/info.c
--- linux-2.2.10/arch/i386/kernel/info.c Thu Jan 1 01:00:00 1970
+++ linux-2.2.10-aib/arch/i386/kernel/info.c Sat Jul 3 18:48:19 1999
@@ -0,0 +1,47 @@
+/*
+
+ linux/arch/i386/kernel/info.c
+
+ Copyright (C) 1999 Alex Buell, alex.buell@tahallah.demon.co.uk
+
+ Implements the cpuinfo() system call
+
+*/
+
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/unistd.h>
+
+#include <asm/processor.h>
+#include <asm/uaccess.h>
+
+extern unsigned long cpu_hz;
+
+asmlinkage int sys_cpuinfo(struct cpuinfo *info)
+{
+ struct cpuinfo_x86 *c = cpu_data;
+ struct cpuinfo val;
+ int n;
+
+ memset((char *)&val, 0, sizeof(struct cpuinfo));
+
+ /* Count the number of processors active - is there an easier way to do it? */
+ for (n = 0; n < NR_CPUS; n++)
+ if (cpu_online_map & (1 << n))
+ val.processors++;
+
+ if (c->x86_capability & X86_FEATURE_TSC)
+ val.megahertz = cpu_hz / 1000000;
+ else
+ val.megahertz = 0L;
+
+ val.bogomips = (c->loops_per_sec + 2600) / 500000; /* don't care for accuracy yet */
+
+ sprintf(val.manufacturer, "%s", c->x86_vendor_id[0] ? c->x86_vendor_id : "unknown");
+ sprintf(val.description, "%s", c->x86_model_id[0] ? c->x86_model_id : "unknown");
+
+ if (copy_to_user(info, &val, sizeof(struct cpuinfo)));
+ return -EFAULT;
+
+ return 0;
+}
diff -uNr linux-2.2.10/include/asm-i386/unistd.h linux-2.2.10-aib/include/asm-i386/unistd.h
--- linux-2.2.10/include/asm-i386/unistd.h Wed Jan 20 19:06:24 1999
+++ linux-2.2.10-aib/include/asm-i386/unistd.h Sat Jul 3 02:33:52 1999
@@ -195,6 +195,7 @@
#define __NR_getpmsg 188 /* some people actually want streams */
#define __NR_putpmsg 189 /* some people actually want streams */
#define __NR_vfork 190
+#define __NR_cpuinfo 191 /* Added by AIB 19990703 */

/* user-visible error numbers are in the range -1 - -122: see <asm-i386/errno.h> */

diff -uNr linux-2.2.10/include/linux/kernel.h linux-2.2.10-aib/include/linux/kernel.h
--- linux-2.2.10/include/linux/kernel.h Thu Dec 31 05:19:20 1998
+++ linux-2.2.10-aib/include/linux/kernel.h Sat Jul 3 17:03:21 1999
@@ -92,4 +92,16 @@
char _f[22]; /* Pads structure to 64 bytes */
};

+/* Added by AIB, 19990703 */
+struct cpuinfo {
+ unsigned long processors; /* Number of processors in system */
+ unsigned long megahertz; /* Speed of processor */
+ unsigned long bogomips; /* How fast is it? */
+ char manufacturer[16]; /* Who makes this processor? */
+ char description[32]; /* What is this processor? */
+
+ /* do I need to pad out this structure to a given size for speed? */
+};
+
+
#endif
diff -uNr linux-2.2.10/include/linux/version.h linux-2.2.10-aib/include/linux/version.h
--- linux-2.2.10/include/linux/version.h Mon Jun 14 21:01:33 1999
+++ linux-2.2.10-aib/include/linux/version.h Sat Jul 3 17:59:37 1999
@@ -1,3 +1,3 @@
-#define UTS_RELEASE "2.2.10"
+#define UTS_RELEASE "2.2.10aib"
#define LINUX_VERSION_CODE 131594
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
--cut-here--

Test program as follows:

--cut-here--
#include <linux/kernel.h>
#include <linux/unistd.h>

static inline _syscall1(int, cpuinfo, struct cpuinfo *, info);

int main(void)
{
struct cpuinfo info;
int err;

err = cpuinfo(&info);

printf("%ld %s %s %ld MHz processors, total %ld bogomips.\n",
info.processors,
info.manufacturer,
info.description,
info.megahertz,
info.bogomips * info.processors);
}
--cut-here--

Cheers,
Alex
--

I hate people who gets offended too easily!

http://www.tahallah.demon.co.uk

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/