xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
	"George Dunlap" <george.dunlap@citrix.com>,
	"Wei Liu" <wl@xen.org>, "Roger Pau Monné" <roger.pau@citrix.com>
Subject: [PATCH v2 3/8] x86/oprofile: avoid effectively open-coding xmalloc_array()
Date: Wed, 21 Apr 2021 16:57:04 +0200	[thread overview]
Message-ID: <b3e46e74-517a-f5b3-1ae3-8fcae49e42ca@suse.com> (raw)
In-Reply-To: <091b4b91-712f-3526-78d1-80d31faf8e41@suse.com>

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@suse.com>

--- 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;



  parent reply	other threads:[~2021-04-21 14:57 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-21 14:54 [PATCH v2 0/8] assorted replacement of x[mz]alloc_bytes() Jan Beulich
2021-04-21 14:56 ` [PATCH v2 1/8] x86/MCE: avoid effectively open-coding xmalloc_array() Jan Beulich
2021-04-21 14:56 ` [PATCH v2 2/8] x86/HVM: " Jan Beulich
2021-04-21 14:57 ` Jan Beulich [this message]
2021-04-21 14:57 ` [PATCH v2 4/8] x86/IRQ: avoid over-alignment in alloc_pirq_struct() Jan Beulich
2021-04-21 14:58 ` [PATCH v2 5/8] EFI/runtime: avoid effectively open-coding x{m,z}alloc_array() Jan Beulich
2021-04-21 14:58 ` [PATCH v2 6/8] kexec: avoid effectively open-coding xzalloc_flex_struct() Jan Beulich
2021-04-21 14:59 ` [PATCH v2 7/8] video/lfb: avoid effectively open-coding xzalloc_array() Jan Beulich
2021-04-21 14:59 ` [PATCH v2 8/8] Arm/optee: don't open-code xzalloc_flex_struct() Jan Beulich
2021-05-03 13:53   ` Ping: " Jan Beulich
2021-05-04 23:49     ` Volodymyr Babchuk
2021-04-21 15:23 ` [PATCH v2 0/8] assorted replacement of x[mz]alloc_bytes() Andrew Cooper
2021-04-21 15:32   ` Jan Beulich
2021-04-23  9:44   ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b3e46e74-517a-f5b3-1ae3-8fcae49e42ca@suse.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=roger.pau@citrix.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    --subject='Re: [PATCH v2 3/8] x86/oprofile: avoid effectively open-coding xmalloc_array()' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).