Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp601721yba; Wed, 15 May 2019 06:55:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqwdJAECpSOGd3EwV1b7Bhg/jeDy4qVr7AGa9b8FPTpbnKs9TBNiAO7OWMM3QMbjL7JTKXUi X-Received: by 2002:a17:902:968b:: with SMTP id n11mr43898259plp.118.1557928532659; Wed, 15 May 2019 06:55:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557928532; cv=none; d=google.com; s=arc-20160816; b=mvPOId6yPHzHn1OZaPLxseGhZIOCWWPTj+4TPmEO9DP6DCXkUN79f/8Ly1Mbh0ZR7R h7TVU2mNgKvqoa+Ed1QP+vVWA/u+Jmq+9rimrcIhS6TJCK6Sty84Ug06E8Xgili79dzZ bPAtGl86BovSCKF35/rwct277/JEQyK4ENrc1P58s+ieuB4V3h8fn8ve4/J6Y37WTlRy ED5T01nSBMcDLzOEq9G5fD3Renv2c2xOC2qjkD2DFnimm0sSlSd7GRptbVBye6BVxYKr bPgkeju7P8G26MQPhT45D3YRcm/GWk+KMQ711+ubh76Lmc97SzkexjgLxAlw/BBAw0Pa MqcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from; bh=+7gBWugGDdFSduK6vxJousBDnNur6zbIQVQ7KUVzPLo=; b=AmkiF4qr/K5RXMciTq7CcnaFNAwzKOm0jsomoXBSoEbyUlrEgtIf31BvF9XakDU4gR eNbvha0MCi5zOVie9VD3v85ZKDjDl0EOeTKsPvANF9/CUILvTBz1Df1TDTA2nXJblU36 boJ2+RbHl9KQcCswS9OFFj6tU6j0pWjEJYVnTaaD6pye4wEJfdnfeXitswhxhnz2dsb5 fJMgBZyKGdrHzWGZsDBIZYqXvT12bybiCwgJC4d3mbPjIfwkPym36j7ZQ+J7RkkQtit4 eJWl/yOJ3oZ31Ayxw+uuNESIWlB2xYDv97KLw67GF+0R5w29OnVM3m6xw2grngTtNoju LF6A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v1si1845591plo.191.2019.05.15.06.55.18; Wed, 15 May 2019 06:55:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728029AbfEONxy (ORCPT + 99 others); Wed, 15 May 2019 09:53:54 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:57542 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727771AbfEONxw (ORCPT ); Wed, 15 May 2019 09:53:52 -0400 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x4FDquhK123722 for ; Wed, 15 May 2019 09:53:51 -0400 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0b-001b2d01.pphosted.com with ESMTP id 2sgjv0csbb-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 15 May 2019 09:53:50 -0400 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 15 May 2019 14:53:48 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 15 May 2019 14:53:46 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x4FDrjOD49414252 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 15 May 2019 13:53:45 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 21FEB52052; Wed, 15 May 2019 13:53:45 +0000 (GMT) Received: from localhost.localdomain.com (unknown [9.102.18.182]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id B9D8E52050; Wed, 15 May 2019 13:53:42 +0000 (GMT) From: Parth Shah To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Cc: mingo@redhat.com, peterz@infradead.org, dietmar.eggemann@arm.com, dsmythies@telus.net Subject: [RFCv2 4/6] sched/fair: Define core capacity to limit task packing Date: Wed, 15 May 2019 19:23:20 +0530 X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190515135322.19393-1-parth@linux.ibm.com> References: <20190515135322.19393-1-parth@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 19051513-0016-0000-0000-0000027C033A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19051513-0017-0000-0000-000032D8D3F7 Message-Id: <20190515135322.19393-5-parth@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-05-15_08:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905150087 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The task packing on a core needs to be bounded based on its capacity. This patch defines a new method which acts as a tipping point for task packing. The Core capacity is the method which limits task packing above certain point. In general, the capacity of a core is defined to be the aggregated sum of all the CPUs in the Core. Some architectures does not have core capacity linearly increasing with the number of threads( or CPUs) in the core. For such cases, architecture specific calculations needs to be done to find core capacity. The `arch_scale_core_capacity` is currently tuned for `powerpc` arch by scaling capacity w.r.t to the number of online SMT in the core. The patch provides default handler for other architecture by scaling core capacity w.r.t. to the capacity of all the threads in the core. ToDo: SMT mode is calculated each time a jitter task wakes up leading to redundant decision time which can be eliminated by keeping track of online CPUs during hotplug task. Signed-off-by: Parth Shah --- arch/powerpc/include/asm/topology.h | 4 ++++ arch/powerpc/kernel/smp.c | 32 +++++++++++++++++++++++++++++ kernel/sched/fair.c | 19 +++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/arch/powerpc/include/asm/topology.h b/arch/powerpc/include/asm/topology.h index f85e2b01c3df..1c777ee67180 100644 --- a/arch/powerpc/include/asm/topology.h +++ b/arch/powerpc/include/asm/topology.h @@ -132,6 +132,10 @@ static inline void shared_proc_topology_init(void) {} #define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu)) #define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu)) #define topology_core_id(cpu) (cpu_to_core_id(cpu)) +#define arch_scale_core_capacity powerpc_scale_core_capacity + +unsigned long powerpc_scale_core_capacity(int first_smt, + unsigned long smt_cap); int dlpar_cpu_readd(int cpu); #endif diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c index e784342bdaa1..256ab2a50f6e 100644 --- a/arch/powerpc/kernel/smp.c +++ b/arch/powerpc/kernel/smp.c @@ -1173,6 +1173,38 @@ static void remove_cpu_from_masks(int cpu) } #endif +#ifdef CONFIG_SCHED_SMT +/* + * Calculate capacity of a core based on the active threads in the core + * Scale the capacity of first SM-thread based on total number of + * active threads in the respective smt_mask. + * + * The scaling is done such that for + * SMT-4, core_capacity = 1.5x first_cpu_capacity + * and for SMT-8, core_capacity multiplication factor is 2x + * + * So, core_capacity multiplication factor = (1 + smt_mode*0.125) + * + * @first_cpu: First/any CPU id in the core + * @cap: Capacity of the first_cpu + */ +inline unsigned long powerpc_scale_core_capacity(int first_cpu, + unsigned long cap) { + struct cpumask select_idles; + struct cpumask *cpus = &select_idles; + int cpu, smt_mode = 0; + + cpumask_and(cpus, cpu_smt_mask(first_cpu), cpu_online_mask); + + /* Find SMT mode from active SM-threads */ + for_each_cpu(cpu, cpus) + smt_mode++; + + /* Scale core capacity based on smt mode */ + return smt_mode == 1 ? cap : ((cap * smt_mode) >> 3) + cap; +} +#endif + static inline void add_cpu_to_smallcore_masks(int cpu) { struct cpumask *this_l1_cache_map = per_cpu(cpu_l1_cache_map, cpu); diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index b7eea9dc4644..2578e6bdf85b 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6231,6 +6231,25 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, int t return cpu; } +#ifdef CONFIG_SCHED_SMT + +#ifndef arch_scale_core_capacity +static inline unsigned long arch_scale_core_capacity(int first_thread, + unsigned long smt_cap) +{ + /* Default capacity of core is sum of cap of all the threads */ + unsigned long ret = 0; + int sibling; + + for_each_cpu(sibling, cpu_smt_mask(first_thread)) + ret += cpu_rq(sibling)->cpu_capacity; + + return ret; +} +#endif + +#endif + /* * Try and locate an idle core/thread in the LLC cache domain. */ -- 2.17.1