Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752768AbbKQLXV (ORCPT ); Tue, 17 Nov 2015 06:23:21 -0500 Received: from smtprelay.synopsys.com ([198.182.60.111]:37177 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751163AbbKQLXU (ORCPT ); Tue, 17 Nov 2015 06:23:20 -0500 Subject: Re: local64_cmpxchg() in arc_perf_event_update() To: Peter Zijlstra References: <1445286926.3913.13.camel@synopsys.com> <20151117110749.GT3816@twins.programming.kicks-ass.net> CC: Alexey Brodkin , arcml , lkml Newsgroups: gmane.linux.kernel,gmane.linux.kernel.arc From: Vineet Gupta Message-ID: <564B0E18.3040207@synopsys.com> Date: Tue, 17 Nov 2015 16:53:04 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <20151117110749.GT3816@twins.programming.kicks-ass.net> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.12.197.182] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1479 Lines: 39 On Tuesday 17 November 2015 04:37 PM, Peter Zijlstra wrote: > On Tue, Nov 17, 2015 at 09:14:59AM +0000, Vineet Gupta wrote: >> > Let's check with Peter as I'm not sure how exactly the read call will >> > nest for same counter on same core ? > Various possible ways, but the easiest is userspace doing a sys_read() > on the counter while the NMI happens. > > That means Alexey need to revert the hunk ? static void arc_perf_event_update(struct perf_event *event, struct hw_perf_event *hwc, int idx) { - uint64_t prev_raw_count, new_raw_count; - int64_t delta; - - do { - prev_raw_count = local64_read(&hwc->prev_count); - new_raw_count = arc_pmu_read_counter(idx); - } while (local64_cmpxchg(&hwc->prev_count, prev_raw_count, - new_raw_count) != prev_raw_count); - - delta = (new_raw_count - prev_raw_count) & - ((1ULL << arc_pmu->counter_size) - 1ULL); + uint64_t prev_raw_count = local64_read(&hwc->prev_count); + uint64_t new_raw_count = arc_pmu_read_counter(idx); + int64_t delta = new_raw_count - prev_raw_count; + /* + * We don't afaraid of hwc->prev_count changing beneath our feet + * because there's no way for us to re-enter this function anytime. + */ + local64_set(&hwc->prev_count, new_raw_count); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/