From patchwork Mon Mar 26 10:57:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10307629 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 7758D60212 for ; Mon, 26 Mar 2018 10:58:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C085292A3 for ; Mon, 26 Mar 2018 10:58:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6047C29410; Mon, 26 Mar 2018 10:58:12 +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 AC1C9292A3 for ; Mon, 26 Mar 2018 10:58:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 255106E3E7; Mon, 26 Mar 2018 10:58:10 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id B37E36E359 for ; Mon, 26 Mar 2018 10:58:08 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id l16so14653034wmh.3 for ; Mon, 26 Mar 2018 03:58:08 -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; bh=h0SFKGDv2BGuIMs58Ae9RvuC9T2/k1/Rq58X8SP6xZU=; b=XwAdcOAf6yK7Jth6PQ4EbdvRc2QynkSqXn0CeQ7lTxlzDJOVVLLK80yxw0DCaLz2D/ pl7IaXX5PVpUFy7i20Q+O1TDUVy7JNDAw+NfWUp2NMlvj3f7/hKJIYOCJPD7RM3wePXL RsaKyYu3ybSD/tKJ2+T+x4T76Uco2G5DMxnGpwKPSGLs43WnxCMav6EsaeVs92lydkKq UMJPSBCo7L8noXyWGeXoOCrZzWfXqT1kq4nzFm7xm5rMOToQ1Lf0kS3au7cRBgvoXsXU 6I+TpDKYMiRs7h80XPxpVHiVAUyuGtCP10L2gEIJvhZ7v7F8tajq0ZcCpfgKCnQzHyiZ wQsw== 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; bh=h0SFKGDv2BGuIMs58Ae9RvuC9T2/k1/Rq58X8SP6xZU=; b=q/dmiDtJGxnJzSiifAJIq6o0vrST/mQA45X8mWCaXwDKk4Tjhos7EnQObbpU6PCbsD rkpeSvG9peOnG9fUdhMEtMUELKN7wHPQN4bnxJpTv64Bw6ubTN6n/NSHv2IMuDiyZheh 1sRVRlrfrzCSQnJq60sRUmE9g0YjWIVwC1RVrGlHJ9CX+rARxX15kkbCu2xMM81Az/I1 5V9UNAYcihYwqjv+M/FlLx4HaQhhLE9YIXMaTWR70bT229nYBseNkGE0e5wJo2VlotDq TRRrAojc9GA/esWLaYg6lDc/pMDXaDH4zBrtvtPayq51bwlr2UW47FKgPtr8Nk2HM2dI ftPg== X-Gm-Message-State: AElRT7Hg4a+7zTdDHSFyMZnQpVAvaxcdDNvc53Mlb1x/p+tii0PcRCnD +FMQPOZ6cyKcQfrmSA/LEz3B2A== X-Google-Smtp-Source: AG47ELuxBnNnvsI9fK5flDhCLgzKfqBZaEd177atUppfv2qXGTaDBBCQxjibGeB28d8arZ/P+Z5Q2g== X-Received: by 10.28.136.74 with SMTP id k71mr14217392wmd.46.1522061887254; Mon, 26 Mar 2018 03:58:07 -0700 (PDT) Received: from localhost.localdomain ([95.146.144.186]) by smtp.gmail.com with ESMTPSA id q81sm16943973wmg.8.2018.03.26.03.58.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Mar 2018 03:58:06 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org Date: Mon, 26 Mar 2018 11:57:58 +0100 Message-Id: <20180326105758.5211-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 Subject: [Intel-gfx] [CI i-g-t] tests/perf_pmu: Avoid RT thread for accuracy test 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 Realtime scheduling interferes with execlists submission (tasklet) so try to simplify the PWM loop in a few ways: * Drop RT. * Longer batches for smaller systematic error. * More truthful test duration calculation. * Less clock queries. * No self-adjust - instead just report the achieved cycle and let the parent check against it. * Report absolute cycle error. Signed-off-by: Tvrtko Ursulin --- tests/perf_pmu.c | 80 ++++++++++++++++++++------------------------------------ 1 file changed, 29 insertions(+), 51 deletions(-) diff --git a/tests/perf_pmu.c b/tests/perf_pmu.c index f27b7ec7d2c2..4436a7a49141 100644 --- a/tests/perf_pmu.c +++ b/tests/perf_pmu.c @@ -1504,12 +1504,6 @@ test_enable_race(int gem_fd, const struct intel_execution_engine2 *e) gem_quiescent_gpu(gem_fd); } -static double __error(double val, double ref) -{ - igt_assert(ref > 1e-5 /* smallval */); - return (100.0 * val / ref) - 100.0; -} - static void __rearm_spin_batch(igt_spin_t *spin) { const uint32_t mi_arb_chk = 0x5 << 23; @@ -1532,13 +1526,12 @@ static void accuracy(int gem_fd, const struct intel_execution_engine2 *e, unsigned long target_busy_pct) { - const unsigned int min_test_loops = 7; - const unsigned long min_test_us = 1e6; - unsigned long busy_us = 2500; + unsigned long busy_us = 10000 - 100 * (1 + abs(50 - target_busy_pct)); unsigned long idle_us = 100 * (busy_us - target_busy_pct * busy_us / 100) / target_busy_pct; - unsigned long pwm_calibration_us; - unsigned long test_us; + const unsigned long min_test_us = 1e6; + const unsigned long pwm_calibration_us = min_test_us; + const unsigned long test_us = min_test_us; double busy_r, expected; uint64_t val[2]; uint64_t ts[2]; @@ -1553,13 +1546,6 @@ accuracy(int gem_fd, const struct intel_execution_engine2 *e, idle_us *= 2; } - pwm_calibration_us = min_test_loops * (busy_us + idle_us); - while (pwm_calibration_us < min_test_us) - pwm_calibration_us += busy_us + idle_us; - test_us = min_test_loops * (idle_us + busy_us); - while (test_us < min_test_us) - test_us += busy_us + idle_us; - igt_info("calibration=%lums, test=%lums; ratio=%.2f%% (%luus/%luus)\n", pwm_calibration_us / 1000, test_us / 1000, (double)busy_us / (busy_us + idle_us) * 100.0, @@ -1572,20 +1558,11 @@ accuracy(int gem_fd, const struct intel_execution_engine2 *e, /* Emit PWM pattern on the engine from a child. */ igt_fork(child, 1) { - struct sched_param rt = { .sched_priority = 99 }; const unsigned long timeout[] = { pwm_calibration_us * 1000, test_us * 1000 }; - uint64_t total_busy_ns = 0, total_idle_ns = 0; + uint64_t busy_ns = 0, idle_ns = 0; igt_spin_t *spin; - int ret; - - /* We need the best sleep accuracy we can get. */ - ret = sched_setscheduler(0, - SCHED_FIFO | SCHED_RESET_ON_FORK, - &rt); - if (ret) - igt_warn("Failed to set scheduling policy!\n"); /* Allocate our spin batch and idle it. */ spin = igt_spin_batch_new(gem_fd, 0, e2ring(gem_fd, e), 0); @@ -1594,37 +1571,38 @@ accuracy(int gem_fd, const struct intel_execution_engine2 *e, /* 1st pass is calibration, second pass is the test. */ for (int pass = 0; pass < ARRAY_SIZE(timeout); pass++) { - uint64_t busy_ns = -total_busy_ns; - uint64_t idle_ns = -total_idle_ns; - struct timespec test_start = { }; + struct timespec start = { }; + unsigned long pass_ns = 0; + + igt_nsec_elapsed(&start); - igt_nsec_elapsed(&test_start); do { - unsigned int target_idle_us, t_busy; + unsigned long loop_ns, loop_busy; + struct timespec _ts = { }; + + /* PWM idle sleep. */ + _ts.tv_nsec = idle_us * 1000; + nanosleep(&_ts, NULL); /* Restart the spinbatch. */ __rearm_spin_batch(spin); __submit_spin_batch(gem_fd, spin, e, 0); - /* - * Note that the submission may be delayed to a - * tasklet (ksoftirqd) which cannot run until we - * sleep as we hog the cpu (we are RT). - */ - - t_busy = measured_usleep(busy_us); + /* PWM busy sleep. */ + loop_busy = igt_nsec_elapsed(&start); + _ts.tv_nsec = busy_us * 1000; + nanosleep(&_ts, NULL); igt_spin_batch_end(spin); - gem_sync(gem_fd, spin->handle); - - total_busy_ns += t_busy; - target_idle_us = - (100 * total_busy_ns / target_busy_pct - (total_busy_ns + total_idle_ns)) / 1000; - total_idle_ns += measured_usleep(target_idle_us); - } while (igt_nsec_elapsed(&test_start) < timeout[pass]); + /* Time accounting. */ + loop_ns = igt_nsec_elapsed(&start); + loop_busy = loop_ns - loop_busy; + loop_ns -= pass_ns; - busy_ns += total_busy_ns; - idle_ns += total_idle_ns; + busy_ns += loop_busy; + idle_ns += loop_ns - loop_busy; + pass_ns += loop_ns; + } while (pass_ns < timeout[pass]); expected = (double)busy_ns / (busy_ns + idle_ns); igt_info("%u: busy %"PRIu64"us, idle %"PRIu64"us: %.2f%% (target: %lu%%)\n", @@ -1655,8 +1633,8 @@ accuracy(int gem_fd, const struct intel_execution_engine2 *e, busy_r = (double)(val[1] - val[0]) / (ts[1] - ts[0]); - igt_info("error=%.2f%% (%.2f%% vs %.2f%%)\n", - __error(busy_r, expected), 100 * busy_r, 100 * expected); + igt_info("error=%.2f (%.2f%% vs %.2f%%)\n", + (busy_r - expected) * 100, 100 * busy_r, 100 * expected); assert_within(100.0 * busy_r, 100.0 * expected, 2); }