public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Richard Palethorpe <rpalethorpe@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v4 2/4] fzsync: Simplify API with start/end race calls and limit exec time
Date: Fri, 23 Nov 2018 15:55:30 +0100	[thread overview]
Message-ID: <874lc7c07x.fsf@rpws.prws.suse.cz> (raw)
In-Reply-To: <20181122154121.GB907@rei.lan>

Hello,

Cyril Hrubis <chrubis@suse.cz> writes:

> Hi!
>
> ...
>
>> +/** Wraps clock_gettime */
>>  static inline void tst_fzsync_time(struct timespec *t)
>>  {
>> +#ifdef CLOCK_MONOTONIC_RAW
>>  	clock_gettime(CLOCK_MONOTONIC_RAW, t);
>> +#else
>> +	clock_gettime(CLOCK_MONOTONIC, t);
>> +#endif
>>  }
>
> We should switch to a runtime detection here.
>
>>  /**
>> - * tst_fzsync_time_a - Set A's time to now.
>> + * Exponential moving average
>>   *
>> - * Called at the point you want to synchronise.
>> + * @param alpha The preference for recent samples over old ones.
>> + * @param sample The current sample
>> + * @param prev_avg The average of the all the previous samples
>> + *
>> + * @return The average including the current sample.
>>   */
>> -static inline void tst_fzsync_time_a(struct tst_fzsync_pair *pair)
>> +static inline float tst_exp_moving_avg(float alpha,
>> +					float sample,
>> +					float prev_avg)
>>  {
>> -	tst_fzsync_time(&pair->a);
>> +	return alpha * sample + (1.0 - alpha) * prev_avg;
>>  }
>
> ...
>
>> +static inline void tst_fzsync_pair_wait(int *our_cntr,
>> +					int *other_cntr,
>> +					int *spins)
>>  {
>>  	if (tst_atomic_inc(other_cntr) == INT_MAX) {
>>  		/*
>> @@ -243,84 +532,178 @@ static inline int tst_fzsync_pair_wait(struct tst_fzsync_pair *pair,
>>  		 * then our counter may already have been set to zero.
>>  		 */
>>  		while (tst_atomic_load(our_cntr) > 0
>> -		       && tst_atomic_load(our_cntr) < INT_MAX
>> -		       && !tst_atomic_load(&pair->exit))
>> -			;
>> +		       && tst_atomic_load(our_cntr) < INT_MAX) {
>> +			if (spins)
>> +				(*spins)++;
>> +		}
>>  
>>  		tst_atomic_store(0, other_cntr);
>>  		/*
>>  		 * Once both counters have been set to zero the invariant
>>  		 * is restored and we can continue.
>>  		 */
>> -		while (tst_atomic_load(our_cntr) > 1
>> -		       && !tst_atomic_load(&pair->exit))
>> +		while (tst_atomic_load(our_cntr) > 1)
>>  			;
>>  	} else {
>>  		/*
>>  		 * If our counter is less than the other thread's we are ahead
>>  		 * of it and need to wait.
>>  		 */
>> -		while (tst_atomic_load(our_cntr) < tst_atomic_load(other_cntr)
>> -		       && !tst_atomic_load(&pair->exit))
>> -			;
>> +		while (tst_atomic_load(our_cntr) < tst_atomic_load(other_cntr)) {
>> +			if (spins)
>> +				(*spins)++;
>
> I do wonder if the if () condition inside of the loop makes actually
> difference in the measurements. If it does we should pass a dummy
> pointer from the functions that pass NULL here.

AFAICT it is optimized out. All that is shown in the disassembler is

../../include/tst_fuzzy_sync.h:
547                                     (*spins)++;
   0x00000000004046f7 <+2023>:  addl   $0x1,0x1813a(%rip)        # 0x41c838 <fzsync_pair+120>

There is no reference to the if statement that I can see. I suppose that
if the function was not inlined then there might be an issue.

>
> -- 
> Cyril Hrubis
> chrubis@suse.cz


-- 
Thank you,
Richard.

  reply	other threads:[~2018-11-23 14:55 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-05 15:42 [LTP] [PATCH v4 0/4] New Fuzzy Sync library API Richard Palethorpe
2018-11-05 15:42 ` [LTP] [PATCH v4 1/4] tst_timer: Add nano second conversions Richard Palethorpe
2018-11-05 15:42 ` [LTP] [PATCH v4 2/4] fzsync: Simplify API with start/end race calls and limit exec time Richard Palethorpe
2018-11-22 15:41   ` Cyril Hrubis
2018-11-23 14:55     ` Richard Palethorpe [this message]
2018-11-05 15:42 ` [LTP] [PATCH v4 3/4] Convert tests to use fzsync_{start, end}_race API Richard Palethorpe
2018-11-05 15:42 ` [LTP] [PATCH v4 4/4] fzsync: Add delay bias for difficult races Richard Palethorpe
2018-11-29 15:19   ` Cyril Hrubis
2018-11-16 14:33 ` [LTP] [PATCH v4 0/4] New Fuzzy Sync library API Li Wang
2018-11-20 11:35   ` Richard Palethorpe
2018-11-20 13:09     ` Cyril Hrubis
2018-12-03 11:40       ` Richard Palethorpe
2018-11-22 15:35 ` 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=874lc7c07x.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox