From: Vincent Fu <vincentfu@gmail.com>
To: "Michael Kelley (LINUX)" <mikelley@microsoft.com>,
"fio@vger.kernel.org" <fio@vger.kernel.org>,
"axboe@kernel.dk" <axboe@kernel.dk>,
"ankit.kumar@samsung.com" <ankit.kumar@samsung.com>
Subject: Re: [PATCH 1/1] thinktime: Avoid calculating a negative time left to wait
Date: Fri, 14 Jul 2023 14:06:05 -0400 [thread overview]
Message-ID: <3d8d379e-bfb2-89e0-2979-3a430638c61b@gmail.com> (raw)
In-Reply-To: <1689354334-131024-1-git-send-email-mikelley@microsoft.com>
On 7/14/23 13:06, Michael Kelley (LINUX) wrote:
> When the thinktime_spin option specifies a value that is within
> a few milliseconds of the thinktime value, in handle_thinktime()
> it's possible in a VM environment for the duration of usec_spin()
> to exceed the thinktime value. While doing usec_spin(), the vCPU
> could get de-scheduled or the hypervisor could steal CPU time
> from the vCPU. When the guest vCPU runs after being scheduled
> again, it may read the clock and find that more time has elapsed
> than intended. In such a case, the time left to wait could be
> calculated as a negative value. Subsequent calculations then go
> awry because the time left is cast as unsigned.
>
> Fix this by detecting when the time left would go negative and
> just set it to zero.
>
> Fixes: 1a9bf8146 ("Add option to ignore thinktime for rated IO")
> Fixes: https://github.com/axboe/fio/issues/1588
> Signed-off-by: Michael Kelley <mikelley@microsoft.com>
> ---
> backend.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/backend.c b/backend.c
> index d67a4a07..b06a11a5 100644
> --- a/backend.c
> +++ b/backend.c
> @@ -897,7 +897,16 @@ static void handle_thinktime(struct thread_data *td, enum fio_ddir ddir,
> if (left)
> total = usec_spin(left);
>
> - left = td->o.thinktime - total;
> + /*
> + * usec_spin() might run for slightly longer than intended in a VM
> + * where the vCPU could get descheduled or the hypervisor could steal
> + * CPU time. Ensure "left" doesn't become negative.
> + */
> + if (total < td->o.thinktime)
> + left = td->o.thinktime - total;
> + else
> + left = 0;
> +
> if (td->o.timeout) {
> runtime_left = td->o.timeout - utime_since_now(&td->epoch);
> if (runtime_left < (unsigned long long)left)
Applied, thanks!
Vincent
prev parent reply other threads:[~2023-07-14 18:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-14 17:06 [PATCH 1/1] thinktime: Avoid calculating a negative time left to wait Michael Kelley (LINUX)
2023-07-14 18:06 ` Vincent Fu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3d8d379e-bfb2-89e0-2979-3a430638c61b@gmail.com \
--to=vincentfu@gmail.com \
--cc=ankit.kumar@samsung.com \
--cc=axboe@kernel.dk \
--cc=fio@vger.kernel.org \
--cc=mikelley@microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).