Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp780687yba; Fri, 5 Apr 2019 17:53:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHPmbBYb4QGpU6Ed5H/6x3/T0FLfq+JOCIIVwHs6VVq4q/0YPZl0eIFMzh03UluedDVxVR X-Received: by 2002:a17:902:e508:: with SMTP id ck8mr15925585plb.96.1554512018137; Fri, 05 Apr 2019 17:53:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554512018; cv=none; d=google.com; s=arc-20160816; b=X7GPbmHmkeSxLmJI36QeZzY2lTPuHnOfsVyhDhkfYGpMr/TBUSt6JPlSFdoMft8g2f 6UcGZOKLRfZRZG6B6UuHYPxyD9jfIhoMaRO7kcBIz5m2tczQSWS+OWBlJqM0abfKhPeF ApaKrtDQxRAJPSJ/c85JitOILKouSkndlLe6iwQKLPZ7I1+MYPOYU3A7tzY4//YSjite YlPB/3NjshnVZOj+R9IRKAfDQ7844QcV23YiFlCBdqzcroJZdhRSCLUBb/k3xqcPS6/8 1xfs3O7hxBmww+7pKxTQSNH8yuqB+0utLZ9soLzk1h58KbVE/IBojiRB7WxuHLj18iW1 U+qw== 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=Hml97b0NmWYMZJBuaShZ+PWX2gT4x6nYAZjr3fyQFIQ=; b=jq5Q7dzv8j1gGYF+4R8F9a+J2zZPVpZHRjB46UaPJftJqzcOaAcfpX2ODuRqci5DWU qUyFLBPmS7FEWTTqFv00PZhHifWyLO9PzspXUSrHgsXUoogHtOmsSHGSQ8M5IQ5mFfWp PC9YR4X1e8mLTdgvJl1rYWSnZzMs9ezBc8A+9UPXbBBCxBwtOqWpceLjum1kmFJ8moeT EesNNdg+FI/kGoGBI8kh3y8GfjP0krReaUnYMSwsvT84RgtS1PvdWlPBo6f/0nBTrVUK KaaNaOq/Wd7QN6AMOgw8CP5wz+W38OgpYvD8lBOV6FIA2InPUwWL/BT7Kqu3aZFidb+P +0xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="gjJ5zVg/"; 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 h11si19219736pgq.529.2019.04.05.17.53.22; Fri, 05 Apr 2019 17:53:38 -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="gjJ5zVg/"; 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 S1726467AbfDFAt2 (ORCPT + 99 others); Fri, 5 Apr 2019 20:49:28 -0400 Received: from mail-vk1-f194.google.com ([209.85.221.194]:44745 "EHLO mail-vk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726316AbfDFAt2 (ORCPT ); Fri, 5 Apr 2019 20:49:28 -0400 Received: by mail-vk1-f194.google.com with SMTP id q189so1838156vkq.11 for ; Fri, 05 Apr 2019 17:49:27 -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=Hml97b0NmWYMZJBuaShZ+PWX2gT4x6nYAZjr3fyQFIQ=; b=gjJ5zVg/l2BWPd2W+Xtyt96po8PpdCFUXwXRGnx18P2di66dvkkcG12/yFXy4xEka8 6C7R+jfG9PtMby+86vrV27iqQg4D881Hic5o/gZPDAIChqElZkvFCow04y+WQCRjNx9H FBK1tvx4bkzltFOOYt2TVBHs2hJXEv/CJAbaDCxiTEzBwp55pHyTqTxnbcJCvMDZkYlS X0z6u2SZH+oT3aT1Ffwef3OeR64im9CLzuErzfsR9f6TdCnZX17ILtWhgVHJGs34Zs8E aOiVC8Pa6UD/nydvd7wZmXo5FFc05uezRJP8JZ9uQbMtfJDELekQP5+qkzjmoUylOKIo pX+g== 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=Hml97b0NmWYMZJBuaShZ+PWX2gT4x6nYAZjr3fyQFIQ=; b=S01zgj1jT33SWM4jQG7Fmi6t+8Om1MWypqMY/njpeXuLlx9DxzUHRgUT/vbamW27UW 82ioeWlLn7n6EpeKZ4BIxypkOk9iDmu9gWNHrpupuYwiZgn3CdMC/Wa0QH+kjfmYi7tX vJ/Po0zJqpXpum2WGHEyN3pEBf/dcNrtYsaAV4H+RomrYXIIB8yCZV3Vs6QxfuYBPiiM MoM7z5iajVLoanpab3Gjd+pgtWIpOc26ZgOzDYjN42IgvdJUOTePKqx3byQtWQBZmq5/ 2r8J0oSzDa7Qpae2NWESJC9/7f0R4IoV05rlaE0UIdCcq5zDnKVznPevIs5LNoHsdsNG KXrA== X-Gm-Message-State: APjAAAUbqGCa2ZZUSZ28XKeEDcsRJR9OmkR1psOXcmE++Fyeq0rPes4f tlRVs7oD3DKGGApGEHXQKEkTY65eYmMHjWUKbcgF4Q== X-Received: by 2002:a1f:9d87:: with SMTP id g129mr9864147vke.56.1554511766979; Fri, 05 Apr 2019 17:49:26 -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> <20190405202620.GG4038@hirez.programming.kicks-ass.net> In-Reply-To: <20190405202620.GG4038@hirez.programming.kicks-ass.net> From: Stephane Eranian Date: Fri, 5 Apr 2019 17:49:15 -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 1:26 PM Peter Zijlstra wrote: > > 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. True. I will post V2 shortly.