ia64/xen-unstable

changeset 1336:75286d976ac6

bitkeeper revision 1.884 (4094408eiFBLnUCY6YdJfald4yk6bw)

Restore now uses fast mapper interface.
author iap10@labyrinth.cl.cam.ac.uk
date Sun May 02 00:27:58 2004 +0000 (2004-05-02)
parents 99a0fa51b992
children b4a9837c89b1
files tools/xc/lib/xc_linux_restore.c
line diff
     1.1 --- a/tools/xc/lib/xc_linux_restore.c	Sat May 01 22:14:05 2004 +0000
     1.2 +++ b/tools/xc/lib/xc_linux_restore.c	Sun May 02 00:27:58 2004 +0000
     1.3 @@ -10,6 +10,8 @@
     1.4  #include <asm-xen/suspend.h>
     1.5  #include <zlib.h>
     1.6  
     1.7 +#define MAX_BATCH_SIZE 1024
     1.8 +
     1.9  /* This may allow us to create a 'quiet' command-line option, if necessary. */
    1.10  #define verbose_printf(_f, _a...) \
    1.11      do {                          \
    1.12 @@ -93,6 +95,9 @@ int xc_linux_restore(int xc_handle,
    1.13      /* A temporary mapping of the guest's suspend record. */
    1.14      suspend_record_t *p_srec;
    1.15  
    1.16 +    mfn_mapper_t *region_mapper, *mapper_handle1;
    1.17 +    char *region_base;
    1.18 +
    1.19      /* The name and descriptor of the file that we are reading from. */
    1.20      int    fd;
    1.21      gzFile gfd;
    1.22 @@ -215,6 +220,15 @@ int xc_linux_restore(int xc_handle,
    1.23          goto out;
    1.24      }
    1.25  
    1.26 +
    1.27 +    if ( (region_mapper = mfn_mapper_init(xc_handle, dom,
    1.28 +					  MAX_BATCH_SIZE*PAGE_SIZE, 
    1.29 +					  PROT_WRITE )) 
    1.30 +	 == NULL )
    1.31 +        goto out;
    1.32 +
    1.33 +    region_base = mfn_mapper_base( region_mapper );
    1.34 +
    1.35      verbose_printf("Reloading memory pages:   0%%");
    1.36  
    1.37      /*
    1.38 @@ -242,7 +256,7 @@ int xc_linux_restore(int xc_handle,
    1.39              goto out;
    1.40          }
    1.41  
    1.42 -	printf("batch=%d\n",j);
    1.43 +	//printf("batch=%d\n",j);
    1.44  	
    1.45  	if(j==0) break;  // our work here is done
    1.46  	
    1.47 @@ -255,6 +269,24 @@ int xc_linux_restore(int xc_handle,
    1.48  	for(i=0;i<j;i++)
    1.49  	{
    1.50  	    pfn = region_pfn_type[i] & ~PGT_type_mask;
    1.51 +	    mfn = pfn_to_mfn_table[pfn];
    1.52 +	    
    1.53 +	    mfn_mapper_queue_entry( region_mapper, i<<PAGE_SHIFT, 
    1.54 +				    mfn, PAGE_SIZE );
    1.55 +	}
    1.56 +
    1.57 +	if( mfn_mapper_flush_queue(region_mapper) )
    1.58 +	{
    1.59 +	    ERROR("Couldn't map page region");
    1.60 +	    goto out;
    1.61 +	}
    1.62 +
    1.63 +
    1.64 +	for(i=0;i<j;i++)
    1.65 +	{
    1.66 +	    unsigned long *ppage;
    1.67 +
    1.68 +	    pfn = region_pfn_type[i] & ~PGT_type_mask;
    1.69  	    	  	    
    1.70  //if(pfn_type[i])printf("^pfn=%d %08lx\n",pfn,pfn_type[i]);
    1.71  
    1.72 @@ -270,9 +302,9 @@ int xc_linux_restore(int xc_handle,
    1.73  
    1.74  	    mfn = pfn_to_mfn_table[pfn];
    1.75  
    1.76 -if(region_pfn_type[i])printf("i=%d pfn=%d mfn=%d type=%lx\n",i,pfn,mfn,region_pfn_type[i]);
    1.77 +//if(region_pfn_type[i])printf("i=%d pfn=%d mfn=%d type=%lx\n",i,pfn,mfn,region_pfn_type[i]);
    1.78  
    1.79 -	    ppage = map_pfn_writeable(pm_handle, mfn);
    1.80 +            ppage = (unsigned long*) (region_base + i*PAGE_SIZE);
    1.81  
    1.82  	    if ( !checked_read(gfd, ppage, PAGE_SIZE) )
    1.83  	    {
    1.84 @@ -327,16 +359,18 @@ if(region_pfn_type[i])printf("i=%d pfn=%
    1.85  		}
    1.86  	    }
    1.87  
    1.88 -	    unmap_pfn(pm_handle, ppage);
    1.89 -
    1.90  	    if ( add_mmu_update(xc_handle, mmu,
    1.91  				(mfn<<PAGE_SHIFT) | MMU_MACHPHYS_UPDATE, pfn) )
    1.92  		goto out;
    1.93  
    1.94  	}
    1.95  
    1.96 +	n+=j; // crude stats
    1.97 +
    1.98      }
    1.99  
   1.100 +    mfn_mapper_close( region_mapper );
   1.101 +
   1.102      /*
   1.103       * Pin page tables. Do this after writing to them as otherwise Xen
   1.104       * will barf when doing the type-checking.
   1.105 @@ -409,20 +443,39 @@ if(region_pfn_type[i])printf("i=%d pfn=%
   1.106      ctxt.pt_base = pfn_to_mfn_table[pfn] << PAGE_SHIFT;
   1.107  
   1.108      /* Uncanonicalise the pfn-to-mfn table frame-number list. */
   1.109 -    for ( i = 0; i < nr_pfns; i += 1024 )
   1.110 +
   1.111 +
   1.112 +    if ( (mapper_handle1 = mfn_mapper_init(xc_handle, dom,
   1.113 +					   1024*1024, PROT_WRITE )) 
   1.114 +	 == NULL )
   1.115 +        goto out;
   1.116 +	
   1.117 +    for ( i = 0; i < (nr_pfns+1023)/1024; i++ )
   1.118      {
   1.119 -        unsigned long copy_size = (nr_pfns - i) * sizeof(unsigned long);
   1.120 -        if ( copy_size > PAGE_SIZE ) copy_size = PAGE_SIZE;
   1.121 -        pfn = pfn_to_mfn_frame_list[i/1024];
   1.122 +	unsigned long pfn, mfn;
   1.123 +
   1.124 +        pfn = pfn_to_mfn_frame_list[i];
   1.125          if ( (pfn >= nr_pfns) || (pfn_type[pfn] != NONE) )
   1.126          {
   1.127              ERROR("PFN-to-MFN frame number is bad");
   1.128              goto out;
   1.129          }
   1.130 -        ppage = map_pfn_writeable(pm_handle, pfn_to_mfn_table[pfn]);
   1.131 -        memcpy(ppage, &pfn_to_mfn_table[i], copy_size);        
   1.132 -        unmap_pfn(pm_handle, ppage);
   1.133 +	mfn = pfn_to_mfn_table[pfn];
   1.134 +
   1.135 +	mfn_mapper_queue_entry( mapper_handle1, i<<PAGE_SHIFT, 
   1.136 +				mfn, PAGE_SIZE );
   1.137      }
   1.138 +    
   1.139 +    if ( mfn_mapper_flush_queue(mapper_handle1) )
   1.140 +    {
   1.141 +        ERROR("Couldn't map pfn_to_mfn table");
   1.142 +        goto out;
   1.143 +    }
   1.144 +
   1.145 +    memcpy( mfn_mapper_base( mapper_handle1 ), pfn_to_mfn_table, 
   1.146 +	    nr_pfns*sizeof(unsigned long) );
   1.147 +
   1.148 +    mfn_mapper_close( mapper_handle1 );
   1.149  
   1.150      /*
   1.151       * Safety checking of saved context: