diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-08-11 21:21:56 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-08-11 21:21:56 +0000 |
commit | 3d7fefedc9ba60bd8e8448efe8b628446d958536 (patch) | |
tree | 61ce41a52cd6e7232cead77818ef265993b2427e /src/util/bandwidth.c | |
parent | 4a0398474db197abed243a123fb971fbeeffab4b (diff) | |
download | gnunet-3d7fefedc9ba60bd8e8448efe8b628446d958536.tar.gz gnunet-3d7fefedc9ba60bd8e8448efe8b628446d958536.zip |
changing time measurement from milliseconds to microseconds
Diffstat (limited to 'src/util/bandwidth.c')
-rw-r--r-- | src/util/bandwidth.c | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/src/util/bandwidth.c b/src/util/bandwidth.c index 60cb50529..5caaec03c 100644 --- a/src/util/bandwidth.c +++ b/src/util/bandwidth.c | |||
@@ -1,10 +1,10 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2010 Christian Grothoff (and other contributing authors) | 3 | (C) 2010, 2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
7 | by the Free Software Foundation; either version 2, or (at your | 7 | by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | 8 | option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
@@ -83,9 +83,9 @@ GNUNET_BANDWIDTH_value_get_available_until (struct GNUNET_BANDWIDTH_Value32NBO | |||
83 | b = ntohl (bps.value__); | 83 | b = ntohl (bps.value__); |
84 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 84 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
85 | "Bandwidth has %llu bytes available until deadline in %s\n", | 85 | "Bandwidth has %llu bytes available until deadline in %s\n", |
86 | (unsigned long long) ((b * deadline.rel_value + 500LL) / 1000LL), | 86 | (unsigned long long) ((b * deadline.rel_value_us + 500000LL) / 1000000LL), |
87 | GNUNET_STRINGS_relative_time_to_string (deadline, GNUNET_YES)); | 87 | GNUNET_STRINGS_relative_time_to_string (deadline, GNUNET_YES)); |
88 | return (b * deadline.rel_value + 500LL) / 1000LL; | 88 | return (b * deadline.rel_value_us + 500000LL) / 1000000LL; |
89 | } | 89 | } |
90 | 90 | ||
91 | 91 | ||
@@ -105,16 +105,17 @@ GNUNET_BANDWIDTH_value_get_delay_for (struct GNUNET_BANDWIDTH_Value32NBO bps, | |||
105 | struct GNUNET_TIME_Relative ret; | 105 | struct GNUNET_TIME_Relative ret; |
106 | 106 | ||
107 | b = ntohl (bps.value__); | 107 | b = ntohl (bps.value__); |
108 | if (b == 0) | 108 | if (0 == b) |
109 | { | 109 | { |
110 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 110 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
111 | "Bandwidth suggests delay of infinity (zero bandwidth)\n"); | 111 | "Bandwidth suggests delay of infinity (zero bandwidth)\n"); |
112 | return GNUNET_TIME_UNIT_FOREVER_REL; | 112 | return GNUNET_TIME_UNIT_FOREVER_REL; |
113 | } | 113 | } |
114 | ret.rel_value = size * 1000LL / b; | 114 | ret.rel_value_us = size * 1000LL * 1000LL / b; |
115 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 115 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
116 | "Bandwidth suggests delay of %llu ms for %llu bytes of traffic\n", | 116 | "Bandwidth suggests delay of %s for %llu bytes of traffic\n", |
117 | (unsigned long long) ret.rel_value, (unsigned long long) size); | 117 | GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES), |
118 | (unsigned long long) size); | ||
118 | return ret; | 119 | return ret; |
119 | } | 120 | } |
120 | 121 | ||
@@ -158,16 +159,17 @@ static void | |||
158 | update_tracker (struct GNUNET_BANDWIDTH_Tracker *av) | 159 | update_tracker (struct GNUNET_BANDWIDTH_Tracker *av) |
159 | { | 160 | { |
160 | struct GNUNET_TIME_Absolute now; | 161 | struct GNUNET_TIME_Absolute now; |
162 | struct GNUNET_TIME_Relative delta; | ||
161 | uint64_t delta_time; | 163 | uint64_t delta_time; |
162 | uint64_t delta_avail; | 164 | uint64_t delta_avail; |
163 | uint64_t left_bytes; | 165 | uint64_t left_bytes; |
164 | uint64_t max_carry; | 166 | uint64_t max_carry; |
165 | 167 | ||
166 | now = GNUNET_TIME_absolute_get (); | 168 | now = GNUNET_TIME_absolute_get (); |
167 | delta_time = now.abs_value - av->last_update__.abs_value; | 169 | delta_time = now.abs_value_us - av->last_update__.abs_value_us; |
168 | delta_avail = | 170 | delta_avail = |
169 | (delta_time * ((unsigned long long) av->available_bytes_per_s__) + | 171 | (delta_time * ((unsigned long long) av->available_bytes_per_s__) + |
170 | 500LL) / 1000LL; | 172 | 500000LL) / 1000000LL; |
171 | av->consumption_since_last_update__ -= delta_avail; | 173 | av->consumption_since_last_update__ -= delta_avail; |
172 | av->last_update__ = now; | 174 | av->last_update__ = now; |
173 | if (av->consumption_since_last_update__ < 0) | 175 | if (av->consumption_since_last_update__ < 0) |
@@ -181,10 +183,11 @@ update_tracker (struct GNUNET_BANDWIDTH_Tracker *av) | |||
181 | else | 183 | else |
182 | av->consumption_since_last_update__ = -max_carry; | 184 | av->consumption_since_last_update__ = -max_carry; |
183 | } | 185 | } |
186 | delta.rel_value_us = delta_time; | ||
184 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 187 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
185 | "Tracker %p updated, have %u Bps, last update was %llu ms ago\n", av, | 188 | "Tracker %p updated, have %u Bps, last update was %s ago\n", av, |
186 | (unsigned int) av->available_bytes_per_s__, | 189 | (unsigned int) av->available_bytes_per_s__, |
187 | (unsigned long long) delta_time); | 190 | GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_YES)); |
188 | } | 191 | } |
189 | 192 | ||
190 | 193 | ||
@@ -251,22 +254,26 @@ GNUNET_BANDWIDTH_tracker_get_delay (struct GNUNET_BANDWIDTH_Tracker *av, | |||
251 | 254 | ||
252 | if (av->available_bytes_per_s__ == 0) | 255 | if (av->available_bytes_per_s__ == 0) |
253 | { | 256 | { |
254 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay is infinity\n", av); | 257 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
258 | "Tracker %p delay is infinity\n", av); | ||
255 | return GNUNET_TIME_UNIT_FOREVER_REL; | 259 | return GNUNET_TIME_UNIT_FOREVER_REL; |
256 | } | 260 | } |
257 | update_tracker (av); | 261 | update_tracker (av); |
258 | bytes_needed = size + av->consumption_since_last_update__; | 262 | bytes_needed = size + av->consumption_since_last_update__; |
259 | if (bytes_needed <= 0) | 263 | if (bytes_needed <= 0) |
260 | { | 264 | { |
261 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay for %u bytes is zero\n", av, | 265 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
266 | "Tracker %p delay for %u bytes is zero\n", av, | ||
262 | (unsigned int) size); | 267 | (unsigned int) size); |
263 | return GNUNET_TIME_UNIT_ZERO; | 268 | return GNUNET_TIME_UNIT_ZERO; |
264 | } | 269 | } |
265 | ret.rel_value = | 270 | ret.rel_value_us = |
266 | (1000LL * bytes_needed) / | 271 | (1000LL * 1000LL * bytes_needed) / |
267 | (unsigned long long) av->available_bytes_per_s__; | 272 | (unsigned long long) av->available_bytes_per_s__; |
268 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p delay for %u bytes is %llu ms\n", | 273 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
269 | av, (unsigned int) size, (unsigned long long) ret.rel_value); | 274 | "Tracker %p delay for %u bytes is %s\n", |
275 | av, (unsigned int) size, | ||
276 | GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES)); | ||
270 | return ret; | 277 | return ret; |
271 | } | 278 | } |
272 | 279 | ||
@@ -293,7 +300,7 @@ GNUNET_BANDWIDTH_tracker_get_available (struct GNUNET_BANDWIDTH_Tracker * av) | |||
293 | (av->last_update__)); | 300 | (av->last_update__)); |
294 | used = av->consumption_since_last_update__; | 301 | used = av->consumption_since_last_update__; |
295 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 302 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
296 | "Tracker %p available bandwidth is %lld bytes\n", av, | 303 | "Tracker %p available bandwidth is %lld bytes\n", av, |
297 | (long long) (int64_t) (avail - used)); | 304 | (long long) (int64_t) (avail - used)); |
298 | return (int64_t) (avail - used); | 305 | return (int64_t) (avail - used); |
299 | } | 306 | } |
@@ -314,7 +321,8 @@ GNUNET_BANDWIDTH_tracker_update_quota (struct GNUNET_BANDWIDTH_Tracker *av, | |||
314 | uint32_t new_limit; | 321 | uint32_t new_limit; |
315 | 322 | ||
316 | new_limit = ntohl (bytes_per_second_limit.value__); | 323 | new_limit = ntohl (bytes_per_second_limit.value__); |
317 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p bandwidth changed to %u Bps\n", av, | 324 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
325 | "Tracker %p bandwidth changed to %u Bps\n", av, | ||
318 | (unsigned int) new_limit); | 326 | (unsigned int) new_limit); |
319 | update_tracker (av); | 327 | update_tracker (av); |
320 | old_limit = av->available_bytes_per_s__; | 328 | old_limit = av->available_bytes_per_s__; |