From nobody Thu Nov 6 08:26:17 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539764860072947.5622091576437; Wed, 17 Oct 2018 01:27:40 -0700 (PDT) Received: from localhost ([::1]:34493 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gChB4-00080r-F0 for importer@patchew.org; Wed, 17 Oct 2018 04:27:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50650) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCh9H-00073t-Mw for qemu-devel@nongnu.org; Wed, 17 Oct 2018 04:25:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCh9F-0008Hn-UM for qemu-devel@nongnu.org; Wed, 17 Oct 2018 04:25:47 -0400 Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]:34642) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gCh9F-0008HE-FA; Wed, 17 Oct 2018 04:25:45 -0400 Received: by mail-lj1-x243.google.com with SMTP id j17-v6so23509847lja.1; Wed, 17 Oct 2018 01:25:45 -0700 (PDT) Received: from localhost.localdomain ([77.221.221.49]) by smtp.gmail.com with ESMTPSA id h77-v6sm3897735ljf.59.2018.10.17.01.25.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Oct 2018 01:25:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=vZHCJVv1KF2WwajVEAqSXw7b0gTXnWkpg+f2UbWMyh0=; b=VKY4nL2AOCk6Fd6dzxrI4y8bhZ9YpE6B6M71l8nBmnKH40eyJNNn1DiuFHX71TIOWN tnjgIlNMxzYJac9qMoA7PTlaJVpLcG1k96gdilhIDOvu22RK2R7IXtxE22a2BZ9eQhCh URqUIos7ldxQtc3Q5ElW1Ilf1tLYFhspjuHljHg0kQarFN/e0vESyut9ukN99lFQLsh8 kFAELzYaXobjBq/ScREhak/MDH7vcnjJENa5KlnOyPfzA2AHla55qTjAUoSAmSjiuh0L qoGeDWyR/u8udbNKf3pyz0s7t34xitQUUB+Xl3z0sr82PSx+erpQINKPSDYO6qTgENKo OxMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=vZHCJVv1KF2WwajVEAqSXw7b0gTXnWkpg+f2UbWMyh0=; b=QSOr6w6/LcbDBcN4Zwxkp/12maXdCHVyF6Uc1K7v/xbs0JJy6WiY/XazESU8KSZEFE KoWvlgNt7bji0lN2ncd0py76QYIhw02a3GK22SE6No/ullUsrzaE5zZ178u5Mj/Wy6yh +BMJ6g+rm5WNuL/bAMPwuCeyDekeN/8SV17ubr3iuzN/nkW7LSkUDV1EroCTt9xSN1Zj /RsY59vbwY5zVKjJUiFM1arBhMz0gZlp5hqc/4RgA0485bU5mQCuiyUgvdoCQn45G/1j PwZ/IEg3Bs0WfwICeDHaYdD3pAO7Lqjcl61WpmJRgO7ufJyn4V92UbY+EAfXidaGDCWw IBwA== X-Gm-Message-State: ABuFfojAPt7K/gafXfwPSxpf+6Lteifj5NPM7fQZAju5lyZZpdxzLKEe HzIO5F785ARcomlkfp9AT3+zyfHmX9U= X-Google-Smtp-Source: ACcGV61cL7RjNFGJ/jQJd6hGId71Zb9fSW2bHyGdQuOvQpnKfGvTW7/XGLi0Pa9Z2bbXM87kktusMg== X-Received: by 2002:a2e:638d:: with SMTP id s13-v6mr15659002lje.117.1539764743437; Wed, 17 Oct 2018 01:25:43 -0700 (PDT) From: Artem Pisarenko To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 14:24:19 +0600 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::243 Subject: [Qemu-devel] [PATCH v2 2/4] Introduce attributes to qemu timer subsystem X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , Pavel Dovgalyuk , "open list:Block I/O path" , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , Artem Pisarenko Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Attributes are simple flags, associated with individual timers for their wh= ole lifetime. They intended to be used to mark individual timers for special handling by = various qemu features operating at qemu core level. New/init functions family in timer interface updated and refactored (new 'a= ttribute' argument added, timer_list replaced with timer_list_group+type co= mbinations, comments improved to avoid info duplication). Also existing aio interface extended with attribute-enabled variants of fun= ctions, which create/initialize timers. Signed-off-by: Artem Pisarenko --- Notes: v2: - timer creation/initialize functions reworked and and their unnecessar= y variants removed (as Paolo Bonzini suggested) - also their comments improved to avoid info duplication include/block/aio.h | 57 ++++++++++++++++++--- include/qemu/timer.h | 128 ++++++++++++++++++++++++++----------------= ---- tests/ptimer-test-stubs.c | 13 +++-- util/qemu-timer.c | 18 +++++-- 4 files changed, 146 insertions(+), 70 deletions(-) diff --git a/include/block/aio.h b/include/block/aio.h index f08630c..fce9d48 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -388,6 +388,31 @@ struct LinuxAioState *aio_setup_linux_aio(AioContext *= ctx, Error **errp); struct LinuxAioState *aio_get_linux_aio(AioContext *ctx); =20 /** + * aio_timer_new_with_attrs: + * @ctx: the aio context + * @type: the clock type + * @scale: the scale + * @attributes: 0, or one to multiple OR'ed QEMU_TIMER_ATTR(id) values to = assign + * @cb: the callback to call on timer expiry + * @opaque: the opaque pointer to pass to the callback + * + * Allocate a new timer (with attributes) attached to the context @ctx. + * The function is responsible for memory allocation. + * + * The preferred interface is aio_timer_init or aio_timer_init_with_attrs. + * Use that unless you really need dynamic memory allocation. + * + * Returns: a pointer to the new timer + */ +static inline QEMUTimer *aio_timer_new_with_attrs(AioContext *ctx, + QEMUClockType type, + int scale, int attribute= s, + QEMUTimerCB *cb, void *o= paque) +{ + return timer_new_full(&ctx->tlg, type, scale, attributes, cb, opaque); +} + +/** * aio_timer_new: * @ctx: the aio context * @type: the clock type @@ -396,10 +421,7 @@ struct LinuxAioState *aio_get_linux_aio(AioContext *ct= x); * @opaque: the opaque pointer to pass to the callback * * Allocate a new timer attached to the context @ctx. - * The function is responsible for memory allocation. - * - * The preferred interface is aio_timer_init. Use that - * unless you really need dynamic memory allocation. + * See aio_timer_new_with_attrs for details. * * Returns: a pointer to the new timer */ @@ -407,7 +429,28 @@ static inline QEMUTimer *aio_timer_new(AioContext *ctx= , QEMUClockType type, int scale, QEMUTimerCB *cb, void *opaque) { - return timer_new_tl(ctx->tlg.tl[type], scale, cb, opaque); + return timer_new_full(&ctx->tlg, type, scale, 0, cb, opaque); +} + +/** + * aio_timer_init_with_attrs: + * @ctx: the aio context + * @ts: the timer + * @type: the clock type + * @scale: the scale + * @attributes: 0, or one to multiple OR'ed QEMU_TIMER_ATTR(id) values to = assign + * @cb: the callback to call on timer expiry + * @opaque: the opaque pointer to pass to the callback + * + * Initialise a new timer (with attributes) attached to the context @ctx. + * The caller is responsible for memory allocation. + */ +static inline void aio_timer_init_with_attrs(AioContext *ctx, + QEMUTimer *ts, QEMUClockType = type, + int scale, int attributes, + QEMUTimerCB *cb, void *opaque) +{ + timer_init_full(ts, &ctx->tlg, type, scale, attributes, cb, opaque); } =20 /** @@ -420,14 +463,14 @@ static inline QEMUTimer *aio_timer_new(AioContext *ct= x, QEMUClockType type, * @opaque: the opaque pointer to pass to the callback * * Initialise a new timer attached to the context @ctx. - * The caller is responsible for memory allocation. + * See aio_timer_init_with_attrs for details. */ static inline void aio_timer_init(AioContext *ctx, QEMUTimer *ts, QEMUClockType type, int scale, QEMUTimerCB *cb, void *opaque) { - timer_init_tl(ts, ctx->tlg.tl[type], scale, cb, opaque); + timer_init_full(ts, &ctx->tlg, type, scale, 0, cb, opaque); } =20 /** diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 39ea907..e225ad4 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -52,6 +52,28 @@ typedef enum { QEMU_CLOCK_MAX } QEMUClockType; =20 +/** + * QEMU Timer attributes: + * + * An individual timer may be assigned with one or multiple attributes when + * initialized. + * Attribute is a static flag, meaning that timer has corresponding proper= ty. + * Attributes are defined in QEMUTimerAttrBit enum and encoded to bit set, + * which used to initialize timer, stored to 'attributes' member and can be + * retrieved externally with timer_get_attributes() call. + * Values of QEMUTimerAttrBit aren't used directly, + * instead each attribute in bit set accessed with QEMU_TIMER_ATTR_ ma= cro, + * where is a unique part of attribute identifier. + * + * No attributes defined currently. + */ + +typedef enum { + QEMU_TIMER_ATTRBIT__NONE +} QEMUTimerAttrBit; + +#define QEMU_TIMER_ATTR__NONE (1 << QEMU_TIMER_ATTRBIT__NONE) + typedef struct QEMUTimerList QEMUTimerList; =20 struct QEMUTimerListGroup { @@ -67,6 +89,7 @@ struct QEMUTimer { QEMUTimerCB *cb; void *opaque; QEMUTimer *next; + int attributes; int scale; }; =20 @@ -418,22 +441,27 @@ int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup= *tlg); */ =20 /** - * timer_init_tl: + * timer_init_full: * @ts: the timer to be initialised - * @timer_list: the timer list to attach the timer to + * @timer_list_group: (optional) the timer list group to attach the timer = to + * @type: the clock type to use * @scale: the scale value for the timer + * @attributes: 0, or one to multiple OR'ed QEMU_TIMER_ATTR(id) values to = assign * @cb: the callback to be called when the timer expires * @opaque: the opaque pointer to be passed to the callback * - * Initialise a new timer and associate it with @timer_list. + * Initialise a timer with the given scale and attributes, + * and associate it with timer list for given clock @type in @timer_list_g= roup + * (or default timer list group, if NULL). * The caller is responsible for allocating the memory. * * You need not call an explicit deinit call. Simply make * sure it is not on a list with timer_del. */ -void timer_init_tl(QEMUTimer *ts, - QEMUTimerList *timer_list, int scale, - QEMUTimerCB *cb, void *opaque); +void timer_init_full(QEMUTimer *ts, + QEMUTimerListGroup *timer_list_group, QEMUClockType t= ype, + int scale, int attributes, + QEMUTimerCB *cb, void *opaque); =20 /** * timer_init: @@ -445,14 +473,12 @@ void timer_init_tl(QEMUTimer *ts, * * Initialize a timer with the given scale on the default timer list * associated with the clock. - * - * You need not call an explicit deinit call. Simply make - * sure it is not on a list with timer_del. + * See timer_init_full for details. */ static inline void timer_init(QEMUTimer *ts, QEMUClockType type, int scale, QEMUTimerCB *cb, void *opaque) { - timer_init_tl(ts, main_loop_tlg.tl[type], scale, cb, opaque); + timer_init_full(ts, &main_loop_tlg, type, scale, 0, cb, opaque); } =20 /** @@ -464,9 +490,7 @@ static inline void timer_init(QEMUTimer *ts, QEMUClockT= ype type, int scale, * * Initialize a timer with nanosecond scale on the default timer list * associated with the clock. - * - * You need not call an explicit deinit call. Simply make - * sure it is not on a list with timer_del. + * See timer_init_full for details. */ static inline void timer_init_ns(QEMUTimer *ts, QEMUClockType type, QEMUTimerCB *cb, void *opaque) @@ -483,9 +507,7 @@ static inline void timer_init_ns(QEMUTimer *ts, QEMUClo= ckType type, * * Initialize a timer with microsecond scale on the default timer list * associated with the clock. - * - * You need not call an explicit deinit call. Simply make - * sure it is not on a list with timer_del. + * See timer_init_full for details. */ static inline void timer_init_us(QEMUTimer *ts, QEMUClockType type, QEMUTimerCB *cb, void *opaque) @@ -502,9 +524,7 @@ static inline void timer_init_us(QEMUTimer *ts, QEMUClo= ckType type, * * Initialize a timer with millisecond scale on the default timer list * associated with the clock. - * - * You need not call an explicit deinit call. Simply make - * sure it is not on a list with timer_del. + * See timer_init_full for details. */ static inline void timer_init_ms(QEMUTimer *ts, QEMUClockType type, QEMUTimerCB *cb, void *opaque) @@ -513,27 +533,37 @@ static inline void timer_init_ms(QEMUTimer *ts, QEMUC= lockType type, } =20 /** - * timer_new_tl: - * @timer_list: the timer list to attach the timer to + * timer_new_full: + * @timer_list_group: (optional) the timer list group to attach the timer = to + * @type: the clock type to use * @scale: the scale value for the timer + * @attributes: 0, or one to multiple OR'ed QEMU_TIMER_ATTR(id) values to = assign * @cb: the callback to be called when the timer expires * @opaque: the opaque pointer to be passed to the callback * - * Create a new timer and associate it with @timer_list. + * Create a new timer with the given scale and attributes, + * and associate it with timer list for given clock @type in @timer_list_g= roup + * (or default timer list group, if NULL). * The memory is allocated by the function. * * This is not the preferred interface unless you know you - * are going to call timer_free. Use timer_init instead. + * are going to call timer_free. Use timer_init or timer_init_full instead. + * + * The default timer list has one special feature: in icount mode, + * %QEMU_CLOCK_VIRTUAL timers are run in the vCPU thread. This is + * not true of other timer lists, which are typically associated + * with an AioContext---each of them runs its timer callbacks in its own + * AioContext thread. * * Returns: a pointer to the timer */ -static inline QEMUTimer *timer_new_tl(QEMUTimerList *timer_list, - int scale, - QEMUTimerCB *cb, - void *opaque) +static inline QEMUTimer *timer_new_full(QEMUTimerListGroup *timer_list_gro= up, + QEMUClockType type, + int scale, int attributes, + QEMUTimerCB *cb, void *opaque) { QEMUTimer *ts =3D g_malloc0(sizeof(QEMUTimer)); - timer_init_tl(ts, timer_list, scale, cb, opaque); + timer_init_full(ts, timer_list_group, type, scale, attributes, cb, opa= que); return ts; } =20 @@ -544,21 +574,16 @@ static inline QEMUTimer *timer_new_tl(QEMUTimerList *= timer_list, * @cb: the callback to be called when the timer expires * @opaque: the opaque pointer to be passed to the callback * - * Create a new timer and associate it with the default - * timer list for the clock type @type. - * - * The default timer list has one special feature: in icount mode, - * %QEMU_CLOCK_VIRTUAL timers are run in the vCPU thread. This is - * not true of other timer lists, which are typically associated - * with an AioContext---each of them runs its timer callbacks in its own - * AioContext thread. + * Create a new timer with the given scale, + * and associate it with the default timer list for the clock type @type. + * See timer_new_full for details. * * Returns: a pointer to the timer */ static inline QEMUTimer *timer_new(QEMUClockType type, int scale, QEMUTimerCB *cb, void *opaque) { - return timer_new_tl(main_loop_tlg.tl[type], scale, cb, opaque); + return timer_new_full(&main_loop_tlg, type, scale, 0, cb, opaque); } =20 /** @@ -569,12 +594,7 @@ static inline QEMUTimer *timer_new(QEMUClockType type,= int scale, * * Create a new timer with nanosecond scale on the default timer list * associated with the clock. - * - * The default timer list has one special feature: in icount mode, - * %QEMU_CLOCK_VIRTUAL timers are run in the vCPU thread. This is - * not true of other timer lists, which are typically associated - * with an AioContext---each of them runs its timer callbacks in its own - * AioContext thread. + * See timer_new_full for details. * * Returns: a pointer to the newly created timer */ @@ -590,14 +610,9 @@ static inline QEMUTimer *timer_new_ns(QEMUClockType ty= pe, QEMUTimerCB *cb, * @cb: the callback to call when the timer expires * @opaque: the opaque pointer to pass to the callback * - * The default timer list has one special feature: in icount mode, - * %QEMU_CLOCK_VIRTUAL timers are run in the vCPU thread. This is - * not true of other timer lists, which are typically associated - * with an AioContext---each of them runs its timer callbacks in its own - * AioContext thread. - * * Create a new timer with microsecond scale on the default timer list * associated with the clock. + * See timer_new_full for details. * * Returns: a pointer to the newly created timer */ @@ -613,14 +628,9 @@ static inline QEMUTimer *timer_new_us(QEMUClockType ty= pe, QEMUTimerCB *cb, * @cb: the callback to call when the timer expires * @opaque: the opaque pointer to pass to the callback * - * The default timer list has one special feature: in icount mode, - * %QEMU_CLOCK_VIRTUAL timers are run in the vCPU thread. This is - * not true of other timer lists, which are typically associated - * with an AioContext---each of them runs its timer callbacks in its own - * AioContext thread. - * * Create a new timer with millisecond scale on the default timer list * associated with the clock. + * See timer_new_full for details. * * Returns: a pointer to the newly created timer */ @@ -631,6 +641,14 @@ static inline QEMUTimer *timer_new_ms(QEMUClockType ty= pe, QEMUTimerCB *cb, } =20 /** + * timer_get_attributes: + * @ts: the timer + * + * Return 0, or one to multiple OR'ed QEMU_TIMER_ATTR(id) values + */ +int timer_get_attributes(QEMUTimer *ts); + +/** * timer_deinit: * @ts: the timer to be de-initialised * diff --git a/tests/ptimer-test-stubs.c b/tests/ptimer-test-stubs.c index ca5cc3b..54b3fd2 100644 --- a/tests/ptimer-test-stubs.c +++ b/tests/ptimer-test-stubs.c @@ -34,14 +34,19 @@ int64_t ptimer_test_time_ns; int use_icount =3D 1; bool qtest_allowed; =20 -void timer_init_tl(QEMUTimer *ts, - QEMUTimerList *timer_list, int scale, - QEMUTimerCB *cb, void *opaque) +void timer_init_full(QEMUTimer *ts, + QEMUTimerListGroup *timer_list_group, QEMUClockType t= ype, + int scale, int attributes, + QEMUTimerCB *cb, void *opaque) { - ts->timer_list =3D timer_list; + if (!timer_list_group) { + timer_list_group =3D &main_loop_tlg; + } + ts->timer_list =3D timer_list_group->tl[type]; ts->cb =3D cb; ts->opaque =3D opaque; ts->scale =3D scale; + ts->attributes =3D attributes; ts->expire_time =3D -1; } =20 diff --git a/util/qemu-timer.c b/util/qemu-timer.c index 86bfe84..2046b68 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -339,17 +339,27 @@ int qemu_poll_ns(GPollFD *fds, guint nfds, int64_t ti= meout) } =20 =20 -void timer_init_tl(QEMUTimer *ts, - QEMUTimerList *timer_list, int scale, - QEMUTimerCB *cb, void *opaque) +void timer_init_full(QEMUTimer *ts, + QEMUTimerListGroup *timer_list_group, QEMUClockType t= ype, + int scale, int attributes, + QEMUTimerCB *cb, void *opaque) { - ts->timer_list =3D timer_list; + if (!timer_list_group) { + timer_list_group =3D &main_loop_tlg; + } + ts->timer_list =3D timer_list_group->tl[type]; ts->cb =3D cb; ts->opaque =3D opaque; ts->scale =3D scale; + ts->attributes =3D attributes; ts->expire_time =3D -1; } =20 +int timer_get_attributes(QEMUTimer *ts) +{ + return ts->attributes; +} + void timer_deinit(QEMUTimer *ts) { assert(ts->expire_time =3D=3D -1); --=20 2.7.4