]>
Commit | Line | Data |
---|---|---|
53b56ca7 FE |
1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
2 | From: Stefan Hajnoczi <stefanha@redhat.com> | |
3 | Date: Mon, 1 May 2023 13:34:43 -0400 | |
4 | Subject: [PATCH] block: compile out assert_bdrv_graph_readable() by default | |
5 | ||
6 | reader_count() is a performance bottleneck because the global | |
7 | aio_context_list_lock mutex causes thread contention. Put this debugging | |
8 | assertion behind a new ./configure --enable-debug-graph-lock option and | |
9 | disable it by default. | |
10 | ||
11 | The --enable-debug-graph-lock option is also enabled by the more general | |
12 | --enable-debug option. | |
13 | ||
14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | |
15 | (picked up from https://lists.nongnu.org/archive/html/qemu-devel/2023-05/msg00058.html) | |
16 | Signed-off-by: Fiona Ebner <f.ebner@proxmox.com> | |
17 | --- | |
18 | block/graph-lock.c | 3 +++ | |
19 | configure | 1 + | |
20 | meson.build | 2 ++ | |
21 | meson_options.txt | 2 ++ | |
22 | scripts/meson-buildoptions.sh | 4 ++++ | |
23 | 5 files changed, 12 insertions(+) | |
24 | ||
25 | diff --git a/block/graph-lock.c b/block/graph-lock.c | |
26 | index 454c31e691..259a7a0bde 100644 | |
27 | --- a/block/graph-lock.c | |
28 | +++ b/block/graph-lock.c | |
29 | @@ -265,7 +265,10 @@ void bdrv_graph_rdunlock_main_loop(void) | |
30 | ||
31 | void assert_bdrv_graph_readable(void) | |
32 | { | |
33 | + /* reader_count() is slow due to aio_context_list_lock lock contention */ | |
34 | +#ifdef CONFIG_DEBUG_GRAPH_LOCK | |
35 | assert(qemu_in_main_thread() || reader_count()); | |
36 | +#endif | |
37 | } | |
38 | ||
39 | void assert_bdrv_graph_writable(void) | |
40 | diff --git a/configure b/configure | |
41 | index 800b5850f4..a62a3e6be9 100755 | |
42 | --- a/configure | |
43 | +++ b/configure | |
44 | @@ -806,6 +806,7 @@ for opt do | |
45 | --enable-debug) | |
46 | # Enable debugging options that aren't excessively noisy | |
47 | debug_tcg="yes" | |
48 | + meson_option_parse --enable-debug-graph-lock "" | |
49 | meson_option_parse --enable-debug-mutex "" | |
50 | meson_option_add -Doptimization=0 | |
51 | fortify_source="no" | |
52 | diff --git a/meson.build b/meson.build | |
53 | index c44d05a13f..d964e741e7 100644 | |
54 | --- a/meson.build | |
55 | +++ b/meson.build | |
56 | @@ -1956,6 +1956,7 @@ if get_option('debug_stack_usage') and have_coroutine_pool | |
57 | have_coroutine_pool = false | |
58 | endif | |
59 | config_host_data.set10('CONFIG_COROUTINE_POOL', have_coroutine_pool) | |
60 | +config_host_data.set('CONFIG_DEBUG_GRAPH_LOCK', get_option('debug_graph_lock')) | |
61 | config_host_data.set('CONFIG_DEBUG_MUTEX', get_option('debug_mutex')) | |
62 | config_host_data.set('CONFIG_DEBUG_STACK_USAGE', get_option('debug_stack_usage')) | |
63 | config_host_data.set('CONFIG_GPROF', get_option('gprof')) | |
64 | @@ -3833,6 +3834,7 @@ summary_info += {'PIE': get_option('b_pie')} | |
65 | summary_info += {'static build': config_host.has_key('CONFIG_STATIC')} | |
66 | summary_info += {'malloc trim support': has_malloc_trim} | |
67 | summary_info += {'membarrier': have_membarrier} | |
68 | +summary_info += {'debug graph lock': get_option('debug_graph_lock')} | |
69 | summary_info += {'debug stack usage': get_option('debug_stack_usage')} | |
70 | summary_info += {'mutex debugging': get_option('debug_mutex')} | |
71 | summary_info += {'memory allocator': get_option('malloc')} | |
72 | diff --git a/meson_options.txt b/meson_options.txt | |
73 | index fc9447d267..bc857fe68b 100644 | |
74 | --- a/meson_options.txt | |
75 | +++ b/meson_options.txt | |
76 | @@ -311,6 +311,8 @@ option('rng_none', type: 'boolean', value: false, | |
77 | description: 'dummy RNG, avoid using /dev/(u)random and getrandom()') | |
78 | option('coroutine_pool', type: 'boolean', value: true, | |
79 | description: 'coroutine freelist (better performance)') | |
80 | +option('debug_graph_lock', type: 'boolean', value: false, | |
81 | + description: 'graph lock debugging support') | |
82 | option('debug_mutex', type: 'boolean', value: false, | |
83 | description: 'mutex debugging support') | |
84 | option('debug_stack_usage', type: 'boolean', value: false, | |
85 | diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh | |
86 | index 009fab1515..30e1f25259 100644 | |
87 | --- a/scripts/meson-buildoptions.sh | |
88 | +++ b/scripts/meson-buildoptions.sh | |
89 | @@ -21,6 +21,8 @@ meson_options_help() { | |
90 | printf "%s\n" ' QEMU' | |
91 | printf "%s\n" ' --enable-cfi Control-Flow Integrity (CFI)' | |
92 | printf "%s\n" ' --enable-cfi-debug Verbose errors in case of CFI violation' | |
93 | + printf "%s\n" ' --enable-debug-graph-lock' | |
94 | + printf "%s\n" ' graph lock debugging support' | |
95 | printf "%s\n" ' --enable-debug-mutex mutex debugging support' | |
96 | printf "%s\n" ' --enable-debug-stack-usage' | |
97 | printf "%s\n" ' measure coroutine stack usage' | |
98 | @@ -249,6 +251,8 @@ _meson_option_parse() { | |
99 | --datadir=*) quote_sh "-Ddatadir=$2" ;; | |
100 | --enable-dbus-display) printf "%s" -Ddbus_display=enabled ;; | |
101 | --disable-dbus-display) printf "%s" -Ddbus_display=disabled ;; | |
102 | + --enable-debug-graph-lock) printf "%s" -Ddebug_graph_lock=true ;; | |
103 | + --disable-debug-graph-lock) printf "%s" -Ddebug_graph_lock=false ;; | |
104 | --enable-debug-mutex) printf "%s" -Ddebug_mutex=true ;; | |
105 | --disable-debug-mutex) printf "%s" -Ddebug_mutex=false ;; | |
106 | --enable-debug-stack-usage) printf "%s" -Ddebug_stack_usage=true ;; |