summaryrefslogtreecommitdiffstats
path: root/src/kernel/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/utils.c')
-rw-r--r--src/kernel/utils.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/kernel/utils.c b/src/kernel/utils.c
index 957d69b..164d51a 100644
--- a/src/kernel/utils.c
+++ b/src/kernel/utils.c
@@ -2,6 +2,7 @@
* This file is part of the Distributed Network Block Device 3
*
* Copyright(c) 2011-2012 Johann Latocha <johann@latocha.de>
+ * Copyright(c) 2019 Frederic Robra <frederic@robra.org>
*
* This file may be licensed under the terms of of the
* GNU General Public License Version 2 (the ``GPL'').
@@ -19,6 +20,7 @@
*/
#include "utils.h"
+#include "clientconfig.h"
#include <linux/kernel.h>
@@ -40,3 +42,20 @@ void inet_ntoa(struct in_addr addr, char *str)
unsigned char *ptr = (unsigned char *) &addr;
sprintf(str, "%d.%d.%d.%d", ptr[0] & 0xff, ptr[1] & 0xff, ptr[2] & 0xff, ptr[3] & 0xff);
}
+
+uint64_t dnbd3_average_rtt(struct dnbd3_server *server)
+{
+ int i, j = 0;
+ uint64_t avg = 0;
+ for (i = 0; i < 4; i++) {
+ avg += server->rtts[i];
+ j += server->rtts[i] == 0 ? 0 : 1;
+ }
+ if (avg == 0) {
+ return RTT_UNKNOWN;
+ } else {
+ avg = avg / j;
+ avg += server->failures * avg / 10;
+ return avg;
+ }
+}