mirror of
https://github.com/qemu/qemu.git
synced 2026-07-08 17:46:10 +00:00
Introduce a configurable poll-weight parameter for adaptive polling in IOThread. This parameter replaces the hardcoded POLL_WEIGHT_SHIFT constant, allowing runtime control over how much the most recent event interval affects the next polling duration calculation. The poll-weight parameter uses a shift value where larger values decrease the weight of the current interval, enabling more gradual adjustments. When set to 0, a default value of 3 is used (meaning the current interval contributes approximately 1/8 to the weighted average). This patch also removes the hardcoded default value checks from adjust_polling_time(). Instead, poll-grow, poll-shrink, and poll-weight now use default values initialized in iothread.c during IOThread creation. Signed-off-by: Jaehoon Kim <jhkim@linux.ibm.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Acked-by: Markus Armbruster <armbru@redhat.com> Message-ID: <20260423195918.661299-4-jhkim@linux.ibm.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
86 lines
2.3 KiB
C
86 lines
2.3 KiB
C
/*
|
|
* Event loop thread
|
|
*
|
|
* Copyright Red Hat Inc., 2013
|
|
*
|
|
* Authors:
|
|
* Stefan Hajnoczi <stefanha@redhat.com>
|
|
*
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
* See the COPYING file in the top-level directory.
|
|
*
|
|
*/
|
|
|
|
#ifndef IOTHREAD_H
|
|
#define IOTHREAD_H
|
|
|
|
#include "qemu/aio.h"
|
|
#include "qemu/thread.h"
|
|
#include "qom/object.h"
|
|
#include "system/event-loop-base.h"
|
|
|
|
#define TYPE_IOTHREAD "iothread"
|
|
|
|
#ifdef CONFIG_POSIX
|
|
/*
|
|
* Benchmark results from 2016 on NVMe SSD drives show max polling times around
|
|
* 16-32 microseconds yield IOPS improvements for both iodepth=1 and iodepth=32
|
|
* workloads.
|
|
*/
|
|
#define IOTHREAD_POLL_MAX_NS_DEFAULT 32768ULL
|
|
#define IOTHREAD_POLL_GROW_DEFAULT 2ULL
|
|
#define IOTHREAD_POLL_SHRINK_DEFAULT 2ULL
|
|
#define IOTHREAD_POLL_WEIGHT_DEFAULT 3ULL
|
|
#else
|
|
#define IOTHREAD_POLL_MAX_NS_DEFAULT 0ULL
|
|
#define IOTHREAD_POLL_GROW_DEFAULT 0ULL
|
|
#define IOTHREAD_POLL_SHRINK_DEFAULT 0ULL
|
|
#define IOTHREAD_POLL_WEIGHT_DEFAULT 0ULL
|
|
#endif
|
|
|
|
struct IOThread {
|
|
EventLoopBase parent_obj;
|
|
|
|
QemuThread thread;
|
|
AioContext *ctx;
|
|
bool run_gcontext; /* whether we should run gcontext */
|
|
GMainContext *worker_context;
|
|
GMainLoop *main_loop;
|
|
QemuSemaphore init_done_sem; /* is thread init done? */
|
|
bool stopping; /* has iothread_stop() been called? */
|
|
bool running; /* should iothread_run() continue? */
|
|
int thread_id;
|
|
|
|
/* AioContext poll parameters */
|
|
int64_t poll_max_ns;
|
|
int64_t poll_grow;
|
|
int64_t poll_shrink;
|
|
int64_t poll_weight;
|
|
};
|
|
typedef struct IOThread IOThread;
|
|
|
|
DECLARE_INSTANCE_CHECKER(IOThread, IOTHREAD,
|
|
TYPE_IOTHREAD)
|
|
|
|
char *iothread_get_id(IOThread *iothread);
|
|
IOThread *iothread_by_id(const char *id);
|
|
AioContext *iothread_get_aio_context(IOThread *iothread);
|
|
GMainContext *iothread_get_g_main_context(IOThread *iothread);
|
|
|
|
/*
|
|
* Helpers used to allocate iothreads for internal use. These
|
|
* iothreads will not be seen by monitor clients when query using
|
|
* "query-iothreads".
|
|
*/
|
|
IOThread *iothread_create(const char *id, Error **errp);
|
|
void iothread_stop(IOThread *iothread);
|
|
void iothread_destroy(IOThread *iothread);
|
|
|
|
/*
|
|
* Returns true if executing within IOThread context,
|
|
* false otherwise.
|
|
*/
|
|
bool qemu_in_iothread(void);
|
|
|
|
#endif /* IOTHREAD_H */
|