From f584d59335ae3de01237ab406a0c67f1dbc6224e Mon Sep 17 00:00:00 2001 From: Adam Michalski Date: Fri, 22 Jul 2022 15:27:27 +0200 Subject: [PATCH] Ensure that the payload message is filled with non-zero characters. Payload messages are filled with a cyclical character pattern consisting of printable ASCII characters for debugging convenience. Co-author: Michal Bloch Change-Id: I4c11508dc08ce7ca07977898d722c4ce4476677e --- Makefile | 4 ++-- benchmark/common.c | 12 ++++++++++++ benchmark/common.h | 3 ++- benchmark/gdbus.c | 3 ++- benchmark/libdbus-p2p-client.cpp | 4 ++++ benchmark/libdbus.c | 3 ++- benchmark/p2p-gdbus.c | 6 ++---- benchmark/pipe.c | 3 ++- benchmark/sharedmem.c | 3 ++- benchmark/socket.c | 3 ++- 10 files changed, 32 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 5788af6..b8b8b09 100644 --- 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: diff --git a/benchmark/common.c b/benchmark/common.c index 43d4925..04d4888 100644 --- a/benchmark/common.c +++ b/benchmark/common.c @@ -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'; +} diff --git a/benchmark/common.h b/benchmark/common.h index f55c3a7..fdef0d9 100644 --- a/benchmark/common.h +++ b/benchmark/common.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -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 diff --git a/benchmark/gdbus.c b/benchmark/gdbus.c index 96b82ef..b9a02f7 100644 --- a/benchmark/gdbus.c +++ b/benchmark/gdbus.c @@ -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 diff --git a/benchmark/libdbus-p2p-client.cpp b/benchmark/libdbus-p2p-client.cpp index 6b3d434..9d13679 100644 --- a/benchmark/libdbus-p2p-client.cpp +++ b/benchmark/libdbus-p2p-client.cpp @@ -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 #include @@ -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 diff --git a/benchmark/libdbus.c b/benchmark/libdbus.c index a5d645b..84f1df7 100644 --- a/benchmark/libdbus.c +++ b/benchmark/libdbus.c @@ -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 diff --git a/benchmark/p2p-gdbus.c b/benchmark/p2p-gdbus.c index 4285efb..f99b6bb 100644 --- a/benchmark/p2p-gdbus.c +++ b/benchmark/p2p-gdbus.c @@ -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'; diff --git a/benchmark/pipe.c b/benchmark/pipe.c index be7bb91..f0b3907 100644 --- a/benchmark/pipe.c +++ b/benchmark/pipe.c @@ -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 diff --git a/benchmark/sharedmem.c b/benchmark/sharedmem.c index fe4ba98..e994473 100644 --- a/benchmark/sharedmem.c +++ b/benchmark/sharedmem.c @@ -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 diff --git a/benchmark/socket.c b/benchmark/socket.c index b3f17ed..01d24d3 100644 --- a/benchmark/socket.c +++ b/benchmark/socket.c @@ -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 -- 2.34.1