Skip to contentSkip to conversation

hwmon: (coretemp) : Add debugfs to support thresholds

PATCH In review Srinivas Pandruvada 2 participants 3 messages Apr 9, 2013 – Apr 19, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 4/4 hwmon: (coretemp) : Add debugfs to support thresholds

Added debugfs inteface to show number of times interrupts callback is called and number of times the work function is scheduled.

---
 drivers/hwmon/coretemp.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
drivers/hwmon/coretemp.c +35 -0
index bc6d4c1..2031499 100644
@@ -40,6 +40,7 @@
 #include <asm/processor.h>
 #include <asm/cpu_device_id.h>
 #include <asm/mce.h>
+#include <linux/debugfs.h>
 
 #define DRVNAME	"coretemp"
 
@@ -122,6 +123,11 @@ static unsigned long pkg_temp_scheduled;
 static DEFINE_PER_CPU(struct delayed_work, pkg_temp_threshold_work);
 static atomic_t pkg_thres_device_cnt =	ATOMIC_INIT(0);
 
+/* Debug counters to show using debugfs */
+static struct dentry *debugfs;
+static unsigned int pkg_interrupt_cnt;
+static unsigned int pkg_work_cnt;
+
 static ssize_t show_name(struct device *dev,
 			struct device_attribute *devattr, char *buf)
 {
@@ -602,6 +608,7 @@ static void pkg_temp_threshold_work_fn(struct work_struct *work)
 	__u64 msr_val;
 	bool notify = false;
 
+	pkg_work_cnt++;
 	clear_bit_unlock(TO_PHYS_ID(smp_processor_id()), &pkg_temp_scheduled);
 	enable_pkg_thres_interrupt();
 	rdmsrl(MSR_IA32_PACKAGE_THERM_STATUS, msr_val);
@@ -623,14 +630,39 @@ static int pkg_temp_platform_thermal_notify(__u64 msr_val)
 {
 	int cpu = smp_processor_id();
 
+	pkg_interrupt_cnt++;
 	if (test_and_set_bit_lock(TO_PHYS_ID(cpu), &pkg_temp_scheduled))
 		return 0;
 	disable_pkg_thres_interrupt();
 	schedule_delayed_work_on(cpu,
 				&per_cpu(pkg_temp_threshold_work, cpu),
 				PKG_TEMP_NOTIFY_DELAY);
+	return 0;
+}
+
+static int pkg_temp_debugfs_init(void)
+{
+	struct dentry *d;
+
+	debugfs = debugfs_create_dir("coretemp", NULL);
+	if (!debugfs)
+		return -ENOMEM;
+
+	d = debugfs_create_u32("threshold_interrupt", S_IRUGO, debugfs,
+				(u32 *)&pkg_interrupt_cnt);
+	if (!d)
+		goto err_out;
+
+	d = debugfs_create_u32("threshold_work_fn", S_IRUGO, debugfs,
+				(u32 *)&pkg_work_cnt);
+	if (!d)
+		goto err_out;
 
 	return 0;
+
+err_out:
+	debugfs_remove(debugfs);
+	return -ENOMEM;
 }
 
 static struct temp_data __cpuinit *init_temp_data(unsigned int cpu,
@@ -1052,6 +1084,8 @@ static int __init coretemp_init(void)
 	if (err)
 		goto exit;
 
+	pkg_temp_debugfs_init(); /* Don't care if fails */
+
 	get_online_cpus();
 	for_each_online_cpu(i)
 		get_core_online(i);
@@ -1093,6 +1127,7 @@ static void __exit coretemp_exit(void)
 	mutex_unlock(&pdev_list_mutex);
 	put_online_cpus();
 	platform_driver_unregister(&coretemp_driver);
+	debugfs_remove_recursive(debugfs);
 }
 
 MODULE_AUTHOR("Rudolf Marek <[email protected]>");
Signature · 7 lines
1.7.11.7


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#1 lore raw
Quoted 22 lines

From: Srinivas Pandruvada [mailto:[email protected]] Added debugfs inteface to show number of times interrupts callback is called and number of times the work function is scheduled.

---
 drivers/hwmon/coretemp.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
drivers/hwmon/coretemp.c +1 -0
index bc6d4c1..2031499 100644
@@ -40,6 +40,7 @@
 #include <asm/processor.h>
 #include <asm/cpu_device_id.h>
 #include <asm/mce.h>
+#include <linux/debugfs.h>
 
 #define DRVNAME	"coretemp"
 

drivers/hwmon/coretemp.c static unsigned long pkg_temp_scheduled; · line 130

Quoted 8 lines
drivers/hwmon/coretemp.c +5 -0
@@ -122,6 +123,11 @@ static unsigned long pkg_temp_scheduled;
 static DEFINE_PER_CPU(struct delayed_work, pkg_temp_threshold_work);
 static atomic_t pkg_thres_device_cnt =	ATOMIC_INIT(0);
 
+/* Debug counters to show using debugfs */
+static struct dentry *debugfs;
+static unsigned int pkg_interrupt_cnt;
+static unsigned int pkg_work_cnt;
+

It would be better to just define the variable ifdef CONFIG_DEBUG_FS.

Quoted 28 lines
drivers/hwmon/coretemp.c +1 -0
 static ssize_t show_name(struct device *dev,
 			struct device_attribute *devattr, char *buf)
 {
@@ -602,6 +608,7 @@ static void pkg_temp_threshold_work_fn(struct
 work_struct *work)
 	__u64 msr_val;
 	bool notify = false;
 
+	pkg_work_cnt++;
 	clear_bit_unlock(TO_PHYS_ID(smp_processor_id()),
 &pkg_temp_scheduled);
drivers/hwmon/coretemp.c +4 -0
 	enable_pkg_thres_interrupt();
 	rdmsrl(MSR_IA32_PACKAGE_THERM_STATUS, msr_val);
@@ -623,14 +630,39 @@ static int pkg_temp_platform_thermal_notify(__u64
 msr_val)
 {
 	int cpu = smp_processor_id();
 
+	pkg_interrupt_cnt++;
 	if (test_and_set_bit_lock(TO_PHYS_ID(cpu), &pkg_temp_scheduled))
 		return 0;
 	disable_pkg_thres_interrupt();
 	schedule_delayed_work_on(cpu,
 				&per_cpu(pkg_temp_threshold_work, cpu),
 				PKG_TEMP_NOTIFY_DELAY);
+	return 0;
+}
+

drivers/hwmon/coretemp.c static int pkg_temp_platform_thermal_notify(__u64 · line 653

Quoted 10 lines
drivers/hwmon/coretemp.c +10 -0
+static int pkg_temp_debugfs_init(void)
+{
+	struct dentry *d;
+
+	debugfs = debugfs_create_dir("coretemp", NULL);
+	if (!debugfs)
+		return -ENOMEM;
+
+	d = debugfs_create_u32("threshold_interrupt", S_IRUGO, debugfs,
+				(u32 *)&pkg_interrupt_cnt);

Isn't it better to change "threshold_interrupt" to "pkg_interrupt_cnt"?

drivers/hwmon/coretemp.c static int pkg_temp_platform_thermal_notify(__u64 msr_val) · line 657

Quoted 5 lines
drivers/hwmon/coretemp.c +5 -0
+	if (!d)
+		goto err_out;
+
+	d = debugfs_create_u32("threshold_work_fn", S_IRUGO, debugfs,
+				(u32 *)&pkg_work_cnt);

Isn't it better to change "threshold_interrupt" to "pkg_work_cnt"?

drivers/hwmon/coretemp.c static int pkg_temp_platform_thermal_notify(__u64 msr_val) · line 664

Quoted 7 lines
drivers/hwmon/coretemp.c +5 -0
+	if (!d)
+		goto err_out;
 
 	return 0;
+
+err_out:
+	debugfs_remove(debugfs);

debugfs_remove_recursive().

Quoted 22 lines
drivers/hwmon/coretemp.c +1 -0
+	return -ENOMEM;
 }
 

static struct temp_data __cpuinit *init_temp_data(unsigned int cpu,

drivers/hwmon/coretemp.c +3 -1
@@ -1052,6 +1084,8 @@ static int __init coretemp_init(void)
 	if (err)
 		goto exit;
 
+	pkg_temp_debugfs_init(); /* Don't care if fails */
+
 	get_online_cpus();
 	for_each_online_cpu(i)
 		get_core_online(i);
@@ -1093,6 +1127,7 @@ static void __exit coretemp_exit(void)
 	mutex_unlock(&pdev_list_mutex);
 	put_online_cpus();
 	platform_driver_unregister(&coretemp_driver);
+	debugfs_remove_recursive(debugfs);
 }
 
 MODULE_AUTHOR("Rudolf Marek <[email protected]>");
--
Quoted 1 line

1.7.11.7

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#2 lore raw
In reply to Srinivas Pandruvada
Quoted 25 lines · Fenghua
Quoted 25 lines

From: Srinivas Pandruvada [mailto:[email protected]] Added debugfs inteface to show number of times interrupts callback is called and number of times the work function is scheduled.

---
  drivers/hwmon/coretemp.c | 35 +++++++++++++++++++++++++++++++++++
  1 file changed, 35 insertions(+)
drivers/hwmon/coretemp.c +1 -0
index bc6d4c1..2031499 100644
@@ -40,6 +40,7 @@
  #include <asm/processor.h>
  #include <asm/cpu_device_id.h>
  #include <asm/mce.h>
+#include <linux/debugfs.h>
 
  #define DRVNAME	"coretemp"
 
@@ -122,6 +123,11 @@ static unsigned long pkg_temp_scheduled;
  static DEFINE_PER_CPU(struct delayed_work, pkg_temp_threshold_work);
  static atomic_t pkg_thres_device_cnt =	ATOMIC_INIT(0);
 
Quoted 6 lines

drivers/hwmon/coretemp.c static unsigned long pkg_temp_scheduled; · line 130

Quoted 5 lines
drivers/hwmon/coretemp.c +5 -0
+/* Debug counters to show using debugfs */
+static struct dentry *debugfs;
+static unsigned int pkg_interrupt_cnt;
+static unsigned int pkg_work_cnt;
+

It would be better to just define the variable ifdef CONFIG_DEBUG_FS.

<I did that before, but removed after review. Either this flag is always defined or
debugfs_calls results in empty functions when DEBUGFS is not defined.>

Quoted 31 lines
Quoted 31 lines
drivers/hwmon/coretemp.c +1 -0
  static ssize_t show_name(struct device *dev,
  			struct device_attribute *devattr, char *buf)
  {
@@ -602,6 +608,7 @@ static void pkg_temp_threshold_work_fn(struct
 work_struct *work)
  	__u64 msr_val;
  	bool notify = false;
 
+	pkg_work_cnt++;
  	clear_bit_unlock(TO_PHYS_ID(smp_processor_id()),
 &pkg_temp_scheduled);
  	enable_pkg_thres_interrupt();
  	rdmsrl(MSR_IA32_PACKAGE_THERM_STATUS, msr_val);
drivers/hwmon/coretemp.c +7 -0
@@ -623,14 +630,39 @@ static int pkg_temp_platform_thermal_notify(__u64
 msr_val)
  {
  	int cpu = smp_processor_id();
 
+	pkg_interrupt_cnt++;
  	if (test_and_set_bit_lock(TO_PHYS_ID(cpu), &pkg_temp_scheduled))
  		return 0;
  	disable_pkg_thres_interrupt();
  	schedule_delayed_work_on(cpu,
  				&per_cpu(pkg_temp_threshold_work, cpu),
  				PKG_TEMP_NOTIFY_DELAY);
+	return 0;
+}
+
+static int pkg_temp_debugfs_init(void)
+{
+	struct dentry *d;
Quoted 8 lines

drivers/hwmon/coretemp.c static int pkg_temp_platform_thermal_notify(__u64 msr_val) · line 652

Quoted 7 lines
drivers/hwmon/coretemp.c +7 -0
+
+	debugfs = debugfs_create_dir("coretemp", NULL);
+	if (!debugfs)
+		return -ENOMEM;
+
+	d = debugfs_create_u32("threshold_interrupt", S_IRUGO, debugfs,
+				(u32 *)&pkg_interrupt_cnt);

Isn't it better to change "threshold_interrupt" to "pkg_interrupt_cnt"?

<OK, can change.>

Quoted 6 lines

drivers/hwmon/coretemp.c static int pkg_temp_platform_thermal_notify(__u64 msr_val) · line 657

Quoted 5 lines
drivers/hwmon/coretemp.c +5 -0
+	if (!d)
+		goto err_out;
+
+	d = debugfs_create_u32("threshold_work_fn", S_IRUGO, debugfs,
+				(u32 *)&pkg_work_cnt);

Isn't it better to change "threshold_interrupt" to "pkg_work_cnt"?

<can change.>

Quoted 8 lines

drivers/hwmon/coretemp.c static int pkg_temp_platform_thermal_notify(__u64 msr_val) · line 664

Quoted 7 lines
drivers/hwmon/coretemp.c +5 -0
+	if (!d)
+		goto err_out;
 
  	return 0;
+
+err_out:
+	debugfs_remove(debugfs);

debugfs_remove_recursive().

<Correct>

Quoted 21 lines
Quoted 21 lines
drivers/hwmon/coretemp.c +1 -0
+	return -ENOMEM;
  }
 

static struct temp_data __cpuinit *init_temp_data(unsigned int cpu,

drivers/hwmon/coretemp.c +3 -0
@@ -1052,6 +1084,8 @@ static int __init coretemp_init(void)
  	if (err)
  		goto exit;
 
+	pkg_temp_debugfs_init(); /* Don't care if fails */
+
  	get_online_cpus();
  	for_each_online_cpu(i)
  		get_core_online(i);
@@ -1093,6 +1127,7 @@ static void __exit coretemp_exit(void)
  	mutex_unlock(&pdev_list_mutex);
  	put_online_cpus();
  	platform_driver_unregister(&coretemp_driver);
+	debugfs_remove_recursive(debugfs);
  }
 
Quoted 4 lines
Quoted 3 lines
drivers/hwmon/coretemp.c +0 -1
  MODULE_AUTHOR("Rudolf Marek <[email protected]>");
--

1.7.11.7

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors