Skip to content

Commit 5c897a9

Browse files
committed
Merge back earlier thermal control material for v6.10.
2 parents b552f63 + 0dbf608 commit 5c897a9

16 files changed

+417
-231
lines changed

drivers/thermal/gov_fair_share.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717

1818
static int get_trip_level(struct thermal_zone_device *tz)
1919
{
20-
const struct thermal_trip *trip, *level_trip = NULL;
20+
const struct thermal_trip *level_trip = NULL;
21+
const struct thermal_trip_desc *td;
2122
int trip_level = -1;
2223

23-
for_each_trip(tz, trip) {
24+
for_each_trip_desc(tz, td) {
25+
const struct thermal_trip *trip = &td->trip;
26+
2427
if (trip->temperature >= tz->temperature)
2528
continue;
2629

drivers/thermal/gov_power_allocator.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,11 @@ static void get_governor_trips(struct thermal_zone_device *tz,
496496
const struct thermal_trip *first_passive = NULL;
497497
const struct thermal_trip *last_passive = NULL;
498498
const struct thermal_trip *last_active = NULL;
499-
const struct thermal_trip *trip;
499+
const struct thermal_trip_desc *td;
500+
501+
for_each_trip_desc(tz, td) {
502+
const struct thermal_trip *trip = &td->trip;
500503

501-
for_each_trip(tz, trip) {
502504
switch (trip->type) {
503505
case THERMAL_TRIP_PASSIVE:
504506
if (!first_passive) {

drivers/thermal/gov_step_wise.c

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,40 +32,33 @@ static unsigned long get_target_state(struct thermal_instance *instance,
3232
{
3333
struct thermal_cooling_device *cdev = instance->cdev;
3434
unsigned long cur_state;
35-
unsigned long next_target;
3635

3736
/*
3837
* We keep this instance the way it is by default.
3938
* Otherwise, we use the current state of the
4039
* cdev in use to determine the next_target.
4140
*/
4241
cdev->ops->get_cur_state(cdev, &cur_state);
43-
next_target = instance->target;
4442
dev_dbg(&cdev->device, "cur_state=%ld\n", cur_state);
4543

4644
if (!instance->initialized) {
47-
if (throttle) {
48-
next_target = clamp((cur_state + 1), instance->lower, instance->upper);
49-
} else {
50-
next_target = THERMAL_NO_TARGET;
51-
}
45+
if (throttle)
46+
return clamp(cur_state + 1, instance->lower, instance->upper);
5247

53-
return next_target;
48+
return THERMAL_NO_TARGET;
5449
}
5550

5651
if (throttle) {
5752
if (trend == THERMAL_TREND_RAISING)
58-
next_target = clamp((cur_state + 1), instance->lower, instance->upper);
59-
} else {
60-
if (trend == THERMAL_TREND_DROPPING) {
61-
if (cur_state <= instance->lower)
62-
next_target = THERMAL_NO_TARGET;
63-
else
64-
next_target = clamp((cur_state - 1), instance->lower, instance->upper);
65-
}
53+
return clamp(cur_state + 1, instance->lower, instance->upper);
54+
} else if (trend == THERMAL_TREND_DROPPING) {
55+
if (cur_state <= instance->lower)
56+
return THERMAL_NO_TARGET;
57+
58+
return clamp(cur_state - 1, instance->lower, instance->upper);
6659
}
6760

68-
return next_target;
61+
return instance->target;
6962
}
7063

7164
static void thermal_zone_trip_update(struct thermal_zone_device *tz,
@@ -99,15 +92,13 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz,
9992
if (instance->initialized && old_target == instance->target)
10093
continue;
10194

102-
if (old_target == THERMAL_NO_TARGET &&
103-
instance->target != THERMAL_NO_TARGET) {
104-
/* Activate a passive thermal instance */
105-
if (trip->type == THERMAL_TRIP_PASSIVE)
95+
if (trip->type == THERMAL_TRIP_PASSIVE) {
96+
/* If needed, update the status of passive polling. */
97+
if (old_target == THERMAL_NO_TARGET &&
98+
instance->target != THERMAL_NO_TARGET)
10699
tz->passive++;
107-
} else if (old_target != THERMAL_NO_TARGET &&
108-
instance->target == THERMAL_NO_TARGET) {
109-
/* Deactivate a passive thermal instance */
110-
if (trip->type == THERMAL_TRIP_PASSIVE)
100+
else if (old_target != THERMAL_NO_TARGET &&
101+
instance->target == THERMAL_NO_TARGET)
111102
tz->passive--;
112103
}
113104

drivers/thermal/intel/int340x_thermal/acpi_thermal_rel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ static int acpi_parse_psvt(acpi_handle handle, int *psvt_count, struct psvt **ps
309309

310310
if (knob->type == ACPI_TYPE_STRING) {
311311
memset(&psvt->limit, 0, sizeof(u64));
312-
strncpy(psvt->limit.string, psvt_ptr->limit.str_ptr, knob->string.length);
312+
strscpy(psvt->limit.string, psvt_ptr->limit.str_ptr, ACPI_LIMIT_STR_MAX_LEN);
313313
} else {
314314
psvt->limit.integer = psvt_ptr->limit.integer;
315315
}
@@ -468,7 +468,7 @@ static int fill_psvt(char __user *ubuf)
468468
psvt_user[i].unlimit_coeff = psvts[i].unlimit_coeff;
469469
psvt_user[i].control_knob_type = psvts[i].control_knob_type;
470470
if (psvt_user[i].control_knob_type == ACPI_TYPE_STRING)
471-
strncpy(psvt_user[i].limit.string, psvts[i].limit.string,
471+
strscpy(psvt_user[i].limit.string, psvts[i].limit.string,
472472
ACPI_LIMIT_STR_MAX_LEN);
473473
else
474474
psvt_user[i].limit.integer = psvts[i].limit.integer;

drivers/thermal/intel/intel_hfi.c

Lines changed: 89 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ struct hfi_cpu_info {
159159
static DEFINE_PER_CPU(struct hfi_cpu_info, hfi_cpu_info) = { .index = -1 };
160160

161161
static int max_hfi_instances;
162+
static int hfi_clients_nr;
162163
static struct hfi_instance *hfi_instances;
163164

164165
static struct hfi_features hfi_features;
@@ -477,8 +478,11 @@ void intel_hfi_online(unsigned int cpu)
477478
enable:
478479
cpumask_set_cpu(cpu, hfi_instance->cpus);
479480

480-
/* Enable this HFI instance if this is its first online CPU. */
481-
if (cpumask_weight(hfi_instance->cpus) == 1) {
481+
/*
482+
* Enable this HFI instance if this is its first online CPU and
483+
* there are user-space clients of thermal events.
484+
*/
485+
if (cpumask_weight(hfi_instance->cpus) == 1 && hfi_clients_nr > 0) {
482486
hfi_set_hw_table(hfi_instance);
483487
hfi_enable();
484488
}
@@ -573,18 +577,33 @@ static __init int hfi_parse_features(void)
573577
return 0;
574578
}
575579

576-
static void hfi_do_enable(void)
580+
/*
581+
* If concurrency is not prevented by other means, the HFI enable/disable
582+
* routines must be called under hfi_instance_lock."
583+
*/
584+
static void hfi_enable_instance(void *ptr)
585+
{
586+
hfi_set_hw_table(ptr);
587+
hfi_enable();
588+
}
589+
590+
static void hfi_disable_instance(void *ptr)
591+
{
592+
hfi_disable();
593+
}
594+
595+
static void hfi_syscore_resume(void)
577596
{
578597
/* This code runs only on the boot CPU. */
579598
struct hfi_cpu_info *info = &per_cpu(hfi_cpu_info, 0);
580599
struct hfi_instance *hfi_instance = info->hfi_instance;
581600

582601
/* No locking needed. There is no concurrency with CPU online. */
583-
hfi_set_hw_table(hfi_instance);
584-
hfi_enable();
602+
if (hfi_clients_nr > 0)
603+
hfi_enable_instance(hfi_instance);
585604
}
586605

587-
static int hfi_do_disable(void)
606+
static int hfi_syscore_suspend(void)
588607
{
589608
/* No locking needed. There is no concurrency with CPU offline. */
590609
hfi_disable();
@@ -593,8 +612,58 @@ static int hfi_do_disable(void)
593612
}
594613

595614
static struct syscore_ops hfi_pm_ops = {
596-
.resume = hfi_do_enable,
597-
.suspend = hfi_do_disable,
615+
.resume = hfi_syscore_resume,
616+
.suspend = hfi_syscore_suspend,
617+
};
618+
619+
static int hfi_thermal_notify(struct notifier_block *nb, unsigned long state,
620+
void *_notify)
621+
{
622+
struct thermal_genl_notify *notify = _notify;
623+
struct hfi_instance *hfi_instance;
624+
smp_call_func_t func = NULL;
625+
unsigned int cpu;
626+
int i;
627+
628+
if (notify->mcgrp != THERMAL_GENL_EVENT_GROUP)
629+
return NOTIFY_DONE;
630+
631+
if (state != THERMAL_NOTIFY_BIND && state != THERMAL_NOTIFY_UNBIND)
632+
return NOTIFY_DONE;
633+
634+
mutex_lock(&hfi_instance_lock);
635+
636+
switch (state) {
637+
case THERMAL_NOTIFY_BIND:
638+
if (++hfi_clients_nr == 1)
639+
func = hfi_enable_instance;
640+
break;
641+
case THERMAL_NOTIFY_UNBIND:
642+
if (--hfi_clients_nr == 0)
643+
func = hfi_disable_instance;
644+
break;
645+
}
646+
647+
if (!func)
648+
goto out;
649+
650+
for (i = 0; i < max_hfi_instances; i++) {
651+
hfi_instance = &hfi_instances[i];
652+
if (cpumask_empty(hfi_instance->cpus))
653+
continue;
654+
655+
cpu = cpumask_any(hfi_instance->cpus);
656+
smp_call_function_single(cpu, func, hfi_instance, true);
657+
}
658+
659+
out:
660+
mutex_unlock(&hfi_instance_lock);
661+
662+
return NOTIFY_OK;
663+
}
664+
665+
static struct notifier_block hfi_thermal_nb = {
666+
.notifier_call = hfi_thermal_notify,
598667
};
599668

600669
void __init intel_hfi_init(void)
@@ -628,10 +697,22 @@ void __init intel_hfi_init(void)
628697
if (!hfi_updates_wq)
629698
goto err_nomem;
630699

700+
/*
701+
* Both thermal core and Intel HFI can not be build as modules.
702+
* As kernel build-in drivers they are initialized before user-space
703+
* starts, hence we can not miss BIND/UNBIND events when applications
704+
* add/remove thermal multicast group to/from a netlink socket.
705+
*/
706+
if (thermal_genl_register_notifier(&hfi_thermal_nb))
707+
goto err_nl_notif;
708+
631709
register_syscore_ops(&hfi_pm_ops);
632710

633711
return;
634712

713+
err_nl_notif:
714+
destroy_workqueue(hfi_updates_wq);
715+
635716
err_nomem:
636717
for (j = 0; j < i; ++j) {
637718
hfi_instance = &hfi_instances[j];

0 commit comments

Comments
 (0)