aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/thermal/x86_pkg_temp_thermal.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2016-11-30thermal/x86 pkg temp: Convert to hotplug state machineSebastian Andrzej Siewior1-57/+23
Install the callbacks via the state machine and let the core invoke the callbacks on the already online CPUs. Replace the wrmsr/rdmrs_on_cpu() calls in the hotplug callbacks as they are guaranteed to be invoked on the incoming/outgoing cpu. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2016-11-30thermal/x86_pkg_temp: Sanitize package managementThomas Gleixner1-20/+22
Packages are kept in a list, which must be searched over and over. We can be smarter than that and just store the package pointers in an array which is allocated at init time. Sizing of the array is determined from the topology information. That makes the package search a simple array lookup. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2016-11-30thermal/x86_pkg_temp: Move work into package structThomas Gleixner1-21/+52
Delayed work structs are held in a static percpu storage, which makes no sense at all because work is strictly per package and we never schedule more than one work per package. Aside of that the work cancelation in the hotplug is broken when the work is queued on the outgoing cpu and canceled. Nothing reschedules the work on another online cpu in the package, so the interrupts stay disabled and the work_scheduled flag stays active. Move the delayed work struct into the package struct, which is the only sensible place to have it. To simplify the cancelation logic schedule the work always on the cpu which is the target for the sysfs files. This is required so the cancelation logic in the cpu offline path cancels only when the outgoing cpu is the current target and reschedule the work when there is still a online CPU in the package. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2016-11-30thermal/x86_pkg_temp: Move work scheduled flag into package structThomas Gleixner1-30/+5
Storage for a boolean information whether work is scheduled for a package is kept in separate allocated storage, which is resized when the number of detected packages grows. With the proper locking in place this is a completely pointless exercise because we can simply stick it into the per package struct. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2016-11-30thermal/x86_pkg_temp: Sanitize lockingThomas Gleixner1-112/+110
The work cancellation code, the thermal zone unregistering, the work code and the interrupt notification function are racy against each other and against cpu hotplug and module exit. The random locking sprinkeled all over the place does not help anything and probably exists to make people feel good. The resulting issues (mainly use after free) are probably hard to trigger, but they clearly exist Protect the package list with a spinlock so it can be accessed from the interrupt notifier and also from the work function. The add/removal code in the hotplug callbacks take the lock for list manipulation. That makes sure that on removal neither the interrupt notifier nor the work function can access the about to be freed package structure anymore. The thermal zone unregistering is another trainwreck. It's not serialized against the work function. So unregistering the zone device can race with the work function and cause havoc. Protect the thermal zone with a mutex, which is held in the work function to make sure that the zone device is not being unregistered concurrently. To solve the module exit issues, we simply invoke the cpu offline callback and let it work its magic. For that it's required to keep track of the participating cpus in a package, because topology_core_mask is not affected by calling the offline callback for teardown of the driver, so it would never free the package as there is always a valid target in topology_core_mask. Use proper names for the locks so it's clear what they are for and add a pile of comments to explain the protection rules. It's amazing that fixing the locking and adding 30 lines of comments explaining it still removes more lines than it adds. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2016-11-30thermal/x86_pkg_temp: Cleanup code some moreThomas Gleixner1-51/+30
Coding style fixups and replacement of overly complex constructs and random error codes instead of returning the real ones. This mess makes the eyes bleeding. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2016-11-30thermal/x86_pkg_temp: Cleanup namespaceThomas Gleixner1-90/+76
Any randomly chosen struct name is more descriptive than phy_dev_entry. Rename the whole thing to struct pkg_device, which describes the content reasonably well and use the same variable name throughout the code so it gets readable. Rename the msr struct members as well. No functional change. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2016-11-30thermal/x86_pkg_temp: Get rid of ref countingThomas Gleixner1-42/+20
There is no point in the whole package data refcounting dance because topology_core_cpumask tells us whether this is the last cpu in the package. If yes, then the package can go, if not it stays. It's already serialized via the hotplug code. While at it rename the first_cpu member of the package structure to cpu. The first has absolutely no meaning. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2016-11-30thermal/x86_pkg_temp: Sanitize callback (de)initializationThomas Gleixner1-11/+8
The threshold callbacks are installed before the initialization of the online cpus has succeeded and removed after the teardown has been done. That's both wrong as callbacks might be invoked into a half initialized or torn down state. Move them to the proper places: Last in init() and first in exit(). While at it shorten the insane long and horrible named function names. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2016-11-30thermal/x86_pkg_temp: Replace open coded cpu searchThomas Gleixner1-15/+4
find_next_sibling() iterates over the online cpus and searches for a cpu with the same package id as the current cpu. This is a pointless exercise as topology_core_cpumask() allows a simple cpumask search for an online cpu on the same package. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2016-11-30thermal/x86_pkg_temp: Remove redundant package searchThomas Gleixner1-19/+14
In pkg_temp_thermal_device_remove() the package device is searched at the beginning of the function. When the device refcount becomes zero another search for the same device is conducted. Remove the pointless loop and use the device pointer which was retrieved at the beginning of the function. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2016-11-30thermal/x86_pkg_temp: Cleanup thermal interrupt handlingThomas Gleixner1-1/+10
Wenn a package is removed nothing restores the thermal interrupt MSR so the content will be stale when a CPU of that package becomes online again. Aside of that the work function reenables interrupts before acknowledging the current one, which is the wrong order to begin with. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2016-09-27thermal: Enhance thermal_zone_device_update for eventsSrinivas Pandruvada1-1/+2
Added one additional parameter to thermal_zone_device_update() to provide caller with an optional capability to specify reason. Currently this event is used by user space governor to trigger different processing based on event code. Also it saves an additional call to read temperature when the event is received. The following events are cuurently defined: - Unspecified event - New temperature sample - Trip point violated - Trip point changed - thermal device up and down - thermal device power capability changed Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2016-05-17thermal: x86_pkg_temp: Handle the FROZEN hot plug notifier actions.Richard Cochran1-1/+1
When performing a suspend operation, the kernel brings all of the non-boot CPUs offline, calling the hot plug notifiers with the flag, CPU_TASKS_FROZEN, set in the action code. Similarly, during resume, the CPUs are brought back online, but again the notifiers have the FROZEN flag set. While some very few drivers really need to treat suspend/resume specially, this driver unintentionally ignores the notifications. This patch changes the driver to cancel its work item when the CPU goes down, even during a suspend operation. As a result, the suspended state is no longer a special case. Cc: Zhang Rui <rui.zhang@intel.com> Cc: Eduardo Valentin <edubezval@gmail.com> Cc: linux-pm@vger.kernel.org Signed-off-by: Richard Cochran <rcochran@linutronix.de> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2015-08-03thermal: consistently use int for temperaturesSascha Hauer1-5/+5
The thermal code uses int, long and unsigned long for temperatures in different places. Using an unsigned type limits the thermal framework to positive temperatures without need. Also several drivers currently will report temperatures near UINT_MAX for temperatures below 0°C. This will probably immediately shut the machine down due to overtemperature if started below 0°C. 'long' is 64bit on several architectures. This is not needed since INT_MAX °mC is above the melting point of all known materials. Consistently use a plain 'int' for temperatures throughout the thermal code and the drivers. This only changes the places in the drivers where the temperature is passed around as pointer, when drivers internally use another type this is not changed. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Acked-by: Geert Uytterhoeven <geert+renesas@glider.be> Reviewed-by: Jean Delvare <jdelvare@suse.de> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com> Reviewed-by: Darren Hart <dvhart@linux.intel.com> Reviewed-by: Heiko Stuebner <heiko@sntech.de> Reviewed-by: Peter Feuerer <peter@piie.net> Cc: Punit Agrawal <punit.agrawal@arm.com> Cc: Zhang Rui <rui.zhang@intel.com> Cc: Eduardo Valentin <edubezval@gmail.com> Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Jean Delvare <jdelvare@suse.de> Cc: Peter Feuerer <peter@piie.net> Cc: Heiko Stuebner <heiko@sntech.de> Cc: Lukasz Majewski <l.majewski@samsung.com> Cc: Stephen Warren <swarren@wwwdotorg.org> Cc: Thierry Reding <thierry.reding@gmail.com> Cc: linux-acpi@vger.kernel.org Cc: platform-driver-x86@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-omap@vger.kernel.org Cc: linux-samsung-soc@vger.kernel.org Cc: Guenter Roeck <linux@roeck-us.net> Cc: Rafael J. Wysocki <rjw@rjwysocki.net> Cc: Maxime Ripard <maxime.ripard@free-electrons.com> Cc: Darren Hart <dvhart@infradead.org> Cc: lm-sensors@lm-sensors.org Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2015-05-04thermal: x86_pkg_temp: drop const for thermal_zone_parametersJavi Merino1-1/+1
8754d5115693 ("thermal: introduce the Power Allocator governor") dropped the const attribute in the struct thermal_zone_device. That means that the thermal_zone_params pointer passed to thermal_zone_device_register() also lost the const qualifier. Drop the const in x86_pkg_temp_thermal.c as well to avoid the following warning as reported by the kbuild test robot: drivers/thermal/x86_pkg_temp_thermal.c: In function 'pkg_temp_thermal_device_add': >> drivers/thermal/x86_pkg_temp_thermal.c:450:31: warning: passing argument 6 of 'thermal_zone_device_register' discards 'const' qualifier from pointer target type phy_dev_entry, &tzone_ops, &pkg_temp_tz_params, 0, 0); ^ In file included from drivers/thermal/x86_pkg_temp_thermal.c:30:0: include/linux/thermal.h:378:29: note: expected 'struct thermal_zone_params *' but argument is of type 'const struct thermal_zone_params *' struct thermal_zone_device *thermal_zone_device_register(const char *, int, int, ^ Cc: Jean Delvare <jdelvare@suse.de> Cc: Zhang Rui <rui.zhang@intel.com> Cc: Eduardo Valentin <edubezval@gmail.com> Signed-off-by: Javi Merino <javi.merino@arm.com> Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2014-03-20thermal, x86-pkg-temp: Fix CPU hotplug callback registrationSrivatsa S. Bhat1-7/+7
Subsystems that want to register CPU hotplug callbacks, as well as perform initialization for the CPUs that are already online, often do it as shown below: get_online_cpus(); for_each_online_cpu(cpu) init_cpu(cpu); register_cpu_notifier(&foobar_cpu_notifier); put_online_cpus(); This is wrong, since it is prone to ABBA deadlocks involving the cpu_add_remove_lock and the cpu_hotplug.lock (when running concurrently with CPU hotplug operations). Instead, the correct and race-free way of performing the callback registration is: cpu_notifier_register_begin(); for_each_online_cpu(cpu) init_cpu(cpu); /* Note the use of the double underscored version of the API */ __register_cpu_notifier(&foobar_cpu_notifier); cpu_notifier_register_done(); Fix the thermal x86-pkg-temp code by using this latter form of callback registration. Cc: Zhang Rui <rui.zhang@intel.com> Cc: Eduardo Valentin <eduardo.valentin@ti.com> Cc: Ingo Molnar <mingo@kernel.org> Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2014-03-03x86_pkg_temp_thermal: Fix the thermal zone typeJean Delvare1-4/+1
The thermal zone type should not include an instance number. Otherwise each zone is considered a different type and the thermal-to-hwmon bridge fails to group them all in a single hwmon device. I also changed the type to "x86_pkg_temp", because "pkg" was too generic, and other thermal drivers use an underscore, not a dash, as a separator. Or maybe "cpu_pkg_temp" would be better? Signed-off-by: Jean Delvare <jdelvare@suse.de> Cc: Zhang Rui <rui.zhang@intel.com> Cc: Eduardo Valentin <eduardo.valentin@ti.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2014-03-03x86_pkg_temp_thermal: Do not expose as a hwmon deviceJean Delvare1-1/+5
The temperature value reported by x86_pkg_temp_thermal is already reported by the coretemp driver. So, do not expose this thermal zone as a hwmon device, because it would be redundant. Signed-off-by: Jean Delvare <jdelvare@suse.de> Cc: Zhang Rui <rui.zhang@intel.com> Cc: Eduardo Valentin <eduardo.valentin@ti.com> Acked-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2014-01-02drivers: thermal: Mark function as static in x86_pkg_temp_thermal.cRashika1-1/+1
Mark function sys_set_trip_temp() as static in x86_pkg_temp_thermal.c because it is not used outside this file. This eliminates the following warning in x86_pkg_temp_thermal.c: drivers/thermal/x86_pkg_temp_thermal.c:218:5: warning: no previous prototype for ‘sys_set_trip_temp’ [-Wmissing-prototypes] Signed-off-by: Rashika Kheria <rashika.kheria@gmail.com> Reviewed-by: Josh Triplett <josh@joshtriplett.org> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2013-09-25Thermal: x86_pkg_temp: change spin lockSrinivas Pandruvada1-6/+8
x86_pkg_temp receives thermal notifications via a callback from a therm_throt driver, where thermal interrupts are processed. This callback is pkg_temp_thermal_platform_thermal_notify. Here to avoid multiple interrupts from cores in a package, we disable the source and also set a variable to avoid scheduling delayed work function. This variable is protected via spin_lock_irqsave. On one buggy platform, we still receiving interrupts even if the source is disabled. This can cause deadlock/lockdep warning, when interrupt is generated while under spinlock in work function. Change spin_lock to spin_lock_irqsave and spin_unlock to spin_unlock_irqrestore as the data it is trying to protect can also be modified in a notification call called from interrupt handler. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2013-07-22Thermal: Fix lockup of cpu_down()Steven Rostedt1-1/+0
Commit f1a18a105 "Thermal: CPU Package temperature thermal" had code that did a get_online_cpus(), run a loop and then do a put_online_cpus(). The problem is that the loop had an error exit that would skip the put_online_cpus() part. In the error exit part of the function, it also did a get_online_cpus(), run a loop and then put_online_cpus(). The only way to get to the error exit part is with get_online_cpus() already performed. If this error condition is hit, the system will be prevented from taking CPUs offline. The process taking the CPU offline will lock up hard. Removing the get_online_cpus() removes the lockup as the hotplug CPU refcount is back to zero. This was bisected with ktest. Signed-off-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2013-07-16Thermal: x86_pkg_temp: Limit number of pkg temp zonesSrinivas Pandruvada1-0/+5
Although it is unlikley that physical package id is set to some arbitary number, it is better to prevent in anycase. Since package temp zones use this in thermal zone type and for allocation, added a limit. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2013-07-15Thermal: x86_pkg_temp: fix krealloc() misuse in in pkg_temp_thermal_device_add()Wei Yongjun1-3/+5
If krealloc() returns NULL, it doesn't free the original. So any code of the form 'foo = krealloc(foo, ...);' is almost certainly a bug. Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2013-07-15Thermal: x86 package temp thermal crashSrinivas Pandruvada1-2/+2
On systems with no package MSR support this caused crash as there is a bug in the logic to check presence of DTHERM and PTS feature together. Added a change so that when there is no PTS support, module doesn't get loaded. Even if some CPU comes online with the PTS feature disabled, and other CPUs has this support, this patch will still prevent such MSR accesses. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Reported-by: Daniel Walker <dwalker@fifo99.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2013-06-18Thermal: CPU Package temperature thermalSrinivas Pandruvada1-0/+642
This driver register CPU digital temperature sensor as a thermal zone at package level. Each package will show up as one zone with at max two trip points. These trip points can be both read and updated. Once a non zero value is set in the trip point, if the package package temperature goes above or below this setting, a thermal notification is generated. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>