Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp349366lqr; Wed, 5 Jun 2024 07:54:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVcG2M40Dx9LBi8nFLP25cO/fs/+IPPcFTobLpw/MZXq69WRDlOb05Bdsl4LTBzINHUPe8oabSTnE1QmlHCBXCWYNpH026848JCd2fKFg== X-Google-Smtp-Source: AGHT+IEbmsxuska6te81NVKNNmL5GtK4j/9D+fGknPUkRP+x/tcIt1s/LDgYudIrYIIyCYbjszdv X-Received: by 2002:a17:90a:9f8b:b0:2c1:424c:1721 with SMTP id 98e67ed59e1d1-2c27db002d9mr2492540a91.3.1717599295989; Wed, 05 Jun 2024 07:54:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717599295; cv=pass; d=google.com; s=arc-20160816; b=Q5IXyq2oDbDZZ8ZVuOTpo+Ejf4VPCTkiWwz5NBzno9wD8i+TWqSJ64UOw3rkM6L6p3 /XmY8zGNCT/d0JEvSBaRfwNCBN790aspjbN212uwgLDj/7IJvDfZc4basyyARv4RJ1gu omOsnPP3g6cVugIIQoYyOkf4Q9HyNYnQpw69K1gNAoPhsI0J2oAeVhpOaUTuuRJx9EkJ 1TKwRw9lrzbmunkQbiJlkjdddVk0azXNmtgzKMJwIS6QE0F2iQTgWj4U+A/5i28bzFFs 9uAXGQPfxJ0Iu68TxICiOkVJZV6qtEQwqf7p+V3t7YE44MOe3kVXSO04vUFMK/Fv8n6s DEiw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=Mrh43luRsp07N3QOm2XsMjER4wk/H8Bu+bitFmDc+Sg=; fh=sBQ8CeE5I7nOzyjFi2iWQQRP13LqsZ1YHIsnc3gjEFo=; b=kxjRZ9A22u/w/BYBxoc1uNP4vRSi6q4+eSCb9gk3iOnX+WaAQzWZhaoSn1nP6IwYt6 WPQ2y4xxuHYYtzXOu7bAmlyNrdSBSusYxAf4wZGGglpzhy2DbX8Ge71TnDnKG0aZ8Twy 0UuWXmUpHEzmMq6TcWMsAUabhRVoMiFvsbBdSsZ+v3fE9BmlvuxmcgsY6FkNbv5+zRFM 6wd8YJi+WSPBLRBoLR6mavUwfxNf9rw+JW80+DZnYfp/Ctrhl1OFNl2RSzAxJ8TwKNbD aod4VLBOH7OyB8j2ZWNa9oJONMPFiRMlXHo/gBirm4VqQlUP6+jo3Bpxqv9zMIdizM0u jnYg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=jjdi6VfW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-202795-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202795-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c28069bdb3si1371745a91.120.2024.06.05.07.54.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 07:54:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202795-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=jjdi6VfW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-202795-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202795-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 8FB892838E2 for ; Wed, 5 Jun 2024 14:54:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5A7B93D548; Wed, 5 Jun 2024 14:54:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jjdi6VfW"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="9FkO87nl" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67ED827702; Wed, 5 Jun 2024 14:54:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717599279; cv=none; b=AP38hH9qdPvN5Lxord5dCUksvDKMD4exglex0BBvQloi5THv+4rkoCH+bLurEz11TfY99v4pppYFkqhvr9o4HDUYj05oh6GXctchCHsvmqN3hqoQSpkIiODkC4ut+d75/KIzGqybeFQOWX3mBVjxOiwuHeeLN4rtWloanaJJYQM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717599279; c=relaxed/simple; bh=NHDlMq4zVASGYwP3wqLssSIjtLD9lNecBMZVvGRfQlU=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=EGtRZEg9NsqLXZMWtyArYhNrDFOWxIL9mGDV9Y3GPyBImnAcFlHHPQg7rtLs7Pcu4bEMr+BspdYCdbgvbukGDr39FEWTgrVTC2POq9VSwjEuXKQ1vKxpElHwVoSBKC2FsgtaXPcmFIUVZ/eGqxf8PRax/DQiX/AdcsoFf9D5FCc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=jjdi6VfW; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=9FkO87nl; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Wed, 05 Jun 2024 14:54:33 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1717599273; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Mrh43luRsp07N3QOm2XsMjER4wk/H8Bu+bitFmDc+Sg=; b=jjdi6VfWEs7kOJAOA1ruNjIOkGbdGos1W2lK5rMwobEmaIyVnqc6rzBdYicz8b6KEMUeUh 3003g6eq3BCzkm59pqj7KpAHiXB03rt+Q84KnQ8Rrtp1IotgcfkF1ZaqhkKn5XAdn7ZGrd YpD4el09dYOj6QWJ8vYSynvvomwap1GGPuHIrjMuIy3naTGDjmDVaGPx84jyHvqrVUHRh1 qjHshKIO3KVBIsUmWBIAKURnKDRLbEU9N7WGTXa9X6I02DG4bSY3hzD9KCHa7o3wgQeENi IC4BWpu4rC4L62JBANso5b7rGrYQR8JRLzmJcEfo5sCJ/dL6r43uUWymuVIr4g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1717599273; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Mrh43luRsp07N3QOm2XsMjER4wk/H8Bu+bitFmDc+Sg=; b=9FkO87nlMFhungtmOEpHEplD3AXK9cVKS1w59FmlBKTrMAGhOgUWPJRUGmYBoJJl7smDhh kD7sMFCz4nsfzZCA== From: "tip-bot2 for Tim Chen" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/balance: Skip unnecessary updates to idle load balancer's flags Cc: Tim Chen , "Peter Zijlstra (Intel)" , Chen Yu , Vincent Guittot , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240531205452.65781-1-tim.c.chen@linux.intel.com> References: <20240531205452.65781-1-tim.c.chen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <171759927306.10875.2450909647126184930.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the sched/core branch of tip: Commit-ID: f90cc919f9e5cbfcd0b952290c57ef1317f4e91e Gitweb: https://git.kernel.org/tip/f90cc919f9e5cbfcd0b952290c57ef1317f= 4e91e Author: Tim Chen AuthorDate: Fri, 31 May 2024 13:54:52 -07:00 Committer: Peter Zijlstra CommitterDate: Wed, 05 Jun 2024 15:52:36 +02:00 sched/balance: Skip unnecessary updates to idle load balancer's flags We observed that the overhead on trigger_load_balance(), now renamed sched_balance_trigger(), has risen with a system's core counts. For an OLTP workload running 6.8 kernel on a 2 socket x86 systems having 96 cores/socket, we saw that 0.7% cpu cycles are spent in trigger_load_balance(). On older systems with fewer cores/socket, this function's overhead was less than 0.1%. The cause of this overhead was that there are multiple cpus calling kick_ilb(flags), updating the balancing work needed to a common idle load balancer cpu. The ilb_cpu's flags field got updated unconditionally with atomic_fetch_or(). The atomic read and writes to ilb_cpu's flags causes much cache bouncing and cpu cycles overhead. This is seen in the annotated profile below. kick_ilb(): if (ilb_cpu < 0) test %r14d,%r14d =E2=86=91 js 6c flags =3D atomic_fetch_or(flags, nohz_flags(ilb_cpu)); mov $0x2d600,%rdi movslq %r14d,%r8 mov %rdi,%rdx add -0x7dd0c3e0(,%r8,8),%rdx arch_atomic_read(): 0.01 mov 0x64(%rdx),%esi 35.58 add $0x64,%rdx arch_atomic_fetch_or(): static __always_inline int arch_atomic_fetch_or(int i, atomic_t = *v) { int val =3D arch_atomic_read(v); do { } while (!arch_atomic_try_cmpxchg(v, &val, val | i)); 0.03 157: mov %r12d,%ecx arch_atomic_try_cmpxchg(): return arch_try_cmpxchg(&v->counter, old, new); 0.00 mov %esi,%eax arch_atomic_fetch_or(): do { } while (!arch_atomic_try_cmpxchg(v, &val, val | i)); or %esi,%ecx arch_atomic_try_cmpxchg(): return arch_try_cmpxchg(&v->counter, old, new); 0.01 lock cmpxchg %ecx,(%rdx) 42.96 =E2=86=93 jne 2d2 kick_ilb(): With instrumentation, we found that 81% of the updates do not result in any change in the ilb_cpu's flags. That is, multiple cpus are asking the ilb_cpu to do the same things over and over again, before the ilb_cpu has a chance to run NOHZ load balance. Skip updates to ilb_cpu's flags if no new work needs to be done. Such updates do not change ilb_cpu's NOHZ flags. This requires an extra atomic read but it is less expensive than frequent unnecessary atomic updates that generate cache bounces. We saw that on the OLTP workload, cpu cycles from trigger_load_balance() (or sched_balance_trigger()) got reduced from 0.7% to 0.2%. Signed-off-by: Tim Chen Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Chen Yu Reviewed-by: Vincent Guittot Link: https://lore.kernel.org/r/20240531205452.65781-1-tim.c.chen@linux.intel= .com --- kernel/sched/fair.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 63113dc..41b5838 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -11892,6 +11892,13 @@ static void kick_ilb(unsigned int flags) return; =20 /* + * Don't bother if no new NOHZ balance work items for ilb_cpu, + * i.e. all bits in flags are already set in ilb_cpu. + */ + if ((atomic_read(nohz_flags(ilb_cpu)) & flags) =3D=3D flags) + return; + + /* * Access to rq::nohz_csd is serialized by NOHZ_KICK_MASK; he who sets * the first flag owns it; cleared by nohz_csd_func(). */