From patchwork Wed Nov 15 09:04:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 165203 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2411934vqg; Wed, 15 Nov 2023 01:04:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IGc4Zi3dNa+bCE5lVciS2hYXz1BPOQo3JEHKKdI10QerPAP93y1XOpxRYNE3Nc5upsiWyDU X-Received: by 2002:a05:6a21:188:b0:187:758e:9781 with SMTP id le8-20020a056a21018800b00187758e9781mr914075pzb.17.1700039099266; Wed, 15 Nov 2023 01:04:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700039099; cv=none; d=google.com; s=arc-20160816; b=L7Wq0dHLHek3NgXlu8cx/hcZQuzq5mfN5zdlWprqgN+Z2ksvb24XcOw8fn3Nh28xAB SYAd376jOWdVAQNsTijmBdjON8mjhpgaqoNvkjEqNJz1VXW1z24UwxT5nS72P6+YrFeL whDFWSYD/0CUIzV+0o13W+6EgWUSNQPJQBLIHTFjF3n8v1yn6zJyQC42JPELyWYcT+Zw ybyNjZZ9KD9n/dNfjdvdIGYOu+s2Y3SW7npKfAi+q/xM55bQLdgsdX/w8Qk78J0a78xx imK+KcsRGtvVUnyRqXNuS8vrcUDHC2hwn3/4m8wfzBKOX7lx6TlXiLEjXIgu4V4Kk93m l2ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=XYjLZIFHPeTFyFVUPt8LdW6UDKPYrmKzL1aYRxJ9lag=; fh=KFSO1avKpsj2PbLT7939+iqdBuUcdlAP4LSCNdUZQ/k=; b=PcM8NXvYKBFYWPciI5nl6Lb0v9HjUMGbqkcXekqb8vN2+zPpCd24PMAd/Pmyh9dHxR wzojjhvbMBBVICgL0eXsApOECWuDjuxbrr+j89UYMfOGYL98iiNKgwAizUvEjzzuD0fT DT6mlIFGvWdS8CR2ITYBqmFMmAeKEEbePM7aLXW6EHb7Ahnn6BKn7n3jMMjWKXblJVrb 4Kth4X7b9EDIkpCa7bgfUiBDeKQFOzPDPB6XHID5s+AROYIR/kSMXgR+o5ZNohkeeH9m 2QGy4mbf5QXtPEmD8joNxSpdqz+SiYxw5pNDOmlduv2o/Fo2500uwzgWyRtCAqLOjCSB NdMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=k2XIrqJc; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id v69-20020a638948000000b005b95ccd1b4dsi9491505pgd.82.2023.11.15.01.04.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 01:04:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=k2XIrqJc; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id C0E25813388D; Wed, 15 Nov 2023 01:04:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234687AbjKOJEz (ORCPT + 28 others); Wed, 15 Nov 2023 04:04:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234651AbjKOJEy (ORCPT ); Wed, 15 Nov 2023 04:04:54 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37D97114; Wed, 15 Nov 2023 01:04:51 -0800 (PST) Date: Wed, 15 Nov 2023 09:04:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1700039088; 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=XYjLZIFHPeTFyFVUPt8LdW6UDKPYrmKzL1aYRxJ9lag=; b=k2XIrqJcyOecy+XDLqmYRNxz8R9ToP9FIE3uwjWHkz59xOLSyRnMUegm545/Y3Ue/9P2ZY xJieYiH2QPUWAVtecvxwgrc1beI3Mi82Ly5XF07c1l3eHio5ub2fxFhK5Zxg7+nqz8wvrD BW24r7rD0+kG0m4y7OaliOfwUWjxjPOoOeEa6YC7rFKUP9bpgFqD+MEG45qE/cX4VNpX3f BZlIE/1AnwElZ4IdjdQ5TKN+QBosealVu4aUESGWOKi5HK4MLmqzfQ9bfdN9YYpH9qMEnx GEqwPmcYHXyLqePiRhB5nNeO21hj3YQBqL0zP48rtM1TbvexhaYJoFwcfgVctQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1700039088; 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=XYjLZIFHPeTFyFVUPt8LdW6UDKPYrmKzL1aYRxJ9lag=; b=P5g4iQT6hQpHBN46BHO93rPBv62BQNKu2znlmcBNHyCsM9bJqzr9MTnMe2DrajRuUz8RgR MYRxbvhR5Z1uLdBw== From: "tip-bot2 for Frederic Weisbecker" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/timers: Explain why idle task schedules out on remote timer enqueue Cc: Frederic Weisbecker , "Peter Zijlstra (Intel)" , "Rafael J. Wysocki" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231114193840.4041-3-frederic@kernel.org> References: <20231114193840.4041-3-frederic@kernel.org> MIME-Version: 1.0 Message-ID: <170003908811.391.7438992731780383646.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 15 Nov 2023 01:04:57 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782569513515035961 X-GMAIL-MSGID: 1782620198612063097 The following commit has been merged into the sched/core branch of tip: Commit-ID: 194600008d5c43b5a4ba98c4b81633397e34ffad Gitweb: https://git.kernel.org/tip/194600008d5c43b5a4ba98c4b81633397e34ffad Author: Frederic Weisbecker AuthorDate: Tue, 14 Nov 2023 14:38:40 -05:00 Committer: Peter Zijlstra CommitterDate: Wed, 15 Nov 2023 09:57:52 +01:00 sched/timers: Explain why idle task schedules out on remote timer enqueue Trying to avoid that didn't bring much value after testing, add comment about this. Signed-off-by: Frederic Weisbecker Signed-off-by: Peter Zijlstra (Intel) Acked-by: Rafael J. Wysocki Link: https://lkml.kernel.org/r/20231114193840.4041-3-frederic@kernel.org --- kernel/sched/core.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index f5f4495..2de77a6 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1131,6 +1131,28 @@ static void wake_up_idle_cpu(int cpu) if (cpu == smp_processor_id()) return; + /* + * Set TIF_NEED_RESCHED and send an IPI if in the non-polling + * part of the idle loop. This forces an exit from the idle loop + * and a round trip to schedule(). Now this could be optimized + * because a simple new idle loop iteration is enough to + * re-evaluate the next tick. Provided some re-ordering of tick + * nohz functions that would need to follow TIF_NR_POLLING + * clearing: + * + * - On most archs, a simple fetch_or on ti::flags with a + * "0" value would be enough to know if an IPI needs to be sent. + * + * - x86 needs to perform a last need_resched() check between + * monitor and mwait which doesn't take timers into account. + * There a dedicated TIF_TIMER flag would be required to + * fetch_or here and be checked along with TIF_NEED_RESCHED + * before mwait(). + * + * However, remote timer enqueue is not such a frequent event + * and testing of the above solutions didn't appear to report + * much benefits. + */ if (set_nr_and_not_polling(rq->idle)) smp_send_reschedule(cpu); else