All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Tian, Kevin" <kevin.tian@intel.com>
To: "Wu, Feng" <feng.wu@intel.com>,
	"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Cc: "Zhang, Yang Z" <yang.z.zhang@intel.com>,
	"keir@xen.org" <keir@xen.org>,
	"JBeulich@suse.com" <JBeulich@suse.com>
Subject: Re: [RFC v1 13/15] Update Posted-Interrupts Descriptor during vCPU scheduling
Date: Thu, 2 Apr 2015 06:24:39 +0000	[thread overview]
Message-ID: <AADFC41AFE54684AB9EE6CBC0274A5D1261FB78E@SHSMSX101.ccr.corp.intel.com> (raw)
In-Reply-To: <1427286717-4093-14-git-send-email-feng.wu@intel.com>

> From: Wu, Feng
> Sent: Wednesday, March 25, 2015 8:32 PM
> 
> The basic idea here is:
> 1. When vCPU's state is RUNSTATE_running,
>         - set 'NV' to 'Notification Vector'.
>         - Clear 'SN' to accpet PI.
>         - set 'NDST' to the right pCPU.
> 2. When vCPU's state is RUNSTATE_blocked,
>         - set 'NV' to 'Wake-up Vector', so we can wake up the
>           related vCPU when posted-interrupt happens for it.
>         - Clear 'SN' to accpet PI.
> 3. When vCPU's state is RUNSTATE_runnable/RUNSTATE_offline,
>         - Set 'SN' to suppress non-urgent interrupts.
>           (Current, we only support non-urgent interrupts)
>         - Set 'NV' back to 'Notification Vector' if needed.
> 
> Signed-off-by: Feng Wu <feng.wu@intel.com>
> ---
>  xen/arch/x86/hvm/vmx/vmx.c | 108
> +++++++++++++++++++++++++++++++++++++++++++++
>  xen/common/schedule.c      |   3 ++
>  2 files changed, 111 insertions(+)
> 
> diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
> index b30392c..6323bd6 100644
> --- a/xen/arch/x86/hvm/vmx/vmx.c
> +++ b/xen/arch/x86/hvm/vmx/vmx.c
> @@ -1710,6 +1710,113 @@ static void vmx_handle_eoi(u8 vector)
>      __vmwrite(GUEST_INTR_STATUS, status);
>  }
> 
> +static void vmx_pi_desc_update(struct vcpu *v, int new_state)
> +{
> +    struct pi_desc *pi_desc = &v->arch.hvm_vmx.pi_desc;
> +    struct pi_desc old, new;
> +    int old_state = v->runstate.state;
> +    unsigned long flags;
> +
> +    if ( !iommu_intpost )
> +        return;
> +
> +    switch ( new_state )
> +    {
> +    case RUNSTATE_runnable:
> +    case RUNSTATE_offline:
> +        /*
> +         * We don't need to send notification event to a non-running
> +         * vcpu, the interrupt information will be delivered to it before
> +         * VM-ENTRY when the vcpu is scheduled to run next time.
> +         */
> +        pi_set_sn(pi_desc);
> +
> +        /*
> +         * If the state is transferred from RUNSTATE_blocked,
> +         * we should set 'NV' feild back to posted_intr_vector,
> +         * so the Posted-Interrupts can be delivered to the vCPU
> +         * by VT-d HW after it is scheduled to run.
> +         */
> +        if ( old_state == RUNSTATE_blocked )
> +        {
> +            do
> +            {
> +                old.control = new.control = pi_desc->control;
> +                new.nv = posted_intr_vector;
> +            }
> +            while ( cmpxchg(&pi_desc->control, old.control, new.control)
> +                    != old.control );
> +
> +           /*
> +            * Delete the vCPU from the related wakeup queue
> +            * if we are resuming from blocked state
> +            */
> +           spin_lock_irqsave(&per_cpu(blocked_vcpu_on_cpu_lock,
> +                             v->processor), flags);
> +           list_del(&v->blocked_vcpu_list);
> +           spin_unlock_irqrestore(&per_cpu(blocked_vcpu_on_cpu_lock,
> +                                  v->processor), flags);
> +        }
> +        break;
> +
> +    case RUNSTATE_blocked:
> +        /*
> +         * The vCPU is blocked on the wait queue.
> +         * Store the blocked vCPU on the list of the
> +         * vcpu->wakeup_cpu, which is the destination
> +         * of the wake-up notification event.
> +         */
> +        spin_lock_irqsave(&per_cpu(blocked_vcpu_on_cpu_lock,
> +                          v->processor), flags);
> +        list_add_tail(&v->blocked_vcpu_list,
> +                      &per_cpu(blocked_vcpu_on_cpu, v->processor));
> +        spin_unlock_irqrestore(&per_cpu(blocked_vcpu_on_cpu_lock,
> +                               v->processor), flags);
> +
> +        do
> +        {
> +            old.control = new.control = pi_desc->control;
> +
> +            /*
> +             * We should not block the vCPU if
> +             * an interrupt is posted for it.
> +             */
> +
> +            if ( pi_test_on(&old) == 1 )
> +            {
> +                tasklet_schedule(&v->vcpu_wakeup_tasklet);
> +                return;
> +            }

so you also need to remove the vcpu from the blocked list, right?

and how do you handle ON is set after above check? looks this is better
handled behind cmpxchg loop...

> +
> +            pi_clear_sn(&new);
> +            new.nv = pi_wakeup_vector;
> +        }
> +        while ( cmpxchg(&pi_desc->control, old.control, new.control)
> +                != old.control );
> +        break;
> +
> +    case RUNSTATE_running:
> +        ASSERT( pi_test_sn(pi_desc) == 1 );
> +
> +        do
> +        {
> +            old.control = new.control = pi_desc->control;
> +            if ( x2apic_enabled )
> +                new.ndst = cpu_physical_id(v->processor);
> +            else
> +                new.ndst = (cpu_physical_id(v->processor) << 8) &
> 0xFF00;
> +
> +            pi_clear_sn(&new);
> +        }
> +        while ( cmpxchg(&pi_desc->control, old.control, new.control)
> +                != old.control );
> +        break;
> +
> +    default:
> +        break;
> +    }
> +}
> +
>  void vmx_hypervisor_cpuid_leaf(uint32_t sub_idx,
>                                 uint32_t *eax, uint32_t *ebx,
>                                 uint32_t *ecx, uint32_t *edx)
> @@ -1795,6 +1902,7 @@ static struct hvm_function_table __initdata
> vmx_function_table = {
>      .process_isr          = vmx_process_isr,
>      .deliver_posted_intr  = vmx_deliver_posted_intr,
>      .sync_pir_to_irr      = vmx_sync_pir_to_irr,
> +    .pi_desc_update       = vmx_pi_desc_update,
>      .handle_eoi           = vmx_handle_eoi,
>      .nhvm_hap_walk_L1_p2m = nvmx_hap_walk_L1_p2m,
>      .hypervisor_cpuid_leaf = vmx_hypervisor_cpuid_leaf,
> diff --git a/xen/common/schedule.c b/xen/common/schedule.c
> index ef79847..acf3186 100644
> --- a/xen/common/schedule.c
> +++ b/xen/common/schedule.c
> @@ -157,6 +157,9 @@ static inline void vcpu_runstate_change(
>          v->runstate.state_entry_time = new_entry_time;
>      }
> 
> +    if ( is_hvm_vcpu(v) && hvm_funcs.pi_desc_update )
> +        hvm_funcs.pi_desc_update(v, new_state);
> +
>      v->runstate.state = new_state;
>  }
> 
> --
> 2.1.0

  parent reply	other threads:[~2015-04-02  6:24 UTC|newest]

Thread overview: 101+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-25 12:31 [RFC v1 00/15] Add VT-d Posted-Interrupts support Feng Wu
2015-03-25 12:31 ` [RFC v1 01/15] iommu: Add iommu_intpost to control VT-d Posted-Interrupts feature Feng Wu
2015-03-26 17:39   ` Andrew Cooper
2015-03-27  4:46     ` Wu, Feng
2015-03-27  9:55       ` Andrew Cooper
2015-03-27  9:52     ` Jan Beulich
2015-03-25 12:31 ` [RFC v1 02/15] vt-d: VT-d Posted-Interrupts feature detection Feng Wu
2015-03-26 18:12   ` Andrew Cooper
2015-03-27  1:21     ` Wu, Feng
2015-03-27 10:06       ` Andrew Cooper
2015-03-27 13:41         ` Wu, Feng
2015-03-25 12:31 ` [RFC v1 03/15] vmx: Extend struct pi_desc to support VT-d Posted-Interrupts Feng Wu
2015-03-26 18:37   ` Andrew Cooper
2015-03-27  1:32     ` Wu, Feng
2015-03-25 12:31 ` [RFC v1 04/15] vmx: Add some helper functions for Posted-Interrupts Feng Wu
2015-03-26 18:44   ` Andrew Cooper
2015-03-25 12:31 ` [RFC v1 05/15] vmx: Initialize VT-d Posted-Interrupts Descriptor Feng Wu
2015-03-26 18:53   ` Andrew Cooper
2015-03-27  1:45     ` Wu, Feng
2015-03-26 19:29   ` Konrad Rzeszutek Wilk
2015-03-27  1:45     ` Wu, Feng
2015-05-04  5:32     ` Wu, Feng
2015-05-04  8:10       ` Jan Beulich
2015-05-04  8:36       ` Andrew Cooper
2015-05-04  9:07         ` Wu, Feng
2015-03-25 12:31 ` [RFC v1 06/15] vt-d: Extend struct iremap_entry to support VT-d Posted-Interrupts Feng Wu
2015-03-26 19:00   ` Andrew Cooper
2015-03-27  1:53     ` Wu, Feng
2015-03-27  9:58       ` Jan Beulich
2015-04-02  6:32         ` Tian, Kevin
2015-03-25 12:31 ` [RFC v1 07/15] vt-d: Add API to update IRTE when VT-d PI is used Feng Wu
2015-03-26 19:17   ` Andrew Cooper
2015-03-27  2:13     ` Wu, Feng
2015-03-27 10:02       ` Jan Beulich
2015-03-27  4:52     ` Wu, Feng
2015-03-26 19:36   ` Konrad Rzeszutek Wilk
2015-03-27  1:59     ` Wu, Feng
2015-04-02  5:34   ` Tian, Kevin
2015-04-02  6:02     ` Wu, Feng
2015-03-25 12:31 ` [RFC v1 08/15] Update IRTE according to guest interrupt config changes Feng Wu
2015-03-26 19:46   ` Konrad Rzeszutek Wilk
2015-03-27  5:45     ` Wu, Feng
2015-03-26 19:59   ` Andrew Cooper
2015-03-27  5:49     ` Wu, Feng
2015-03-27 11:31       ` Andrew Cooper
2015-04-02  5:52   ` Tian, Kevin
2015-04-02  6:20     ` Wu, Feng
2015-04-02  6:49       ` Tian, Kevin
2015-04-02  8:02         ` Wu, Feng
2015-04-03  8:29           ` Tian, Kevin
2015-03-25 12:31 ` [RFC v1 09/15] Add a new per-vCPU tasklet to wakeup the blocked vCPU Feng Wu
2015-04-02  5:53   ` Tian, Kevin
2015-04-02  7:20     ` Wu, Feng
2015-03-25 12:31 ` [RFC v1 10/15] vmx: Define two per-cpu variants Feng Wu
2015-03-26 19:59   ` Andrew Cooper
2015-04-02  5:54   ` Tian, Kevin
2015-04-02  6:24     ` Wu, Feng
2015-03-25 12:31 ` [RFC v1 11/15] vmx: Add a global wake-up vector for VT-d Posted-Interrupts Feng Wu
2015-03-26 20:07   ` Andrew Cooper
2015-04-02  6:00   ` Tian, Kevin
2015-04-02  7:18     ` Wu, Feng
2015-04-08  9:02       ` Tian, Kevin
2015-04-08 11:14         ` Wu, Feng
2015-03-25 12:31 ` [RFC v1 12/15] vmx: Properly handle notification event when vCPU is running Feng Wu
2015-03-25 14:14   ` Zhang, Yang Z
2015-03-27  4:40     ` Wu, Feng
2015-03-27  4:44       ` Zhang, Yang Z
2015-03-27  4:57         ` Wu, Feng
2015-04-02  6:08           ` Tian, Kevin
2015-04-02  7:21             ` Wu, Feng
2015-04-02 19:15             ` Konrad Rzeszutek Wilk
2015-04-03  2:00               ` Wu, Feng
2015-04-03 13:36                 ` Konrad Rzeszutek Wilk
2015-04-07  0:35                   ` Wu, Feng
2015-03-26 19:57   ` Konrad Rzeszutek Wilk
2015-03-27  3:06     ` Wu, Feng
2015-03-25 12:31 ` [RFC v1 13/15] Update Posted-Interrupts Descriptor during vCPU scheduling Feng Wu
2015-03-26 20:16   ` Andrew Cooper
2015-03-27  2:59     ` Wu, Feng
2015-04-02  6:24   ` Tian, Kevin [this message]
2015-04-02  8:39     ` Wu, Feng
2015-04-08  8:53       ` Tian, Kevin
2015-04-08 11:01         ` Wu, Feng
2015-04-09  2:37           ` Tian, Kevin
2015-03-25 12:31 ` [RFC v1 14/15] Suppress posting interrupts when 'SN' is set Feng Wu
2015-03-26 20:34   ` Andrew Cooper
2015-03-27  3:00     ` Wu, Feng
2015-03-27 12:06       ` Andrew Cooper
2015-03-27 13:45         ` Wu, Feng
2015-03-27 13:49           ` Andrew Cooper
2015-03-30  2:11             ` Wu, Feng
2015-03-30 10:11               ` Andrew Cooper
2015-03-25 12:31 ` [RFC v1 15/15] Add a command line parameter for VT-d posted-interrupts Feng Wu
2015-03-26 18:50 ` [RFC v1 00/15] Add VT-d Posted-Interrupts support Konrad Rzeszutek Wilk
2015-03-27  1:06   ` Wu, Feng
2015-03-27 14:44     ` Konrad Rzeszutek Wilk
2015-04-01 13:21 ` Wu, Feng
2015-04-13 12:12   ` Jan Beulich
2015-04-13 23:38     ` Wu, Feng
2015-04-24 17:50     ` Wu, Feng
2015-04-27 23:40       ` Jan Beulich

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=AADFC41AFE54684AB9EE6CBC0274A5D1261FB78E@SHSMSX101.ccr.corp.intel.com \
    --to=kevin.tian@intel.com \
    --cc=JBeulich@suse.com \
    --cc=feng.wu@intel.com \
    --cc=keir@xen.org \
    --cc=xen-devel@lists.xen.org \
    --cc=yang.z.zhang@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.