From patchwork Mon Nov 14 10:00:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Piotr Gregor X-Patchwork-Id: 82034 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp929084qge; Mon, 14 Nov 2016 02:01:26 -0800 (PST) X-Received: by 10.107.133.76 with SMTP id h73mr28364074iod.148.1479117686039; Mon, 14 Nov 2016 02:01:26 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o4si18082503pav.64.2016.11.14.02.01.25; Mon, 14 Nov 2016 02:01:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-rt-users-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@rsyncme-org.20150623.gappssmtp.com; spf=pass (google.com: best guess record for domain of linux-rt-users-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-rt-users-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753066AbcKNKBM (ORCPT + 3 others); Mon, 14 Nov 2016 05:01:12 -0500 Received: from mail-yw0-f179.google.com ([209.85.161.179]:32818 "EHLO mail-yw0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752433AbcKNKAt (ORCPT ); Mon, 14 Nov 2016 05:00:49 -0500 Received: by mail-yw0-f179.google.com with SMTP id r204so52697099ywb.0 for ; Mon, 14 Nov 2016 02:00:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rsyncme-org.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to:cc; bh=uOlnSpZsu5UA4QpRu13EZN2pbCuN/X1oZlC/QCwebDs=; b=qSzB6vwQCbpnkKtlnH3aH1sJeXP0ypjF7FEnEU+hWC5BN41RAg9DOGyJLuOdrHIoMe TnbaKNACKna/kXGT6fJWHRo2agcLl+vubo+w0P8f+pRz3UK2t4gnOg7UmVHdeOLqjcQf zWANKHS5XqyYtm7MCuEHt8XXQ/GfpAiZKNgAjQqzLRSNGPfseYaAWuvdLRU7HceOiWF4 nbDFrK3eEJVPc7S97YSNlL5R7XSAO+c20ANjJPBJo0oycyX2iLJgF73agMwrX2kyM6uZ HtBHtMjqmj+21ah0DON8nr0Whg4pX1KTREqaO55PSa5Tx5Td56uV/tXdPlZRzTpbOLtS uWWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=uOlnSpZsu5UA4QpRu13EZN2pbCuN/X1oZlC/QCwebDs=; b=Aggix0QqAS5uTYk3QZaBsEtmMo4KctwIvaGvN13cd+KM0Ni5OQmCD0GOSNzF15wvrL V8H2t8Mxw3rufF5YaGUJCbp4IkJ3HmgNvwNP1XH1KHUgLjrUnlvtPOATQjyQm3dXbqmN nHhoK2N3WzxyOsSN2mwMfq52PliOUDHaVdDBlwyxGjhrMTxohOeEVirJ+osSPhpg6SYf adxmGFd7XMw7n9vieP5WG2lSW7SogElhA/MhYdAPD0lPU026MVEbUNpD7vArHWMuxEAN 6U0Zj04w4ZBNUhKqwMKSlPjDaTtneOm65Q4pDgDQURk2bVJU1aWOta+DYXgcl6iZUcfO gWPQ== X-Gm-Message-State: ABUngvffGbQMaZ7aOdDiykAyrNYBTOwtWKhEIPQjRicE7DC4kibG5s40duMsLbBmS6RCN57QYmunvpsXroCFng== X-Received: by 10.13.229.66 with SMTP id o63mr15626343ywe.212.1479117648918; Mon, 14 Nov 2016 02:00:48 -0800 (PST) MIME-Version: 1.0 Received: by 10.129.76.210 with HTTP; Mon, 14 Nov 2016 02:00:48 -0800 (PST) X-Originating-IP: [185.63.83.17] From: Piotr Gregor Date: Mon, 14 Nov 2016 10:00:48 +0000 Message-ID: Subject: Calculate average latencies on the fly To: Clark Williams , John Kacur Cc: linux-rt-users@vger.kernel.org Sender: linux-rt-users-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org Hi, There is a possibility for average to overflow as it is first accumulated and only divided when printing statistics. Attached is the patch to calculate average on the go. Patch is diffed between stable/v1.0 branch git format-patch origin/stable/v1.0 --stdout > calc_average_on_the_fly.patch cheers, Piotr >From cb9a85222dff1a299fde25a96243139cde6a4947 Mon Sep 17 00:00:00 2001 From: Piotr Gregor Date: Fri, 11 Nov 2016 11:28:09 +0000 Subject: [PATCH] rt-tests: cyclictest: Calculate average latencies on the fly Prevents stat->avg variable from overflow. --- src/cyclictest/cyclictest.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c index 3f1bef1..2c4e450 100644 --- a/src/cyclictest/cyclictest.c +++ b/src/cyclictest/cyclictest.c @@ -1178,7 +1178,11 @@ static void *timerthread(void *param) if (refresh_on_max) pthread_cond_signal(&refresh_on_max_cond); } - stat->avg += (double) diff; + if (stat->cycles == 0) { + stat->avg = (double) diff; + } else { + stat->avg = (stat->avg + (double) diff) * ((double) stat->cycles / (double) (stat->cycles + 1)); + } if (trigger && (diff > trigger)) { trigger_update(par, diff, calctime(now)); @@ -2005,7 +2009,7 @@ static void print_hist(struct thread_param *par[], int nthreads) fprintf(fd, "# Avg Latencies:"); for (j = 0; j < nthreads; j++) fprintf(fd, " %05lu", par[j]->stats->cycles ? - (long)(par[j]->stats->avg/par[j]->stats->cycles) : 0); + (long)(par[j]->stats->avg) : 0); fprintf(fd, "\n"); fprintf(fd, "# Max Latencies:"); maxmax = 0; @@ -2059,7 +2063,7 @@ static void print_stat(FILE *fp, struct thread_param *par, int index, int verbos fprintf(fp, fmt, index, stat->tid, par->prio, par->interval, stat->cycles, stat->min, stat->act, stat->cycles ? - (long)(stat->avg/stat->cycles) : 0, stat->max); + (long)(stat->avg) : 0, stat->max); if (smi) fprintf(fp," SMI:%8ld", stat->smi_count); -- 2.7.4