Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp437580imm; Wed, 29 Aug 2018 03:56:24 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda45/9KJVZymGb1uAiXBdLE1+35DwRbw8QBSsQhYgfU1NpCAHNE4+OEASh5LCYDKnJi+VZc X-Received: by 2002:aa7:82c3:: with SMTP id f3-v6mr5520948pfn.136.1535540184383; Wed, 29 Aug 2018 03:56:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535540184; cv=none; d=google.com; s=arc-20160816; b=kqpCXnCdEw5i96gcVcgjbWef7SMcIyc3GstXBKz4o8EW/kCwsIOMUnTqrzUT9jrc8i 9bo7bxZoUEZHQnoR61Flb2l9eo0Nm9F5ZxiMtgbhdBRwqy+fbnUj+dzIjJ2G+DVmx2Cr 2lc40AYyQ38wP1SS8IAzKzu9cM8fBxaeWmn61H5lEmXmc13DXaXuiA5/sg7IEJKtYSTb rX8FUEw2ViBJYVj24yaVIqXVnwz3Gnk/LTOlpehXkiOH8xz/GY8TyKGJIw+E7VB9yJEv y+lAh9k9bXsCjwmKKmqsl/h8syRKX9tt7HfFy99KcMjq90/q1FCFIJxvUnJ+XAjVPKPA wIkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject:arc-authentication-results; bh=ShGnIX4oxRsjofkoE9NSzcpSTdFE+/xXy/aQPhmnOO0=; b=FOvXBi86WJQ7qr3FxxgZ7KUpoTZTNNa/7cluXafaF7kqS2BJPcdENy5V3SxoJFJjTV 1SvLw1orKiVoAfRWCFKBfqTP494c4lhPS6kIIoraTX/02AdSv68VIBUlnc5IpTH2DcFK 6svcgfTxaEU/D7E4QvdWltwNEqR5z9iBdpXMLyTgd/T0/8fSWbSD6wyfVPtR9g9krcOE 8qHxIsw/Dr5khqdtKhjOMfsXAKkTCd2qtnAplWZWgsFFgA7MXzIAEc2vj6zF1YP/mqW5 0Pdf7zxg8hi2rAzrxl8AxvkmTJkDAbMiPm6k+zcRLoLiIamD2rzn0u1Ge19aMCmiTic4 qkVQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t13-v6si3484232pgl.461.2018.08.29.03.56.08; Wed, 29 Aug 2018 03:56:24 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728196AbeH2OvV (ORCPT + 99 others); Wed, 29 Aug 2018 10:51:21 -0400 Received: from foss.arm.com ([217.140.101.70]:52258 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727190AbeH2OvV (ORCPT ); Wed, 29 Aug 2018 10:51:21 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D50A680D; Wed, 29 Aug 2018 03:55:01 -0700 (PDT) Received: from [10.1.34.70] (deggeman-mac.cambridge.arm.com [10.1.34.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B1A283F557; Wed, 29 Aug 2018 03:54:59 -0700 (PDT) Subject: Re: [PATCH] sched/fair: vruntime should normalize when switching from fair From: Dietmar Eggemann To: Peter Zijlstra , Steve Muckle Cc: Miguel de Dios , Ingo Molnar , linux-kernel@vger.kernel.org, kernel-team@android.com, Todd Kjos , Paul Turner , Quentin Perret , Patrick Bellasi , Chris Redpath , Morten Rasmussen , John Dias 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> Message-ID: <273b9b52-8c00-0414-ea11-214d81cd57c7@arm.com> Date: Wed, 29 Aug 2018 11:54:58 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <2ed346fa-dbe8-4928-928b-a34338b2d8c9@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/28/2018 03:53 PM, 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. >>>> >>>> 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. I forgot to mention that since fair_task's cpu affinity is restricted to CPU4, there is no call to set_task_cpu()->migrate_task_rq_fair() since if (task_cpu(p) != cpu) fails. I think the combination of cpu affinity of the fair_task to CPU4 and the fact that the scheduler runs on CPU1 when waking fair_task (with the two cpus not sharing LLC) while TTWU_QUEUE is enabled is the situation in which this vruntime issue can happen. [...]