]> Zhao Yanbai Git Server - minix.git/commitdiff
/proc/cpuinfo
authorTomas Hruby <tom@minix3.org>
Tue, 26 Oct 2010 21:08:00 +0000 (21:08 +0000)
committerTomas Hruby <tom@minix3.org>
Tue, 26 Oct 2010 21:08:00 +0000 (21:08 +0000)
- when /proc/cpuinfo is read procfs retrievs information about cpus
  from the kernel, formats it and prints it

servers/procfs/Makefile
servers/procfs/cpuinfo.c [new file with mode: 0644]
servers/procfs/cpuinfo.h [new file with mode: 0644]
servers/procfs/main.c
servers/procfs/root.c

index 38ae2ab068743c5838b273e8faaea3b137d3f05f..a479da817ca6fd212c289929a54c9339c6c5123c 100644 (file)
@@ -1,6 +1,6 @@
 # Makefile for ProcFS server
 PROG=  procfs
-SRCS=  buf.c main.c pid.c root.c tree.c util.c
+SRCS=  buf.c main.c pid.c root.c tree.c util.c cpuinfo.c
 
 CPPFLAGS+= -I${MINIXSRCDIR} -I${MINIXSRCDIR}/servers
 
diff --git a/servers/procfs/cpuinfo.c b/servers/procfs/cpuinfo.c
new file mode 100644 (file)
index 0000000..cd2f838
--- /dev/null
@@ -0,0 +1,133 @@
+#include "inc.h"
+#include "../../kernel/arch/i386/include/archconst.h"
+
+#ifndef CONFIG_MAX_CPUS
+#define CONFIG_MAX_CPUS        1
+#endif
+
+PRIVATE const char * x86_flag[] = {
+       "fpu",
+       "vme",
+       "de",
+       "pse",
+       "tsc",
+       "msr",
+       "pae",
+       "mce",
+       "cx8",
+       "apic",
+       "",
+       "sep",
+       "mtrr",
+       "pge",
+       "mca",
+       "cmov",
+       "pat",
+       "pse36",
+       "psn",
+       "clfsh",
+       "",
+       "dts",
+       "acpi",
+       "mmx",
+       "fxsr",
+       "sse",
+       "sse2",
+       "ss",
+       "ht",
+       "tm",
+       "",
+       "pbe",
+       "pni",
+       "",
+       "",
+       "monitor",
+       "ds_cpl",
+       "vmx",
+       "smx",
+       "est",
+       "tm2",
+       "ssse3",
+       "cid",
+       "",
+       "",
+       "cx16",
+       "xtpr",
+       "pdcm",
+       "",
+       "",
+       "dca",
+       "sse4_1",
+       "sse4_2",
+       "x2apic",
+       "movbe",
+       "popcnt",
+       "",
+       "",
+       "xsave",
+       "osxsave",
+       "",
+       "",
+       "",
+       "",
+};
+
+PRIVATE void print_cpu_flags(u32_t * flags)
+{
+       int i, j;
+
+       for (i = 0; i < 2; i++) {
+               for (j = 0; j < 32; j++) {
+                       if (flags[i] & (1 << j) &&
+                                       x86_flag[i * 32 + j][0])
+                               buf_printf("%s ", x86_flag[i * 32 + j]);
+               }
+       }
+       buf_printf("\n");
+}
+
+PRIVATE void print_cpu(struct cpu_info * cpu_info, unsigned id)
+{
+       buf_printf("%-16s: %d\n", "processor", id);
+
+       switch (cpu_info->vendor) {
+               case CPU_VENDOR_INTEL:
+                       buf_printf("%-16s: %s\n", "vendor_id", "GenuineIntel");
+                       buf_printf("%-16s: %s\n", "model name", "Intel");
+                       break;
+               case CPU_VENDOR_AMD:
+                       buf_printf("%-16s: %s\n", "vendor_id", "AuthenticAMD");
+                       buf_printf("%-16s: %s\n", "model name", "AMD");
+                       break;
+               default:
+                       buf_printf("%-16: %s\n", "vendor_id", "unknown");
+       }
+
+       buf_printf("%-16s: %d\n", "cpu family", cpu_info->family);
+       buf_printf("%-16s: %d\n", "model", cpu_info->model);
+       buf_printf("%-16s: %d\n", "stepping", cpu_info->stepping);
+       buf_printf("%-16s: %d\n", "cpu MHz", cpu_info->freq);
+       buf_printf("%-16s: ", "flags");
+       print_cpu_flags(cpu_info->flags);
+
+       buf_printf("\n");
+}
+
+PUBLIC void root_cpuinfo(void)
+{
+       struct cpu_info cpu_info[CONFIG_MAX_CPUS];
+       struct machine machine;
+       unsigned c;
+
+       if (sys_getmachine(&machine)) {
+               printf("PROCFS: cannot get machine\n");
+               return;
+       }
+       if (sys_getcpuinfo(&cpu_info)) {
+               printf("PROCFS: cannot get cpu info\n");
+               return;
+       }
+
+       for (c = 0; c < machine.processors_count; c++)
+               print_cpu(&cpu_info[c], c);
+}
diff --git a/servers/procfs/cpuinfo.h b/servers/procfs/cpuinfo.h
new file mode 100644 (file)
index 0000000..7e381de
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef __PROCFS_CPUINFO_H__
+#define __PROCFS_CPUINFO_H__
+
+void root_cpuinfo(void);
+
+#endif /* __PROCFS_CPUINFO_H__ */
index 152acb2121ee124f6b38a8b2072d3313075682c1..fac11eafad6655b1e8c06998cb78ca229fcac4ec 100644 (file)
@@ -1,6 +1,7 @@
 /* ProcFS - main.c - by Alen Stojanov and David van Moolenbroek */
 
 #include "inc.h"
+#include "cpuinfo.h"
 
 FORWARD _PROTOTYPE( void init_hook, (void)                             );
 
index d57bc0a55ae376bc56b2e6a70339b936d7524aae..2b70b993e7f200d4be3ed404c4fe2d82d805ef55 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "inc.h"
 #include <machine/pci.h>
+#include "cpuinfo.h"
 
 FORWARD _PROTOTYPE( void root_hz, (void)                               );
 FORWARD _PROTOTYPE( void root_uptime, (void)                           );
@@ -17,6 +18,7 @@ struct file root_files[] = {
        { "kinfo",      REG_ALL_MODE,   (data_t) root_kinfo     },
        { "meminfo",    REG_ALL_MODE,   (data_t) root_meminfo   },
        { "pci",        REG_ALL_MODE,   (data_t) root_pci       },
+       { "cpuinfo",    REG_ALL_MODE,   (data_t) root_cpuinfo   },
        { NULL,         0,              NULL                    }
 };