Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2460180imd; Fri, 2 Nov 2018 11:47:23 -0700 (PDT) X-Google-Smtp-Source: AJdET5c02xdMw0FenGw9g8nEletoavDavVL9Bri9Br6NqbBwq3mfbXc9Ean4J0FzG+lyC4vKmbVH X-Received: by 2002:a17:902:25ab:: with SMTP id y40-v6mr12652445pla.258.1541184443573; Fri, 02 Nov 2018 11:47:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541184443; cv=none; d=google.com; s=arc-20160816; b=J/s4c+aM3/n/ZOUx8hJZhaEojBFF0cSfp6x0siCdSkORcyahrxBySXiezCbKRJvFNx a/tAUhVcTXBpsFJ1xdl+FiE3nyuZqHCYXrP1VxkphqnIX2qgTyLClHVeEuDEJ0/r230X v8X0LVUdWO3w1Ae799t8/vcrXICwZFzH1pBp0u219lyZfn8wS7169ypOmk9RPh6IJDsh XAqsh/sBzgUOkMkEWPwDzIaxHINS2sILyhhXuNaGBkYhNmXE0bEirMNcKs2lLwYjngls UgiYF0QOudqeUBsveXDLshbUnXgbKTc6gDZDgV4pBSDnpDiggmmt5UvaB9byMY/BnWi1 JkIw== 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=wBFciVb1qx85bJVIxbNYjIB259VNpeGt+w+fMXhCmWw=; b=Lm6HU9fZknVgK4FbTktDfyLMKUK55RR+18B3jf8TCJTzHDMQXqXHQk0U4psKBR02ZE YF0t1y40BvYxx5LaO3tDiiGiTgO2sSfY9PBu5M/hkJy/OgN+p4+FpwOGyMexQwW1TReb SwXzdY82XFpa+WFxmzXF12T7DczQigLxKq6+NgjNgebQoBwtDDJC8BRr2WKZ5hCV9nBu eGmiTDfl+TEsKaHliZyh/v5uI/x8t8nXZ0+GAxLtg8xUPjTUixknv7vWtGD0L7MTOitD v37clYjyeVl5pTE5my3EGX6vY2ib6hMQd9kHW/TCAJMz50hjX5GQLqko1pQUfIxg6DtZ TybA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=F78USvTb; 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 x3-v6si36164956pfb.122.2018.11.02.11.47.09; Fri, 02 Nov 2018 11:47:23 -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=@kernel.org header.s=default header.b=F78USvTb; 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 S1730340AbeKCDy1 (ORCPT + 99 others); Fri, 2 Nov 2018 23:54:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:50364 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729136AbeKCDy0 (ORCPT ); Fri, 2 Nov 2018 23:54:26 -0400 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 4E52820837; Fri, 2 Nov 2018 18:46:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541184372; bh=GvBHhN3x8/oJOl7rLoRgnhtyLju4x2bkvFV5DxRejGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F78USvTbk613ze4Rc05C1GfZPV8s4pmGrRjizYDNh8Fku5+ayqsLJfNij10qz8oxq eW0VJz/q4S6xuPclqaXInq70VE3tCo98ofNBoSUbSdk1Pf6s/ki9mz1YlIodtek/mn xgW4GGYrc4HL1+nlCO5fI3SCJjD2Mzc+0DT7iJF0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "David S. Miller" Subject: [PATCH 4.18 147/150] sparc: Fix single-pcr perf event counter management. Date: Fri, 2 Nov 2018 19:35:09 +0100 Message-Id: <20181102182912.632649499@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181102182902.250560510@linuxfoundation.org> References: <20181102182902.250560510@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.18-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: 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,