Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp460202ybt; Fri, 19 Jun 2020 06:06:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvkUjkFAYIAwXdlmUnlTdd8dupRnc3SRXYjSMKzZKA5xedk/fu7bQl8jMbv4HbZY5I7B2Z X-Received: by 2002:a05:6402:1ca2:: with SMTP id cz2mr3061528edb.15.1592571972238; Fri, 19 Jun 2020 06:06:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592571972; cv=none; d=google.com; s=arc-20160816; b=Re9ZUL8UzeBDwG0YikF/88D3bnVh9syztU5FIEDLN1FWK/GzLHy1uzmFlP6Yud4cN7 AZLN1TtdJE6qfn7HJ8egBJbZvGflMSOW1hIJ5kapH/4QlVpso4KM/FNmZgCje4wfD1vj tIzidNlIz0w2ztCFjxa6ufRJWRwlOsbc/GcvsTppztpUgdCEhJ0ujGCnUG4DAUPwpcTt bPO5L3aVIcbE1Zu3qRsmc0npULvPIBidFIFI3xLd3tpVwFM2L47R1RpWSYCDYs+o8bk3 jIQolgtobN0ZibBOF+8d8lITHgqs4d7J5PjaUPSR3qsbUo37/FCS8xek87wouAqAZ0f7 EP/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=EG3wwE63Es6mYtg3quUYJfn4pVRp9wsMUWie3wtddSs=; b=Fa5jgFghCBnnDRLZxS9sj8seZKh/VXe8C5A0orXpkUU4YHiEbqw5X+tDNchjQgNzWe 4koahTXN0tRQIc0ABjSnfsSVg9OoYY693p1yhtE0ZUeYRyApoB/Ug243plbYDL9bedSu KZGo2+/ETxWnnYMtanD0wnMC77xtx6lrwVMW/9BwV6OtVtw2HAqAaucdKQPCDD267hqR AKxpc2aeoE/OfK90vYc9PoeSm3lDrneIvasOfYcV/GZycnZdvBmREAeyZt/ms5Rs2bf2 vEFEUS0Vta+7v/JS6aL9w4Xw3OxMlnTzEWWzc0p960NEIulSTO6/v617JUEqf56eMIrQ W/8w== 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 a2si4098716edr.468.2020.06.19.06.05.50; Fri, 19 Jun 2020 06:06:12 -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 S1731835AbgFSMvy (ORCPT + 99 others); Fri, 19 Jun 2020 08:51:54 -0400 Received: from foss.arm.com ([217.140.110.172]:56780 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728081AbgFSMvx (ORCPT ); Fri, 19 Jun 2020 08:51:53 -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 668032B; Fri, 19 Jun 2020 05:51:52 -0700 (PDT) Received: from e107158-lin.cambridge.arm.com (e107158-lin.cambridge.arm.com [10.1.195.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BB1BE3F6CF; Fri, 19 Jun 2020 05:51:50 -0700 (PDT) Date: Fri, 19 Jun 2020 13:51:48 +0100 From: Qais Yousef To: Valentin Schneider Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Patrick Bellasi , Chris Redpath , Lukasz Luba , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] sched/uclamp: Protect uclamp fast path code with static key Message-ID: <20200619125148.y4cq3hwllgozbutq@e107158-lin.cambridge.arm.com> References: <20200618195525.7889-1-qais.yousef@arm.com> <20200618195525.7889-3-qais.yousef@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/19/20 11:36, Valentin Schneider wrote: > > On 18/06/20 20:55, Qais Yousef wrote: > > There is a report that when uclamp is enabled, a netperf UDP test > > regresses compared to a kernel compiled without uclamp. > > > > https://lore.kernel.org/lkml/20200529100806.GA3070@suse.de/ > > > > ISTR the perennial form for those is: https://lkml.kernel.org/r/ The link is correct permalinnk from lore and contains the message-id as Peter likes and he has accepted this form before. If you look closely you'll see that what you suggest is just moving 'lkml' to replace lore in the dns name and put an /r/. I don't see a need to enforce one form over the other as the one I used is much easier to get. If Peter really insists I'll be happy to change. [...] > > + * This could happen if sched_uclamp_unused was disabled while the > > + * current task was running, hence we could end up with unbalanced call > > + * to uclamp_rq_dec_id(). > > + */ > > + if (unlikely(!bucket->tasks)) > > + return; > > I'm slightly worried about silent returns for cases like these, can we try > to cook something up to preserve the previous SCHED_WARN_ON()? Say, > something like the horrendous below - alternatively might be feasible with > with some clever p->on_rq flag. I am really against extra churn and debug code to detect an impossible case that is not really tricky for reviewers to discern. Outside of enqueue/dequeue path, it's only used in update_uclamp_active(). It is quite easy to see that it's impossible, except for the legit case now when we have a static key changing when a task is running. I am strongly against extra debug code just to be safe. It ends up with confusion down the line and extra complexity, and since this is the hot path maybe potential extra variables to mess with cache behaviors. Thanks -- Qais Yousef > > --- > diff --git a/include/linux/sched.h b/include/linux/sched.h > index b62e6aaf28f0..09a7891eb481 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -695,6 +695,9 @@ struct task_struct { > struct uclamp_se uclamp_req[UCLAMP_CNT]; > /* Effective clamp values used for a scheduling entity */ > struct uclamp_se uclamp[UCLAMP_CNT]; > +#ifdef CONFIG_SCHED_DEBUG > + int uclamp_unused_enqueue; > +#endif > #endif > > #ifdef CONFIG_PREEMPT_NOTIFIERS > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 2a712dcb682b..2a723e9d5219 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -1018,8 +1018,10 @@ static inline void uclamp_rq_dec_id(struct rq *rq, struct task_struct *p, > * current task was running, hence we could end up with unbalanced call > * to uclamp_rq_dec_id(). > */ > - if (unlikely(!bucket->tasks)) > + if (unlikely(!bucket->tasks)) { > + SCHED_WARN_ON(!p->uclamp_unused_enqueue); > return; > + } > > bucket->tasks--; > uc_se->active = false; > @@ -1049,8 +1051,16 @@ static inline void uclamp_rq_inc(struct rq *rq, struct task_struct *p) > { > enum uclamp_id clamp_id; > > - if (static_branch_likely(&sched_uclamp_unused)) > +#ifdef CONFIG_SCHED_DEBUG > + p->uclamp_unused_enqueue = 0; > +#endif > + > + if (static_branch_likely(&sched_uclamp_unused)) { > +#ifdef CONFIG_SCHED_DEBUG > + p->uclamp_unused_enqueue = 1; > +#endif > return; > + } > > if (unlikely(!p->sched_class->uclamp_enabled)) > return; > @@ -1075,6 +1085,10 @@ static inline void uclamp_rq_dec(struct rq *rq, struct task_struct *p) > > for_each_clamp_id(clamp_id) > uclamp_rq_dec_id(rq, p, clamp_id); > + > +#ifdef CONFIG_SCHED_DEBUG > + p->uclamp_unused_enqueue = 0; > +#endif > } > > static inline void > ---