Skip to content

Commit 1c53081

Browse files
ricardonrafaeljw
authored andcommitted
thermal: intel: hfi: Disable an HFI instance when all its CPUs go offline
In preparation to support hibernation, add functionality to disable an HFI instance during CPU offline. The last CPU of an instance that goes offline will disable such instance. The Intel Software Development Manual states that the operating system must wait for the hardware to set MSR_IA32_PACKAGE_THERM_STATUS[26] after disabling an HFI instance to ensure that it will no longer write on the HFI memory. Some processors, however, do not ever set such bit. Wait a minimum of 2ms to give time hardware to complete any pending memory writes. Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent ac1f923 commit 1c53081

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

drivers/thermal/intel/intel_hfi.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/bitops.h>
2525
#include <linux/cpufeature.h>
2626
#include <linux/cpumask.h>
27+
#include <linux/delay.h>
2728
#include <linux/gfp.h>
2829
#include <linux/io.h>
2930
#include <linux/kernel.h>
@@ -367,6 +368,32 @@ static void hfi_set_hw_table(struct hfi_instance *hfi_instance)
367368
wrmsrl(MSR_IA32_HW_FEEDBACK_PTR, msr_val);
368369
}
369370

371+
/* Caller must hold hfi_instance_lock. */
372+
static void hfi_disable(void)
373+
{
374+
u64 msr_val;
375+
int i;
376+
377+
rdmsrl(MSR_IA32_HW_FEEDBACK_CONFIG, msr_val);
378+
msr_val &= ~HW_FEEDBACK_CONFIG_HFI_ENABLE_BIT;
379+
wrmsrl(MSR_IA32_HW_FEEDBACK_CONFIG, msr_val);
380+
381+
/*
382+
* Wait for hardware to acknowledge the disabling of HFI. Some
383+
* processors may not do it. Wait for ~2ms. This is a reasonable
384+
* time for hardware to complete any pending actions on the HFI
385+
* memory.
386+
*/
387+
for (i = 0; i < 2000; i++) {
388+
rdmsrl(MSR_IA32_PACKAGE_THERM_STATUS, msr_val);
389+
if (msr_val & PACKAGE_THERM_STATUS_HFI_UPDATED)
390+
break;
391+
392+
udelay(1);
393+
cpu_relax();
394+
}
395+
}
396+
370397
/**
371398
* intel_hfi_online() - Enable HFI on @cpu
372399
* @cpu: CPU in which the HFI will be enabled
@@ -420,6 +447,10 @@ void intel_hfi_online(unsigned int cpu)
420447
/*
421448
* Hardware is programmed with the physical address of the first page
422449
* frame of the table. Hence, the allocated memory must be page-aligned.
450+
*
451+
* Some processors do not forget the initial address of the HFI table
452+
* even after having been reprogrammed. Keep using the same pages. Do
453+
* not free them.
423454
*/
424455
hfi_instance->hw_table = alloc_pages_exact(hfi_features.nr_table_pages,
425456
GFP_KERNEL | __GFP_ZERO);
@@ -488,6 +519,10 @@ void intel_hfi_offline(unsigned int cpu)
488519

489520
mutex_lock(&hfi_instance_lock);
490521
cpumask_clear_cpu(cpu, hfi_instance->cpus);
522+
523+
if (!cpumask_weight(hfi_instance->cpus))
524+
hfi_disable();
525+
491526
mutex_unlock(&hfi_instance_lock);
492527
}
493528

0 commit comments

Comments
 (0)