]> git.neil.brown.name Git - history.git/commitdiff
[PATCH] oprofile: CPU type as string
authorJohn Levon <levon@movementarian.org>
Tue, 11 Feb 2003 04:25:38 +0000 (20:25 -0800)
committerLinus Torvalds <torvalds@home.transmeta.com>
Tue, 11 Feb 2003 04:25:38 +0000 (20:25 -0800)
This patch updates the horrible enum for the logical CPU type with a
string instead.

14 files changed:
arch/i386/oprofile/init.c
arch/i386/oprofile/nmi_int.c
arch/i386/oprofile/timer_int.c
arch/parisc/oprofile/init.c
arch/parisc/oprofile/timer_int.c
arch/ppc64/oprofile/init.c
arch/ppc64/oprofile/timer_int.c
arch/sparc64/oprofile/init.c
arch/sparc64/oprofile/timer_int.c
drivers/oprofile/oprof.c
drivers/oprofile/oprof.h
drivers/oprofile/oprofile_files.c
drivers/oprofile/oprofilefs.c
include/linux/oprofile.h

index d4306ca27025158b183f4a657fd61c3327b587e6..c1d72e74750698f86220df3eb18dd4c64ea57c07 100644 (file)
  * code unlike the NMI-based code.
  */
  
-extern int nmi_init(struct oprofile_operations ** ops, enum oprofile_cpu * cpu);
-extern void timer_init(struct oprofile_operations ** ops, enum oprofile_cpu * cpu);
+extern int nmi_init(struct oprofile_operations ** ops);
+extern void timer_init(struct oprofile_operations ** ops);
 
-int __init oprofile_arch_init(struct oprofile_operations ** ops, enum oprofile_cpu * cpu)
+int __init oprofile_arch_init(struct oprofile_operations ** ops)
 {
 #ifdef CONFIG_X86_LOCAL_APIC
-       if (!nmi_init(ops, cpu))
+       if (!nmi_init(ops))
 #endif
-               timer_init(ops, cpu);
+               timer_init(ops);
        return 0;
 }
index cd3adcc80a5568dc5fdf996659d67b6c3512896b..e426bbfb37188af9827a6be9b39a403fddd8e83e 100644 (file)
@@ -217,7 +217,7 @@ struct oprofile_operations nmi_ops = {
 
 #if !defined(CONFIG_X86_64)
 
-static int __init p4_init(enum oprofile_cpu * cpu)
+static int __init p4_init(void)
 {
        __u8 cpu_model = current_cpu_data.x86_model;
 
@@ -225,18 +225,18 @@ static int __init p4_init(enum oprofile_cpu * cpu)
                return 0;
 
 #ifndef CONFIG_SMP
-       *cpu = OPROFILE_CPU_P4;
+       nmi_ops.cpu_type = "i386/p4";
        model = &op_p4_spec;
        return 1;
 #else
        switch (smp_num_siblings) {
                case 1:
-                       *cpu = OPROFILE_CPU_P4;
+                       nmi_ops.cpu_type = "i386/p4";
                        model = &op_p4_spec;
                        return 1;
 
                case 2:
-                       *cpu = OPROFILE_CPU_P4_HT2;
+                       nmi_ops.cpu_type = "i386/p4-ht";
                        model = &op_p4_ht2_spec;
                        return 1;
        }
@@ -248,16 +248,16 @@ static int __init p4_init(enum oprofile_cpu * cpu)
 }
 
 
-static int __init ppro_init(enum oprofile_cpu * cpu)
+static int __init ppro_init(void)
 {
        __u8 cpu_model = current_cpu_data.x86_model;
 
        if (cpu_model > 5) {
-               *cpu = OPROFILE_CPU_PIII;
+               nmi_ops.cpu_type = "i386/piii";
        } else if (cpu_model > 2) {
-               *cpu = OPROFILE_CPU_PII;
+               nmi_ops.cpu_type = "i386/pii";
        } else {
-               *cpu = OPROFILE_CPU_PPRO;
+               nmi_ops.cpu_type = "i386/ppro";
        }
 
        model = &op_ppro_spec;
@@ -266,7 +266,7 @@ static int __init ppro_init(enum oprofile_cpu * cpu)
 
 #endif /* !CONFIG_X86_64 */
  
-int __init nmi_init(struct oprofile_operations ** ops, enum oprofile_cpu * cpu)
+int __init nmi_init(struct oprofile_operations ** ops)
 {
        __u8 vendor = current_cpu_data.x86_vendor;
        __u8 family = current_cpu_data.x86;
@@ -280,7 +280,7 @@ int __init nmi_init(struct oprofile_operations ** ops, enum oprofile_cpu * cpu)
                        if (family < 6)
                                return 0;
                        model = &op_athlon_spec;
-                       *cpu = OPROFILE_CPU_ATHLON;
+                       nmi_ops.cpu_type = "i386/athlon";
                        break;
  
 #if !defined(CONFIG_X86_64)
@@ -288,13 +288,13 @@ int __init nmi_init(struct oprofile_operations ** ops, enum oprofile_cpu * cpu)
                        switch (family) {
                                /* Pentium IV */
                                case 0xf:
-                                       if (!p4_init(cpu))
+                                       if (!p4_init())
                                                return 0;
                                        break;
 
                                /* A P6-class processor */
                                case 6:
-                                       if (!ppro_init(cpu))
+                                       if (!ppro_init())
                                                return 0;
                                        break;
 
index d4f0c24d89d9a853a2e49587fa571985133403db..56ce7e2a7349f30bb9fe081c1c9e9d56ea2cd30b 100644 (file)
@@ -45,13 +45,13 @@ static void timer_stop(void)
 
 static struct oprofile_operations timer_ops = {
        .start  = timer_start,
-       .stop   = timer_stop
+       .stop   = timer_stop,
+       .cpu_type = "timer"
 };
 
  
-void __init timer_init(struct oprofile_operations ** ops, enum oprofile_cpu * cpu)
+void __init timer_init(struct oprofile_operations ** ops)
 {
        *ops = &timer_ops;
-       *cpu = OPROFILE_CPU_TIMER;
        printk(KERN_INFO "oprofile: using timer interrupt.\n");
 }
index 3c68de06f8c573060d5adbd0336215acd892dfab..c7268ba1a8d2b288a3953fae8560795f63fc2e5a 100644 (file)
 #include <linux/oprofile.h>
 #include <linux/init.h>
  
-extern void timer_init(struct oprofile_operations ** ops, enum oprofile_cpu * cpu);
+extern void timer_init(struct oprofile_operations ** ops);
 
-int __init oprofile_arch_init(struct oprofile_operations ** ops, enum oprofile_cpu * cpu)
+int __init oprofile_arch_init(struct oprofile_operations ** ops)
 {
-       timer_init(ops, cpu);
+       timer_init(ops);
        return 0;
 }
index 0e1ca64300de44167719cc9f7a939f1af008500f..6a8f81f9e7f9641dd5eded484f754beb419a736c 100644 (file)
@@ -44,13 +44,13 @@ static void timer_stop(void)
 
 static struct oprofile_operations timer_ops = {
        .start  = timer_start,
-       .stop   = timer_stop
+       .stop   = timer_stop,
+       .cpu_type = "timer"
 };
 
  
-void __init timer_init(struct oprofile_operations ** ops, enum oprofile_cpu * cpu)
+void __init timer_init(struct oprofile_operations ** ops)
 {
        *ops = &timer_ops;
-       *cpu = OPROFILE_CPU_TIMER;
        printk(KERN_INFO "oprofile: using timer interrupt.\n");
 }
index 3c68de06f8c573060d5adbd0336215acd892dfab..c7268ba1a8d2b288a3953fae8560795f63fc2e5a 100644 (file)
 #include <linux/oprofile.h>
 #include <linux/init.h>
  
-extern void timer_init(struct oprofile_operations ** ops, enum oprofile_cpu * cpu);
+extern void timer_init(struct oprofile_operations ** ops);
 
-int __init oprofile_arch_init(struct oprofile_operations ** ops, enum oprofile_cpu * cpu)
+int __init oprofile_arch_init(struct oprofile_operations ** ops)
 {
-       timer_init(ops, cpu);
+       timer_init(ops);
        return 0;
 }
index 5d6a86f61eda96d0852e92c36865a5bc9762d517..70c41425f3836c195f6e5e27c36f9709f45ab500 100644 (file)
@@ -44,13 +44,13 @@ static void timer_stop(void)
 
 static struct oprofile_operations timer_ops = {
        .start  = timer_start,
-       .stop   = timer_stop
+       .stop   = timer_stop,
+       .cpu_type = "timer"
 };
 
  
-void __init timer_init(struct oprofile_operations ** ops, enum oprofile_cpu * cpu)
+void __init timer_init(struct oprofile_operations ** ops)
 {
        *ops = &timer_ops;
-       *cpu = OPROFILE_CPU_TIMER;
        printk(KERN_INFO "oprofile: using timer interrupt.\n");
 }
index 3c68de06f8c573060d5adbd0336215acd892dfab..c7268ba1a8d2b288a3953fae8560795f63fc2e5a 100644 (file)
 #include <linux/oprofile.h>
 #include <linux/init.h>
  
-extern void timer_init(struct oprofile_operations ** ops, enum oprofile_cpu * cpu);
+extern void timer_init(struct oprofile_operations ** ops);
 
-int __init oprofile_arch_init(struct oprofile_operations ** ops, enum oprofile_cpu * cpu)
+int __init oprofile_arch_init(struct oprofile_operations ** ops)
 {
-       timer_init(ops, cpu);
+       timer_init(ops);
        return 0;
 }
index 5d6a86f61eda96d0852e92c36865a5bc9762d517..70c41425f3836c195f6e5e27c36f9709f45ab500 100644 (file)
@@ -44,13 +44,13 @@ static void timer_stop(void)
 
 static struct oprofile_operations timer_ops = {
        .start  = timer_start,
-       .stop   = timer_stop
+       .stop   = timer_stop,
+       .cpu_type = "timer"
 };
 
  
-void __init timer_init(struct oprofile_operations ** ops, enum oprofile_cpu * cpu)
+void __init timer_init(struct oprofile_operations ** ops)
 {
        *ops = &timer_ops;
-       *cpu = OPROFILE_CPU_TIMER;
        printk(KERN_INFO "oprofile: using timer interrupt.\n");
 }
index 649e22ce6f1ca5dea2168f272b0a372d9b499d66..04f9131c8dd51dc86cb9e77508c1f6574c5e3cac 100644 (file)
@@ -20,7 +20,6 @@
 #include "oprofile_stats.h"
  
 struct oprofile_operations * oprofile_ops;
-enum oprofile_cpu oprofile_cpu_type;
 unsigned long oprofile_started;
 static unsigned long is_setup;
 static DECLARE_MUTEX(start_sem);
@@ -127,10 +126,16 @@ static int __init oprofile_init(void)
        /* Architecture must fill in the interrupt ops and the
         * logical CPU type.
         */
-       err = oprofile_arch_init(&oprofile_ops, &oprofile_cpu_type);
+       err = oprofile_arch_init(&oprofile_ops);
        if (err)
                goto out;
 
+       if (!oprofile_ops->cpu_type) {
+               printk(KERN_ERR "oprofile: cpu_type not set !\n");
+               err = -EFAULT;
+               goto out;
+       }
+
        err = oprofilefs_register();
        if (err)
                goto out;
index 36771cfc3d5425acffc6289465d584535d45a4b2..3f647b76a4932901f300cbd4eff2a9d41feb1b38 100644 (file)
@@ -24,7 +24,6 @@ struct oprofile_operations;
 extern unsigned long fs_buffer_size;
 extern unsigned long fs_cpu_buffer_size;
 extern unsigned long fs_buffer_watershed;
-extern enum oprofile_cpu oprofile_cpu_type;
 extern struct oprofile_operations * oprofile_ops;
 extern unsigned long oprofile_started;
  
index c49abc05429c0ed860beab2316965c93e9f1651d..21ae41a54e9056da0c86a639478a0363e1e420e7 100644 (file)
@@ -21,9 +21,7 @@ unsigned long fs_buffer_watershed = 32768; /* FIXME: tune */
  
 static ssize_t cpu_type_read(struct file * file, char * buf, size_t count, loff_t * offset)
 {
-       unsigned long cpu_type = oprofile_cpu_type;
-
-       return oprofilefs_ulong_to_user(&cpu_type, buf, count, offset);
+       return oprofilefs_str_to_user(oprofile_ops->cpu_type, buf, count, offset);
 }
  
  
index 6adf58777f402a3bab84d7af29d425e6f1dbe3c9..b08b252831c7ab4bbc06b32e7aab71530ad59531 100644 (file)
@@ -44,6 +44,29 @@ static struct super_operations s_ops = {
        .drop_inode     = generic_delete_inode,
 };
 
+
+ssize_t oprofilefs_str_to_user(char const * str, char * buf, size_t count, loff_t * offset)
+{
+       size_t len = strlen(str);
+
+       if (!count)
+               return 0;
+
+       if (*offset > len)
+               return 0;
+
+       if (count > len - *offset)
+               count = len - *offset;
+
+       if (copy_to_user(buf, str + *offset, count))
+               return -EFAULT;
+
+       *offset += count;
+
+       return count;
+}
+
+
 #define TMPBUFSIZE 50
 
 ssize_t oprofilefs_ulong_to_user(unsigned long * val, char * buf, size_t count, loff_t * offset)
index c8202efc7a1a45698a410f2ee7947232e967cae5..0c52f8df882d149bfd17d976baa445ba4bf1545b 100644 (file)
@@ -21,24 +21,6 @@ struct super_block;
 struct dentry;
 struct file_operations;
  
-/* This is duplicated from user-space so
- * must be kept in sync :(
- */
-enum oprofile_cpu {
-       OPROFILE_CPU_PPRO,
-       OPROFILE_CPU_PII,
-       OPROFILE_CPU_PIII,
-       OPROFILE_CPU_ATHLON,
-       OPROFILE_CPU_TIMER,
-       OPROFILE_UNUSED1, /* 2.4's RTC mode */
-       OPROFILE_CPU_P4,
-       OPROFILE_CPU_IA64,
-       OPROFILE_CPU_IA64_1,
-       OPROFILE_CPU_IA64_2,
-       OPROFILE_CPU_HAMMER,
-       OPROFILE_CPU_P4_HT2
-};
-
 /* Operations structure to be filled in */
 struct oprofile_operations {
        /* create any necessary configuration files in the oprofile fs.
@@ -52,14 +34,16 @@ struct oprofile_operations {
        int (*start)(void);
        /* Stop delivering interrupts. */
        void (*stop)(void);
+       /* CPU identification string. */
+       char * cpu_type;
 };
 
 /**
  * One-time initialisation. *ops must be set to a filled-in
- * operations structure. oprofile_cpu_type must be set.
+ * operations structure.
  * Return 0 on success.
  */
-int oprofile_arch_init(struct oprofile_operations ** ops, enum oprofile_cpu * cpu);
+int oprofile_arch_init(struct oprofile_operations ** ops);
  
 /**
  * Add a sample. This may be called from any context. Pass
@@ -90,6 +74,12 @@ int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
        char const * name);
 
+/**
+ * Write the given asciz string to the given user buffer @buf, updating *offset
+ * appropriately. Returns bytes written or -EFAULT.
+ */
+ssize_t oprofilefs_str_to_user(char const * str, char * buf, size_t count, loff_t * offset);
+
 /**
  * Convert an unsigned long value into ASCII and copy it to the user buffer @buf,
  * updating *offset appropriately. Returns bytes written or -EFAULT.