Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp532821imm; Wed, 26 Sep 2018 02:51:21 -0700 (PDT) X-Google-Smtp-Source: ACcGV621xgUAUeTT8l7DmWyFOfO85MzsxLQgr9nbIeMqnCreewJHoPNBg0Qpd9qUU0AO+0oWneWk X-Received: by 2002:a62:b604:: with SMTP id j4-v6mr5392471pff.199.1537955481607; Wed, 26 Sep 2018 02:51:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537955481; cv=none; d=google.com; s=arc-20160816; b=LJi5uHNt3MSROcSOe9/UUPFTigtoEyjab+xK89/a7OwKAtZK+3sgTE3gxL32my8S/I Aegix0jJzM37mItKjQQN1a1xDWk1pgOkrlaz9JFT0lLY319bsyDTKzlY6FjzejQ2p3t0 QCkAIUqI5vTJXsVW4PEVrjbT8Ynyy82YNO3FW6fHSDcFcq0hDB/EL7TP1CFLh0DciWBm zdzQuIlygOM3OrTTDZN1LojNCSZzovVpBQ96IAWufsQnbUKqs+Ol4JtWJontgEYV+kEq jGoBwmKUSgxW2LY5NHxG50d3AihVLSYRLtlslb+EvH8GgnSnbhmrxhwKYrQUkofQcNZv kR0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=6UNz3oRZjb+c2BUIGIK4jcLgE/3H08EPW634lvVLcUw=; b=PeqIIW+0VHmzSvOUrpJOVHh+ILcy3xLslozfnehlAqymX2FNYe6TNPDioykrumgdNZ 5wvCBeyWgqQ0cHxsYBV/S03BRFbvw0sknupNIl/FTpQg/CuxEcaYGXzVFME820XNInXN sz5juOYb7GKlM/AhOXHd/WC2pwTIgJEEDM3tXvtluf3aZEorqtkT55C0uog3VL7ZHNq7 6isGcmk+tOlAbcq7dNsDrvvOygIXWcPWbbwAS9F2+5EbKDY1bkBGxGgk+MFIeQj1VUDK LBkNWpJLlto6ZudCPvVAD8f599RstI7LEaxNNz4kaNzMU0DhQCOD/zYrxZ/dmGhmMHtm H8NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bEKjLenX; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j10-v6si5143497plg.143.2018.09.26.02.51.06; Wed, 26 Sep 2018 02:51:21 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bEKjLenX; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727113AbeIZQDG (ORCPT + 99 others); Wed, 26 Sep 2018 12:03:06 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:40425 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726401AbeIZQDF (ORCPT ); Wed, 26 Sep 2018 12:03:05 -0400 Received: by mail-ot1-f67.google.com with SMTP id g14-v6so13910792otj.7 for ; Wed, 26 Sep 2018 02:50:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6UNz3oRZjb+c2BUIGIK4jcLgE/3H08EPW634lvVLcUw=; b=bEKjLenXjS+lvqvSKkXx276Bj92q3k3BTFZjfsUR/hNFyHvTVj6qlmmR/BRz6G0kks 86ETbCimkL5GaQa6FDv0op+R8NYOS5nJY5wVHyzMGJmxa2mQHlJCaQqljNct5PWxSuv0 CrLAtr0BIuWlk8yUy1iKcLTlVRzLXKXbIlIiHcpYbQ7l4WIz814kKf6b98wP8ulV7yJ1 0CqZHMjheGb40uL48B/WU2mWPOjUKBtr/uFKHt4uQvMpHkP2WJOA3izoJtHicE8l6QNw Ori/l83c6w+VAHR+FiZI2dUwlkb/HdTN1QDcmg/A5PGGFZDjSan9JtoTODOFYaP1yJq4 +/xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6UNz3oRZjb+c2BUIGIK4jcLgE/3H08EPW634lvVLcUw=; b=ocwEJ+rH0m239K6DOCtp5UpoRtF8Ex1R0ZhtxyQcdTd2AA03YX6yPttKT6J90QvUuc mtkWR1TT5q4Y4wgaWjF+DNI52zpGC1W1ricPLjmFeeb8S81CIaVX4d4qAGIPYxsL1pVq OYcwcpw3XDbmdNaT9TQUH8Tp7AYjyqWlFL/L9htt096Srb05e+vdiWTwDzZkUBhRwOM3 iFvm6ODysj57Xk6U9NCTZGywfX8JT6niQDGVR1Nt2J1qcNZR8H2pKTiBWDmmCrVSnBvM upzmvynnzV0MCn5msviUWXb2PYaXRq0hyiYd1r33WHL78UhBCk/2XtLS75QDL1d4sYWI /EFw== X-Gm-Message-State: ABuFfohayqNJnxuRpKj96HC3+RsbrjzZwyut4tXCv4KT94nonx2aFkg7 +jah4MgNBGyt5k+aZEW3PxaAvxE6gtQxZ1sje4o= X-Received: by 2002:a9d:5d7:: with SMTP id 81-v6mr3814152otd.262.1537955456558; Wed, 26 Sep 2018 02:50:56 -0700 (PDT) MIME-Version: 1.0 References: <20180817182728.76129-1-smuckle@google.com> <20180824093227.GN24124@hirez.programming.kicks-ass.net> <20180824094742.GJ24142@hirez.programming.kicks-ass.net> <20180827111458.GB24124@hirez.programming.kicks-ass.net> <2ed346fa-dbe8-4928-928b-a34338b2d8c9@arm.com> In-Reply-To: <2ed346fa-dbe8-4928-928b-a34338b2d8c9@arm.com> From: Wanpeng Li Date: Wed, 26 Sep 2018 17:50:52 +0800 Message-ID: Subject: Re: [PATCH] sched/fair: vruntime should normalize when switching from fair To: Dietmar Eggemann Cc: Peter Zijlstra , smuckle@google.com, migueldedios@google.com, Ingo Molnar , LKML , kernel-team@android.com, Todd Kjos , Paul Turner , quentin.perret@arm.com, Patrick Bellasi , Chris.Redpath@arm.com, Morten Rasmussen , joaodias@google.com, Wanpeng Li Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Dietmar, On Tue, 28 Aug 2018 at 22:55, Dietmar Eggemann wrote: > > On 08/27/2018 12:14 PM, Peter Zijlstra wrote: > > On Fri, Aug 24, 2018 at 02:24:48PM -0700, Steve Muckle wrote: > >> On 08/24/2018 02:47 AM, Peter Zijlstra wrote: > >>>>> On 08/17/2018 11:27 AM, Steve Muckle wrote: > >>> > >>>>>> When rt_mutex_setprio changes a task's scheduling class to RT, > >>>>>> we're seeing cases where the task's vruntime is not updated > >>>>>> correctly upon return to the fair class. > >>> > >>>>>> Specifically, the following is being observed: > >>>>>> - task is deactivated while still in the fair class > >>>>>> - task is boosted to RT via rt_mutex_setprio, which changes > >>>>>> the task to RT and calls check_class_changed. > >>>>>> - check_class_changed leads to detach_task_cfs_rq, at which point > >>>>>> the vruntime_normalized check sees that the task's state is TASK_WAKING, > >>>>>> which results in skipping the subtraction of the rq's min_vruntime > >>>>>> from the task's vruntime > >>>>>> - later, when the prio is deboosted and the task is moved back > >>>>>> to the fair class, the fair rq's min_vruntime is added to > >>>>>> the task's vruntime, even though it wasn't subtracted earlier. Could you point out when the fair rq's min_vruntime is added to the task's vruntime in your *later* scenario? attach_task_cfs_rq will not do that the same reason as detach_task_cfs_rq. fair task's sched_remote_wakeup is false which results in vruntime will not be renormalized in enqueue_entity. Regards, Wanpeng Li > >>> > >>> I'm thinking that is an incomplete scenario; where do we get to > >>> TASK_WAKING. > >> > >> Yes there's a missing bit of context here at the beginning that the task to > >> be boosted had already been put into TASK_WAKING. > > > > See, I'm confused... > > > > The only time TASK_WAKING is visible, is if we've done a remote wakeup > > and it's 'stuck' on the remote wake_list. And in that case we've done > > migrate_task_rq_fair() on it. > > > > So by the time either rt_mutex_setprio() or __sched_setscheduler() get > > to calling check_class_changed(), under both pi_lock and rq->lock, the > > vruntime_normalized() thing should be right. > > > > So please detail the exact scenario. Because I'm not seeing it. > > Using Steve's test program (https://lkml.org/lkml/2018/8/24/686) I see the > issue but only if the two tasks (rt_task, fair_task) run on 2 cpus which > don't share LLC (e.g. CPU0 and CPU4 on hikey960). > > So the wakeup goes the TTWU_QUEUE && !share_cache (ttwu_queue_remote) path. > > ... > rt_task-3579 [000] 35.391573: sched_waking: comm=fair_task pid=3580 prio=120 target_cpu=004 > rt_task-3579 [000] 35.391580: bprint: try_to_wake_up: try_to_wake_up: task=fair_task pid=3580 task_cpu(p)=4 p->on_rq=0 > rt_task-3579 [000] 35.391584: bprint: try_to_wake_up: ttwu_queue: task=fair_task pid=3580 > rt_task-3579 [000] 35.391588: bprint: try_to_wake_up: ttwu_queue_remote: task=fair_task pid=3580 > rt_task-3579 [000] 35.391591: bprint: try_to_wake_up: ttwu_queue_remote: cpu=4 smp_send_reschedule > rt_task-3579 [000] 35.391627: sched_pi_setprio: comm=fair_task pid=3580 oldprio=120 newprio=19 > rt_task-3579 [000] 35.391635: bprint: rt_mutex_setprio: task=fair_task pid=3580 prio=120->19 queued=0 running=0 state=0x200 vruntime=46922871 cpu=4 cfs_rq->min_vruntime=7807420844 > rt_task-3579 [000] 35.391641: bprint: rt_mutex_setprio: p->prio set: task=fair_task pid=3580 prio=19 queued=0 running=0 state=0x200 vruntime=46922871 > rt_task-3579 [000] 35.391646: bprint: rt_mutex_setprio: queued checked: task=fair_task pid=3580 prio=19 queued=0 running=0 state=0x200 vruntime=46922871 > rt_task-3579 [000] 35.391652: bprint: rt_mutex_setprio: running checked: task=fair_task pid=3580 prio=19 queued=0 running=0 state=0x200 vruntime=46922871 > rt_task-3579 [000] 35.391657: bprint: rt_mutex_setprio: fair_class=0xffff000008da2c80 rt_class=0xffff000008da2d70 prev_class=0xffff000008da2c80 p->sched_class=0xffff000008da2d70 oldprio=120 p->prio=19 > rt_task-3579 [000] 35.391661: bprint: detach_task_cfs_rq: task=fair_task pid=3580 cpu=4 vruntime_normalized=1 > rt_task-3579 [000] 35.391706: sched_switch: rt_task:3579 [19] D ==> swapper/0:0 [120] > -0 [004] 35.391828: bprint: ttwu_do_activate: ttwu_do_activate: task=fair_task pid=3580 > -0 [004] 35.391832: bprint: ttwu_do_activate: ttwu_activate: task=fair_task pid=3580 > -0 [004] 35.391833: bprint: ttwu_do_wakeup: ttwu_do_wakeup: task=fair_task pid=3580 > -0 [004] 35.391834: sched_wakeup: fair_task:3580 [19] success=1 CPU:004 > > It doesn't happen on hikey960 when I use two cpus of the same LLC or on my > laptop (i7-4750HQ).