From a511dd988f5e05c5eebfadb823ef2ff6fe2d7379 Mon Sep 17 00:00:00 2001 From: John Levon Date: Thu, 18 Aug 2022 10:58:58 +0100 Subject: avoid vfu_log() in SGL hot path (#705) Even though in non-debug, we don't actually log anything here, even assembling the arguments to vfu_log() has a performance impact. Hide them behind a DEBUG_SGL define - even in a DEBUG build, they are particularly noisy and low-value. Signed-off-by: John Levon Reviewed-by: Swapnil Ingle --- .github/workflows/pull_request.sh | 2 +- lib/dma.h | 10 ++++++++++ meson.build | 5 +++++ meson_options.txt | 2 ++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.sh b/.github/workflows/pull_request.sh index b972bda..0462c7c 100755 --- a/.github/workflows/pull_request.sh +++ b/.github/workflows/pull_request.sh @@ -32,7 +32,7 @@ ninja -C $BUILD/clang-release -v meson test -C $BUILD/clang-release --no-suite style --print-errorlogs # debug build with gcc -CC=gcc meson setup build/gcc-debug -Dtran-pipe=true +CC=gcc meson setup build/gcc-debug -Dtran-pipe=true -Ddebug-sgl=true ninja -C $BUILD/gcc-debug -v meson test -C $BUILD/gcc-debug --no-suite style --print-errorlogs diff --git a/lib/dma.h b/lib/dma.h index 089f973..be64617 100644 --- a/lib/dma.h +++ b/lib/dma.h @@ -288,9 +288,13 @@ dma_sgl_get(dma_controller_t *dma, dma_sg_t *sgl, struct iovec *iov, size_t cnt) return ERROR_INT(EFAULT); } +#ifdef DEBUG_SGL vfu_log(dma->vfu_ctx, LOG_DEBUG, "map %p-%p", sg->dma_addr + sg->offset, sg->dma_addr + sg->offset + sg->length); + +#endif + iov->iov_base = region->info.vaddr + sg->offset; iov->iov_len = sg->length; @@ -326,9 +330,12 @@ dma_sgl_mark_dirty(dma_controller_t *dma, dma_sg_t *sgl, size_t cnt) } } +#ifdef DEBUG_SGL vfu_log(dma->vfu_ctx, LOG_DEBUG, "mark dirty %p-%p", sg->dma_addr + sg->offset, sg->dma_addr + sg->offset + sg->length); +#endif + sg++; } while (--cnt > 0); } @@ -358,9 +365,12 @@ dma_sgl_put(dma_controller_t *dma, dma_sg_t *sgl, size_t cnt) } } +#ifdef DEBUG_SGL vfu_log(dma->vfu_ctx, LOG_DEBUG, "unmap %p-%p", sg->dma_addr + sg->offset, sg->dma_addr + sg->offset + sg->length); +#endif + sg++; } while (--cnt > 0); } diff --git a/meson.build b/meson.build index dba2ba6..bc0de78 100644 --- a/meson.build +++ b/meson.build @@ -19,6 +19,7 @@ opt_debug_logs = get_option('debug-logs') opt_sanitizers = get_option('b_sanitize') opt_debug = get_option('debug') opt_shadow_ioeventfd = get_option('shadow-ioeventfd') +opt_debug_sgl = get_option('debug-sgl') cc = meson.get_compiler('c') @@ -62,6 +63,10 @@ if opt_shadow_ioeventfd common_cflags += ['-DSHADOW_IOEVENTFD'] endif +if opt_debug_sgl + common_cflags += ['-DDEBUG_SGL'] +endif + if get_option('warning_level') == '2' # -Wall is set for 'warning_level>=1' # -Wextra is set for 'warning_level>=2' diff --git a/meson_options.txt b/meson_options.txt index a731e06..31cbc67 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -8,3 +8,5 @@ option('shadow-ioeventfd', type: 'boolean', value : false, description: 'enable shadow ioeventfd (experimental)') option('client-server-test', type: 'boolean', value : false, description: 'enable client-server test (flaky)') +option('debug-sgl', type: 'boolean', value : false, + description: 'additional debugging for sgl maps') -- cgit v1.1