Skip to contentSkip to conversation

bk - fix oprofile for pm driver register

PATCH New John Levon 1 participant 1 message Apr 3, 2003

Subsystems (2)
lore
Share & tools
lore

John Levon

author
#0 lore raw

PATCH 1/1 bk - fix oprofile for pm driver register

OK, so I screwed up - didn't notice the late_initcall() that was introduced, which was obviously bogus. This one should build OK for the module case. I've tested insmod/rmmod alongside a mounted sysfs, seems to work.

I think the built-in case is OK: oprofile/ is after kernel/ in the link order. I tested that too.

please apply,
john

arch/alpha/oprofile/common.c +6 -0
diff -X dontdiff -Naur linux-cvs/arch/alpha/oprofile/common.c linux-me/arch/alpha/oprofile/common.c
@@ -186,3 +186,9 @@
 
 	return 0;
 }
+
+
+void __exit
+oprofile_arch_exit(void)
+{
+}
arch/i386/Makefile +1 -1
diff -X dontdiff -Naur linux-cvs/arch/i386/Makefile linux-me/arch/i386/Makefile
@@ -84,7 +84,7 @@
 					   arch/i386/$(mcore-y)/
 drivers-$(CONFIG_MATH_EMULATION)	+= arch/i386/math-emu/
 drivers-$(CONFIG_PCI)			+= arch/i386/pci/
-# FIXME: is drivers- right ?
+# must be linked after kernel/
 drivers-$(CONFIG_OPROFILE)		+= arch/i386/oprofile/
 
 CFLAGS += $(mflags-y)
arch/i386/oprofile/init.c +9 -0
diff -X dontdiff -Naur linux-cvs/arch/i386/oprofile/init.c linux-me/arch/i386/oprofile/init.c
@@ -17,6 +17,7 @@
  */
  
 extern int nmi_init(struct oprofile_operations ** ops);
+extern void nmi_exit(void);
 extern void timer_init(struct oprofile_operations ** ops);
 
 int __init oprofile_arch_init(struct oprofile_operations ** ops)
@@ -27,3 +28,11 @@
 		timer_init(ops);
 	return 0;
 }
+
+
+void __exit oprofile_arch_exit(void)
+{
+#ifdef CONFIG_X86_LOCAL_APIC
+	nmi_exit();
+#endif
+}
arch/i386/oprofile/nmi_int.c +22 -2
diff -X dontdiff -Naur linux-cvs/arch/i386/oprofile/nmi_int.c linux-me/arch/i386/oprofile/nmi_int.c
@@ -67,15 +67,22 @@
 };
 
 
-static int __init init_nmi_driverfs(void)
+static int __init init_driverfs(void)
 {
 	driver_register(&nmi_driver);
 	return device_register(&device_nmi);
 }
 
 
-late_initcall(init_nmi_driverfs);
+static void __exit exit_driverfs(void)
+{
+	device_unregister(&device_nmi);
+	driver_unregister(&nmi_driver);
+}
 
+#else
+#define init_driverfs() do { } while (0)
+#define exit_driverfs() do { } while (0)
 #endif /* CONFIG_PM */
 
 
@@ -297,6 +304,10 @@
 
 #endif /* !CONFIG_X86_64 */
  
+
+/* in order to get driverfs right */
+static int using_nmi;
+
 int __init nmi_init(struct oprofile_operations ** ops)
 {
 	__u8 vendor = current_cpu_data.x86_vendor;
@@ -339,7 +350,16 @@
 			return 0;
 	}
 
+	init_driverfs();
+	using_nmi = 1;
 	*ops = &nmi_ops;
 	printk(KERN_INFO "oprofile: using NMI interrupt.\n");
 	return 1;
 }
+
+
+void __exit nmi_exit(void)
+{
+	if (using_nmi)
+		exit_driverfs();
+}
arch/parisc/oprofile/init.c +5 -0
diff -X dontdiff -Naur linux-cvs/arch/parisc/oprofile/init.c linux-me/arch/parisc/oprofile/init.c
@@ -18,3 +18,8 @@
 	timer_init(ops);
 	return 0;
 }
+
+
+void __exit oprofile_arch_exit()
+{
+}
arch/ppc64/oprofile/init.c +5 -0
diff -X dontdiff -Naur linux-cvs/arch/ppc64/oprofile/init.c linux-me/arch/ppc64/oprofile/init.c
@@ -18,3 +18,8 @@
 	timer_init(ops);
 	return 0;
 }
+
+
+void __exit oprofile_arch_exit(void)
+{
+}
arch/sparc64/oprofile/init.c +5 -0
diff -X dontdiff -Naur linux-cvs/arch/sparc64/oprofile/init.c linux-me/arch/sparc64/oprofile/init.c
@@ -18,3 +18,8 @@
 	timer_init(ops);
 	return 0;
 }
+
+
+void __exit oprofile_arch_exit(void)
+{
+}
drivers/oprofile/oprof.c +1 -0
diff -X dontdiff -Naur linux-cvs/drivers/oprofile/oprof.c linux-me/drivers/oprofile/oprof.c
@@ -148,6 +148,7 @@
 static void __exit oprofile_exit(void)
 {
 	oprofilefs_unregister();
+	oprofile_arch_exit();
 }
 
  
include/linux/oprofile.h +5 -0
diff -X dontdiff -Naur linux-cvs/include/linux/oprofile.h linux-me/include/linux/oprofile.h
@@ -46,6 +46,11 @@
 int oprofile_arch_init(struct oprofile_operations ** ops);
  
 /**
+ * One-time exit/cleanup for the arch.
+ */
+void oprofile_arch_exit(void);
+
+/**
  * Add a sample. This may be called from any context. Pass
  * smp_processor_id() as cpu.
  */