@@ -55,7 +55,7 @@ MODULE_PARM_DESC(notify_delay_ms,
55
55
*/
56
56
#define MAX_NUMBER_OF_TRIPS 2
57
57
58
- struct pkg_device {
58
+ struct zone_device {
59
59
int cpu ;
60
60
bool work_scheduled ;
61
61
u32 tj_max ;
@@ -70,10 +70,10 @@ static struct thermal_zone_params pkg_temp_tz_params = {
70
70
.no_hwmon = true,
71
71
};
72
72
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 ;
77
77
/* Serializes interrupt notification, work and hotplug */
78
78
static DEFINE_SPINLOCK (pkg_temp_lock );
79
79
/* Protects zone operation in the work function against hotplug removal */
@@ -120,12 +120,12 @@ static int pkg_temp_debugfs_init(void)
120
120
*
121
121
* - Other callsites: Must hold pkg_temp_lock
122
122
*/
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 )
124
124
{
125
- int pkgid = topology_logical_die_id (cpu );
125
+ int id = topology_logical_die_id (cpu );
126
126
127
- if (pkgid >= 0 && pkgid < max_packages )
128
- return packages [ pkgid ];
127
+ if (id >= 0 && id < max_id )
128
+ return zones [ id ];
129
129
return NULL ;
130
130
}
131
131
@@ -150,12 +150,13 @@ static int get_tj_max(int cpu, u32 *tj_max)
150
150
151
151
static int sys_get_curr_temp (struct thermal_zone_device * tzd , int * temp )
152
152
{
153
- struct pkg_device * pkgdev = tzd -> devdata ;
153
+ struct zone_device * zonedev = tzd -> devdata ;
154
154
u32 eax , edx ;
155
155
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 );
157
158
if (eax & 0x80000000 ) {
158
- * temp = pkgdev -> tj_max - ((eax >> 16 ) & 0x7f ) * 1000 ;
159
+ * temp = zonedev -> tj_max - ((eax >> 16 ) & 0x7f ) * 1000 ;
159
160
pr_debug ("sys_get_curr_temp %d\n" , * temp );
160
161
return 0 ;
161
162
}
@@ -165,7 +166,7 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
165
166
static int sys_get_trip_temp (struct thermal_zone_device * tzd ,
166
167
int trip , int * temp )
167
168
{
168
- struct pkg_device * pkgdev = tzd -> devdata ;
169
+ struct zone_device * zonedev = tzd -> devdata ;
169
170
unsigned long thres_reg_value ;
170
171
u32 mask , shift , eax , edx ;
171
172
int ret ;
@@ -181,14 +182,14 @@ static int sys_get_trip_temp(struct thermal_zone_device *tzd,
181
182
shift = THERM_SHIFT_THRESHOLD0 ;
182
183
}
183
184
184
- ret = rdmsr_on_cpu (pkgdev -> cpu , MSR_IA32_PACKAGE_THERM_INTERRUPT ,
185
+ ret = rdmsr_on_cpu (zonedev -> cpu , MSR_IA32_PACKAGE_THERM_INTERRUPT ,
185
186
& eax , & edx );
186
187
if (ret < 0 )
187
188
return ret ;
188
189
189
190
thres_reg_value = (eax & mask ) >> shift ;
190
191
if (thres_reg_value )
191
- * temp = pkgdev -> tj_max - thres_reg_value * 1000 ;
192
+ * temp = zonedev -> tj_max - thres_reg_value * 1000 ;
192
193
else
193
194
* temp = 0 ;
194
195
pr_debug ("sys_get_trip_temp %d\n" , * temp );
@@ -199,14 +200,14 @@ static int sys_get_trip_temp(struct thermal_zone_device *tzd,
199
200
static int
200
201
sys_set_trip_temp (struct thermal_zone_device * tzd , int trip , int temp )
201
202
{
202
- struct pkg_device * pkgdev = tzd -> devdata ;
203
+ struct zone_device * zonedev = tzd -> devdata ;
203
204
u32 l , h , mask , shift , intr ;
204
205
int ret ;
205
206
206
- if (trip >= MAX_NUMBER_OF_TRIPS || temp >= pkgdev -> tj_max )
207
+ if (trip >= MAX_NUMBER_OF_TRIPS || temp >= zonedev -> tj_max )
207
208
return - EINVAL ;
208
209
209
- ret = rdmsr_on_cpu (pkgdev -> cpu , MSR_IA32_PACKAGE_THERM_INTERRUPT ,
210
+ ret = rdmsr_on_cpu (zonedev -> cpu , MSR_IA32_PACKAGE_THERM_INTERRUPT ,
210
211
& l , & h );
211
212
if (ret < 0 )
212
213
return ret ;
@@ -228,11 +229,12 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
228
229
if (!temp ) {
229
230
l &= ~intr ;
230
231
} else {
231
- l |= (pkgdev -> tj_max - temp )/1000 << shift ;
232
+ l |= (zonedev -> tj_max - temp )/1000 << shift ;
232
233
l |= intr ;
233
234
}
234
235
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 );
236
238
}
237
239
238
240
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)
287
289
{
288
290
struct thermal_zone_device * tzone = NULL ;
289
291
int cpu = smp_processor_id ();
290
- struct pkg_device * pkgdev ;
292
+ struct zone_device * zonedev ;
291
293
u64 msr_val , wr_val ;
292
294
293
295
mutex_lock (& thermal_zone_mutex );
294
296
spin_lock_irq (& pkg_temp_lock );
295
297
++ pkg_work_cnt ;
296
298
297
- pkgdev = pkg_temp_thermal_get_dev (cpu );
298
- if (!pkgdev ) {
299
+ zonedev = pkg_temp_thermal_get_dev (cpu );
300
+ if (!zonedev ) {
299
301
spin_unlock_irq (& pkg_temp_lock );
300
302
mutex_unlock (& thermal_zone_mutex );
301
303
return ;
302
304
}
303
- pkgdev -> work_scheduled = false;
305
+ zonedev -> work_scheduled = false;
304
306
305
307
rdmsrl (MSR_IA32_PACKAGE_THERM_STATUS , msr_val );
306
308
wr_val = msr_val & ~(THERM_LOG_THRESHOLD0 | THERM_LOG_THRESHOLD1 );
307
309
if (wr_val != msr_val ) {
308
310
wrmsrl (MSR_IA32_PACKAGE_THERM_STATUS , wr_val );
309
- tzone = pkgdev -> tzone ;
311
+ tzone = zonedev -> tzone ;
310
312
}
311
313
312
314
enable_pkg_thres_interrupt ();
@@ -332,7 +334,7 @@ static void pkg_thermal_schedule_work(int cpu, struct delayed_work *work)
332
334
static int pkg_thermal_notify (u64 msr_val )
333
335
{
334
336
int cpu = smp_processor_id ();
335
- struct pkg_device * pkgdev ;
337
+ struct zone_device * zonedev ;
336
338
unsigned long flags ;
337
339
338
340
spin_lock_irqsave (& pkg_temp_lock , flags );
@@ -341,10 +343,10 @@ static int pkg_thermal_notify(u64 msr_val)
341
343
disable_pkg_thres_interrupt ();
342
344
343
345
/* 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 );
348
350
}
349
351
350
352
spin_unlock_irqrestore (& pkg_temp_lock , flags );
@@ -353,12 +355,12 @@ static int pkg_thermal_notify(u64 msr_val)
353
355
354
356
static int pkg_temp_thermal_device_add (unsigned int cpu )
355
357
{
356
- int pkgid = topology_logical_die_id (cpu );
358
+ int id = topology_logical_die_id (cpu );
357
359
u32 tj_max , eax , ebx , ecx , edx ;
358
- struct pkg_device * pkgdev ;
360
+ struct zone_device * zonedev ;
359
361
int thres_count , err ;
360
362
361
- if (pkgid >= max_packages )
363
+ if (id >= max_id )
362
364
return - ENOMEM ;
363
365
364
366
cpuid (6 , & eax , & ebx , & ecx , & edx );
@@ -372,51 +374,51 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
372
374
if (err )
373
375
return err ;
374
376
375
- pkgdev = kzalloc (sizeof (* pkgdev ), GFP_KERNEL );
376
- if (!pkgdev )
377
+ zonedev = kzalloc (sizeof (* zonedev ), GFP_KERNEL );
378
+ if (!zonedev )
377
379
return - ENOMEM ;
378
380
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" ,
383
385
thres_count ,
384
386
(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 );
389
391
return err ;
390
392
}
391
393
/* 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 );
394
396
395
- cpumask_set_cpu (cpu , & pkgdev -> cpumask );
397
+ cpumask_set_cpu (cpu , & zonedev -> cpumask );
396
398
spin_lock_irq (& pkg_temp_lock );
397
- packages [ pkgid ] = pkgdev ;
399
+ zones [ id ] = zonedev ;
398
400
spin_unlock_irq (& pkg_temp_lock );
399
401
return 0 ;
400
402
}
401
403
402
404
static int pkg_thermal_cpu_offline (unsigned int cpu )
403
405
{
404
- struct pkg_device * pkgdev = pkg_temp_thermal_get_dev (cpu );
406
+ struct zone_device * zonedev = pkg_temp_thermal_get_dev (cpu );
405
407
bool lastcpu , was_target ;
406
408
int target ;
407
409
408
- if (!pkgdev )
410
+ if (!zonedev )
409
411
return 0 ;
410
412
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 );
413
415
lastcpu = target >= nr_cpu_ids ;
414
416
/*
415
417
* Remove the sysfs files, if this is the last cpu in the package
416
418
* before doing further cleanups.
417
419
*/
418
420
if (lastcpu ) {
419
- struct thermal_zone_device * tzone = pkgdev -> tzone ;
421
+ struct thermal_zone_device * tzone = zonedev -> tzone ;
420
422
421
423
/*
422
424
* We must protect against a work function calling
@@ -425,7 +427,7 @@ static int pkg_thermal_cpu_offline(unsigned int cpu)
425
427
* won't try to call.
426
428
*/
427
429
mutex_lock (& thermal_zone_mutex );
428
- pkgdev -> tzone = NULL ;
430
+ zonedev -> tzone = NULL ;
429
431
mutex_unlock (& thermal_zone_mutex );
430
432
431
433
thermal_zone_device_unregister (tzone );
@@ -439,8 +441,8 @@ static int pkg_thermal_cpu_offline(unsigned int cpu)
439
441
* one. When we drop the lock, then the interrupt notify function
440
442
* will see the new target.
441
443
*/
442
- was_target = pkgdev -> cpu == cpu ;
443
- pkgdev -> cpu = target ;
444
+ was_target = zonedev -> cpu == cpu ;
445
+ zonedev -> cpu = target ;
444
446
445
447
/*
446
448
* 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)
449
451
* worker will see the package anymore.
450
452
*/
451
453
if (lastcpu ) {
452
- packages [topology_logical_die_id (cpu )] = NULL ;
454
+ zones [topology_logical_die_id (cpu )] = NULL ;
453
455
/* After this point nothing touches the MSR anymore. */
454
456
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 );
456
458
}
457
459
458
460
/*
459
461
* Check whether there is work scheduled and whether the work is
460
462
* targeted at the outgoing CPU.
461
463
*/
462
- if (pkgdev -> work_scheduled && was_target ) {
464
+ if (zonedev -> work_scheduled && was_target ) {
463
465
/*
464
466
* To cancel the work we need to drop the lock, otherwise
465
467
* we might deadlock if the work needs to be flushed.
466
468
*/
467
469
spin_unlock_irq (& pkg_temp_lock );
468
- cancel_delayed_work_sync (& pkgdev -> work );
470
+ cancel_delayed_work_sync (& zonedev -> work );
469
471
spin_lock_irq (& pkg_temp_lock );
470
472
/*
471
473
* If this is not the last cpu in the package and the work
472
474
* did not run after we dropped the lock above, then we
473
475
* need to reschedule the work, otherwise the interrupt
474
476
* stays disabled forever.
475
477
*/
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 );
478
480
}
479
481
480
482
spin_unlock_irq (& pkg_temp_lock );
481
483
482
484
/* Final cleanup if this is the last cpu */
483
485
if (lastcpu )
484
- kfree (pkgdev );
486
+ kfree (zonedev );
485
487
return 0 ;
486
488
}
487
489
488
490
static int pkg_thermal_cpu_online (unsigned int cpu )
489
491
{
490
- struct pkg_device * pkgdev = pkg_temp_thermal_get_dev (cpu );
492
+ struct zone_device * zonedev = pkg_temp_thermal_get_dev (cpu );
491
493
struct cpuinfo_x86 * c = & cpu_data (cpu );
492
494
493
495
/* Paranoia check */
494
496
if (!cpu_has (c , X86_FEATURE_DTHERM ) || !cpu_has (c , X86_FEATURE_PTS ))
495
497
return - ENODEV ;
496
498
497
499
/* 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 );
500
502
return 0 ;
501
503
}
502
504
return pkg_temp_thermal_device_add (cpu );
@@ -515,10 +517,10 @@ static int __init pkg_temp_thermal_init(void)
515
517
if (!x86_match_cpu (pkg_temp_thermal_ids ))
516
518
return - ENODEV ;
517
519
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 * ),
520
522
GFP_KERNEL );
521
- if (!packages )
523
+ if (!zones )
522
524
return - ENOMEM ;
523
525
524
526
ret = cpuhp_setup_state (CPUHP_AP_ONLINE_DYN , "thermal/x86_pkg:online" ,
@@ -537,7 +539,7 @@ static int __init pkg_temp_thermal_init(void)
537
539
return 0 ;
538
540
539
541
err :
540
- kfree (packages );
542
+ kfree (zones );
541
543
return ret ;
542
544
}
543
545
module_init (pkg_temp_thermal_init )
@@ -549,7 +551,7 @@ static void __exit pkg_temp_thermal_exit(void)
549
551
550
552
cpuhp_remove_state (pkg_thermal_hp_state );
551
553
debugfs_remove_recursive (debugfs );
552
- kfree (packages );
554
+ kfree (zones );
553
555
}
554
556
module_exit (pkg_temp_thermal_exit )
555
557
0 commit comments