Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp619243yba; Fri, 5 Apr 2019 13:27:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqxB/cDjywBPF4mE46B1wxWIiVv3Hu6l3jyJcCKlIbL4RTgSON80IMz3eE1cZoMZxREjZjfj X-Received: by 2002:a62:ed10:: with SMTP id u16mr14900332pfh.187.1554496055040; Fri, 05 Apr 2019 13:27:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554496055; cv=none; d=google.com; s=arc-20160816; b=GC3TvXovUCIsGsGoN64S8aWexEJGzPehDSvfaTW4abTt8wfwvnt7YWmjOfg+lxncGX LXor8z7Bohd7CEOaBvW1a5QriG/ee4mriBsebHCXqq93mTdTsxnyzXkJQ07yFpXla1G8 mGufUCJ3SBlZL35EV/N3/sEsgEOFxPHd2i1gQBzzCm+9AeuOvLsBENBI7cQQ9m928Bcd CdyhcTUyi7qdyYlYHE1A1Rf5ConbPpCJrqFoASTrxDnHzoOXlKMvE/tvIohRiBSTIwg6 KXsRC7hCPTF4s9ZeOmmJ08CguQ+d1BAP5z4XqVzQOpqW2xkh3LEy5D8p5aels41UAYN5 po6g== 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=de0AH5cMYxV/DxIWWoZmP1MVzSoXcTp/ga6eLlyDjhc=; b=t+Do1YWRV4o+O3oXeyDK9DhuzoyzW5+wZ5SEno8YQsO0MKxmdsx1FQSc5A/CH/+9ff aWmRBSZh/Ut4rpwJfdc5eoCWw3wduwuLpQWc/BHn10xmdoPeIqZ3kMrAtCmNjxVwufzH J1CNtE51HnsDiG6ixAv7UMGB+qhIKjFGyKe/6IVl0dG3WZxDQzAeAri03ojQaNBsvOtH 4ba+qOIAZKVx9/BqgwFyL4fvvIX1veJMb02v8/sYczsRkD4FC1EZhCzk4C8umNXbl83L cZLaN/IXdgh+OO6f2dp/ht74dArfByjUwsL7h455EHXl1lTgSi1yBCkermkhiOJfiBlU S/uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (dns failure for signature) header.i=@infradead.org header.s=merlin.20170209 header.b=ZT92meut; 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 4si3716647pfp.185.2019.04.05.13.27.18; Fri, 05 Apr 2019 13:27:35 -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=temperror (dns failure for signature) header.i=@infradead.org header.s=merlin.20170209 header.b=ZT92meut; 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 S1726271AbfDEU0o (ORCPT + 99 others); Fri, 5 Apr 2019 16:26:44 -0400 Received: from merlin.infradead.org ([205.233.59.134]:40314 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726124AbfDEU0o (ORCPT ); Fri, 5 Apr 2019 16:26:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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=de0AH5cMYxV/DxIWWoZmP1MVzSoXcTp/ga6eLlyDjhc=; b=ZT92meut+OovvqJjbcDnw5Ilf mFK8x/BEC/C96obdUvlBJxak7cO3f6I3XKE89P5cXYcoYX5toTWJ8ZfrnGfx00wPMafJ3oASeFtlw M/prI4rcksOFoQcLdS9X/hTttvlC5mZIAGE1BtZtTUEmbefSzPK9uNpbJ7MU5YLiKduHAnELwdfnF sAieSlG5UGe4SXTifsLz+227yKuXBpHgi6ngSQ0h6tj/Z06VGstwot5FfCKzFLhK4yc9c6w/+HzMg wGWCsNYbWRpl1KMarSC/fA6Qh/KBZ3+o72XmZ3Qu8mNV4LNrBdlCfwx1EUG7szAjAeCttFElPxnkG 9U3XjdNKg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hCVPq-0007M2-Tf; Fri, 05 Apr 2019 20:26:23 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 6786B29AB64A1; Fri, 5 Apr 2019 22:26:20 +0200 (CEST) Date: Fri, 5 Apr 2019 22:26:20 +0200 From: Peter Zijlstra To: Stephane Eranian Cc: LKML , Thomas Gleixner , Andi Kleen , "Liang, Kan" , mingo@elte.hu, nelson.dsouza@intel.com, Jiri Olsa , tonyj@suse.com Subject: Re: [PATCH 3/3] perf/x86/intel: force resched when TFA sysctl is modified Message-ID: <20190405202620.GG4038@hirez.programming.kicks-ass.net> References: <20190404183219.125083-1-eranian@google.com> <20190404183219.125083-4-eranian@google.com> <20190405071333.GB4038@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 Fri, Apr 05, 2019 at 10:00:03AM -0700, Stephane Eranian wrote: > > > +static void update_tfa_sched(void *ignored) > > > +{ > > > + struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); > > > + struct pmu *pmu = x86_get_pmu(); > > > + struct perf_cpu_context *cpuctx = this_cpu_ptr(pmu->pmu_cpu_context); > > > + struct perf_event_context *task_ctx = cpuctx->task_ctx; > > > + > > > + /* prevent any changes to the two contexts */ > > > + perf_ctx_lock(cpuctx, task_ctx); > > > + > > > + /* > > > + * check if PMC3 is used > > > + * and if so force schedule out for all event types all contexts > > > + */ > > > + if (test_bit(3, cpuc->active_mask)) > > > + perf_ctx_resched(cpuctx, task_ctx, EVENT_ALL|EVENT_CPU); > > > + > > > + perf_ctx_unlock(cpuctx, task_ctx); > > > > I'm not particularly happy with exporting all that. Can't we create this > > new perf_ctx_resched() to include the locking and everything. Then the > > above reduces to: > > > > if (test_bit(3, cpuc->active_mask)) > > perf_ctx_resched(cpuctx); > > > > And we don't get to export the tricky bits. > > > The only reason I exported the locking is to protect > cpuc->active_mask. But if you > think there is no race, then sure, we can just export a new > perf_ctx_resched() that > does the locking and invokes the ctx_resched() function. It doesn't matter if it races, if it was used and isn't anymore, it's a pointless reschedule, if it isn't used and we don't reschedule, it cannot be used because we've already set the flag.