Skip to contentSkip to conversation

xen/arm: vcpu_yield on WFE

PATCH Superseded Stefano Stabellini 3 participants 10 messages Jul 23, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover xen/arm: vcpu_yield on WFE

Hi all,
the patches should be self-explanatory.

Stefano Stabellini (2):
xen: export do_yield as vcpu_yield
xen/arm: call vcpu_yield on WFE trap

 xen/arch/arm/traps.c    |    2 +-
 xen/common/schedule.c   |   10 +++++-----
 xen/include/xen/sched.h |    1 +
 3 files changed, 7 insertions(+), 6 deletions(-)
#1 lore raw

PATCH 1/2 xen: export do_yield as vcpu_yield

---
 xen/common/schedule.c   |   10 +++++-----
 xen/include/xen/sched.h |    1 +
 2 files changed, 6 insertions(+), 5 deletions(-)
xen/common/schedule.c +5 -5
index e9eb0bc..6631dc8 100644
@@ -795,9 +795,8 @@ static long do_poll(struct sched_poll *sched_poll)
 }
 
 /* Voluntarily yield the processor for this allocation. */
-static long do_yield(void)
+void vcpu_yield(struct vcpu *v)
 {
-    struct vcpu * v=current;
     spinlock_t *lock = vcpu_schedule_lock_irq(v);
 
     SCHED_OP(VCPU2OP(v), yield, v);
@@ -805,7 +804,6 @@ static long do_yield(void)
 
     TRACE_2D(TRC_SCHED_YIELD, current->domain->domain_id, current->vcpu_id);
     raise_softirq(SCHEDULE_SOFTIRQ);
-    return 0;
 }
 
 static void domain_watchdog_timeout(void *data)
@@ -888,7 +886,8 @@ long do_sched_op_compat(int cmd, unsigned long arg)
     {
     case SCHEDOP_yield:
     {
-        ret = do_yield();
+        vcpu_yield(current);
+        ret = 0;
         break;
     }
 
@@ -925,7 +924,8 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
     {
     case SCHEDOP_yield:
     {
-        ret = do_yield();
+        vcpu_yield(current);
+        ret = 0;
         break;
     }
 
xen/include/xen/sched.h +1 -0
index 2f876f5..b99a8d3 100644
@@ -634,6 +634,7 @@ int  sched_id(void);
 void sched_tick_suspend(void);
 void sched_tick_resume(void);
 void vcpu_wake(struct vcpu *v);
+void vcpu_yield(struct vcpu *v);
 void vcpu_sleep_nosync(struct vcpu *v);
 void vcpu_sleep_sync(struct vcpu *v);
 
Signature · 1 line
1.7.10.4
#2 lore raw

Re: [PATCH 1/2] xen: export do_yield as vcpu_yield

Quoted 13 lines · Stefano Stabellini
---
 xen/common/schedule.c   |   10 +++++-----
 xen/include/xen/sched.h |    1 +
 2 files changed, 6 insertions(+), 5 deletions(-)
xen/common/schedule.c +0 -0
index e9eb0bc..6631dc8 100644

xen/common/schedule.c static long do_poll(struct sched_poll *sched_poll) · line 800

Quoted 7 lines
xen/common/schedule.c +1 -2
@@ -795,9 +795,8 @@ static long do_poll(struct sched_poll *sched_poll)
 }
 
 /* Voluntarily yield the processor for this allocation. */
-static long do_yield(void)
+void vcpu_yield(struct vcpu *v)
 {
-    struct vcpu * v=current;

Is it safe to yield another vcpu?

Ian.

#3 lore raw

Re: [PATCH 1/2] xen: export do_yield as vcpu_yield

In reply to Stefano Stabellini
Quoted 13 lines · Stefano Stabellini
---
  xen/common/schedule.c   |   10 +++++-----
  xen/include/xen/sched.h |    1 +
  2 files changed, 6 insertions(+), 5 deletions(-)
xen/common/schedule.c +0 -0
index e9eb0bc..6631dc8 100644

xen/common/schedule.c static long do_poll(struct sched_poll *sched_poll) · line 798

Quoted 5 lines
xen/common/schedule.c +1 -1
@@ -795,9 +795,8 @@ static long do_poll(struct sched_poll *sched_poll)
  }
 
  /* Voluntarily yield the processor for this allocation. */
-static long do_yield(void)
+void vcpu_yield(struct vcpu *v)

What are you actually trying to do here? Why do you add a vcpu struct, when all the callers (including the one you add in 2/2) just pass current?

xen/common/schedule.c static long do_yield(void) · line 806

Quoted 9 lines
xen/common/schedule.c +0 -1
  {
-    struct vcpu * v=current;
      spinlock_t *lock = vcpu_schedule_lock_irq(v);
 
      SCHED_OP(VCPU2OP(v), yield, v);
@@ -805,7 +804,6 @@ static long do_yield(void)
 
      TRACE_2D(TRC_SCHED_YIELD, current->domain->domain_id, current->vcpu_id);
      raise_softirq(SCHEDULE_SOFTIRQ);

This is broken: it's still tracing current instead of v, and you're raising the schedule softirq on the current cpu rather than on the cpu on which v is running. If v!=current, you have to go through force reschedule for safety.

Just rename the function and make it non-static, leaving the arguments and return value alone.

-George

#4 lore raw

Re: [PATCH 1/2] xen: export do_yield as vcpu_yield

Quoted 9 lines · George Dunlap
Quoted 8 lines · Stefano Stabellini
---
  xen/common/schedule.c   |   10 +++++-----
  xen/include/xen/sched.h |    1 +
  2 files changed, 6 insertions(+), 5 deletions(-)
Quoted 12 lines

xen/common/schedule.c static long do_poll(struct sched_poll *sched_poll) · line 797

Quoted 9 lines
xen/common/schedule.c +1 -1
index e9eb0bc..6631dc8 100644
@@ -795,9 +795,8 @@ static long do_poll(struct sched_poll *sched_poll)
  }
    /* Voluntarily yield the processor for this allocation. */
-static long do_yield(void)
+void vcpu_yield(struct vcpu *v)

What are you actually trying to do here? Why do you add a vcpu struct, when all the callers (including the one you add in 2/2) just pass current?

I was just trying to be coherent with the other vcpu_* functions in sched.h.

Quoted 13 lines

xen/common/schedule.c static long do_yield(void) · line 806

Quoted 8 lines
xen/common/schedule.c +0 -1
  {
-    struct vcpu * v=current;
      spinlock_t *lock = vcpu_schedule_lock_irq(v);
        SCHED_OP(VCPU2OP(v), yield, v);
@@ -805,7 +804,6 @@ static long do_yield(void)
        TRACE_2D(TRC_SCHED_YIELD, current->domain->domain_id,
 current->vcpu_id);
      raise_softirq(SCHEDULE_SOFTIRQ);

This is broken: it's still tracing current instead of v, and you're raising the schedule softirq on the current cpu rather than on the cpu on which v is running. If v!=current, you have to go through force reschedule for safety.

Quoted 2 lines

Just rename the function and make it non-static, leaving the arguments and return value alone.

OK

#5 lore raw

Re: [PATCH 1/2] xen: export do_yield as vcpu_yield

Quoted 21 lines · Stefano Stabellini
Quoted 9 lines · George Dunlap
Quoted 8 lines · Stefano Stabellini
---
   xen/common/schedule.c   |   10 +++++-----
   xen/include/xen/sched.h |    1 +
   2 files changed, 6 insertions(+), 5 deletions(-)
Quoted 11 lines

xen/common/schedule.c static long do_poll(struct sched_poll *sched_poll) · line 797

Quoted 9 lines
xen/common/schedule.c +1 -1
index e9eb0bc..6631dc8 100644
@@ -795,9 +795,8 @@ static long do_poll(struct sched_poll *sched_poll)
   }
     /* Voluntarily yield the processor for this allocation. */
-static long do_yield(void)
+void vcpu_yield(struct vcpu *v)

What are you actually trying to do here? Why do you add a vcpu struct, when all the callers (including the one you add in 2/2) just pass current?

Quoted 2 lines

I was just trying to be coherent with the other vcpu_* functions in sched.h.

I see. Yeah, I think even apart from the rest of it, "yield" implies "myself"; you can't really yield someone else. :-)

-George

#6 lore raw

PATCH 2/2 xen/arm: call vcpu_yield on WFE trap

In reply to Stefano Stabellini

No need to call vcpu_force_reschedule, is too expensive.

---
 xen/arch/arm/traps.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/traps.c +1 -1
index 3dfabd0..8cd06cc 100644
@@ -1805,7 +1805,7 @@ asmlinkage void do_trap_hypervisor(struct cpu_user_regs *regs)
         }
         if ( hsr.wfi_wfe.ti ) {
             /* Yield the VCPU for WFE */
-            vcpu_force_reschedule(current);
+            vcpu_yield(current);
         } else {
             /* Block the VCPU for WFI */
             vcpu_block_unless_event_pending(current);
Signature · 1 line
1.7.10.4
#7 lore raw

Re: [PATCH 2/2] xen/arm: call vcpu_yield on WFE trap

Quoted 12 lines · Stefano Stabellini

No need to call vcpu_force_reschedule, is too expensive.

---
 xen/arch/arm/traps.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/traps.c +0 -0
index 3dfabd0..8cd06cc 100644

xen/arch/arm/traps.c asmlinkage void do_trap_hypervisor(struct cpu_user_regs *regs) · line 1808

Quoted 5 lines
xen/arch/arm/traps.c +1 -1
@@ -1805,7 +1805,7 @@ asmlinkage void do_trap_hypervisor(struct cpu_user_regs *regs)
         }
         if ( hsr.wfi_wfe.ti ) {
             /* Yield the VCPU for WFE */
-            vcpu_force_reschedule(current);
+            vcpu_yield(current);

Actually, sorry -- why are you wanting to yield here?

At the moment "yield" is only initiated by the guest itself, and the individual schedulers are notified that the guest has called "yield". If what you want to do is yield for some other reason, it might be better to have a slightly separate path for that.

-George

#8 lore raw

Re: [PATCH 2/2] xen/arm: call vcpu_yield on WFE trap

Quoted 22 lines · George Dunlap
Quoted 12 lines · Stefano Stabellini

No need to call vcpu_force_reschedule, is too expensive.

---
 xen/arch/arm/traps.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/traps.c +0 -0
index 3dfabd0..8cd06cc 100644

xen/arch/arm/traps.c asmlinkage void do_trap_hypervisor(struct cpu_user_regs *regs) · line 1808

Quoted 5 lines
xen/arch/arm/traps.c +1 -1
@@ -1805,7 +1805,7 @@ asmlinkage void do_trap_hypervisor(struct cpu_user_regs *regs)
         }
         if ( hsr.wfi_wfe.ti ) {
             /* Yield the VCPU for WFE */
-            vcpu_force_reschedule(current);
+            vcpu_yield(current);

Actually, sorry -- why are you wanting to yield here?

Quoted 4 lines

At the moment "yield" is only initiated by the guest itself, and the individual schedulers are notified that the guest has called "yield". If what you want to do is yield for some other reason, it might be better to have a slightly separate path for that.

It is a very similar situation: WFE means "wait for event" and it is used in the implementation of spin_locks, for example.
I think that trapping the instruction and yielding is what we want.

#9 lore raw

Re: [PATCH 2/2] xen/arm: call vcpu_yield on WFE trap

Quoted 22 lines · Stefano Stabellini
Quoted 21 lines · George Dunlap
Quoted 12 lines · Stefano Stabellini

No need to call vcpu_force_reschedule, is too expensive.

---
  xen/arch/arm/traps.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/traps.c +0 -0
index 3dfabd0..8cd06cc 100644

xen/arch/arm/traps.c asmlinkage void do_trap_hypervisor(struct cpu_user_regs *regs) · line 1808

Quoted 5 lines
xen/arch/arm/traps.c +1 -1
@@ -1805,7 +1805,7 @@ asmlinkage void do_trap_hypervisor(struct cpu_user_regs *regs)
          }
          if ( hsr.wfi_wfe.ti ) {
              /* Yield the VCPU for WFE */
-            vcpu_force_reschedule(current);
+            vcpu_yield(current);

Actually, sorry -- why are you wanting to yield here?

Quoted 8 lines
Quoted 4 lines

At the moment "yield" is only initiated by the guest itself, and the individual schedulers are notified that the guest has called "yield". If what you want to do is yield for some other reason, it might be better to have a slightly separate path for that.

It is a very similar situation: WFE means "wait for event" and it is used in the implementation of spin_locks, for example.
I think that trapping the instruction and yielding is what we want.

Right -- sounds good then.

-George