diff mbox series

[02/11] x86/vPMU: avoid effectively open-coding xzalloc_flex_struct()

Message ID ec03cef8-a883-fd68-a062-c243d782394c@suse.com (mailing list archive)
State Superseded
Headers show
Series assorted replacement of x[mz]alloc_bytes() | expand

Commit Message

Jan Beulich April 8, 2021, 12:17 p.m. UTC
There is a difference in generated code: xzalloc_bytes() forces
SMP_CACHE_BYTES alignment. I think we not only don't need this here, but
actually don't want it.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

Comments

Andrew Cooper April 8, 2021, 12:25 p.m. UTC | #1
On 08/04/2021 13:17, Jan Beulich wrote:
> There is a difference in generated code: xzalloc_bytes() forces
> SMP_CACHE_BYTES alignment. I think we not only don't need this here, but
> actually don't want it.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>

>
> --- a/xen/arch/x86/cpu/vpmu_intel.c
> +++ b/xen/arch/x86/cpu/vpmu_intel.c
> @@ -461,10 +461,10 @@ static int core2_vpmu_alloc_resource(str
>              goto out_err;
>      }
>  
> -    core2_vpmu_cxt = xzalloc_bytes(sizeof(*core2_vpmu_cxt) +
> -                                   sizeof(uint64_t) * fixed_pmc_cnt +
> -                                   sizeof(struct xen_pmu_cntr_pair) *
> -                                   arch_pmc_cnt);
> +    core2_vpmu_cxt = xzalloc_flex_struct(struct xen_pmu_intel_ctxt, regs,
> +                                         fixed_pmc_cnt + arch_pmc_cnt *
> +                                         (sizeof(struct xen_pmu_cntr_pair) /
> +                                          sizeof(*core2_vpmu_cxt->regs)));
>      p = xzalloc(uint64_t);

However, this is very wtf, and clearly wants reworking.  I'll see if I
can find some time, unless anyone else beats me to it.

~Andrew

>      if ( !core2_vpmu_cxt || !p )
>          goto out_err;
>
Jan Beulich April 8, 2021, 12:29 p.m. UTC | #2
On 08.04.2021 14:25, Andrew Cooper wrote:
> On 08/04/2021 13:17, Jan Beulich wrote:
>> There is a difference in generated code: xzalloc_bytes() forces
>> SMP_CACHE_BYTES alignment. I think we not only don't need this here, but
>> actually don't want it.
>>
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> 
> Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>

Thanks.

>> --- a/xen/arch/x86/cpu/vpmu_intel.c
>> +++ b/xen/arch/x86/cpu/vpmu_intel.c
>> @@ -461,10 +461,10 @@ static int core2_vpmu_alloc_resource(str
>>              goto out_err;
>>      }
>>  
>> -    core2_vpmu_cxt = xzalloc_bytes(sizeof(*core2_vpmu_cxt) +
>> -                                   sizeof(uint64_t) * fixed_pmc_cnt +
>> -                                   sizeof(struct xen_pmu_cntr_pair) *
>> -                                   arch_pmc_cnt);
>> +    core2_vpmu_cxt = xzalloc_flex_struct(struct xen_pmu_intel_ctxt, regs,
>> +                                         fixed_pmc_cnt + arch_pmc_cnt *
>> +                                         (sizeof(struct xen_pmu_cntr_pair) /
>> +                                          sizeof(*core2_vpmu_cxt->regs)));
>>      p = xzalloc(uint64_t);
> 
> However, this is very wtf, and clearly wants reworking.  I'll see if I
> can find some time, unless anyone else beats me to it.

I thought so too while seeing this, but it's quite a bit more of a
rework than I felt I'd like to tackle right away.

Jan
diff mbox series

Patch

--- a/xen/arch/x86/cpu/vpmu_intel.c
+++ b/xen/arch/x86/cpu/vpmu_intel.c
@@ -461,10 +461,10 @@  static int core2_vpmu_alloc_resource(str
             goto out_err;
     }
 
-    core2_vpmu_cxt = xzalloc_bytes(sizeof(*core2_vpmu_cxt) +
-                                   sizeof(uint64_t) * fixed_pmc_cnt +
-                                   sizeof(struct xen_pmu_cntr_pair) *
-                                   arch_pmc_cnt);
+    core2_vpmu_cxt = xzalloc_flex_struct(struct xen_pmu_intel_ctxt, regs,
+                                         fixed_pmc_cnt + arch_pmc_cnt *
+                                         (sizeof(struct xen_pmu_cntr_pair) /
+                                          sizeof(*core2_vpmu_cxt->regs)));
     p = xzalloc(uint64_t);
     if ( !core2_vpmu_cxt || !p )
         goto out_err;