All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Palethorpe <rpalethorpe@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH RFC v3 2/3] lib: introduce tst_timeout_remaining()
Date: Thu, 30 Aug 2018 11:46:11 +0200	[thread overview]
Message-ID: <87sh2wrxuk.fsf@rpws.prws.suse.cz> (raw)
In-Reply-To: <20180829143507.GD30074@rei>

Hello,

Cyril Hrubis <chrubis@suse.cz> writes:

> Hi!
>> > Maybe we should do something as:
>> >
>> > 	while (tst_timeout_remaining() > 2)
>> > 		sleep(1);
>> >
>> > 	tst_res(TPASS, ...);
>>
>> Yeah, I felt guilty adding more sleeps() :-).
>
> Well in this case it's reasonable use... ;-)
>
>> > And set timeout in tst_test to something as 10s, to really test the API.
>> >
>> > > +	if (remaining >= 200)
>> > > +		tst_res(TPASS, "Timeout remaining: %d", remaining);
>> > > +	else
>> > > +		tst_res(TFAIL, "Timeout remaining: %d", remaining);
>> > > +}
>> > > +
>> > > +static struct tst_test test = {
>> > > +	.test_all = run,
>> > > +};
>> > > diff --git a/lib/tst_test.c b/lib/tst_test.c
>> > > index 2f3d357d2fcc..75619fabffa4 100644
>> > > --- a/lib/tst_test.c
>> > > +++ b/lib/tst_test.c
>> > > @@ -47,6 +47,8 @@ static int iterations = 1;
>> > >  static float duration = -1;
>> > >  static pid_t main_pid, lib_pid;
>> > >  static int mntpoint_mounted;
>> > > +static clockid_t tst_clock;
>> > > +static struct timespec tst_start_time;
>> > >
>> > >  struct results {
>> > >  	int passed;
>> > > @@ -758,6 +760,7 @@ static void do_setup(int argc, char *argv[])
>> > >
>> > >  	if (tst_test->sample)
>> > >  		tst_test = tst_timer_test_setup(tst_test);
>> > > +	tst_clock = tst_timer_find_clock();
>> >
>> > I wonder if we really need this, we were running with CLOCK_MONOTONIC
>> > timer in the testrun() for quite some time now and nobody complained so
>> > far.
>>
>> I don't have strong opinion on this. It's fairly cheap to go through that list,
>> and we can be more courageous to change order later.
>
> We do use CLOCK_MONOTONIC in the tst_test.c unconditionally anyways, so
> I wouldn't bother with this unless somebody complains.
>
>> > Well I guess that it would be nice to use CLOCK_MONOTONIC_COARSE for the
>> > tst_timeout_remaining if available, which should save us some CPU since
>> > it's supposed to be called in a loop.

I doubt we will notice the difference in speed, if there is any on a
modern CPU. On all the implementations I found in glibc
CLOCK_MONOTONIC(_RAW) appears to just read a register value and scale it
to the CPU frequency. It doesn't look like an expensive operation in LTP
terms. However in some scenarious we definitely need a high resolution
clock.

I think defining TST_DEFAULT_CLOCK as CLOCK_MONOTONIC(_RAW) and using it
everywhere should be fine, although I don't have anything against
returning it from an inline function either.

--
Thank you,
Richard.

  reply	other threads:[~2018-08-30  9:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-28 14:40 [LTP] [PATCH RFC v3 1/3] lib: add tst_timer_find_clock() Jan Stancek
2018-08-28 14:40 ` [LTP] [PATCH RFC v3 2/3] lib: introduce tst_timeout_remaining() Jan Stancek
2018-08-29 13:08   ` Cyril Hrubis
2018-08-29 13:33     ` Jan Stancek
2018-08-29 14:35       ` Cyril Hrubis
2018-08-30  9:46         ` Richard Palethorpe [this message]
2018-08-30  7:21   ` Li Wang
2018-08-28 14:40 ` [LTP] [PATCH RFC v3 3/3] move_pages12: end early if runtime gets close to test time Jan Stancek
2018-08-29 13:18   ` Cyril Hrubis

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=87sh2wrxuk.fsf@rpws.prws.suse.cz \
    --to=rpalethorpe@suse.de \
    --cc=ltp@lists.linux.it \
    /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.