Patch[2/2] Adding_Notification_Support_to_Coretemp

From: R, Durgadoss
Date: Sat Dec 18 2010 - 09:14:47 EST


Hi,

This is the second patch in the series.
This patch adds support for coretemp to notify the
threshold violations using netlink events.

This patch has a dependency on the patch
"Adding Notification support to the thermal framework"
which can be downloaded from here:
https://patchwork.kernel.org/patch/282042/

Kindly review and merge.
------------------------------------------------------
From: Durgadoss R <durgadoss.r@xxxxxxxxx>

Date: Sat, 18 Dec 2010 07:23:21 +0530
Subject: [PATCH 2/2] Adding_Notification_Support_to_Coretemp

Thos patch adds event notification support to coretemp.
Whenever a threshold interrupt occurs, it is notified to
the user space by a netlink event.

Signed-off-by: Durgadoss R <durgadoss.r@xxxxxxxxx>

---
drivers/hwmon/coretemp.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index 025902f..c28a61f 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -37,9 +37,16 @@
#include <asm/processor.h>
#include <asm/smp.h>
#include <asm/mce.h>
+#include <linux/thermal.h>

#define DRVNAME "coretemp"

+/* An identification number to the DTS sensor.
+ * This will help the user space to figure out which
+ * sensor caused the event
+ */
+#define DTS_ID 0
+
enum attributes { SHOW_TEMP, SHOW_TJMAX, CORE_TTARGET, CORE_TMIN, SHOW_LABEL,
SHOW_NAME, SHOW_CRIT_ALARM, SHOW_MAX_ALARM } attrs;

@@ -68,6 +75,22 @@ struct coretemp_data {
static void update_alarm(struct coretemp_data *data);
static int set_core_threshold(struct coretemp_data *data, int temp, int thres);

+/* Interrupt Handlers for core/package thresholds */
+struct work_struct *t0_netlink_handlr;
+struct work_struct *t1_netlink_handlr;
+
+/* Send netlink event for DTS sensor reaching threshold0 */
+static void gen_netlink_t0(struct work_struct *work)
+{
+ generate_netlink_event(DTS_ID, THERMAL_AUX0);
+}
+
+/* Send netlink event for DTS sensor reaching threshold1 */
+static void gen_netlink_t1(struct work_struct *work)
+{
+ generate_netlink_event(DTS_ID, THERMAL_AUX1);
+}
+
/*
* Sysfs stuff
*/
@@ -368,15 +391,19 @@ static int coretemp_interrupt(__u64 msr_val)
{

if (msr_val & THERM_LOG_THRESHOLD0) {
- if (!(msr_val & THERM_STATUS_THRESHOLD0))
+ if (!(msr_val & THERM_STATUS_THRESHOLD0)) {
pr_info("%s:Lower Threshold Reached\n", __func__);
+ schedule_work(t0_netlink_handlr);
+ }
/* Reset the Threshold0 interrupt */
wrmsrl(MSR_IA32_THERM_STATUS, msr_val & ~THERM_LOG_THRESHOLD0);
}

if (msr_val & THERM_LOG_THRESHOLD1) {
- if (msr_val & THERM_STATUS_THRESHOLD1)
+ if (msr_val & THERM_STATUS_THRESHOLD1) {
pr_info("%s:Upper Threshold Reached\n", __func__);
+ schedule_work(t1_netlink_handlr);
+ }
/* Reset the Threshold1 interrupt */
wrmsrl(MSR_IA32_THERM_STATUS, msr_val & ~THERM_LOG_THRESHOLD1);
}
@@ -743,6 +770,20 @@ static int __init coretemp_init(void)
#endif

register_hotcpu_notifier(&coretemp_cpu_notifier);
+
+ /* Initialize the Interrupt Handlers */
+ t0_netlink_handlr = kzalloc(sizeof(struct work_struct), GFP_KERNEL);
+ if (!t0_netlink_handlr)
+ return -ENOMEM;
+
+ t1_netlink_handlr = kzalloc(sizeof(struct work_struct), GFP_KERNEL);
+ if (!t1_netlink_handlr) {
+ kfree(t0_netlink_handlr);
+ return -ENOMEM;
+ }
+ INIT_WORK(t0_netlink_handlr, (void *)gen_netlink_t0);
+ INIT_WORK(t1_netlink_handlr, (void *)gen_netlink_t1);
+
return 0;

#ifndef CONFIG_HOTPLUG_CPU
--
1.6.5.2

Attachment: 0002-Adding_Notification_Support_to_Coretemp.patch
Description: 0002-Adding_Notification_Support_to_Coretemp.patch