Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3437935imu; Sun, 11 Nov 2018 15:05:42 -0800 (PST) X-Google-Smtp-Source: AJdET5dBEu+1t6cuh8WeXrNK1A9eElX3HJw17iJq6VXuzcbntLKHi0d5R740yAc+tBa7KsS/tUxn X-Received: by 2002:a63:d547:: with SMTP id v7mr15148987pgi.339.1541977542588; Sun, 11 Nov 2018 15:05:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541977542; cv=none; d=google.com; s=arc-20160816; b=u4xfuuaI0wGIrvEK+7O2g5MBA6Od3V+X6IzecCq4INQPR6pvdaHlOv/RC8S1SjTAtF 1LhTbvmwAAnOwMR7sYu48Epn6nMrbGZCBr3dK9ZhOvdDdUW426pFf9udT1w4uxq2hW60 8bcuGojc1xQKnrrBvkGo2A347AQYUG57xFFAHzVT8yty8KiNitM0NHJ3duC2iPOz8Ykv dJI5PcyWEwgZCa2L5AoG62/pKs6TxuGKfv5yTwzHojUq8uOKJBYkjpK9ZHnHxm8sXPv0 Yu5IsAeaJMJVyVMBPaNNM/UX6ys7ajTpQOLJGpNDCkdM3K0Wb7lJAUR2a+QfQbUx1gaA DpdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9wNjveMxut0HroQ5yfNmjTzLSFMEup21VYUNspjMNhw=; b=HDayKawrzj357PV0XJHc/4NEoYxTtBZWocqfZbCtXUqprQc4cXF+9+1pxol7TW1SmX qwtnMbhw59hTQDwA+puMxC9RwWwHJrkROTm7bqE9P+x8lBVYHkpyradCmZJUwkmEQ+jD oio9SeomMVjyvxSvsuJTROA8w/MoIn6OkYFgxk8gi/eAi6MvHjBK2AcfLrtgVrE/x6W3 woby6FiG9GOCsCNX5mceqAe+CIjBq7Ov3xLHwsgZCHUjQ0jat+rAO/woJIiMiA5/TUCa bX9dV3PSztTxf+dz1L1LQQ5H9hwwSptqvqHB58gUEMEoI4lJ8DHPWcQwk3+SX1ECpfqM pBjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oKJwbvoh; 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 v14-v6si15120371pgt.78.2018.11.11.15.05.26; Sun, 11 Nov 2018 15:05:42 -0800 (PST) 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=@kernel.org header.s=default header.b=oKJwbvoh; 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 S2387727AbeKLIzP (ORCPT + 99 others); Mon, 12 Nov 2018 03:55:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:51836 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390455AbeKLIWR (ORCPT ); Mon, 12 Nov 2018 03:22:17 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A20E5224B3; Sun, 11 Nov 2018 22:32:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975540; bh=lE4HLpUbhkLMj/0G9CoX5TSre2PwysbyNVVjOthiDww=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oKJwbvohZjlWYoE1gLLTpdUGERSNsn5bUbrx53GziXXgYbrt5a+HkYTMYaym3Y5Di tzcOkDgZVEUExU+Pwef6mZWjJ08ipiqGuEhW7ZQQnKlsk6U2Y/+y26C/XF1OzB1O8d e3C+3LBxOs8IggHe+Ru5vuLPqFpgBLWsq8C6zLhQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "David S. Miller" , Sasha Levin Subject: [PATCH 4.14 029/222] sparc: Fix single-pcr perf event counter management. Date: Sun, 11 Nov 2018 14:22:06 -0800 Message-Id: <20181111221650.861800715@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: "David S. Miller" [ Upstream commit cfdc3170d214046b9509183fe9b9544dc644d40b ] It is important to clear the hw->state value for non-stopped events when they are added into the PMU. Otherwise when the event is scheduled out, we won't read the counter because HES_UPTODATE is still set. This breaks 'perf stat' and similar use cases, causing all the events to show zero. This worked for multi-pcr because we make explicit sparc_pmu_start() calls in calculate_multiple_pcrs(). calculate_single_pcr() doesn't do this because the idea there is to accumulate all of the counter settings into the single pcr value. So we have to add explicit hw->state handling there. Like x86, we use the PERF_HES_ARCH bit to track truly stopped events so that we don't accidently start them on a reload. Related to all of this, sparc_pmu_start() is missing a userpage update so add it. Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/sparc/kernel/perf_event.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) --- a/arch/sparc/kernel/perf_event.c +++ b/arch/sparc/kernel/perf_event.c @@ -927,6 +927,8 @@ static void read_in_all_counters(struct sparc_perf_event_update(cp, &cp->hw, cpuc->current_idx[i]); cpuc->current_idx[i] = PIC_NO_INDEX; + if (cp->hw.state & PERF_HES_STOPPED) + cp->hw.state |= PERF_HES_ARCH; } } } @@ -959,10 +961,12 @@ static void calculate_single_pcr(struct enc = perf_event_get_enc(cpuc->events[i]); cpuc->pcr[0] &= ~mask_for_index(idx); - if (hwc->state & PERF_HES_STOPPED) + if (hwc->state & PERF_HES_ARCH) { cpuc->pcr[0] |= nop_for_index(idx); - else + } else { cpuc->pcr[0] |= event_encoding(enc, idx); + hwc->state = 0; + } } out: cpuc->pcr[0] |= cpuc->event[0]->hw.config_base; @@ -988,6 +992,9 @@ static void calculate_multiple_pcrs(stru cpuc->current_idx[i] = idx; + if (cp->hw.state & PERF_HES_ARCH) + continue; + sparc_pmu_start(cp, PERF_EF_RELOAD); } out: @@ -1079,6 +1086,8 @@ static void sparc_pmu_start(struct perf_ event->hw.state = 0; sparc_pmu_enable_event(cpuc, &event->hw, idx); + + perf_event_update_userpage(event); } static void sparc_pmu_stop(struct perf_event *event, int flags) @@ -1371,9 +1380,9 @@ static int sparc_pmu_add(struct perf_eve cpuc->events[n0] = event->hw.event_base; cpuc->current_idx[n0] = PIC_NO_INDEX; - event->hw.state = PERF_HES_UPTODATE; + event->hw.state = PERF_HES_UPTODATE | PERF_HES_STOPPED; if (!(ef_flags & PERF_EF_START)) - event->hw.state |= PERF_HES_STOPPED; + event->hw.state |= PERF_HES_ARCH; /* * If group events scheduling transaction was started,