Received: by 10.213.65.68 with SMTP id h4csp839360imn; Tue, 27 Mar 2018 09:44:02 -0700 (PDT) X-Google-Smtp-Source: AIpwx480q1QboJi+Wat1XYLXCxQj9cWXnpAAOCzWvkKS+cMAqxZCMY2JF5b2COTQrgs0xfr81wTM X-Received: by 2002:a17:902:51ee:: with SMTP id y101-v6mr36248plh.359.1522169042147; Tue, 27 Mar 2018 09:44:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522169042; cv=none; d=google.com; s=arc-20160816; b=CPAYY9MawRahXHg5xia/qUlPS7wZy4wDY79FlAEvEZBTjaykOE/85/Pdg5vYV7KvLI FAz3bXcSirm2Q7HgM/j8OX6fJYFqYzFCLyB7TFoAStvfLaXLuqrxK1ki/Z0wXl/fMODy yrYqoVHwT2XHTrEpNaq/45i5OHwB+W0gMqkSAkxPtI5w2I+jNDgzpEi28xdYWG5D+p1i EqGJ+FAKelA7AJmk5slvy6DJzxBQq5mKDrN+hKAnjFjBSozxMhscrGWjcF59Vl4fvaEx J0mgxAalas0EHj9ejaJnukPHHB89pupGt7Yr/p2O8qiMag0L+HV1yWC43X52jMaIzSSn JYNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=XYgW/ngCyQQAzzYT3siWyaXePmgNNeUeAyAKmKLDs2E=; b=mnXRsji5oFaYTLKC9HKQg8/pwyDvdfHxAOcp+p7KaC+eyDH+47kWqM68Wvs/4+Mmeh GUP5acKMGimRnM8e9mUvQIlU6orwXE+0CHBSqtI0TaMI2gUYi/S/YVAMm8hLnl2gmRBl I1cIPv6q5FChOyQZ4mYxPGiAFFY9ItQa9rgX+bNKnUTOSnsa/nFZ0AufVND2Jap/NIaG pOkGU3v7764RiOrphh1W75Rfzh1t0J/R+lMsIqeqnS7dWZa9V15MxBcEjrcP8MMWaLcO APtu4efGCV7OlFuKOIRZrf1v7E11i5V65YH/wBVQZi1IaxKgrpszLXICw60oc7wARF7j 5wZQ== ARC-Authentication-Results: i=1; mx.google.com; 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 t190si1102393pgd.101.2018.03.27.09.43.47; Tue, 27 Mar 2018 09:44:02 -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; 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 S932840AbeC0Qmv (ORCPT + 99 others); Tue, 27 Mar 2018 12:42:51 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:49270 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932819AbeC0Qms (ORCPT ); Tue, 27 Mar 2018 12:42:48 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A225B10B5; Tue, 27 Mar 2018 16:42:47 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ephraim Park , Song Liu , "Peter Zijlstra (Intel)" , jolsa@redhat.com, kernel-team@fb.com, Alexander Shishkin , Arnaldo Carvalho de Melo , Linus Torvalds , Stephane Eranian , Thomas Gleixner , Vince Weaver , Ingo Molnar Subject: [PATCH 4.15 095/105] perf/core: Fix ctx_event_type in ctx_resched() Date: Tue, 27 Mar 2018 18:28:15 +0200 Message-Id: <20180327162803.870967820@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180327162757.813009222@linuxfoundation.org> References: <20180327162757.813009222@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 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 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Song Liu commit bd903afeb504db5655a45bb4cf86f38be5b1bf62 upstream. In ctx_resched(), EVENT_FLEXIBLE should be sched_out when EVENT_PINNED is added. However, ctx_resched() calculates ctx_event_type before checking this condition. As a result, pinned events will NOT get higher priority than flexible events. The following shows this issue on an Intel CPU (where ref-cycles can only use one hardware counter). 1. First start: perf stat -C 0 -e ref-cycles -I 1000 2. Then, in the second console, run: perf stat -C 0 -e ref-cycles:D -I 1000 The second perf uses pinned events, which is expected to have higher priority. However, because it failed in ctx_resched(). It is never run. This patch fixes this by calculating ctx_event_type after re-evaluating event_type. Reported-by: Ephraim Park Signed-off-by: Song Liu Signed-off-by: Peter Zijlstra (Intel) Cc: Cc: Cc: Alexander Shishkin Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Linus Torvalds Cc: Stephane Eranian Cc: Thomas Gleixner Cc: Vince Weaver Fixes: 487f05e18aa4 ("perf/core: Optimize event rescheduling on active contexts") Link: http://lkml.kernel.org/r/20180306055504.3283731-1-songliubraving@fb.com Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- kernel/events/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -2246,7 +2246,7 @@ static void ctx_resched(struct perf_cpu_ struct perf_event_context *task_ctx, enum event_type_t event_type) { - enum event_type_t ctx_event_type = event_type & EVENT_ALL; + enum event_type_t ctx_event_type; bool cpu_event = !!(event_type & EVENT_CPU); /* @@ -2256,6 +2256,8 @@ static void ctx_resched(struct perf_cpu_ if (event_type & EVENT_PINNED) event_type |= EVENT_FLEXIBLE; + ctx_event_type = event_type & EVENT_ALL; + perf_pmu_disable(cpuctx->ctx.pmu); if (task_ctx) task_ctx_sched_out(cpuctx, task_ctx, event_type);