From da199704c7fb21e46e67d5afb1531cc5da51d83b Mon Sep 17 00:00:00 2001 From: Qizhen Zhang Date: Sat, 30 Sep 2023 16:03:45 -0700 Subject: [PATCH] Cache table microbenchmark --- DPDPU/Benchmarks/Micro/CacheTable/Build.sh | 1 + DPDPU/Benchmarks/Micro/CacheTable/Run.sh | 1 + .../Benchmarks/Micro/CacheTable/Source/Main.c | 70 +++++++++++++++++++ DPDPU/Benchmarks/Micro/CacheTable/meson.build | 58 +++++++++++++++ .../Include/DPU}/CacheTable.h | 0 .../Source => Common/Source/DPU}/CacheTable.c | 0 6 files changed, 130 insertions(+) create mode 100755 DPDPU/Benchmarks/Micro/CacheTable/Build.sh create mode 100755 DPDPU/Benchmarks/Micro/CacheTable/Run.sh create mode 100644 DPDPU/Benchmarks/Micro/CacheTable/Source/Main.c create mode 100644 DPDPU/Benchmarks/Micro/CacheTable/meson.build rename DPDPU/{OffloadEngine/DPU/Include => Common/Include/DPU}/CacheTable.h (100%) rename DPDPU/{OffloadEngine/DPU/Source => Common/Source/DPU}/CacheTable.c (100%) diff --git a/DPDPU/Benchmarks/Micro/CacheTable/Build.sh b/DPDPU/Benchmarks/Micro/CacheTable/Build.sh new file mode 100755 index 0000000..95d6c59 --- /dev/null +++ b/DPDPU/Benchmarks/Micro/CacheTable/Build.sh @@ -0,0 +1 @@ +rm -r build; meson build; ninja -C build diff --git a/DPDPU/Benchmarks/Micro/CacheTable/Run.sh b/DPDPU/Benchmarks/Micro/CacheTable/Run.sh new file mode 100755 index 0000000..7ba399d --- /dev/null +++ b/DPDPU/Benchmarks/Micro/CacheTable/Run.sh @@ -0,0 +1 @@ +./build/CacheTableBenchmark diff --git a/DPDPU/Benchmarks/Micro/CacheTable/Source/Main.c b/DPDPU/Benchmarks/Micro/CacheTable/Source/Main.c new file mode 100644 index 0000000..e89578a --- /dev/null +++ b/DPDPU/Benchmarks/Micro/CacheTable/Source/Main.c @@ -0,0 +1,70 @@ +#include +#include + +#include "CacheTable.h" +#include "Profiler.h" + +int main() { + int result = 0; + const size_t totalItems = 2000000; + + fprintf(stdout, "Allocating test items...\n"); + CacheItemT* items = malloc(totalItems * sizeof(CacheItemT)); + if (!items) { + fprintf(stderr, "Failed to allocate items\n"); + } + + for (size_t i = 0; i != totalItems; i++) { + items[i].Key = i; + items[i].Version = 42; + items[i].FileId = 0; + items[i].Offset = i; + items[i].Size = 1; + } + + fprintf(stdout, "Init the cache table...\n"); + result = InitCacheTable(); + if (result) { + fprintf(stderr, "InitCacheTable failed\n"); + } + + fprintf(stdout, "Adding to the cache table...\n"); + size_t itemCount = 0; + struct Profiler profiler; + InitProfiler(&profiler, totalItems); + + StartProfiler(&profiler); + while (!result && itemCount <= totalItems) { + result = AddToCacheTable(&items[itemCount]); + itemCount++; + } + StopProfiler(&profiler); + profiler.Operations = itemCount; + + fprintf(stdout, "%ld items added before failure\n"); + ReportProfiler(&profiler); + + fprintf(stdout, "Testing if added items are correct"); + CacheItemT* itemQueried; + for (size_t i = 0; i != itemCount; i++) { + itemQueried = LookUpCacheTable(&items[i].Key)->Offset; + if (itemQueried->Offset != items[i].Offset) { + fprintf(stderr, "Test failed: key = %ld (%ld -> %ld)\n", items[i].Key, items[i].Offset, itemQueried->Offset); + } + } + + fprintf(stdout, "Looking up from the cache table...\n"); + itemCount = 0; + StartProfiler(&profiler); + while (itemCount <= totalItems) { + result = LookUpCacheTable(&items[itemCount].Key); + itemCount++; + } + StopProfiler(&profiler); + profiler.Operations = itemCount; + + fprintf(stdout, "%ld items looked up\n"); + ReportProfiler(&profiler); + + return 0; +} \ No newline at end of file diff --git a/DPDPU/Benchmarks/Micro/CacheTable/meson.build b/DPDPU/Benchmarks/Micro/CacheTable/meson.build new file mode 100644 index 0000000..fd17fba --- /dev/null +++ b/DPDPU/Benchmarks/Micro/CacheTable/meson.build @@ -0,0 +1,58 @@ +project('DDSFileBackEnd', 'C', 'CPP', + version: '0.1', + license: 'Proprietary', + default_options: ['buildtype=release'], + meson_version: '>= 0.61.2' +) + +languages = ['c', 'cpp'] + +install_apps = false + +base_cpp_args = [ + '-std=c++11', +] + +base_c_args = [ + '-flax-vector-conversions', +] + +# Resolve irrelevant compiler warnings +add_project_arguments('-Wno-format-zero-length', language: languages) +add_project_arguments('-Wno-address-of-packed-member', language: languages) +add_project_arguments('-Wno-deprecated-declarations', language: languages) + +base_app_dependencies = [] +base_app_dependencies += dependency('threads') + +base_app_inc_dirs = [ + include_directories('../../../Common/Include/DPU/'), +] + +app_link_args = [] +app_link_args += ['-libverbs'] +app_link_args += ['-lrdmacm'] + +APP_NAME = 'CacheTableBenchmark' + +app_dependencies = base_app_dependencies +app_inc_dirs = base_app_inc_dirs +app_srcs = [] + +src = 'Source/' + +app_srcs += [ + src + 'Main.c', + '../../../Common/Source/DPU/CacheTable.c', + '../../../Common/Source/DPU/Profiler.c', +] + +executable(APP_NAME, + app_srcs, + c_args : base_c_args, + cpp_args : base_cpp_args, + dependencies : [app_dependencies], + include_directories : app_inc_dirs, + link_args : app_link_args, + install: install_apps +) diff --git a/DPDPU/OffloadEngine/DPU/Include/CacheTable.h b/DPDPU/Common/Include/DPU/CacheTable.h similarity index 100% rename from DPDPU/OffloadEngine/DPU/Include/CacheTable.h rename to DPDPU/Common/Include/DPU/CacheTable.h diff --git a/DPDPU/OffloadEngine/DPU/Source/CacheTable.c b/DPDPU/Common/Source/DPU/CacheTable.c similarity index 100% rename from DPDPU/OffloadEngine/DPU/Source/CacheTable.c rename to DPDPU/Common/Source/DPU/CacheTable.c