All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Winchell <dwinchell@virtualiron.com>
To: Keir Fraser <Keir.Fraser@cl.cam.ac.uk>
Cc: "Dong, Eddie" <eddie.dong@intel.com>,
	Dave Winchell <dwinchell@virtualiron.com>,
	xen-devel@lists.xensource.com, "Shan,
	Haitao" <haitao.shan@intel.com>,
	"Jiang, Yunhong" <yunhong.jiang@intel.com>
Subject: Re: [PATCH] Add a timer mode that disables pending missed ticks
Date: Tue, 30 Oct 2007 17:16:15 -0400	[thread overview]
Message-ID: <47279F1F.6050904@virtualiron.com> (raw)
In-Reply-To: <C34D0886.17A54%Keir.Fraser@cl.cam.ac.uk>

[-- Attachment #1: Type: text/plain, Size: 1328 bytes --]

Keir,

Here are my comments on your change.
I've attached an updated vpt.c with the changes.

1. For the no_missed_tick_accounting method, we still need the update
    to pt->scheduled taking into account the time that has elapsed when
    missed ticks are calculated. missed_ticks (pt_process_missed_ticks)
    is called from pt_restore_timer() and pt_timer_fn() and, thus, its
    easiest to put the check for no_missed_tick_accounting method in
    missed_ticks() itself.

2. In pt_timer_fn you don't want to increment pending_intr_nr beyond 1
    for no_missed_tick_accounting option.

thanks,
Dave


Keir Fraser wrote:

>
> Applied as c/s 16274. Please take a look and make sure the mode works 
> as you expect.
>
>  -- Keir
>
> On 30/10/07 14:28, "Shan, Haitao" <haitao.shan@intel.com> wrote:
>
>     Hi, Keir,
>
>     This patch adds a new timer mode, in which no missed ticks is
>     calculated. This can be used with latest x86_64 linux guest, since
>     it can pick up missed ticks themselves.
>
>      <<no_missed_ticks.patch>>
>
>     Best Regards
>     Haitao Shan
>
>     ------------------------------------------------------------------------
>     _______________________________________________
>     Xen-devel mailing list
>     Xen-devel@lists.xensource.com
>     http://lists.xensource.com/xen-devel
>
>


[-- Attachment #2: diff.vpt --]
[-- Type: text/plain, Size: 2208 bytes --]

*** vpt.c.new.c	2007-10-30 16:45:26.000000000 -0400
--- vpt.c	2007-10-30 15:30:57.000000000 -0400
***************
*** 57,73 ****
          return;
  
      missed_ticks = missed_ticks / (s_time_t) pt->period + 1;
! 
!     if( !mode_is(pt->vcpu->domain, no_missed_tick_accounting) ) {
! 	if ( missed_ticks > 1000 )
! 	    {
! 		/* TODO: Adjust guest time together */
! 		pt->pending_intr_nr++;
! 	    }
! 	else
! 	    {
! 		pt->pending_intr_nr += missed_ticks;
! 	    }
      }
  
      pt->scheduled += missed_ticks * pt->period;
--- 57,70 ----
          return;
  
      missed_ticks = missed_ticks / (s_time_t) pt->period + 1;
!     if ( missed_ticks > 1000 )
!     {
!         /* TODO: Adjust guest time together */
!         pt->pending_intr_nr++;
!     }
!     else
!     {
!         pt->pending_intr_nr += missed_ticks;
      }
  
      pt->scheduled += missed_ticks * pt->period;
***************
*** 120,126 ****
  
      list_for_each_entry ( pt, head, list )
      {
! 	pt_process_missed_ticks(pt);
          set_timer(&pt->timer, pt->scheduled);
      }
  
--- 117,124 ----
  
      list_for_each_entry ( pt, head, list )
      {
!         if ( !mode_is(v->domain, no_missed_tick_accounting) )
!             pt_process_missed_ticks(pt);
          set_timer(&pt->timer, pt->scheduled);
      }
  
***************
*** 135,151 ****
  
      pt_lock(pt);
  
!     if (mode_is(pt->vcpu->domain, no_missed_tick_accounting)) {
! 	if(!pt->pending_intr_nr)
! 	    pt->pending_intr_nr++;
!     }
!     else
! 	pt->pending_intr_nr++;
  
      if ( !pt->one_shot )
      {
          pt->scheduled += pt->period;
! 	pt_process_missed_ticks(pt);
          set_timer(&pt->timer, pt->scheduled);
      }
  
--- 133,152 ----
  
      pt_lock(pt);
  
!     pt->pending_intr_nr++;
  
      if ( !pt->one_shot )
      {
          pt->scheduled += pt->period;
!         if ( !mode_is(pt->vcpu->domain, no_missed_tick_accounting) )
!         {
!             pt_process_missed_ticks(pt);
!         }
!         else if ( (NOW() - pt->scheduled) >= 0 )
!         {
!             pt->pending_intr_nr++;
!             pt->scheduled = NOW() + pt->period;
!         }
          set_timer(&pt->timer, pt->scheduled);
      }
  

[-- Attachment #3: vpt.c --]
[-- Type: text/x-csrc, Size: 8507 bytes --]

/*
 * vpt.c: Virtual Platform Timer
 *
 * Copyright (c) 2006, Xiaowei Yang, Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place - Suite 330, Boston, MA 02111-1307 USA.
 *
 */

#include <xen/time.h>
#include <asm/hvm/support.h>
#include <asm/hvm/vpt.h>
#include <asm/event.h>

#define mode_is(d, name) \
    ((d)->arch.hvm_domain.params[HVM_PARAM_TIMER_MODE] == HVMPTM_##name)

static void pt_lock(struct periodic_time *pt)
{
    struct vcpu *v;

    for ( ; ; )
    {
        v = pt->vcpu;
        spin_lock(&v->arch.hvm_vcpu.tm_lock);
        if ( likely(pt->vcpu == v) )
            break;
        spin_unlock(&v->arch.hvm_vcpu.tm_lock);
    }
}

static void pt_unlock(struct periodic_time *pt)
{
    spin_unlock(&pt->vcpu->arch.hvm_vcpu.tm_lock);
}

static void pt_process_missed_ticks(struct periodic_time *pt)
{
    s_time_t missed_ticks;

    if ( pt->one_shot )
        return;

    missed_ticks = NOW() - pt->scheduled;
    if ( missed_ticks <= 0 )
        return;

    missed_ticks = missed_ticks / (s_time_t) pt->period + 1;

    if( !mode_is(pt->vcpu->domain, no_missed_tick_accounting) ) {
	if ( missed_ticks > 1000 )
	    {
		/* TODO: Adjust guest time together */
		pt->pending_intr_nr++;
	    }
	else
	    {
		pt->pending_intr_nr += missed_ticks;
	    }
    }

    pt->scheduled += missed_ticks * pt->period;
}

static void pt_freeze_time(struct vcpu *v)
{
    if ( !mode_is(v->domain, delay_for_missed_ticks) )
        return;

    v->arch.hvm_vcpu.guest_time = hvm_get_guest_time(v);
}

static void pt_thaw_time(struct vcpu *v)
{
    if ( !mode_is(v->domain, delay_for_missed_ticks) )
        return;

    if ( v->arch.hvm_vcpu.guest_time == 0 )
        return;

    hvm_set_guest_time(v, v->arch.hvm_vcpu.guest_time);
    v->arch.hvm_vcpu.guest_time = 0;
}

void pt_save_timer(struct vcpu *v)
{
    struct list_head *head = &v->arch.hvm_vcpu.tm_list;
    struct periodic_time *pt;

    if ( test_bit(_VPF_blocked, &v->pause_flags) )
        return;

    spin_lock(&v->arch.hvm_vcpu.tm_lock);

    list_for_each_entry ( pt, head, list )
        stop_timer(&pt->timer);

    pt_freeze_time(v);

    spin_unlock(&v->arch.hvm_vcpu.tm_lock);
}

void pt_restore_timer(struct vcpu *v)
{
    struct list_head *head = &v->arch.hvm_vcpu.tm_list;
    struct periodic_time *pt;

    spin_lock(&v->arch.hvm_vcpu.tm_lock);

    list_for_each_entry ( pt, head, list )
    {
	pt_process_missed_ticks(pt);
        set_timer(&pt->timer, pt->scheduled);
    }

    pt_thaw_time(v);

    spin_unlock(&v->arch.hvm_vcpu.tm_lock);
}

static void pt_timer_fn(void *data)
{
    struct periodic_time *pt = data;

    pt_lock(pt);

    if (mode_is(pt->vcpu->domain, no_missed_tick_accounting)) {
	if(!pt->pending_intr_nr)
	    pt->pending_intr_nr++;
    }
    else
	pt->pending_intr_nr++;

    if ( !pt->one_shot )
    {
        pt->scheduled += pt->period;
	pt_process_missed_ticks(pt);
        set_timer(&pt->timer, pt->scheduled);
    }

    vcpu_kick(pt->vcpu);

    pt_unlock(pt);
}

void pt_update_irq(struct vcpu *v)
{
    struct list_head *head = &v->arch.hvm_vcpu.tm_list;
    struct periodic_time *pt;
    uint64_t max_lag = -1ULL;
    int irq = -1;

    spin_lock(&v->arch.hvm_vcpu.tm_lock);

    list_for_each_entry ( pt, head, list )
    {
        if ( !is_isa_irq_masked(v, pt->irq) && pt->pending_intr_nr &&
             ((pt->last_plt_gtime + pt->period_cycles) < max_lag) )
        {
            max_lag = pt->last_plt_gtime + pt->period_cycles;
            irq = pt->irq;
        }
    }

    spin_unlock(&v->arch.hvm_vcpu.tm_lock);

    if ( is_lvtt(v, irq) )
    {
        vlapic_set_irq(vcpu_vlapic(v), irq, 0);
    }
    else if ( irq >= 0 )
    {
        hvm_isa_irq_deassert(v->domain, irq);
        hvm_isa_irq_assert(v->domain, irq);
    }
}

static struct periodic_time *is_pt_irq(
    struct vcpu *v, struct hvm_intack intack)
{
    struct list_head *head = &v->arch.hvm_vcpu.tm_list;
    struct periodic_time *pt;
    struct RTCState *rtc = &v->domain->arch.hvm_domain.pl_time.vrtc;
    int vector;

    list_for_each_entry ( pt, head, list )
    {
        if ( !pt->pending_intr_nr )
            continue;

        if ( is_lvtt(v, pt->irq) )
        {
            if ( pt->irq != intack.vector )
                continue;
            return pt;
        }

        vector = get_isa_irq_vector(v, pt->irq, intack.source);

        /* RTC irq need special care */
        if ( (intack.vector != vector) ||
             ((pt->irq == 8) && !is_rtc_periodic_irq(rtc)) )
            continue;

        return pt;
    }

    return NULL;
}

void pt_intr_post(struct vcpu *v, struct hvm_intack intack)
{
    struct periodic_time *pt;
    time_cb *cb;
    void *cb_priv;

    spin_lock(&v->arch.hvm_vcpu.tm_lock);

    pt = is_pt_irq(v, intack);
    if ( pt == NULL )
    {
        spin_unlock(&v->arch.hvm_vcpu.tm_lock);
        return;
    }

    if ( pt->one_shot )
    {
        pt->enabled = 0;
        list_del(&pt->list);
    }
    else
    {
        pt->pending_intr_nr--;
        if ( mode_is(v->domain, no_missed_tick_accounting) )
            pt->last_plt_gtime = hvm_get_guest_time(v);
        else
            pt->last_plt_gtime += pt->period_cycles;
    }

    if ( mode_is(v->domain, delay_for_missed_ticks) &&
         (hvm_get_guest_time(v) < pt->last_plt_gtime) )
        hvm_set_guest_time(v, pt->last_plt_gtime);

    cb = pt->cb;
    cb_priv = pt->priv;

    spin_unlock(&v->arch.hvm_vcpu.tm_lock);

    if ( cb != NULL )
        cb(v, cb_priv);
}

void pt_reset(struct vcpu *v)
{
    struct list_head *head = &v->arch.hvm_vcpu.tm_list;
    struct periodic_time *pt;

    spin_lock(&v->arch.hvm_vcpu.tm_lock);

    list_for_each_entry ( pt, head, list )
    {
        pt->pending_intr_nr = 0;
        pt->last_plt_gtime = hvm_get_guest_time(pt->vcpu);
        pt->scheduled = NOW() + pt->period;
        set_timer(&pt->timer, pt->scheduled);
    }

    spin_unlock(&v->arch.hvm_vcpu.tm_lock);
}

void pt_migrate(struct vcpu *v)
{
    struct list_head *head = &v->arch.hvm_vcpu.tm_list;
    struct periodic_time *pt;

    spin_lock(&v->arch.hvm_vcpu.tm_lock);

    list_for_each_entry ( pt, head, list )
        migrate_timer(&pt->timer, v->processor);

    spin_unlock(&v->arch.hvm_vcpu.tm_lock);
}

void create_periodic_time(
    struct vcpu *v, struct periodic_time *pt, uint64_t period,
    uint8_t irq, char one_shot, time_cb *cb, void *data)
{
    destroy_periodic_time(pt);

    spin_lock(&v->arch.hvm_vcpu.tm_lock);

    pt->enabled = 1;
    pt->pending_intr_nr = 0;

    /* Periodic timer must be at least 0.9ms. */
    if ( (period < 900000) && !one_shot )
    {
        gdprintk(XENLOG_WARNING,
                 "HVM_PlatformTime: program too small period %"PRIu64"\n",
                 period);
        period = 900000;
    }

    pt->period = period;
    pt->vcpu = v;
    pt->last_plt_gtime = hvm_get_guest_time(pt->vcpu);
    pt->irq = irq;
    pt->period_cycles = (u64)period * cpu_khz / 1000000L;
    pt->one_shot = one_shot;
    pt->scheduled = NOW() + period;
    /*
     * Offset LAPIC ticks from other timer ticks. Otherwise guests which use
     * LAPIC ticks for process accounting can see long sequences of process
     * ticks incorrectly accounted to interrupt processing.
     */
    if ( is_lvtt(v, irq) )
        pt->scheduled += period >> 1;
    pt->cb = cb;
    pt->priv = data;

    list_add(&pt->list, &v->arch.hvm_vcpu.tm_list);

    init_timer(&pt->timer, pt_timer_fn, pt, v->processor);
    set_timer(&pt->timer, pt->scheduled);

    spin_unlock(&v->arch.hvm_vcpu.tm_lock);
}

void destroy_periodic_time(struct periodic_time *pt)
{
    if ( !pt->enabled )
        return;

    pt_lock(pt);
    pt->enabled = 0;
    list_del(&pt->list);
    pt_unlock(pt);

    /*
     * pt_timer_fn() can run until this kill_timer() returns. We must do this
     * outside pt_lock() otherwise we can deadlock with pt_timer_fn().
     */
    kill_timer(&pt->timer);
}

[-- Attachment #4: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

  reply	other threads:[~2007-10-30 21:16 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-30 14:28 [PATCH] Add a timer mode that disables pending missed ticks Shan, Haitao
2007-10-30 16:12 ` Keir Fraser
2007-10-30 21:16   ` Dave Winchell [this message]
2007-10-31  7:09     ` Keir Fraser
2007-11-01 21:14       ` Dave Winchell
2007-11-01 21:21         ` Dave Winchell
2007-11-02  9:40         ` Keir Fraser
2007-11-02 15:51           ` Dave Winchell
2007-11-02 16:14             ` Keir Fraser
2007-11-02 16:35               ` Keir Fraser
2007-11-02 18:05               ` Dave Winchell
2007-11-03 21:17                 ` Dave Winchell
2007-11-03 22:31                   ` Keir Fraser
2007-11-05 14:36                     ` Dave Winchell
2007-11-07 14:39                       ` Dave Winchell
2007-11-07 14:39                         ` Keir Fraser
2007-11-07 16:23                           ` Dave Winchell
2007-11-07 17:10                             ` Keir Fraser
2007-11-07 17:29                               ` Keir Fraser
2007-11-07 17:47                                 ` Keir Fraser
2007-11-07 19:38                                   ` Dave Winchell
2007-11-08  8:07                                     ` Keir Fraser
2007-11-08 14:43                                       ` Dave Winchell
2007-11-08 14:53                                         ` Keir Fraser
2007-11-08 15:08                                           ` Dave Winchell
2007-11-09 19:22                                           ` Dave Winchell
2007-11-10 10:55                                             ` Keir Fraser
2007-11-12 15:37                                               ` Dave Winchell
2007-11-26 20:57                                               ` Dave Winchell
2007-12-06 11:57                                                 ` Keir Fraser
2007-12-19 18:57                                                   ` Dan Magenheimer
2007-12-19 19:32                                                     ` Dave Winchell
2008-01-03 22:57                                                       ` Dan Magenheimer
2008-01-03 23:24                                                         ` Dave Winchell
2008-01-04 23:24                                                         ` Dave Winchell
2008-01-08 14:33                                                           ` Keir Fraser
2008-01-09 16:53                                                             ` Dave Winchell
2008-01-09 17:19                                                               ` Dan Magenheimer
2008-01-09 19:14                                                                 ` Keir Fraser
2008-01-25 23:50                                                               ` Dan Magenheimer
2008-01-27 21:21                                                                 ` Dave Winchell
2008-01-28  0:29                                                                   ` Dan Magenheimer
2008-01-28 15:21                                                                     ` Dave Winchell
2008-01-29 22:34                                                                       ` Dan Magenheimer
2008-01-30 15:25                                                                         ` Dave Winchell
2008-01-30 21:04                                                                           ` Deepak Patel
2008-01-30 21:44                                                                             ` Dave Winchell
2008-02-01 22:31                                                                               ` Dan Magenheimer
2008-02-04 20:07                                                                                 ` Dave Winchell
2008-02-08 21:21                                                                                   ` Dave Winchell
2008-02-11 16:52                                                                                     ` Dave Winchell
2008-02-14 15:59                                                                                       ` Dave Winchell
2008-02-14 16:21                                                                                         ` Dan Magenheimer
2008-02-14 17:55                                                                                           ` Dave Winchell
2008-02-15 16:46                                                                                             ` Dan Magenheimer
2008-02-15 17:28                                                                                               ` Dave Winchell
2008-02-19 15:26                                                                                                 ` Dave Winchell
2008-02-19 17:55                                                                                                   ` Dan Magenheimer
2008-02-19 19:29                                                                                                     ` Keir Fraser
2008-02-19 20:50                                                                                                     ` Dave Winchell
2008-02-19 23:38                                                                                                       ` Dan Magenheimer
2008-02-20 23:40                                                                                                         ` Dan Magenheimer
2008-02-25 16:42                                                                                                       ` Dan Magenheimer
2008-02-25 20:01                                                                                                         ` (progress on hpet accuracy) and " Dave Winchell
2008-02-26  8:26                                                                                                           ` Keir Fraser
2008-02-26 14:45                                                                                                             ` Dave Winchell
2008-02-26 14:56                                                                                                               ` Keir Fraser
2008-02-26 15:49                                                                                                                 ` Dave Winchell
2008-03-05 15:06                                                                                                                 ` Dave Winchell
2008-03-05 15:20                                                                                                                   ` Keir Fraser
2008-03-05 17:25                                                                                                                     ` Dave Winchell
2008-03-05 17:21                                                                                                                       ` Keir Fraser
2008-03-05 17:42                                                                                                                         ` Dave Winchell
2008-03-05 17:53                                                                                                                           ` Dan Magenheimer
2008-03-06 23:36                                                                                                         ` Dan Magenheimer
2007-12-19 19:40                                                     ` Dave Winchell
2007-11-08 14:57                                         ` Dave Winchell
2007-10-31  3:10   ` Shan, Haitao

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=47279F1F.6050904@virtualiron.com \
    --to=dwinchell@virtualiron.com \
    --cc=Keir.Fraser@cl.cam.ac.uk \
    --cc=eddie.dong@intel.com \
    --cc=haitao.shan@intel.com \
    --cc=xen-devel@lists.xensource.com \
    --cc=yunhong.jiang@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.