Misc patches for 2019-09-16
The following changes since commit 138985c1ef8b66e4e5b383354e133e05d01d0b5f:
Merge remote-tracking branch 'remotes/amarkovic/tags/mips-queue-sep-12-2019' into staging (2019-09-13 16:04:46 +0100)
are available in the git repository at:
git://github.com/bonzini/qemu.git tags/for-upstream
for you to fetch changes up to b29799d93fde775ef7e4104c834a1c1da15b34c3:
hw/i386/pc: Extract the x86 generic fw_cfg code (2019-09-16 14:39:03 +0200)
----------------------------------------------------------------
* Fix Patchew CI failures (myself)
* i386 fw_cfg refactoring (Philippe)
* pmem bugfix (Stefan)
* Support for accessing cstate MSRs (Wanpeng)
* exec.c cleanups (Wei Yang)
* Improved throttling (Yury)
* elf-ops.h coverity fix (Stefano)
----------------------------------------------------------------
Cole Robinson (1):
hw/i386: Move CONFIG_ACPI_PCI to CONFIG_PC
Paolo Bonzini (4):
win32: fix README file in NSIS installer
test-char: fix AddressSanitizer failure
memory: inline and optimize devend_memop
hw/i386/pc: Replace PCMachineState argument with MachineState in fw_cfg_arch_create
Philippe Mathieu-Daudé (14):
hw/i386/pc: Use e820_get_num_entries() to access e820_entries hw/i386/pc: Extract e820 memory layout code
hw/i386/pc: Use address_space_memory in place
hw/i386/pc: Rename bochs_bios_init as more generic fw_cfg_arch_create hw/i386/pc: Pass the boot_cpus value by argument hw/i386/pc: Pass the apic_id_limit value by argument hw/i386/pc: Pass the CPUArchIdList array by argument hw/i386/pc: Let pc_build_smbios() take a FWCfgState argument hw/i386/pc: Let pc_build_smbios() take a generic MachineState argument hw/i386/pc: Rename pc_build_smbios() as generic fw_cfg_build_smbios() hw/i386/pc: Let pc_build_feature_control() take a FWCfgState argument hw/i386/pc: Let pc_build_feature_control() take a MachineState argument hw/i386/pc: Rename pc_build_feature_control() as generic fw_cfg_build_* hw/i386/pc: Extract the x86 generic fw_cfg code
Stefan Hajnoczi (1):
memory: fetch pmem size in get_file_size()
Stefano Garzarella (1):
elf-ops.h: fix int overflow in load_elf()
Wanpeng Li (1):
i386/kvm: support guest access CORE cstate
Wei Yang (5):
exec.c: replace hwaddr with uint64_t for better understanding exec.c: get nodes_nb_alloc with one MAX calculation exec.c: subpage->sub_section is already initialized to 0 exec.c: correct the maximum skip value during compact exec.c: add a check between constants to see whether we could skip
Yury Kotov (2):
qemu-thread: Add qemu_cond_timedwait
cpus: Fix throttling during vm_stop
backends/hostmem-file.c | 22 ----- cpus.c | 25 +++-- default-configs/i386-softmmu.mak | 1 - exec.c | 54 ++++++++--- hw/core/loader.c | 2 + hw/i386/Kconfig | 1 + hw/i386/Makefile.objs | 2 +- hw/i386/e820_memory_layout.c | 59 +++++++++++ hw/i386/e820_memory_layout.h | 42 ++++++++ hw/i386/fw_cfg.c | 137 ++++++++++++++++++++++++++ hw/i386/fw_cfg.h | 7 ++ hw/i386/pc.c | 204 ++------------------------------------- include/exec/memory.h | 19 +++- include/hw/elf_ops.h | 5 + include/hw/i386/pc.h | 11 --- include/hw/loader.h | 1 + include/qemu/osdep.h | 13 --- include/qemu/thread.h | 19 ++++ linux-headers/linux/kvm.h | 4 +- memory.c | 18 ---- qemu.nsi | 4 +- target/i386/kvm.c | 4 +- tests/test-char.c | 44 ++++----- util/oslib-posix.c | 54 ----------- util/oslib-win32.c | 6 -- util/qemu-thread-posix.c | 41 +++++--- util/qemu-thread-win32.c | 17 ++++ util/qsp.c | 20 ++++ 28 files changed, 456 insertions(+), 380 deletions(-) create mode 100644 hw/i386/e820_memory_layout.c create mode 100644 hw/i386/e820_memory_layout.h
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 02/29] exec.c: replace hwaddr with uint64_t for better understanding
From: Wei Yang <[email protected]>
Function phys_page_set() and phys_page_set_level() 's argument *nb* stands for number of pages to set instead of hardware address.
This would be more proper to use uint64_t instead of hwaddr for its type.
Message-Id: <[email protected]>
--- exec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
exec.c +2 -2
@@ -255,7 +255,7 @@ static uint32_t phys_map_node_alloc(PhysPageMap *map, bool leaf) }static void phys_page_set_level (PhysPageMap *map,PhysPageEntry *lp, -hwaddr *index,hwaddr *nb,uint16_t leaf, +hwaddr *index,uint64_t *nb,uint16_t leaf,int level) {PhysPageEntry *p;
@@ -281,7 +281,7 @@ static void phys_page_set_level(PhysPageMap *map, PhysPageEntry *lp, }static void phys_page_set (AddressSpaceDispatch *d, -hwaddr index,hwaddr nb, +hwaddr index,uint64_t nb,uint16_t leaf) {/* Wildly overreserve - it doesn't matter much. */
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 03/29] exec.c: get nodes_nb_alloc with one MAX calculation
In reply to Paolo BonziniFrom: Wei Yang <[email protected]>
The purpose of these two MAX here is to get the maximum of these three variables:
A: map->nodes_nb + nodes
B: map->nodes_nb_alloc
C: alloc_hintWe can write it like MAX(A, B, C). Since the if condition says A > B, this means MAX(A, B, C) = MAX(A, C).
This patch just simplify the calculation a bit.
Message-Id: <[email protected]>
--- exec.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
exec.c +1 -2
@@ -227,8 +227,7 @@ static void phys_map_node_reserve(PhysPageMap *map, unsigned nodes) {static unsigned alloc_hint =16 ;if (map->nodes_nb + nodes > map->nodes_nb_alloc) { - map->nodes_nb_alloc =MAX (map->nodes_nb_alloc, alloc_hint); - map->nodes_nb_alloc =MAX (map->nodes_nb_alloc, map->nodes_nb + nodes); + map->nodes_nb_alloc =MAX (alloc_hint, map->nodes_nb + nodes); map->nodes =g_renew (Node, map->nodes, map->nodes_nb_alloc); alloc_hint = map->nodes_nb_alloc; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 05/29] exec.c: correct the maximum skip value during compact
In reply to Paolo BonziniFrom: Wei Yang <[email protected]>
skip is defined with 6 bits. So the maximum value should be (1 << 6).
Message-Id: <[email protected]>
--- exec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
exec.c +1 -1
@@ -324,7 +324,7 @@ static void phys_page_compact(PhysPageEntry *lp, Node *nodes)assert (valid_ptr <P_L2_SIZE );/* Don't compress if it won't fit in the # of bits we have. */ -if (lp->skip + p[valid_ptr].skip >= (1 <<3 )) { +if (lp->skip + p[valid_ptr].skip >= (1 <<6 )) {return ; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 04/29] exec.c: subpage->sub_section is already initialized to 0
In reply to Paolo BonziniFrom: Wei Yang <[email protected]>
In subpage_init(), we will set subpage->sub_section to PHYS_SECTION_UNASSIGNED by subpage_register. Since PHYS_SECTION_UNASSIGNED is defined to be 0, and we allocate subpage with g_malloc0, this means subpage->sub_section is already initialized to 0.
This patch removes the redundant setup for a new subpage and also fix the code style.
Message-Id: <[email protected]>
--- exec.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
exec.c +5 -5
@@ -1491,8 +1491,8 @@ hwaddr memory_region_section_get_iotlb(CPUState *cpu,#if !defined(CONFIG_USER_ONLY ) -static int subpage_register (subpage_t *mmio,uint32_t start,uint32_t end, -uint16_t section); +static int subpage_register (subpage_t *mmio,uint32_t start,uint32_t end, +uint16_t section);static subpage_t *subpage_init (FlatView *fv,hwaddr base); static void *(*phys_mem_alloc)(size_t size, uint64_t *align, bool shared) =
@@ -2913,8 +2913,8 @@ static const MemoryRegionOps subpage_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static int subpage_register (subpage_t *mmio,uint32_t start,uint32_t end, -uint16_t section) +static int subpage_register (subpage_t *mmio,uint32_t start,uint32_t end, +uint16_t section) {int idx, eidx;
@@ -2937,6 +2937,7 @@ static subpage_t *subpage_init(FlatView *fv, hwaddr base) {subpage_t *mmio; +/* mmio->sub_section is set to PHYS_SECTION_UNASSIGNED with g_malloc0 */ mmio =g_malloc0 (sizeof (subpage_t) +TARGET_PAGE_SIZE *sizeof (uint16_t )); mmio->fv = fv; mmio->base = base;
@@ -2947,7 +2948,6 @@ static subpage_t *subpage_init(FlatView *fv, hwaddr base)printf ("%s: %p base " TARGET_FMT_plx" len %08x\n" , __func__, mmio, base,TARGET_PAGE_SIZE );#endif -subpage_register (mmio,0 ,TARGET_PAGE_SIZE -1 ,PHYS_SECTION_UNASSIGNED );return mmio; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 07/29] win32: fix README file in NSIS installer
In reply to Paolo BonziniAdjust after the rST conversion and consequent renaming.
--- qemu.nsi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
qemu.nsi +2 -2
@@ -119,7 +119,7 @@ Section "${PRODUCT} (required)" File "${SRCDIR}\Changelog" File "${SRCDIR}\COPYING" File "${SRCDIR}\COPYING.LIB" - File "${SRCDIR}\README" + File "${SRCDIR}\README.rst" File "${SRCDIR}\VERSION" File "${BINDIR}\*.bmp"
@@ -211,7 +211,7 @@ Section "Uninstall" Delete "$INSTDIR\Changelog" Delete "$INSTDIR\COPYING" Delete "$INSTDIR\COPYING.LIB" - Delete "$INSTDIR\README" + Delete "$INSTDIR\README.rst" Delete "$INSTDIR\VERSION" Delete "$INSTDIR\*.bmp" Delete "$INSTDIR\*.bin"
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 08/29] test-char: fix AddressSanitizer failure
In reply to Paolo BonziniThe CharSocketServerTestConfig and CharSocketClientTestConfig objects escape after they are passed to g_test_add_data_func, but they cease existing after the scope that defines them is closed. Make them static to fix this issue.
--- tests/test-char.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-)
tests/test-char.c +22 -22
@@ -1355,6 +1355,18 @@ static void char_hotswap_test(void)g_free (chr_args); } +static SocketAddress tcpaddr = { + .type =SOCKET_ADDRESS_TYPE_INET , + .u.inet.host = (char *)"127.0.0.1" , + .u.inet.port = (char *)"0" , +}; +#ifndef WIN32 +static SocketAddress unixaddr = { + .type =SOCKET_ADDRESS_TYPE_UNIX , + .u.q_unix.path = (char *)"test-char.sock" , +}; +#endif +int main (int argc,char **argv) {bool has_ipv4, has_ipv6;
@@ -1390,26 +1402,14 @@ int main(int argc, char **argv)g_test_add_func ("/char/file-fifo" , char_file_fifo_test);#endif -SocketAddress tcpaddr = { - .type =SOCKET_ADDRESS_TYPE_INET , - .u.inet.host = (char *)"127.0.0.1" , - .u.inet.port = (char *)"0" , - }; -#ifndef WIN32 -SocketAddress unixaddr = { - .type =SOCKET_ADDRESS_TYPE_UNIX , - .u.q_unix.path = (char *)"test-char.sock" , - }; -#endif -#define SOCKET_SERVER_TEST (name, addr) \ - CharSocketServerTestConfig server1 ## name = \ + static CharSocketServerTestConfig server1 ## name = \ { addr, false, false }; \ - CharSocketServerTestConfig server2 ## name = \ + static CharSocketServerTestConfig server2 ## name = \ { addr, true, false }; \ - CharSocketServerTestConfig server3 ## name = \ + static CharSocketServerTestConfig server3 ## name = \ { addr, false, true }; \ - CharSocketServerTestConfig server4 ## name = \ + static CharSocketServerTestConfig server4 ## name = \ { addr, true, true }; \ g_test_add_data_func("/char/socket/server/mainloop/" # name, \ &server1 ##name, char_socket_server_test); \
@@ -1421,17 +1421,17 @@ int main(int argc, char **argv) &server4 ##name, char_socket_server_test)#define SOCKET_CLIENT_TEST (name, addr) \ - CharSocketClientTestConfig client1 ## name = \ + static CharSocketClientTestConfig client1 ## name = \ { addr, NULL, false, false }; \ - CharSocketClientTestConfig client2 ## name = \ + static CharSocketClientTestConfig client2 ## name = \ { addr, NULL, true, false }; \ - CharSocketClientTestConfig client3 ## name = \ + static CharSocketClientTestConfig client3 ## name = \ { addr, ",reconnect=1", false }; \ - CharSocketClientTestConfig client4 ## name = \ + static CharSocketClientTestConfig client4 ## name = \ { addr, ",reconnect=1", true }; \ - CharSocketClientTestConfig client5 ## name = \ + static CharSocketClientTestConfig client5 ## name = \ { addr, NULL, false, true }; \ - CharSocketClientTestConfig client6 ## name = \ + static CharSocketClientTestConfig client6 ## name = \ { addr, NULL, true, true }; \ g_test_add_data_func("/char/socket/client/mainloop/" # name, \ &client1 ##name, char_socket_client_test); \
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 10/29] elf-ops.h: fix int overflow in load_elf()
In reply to Paolo BonziniFrom: Stefano Garzarella <[email protected]>
This patch fixes a possible integer overflow when we calculate the total size of ELF segments loaded.
Message-Id: <[email protected]>
--- hw/core/loader.c | 2 ++ include/hw/elf_ops.h | 5 +++++ include/hw/loader.h | 1 + 3 files changed, 8 insertions(+)
hw/core/loader.c +2 -0
@@ -338,6 +338,8 @@ const char *load_elf_strerror(int error)return "The image is from incompatible architecture" ;case ELF_LOAD_WRONG_ENDIAN :return "The image has incorrect endianness" ; +case ELF_LOAD_TOO_BIG : +return "The image segments are too big to load" ;default :return "Unknown error" ; }
include/hw/elf_ops.h +5 -0
@@ -485,6 +485,11 @@ static int glue(load_elf, SZ)(const char *name, int fd, } } +if (mem_size >INT_MAX - total_size) { + ret =ELF_LOAD_TOO_BIG ; + goto fail; + } +/* address_offset is hack for kernel images that are linked at the wrong physical address. */ if (translate_fn) {
include/hw/loader.h +1 -0
@@ -89,6 +89,7 @@ int load_image_gzipped(const char *filename, hwaddr addr, uint64_t max_sz);#define ELF_LOAD_NOT_ELF -2#define ELF_LOAD_WRONG_ARCH -3#define ELF_LOAD_WRONG_ENDIAN -4 +#define ELF_LOAD_TOO_BIG -5const char *load_elf_strerror (int error);/** load_elf_ram_sym:
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 20/29] hw/i386/pc: Pass the apic_id_limit value by argument
In reply to Paolo BonziniFrom: Philippe Mathieu-Daudé <[email protected]>
Pass the apic_id_limit value by argument, this will allow us to remove the PCMachineState argument later.
Message-Id: <[email protected]>
--- hw/i386/pc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/i386/pc.c +3 -2
@@ -937,7 +937,8 @@ static void pc_build_smbios(PCMachineState *pcms) }static FWCfgState *fw_cfg_arch_create (PCMachineState *pcms, -uint16_t boot_cpus) +uint16_t boot_cpus, +uint16_t apic_id_limit) {FWCfgState *fw_cfg;uint64_t *numa_fw_cfg;
@@ -1870,7 +1871,7 @@ void pc_memory_init(PCMachineState *pcms, option_rom_mr, 1); - fw_cfg =fw_cfg_arch_create (pcms, pcms->boot_cpus); + fw_cfg =fw_cfg_arch_create (pcms, pcms->boot_cpus, pcms->apic_id_limit);rom_set_fw (fw_cfg);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 13/29] qemu-thread: Add qemu_cond_timedwait
In reply to Paolo BonziniFrom: Yury Kotov <[email protected]>
The new function is needed to implement conditional sleep for CPU throttling. It's possible to reuse qemu_sem_timedwait, but it's more difficult than just add qemu_cond_timedwait.
Also moved compute_abs_deadline function up the code to reuse it in qemu_cond_timedwait_impl win32.
Message-Id: <[email protected]>
--- include/qemu/thread.h | 19 +++++++++++++++++++ util/qemu-thread-posix.c | 41 +++++++++++++++++++++++++++++------------ util/qemu-thread-win32.c | 17 +++++++++++++++++ util/qsp.c | 20 ++++++++++++++++++++ 4 files changed, 85 insertions(+), 12 deletions(-)
include/qemu/thread.h +19 -0
@@ -34,6 +34,8 @@ typedef void (*QemuRecMutexLockFunc)(QemuRecMutex *m, const char *f, int l);typedef int (*QemuRecMutexTrylockFunc )(QemuRecMutex *m,const char *f,int l);typedef void (*QemuCondWaitFunc )(QemuCond *c,QemuMutex *m,const char *f,int l); +typedef bool (*QemuCondTimedWaitFunc )(QemuCond *c,QemuMutex *m,int ms, +const char *f,int l);extern QemuMutexLockFunc qemu_bql_mutex_lock_func;extern QemuMutexLockFunc qemu_mutex_lock_func;
@@ -41,6 +43,7 @@ extern QemuMutexTrylockFunc qemu_mutex_trylock_func;extern QemuRecMutexLockFunc qemu_rec_mutex_lock_func;extern QemuRecMutexTrylockFunc qemu_rec_mutex_trylock_func;extern QemuCondWaitFunc qemu_cond_wait_func; +extern QemuCondTimedWaitFunc qemu_cond_timedwait_func;/* convenience macros to bypass the profiler */ #define qemu_mutex_lock__raw (m) \
@@ -63,6 +66,8 @@ extern QemuCondWaitFunc qemu_cond_wait_func;qemu_rec_mutex_trylock_impl (m, __FILE__, __LINE__);#define qemu_cond_wait (c, m) \ qemu_cond_wait_impl(c, m, __FILE__, __LINE__); +#define qemu_cond_timedwait (c, m, ms) \ + qemu_cond_wait_impl(c, m, ms, __FILE__, __LINE__);#else #define qemu_mutex_lock (m) ({ \ QemuMutexLockFunc _f = atomic_read(&qemu_mutex_lock_func); \
@@ -89,6 +94,11 @@ extern QemuCondWaitFunc qemu_cond_wait_func;QemuCondWaitFunc _f =atomic_read (&qemu_cond_wait_func); \_f (c, m, __FILE__, __LINE__); \ }) + +#define qemu_cond_timedwait (c, m, ms) ({ \ + QemuCondTimedWaitFunc _f = atomic_read(&qemu_cond_timedwait_func); \ + _f(c, m, ms, __FILE__, __LINE__); \ + })#endif #define qemu_mutex_unlock (mutex) \
@@ -134,12 +144,21 @@ void qemu_cond_signal(QemuCond *cond);void qemu_cond_broadcast (QemuCond *cond);void qemu_cond_wait_impl (QemuCond *cond,QemuMutex *mutex,const char *file,const int line); +bool qemu_cond_timedwait_impl (QemuCond *cond,QemuMutex *mutex,int ms, +const char *file,const int line);static inline void (qemu_cond_wait)(QemuCond *cond,QemuMutex *mutex) {qemu_cond_wait (cond, mutex); } +/* Returns true if timeout has not expired, and false otherwise */ +static inline bool (qemu_cond_timedwait)(QemuCond *cond,QemuMutex *mutex, +int ms) +{ +return qemu_cond_timedwait (cond, mutex, ms); +} +void qemu_sem_init (QemuSemaphore *sem,int init);void qemu_sem_post (QemuSemaphore *sem);void qemu_sem_wait (QemuSemaphore *sem);
util/qemu-thread-posix.c +29 -12
59 lines not on this page · raw message
util/qemu-thread-win32.c +17 -0
@@ -145,6 +145,23 @@ void qemu_cond_wait_impl(QemuCond *cond, QemuMutex *mutex, const char *file, conqemu_mutex_post_lock (mutex, file, line); } +bool qemu_cond_timedwait_impl (QemuCond *cond,QemuMutex *mutex,int ms, +const char *file,const int line) +{ +int rc =0 ; + +assert (cond->initialized); +trace_qemu_mutex_unlock (mutex, file, line); +if (!SleepConditionVariableSRW (&cond->var, &mutex->lock, ms,0 )) { + rc =GetLastError (); + } +trace_qemu_mutex_locked (mutex, file, line); +if (rc && rc !=ERROR_TIMEOUT ) { +error_exit (rc, __func__); + } +return rc !=ERROR_TIMEOUT ; +} +void qemu_sem_init (QemuSemaphore *sem,int init) {/* Manual reset. */
util/qsp.c +20 -0
@@ -131,6 +131,7 @@ QemuRecMutexLockFunc qemu_rec_mutex_lock_func = qemu_rec_mutex_lock_impl;QemuRecMutexTrylockFunc qemu_rec_mutex_trylock_func = qemu_rec_mutex_trylock_impl;QemuCondWaitFunc qemu_cond_wait_func = qemu_cond_wait_impl; +QemuCondTimedWaitFunc qemu_cond_timedwait_func = qemu_cond_timedwait_impl;/* * It pays off to _not_ hash callsite->file; hashing a string is slow, and
@@ -412,6 +413,23 @@ qsp_cond_wait(QemuCond *cond, QemuMutex *mutex, const char *file, int line)qsp_entry_record (e, t1 - t0); } +static bool +qsp_cond_timedwait (QemuCond *cond,QemuMutex *mutex,int ms, +const char *file,int line) +{ +QSPEntry *e; +int64_t t0, t1; +bool ret; + + t0 =get_clock (); + ret =qemu_cond_timedwait_impl (cond, mutex, ms, file, line); + t1 =get_clock (); + + e =qsp_entry_get (cond, file, line,QSP_CONDVAR ); +qsp_entry_record (e, t1 - t0); +return ret; +} +bool qsp_is_enabled (void ) {return atomic_read (&qemu_mutex_lock_func) == qsp_mutex_lock;
@@ -425,6 +443,7 @@ void qsp_enable(void)atomic_set (&qemu_rec_mutex_lock_func, qsp_rec_mutex_lock);atomic_set (&qemu_rec_mutex_trylock_func, qsp_rec_mutex_trylock);atomic_set (&qemu_cond_wait_func, qsp_cond_wait); +atomic_set (&qemu_cond_timedwait_func, qsp_cond_timedwait); }void qsp_disable (void )
@@ -435,6 +454,7 @@ void qsp_disable(void)atomic_set (&qemu_rec_mutex_lock_func, qemu_rec_mutex_lock_impl);atomic_set (&qemu_rec_mutex_trylock_func, qemu_rec_mutex_trylock_impl);atomic_set (&qemu_cond_wait_func, qemu_cond_wait_impl); +atomic_set (&qemu_cond_timedwait_func, qemu_cond_timedwait_impl); }static gint qsp_tree_cmp (gconstpointer ap,gconstpointer bp,gpointer up)
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 26/29] hw/i386/pc: Let pc_build_feature_control() take a FWCfgState argument
In reply to Paolo BonziniFrom: Philippe Mathieu-Daudé <[email protected]>
Pass the FWCfgState object by argument, this will allow us to remove the PCMachineState argument later.
Message-Id: <[email protected]>
--- hw/i386/pc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
hw/i386/pc.c +4 -3
@@ -1623,7 +1623,8 @@ void pc_cpus_init(PCMachineState *pcms) } } -static void pc_build_feature_control_file (PCMachineState *pcms) +static void pc_build_feature_control_file (PCMachineState *pcms, +FWCfgState *fw_cfg) {MachineState *ms =MACHINE (pcms);X86CPU *cpu =X86_CPU (ms->possible_cpus->cpus[0 ].cpu);
@@ -1649,7 +1650,7 @@ static void pc_build_feature_control_file(PCMachineState *pcms) val =g_malloc (sizeof (*val)); *val =cpu_to_le64 (feature_control_bits |FEATURE_CONTROL_LOCKED ); -fw_cfg_add_file (pcms->fw_cfg,"etc/msr_feature_control" , val,sizeof (*val)); +fw_cfg_add_file (fw_cfg,"etc/msr_feature_control" , val,sizeof (*val)); }static void rtc_set_cpus_count (ISADevice *rtc,uint16_t cpus_count)
@@ -1695,7 +1696,7 @@ void pc_machine_done(Notifier *notifier, void *data)acpi_setup ();if (pcms->fw_cfg) {fw_cfg_build_smbios (MACHINE (pcms), pcms->fw_cfg); -pc_build_feature_control_file (pcms); +pc_build_feature_control_file (pcms, pcms->fw_cfg);/* update FW_CFG_NB_CPUS to account for -device added CPUs */ fw_cfg_modify_i16 (pcms->fw_cfg,FW_CFG_NB_CPUS , pcms->boot_cpus); }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 21/29] hw/i386/pc: Pass the CPUArchIdList array by argument
In reply to Paolo BonziniFrom: Philippe Mathieu-Daudé <[email protected]>
Pass the CPUArchIdList array by argument, this will allow us to remove the PCMachineState argument later.
Message-Id: <[email protected]>
--- hw/i386/pc.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
hw/i386/pc.c +9 -10
@@ -937,14 +937,13 @@ static void pc_build_smbios(PCMachineState *pcms) }static FWCfgState *fw_cfg_arch_create (PCMachineState *pcms, +const CPUArchIdList *cpus,uint16_t boot_cpus,uint16_t apic_id_limit) {FWCfgState *fw_cfg;uint64_t *numa_fw_cfg;int i; -const CPUArchIdList *cpus; -MachineClass *mc =MACHINE_GET_CLASS (pcms);MachineState *ms =MACHINE (pcms);int nb_numa_nodes = ms->numa_state->num_nodes;
@@ -964,7 +963,7 @@ static FWCfgState *fw_cfg_arch_create(PCMachineState *pcms,* So for compatibility reasons with old BIOSes we are stuck with * "etc/max-cpus" actually being apic_id_limit */ -fw_cfg_add_i16 (fw_cfg,FW_CFG_MAX_CPUS , (uint16_t )pcms->apic_id_limit); +fw_cfg_add_i16 (fw_cfg,FW_CFG_MAX_CPUS , apic_id_limit);fw_cfg_add_i64 (fw_cfg,FW_CFG_RAM_SIZE , (uint64_t )ram_size);fw_cfg_add_bytes (fw_cfg,FW_CFG_ACPI_TABLES , acpi_tables, acpi_tables_len);
@@ -980,20 +979,19 @@ static FWCfgState *fw_cfg_arch_create(PCMachineState *pcms,* of nodes, one word for each VCPU->node and one word for each node to * hold the amount of memory. */ - numa_fw_cfg =g_new0 (uint64_t,1 + pcms->apic_id_limit + nb_numa_nodes); + numa_fw_cfg =g_new0 (uint64_t,1 + apic_id_limit + nb_numa_nodes); numa_fw_cfg[0 ] =cpu_to_le64 (nb_numa_nodes); - cpus = mc->possible_cpu_arch_ids (MACHINE (pcms));for (i =0 ; i < cpus->len; i++) {unsigned int apic_id = cpus->cpus[i].arch_id; -assert (apic_id < pcms->apic_id_limit); +assert (apic_id < apic_id_limit); numa_fw_cfg[apic_id +1 ] =cpu_to_le64 (cpus->cpus[i].props.node_id); }for (i =0 ; i < nb_numa_nodes; i++) { - numa_fw_cfg[pcms->apic_id_limit +1 + i] = + numa_fw_cfg[apic_id_limit +1 + i] =cpu_to_le64 (ms->numa_state->nodes[i].node_mem); }fw_cfg_add_bytes (fw_cfg,FW_CFG_NUMA , numa_fw_cfg, - (1 + pcms->apic_id_limit + nb_numa_nodes) * + (1 + apic_id_limit + nb_numa_nodes) *sizeof (*numa_fw_cfg));return fw_cfg;
@@ -1775,6 +1773,7 @@ void pc_memory_init(PCMachineState *pcms,MemoryRegion *ram_below_4g, *ram_above_4g;FWCfgState *fw_cfg;MachineState *machine =MACHINE (pcms); +MachineClass *mc =MACHINE_GET_CLASS (machine);PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (pcms); assert(machine->ram_size == pcms->below_4g_mem_size +
@@ -1808,7 +1807,6 @@ void pc_memory_init(PCMachineState *pcms,if (!pcmc->has_reserved_memory && (machine->ram_slots || (machine->maxram_size > machine->ram_size))) { -MachineClass *mc =MACHINE_GET_CLASS (machine);error_report ("\"-memory 'slots|maxmem'\" is not supported by: %s" , mc->name);
@@ -1871,7 +1869,8 @@ void pc_memory_init(PCMachineState *pcms, option_rom_mr, 1); - fw_cfg =fw_cfg_arch_create (pcms, pcms->boot_cpus, pcms->apic_id_limit); + fw_cfg =fw_cfg_arch_create (pcms, mc->possible_cpu_arch_ids (machine), + pcms->boot_cpus, pcms->apic_id_limit);rom_set_fw (fw_cfg);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 28/29] hw/i386/pc: Rename pc_build_feature_control() as generic fw_cfg_build_*
In reply to Paolo BonziniFrom: Philippe Mathieu-Daudé <[email protected]>
Now that the pc_build_feature_control_file() function has been refactored to not depend of PC specific types, rename it to a more generic name.
Message-Id: <[email protected]>
--- hw/i386/pc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/i386/pc.c +3 -3
@@ -1623,8 +1623,8 @@ void pc_cpus_init(PCMachineState *pcms) } } -static void pc_build_feature_control_file (MachineState *ms, -FWCfgState *fw_cfg) +static void fw_cfg_build_feature_control (MachineState *ms, +FWCfgState *fw_cfg) {X86CPU *cpu =X86_CPU (ms->possible_cpus->cpus[0 ].cpu);CPUX86State *env = &cpu->env;
@@ -1695,7 +1695,7 @@ void pc_machine_done(Notifier *notifier, void *data)acpi_setup ();if (pcms->fw_cfg) {fw_cfg_build_smbios (MACHINE (pcms), pcms->fw_cfg); -pc_build_feature_control_file (MACHINE (pcms), pcms->fw_cfg); +fw_cfg_build_feature_control (MACHINE (pcms), pcms->fw_cfg);/* update FW_CFG_NB_CPUS to account for -device added CPUs */ fw_cfg_modify_i16 (pcms->fw_cfg,FW_CFG_NB_CPUS , pcms->boot_cpus); }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 22/29] hw/i386/pc: Replace PCMachineState argument with MachineState in fw_cfg_arch_create
In reply to Paolo BonziniIn the previous commit we removed the last access to PCMachineState. Replace it with a generic MachineState argument and use it to retrieve the CPUArchIdList.
--- hw/i386/pc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
hw/i386/pc.c +4 -4
@@ -936,15 +936,15 @@ static void pc_build_smbios(PCMachineState *pcms) } } -static FWCfgState *fw_cfg_arch_create (PCMachineState *pcms, -const CPUArchIdList *cpus, +static FWCfgState *fw_cfg_arch_create (MachineState *ms,uint16_t boot_cpus,uint16_t apic_id_limit) {FWCfgState *fw_cfg;uint64_t *numa_fw_cfg;int i; -MachineState *ms =MACHINE (pcms); +MachineClass *mc =MACHINE_GET_CLASS (ms); +const CPUArchIdList *cpus = mc->possible_cpu_arch_ids (ms);int nb_numa_nodes = ms->numa_state->num_nodes; fw_cfg = fw_cfg_init_io_dma(FW_CFG_IO_BASE, FW_CFG_IO_BASE + 4,
@@ -1869,7 +1869,7 @@ void pc_memory_init(PCMachineState *pcms, option_rom_mr, 1); - fw_cfg =fw_cfg_arch_create (pcms, mc->possible_cpu_arch_ids (machine), + fw_cfg =fw_cfg_arch_create (machine, pcms->boot_cpus, pcms->apic_id_limit);rom_set_fw (fw_cfg);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 27/29] hw/i386/pc: Let pc_build_feature_control() take a MachineState argument
In reply to Paolo BonziniFrom: Philippe Mathieu-Daudé <[email protected]>
Let the pc_build_feature_control_file() function take a generic MachineState argument.
Message-Id: <[email protected]>
--- hw/i386/pc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
hw/i386/pc.c +2 -3
@@ -1623,10 +1623,9 @@ void pc_cpus_init(PCMachineState *pcms) } } -static void pc_build_feature_control_file (PCMachineState *pcms, +static void pc_build_feature_control_file (MachineState *ms,FWCfgState *fw_cfg) { -MachineState *ms =MACHINE (pcms);X86CPU *cpu =X86_CPU (ms->possible_cpus->cpus[0 ].cpu);CPUX86State *env = &cpu->env;uint32_t unused, ecx, edx;
@@ -1696,7 +1695,7 @@ void pc_machine_done(Notifier *notifier, void *data)acpi_setup ();if (pcms->fw_cfg) {fw_cfg_build_smbios (MACHINE (pcms), pcms->fw_cfg); -pc_build_feature_control_file (pcms, pcms->fw_cfg); +pc_build_feature_control_file (MACHINE (pcms), pcms->fw_cfg);/* update FW_CFG_NB_CPUS to account for -device added CPUs */ fw_cfg_modify_i16 (pcms->fw_cfg,FW_CFG_NB_CPUS , pcms->boot_cpus); }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 06/29] exec.c: add a check between constants to see whether we could skip
In reply to Paolo BonziniFrom: Wei Yang <[email protected]>
The maximum level is defined as P_L2_LEVELS and skip is defined with 6 bits, which means if P_L2_LEVELS < (1 << 6), skip never exceeds the boundary.
Since this check is between two constants, which leverages compiler to optimize the code based on different configuration.
Message-Id: <[email protected]>
--- exec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
exec.c +2 -1
@@ -324,7 +324,8 @@ static void phys_page_compact(PhysPageEntry *lp, Node *nodes)assert (valid_ptr <P_L2_SIZE );/* Don't compress if it won't fit in the # of bits we have. */ -if (lp->skip + p[valid_ptr].skip >= (1 <<6 )) { +if (P_L2_LEVELS >= (1 <<6 ) && + lp->skip + p[valid_ptr].skip >= (1 <<6 )) {return ; }
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 01/29] i386/kvm: support guest access CORE cstate
In reply to Paolo BonziniFrom: Wanpeng Li <[email protected]>
Allow guest reads CORE cstate when exposing host CPU power management capabilities to the guest. PKG cstate is restricted to avoid a guest to get the whole package information in multi-tenant scenario.
Message-Id: <[email protected]>
--- linux-headers/linux/kvm.h | 4 +++- target/i386/kvm.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-)
linux-headers/linux/kvm.h +3 -1
@@ -696,9 +696,11 @@ struct kvm_ioeventfd {#define KVM_X86_DISABLE_EXITS_MWAIT (1 << 0)#define KVM_X86_DISABLE_EXITS_HLT (1 << 1)#define KVM_X86_DISABLE_EXITS_PAUSE (1 << 2) +#define KVM_X86_DISABLE_EXITS_CSTATE (1 << 3)#define KVM_X86_DISABLE_VALID_EXITS (KVM_X86_DISABLE_EXITS_MWAIT | \ KVM_X86_DISABLE_EXITS_HLT | \ - KVM_X86_DISABLE_EXITS_PAUSE) + KVM_X86_DISABLE_EXITS_PAUSE | \ + KVM_X86_DISABLE_EXITS_CSTATE)/* for KVM_ENABLE_CAP */ struct kvm_enable_cap {
target/i386/kvm.c +2 -1
@@ -2076,7 +2076,8 @@ int kvm_arch_init(MachineState *ms, KVMState *s)if (disable_exits) { disable_exits &= (KVM_X86_DISABLE_EXITS_MWAIT |KVM_X86_DISABLE_EXITS_HLT | -KVM_X86_DISABLE_EXITS_PAUSE ); +KVM_X86_DISABLE_EXITS_PAUSE | +KVM_X86_DISABLE_EXITS_CSTATE ); } ret = kvm_vm_enable_cap(s, KVM_CAP_X86_DISABLE_EXITS, 0,
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 09/29] hw/i386: Move CONFIG_ACPI_PCI to CONFIG_PC
In reply to Paolo BonziniFrom: Cole Robinson <[email protected]>
CONFIG_ACPI_PCI is a hard requirement of acpi-build.c, which is built unconditionally for x86 target. Putting it in default-configs/ suggests that it can be easily disabled, which isn't true.
Relocate the symbol with the other acpi-build.c requirements, under 'config PC'. This is similar to what is done for the arm 'virt' machine type and CONFIG_ACPI_PCI
Message-Id: <e73e6edff68fd30d69c6a1d02c9ef9192f773c63.1568049871.git.crobinso@redhat.com>
--- default-configs/i386-softmmu.mak | 1 - hw/i386/Kconfig | 1 + 2 files changed, 1 insertion(+), 1 deletion(-)
default-configs/i386-softmmu.mak +0 -1
@@ -25,4 +25,3 @@ CONFIG_ISAPC=y CONFIG_I440FX=y CONFIG_Q35=y -CONFIG_ACPI_PCI=y
hw/i386/Kconfig +1 -0
@@ -29,6 +29,7 @@ config PC select MC146818RTC # For ACPI builder: select SERIAL_ISA + select ACPI_PCI select ACPI_VMGENID select VIRTIO_PMEM_SUPPORTED
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 12/29] memory: inline and optimize devend_memop
In reply to Paolo Bonzinidevend_memop can rely on the fact that the result is always either 0 or MO_BSWAP, corresponding respectively to host endianness and the opposite. Native (target) endianness in turn can be either the host endianness, in which case MO_BSWAP is only returned for host-opposite endianness, or the opposite, in which case 0 is only returned for host endianness.
With this in mind, devend_memop can be compiled as a setcond+shift for every target. Do this and, while at it, move it to include/exec/memory.h since !NEED_CPU_H files do not (and should not) need it.
--- include/exec/memory.h | 19 ++++++++++++++++++- memory.c | 18 ------------------ 2 files changed, 18 insertions(+), 19 deletions(-)
include/exec/memory.h +18 -1
@@ -2201,8 +2201,25 @@ address_space_write_cached(MemoryRegionCache *cache, hwaddr addr, } } +#ifdef NEED_CPU_H /* enum device_endian to MemOp. */ -MemOp devend_memop (enum device_endian end); +static inline MemOp devend_memop (enum device_endian end) +{ +QEMU_BUILD_BUG_ON (DEVICE_HOST_ENDIAN !=DEVICE_LITTLE_ENDIAN && +DEVICE_HOST_ENDIAN !=DEVICE_BIG_ENDIAN ); + +#if defined(HOST_WORDS_BIGENDIAN ) != defined(TARGET_WORDS_BIGENDIAN ) +/* Swap if non-host endianness or native (target) endianness */ +return (end ==DEVICE_HOST_ENDIAN ) ?0 :MO_BSWAP ; +#else +const int non_host_endianness = +DEVICE_LITTLE_ENDIAN ^DEVICE_BIG_ENDIAN ^DEVICE_HOST_ENDIAN ; + +/* In this case, native (target) endianness needs no swap. */ +return (end == non_host_endianness) ?MO_BSWAP :0 ; +#endif +} +#endif #endif
memory.c +0 -18
@@ -3267,21 +3267,3 @@ static void memory_register_types(void) }type_init (memory_register_types) - -MemOp devend_memop(enum device_endian end) -{ -static MemOp conv[] = { - [DEVICE_LITTLE_ENDIAN ] =MO_LE , - [DEVICE_BIG_ENDIAN ] =MO_BE , - [DEVICE_NATIVE_ENDIAN ] =MO_TE , - [DEVICE_HOST_ENDIAN ] =0 , - }; -switch (end) { -case DEVICE_LITTLE_ENDIAN : -case DEVICE_BIG_ENDIAN : -case DEVICE_NATIVE_ENDIAN : -return conv[end]; -default : -g_assert_not_reached (); - } -}
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 11/29] memory: fetch pmem size in get_file_size()
In reply to Paolo BonziniFrom: Stefan Hajnoczi <[email protected]>
Neither stat(2) nor lseek(2) report the size of Linux devdax pmem character device nodes. Commit 314aec4a6e06844937f1677f6cba21981005f389 ("hostmem-file: reject invalid pmem file sizes") added code to hostmem-file.c to fetch the size from sysfs and compare against the user-provided size=NUM parameter:
if (backend->size > size) {
error_setg(errp, "size property %" PRIu64 " is larger than "
"pmem file \"%s\" size %" PRIu64, backend->size,
fb->mem_path, size);
return;
}It turns out that exec.c:qemu_ram_alloc_from_fd() already has an equivalent size check but it skips devdax pmem character devices because lseek(2) returns 0:
if (file_size > 0 && file_size < size) {
error_setg(errp, "backing store %s size 0x%" PRIx64
" does not match 'size' option 0x" RAM_ADDR_FMT,
mem_path, file_size, size);
return NULL;
}This patch moves the devdax pmem file size code into get_file_size() so that we check the memory size in a single place:qemu_ram_alloc_from_fd(). This simplifies the code and makes it more general.
This also fixes the problem that hostmem-file only checks the devdax pmem file size when the pmem=on parameter is given. An unchecked size=NUM parameter can lead to SIGBUS in QEMU so we must always fetch the file size for Linux devdax pmem character device nodes.
Message-Id: <[email protected]>
--- backends/hostmem-file.c | 22 -------------------- exec.c | 34 ++++++++++++++++++++++++++++++- include/qemu/osdep.h | 13 ------------ util/oslib-posix.c | 54 ------------------------------------------------- util/oslib-win32.c | 6 ------ 5 files changed, 33 insertions(+), 96 deletions(-)
backends/hostmem-file.c +0 -22
@@ -58,28 +58,6 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)return ; } -/* -* Verify pmem file size since starting a guest with an incorrect size -* leads to confusing failures inside the guest. -*/ -if (fb->is_pmem) { -Error *local_err =NULL ; -uint64_t size; - - size =qemu_get_pmem_size (fb->mem_path, &local_err); -if (local_err) { -error_propagate (errp, local_err); -return ; - } - -if (size && backend->size > size) { -error_setg (errp,"size property %" PRIu64" is larger than " -"pmem file \"%s\" size %" PRIu64, backend->size, - fb->mem_path, size); -return ; - } - } - backend->force_prealloc = mem_prealloc; name =host_memory_backend_get_name (backend); memory_region_init_ram_from_file(&backend->mr, OBJECT(backend),
exec.c +33 -1
@@ -1791,7 +1791,39 @@ long qemu_maxrampagesize(void)#ifdef CONFIG_POSIX static int64_t get_file_size (int fd) { -int64_t size =lseek (fd,0 ,SEEK_END ); +int64_t size; +#if defined(__linux__) +struct stat st; + +if (fstat (fd, &st) <0 ) { +return -errno; + } + +/* Special handling for devdax character devices */ +if (S_ISCHR (st.st_mode)) { + g_autofree char *subsystem_path = NULL; + g_autofree char *subsystem = NULL; + + subsystem_path =g_strdup_printf ("/sys/dev/char/%d:%d/subsystem" , +major (st.st_rdev),minor (st.st_rdev)); + subsystem =g_file_read_link (subsystem_path,NULL ); + +if (subsystem &&g_str_has_suffix (subsystem,"/dax" )) { + g_autofree char *size_path = NULL; + g_autofree char *size_str = NULL; + + size_path =g_strdup_printf ("/sys/dev/char/%d:%d/size" , +major (st.st_rdev),minor (st.st_rdev)); + +if (g_file_get_contents (size_path, &size_str,NULL ,NULL )) { +return g_ascii_strtoll (size_str,NULL ,0 ); + } + } + } +#endif /* defined(__linux__) */ + +/* st.st_size may be zero for special files yet lseek(2) works */ + size =lseek (fd,0 ,SEEK_END );if (size <0 ) {return -errno; }
include/qemu/osdep.h +0 -13
@@ -571,19 +571,6 @@ void os_mem_prealloc(int fd, char *area, size_t sz, int smp_cpus, Error **errp);/** -* qemu_get_pmem_size: -* @filename: path to a pmem file -* @errp: pointer to a NULL-initialized error object -* -* Determine the size of a persistent memory file. Besides supporting files on -* DAX file systems, this function also supports Linux devdax character -* devices. -* -* Returns: the size or 0 on failure -*/ -uint64_t qemu_get_pmem_size (const char *filename,Error **errp); - -/** * qemu_get_pid_name: * @pid: pid of a process *
util/oslib-posix.c +0 -54
60 lines not on this page · raw message
util/oslib-win32.c +0 -6
@@ -562,12 +562,6 @@ void os_mem_prealloc(int fd, char *area, size_t memory, int smp_cpus, } } -uint64_t qemu_get_pmem_size (const char *filename,Error **errp) -{ -error_setg (errp,"pmem support not available" ); -return 0 ; -} -char *qemu_get_pid_name (pid_t pid) {/* XXX Implement me */
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 15/29] hw/i386/pc: Use e820_get_num_entries() to access e820_entries
In reply to Paolo BonziniFrom: Philippe Mathieu-Daudé <[email protected]>
To be able to extract the e820* code out of this file (in the next patch), access e820_entries with its correct helper.
Message-Id: <[email protected]>
--- hw/i386/pc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/pc.c +1 -1
@@ -1029,7 +1029,7 @@ static FWCfgState *bochs_bios_init(AddressSpace *as, PCMachineState *pcms)fw_cfg_add_bytes (fw_cfg,FW_CFG_E820_TABLE , &e820_reserve,sizeof (e820_reserve));fw_cfg_add_file (fw_cfg,"etc/e820" , e820_table, -sizeof (struct e820_entry ) * e820_entries); +sizeof (struct e820_entry ) *e820_get_num_entries ());fw_cfg_add_bytes (fw_cfg,FW_CFG_HPET , &hpet_cfg,sizeof (hpet_cfg));/* allocate memory for the NUMA channel: one (64bit) word for the number
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 14/29] cpus: Fix throttling during vm_stop
In reply to Paolo BonziniFrom: Yury Kotov <[email protected]>
Throttling thread sleeps in VCPU thread. For high throttle percentage this sleep is more than 10ms. E.g. for 60% - 15ms, for 99% - 990ms. vm_stop() kicks all VCPUs and waits for them. It's called at the end of migration and because of the long sleep the migration downtime might be more than 100ms even for downtime-limit 1ms.
Use qemu_cond_timedwait for high percentage to wake up during vm_stop.
Message-Id: <[email protected]>
--- cpus.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
cpus.c +17 -8
@@ -77,6 +77,8 @@#endif /* CONFIG_LINUX */ +static QemuMutex qemu_global_mutex; +int64_t max_delay;int64_t max_advance;
@@ -782,7 +784,7 @@ static void cpu_throttle_thread(CPUState *cpu, run_on_cpu_data opaque) {double pct;double throttle_ratio; -long sleeptime_ns; +int64_t sleeptime_ns, endtime_ns;if (!cpu_throttle_get_percentage ()) {return ;
@@ -790,11 +792,20 @@ static void cpu_throttle_thread(CPUState *cpu, run_on_cpu_data opaque) pct = (double )cpu_throttle_get_percentage ()/100 ; throttle_ratio = pct / (1 - pct); - sleeptime_ns = (long )(throttle_ratio *CPU_THROTTLE_TIMESLICE_NS ); - -qemu_mutex_unlock_iothread (); -g_usleep (sleeptime_ns /1000 );/* Convert ns to us for usleep call */ -qemu_mutex_lock_iothread (); +/* Add 1ns to fix double's rounding error (like 0.9999999...) */ + sleeptime_ns = (int64_t )(throttle_ratio *CPU_THROTTLE_TIMESLICE_NS +1 ); + endtime_ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) + sleeptime_ns; +while (sleeptime_ns >0 && !cpu->stop) { +if (sleeptime_ns >SCALE_MS ) { +qemu_cond_timedwait (cpu->halt_cond, &qemu_global_mutex, + sleeptime_ns /SCALE_MS ); + }else { +qemu_mutex_unlock_iothread (); +g_usleep (sleeptime_ns /SCALE_US ); +qemu_mutex_lock_iothread (); + } + sleeptime_ns = endtime_ns -qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); + }atomic_set (&cpu->throttle_thread_scheduled,0 ); }
@@ -1172,8 +1183,6 @@ static void qemu_init_sigbus(void) }#endif /* !CONFIG_LINUX */ -static QemuMutex qemu_global_mutex; -static QemuThread io_thread;/* cpu creation */
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 16/29] hw/i386/pc: Extract e820 memory layout code
In reply to Paolo BonziniFrom: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <[email protected]>
--- hw/i386/Makefile.objs | 2 +- hw/i386/e820_memory_layout.c | 59 ++++++++++++++++++++++++++++++++++++++++++ hw/i386/e820_memory_layout.h | 42 ++++++++++++++++++++++++++++++ hw/i386/pc.c | 61 +------------------------------------------- include/hw/i386/pc.h | 11 -------- target/i386/kvm.c | 1 + 6 files changed, 104 insertions(+), 72 deletions(-) create mode 100644 hw/i386/e820_memory_layout.c create mode 100644 hw/i386/e820_memory_layout.h
hw/i386/Makefile.objs +1 -1
@@ -1,5 +1,5 @@ obj-$(CONFIG_KVM) += kvm/ -obj-y += multiboot.o +obj-y += e820_memory_layout.o multiboot.o obj-y += pc.o obj-$(CONFIG_I440FX) += pc_piix.o obj-$(CONFIG_Q35) += pc_q35.o
hw/i386/e820_memory_layout.c new file +59 -0
59 lines not on this page · raw message
hw/i386/e820_memory_layout.h new file +42 -0
42 lines not on this page · raw message
hw/i386/pc.c +1 -60
79 lines not on this page · raw message
include/hw/i386/pc.h +0 -11
@@ -291,17 +291,6 @@ void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion *rom_memory);void pc_madt_cpu_entry (AcpiDeviceIf *adev,int uid,const CPUArchIdList *apic_ids,GArray *entry); -/* e820 types */ -#define E820_RAM 1 -#define E820_RESERVED 2 -#define E820_ACPI 3 -#define E820_NVS 4 -#define E820_UNUSABLE 5 - -int e820_add_entry (uint64_t ,uint64_t ,uint32_t ); -int e820_get_num_entries (void ); -bool e820_get_entry (int ,uint32_t ,uint64_t *,uint64_t *); -extern GlobalProperty pc_compat_4_1[];extern const size_t pc_compat_4_1_len;
target/i386/kvm.c +1 -0
@@ -41,6 +41,7 @@#include "hw/i386/apic-msidef.h" #include "hw/i386/intel_iommu.h" #include "hw/i386/x86-iommu.h" +#include "hw/i386/e820_memory_layout.h" #include "hw/pci/pci.h" #include "hw/pci/msi.h"
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 17/29] hw/i386/pc: Use address_space_memory in place
In reply to Paolo BonziniFrom: Philippe Mathieu-Daudé <[email protected]>
The address_space_memory variable is used once. Use it in place and remove the argument.
Message-Id: <[email protected]>
--- hw/i386/pc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
hw/i386/pc.c +4 -3
@@ -936,7 +936,7 @@ static void pc_build_smbios(PCMachineState *pcms) } } -static FWCfgState *bochs_bios_init (AddressSpace *as,PCMachineState *pcms) +static FWCfgState *bochs_bios_init (PCMachineState *pcms) {FWCfgState *fw_cfg;uint64_t *numa_fw_cfg;
@@ -946,7 +946,8 @@ static FWCfgState *bochs_bios_init(AddressSpace *as, PCMachineState *pcms)MachineState *ms =MACHINE (pcms);int nb_numa_nodes = ms->numa_state->num_nodes; - fw_cfg =fw_cfg_init_io_dma (FW_CFG_IO_BASE ,FW_CFG_IO_BASE +4 , as); + fw_cfg =fw_cfg_init_io_dma (FW_CFG_IO_BASE ,FW_CFG_IO_BASE +4 , + &address_space_memory);fw_cfg_add_i16 (fw_cfg,FW_CFG_NB_CPUS , pcms->boot_cpus);/* FW_CFG_MAX_CPUS is a bit confusing/problematic on x86:
@@ -1868,7 +1869,7 @@ void pc_memory_init(PCMachineState *pcms, option_rom_mr, 1); - fw_cfg =bochs_bios_init (&address_space_memory, pcms); + fw_cfg =bochs_bios_init (pcms);rom_set_fw (fw_cfg);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 18/29] hw/i386/pc: Rename bochs_bios_init as more generic fw_cfg_arch_create
In reply to Paolo BonziniFrom: Philippe Mathieu-Daudé <[email protected]>
The bochs_bios_init() function is not restricted to the Bochs BIOS and is useful to other BIOS.
Since it is not specific to the PC machine, and can be reused by other machines of the X86 architecture, rename it as fw_cfg_arch_create().
Message-Id: <[email protected]>
--- hw/i386/pc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/i386/pc.c +3 -3
@@ -936,7 +936,7 @@ static void pc_build_smbios(PCMachineState *pcms) } } -static FWCfgState *bochs_bios_init (PCMachineState *pcms) +static FWCfgState *fw_cfg_arch_create (PCMachineState *pcms) {FWCfgState *fw_cfg;uint64_t *numa_fw_cfg;
@@ -1614,7 +1614,7 @@ void pc_cpus_init(PCMachineState *pcms)* Limit for the APIC ID value, so that all * CPU APIC IDs are < pcms->apic_id_limit. * -* This is used for FW_CFG_MAX_CPUS. See comments on bochs_bios_init(). +* This is used for FW_CFG_MAX_CPUS. See comments on fw_cfg_arch_create(). */ pcms->apic_id_limit =x86_cpu_apic_id_from_index (pcms, ms->smp.max_cpus -1 ) +1 ;
@@ -1869,7 +1869,7 @@ void pc_memory_init(PCMachineState *pcms, option_rom_mr, 1); - fw_cfg =bochs_bios_init (pcms); + fw_cfg =fw_cfg_arch_create (pcms);rom_set_fw (fw_cfg);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 25/29] hw/i386/pc: Rename pc_build_smbios() as generic fw_cfg_build_smbios()
In reply to Paolo BonziniFrom: Philippe Mathieu-Daudé <[email protected]>
Now that the pc_build_smbios() function has been refactored to not depend of PC specific types, rename it to a more generic name.
Message-Id: <[email protected]>
--- hw/i386/pc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/i386/pc.c +2 -2
@@ -894,7 +894,7 @@ static uint32_t x86_cpu_apic_id_from_index(PCMachineState *pcms, } } -static void pc_build_smbios (MachineState *ms,FWCfgState *fw_cfg) +static void fw_cfg_build_smbios (MachineState *ms,FWCfgState *fw_cfg) {uint8_t *smbios_tables, *smbios_anchor;size_t smbios_tables_len, smbios_anchor_len;
@@ -1694,7 +1694,7 @@ void pc_machine_done(Notifier *notifier, void *data)acpi_setup ();if (pcms->fw_cfg) { -pc_build_smbios (MACHINE (pcms), pcms->fw_cfg); +fw_cfg_build_smbios (MACHINE (pcms), pcms->fw_cfg);pc_build_feature_control_file (pcms);/* update FW_CFG_NB_CPUS to account for -device added CPUs */ fw_cfg_modify_i16 (pcms->fw_cfg,FW_CFG_NB_CPUS , pcms->boot_cpus);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 19/29] hw/i386/pc: Pass the boot_cpus value by argument
In reply to Paolo BonziniFrom: Philippe Mathieu-Daudé <[email protected]>
The boot_cpus is used once. Pass it by argument, this will allow us to remove the PCMachineState argument later.
Message-Id: <[email protected]>
--- hw/i386/pc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
hw/i386/pc.c +4 -3
@@ -936,7 +936,8 @@ static void pc_build_smbios(PCMachineState *pcms) } } -static FWCfgState *fw_cfg_arch_create (PCMachineState *pcms) +static FWCfgState *fw_cfg_arch_create (PCMachineState *pcms, +uint16_t boot_cpus) {FWCfgState *fw_cfg;uint64_t *numa_fw_cfg;
@@ -948,7 +949,7 @@ static FWCfgState *fw_cfg_arch_create(PCMachineState *pcms) fw_cfg =fw_cfg_init_io_dma (FW_CFG_IO_BASE ,FW_CFG_IO_BASE +4 , &address_space_memory); -fw_cfg_add_i16 (fw_cfg,FW_CFG_NB_CPUS , pcms->boot_cpus); +fw_cfg_add_i16 (fw_cfg,FW_CFG_NB_CPUS , boot_cpus);/* FW_CFG_MAX_CPUS is a bit confusing/problematic on x86: *
@@ -1869,7 +1870,7 @@ void pc_memory_init(PCMachineState *pcms, option_rom_mr, 1); - fw_cfg =fw_cfg_arch_create (pcms); + fw_cfg =fw_cfg_arch_create (pcms, pcms->boot_cpus);rom_set_fw (fw_cfg);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 24/29] hw/i386/pc: Let pc_build_smbios() take a generic MachineState argument
In reply to Paolo BonziniFrom: Philippe Mathieu-Daudé <[email protected]>
Let the pc_build_smbios() function take a generic MachineState argument.
Message-Id: <[email protected]>
--- hw/i386/pc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
hw/i386/pc.c +2 -3
@@ -894,13 +894,12 @@ static uint32_t x86_cpu_apic_id_from_index(PCMachineState *pcms, } } -static void pc_build_smbios (PCMachineState *pcms,FWCfgState *fw_cfg) +static void pc_build_smbios (MachineState *ms,FWCfgState *fw_cfg) {uint8_t *smbios_tables, *smbios_anchor;size_t smbios_tables_len, smbios_anchor_len;struct smbios_phys_mem_area *mem_array;unsigned i, array_count; -MachineState *ms =MACHINE (pcms);X86CPU *cpu =X86_CPU (ms->possible_cpus->cpus[0 ].cpu);/* tell smbios about cpuid version and features */
@@ -1695,7 +1694,7 @@ void pc_machine_done(Notifier *notifier, void *data)acpi_setup ();if (pcms->fw_cfg) { -pc_build_smbios (pcms, pcms->fw_cfg); +pc_build_smbios (MACHINE (pcms), pcms->fw_cfg);pc_build_feature_control_file (pcms);/* update FW_CFG_NB_CPUS to account for -device added CPUs */ fw_cfg_modify_i16 (pcms->fw_cfg,FW_CFG_NB_CPUS , pcms->boot_cpus);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 23/29] hw/i386/pc: Let pc_build_smbios() take a FWCfgState argument
In reply to Paolo BonziniFrom: Philippe Mathieu-Daudé <[email protected]>
Pass the FWCfgState object by argument, this will allow us to remove the PCMachineState argument later.
Message-Id: <[email protected]>
--- hw/i386/pc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
hw/i386/pc.c +5 -5
@@ -894,7 +894,7 @@ static uint32_t x86_cpu_apic_id_from_index(PCMachineState *pcms, } } -static void pc_build_smbios (PCMachineState *pcms) +static void pc_build_smbios (PCMachineState *pcms,FWCfgState *fw_cfg) {uint8_t *smbios_tables, *smbios_anchor;size_t smbios_tables_len, smbios_anchor_len;
@@ -908,7 +908,7 @@ static void pc_build_smbios(PCMachineState *pcms) smbios_tables =smbios_get_table_legacy (ms, &smbios_tables_len);if (smbios_tables) { -fw_cfg_add_bytes (pcms->fw_cfg,FW_CFG_SMBIOS_ENTRIES , +fw_cfg_add_bytes (fw_cfg,FW_CFG_SMBIOS_ENTRIES , smbios_tables, smbios_tables_len); }
@@ -929,9 +929,9 @@ static void pc_build_smbios(PCMachineState *pcms)g_free (mem_array);if (smbios_anchor) { -fw_cfg_add_file (pcms->fw_cfg,"etc/smbios/smbios-tables" , +fw_cfg_add_file (fw_cfg,"etc/smbios/smbios-tables" , smbios_tables, smbios_tables_len); -fw_cfg_add_file (pcms->fw_cfg,"etc/smbios/smbios-anchor" , +fw_cfg_add_file (fw_cfg,"etc/smbios/smbios-anchor" , smbios_anchor, smbios_anchor_len); } }
@@ -1695,7 +1695,7 @@ void pc_machine_done(Notifier *notifier, void *data)acpi_setup ();if (pcms->fw_cfg) { -pc_build_smbios (pcms); +pc_build_smbios (pcms, pcms->fw_cfg);pc_build_feature_control_file (pcms);/* update FW_CFG_NB_CPUS to account for -device added CPUs */ fw_cfg_modify_i16 (pcms->fw_cfg,FW_CFG_NB_CPUS , pcms->boot_cpus);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 29/29] hw/i386/pc: Extract the x86 generic fw_cfg code
In reply to Paolo BonziniFrom: Philippe Mathieu-Daudé <[email protected]>
Extract all the functions that are not PC-machine specific into the (arch-specific) fw_cfg.c file. This will allow other X86-machine to reuse these functions.
Message-Id: <[email protected]>
--- hw/i386/fw_cfg.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/fw_cfg.h | 7 +++ hw/i386/pc.c | 132 +---------------------------------------------------- 3 files changed, 145 insertions(+), 131 deletions(-)
hw/i386/fw_cfg.c +137 -0
@@ -13,8 +13,15 @@*/ #include "qemu/osdep.h" +#include "sysemu/numa.h" +#include "hw/acpi/acpi.h" +#include "hw/firmware/smbios.h" +#include "hw/i386/pc.h" #include "hw/i386/fw_cfg.h" +#include "hw/timer/hpet.h" #include "hw/nvram/fw_cfg.h" +#include "e820_memory_layout.h" +#include "kvm_i386.h" const char *fw_cfg_arch_key_name (uint16_t key) {
@@ -36,3 +43,133 @@ const char *fw_cfg_arch_key_name(uint16_t key) }return NULL ; } + +void fw_cfg_build_smbios (MachineState *ms,FWCfgState *fw_cfg) +{ +uint8_t *smbios_tables, *smbios_anchor; +size_t smbios_tables_len, smbios_anchor_len; +struct smbios_phys_mem_area *mem_array; +unsigned i, array_count; +X86CPU *cpu =X86_CPU (ms->possible_cpus->cpus[0 ].cpu); + +/* tell smbios about cpuid version and features */ +smbios_set_cpuid (cpu->env.cpuid_version, cpu->env.features[FEAT_1_EDX ]); + + smbios_tables =smbios_get_table_legacy (ms, &smbios_tables_len); +if (smbios_tables) { +fw_cfg_add_bytes (fw_cfg,FW_CFG_SMBIOS_ENTRIES , + smbios_tables, smbios_tables_len); + } + +/* build the array of physical mem area from e820 table */ + mem_array =g_malloc0 (sizeof (*mem_array) *e820_get_num_entries ()); +for (i =0 , array_count =0 ; i <e820_get_num_entries (); i++) { +uint64_t addr, len; + +if (e820_get_entry (i,E820_RAM , &addr, &len)) { + mem_array[array_count].address = addr; + mem_array[array_count].length = len; + array_count++; + } + } +smbios_get_tables (ms, mem_array, array_count, + &smbios_tables, &smbios_tables_len, + &smbios_anchor, &smbios_anchor_len); +g_free (mem_array); + +if (smbios_anchor) { +fw_cfg_add_file (fw_cfg,"etc/smbios/smbios-tables" , + smbios_tables, smbios_tables_len); +fw_cfg_add_file (fw_cfg,"etc/smbios/smbios-anchor" , + smbios_anchor, smbios_anchor_len); + } +} + +FWCfgState *fw_cfg_arch_create (MachineState *ms, +uint16_t boot_cpus, +uint16_t apic_id_limit) +{ +FWCfgState *fw_cfg; +uint64_t *numa_fw_cfg; +int i; +MachineClass *mc =MACHINE_GET_CLASS (ms); +const CPUArchIdList *cpus = mc->possible_cpu_arch_ids (ms); +int nb_numa_nodes = ms->numa_state->num_nodes; + + fw_cfg =fw_cfg_init_io_dma (FW_CFG_IO_BASE ,FW_CFG_IO_BASE +4 , + &address_space_memory); +fw_cfg_add_i16 (fw_cfg,FW_CFG_NB_CPUS , boot_cpus); + +/* FW_CFG_MAX_CPUS is a bit confusing/problematic on x86: +* +* For machine types prior to 1.8, SeaBIOS needs FW_CFG_MAX_CPUS for +* building MPTable, ACPI MADT, ACPI CPU hotplug and ACPI SRAT table, +* that tables are based on xAPIC ID and QEMU<->SeaBIOS interface +* for CPU hotplug also uses APIC ID and not "CPU index". +* This means that FW_CFG_MAX_CPUS is not the "maximum number of CPUs", +* but the "limit to the APIC ID values SeaBIOS may see". +* +* So for compatibility reasons with old BIOSes we are stuck with +* "etc/max-cpus" actually being apic_id_limit +*/ +fw_cfg_add_i16 (fw_cfg,FW_CFG_MAX_CPUS , apic_id_limit); +fw_cfg_add_i64 (fw_cfg,FW_CFG_RAM_SIZE , (uint64_t )ram_size); +fw_cfg_add_bytes (fw_cfg,FW_CFG_ACPI_TABLES , + acpi_tables, acpi_tables_len); +fw_cfg_add_i32 (fw_cfg,FW_CFG_IRQ0_OVERRIDE ,kvm_allows_irq0_override ()); + +fw_cfg_add_bytes (fw_cfg,FW_CFG_E820_TABLE , + &e820_reserve,sizeof (e820_reserve)); +fw_cfg_add_file (fw_cfg,"etc/e820" , e820_table, +sizeof (struct e820_entry ) *e820_get_num_entries ()); + +fw_cfg_add_bytes (fw_cfg,FW_CFG_HPET , &hpet_cfg,sizeof (hpet_cfg)); +/* allocate memory for the NUMA channel: one (64bit) word for the number +* of nodes, one word for each VCPU->node and one word for each node to +* hold the amount of memory. +*/ + numa_fw_cfg =g_new0 (uint64_t,1 + apic_id_limit + nb_numa_nodes); + numa_fw_cfg[0 ] =cpu_to_le64 (nb_numa_nodes); +for (i =0 ; i < cpus->len; i++) { +unsigned int apic_id = cpus->cpus[i].arch_id; +assert (apic_id < apic_id_limit); + numa_fw_cfg[apic_id +1 ] =cpu_to_le64 (cpus->cpus[i].props.node_id); + } +for (i =0 ; i < nb_numa_nodes; i++) { + numa_fw_cfg[apic_id_limit +1 + i] = +cpu_to_le64 (ms->numa_state->nodes[i].node_mem); + } +fw_cfg_add_bytes (fw_cfg,FW_CFG_NUMA , numa_fw_cfg, + (1 + apic_id_limit + nb_numa_nodes) * +sizeof (*numa_fw_cfg)); + +return fw_cfg; +} + +void fw_cfg_build_feature_control (MachineState *ms,FWCfgState *fw_cfg) +{ +X86CPU *cpu =X86_CPU (ms->possible_cpus->cpus[0 ].cpu); +CPUX86State *env = &cpu->env; +uint32_t unused, ecx, edx; +uint64_t feature_control_bits =0 ; +uint64_t *val; + +cpu_x86_cpuid (env,1 ,0 , &unused, &unused, &ecx, &edx); +if (ecx &CPUID_EXT_VMX ) { + feature_control_bits |=FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX ; + } + +if ((edx & (CPUID_EXT2_MCE |CPUID_EXT2_MCA )) == + (CPUID_EXT2_MCE |CPUID_EXT2_MCA ) && + (env->mcg_cap &MCG_LMCE_P )) { + feature_control_bits |=FEATURE_CONTROL_LMCE ; + } + +if (!feature_control_bits) { +return ; + } + + val =g_malloc (sizeof (*val)); + *val =cpu_to_le64 (feature_control_bits |FEATURE_CONTROL_LOCKED ); +fw_cfg_add_file (fw_cfg,"etc/msr_feature_control" , val,sizeof (*val)); +}
hw/i386/fw_cfg.h +7 -0
@@ -9,6 +9,7 @@#ifndef HW_I386_FW_CFG_H #define HW_I386_FW_CFG_H +#include "hw/boards.h" #include "hw/nvram/fw_cfg.h" #define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0)
@@ -17,4 +18,10 @@#define FW_CFG_E820_TABLE (FW_CFG_ARCH_LOCAL + 3)#define FW_CFG_HPET (FW_CFG_ARCH_LOCAL + 4) +FWCfgState *fw_cfg_arch_create (MachineState *ms, +uint16_t boot_cpus, +uint16_t apic_id_limit); +void fw_cfg_build_smbios (MachineState *ms,FWCfgState *fw_cfg); +void fw_cfg_build_feature_control (MachineState *ms,FWCfgState *fw_cfg); +#endif
hw/i386/pc.c +1 -131
150 lines not on this page · raw message
Signature · 1 line
1.8.3.1