From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752660AbcFNNgl (ORCPT ); Tue, 14 Jun 2016 09:36:41 -0400 Received: from mail-wm0-f45.google.com ([74.125.82.45]:37763 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751976AbcFNNgk (ORCPT ); Tue, 14 Jun 2016 09:36:40 -0400 Subject: Re: [PATCH V4] irq: Track the interrupt timings To: Thomas Gleixner References: <1460545556-15085-1-git-send-email-daniel.lezcano@linaro.org> Cc: nicolas.pitre@linaro.org, shreyas@linux.vnet.ibm.com, linux-kernel@vger.kernel.org, peterz@infradead.org, rafael@kernel.org, vincent.guittot@linaro.org From: Daniel Lezcano Message-ID: <57600866.4070601@linaro.org> Date: Tue, 14 Jun 2016 15:36:38 +0200 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/10/2016 04:52 PM, Thomas Gleixner wrote: Hi Thomas, [ ... ] >> + now = local_clock(); >> + prev = timings->timestamp; >> + timings->timestamp = now; >> + >> + /* >> + * If it is the first interrupt of the series, we can't >> + * compute an interval, just store the timestamp and exit. >> + */ >> + if (unlikely(!prev)) >> + return; > > The delta will be large enough that you drop out in the check below. So you > can spare that conditional. Good point. >> + >> + diff = now - prev; >> + >> + /* >> + * microsec (actually 1024th of a milisec) precision is good >> + * enough for our purpose. >> + */ >> + diff >>= 10; > > And that shift instruction is required because of the following? > >> * Otherwise we know the magnitude of diff is >> + * well within 32 bits. > > AFAICT that's pointless. You are not saving anything because NSEC_PER_SEC is > smaller than 2^32 and your 8 values are not going to overflow 64 bit in the > sum. > >> + */ >> + if (unlikely(diff > USEC_PER_SEC)) { >> + memset(timings, 0, sizeof(*timings)); >> + timings->timestamp = now; > > Redundant store. Yeah, I thought it was more efficient than: memset(timings->value, 0, sizeof(timings->value)); timings->w_index = 0; timings->sum = 0; >> + return; >> + } >> + >> + /* The oldest value corresponds to the next index. */ >> + timings->w_index = (timings->w_index + 1) & IRQ_TIMINGS_MASK; >> + >> + /* >> + * Remove the oldest value from the summing. If this is the >> + * first time we go through this array slot, the previous >> + * value will be zero and we won't substract anything from the >> + * current sum. Hence this code relies on a zero-ed structure. >> + */ >> + timings->sum -= timings->values[timings->w_index]; >> + timings->values[timings->w_index] = diff; >> + timings->sum += diff; > > Now the real question is whether you really need all that math, checks and > memsets in the irq hotpath. If you make the storage slightly larger then you > can just store the values unconditionally in the circular buffer and do all > the computational stuff when you really it. Yes, that was one concern when I wrote the code: do some basic computation when an interrupt occurs, and the rest after or do the entire math when entering idle. If the storage is a bit larger (let's say 16 values) and there is no memset and the sum is not computed, at least we need a count for the number of values in the array before this one is fulfilled, otherwise the statistics will be wrong as we will take into account the entire array with old values, no ? -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog