intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Eugeni Dodonov <eugeni@dodonov.net>
To: intel-gfx@lists.freedesktop.org
Cc: Eugeni Dodonov <eugeni.dodonov@intel.com>
Subject: [PATCH 1/6] intel_gpu_top: account for time spent in syscalls
Date: Mon,  5 Sep 2011 17:19:28 -0300	[thread overview]
Message-ID: <1315253973-18950-2-git-send-email-eugeni@dodonov.net> (raw)
In-Reply-To: <1315253973-18950-1-git-send-email-eugeni@dodonov.net>

From: Eugeni Dodonov <eugeni.dodonov@intel.com>

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 <eugeni.dodonov@intel.com>
---
 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 <eric@anholt.net>
+ *    Eugeni Dodonov <eugeni.dodonov@intel.com>
  *
  */
 
@@ -30,6 +32,7 @@
 #include <stdio.h>
 #include <err.h>
 #include <sys/ioctl.h>
+#include <sys/time.h>
 #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);
-- 
1.7.6.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2011-09-05 20:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-05 20:19 [PATCH 0/6] additional intel_gpu_top profiling features Eugeni Dodonov
2011-09-05 20:19 ` Eugeni Dodonov [this message]
2011-09-05 20:19 ` [PATCH 2/6] intel_gpu_top: suport command line parameters and variable samples per second Eugeni Dodonov
2011-09-05 21:44   ` Chris Wilson
2011-09-05 22:16     ` Eugeni Dodonov
2011-09-05 20:19 ` [PATCH 3/6] intel_gpu_tool: initial support for non-screen output Eugeni Dodonov
2011-09-05 22:56   ` Łukasz Kuryło
2011-09-05 23:48     ` Łukasz Kuryło
2011-09-06  0:05     ` Eugeni Dodonov
2011-09-05 20:19 ` [PATCH 4/6] intel_gpu_top: initialize monitoring statistics at startup Eugeni Dodonov
2011-09-05 20:19 ` [PATCH 5/6] intel_gpu_top: support non-interactive mode Eugeni Dodonov
2011-09-05 20:19 ` [PATCH 6/6] intel_gpu_top: support profiling user-specified commands Eugeni Dodonov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1315253973-18950-2-git-send-email-eugeni@dodonov.net \
    --to=eugeni@dodonov.net \
    --cc=eugeni.dodonov@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).