Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp961847ybt; Fri, 26 Jun 2020 16:22:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZTPnREuLdZwId9B2k7IEANLBB1GnblACpFG5PQ7EYQQZGNuBA48RE2gr3lmc0K3veRYbB X-Received: by 2002:aa7:dd10:: with SMTP id i16mr3223247edv.227.1593213760241; Fri, 26 Jun 2020 16:22:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593213760; cv=none; d=google.com; s=arc-20160816; b=kgxpl4o2pSWaT8+3qNbTD/6GfWWqNv+CezooROY3qjf1ftvzSvn5yTtiXT4No3vubY INiR9/4XTE3J9gqJEemvdwtQFI5YHMA3DR2bsrac0QrU7mmGMBWWf/VqfwgvlQcSqNK2 l+/usfd/D8xYsBpfnUZMgdqEhUmBnhSLRH4vNUg2CSAk+XX4wIxHQS6e4NAna1UxRaaj kNfGvJ8dCVLtH7w4Ik4lykwDFZXBI4aX12BJYyf1tyALLZobHXMDBKueBLoIButtf3T5 OKDxEdj76izUPfD+KTNkfyu+Wj1F90rHDjagNp74PASMBI82LcuJkMgvzC+V3llSonpc aMBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:in-reply-to :subject:cc:to:from:user-agent:references; bh=6hxukVxmTgN0Hqlm7sn10QXZRFJnQbRLJ1wRzX3DZ0k=; b=EhJn+w/Ebhf6aTplA39WVUypQE+AJ1pt2BydNTaRKNvwv6jyjlX2/6FfRKBgppLySu Yps+Fu4voOfOL/XMBs0Db9h0zyIczAk0k14rEE9yeCyxR5bWk7AhTqyTnXqhxiSKaL3f OJYvFSSj16R8sDZHcpz3gTnRsm0j5Yh5LVX1N8Wxty7e2D8PL5pGo8RCX5jegvKBIMeJ hOTSGReJj7DsP5BRN+DtA0zmBYBv+BxS0i36z8PyYvImrfPkKbw7J+AJU6U9aFFUlHwP OWyXt4ZXpmGLIYeVqQuojOuGvyECXLwCr+DxhZte7LqpsCZEaXeggmFtLaV/YtsIdQSA BLzg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o6si9594088edq.450.2020.06.26.16.22.16; Fri, 26 Jun 2020 16:22:40 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726158AbgFZXVe (ORCPT + 99 others); Fri, 26 Jun 2020 19:21:34 -0400 Received: from foss.arm.com ([217.140.110.172]:35274 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725883AbgFZXVd (ORCPT ); Fri, 26 Jun 2020 19:21:33 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E531A30E; Fri, 26 Jun 2020 16:21:32 -0700 (PDT) Received: from e113632-lin (e113632-lin.cambridge.arm.com [10.1.194.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 427353F73C; Fri, 26 Jun 2020 16:21:31 -0700 (PDT) References: <20200625154352.24767-1-qais.yousef@arm.com> <20200625154352.24767-3-qais.yousef@arm.com> <87bll6ngrr.derkling@matbug.net> User-agent: mu4e 0.9.17; emacs 26.3 From: Valentin Schneider To: Patrick Bellasi Cc: Qais Yousef , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Chris Redpath , Lukasz Luba , linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 2/2] sched/uclamp: Protect uclamp fast path code with static key In-reply-to: <87bll6ngrr.derkling@matbug.net> Date: Sat, 27 Jun 2020 00:21:29 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 26/06/20 13:38, Patrick Bellasi wrote: > On Thu, Jun 25, 2020 at 17:43:52 +0200, Qais Yousef wrote... >> @@ -994,9 +1013,16 @@ static inline void uclamp_rq_dec_id(struct rq *rq, struct task_struct *p, >> lockdep_assert_held(&rq->lock); >> >> bucket = &uc_rq->bucket[uc_se->bucket_id]; >> - SCHED_WARN_ON(!bucket->tasks); >> - if (likely(bucket->tasks)) >> - bucket->tasks--; >> + >> + /* >> + * This could happen if sched_uclamp_used was enabled while the >> + * current task was running, hence we could end up with unbalanced call >> + * to uclamp_rq_dec_id(). >> + */ >> + if (unlikely(!bucket->tasks)) >> + return; >> + >> + bucket->tasks--; >> uc_se->active = false; > > In this chunk you are indeed changing the code. > > Are we sure there are not issues with patterns like: > > enqueue(taskA) > // uclamp gets enabled > enqueue(taskB) > dequeue(taskA) > // bucket->tasks is now 0 > dequeue(taskB) > > TaskB has been enqueued with with uclamp enabled, thus it > has got uc_se->active=True and enforced its clamp value at RQ level. > > But with your change above we don't reset that anymore. > Harumph indeed... > As per my previous proposal: why not just removing the SCHED_WARN_ON? > That's the only real problem in the code above, since now we are not > more granted to have balanced inc/dec. > The SCHED_WARN_ON is gone, were you thinking of something else?