Make yield a noop for the primary.

Change-Id: Idc5f650928eef5185dfa604a52f2a580acaf514a
diff --git a/inc/hf/api.h b/inc/hf/api.h
index 06f33fd..95d97ab 100644
--- a/inc/hf/api.h
+++ b/inc/hf/api.h
@@ -43,8 +43,8 @@
 			 enum hf_share share, struct vcpu *current);
 
 struct vcpu *api_preempt(struct vcpu *current);
-struct vcpu *api_yield(struct vcpu *current);
 struct vcpu *api_wait_for_interrupt(struct vcpu *current);
+struct vcpu *api_yield(struct vcpu *current);
 struct vcpu *api_abort(struct vcpu *current);
 
 int64_t api_interrupt_enable(uint32_t intid, bool enable, struct vcpu *current);
diff --git a/src/api.c b/src/api.c
index 031c07f..ffb431b 100644
--- a/src/api.c
+++ b/src/api.c
@@ -93,20 +93,6 @@
 }
 
 /**
- * Returns to the primary vm to allow this cpu to be used for other tasks as the
- * vcpu does not have work to do at this moment. The current vcpu is marked as
- * ready to be scheduled again.
- */
-struct vcpu *api_yield(struct vcpu *current)
-{
-	struct hf_vcpu_run_return ret = {
-		.code = HF_VCPU_RUN_YIELD,
-	};
-
-	return api_switch_to_primary(current, ret, vcpu_state_ready);
-}
-
-/**
  * Puts the current vcpu in wait for interrupt mode, and returns to the primary
  * vm.
  */
@@ -121,6 +107,25 @@
 }
 
 /**
+ * Returns to the primary vm to allow this cpu to be used for other tasks as the
+ * vcpu does not have work to do at this moment. The current vcpu is marked as
+ * ready to be scheduled again.
+ */
+struct vcpu *api_yield(struct vcpu *current)
+{
+	struct hf_vcpu_run_return ret = {
+		.code = HF_VCPU_RUN_YIELD,
+	};
+
+	if (current->vm->id == HF_PRIMARY_VM_ID) {
+		/* Noop on the primary as it makes the scheduling decisions.  */
+		return NULL;
+	}
+
+	return api_switch_to_primary(current, ret, vcpu_state_ready);
+}
+
+/**
  * Aborts the vCPU and triggers its VM to abort fully.
  */
 struct vcpu *api_abort(struct vcpu *current)
diff --git a/test/vmapi/primary_only/primary_only.c b/test/vmapi/primary_only/primary_only.c
index 5b3d0f0..d178517 100644
--- a/test/vmapi/primary_only/primary_only.c
+++ b/test/vmapi/primary_only/primary_only.c
@@ -87,7 +87,7 @@
 }
 
 /**
- * Confirm that yielding from the primary will still allow the test to complete.
+ * Yielding from the primary is a noop.
  */
 TEST(hf_vcpu_yield, yield_is_noop_for_primary)
 {