Skip to content

Commit c0e3acd

Browse files
spandruvadarafaeljw
authored andcommitted
thermal: intel: hfi: ACK HFI for the same timestamp
Some processors issue more than one HFI interrupt with the same timestamp. Each interrupt must be acknowledged to let the hardware issue new HFI interrupts. But this can't be done without some additional flow modification in the existing interrupt handling. For background, the HFI interrupt is a package level thermal interrupt delivered via a LVT. This LVT is common for both the CPU and package level interrupts. Hence, all CPUs receive the HFI interrupts. But only one CPU should process interrupt and others simply exit by issuing EOI to LAPIC. The current HFI interrupt processing flow: 1. Receive Thermal interrupt 2. Check if there is an active HFI status in MSR_IA32_THERM_STATUS 3. Try and get spinlock, one CPU will enter spinlock and others will simply return from here to issue EOI. (Let's assume CPU 4 is processing interrupt) 4. Check the stored time-stamp from the HFI memory time-stamp 5. if same 6. ignore interrupt, unlock and return 7. Copy the HFI message to local buffer 8. unlock spinlock 9. ACK HFI interrupt 10. Queue the message for processing in a work-queue It is tempting to simply acknowledge all the interrupts even if they have the same timestamp. This may cause some interrupts to not be processed. Let's say CPU5 is slightly late and reaches step 4 while CPU4 is between steps 8 and 9. Currently we simply ignore interrupts with the same timestamp. No issue here for CPU5. When CPU4 acknowledges the interrupt, the next HFI interrupt can be delivered. If we acknowledge interrupts with the same timestamp (at step 6), there is a race condition. Under the same scenario, CPU 5 will acknowledge the HFI interrupt. This lets hardware generate another HFI interrupt, before CPU 4 start executing step 9. Once CPU 4 complete step 9, it will acknowledge the newly arrived HFI interrupt, without actually processing it. Acknowledge the interrupt when holding the spinlock. This avoids contention of the interrupt acknowledgment. Updated flow: 1. Receive HFI Thermal interrupt 2. Check if there is an active HFI status in MSR_IA32_THERM_STATUS 3. Try and get spin-lock Let's assume CPU 4 is processing interrupt 4.1 Read MSR_IA32_PACKAGE_THERM_STATUS and check HFI status bit 4.2 If hfi status is 0 4.3 unlock spinlock 4.4 return 4.5 Check the stored time-stamp from the HFI memory time-stamp 5. if same 6.1 ACK HFI Interrupt, 6.2 unlock spinlock 6.3 return 7. Copy the HFI message to local buffer 8. ACK HFI interrupt 9. unlock spinlock 10. Queue the message for processing in a work-queue To avoid taking the lock unnecessarily, intel_hfi_process_event() checks the status of the HFI interrupt before taking the lock. If CPU5 is late, when it starts processing the interrupt there are two scenarios: a) CPU4 acknowledged the HFI interrupt before CPU5 read MSR_IA32_THERM_STATUS. CPU5 exits. b) CPU5 reads MSR_IA32_THERM_STATUS before CPU4 has acknowledged the interrupt. CPU5 will take the lock if CPU4 has released it. It then re-reads MSR_IA32_THERM_STATUS. If there is not a new interrupt, the HFI status bit is clear and CPU5 exits. If a new HFI interrupt was generated it will find that the status bit is set and it will continue to process the interrupt. In this case even if timestamp is not changed, the ACK can be issued as this is a new interrupt. Signed-off-by: Srinivas Pandruvada <[email protected]> Reviewed-by: Ricardo Neri <[email protected]> Tested-by: Arshad, Adeel<[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 930d06b commit c0e3acd

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

drivers/thermal/intel/intel_hfi.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ void intel_hfi_process_event(__u64 pkg_therm_status_msr_val)
250250
struct hfi_instance *hfi_instance;
251251
int cpu = smp_processor_id();
252252
struct hfi_cpu_info *info;
253-
u64 new_timestamp;
253+
u64 new_timestamp, msr, hfi;
254254

255255
if (!pkg_therm_status_msr_val)
256256
return;
@@ -279,9 +279,21 @@ void intel_hfi_process_event(__u64 pkg_therm_status_msr_val)
279279
if (!raw_spin_trylock(&hfi_instance->event_lock))
280280
return;
281281

282-
/* Skip duplicated updates. */
282+
rdmsrl(MSR_IA32_PACKAGE_THERM_STATUS, msr);
283+
hfi = msr & PACKAGE_THERM_STATUS_HFI_UPDATED;
284+
if (!hfi) {
285+
raw_spin_unlock(&hfi_instance->event_lock);
286+
return;
287+
}
288+
289+
/*
290+
* Ack duplicate update. Since there is an active HFI
291+
* status from HW, it must be a new event, not a case
292+
* where a lagging CPU entered the locked region.
293+
*/
283294
new_timestamp = *(u64 *)hfi_instance->hw_table;
284295
if (*hfi_instance->timestamp == new_timestamp) {
296+
thermal_clear_package_intr_status(PACKAGE_LEVEL, PACKAGE_THERM_STATUS_HFI_UPDATED);
285297
raw_spin_unlock(&hfi_instance->event_lock);
286298
return;
287299
}
@@ -295,15 +307,15 @@ void intel_hfi_process_event(__u64 pkg_therm_status_msr_val)
295307
memcpy(hfi_instance->local_table, hfi_instance->hw_table,
296308
hfi_features.nr_table_pages << PAGE_SHIFT);
297309

298-
raw_spin_unlock(&hfi_instance->table_lock);
299-
raw_spin_unlock(&hfi_instance->event_lock);
300-
301310
/*
302311
* Let hardware know that we are done reading the HFI table and it is
303312
* free to update it again.
304313
*/
305314
thermal_clear_package_intr_status(PACKAGE_LEVEL, PACKAGE_THERM_STATUS_HFI_UPDATED);
306315

316+
raw_spin_unlock(&hfi_instance->table_lock);
317+
raw_spin_unlock(&hfi_instance->event_lock);
318+
307319
queue_delayed_work(hfi_updates_wq, &hfi_instance->update_work,
308320
HFI_UPDATE_INTERVAL);
309321
}

0 commit comments

Comments
 (0)