From patchwork Sat Jun 27 17:07:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lespiau, Damien" X-Patchwork-Id: 6685341 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 74B939F39B for ; Sat, 27 Jun 2015 17:08:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7BDD1204CF for ; Sat, 27 Jun 2015 17:07:59 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 6EFDC204D3 for ; Sat, 27 Jun 2015 17:07:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 13CAC6E74E; Sat, 27 Jun 2015 10:07:58 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTP id 93BEC6E74E for ; Sat, 27 Jun 2015 10:07:56 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP; 27 Jun 2015 10:07:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,690,1427785200"; d="scan'208";a="595849327" Received: from kczmudzi-mobl4.amr.corp.intel.com (HELO strange.ger.corp.intel.com) ([10.252.53.243]) by orsmga003.jf.intel.com with ESMTP; 27 Jun 2015 10:07:55 -0700 From: Damien Lespiau To: intel-gfx@lists.freedesktop.org Date: Sat, 27 Jun 2015 18:07:48 +0100 Message-Id: <1435424869-17455-3-git-send-email-damien.lespiau@intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1435424869-17455-1-git-send-email-damien.lespiau@intel.com> References: <1435424869-17455-1-git-send-email-damien.lespiau@intel.com> Subject: [Intel-gfx] [PATCH i-g-t 2/3] stats: Spwan igt_init_with_size() from igt_init() 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 It's all about good looking APIs. Signed-off-by: Damien Lespiau --- lib/igt_stats.c | 27 ++++++++++++++++++++++----- lib/igt_stats.h | 3 ++- lib/tests/igt_stats.c | 20 ++++++++++---------- tools/skl_compute_wrpll.c | 2 +- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/lib/igt_stats.c b/lib/igt_stats.c index cd97ab0..6b867e3 100644 --- a/lib/igt_stats.c +++ b/lib/igt_stats.c @@ -101,15 +101,32 @@ static void igt_stats_ensure_capacity(igt_stats_t *stats, /** * igt_stats_init: * @stats: An #igt_stats_t instance + * + * Initializes an #igt_stats_t instance. igt_stats_fini() must be called once + * finished with @stats. + */ +void igt_stats_init(igt_stats_t *stats) +{ + memset(stats, 0, sizeof(*stats)); + + igt_stats_ensure_capacity(stats, 128); + + stats->min = U64_MAX; + stats->max = 0; +} + +/** + * igt_stats_init_with_size: + * @stats: An #igt_stats_t instance * @capacity: Number of data samples @stats can contain * - * Initializes an #igt_stats_t instance to hold @capacity samples. - * igt_stats_fini() must be called once finished with @stats. + * Like igt_stats_init() but with a size to avoid reallocating the underlying + * array(s) when pushing new values. Useful if we have a good idea of the + * number of data points we want @stats to hold. * - * We currently assume the user knows how many data samples upfront and there's - * no need to grow the array of values. + * igt_stats_fini() must be called once finished with @stats. */ -void igt_stats_init(igt_stats_t *stats, unsigned int capacity) +void igt_stats_init_with_size(igt_stats_t *stats, unsigned int capacity) { memset(stats, 0, sizeof(*stats)); diff --git a/lib/igt_stats.h b/lib/igt_stats.h index 6ee3ae6..dd04097 100644 --- a/lib/igt_stats.h +++ b/lib/igt_stats.h @@ -47,7 +47,8 @@ typedef struct { uint64_t *sorted; } igt_stats_t; -void igt_stats_init(igt_stats_t *stats, unsigned int capacity); +void igt_stats_init(igt_stats_t *stats); +void igt_stats_init_with_size(igt_stats_t *stats, unsigned int capacity); void igt_stats_fini(igt_stats_t *stats); bool igt_stats_is_population(igt_stats_t *stats); void igt_stats_set_population(igt_stats_t *stats, bool full_population); diff --git a/lib/tests/igt_stats.c b/lib/tests/igt_stats.c index dfdc507..6e4b233 100644 --- a/lib/tests/igt_stats.c +++ b/lib/tests/igt_stats.c @@ -42,7 +42,7 @@ static void test_init_zero(void) igt_stats_t stats; stats.mean = 1.; - igt_stats_init(&stats, 2); + igt_stats_init(&stats); igt_assert_eq_double(stats.mean, 0.); } @@ -50,7 +50,7 @@ static void test_init(void) { igt_stats_t stats; - igt_stats_init(&stats, 2); + igt_stats_init(&stats); /* * Make sure we default to representing only a sample of a bigger @@ -63,7 +63,7 @@ static void test_min_max(void) { igt_stats_t stats; - igt_stats_init(&stats, 5); + igt_stats_init(&stats); push_fixture_1(&stats); igt_assert(igt_stats_get_min(&stats) == 2); @@ -74,7 +74,7 @@ static void test_range(void) { igt_stats_t stats; - igt_stats_init(&stats, 5); + igt_stats_init(&stats); push_fixture_1(&stats); igt_assert(igt_stats_get_range(&stats) == 8); @@ -94,7 +94,7 @@ static void test_quartiles(void) double q1, q2, q3; /* s1, odd number of data points */ - igt_stats_init(&stats, ARRAY_SIZE(s1)); + igt_stats_init(&stats); igt_stats_push_array(&stats, s1, ARRAY_SIZE(s1)); igt_stats_get_quartiles(&stats, &q1, &q2, &q3); @@ -107,7 +107,7 @@ static void test_quartiles(void) igt_stats_fini(&stats); /* s1, even number of data points */ - igt_stats_init(&stats, ARRAY_SIZE(s2)); + igt_stats_init(&stats); igt_stats_push_array(&stats, s2, ARRAY_SIZE(s2)); igt_stats_get_quartiles(&stats, &q1, &q2, &q3); @@ -127,7 +127,7 @@ static void test_invalidate_sorted(void) { 47, 49, 6, 7, 15, 36, 39, 40, 41, 42}; double median1, median2; - igt_stats_init(&stats, ARRAY_SIZE(s1_truncated) + 1); + igt_stats_init(&stats); igt_stats_push_array(&stats, s1_truncated, ARRAY_SIZE(s1_truncated)); median1 = igt_stats_get_median(&stats); @@ -143,7 +143,7 @@ static void test_mean(void) igt_stats_t stats; double mean; - igt_stats_init(&stats, 5); + igt_stats_init(&stats); push_fixture_1(&stats); mean = igt_stats_get_mean(&stats); @@ -157,7 +157,7 @@ static void test_invalidate_mean(void) igt_stats_t stats; double mean1, mean2; - igt_stats_init(&stats, 6); + igt_stats_init(&stats); push_fixture_1(&stats); mean1 = igt_stats_get_mean(&stats); @@ -180,7 +180,7 @@ static void test_std_deviation(void) igt_stats_t stats; double mean, variance, std_deviation; - igt_stats_init(&stats, 8); + igt_stats_init(&stats); igt_stats_set_population(&stats, true); igt_stats_push(&stats, 2); diff --git a/tools/skl_compute_wrpll.c b/tools/skl_compute_wrpll.c index 8b6fcd3..0e5965c 100644 --- a/tools/skl_compute_wrpll.c +++ b/tools/skl_compute_wrpll.c @@ -866,7 +866,7 @@ static void test_run(struct test_ops *test) unsigned p_odd_even[2] = { 0, 0 }; igt_stats_t stats; - igt_stats_init(&stats, ARRAY_SIZE(modes)); + igt_stats_init_with_size(&stats, ARRAY_SIZE(modes)); igt_stats_set_population(&stats, true); for (m = 0; m < ARRAY_SIZE(modes); m++) {