From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755838AbcC2Bdm (ORCPT ); Mon, 28 Mar 2016 21:33:42 -0400 Received: from mail-pf0-f175.google.com ([209.85.192.175]:33400 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755755AbcC2Bdj (ORCPT ); Mon, 28 Mar 2016 21:33:39 -0400 From: Stephane Eranian To: linux-kernel@vger.kernel.org Cc: acme@redhat.com, peterz@infradead.org, mingo@elte.hu, ak@linux.intel.com, kan.liang@intel.com, jolsa@redhat.com, namhyung@kernel.org, vincent.weaver@maine.edu Subject: [PATCH] perf/core: Fix time tracking bug with multiplexing Date: Tue, 29 Mar 2016 03:33:23 +0200 Message-Id: <1459215203-12885-1-git-send-email-eranian@google.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch fixes a bug introduced by: commit 3cbaa59069677920186dcf502632ca1df4329f80 Author: Peter Zijlstra Date: Wed Feb 24 18:45:47 2016 +0100 perf: Fix ctx time tracking by introducing EVENT_TIME This patch introduce a bug in the time tracking of events when multiplexing is used. The issue is easily reproducible with the following perf run: $ perf stat -a -C 0 -e branches,branches,branches,branches,branches -I 1000 1.000730239 652,394 branches (66.41%) 1.000730239 597,809 branches (66.41%) 1.000730239 593,870 branches (66.63%) 1.000730239 651,440 branches (67.03%) 1.000730239 656,725 branches (66.96%) 1.000730239 branches One branches event is shown as not having run. Yet, with multiplexing, all events should run especially with a 1s (-I 1000) interval. The delta for time_running comes out to 0. Yet, the event has run because the kernel is actually multiplexing the events. The problem is that the time tracking is the kernel and especially in ctx_sched_out() is wrong now. The problem is that in case that the kernel enters ctx_sched_out() with the following state: ctx->is_active=0x7 event_type=0x1 Call Trace: [] dump_stack+0x63/0x82 [] ctx_sched_out+0x2bc/0x2d0 [] perf_mux_hrtimer_handler+0xf6/0x2c0 [] ? __perf_install_in_context+0x130/0x130 [] __hrtimer_run_queues+0xf8/0x2f0 [] hrtimer_interrupt+0xb7/0x1d0 [] local_apic_timer_interrupt+0x38/0x60 [] smp_apic_timer_interrupt+0x3d/0x50 [] apic_timer_interrupt+0x8c/0xa0 In that case, the test: if (is_active & EVENT_TIME) will be false and the time will not be updated. Time must always be updated on sched out. This patch fixes the problem. Patch is relative to PeterZ queue.tip perf/core branch. Signed-off-by: Stephane Eranian --- kernel/events/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 339aa46..4ba41f6 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -2447,7 +2447,7 @@ static void ctx_sched_out(struct perf_event_context *ctx, is_active ^= ctx->is_active; /* changed bits */ - if (is_active & EVENT_TIME) { + if (ctx->is_active & EVENT_TIME) { /* update (and stop) ctx time */ update_context_time(ctx); update_cgrp_time_from_cpuctx(cpuctx); -- 2.5.0