From patchwork Mon Mar 19 18:22:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10293989 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4D744602C2 for ; Mon, 19 Mar 2018 18:22:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C28328987 for ; Mon, 19 Mar 2018 18:22:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30F1028A29; Mon, 19 Mar 2018 18:22:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 48211294DC for ; Mon, 19 Mar 2018 18:22:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A198C6E5F2; Mon, 19 Mar 2018 18:22:24 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4E8656E5EC for ; Mon, 19 Mar 2018 18:22:18 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id h21so16915826wmd.1 for ; Mon, 19 Mar 2018 11:22:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=viaRSn+7GnlVJg6SADnXZyG/j51EoU59FD+NMigdw/Q=; b=VzQ4CkyKvgEKX1X2wBFkBPsI7V6Vml5vQF/HWNqyr6ks7yLvnWx5miwH/OT7JhvMPr izX5dTtfyCtMqus28mh3gWrnRS4/h9e/MC924AkpWjm3PrTDiappU2Kdv0kdQr0uTWqV zqyaG0jSmNEYaj8Lw4905X1KUbk7mLFNwEGarbfeXJ0b4gP4oMyHfRMme1IFRZBVMRWp kJtLnqwYfj8RFkTMO+AphhyHVIJDPkbYJSwJ2rktLeHEbVG4AqQmsCS6nVRkS0MeAVTg xnmY/hkbc4axMkiCPNM9g+PbNpMCgwB0iUmPlS8ZhgW58dkRZVuVDfk8mA7+wlgfg63r Gpww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=viaRSn+7GnlVJg6SADnXZyG/j51EoU59FD+NMigdw/Q=; b=eVU0NtF0OAbna28ZqrhaA8GHJl5P+wUe9CC7GtuPcce08xo/vQVv+dYJdWpllFGf+T QUZktyedMIdwQz7XiRLtiWWp2BFjrFyFU8P7E+cYoHqgOOw4EbYlXLVz+If1fo/DTzNg cZP6LursGmOax25ZUFXZ5umNRkO+y5EOC2+pO8SLt6z2delZpz4ZNTSmEdF1/NgcsgVu vLTmGyV3uLP87iyT0QtgqGRvy4LIg+9utk2xRqnGwq/6iWwZVKm62Le37YpGFi6AhS8H 53HM9zQFZlUg0Rly/Ms3sO11gXuOu0AIFE1pv5VxRnTAytbTVQn8kdWTiZpLAoZHpIzE slMA== X-Gm-Message-State: AElRT7FAdEu9AiSPOukxGXdvfEYIzJAHJEWtohqt67MeO48nrgkOBa/x MRvNwC0LWQ/XPQyvzn6Urm9scw== X-Google-Smtp-Source: AG47ELsuYZnnGUNNLEIqgjtN7Fu0K7qsgKPQXCNKkBlPyGviw9CFH8Z/OEBCaRmzdqblOd13N+YH3w== X-Received: by 10.28.59.130 with SMTP id i124mr8841514wma.23.1521483736924; Mon, 19 Mar 2018 11:22:16 -0700 (PDT) Received: from localhost.localdomain ([95.146.144.186]) by smtp.gmail.com with ESMTPSA id f23sm837009wra.51.2018.03.19.11.22.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Mar 2018 11:22:16 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org Date: Mon, 19 Mar 2018 18:22:03 +0000 Message-Id: <20180319182205.29454-4-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180319182205.29454-1-tvrtko.ursulin@linux.intel.com> References: <20180319182205.29454-1-tvrtko.ursulin@linux.intel.com> Subject: [Intel-gfx] [PATCH i-g-t 3/5] intel-gpu-overlay: Show 1s, 30s and 15m GPU load X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Intel-gfx@lists.freedesktop.org MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin Show total GPU loads in the window banner. Engine load is defined as total of runnable and running requests on an engine. Total, non-normalized, load is display. In other words if N engines are busy with exactly one request, the load will be shown as N. v2: * Different flavour of load avg. (Chris Wilson) * Simplify code. (Chris Wilson) Signed-off-by: Tvrtko Ursulin --- overlay/gpu-top.c | 39 ++++++++++++++++++++++++++++++++++++++- overlay/gpu-top.h | 11 ++++++++++- overlay/overlay.c | 28 ++++++++++++++++++++++------ 3 files changed, 70 insertions(+), 8 deletions(-) diff --git a/overlay/gpu-top.c b/overlay/gpu-top.c index 22e9badb22c1..501429b86379 100644 --- a/overlay/gpu-top.c +++ b/overlay/gpu-top.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -126,6 +127,10 @@ static int perf_init(struct gpu_top *gt) gt->ring[gt->num_rings++].name = d->name; } + gt->have_load_avg = gt->have_queued && + gt->have_runnable && + gt->have_running; + return 0; } @@ -290,17 +295,32 @@ static void mmio_init(struct gpu_top *gt) } } -void gpu_top_init(struct gpu_top *gt) +void gpu_top_init(struct gpu_top *gt, unsigned int period_us) { + const double period = (double)period_us / 1e6; + const double load_period[NUM_LOADS] = { 1.0, 30.0, 900.0 }; + const char *load_names[NUM_LOADS] = { "1s", "30s", "15m" }; + unsigned int i; + memset(gt, 0, sizeof(*gt)); gt->fd = -1; + for (i = 0; i < NUM_LOADS; i++) { + gt->load_name[i] = load_names[i]; + gt->exp[i] = exp(-period / load_period[i]); + } + if (perf_init(gt) == 0) return; mmio_init(gt); } +static double update_load(double load, double exp, double val) +{ + return val + exp * (load - val); +} + int gpu_top_update(struct gpu_top *gt) { uint32_t data[1024]; @@ -313,6 +333,8 @@ int gpu_top_update(struct gpu_top *gt) struct gpu_top_stat *s = >->stat[gt->count++&1]; struct gpu_top_stat *d = >->stat[gt->count&1]; uint64_t *sample, d_time; + double gpu_qd = 0.0; + unsigned int i; int n, m; len = read(gt->fd, data, sizeof(data)); @@ -341,6 +363,8 @@ int gpu_top_update(struct gpu_top *gt) d_time = s->time - d->time; for (n = 0; n < gt->num_rings; n++) { + double qd = 0.0; + gt->ring[n].u.u.busy = (100 * (s->busy[n] - d->busy[n]) + d_time/2) / d_time; if (gt->have_wait) gt->ring[n].u.u.wait = (100 * (s->wait[n] - d->wait[n]) + d_time/2) / d_time; @@ -353,6 +377,14 @@ int gpu_top_update(struct gpu_top *gt) if (gt->have_running) gt->ring[n].running = (double)((s->running[n] - d->running[n])) / I915_SAMPLE_RUNNING_DIVISOR * 1e9 / d_time; + qd = gt->ring[n].runnable + gt->ring[n].running; + gpu_qd += qd; + + for (i = 0; i < NUM_LOADS; i++) + gt->ring[n].load[i] = + update_load(gt->ring[n].load[i], + gt->exp[i], qd); + /* in case of rounding + sampling errors, fudge */ if (gt->ring[n].u.u.busy > 100) gt->ring[n].u.u.busy = 100; @@ -362,6 +394,11 @@ int gpu_top_update(struct gpu_top *gt) gt->ring[n].u.u.sema = 100; } + for (i = 0; i < NUM_LOADS; i++) { + gt->load[i] = update_load(gt->load[i], gt->exp[i], + gpu_qd); + gt->norm_load[i] = gt->load[i] / gt->num_rings; + } update = 1; } else { while ((len = read(gt->fd, data, sizeof(data))) > 0) { diff --git a/overlay/gpu-top.h b/overlay/gpu-top.h index cb4310c82a94..115ce8c482c1 100644 --- a/overlay/gpu-top.h +++ b/overlay/gpu-top.h @@ -26,6 +26,7 @@ #define GPU_TOP_H #define MAX_RINGS 16 +#define NUM_LOADS 3 #include @@ -39,6 +40,12 @@ struct gpu_top { int have_queued; int have_runnable; int have_running; + int have_load_avg; + + double exp[NUM_LOADS]; + double load[NUM_LOADS]; + double norm_load[NUM_LOADS]; + const char *load_name[NUM_LOADS]; struct gpu_top_ring { const char *name; @@ -54,6 +61,8 @@ struct gpu_top { double queued; double runnable; double running; + + double load[NUM_LOADS]; } ring[MAX_RINGS]; struct gpu_top_stat { @@ -69,7 +78,7 @@ struct gpu_top { int count; }; -void gpu_top_init(struct gpu_top *gt); +void gpu_top_init(struct gpu_top *gt, unsigned int period_us); int gpu_top_update(struct gpu_top *gt); #endif /* GPU_TOP_H */ diff --git a/overlay/overlay.c b/overlay/overlay.c index d3755397061b..63512059d8ff 100644 --- a/overlay/overlay.c +++ b/overlay/overlay.c @@ -141,7 +141,8 @@ struct overlay_context { }; static void init_gpu_top(struct overlay_context *ctx, - struct overlay_gpu_top *gt) + struct overlay_gpu_top *gt, + unsigned int period_us) { const double rgba[][4] = { { 1, 0.25, 0.25, 1 }, @@ -152,7 +153,7 @@ static void init_gpu_top(struct overlay_context *ctx, int n; cpu_top_init(>->cpu_top); - gpu_top_init(>->gpu_top); + gpu_top_init(>->gpu_top, period_us); chart_init(>->cpu, "CPU", 120); chart_set_position(>->cpu, PAD, PAD); @@ -927,13 +928,13 @@ int main(int argc, char **argv) debugfs_init(); - init_gpu_top(&ctx, &ctx.gpu_top); + sample_period = get_sample_period(&config); + + init_gpu_top(&ctx, &ctx.gpu_top, sample_period); init_gpu_perf(&ctx, &ctx.gpu_perf); init_gpu_freq(&ctx, &ctx.gpu_freq); init_gem_objects(&ctx, &ctx.gem_objects); - sample_period = get_sample_period(&config); - i = 0; while (1) { ctx.time = time(NULL); @@ -949,9 +950,24 @@ int main(int argc, char **argv) show_gem_objects(&ctx, &ctx.gem_objects); { - char buf[80]; + struct gpu_top *gt = &ctx.gpu_top.gpu_top; cairo_text_extents_t extents; + char buf[256]; + gethostname(buf, sizeof(buf)); + + if (gt->have_load_avg) { + int len = strlen(buf); + + snprintf(buf + len, sizeof(buf) - len, + "%s; %u engines; load %s %.2f, %s %.2f, %s %.2f", + buf, + gt->num_rings, + gt->load_name[0], gt->load[0], + gt->load_name[1], gt->load[1], + gt->load_name[2], gt->load[2]); + } + cairo_set_source_rgb(ctx.cr, .5, .5, .5); cairo_set_font_size(ctx.cr, PAD-2); cairo_text_extents(ctx.cr, buf, &extents);