public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Jan Stancek <jstancek@redhat.com>
Cc: jkastner@redhat.com, ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [PATCH 1/2] sched_setparam/9-1: fix hang on -rt kernel
Date: Mon, 2 Mar 2015 14:47:17 +0100	[thread overview]
Message-ID: <20150302134716.GA11619@rei> (raw)
In-Reply-To: <1750098575.20916844.1425303360282.JavaMail.zimbra@redhat.com>

Hi!
> > >  static void test_process(void)
> > >  {
> > > -	/* to avoid blocking */
> > > -	alarm(2);
> > > -
> > > -	while (1) {
> > > -		(*shmptr)++;
> > > +	struct sched_param param;
> > > +	time_t t1, t2;
> > > +
> > > +	t1 = time(NULL);
> > > +	do {
> > > +		sched_getparam(getpid(), &param);
> > > +		(*shmptr) = param.sched_priority;
> > > +		/* if we can see that our priority has changed
> > > +		 * that means we preempted parent, so we are done */
> > > +		if ((*shmptr) == mean_prio)
> > > +			break;
> > > +
> > > +		t2 = time(NULL);
> > > +		/* immediately after parent forks us, we has same
> > > +		 * priority and compete with parent for same CPU,
> > > +		 * give parent chance to run and boost our priority */
> > >  		sched_yield();
> > 
> > Hmm, is this the case? Because the main thread should continue to run
> > until blocked and without the sleep(1) in the main() there is nothing
> > that could block the parent process between the fork and the priority
> > boost. Or am I mistaken?
> 
> I think you're right in scenario with single CPU.
> In theory, is it possible that set_affinity() would be dummy, and one of
> ncpu-1 children running with max FIFO priority would preempt parent
> allowing test_process() to run before its priority is changed?

Aren't the child proceesses forked with the same priority as the parent?
In this case they shouldn't get executed for the same reason unless they
are migrated other CPUs. But yes then it's a kind of unpredictable which
is the reason we have the affinity call there.

> I'd prefer to keep sched_yield() in test_process() as it poses
> no harm even in case parent can't be blocked/preempted.

Ok.

> > Shouldn't we rather initialize the shmptr to some known value (!=
> > mean_prio) now?
> 
> It's initialized to 0, after call to shmat.

Missed that, you are right.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

  parent reply	other threads:[~2015-03-02 13:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-27 10:41 [LTP] [PATCH 1/2] sched_setparam/9-1: fix hang on -rt kernel Jan Stancek
2015-02-27 10:41 ` [LTP] [PATCH 2/2] sched_setparam/10-1: remove testcase Jan Stancek
2015-03-02 13:11   ` Cyril Hrubis
2015-03-02 13:04 ` [LTP] [PATCH 1/2] sched_setparam/9-1: fix hang on -rt kernel Cyril Hrubis
     [not found]   ` <1750098575.20916844.1425303360282.JavaMail.zimbra@redhat.com>
2015-03-02 13:47     ` Cyril Hrubis [this message]
     [not found]       ` <951353219.21574463.1425379677968.JavaMail.zimbra@redhat.com>
2015-03-03 14:23         ` 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=20150302134716.GA11619@rei \
    --to=chrubis@suse.cz \
    --cc=jkastner@redhat.com \
    --cc=jstancek@redhat.com \
    --cc=ltp-list@lists.sourceforge.net \
    /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