<HTML><BODY><br><blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;">
Вторник, 19 ноября 2019, 1:19 +03:00 от Vladislav Shpilevoy <v.shpilevoy@tarantool.org>:<br><br><div id=""><div class="js-helper js-readmsg-msg"><div><div id="style_15741155561200641291_BODY">Hi! Thanks for the fixes!<br><br>
I suggest you to move all functions related to cpu and clock<br>
state to fiber.c and make them static there. In order not to<br>
pollute the global namespace with fiber's private functions.<br><br>
I did that in a commit above this one. You may squash, or redo,<br>
whatever:</div></div></div></div></blockquote><br>Hi! Thanks, I squashed.<br><blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;"><div id=""><div class="js-helper js-readmsg-msg"><div><div id="style_15741155561200641291_BODY"><br><br>
===================================================================<br><br>
diff --git a/src/lib/core/fiber.c b/src/lib/core/fiber.c<br>
index 1e08d0ec9..3faa198d3 100644<br>
--- a/src/lib/core/fiber.c<br>
+++ b/src/lib/core/fiber.c<br>
@@ -44,6 +44,112 @@<br><br>
#if ENABLE_FIBER_TOP<br>
#include <x86intrin.h> /* __rdtscp() */<br>
+<br>
+static inline void<br>
+clock_stat_add_delta(struct clock_stat *stat, uint64_t clock_delta)<br>
+{<br>
+ stat->delta += clock_delta;<br>
+}<br>
+<br>
+/**<br>
+ * Calculate the exponential moving average for the clock deltas<br>
+ * per loop iteration. The coeffitient is 1/16.<br>
+ */<br>
+static inline uint64_t<br>
+clock_diff_accumulate(uint64_t acc, uint64_t delta)<br>
+{<br>
+ if (acc > 0)<br>
+ return delta / 16 + 15 * acc / 16;<br>
+ else<br>
+ return delta;<br>
+}<br>
+<br>
+static inline void<br>
+clock_stat_update(struct clock_stat *stat, double nsec_per_clock)<br>
+{<br>
+ stat->acc = clock_diff_accumulate(stat->acc, stat->delta);<br>
+ stat->prev_delta = stat->delta;<br>
+ stat->cputime += stat->delta * nsec_per_clock;<br>
+ stat->delta = 0;<br>
+}<br>
+<br>
+static inline void<br>
+clock_stat_reset(struct clock_stat *stat)<br>
+{<br>
+ stat->acc = 0;<br>
+ stat->delta = 0;<br>
+ stat->prev_delta = 0;<br>
+ stat->cputime = 0;<br>
+}<br>
+<br>
+static void<br>
+cpu_stat_start(struct cpu_stat *stat)<br>
+{<br>
+ stat->prev_clock = __rdtscp(&stat->prev_cpu_id);<br>
+ stat->cpu_miss_count = 0;<br>
+ /*<br>
+ * We want to measure thread cpu time here to calculate<br>
+ * each fiber's cpu time, so don't use libev's ev_now() or<br>
+ * ev_time() since they use either monotonic or realtime<br>
+ * system clocks.<br>
+ */<br>
+ struct timespec ts;<br>
+ if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) != 0) {<br>
+ say_debug("clock_gettime(): failed to get this thread's"<br>
+ " cpu time.");<br>
+ return;<br>
+ }<br>
+ stat->prev_cputime = (uint64_t) ts.tv_sec * FIBER_TIME_RES + ts.tv_nsec;<br>
+}<br>
+<br>
+static inline void<br>
+cpu_stat_reset(struct cpu_stat *stat)<br>
+{<br>
+ stat->prev_cpu_miss_count = 0;<br>
+ cpu_stat_start(stat);<br>
+}<br>
+<br>
+static uint64_t<br>
+cpu_stat_on_csw(struct cpu_stat *stat)<br>
+{<br>
+ uint32_t cpu_id;<br>
+ uint64_t delta, clock = __rdtscp(&cpu_id);<br>
+<br>
+ if (cpu_id == stat->prev_cpu_id) {<br>
+ delta = clock - stat->prev_clock;<br>
+ } else {<br>
+ delta = 0;<br>
+ stat->prev_cpu_id = cpu_id;<br>
+ stat->cpu_miss_count++;<br>
+ }<br>
+ stat->prev_clock = clock;<br>
+<br>
+ return delta;<br>
+}<br>
+<br>
+static double<br>
+cpu_stat_end(struct cpu_stat *stat, struct clock_stat *cord_clock_stat)<br>
+{<br>
+ stat->prev_cpu_miss_count = stat->cpu_miss_count;<br>
+ stat->cpu_miss_count = 0;<br>
+<br>
+ struct timespec ts;<br>
+ uint64_t delta_time;<br>
+ double nsec_per_clock = 0;<br>
+ if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) != 0) {<br>
+ say_debug("clock_gettime(): failed to get this thread's"<br>
+ " cpu time.");<br>
+ } else {<br>
+ delta_time = (uint64_t) ts.tv_sec * FIBER_TIME_RES +<br>
+ ts.tv_nsec;<br>
+ if (delta_time > stat->prev_cputime && cord_clock_stat->delta > 0) {<br>
+ delta_time -= stat->prev_cputime;<br>
+ nsec_per_clock = (double) delta_time / cord()->clock_stat.delta;<br>
+ }<br>
+ }<br>
+ return nsec_per_clock;<br>
+}<br>
+<br>
#endif /* ENABLE_FIBER_TOP */<br><br>
#include "third_party/valgrind/memcheck.h"<br>
@@ -88,9 +194,6 @@ static int (*fiber_invoke)(fiber_func f, va_list ap);<br><br>
#if ENABLE_FIBER_TOP<br>
static __thread bool fiber_top_enabled = false;<br>
-<br>
-uint64_t<br>
-cpu_stat_on_csw(struct cpu_stat *stat);<br>
#endif /* ENABLE_FIBER_TOP */<br><br>
/**<br>
@@ -1091,112 +1194,6 @@ loop_on_iteration_start(ev_loop *loop, ev_check *watcher, int revents)<br>
cpu_stat_start(&cord()->cpu_stat);<br>
}<br><br>
-/**<br>
- * Calculate the exponential moving average for the clock deltas<br>
- * per loop iteration. The coeffitient is 1/16.<br>
- */<br>
-static inline uint64_t<br>
-clock_diff_accumulate(uint64_t acc, uint64_t delta)<br>
-{<br>
- if (acc > 0) {<br>
- return delta / 16 + 15 * acc / 16;<br>
- } else {<br>
- return delta;<br>
- }<br>
-}<br>
-<br>
-inline void<br>
-clock_stat_add_delta(struct clock_stat *stat, uint64_t clock_delta)<br>
-{<br>
- stat->delta += clock_delta;<br>
-}<br>
-<br>
-void<br>
-clock_stat_update(struct clock_stat *stat, double nsec_per_clock)<br>
-{<br>
- stat->acc = clock_diff_accumulate(stat->acc, stat->delta);<br>
- stat->prev_delta = stat->delta;<br>
- stat->cputime += stat->delta * nsec_per_clock;<br>
- stat->delta = 0;<br>
-}<br>
-<br>
-void<br>
-clock_stat_reset(struct clock_stat *stat)<br>
-{<br>
- stat->acc = 0;<br>
- stat->delta = 0;<br>
- stat->prev_delta = 0;<br>
- stat->cputime = 0;<br>
-}<br>
-<br>
-void<br>
-cpu_stat_start(struct cpu_stat *stat)<br>
-{<br>
- stat->prev_clock = __rdtscp(&stat->prev_cpu_id);<br>
- stat->cpu_miss_count = 0;<br>
- /*<br>
- * We want to measure thread cpu time here to calculate<br>
- * each fiber's cpu time, so don't use libev's ev_now() or<br>
- * ev_time() since they use either monotonic or realtime<br>
- * system clocks.<br>
- */<br>
- struct timespec ts;<br>
- if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) != 0) {<br>
- say_debug("clock_gettime(): failed to get this thread's"<br>
- " cpu time.");<br>
- return;<br>
- }<br>
- stat->prev_cputime = (uint64_t) ts.tv_sec * FIBER_TIME_RES + ts.tv_nsec;<br>
-}<br>
-<br>
-void<br>
-cpu_stat_reset(struct cpu_stat *stat)<br>
-{<br>
- stat->prev_cpu_miss_count = 0;<br>
- cpu_stat_start(stat);<br>
-}<br>
-<br>
-uint64_t<br>
-cpu_stat_on_csw(struct cpu_stat *stat)<br>
-{<br>
- uint32_t cpu_id;<br>
- uint64_t delta = 0;<br>
- uint64_t clock = __rdtscp(&cpu_id);<br>
-<br>
- if (cpu_id == stat->prev_cpu_id) {<br>
- delta = clock - stat->prev_clock;<br>
- } else {<br>
- stat->prev_cpu_id = cpu_id;<br>
- stat->cpu_miss_count++;<br>
- }<br>
- stat->prev_clock = clock;<br>
-<br>
- return delta;<br>
-}<br>
-<br>
-double<br>
-cpu_stat_end(struct cpu_stat *stat, struct clock_stat *cord_clock_stat)<br>
-{<br>
- stat->prev_cpu_miss_count = stat->cpu_miss_count;<br>
- stat->cpu_miss_count = 0;<br>
-<br>
- struct timespec ts;<br>
- uint64_t delta_time;<br>
- double nsec_per_clock = 0;<br>
- if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) != 0) {<br>
- say_debug("clock_gettime(): failed to get this thread's"<br>
- " cpu time.");<br>
- } else {<br>
- delta_time = (uint64_t) ts.tv_sec * FIBER_TIME_RES +<br>
- ts.tv_nsec;<br>
- if (delta_time > stat->prev_cputime && cord_clock_stat->delta > 0) {<br>
- delta_time -= stat->prev_cputime;<br>
- nsec_per_clock = (double) delta_time / cord()->clock_stat.delta;<br>
- }<br>
- }<br>
- return nsec_per_clock;<br>
-}<br>
-<br>
static void<br>
loop_on_iteration_end(ev_loop *loop, ev_prepare *watcher, int revents)<br>
{<br>
diff --git a/src/lib/core/fiber.h b/src/lib/core/fiber.h<br>
index 06ce28bb1..c5b975513 100644<br>
--- a/src/lib/core/fiber.h<br>
+++ b/src/lib/core/fiber.h<br>
@@ -91,15 +91,6 @@ struct clock_stat {<br>
uint64_t cputime;<br>
};<br><br>
-void<br>
-clock_stat_add_delta(struct clock_stat *stat, uint64_t clock_delta);<br>
-<br>
-void<br>
-clock_stat_update(struct clock_stat *stat, double nsec_per_clock);<br>
-<br>
-void<br>
-clock_stat_reset(struct clock_stat *stat);<br>
-<br>
/**<br>
* A struct encapsulating all knowledge this cord has about cpu<br>
* clocks and their state.<br>
@@ -119,18 +110,6 @@ struct cpu_stat {<br>
uint32_t prev_cpu_miss_count;<br>
};<br><br>
-void<br>
-cpu_stat_start(struct cpu_stat *stat);<br>
-<br>
-void<br>
-cpu_stat_reset(struct cpu_stat *stat);<br>
-<br>
-uint64_t<br>
-cpu_stat_on_csw(struct cpu_stat *stat);<br>
-<br>
-double<br>
-cpu_stat_end(struct cpu_stat *stat, struct clock_stat *cord_clock_stat);<br>
-<br>
#endif /* ENABLE_FIBER_TOP */<br><br>
enum { FIBER_NAME_MAX = 32 };<br></div></div></div></div></blockquote>
<br>
<br>-- <br>Sergey Petrenko<br></BODY></HTML>