]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/xen.git/commitdiff
x86: shrink 'struct domain', was already PAGE_SIZE
authorCorneliu ZUZU <czuzu@bitdefender.com>
Mon, 1 Feb 2016 13:00:30 +0000 (14:00 +0100)
committerJan Beulich <jbeulich@suse.com>
Mon, 1 Feb 2016 13:00:30 +0000 (14:00 +0100)
The X86 domain structure already occupied PAGE_SIZE (4096).

Looking @ the memory layout of the structure, we could see that
overall most was occupied by (used the pahole tool on domain.o):
 * sizeof(domain.arch) = sizeof(arch_domain) = 3328 bytes.
 * sizeof(domain.arch.hvm_domain) = 2224 bytes.
 * sizeof(domain.arch.hvm_domain.pl_time) = 1088 bytes.
This patch attempts to free some space, by making the pl_time
field in hvm_domain dynamically allocated.
We xzalloc/xfree it @ hvm_domain_initialise/hvm_domain_destroy.

After this change, the domain structure shrunk w/ 1152 bytes (>1K!).

Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
xen/arch/x86/hvm/hpet.c
xen/arch/x86/hvm/hvm.c
xen/arch/x86/hvm/pmtimer.c
xen/arch/x86/hvm/rtc.c
xen/arch/x86/hvm/vpt.c
xen/arch/x86/time.c
xen/include/asm-x86/hvm/domain.h
xen/include/asm-x86/hvm/vpt.h

index 5e020aecfa76eff74c661ff3bbf201c6eacb6d36..3ea895a0fb8d44d7b5f2fe29f645b4a62a3ab88c 100644 (file)
 #include <xen/event.h>
 #include <xen/trace.h>
 
-#define domain_vhpet(x) (&(x)->arch.hvm_domain.pl_time.vhpet)
+#define domain_vhpet(x) (&(x)->arch.hvm_domain.pl_time->vhpet)
 #define vcpu_vhpet(x)   (domain_vhpet((x)->domain))
-#define vhpet_domain(x) (container_of((x), struct domain, \
-                                      arch.hvm_domain.pl_time.vhpet))
+#define vhpet_domain(x) (container_of(x, struct pl_time, vhpet)->domain)
 #define vhpet_vcpu(x)   (pt_global_vcpu_target(vhpet_domain(x)))
 
 #define HPET_BASE_ADDRESS   0xfed00000ULL
index dea3335ec98c1e51ecde669f1ff27264da1ef61a..f24400d3edc5e802bf74b5076689f36820ec3bd9 100644 (file)
@@ -1576,13 +1576,18 @@ int hvm_domain_initialise(struct domain *d)
     if ( rc != 0 )
         goto fail0;
 
+    d->arch.hvm_domain.pl_time = xzalloc(struct pl_time);
     d->arch.hvm_domain.params = xzalloc_array(uint64_t, HVM_NR_PARAMS);
     d->arch.hvm_domain.io_handler = xzalloc_array(struct hvm_io_handler,
                                                   NR_IO_HANDLERS);
     rc = -ENOMEM;
-    if ( !d->arch.hvm_domain.params || !d->arch.hvm_domain.io_handler )
+    if ( !d->arch.hvm_domain.pl_time ||
+         !d->arch.hvm_domain.params  || !d->arch.hvm_domain.io_handler )
         goto fail1;
 
+    /* need link to containing domain */
+    d->arch.hvm_domain.pl_time->domain = d;
+
     /* Set the default IO Bitmap. */
     if ( is_hardware_domain(d) )
     {
@@ -1639,6 +1644,7 @@ int hvm_domain_initialise(struct domain *d)
         xfree(d->arch.hvm_domain.io_bitmap);
     xfree(d->arch.hvm_domain.io_handler);
     xfree(d->arch.hvm_domain.params);
+    xfree(d->arch.hvm_domain.pl_time);
  fail0:
     hvm_destroy_cacheattr_region_list(d);
     return rc;
@@ -1669,6 +1675,7 @@ void hvm_domain_destroy(struct domain *d)
 {
     xfree(d->arch.hvm_domain.io_handler);
     xfree(d->arch.hvm_domain.params);
+    xfree(d->arch.hvm_domain.pl_time);
 
     hvm_destroy_cacheattr_region_list(d);
 
index 9c2e4bd2d818d2cf57805e127c1c2034119dcfff..b1a55659d98e09dd4db970dccce24d686f722a7f 100644 (file)
@@ -66,7 +66,7 @@ static void pmt_update_sci(PMTState *s)
 
 void hvm_acpi_power_button(struct domain *d)
 {
-    PMTState *s = &d->arch.hvm_domain.pl_time.vpmt;
+    PMTState *s = &d->arch.hvm_domain.pl_time->vpmt;
 
     if ( !has_vpm(d) )
         return;
@@ -79,7 +79,7 @@ void hvm_acpi_power_button(struct domain *d)
 
 void hvm_acpi_sleep_button(struct domain *d)
 {
-    PMTState *s = &d->arch.hvm_domain.pl_time.vpmt;
+    PMTState *s = &d->arch.hvm_domain.pl_time->vpmt;
 
     if ( !has_vpm(d) )
         return;
@@ -152,7 +152,7 @@ static int handle_evt_io(
     int dir, unsigned int port, unsigned int bytes, uint32_t *val)
 {
     struct vcpu *v = current;
-    PMTState *s = &v->domain->arch.hvm_domain.pl_time.vpmt;
+    PMTState *s = &v->domain->arch.hvm_domain.pl_time->vpmt;
     uint32_t addr, data, byte;
     int i;
 
@@ -215,7 +215,7 @@ static int handle_pmt_io(
     int dir, unsigned int port, unsigned int bytes, uint32_t *val)
 {
     struct vcpu *v = current;
-    PMTState *s = &v->domain->arch.hvm_domain.pl_time.vpmt;
+    PMTState *s = &v->domain->arch.hvm_domain.pl_time->vpmt;
 
     if ( bytes != 4 )
     {
@@ -251,7 +251,7 @@ static int handle_pmt_io(
 
 static int pmtimer_save(struct domain *d, hvm_domain_context_t *h)
 {
-    PMTState *s = &d->arch.hvm_domain.pl_time.vpmt;
+    PMTState *s = &d->arch.hvm_domain.pl_time->vpmt;
     uint32_t x, msb = s->pm.tmr_val & TMR_VAL_MSB;
     int rc;
 
@@ -282,7 +282,7 @@ static int pmtimer_save(struct domain *d, hvm_domain_context_t *h)
 
 static int pmtimer_load(struct domain *d, hvm_domain_context_t *h)
 {
-    PMTState *s = &d->arch.hvm_domain.pl_time.vpmt;
+    PMTState *s = &d->arch.hvm_domain.pl_time->vpmt;
 
     if ( !has_vpm(d) )
         return -ENODEV;
@@ -345,7 +345,7 @@ int pmtimer_change_ioport(struct domain *d, unsigned int version)
 
 void pmtimer_init(struct vcpu *v)
 {
-    PMTState *s = &v->domain->arch.hvm_domain.pl_time.vpmt;
+    PMTState *s = &v->domain->arch.hvm_domain.pl_time->vpmt;
 
     if ( !has_vpm(v->domain) )
         return;
@@ -369,7 +369,7 @@ void pmtimer_init(struct vcpu *v)
 
 void pmtimer_deinit(struct domain *d)
 {
-    PMTState *s = &d->arch.hvm_domain.pl_time.vpmt;
+    PMTState *s = &d->arch.hvm_domain.pl_time->vpmt;
 
     if ( !has_vpm(d) )
         return;
@@ -383,5 +383,5 @@ void pmtimer_reset(struct domain *d)
         return;
 
     /* Reset the counter. */
-    d->arch.hvm_domain.pl_time.vpmt.pm.tmr_val = 0;
+    d->arch.hvm_domain.pl_time->vpmt.pm.tmr_val = 0;
 }
index d391e38ae59b188a9dce240e4828b87266e7d8d7..4d792a49e1182149bb2e9ff574666ecde861e1b4 100644 (file)
 #define MIN_PER_HOUR    60
 #define HOUR_PER_DAY    24
 
-#define domain_vrtc(x) (&(x)->arch.hvm_domain.pl_time.vrtc)
+#define domain_vrtc(x) (&(x)->arch.hvm_domain.pl_time->vrtc)
 #define vcpu_vrtc(x)   (domain_vrtc((x)->domain))
-#define vrtc_domain(x) (container_of((x), struct domain, \
-                                     arch.hvm_domain.pl_time.vrtc))
+#define vrtc_domain(x) (container_of(x, struct pl_time, vrtc)->domain)
 #define vrtc_vcpu(x)   (pt_global_vcpu_target(vrtc_domain(x)))
 #define epoch_year     1900
 #define get_year(x)    (x + epoch_year)
index 4fa65660c26a4035ca5e99d8a400696d5e5b3dc7..358ec576fedbe8df5c4e3a6b7b26ae1178f25dcc 100644 (file)
@@ -28,7 +28,7 @@
 
 void hvm_init_guest_time(struct domain *d)
 {
-    struct pl_time *pl = &d->arch.hvm_domain.pl_time;
+    struct pl_time *pl = d->arch.hvm_domain.pl_time;
 
     spin_lock_init(&pl->pl_time_lock);
     pl->stime_offset = -(u64)get_s_time();
@@ -37,7 +37,7 @@ void hvm_init_guest_time(struct domain *d)
 
 u64 hvm_get_guest_time_fixed(struct vcpu *v, u64 at_tsc)
 {
-    struct pl_time *pl = &v->domain->arch.hvm_domain.pl_time;
+    struct pl_time *pl = v->domain->arch.hvm_domain.pl_time;
     u64 now;
 
     /* Called from device models shared with PV guests. Be careful. */
@@ -505,7 +505,7 @@ void pt_adjust_global_vcpu_target(struct vcpu *v)
     pt_adjust_vcpu(&vpit->pt0, v);
     spin_unlock(&vpit->lock);
 
-    pl_time = &v->domain->arch.hvm_domain.pl_time;
+    pl_time = v->domain->arch.hvm_domain.pl_time;
 
     spin_lock(&pl_time->vrtc.lock);
     pt_adjust_vcpu(&pl_time->vrtc.pt, v);
@@ -540,9 +540,9 @@ void pt_may_unmask_irq(struct domain *d, struct periodic_time *vlapic_pt)
     if ( d )
     {
         pt_resume(&d->arch.vpit.pt0);
-        pt_resume(&d->arch.hvm_domain.pl_time.vrtc.pt);
+        pt_resume(&d->arch.hvm_domain.pl_time->vrtc.pt);
         for ( i = 0; i < HPET_TIMER_NUM; i++ )
-            pt_resume(&d->arch.hvm_domain.pl_time.vhpet.pt[i]);
+            pt_resume(&d->arch.hvm_domain.pl_time->vhpet.pt[i]);
     }
 
     if ( vlapic_pt )
index 988403aedf2a5cb1ae531cdb43c32ec3a0b06065..5819b9ffdb711545488f1dae9143fcf95a983000 100644 (file)
@@ -799,7 +799,7 @@ static void __update_vcpu_system_time(struct vcpu *v, int force)
 
         if ( is_hvm_domain(d) )
         {
-            struct pl_time *pl = &v->domain->arch.hvm_domain.pl_time;
+            struct pl_time *pl = v->domain->arch.hvm_domain.pl_time;
 
             stime += pl->stime_offset + v->arch.hvm_vcpu.stime_offset;
             if ( stime >= 0 )
index 1e139737ccafd3e282ecaa1453d4df9c9c29bb5e..4b54c5da615c379a2701a1f7dc92d0637c87607e 100644 (file)
@@ -91,7 +91,7 @@ struct hvm_domain {
     /* Cached CF8 for guest PCI config cycles */
     uint32_t                pci_cf8;
 
-    struct pl_time         pl_time;
+    struct pl_time         *pl_time;
 
     struct hvm_io_handler *io_handler;
     unsigned int          io_handler_count;
index 495d669b5fef4aa06a401087fb7793eb1c9c25aa..a27bea4ff26db0b686fcf92f21c04c1279123fdb 100644 (file)
@@ -139,6 +139,7 @@ struct pl_time {    /* platform time */
     /* Ensures monotonicity in appropriate timer modes. */
     uint64_t last_guest_time;
     spinlock_t pl_time_lock;
+    struct domain *domain;
 };
 
 void pt_save_timer(struct vcpu *v);