mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@tv-sign.ru>
To: Roland McGrath <roland@redhat.com>
Cc: akpm@linux-foundation.org, torvalds@linux-foundation.org,
	mingo@elte.hu, linux-kernel@vger.kernel.org
Subject: Re: Q: wait_task_inactive() and !CONFIG_SMP && CONFIG_PREEMPT
Date: Tue, 29 Jul 2008 16:21:12 +0400	[thread overview]
Message-ID: <20080729122010.GB177@tv-sign.ru> (raw)
In-Reply-To: <20080728233915.0D00015427E@magilla.localdomain>

On 07/28, Roland McGrath wrote:
>
> I can't speak to the kthread case.  I suspect that set_task_cpu() is always
> safe on !SMP PREEMPT, and that's why it's fine.

Yes, kthread_bind() is fine, it changes nothing in *k if !SMP.

> > I refer to this patch of the comment:
> > 
> > 	If a second call a short while later returns the same number, the
> > 	caller can be sure that @p has remained unscheduled the whole time.
> > 
> > The dummy version always returns the same number == 1.
> 
> Right.  For the general case where this is the contract wait_task_inactive
> is expected to meet, it does matter.  I think task_current_syscall() does
> want this checked for the preempted uniprocessor case, for example.
> 
> > So. I think that wait_task_inactive() needs "defined(SMP) || defined(PREEMPT)"
> > and the dummy version should return ->nvcsw too.
> 
> Is this what we want?
> 
> 	#ifdef CONFIG_SMP
> 	extern unsigned long wait_task_inactive(struct task_struct *, long);
> 	#else
> 	static inline unsigned long wait_task_inactive(struct task_struct *p,
> 						       long match_state)
> 	{
> 		unsigned long ret = 0;
> 		if (match_state) {
> 			preempt_disable();
> 			if (p->state == match_state)
> 				ret = (p->nvcsw << 1) | 1;
> 			preempt_enable();
> 		}
> 		return ret;
> 	}
> 	#endif

I dont think this is right.

Firstly, the above always fails if match_state == 0, this is not right.

But more importantly, we can't just check ->state == match_state. And
preempt_disable() buys nothing.

Let's look at task_current_syscall(). The "target" can set, say,
TASK_UNINTERRUPTIBLE many times, do a lot of syscalls, and not once
call schedule().

And the task remains fully preemptible even if it runs in
TASK_UNINTERRUPTIBLE state.


Let's suppose we implement kthread_set_nice() in the same manner
as kthread_bind(),

	kthread_set_nice(struct task_struct *k, long nice)
	{
		wait_task_inactive(k, TASK_UNINTERRUPTIBLE);

		... just change ->prio/static_prio ...
	}

the above is ugly of course, but should be correct correct even
with !SMP && PREEMPT.


I think we need

	#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT)
	extern unsigned long wait_task_inactive(struct task_struct *, long);
	#else
	static inline unsigned long wait_task_inactive(struct task_struct *p,
							long match_state)
	{
		if (match_state && p->state != match_state)
			return 0;
		return p->nvcsw | (LONG_MAX + 1); // the same in sched.c
	}

Oleg.


  reply	other threads:[~2008-07-29 12:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200807260245.m6Q2jwB4012297@imap1.linux-foundation.org>
2008-07-27 11:37 ` [PATCH] wait_task_inactive: don't consider task->nivcsw Oleg Nesterov
2008-07-27 19:55   ` Roland McGrath
2008-07-27 12:15 ` Q: wait_task_inactive() and !CONFIG_SMP && CONFIG_PREEMPT Oleg Nesterov
2008-07-27 16:51   ` Linus Torvalds
2008-07-27 20:05   ` Roland McGrath
2008-07-28 12:57     ` Oleg Nesterov
2008-07-28 23:39       ` Roland McGrath
2008-07-29 12:21         ` Oleg Nesterov [this message]
2008-08-01  1:27           ` Roland McGrath
2008-08-01 11:49             ` Oleg Nesterov
2008-08-01 21:22               ` Roland McGrath
2008-07-27 12:42 ` [PATCH] kthread_bind: use wait_task_inactive(TASK_UNINTERRUPTIBLE) 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=20080729122010.GB177@tv-sign.ru \
    --to=oleg@tv-sign.ru \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=roland@redhat.com \
    --cc=torvalds@linux-foundation.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®