Diff for /qemu/xen-mapcache.c between versions 1.1.1.2 and 1.1.1.3

version 1.1.1.2, 2018/04/24 19:16:42 version 1.1.1.3, 2018/04/24 19:33:40
Line 4 Line 4
  * This work is licensed under the terms of the GNU GPL, version 2.  See   * This work is licensed under the terms of the GNU GPL, version 2.  See
  * the COPYING file in the top-level directory.   * the COPYING file in the top-level directory.
  *   *
    * Contributions after 2012-01-13 are licensed under the terms of the
    * GNU GPL, version 2 or (at your option) any later version.
  */   */
   
 #include "config.h"  #include "config.h"
Line 76  typedef struct MapCache { Line 78  typedef struct MapCache {
     uint8_t *last_address_vaddr;      uint8_t *last_address_vaddr;
     unsigned long max_mcache_size;      unsigned long max_mcache_size;
     unsigned int mcache_bucket_shift;      unsigned int mcache_bucket_shift;
   
       phys_offset_to_gaddr_t phys_offset_to_gaddr;
       void *opaque;
 } MapCache;  } MapCache;
   
 static MapCache *mapcache;  static MapCache *mapcache;
Line 89  static inline int test_bits(int nr, int  Line 94  static inline int test_bits(int nr, int 
         return 0;          return 0;
 }  }
   
 void xen_map_cache_init(void)  void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque)
 {  {
     unsigned long size;      unsigned long size;
     struct rlimit rlimit_as;      struct rlimit rlimit_as;
   
     mapcache = g_malloc0(sizeof (MapCache));      mapcache = g_malloc0(sizeof (MapCache));
   
       mapcache->phys_offset_to_gaddr = f;
       mapcache->opaque = opaque;
   
     QTAILQ_INIT(&mapcache->locked_entries);      QTAILQ_INIT(&mapcache->locked_entries);
     mapcache->last_address_index = -1;      mapcache->last_address_index = -1;
   
Line 191  uint8_t *xen_map_cache(target_phys_addr_ Line 199  uint8_t *xen_map_cache(target_phys_addr_
                        uint8_t lock)                         uint8_t lock)
 {  {
     MapCacheEntry *entry, *pentry = NULL;      MapCacheEntry *entry, *pentry = NULL;
     target_phys_addr_t address_index  = phys_addr >> MCACHE_BUCKET_SHIFT;      target_phys_addr_t address_index;
     target_phys_addr_t address_offset = phys_addr & (MCACHE_BUCKET_SIZE - 1);      target_phys_addr_t address_offset;
     target_phys_addr_t __size = size;      target_phys_addr_t __size = size;
       bool translated = false;
   
   tryagain:
       address_index  = phys_addr >> MCACHE_BUCKET_SHIFT;
       address_offset = phys_addr & (MCACHE_BUCKET_SIZE - 1);
   
     trace_xen_map_cache(phys_addr);      trace_xen_map_cache(phys_addr);
   
Line 203  uint8_t *xen_map_cache(target_phys_addr_ Line 216  uint8_t *xen_map_cache(target_phys_addr_
     }      }
   
     /* size is always a multiple of MCACHE_BUCKET_SIZE */      /* size is always a multiple of MCACHE_BUCKET_SIZE */
     if ((address_offset + (__size % MCACHE_BUCKET_SIZE)) > MCACHE_BUCKET_SIZE)      if (size) {
         __size += MCACHE_BUCKET_SIZE;          __size = size + address_offset;
     if (__size % MCACHE_BUCKET_SIZE)          if (__size % MCACHE_BUCKET_SIZE) {
         __size += MCACHE_BUCKET_SIZE - (__size % MCACHE_BUCKET_SIZE);              __size += MCACHE_BUCKET_SIZE - (__size % MCACHE_BUCKET_SIZE);
     if (!__size)          }
       } else {
         __size = MCACHE_BUCKET_SIZE;          __size = MCACHE_BUCKET_SIZE;
       }
   
     entry = &mapcache->entry[address_index % mapcache->nr_buckets];      entry = &mapcache->entry[address_index % mapcache->nr_buckets];
   
Line 235  uint8_t *xen_map_cache(target_phys_addr_ Line 250  uint8_t *xen_map_cache(target_phys_addr_
     if(!test_bits(address_offset >> XC_PAGE_SHIFT, size >> XC_PAGE_SHIFT,      if(!test_bits(address_offset >> XC_PAGE_SHIFT, size >> XC_PAGE_SHIFT,
                 entry->valid_mapping)) {                  entry->valid_mapping)) {
         mapcache->last_address_index = -1;          mapcache->last_address_index = -1;
           if (!translated && mapcache->phys_offset_to_gaddr) {
               phys_addr = mapcache->phys_offset_to_gaddr(phys_addr, size, mapcache->opaque);
               translated = true;
               goto tryagain;
           }
         trace_xen_map_cache_return(NULL);          trace_xen_map_cache_return(NULL);
         return NULL;          return NULL;
     }      }
Line 351  void xen_invalidate_map_cache(void) Line 371  void xen_invalidate_map_cache(void)
     MapCacheRev *reventry;      MapCacheRev *reventry;
   
     /* Flush pending AIO before destroying the mapcache */      /* Flush pending AIO before destroying the mapcache */
     qemu_aio_flush();      bdrv_drain_all();
   
     QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) {      QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) {
         DPRINTF("There should be no locked mappings at this time, "          DPRINTF("There should be no locked mappings at this time, "
Line 367  void xen_invalidate_map_cache(void) Line 387  void xen_invalidate_map_cache(void)
         if (entry->vaddr_base == NULL) {          if (entry->vaddr_base == NULL) {
             continue;              continue;
         }          }
           if (entry->lock > 0) {
               continue;
           }
   
         if (munmap(entry->vaddr_base, entry->size) != 0) {          if (munmap(entry->vaddr_base, entry->size) != 0) {
             perror("unmap fails");              perror("unmap fails");

Removed from v.1.1.1.2  
changed lines
  Added in v.1.1.1.3


unix.superglobalmegacorp.com