X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=examples%2Fvm_power_manager%2Fpower_manager.c;h=7b4f4b3c4dfaeabc189f90e90aaf771a40c4a3b7;hb=936e294c8eb025df7f070b62389ee8ce49d6463f;hp=4bdde23daf1a37ec2be624554b054c6d52a4eae0;hpb=6453b9284b64ffee841c73193ed26b1f3ebc5b99;p=dpdk.git diff --git a/examples/vm_power_manager/power_manager.c b/examples/vm_power_manager/power_manager.c index 4bdde23daf..7b4f4b3c4d 100644 --- a/examples/vm_power_manager/power_manager.c +++ b/examples/vm_power_manager/power_manager.c @@ -33,27 +33,13 @@ rte_spinlock_unlock(&global_core_freq_info[core_num].power_sl); \ } while (0) -#define POWER_SCALE_MASK(DIRECTION, core_mask, ret) do { \ - int i; \ - for (i = 0; core_mask; core_mask &= ~(1 << i++)) { \ - if ((core_mask >> i) & 1) { \ - if (!(ci.cd[i].global_enabled_cpus)) \ - continue; \ - rte_spinlock_lock(&global_core_freq_info[i].power_sl); \ - if (rte_power_freq_##DIRECTION(i) != 1) \ - ret = -1; \ - rte_spinlock_unlock(&global_core_freq_info[i].power_sl); \ - } \ - } \ -} while (0) - struct freq_info { rte_spinlock_t power_sl; uint32_t freqs[RTE_MAX_LCORE_FREQS]; unsigned num_freqs; } __rte_cache_aligned; -static struct freq_info global_core_freq_info[POWER_MGR_MAX_CPUS]; +static struct freq_info global_core_freq_info[RTE_MAX_LCORE]; struct core_info ci; @@ -74,15 +60,15 @@ core_info_init(void) ci = get_core_info(); ci->core_count = get_nprocs_conf(); + ci->branch_ratio_threshold = BRANCH_RATIO_THRESHOLD; ci->cd = malloc(ci->core_count * sizeof(struct core_details)); + memset(ci->cd, 0, ci->core_count * sizeof(struct core_details)); if (!ci->cd) { RTE_LOG(ERR, POWER_MANAGER, "Failed to allocate memory for core info."); return -1; } for (i = 0; i < ci->core_count; i++) { ci->cd[i].global_enabled_cpus = 1; - ci->cd[i].oob_enabled = 0; - ci->cd[i].msr_fd = 0; } printf("%d cores in system\n", ci->core_count); return 0; @@ -94,8 +80,9 @@ power_manager_init(void) unsigned int i, num_cpus = 0, num_freqs = 0; int ret = 0; struct core_info *ci; + unsigned int max_core_num; - rte_power_set_env(PM_ENV_ACPI_CPUFREQ); + rte_power_set_env(PM_ENV_NOT_SET); ci = get_core_info(); if (!ci) { @@ -104,7 +91,12 @@ power_manager_init(void) return -1; } - for (i = 0; i < ci->core_count; i++) { + if (ci->core_count > RTE_MAX_LCORE) + max_core_num = RTE_MAX_LCORE; + else + max_core_num = ci->core_count; + + for (i = 0; i < max_core_num; i++) { if (ci->cd[i].global_enabled_cpus) { if (rte_power_init(i) < 0) RTE_LOG(ERR, POWER_MANAGER, @@ -139,9 +131,9 @@ power_manager_get_current_frequency(unsigned core_num) { uint32_t freq, index; - if (core_num >= POWER_MGR_MAX_CPUS) { + if (core_num >= RTE_MAX_LCORE) { RTE_LOG(ERR, POWER_MANAGER, "Core(%u) is out of range 0...%d\n", - core_num, POWER_MGR_MAX_CPUS-1); + core_num, RTE_MAX_LCORE-1); return -1; } if (!(ci.cd[core_num].global_enabled_cpus)) @@ -150,7 +142,7 @@ power_manager_get_current_frequency(unsigned core_num) rte_spinlock_lock(&global_core_freq_info[core_num].power_sl); index = rte_power_get_freq(core_num); rte_spinlock_unlock(&global_core_freq_info[core_num].power_sl); - if (index >= POWER_MGR_MAX_CPUS) + if (index >= RTE_MAX_LCORE_FREQS) freq = 0; else freq = global_core_freq_info[core_num].freqs[index]; @@ -164,6 +156,7 @@ power_manager_exit(void) unsigned int i; int ret = 0; struct core_info *ci; + unsigned int max_core_num; ci = get_core_info(); if (!ci) { @@ -172,7 +165,12 @@ power_manager_exit(void) return -1; } - for (i = 0; i < ci->core_count; i++) { + if (ci->core_count > RTE_MAX_LCORE) + max_core_num = RTE_MAX_LCORE; + else + max_core_num = ci->core_count; + + for (i = 0; i < max_core_num; i++) { if (ci->cd[i].global_enabled_cpus) { if (rte_power_exit(i) < 0) { RTE_LOG(ERR, POWER_MANAGER, "Unable to shutdown power manager " @@ -186,60 +184,6 @@ power_manager_exit(void) return ret; } -int -power_manager_scale_mask_up(uint64_t core_mask) -{ - int ret = 0; - - POWER_SCALE_MASK(up, core_mask, ret); - return ret; -} - -int -power_manager_scale_mask_down(uint64_t core_mask) -{ - int ret = 0; - - POWER_SCALE_MASK(down, core_mask, ret); - return ret; -} - -int -power_manager_scale_mask_min(uint64_t core_mask) -{ - int ret = 0; - - POWER_SCALE_MASK(min, core_mask, ret); - return ret; -} - -int -power_manager_scale_mask_max(uint64_t core_mask) -{ - int ret = 0; - - POWER_SCALE_MASK(max, core_mask, ret); - return ret; -} - -int -power_manager_enable_turbo_mask(uint64_t core_mask) -{ - int ret = 0; - - POWER_SCALE_MASK(enable_turbo, core_mask, ret); - return ret; -} - -int -power_manager_disable_turbo_mask(uint64_t core_mask) -{ - int ret = 0; - - POWER_SCALE_MASK(disable_turbo, core_mask, ret); - return ret; -} - int power_manager_scale_core_up(unsigned core_num) { @@ -301,7 +245,7 @@ power_manager_scale_core_med(unsigned int core_num) struct core_info *ci; ci = get_core_info(); - if (core_num >= POWER_MGR_MAX_CPUS) + if (core_num >= RTE_MAX_LCORE) return -1; if (!(ci->cd[core_num].global_enabled_cpus)) return -1;