xref: /qemu/include/sysemu/accel-blocker.h (revision 84615a19)
1 /*
2  * Accelerator blocking API, to prevent new ioctls from starting and wait the
3  * running ones finish.
4  * This mechanism differs from pause/resume_all_vcpus() in that it does not
5  * release the BQL.
6  *
7  *  Copyright (c) 2022 Red Hat Inc.
8  *
9  * Author: Emanuele Giuseppe Esposito       <eesposit@redhat.com>
10  *
11  * This work is licensed under the terms of the GNU GPL, version 2 or later.
12  * See the COPYING file in the top-level directory.
13  */
14 #ifndef ACCEL_BLOCKER_H
15 #define ACCEL_BLOCKER_H
16 
17 #include "qemu/osdep.h"
18 #include "sysemu/cpus.h"
19 
20 extern void accel_blocker_init(void);
21 
22 /*
23  * accel_{cpu_}ioctl_begin/end:
24  * Mark when ioctl is about to run or just finished.
25  *
26  * accel_{cpu_}ioctl_begin will block after accel_ioctl_inhibit_begin() is
27  * called, preventing new ioctls to run. They will continue only after
28  * accel_ioctl_inibith_end().
29  */
30 extern void accel_ioctl_begin(void);
31 extern void accel_ioctl_end(void);
32 extern void accel_cpu_ioctl_begin(CPUState *cpu);
33 extern void accel_cpu_ioctl_end(CPUState *cpu);
34 
35 /*
36  * accel_ioctl_inhibit_begin: start critical section
37  *
38  * This function makes sure that:
39  * 1) incoming accel_{cpu_}ioctl_begin() calls block
40  * 2) wait that all ioctls that were already running reach
41  *    accel_{cpu_}ioctl_end(), kicking vcpus if necessary.
42  *
43  * This allows the caller to access shared data or perform operations without
44  * worrying of concurrent vcpus accesses.
45  */
46 extern void accel_ioctl_inhibit_begin(void);
47 
48 /*
49  * accel_ioctl_inhibit_end: end critical section started by
50  * accel_ioctl_inhibit_begin()
51  *
52  * This function allows blocked accel_{cpu_}ioctl_begin() to continue.
53  */
54 extern void accel_ioctl_inhibit_end(void);
55 
56 #endif /* ACCEL_BLOCKER_H */
57