public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: "Metzger, Markus T" <markus.t.metzger@intel.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"mingo@elte.hu" <mingo@elte.hu>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"hpa@zytor.com" <hpa@zytor.com>,
	"markus.t.metzger@gmail.com" <markus.t.metzger@gmail.com>,
	"roland@redhat.com" <roland@redhat.com>,
	"eranian@googlemail.com" <eranian@googlemail.com>,
	"Villacis, Juan" <juan.villacis@intel.com>,
	"ak@linux.jf.intel.com" <ak@linux.jf.intel.com>
Subject: Re: [patch 3/21] x86, bts: wait until traced task has been scheduled out
Date: Wed, 1 Apr 2009 21:04:45 +0200	[thread overview]
Message-ID: <20090401190445.GA16033@redhat.com> (raw)
In-Reply-To: <928CFBE8E7CB0040959E56B4EA41A77E926D5093@irsmsx504.ger.corp.intel.com>

On 04/01, Metzger, Markus T wrote:
>
> >-----Original Message-----
> >From: Oleg Nesterov [mailto:oleg@redhat.com]
> >Sent: Wednesday, April 01, 2009 2:17 AM
> >To: Metzger, Markus T
>
> >> +static void wait_to_unschedule(struct task_struct *task)
> >> +{
> >> +	unsigned long nvcsw;
> >> +	unsigned long nivcsw;
> >> +
> >> +	if (!task)
> >> +		return;
> >> +
> >> +	if (task == current)
> >> +		return;
> >> +
> >> +	nvcsw  = task->nvcsw;
> >> +	nivcsw = task->nivcsw;
> >> +	for (;;) {
> >> +		if (!task_is_running(task))
> >> +			break;
> >> +		/*
> >> +		 * The switch count is incremented before the actual
> >> +		 * context switch. We thus wait for two switches to be
> >> +		 * sure at least one completed.
> >> +		 */
> >> +		if ((task->nvcsw - nvcsw) > 1)
> >> +			break;
> >> +		if ((task->nivcsw - nivcsw) > 1)
> >> +			break;
> >> +
> >> +		schedule();
> >
> >schedule() is a nop here. We can wait unpredictably long...
>
> Hmmm, As far as I understand the code, rt-workqueues use a higher sched_class
> and can thus not be preempted by normal threads. Non-rt workqueues
> use the fair_sched_class. And schedule_work() uses a non-rt workqueue.

I was unclear, sorry.

I meant, in this case

	while (!CONDITION)
		schedule();

is not better compared to

	while (!CONDITION)
		; /* do nothing */

(OK, schedule() is better without CONFIG_PREEMPT, but this doesn't matter).
wait_to_unschedule() just spins waiting for ->nXvcsw, this is not optimal.

And another problem, we can wait unpredictably long, because

> In practice, task is ptraced. It is either stopped or exiting.
> I don't expect to loop very often.

No. The task _was_ ptraced when we called (say) ptrace_detach(). But when
work->func() runs, the tracee is not traced, it is running (not necessary
of course, the tracer _can_ leave it in TASK_STOPPED).

Now, again, suppose that this task does "for (;;) ;" in user-space.
If CPU is "free", it can spin "forever" without re-scheduling. Yes sure,
this case is not likely in practice, but still.

Oleg.


  reply	other threads:[~2009-04-01 19:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-31 12:59 [patch 3/21] x86, bts: wait until traced task has been scheduled out Markus Metzger
2009-04-01  0:17 ` Oleg Nesterov
2009-04-01  8:09   ` Metzger, Markus T
2009-04-01 19:04     ` Oleg Nesterov [this message]
2009-04-01 19:52       ` Markus Metzger
2009-04-01 11:41   ` Ingo Molnar
2009-04-01 12:43     ` Metzger, Markus T
2009-04-01 12:53       ` Ingo Molnar
2009-04-01 19:45     ` Oleg Nesterov
2009-04-01  0:26 ` Oleg Nesterov

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=20090401190445.GA16033@redhat.com \
    --to=oleg@redhat.com \
    --cc=ak@linux.jf.intel.com \
    --cc=eranian@googlemail.com \
    --cc=hpa@zytor.com \
    --cc=juan.villacis@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markus.t.metzger@gmail.com \
    --cc=markus.t.metzger@intel.com \
    --cc=mingo@elte.hu \
    --cc=roland@redhat.com \
    --cc=tglx@linutronix.de \
    /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