Ensure that the payload message is filled with non-zero characters. 25/278625/5
authorAdam Michalski <a.michalski2@partner.samsung.com>
Fri, 22 Jul 2022 13:27:27 +0000 (15:27 +0200)
committerAdam Michalski <a.michalski2@partner.samsung.com>
Tue, 2 Aug 2022 14:36:56 +0000 (16:36 +0200)
Payload messages are filled with a cyclical character pattern
consisting of printable ASCII characters for debugging convenience.

Co-author: Michal Bloch <m.bloch@samsung.com>

Change-Id: I4c11508dc08ce7ca07977898d722c4ce4476677e

Makefile
benchmark/common.c
benchmark/common.h
benchmark/gdbus.c
benchmark/libdbus-p2p-client.cpp
benchmark/libdbus.c
benchmark/p2p-gdbus.c
benchmark/pipe.c
benchmark/sharedmem.c
benchmark/socket.c

index 5788af631a01674ee0612b367c92fa4de108bd7d..b8b8b0906117a332ab562241c5188934ddd197b1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -16,13 +16,13 @@ all: libdbus-p2p-client libdbus-p2p-server libdbus-p2p-common
        gcc $(CFLAGS) -o benchmark/p2p-gdbus $(DFTSRC) benchmark/p2p-gdbus.c $(LDFLAGS)
        gcc $(CFLAGS) -o benchmark/libdbus $(DFTSRC) benchmark/libdbus.c $(LDFLAGS)
 
-libdbus-p2p-client: benchmark/libdbus-p2p-client.cpp
+libdbus-p2p-client: benchmark/libdbus-p2p-client.cpp benchmark/common.c
        $(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o benchmark/$@
 
 libdbus-p2p-server: benchmark/libdbus-p2p-server.cpp
        $(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o benchmark/$@
 
-libdbus-p2p-common: benchmark/libdbus-p2p-common.cpp benchmark/libdbus-p2p-client.cpp benchmark/libdbus-p2p-server.cpp
+libdbus-p2p-common: benchmark/libdbus-p2p-common.cpp benchmark/libdbus-p2p-client.cpp benchmark/libdbus-p2p-server.cpp benchmark/common.c
        $(CXX) $(CXXFLAGS) -DLIBDBUS_P2P_COMMON $^ $(LDLIBS) -o benchmark/$@
 
 install:
index 43d4925b1bb96ed3d0284ecb8beb74bc5456622b..04d4888f0535f5dbd98dafea19451482574af687 100644 (file)
@@ -26,3 +26,15 @@ void print_help(char **argv)
        printf("-r: raw data mode (store every possible latency measurement in a csv file)\n");
        printf("-h: print help page\n");
 }
+
+void fill_string_with_offset(size_t size, char *str, size_t offset)
+{
+       /* Fills a string with some predictable garbage. This is so
+        * that strings change depending on the offset so as to minimize
+        * the possibility of caching etc., but is done using a trivial
+        * pattern for easier debugging. */
+
+       for (size_t i = 0; i < size - 1; ++i)
+               str[i] = '!' + (i + offset) % ('~' - '!' + 1);
+       str[size - 1] = '\0';
+}
index f55c3a77d490b1892107057bf2c4ec2fdc846502..fdef0d948b5dec73a628eda9d4a8d464331a9359 100644 (file)
@@ -4,6 +4,7 @@
 #include <fcntl.h>
 #include <time.h>
 #include <string.h>
+#include <stdbool.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
@@ -22,8 +23,8 @@
 
 #define        ONE_PAGE_SIZE   4096
 
-typedef        enum {false, true}      bool;
 void print_help(char **argv);
 int cpu_pin(int cpuid, int pid);
+void fill_string_with_offset(size_t size, char *str, size_t offset);
 
 #endif
index 96b82ef9181fd9efdcdbec452b759868d49e7a79..b9a02f7925085c726a641396080f6016a8e0a0d9 100644 (file)
@@ -198,7 +198,8 @@ void Send(register int size, const char *name, const char *path, bool is_lt)
        for(int i = 0; i < WARMUP_TRY + n_real_tries; i++) {
                struct timespec clock;
 
-               memset(cptr, 0, size);
+               fill_string_with_offset(size, cptr, i);
+
                if(i >= WARMUP_TRY)
                        cptr[0] = 'r';
                else
index 6b3d434e991480997dc67717c897d4523ea8d651..9d1367931a61046952563f40f2a0814340bc09b9 100644 (file)
@@ -20,6 +20,8 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE. */
 
+#include "common.h"
+
 #include <dbus/dbus.h>
 
 #include <unistd.h>
@@ -139,6 +141,8 @@ int main_client (int argc, char ** argv)
        auto message = new char [opt.payload];
 
        for (size_t i = 0; i < opt.try_count; ++i) {
+               fill_string_with_offset (opt.payload, message, i);
+
                auto * const msg = dbus_message_new_method_call
                        ( TEST_NAME
                        , TEST_PATH
index a5d645b985eaa126c35fa9c3eee5547fbee5cf09..84f1df79c15cbd6339d55c2fd7ab27542207f90c 100644 (file)
@@ -163,7 +163,8 @@ void Send(register int size, const char *name, const char *path, const char *cli
        for(int i = 0; i < WARMUP_TRY + n_real_tries; i++) {
                struct timespec clock;
 
-               memset(cptr, 0, size);
+               fill_string_with_offset(size, cptr, i);
+
                if(i >= WARMUP_TRY)
                        cptr[0] = 'r';
                else
index 4285efb7312544c5dc09443e11c4c8df5d799d8e..f99b6bb1fafdd1c6d8af4c8914f81e6e59f8baa2 100644 (file)
@@ -339,7 +339,7 @@ void Send(int size, const char *name, const char *path, const char *number, bool
        GError *error = NULL;
        register char *cptr = malloc(size);
        unsigned long long start;
-       int i, j;
+       int i;
 
        char dbus_test_svc_name[strlen(DBUS_TEST_SVC_NAME) + strlen(number) + 1];
        strncpy(&dbus_test_svc_name[0], DBUS_TEST_SVC_NAME, strlen(DBUS_TEST_SVC_NAME)+1);
@@ -364,9 +364,7 @@ void Send(int size, const char *name, const char *path, const char *number, bool
 
        sleep(2);
        for (i = 0; i < WARMUP_TRY + n_real_tries; ++i) {
-               for (j = 0; j < size-1; ++j)
-                       cptr[j] = '!' + (j + i) % ('~' - '!' + 1);
-               cptr[size-1] = '\0';
+               fill_string_with_offset(size, cptr, i);
 
                if (i >= WARMUP_TRY)
                        cptr[0] = 'R';
index be7bb9184adb600c8931733766574682b7369d81..f0b39073d980df32a3b9bf3fbe5ba655b284cd8f 100644 (file)
@@ -91,7 +91,8 @@ void Send(int wfd1, int wfd2, register int size, bool is_lt)
                int wres1, wres2;
                struct timespec clock;
 
-               memset(cptr, 0, size);
+               fill_string_with_offset(size, cptr, i);
+
                if(i >= WARMUP_TRY)
                        cptr[0] = 'r';
                else
index fe4ba9891572430bb0df6dda35aa21aec40840d6..e9944737a2d799c8684c91d8d5e8307f9f1e659e 100644 (file)
@@ -107,7 +107,8 @@ repeat:
                        goto repeat;
                }
 
-               memset(cptr, 0, size);
+               fill_string_with_offset(size, cptr, i);
+
                if(i >= WARMUP_TRY)
                        cptr[0] = 'r';
                else
index b3f17edbdf0d5809e67b1af0d485874e033de708..01d24d3e7ef11c1ae0db077c575cb24878597af1 100644 (file)
@@ -91,7 +91,8 @@ void Send(int wfd1, int wfd2, register int size, bool is_lt)
                int wres1, wres2;
                struct timespec clock;
 
-               memset(cptr, 0, size);
+               fill_string_with_offset(size, cptr, i);
+
                if(i >= WARMUP_TRY)
                        cptr[0] = 'r';
                else