Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2248340ybd; Mon, 24 Jun 2019 03:16:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqyd2YuRXqOrFJO8QGa42MmwdE3ClauxYwu+UpVWgEZBNmXli4BhUrRX6i3hZ5GkWKR/GtfM X-Received: by 2002:a17:90a:5884:: with SMTP id j4mr24910568pji.142.1561371372587; Mon, 24 Jun 2019 03:16:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561371372; cv=none; d=google.com; s=arc-20160816; b=jYviOE4GdlpPgqA4dWnRYgU2TltBHZlqNCEGriYnpeGDYJCMI3pK17RZWwU87brUiX iA/SLD3w/BWyR3JkmMzIQOY4Whibrivg2L2fin8o8GHVGpxVhvqNdv0SrNNepvH1f9ud HhSYkoZRvbQ9PuH00vokMpurQPr6s4O7Y0/8tZf0zaKM9o8yFCg3TMGB7HEvIGEJ0UPz flVWmy+xP7D9Bw5U0EbR61OAxmN+TBFAC+6g/GaVGppmqGdWSAQGaLVgpatt670BibCI kazHbKQXpnlEHen0+bgOozFaHgHR12qOuqm16/9lqnG/MJq3mgDKsTMg4DNt4st2NokI psnQ== 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=/FQto8axC70qE3ddCgMeqGn9hlpCForuzJjWwOHWK5s=; b=egf1gRiHZqsUPWWRv54X29oegpV018lALXo2FXMzELkc+kQ/+RkDfLajh4LfaaraN0 tAkOB9Bow1OCBR+zaEA7aoBL9P8Y+1ZvQ1ip/PZMjnNmH9sR/q30/DbfGuou6P7LkWXC y0pPMA6vukUOurI3w9HzIr4NKHk4miTr1kEtw2vTrT5h8QG6Kbp9K7z45i2Wh7MvM3gJ 09eaHbppD/L4C//qTxUzlWfF8N9ZUsF566kHo12IifiFqHw1iw/5f8/wlWpP2U7FW9Og XI5shOP7j+nUO0EIHlZEKQxakPyjQt8cHU79KSZpzB6wztJ63YkWEeRxEsctHB2LEkgj SiEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="K/QllV4T"; 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 u6si10583170pjv.29.2019.06.24.03.15.56; Mon, 24 Jun 2019 03:16:12 -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="K/QllV4T"; 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 S1730174AbfFXKPq (ORCPT + 99 others); Mon, 24 Jun 2019 06:15:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:53044 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729706AbfFXKPm (ORCPT ); Mon, 24 Jun 2019 06:15:42 -0400 Received: from localhost (f4.8f.5177.ip4.static.sl-reverse.com [119.81.143.244]) (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 6456A2089F; Mon, 24 Jun 2019 10:15:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561371341; bh=6OdPh8UvNgFw9kAu6ULVURDzR2ajJLVxWU0NRDBdpe0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K/QllV4T15nfPeq9EY5tYSi16iLAylaiJY1d6mSaDTaD+9wIYSQUEddMbVVqEdkGY zRabsYg1U52ipTsaCbZazBtfQHYCdOtsabNh2V+Ljj7GjW0XvkW+Fu/tTG4YvSpKp8 PyfVTBSkKbYFAuP/wXTHk8oVgkU4HyTzHHPsovXA= 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 5.1 066/121] sparc: perf: fix updated event period in response to PERF_EVENT_IOC_PERIOD Date: Mon, 24 Jun 2019 17:56:38 +0800 Message-Id: <20190624092324.192490402@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190624092320.652599624@linuxfoundation.org> References: <20190624092320.652599624@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 6de7c684c29f..a58ae9c42803 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