diff options
Diffstat (limited to '')
-rw-r--r-- | tools/power/x86/intel-speed-select/isst-core.c | 434 |
1 files changed, 263 insertions, 171 deletions
diff --git a/tools/power/x86/intel-speed-select/isst-core.c b/tools/power/x86/intel-speed-select/isst-core.c index 81a119f688a3..f701b45c832c 100644 --- a/tools/power/x86/intel-speed-select/isst-core.c +++ b/tools/power/x86/intel-speed-select/isst-core.c @@ -6,7 +6,7 @@ #include "isst.h" -int isst_write_pm_config(int cpu, int cp_state) +int isst_write_pm_config(struct isst_id *id, int cp_state) { unsigned int req, resp; int ret; @@ -16,27 +16,27 @@ int isst_write_pm_config(int cpu, int cp_state) else req = 0; - ret = isst_send_mbox_command(cpu, WRITE_PM_CONFIG, PM_FEATURE, 0, req, + ret = isst_send_mbox_command(id->cpu, WRITE_PM_CONFIG, PM_FEATURE, 0, req, &resp); if (ret) return ret; - debug_printf("cpu:%d WRITE_PM_CONFIG resp:%x\n", cpu, resp); + debug_printf("cpu:%d WRITE_PM_CONFIG resp:%x\n", id->cpu, resp); return 0; } -int isst_read_pm_config(int cpu, int *cp_state, int *cp_cap) +int isst_read_pm_config(struct isst_id *id, int *cp_state, int *cp_cap) { unsigned int resp; int ret; - ret = isst_send_mbox_command(cpu, READ_PM_CONFIG, PM_FEATURE, 0, 0, + ret = isst_send_mbox_command(id->cpu, READ_PM_CONFIG, PM_FEATURE, 0, 0, &resp); if (ret) return ret; - debug_printf("cpu:%d READ_PM_CONFIG resp:%x\n", cpu, resp); + debug_printf("cpu:%d READ_PM_CONFIG resp:%x\n", id->cpu, resp); *cp_state = resp & BIT(16); *cp_cap = resp & BIT(0) ? 1 : 0; @@ -44,12 +44,12 @@ int isst_read_pm_config(int cpu, int *cp_state, int *cp_cap) return 0; } -int isst_get_ctdp_levels(int cpu, struct isst_pkg_ctdp *pkg_dev) +int isst_get_ctdp_levels(struct isst_id *id, struct isst_pkg_ctdp *pkg_dev) { unsigned int resp; int ret; - ret = isst_send_mbox_command(cpu, CONFIG_TDP, + ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_LEVELS_INFO, 0, 0, &resp); if (ret) { pkg_dev->levels = 0; @@ -60,7 +60,7 @@ int isst_get_ctdp_levels(int cpu, struct isst_pkg_ctdp *pkg_dev) return 0; } - debug_printf("cpu:%d CONFIG_TDP_GET_LEVELS_INFO resp:%x\n", cpu, resp); + debug_printf("cpu:%d CONFIG_TDP_GET_LEVELS_INFO resp:%x\n", id->cpu, resp); pkg_dev->version = resp & 0xff; pkg_dev->levels = (resp >> 8) & 0xff; @@ -71,14 +71,14 @@ int isst_get_ctdp_levels(int cpu, struct isst_pkg_ctdp *pkg_dev) return 0; } -int isst_get_ctdp_control(int cpu, int config_index, +int isst_get_ctdp_control(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level) { int cp_state, cp_cap; unsigned int resp; int ret; - ret = isst_send_mbox_command(cpu, CONFIG_TDP, + ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_TDP_CONTROL, 0, config_index, &resp); if (ret) @@ -89,51 +89,53 @@ int isst_get_ctdp_control(int cpu, int config_index, ctdp_level->fact_enabled = !!(resp & BIT(16)); ctdp_level->pbf_enabled = !!(resp & BIT(17)); - ret = isst_read_pm_config(cpu, &cp_state, &cp_cap); + ret = isst_read_pm_config(id, &cp_state, &cp_cap); if (ret) { - debug_printf("cpu:%d pm_config is not supported \n", cpu); + debug_printf("cpu:%d pm_config is not supported\n", id->cpu); } else { - debug_printf("cpu:%d pm_config SST-CP state:%d cap:%d \n", cpu, cp_state, cp_cap); + debug_printf("cpu:%d pm_config SST-CP state:%d cap:%d\n", id->cpu, cp_state, cp_cap); ctdp_level->sst_cp_support = cp_cap; ctdp_level->sst_cp_enabled = cp_state; } debug_printf( "cpu:%d CONFIG_TDP_GET_TDP_CONTROL resp:%x fact_support:%d pbf_support: %d fact_enabled:%d pbf_enabled:%d\n", - cpu, resp, ctdp_level->fact_support, ctdp_level->pbf_support, + id->cpu, resp, ctdp_level->fact_support, ctdp_level->pbf_support, ctdp_level->fact_enabled, ctdp_level->pbf_enabled); return 0; } -int isst_get_tdp_info(int cpu, int config_index, +int isst_get_tdp_info(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level) { unsigned int resp; int ret; - ret = isst_send_mbox_command(cpu, CONFIG_TDP, CONFIG_TDP_GET_TDP_INFO, + ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_TDP_INFO, 0, config_index, &resp); - if (ret) + if (ret) { + isst_display_error_info_message(1, "Invalid level, Can't get TDP information at level", 1, config_index); return ret; + } ctdp_level->pkg_tdp = resp & GENMASK(14, 0); ctdp_level->tdp_ratio = (resp & GENMASK(23, 16)) >> 16; debug_printf( "cpu:%d ctdp:%d CONFIG_TDP_GET_TDP_INFO resp:%x tdp_ratio:%d pkg_tdp:%d\n", - cpu, config_index, resp, ctdp_level->tdp_ratio, + id->cpu, config_index, resp, ctdp_level->tdp_ratio, ctdp_level->pkg_tdp); return 0; } -int isst_get_pwr_info(int cpu, int config_index, +int isst_get_pwr_info(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level) { unsigned int resp; int ret; - ret = isst_send_mbox_command(cpu, CONFIG_TDP, CONFIG_TDP_GET_PWR_INFO, + ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_PWR_INFO, 0, config_index, &resp); if (ret) return ret; @@ -143,18 +145,18 @@ int isst_get_pwr_info(int cpu, int config_index, debug_printf( "cpu:%d ctdp:%d CONFIG_TDP_GET_PWR_INFO resp:%x pkg_max_power:%d pkg_min_power:%d\n", - cpu, config_index, resp, ctdp_level->pkg_max_power, + id->cpu, config_index, resp, ctdp_level->pkg_max_power, ctdp_level->pkg_min_power); return 0; } -void isst_get_uncore_p0_p1_info(int cpu, int config_index, +void isst_get_uncore_p0_p1_info(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level) { unsigned int resp; int ret; - ret = isst_send_mbox_command(cpu, CONFIG_TDP, + ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_UNCORE_P0_P1_INFO, 0, config_index, &resp); if (ret) { @@ -167,16 +169,16 @@ void isst_get_uncore_p0_p1_info(int cpu, int config_index, ctdp_level->uncore_p1 = (resp & GENMASK(15, 8)) >> 8; debug_printf( "cpu:%d ctdp:%d CONFIG_TDP_GET_UNCORE_P0_P1_INFO resp:%x uncore p0:%d uncore p1:%d\n", - cpu, config_index, resp, ctdp_level->uncore_p0, + id->cpu, config_index, resp, ctdp_level->uncore_p0, ctdp_level->uncore_p1); } -void isst_get_p1_info(int cpu, int config_index, +void isst_get_p1_info(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level) { unsigned int resp; int ret; - ret = isst_send_mbox_command(cpu, CONFIG_TDP, CONFIG_TDP_GET_P1_INFO, 0, + ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_P1_INFO, 0, config_index, &resp); if (ret) { ctdp_level->sse_p1 = 0; @@ -190,16 +192,17 @@ void isst_get_p1_info(int cpu, int config_index, ctdp_level->avx512_p1 = (resp & GENMASK(23, 16)) >> 16; debug_printf( "cpu:%d ctdp:%d CONFIG_TDP_GET_P1_INFO resp:%x sse_p1:%d avx2_p1:%d avx512_p1:%d\n", - cpu, config_index, resp, ctdp_level->sse_p1, + id->cpu, config_index, resp, ctdp_level->sse_p1, ctdp_level->avx2_p1, ctdp_level->avx512_p1); } -void isst_get_uncore_mem_freq(int cpu, int config_index, +void isst_get_uncore_mem_freq(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level) { unsigned int resp; int ret; - ret = isst_send_mbox_command(cpu, CONFIG_TDP, CONFIG_TDP_GET_MEM_FREQ, + + ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_MEM_FREQ, 0, config_index, &resp); if (ret) { ctdp_level->mem_freq = 0; @@ -207,18 +210,32 @@ void isst_get_uncore_mem_freq(int cpu, int config_index, } ctdp_level->mem_freq = resp & GENMASK(7, 0); + if (is_spr_platform()) { + ctdp_level->mem_freq *= 200; + } else if (is_icx_platform()) { + if (ctdp_level->mem_freq < 7) { + ctdp_level->mem_freq = (12 - ctdp_level->mem_freq) * 133.33 * 2 * 10; + ctdp_level->mem_freq /= 10; + if (ctdp_level->mem_freq % 10 > 5) + ctdp_level->mem_freq++; + } else { + ctdp_level->mem_freq = 0; + } + } else { + ctdp_level->mem_freq = 0; + } debug_printf( "cpu:%d ctdp:%d CONFIG_TDP_GET_MEM_FREQ resp:%x uncore mem_freq:%d\n", - cpu, config_index, resp, ctdp_level->mem_freq); + id->cpu, config_index, resp, ctdp_level->mem_freq); } -int isst_get_tjmax_info(int cpu, int config_index, +int isst_get_tjmax_info(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level) { unsigned int resp; int ret; - ret = isst_send_mbox_command(cpu, CONFIG_TDP, CONFIG_TDP_GET_TJMAX_INFO, + ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_TJMAX_INFO, 0, config_index, &resp); if (ret) return ret; @@ -227,12 +244,12 @@ int isst_get_tjmax_info(int cpu, int config_index, debug_printf( "cpu:%d ctdp:%d CONFIG_TDP_GET_TJMAX_INFO resp:%x t_proc_hot:%d\n", - cpu, config_index, resp, ctdp_level->t_proc_hot); + id->cpu, config_index, resp, ctdp_level->t_proc_hot); return 0; } -int isst_get_coremask_info(int cpu, int config_index, +int isst_get_coremask_info(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level) { unsigned int resp; @@ -243,7 +260,7 @@ int isst_get_coremask_info(int cpu, int config_index, unsigned long long mask; int cpu_count = 0; - ret = isst_send_mbox_command(cpu, CONFIG_TDP, + ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_CORE_MASK, 0, (i << 8) | config_index, &resp); if (ret) @@ -251,27 +268,27 @@ int isst_get_coremask_info(int cpu, int config_index, debug_printf( "cpu:%d ctdp:%d mask:%d CONFIG_TDP_GET_CORE_MASK resp:%x\n", - cpu, config_index, i, resp); + id->cpu, config_index, i, resp); mask = (unsigned long long)resp << (32 * i); - set_cpu_mask_from_punit_coremask(cpu, mask, + set_cpu_mask_from_punit_coremask(id, mask, ctdp_level->core_cpumask_size, ctdp_level->core_cpumask, &cpu_count); ctdp_level->cpu_count += cpu_count; - debug_printf("cpu:%d ctdp:%d mask:%d cpu count:%d\n", cpu, + debug_printf("cpu:%d ctdp:%d mask:%d cpu count:%d\n", id->cpu, config_index, i, ctdp_level->cpu_count); } return 0; } -int isst_get_get_trl_from_msr(int cpu, int *trl) +int isst_get_get_trl_from_msr(struct isst_id *id, int *trl) { unsigned long long msr_trl; int ret; - ret = isst_send_msr_command(cpu, 0x1AD, 0, &msr_trl); + ret = isst_send_msr_command(id->cpu, 0x1AD, 0, &msr_trl); if (ret) return ret; @@ -287,13 +304,13 @@ int isst_get_get_trl_from_msr(int cpu, int *trl) return 0; } -int isst_get_get_trl(int cpu, int level, int avx_level, int *trl) +int isst_get_get_trl(struct isst_id *id, int level, int avx_level, int *trl) { unsigned int req, resp; int ret; req = level | (avx_level << 16); - ret = isst_send_mbox_command(cpu, CONFIG_TDP, + ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_TURBO_LIMIT_RATIOS, 0, req, &resp); if (ret) @@ -301,7 +318,7 @@ int isst_get_get_trl(int cpu, int level, int avx_level, int *trl) debug_printf( "cpu:%d CONFIG_TDP_GET_TURBO_LIMIT_RATIOS req:%x resp:%x\n", - cpu, req, resp); + id->cpu, req, resp); trl[0] = resp & GENMASK(7, 0); trl[1] = (resp & GENMASK(15, 8)) >> 8; @@ -309,13 +326,13 @@ int isst_get_get_trl(int cpu, int level, int avx_level, int *trl) trl[3] = (resp & GENMASK(31, 24)) >> 24; req = level | BIT(8) | (avx_level << 16); - ret = isst_send_mbox_command(cpu, CONFIG_TDP, + ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_TURBO_LIMIT_RATIOS, 0, req, &resp); if (ret) return ret; - debug_printf("cpu:%d CONFIG_TDP_GET_TURBO_LIMIT req:%x resp:%x\n", cpu, + debug_printf("cpu:%d CONFIG_TDP_GET_TURBO_LIMIT req:%x resp:%x\n", id->cpu, req, resp); trl[4] = resp & GENMASK(7, 0); @@ -326,76 +343,83 @@ int isst_get_get_trl(int cpu, int level, int avx_level, int *trl) return 0; } -int isst_get_trl_bucket_info(int cpu, unsigned long long *buckets_info) +int isst_get_trl_bucket_info(struct isst_id *id, unsigned long long *buckets_info) { int ret; - debug_printf("cpu:%d bucket info via MSR\n", cpu); + debug_printf("cpu:%d bucket info via MSR\n", id->cpu); *buckets_info = 0; - ret = isst_send_msr_command(cpu, 0x1ae, 0, buckets_info); + ret = isst_send_msr_command(id->cpu, 0x1ae, 0, buckets_info); if (ret) return ret; - debug_printf("cpu:%d bucket info via MSR successful 0x%llx\n", cpu, + debug_printf("cpu:%d bucket info via MSR successful 0x%llx\n", id->cpu, *buckets_info); return 0; } -int isst_set_tdp_level_msr(int cpu, int tdp_level) +int isst_set_tdp_level(struct isst_id *id, int tdp_level) { - unsigned long long level = tdp_level; + unsigned int resp; int ret; - debug_printf("cpu: tdp_level via MSR %d\n", cpu, tdp_level); - if (isst_get_config_tdp_lock_status(cpu)) { - debug_printf("cpu: tdp_locked %d\n", cpu); + if (isst_get_config_tdp_lock_status(id)) { + isst_display_error_info_message(1, "TDP is locked", 0, 0); return -1; - } - if (tdp_level > 2) - return -1; /* invalid value */ + } - ret = isst_send_msr_command(cpu, 0x64b, 1, &level); - if (ret) + ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_SET_LEVEL, 0, + tdp_level, &resp); + if (ret) { + isst_display_error_info_message(1, "Set TDP level failed for level", 1, tdp_level); return ret; - - debug_printf("cpu: tdp_level via MSR successful %d\n", cpu, tdp_level); + } return 0; } -int isst_set_tdp_level(int cpu, int tdp_level) +int isst_get_pbf_info(struct isst_id *id, int level, struct isst_pbf_info *pbf_info) { - unsigned int resp; - int ret; + struct isst_pkg_ctdp_level_info ctdp_level; + struct isst_pkg_ctdp pkg_dev; + int i, ret, max_punit_core, max_mask_index; + unsigned int req, resp; - ret = isst_send_mbox_command(cpu, CONFIG_TDP, CONFIG_TDP_SET_LEVEL, 0, - tdp_level, &resp); - if (ret) - return isst_set_tdp_level_msr(cpu, tdp_level); + ret = isst_get_ctdp_levels(id, &pkg_dev); + if (ret) { + isst_display_error_info_message(1, "Failed to get number of levels", 0, 0); + return ret; + } - return 0; -} + if (level > pkg_dev.levels) { + isst_display_error_info_message(1, "Invalid level", 1, level); + return -1; + } -int isst_get_pbf_info(int cpu, int level, struct isst_pbf_info *pbf_info) -{ - int i, ret, core_cnt, max; - unsigned int req, resp; + ret = isst_get_ctdp_control(id, level, &ctdp_level); + if (ret) + return ret; + + if (!ctdp_level.pbf_support) { + isst_display_error_info_message(1, "base-freq feature is not present at this level", 1, level); + return -1; + } pbf_info->core_cpumask_size = alloc_cpu_set(&pbf_info->core_cpumask); - core_cnt = get_core_count(get_physical_package_id(cpu), get_physical_die_id(cpu)); - max = core_cnt > 32 ? 2 : 1; + max_punit_core = get_max_punit_core_id(id); + max_mask_index = max_punit_core > 32 ? 2 : 1; - for (i = 0; i < max; ++i) { + for (i = 0; i < max_mask_index; ++i) { unsigned long long mask; int count; - ret = isst_send_mbox_command(cpu, CONFIG_TDP, + ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_PBF_GET_CORE_MASK_INFO, 0, (i << 8) | level, &resp); if (ret) @@ -403,23 +427,23 @@ int isst_get_pbf_info(int cpu, int level, struct isst_pbf_info *pbf_info) debug_printf( "cpu:%d CONFIG_TDP_PBF_GET_CORE_MASK_INFO resp:%x\n", - cpu, resp); + id->cpu, resp); mask = (unsigned long long)resp << (32 * i); - set_cpu_mask_from_punit_coremask(cpu, mask, + set_cpu_mask_from_punit_coremask(id, mask, pbf_info->core_cpumask_size, pbf_info->core_cpumask, &count); } req = level; - ret = isst_send_mbox_command(cpu, CONFIG_TDP, + ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_PBF_GET_P1HI_P1LO_INFO, 0, req, &resp); if (ret) return ret; - debug_printf("cpu:%d CONFIG_TDP_PBF_GET_P1HI_P1LO_INFO resp:%x\n", cpu, + debug_printf("cpu:%d CONFIG_TDP_PBF_GET_P1HI_P1LO_INFO resp:%x\n", id->cpu, resp); pbf_info->p1_low = resp & 0xff; @@ -427,21 +451,21 @@ int isst_get_pbf_info(int cpu, int level, struct isst_pbf_info *pbf_info) req = level; ret = isst_send_mbox_command( - cpu, CONFIG_TDP, CONFIG_TDP_PBF_GET_TDP_INFO, 0, req, &resp); + id->cpu, CONFIG_TDP, CONFIG_TDP_PBF_GET_TDP_INFO, 0, req, &resp); if (ret) return ret; - debug_printf("cpu:%d CONFIG_TDP_PBF_GET_TDP_INFO resp:%x\n", cpu, resp); + debug_printf("cpu:%d CONFIG_TDP_PBF_GET_TDP_INFO resp:%x\n", id->cpu, resp); pbf_info->tdp = resp & 0xffff; req = level; ret = isst_send_mbox_command( - cpu, CONFIG_TDP, CONFIG_TDP_PBF_GET_TJ_MAX_INFO, 0, req, &resp); + id->cpu, CONFIG_TDP, CONFIG_TDP_PBF_GET_TJ_MAX_INFO, 0, req, &resp); if (ret) return ret; - debug_printf("cpu:%d CONFIG_TDP_PBF_GET_TJ_MAX_INFO resp:%x\n", cpu, + debug_printf("cpu:%d CONFIG_TDP_PBF_GET_TJ_MAX_INFO resp:%x\n", id->cpu, resp); pbf_info->t_control = (resp >> 8) & 0xff; pbf_info->t_prochot = resp & 0xff; @@ -454,7 +478,7 @@ void isst_get_pbf_info_complete(struct isst_pbf_info *pbf_info) free_cpu_set(pbf_info->core_cpumask); } -int isst_set_pbf_fact_status(int cpu, int pbf, int enable) +int isst_set_pbf_fact_status(struct isst_id *id, int pbf, int enable) { struct isst_pkg_ctdp pkg_dev; struct isst_pkg_ctdp_level_info ctdp_level; @@ -462,13 +486,13 @@ int isst_set_pbf_fact_status(int cpu, int pbf, int enable) unsigned int req = 0, resp; int ret; - ret = isst_get_ctdp_levels(cpu, &pkg_dev); + ret = isst_get_ctdp_levels(id, &pkg_dev); if (ret) - debug_printf("cpu:%d No support for dynamic ISST\n", cpu); + debug_printf("cpu:%d No support for dynamic ISST\n", id->cpu); current_level = pkg_dev.current_level; - ret = isst_get_ctdp_control(cpu, current_level, &ctdp_level); + ret = isst_get_ctdp_control(id, current_level, &ctdp_level); if (ret) return ret; @@ -481,6 +505,10 @@ int isst_set_pbf_fact_status(int cpu, int pbf, int enable) else req &= ~BIT(17); } else { + + if (enable && !ctdp_level.sst_cp_enabled) + isst_display_error_info_message(0, "Make sure to execute before: core-power enable", 0, 0); + if (ctdp_level.pbf_enabled) req = BIT(17); @@ -490,18 +518,18 @@ int isst_set_pbf_fact_status(int cpu, int pbf, int enable) req &= ~BIT(16); } - ret = isst_send_mbox_command(cpu, CONFIG_TDP, + ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_SET_TDP_CONTROL, 0, req, &resp); if (ret) return ret; debug_printf("cpu:%d CONFIG_TDP_SET_TDP_CONTROL pbf/fact:%d req:%x\n", - cpu, pbf, req); + id->cpu, pbf, req); return 0; } -int isst_get_fact_bucket_info(int cpu, int level, +int isst_get_fact_bucket_info(struct isst_id *id, int level, struct isst_fact_bucket_info *bucket_info) { unsigned int resp; @@ -511,7 +539,7 @@ int isst_get_fact_bucket_info(int cpu, int level, int j; ret = isst_send_mbox_command( - cpu, CONFIG_TDP, + id->cpu, CONFIG_TDP, CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_NUMCORES, 0, (i << 8) | level, &resp); if (ret) @@ -519,7 +547,7 @@ int isst_get_fact_bucket_info(int cpu, int level, debug_printf( "cpu:%d CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_NUMCORES index:%d level:%d resp:%x\n", - cpu, i, level, resp); + id->cpu, i, level, resp); for (j = 0; j < 4; ++j) { bucket_info[j + (i * 4)].high_priority_cores_count = @@ -532,7 +560,7 @@ int isst_get_fact_bucket_info(int cpu, int level, int j; ret = isst_send_mbox_command( - cpu, CONFIG_TDP, + id->cpu, CONFIG_TDP, CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_RATIOS, 0, (k << 16) | (i << 8) | level, &resp); if (ret) @@ -540,7 +568,7 @@ int isst_get_fact_bucket_info(int cpu, int level, debug_printf( "cpu:%d CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_RATIOS index:%d level:%d avx:%d resp:%x\n", - cpu, i, level, k, resp); + id->cpu, i, level, k, resp); for (j = 0; j < 4; ++j) { switch (k) { @@ -566,44 +594,94 @@ int isst_get_fact_bucket_info(int cpu, int level, return 0; } -int isst_get_fact_info(int cpu, int level, struct isst_fact_info *fact_info) +int isst_get_fact_info(struct isst_id *id, int level, int fact_bucket, struct isst_fact_info *fact_info) { + struct isst_pkg_ctdp_level_info ctdp_level; + struct isst_pkg_ctdp pkg_dev; unsigned int resp; - int ret; + int j, ret, print; - ret = isst_send_mbox_command(cpu, CONFIG_TDP, + ret = isst_get_ctdp_levels(id, &pkg_dev); + if (ret) { + isst_display_error_info_message(1, "Failed to get number of levels", 0, 0); + return ret; + } + + if (level > pkg_dev.levels) { + isst_display_error_info_message(1, "Invalid level", 1, level); + return -1; + } + + ret = isst_get_ctdp_control(id, level, &ctdp_level); + if (ret) + return ret; + + if (!ctdp_level.fact_support) { + isst_display_error_info_message(1, "turbo-freq feature is not present at this level", 1, level); + return -1; + } + + ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_FACT_LP_CLIPPING_RATIO, 0, level, &resp); if (ret) return ret; debug_printf("cpu:%d CONFIG_TDP_GET_FACT_LP_CLIPPING_RATIO resp:%x\n", - cpu, resp); + id->cpu, resp); fact_info->lp_clipping_ratio_license_sse = resp & 0xff; fact_info->lp_clipping_ratio_license_avx2 = (resp >> 8) & 0xff; fact_info->lp_clipping_ratio_license_avx512 = (resp >> 16) & 0xff; - ret = isst_get_fact_bucket_info(cpu, level, fact_info->bucket_info); + ret = isst_get_fact_bucket_info(id, level, fact_info->bucket_info); + if (ret) + return ret; - return ret; + print = 0; + for (j = 0; j < ISST_FACT_MAX_BUCKETS; ++j) { + if (fact_bucket != 0xff && fact_bucket != j) + continue; + + if (!fact_info->bucket_info[j].high_priority_cores_count) + break; + + print = 1; + } + if (!print) { + isst_display_error_info_message(1, "Invalid bucket", 0, 0); + return -1; + } + + return 0; } -int isst_set_trl(int cpu, unsigned long long trl) +int isst_get_trl(struct isst_id *id, unsigned long long *trl) +{ + int ret; + + ret = isst_send_msr_command(id->cpu, 0x1AD, 0, trl); + if (ret) + return ret; + + return 0; +} + +int isst_set_trl(struct isst_id *id, unsigned long long trl) { int ret; if (!trl) trl = 0xFFFFFFFFFFFFFFFFULL; - ret = isst_send_msr_command(cpu, 0x1AD, 1, &trl); + ret = isst_send_msr_command(id->cpu, 0x1AD, 1, &trl); if (ret) return ret; return 0; } -int isst_set_trl_from_current_tdp(int cpu, unsigned long long trl) +int isst_set_trl_from_current_tdp(struct isst_id *id, unsigned long long trl) { unsigned long long msr_trl; int ret; @@ -615,11 +693,11 @@ int isst_set_trl_from_current_tdp(int cpu, unsigned long long trl) int trl[8]; int i; - ret = isst_get_ctdp_levels(cpu, &pkg_dev); + ret = isst_get_ctdp_levels(id, &pkg_dev); if (ret) return ret; - ret = isst_get_get_trl(cpu, pkg_dev.current_level, 0, trl); + ret = isst_get_get_trl(id, pkg_dev.current_level, 0, trl); if (ret) return ret; @@ -630,7 +708,7 @@ int isst_set_trl_from_current_tdp(int cpu, unsigned long long trl) msr_trl |= (_trl << (i * 8)); } } - ret = isst_send_msr_command(cpu, 0x1AD, 1, &msr_trl); + ret = isst_send_msr_command(id->cpu, 0x1AD, 1, &msr_trl); if (ret) return ret; @@ -638,12 +716,12 @@ int isst_set_trl_from_current_tdp(int cpu, unsigned long long trl) } /* Return 1 if locked */ -int isst_get_config_tdp_lock_status(int cpu) +int isst_get_config_tdp_lock_status(struct isst_id *id) { unsigned long long tdp_control = 0; int ret; - ret = isst_send_msr_command(cpu, 0x64b, 0, &tdp_control); + ret = isst_send_msr_command(id->cpu, 0x64b, 0, &tdp_control); if (ret) return ret; @@ -652,7 +730,7 @@ int isst_get_config_tdp_lock_status(int cpu) return ret; } -void isst_get_process_ctdp_complete(int cpu, struct isst_pkg_ctdp *pkg_dev) +void isst_get_process_ctdp_complete(struct isst_id *id, struct isst_pkg_ctdp *pkg_dev) { int i; @@ -669,126 +747,138 @@ void isst_get_process_ctdp_complete(int cpu, struct isst_pkg_ctdp *pkg_dev) } } -int isst_get_process_ctdp(int cpu, int tdp_level, struct isst_pkg_ctdp *pkg_dev) +int isst_get_process_ctdp(struct isst_id *id, int tdp_level, struct isst_pkg_ctdp *pkg_dev) { - int i, ret; + int i, ret, valid = 0; if (pkg_dev->processed) return 0; - ret = isst_get_ctdp_levels(cpu, pkg_dev); + ret = isst_get_ctdp_levels(id, pkg_dev); if (ret) return ret; debug_printf("cpu: %d ctdp enable:%d current level: %d levels:%d\n", - cpu, pkg_dev->enabled, pkg_dev->current_level, + id->cpu, pkg_dev->enabled, pkg_dev->current_level, pkg_dev->levels); + if (tdp_level != 0xff && tdp_level > pkg_dev->levels) { + isst_display_error_info_message(1, "Invalid level", 0, 0); + return -1; + } + + if (!pkg_dev->enabled) + isst_display_error_info_message(0, "perf-profile feature is not supported, just base-config level 0 is valid", 0, 0); + for (i = 0; i <= pkg_dev->levels; ++i) { struct isst_pkg_ctdp_level_info *ctdp_level; if (tdp_level != 0xff && i != tdp_level) continue; - debug_printf("cpu:%d Get Information for TDP level:%d\n", cpu, + debug_printf("cpu:%d Get Information for TDP level:%d\n", id->cpu, i); ctdp_level = &pkg_dev->ctdp_level[i]; ctdp_level->level = i; - ctdp_level->control_cpu = cpu; - ctdp_level->pkg_id = get_physical_package_id(cpu); - ctdp_level->die_id = get_physical_die_id(cpu); + ctdp_level->control_cpu = id->cpu; + ctdp_level->pkg_id = id->pkg; + ctdp_level->die_id = id->die; - ret = isst_get_ctdp_control(cpu, i, ctdp_level); + ret = isst_get_ctdp_control(id, i, ctdp_level); if (ret) continue; + valid = 1; pkg_dev->processed = 1; ctdp_level->processed = 1; if (ctdp_level->pbf_support) { - ret = isst_get_pbf_info(cpu, i, &ctdp_level->pbf_info); + ret = isst_get_pbf_info(id, i, &ctdp_level->pbf_info); if (!ret) ctdp_level->pbf_found = 1; } if (ctdp_level->fact_support) { - ret = isst_get_fact_info(cpu, i, + ret = isst_get_fact_info(id, i, 0xff, &ctdp_level->fact_info); if (ret) return ret; } - if (!pkg_dev->enabled) { + if (!pkg_dev->enabled && is_skx_based_platform()) { int freq; - freq = get_cpufreq_base_freq(cpu); + freq = get_cpufreq_base_freq(id->cpu); if (freq > 0) { ctdp_level->sse_p1 = freq / 100000; ctdp_level->tdp_ratio = ctdp_level->sse_p1; } - isst_get_get_trl_from_msr(cpu, ctdp_level->trl_sse_active_cores); - isst_get_trl_bucket_info(cpu, &ctdp_level->buckets_info); + isst_get_get_trl_from_msr(id, ctdp_level->trl_sse_active_cores); + isst_get_trl_bucket_info(id, &ctdp_level->buckets_info); continue; } - ret = isst_get_tdp_info(cpu, i, ctdp_level); + ret = isst_get_tdp_info(id, i, ctdp_level); if (ret) return ret; - ret = isst_get_pwr_info(cpu, i, ctdp_level); + ret = isst_get_pwr_info(id, i, ctdp_level); if (ret) return ret; - ret = isst_get_tjmax_info(cpu, i, ctdp_level); + ret = isst_get_tjmax_info(id, i, ctdp_level); if (ret) return ret; ctdp_level->core_cpumask_size = alloc_cpu_set(&ctdp_level->core_cpumask); - ret = isst_get_coremask_info(cpu, i, ctdp_level); + ret = isst_get_coremask_info(id, i, ctdp_level); if (ret) return ret; - ret = isst_get_trl_bucket_info(cpu, &ctdp_level->buckets_info); + ret = isst_get_trl_bucket_info(id, &ctdp_level->buckets_info); if (ret) return ret; - ret = isst_get_get_trl(cpu, i, 0, + ret = isst_get_get_trl(id, i, 0, ctdp_level->trl_sse_active_cores); if (ret) return ret; - ret = isst_get_get_trl(cpu, i, 1, + ret = isst_get_get_trl(id, i, 1, ctdp_level->trl_avx_active_cores); if (ret) return ret; - ret = isst_get_get_trl(cpu, i, 2, + ret = isst_get_get_trl(id, i, 2, ctdp_level->trl_avx_512_active_cores); if (ret) return ret; - isst_get_uncore_p0_p1_info(cpu, i, ctdp_level); - isst_get_p1_info(cpu, i, ctdp_level); - isst_get_uncore_mem_freq(cpu, i, ctdp_level); + isst_get_uncore_p0_p1_info(id, i, ctdp_level); + isst_get_p1_info(id, i, ctdp_level); + isst_get_uncore_mem_freq(id, i, ctdp_level); } + if (!valid) + isst_display_error_info_message(0, "Invalid level, Can't get TDP control information at specified levels on cpu", 1, id->cpu); + return 0; } -int isst_clos_get_clos_information(int cpu, int *enable, int *type) +int isst_clos_get_clos_information(struct isst_id *id, int *enable, int *type) { unsigned int resp; int ret; - ret = isst_send_mbox_command(cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG, 0, 0, + ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG, 0, 0, &resp); if (ret) return ret; - debug_printf("cpu:%d CLOS_PM_QOS_CONFIG resp:%x\n", cpu, resp); + debug_printf("cpu:%d CLOS_PM_QOS_CONFIG resp:%x\n", id->cpu, resp); if (resp & BIT(1)) *enable = 1; @@ -803,7 +893,7 @@ int isst_clos_get_clos_information(int cpu, int *enable, int *type) return 0; } -int isst_pm_qos_config(int cpu, int enable_clos, int priority_type) +int isst_pm_qos_config(struct isst_id *id, int enable_clos, int priority_type) { unsigned int req, resp; int ret; @@ -812,36 +902,38 @@ int isst_pm_qos_config(int cpu, int enable_clos, int priority_type) struct isst_pkg_ctdp pkg_dev; struct isst_pkg_ctdp_level_info ctdp_level; - ret = isst_get_ctdp_levels(cpu, &pkg_dev); + ret = isst_get_ctdp_levels(id, &pkg_dev); if (ret) { debug_printf("isst_get_ctdp_levels\n"); return ret; } - ret = isst_get_ctdp_control(cpu, pkg_dev.current_level, + ret = isst_get_ctdp_control(id, pkg_dev.current_level, &ctdp_level); if (ret) return ret; if (ctdp_level.fact_enabled) { - debug_printf("Turbo-freq feature must be disabled first\n"); + isst_display_error_info_message(1, "Ignoring request, turbo-freq feature is still enabled", 0, 0); return -EINVAL; } - ret = isst_write_pm_config(cpu, 0); + ret = isst_write_pm_config(id, 0); if (ret) - perror("isst_write_pm_config\n"); + isst_display_error_info_message(0, "WRITE_PM_CONFIG command failed, ignoring error", 0, 0); } else { - ret = isst_write_pm_config(cpu, 1); + ret = isst_write_pm_config(id, 1); if (ret) - perror("isst_write_pm_config\n"); + isst_display_error_info_message(0, "WRITE_PM_CONFIG command failed, ignoring error", 0, 0); } - ret = isst_send_mbox_command(cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG, 0, 0, + ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG, 0, 0, &resp); - if (ret) + if (ret) { + isst_display_error_info_message(1, "CLOS_PM_QOS_CONFIG command failed", 0, 0); return ret; + } - debug_printf("cpu:%d CLOS_PM_QOS_CONFIG resp:%x\n", cpu, resp); + debug_printf("cpu:%d CLOS_PM_QOS_CONFIG resp:%x\n", id->cpu, resp); req = resp; @@ -850,35 +942,35 @@ int isst_pm_qos_config(int cpu, int enable_clos, int priority_type) else req = req & ~BIT(1); + if (priority_type > 1) + isst_display_error_info_message(1, "Invalid priority type: Changing type to ordered", 0, 0); + if (priority_type) req = req | BIT(2); else req = req & ~BIT(2); - ret = isst_send_mbox_command(cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG, + ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG, BIT(MBOX_CMD_WRITE_BIT), req, &resp); if (ret) return ret; - debug_printf("cpu:%d CLOS_PM_QOS_CONFIG priority type:%d req:%x\n", cpu, + debug_printf("cpu:%d CLOS_PM_QOS_CONFIG priority type:%d req:%x\n", id->cpu, priority_type, req); return 0; } -int isst_pm_get_clos(int cpu, int clos, struct isst_clos_config *clos_config) +int isst_pm_get_clos(struct isst_id *id, int clos, struct isst_clos_config *clos_config) { unsigned int resp; int ret; - ret = isst_send_mbox_command(cpu, CONFIG_CLOS, CLOS_PM_CLOS, clos, 0, + ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_CLOS, clos, 0, &resp); if (ret) return ret; - clos_config->pkg_id = get_physical_package_id(cpu); - clos_config->die_id = get_physical_die_id(cpu); - clos_config->epp = resp & 0x0f; clos_config->clos_prop_prio = (resp >> 4) & 0x0f; clos_config->clos_min = (resp >> 8) & 0xff; @@ -888,7 +980,7 @@ int isst_pm_get_clos(int cpu, int clos, struct isst_clos_config *clos_config) return 0; } -int isst_set_clos(int cpu, int clos, struct isst_clos_config *clos_config) +int isst_set_clos(struct isst_id *id, int clos, struct isst_clos_config *clos_config) { unsigned int req, resp; unsigned int param; @@ -902,53 +994,53 @@ int isst_set_clos(int cpu, int clos, struct isst_clos_config *clos_config) param = BIT(MBOX_CMD_WRITE_BIT) | clos; - ret = isst_send_mbox_command(cpu, CONFIG_CLOS, CLOS_PM_CLOS, param, req, + ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_CLOS, param, req, &resp); if (ret) return ret; - debug_printf("cpu:%d CLOS_PM_CLOS param:%x req:%x\n", cpu, param, req); + debug_printf("cpu:%d CLOS_PM_CLOS param:%x req:%x\n", id->cpu, param, req); return 0; } -int isst_clos_get_assoc_status(int cpu, int *clos_id) +int isst_clos_get_assoc_status(struct isst_id *id, int *clos_id) { unsigned int resp; unsigned int param; int core_id, ret; - core_id = find_phy_core_num(cpu); + core_id = find_phy_core_num(id->cpu); param = core_id; - ret = isst_send_mbox_command(cpu, CONFIG_CLOS, CLOS_PQR_ASSOC, param, 0, + ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PQR_ASSOC, param, 0, &resp); if (ret) return ret; - debug_printf("cpu:%d CLOS_PQR_ASSOC param:%x resp:%x\n", cpu, param, + debug_printf("cpu:%d CLOS_PQR_ASSOC param:%x resp:%x\n", id->cpu, param, resp); *clos_id = (resp >> 16) & 0x03; return 0; } -int isst_clos_associate(int cpu, int clos_id) +int isst_clos_associate(struct isst_id *id, int clos_id) { unsigned int req, resp; unsigned int param; int core_id, ret; req = (clos_id & 0x03) << 16; - core_id = find_phy_core_num(cpu); + core_id = find_phy_core_num(id->cpu); param = BIT(MBOX_CMD_WRITE_BIT) | core_id; - ret = isst_send_mbox_command(cpu, CONFIG_CLOS, CLOS_PQR_ASSOC, param, + ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PQR_ASSOC, param, req, &resp); if (ret) return ret; - debug_printf("cpu:%d CLOS_PQR_ASSOC param:%x req:%x\n", cpu, param, + debug_printf("cpu:%d CLOS_PQR_ASSOC param:%x req:%x\n", id->cpu, param, req); return 0; |