All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: "Yan, Zheng" <zheng.z.yan@intel.com>
Cc: eranian@google.com, mingo@elte.hu, andi@firstfloor.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] perf/x86: Uncore Filter support for SandyBridge-EP
Date: Wed, 27 Jun 2012 12:01:22 +0200	[thread overview]
Message-ID: <1340791282.10063.8.camel@twins> (raw)
In-Reply-To: <1340780953-21130-2-git-send-email-zheng.z.yan@intel.com>

On Wed, 2012-06-27 at 15:09 +0800, Yan, Zheng wrote:
> +struct intel_uncore_box *uncore_alloc_box(struct intel_uncore_type *type,
> +                                         int cpu)
>  {
>         struct intel_uncore_box *box;
> +       int size = sizeof(*box);
> +
> +       if (type->num_shared_regs)
> +               size += type->num_shared_regs *
> +                       sizeof(struct intel_uncore_extra_reg);
>  
> -       box = kmalloc_node(sizeof(*box), GFP_KERNEL | __GFP_ZERO,
> -                          cpu_to_node(cpu));
> +       box = kmalloc_node(size, GFP_KERNEL | __GFP_ZERO, cpu_to_node(cpu));
>         if (!box)
>                 return NULL;
>  
> +       if (type->num_shared_regs) {
> +               int i;
> +               box->shared_regs = (struct intel_uncore_extra_reg *)(box + 1);
> +               for (i = 0; i < type->num_shared_regs; i++)
> +                       raw_spin_lock_init(&box->shared_regs[i].lock);
> +       }
> +
>         uncore_pmu_init_hrtimer(box);
>         atomic_set(&box->refcnt, 1);
>         box->cpu = -1; 

Yuck.. that's vile. How about something like this:


---
--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
@@ -206,7 +206,7 @@ static void snbep_uncore_put_constraint(
 		return;
 
 	er = &box->shared_regs[reg1->idx];
-	atomic_sub(1, &er->ref);
+	atomic_dec(&er->ref);
 	reg1->alloc = 0;
 }
 
@@ -862,22 +862,17 @@ struct intel_uncore_box *uncore_alloc_bo
 					  int cpu)
 {
 	struct intel_uncore_box *box;
-	int size = sizeof(*box);
-
-	if (type->num_shared_regs)
-		size += type->num_shared_regs *
-			sizeof(struct intel_uncore_extra_reg);
+	int i, size;
+       
+	size = sizeof(*box) + type->num_shared_regs *
+		sizeof(struct intel_uncore_extra_reg);
 
 	box = kmalloc_node(size, GFP_KERNEL | __GFP_ZERO, cpu_to_node(cpu));
 	if (!box)
 		return NULL;
 
-	if (type->num_shared_regs) {
-		int i;
-		box->shared_regs = (struct intel_uncore_extra_reg *)(box + 1);
-		for (i = 0; i < type->num_shared_regs; i++)
-			raw_spin_lock_init(&box->shared_regs[i].lock);
-	}
+	for (i = 0; i < type->num_shared_regs; i++)
+		raw_spin_lock_init(&box->shared_regs[i].lock);
 
 	uncore_pmu_init_hrtimer(box);
 	atomic_set(&box->refcnt, 1);
--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
@@ -228,11 +228,11 @@ struct intel_uncore_box {
 	struct perf_event *event_list[UNCORE_PMC_IDX_MAX];
 	unsigned long active_mask[BITS_TO_LONGS(UNCORE_PMC_IDX_MAX)];
 	u64 tags[UNCORE_PMC_IDX_MAX];
-	struct intel_uncore_extra_reg *shared_regs;
 	struct pci_dev *pci_dev;
 	struct intel_uncore_pmu *pmu;
 	struct hrtimer hrtimer;
 	struct list_head list;
+	struct intel_uncore_extra_reg shared_regs[0];
 };
 
 #define UNCORE_BOX_FLAG_INITIATED	0


  parent reply	other threads:[~2012-06-27 10:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-27  7:09 [PATCH 1/2] perf/x86: Use 0xff as pseudo code for fixed uncore event Yan, Zheng
2012-06-27  7:09 ` [PATCH 2/2] perf/x86: Uncore Filter support for SandyBridge-EP Yan, Zheng
2012-06-27  9:42   ` Peter Zijlstra
2012-06-27 10:01   ` Peter Zijlstra [this message]
2012-06-27 10:06   ` Peter Zijlstra
2012-06-28  1:30     ` Yan, Zheng
2012-06-28 10:10       ` Peter Zijlstra
2012-06-27 13:06 ` [PATCH 1/2] perf/x86: Use 0xff as pseudo code for fixed uncore event Stephane Eranian
2012-06-27 13:10   ` Peter Zijlstra
2012-07-06  6:30 ` [tip:perf/core] " tip-bot for Yan, Zheng

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=1340791282.10063.8.camel@twins \
    --to=a.p.zijlstra@chello.nl \
    --cc=andi@firstfloor.org \
    --cc=eranian@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=zheng.z.yan@intel.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.