Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp460007yba; Fri, 5 Apr 2019 10:01:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqx8Wf0Dckqrr4nFS1HhxhL/op8wLyIFY6/lW82VIrniUiDAFaaZ4EUgWYJF/UVEt7J+CYoZ X-Received: by 2002:a65:6148:: with SMTP id o8mr13371542pgv.153.1554483671223; Fri, 05 Apr 2019 10:01:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554483671; cv=none; d=google.com; s=arc-20160816; b=me8j7Noe4pDcbqhQKGdPvUNF7IxnG7TZF6Nn/byBAt7V2FbAIbobK9GgbMose8KIk3 JXHZEVkWwQmbcrAFjGSVcoR9hAlzqeVqjDdSubCoGTn9Qx5lrcM5W2mggQ4KfSP9i3jr L/H/nh1QyCu6muHuGt5XhlGEsh1MCpaWkZt7fj3WAk9xfYV43O4UjAzBfV+jfAgkueKx f+lm03LJmgOLaNXFfgML+ZY31G/7dAwj4f2M6ehAGi3cbZhi8fdpWk1Q6TgKwkdrsR21 FHvo5ysxQDnKYA9sdHUGkgnNRDqCvA7kT096eP9AyKhLgOBXViWLpY1hiwlp8mxrYX6Z AGYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=+j8JRpx63PertkzWVtVzgs5Y9k8FnyIUlW0cUxHjtY0=; b=1AQLg7vLcqo81VtbeEzNkab2c8XJEiXhL430kdjsA5B1b9F2ANATy+nmZXxE5yOVhe 44+z+5mxwAuCxOvGlPzt+aW0J2ZuOxx8FUhTIz7fFXrh494PcZNPntFVNKZaSVqLqhn/ B0yyUnJ/aYpextIZ3g3SJ6FLIh55n9CCsnks8x7jkNcceAmktryjWpfTv3lO4AfC9LUV GIoj8K5npBxerdQgusMArW2s7xQANZwk1MNxDAlSx5n7yMrr+bLfC3Lx5gBhsxccUpQM h54f88NUU+LynB8wP5uhr9tAZ+8GpCpolivZp+YLecGngSoif7jq7lY4o9JKwAGf67Mc Jngw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=XG6wtRLg; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f63si13156348pff.107.2019.04.05.10.00.55; Fri, 05 Apr 2019 10:01:11 -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=pass header.i=@google.com header.s=20161025 header.b=XG6wtRLg; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731542AbfDERAQ (ORCPT + 99 others); Fri, 5 Apr 2019 13:00:16 -0400 Received: from mail-vk1-f194.google.com ([209.85.221.194]:44584 "EHLO mail-vk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731185AbfDERAQ (ORCPT ); Fri, 5 Apr 2019 13:00:16 -0400 Received: by mail-vk1-f194.google.com with SMTP id q189so1590806vkq.11 for ; Fri, 05 Apr 2019 10:00:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+j8JRpx63PertkzWVtVzgs5Y9k8FnyIUlW0cUxHjtY0=; b=XG6wtRLgq9xvOropKTtfRoU4BvZx8odmTka2MRaqCNzARfr7WQWYhzYckbAofBNqyE BAntEe3nel8V6gPgplKGrYirrciLyY5l6WgNasp4o0uVEUFID9OhVfkd1lLLd1EY5QDR uCcDSjUW3bQoco+VAjcdrKYuCOm2Qu7Pzig6FQbyFaj7otSgv9Fp0LGXawKgG8bVYj4w +78247a5okKUMQx/bfkFyStJ0vuR/nFdwEETuaWEMc1EwFScZndZQob/BBkhQdYNl48r hbGZTVBXT8fuNt/31OVhTrXh8OiOy4SVIIY5nmhOhbd6y9/bbPeMHdUJ2z0a60W5nSsH XUWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+j8JRpx63PertkzWVtVzgs5Y9k8FnyIUlW0cUxHjtY0=; b=iNkRPcBPQQCYgx3PBMlkvg2JVhSZbJybiPZQR7wa9rb9dPGvSBxLEVI35vtIypURmL 8FkSU/ldF59OXwQZ4dyeFEfogDvL/LINJk3fly8uhGw6j9be4ufdH799bc/6VwqbXKzS fhR+lnWZtv+hp4wUp28nuV3HJ4hQrKS7HRNpcL4iTBSl+dgHODjd3mKdjCU/8phoxHlU TS8Sv1zfjMKHb001LYGEnttAv0V4FzefkDZRpyMEHc/Hn7ZPK7wuE43wOyg1Nn+PvDsx o6pRQsY7IkojSK0av+buSiFDgdY0L+sPQKClJjD6JC4n+ANqorYEdYLtSlnvyx3HyH5P kJVw== X-Gm-Message-State: APjAAAUIPusSuu+ciS81Rz1XKa8Awb+fMO1UG+D3zIw09w89p7vNP52v nWV0NLeo0qBjspOdNmFz5gKU/AWN6J+p+HbuJgiqgw== X-Received: by 2002:a1f:607:: with SMTP id 7mr8502617vkg.2.1554483614815; Fri, 05 Apr 2019 10:00:14 -0700 (PDT) MIME-Version: 1.0 References: <20190404183219.125083-1-eranian@google.com> <20190404183219.125083-4-eranian@google.com> <20190405071333.GB4038@hirez.programming.kicks-ass.net> In-Reply-To: <20190405071333.GB4038@hirez.programming.kicks-ass.net> From: Stephane Eranian Date: Fri, 5 Apr 2019 10:00:03 -0700 Message-ID: Subject: Re: [PATCH 3/3] perf/x86/intel: force resched when TFA sysctl is modified To: Peter Zijlstra Cc: LKML , Thomas Gleixner , Andi Kleen , "Liang, Kan" , mingo@elte.hu, nelson.dsouza@intel.com, Jiri Olsa , tonyj@suse.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 5, 2019 at 12:13 AM Peter Zijlstra wrote: > > On Thu, Apr 04, 2019 at 11:32:19AM -0700, Stephane Eranian wrote: > > diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c > > index a4b7711ef0ee..8d356c2096bc 100644 > > --- a/arch/x86/events/intel/core.c > > +++ b/arch/x86/events/intel/core.c > > @@ -4483,6 +4483,60 @@ static ssize_t freeze_on_smi_store(struct device *cdev, > > return count; > > } > > > > +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. > > +} > > + > > +static ssize_t show_sysctl_tfa(struct device *cdev, > > + struct device_attribute *attr, > > + char *buf) > > +{ > > + return snprintf(buf, 40, "%d\n", allow_tsx_force_abort); > > +} > > + > > +static ssize_t set_sysctl_tfa(struct device *cdev, > > + struct device_attribute *attr, > > + const char *buf, size_t count) > > +{ > > + unsigned long val; > > + ssize_t ret; > > + > > + ret = kstrtoul(buf, 0, &val); > > You want kstrtobool() > ok. > > + if (ret) > > + return ret; > > + > > + /* looking for boolean value */ > > + if (val > 2) > > + return -EINVAL; > > + > > + /* no change */ > > + if (val == allow_tsx_force_abort) > > + return count; > > + > > + allow_tsx_force_abort ^= 1; > > allow_tsx_force_abort = val; > > is simpler > ok. > > + > > + on_each_cpu(update_tfa_sched, NULL, 1); > > + > > + return count; > > +}