Received: by 10.213.65.68 with SMTP id h4csp876025imn; Tue, 27 Mar 2018 10:23:36 -0700 (PDT) X-Google-Smtp-Source: AIpwx48hhHJBfWNy7vCTbaO17TUonNcE37dSx4oSgMbeZXDBrTz6Cj5ct1C+u9e1xRZYsLoMIT7f X-Received: by 10.99.111.3 with SMTP id k3mr124430pgc.135.1522171416688; Tue, 27 Mar 2018 10:23:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522171416; cv=none; d=google.com; s=arc-20160816; b=qfD8TJMmf21wVOnr382jOVqahIXiogrHMRFWNE4YXCfPyUdaMjofhx5KtazSteTeJU qpRU97bdxuwor4AJfSvHPdo3uycCXszUIkinlamSs7XQLYTyMDiXtL7IqDsRgrMUkdqO 2DG4SyJrGH7Pk/bh2X5ymsHr6QGT7ThfgYb0uUPZ2L2U25lGoebBKRxiO+Az7FZVEAi2 uw16c8Wh+IKAsgK5hjZzR2d1ubHJ0t9dYW0PXvzD2CG4s2O+fXlE4UNnsEwua3JRN5eO 4il/8VoOttMfhkLf6EA6u0eWlc8oKl94g2JGSVsoLrubjtVibLUUpzCqy178KkdCcCaQ LWCQ== 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=ZYMw6Y3KWPa4DMofcKPawXHP5szninevGMzJ0XpE0tU=; b=f+rjdNnMzU7a+TfXKOkmifz/ruSBg2ZSERjh1oILblR2qouRKdRMznkS6+bG+UA++4 tg5kUfIsFGEowzJSI2VPQe+RPWtr5L3jBd6Xw3UAGU1e6OPJ0nlh5sxAuocLAUCkEqZB g01vkvGyKB6nZT1Cb8GVLDo0fPzjHDUArjvfQ4WjebxZBEXtvlYHYRCanDGX1+JalJMG XX2BCYK/gvIyvhpMj/Tr/FkJWa/QJP15clEwfrtZCLptgG856iSVD9/v6NN5MVucJ7Xw ZsSqwqOUrdvtcio0sKknqX12grPKILo2rU4gaXTGguSLGOB9qNyavTtYlpRgIloSI++J QJgQ== 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 x9-v6si1711050plo.41.2018.03.27.10.23.21; Tue, 27 Mar 2018 10:23:36 -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 S1755092AbeC0RVn (ORCPT + 99 others); Tue, 27 Mar 2018 13:21:43 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46450 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755030AbeC0Qhs (ORCPT ); Tue, 27 Mar 2018 12:37: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 EC096FE4; Tue, 27 Mar 2018 16:37: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.14 089/101] perf/core: Fix ctx_event_type in ctx_resched() Date: Tue, 27 Mar 2018 18:28:01 +0200 Message-Id: <20180327162755.502643123@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180327162749.993880276@linuxfoundation.org> References: <20180327162749.993880276@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.14-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 @@ -2322,7 +2322,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); /* @@ -2332,6 +2332,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);