kdbus benchmark: use realtime clock instead of thread 02/308502/1
authorMichal Bloch <m.bloch@samsung.com>
Mon, 25 Mar 2024 17:32:06 +0000 (18:32 +0100)
committerMichal Bloch <m.bloch@samsung.com>
Mon, 25 Mar 2024 17:32:10 +0000 (18:32 +0100)
* other benchmarks (binder; other kdbus tests from dbus-tools)
  use the REALTIME clock so we should use the same clock type.

* using per-thread clock won't make much sense with more threads.

Change-Id: I68ca1dd26466f6635385019d65b6815fa751972d
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
tests/kdbus/test-benchmark.c

index 8b846719f6afc08d1f2fb9de90e2456304f0f8a8..f7c64a5a49feeb989e67cf710f0bc5250d2b83f6 100644 (file)
@@ -75,7 +75,7 @@ static void add_stats(uint64_t prev)
 {
        uint64_t diff, latency_avg_prev;
 
-       diff = now(CLOCK_THREAD_CPUTIME_ID) - prev;
+       diff = now(CLOCK_REALTIME) - prev;
 
        stats.count++;
        stats.latency_acc += diff;
@@ -173,7 +173,7 @@ send_echo_request(struct kdbus_conn *conn, void *kdbus_msg, off_t memfd_item_off
        int ret;
 
        if (use_memfd) {
-               uint64_t now_ns = now(CLOCK_THREAD_CPUTIME_ID);
+               uint64_t now_ns = now(CLOCK_REALTIME);
                struct kdbus_item *item = memfd_item_offset + kdbus_msg;
                memfd = sys_memfd_create("memfd-name", 0);
                ASSERT_RETURN_VAL(memfd,>=,0, memfd);
@@ -306,10 +306,10 @@ static wur int benchmark(struct kdbus_test_env *env)
                fds[0].fd = conn_a->fd;
                fds[1].fd = conn_b->fd;
 
-               start = now(CLOCK_THREAD_CPUTIME_ID);
+               start = now(CLOCK_REALTIME);
                reset_stats();
 
-               send_ns = now(CLOCK_THREAD_CPUTIME_ID);
+               send_ns = now(CLOCK_REALTIME);
                ASSERT_ZERO(send_echo_request(conn_b, kdbus_msg, memfd_cached_offset));
 
                while (1) {
@@ -327,11 +327,11 @@ static wur int benchmark(struct kdbus_test_env *env)
                        if (fds[0].revents & POLLIN) {
                                ASSERT_ZERO(handle_echo_reply(conn_a, send_ns));
 
-                               send_ns = now(CLOCK_THREAD_CPUTIME_ID);
+                               send_ns = now(CLOCK_REALTIME);
                                ASSERT_ZERO(send_echo_request(conn_b, kdbus_msg, memfd_cached_offset));
                        }
 
-                       now_ns = now(CLOCK_THREAD_CPUTIME_ID);
+                       now_ns = now(CLOCK_REALTIME);
                        diff = now_ns - start;
                        if (diff > 1000000000ULL) {
                                start = now_ns;
@@ -353,10 +353,10 @@ static wur int benchmark(struct kdbus_test_env *env)
                /* cancel any pending message */
                UNUSED(read(uds[1], buf, sizeof(buf)));
 
-               start = now(CLOCK_THREAD_CPUTIME_ID);
+               start = now(CLOCK_REALTIME);
                reset_stats();
 
-               send_ns = now(CLOCK_THREAD_CPUTIME_ID);
+               send_ns = now(CLOCK_REALTIME);
                ASSERT_RETURN((typeof(write(uds[0], stress_payload, sizeof(stress_payload))))sizeof(stress_payload),==,write(uds[0], stress_payload, sizeof(stress_payload)));
 
                while (1) {
@@ -376,11 +376,11 @@ static wur int benchmark(struct kdbus_test_env *env)
 
                                add_stats(send_ns);
 
-                               send_ns = now(CLOCK_THREAD_CPUTIME_ID);
+                               send_ns = now(CLOCK_REALTIME);
                                ASSERT_RETURN((typeof(write(uds[0], buf, sizeof(buf))))sizeof(buf),==,write(uds[0], buf, sizeof(buf)));
                        }
 
-                       now_ns = now(CLOCK_THREAD_CPUTIME_ID);
+                       now_ns = now(CLOCK_REALTIME);
                        diff = now_ns - start;
                        if (diff > 1000000000ULL) {
                                start = now_ns;