From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753489AbbKYMef (ORCPT ); Wed, 25 Nov 2015 07:34:35 -0500 Received: from mail-wm0-f50.google.com ([74.125.82.50]:37240 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752453AbbKYMed (ORCPT ); Wed, 25 Nov 2015 07:34:33 -0500 Date: Wed, 25 Nov 2015 13:34:30 +0100 From: Frederic Weisbecker To: Chris Metcalf Cc: LKML , Peter Zijlstra , Thomas Gleixner , Luiz Capitulino , Christoph Lameter , Ingo Molnar , Viresh Kumar , Rik van Riel Subject: Re: [PATCH 3/7] perf: Migrate perf to use new tick dependency mask model Message-ID: <20151125123428.GD16609@lerouge> References: <1447424529-13671-1-git-send-email-fweisbec@gmail.com> <1447424529-13671-4-git-send-email-fweisbec@gmail.com> <56548E15.5050004@ezchip.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <56548E15.5050004@ezchip.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 24, 2015 at 11:19:33AM -0500, Chris Metcalf wrote: > On 11/13/2015 09:22 AM, Frederic Weisbecker wrote: > >Instead of providing asynchronous checks for the nohz subsystem to verify > >perf event tick dependency, migrate perf to the new mask. > > > >Perf needs the tick for two situations: > > > >1) Freq events. We could set the tick dependency when those are > >installed on a CPU context. But setting a global dependency on top of > >the global freq events accounting is much easier. If people want that > >to be optimized, we can still refine that on the per-CPU tick dependency > >level. This patch dooesn't change the current behaviour anyway. > > > >2) Throttled events: this is a per-cpu dependency. > > > > > >@@ -3540,8 +3530,10 @@ static void unaccount_event(struct perf_event *event) > > atomic_dec(&nr_comm_events); > > if (event->attr.task) > > atomic_dec(&nr_task_events); > >- if (event->attr.freq) > >- atomic_dec(&nr_freq_events); > >+ if (event->attr.freq) { > >+ if (atomic_dec_and_test(&nr_freq_events)) > >+ tick_nohz_clear_dep(TICK_PERF_EVENTS_BIT); > >+ } > > if (event->attr.context_switch) { > > static_key_slow_dec_deferred(&perf_sched_events); > > atomic_dec(&nr_switch_events); > > > >@@ -7695,7 +7687,7 @@ static void account_event(struct perf_event *event) > > atomic_inc(&nr_task_events); > > if (event->attr.freq) { > > if (atomic_inc_return(&nr_freq_events) == 1) > >- tick_nohz_full_kick_all(); > >+ tick_nohz_set_dep(TICK_PERF_EVENTS_BIT); > > } > > if (event->attr.context_switch) { > > atomic_inc(&nr_switch_events); > > It would be helpful to have a comment explaining why these two > can't race with each other, e.g. this race: > > [cpu 1] atomic_dec_and_test > [cpu 2] atomic_inc_return > [cpu 2] tick_nohz_set_dep() > [cpu 1] tick_nohz_clear_dep() > > Or perhaps this is a true race condition possibility? > > I think we're OK for the sched cases since they're protected under > the rq lock, I think. I'm not sure about the POSIX cpu timers. Hmm, how did I miss that... So in the case of perf, either we need locking, in which case we may want to use something like tick_nohz_add_dep() which takes care of counting. But perf would be the only user. Another possibility is to rather set/clear the tick mask on the task level in event_sched_in/event_sched_out using ctx->nr_freq which is protected by ctx->lock. I think I should rather do that. Concerning the others: _ sched: we are under the rq lock, like you noticed, we are fine. _ posix timers: we are under sighand lock, so we are fine too. _ sched_clock_stable: that one is more obscure. It seems that set_sched_clock_stable() and clear_sched_clock_stable() can race on static keys if running concurrently, and that would concern tick mask as well. Thanks. > > -- > Chris Metcalf, EZChip Semiconductor > http://www.ezchip.com >