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.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 EC2C9C606C2 for ; Mon, 8 Jul 2019 15:15:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BC10121734 for ; Mon, 8 Jul 2019 15:15:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562598913; bh=GsJ/jriVqesY5hG7ydJ9EDvUFwT2ScZGlDjXsi/bvE8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=rCQs5Y6oew0vRZ8NP7LVG5yUk0MoJUiMF2GO7dAE39gJNhut+ATkIbexv44DPAwCF YKWFpHTI/Vrd32/mf6gJ+eBMKrW9FYIpzYGgrmtzpRr5AX1QPw5Ye8c7jAsXVlfWvW ICerSvYmvTwUoEEcG3zBPKqlZTGlbNP5fMENqHok= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732282AbfGHPPM (ORCPT ); Mon, 8 Jul 2019 11:15:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:37512 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732260AbfGHPPJ (ORCPT ); Mon, 8 Jul 2019 11:15:09 -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 A83C2216F4; Mon, 8 Jul 2019 15:15:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562598909; bh=GsJ/jriVqesY5hG7ydJ9EDvUFwT2ScZGlDjXsi/bvE8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V+VhtcOqICltuO5XkI4CHTEE0v/9TTKK+h2YN6cepGK68797scktB9nnkRe4sr4Xp Wzb+6Ih/YRelv2upsjehlNIu9A3IDawmZIvbDsAELReOXw+ErHRhrbdFBmhj6eanUd gEDhtVxsS076AiRu9mitt2taPie4jvweNFA3edaU= 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.4 14/73] sparc: perf: fix updated event period in response to PERF_EVENT_IOC_PERIOD Date: Mon, 8 Jul 2019 17:12:24 +0200 Message-Id: <20190708150520.003246074@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708150513.136580595@linuxfoundation.org> References: <20190708150513.136580595@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 a5d0c2f08110..815352d501f0 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