All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Tesarik <ptesarik@suse.cz>
To: lijiang <lijiang@redhat.com>
Cc: Masaki Tachibana <mas-tachibana@vf.jp.nec.com>,
	Daisuke Nishimura <dai-nishimura@rc.jp.nec.com>,
	Takuya Nakayama <tak-nakayama@tg.jp.nec.com>,
	kexec-ml <kexec@lists.infradead.org>
Subject: Re: [PATCH] makedumpfile: Do not print ETA value if current progress is 0
Date: Tue, 10 Apr 2018 09:47:07 +0200	[thread overview]
Message-ID: <20180410094707.0d1ec7f2@ezekiel.suse.cz> (raw)
In-Reply-To: <90ec5728-2318-1074-0fc2-b02a69e6c7f4@redhat.com>

On Tue, 10 Apr 2018 15:09:37 +0800
lijiang <lijiang@redhat.com> wrote:

> 在 2018年04月09日 17:40, Petr Tesarik 写道:
>[...]
> > Last but not least, part of the issue was probably caused by the
> > wrong assumption that integers < 100 can be interpreted with max 3
> > ASCII characters, but that's not true for signed integers. To make
> > eta_to_human_short() a bit safer, use an unsigned integer type.  
> > > Signed-off-by: Petr Tesarik <ptesarik@suse.com>  
> Hi, Petr
> It is good that checks the value of "current".
> The previous patch resolved system crash in exceptional case. The calculation
> result of "calc_delta" may be very large number

Hmmm. The resulting ETA is in seconds. To overflow a 32-bit integer,
the elapsed time would have to be more than 2^32 seconds, or approx.
136 years. I think it is reasonable to assume that makedumpfile will
never run for more than a century...

> or even a negative number when making the time jump very great.

Yes, the current code will not produce sensible results if the system
clock moves backwards. With my patch it will most likely say: ">2day".
But it will not work any better if you use a 64-bit integer.

Instead, we should be using clock_gettime(CLOCK_MONOTONIC, ...).
That's a separate issue that I can solve in another patch.

> In this case, it is not enough for "unsigned
> integer type" and double. The struct timeval has two 64bit variables in x86 64.

First, of the second field (tv_usec), only 20 bits may actually be
used, because it can never be greater than one million.

Second, to make 100% sure that the target value fits into the eta
variable, you would have to consider the worst case:

  end = ULONG_MAX
  current = 1
  progress = 100.0 / ULONG_MAX
  delta = { ULONG_MAX, 999999 }
  eta = ULONG_MAX + 999999/1e6
  eta = (100 - progress) * eta / progress

Theoretically, this gives:

  eta = 340345831618257409870852130465035835837

Even a 128-bit integer is too small to hold this maximum theoretical
value (129 bits would be needed).

Let's stay reasonable. Any value which represents more than a few
(dozen) hours is not usable in practice. But hey, to make sure we
cannot hit undefined behaviour, why not pass a double to
eta_to_human_short()...

Going to send an updated patch.

Petr T

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

  reply	other threads:[~2018-04-10  7:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-09  9:40 [PATCH] makedumpfile: Do not print ETA value if current progress is 0 Petr Tesarik
2018-04-10  7:09 ` lijiang
2018-04-10  7:47   ` Petr Tesarik [this message]
2018-04-10  8:28     ` Petr Tesarik
2018-04-10 11:39       ` [PATCH v2] makedumpfile: Use integer arithmetics for the progress bar Petr Tesarik
2018-05-18  8:22         ` Masaki Tachibana
2018-05-18 12:46           ` Petr Tesarik
2018-06-20  3:07     ` [PATCH] makedumpfile: Do not print ETA value if current progress is 0 lijiang
2018-06-20  7:17       ` Petr Tesarik
2018-06-20 11:24         ` lijiang

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=20180410094707.0d1ec7f2@ezekiel.suse.cz \
    --to=ptesarik@suse.cz \
    --cc=dai-nishimura@rc.jp.nec.com \
    --cc=kexec@lists.infradead.org \
    --cc=lijiang@redhat.com \
    --cc=mas-tachibana@vf.jp.nec.com \
    --cc=tak-nakayama@tg.jp.nec.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.