Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7147172ybi; Mon, 8 Jul 2019 15:35:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqzC+1DUxloTfvFo6t3I1tGvJroCF+iiZhQqOA5WZ9Pw4NmOnEFIMx6+2fenN2Dk5LHRpFf3 X-Received: by 2002:a17:90a:9bca:: with SMTP id b10mr28599838pjw.90.1562625315965; Mon, 08 Jul 2019 15:35:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562625315; cv=none; d=google.com; s=arc-20160816; b=Gxt+8rX+EAOSGjsM7eCSDhuRXku8nz9ooGsJzbUaRZpGNOIJv4Rc7O92pho0/aLOLI duSZDoFffgPW+lxkLoGk5VFi9iCcNz+2j7Mvq2skQ/yJHx5/VKtNvLYYfIeHGeZbLn1I Kc3WGXO68z6AFDRWlAKVmOkjjFIfBwJx7S+/MzFHmVwuV6/Npq0mE/xJPFmvzfw/khEm dhDSKdRVbiYTkdd4JrUHZwdzar03t0i7KxneDORtiS7kxZhQjqhP/bWCmUuH8lQ+r+v/ 2mPV4vyLFB6pWhB8ELucUD84uf2lZt+pAsWKX/S2w+WCsLD48ADWABNYoDKgsTQSS001 YEuA== 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=9wbuYxnoQHC5TaOZP2kT0wfh+CNOqLUBewRz73yYIyQ=; b=CzzlC/W/v4R7Bs0ckOZcd1sOCdTMIJtR2869tsFcYpSlGQyY3NYub23m1SnjrfjP87 wnNNrh4HGYvxokLhCqIqe32zSZ4xVELKviuHHl7+0s9Pc2q/FrXor+8EfXFOZTT/1a1a 5b9h8ap+4pas+MjSZV8ZYue1kqyPspZVGo01mVDey2uRWw8jAErfdYylGgckGoTI1gGy HeqxdM6N9jK17sxRgCxxg8G/5xaPUp45WyT8W6pIl/pyR34uPQ/Z+bz7l8WiTxYZD7aI EqbLV7VLe4NrdQoSkyZpxorkN34Xbut1sJJ0NoeT7IAHVpWJlmv9qAXms7lPBL2fV5wj zx+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YUGgrLwl; 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 g12si19945665pla.363.2019.07.08.15.35.01; Mon, 08 Jul 2019 15:35:15 -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=YUGgrLwl; 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 S1733136AbfGHPS6 (ORCPT + 99 others); Mon, 8 Jul 2019 11:18:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:42914 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730690AbfGHPSy (ORCPT ); Mon, 8 Jul 2019 11:18:54 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 692B8216FD; Mon, 8 Jul 2019 15:18:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562599133; bh=8WFReox3sk8YgaXFZ4lhamtoghRFzlHCt7+B7fMxcok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YUGgrLwl34BTu+poR7OzP/rVrBHzozUNZ5/4d5yZr/OEubDJf2cCQJRupTs6MjFGl nKqutudNpYAlYpjQCbKWFYDWnt7fH9/mWC4W8xtFhP+/Agb1QQlhEvMnwq132q6ASE D0/vod8qqWnbMFkBtEImukI7BT1r/ayCjyHhTbis= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Young Xiao <92siuyang@gmail.com>, "David S. Miller" , Sasha Levin Subject: [PATCH 4.9 017/102] sparc: perf: fix updated event period in response to PERF_EVENT_IOC_PERIOD Date: Mon, 8 Jul 2019 17:12:10 +0200 Message-Id: <20190708150527.052385847@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708150525.973820964@linuxfoundation.org> References: <20190708150525.973820964@linuxfoundation.org> User-Agent: quilt/0.66 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 [ Upstream commit 56cd0aefa475079e9613085b14a0f05037518fed ] The PERF_EVENT_IOC_PERIOD ioctl command can be used to change the sample period of a running perf_event. Consequently, when calculating the next event period, the new period will only be considered after the previous one has overflowed. This patch changes the calculation of the remaining event ticks so that they are offset if the period has changed. See commit 3581fe0ef37c ("ARM: 7556/1: perf: fix updated event period in response to PERF_EVENT_IOC_PERIOD") for details. Signed-off-by: Young Xiao <92siuyang@gmail.com> Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- arch/sparc/kernel/perf_event.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/sparc/kernel/perf_event.c b/arch/sparc/kernel/perf_event.c index 71e7f77f6776..84a80cd004eb 100644 --- a/arch/sparc/kernel/perf_event.c +++ b/arch/sparc/kernel/perf_event.c @@ -889,6 +889,10 @@ static int sparc_perf_event_set_period(struct perf_event *event, s64 period = hwc->sample_period; int ret = 0; + /* The period may have been changed by PERF_EVENT_IOC_PERIOD */ + if (unlikely(period != hwc->last_period)) + left = period - (hwc->last_period - left); + if (unlikely(left <= -period)) { left = period; local64_set(&hwc->period_left, left); -- 2.20.1