From patchwork Mon Sep 5 20:19:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugeni Dodonov X-Patchwork-Id: 1125402 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p85KLJW5000465 for ; Mon, 5 Sep 2011 20:21:39 GMT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4E54E9F51D for ; Mon, 5 Sep 2011 13:21:19 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from oproxy8-pub.bluehost.com (oproxy8-pub.bluehost.com [69.89.22.20]) by gabe.freedesktop.org (Postfix) with SMTP id C7DA59E787 for ; Mon, 5 Sep 2011 13:20:26 -0700 (PDT) Received: (qmail 26709 invoked by uid 0); 5 Sep 2011 20:20:26 -0000 Received: from unknown (HELO box335.bluehost.com) (69.89.31.135) by oproxy8.bluehost.com with SMTP; 5 Sep 2011 20:20:26 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=dodonov.net; s=default; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=19dn+vWD33dSzUzObBJXIS0bYXyaQM9ZVEc2n5IZCFA=; b=sLZLgRfOFLDmKlWqg07HmfRHfpFvzgYMc7xtFoDaB3L1tISTyq81a/ty4kZVdS8LHC11mHA3Vgseh73lW+RmffJvVrndt1OIkweQ7uABXZGia/r3ctXy9/kFVnC/N75m; Received: from 200.188.217.18.dedicated.neoviatelecom.com.br ([200.188.217.18] helo=localhost.localdomain) by box335.bluehost.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1R0feb-0007ag-AN; Mon, 05 Sep 2011 14:20:26 -0600 From: Eugeni Dodonov To: intel-gfx@lists.freedesktop.org Date: Mon, 5 Sep 2011 17:19:28 -0300 Message-Id: <1315253973-18950-2-git-send-email-eugeni@dodonov.net> X-Mailer: git-send-email 1.7.6.1 In-Reply-To: <1315253973-18950-1-git-send-email-eugeni@dodonov.net> References: <1315253973-18950-1-git-send-email-eugeni@dodonov.net> MIME-Version: 1.0 X-Identified-User: {669:box335.bluehost.com:dodonovn:dodonov.net} {sentby:smtp auth 200.188.217.18 authed with eugeni@dodonov.net} Cc: Eugeni Dodonov Subject: [Intel-gfx] =?utf-8?q?=5BPATCH_1/6=5D_intel=5Fgpu=5Ftop=3A_accoun?= =?utf-8?q?t_for_time_spent_in_syscalls?= X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 05 Sep 2011 20:21:39 +0000 (UTC) X-MIME-Autoconverted: from base64 to 8bit by demeter1.kernel.org id p85KLJW5000465 From: Eugeni Dodonov This allows intel_gpu_top to properly account for time spent inside system calls. Effectively, with previous implementation, intel_gpu_top could spent longer than 1s between consecutive measures. This attempts to minimize the extra time spent while polling for data. Signed-off-by: Eugeni Dodonov --- tools/intel_gpu_top.c | 53 +++++++++++++++++++++++++++++++++++++----------- 1 files changed, 41 insertions(+), 12 deletions(-) diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c index e9fbf43..64ce828 100644 --- a/tools/intel_gpu_top.c +++ b/tools/intel_gpu_top.c @@ -1,5 +1,6 @@ /* * Copyright © 2007 Intel Corporation + * Copyright © 2011 Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -22,6 +23,7 @@ * * Authors: * Eric Anholt + * Eugeni Dodonov * */ @@ -30,6 +32,7 @@ #include #include #include +#include #include "intel_gpu_tools.h" #include "instdone.h" @@ -104,6 +107,14 @@ const char *stats_reg_names[STATS_COUNT] = { uint64_t stats[STATS_COUNT]; uint64_t last_stats[STATS_COUNT]; +static unsigned long +gettime(void) +{ + struct timeval t; + gettimeofday(&t, NULL); + return (t.tv_usec + (t.tv_sec * 1000000)); +} + static int top_bits_sort(const void *a, const void *b) { @@ -362,21 +373,23 @@ static void ring_sample(struct ring *ring) ring->full += full; } -static void ring_print(struct ring *ring) +static void ring_print(struct ring *ring, unsigned long samples_per_sec) { - int percent, len; + int samples_to_percent_ratio, percent, len; if (!ring->size) return; - percent = 100 - ring->idle / SAMPLES_TO_PERCENT_RATIO; + /* Calculate current value of samples_to_percent_ratio */ + samples_to_percent_ratio = (ring->idle * 100) / samples_per_sec; + percent = 100 - samples_to_percent_ratio; len = printf("%25s busy: %3d%%: ", ring->name, percent); print_percentage_bar (percent, len); printf("%24s space: %d/%d (%d%%)\n", ring->name, - (int)(ring->full / SAMPLES_PER_SEC), + (int)(ring->full / samples_per_sec), ring->size, - (int)((ring->full / SAMPLES_TO_PERCENT_RATIO) / ring->size)); + (int)((ring->full / samples_to_percent_ratio) / ring->size)); } int main(int argc, char **argv) @@ -418,18 +431,25 @@ int main(int argc, char **argv) for (;;) { int j; + unsigned long long t1, ti, tf; + unsigned long long def_sleep = 1000000 / SAMPLES_PER_SEC; + unsigned long long last_samples_per_sec = SAMPLES_PER_SEC; char clear_screen[] = {0x1b, '[', 'H', 0x1b, '[', 'J', 0x0}; int percent; int len; + t1 = gettime(); + ring_reset(&render_ring); ring_reset(&bsd_ring); ring_reset(&bsd6_ring); ring_reset(&blt_ring); for (i = 0; i < SAMPLES_PER_SEC; i++) { + long long interval; + ti = gettime(); if (IS_965(devid)) { instdone = INREG(INST_DONE_I965); instdone1 = INREG(INST_DONE_1); @@ -443,7 +463,16 @@ int main(int argc, char **argv) ring_sample(&bsd_ring); ring_sample(&bsd6_ring); ring_sample(&blt_ring); - usleep(1000000 / SAMPLES_PER_SEC); + + tf = gettime(); + if (tf - t1 >= 1000000) { + /* We are out of sync, bail out */ + last_samples_per_sec = i+1; + break; + } + interval = def_sleep - (tf - ti); + if (interval > 0) + usleep(interval); } if (HAS_STATS_REGS(devid)) { @@ -477,16 +506,16 @@ int main(int argc, char **argv) print_clock_info(pci_dev); - ring_print(&render_ring); - ring_print(&bsd_ring); - ring_print(&bsd6_ring); - ring_print(&blt_ring); + ring_print(&render_ring, last_samples_per_sec); + ring_print(&bsd_ring, last_samples_per_sec); + ring_print(&bsd6_ring, last_samples_per_sec); + ring_print(&blt_ring, last_samples_per_sec); printf("\n%30s %s\n", "task", "percent busy"); for (i = 0; i < max_lines; i++) { if (top_bits_sorted[i]->count > 0) { - percent = top_bits_sorted[i]->count / - SAMPLES_TO_PERCENT_RATIO; + percent = (top_bits_sorted[i]->count * 100) / + last_samples_per_sec; len = printf("%30s: %3d%%: ", top_bits_sorted[i]->bit->name, percent);