From patchwork Mon Nov 14 11:50:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Piotr Gregor X-Patchwork-Id: 82094 Delivered-To: patch@linaro.org Received: by 10.182.1.168 with SMTP id 8csp1084453obn; Mon, 14 Nov 2016 03:50:04 -0800 (PST) X-Received: by 10.99.159.26 with SMTP id g26mr28520016pge.62.1479124204923; Mon, 14 Nov 2016 03:50:04 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g23si4373415pfe.198.2016.11.14.03.50.04; Mon, 14 Nov 2016 03:50:04 -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 S933587AbcKNLuC (ORCPT + 3 others); Mon, 14 Nov 2016 06:50:02 -0500 Received: from mail-yw0-f178.google.com ([209.85.161.178]:33889 "EHLO mail-yw0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932261AbcKNLuC (ORCPT ); Mon, 14 Nov 2016 06:50:02 -0500 Received: by mail-yw0-f178.google.com with SMTP id t125so54783372ywc.1 for ; Mon, 14 Nov 2016 03:50:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rsyncme-org.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=hz+Cz67nl1jjsIIxEdydJFe4vhF89rB6ZevRdpIZKIE=; b=0Z2NKNvE+gewInUTx1nBfubOo/mlHLuLYPs80YEgx60ZfvadF4lffSjAvl5oRcaY78 ZwV+A8TzmVQy7l0G09jlrpZrCSdEgbsXr0LPVIGrvV1sjotPLwW05XIZ5x60pCkt0Vnb pQZTUYYg3EPb+nfp+5FfOag4XU1YfSfNvjxHpZdCbORBMr+DQr4d7vT/H/B6HgPXXYsk rGYUgZI4d1kkSNwIUVth7FGGZeKi3eK4wI8Jb7KPJ7/K0B4m2HjrBQxXgMTjllYpHcOR CnKmPwByoBfFVqxBZbKrApjD07hb/0WF9U/d4HzTtLxtTPIUjyBcmwqCqM5ub9G771WX JTEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=hz+Cz67nl1jjsIIxEdydJFe4vhF89rB6ZevRdpIZKIE=; b=CU74NtZSx2aembKx26FqtXv8sFwPBNJBtbyYqNdYNBx/8/WSLnrElnAw2U8IQv64a/ jmiCUdDkCYffodZroc5yp+TZWwIPy8ci04sO2UNTxNpiJqbkU2HJLSh3GJ8cixGrnv9K GS+ayxtnH1uEnE4odY6PV/7TaYnK51YDudZcSSRegMSOprLEjJeUKLHWWTaUKtt8SsTO WGhZzwekVwsT3yrb8fsZogAgvMFpW13wHYGSvbwf9SMguDx//Z8P03ZD6t2wuHFV/cQc W3NcZHGLgqUvYuWU06kIibRwvTvknG8QaPkDk3kugcdmspgZ9jTt2YipR00mp9tdmv7x wH4w== X-Gm-Message-State: ABUngvcNYasRXNsCR3ACL/+NZx53vtd5OOh1/VN8TjXdWCxVQRheIzjRbyGDqWWGw+8d+3o9NTrhBDJWpR8hDA== X-Received: by 10.129.169.132 with SMTP id g126mr13533894ywh.92.1479124201264; Mon, 14 Nov 2016 03:50:01 -0800 (PST) MIME-Version: 1.0 Received: by 10.129.76.210 with HTTP; Mon, 14 Nov 2016 03:50:00 -0800 (PST) X-Originating-IP: [185.63.83.17] In-Reply-To: References: From: Piotr Gregor Date: Mon, 14 Nov 2016 11:50:00 +0000 Message-ID: Subject: Re: 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 There was an error in previous patch. Please find attached corrected patch. cheers, Piotr >From 5610e2b01e5302a5ecff7ca368198863a6ce9f78 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..0d2ddbc 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 / (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