summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/igt_stats.c27
-rw-r--r--lib/igt_stats.h3
-rw-r--r--lib/tests/igt_stats.c20
-rw-r--r--tools/skl_compute_wrpll.c2
4 files changed, 35 insertions, 17 deletions
diff --git a/lib/igt_stats.c b/lib/igt_stats.c
index 665f1c99..9032a685 100644
--- a/lib/igt_stats.c
+++ b/lib/igt_stats.c
@@ -97,15 +97,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 6ee3ae69..dd04097f 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 dfdc5072..6e4b233e 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 8b6fcd3a..0e5965cf 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++) {