From patchwork Mon Nov 7 19:49:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Bragg X-Patchwork-Id: 9415969 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 1E66960512 for ; Mon, 7 Nov 2016 19:50:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E34328AF5 for ; Mon, 7 Nov 2016 19:50:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01A9428D42; Mon, 7 Nov 2016 19:50:58 +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=unavailable 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 B333B28AF5 for ; Mon, 7 Nov 2016 19:50:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 51A2F6E42C; Mon, 7 Nov 2016 19:50:17 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 562C46E416; Mon, 7 Nov 2016 19:50:12 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id c17so18255196wmc.3; Mon, 07 Nov 2016 11:50:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=8v1mgLswUwaNzfgy76F/bCMlXOfurP1hdm9KDBQo7PY=; b=ABUhDPdawcGlIHkoIzV9IX3QB+N0lDsXin246KPCe1ZydqOQflIpGi4GlZ85c/h4Ql NtGdr+BTZxn5vkuOrZiaN/AdIICoLVER1i2X2Z4XthX/7AigTgRg839OFBd1p0v4OoCR x000ay/bq6/LTPgvVM7zQxwe2LrPnAWs/VIQKhJysfmxtvuA/W87VVPQGvEv6Vryo8DH w2ynE1FWVtciY429l+KAohlPtXi7szJB8YPcICtdV1wxrC03T6fsWucuMan6tTClwchl MBQFMFv+h37G1xMDJgAX7vPwzrqn2Q2yOxYBKd+TxVfCFagFkvUG3facGMqKLPg6QcXe hzig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=8v1mgLswUwaNzfgy76F/bCMlXOfurP1hdm9KDBQo7PY=; b=NEroW/bgyvpA58dMvNRrzCqFif71/JKi0n+G+cCwqtZzLmNrXkfm/raFEzL68TZP3l OVx/D98t0oevUPa6XXNcgyIWOyMdZmJMiPGDgAKkzF8myqkwXFb9x2qpzERveBQVy3MM ReD4mkzhdu+QJFl68C7kxIpeCZ3ImNCqTAJT4Fhmk8biG6P4UId8FH1TnDNHo/GFh4Xb XVdsXzTP8n7Bf3EAix2LPsB1ja0ymUrhCPmGyk83mzU5btnNOCv0iVOdipNU8sRxMhRf dw7JPv6h+ZabACjlr9qJl3wn3m71V25ih2QlLpdZIy2ou1HioWi2PyB9MEgG8WIcoBp+ uBag== X-Gm-Message-State: ABUngveGz94RBdqLXnSVAwDECpvPdvKvkMVs0oydalnsYQ2Dt32PSmW3e18ZR1+1lr5QhQ== X-Received: by 10.194.42.39 with SMTP id k7mr6881568wjl.212.1478548210853; Mon, 07 Nov 2016 11:50:10 -0800 (PST) Received: from sixbynine.org (cpc26-heme10-2-0-cust305.9-1.cable.virginm.net. [86.3.57.50]) by smtp.gmail.com with ESMTPSA id g142sm15382203wmd.2.2016.11.07.11.50.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Nov 2016 11:50:10 -0800 (PST) From: Robert Bragg To: intel-gfx@lists.freedesktop.org Subject: [PATCH v9 09/11] drm/i915: add dev.i915.oa_max_sample_rate sysctl Date: Mon, 7 Nov 2016 19:49:55 +0000 Message-Id: <20161107194957.3385-10-robert@sixbynine.org> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161107194957.3385-1-robert@sixbynine.org> References: <20161107194957.3385-1-robert@sixbynine.org> Cc: dri-devel@lists.freedesktop.org, Matthew Auld , Sourab Gupta , Daniel Vetter , Robert Bragg X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The maximum OA sampling frequency is now configurable via a dev.i915.oa_max_sample_rate sysctl parameter. Following the precedent set by perf's similar kernel.perf_event_max_sample_rate the default maximum rate is 100000Hz Signed-off-by: Robert Bragg Reviewed-by: Sourab Gupta Reviewed-by: Matthew Auld --- drivers/gpu/drm/i915/i915_perf.c | 61 ++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c index e51c1d8..1a87fe9 100644 --- a/drivers/gpu/drm/i915/i915_perf.c +++ b/drivers/gpu/drm/i915/i915_perf.c @@ -82,6 +82,21 @@ static u32 i915_perf_stream_paranoid = true; #define INVALID_CTX_ID 0xffffffff +/* For sysctl proc_dointvec_minmax of i915_oa_max_sample_rate + * + * 160ns is the smallest sampling period we can theoretically program the OA + * unit with on Haswell, corresponding to 6.25MHz. + */ +static int oa_sample_rate_hard_limit = 6250000; + +/* Theoretically we can program the OA unit to sample every 160ns but don't + * allow that by default unless root... + * + * The default threshold of 100000Hz is based on perf's similar + * kernel.perf_event_max_sample_rate sysctl parameter. + */ +static u32 i915_oa_max_sample_rate = 100000; + /* XXX: beware if future OA HW adds new report formats that the current * code assumes all reports have a power-of-two size and ~(size - 1) can * be used as a mask to align the OA tail pointer. @@ -1314,6 +1329,7 @@ static int read_properties_unlocked(struct drm_i915_private *dev_priv, } for (i = 0; i < n_props; i++) { + u64 oa_period, oa_freq_hz; u64 id, value; int ret; @@ -1359,21 +1375,35 @@ static int read_properties_unlocked(struct drm_i915_private *dev_priv, return -EINVAL; } - /* NB: The exponent represents a period as follows: - * - * 80ns * 2^(period_exponent + 1) - * - * Theoretically we can program the OA unit to sample + /* Theoretically we can program the OA unit to sample * every 160ns but don't allow that by default unless * root. * - * Referring to perf's - * kernel.perf_event_max_sample_rate for a precedent - * (100000 by default); with an OA exponent of 6 we get - * a period of 10.240 microseconds -just under 100000Hz + * On Haswell the period is derived from the exponent + * as: + * + * period = 80ns * 2^(exponent + 1) + */ + BUILD_BUG_ON(sizeof(oa_period) != 8); + oa_period = 80ull * (2ull << value); + + /* This check is primarily to ensure that oa_period <= + * UINT32_MAX (before passing to do_div which only + * accepts a u32 denominator), but we can also skip + * checking anything < 1Hz which implicitly can't be + * limited via an integer oa_max_sample_rate. */ - if (value < 6 && !capable(CAP_SYS_ADMIN)) { - DRM_ERROR("Minimum OA sampling exponent is 6 without root privileges\n"); + if (oa_period <= NSEC_PER_SEC) { + u64 tmp = NSEC_PER_SEC; + do_div(tmp, oa_period); + oa_freq_hz = tmp; + } else + oa_freq_hz = 0; + + if (oa_freq_hz > i915_oa_max_sample_rate && + !capable(CAP_SYS_ADMIN)) { + DRM_ERROR("OA exponent would exceed the max sampling frequency (sysctl dev.i915.oa_max_sample_rate) %uHz without root privileges\n", + i915_oa_max_sample_rate); return -EACCES; } @@ -1481,6 +1511,15 @@ static struct ctl_table oa_table[] = { .extra1 = &zero, .extra2 = &one, }, + { + .procname = "oa_max_sample_rate", + .data = &i915_oa_max_sample_rate, + .maxlen = sizeof(i915_oa_max_sample_rate), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &oa_sample_rate_hard_limit, + }, {} };