Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp307657iof; Mon, 6 Jun 2022 04:00:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3COA7XrunHQ4C75/XfHUHkFBqjVw0jEChJ/Sg6TkQ8YtVnc8A6JqIiPSEQ5n6TAKlKox3 X-Received: by 2002:a63:f244:0:b0:3fd:a384:a5f9 with SMTP id d4-20020a63f244000000b003fda384a5f9mr5982536pgk.354.1654513203643; Mon, 06 Jun 2022 04:00:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654513203; cv=none; d=google.com; s=arc-20160816; b=VAZcxKsVp0jyRrsUcVDfdaHhTGo/0NCYPCx4aNpULd6LY3iAs4jrR6OVih3IY2T79r bp+rX/ZfMVadhErD36IWCZzfcm9hGxh5GjzCOwzkXRg4KENrluupGVZFq9fd+ylyXj8X pbSKIpta41wEqLajEJjwI5wUgv8FmB8EHPhCZ/ihHKMyO12OQ6IXgDzCW/d9cGG6gLgR b2XhaRimsK5cU8D/gUfKK9xbriov/NxmDpzarOKQp0DE43v6g2be4rWYCV+QREWNvzG1 k93Kt9BdwQeqd798rWptaP/LIQ9O5CMk77mqO109D0tRqqVoe5hQSH1/yNefwCH3/QX6 8NWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=vrelzPu29G5H09jtTZEwLxLwvFgbNRNQUR/RMZob9kk=; b=etKuoLps4+cxZ3rNojbbY7DeXsfhn5aSRBOH/6NbqQ484Y3zfxkrXqKBp8THT7PSqg FAjc3NeN41b1GwcraFucykdJ1QpPxi6X17eVoA7RFn8pkoW/DWRyPUlBJzlwzqRy6z7x j9npJ3f78wQi/ssS+VeA1cQ8FSJSgafU3HAjhkPmZASW+oG4KdgdhIAwBMFcTy+MOv43 yXlUB/OmwrkEb5oia2IRhb6BN0bvxXO82oH+NIY+yuoo93rJmM9DV/51ymLI9q5TbpxP 3bRTRJRyrT6AusOA0DysNKMKoK3Os226s6dLzXcZVD5Azt9ICqjqIaERnkGoEr/ZO9gN 5Kng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BIfFdbG3; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id z8-20020a170903018800b00153b2d16403si23861608plg.11.2022.06.06.04.00.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 04:00:03 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BIfFdbG3; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7B5C82654A; Mon, 6 Jun 2022 03:39:36 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234001AbiFFKjW (ORCPT + 99 others); Mon, 6 Jun 2022 06:39:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233980AbiFFKjQ (ORCPT ); Mon, 6 Jun 2022 06:39:16 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 601411EED7 for ; Mon, 6 Jun 2022 03:39:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654511954; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vrelzPu29G5H09jtTZEwLxLwvFgbNRNQUR/RMZob9kk=; b=BIfFdbG3STvzThfuh0xqouXiH5CIpSAFJlN9h6yOEvp9nQyJb+0XbGsX7EVH+CmPbQ0WES aGULMAhZ77qkhY++ryQpMWZtpeDGo2Pj8LsZZE31VY+4B7Hd+H+KUWzSQRsSXGsmtEeo67 U5Y4ChdEnjq9yAGnY8gFw6kJzEqUfqo= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-474-e2akaoG_N_mVW5u3BpvpCA-1; Mon, 06 Jun 2022 06:39:06 -0400 X-MC-Unique: e2akaoG_N_mVW5u3BpvpCA-1 Received: by mail-wr1-f70.google.com with SMTP id r13-20020adff10d000000b002160e9d64f8so1192343wro.0 for ; Mon, 06 Jun 2022 03:39:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=vrelzPu29G5H09jtTZEwLxLwvFgbNRNQUR/RMZob9kk=; b=wMqaM+Oiq+rNcyXLQcwHPW0U4z4rhuTVZt8i6zwSwul5p25S9i04T805ffxtmXjsJL FX9LwRnH2LjKbcd7PlpIcPhDofJVSFjkDNyKQ2A/AWbzVP9W1nSjJ1XZA50OGjnAkpa2 Mp7DkZ9rMMpn0PtIobv+vIh5zE4sFvwtu/AcM/dtrctBBqFNx2JC6Qkntleb/SA8OCH4 mb5E1SuUz8E+Xwj7NkKadeqShT15rPGbt7haKWT7Ek8qSW5Wt7LY1GlmESul8Puuepz0 ujQfWemYxmNCv7rb+tRUW4SWHNv6k8UYsL85443DCsd3tVhoztprXYGVDG45OVJd1MYZ 6aeQ== X-Gm-Message-State: AOAM532QRW6060tZrSn7Sf65MrwLBeriRfgHKxQ/1DEdL4z7y/n45UzU M3XUpbOWbBDDDy32hmuJ8LINJ6zJLmBeIGS2EJ/DDa/w1PIHEWFjHgT4uill/2V7HWlXW0XKCht NQAq1m/TLw9F0smBLaJ4lTfe83U7bZ/VX+7oVJioWQR44QUaMDMuBnER1kfZUQ8j9w2nKWAclKy LW X-Received: by 2002:a05:600c:2e47:b0:39c:37f5:cd74 with SMTP id q7-20020a05600c2e4700b0039c37f5cd74mr18196261wmf.32.1654511944525; Mon, 06 Jun 2022 03:39:04 -0700 (PDT) X-Received: by 2002:a05:600c:2e47:b0:39c:37f5:cd74 with SMTP id q7-20020a05600c2e4700b0039c37f5cd74mr18196226wmf.32.1654511944174; Mon, 06 Jun 2022 03:39:04 -0700 (PDT) Received: from vschneid.remote.csb ([185.11.37.247]) by smtp.gmail.com with ESMTPSA id r19-20020a05600c35d300b0039c2e2d0502sm14335927wmq.4.2022.06.06.03.39.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 03:39:03 -0700 (PDT) From: Valentin Schneider To: Tianchen Ding , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 1/2] sched: Fix the check of nr_running at queue wakelist In-Reply-To: <20220602040645.275555-2-dtcccc@linux.alibaba.com> References: <20220602040645.275555-1-dtcccc@linux.alibaba.com> <20220602040645.275555-2-dtcccc@linux.alibaba.com> Date: Mon, 06 Jun 2022 11:39:02 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On 02/06/22 12:06, Tianchen Ding wrote: > The commit 2ebb17717550 ("sched/core: Offload wakee task activation if it > the wakee is descheduling") checked nr_running <= 1 to avoid task > stacking when WF_ON_CPU. Consider the order of p->on_rq and p->on_cpu, > if we have WF_ON_CPU here then we must have !p->on_rq, so the deactivate > has happened, thus the task being alone on the rq implies nr_running==0. > Change the check to !cpu_rq(cpu)->nr_running to fix it. > I'd flesh this out a bit as in the below: """ The commit 2ebb17717550 ("sched/core: Offload wakee task activation if it the wakee is descheduling") checked rq->nr_running <= 1 to avoid task stacking when WF_ON_CPU. Per the ordering of writes to p->on_rq and p->on_cpu, observing p->on_cpu (WF_ON_CPU) in ttwu_queue_cond() implies !p->on_rq, IOW p has gone through the deactivate_task() in __schedule(), thus p has been accounted out of rq->nr_running. As such, the task being the only runnable task on the rq implies reading rq->nr_running == 0 at that point. Change the check to !cpu_rq(cpu)->nr_running. """ Also, this is lacking some mention of tests that have been run to verify this isn't causing a regression. This does however make sense to me, so as long as nothing gets hurt by the change: Reviewed-by: Valentin Schneider > Signed-off-by: Tianchen Ding > --- > kernel/sched/core.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index bfa7452ca92e..a9efe134fbe5 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -3830,7 +3830,7 @@ static inline bool ttwu_queue_cond(int cpu, int wake_flags) > * the soon-to-be-idle CPU as the current CPU is likely busy. > * nr_running is checked to avoid unnecessary task stacking. > */ > - if ((wake_flags & WF_ON_CPU) && cpu_rq(cpu)->nr_running <= 1) > + if ((wake_flags & WF_ON_CPU) && !cpu_rq(cpu)->nr_running) > return true; > > return false; > -- > 2.27.0