Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3664038pxj; Mon, 21 Jun 2021 03:59:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7/qJgBAoT7/ztM6R9t7w3EL69qPPzlqDZmweMAiB2OM/Aew+S5C0IpM0P8/22voJKZGGV X-Received: by 2002:a5d:8b8b:: with SMTP id p11mr19761266iol.77.1624273151077; Mon, 21 Jun 2021 03:59:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624273151; cv=none; d=google.com; s=arc-20160816; b=cU8Jo7KK3xMWd1WGD3J9DTfPeVY5n8kx+r620gftWLMw/D789IGWV5EYYL2zBIk4hL +v37jhIJFWPf+H1kEV4+AejdFvhjsfd+bFp6p4BPO730HtjBLl2F3x/aiKagMi8Ph7w9 VO/bJslOxeMFqPAJcXk0+S28uwCv+KChdiqsYN+dIZcti4u9Jg0c7PG2HL3fwf4unbOX syl4PK/Gnro0xfnCau0DMXY3ABQi+H5mYum1FQLaC2jbM0FGhHlP4P5HWMSBp64WLxD6 BiSl9gd26gNwOg7ZpxTBTcjE3SIE4gS/nWNV26gItvGBxUGOD+aGlaifEf+3Dd9JzPsM Yzww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=clF9wEFSrz/v2WVCRdc6dS5IP9XeQy5WQHIia05IgYQ=; b=UtCaWsNXtYaAy+8EKpYcuDDzJ95NgM88wLsX9Yigc5BWs+0UizdGH5RUF5+YhrURzI oe6Grj0Q7kGauWUxC+clrCh+J8gAlCXuowKUI0CbSkGAN9zLoCB6bkqToVnhbnbmCC1F qRayZa0YNb8BwcgUBemaCAvTqmPNQO7/+xzbWMivOU8tA8BZVaaBiCsGluMXi5/wTrA1 2vQ/ka7luM2UrHwsHnqezyrbCpf9FQ4+vYrgphKYaPVzxAuDjQTI1kjbBRzAs+YDiF5T jeURko5N54wV2//F5q0wOJ4bTPU61kaGh9FCOSlWxjN0iwS5H+Lzj/KdtKGjT86ewAZS mGVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KPtNjFRC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c2si11585096ilr.135.2021.06.21.03.58.58; Mon, 21 Jun 2021 03:59:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KPtNjFRC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230118AbhFUK7i (ORCPT + 99 others); Mon, 21 Jun 2021 06:59:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229663AbhFUK7h (ORCPT ); Mon, 21 Jun 2021 06:59:37 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92417C061574 for ; Mon, 21 Jun 2021 03:57:23 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id n23so10192668wms.2 for ; Mon, 21 Jun 2021 03:57:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=clF9wEFSrz/v2WVCRdc6dS5IP9XeQy5WQHIia05IgYQ=; b=KPtNjFRCb/EW9vegJsEI18s4uWG03qNGQbL7vvggXIxX46EGXTONi8d2khNA64emoN hIzoQr7FlbuhqQoFzhTdnXbDR9WOGlT+doWPdYWc6yoDM1mm0YICATMaPH7mlwKIPjgb QBBjkRE37ABX4dYD7a0j2HsIiLv/HuZWiT5zzQ+YW6EzUqfBiMOtUUDsbSuY1trRuMpn SdSKUdSnBiLYTNeg9VhTpAKeh3ENA3A2qVs9GzpZXmhR6IBSctdzmyF1PbmyqlZXwHMy 6jFbJl2IpvZDpy+feDWvf+mpn2kUkcHngD6vOzZ4r4NPO/P0Xzc/UTovWgaswE2Tu8QH goug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=clF9wEFSrz/v2WVCRdc6dS5IP9XeQy5WQHIia05IgYQ=; b=oQ3OiIivvzgj8KlGnDw1qJziGfIGgWyTDksJ8Worr0vXgXDLhK8YLnPOpeccsAFr3+ ZD77Gl6o4AVv9Awp8/81tUL0Id95ppX0IEm/GbzOeESnCCLiE/6Lk3lsA8vKUoeQ9thU Mj9Xe9q0YxDJwAqPYMZJUWNpLtOC284pYd8K9fhL0tgVBchKv6VragZEne3L5O/dPCiE tXdj9DLMT2fQ43eCtTn27QoCYKx9d8wBrDXDEO4E94x8e4XobFa4BD8mARyXNDg+Mchb PNjj/em37a9SVx/EqJGF+Fjunt8VRywsW7VfamYDpPDAd5zKYtjSCVtVn6CEQv2garYA 5EgQ== X-Gm-Message-State: AOAM5303b7KHxaya7MK8QXv1vepJ7HGudVka3uWWFwgNSBi9UbL6bpet DjFO83hVW93E6iDPLSWF/MW7PA== X-Received: by 2002:a05:600c:3ba0:: with SMTP id n32mr26530846wms.107.1624273042055; Mon, 21 Jun 2021 03:57:22 -0700 (PDT) Received: from google.com (105.168.195.35.bc.googleusercontent.com. [35.195.168.105]) by smtp.gmail.com with ESMTPSA id p13sm16352891wrt.89.2021.06.21.03.57.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 03:57:21 -0700 (PDT) Date: Mon, 21 Jun 2021 10:57:18 +0000 From: Quentin Perret To: Dietmar Eggemann Cc: Peter Zijlstra , mingo@redhat.com, vincent.guittot@linaro.org, qais.yousef@arm.com, rickyiu@google.com, wvw@google.com, patrick.bellasi@matbug.net, xuewen.yan94@gmail.com, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH v2 1/3] sched: Fix UCLAMP_FLAG_IDLE setting Message-ID: References: <20210610151306.1789549-1-qperret@google.com> <20210610151306.1789549-2-qperret@google.com> <23e44dd5-5229-ac16-5801-3b74f013b7f3@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <23e44dd5-5229-ac16-5801-3b74f013b7f3@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Dietmar, On Thursday 17 Jun 2021 at 17:27:56 (+0200), Dietmar Eggemann wrote: > On 11/06/2021 09:25, Quentin Perret wrote: > > On Thursday 10 Jun 2021 at 21:05:12 (+0200), Peter Zijlstra wrote: > >> On Thu, Jun 10, 2021 at 03:13:04PM +0000, Quentin Perret wrote: > >>> The UCLAMP_FLAG_IDLE flag is set on a runqueue when dequeueing the last > >>> active task to maintain the last uclamp.max and prevent blocked util > >>> from suddenly becoming visible. > >>> > >>> However, there is an asymmetry in how the flag is set and cleared which > >>> can lead to having the flag set whilst there are active tasks on the rq. > >>> Specifically, the flag is cleared in the uclamp_rq_inc() path, which is > >>> called at enqueue time, but set in uclamp_rq_dec_id() which is called > >>> both when dequeueing a task _and_ in the update_uclamp_active() path. As > >>> a result, when both uclamp_rq_{dec,ind}_id() are called from > >>> update_uclamp_active(), the flag ends up being set but not cleared, > >>> hence leaving the runqueue in a broken state. > >>> > >>> Fix this by setting the flag in the uclamp_rq_inc_id() path to ensure > >>> things remain symmetrical. > >> > >> The code you moved is neither in uclamp_rq_inc_id(), although > >> uclamp_idle_reset() is called from there > > > > Yep, that is what I was trying to say. > > > >> nor does it _set_ the flag. > > > > Ahem. That I don't have a good excuse for ... > > (A) dequeue -> set > > (1) dequeue_task() -> uclamp_rq_dec() -> > > (2) cpu_util_update_eff() -> ... -> uclamp_update_active() -> > > uclamp_rq_dec_id() > > uclamp_rq_max_value() > > /* No tasks -- default clamp values */ > uclamp_idle_value() { > > if (clamp_id == UCLAMP_MAX) > rq->uclamp_flags |= UCLAMP_FLAG_IDLE; <-- set > } > > --- > > (B) enqueue -> clear > > (1) enqueue_task() -> > > uclamp_rq_inc() { > > (2) cpu_util_update_eff() -> ... -> uclamp_update_active() -> > > uclamp_rq_inc_id() { > > uclamp_idle_reset() { > <-- new clear > } ^ > } | > | > if (rq->uclamp_flags & UCLAMP_FLAG_IDLE) | > rq->uclamp_flags &= ~UCLAMP_FLAG_IDLE; <-- old clear > } > > --- > > uclamp_update_active() > > if (p->uclamp[clamp_id].active) { > uclamp_rq_dec_id() <-- (A2) > uclamp_rq_inc_id() <-- (B2) > } > > Is this existing asymmetry in setting the flag but not clearing it in > uclamp_update_active() the only issue this patch fixes? I think this is the root of the problem, but it can have odd symptoms. In a bad case that can lead to hitting the WARN in uclamp_rq_dec_id (which is how we've found the bug in the first place). I'll try and repost this with a correct commit message soon -- still fighting with my inbox right now. Thanks, Quentin