@@ -1229,46 +1229,59 @@ static void adjust_scaling_max_from_base_freq(int cpu);
1229
1229
static void set_tdp_level_for_cpu (struct isst_id * id , void * arg1 , void * arg2 , void * arg3 ,
1230
1230
void * arg4 )
1231
1231
{
1232
+ struct isst_pkg_ctdp pkg_dev ;
1232
1233
int ret ;
1233
1234
1235
+ ret = isst_get_ctdp_levels (id , & pkg_dev );
1236
+ if (ret ) {
1237
+ isst_display_error_info_message (1 , "Get TDP level failed" , 0 , 0 );
1238
+ isst_ctdp_display_information_end (outf );
1239
+ exit (1 );
1240
+ }
1241
+
1242
+ if (pkg_dev .current_level == tdp_level ) {
1243
+ debug_printf ("TDP level already set. Skipped\n" );
1244
+ goto display_result ;
1245
+ }
1246
+
1234
1247
ret = isst_set_tdp_level (id , tdp_level );
1235
1248
if (ret ) {
1236
1249
isst_display_error_info_message (1 , "Set TDP level failed" , 0 , 0 );
1237
1250
isst_ctdp_display_information_end (outf );
1238
1251
exit (1 );
1239
- } else {
1240
- isst_display_result ( id , outf , "perf-profile" , "set_tdp_level" ,
1241
- ret );
1242
- if ( force_online_offline ) {
1243
- struct isst_pkg_ctdp_level_info ctdp_level ;
1244
-
1245
- /* Wait for updated base frequencies */
1246
- usleep ( 2000 );
1247
-
1248
- /* Adjusting uncore freq */
1249
- isst_adjust_uncore_freq ( id , tdp_level , & ctdp_level );
1250
-
1251
- fprintf ( stderr , "Option is set to online/offline\n" );
1252
- ctdp_level . core_cpumask_size =
1253
- alloc_cpu_set ( & ctdp_level .core_cpumask );
1254
- ret = isst_get_coremask_info ( id , tdp_level , & ctdp_level );
1255
- if ( ret ) {
1256
- isst_display_error_info_message ( 1 , "Can't get coremask, online/offline option is ignored" , 0 , 0 );
1257
- return ;
1258
- }
1259
- if ( ctdp_level . cpu_count ) {
1260
- int i , max_cpus = get_topo_max_cpus ();
1261
- for ( i = 0 ; i < max_cpus ; ++ i ) {
1262
- if (! is_cpu_in_power_domain ( i , id ))
1263
- continue ;
1264
- if ( CPU_ISSET_S ( i , ctdp_level . core_cpumask_size , ctdp_level . core_cpumask )) {
1265
- fprintf ( stderr , "online cpu %d\n" , i );
1266
- set_cpu_online_offline ( i , 1 );
1267
- adjust_scaling_max_from_base_freq ( i );
1268
- } else {
1269
- fprintf ( stderr , "offline cpu %d\n" , i );
1270
- set_cpu_online_offline ( i , 0 );
1271
- }
1252
+ }
1253
+
1254
+ display_result :
1255
+ isst_display_result ( id , outf , "perf-profile" , "set_tdp_level" , ret );
1256
+ if ( force_online_offline ) {
1257
+ struct isst_pkg_ctdp_level_info ctdp_level ;
1258
+
1259
+ /* Wait for updated base frequencies */
1260
+ usleep ( 2000 );
1261
+
1262
+ /* Adjusting uncore freq */
1263
+ isst_adjust_uncore_freq ( id , tdp_level , & ctdp_level );
1264
+
1265
+ fprintf ( stderr , "Option is set to online/offline\n" );
1266
+ ctdp_level .core_cpumask_size =
1267
+ alloc_cpu_set ( & ctdp_level . core_cpumask );
1268
+ ret = isst_get_coremask_info ( id , tdp_level , & ctdp_level );
1269
+ if ( ret ) {
1270
+ isst_display_error_info_message ( 1 , "Can't get coremask, online/offline option is ignored" , 0 , 0 ) ;
1271
+ return ;
1272
+ }
1273
+ if ( ctdp_level . cpu_count ) {
1274
+ int i , max_cpus = get_topo_max_cpus ();
1275
+ for ( i = 0 ; i < max_cpus ; ++ i ) {
1276
+ if (! is_cpu_in_power_domain ( i , id ))
1277
+ continue ;
1278
+ if ( CPU_ISSET_S ( i , ctdp_level . core_cpumask_size , ctdp_level . core_cpumask )) {
1279
+ fprintf ( stderr , "online cpu %d\n" , i );
1280
+ set_cpu_online_offline ( i , 1 );
1281
+ adjust_scaling_max_from_base_freq ( i );
1282
+ } else {
1283
+ fprintf ( stderr , "offline cpu %d\n" , i );
1284
+ set_cpu_online_offline ( i , 0 );
1272
1285
}
1273
1286
}
1274
1287
}
0 commit comments