From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 351ABC31E4B for ; Fri, 14 Jun 2019 20:34:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F1AD9217F9 for ; Fri, 14 Jun 2019 20:34:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560544495; bh=/edHFZvVZoybWG8IEgaHCnxRgLMyf1pUbhW3uxJpgOE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=MUmWxh27b1ZqQ3UJJfYaJe+cl/dhsuH2UhzIIHp5zjs65atpbCO10TF7tKmnBg/oI /cGlcjMhWFE1+0OHb6LtYj/k46YMOxCS1NxW9HKlwktFJ46WZluGBs1sXgkYh0BJv5 eaFKlpHxIlE9RGoVWigs3Tl3o9CAftPEijpjbBz4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728120AbfFNUex (ORCPT ); Fri, 14 Jun 2019 16:34:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:53042 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727405AbfFNUaP (ORCPT ); Fri, 14 Jun 2019 16:30:15 -0400 Received: from sasha-vm.mshome.net (unknown [131.107.159.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1488421871; Fri, 14 Jun 2019 20:30:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560544215; bh=/edHFZvVZoybWG8IEgaHCnxRgLMyf1pUbhW3uxJpgOE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XQ8qppp/CE5WcUBAiXo3W7ETk8YYzAnL8cYUWV4vLRfuZEOUvzD39hZYUoY0/FTeZ Z3UGiPA1TDW8ERe5BQaxQ6b1WsanrRsXBK42TlzN905C+eCVFiTYSw295w1przL5rF WmnWWxudQ5eutIVhUGIgI5xTBboRgLJ8livp+HkM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Young Xiao <92siuyang@gmail.com>, "David S . Miller" , Sasha Levin , sparclinux@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 24/39] sparc: perf: fix updated event period in response to PERF_EVENT_IOC_PERIOD Date: Fri, 14 Jun 2019 16:29:29 -0400 Message-Id: <20190614202946.27385-24-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190614202946.27385-1-sashal@kernel.org> References: <20190614202946.27385-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Young Xiao <92siuyang@gmail.com> [ 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 67b3e6b3ce5d..1ad5911f62b4 100644 --- a/arch/sparc/kernel/perf_event.c +++ b/arch/sparc/kernel/perf_event.c @@ -891,6 +891,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