Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp583112ybg; Wed, 23 Oct 2019 02:41:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqwvWEiIWtFTYVnH5wmeoJybqFNwqf9fGeEsu+wb767e/wC2+XchnAmqEnidPGC2tG2ZGOol X-Received: by 2002:a17:906:6451:: with SMTP id l17mr31713800ejn.114.1571823708810; Wed, 23 Oct 2019 02:41:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571823708; cv=none; d=google.com; s=arc-20160816; b=QnBx41XybK6eJeqMuqboQJ3teENTAgWNIMtgV946PyT/d/fWNmFvQs+UEck7o6GDjB 5VfA2U3yXamhlyM0F2E6CT/4l1rBwbqmoJTRjyLWN94ghVhZtLommCjkb/XUe79hyTTm x7993IANaDS4kitfYCc42ZGAHdmpnRgyzHRLN0QsYQnVLMTsQiDem/60JZRzB1jNHQya aQg/eFrQ9pwh/X9WNmFBrdtV9BSKtJfDBEPl6KsEtel9mNmME6zhHxDzyKKr5OJW3qbN MEsXhOfnhojTHMXfCGoPkpWWTVE1vECgXE5zFmcEgFoIoPlY3Td6nhZDJRnfsbWfglgF ipNw== 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:dkim-signature; bh=08h2Fac4binfde4ottD+HQZVrVOQxbpKLsAB927oEJs=; b=ByovSc/4XZ6xOz53ZQ4iSqv3UCY0bTUKhlDS8m1EyMISeS7AtPPGWvaJE8xq+L/L0M 3qrqF0BNOA+E+vKvm6tGkHBFNzvd1f5j4QkB28MtMcEp8xkn+O0zXmdsUjFoFHDApLCI G3ToKOu1YPUqx2ZTTt0lkhsyxSW9F2l3Za231JoBhB9NF/mcz114yGEixODoqGpsD64U tXtDmRwHuX+kr2l2FeL9Kb9Ng2DQXRsZwBtrCExP/41xXNpHLZKXMYuwbf7XBcVFXIPc jpT04KETpJ2X5OA8PLFnTT6H3kwTi3S9lJ1DaHDcjeYfW5JRobO2NBADOSHlPI7JneDG fvrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=IAXJcfjg; 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 l47si8354293edb.111.2019.10.23.02.41.25; Wed, 23 Oct 2019 02:41:48 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=IAXJcfjg; 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 S2403892AbfJWJiG (ORCPT + 99 others); Wed, 23 Oct 2019 05:38:06 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:48880 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390165AbfJWJiF (ORCPT ); Wed, 23 Oct 2019 05:38:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=08h2Fac4binfde4ottD+HQZVrVOQxbpKLsAB927oEJs=; b=IAXJcfjgK/GUlvRiGaRoOru2V Glp2+FLESPHbp6mucnf59vda8jyHelKbFehC5EQYpU27itgefobVbQrlQxeuf4EJVDbgDuXs6j0/f 08cWrdLvUP+DcTFL/lsvdrnwpOiqKOA7M8y1Zcx6XZr78RZVxECvOzIQASWb1xoMflPaWAMs7BNn2 BzfkayP70VSySTwFe0P0tczGubWh6ODHWxHx1V2iRFSmTqj+DaZF4x3ffvQTIwDFnewCXBfgi+2hY mIqpNiNNOTXQx6Qi1NwgyjbV1TN+Y5AW64+RRebJSIuB0HLqYNfcnAT4+4sKI5tUSKFkza5FToqVa BAaavjnWQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1iND5b-00088E-9O; Wed, 23 Oct 2019 09:37:59 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 7448D300EBF; Wed, 23 Oct 2019 11:36:59 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 36F492B1C6361; Wed, 23 Oct 2019 11:37:57 +0200 (CEST) Date: Wed, 23 Oct 2019 11:37:57 +0200 From: Peter Zijlstra To: Stephane Eranian Cc: LKML , mingo@elte.hu, Arnaldo Carvalho de Melo , Jiri Olsa , "Liang, Kan" , Song Liu , Ian Rogers Subject: Re: [PATCH] perf/core: fix multiplexing event scheduling issue Message-ID: <20191023093757.GR1817@hirez.programming.kicks-ass.net> References: <20191018002746.149200-1-eranian@google.com> <20191021100558.GC1800@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 23, 2019 at 12:06:43AM -0700, Stephane Eranian wrote: > On Mon, Oct 21, 2019 at 3:06 AM Peter Zijlstra wrote: > > On Thu, Oct 17, 2019 at 05:27:46PM -0700, Stephane Eranian wrote: > > > + * others removed. There is a way to get removed and not be disabled first. > > > + */ > > > + if (ctx->rotate_necessary && ctx->nr_events) { > > > + int type = get_event_type(event); > > > + /* > > > + * In case we removed a pinned event, then we need to > > > + * resched for both pinned and flexible events. The > > > + * opposite is not true. A pinned event can never be > > > + * inactive due to multiplexing. > > > + */ > > > + if (type & EVENT_PINNED) > > > + type |= EVENT_FLEXIBLE; > > > + ctx_resched(cpuctx, cpuctx->task_ctx, type); > > > + } > > > > What you're relying on is that ->rotate_necessary implies ->is_active > > and there's pending events. And if we tighten ->rotate_necessary you can > > remove the && ->nr_events. > > > Imagine I have 6 events and 4 counters and I do delete them all before > the timer expires. Then, I can be in a situation where > rotate_necessary is still true and yet have no more events in the > context. That is because only ctx_sched_out() clears rotate_necessary, > IIRC. So that is why there is the && nr_events. Now, calling > ctx_resched() with no events wouldn't probably cause any harm, just > wasted work. > So if by tightening, I am guessing you mean clearing rotate_necessary > earlier. But that would be tricky because the only reliable way of > clearing it is when you know you are about the reschedule everything. > Removing an event by itself may not be enough to eliminate > multiplexing. I think you're over-thinking things. The thing you test 'ctx->nr_events' has a clear place where it drops to 0. If we add ctx->nr_events--; + if (!ctx->nr_events && ctx->rotate_necessary) + ctx->rotate_necessary = 0; to list_del_event(), we can get rid of that. Further, since we set it on reschedule, I propose you change the above like: if (ctx->rotate_necessary) { int type = get_event_type(event); /* * comment.. */ if (type & EVENT_PINNED) type |= EVENT_FLEXIBLE; + /* + * Will be reset by ctx_resched()'s flexible_sched_in(). + */ + ctx->rotate_necessary = 0; ctx_resched(cpuctx, cpuctx->task_ctx, type); } Then rotate_necessary will be tight.