From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161581AbbKFMF5 (ORCPT ); Fri, 6 Nov 2015 07:05:57 -0500 Received: from mailout3.w1.samsung.com ([210.118.77.13]:60116 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161362AbbKFMDk (ORCPT ); Fri, 6 Nov 2015 07:03:40 -0500 X-AuditID: cbfec7f5-f794b6d000001495-d6-563c971a3ec5 From: Arseniy Krasnov To: linux@arm.linux.org.uk, mingo@redhat.com, peterz@infradead.org Cc: a.krasnov@samsung.com, v.tyrtov@samsung.com, s.rogachev@samsung.com, linux-kernel@vger.kernel.org, Tarek Dakhran , Sergey Dyasly , Dmitriy Safonov , Ilya Maximets Subject: [PATCH 06/13] hperf_hmp: is_hmp_imbalance introduced. Date: Fri, 06 Nov 2015 15:02:40 +0300 Message-id: <1446811367-23783-7-git-send-email-a.krasnov@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1446811367-23783-1-git-send-email-a.krasnov@samsung.com> References: <1446811367-23783-1-git-send-email-a.krasnov@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrBLMWRmVeSWpSXmKPExsVy+t/xK7pS023CDCZdUbWY91nQ4tPKp2wW V9p/sltc3jWHzeL2ZV6LSwcWMFkc7z3AZDF5tpTFu63XWC3WPz/FaDF1xg92B26PluYeNo/N K7Q8Dr7bw+Txft9VNo++LasYPT5vkgtgi+KySUnNySxLLdK3S+DKOLfDpuCEUsW21vdMDYzH ZboYOTkkBEwktq5uZIWwxSQu3FvP1sXIxSEksJRR4t3Tv0wQTjuTxNwrvUwgVWwCuhI/N25h A7FFBJwkep6dZQSxmQUmM0ls+JoGYgsL2En0b38GVsMioCrR0bIEzOYVcJXYNKWBEWKbnMTJ Y5PBNnMKuEl0dN1mB7GFgGo6zr5jmcDIu4CRYRWjaGppckFxUnqukV5xYm5xaV66XnJ+7iZG SPh93cG49JjVIUYBDkYlHl6D5dZhQqyJZcWVuYcYJTiYlUR45ZhtwoR4UxIrq1KL8uOLSnNS iw8xSnOwKInzztz1PkRIID2xJDU7NbUgtQgmy8TBKdXAKDJtjaSLZ2vzfWFZBlcxcU9TwUm/ L4n7OIg9ztgem9lzSn6DypIPT05tElP6Fp2rZma0QI6/l5Exd/GV6KU1f44EBvi0e3Gkbmkv 6b246IebBue+YyvErzF/Mcj4tlnzoNHWIuFagXluVXeENE2KP3C9E7Zl14kK8UuUfLhD/7d7 2i3Bmf+VWIozEg21mIuKEwEiS+pfOwIAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 'is_hmp_imbalance' function calculates imbalance between clusters, four cases are possible: balancing from/to one of clusters, task swap(when clusters are balanced) or skip rebalance. Function calculates load difference between two cluster(cluster load / cluster power) and threshold when balancing is needed. Signed-off-by: Tarek Dakhran Signed-off-by: Sergey Dyasly Signed-off-by: Dmitriy Safonov Signed-off-by: Arseniy Krasnov Signed-off-by: Ilya Maximets --- kernel/sched/fair.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index e94fab4..3ab39b6 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -104,9 +104,21 @@ unsigned int __read_mostly sysctl_sched_shares_window = 10000000UL; extern void hmp_set_cpu_masks(struct cpumask *, struct cpumask *); static atomic_t a15_nr_hmp_busy = ATOMIC_INIT(0); static atomic_t a7_nr_hmp_busy = ATOMIC_INIT(0); + +/* Total weight of all running tasks on A15 and A7 CPU domains */ +static atomic_long_t a15_total_weight = ATOMIC_LONG_INIT(0); +static atomic_long_t a7_total_weight = ATOMIC_LONG_INIT(0); + static atomic_t hmp_imbalance = ATOMIC_INIT(0); static unsigned int freq_scale_cpu_power[CONFIG_NR_CPUS]; + +enum hmp_balance_actions { + SWAP_TASKS, + A15_TO_A7, + A7_TO_A15, + SKIP_REBALANCE, +}; #endif /* CONFIG_HPERF_HMP */ #ifdef CONFIG_CFS_BANDWIDTH @@ -7016,6 +7028,97 @@ static int should_we_balance(struct lb_env *env) */ return balance_cpu == env->dst_cpu; } +#ifdef CONFIG_HPERF_HMP +/** + * is_hmp_imbalance(): Calculates imbalance between HMP domains. + * @sd: Current sched domain. + * + * Returns migration direction(see SWAP_TASKS, A15_TO_A7, A7_TO_A15, + * SKIP_REBALANCE). + * + * Imbalance depends on load of tasks on A15 cores and A7 cores, + * current CPU's frequencies, and A7 slowdown coefficient which is about 2.4. + */ +static int is_hmp_imbalance(struct sched_domain *sd) +{ + int imbalance, cpu; + int a15_group_power = 0, a7_group_power = 0, + hmp_imbalance_min_threshold; + int a15_group_load, a7_group_load, a15_a7_group_power; + unsigned int a7_balanced_num; + int reminder, divisor; + unsigned int a15_balanced_num; + long long int hmp_imbalance_threshold; + + if (!sd->a15_group) { + return SKIP_REBALANCE; + } + + if (!sd->a7_group) { + return SKIP_REBALANCE; + } + for_each_online_cpu(cpu) { + if (cpu_is_fastest(cpu)) + a15_group_power += freq_scale_cpu_power[cpu]; + else + a7_group_power += freq_scale_cpu_power[cpu]; + } + + if (a15_group_power == 0 || a7_group_power == 0) { + return SKIP_REBALANCE; + } + + a15_balanced_num = 0; + a7_balanced_num = 0; + + for_each_online_cpu(cpu) { + if (cpu_rq(cpu)->cfs.h_nr_running <= 1) { + if (cpu_is_fastest(cpu)) + a15_balanced_num++; + else + a7_balanced_num++; + } + } + + a7_group_load = atomic_long_read(&a7_total_weight); + + if (atomic_long_read(&a7_total_weight) == 0 && + (a15_balanced_num == sd->a15_group->group_weight)) { + return SKIP_REBALANCE; + } + + a15_group_load = atomic_long_read(&a15_total_weight); + a15_a7_group_power = a15_group_power + a7_group_power; + + imbalance = (a15_group_load * 1024) / (a15_group_power) - + (a7_group_load * 1024) / (a7_group_power); + hmp_imbalance_threshold = ((long long int)NICE_0_LOAD * + 1024 * a15_a7_group_power); + divisor = 2 * a15_group_power * a7_group_power; + hmp_imbalance_threshold = div_s64_rem(hmp_imbalance_threshold, + divisor, &reminder); + hmp_imbalance_min_threshold = hmp_imbalance_threshold >> 3; + + if (imbalance < hmp_imbalance_min_threshold && + imbalance > -hmp_imbalance_min_threshold) { + atomic_set(&hmp_imbalance, 0); + return SKIP_REBALANCE; + } + + if (imbalance > hmp_imbalance_threshold) { + return A15_TO_A7; + } else { + if (imbalance < -hmp_imbalance_threshold) { + if (a7_balanced_num == sd->a7_group->group_weight) + return SWAP_TASKS; + else + return A7_TO_A15; + } else { + return SWAP_TASKS; + } + } +} +#endif /* CONFIG_HPERF_HMP */ /* * Check this_cpu to ensure it is balanced within domain. Attempt to move -- 1.9.1