From patchwork Thu Jun 25 15:21:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lespiau, Damien" X-Patchwork-Id: 6676041 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B5B73C05AD for ; Thu, 25 Jun 2015 15:21:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D7D0A205DE for ; Thu, 25 Jun 2015 15:21:52 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id F3D29206CB for ; Thu, 25 Jun 2015 15:21:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 759F26EC56; Thu, 25 Jun 2015 08:21:51 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTP id B3DD96EC55 for ; Thu, 25 Jun 2015 08:21:49 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP; 25 Jun 2015 08:21:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,677,1427785200"; d="scan'208";a="717572061" Received: from unknown (HELO strange.ger.corp.intel.com) ([10.252.34.49]) by orsmga001.jf.intel.com with ESMTP; 25 Jun 2015 08:21:49 -0700 From: Damien Lespiau To: intel-gfx@lists.freedesktop.org Date: Thu, 25 Jun 2015 16:21:43 +0100 Message-Id: <1435245703-31083-4-git-send-email-damien.lespiau@intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1435245703-31083-1-git-send-email-damien.lespiau@intel.com> References: <1435245703-31083-1-git-send-email-damien.lespiau@intel.com> Subject: [Intel-gfx] [PATCH i-g-t 4/4] skl_compute_wrpll: Fix the mininum deviation computation X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Paulo noticed that, because we were only comparing positive deviations with positive deviations and negative deviations with negative deviations, we weren't actually always using the absolute minimal deviation at all. This improves the average deviation across all tested frequencies (373): before: average deviation: 215.13 after: average deviation: 194.47 Signed-off-by: Damien Lespiau --- tools/skl_compute_wrpll.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tools/skl_compute_wrpll.c b/tools/skl_compute_wrpll.c index 3a2d029..5468b58 100644 --- a/tools/skl_compute_wrpll.c +++ b/tools/skl_compute_wrpll.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -31,6 +32,7 @@ #include "igt_stats.h" +#define U64_MAX ((uint64_t)~0ULL) #define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0])) #define WARN(cond, msg) printf(msg) @@ -255,8 +257,7 @@ found: } struct skl_wrpll_context { - uint32_t min_pdeviation; /* record the minimum deviations to */ - uint32_t min_ndeviation; /* compare candidates */ + uint64_t min_deviation; /* current minimal deviation */ uint64_t central_freq; /* chosen central freq */ uint64_t dco_freq; /* chosen dco freq */ unsigned int p; /* chosen divider */ @@ -266,11 +267,12 @@ static void skl_wrpll_context_init(struct skl_wrpll_context *ctx) { memset(ctx, 0, sizeof(*ctx)); - /* DCO freq must be within +1%/-6% of the DCO central freq */ - ctx->min_pdeviation = 100; - ctx-> min_ndeviation = 600; + ctx->min_deviation = U64_MAX; } +#define SKL_MAX_PDEVIATION 100 +#define SKL_MAX_NDEVIATION 600 + static void skl_wrpll_try_divider(struct skl_wrpll_context *ctx, uint64_t central_freq, uint64_t dco_freq, @@ -284,8 +286,9 @@ static void skl_wrpll_try_divider(struct skl_wrpll_context *ctx, /* positive deviation */ if (dco_freq >= central_freq) { - if (deviation < ctx->min_pdeviation) { - ctx->min_pdeviation = deviation; + if (deviation < SKL_MAX_PDEVIATION && + deviation < ctx->min_deviation) { + ctx->min_deviation = deviation; ctx->central_freq = central_freq; ctx->dco_freq = dco_freq; ctx->p = divider; @@ -294,8 +297,9 @@ static void skl_wrpll_try_divider(struct skl_wrpll_context *ctx, #endif } /* negative deviation */ - } else if (deviation < ctx->min_ndeviation) { - ctx->min_ndeviation = deviation; + } else if (deviation < SKL_MAX_NDEVIATION && + deviation < ctx->min_deviation) { + ctx->min_deviation = deviation; ctx->central_freq = central_freq; ctx->dco_freq = dco_freq; ctx->p = divider;