[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 3/8] x86/oprofile: avoid effectively open-coding xmalloc_array()



There is a difference in generated code: xmalloc_bytes() forces
SMP_CACHE_BYTES alignment. But if code really cared about such higher
than default alignment, it should request so explicitly rather than
using a type-unsafe interface. And if e.g. cache line sharing was a
concern, the allocator itself should arrange to avoid such.

While at it also use XFREE() instead of open-coding it and change loop
induction variable types.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- a/xen/arch/x86/oprofile/nmi_int.c
+++ b/xen/arch/x86/oprofile/nmi_int.c
@@ -142,30 +142,29 @@ static void nmi_save_registers(void * du
 
 static void free_msrs(void)
 {
-       int i;
+       unsigned int i;
+
        for (i = 0; i < nr_cpu_ids; ++i) {
-               xfree(cpu_msrs[i].counters);
-               cpu_msrs[i].counters = NULL;
-               xfree(cpu_msrs[i].controls);
-               cpu_msrs[i].controls = NULL;
+               XFREE(cpu_msrs[i].counters);
+               XFREE(cpu_msrs[i].controls);
        }
 }
 
 
 static int allocate_msrs(void)
 {
+       unsigned int i;
        int success = 1;
-       size_t controls_size = sizeof(struct op_msr) * model->num_controls;
-       size_t counters_size = sizeof(struct op_msr) * model->num_counters;
 
-       int i;
        for_each_online_cpu (i) {
-               cpu_msrs[i].counters = xmalloc_bytes(counters_size);
+               cpu_msrs[i].counters = xmalloc_array(struct op_msr,
+                                                    model->num_counters);
                if (!cpu_msrs[i].counters) {
                        success = 0;
                        break;
                }
-               cpu_msrs[i].controls = xmalloc_bytes(controls_size);
+               cpu_msrs[i].controls = xmalloc_array(struct op_msr,
+                                                    model->num_controls);
                if (!cpu_msrs[i].controls) {
                        success = 0;
                        break;




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.