From 8830d27022a4c303baab008ad5d4dfeef0c0ee8e Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Fri, 23 Aug 2013 15:34:50 +0000 Subject: [PATCH] - negative deviation factor --- src/testbed/test_testbed_api_sd.c | 11 +++++++---- src/testbed/testbed_api_operations.c | 16 +++++++++------- src/testbed/testbed_api_sd.c | 27 +++++++++++++++++---------- src/testbed/testbed_api_sd.h | 5 +++-- 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/testbed/test_testbed_api_sd.c b/src/testbed/test_testbed_api_sd.c index 343d1650a..d4fa7af84 100644 --- a/src/testbed/test_testbed_api_sd.c +++ b/src/testbed/test_testbed_api_sd.c @@ -48,24 +48,26 @@ run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *config) { struct SDHandle *h = GNUNET_TESTBED_SD_init_ (20); + int sd; ret = 0; GNUNET_TESTBED_SD_add_data_ (h, 40); - if (GNUNET_SYSERR != GNUNET_TESTBED_SD_deviation_factor_ (h, 10)) + if (GNUNET_SYSERR != GNUNET_TESTBED_SD_deviation_factor_ (h, 10, &sd)) { GNUNET_break (0); ret = 1; goto err; } GNUNET_TESTBED_SD_add_data_ (h, 30); - if (GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 80)) + if (GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 80, &sd)) { GNUNET_break (0); ret = 1; goto err; } GNUNET_TESTBED_SD_add_data_ (h, 40); - if (0 != GNUNET_TESTBED_SD_deviation_factor_ (h, 10)) + if ((GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 30, &sd)) + || (-2 != sd)) { GNUNET_break (0); ret = 1; @@ -73,7 +75,8 @@ run (void *cls, char *const *args, const char *cfgfile, } GNUNET_TESTBED_SD_add_data_ (h, 10); GNUNET_TESTBED_SD_add_data_ (h, 30); - if (3 != GNUNET_TESTBED_SD_deviation_factor_ (h, 60)) + if ((GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 60, &sd)) + || (3 != sd)) { GNUNET_break (0); ret = 1; diff --git a/src/testbed/testbed_api_operations.c b/src/testbed/testbed_api_operations.c index e1034a18c..c09ec366a 100644 --- a/src/testbed/testbed_api_operations.c +++ b/src/testbed/testbed_api_operations.c @@ -854,17 +854,19 @@ adapt_parallelism (struct OperationQueue *queue, int fail) } GNUNET_assert (nvals >= queue->max_active); avg = GNUNET_TIME_relative_divide (avg, nvals); - sd = GNUNET_TESTBED_SD_deviation_factor_ (fctx->sd, (unsigned int) - avg.rel_value_us); - if ( (sd <= 5) || - (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - queue->max_active)) ) - GNUNET_TESTBED_SD_add_data_ (fctx->sd, (unsigned int) avg.rel_value_us); - if (GNUNET_SYSERR == sd) + if (GNUNET_SYSERR == + GNUNET_TESTBED_SD_deviation_factor_ (fctx->sd, + (unsigned int) avg.rel_value_us, + &sd)) { + GNUNET_TESTBED_SD_add_data_ (fctx->sd, (unsigned int) avg.rel_value_us); adaptive_queue_set_max_active (queue, queue->max_active); /* no change */ return; } + if ((0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, queue->max_active))) + GNUNET_TESTBED_SD_add_data_ (fctx->sd, (unsigned int) avg.rel_value_us); + if (sd < 0) + sd = 0; GNUNET_assert (0 <= sd); if ((0 == sd) && (! fail)) { diff --git a/src/testbed/testbed_api_sd.c b/src/testbed/testbed_api_sd.c index cbafff08f..62f358de9 100644 --- a/src/testbed/testbed_api_sd.c +++ b/src/testbed/testbed_api_sd.c @@ -173,33 +173,40 @@ GNUNET_TESTBED_SD_add_data_ (struct SDHandle *h, unsigned int amount) /** - * Returns the factor by which the given amount differs from the standard deviation + * Calculates the factor by which the given amount differs * * @param h the SDhandle * @param amount the value for which the deviation is returned - - * @return the deviation from the average; GNUNET_SYSERR if the deviation cannot - * be calculated OR 0 if the given amount is less than or equal to the - * average; a maximum of 4 is returned for deviations equal to or - * larger than 4 + * @param factor the factor by which the given amont differs + * @return GNUNET_SYSERR if the deviation cannot + * be calculated; GNUNET_OK if the deviation is returned through factor */ int -GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount) +GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount, + int *factor) { double diff; - unsigned int n; + int f; + int n; if (h->cnt < 2) return GNUNET_SYSERR; if (((float) amount) > h->avg) + { diff = ((float) amount) - h->avg; + f = 1; + } else - return 0; //diff = h->avg - ((float) amount); + { + diff = h->avg - ((float) amount); + f = -1; + } diff *= diff; for (n = 1; n < 4; n++) if (diff < (((double) (n * n)) * h->vr)) break; - return n; + *factor = f * n; + return GNUNET_OK; } /* end of testbed_api_sd.c */ diff --git a/src/testbed/testbed_api_sd.h b/src/testbed/testbed_api_sd.h index abef1d9c7..b3e19c0bd 100644 --- a/src/testbed/testbed_api_sd.h +++ b/src/testbed/testbed_api_sd.h @@ -68,13 +68,14 @@ GNUNET_TESTBED_SD_add_data_ (struct SDHandle *h, unsigned int amount); * * @param h the SDhandle * @param amount the value for which the deviation is returned - + * @param factor the factor by which the given amont differs * @return the deviation from the average; GNUNET_SYSERR if the deviation cannot * be calculated OR 0 if the deviation is less than the average; a * maximum of 4 is returned for deviations equal to or larger than 4 */ int -GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount); +GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount, + int *factor); #endif /* end of testbed_api.h */ -- 2.25.1