summaryrefslogtreecommitdiff
path: root/tools/skl_compute_wrpll.c
diff options
context:
space:
mode:
authorDamien Lespiau <damien.lespiau@intel.com>2015-06-25 14:18:34 +0100
committerDamien Lespiau <damien.lespiau@intel.com>2015-06-25 17:22:04 +0100
commitdfebf08d9a21146e4d53ddb684e71b934d96bc59 (patch)
treed53b7c5dd49a0a07c6e6153a5cd1727909f71364 /tools/skl_compute_wrpll.c
parentafdaeabbcfd9a2fd1b27b8742681d52d12161dd0 (diff)
skl_compute_wrpll: Fix the mininum deviation computation
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 <damien.lespiau@intel.com>
Diffstat (limited to 'tools/skl_compute_wrpll.c')
-rw-r--r--tools/skl_compute_wrpll.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/tools/skl_compute_wrpll.c b/tools/skl_compute_wrpll.c
index 3a2d029d..5468b58b 100644
--- a/tools/skl_compute_wrpll.c
+++ b/tools/skl_compute_wrpll.c
@@ -23,6 +23,7 @@
#include <assert.h>
#include <inttypes.h>
+#include <limits.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
@@ -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;