diff options
author | Hyman Huang <yong.huang@smartx.com> | 2023-11-01 22:04:04 +0800 |
---|---|---|
committer | Juan Quintela <quintela@redhat.com> | 2023-11-03 07:48:25 +0100 |
commit | cce10a1f0c827653c00e81b6d7865cf974275994 (patch) | |
tree | fdaf03f4d004287d69211dfff0aeb47f7382d598 /system/dirtylimit.c | |
parent | d762bf97931b58839316b68a570eecc6143c9e3e (diff) |
system/dirtylimit: Fix a race situation
Fix a race situation for global variable dirtylimit_state.
Also, replace usleep by g_usleep to increase platform
accessibility to the sleep function.
Signed-off-by: Hyman Huang <yong.huang@smartx.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Message-ID: <27c86239e21eda03d11ce5a3d07da3c229f562e3.1698847223.git.yong.huang@smartx.com>
Diffstat (limited to 'system/dirtylimit.c')
-rw-r--r-- | system/dirtylimit.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/system/dirtylimit.c b/system/dirtylimit.c index fa959d7743..3666c4cb7c 100644 --- a/system/dirtylimit.c +++ b/system/dirtylimit.c @@ -411,12 +411,20 @@ void dirtylimit_set_all(uint64_t quota, void dirtylimit_vcpu_execute(CPUState *cpu) { - if (dirtylimit_in_service() && - dirtylimit_vcpu_get_state(cpu->cpu_index)->enabled && - cpu->throttle_us_per_full) { - trace_dirtylimit_vcpu_execute(cpu->cpu_index, - cpu->throttle_us_per_full); - usleep(cpu->throttle_us_per_full); + if (cpu->throttle_us_per_full) { + dirtylimit_state_lock(); + + if (dirtylimit_in_service() && + dirtylimit_vcpu_get_state(cpu->cpu_index)->enabled) { + dirtylimit_state_unlock(); + trace_dirtylimit_vcpu_execute(cpu->cpu_index, + cpu->throttle_us_per_full); + + g_usleep(cpu->throttle_us_per_full); + return; + } + + dirtylimit_state_unlock(); } } |