Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PM: EM: Refactor em_adjust_new_capacity()

Extract em_table_dup() and em_recalc_and_update() from
em_adjust_new_capacity(). Both functions will be later reused by the
'update EM due to chip binning' functionality.

Reviewed-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Lukasz Luba and committed by
Rafael J. Wysocki
d61c2695 e3ac0f36

+39 -19
+39 -19
kernel/power/energy_model.c
··· 674 674 } 675 675 EXPORT_SYMBOL_GPL(em_dev_unregister_perf_domain); 676 676 677 - /* 678 - * Adjustment of CPU performance values after boot, when all CPUs capacites 679 - * are correctly calculated. 680 - */ 681 - static void em_adjust_new_capacity(struct device *dev, 682 - struct em_perf_domain *pd, 683 - u64 max_cap) 677 + static struct em_perf_table __rcu *em_table_dup(struct em_perf_domain *pd) 684 678 { 685 679 struct em_perf_table __rcu *em_table; 686 680 struct em_perf_state *ps, *new_ps; 687 - int ret, ps_size; 681 + int ps_size; 688 682 689 683 em_table = em_table_alloc(pd); 690 - if (!em_table) { 691 - dev_warn(dev, "EM: allocation failed\n"); 692 - return; 693 - } 684 + if (!em_table) 685 + return NULL; 694 686 695 687 new_ps = em_table->state; 696 688 ··· 694 702 695 703 rcu_read_unlock(); 696 704 697 - em_init_performance(dev, pd, new_ps, pd->nr_perf_states); 698 - ret = em_compute_costs(dev, new_ps, NULL, pd->nr_perf_states, 705 + return em_table; 706 + } 707 + 708 + static int em_recalc_and_update(struct device *dev, struct em_perf_domain *pd, 709 + struct em_perf_table __rcu *em_table) 710 + { 711 + int ret; 712 + 713 + ret = em_compute_costs(dev, em_table->state, NULL, pd->nr_perf_states, 699 714 pd->flags); 700 - if (ret) { 701 - dev_warn(dev, "EM: compute costs failed\n"); 702 - return; 703 - } 715 + if (ret) 716 + goto free_em_table; 704 717 705 718 ret = em_dev_update_perf_domain(dev, em_table); 706 719 if (ret) 707 - dev_warn(dev, "EM: update failed %d\n", ret); 720 + goto free_em_table; 708 721 709 722 /* 710 723 * This is one-time-update, so give up the ownership in this updater. 711 724 * The EM framework has incremented the usage counter and from now 712 725 * will keep the reference (then free the memory when needed). 713 726 */ 727 + free_em_table: 714 728 em_table_free(em_table); 729 + return ret; 730 + } 731 + 732 + /* 733 + * Adjustment of CPU performance values after boot, when all CPUs capacites 734 + * are correctly calculated. 735 + */ 736 + static void em_adjust_new_capacity(struct device *dev, 737 + struct em_perf_domain *pd, 738 + u64 max_cap) 739 + { 740 + struct em_perf_table __rcu *em_table; 741 + 742 + em_table = em_table_dup(pd); 743 + if (!em_table) { 744 + dev_warn(dev, "EM: allocation failed\n"); 745 + return; 746 + } 747 + 748 + em_init_performance(dev, pd, em_table->state, pd->nr_perf_states); 749 + 750 + em_recalc_and_update(dev, pd, em_table); 715 751 } 716 752 717 753 static void em_check_capacity_update(void)