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 <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
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 @@ 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 @@ 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 @@ } } +#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 @@ } } +#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_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 @@ 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 @@ 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')