Skip to contentSkip to conversation

x86: re-order struct arch_domain fields

PATCH Superseded Jan Beulich 2 participants 5 messages Jan 19, 2015 – Feb 4, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: re-order struct arch_domain fields

... to reduce padding holes. While doing this I noticed vtsc_usercount is a PV-only thing, so it gets moved straight to struct pv_domain.

xen/arch/x86/time.c +7 -9
@@ -1767,7 +1767,7 @@ void pv_soft_rdtsc(struct vcpu *v, struc
     if ( guest_kernel_mode(v, regs) )
         d->arch.vtsc_kerncount++;
     else
-        d->arch.vtsc_usercount++;
+        d->arch.pv_domain.vtsc_usercount++;
 
     if ( (int64_t)(now - d->arch.vtsc_last) > 0 )
         d->arch.vtsc_last = now;
@@ -2020,17 +2020,15 @@ static void dump_softtsc(unsigned char k
             printk(",khz=%"PRIu32, d->arch.tsc_khz);
         if ( d->arch.incarnation )
             printk(",inc=%"PRIu32, d->arch.incarnation);
-        if ( !(d->arch.vtsc_kerncount | d->arch.vtsc_usercount) )
-        {
-            printk("\n");
-            continue;
-        }
-        if ( is_hvm_domain(d) )
+        if ( is_hvm_domain(d) && d->arch.vtsc_kerncount )
             printk(",vtsc count: %"PRIu64" total\n",
                    d->arch.vtsc_kerncount);
-        else
+        else if ( is_pv_domain(d) &&
+                  (d->arch.vtsc_kerncount | d->arch.pv_domain.vtsc_usercount) )
             printk(",vtsc count: %"PRIu64" kernel, %"PRIu64" user\n",
-                   d->arch.vtsc_kerncount, d->arch.vtsc_usercount);
+                   d->arch.vtsc_kerncount, d->arch.pv_domain.vtsc_usercount);
+        else
+            printk("\n");
         domcnt++;
     }
 
xen/include/asm-x86/domain.h +25 -23

106 lines not on this page · raw message

x86: re-order struct arch_domain fields

... to reduce padding holes. While doing this I noticed vtsc_usercount is a PV-only thing, so it gets moved straight to struct pv_domain.

xen/arch/x86/time.c +7 -9
@@ -1767,7 +1767,7 @@ void pv_soft_rdtsc(struct vcpu *v, struc
     if ( guest_kernel_mode(v, regs) )
         d->arch.vtsc_kerncount++;
     else
-        d->arch.vtsc_usercount++;
+        d->arch.pv_domain.vtsc_usercount++;
 
     if ( (int64_t)(now - d->arch.vtsc_last) > 0 )
         d->arch.vtsc_last = now;
@@ -2020,17 +2020,15 @@ static void dump_softtsc(unsigned char k
             printk(",khz=%"PRIu32, d->arch.tsc_khz);
         if ( d->arch.incarnation )
             printk(",inc=%"PRIu32, d->arch.incarnation);
-        if ( !(d->arch.vtsc_kerncount | d->arch.vtsc_usercount) )
-        {
-            printk("\n");
-            continue;
-        }
-        if ( is_hvm_domain(d) )
+        if ( is_hvm_domain(d) && d->arch.vtsc_kerncount )
             printk(",vtsc count: %"PRIu64" total\n",
                    d->arch.vtsc_kerncount);
-        else
+        else if ( is_pv_domain(d) &&
+                  (d->arch.vtsc_kerncount | d->arch.pv_domain.vtsc_usercount) )
             printk(",vtsc count: %"PRIu64" kernel, %"PRIu64" user\n",
-                   d->arch.vtsc_kerncount, d->arch.vtsc_usercount);
+                   d->arch.vtsc_kerncount, d->arch.pv_domain.vtsc_usercount);
+        else
+            printk("\n");
         domcnt++;
     }
 
xen/include/asm-x86/domain.h +25 -23

106 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#1 lore raw
Quoted 2 lines · Jan Beulich

... to reduce padding holes. While doing this I noticed vtsc_usercount is a PV-only thing, so it gets moved straight to struct pv_domain.

The vtsc_{user,kernel}count split is curious. They are both for stats purposes alone, but there is nothing pv specific about the usercount. It frankly looks as if it has been mis-implemented for HVM, despite the split appearing to be deliberate when it was introduced in c/s bf2c44f8b469. I am really not sure what to make of it.

Quoted 20 lines
xen/arch/x86/time.c +1 -3
@@ -1767,7 +1767,7 @@ void pv_soft_rdtsc(struct vcpu *v, struc
     if ( guest_kernel_mode(v, regs) )
         d->arch.vtsc_kerncount++;
     else
-        d->arch.vtsc_usercount++;
+        d->arch.pv_domain.vtsc_usercount++;
 
     if ( (int64_t)(now - d->arch.vtsc_last) > 0 )
         d->arch.vtsc_last = now;
@@ -2020,17 +2020,15 @@ static void dump_softtsc(unsigned char k
             printk(",khz=%"PRIu32, d->arch.tsc_khz);
         if ( d->arch.incarnation )
             printk(",inc=%"PRIu32, d->arch.incarnation);
-        if ( !(d->arch.vtsc_kerncount | d->arch.vtsc_usercount) )
-        {

xen/arch/x86/time.c static void dump_softtsc(unsigned char k · line 2027

Quoted 10 lines
xen/arch/x86/time.c +3 -5
-            printk("\n");
-            continue;
-        }
-        if ( is_hvm_domain(d) )
+        if ( is_hvm_domain(d) && d->arch.vtsc_kerncount )
             printk(",vtsc count: %"PRIu64" total\n",
                    d->arch.vtsc_kerncount);
-        else
+        else if ( is_pv_domain(d) &&
+                  (d->arch.vtsc_kerncount | d->arch.pv_domain.vtsc_usercount) )

I realise you are simply rearanging the logic from before, but this should really be a logic or rather than a bitwise or, and is probably worth tweaking with the movement.

~Andrew

#2 lore raw
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 19.01.15 at 18:52, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich

... to reduce padding holes. While doing this I noticed vtsc_usercount is a PV-only thing, so it gets moved straight to struct pv_domain.

The vtsc_{user,kernel}count split is curious. They are both for stats purposes alone, but there is nothing pv specific about the usercount. It frankly looks as if it has been mis-implemented for HVM, despite the split appearing to be deliberate when it was introduced in c/s bf2c44f8b469. I am really not sure what to make of it.

It's clearly used for PV only at present. Anyone wanting to change this (including if the current implementation was really buggy) could easily move the field back out of struct pv_domain.

Quoted 23 lines
Quoted 23 lines
xen/arch/x86/time.c +2 -7
@@ -1767,7 +1767,7 @@ void pv_soft_rdtsc(struct vcpu *v, struc
     if ( guest_kernel_mode(v, regs) )
         d->arch.vtsc_kerncount++;
     else
-        d->arch.vtsc_usercount++;
+        d->arch.pv_domain.vtsc_usercount++;
 
     if ( (int64_t)(now - d->arch.vtsc_last) > 0 )
         d->arch.vtsc_last = now;
@@ -2020,17 +2020,15 @@ static void dump_softtsc(unsigned char k
             printk(",khz=%"PRIu32, d->arch.tsc_khz);
         if ( d->arch.incarnation )
             printk(",inc=%"PRIu32, d->arch.incarnation);
-        if ( !(d->arch.vtsc_kerncount | d->arch.vtsc_usercount) )
-        {
-            printk("\n");
-            continue;
-        }
-        if ( is_hvm_domain(d) )
+        if ( is_hvm_domain(d) && d->arch.vtsc_kerncount )
             printk(",vtsc count: %"PRIu64" total\n",
Quoted 8 lines

xen/arch/x86/time.c static void dump_softtsc(unsigned char k · line 2027

Quoted 4 lines
xen/arch/x86/time.c +2 -1
                    d->arch.vtsc_kerncount);
-        else
+        else if ( is_pv_domain(d) &&
+                  (d->arch.vtsc_kerncount | d->arch.pv_domain.vtsc_usercount) )

I realise you are simply rearanging the logic from before, but this should really be a logic or rather than a bitwise or, and is probably worth tweaking with the movement.

I disagree - for the purpose here, | vs || doesn't matter at all, and personally (working with compilers other than gcc) I prefer | where possible as not all compilers know to optimize || to | in cases like this on architectures where logical machine instructions produce usable status flags (in fact, none of the three different vendor Windows compilers I just tried do).

Jan

#3 lore raw
In reply to Andrew Cooper
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 19.01.15 at 18:52, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich

... to reduce padding holes. While doing this I noticed vtsc_usercount is a PV-only thing, so it gets moved straight to struct pv_domain.

The vtsc_{user,kernel}count split is curious. They are both for stats purposes alone, but there is nothing pv specific about the usercount. It frankly looks as if it has been mis-implemented for HVM, despite the split appearing to be deliberate when it was introduced in c/s bf2c44f8b469. I am really not sure what to make of it.

Since I didn't hear back on my earlier response, I looked at this again:
Considering especially the explicit callers of hvm_get_guest_tsc_fixed(), I also wonder whether the accounting for HVM makes sense in the first place - to me, these two numbers are meant to be _only_ counting actual emulations. Hence I first of all would think this ought to be moved into hvm_rdtsc_intercept() (and maybe mirrored in hvm_msr_read_intercept(), perhaps by refactoring the former to be usable by the latter).

In that case it would indeed make sense to keep the user count for non-PV, as then it really makes sense to check for user/kernel mode there.

Jan

#4 lore raw
Quoted 18 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 19.01.15 at 18:52, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich

... to reduce padding holes. While doing this I noticed vtsc_usercount is a PV-only thing, so it gets moved straight to struct pv_domain.

The vtsc_{user,kernel}count split is curious. They are both for stats purposes alone, but there is nothing pv specific about the usercount. It frankly looks as if it has been mis-implemented for HVM, despite the split appearing to be deliberate when it was introduced in c/s bf2c44f8b469. I am really not sure what to make of it.

Since I didn't hear back on my earlier response, I looked at this again:
Considering especially the explicit callers of hvm_get_guest_tsc_fixed(), I also wonder whether the accounting for HVM makes sense in the first place - to me, these two numbers are meant to be _only_ counting actual emulations. Hence I first of all would think this ought to be moved into hvm_rdtsc_intercept() (and maybe mirrored in hvm_msr_read_intercept(), perhaps by refactoring the former to be usable by the latter).

Quoted 6 lines

In that case it would indeed make sense to keep the user count for non-PV, as then it really makes sense to check for user/kernel mode there.

Jan

I agree with your analysis. Now that you point it out, the current code does look wrong.

~Andrew