From patchwork Fri Nov 21 16:24:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 41328 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f69.google.com (mail-ee0-f69.google.com [74.125.83.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5583325B55 for ; Fri, 21 Nov 2014 16:24:49 +0000 (UTC) Received: by mail-ee0-f69.google.com with SMTP id d49sf3248544eek.0 for ; Fri, 21 Nov 2014 08:24:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=HbJBoXeDUrRw30HVu6cN7Zn4INc5Oxevti2YrcOL5Jk=; b=nD6xIofiUYKrlE4OmLl8ei2kwisbDmo1//3eemkbUmtpwoGSy7NQgunLi4sNc8TjWj iIfcF69khqB06djCOOXGku4os8eElEfM6fHpa67bNCfsmGmx0l99BemantoDbfMzB+Oy BLacI1fkKpOyJn9wVn5qydjZnh7Ph0EHM1EW7xOMd1h4DI9KRGjJT0mwSZdtdQsNdq10 PSo5f3ZSImhp2IW3VymLP/rOuw/t1UI7PnFVX15wIAHnPYxEPLoEsDVhtATYgtUV9yet 1QSkeQ844T0JmiYRdBkE7o99CbgIJKwXoKlCYL5XUal9bGQIuWSQyMDQmy9TP2RQsSSg zsOA== X-Gm-Message-State: ALoCoQnd1iD4RiiioPME2a67516zoXRpkYPu45ACHbyG91//wHt+5iYu/tJOYbn6eCGOJpeVRMnb X-Received: by 10.181.13.147 with SMTP id ey19mr9715834wid.2.1416587088559; Fri, 21 Nov 2014 08:24:48 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.39 with SMTP id p7ls228506lap.5.gmail; Fri, 21 Nov 2014 08:24:48 -0800 (PST) X-Received: by 10.152.205.11 with SMTP id lc11mr6060857lac.34.1416587088408; Fri, 21 Nov 2014 08:24:48 -0800 (PST) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id tl10si6157466lbb.131.2014.11.21.08.24.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 21 Nov 2014 08:24:47 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by mail-la0-f52.google.com with SMTP id q1so4460911lam.39 for ; Fri, 21 Nov 2014 08:24:47 -0800 (PST) X-Received: by 10.112.138.137 with SMTP id qq9mr5970838lbb.80.1416587087071; Fri, 21 Nov 2014 08:24:47 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp121241lbc; Fri, 21 Nov 2014 08:24:46 -0800 (PST) X-Received: by 10.194.90.112 with SMTP id bv16mr9393329wjb.122.1416587086088; Fri, 21 Nov 2014 08:24:46 -0800 (PST) Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com. [74.125.82.45]) by mx.google.com with ESMTPS id ex8si10283459wjb.33.2014.11.21.08.24.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 21 Nov 2014 08:24:45 -0800 (PST) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 74.125.82.45 as permitted sender) client-ip=74.125.82.45; Received: by mail-wg0-f45.google.com with SMTP id b13so6980134wgh.32 for ; Fri, 21 Nov 2014 08:24:45 -0800 (PST) X-Received: by 10.194.3.2 with SMTP id 2mr9088131wjy.89.1416587084880; Fri, 21 Nov 2014 08:24:44 -0800 (PST) Received: from sundance.lan (cpc4-aztw19-0-0-cust157.18-1.cable.virginm.net. [82.33.25.158]) by mx.google.com with ESMTPSA id g16sm8661348wjq.20.2014.11.21.08.24.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Nov 2014 08:24:44 -0800 (PST) From: Daniel Thompson To: Russell King , Will Deacon , Catalin Marinas Cc: Daniel Thompson , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Peter Zijlstra , Paul Mackerras , Ingo Molnar , Arnaldo Carvalho de Melo , patches@linaro.org, linaro-kernel@lists.linaro.org, John Stultz , Sumit Semwal Subject: [PATCH v2 2/2] arm64: perf: Prevent wraparound during overflow Date: Fri, 21 Nov 2014 16:24:27 +0000 Message-Id: <1416587067-3220-3-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1416587067-3220-1-git-send-email-daniel.thompson@linaro.org> References: <1416412346-8759-1-git-send-email-daniel.thompson@linaro.org> <1416587067-3220-1-git-send-email-daniel.thompson@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: daniel.thompson@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , If the overflow threshold for a counter is set above or near the 0xffffffff boundary then the kernel may lose track of the overflow causing only events that occur *after* the overflow to be recorded. Specifically the problem occurs when the value of the performance counter overtakes its original programmed value due to wrap around. Typical solutions to this problem are either to avoid programming in values likely to be overtaken or to treat the overflow bit as the 33rd bit of the counter. Its somewhat fiddly to refactor the code to correctly handle the 33rd bit during irqsave sections (context switches for example) so instead we take the simpler approach of avoiding values likely to be overtaken. We set the limit to half of max_period because this matches the limit imposed in __hw_perf_event_init(). This causes a doubling of the interrupt rate for large threshold values, however even with a very fast counter ticking at 4GHz the interrupt rate would only be ~1Hz. Signed-off-by: Daniel Thompson --- arch/arm64/kernel/perf_event.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c index aa29ecb4f800..25a5308744b1 100644 --- a/arch/arm64/kernel/perf_event.c +++ b/arch/arm64/kernel/perf_event.c @@ -169,8 +169,14 @@ armpmu_event_set_period(struct perf_event *event, ret = 1; } - if (left > (s64)armpmu->max_period) - left = armpmu->max_period; + /* + * Limit the maximum period to prevent the counter value + * from overtaking the one we are about to program. In + * effect we are reducing max_period to account for + * interrupt latency (and we are being very conservative). + */ + if (left > (armpmu->max_period >> 1)) + left = armpmu->max_period >> 1; local64_set(&hwc->prev_count, (u64)-left);