mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stephane Eranian <eranian@hpl.hp.com>
To: linux-kernel@vger.kernel.org
Subject: how to force a task out in SMP?
Date: Fri, 18 Oct 2002 15:50:46 -0700	[thread overview]
Message-ID: <20021018155046.H30560@frankl.hpl.hp.com> (raw)

Hi,

I am developing a kernel performance monitoring (perfmon) subsystem in 
Linux/ia64 and I need to access the perfmon state of another task that
is *possibly* running at the same time in a SMP configurations. Unlike 
debuggers, I don't want to change the behavior of the task. For instance, 
if it was blocked, then it must stay blocked, i.e., no EINTR.

I have looked in the lkml archives and found that some people have had
to deal with the same problem when trying to dump core in a multithreaded
applications. While their goal is different, what they need is similar.

What we want: "a mechanism to force a task out of the CPU, if it is running,
which also ensures that it will not be scheduled again  until we tell
it to do so". 

There has been several iterations of the multithreaded core dump patch, 
some for 2.4 and some for 2.5. They used the following techniques:

For 2.4:
	1/ cpus_allowed

	stop   : force task->cpus_allowed=0, task->need_resched=1 and force a 
	         reschedule. Then wait until task leaves cpu. 
	restart: restablish a good task->cpus_allowed and force a resched.

For 2.5 several versions exist:

	1/ SIGSTOP/SIGCONT

	stop   : send SIGSTOP to the other task, wait until it leaves the CPU
	restart: send SIGCONT.

	2/ Phantom runqueue

	add a runqueue not associated with any CPU (NR_CPUS+1).
	stop   : move task to phantom runqueue
	restart: move back to valid queue.
	

The cpus_allowed is clearly a hack which is not possible in 2.5 (see
set_cpus_allowed()).

The SIGSTOP/SIGCONT technique is not that good because it is visible to the
program and possibly others. For instance, your shell gets notified if the
task is stopped (if was launched from it). Then the job control gets confused.

The shadow runqueue seems interesting but I am wondering if it could not be
implemented with no extra queue. All that is needed is to get the task out 
of the queue it is on and then put it back into a queue when we're done. 
I am no expert in the scheduler code but it seems to have internal routines
to do just that (deactivate_task() and activate_task()). I wonder if those
could be used (if made visible outside of sched.c), however I can believe
that they are called in a specific context and that it may be difficult to
export them.

My question is then what is the right way of implementing this in 2.5?

Thanks.

-- 
-Stephane

             reply	other threads:[~2002-10-18 22:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-18 22:50 Stephane Eranian [this message]
2002-10-21 14:44 ` mgross

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=20021018155046.H30560@frankl.hpl.hp.com \
    --to=eranian@hpl.hp.com \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®