From: Rik van Riel <riel@redhat.com>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Avi Kiviti <avi@redhat.com>,
Srivatsa Vaddagiri <vatsa@linux.vnet.ibm.com>,
Mike Galbraith <efault@gmx.de>,
Chris Wright <chrisw@sous-sol.org>,
ttracy@redhat.com, dshaks@redhat.com, "Nakajima,
Jun" <jun.nakajima@intel.com>
Subject: Re: [RFC -v6 PATCH 4/8] sched: Add yield_to(task, preempt) functionality
Date: Mon, 24 Jan 2011 13:19:46 -0500 [thread overview]
Message-ID: <4D3DC2C2.1060905@redhat.com> (raw)
In-Reply-To: <1295892748.28776.463.camel@laptop>
On 01/24/2011 01:12 PM, Peter Zijlstra wrote:
> On Thu, 2011-01-20 at 16:34 -0500, Rik van Riel wrote:
>> From: Mike Galbraith<efault@gmx.de>
>>
>> Currently only implemented for fair class tasks.
>>
>> Add a yield_to_task method() to the fair scheduling class. allowing the
>> caller of yield_to() to accelerate another thread in it's thread group,
>> task group.
>>
>> Implemented via a scheduler hint, using cfs_rq->next to encourage the
>> target being selected. We can rely on pick_next_entity to keep things
>> fair, so noone can accelerate a thread that has already used its fair
>> share of CPU time.
>>
>> This also means callers should only call yield_to when they really
>> mean it. Calling it too often can result in the scheduler just
>> ignoring the hint.
>>
>> Signed-off-by: Rik van Riel<riel@redhat.com>
>> Signed-off-by: Marcelo Tosatti<mtosatti@redhat.com>
>> Signed-off-by: Mike Galbraith<efault@gmx.de>
>
> Patch 5 wants to be merged back in here I think..
Agreed, but I wanted Mike's comments first :)
>> +/**
>> + * yield_to - yield the current processor to another thread in
>> + * your thread group, or accelerate that thread toward the
>> + * processor it's on.
>> + *
>> + * It's the caller's job to ensure that the target task struct
>> + * can't go away on us before we can do any checks.
>> + *
>> + * Returns true if we indeed boosted the target task.
>> + */
>> +bool __sched yield_to(struct task_struct *p, bool preempt)
>> +{
>> + struct task_struct *curr = current;
>> + struct rq *rq, *p_rq;
>> + unsigned long flags;
>> + bool yielded = 0;
>> +
>> + local_irq_save(flags);
>> + rq = this_rq();
>> +
>> +again:
>> + p_rq = task_rq(p);
>> + double_rq_lock(rq, p_rq);
>> + while (task_rq(p) != p_rq) {
>> + double_rq_unlock(rq, p_rq);
>> + goto again;
>> + }
>> +
>> + if (!curr->sched_class->yield_to_task)
>> + goto out;
>> +
>> + if (curr->sched_class != p->sched_class)
>> + goto out;
>> +
>> + if (task_running(p_rq, p) || p->state)
>> + goto out;
>> +
>> + if (!same_thread_group(p, curr))
>> + goto out;
>> +
>> +#ifdef CONFIG_FAIR_GROUP_SCHED
>> + if (task_group(p) != task_group(curr))
>> + goto out;
>> +#endif
>> +
>> + yielded = curr->sched_class->yield_to_task(rq, p, preempt);
>> +
>> +out:
>> + double_rq_unlock(rq, p_rq);
>> + local_irq_restore(flags);
>> +
>> + if (yielded)
>> + yield();
>
> Calling yield() here is funny, you just had all the locks to actually do
> it..
This is us giving up the CPU, which requires not holding locks.
A different thing than us giving the CPU away to someone else.
>> +static bool yield_to_task_fair(struct rq *rq, struct task_struct *p, bool preempt)
>> +{
>> + struct sched_entity *se =&p->se;
>> +
>> + if (!se->on_rq)
>> + return false;
>> +
>> + /* Tell the scheduler that we'd really like pse to run next. */
>> + set_next_buddy(se);
>> +
>> + /* Make p's CPU reschedule; pick_next_entity takes care of fairness. */
>> + if (preempt)
>> + resched_task(rq->curr);
>> +
>> + return true;
>> +}
>
> So here we set ->next, we could be ->last, and after this we'll set
> ->yield to curr by calling yield().
>
> So if you do this cyclically I can see ->yield == {->next,->last}
> happening.
That would only happen if we called yield_to with ourselves
as the argument!
There is no caller in the tree that does that - task p is
another task, not ourselves.
next prev parent reply other threads:[~2011-01-24 18:19 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-20 21:31 [RFC -v6 PATCH 0/8] directed yield for Pause Loop Exiting Rik van Riel
2011-01-20 21:32 ` [RFC -v6 PATCH 1/8] sched: check the right ->nr_running in yield_task_fair Rik van Riel
2011-01-20 21:33 ` [RFC -v6 PATCH 2/8] sched: limit the scope of clear_buddies Rik van Riel
2011-01-24 17:57 ` Peter Zijlstra
2011-01-24 18:04 ` Rik van Riel
2011-01-20 21:33 ` [RFC -v6 PATCH 3/8] sched: use a buddy to implement yield_task_fair Rik van Riel
2011-01-24 18:04 ` Peter Zijlstra
2011-01-24 18:16 ` Rik van Riel
2011-01-20 21:34 ` [RFC -v6 PATCH 4/8] sched: Add yield_to(task, preempt) functionality Rik van Riel
2011-01-24 18:12 ` Peter Zijlstra
2011-01-24 18:19 ` Rik van Riel [this message]
2011-01-20 21:36 ` [RFC -v6 PATCH 6/8] export pid symbols needed for kvm_vcpu_on_spin Rik van Riel
2011-01-20 21:36 ` [RFC -v6 PATCH 7/8] kvm: keep track of which task is running a KVM vcpu Rik van Riel
2011-01-26 13:01 ` Avi Kivity
2011-01-26 15:20 ` Rik van Riel
2011-01-20 21:37 ` [RFC -v6 PATCH 5/8] sched: drop superfluous tests from yield_to Rik van Riel
2011-01-20 21:38 ` [RFC -v6 PATCH 8/8] kvm: use yield_to instead of sleep in kvm_vcpu_on_spin Rik van Riel
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=4D3DC2C2.1060905@redhat.com \
--to=riel@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=avi@redhat.com \
--cc=chrisw@sous-sol.org \
--cc=dshaks@redhat.com \
--cc=efault@gmx.de \
--cc=jun.nakajima@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ttracy@redhat.com \
--cc=vatsa@linux.vnet.ibm.com \
/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;
as well as URLs for NNTP newsgroup(s).