ia64/xen-unstable

changeset 1588:bed9d3625f2e

bitkeeper revision 1.1018 (40dda73dmOqfB0T5ld-VOSobhH5ljg)

cleanups
author kaf24@scramble.cl.cam.ac.uk
date Sat Jun 26 16:41:33 2004 +0000 (2004-06-26)
parents 909193d7ebaa
children 9eda3ea2b4a0
files tools/xc/lib/xc.h tools/xc/lib/xc_domain.c tools/xc/lib/xc_linux_save.c tools/xc/py/Xc.c
line diff
     1.1 --- a/tools/xc/lib/xc.h	Fri Jun 25 21:56:38 2004 +0000
     1.2 +++ b/tools/xc/lib/xc.h	Sat Jun 26 16:41:33 2004 +0000
     1.3 @@ -47,7 +47,7 @@ typedef struct xc_shadow_control_stats_s
     1.4  int xc_domain_create(int xc_handle, 
     1.5                       unsigned int mem_kb, 
     1.6                       const char *name,
     1.7 -		     int cpu,
     1.8 +                     int cpu,
     1.9                       u32 *pdomid);
    1.10  int xc_domain_pause(int xc_handle, 
    1.11                      u32 domid);
    1.12 @@ -66,9 +66,9 @@ int xc_domain_getinfo(int xc_handle,
    1.13  int xc_shadow_control(int xc_handle,
    1.14                        u32 domid, 
    1.15                        unsigned int sop,
    1.16 -		      unsigned long *dirty_bitmap,
    1.17 -		      unsigned long pages,
    1.18 -		      xc_shadow_control_stats_t *stats);
    1.19 +                      unsigned long *dirty_bitmap,
    1.20 +                      unsigned long pages,
    1.21 +                      xc_shadow_control_stats_t *stats);
    1.22  
    1.23  
    1.24  #define XCFLAGS_VERBOSE 1
    1.25 @@ -78,14 +78,14 @@ int xc_shadow_control(int xc_handle,
    1.26  int xc_linux_save(int xc_handle,
    1.27                    u32 domid, 
    1.28                    unsigned int flags,
    1.29 -		  int (*writerfn)(void *, const void *, size_t),
    1.30 -		  void *writerst );
    1.31 +                  int (*writerfn)(void *, const void *, size_t),
    1.32 +                  void *writerst);
    1.33  
    1.34  int xc_linux_restore(int xc_handle,
    1.35                       u32 domid,
    1.36 -                     unsigned int flags,		     
    1.37 -		     int (*readerfn)(void *, void *, size_t),
    1.38 -		     void *readerst,
    1.39 +                     unsigned int flags,
    1.40 +                     int (*readerfn)(void *, void *, size_t),
    1.41 +                     void *readerst,
    1.42                       u32 *pdomid);
    1.43  
    1.44  int xc_linux_build(int xc_handle,
    1.45 @@ -94,7 +94,7 @@ int xc_linux_build(int xc_handle,
    1.46                     const char *ramdisk_name,
    1.47                     const char *cmdline,
    1.48                     unsigned int control_evtchn,
    1.49 -		   unsigned long flags);
    1.50 +                   unsigned long flags);
    1.51  
    1.52  int xc_netbsd_build(int xc_handle,
    1.53                      u32 domid,
     2.1 --- a/tools/xc/lib/xc_domain.c	Fri Jun 25 21:56:38 2004 +0000
     2.2 +++ b/tools/xc/lib/xc_domain.c	Sat Jun 26 16:41:33 2004 +0000
     2.3 @@ -118,9 +118,9 @@ int xc_domain_getinfo(int xc_handle,
     2.4  }
     2.5  
     2.6  int xc_domain_getfullinfo(int xc_handle,
     2.7 -		       u32 domid,
     2.8 -		       dom0_op_t *op,
     2.9 -		       full_execution_context_t *ctxt )
    2.10 +                          u32 domid,
    2.11 +                          dom0_op_t *op,
    2.12 +                          full_execution_context_t *ctxt )
    2.13  {
    2.14      int rc;
    2.15      op->cmd = DOM0_GETDOMAININFO;
    2.16 @@ -129,18 +129,18 @@ int xc_domain_getfullinfo(int xc_handle,
    2.17  
    2.18      rc = do_dom0_op(xc_handle, op);
    2.19      if ( ((u32)op->u.getdomaininfo.domain != domid) && rc > 0 )
    2.20 -	return -ESRCH;
    2.21 +        return -ESRCH;
    2.22      else
    2.23 -	return rc;
    2.24 +        return rc;
    2.25  }
    2.26  
    2.27  
    2.28  int xc_shadow_control(int xc_handle,
    2.29                        u32 domid, 
    2.30                        unsigned int sop,
    2.31 -		      unsigned long *dirty_bitmap,
    2.32 -		      unsigned long pages,
    2.33 -		      xc_shadow_control_stats_t *stats )
    2.34 +                      unsigned long *dirty_bitmap,
    2.35 +                      unsigned long pages,
    2.36 +                      xc_shadow_control_stats_t *stats )
    2.37  {
    2.38      int rc;
    2.39      dom0_op_t op;
    2.40 @@ -152,8 +152,9 @@ int xc_shadow_control(int xc_handle,
    2.41  
    2.42      rc = do_dom0_op(xc_handle, &op);
    2.43  
    2.44 -    if(stats) memcpy(stats, &op.u.shadow_control.stats,
    2.45 -		     sizeof(xc_shadow_control_stats_t));
    2.46 +    if ( stats )
    2.47 +        memcpy(stats, &op.u.shadow_control.stats,
    2.48 +               sizeof(xc_shadow_control_stats_t));
    2.49  
    2.50      return (rc == 0) ? op.u.shadow_control.pages : rc;
    2.51  }
     3.1 --- a/tools/xc/lib/xc_linux_save.c	Fri Jun 25 21:56:38 2004 +0000
     3.2 +++ b/tools/xc/lib/xc_linux_save.c	Sat Jun 26 16:41:33 2004 +0000
     3.3 @@ -26,8 +26,6 @@
     3.4  #define DDPRINTF(_f, _a...) ((void)0)
     3.5  #endif
     3.6  
     3.7 -
     3.8 -
     3.9  /* This may allow us to create a 'quiet' command-line option, if necessary. */
    3.10  #define verbose_printf(_f, _a...) \
    3.11      do {                          \
    3.12 @@ -41,67 +39,61 @@
    3.13   * in the guest's pseudophysical map.
    3.14   * 0x80000000-3 mark the shared_info, and blk/net rings
    3.15   */
    3.16 -#define MFN_IS_IN_PSEUDOPHYS_MAP(_mfn) \
    3.17 -    (((_mfn) < (1024*1024)) && \
    3.18 -     ( ( (live_mfn_to_pfn_table[_mfn] < nr_pfns) && \
    3.19 -       (live_pfn_to_mfn_table[live_mfn_to_pfn_table[_mfn]] == (_mfn)) ) || \
    3.20 -\
    3.21 -       (live_mfn_to_pfn_table[_mfn] >= 0x80000000 && \
    3.22 -	live_mfn_to_pfn_table[_mfn] <= 0x80000003 ) || \
    3.23 -	live_pfn_to_mfn_table[live_mfn_to_pfn_table[_mfn]] == 0x80000004 )  )
    3.24 +#define MFN_IS_IN_PSEUDOPHYS_MAP(_mfn)                                    \
    3.25 +    (((_mfn) < (1024*1024)) &&                                            \
    3.26 +     (((live_mfn_to_pfn_table[_mfn] < nr_pfns) &&                         \
    3.27 +       (live_pfn_to_mfn_table[live_mfn_to_pfn_table[_mfn]] == (_mfn))) || \
    3.28 +      ((live_mfn_to_pfn_table[_mfn] >= 0x80000000) &&                     \
    3.29 +       (live_mfn_to_pfn_table[_mfn] <= 0x80000003)) ||                    \
    3.30 +      (live_pfn_to_mfn_table[live_mfn_to_pfn_table[_mfn]] == 0x80000004)))
    3.31       
    3.32  /* Returns TRUE if MFN is successfully converted to a PFN. */
    3.33 -#define translate_mfn_to_pfn(_pmfn)         \
    3.34 -({                                          \
    3.35 -    unsigned long mfn = *(_pmfn);           \
    3.36 -    int _res = 1;                           \
    3.37 -    if ( !MFN_IS_IN_PSEUDOPHYS_MAP(mfn) )   \
    3.38 -        _res = 0;                           \
    3.39 -    else                                    \
    3.40 -        *(_pmfn) = live_mfn_to_pfn_table[mfn];   \
    3.41 -    _res;                                   \
    3.42 +#define translate_mfn_to_pfn(_pmfn)            \
    3.43 +({                                             \
    3.44 +    unsigned long mfn = *(_pmfn);              \
    3.45 +    int _res = 1;                              \
    3.46 +    if ( !MFN_IS_IN_PSEUDOPHYS_MAP(mfn) )      \
    3.47 +        _res = 0;                              \
    3.48 +    else                                       \
    3.49 +        *(_pmfn) = live_mfn_to_pfn_table[mfn]; \
    3.50 +    _res;                                      \
    3.51  })
    3.52  
    3.53 -
    3.54 -/* test_bit */
    3.55  static inline int test_bit ( int nr, volatile void * addr)
    3.56  {
    3.57 -    return ( ((unsigned long*)addr)[nr/(sizeof(unsigned long)*8)] >> 
    3.58 -	     (nr % (sizeof(unsigned long)*8) ) ) & 1;
    3.59 +    return (((unsigned long*)addr)[nr/(sizeof(unsigned long)*8)] >> 
    3.60 +            (nr % (sizeof(unsigned long)*8))) & 1;
    3.61  }
    3.62  
    3.63  static inline void clear_bit ( int nr, volatile void * addr)
    3.64  {
    3.65      ((unsigned long*)addr)[nr/(sizeof(unsigned long)*8)] &= 
    3.66 -	~(1 << (nr % (sizeof(unsigned long)*8) ) );
    3.67 +        ~(1 << (nr % (sizeof(unsigned long)*8) ) );
    3.68  }
    3.69  
    3.70  static inline void set_bit ( int nr, volatile void * addr)
    3.71  {
    3.72      ((unsigned long*)addr)[nr/(sizeof(unsigned long)*8)] |= 
    3.73 -	(1 << (nr % (sizeof(unsigned long)*8) ) );
    3.74 +        (1 << (nr % (sizeof(unsigned long)*8) ) );
    3.75  }
    3.76 -/*
    3.77 - * hweightN: returns the hamming weight (i.e. the number
    3.78 - * of bits set) of a N-bit word
    3.79 - */
    3.80  
    3.81 +/* Returns the hamming weight (i.e. the number of bits set) in a N-bit word */
    3.82  static inline unsigned int hweight32(unsigned int w)
    3.83  {
    3.84 -        unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
    3.85 -        res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
    3.86 -        res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
    3.87 -        res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
    3.88 -        return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
    3.89 +    unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
    3.90 +    res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
    3.91 +    res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
    3.92 +    res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
    3.93 +    return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
    3.94  }
    3.95  
    3.96  static inline int count_bits ( int nr, volatile void *addr)
    3.97  {
    3.98      int i, count = 0;
    3.99      unsigned long *p = (unsigned long *)addr;
   3.100 -    // we know the array is padded to unsigned long
   3.101 +    /* We know that the array is padded to unsigned long. */
   3.102      for(i=0;i<nr/(sizeof(unsigned long)*8);i++,p++)
   3.103 -	count += hweight32( *p );
   3.104 +        count += hweight32( *p );
   3.105      return count;
   3.106  }
   3.107  
   3.108 @@ -129,12 +121,8 @@ static inline int permute( int i, int nr
   3.109        LKJIHGF
   3.110        */
   3.111  
   3.112 -    do
   3.113 -    {
   3.114 -	i = ( ( i>>(order_nr-10))  | ( i<<10 ) ) &
   3.115 -	    ((1<<order_nr)-1);
   3.116 -    }
   3.117 -    while ( i >= nr ); // this won't ever loop if nr is a power of 2
   3.118 +    do { i = ((i>>(order_nr-10)) | ( i<<10 ) ) & ((1<<order_nr)-1); }
   3.119 +    while ( i >= nr ); /* this won't ever loop if nr is a power of 2 */
   3.120  
   3.121      return i;
   3.122  }
   3.123 @@ -154,12 +142,12 @@ static long long llgettimeofday()
   3.124  static long long tv_delta( struct timeval *new, struct timeval *old )
   3.125  {
   3.126      return ((new->tv_sec - old->tv_sec)*1000000 ) + 
   3.127 -	(new->tv_usec - old->tv_usec);
   3.128 +        (new->tv_usec - old->tv_usec);
   3.129  }
   3.130  
   3.131  static int print_stats( int xc_handle, u32 domid, 
   3.132 -			int pages_sent, xc_shadow_control_stats_t *stats,
   3.133 -			int print )
   3.134 +                        int pages_sent, xc_shadow_control_stats_t *stats,
   3.135 +                        int print )
   3.136  {
   3.137      static struct timeval wall_last;
   3.138      static long long      d0_cpu_last;
   3.139 @@ -175,10 +163,8 @@ static int print_stats( int xc_handle, u
   3.140      d0_cpu_now = xc_domain_get_cpu_usage( xc_handle, 0 )/1000;
   3.141      d1_cpu_now = xc_domain_get_cpu_usage( xc_handle, domid )/1000;
   3.142  
   3.143 -    if ( d0_cpu_now == -1 || d1_cpu_now == -1 )	
   3.144 -    {
   3.145 -	printf("ARRHHH!!\n");
   3.146 -    }
   3.147 +    if ( (d0_cpu_now == -1) || (d1_cpu_now == -1) ) 
   3.148 +        printf("ARRHHH!!\n");
   3.149  
   3.150      wall_delta = tv_delta(&wall_now,&wall_last)/1000;
   3.151  
   3.152 @@ -187,66 +173,63 @@ static int print_stats( int xc_handle, u
   3.153      d0_cpu_delta  = (d0_cpu_now - d0_cpu_last)/1000;
   3.154      d1_cpu_delta  = (d1_cpu_now - d1_cpu_last)/1000;
   3.155  
   3.156 -    if(print)
   3.157 -	printf("delta %lldms, dom0 %d%%, target %d%%, sent %dMb/s, dirtied %dMb/s\n",
   3.158 -	       wall_delta, 
   3.159 -	       (int)((d0_cpu_delta*100)/wall_delta),
   3.160 -	       (int)((d1_cpu_delta*100)/wall_delta),
   3.161 -	       (int)((pages_sent*PAGE_SIZE*8)/(wall_delta*1000)),
   3.162 -	       (int)((stats->dirty_count*PAGE_SIZE*8)/(wall_delta*1000))
   3.163 -	    );
   3.164 +    if ( print )
   3.165 +        printf("delta %lldms, dom0 %d%%, target %d%%, sent %dMb/s, "
   3.166 +               "dirtied %dMb/s\n",
   3.167 +               wall_delta, 
   3.168 +               (int)((d0_cpu_delta*100)/wall_delta),
   3.169 +               (int)((d1_cpu_delta*100)/wall_delta),
   3.170 +               (int)((pages_sent*PAGE_SIZE*8)/(wall_delta*1000)),
   3.171 +               (int)((stats->dirty_count*PAGE_SIZE*8)/(wall_delta*1000)));
   3.172  
   3.173      d0_cpu_last  = d0_cpu_now;
   3.174      d1_cpu_last  = d1_cpu_now;
   3.175 -    wall_last = wall_now;	
   3.176 +    wall_last = wall_now; 
   3.177  
   3.178      return 0;
   3.179  }
   3.180  
   3.181  
   3.182  static int analysis_phase( int xc_handle, u32 domid, 
   3.183 -			   int nr_pfns, unsigned long *arr )
   3.184 +                           int nr_pfns, unsigned long *arr )
   3.185  {
   3.186      long long start, now;
   3.187      xc_shadow_control_stats_t stats;
   3.188  
   3.189      start = llgettimeofday();
   3.190  
   3.191 -    while(0)
   3.192 +    while ( 0 )
   3.193      {
   3.194 -	int i;
   3.195 +        int i;
   3.196  
   3.197 -	xc_shadow_control( xc_handle, domid, 
   3.198 -			   DOM0_SHADOW_CONTROL_OP_CLEAN2,
   3.199 -			   arr, nr_pfns, NULL);
   3.200 -	printf("#Flush\n");
   3.201 -	for(i=0;i<100;i++)
   3.202 -	{	    
   3.203 -	    usleep(10000);	    
   3.204 -	    now = llgettimeofday();
   3.205 -	    xc_shadow_control( xc_handle, domid, 
   3.206 -			       DOM0_SHADOW_CONTROL_OP_PEEK,
   3.207 -			       NULL, 0, &stats);
   3.208 +        xc_shadow_control( xc_handle, domid, 
   3.209 +                           DOM0_SHADOW_CONTROL_OP_CLEAN2,
   3.210 +                           arr, nr_pfns, NULL);
   3.211 +        printf("#Flush\n");
   3.212 +        for ( i = 0; i < 100; i++ )
   3.213 +        {     
   3.214 +            usleep(10000);     
   3.215 +            now = llgettimeofday();
   3.216 +            xc_shadow_control( xc_handle, domid, 
   3.217 +                               DOM0_SHADOW_CONTROL_OP_PEEK,
   3.218 +                               NULL, 0, &stats);
   3.219  
   3.220 -	    printf("now= %lld faults= %ld dirty= %ld dirty_net= %ld dirty_block= %ld\n", 
   3.221 -		   ((now-start)+500)/1000, 
   3.222 -		   stats.fault_count, stats.dirty_count,
   3.223 -		   stats.dirty_net_count, stats.dirty_block_count );
   3.224 -
   3.225 -	}
   3.226 -
   3.227 -
   3.228 +            printf("now= %lld faults= %ld dirty= %ld dirty_net= %ld "
   3.229 +                   "dirty_block= %ld\n", 
   3.230 +                   ((now-start)+500)/1000, 
   3.231 +                   stats.fault_count, stats.dirty_count,
   3.232 +                   stats.dirty_net_count, stats.dirty_block_count);
   3.233 +        }
   3.234      }
   3.235 -    
   3.236  
   3.237      return -1;
   3.238  }
   3.239  
   3.240  int xc_linux_save(int xc_handle,
   3.241                    u32 domid, 
   3.242 -		  unsigned int flags,
   3.243 -		  int (*writerfn)(void *, const void *, size_t),
   3.244 -		  void *writerst )
   3.245 +                  unsigned int flags,
   3.246 +                  int (*writerfn)(void *, const void *, size_t),
   3.247 +                  void *writerst )
   3.248  {
   3.249      dom0_op_t op;
   3.250      int rc = 1, i, j, k, last_iter, iter = 0;
   3.251 @@ -257,8 +240,8 @@ int xc_linux_save(int xc_handle,
   3.252      int sent_last_iter, sent_this_iter, skip_this_iter;
   3.253  
   3.254      /* Important tuning parameters */
   3.255 -    int max_iters  = 29; // limit us to 30 times round loop
   3.256 -    int max_factor = 3;  // never send more than 3x nr_pfns 
   3.257 +    int max_iters  = 29; /* limit us to 30 times round loop */
   3.258 +    int max_factor = 3;  /* never send more than 3x nr_pfns */
   3.259  
   3.260      /* The new domain's shared-info frame number. */
   3.261      unsigned long shared_info_frame;
   3.262 @@ -321,14 +304,14 @@ int xc_linux_save(int xc_handle,
   3.263  
   3.264      if ( xc_domain_pause( xc_handle, domid ) )
   3.265      {
   3.266 -	PERROR("Could not pause domain");
   3.267 -	goto out;
   3.268 +        PERROR("Could not pause domain");
   3.269 +        goto out;
   3.270      }
   3.271  
   3.272      if ( xc_domain_getfullinfo( xc_handle, domid, &op, &ctxt) )
   3.273      {
   3.274 -	PERROR("Could not get full domain info");
   3.275 -	goto out;
   3.276 +        PERROR("Could not get full domain info");
   3.277 +        goto out;
   3.278      }
   3.279      memcpy(name, op.u.getdomaininfo.name, sizeof(name));
   3.280      shared_info_frame = op.u.getdomaininfo.shared_info_frame;
   3.281 @@ -343,8 +326,8 @@ int xc_linux_save(int xc_handle,
   3.282      /* Map the suspend-record MFN to pin it. The page must be owned by 
   3.283         domid for this to succeed. */
   3.284      p_srec = mfn_mapper_map_single(xc_handle, domid,
   3.285 -				 sizeof(*p_srec), PROT_READ, 
   3.286 -				 ctxt.cpu_ctxt.esi );
   3.287 +                                   sizeof(*p_srec), PROT_READ, 
   3.288 +                                   ctxt.cpu_ctxt.esi );
   3.289  
   3.290      if (!p_srec)
   3.291      {
   3.292 @@ -363,9 +346,9 @@ int xc_linux_save(int xc_handle,
   3.293  
   3.294      /* the pfn_to_mfn_frame_list fits in a single page */
   3.295      live_pfn_to_mfn_frame_list = 
   3.296 -	mfn_mapper_map_single(xc_handle, domid, 
   3.297 -			      PAGE_SIZE, PROT_READ, 
   3.298 -			      p_srec->pfn_to_mfn_frame_list );
   3.299 +        mfn_mapper_map_single(xc_handle, domid, 
   3.300 +                              PAGE_SIZE, PROT_READ, 
   3.301 +                              p_srec->pfn_to_mfn_frame_list );
   3.302  
   3.303      if (!live_pfn_to_mfn_frame_list)
   3.304      {
   3.305 @@ -375,20 +358,20 @@ int xc_linux_save(int xc_handle,
   3.306  
   3.307      /* Track the mfn_to_pfn table down from the domains PT */
   3.308      {
   3.309 -	unsigned long *pgd;
   3.310 -	unsigned long mfn_to_pfn_table_start_mfn;
   3.311 +        unsigned long *pgd;
   3.312 +        unsigned long mfn_to_pfn_table_start_mfn;
   3.313  
   3.314 -	pgd = mfn_mapper_map_single(xc_handle, domid, 
   3.315 -				PAGE_SIZE, PROT_READ, 
   3.316 -				ctxt.pt_base>>PAGE_SHIFT);
   3.317 +        pgd = mfn_mapper_map_single(xc_handle, domid, 
   3.318 +                                    PAGE_SIZE, PROT_READ, 
   3.319 +                                    ctxt.pt_base>>PAGE_SHIFT);
   3.320  
   3.321 -	mfn_to_pfn_table_start_mfn = 
   3.322 -	    pgd[HYPERVISOR_VIRT_START>>L2_PAGETABLE_SHIFT]>>PAGE_SHIFT;
   3.323 +        mfn_to_pfn_table_start_mfn = 
   3.324 +            pgd[HYPERVISOR_VIRT_START>>L2_PAGETABLE_SHIFT]>>PAGE_SHIFT;
   3.325  
   3.326 -	live_mfn_to_pfn_table = 
   3.327 -	    mfn_mapper_map_single(xc_handle, ~0UL, 
   3.328 -				  PAGE_SIZE*1024, PROT_READ, 
   3.329 -				  mfn_to_pfn_table_start_mfn );
   3.330 +        live_mfn_to_pfn_table = 
   3.331 +            mfn_mapper_map_single(xc_handle, ~0UL, 
   3.332 +                                  PAGE_SIZE*1024, PROT_READ, 
   3.333 +                                  mfn_to_pfn_table_start_mfn );
   3.334      }
   3.335  
   3.336      /* Map all the frames of the pfn->mfn table. For migrate to succeed, 
   3.337 @@ -397,9 +380,9 @@ int xc_linux_save(int xc_handle,
   3.338         from a safety POV anyhow. */
   3.339  
   3.340      live_pfn_to_mfn_table = mfn_mapper_map_batch( xc_handle, domid, 
   3.341 -						  PROT_READ,
   3.342 -						  live_pfn_to_mfn_frame_list,
   3.343 -						  (nr_pfns+1023)/1024 );  
   3.344 +                                                  PROT_READ,
   3.345 +                                                  live_pfn_to_mfn_frame_list,
   3.346 +                                                  (nr_pfns+1023)/1024 );  
   3.347      if( !live_pfn_to_mfn_table )
   3.348      {
   3.349          PERROR("Couldn't map pfn_to_mfn table");
   3.350 @@ -423,59 +406,59 @@ int xc_linux_save(int xc_handle,
   3.351  
   3.352      if( live )
   3.353      { 
   3.354 -	if ( xc_shadow_control( xc_handle, domid, 
   3.355 -			   DOM0_SHADOW_CONTROL_OP_ENABLE_LOGDIRTY,
   3.356 -			   NULL, 0, NULL ) < 0 )
   3.357 -	{
   3.358 -	    ERROR("Couldn't enable shadow mode");
   3.359 -	    goto out;
   3.360 -	}
   3.361 +        if ( xc_shadow_control( xc_handle, domid, 
   3.362 +                                DOM0_SHADOW_CONTROL_OP_ENABLE_LOGDIRTY,
   3.363 +                                NULL, 0, NULL ) < 0 )
   3.364 +        {
   3.365 +            ERROR("Couldn't enable shadow mode");
   3.366 +            goto out;
   3.367 +        }
   3.368  
   3.369 -	if ( xc_domain_unpause( xc_handle, domid ) < 0 )
   3.370 -	{
   3.371 -	    ERROR("Couldn't unpause domain");
   3.372 -	    goto out;
   3.373 -	}
   3.374 +        if ( xc_domain_unpause( xc_handle, domid ) < 0 )
   3.375 +        {
   3.376 +            ERROR("Couldn't unpause domain");
   3.377 +            goto out;
   3.378 +        }
   3.379  
   3.380 -	last_iter = 0;
   3.381 -	sent_last_iter = 1<<20; // 4GB's worth of pages
   3.382 +        last_iter = 0;
   3.383 +        sent_last_iter = 1<<20; /* 4GB of pages */
   3.384      }
   3.385      else
   3.386 -	last_iter = 1;
   3.387 +        last_iter = 1;
   3.388  
   3.389      /* calculate the power of 2 order of nr_pfns, e.g.
   3.390 -     15->4 16->4 17->5 */
   3.391 +       15->4 16->4 17->5 */
   3.392      for( i=nr_pfns-1, order_nr=0; i ; i>>=1, order_nr++ );
   3.393  
   3.394      /* Setup to_send bitmap */
   3.395      {
   3.396 -	int sz = (nr_pfns/8) + 8; // includes slop at end of array
   3.397 -	
   3.398 -	to_send = malloc( sz );
   3.399 -	to_fix  = calloc( 1, sz );
   3.400 -	to_skip = malloc( sz );
   3.401 +        int sz = (nr_pfns/8) + 8; /* includes slop at end of array */
   3.402 + 
   3.403 +        to_send = malloc( sz );
   3.404 +        to_fix  = calloc( 1, sz );
   3.405 +        to_skip = malloc( sz );
   3.406  
   3.407 -	if (!to_send || !to_fix || !to_skip)
   3.408 -	{
   3.409 -	    ERROR("Couldn't allocate to_send array");
   3.410 -	    goto out;
   3.411 -	}
   3.412 +        if (!to_send || !to_fix || !to_skip)
   3.413 +        {
   3.414 +            ERROR("Couldn't allocate to_send array");
   3.415 +            goto out;
   3.416 +        }
   3.417  
   3.418 -	memset( to_send, 0xff, sz );
   3.419 +        memset( to_send, 0xff, sz );
   3.420  
   3.421 -	if ( mlock( to_send, sz ) )
   3.422 -	{
   3.423 -	    PERROR("Unable to mlock to_send");
   3.424 -	    return 1;
   3.425 -	}
   3.426 +        if ( mlock( to_send, sz ) )
   3.427 +        {
   3.428 +            PERROR("Unable to mlock to_send");
   3.429 +            return 1;
   3.430 +        }
   3.431  
   3.432 -	/* (to fix is local only) */
   3.433 +        /* (to fix is local only) */
   3.434  
   3.435 -	if ( mlock( to_skip, sz ) )
   3.436 -	{
   3.437 -	    PERROR("Unable to mlock to_skip");
   3.438 -	    return 1;
   3.439 -	}
   3.440 +        if ( mlock( to_skip, sz ) )
   3.441 +        {
   3.442 +            PERROR("Unable to mlock to_skip");
   3.443 +            return 1;
   3.444 +        }
   3.445  
   3.446      }
   3.447  
   3.448 @@ -493,8 +476,8 @@ int xc_linux_save(int xc_handle,
   3.449  
   3.450      if ( mlock( pfn_type, BATCH_SIZE * sizeof(unsigned long) ) )
   3.451      {
   3.452 -	ERROR("Unable to mlock");
   3.453 -	goto out;
   3.454 +        ERROR("Unable to mlock");
   3.455 +        goto out;
   3.456      }
   3.457  
   3.458  
   3.459 @@ -506,16 +489,16 @@ int xc_linux_save(int xc_handle,
   3.460      {
   3.461          mfn = live_pfn_to_mfn_table[i];
   3.462  
   3.463 -	if( (live_mfn_to_pfn_table[mfn] != i) && (mfn != 0x80000004) )
   3.464 -	    printf("i=0x%x mfn=%x live_mfn_to_pfn_table=%x\n",
   3.465 -		   i,mfn,live_mfn_to_pfn_table[mfn]);
   3.466 +        if( (live_mfn_to_pfn_table[mfn] != i) && (mfn != 0x80000004) )
   3.467 +            printf("i=0x%x mfn=%x live_mfn_to_pfn_table=%x\n",
   3.468 +                   i,mfn,live_mfn_to_pfn_table[mfn]);
   3.469      }
   3.470  #endif
   3.471  
   3.472      /* Map the shared info frame */
   3.473      live_shinfo = mfn_mapper_map_single(xc_handle, domid,
   3.474 -					PAGE_SIZE, PROT_READ,
   3.475 -					shared_info_frame);
   3.476 +                                        PAGE_SIZE, PROT_READ,
   3.477 +                                        shared_info_frame);
   3.478  
   3.479      if (!live_shinfo)
   3.480      {
   3.481 @@ -540,293 +523,297 @@ int xc_linux_save(int xc_handle,
   3.482      
   3.483      while(1)
   3.484      {
   3.485 -	unsigned int prev_pc, sent_this_iter, N, batch;
   3.486 +        unsigned int prev_pc, sent_this_iter, N, batch;
   3.487  
   3.488 -	iter++;
   3.489 -	sent_this_iter = 0;
   3.490 -	skip_this_iter = 0;
   3.491 -	prev_pc = 0;
   3.492 -	N=0;
   3.493 +        iter++;
   3.494 +        sent_this_iter = 0;
   3.495 +        skip_this_iter = 0;
   3.496 +        prev_pc = 0;
   3.497 +        N=0;
   3.498  
   3.499 -	verbose_printf("Saving memory pages: iter %d   0%%", iter);
   3.500 +        verbose_printf("Saving memory pages: iter %d   0%%", iter);
   3.501  
   3.502 -	while( N < nr_pfns )
   3.503 -	{
   3.504 -	    unsigned int this_pc = (N * 100) / nr_pfns;
   3.505 +        while( N < nr_pfns )
   3.506 +        {
   3.507 +            unsigned int this_pc = (N * 100) / nr_pfns;
   3.508  
   3.509 -	    if ( (this_pc - prev_pc) >= 5 )
   3.510 -	    {
   3.511 -		verbose_printf("\b\b\b\b%3d%%", this_pc);
   3.512 -		prev_pc = this_pc;
   3.513 -	    }
   3.514 +            if ( (this_pc - prev_pc) >= 5 )
   3.515 +            {
   3.516 +                verbose_printf("\b\b\b\b%3d%%", this_pc);
   3.517 +                prev_pc = this_pc;
   3.518 +            }
   3.519 +
   3.520 +            /* slightly wasteful to peek the whole array evey time, 
   3.521 +               but this is fast enough for the moment. */
   3.522  
   3.523 -	    /* slightly wasteful to peek the whole array evey time, 
   3.524 -	       but this is fast enough for the moment. */
   3.525 +            if ( !last_iter && 
   3.526 +                 xc_shadow_control(xc_handle, domid, 
   3.527 +                                   DOM0_SHADOW_CONTROL_OP_PEEK,
   3.528 +                                   to_skip, nr_pfns, NULL) != nr_pfns ) 
   3.529 +            {
   3.530 +                ERROR("Error peeking shadow bitmap");
   3.531 +                goto out;
   3.532 +            }
   3.533 +     
   3.534  
   3.535 -	    if ( !last_iter && 
   3.536 -		 xc_shadow_control(xc_handle, domid, 
   3.537 -				   DOM0_SHADOW_CONTROL_OP_PEEK,
   3.538 -				   to_skip, nr_pfns, NULL) != nr_pfns ) 
   3.539 -	    {
   3.540 -		ERROR("Error peeking shadow bitmap");
   3.541 -		goto out;
   3.542 -	    }
   3.543 -	    
   3.544 +            /* load pfn_type[] with the mfn of all the pages we're doing in
   3.545 +               this batch. */
   3.546 +
   3.547 +            for ( batch = 0; batch < BATCH_SIZE && N < nr_pfns ; N++ )
   3.548 +            {
   3.549 +                int n = permute(N, nr_pfns, order_nr );
   3.550  
   3.551 -	    /* load pfn_type[] with the mfn of all the pages we're doing in
   3.552 -	       this batch. */
   3.553 -
   3.554 -	    for( batch = 0; batch < BATCH_SIZE && N < nr_pfns ; N++ )
   3.555 -	    {
   3.556 -		int n = permute(N, nr_pfns, order_nr );
   3.557 +                if ( 0 && debug )
   3.558 +                    fprintf(stderr,"%d pfn= %08lx mfn= %08lx %d  "
   3.559 +                            " [mfn]= %08lx\n",
   3.560 +                            iter, n, live_pfn_to_mfn_table[n],
   3.561 +                            test_bit(n,to_send),
   3.562 +                            live_mfn_to_pfn_table[live_pfn_to_mfn_table[n]&
   3.563 +                                                 0xFFFFF]);
   3.564  
   3.565 -		if(0 && debug)
   3.566 -		    fprintf(stderr,"%d pfn= %08lx mfn= %08lx %d   [mfn]= %08lx\n",
   3.567 -			    iter, n, live_pfn_to_mfn_table[n],
   3.568 -			    test_bit(n,to_send),
   3.569 -			    live_mfn_to_pfn_table[live_pfn_to_mfn_table[n]&0xFFFFF]);
   3.570 -
   3.571 -		if (!last_iter && test_bit(n, to_send) && test_bit(n, to_skip))
   3.572 -		    skip_this_iter++; // stats keeping
   3.573 +                if ( !last_iter && 
   3.574 +                     test_bit(n, to_send) && 
   3.575 +                     test_bit(n, to_skip) )
   3.576 +                    skip_this_iter++; /* stats keeping */
   3.577  
   3.578 -		if (! ( (test_bit(n, to_send) && !test_bit(n, to_skip)) ||
   3.579 -			(test_bit(n, to_send) && last_iter) ||
   3.580 -			(test_bit(n, to_fix)  && last_iter) )   )
   3.581 -		    continue;
   3.582 +                if ( !((test_bit(n, to_send) && !test_bit(n, to_skip)) ||
   3.583 +                       (test_bit(n, to_send) && last_iter) ||
   3.584 +                       (test_bit(n, to_fix)  && last_iter)) )
   3.585 +                    continue;
   3.586  
   3.587 -		/* we get here if:
   3.588 -		   1. page is marked to_send & hasn't already been re-dirtied
   3.589 -		   2. (ignore to_skip in last iteration)
   3.590 -		   3. add in pages that still need fixup (net bufs)
   3.591 -		 */
   3.592 -		
   3.593 -		pfn_batch[batch] = n;
   3.594 -		pfn_type[batch] = live_pfn_to_mfn_table[n];
   3.595 +                /* we get here if:
   3.596 +                   1. page is marked to_send & hasn't already been re-dirtied
   3.597 +                   2. (ignore to_skip in last iteration)
   3.598 +                   3. add in pages that still need fixup (net bufs)
   3.599 +                */
   3.600 +  
   3.601 +                pfn_batch[batch] = n;
   3.602 +                pfn_type[batch] = live_pfn_to_mfn_table[n];
   3.603  
   3.604 -		if( pfn_type[batch] == 0x80000004 )
   3.605 -		{
   3.606 -		    /* not currently in pusedo-physical map -- set bit
   3.607 -		       in to_fix that we must send this page in last_iter
   3.608 -		       unless its sent sooner anyhow */
   3.609 +                if( pfn_type[batch] == 0x80000004 )
   3.610 +                {
   3.611 +                    /* not currently in pusedo-physical map -- set bit
   3.612 +                       in to_fix that we must send this page in last_iter
   3.613 +                       unless its sent sooner anyhow */
   3.614  
   3.615 -		    set_bit( n, to_fix );
   3.616 -		    if( iter>1 )
   3.617 -			DDPRINTF("Urk! netbuf race: iter %d, pfn %lx. mfn %lx\n",
   3.618 -			       iter,n,pfn_type[batch]);
   3.619 -		    continue;
   3.620 -		}
   3.621 +                    set_bit( n, to_fix );
   3.622 +                    if( iter>1 )
   3.623 +                        DDPRINTF("netbuf race: iter %d, pfn %lx. mfn %lx\n",
   3.624 +                                 iter,n,pfn_type[batch]);
   3.625 +                    continue;
   3.626 +                }
   3.627  
   3.628 -		if ( last_iter && test_bit(n, to_fix ) && !test_bit(n, to_send ))
   3.629 -		{
   3.630 -		    needed_to_fix++;
   3.631 -		    DPRINTF("Fix! iter %d, pfn %lx. mfn %lx\n",
   3.632 -			       iter,n,pfn_type[batch]);
   3.633 -		}
   3.634 +                if ( last_iter && 
   3.635 +                     test_bit(n, to_fix) && 
   3.636 +                     !test_bit(n, to_send) )
   3.637 +                {
   3.638 +                    needed_to_fix++;
   3.639 +                    DPRINTF("Fix! iter %d, pfn %lx. mfn %lx\n",
   3.640 +                            iter,n,pfn_type[batch]);
   3.641 +                }
   3.642  
   3.643 -		clear_bit( n, to_fix ); 
   3.644 +                clear_bit(n, to_fix); 
   3.645  
   3.646 -		batch++;
   3.647 -	    }
   3.648 -	    
   3.649 -	    DDPRINTF("batch %d:%d (n=%d)\n",iter,batch,n);
   3.650 +                batch++;
   3.651 +            }
   3.652 +     
   3.653 +            DDPRINTF("batch %d:%d (n=%d)\n", iter, batch, n);
   3.654  
   3.655 -	    if(batch == 0) goto skip; // vanishingly unlikely...
   3.656 - 	    
   3.657 -	    if ( (region_base = mfn_mapper_map_batch( xc_handle, domid, 
   3.658 -						      PROT_READ,
   3.659 -						      pfn_type,
   3.660 -						      batch )) == 0)
   3.661 -	    {
   3.662 -		PERROR("map batch failed");
   3.663 -		goto out;
   3.664 -	    }
   3.665 -	    
   3.666 -	    if ( get_pfn_type_batch(xc_handle, domid, batch, pfn_type) )
   3.667 -	    {
   3.668 -		ERROR("get_pfn_type_batch failed");
   3.669 -		goto out;
   3.670 -	    }
   3.671 -	    
   3.672 -	    for( j = 0; j < batch; j++ )
   3.673 -	    {
   3.674 -		if( (pfn_type[j] & LTAB_MASK) == XTAB)
   3.675 -		{
   3.676 -		    DDPRINTF("type fail: page %i mfn %08lx\n",j,pfn_type[j]);
   3.677 -		    continue;
   3.678 -		}
   3.679 -		
   3.680 -		if(0 && debug)
   3.681 -		    fprintf(stderr,"%d pfn= %08lx mfn= %08lx [mfn]= %08lx sum= %08lx\n",
   3.682 -			    iter, 
   3.683 -			    (pfn_type[j] & LTAB_MASK) | pfn_batch[j],
   3.684 -			    pfn_type[j],
   3.685 -			    live_mfn_to_pfn_table[pfn_type[j]&(~LTAB_MASK)],
   3.686 -			    csum_page(region_base + (PAGE_SIZE*j))
   3.687 -			);
   3.688 +            if ( batch == 0 )
   3.689 +                goto skip; /* vanishingly unlikely... */
   3.690 +      
   3.691 +            if ( (region_base = mfn_mapper_map_batch(xc_handle, domid, 
   3.692 +                                                     PROT_READ,
   3.693 +                                                     pfn_type,
   3.694 +                                                     batch)) == 0 )
   3.695 +            {
   3.696 +                PERROR("map batch failed");
   3.697 +                goto out;
   3.698 +            }
   3.699 +     
   3.700 +            if ( get_pfn_type_batch(xc_handle, domid, batch, pfn_type) )
   3.701 +            {
   3.702 +                ERROR("get_pfn_type_batch failed");
   3.703 +                goto out;
   3.704 +            }
   3.705 +     
   3.706 +            for ( j = 0; j < batch; j++ )
   3.707 +            {
   3.708 +                if ( (pfn_type[j] & LTAB_MASK) == XTAB )
   3.709 +                {
   3.710 +                    DDPRINTF("type fail: page %i mfn %08lx\n",j,pfn_type[j]);
   3.711 +                    continue;
   3.712 +                }
   3.713 +  
   3.714 +                if ( 0 && debug )
   3.715 +                    fprintf(stderr, "%d pfn= %08lx mfn= %08lx [mfn]= %08lx"
   3.716 +                            " sum= %08lx\n",
   3.717 +                            iter, 
   3.718 +                            (pfn_type[j] & LTAB_MASK) | pfn_batch[j],
   3.719 +                            pfn_type[j],
   3.720 +                            live_mfn_to_pfn_table[pfn_type[j]&(~LTAB_MASK)],
   3.721 +                            csum_page(region_base + (PAGE_SIZE*j)));
   3.722  
   3.723 -		/* canonicalise mfn->pfn */
   3.724 -		pfn_type[j] = (pfn_type[j] & LTAB_MASK) |
   3.725 -		    pfn_batch[j];
   3.726 -		//live_mfn_to_pfn_table[pfn_type[j]&~LTAB_MASK];
   3.727 -
   3.728 -	    }
   3.729 +                /* canonicalise mfn->pfn */
   3.730 +                pfn_type[j] = (pfn_type[j] & LTAB_MASK) | pfn_batch[j];
   3.731 +            }
   3.732  
   3.733 -	    
   3.734 -	    if ( (*writerfn)(writerst, &batch, sizeof(int) ) )
   3.735 -	    {
   3.736 -		ERROR("Error when writing to state file (2)");
   3.737 -		goto out;
   3.738 -	    }
   3.739 +            if ( (*writerfn)(writerst, &batch, sizeof(int) ) )
   3.740 +            {
   3.741 +                ERROR("Error when writing to state file (2)");
   3.742 +                goto out;
   3.743 +            }
   3.744  
   3.745 -	    if ( (*writerfn)(writerst, pfn_type, sizeof(unsigned long)*j ) )
   3.746 -	    {
   3.747 -		ERROR("Error when writing to state file (3)");
   3.748 -		goto out;
   3.749 -	    }
   3.750 -	    
   3.751 -	    /* entering this loop, pfn_type is now in pfns (Not mfns) */
   3.752 -	    for( j = 0; j < batch; j++ )
   3.753 -	    {
   3.754 -		/* write out pages in batch */
   3.755 -		
   3.756 -		if( (pfn_type[j] & LTAB_MASK) == XTAB)
   3.757 -		{
   3.758 -		    DDPRINTF("SKIP BOGUS page %i mfn %08lx\n",j,pfn_type[j]);
   3.759 -		    continue;
   3.760 -		}
   3.761 -		
   3.762 -		if ( ((pfn_type[j] & LTAB_MASK) == L1TAB) || 
   3.763 -		     ((pfn_type[j] & LTAB_MASK) == L2TAB) )
   3.764 -		{
   3.765 -		    
   3.766 -		    memcpy(page, region_base + (PAGE_SIZE*j), PAGE_SIZE);
   3.767 -		    
   3.768 -		    for ( k = 0; 
   3.769 -			  k < (((pfn_type[j] & LTAB_MASK) == L2TAB) ? 
   3.770 -		       (HYPERVISOR_VIRT_START >> L2_PAGETABLE_SHIFT) : 1024); 
   3.771 -			  k++ )
   3.772 -		    {
   3.773 -			unsigned long pfn;
   3.774 +            if ( (*writerfn)(writerst, pfn_type, sizeof(unsigned long)*j ) )
   3.775 +            {
   3.776 +                ERROR("Error when writing to state file (3)");
   3.777 +                goto out;
   3.778 +            }
   3.779 +     
   3.780 +            /* entering this loop, pfn_type is now in pfns (Not mfns) */
   3.781 +            for( j = 0; j < batch; j++ )
   3.782 +            {
   3.783 +                /* write out pages in batch */
   3.784 +                if( (pfn_type[j] & LTAB_MASK) == XTAB)
   3.785 +                {
   3.786 +                    DDPRINTF("SKIP BOGUS page %i mfn %08lx\n",j,pfn_type[j]);
   3.787 +                    continue;
   3.788 +                }
   3.789 +  
   3.790 +                if ( ((pfn_type[j] & LTAB_MASK) == L1TAB) || 
   3.791 +                     ((pfn_type[j] & LTAB_MASK) == L2TAB) )
   3.792 +                {
   3.793 +                    memcpy(page, region_base + (PAGE_SIZE*j), PAGE_SIZE);
   3.794 +      
   3.795 +                    for ( k = 0; 
   3.796 +                          k < (((pfn_type[j] & LTAB_MASK) == L2TAB) ? 
   3.797 +                               (HYPERVISOR_VIRT_START >> L2_PAGETABLE_SHIFT) :
   3.798 +                               1024); 
   3.799 +                          k++ )
   3.800 +                    {
   3.801 +                        unsigned long pfn;
   3.802  
   3.803 -			if ( !(page[k] & _PAGE_PRESENT) ) continue;
   3.804 -			mfn = page[k] >> PAGE_SHIFT;		    
   3.805 -			pfn = live_mfn_to_pfn_table[mfn];
   3.806 -
   3.807 -			if ( !MFN_IS_IN_PSEUDOPHYS_MAP(mfn) )
   3.808 -			{
   3.809 -			    // I don't think this should ever happen
   3.810 +                        if ( !(page[k] & _PAGE_PRESENT) )
   3.811 +                            continue;
   3.812 +                        
   3.813 +                        mfn = page[k] >> PAGE_SHIFT;      
   3.814 +                        pfn = live_mfn_to_pfn_table[mfn];
   3.815  
   3.816 -			    printf("FNI %d : [%08lx,%d] pte=%08lx, mfn=%08lx, pfn=%08lx [mfn]=%08lx\n",
   3.817 -				   j, pfn_type[j], k,
   3.818 -				   page[k], mfn, live_mfn_to_pfn_table[mfn],
   3.819 -				   (live_mfn_to_pfn_table[mfn]<nr_pfns)? 
   3.820 -				   live_pfn_to_mfn_table[live_mfn_to_pfn_table[mfn]]: 0xdeadbeef);
   3.821 +                        if ( !MFN_IS_IN_PSEUDOPHYS_MAP(mfn) )
   3.822 +                        {
   3.823 +                            /* I don't think this should ever happen */
   3.824 +                            printf("FNI %d : [%08lx,%d] pte=%08lx, "
   3.825 +                                   "mfn=%08lx, pfn=%08lx [mfn]=%08lx\n",
   3.826 +                                   j, pfn_type[j], k,
   3.827 +                                   page[k], mfn, live_mfn_to_pfn_table[mfn],
   3.828 +                                   (live_mfn_to_pfn_table[mfn]<nr_pfns)? 
   3.829 +                                   live_pfn_to_mfn_table[
   3.830 +                                       live_mfn_to_pfn_table[mfn]] : 
   3.831 +                                   0xdeadbeef);
   3.832  
   3.833 -			    pfn = 0; // be suspicious, very suspicious
   3.834 -			    
   3.835 -			    //goto out;  // let's try our luck
   3.836 -
   3.837 +                            pfn = 0; /* be suspicious */
   3.838 +                        }
   3.839  
   3.840 -			}
   3.841 -			page[k] &= PAGE_SIZE - 1;
   3.842 -			page[k] |= pfn << PAGE_SHIFT;
   3.843 -			
   3.844 +                        page[k] &= PAGE_SIZE - 1;
   3.845 +                        page[k] |= pfn << PAGE_SHIFT;
   3.846 +   
   3.847  #if 0
   3.848 -			printf("L%d i=%d pfn=%d mfn=%d k=%d pte=%08lx xpfn=%d\n",
   3.849 -			       pfn_type[j]>>28,
   3.850 -			       j,i,mfn,k,page[k],page[k]>>PAGE_SHIFT);
   3.851 -#endif			  
   3.852 -			
   3.853 -		    } /* end of page table rewrite for loop */
   3.854 -		    
   3.855 -		    if ( (*writerfn)(writerst, page, PAGE_SIZE) )
   3.856 -		    {
   3.857 -			ERROR("Error when writing to state file (4)");
   3.858 -			goto out;
   3.859 -		    }
   3.860 -		    
   3.861 -		}  /* end of it's a PT page */
   3.862 -		else
   3.863 -		{  /* normal page */
   3.864 +                        printf("L%d i=%d pfn=%d mfn=%d k=%d pte=%08lx "
   3.865 +                               "xpfn=%d\n",
   3.866 +                               pfn_type[j]>>28,
   3.867 +                               j,i,mfn,k,page[k],page[k]>>PAGE_SHIFT);
   3.868 +#endif     
   3.869 +   
   3.870 +                    } /* end of page table rewrite for loop */
   3.871 +      
   3.872 +                    if ( (*writerfn)(writerst, page, PAGE_SIZE) )
   3.873 +                    {
   3.874 +                        ERROR("Error when writing to state file (4)");
   3.875 +                        goto out;
   3.876 +                    }
   3.877 +      
   3.878 +                }  /* end of it's a PT page */
   3.879 +                else
   3.880 +                {  /* normal page */
   3.881  
   3.882 -		    if ( (*writerfn)(writerst, region_base + (PAGE_SIZE*j), PAGE_SIZE) )
   3.883 -		    {
   3.884 -			ERROR("Error when writing to state file (5)");
   3.885 -			goto out;
   3.886 -		    }
   3.887 -		}
   3.888 -	    } /* end of the write out for this batch */
   3.889 -	    
   3.890 -	    sent_this_iter += batch;
   3.891 +                    if ( (*writerfn)(writerst, region_base + (PAGE_SIZE*j),
   3.892 +                                     PAGE_SIZE) )
   3.893 +                    {
   3.894 +                        ERROR("Error when writing to state file (5)");
   3.895 +                        goto out;
   3.896 +                    }
   3.897 +                }
   3.898 +            } /* end of the write out for this batch */
   3.899 +     
   3.900 +            sent_this_iter += batch;
   3.901  
   3.902 -	} /* end of this while loop for this iteration */
   3.903 +        } /* end of this while loop for this iteration */
   3.904  
   3.905 -	munmap(region_base, batch*PAGE_SIZE);
   3.906 +        munmap(region_base, batch*PAGE_SIZE);
   3.907  
   3.908      skip: 
   3.909  
   3.910 -	total_sent += sent_this_iter;
   3.911 +        total_sent += sent_this_iter;
   3.912  
   3.913 -	verbose_printf("\r %d: sent %d, skipped %d, ", 
   3.914 -		       iter, sent_this_iter, skip_this_iter );
   3.915 +        verbose_printf("\r %d: sent %d, skipped %d, ", 
   3.916 +                       iter, sent_this_iter, skip_this_iter );
   3.917  
   3.918 -	if ( last_iter )
   3.919 -	{
   3.920 -	    print_stats( xc_handle, domid, sent_this_iter, &stats, 1);
   3.921 +        if ( last_iter )
   3.922 +        {
   3.923 +            print_stats( xc_handle, domid, sent_this_iter, &stats, 1);
   3.924  
   3.925 -	    verbose_printf("Total pages sent= %d (%.2fx)\n", 
   3.926 -			   total_sent, ((float)total_sent)/nr_pfns );
   3.927 -	    verbose_printf("(of which %d were fixups)\n", needed_to_fix  );
   3.928 -	}       
   3.929 +            verbose_printf("Total pages sent= %d (%.2fx)\n", 
   3.930 +                           total_sent, ((float)total_sent)/nr_pfns );
   3.931 +            verbose_printf("(of which %d were fixups)\n", needed_to_fix  );
   3.932 +        }       
   3.933  
   3.934 -	if ( debug && last_iter )
   3.935 -	{
   3.936 -	    int minusone = -1;
   3.937 -	    memset( to_send, 0xff, (nr_pfns+8)/8 );
   3.938 -	    debug = 0;
   3.939 -	    printf("Entering debug resend-all mode\n");
   3.940 +        if ( debug && last_iter )
   3.941 +        {
   3.942 +            int minusone = -1;
   3.943 +            memset( to_send, 0xff, (nr_pfns+8)/8 );
   3.944 +            debug = 0;
   3.945 +            printf("Entering debug resend-all mode\n");
   3.946      
   3.947 -	    /* send "-1" to put receiver into debug mode */
   3.948 -	    if ( (*writerfn)(writerst, &minusone, sizeof(int)) )
   3.949 -	    {
   3.950 -		ERROR("Error when writing to state file (6)");
   3.951 -		goto out;
   3.952 -	    }
   3.953 +            /* send "-1" to put receiver into debug mode */
   3.954 +            if ( (*writerfn)(writerst, &minusone, sizeof(int)) )
   3.955 +            {
   3.956 +                ERROR("Error when writing to state file (6)");
   3.957 +                goto out;
   3.958 +            }
   3.959  
   3.960 -	    continue;
   3.961 -	}
   3.962 +            continue;
   3.963 +        }
   3.964  
   3.965 -	if ( last_iter )
   3.966 -	    break;
   3.967 +        if ( last_iter )
   3.968 +            break;
   3.969  
   3.970 -	if ( live )
   3.971 -	{
   3.972 -	    if ( 
   3.973 -		 // ( sent_this_iter > (sent_last_iter * 0.95) ) ||		 
   3.974 -		 (iter >= max_iters) || 
   3.975 -		 (sent_this_iter+skip_this_iter < 50) || 
   3.976 -		 (total_sent > nr_pfns*max_factor) )
   3.977 -	    {
   3.978 -		DPRINTF("Start last iteration\n");
   3.979 -		last_iter = 1;
   3.980 -
   3.981 -		xc_domain_pause( xc_handle, domid );
   3.982 +        if ( live )
   3.983 +        {
   3.984 +            if ( 
   3.985 +                /* ( sent_this_iter > (sent_last_iter * 0.95) ) || */
   3.986 +                (iter >= max_iters) || 
   3.987 +                (sent_this_iter+skip_this_iter < 50) || 
   3.988 +                (total_sent > nr_pfns*max_factor) )
   3.989 +            {
   3.990 +                DPRINTF("Start last iteration\n");
   3.991 +                last_iter = 1;
   3.992  
   3.993 -	    } 
   3.994 +                xc_domain_pause( xc_handle, domid );
   3.995 +            } 
   3.996  
   3.997 -	    if ( xc_shadow_control( xc_handle, domid, 
   3.998 -				    DOM0_SHADOW_CONTROL_OP_CLEAN2,
   3.999 -				    to_send, nr_pfns, &stats ) != nr_pfns ) 
  3.1000 -	    {
  3.1001 -		ERROR("Error flushing shadow PT");
  3.1002 -		goto out;
  3.1003 -	    }
  3.1004 +            if ( xc_shadow_control( xc_handle, domid, 
  3.1005 +                                    DOM0_SHADOW_CONTROL_OP_CLEAN2,
  3.1006 +                                    to_send, nr_pfns, &stats ) != nr_pfns ) 
  3.1007 +            {
  3.1008 +                ERROR("Error flushing shadow PT");
  3.1009 +                goto out;
  3.1010 +            }
  3.1011  
  3.1012 -	    sent_last_iter = sent_this_iter;
  3.1013 +            sent_last_iter = sent_this_iter;
  3.1014  
  3.1015 -	    print_stats( xc_handle, domid, sent_this_iter, &stats, 1);
  3.1016 -	    
  3.1017 -	}
  3.1018 +            print_stats( xc_handle, domid, sent_this_iter, &stats, 1);
  3.1019 +     
  3.1020 +        }
  3.1021  
  3.1022  
  3.1023      } /* end of while 1 */
  3.1024 @@ -839,15 +826,15 @@ int xc_linux_save(int xc_handle,
  3.1025      /* Zero terminate */
  3.1026      if ( (*writerfn)(writerst, &rc, sizeof(int)) )
  3.1027      {
  3.1028 -	ERROR("Error when writing to state file (6)");
  3.1029 -	goto out;
  3.1030 +        ERROR("Error when writing to state file (6)");
  3.1031 +        goto out;
  3.1032      }
  3.1033  
  3.1034      /* Get the final execution context */
  3.1035      if ( xc_domain_getfullinfo( xc_handle, domid, &op, &ctxt) )
  3.1036      {
  3.1037 -	PERROR("Could not get full domain info");
  3.1038 -	goto out;
  3.1039 +        PERROR("Could not get full domain info");
  3.1040 +        goto out;
  3.1041      }
  3.1042  
  3.1043      /* Canonicalise the suspend-record frame number. */
  3.1044 @@ -873,17 +860,18 @@ int xc_linux_save(int xc_handle,
  3.1045          ERROR("PT base is not in range of pseudophys map");
  3.1046          goto out;
  3.1047      }
  3.1048 -    ctxt.pt_base = live_mfn_to_pfn_table[ctxt.pt_base >> PAGE_SHIFT] << PAGE_SHIFT;
  3.1049 +    ctxt.pt_base = live_mfn_to_pfn_table[ctxt.pt_base >> PAGE_SHIFT] <<
  3.1050 +        PAGE_SHIFT;
  3.1051  
  3.1052 -    if ( (*writerfn)(writerst, &ctxt,                 sizeof(ctxt)) ||
  3.1053 -         (*writerfn)(writerst, live_shinfo,           PAGE_SIZE) )
  3.1054 +    if ( (*writerfn)(writerst, &ctxt,       sizeof(ctxt)) ||
  3.1055 +         (*writerfn)(writerst, live_shinfo, PAGE_SIZE) )
  3.1056      {
  3.1057          ERROR("Error when writing to state file (1)");
  3.1058          goto out;
  3.1059      }
  3.1060      munmap(live_shinfo, PAGE_SIZE);
  3.1061  
  3.1062 -out:
  3.1063 + out:
  3.1064  
  3.1065      if ( pfn_type != NULL )
  3.1066          free(pfn_type);
     4.1 --- a/tools/xc/py/Xc.c	Fri Jun 25 21:56:38 2004 +0000
     4.2 +++ b/tools/xc/py/Xc.c	Sat Jun 26 16:41:33 2004 +0000
     4.3 @@ -521,7 +521,7 @@ static PyObject *pyxc_linux_build(PyObje
     4.4  
     4.5      static char *kwd_list[] = { "dom", "control_evtchn", 
     4.6                                  "image", "ramdisk", "cmdline", "flags",
     4.7 -				NULL };
     4.8 +                                NULL };
     4.9  
    4.10      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iis|ssi", kwd_list, 
    4.11                                        &dom, &control_evtchn,