Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp9996lqc; Thu, 7 Mar 2024 08:51:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXAxYSgCd8qSrAYiPMcLYW+CHyEeSM0UC+j5ZgRacldRjT7qxyI/UxS4DIcIh/WtjUPi0xERdi+7fHOsITHzB0yWyqeaLKkAO1sXeLdLg== X-Google-Smtp-Source: AGHT+IHtLkBy1Aykj6ThKb84UVJdXY4spZcIMKxtN6GFdT3CtbzMj/K1iuvtmOfjqKpmm7Mz1JM8 X-Received: by 2002:a0c:ecc2:0:b0:690:acb6:23ea with SMTP id o2-20020a0cecc2000000b00690acb623eamr868162qvq.30.1709830267521; Thu, 07 Mar 2024 08:51:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709830267; cv=pass; d=google.com; s=arc-20160816; b=lLFPz6ToNQd/Wx+j/hDDH4YsvvHOq/Htyvk9v/Iwbmbe8rdkrKd9knG53XfTGv2pIl t5hf2t3LQSGuu45lG8HJP3d8LpOjCXsOv+AIvhXUaLezhSv3c31TwcjuJ/ORBJTEovDk 3dqBE5xbx28p/uzfXxFHGNr/omFSrQMekDmdo3/TNc3QEvs9Dc3QahXP4cPc0qM+QQZf vhG41mS/pWJVqv32OqY5iGI2OlX72fHCYNrRbAYzsw5/x4/Qd06ntWyY7gP5j0rUmUVO LSgmXznlJQHEdw9W3uD2mSD8lvw5ogFHZc0K2ei7ZGzPG5iIX8B/PTr4uhyBVsu9kQUj G5Pw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=+2EL+36/QM0SPYJ1Yjq4H+n/RkoUib4NeLlBdPXO/Vc=; fh=VuM1RGM9sgxQne441QKTvWXD7v4+P8zORhyOkpfwrSc=; b=xxeFC7LGHL3k8dN57BF4ulrHyJJcmaSvvWINO+Nj8YB2k1NQpvRtLfjZiO/rCTa05V KzlH+LghzTbLVZtQTsT8pgVRdy++WtK2LwS9K1SWeyl5wWbssTfmMSSCbszrO7oZBjvT GFeWk73U221OwM1nX9tQbBPrOxmEaF5J5dAS/q4pkEW1ftCdmuI+K9fCGE1dyb2Jl0xP PhmKjJSEcuLal+nHh/Kzdt3Xp4hr+ERuJsPnMNEMqWfl7jpwnpDjU8SFz9LPKnC77Q+d N6UHi2I8Y0vkJ2N25qW1rDSDetSA8mUm77HqEnWm7T2n3UqZYrm+w8XPW2kja3yFB2xK xV8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CNmBpf27; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-95883-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95883-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ow2-20020a0562143f8200b006903ca3f5b3si17053472qvb.129.2024.03.07.08.51.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 08:51:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-95883-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CNmBpf27; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-95883-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95883-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 34FAD1C212C5 for ; Thu, 7 Mar 2024 16:51:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2253A12FF90; Thu, 7 Mar 2024 16:51:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="CNmBpf27" Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16E817AE43 for ; Thu, 7 Mar 2024 16:50:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709830260; cv=none; b=nnf6Y9XMt3oZQORRObo/sosebCqeZmoTza091CFs/FpzfyOepMmmoG9kuRgJWYvkqaLIYu1ZPevU+kV1JoOTITQSUwUuZl3LR1CJg0t5IwnjOmBQL0PfB42+UUs4DAJEXED6jSyeq1e4Yf8RxT19byhq4i4rjU/DKoe3YCuK5+8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709830260; c=relaxed/simple; bh=cDg7BLE3fcUKhWVulwdNMzB+xKXZ9swBkar0n40qnFc=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=fk+7/QeHVF+swoK7Zemc2YxGM7XEXcRopxeMv/cqjKhMETqTFzuy+Qooo5WZpTkbQMbBXOv00hTkf+33aIFnSsoeiZxeuNc8iwAHcyyK9VNQVWi04hb3zyd9Yed31SQzg6sBrxifvHJtKnX92ieub7DbsmF+8nytPZr8ixbdmwk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=CNmBpf27; arc=none smtp.client-ip=209.85.215.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-5d3912c9a83so709730a12.3 for ; Thu, 07 Mar 2024 08:50:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709830258; x=1710435058; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=+2EL+36/QM0SPYJ1Yjq4H+n/RkoUib4NeLlBdPXO/Vc=; b=CNmBpf27xr16E/xm6fXXnVYE6JWHnn8QkPt6USsGGZCCU6OmwHpySOmZwgS2ocjMct y1u9EDpu8FdG7YMRdw7j3ZBExUOD9FSMdVBwWoSdD/ULT03bT8sqH0uyX2r7FFvvPmcW vjH7SCJnVyQkqSaDtmSyCeBrWEMra30+DFZQvF0ZZ2Qqf7/aOcaSTxZw1/BGLCRlF+5n jO9hmcu15ciABsAnHHUYn9gODKYw7ObsAGbdvTea33jZb0Hvu7j8Q6hMkritKsffmjkY mOs0WmJoUeM8AJk1xphcKyTRlDXVSY5ceITHNgW7pNtUcCG81iJacB+aLgKqKuCH6N0L RBnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709830258; x=1710435058; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+2EL+36/QM0SPYJ1Yjq4H+n/RkoUib4NeLlBdPXO/Vc=; b=PlJUaDHzjWRcgPM4BYwcd2TiQMazKrsbVbc8yNUJe7wZXJEVrBSG+qoSLwgPvDxgaG ERdX1zMo86SnuuNYddrtN2CNC8nQy7Q86qFcCZCLY7Q07ZmyPtGZZqSPm99Hl8Co4+5P JeWV/dSNRUu0h7J+qrfWttOU8UBf4QHHPbYA7OLOzbmoGJKkcuhOQHaSN2GslNJPQ5Km MZ2GLEYJ2AwpkBqDvEmX9TD/uH5tA3pJugjCkzqNTRsh806uOJ538aVz+DpK8xxug0hF 9VoWew2kIAhMGPCkQxfMD4q8yBFwQTn/O5HQJ0rs2HH3HDKV1ACqvvQRMvHSX+ma2Zqq aHlw== X-Forwarded-Encrypted: i=1; AJvYcCU8PtRKwWtcOCPGq/NsLCrwt7a4nLs66iYrbQHj+aZwdriqJQHp1r7nU9bz1A9Roh/FzSuiASIIHFaeqTqsy/p1GA0CNNm6H24+/UxR X-Gm-Message-State: AOJu0YwpqRAeLuEP7F1hHdSPnkScuoyYnxlLvUqBM/JKtVIYamlf+iEm 0pYq/oYK2Tx/DUPxzkw2z0eVlikix18JdmX8mlY2Ac0DTCgRJEm4ZzSWcf6vbTfSXd8KpR8mUTU LXe/+N2O1jEzzMwDnPh+NthlUDawRKJ+VH8Kftg== X-Received: by 2002:a17:90a:de18:b0:29a:97f5:9970 with SMTP id m24-20020a17090ade1800b0029a97f59970mr14151303pjv.45.1709830256753; Thu, 07 Mar 2024 08:50:56 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240307085725.444486-1-sshegde@linux.ibm.com> <20240307085725.444486-2-sshegde@linux.ibm.com> In-Reply-To: <20240307085725.444486-2-sshegde@linux.ibm.com> From: Vincent Guittot Date: Thu, 7 Mar 2024 17:50:43 +0100 Message-ID: Subject: Re: [PATCH v6 1/3] sched/fair: Add EAS checks before updating overutilized To: Shrikanth Hegde Cc: mingo@kernel.org, peterz@infradead.org, yu.c.chen@intel.com, dietmar.eggemann@arm.com, linux-kernel@vger.kernel.org, nysal@linux.ibm.com, aboorvad@linux.ibm.com, srikar@linux.ibm.com, vschneid@redhat.com, pierre.gondois@arm.com, qyousef@layalina.io Content-Type: text/plain; charset="UTF-8" On Thu, 7 Mar 2024 at 09:57, Shrikanth Hegde wrote: > > Overutilized field of root domain is only used for EAS(energy aware scheduler) > to decide whether to do load balance or not. It is not used if EAS > not possible. > > Currently enqueue_task_fair and task_tick_fair accesses, sometime updates > this field. In update_sd_lb_stats it is updated often. This causes cache > contention due to true sharing and burns a lot of cycles. overload and > overutilized are part of the same cacheline. Updating it often invalidates > the cacheline. That causes access to overload to slow down due to > false sharing. Hence add EAS check before accessing/updating this field. > EAS check is optimized at compile time or it is a static branch. > Hence it shouldn't cost much. > > With the patch, both enqueue_task_fair and newidle_balance don't show > up as hot routines in perf profile. > > 6.8-rc4: > 7.18% swapper [kernel.vmlinux] [k] enqueue_task_fair > 6.78% s [kernel.vmlinux] [k] newidle_balance > +patch: > 0.14% swapper [kernel.vmlinux] [k] enqueue_task_fair > 0.00% swapper [kernel.vmlinux] [k] newidle_balance > > Minor change: trace_sched_overutilized_tp expect that second argument to > be bool. So do a int to bool conversion for that. > > Fixes: 2802bf3cd936 ("sched/fair: Add over-utilization/tipping point indicator") > Reviewed-by: Qais Yousef > Reviewed-by: Srikar Dronamraju > Signed-off-by: Shrikanth Hegde Reviewed-by: Vincent Guittot > --- > kernel/sched/fair.c | 53 +++++++++++++++++++++++++++++---------------- > 1 file changed, 34 insertions(+), 19 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 6a16129f9a5c..5aa6e918598c 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -6663,22 +6663,42 @@ static inline void hrtick_update(struct rq *rq) > #ifdef CONFIG_SMP > static inline bool cpu_overutilized(int cpu) > { > - unsigned long rq_util_min = uclamp_rq_get(cpu_rq(cpu), UCLAMP_MIN); > - unsigned long rq_util_max = uclamp_rq_get(cpu_rq(cpu), UCLAMP_MAX); > + unsigned long rq_util_min, rq_util_max; > + > + if (!sched_energy_enabled()) > + return false; > + > + rq_util_min = uclamp_rq_get(cpu_rq(cpu), UCLAMP_MIN); > + rq_util_max = uclamp_rq_get(cpu_rq(cpu), UCLAMP_MAX); > > /* Return true only if the utilization doesn't fit CPU's capacity */ > return !util_fits_cpu(cpu_util_cfs(cpu), rq_util_min, rq_util_max, cpu); > } > > -static inline void update_overutilized_status(struct rq *rq) > +static inline void set_rd_overutilized_status(struct root_domain *rd, > + unsigned int status) > { > - if (!READ_ONCE(rq->rd->overutilized) && cpu_overutilized(rq->cpu)) { > - WRITE_ONCE(rq->rd->overutilized, SG_OVERUTILIZED); > - trace_sched_overutilized_tp(rq->rd, SG_OVERUTILIZED); > - } > + if (!sched_energy_enabled()) > + return; > + > + WRITE_ONCE(rd->overutilized, status); > + trace_sched_overutilized_tp(rd, !!status); > +} > + > +static inline void check_update_overutilized_status(struct rq *rq) > +{ > + /* > + * overutilized field is used for load balancing decisions only > + * if energy aware scheduler is being used > + */ > + if (!sched_energy_enabled()) > + return; > + > + if (!READ_ONCE(rq->rd->overutilized) && cpu_overutilized(rq->cpu)) > + set_rd_overutilized_status(rq->rd, SG_OVERUTILIZED); > } > #else > -static inline void update_overutilized_status(struct rq *rq) { } > +static inline void check_update_overutilized_status(struct rq *rq) { } > #endif > > /* Runqueue only has SCHED_IDLE tasks enqueued */ > @@ -6779,7 +6799,7 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) > * and the following generally works well enough in practice. > */ > if (!task_new) > - update_overutilized_status(rq); > + check_update_overutilized_status(rq); > > enqueue_throttle: > assert_list_leaf_cfs_rq(rq); > @@ -10596,19 +10616,14 @@ static inline void update_sd_lb_stats(struct lb_env *env, struct sd_lb_stats *sd > env->fbq_type = fbq_classify_group(&sds->busiest_stat); > > if (!env->sd->parent) { > - struct root_domain *rd = env->dst_rq->rd; > - > /* update overload indicator if we are at root domain */ > - WRITE_ONCE(rd->overload, sg_status & SG_OVERLOAD); > + WRITE_ONCE(env->dst_rq->rd->overload, sg_status & SG_OVERLOAD); > > /* Update over-utilization (tipping point, U >= 0) indicator */ > - WRITE_ONCE(rd->overutilized, sg_status & SG_OVERUTILIZED); > - trace_sched_overutilized_tp(rd, sg_status & SG_OVERUTILIZED); > + set_rd_overutilized_status(env->dst_rq->rd, > + sg_status & SG_OVERUTILIZED); > } else if (sg_status & SG_OVERUTILIZED) { > - struct root_domain *rd = env->dst_rq->rd; > - > - WRITE_ONCE(rd->overutilized, SG_OVERUTILIZED); > - trace_sched_overutilized_tp(rd, SG_OVERUTILIZED); > + set_rd_overutilized_status(env->dst_rq->rd, SG_OVERUTILIZED); > } > > update_idle_cpu_scan(env, sum_util); > @@ -12609,7 +12624,7 @@ static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued) > task_tick_numa(rq, curr); > > update_misfit_status(curr, rq); > - update_overutilized_status(task_rq(curr)); > + check_update_overutilized_status(task_rq(curr)); > > task_tick_core(rq, curr); > } > -- > 2.39.3 >