ia64/xen-unstable

changeset 18976:2a8ae362a828

PoD memory 8/9: libxc interface

Implement libxc interface to PoD functionality:
* Add xc_hvm_build_target_mem(), which takes both memsize and target.
Memsize is the total memory, allocated in PoD pages and reported in
the e820; target is the size of the cache. If these are the same, the
normal funcitonality is called. (So you can use the same function to
build always, and it will decide whether to use PoD or not.)
* Add xc_domain_memory_[gs]et_pod_target(), which sets and/or returns
information about the PoD cache and p2m entries.

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Jan 05 10:46:37 2009 +0000 (2009-01-05)
parents 2090917489c5
children 5b44cfde9666
files tools/libxc/xc_domain.c tools/libxc/xc_hvm_build.c tools/libxc/xc_private.c tools/libxc/xenctrl.h tools/libxc/xenguest.h
line diff
     1.1 --- a/tools/libxc/xc_domain.c	Mon Jan 05 10:45:48 2009 +0000
     1.2 +++ b/tools/libxc/xc_domain.c	Mon Jan 05 10:46:37 2009 +0000
     1.3 @@ -564,6 +564,76 @@ int xc_domain_memory_translate_gpfn_list
     1.4      return err;
     1.5  }
     1.6  
     1.7 +static int xc_domain_memory_pod_target(int xc_handle,
     1.8 +                                       int op,
     1.9 +                                       uint32_t domid,
    1.10 +                                       uint64_t target_pages,
    1.11 +                                       uint64_t *tot_pages,
    1.12 +                                       uint64_t *pod_cache_pages,
    1.13 +                                       uint64_t *pod_entries)
    1.14 +{
    1.15 +    int err;
    1.16 +
    1.17 +    struct xen_pod_target pod_target = {
    1.18 +        .domid = domid,
    1.19 +        .target_pages = target_pages
    1.20 +    };
    1.21 +
    1.22 +    err = xc_memory_op(xc_handle, op, &pod_target);
    1.23 +
    1.24 +    if ( err < 0 )
    1.25 +    {
    1.26 +        DPRINTF("Failed %s_memory_target dom %d\n",
    1.27 +                (op==XENMEM_set_pod_target)?"set":"get",
    1.28 +                domid);
    1.29 +        errno = -err;
    1.30 +        err = -1;
    1.31 +    }
    1.32 +    else
    1.33 +        err = 0;
    1.34 +
    1.35 +    if ( tot_pages )
    1.36 +        *tot_pages = pod_target.tot_pages;
    1.37 +    if ( pod_cache_pages )
    1.38 +        *pod_cache_pages = pod_target.pod_cache_pages;
    1.39 +    if ( pod_entries )
    1.40 +        *pod_entries = pod_target.pod_entries;
    1.41 +
    1.42 +    return err;
    1.43 +}
    1.44 +                                       
    1.45 +
    1.46 +int xc_domain_memory_set_pod_target(int xc_handle,
    1.47 +                                    uint32_t domid,
    1.48 +                                    uint64_t target_pages,
    1.49 +                                    uint64_t *tot_pages,
    1.50 +                                    uint64_t *pod_cache_pages,
    1.51 +                                    uint64_t *pod_entries)
    1.52 +{
    1.53 +    return xc_domain_memory_pod_target(xc_handle,
    1.54 +                                       XENMEM_set_pod_target,
    1.55 +                                       domid,
    1.56 +                                       target_pages,
    1.57 +                                       tot_pages,
    1.58 +                                       pod_cache_pages,
    1.59 +                                       pod_entries);
    1.60 +}
    1.61 +
    1.62 +int xc_domain_memory_get_pod_target(int xc_handle,
    1.63 +                                    uint32_t domid,
    1.64 +                                    uint64_t *tot_pages,
    1.65 +                                    uint64_t *pod_cache_pages,
    1.66 +                                    uint64_t *pod_entries)
    1.67 +{
    1.68 +    return xc_domain_memory_pod_target(xc_handle,
    1.69 +                                       XENMEM_get_pod_target,
    1.70 +                                       domid,
    1.71 +                                       -1,
    1.72 +                                       tot_pages,
    1.73 +                                       pod_cache_pages,
    1.74 +                                       pod_entries);
    1.75 +}
    1.76 +
    1.77  int xc_domain_max_vcpus(int xc_handle, uint32_t domid, unsigned int max)
    1.78  {
    1.79      DECLARE_DOMCTL;
     2.1 --- a/tools/libxc/xc_hvm_build.c	Mon Jan 05 10:45:48 2009 +0000
     2.2 +++ b/tools/libxc/xc_hvm_build.c	Mon Jan 05 10:46:37 2009 +0000
     2.3 @@ -146,11 +146,13 @@ static int loadelfimage(
     2.4  }
     2.5  
     2.6  static int setup_guest(int xc_handle,
     2.7 -                       uint32_t dom, int memsize,
     2.8 +                       uint32_t dom, int memsize, int target,
     2.9                         char *image, unsigned long image_size)
    2.10  {
    2.11      xen_pfn_t *page_array = NULL;
    2.12      unsigned long i, nr_pages = (unsigned long)memsize << (20 - PAGE_SHIFT);
    2.13 +    unsigned long target_pages = (unsigned long)target << (20 - PAGE_SHIFT);
    2.14 +    unsigned long pod_pages = 0;
    2.15      unsigned long special_page_nr, entry_eip, cur_pages;
    2.16      struct xen_add_to_physmap xatp;
    2.17      struct shared_info *shared_info;
    2.18 @@ -160,11 +162,16 @@ static int setup_guest(int xc_handle,
    2.19      uint64_t v_start, v_end;
    2.20      int rc;
    2.21      xen_capabilities_info_t caps;
    2.22 +    int pod_mode = 0;
    2.23 +    
    2.24  
    2.25      /* An HVM guest must be initialised with at least 2MB memory. */
    2.26 -    if ( memsize < 2 )
    2.27 +    if ( memsize < 2 || target < 2 )
    2.28          goto error_out;
    2.29  
    2.30 +    if ( memsize > target )
    2.31 +        pod_mode = 1;
    2.32 +
    2.33      if ( elf_init(&elf, image, image_size) != 0 )
    2.34          goto error_out;
    2.35      elf_parse_binary(&elf);
    2.36 @@ -235,6 +242,10 @@ static int setup_guest(int xc_handle,
    2.37                  .extent_order = SUPERPAGE_PFN_SHIFT,
    2.38                  .domid        = dom
    2.39              };
    2.40 +
    2.41 +            if ( pod_mode )
    2.42 +                sp_req.mem_flags = XENMEMF_populate_on_demand;
    2.43 +
    2.44              set_xen_guest_handle(sp_req.extent_start, sp_extents);
    2.45              for ( i = 0; i < sp_req.nr_extents; i++ )
    2.46                  sp_extents[i] = page_array[cur_pages+(i<<SUPERPAGE_PFN_SHIFT)];
    2.47 @@ -242,6 +253,11 @@ static int setup_guest(int xc_handle,
    2.48              if ( done > 0 )
    2.49              {
    2.50                  done <<= SUPERPAGE_PFN_SHIFT;
    2.51 +                if ( pod_mode && target_pages > cur_pages )
    2.52 +                {
    2.53 +                    int d = target_pages - cur_pages;
    2.54 +                    pod_pages += ( done < d ) ? done : d;
    2.55 +                }
    2.56                  cur_pages += done;
    2.57                  count -= done;
    2.58              }
    2.59 @@ -253,9 +269,17 @@ static int setup_guest(int xc_handle,
    2.60              rc = xc_domain_memory_populate_physmap(
    2.61                  xc_handle, dom, count, 0, 0, &page_array[cur_pages]);
    2.62              cur_pages += count;
    2.63 +            if ( pod_mode )
    2.64 +                pod_pages -= count;
    2.65          }
    2.66      }
    2.67  
    2.68 +    if ( pod_mode )
    2.69 +        rc = xc_domain_memory_set_pod_target(xc_handle,
    2.70 +                                             dom,
    2.71 +                                             pod_pages,
    2.72 +                                             NULL, NULL, NULL);
    2.73 +
    2.74      if ( rc != 0 )
    2.75      {
    2.76          PERROR("Could not allocate memory for HVM guest.\n");
    2.77 @@ -354,6 +378,7 @@ static int setup_guest(int xc_handle,
    2.78  static int xc_hvm_build_internal(int xc_handle,
    2.79                                   uint32_t domid,
    2.80                                   int memsize,
    2.81 +                                 int target,
    2.82                                   char *image,
    2.83                                   unsigned long image_size)
    2.84  {
    2.85 @@ -363,7 +388,7 @@ static int xc_hvm_build_internal(int xc_
    2.86          return -1;
    2.87      }
    2.88  
    2.89 -    return setup_guest(xc_handle, domid, memsize, image, image_size);
    2.90 +    return setup_guest(xc_handle, domid, memsize, target, image, image_size);
    2.91  }
    2.92  
    2.93  static inline int is_loadable_phdr(Elf32_Phdr *phdr)
    2.94 @@ -388,7 +413,34 @@ int xc_hvm_build(int xc_handle,
    2.95           ((image = xc_read_image(image_name, &image_size)) == NULL) )
    2.96          return -1;
    2.97  
    2.98 -    sts = xc_hvm_build_internal(xc_handle, domid, memsize, image, image_size);
    2.99 +    sts = xc_hvm_build_internal(xc_handle, domid, memsize, memsize, image, image_size);
   2.100 +
   2.101 +    free(image);
   2.102 +
   2.103 +    return sts;
   2.104 +}
   2.105 +
   2.106 +/* xc_hvm_build_target_mem: 
   2.107 + * Create a domain for a pre-ballooned virtualized Linux, using
   2.108 + * files/filenames.  If target < memsize, domain is created with
   2.109 + * memsize pages marked populate-on-demand, and with a PoD cache size
   2.110 + * of target.  If target == memsize, pages are populated normally.
   2.111 + */
   2.112 +int xc_hvm_build_target_mem(int xc_handle,
   2.113 +                           uint32_t domid,
   2.114 +                           int memsize,
   2.115 +                           int target,
   2.116 +                           const char *image_name)
   2.117 +{
   2.118 +    char *image;
   2.119 +    int  sts;
   2.120 +    unsigned long image_size;
   2.121 +
   2.122 +    if ( (image_name == NULL) ||
   2.123 +         ((image = xc_read_image(image_name, &image_size)) == NULL) )
   2.124 +        return -1;
   2.125 +
   2.126 +    sts = xc_hvm_build_internal(xc_handle, domid, memsize, target, image, image_size);
   2.127  
   2.128      free(image);
   2.129  
   2.130 @@ -423,7 +475,7 @@ int xc_hvm_build_mem(int xc_handle,
   2.131          return -1;
   2.132      }
   2.133  
   2.134 -    sts = xc_hvm_build_internal(xc_handle, domid, memsize,
   2.135 +    sts = xc_hvm_build_internal(xc_handle, domid, memsize, memsize,
   2.136                                  img, img_len);
   2.137  
   2.138      /* xc_inflate_buffer may return the original buffer pointer (for
     3.1 --- a/tools/libxc/xc_private.c	Mon Jan 05 10:45:48 2009 +0000
     3.2 +++ b/tools/libxc/xc_private.c	Mon Jan 05 10:46:37 2009 +0000
     3.3 @@ -323,6 +323,14 @@ int xc_memory_op(int xc_handle,
     3.4              goto out1;
     3.5          }
     3.6          break;
     3.7 +    case XENMEM_set_pod_target:
     3.8 +    case XENMEM_get_pod_target:
     3.9 +        if ( lock_pages(arg, sizeof(struct xen_pod_target)) )
    3.10 +        {
    3.11 +            PERROR("Could not lock");
    3.12 +            goto out1;
    3.13 +        }
    3.14 +        break;
    3.15      }
    3.16  
    3.17      ret = do_xen_hypercall(xc_handle, &hypercall);
    3.18 @@ -355,6 +363,10 @@ int xc_memory_op(int xc_handle,
    3.19      case XENMEM_maximum_gpfn:
    3.20          unlock_pages(arg, sizeof(domid_t));
    3.21          break;
    3.22 +    case XENMEM_set_pod_target:
    3.23 +    case XENMEM_get_pod_target:
    3.24 +        unlock_pages(arg, sizeof(struct xen_pod_target));
    3.25 +        break;
    3.26      }
    3.27  
    3.28   out1:
     4.1 --- a/tools/libxc/xenctrl.h	Mon Jan 05 10:45:48 2009 +0000
     4.2 +++ b/tools/libxc/xenctrl.h	Mon Jan 05 10:46:37 2009 +0000
     4.3 @@ -634,6 +634,19 @@ int xc_domain_memory_translate_gpfn_list
     4.4                                           xen_pfn_t *gpfn_list,
     4.5                                           xen_pfn_t *mfn_list);
     4.6  
     4.7 +int xc_domain_memory_set_pod_target(int xc_handle,
     4.8 +                                    uint32_t domid,
     4.9 +                                    uint64_t target_pages,
    4.10 +                                    uint64_t *tot_pages,
    4.11 +                                    uint64_t *pod_cache_pages,
    4.12 +                                    uint64_t *pod_entries);
    4.13 +
    4.14 +int xc_domain_memory_get_pod_target(int xc_handle,
    4.15 +                                    uint32_t domid,
    4.16 +                                    uint64_t *tot_pages,
    4.17 +                                    uint64_t *pod_cache_pages,
    4.18 +                                    uint64_t *pod_entries);
    4.19 +
    4.20  int xc_domain_ioport_permission(int xc_handle,
    4.21                                  uint32_t domid,
    4.22                                  uint32_t first_port,
     5.1 --- a/tools/libxc/xenguest.h	Mon Jan 05 10:45:48 2009 +0000
     5.2 +++ b/tools/libxc/xenguest.h	Mon Jan 05 10:46:37 2009 +0000
     5.3 @@ -130,6 +130,12 @@ int xc_hvm_build(int xc_handle,
     5.4                   int memsize,
     5.5                   const char *image_name);
     5.6  
     5.7 +int xc_hvm_build_target_mem(int xc_handle,
     5.8 +                            uint32_t domid,
     5.9 +                            int memsize,
    5.10 +                            int target,
    5.11 +                            const char *image_name);
    5.12 +
    5.13  int xc_hvm_build_mem(int xc_handle,
    5.14                       uint32_t domid,
    5.15                       int memsize,