Skip to content

Commit b2ce1c8

Browse files
lenbKAGA-KOKO
authored andcommitted
thermal/x86_pkg_temp_thermal: Cosmetic: Rename internal variables to zones from packages
Syntax update only -- no logical or functional change. In response to the new multi-die/package changes, update variable names to use the more generic thermal "zone" terminology, instead of "package", as the zones can refer to either packages or die. Signed-off-by: Len Brown <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Ingo Molnar <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Cc: Zhang Rui <[email protected]> Link: https://lkml.kernel.org/r/b65494a76be13481dc3a809c75debb2574c34eda.1557769318.git.len.brown@intel.com
1 parent cb63ba0 commit b2ce1c8

File tree

1 file changed

+72
-70
lines changed

1 file changed

+72
-70
lines changed

drivers/thermal/intel/x86_pkg_temp_thermal.c

Lines changed: 72 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ MODULE_PARM_DESC(notify_delay_ms,
5555
*/
5656
#define MAX_NUMBER_OF_TRIPS 2
5757

58-
struct pkg_device {
58+
struct zone_device {
5959
int cpu;
6060
bool work_scheduled;
6161
u32 tj_max;
@@ -70,10 +70,10 @@ static struct thermal_zone_params pkg_temp_tz_params = {
7070
.no_hwmon = true,
7171
};
7272

73-
/* Keep track of how many package pointers we allocated in init() */
74-
static int max_packages __read_mostly;
75-
/* Array of package pointers */
76-
static struct pkg_device **packages;
73+
/* Keep track of how many zone pointers we allocated in init() */
74+
static int max_id __read_mostly;
75+
/* Array of zone pointers */
76+
static struct zone_device **zones;
7777
/* Serializes interrupt notification, work and hotplug */
7878
static DEFINE_SPINLOCK(pkg_temp_lock);
7979
/* Protects zone operation in the work function against hotplug removal */
@@ -120,12 +120,12 @@ static int pkg_temp_debugfs_init(void)
120120
*
121121
* - Other callsites: Must hold pkg_temp_lock
122122
*/
123-
static struct pkg_device *pkg_temp_thermal_get_dev(unsigned int cpu)
123+
static struct zone_device *pkg_temp_thermal_get_dev(unsigned int cpu)
124124
{
125-
int pkgid = topology_logical_die_id(cpu);
125+
int id = topology_logical_die_id(cpu);
126126

127-
if (pkgid >= 0 && pkgid < max_packages)
128-
return packages[pkgid];
127+
if (id >= 0 && id < max_id)
128+
return zones[id];
129129
return NULL;
130130
}
131131

@@ -150,12 +150,13 @@ static int get_tj_max(int cpu, u32 *tj_max)
150150

151151
static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
152152
{
153-
struct pkg_device *pkgdev = tzd->devdata;
153+
struct zone_device *zonedev = tzd->devdata;
154154
u32 eax, edx;
155155

156-
rdmsr_on_cpu(pkgdev->cpu, MSR_IA32_PACKAGE_THERM_STATUS, &eax, &edx);
156+
rdmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_STATUS,
157+
&eax, &edx);
157158
if (eax & 0x80000000) {
158-
*temp = pkgdev->tj_max - ((eax >> 16) & 0x7f) * 1000;
159+
*temp = zonedev->tj_max - ((eax >> 16) & 0x7f) * 1000;
159160
pr_debug("sys_get_curr_temp %d\n", *temp);
160161
return 0;
161162
}
@@ -165,7 +166,7 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
165166
static int sys_get_trip_temp(struct thermal_zone_device *tzd,
166167
int trip, int *temp)
167168
{
168-
struct pkg_device *pkgdev = tzd->devdata;
169+
struct zone_device *zonedev = tzd->devdata;
169170
unsigned long thres_reg_value;
170171
u32 mask, shift, eax, edx;
171172
int ret;
@@ -181,14 +182,14 @@ static int sys_get_trip_temp(struct thermal_zone_device *tzd,
181182
shift = THERM_SHIFT_THRESHOLD0;
182183
}
183184

184-
ret = rdmsr_on_cpu(pkgdev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
185+
ret = rdmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
185186
&eax, &edx);
186187
if (ret < 0)
187188
return ret;
188189

189190
thres_reg_value = (eax & mask) >> shift;
190191
if (thres_reg_value)
191-
*temp = pkgdev->tj_max - thres_reg_value * 1000;
192+
*temp = zonedev->tj_max - thres_reg_value * 1000;
192193
else
193194
*temp = 0;
194195
pr_debug("sys_get_trip_temp %d\n", *temp);
@@ -199,14 +200,14 @@ static int sys_get_trip_temp(struct thermal_zone_device *tzd,
199200
static int
200201
sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
201202
{
202-
struct pkg_device *pkgdev = tzd->devdata;
203+
struct zone_device *zonedev = tzd->devdata;
203204
u32 l, h, mask, shift, intr;
204205
int ret;
205206

206-
if (trip >= MAX_NUMBER_OF_TRIPS || temp >= pkgdev->tj_max)
207+
if (trip >= MAX_NUMBER_OF_TRIPS || temp >= zonedev->tj_max)
207208
return -EINVAL;
208209

209-
ret = rdmsr_on_cpu(pkgdev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
210+
ret = rdmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
210211
&l, &h);
211212
if (ret < 0)
212213
return ret;
@@ -228,11 +229,12 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
228229
if (!temp) {
229230
l &= ~intr;
230231
} else {
231-
l |= (pkgdev->tj_max - temp)/1000 << shift;
232+
l |= (zonedev->tj_max - temp)/1000 << shift;
232233
l |= intr;
233234
}
234235

235-
return wrmsr_on_cpu(pkgdev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
236+
return wrmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
237+
l, h);
236238
}
237239

238240
static int sys_get_trip_type(struct thermal_zone_device *thermal, int trip,
@@ -287,26 +289,26 @@ static void pkg_temp_thermal_threshold_work_fn(struct work_struct *work)
287289
{
288290
struct thermal_zone_device *tzone = NULL;
289291
int cpu = smp_processor_id();
290-
struct pkg_device *pkgdev;
292+
struct zone_device *zonedev;
291293
u64 msr_val, wr_val;
292294

293295
mutex_lock(&thermal_zone_mutex);
294296
spin_lock_irq(&pkg_temp_lock);
295297
++pkg_work_cnt;
296298

297-
pkgdev = pkg_temp_thermal_get_dev(cpu);
298-
if (!pkgdev) {
299+
zonedev = pkg_temp_thermal_get_dev(cpu);
300+
if (!zonedev) {
299301
spin_unlock_irq(&pkg_temp_lock);
300302
mutex_unlock(&thermal_zone_mutex);
301303
return;
302304
}
303-
pkgdev->work_scheduled = false;
305+
zonedev->work_scheduled = false;
304306

305307
rdmsrl(MSR_IA32_PACKAGE_THERM_STATUS, msr_val);
306308
wr_val = msr_val & ~(THERM_LOG_THRESHOLD0 | THERM_LOG_THRESHOLD1);
307309
if (wr_val != msr_val) {
308310
wrmsrl(MSR_IA32_PACKAGE_THERM_STATUS, wr_val);
309-
tzone = pkgdev->tzone;
311+
tzone = zonedev->tzone;
310312
}
311313

312314
enable_pkg_thres_interrupt();
@@ -332,7 +334,7 @@ static void pkg_thermal_schedule_work(int cpu, struct delayed_work *work)
332334
static int pkg_thermal_notify(u64 msr_val)
333335
{
334336
int cpu = smp_processor_id();
335-
struct pkg_device *pkgdev;
337+
struct zone_device *zonedev;
336338
unsigned long flags;
337339

338340
spin_lock_irqsave(&pkg_temp_lock, flags);
@@ -341,10 +343,10 @@ static int pkg_thermal_notify(u64 msr_val)
341343
disable_pkg_thres_interrupt();
342344

343345
/* Work is per package, so scheduling it once is enough. */
344-
pkgdev = pkg_temp_thermal_get_dev(cpu);
345-
if (pkgdev && !pkgdev->work_scheduled) {
346-
pkgdev->work_scheduled = true;
347-
pkg_thermal_schedule_work(pkgdev->cpu, &pkgdev->work);
346+
zonedev = pkg_temp_thermal_get_dev(cpu);
347+
if (zonedev && !zonedev->work_scheduled) {
348+
zonedev->work_scheduled = true;
349+
pkg_thermal_schedule_work(zonedev->cpu, &zonedev->work);
348350
}
349351

350352
spin_unlock_irqrestore(&pkg_temp_lock, flags);
@@ -353,12 +355,12 @@ static int pkg_thermal_notify(u64 msr_val)
353355

354356
static int pkg_temp_thermal_device_add(unsigned int cpu)
355357
{
356-
int pkgid = topology_logical_die_id(cpu);
358+
int id = topology_logical_die_id(cpu);
357359
u32 tj_max, eax, ebx, ecx, edx;
358-
struct pkg_device *pkgdev;
360+
struct zone_device *zonedev;
359361
int thres_count, err;
360362

361-
if (pkgid >= max_packages)
363+
if (id >= max_id)
362364
return -ENOMEM;
363365

364366
cpuid(6, &eax, &ebx, &ecx, &edx);
@@ -372,51 +374,51 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
372374
if (err)
373375
return err;
374376

375-
pkgdev = kzalloc(sizeof(*pkgdev), GFP_KERNEL);
376-
if (!pkgdev)
377+
zonedev = kzalloc(sizeof(*zonedev), GFP_KERNEL);
378+
if (!zonedev)
377379
return -ENOMEM;
378380

379-
INIT_DELAYED_WORK(&pkgdev->work, pkg_temp_thermal_threshold_work_fn);
380-
pkgdev->cpu = cpu;
381-
pkgdev->tj_max = tj_max;
382-
pkgdev->tzone = thermal_zone_device_register("x86_pkg_temp",
381+
INIT_DELAYED_WORK(&zonedev->work, pkg_temp_thermal_threshold_work_fn);
382+
zonedev->cpu = cpu;
383+
zonedev->tj_max = tj_max;
384+
zonedev->tzone = thermal_zone_device_register("x86_pkg_temp",
383385
thres_count,
384386
(thres_count == MAX_NUMBER_OF_TRIPS) ? 0x03 : 0x01,
385-
pkgdev, &tzone_ops, &pkg_temp_tz_params, 0, 0);
386-
if (IS_ERR(pkgdev->tzone)) {
387-
err = PTR_ERR(pkgdev->tzone);
388-
kfree(pkgdev);
387+
zonedev, &tzone_ops, &pkg_temp_tz_params, 0, 0);
388+
if (IS_ERR(zonedev->tzone)) {
389+
err = PTR_ERR(zonedev->tzone);
390+
kfree(zonedev);
389391
return err;
390392
}
391393
/* Store MSR value for package thermal interrupt, to restore at exit */
392-
rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, pkgdev->msr_pkg_therm_low,
393-
pkgdev->msr_pkg_therm_high);
394+
rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, zonedev->msr_pkg_therm_low,
395+
zonedev->msr_pkg_therm_high);
394396

395-
cpumask_set_cpu(cpu, &pkgdev->cpumask);
397+
cpumask_set_cpu(cpu, &zonedev->cpumask);
396398
spin_lock_irq(&pkg_temp_lock);
397-
packages[pkgid] = pkgdev;
399+
zones[id] = zonedev;
398400
spin_unlock_irq(&pkg_temp_lock);
399401
return 0;
400402
}
401403

402404
static int pkg_thermal_cpu_offline(unsigned int cpu)
403405
{
404-
struct pkg_device *pkgdev = pkg_temp_thermal_get_dev(cpu);
406+
struct zone_device *zonedev = pkg_temp_thermal_get_dev(cpu);
405407
bool lastcpu, was_target;
406408
int target;
407409

408-
if (!pkgdev)
410+
if (!zonedev)
409411
return 0;
410412

411-
target = cpumask_any_but(&pkgdev->cpumask, cpu);
412-
cpumask_clear_cpu(cpu, &pkgdev->cpumask);
413+
target = cpumask_any_but(&zonedev->cpumask, cpu);
414+
cpumask_clear_cpu(cpu, &zonedev->cpumask);
413415
lastcpu = target >= nr_cpu_ids;
414416
/*
415417
* Remove the sysfs files, if this is the last cpu in the package
416418
* before doing further cleanups.
417419
*/
418420
if (lastcpu) {
419-
struct thermal_zone_device *tzone = pkgdev->tzone;
421+
struct thermal_zone_device *tzone = zonedev->tzone;
420422

421423
/*
422424
* We must protect against a work function calling
@@ -425,7 +427,7 @@ static int pkg_thermal_cpu_offline(unsigned int cpu)
425427
* won't try to call.
426428
*/
427429
mutex_lock(&thermal_zone_mutex);
428-
pkgdev->tzone = NULL;
430+
zonedev->tzone = NULL;
429431
mutex_unlock(&thermal_zone_mutex);
430432

431433
thermal_zone_device_unregister(tzone);
@@ -439,8 +441,8 @@ static int pkg_thermal_cpu_offline(unsigned int cpu)
439441
* one. When we drop the lock, then the interrupt notify function
440442
* will see the new target.
441443
*/
442-
was_target = pkgdev->cpu == cpu;
443-
pkgdev->cpu = target;
444+
was_target = zonedev->cpu == cpu;
445+
zonedev->cpu = target;
444446

445447
/*
446448
* If this is the last CPU in the package remove the package
@@ -449,54 +451,54 @@ static int pkg_thermal_cpu_offline(unsigned int cpu)
449451
* worker will see the package anymore.
450452
*/
451453
if (lastcpu) {
452-
packages[topology_logical_die_id(cpu)] = NULL;
454+
zones[topology_logical_die_id(cpu)] = NULL;
453455
/* After this point nothing touches the MSR anymore. */
454456
wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT,
455-
pkgdev->msr_pkg_therm_low, pkgdev->msr_pkg_therm_high);
457+
zonedev->msr_pkg_therm_low, zonedev->msr_pkg_therm_high);
456458
}
457459

458460
/*
459461
* Check whether there is work scheduled and whether the work is
460462
* targeted at the outgoing CPU.
461463
*/
462-
if (pkgdev->work_scheduled && was_target) {
464+
if (zonedev->work_scheduled && was_target) {
463465
/*
464466
* To cancel the work we need to drop the lock, otherwise
465467
* we might deadlock if the work needs to be flushed.
466468
*/
467469
spin_unlock_irq(&pkg_temp_lock);
468-
cancel_delayed_work_sync(&pkgdev->work);
470+
cancel_delayed_work_sync(&zonedev->work);
469471
spin_lock_irq(&pkg_temp_lock);
470472
/*
471473
* If this is not the last cpu in the package and the work
472474
* did not run after we dropped the lock above, then we
473475
* need to reschedule the work, otherwise the interrupt
474476
* stays disabled forever.
475477
*/
476-
if (!lastcpu && pkgdev->work_scheduled)
477-
pkg_thermal_schedule_work(target, &pkgdev->work);
478+
if (!lastcpu && zonedev->work_scheduled)
479+
pkg_thermal_schedule_work(target, &zonedev->work);
478480
}
479481

480482
spin_unlock_irq(&pkg_temp_lock);
481483

482484
/* Final cleanup if this is the last cpu */
483485
if (lastcpu)
484-
kfree(pkgdev);
486+
kfree(zonedev);
485487
return 0;
486488
}
487489

488490
static int pkg_thermal_cpu_online(unsigned int cpu)
489491
{
490-
struct pkg_device *pkgdev = pkg_temp_thermal_get_dev(cpu);
492+
struct zone_device *zonedev = pkg_temp_thermal_get_dev(cpu);
491493
struct cpuinfo_x86 *c = &cpu_data(cpu);
492494

493495
/* Paranoia check */
494496
if (!cpu_has(c, X86_FEATURE_DTHERM) || !cpu_has(c, X86_FEATURE_PTS))
495497
return -ENODEV;
496498

497499
/* If the package exists, nothing to do */
498-
if (pkgdev) {
499-
cpumask_set_cpu(cpu, &pkgdev->cpumask);
500+
if (zonedev) {
501+
cpumask_set_cpu(cpu, &zonedev->cpumask);
500502
return 0;
501503
}
502504
return pkg_temp_thermal_device_add(cpu);
@@ -515,10 +517,10 @@ static int __init pkg_temp_thermal_init(void)
515517
if (!x86_match_cpu(pkg_temp_thermal_ids))
516518
return -ENODEV;
517519

518-
max_packages = topology_max_packages() * topology_max_die_per_package();
519-
packages = kcalloc(max_packages, sizeof(struct pkg_device *),
520+
max_id = topology_max_packages() * topology_max_die_per_package();
521+
zones = kcalloc(max_id, sizeof(struct zone_device *),
520522
GFP_KERNEL);
521-
if (!packages)
523+
if (!zones)
522524
return -ENOMEM;
523525

524526
ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "thermal/x86_pkg:online",
@@ -537,7 +539,7 @@ static int __init pkg_temp_thermal_init(void)
537539
return 0;
538540

539541
err:
540-
kfree(packages);
542+
kfree(zones);
541543
return ret;
542544
}
543545
module_init(pkg_temp_thermal_init)
@@ -549,7 +551,7 @@ static void __exit pkg_temp_thermal_exit(void)
549551

550552
cpuhp_remove_state(pkg_thermal_hp_state);
551553
debugfs_remove_recursive(debugfs);
552-
kfree(packages);
554+
kfree(zones);
553555
}
554556
module_exit(pkg_temp_thermal_exit)
555557

0 commit comments

Comments
 (0)