Commit c05199e5 authored by Kan Liang's avatar Kan Liang Committed by Ingo Molnar

perf/x86/intel/uncore: Move uncore_box_init() out of driver initialization

There were some issues about the uncore driver tried to access
non-existing boxes, which caused boot crashes. These issues have
been all fixed. But we should avoid boot failures if that ever
happens again.

This patch intends to prevent this kind of potential issues.
It moves uncore_box_init out of driver initialization. The box
will be initialized when it's first enabled.
Signed-off-by: default avatarKan Liang <kan.liang@intel.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1421729665-5912-1-git-send-email-kan.liang@intel.com
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Yan, Zheng <zheng.z.yan@intel.com>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 4adca1cb
...@@ -840,7 +840,6 @@ static int uncore_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id ...@@ -840,7 +840,6 @@ static int uncore_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id
box->phys_id = phys_id; box->phys_id = phys_id;
box->pci_dev = pdev; box->pci_dev = pdev;
box->pmu = pmu; box->pmu = pmu;
uncore_box_init(box);
pci_set_drvdata(pdev, box); pci_set_drvdata(pdev, box);
raw_spin_lock(&uncore_box_lock); raw_spin_lock(&uncore_box_lock);
...@@ -1004,10 +1003,8 @@ static int uncore_cpu_starting(int cpu) ...@@ -1004,10 +1003,8 @@ static int uncore_cpu_starting(int cpu)
pmu = &type->pmus[j]; pmu = &type->pmus[j];
box = *per_cpu_ptr(pmu->box, cpu); box = *per_cpu_ptr(pmu->box, cpu);
/* called by uncore_cpu_init? */ /* called by uncore_cpu_init? */
if (box && box->phys_id >= 0) { if (box && box->phys_id >= 0)
uncore_box_init(box);
continue; continue;
}
for_each_online_cpu(k) { for_each_online_cpu(k) {
exist = *per_cpu_ptr(pmu->box, k); exist = *per_cpu_ptr(pmu->box, k);
...@@ -1023,10 +1020,8 @@ static int uncore_cpu_starting(int cpu) ...@@ -1023,10 +1020,8 @@ static int uncore_cpu_starting(int cpu)
} }
} }
if (box) { if (box)
box->phys_id = phys_id; box->phys_id = phys_id;
uncore_box_init(box);
}
} }
} }
return 0; return 0;
......
...@@ -257,6 +257,14 @@ static inline int uncore_num_counters(struct intel_uncore_box *box) ...@@ -257,6 +257,14 @@ static inline int uncore_num_counters(struct intel_uncore_box *box)
return box->pmu->type->num_counters; return box->pmu->type->num_counters;
} }
static inline void uncore_box_init(struct intel_uncore_box *box)
{
if (!test_and_set_bit(UNCORE_BOX_FLAG_INITIATED, &box->flags)) {
if (box->pmu->type->ops->init_box)
box->pmu->type->ops->init_box(box);
}
}
static inline void uncore_disable_box(struct intel_uncore_box *box) static inline void uncore_disable_box(struct intel_uncore_box *box)
{ {
if (box->pmu->type->ops->disable_box) if (box->pmu->type->ops->disable_box)
...@@ -265,6 +273,8 @@ static inline void uncore_disable_box(struct intel_uncore_box *box) ...@@ -265,6 +273,8 @@ static inline void uncore_disable_box(struct intel_uncore_box *box)
static inline void uncore_enable_box(struct intel_uncore_box *box) static inline void uncore_enable_box(struct intel_uncore_box *box)
{ {
uncore_box_init(box);
if (box->pmu->type->ops->enable_box) if (box->pmu->type->ops->enable_box)
box->pmu->type->ops->enable_box(box); box->pmu->type->ops->enable_box(box);
} }
...@@ -287,14 +297,6 @@ static inline u64 uncore_read_counter(struct intel_uncore_box *box, ...@@ -287,14 +297,6 @@ static inline u64 uncore_read_counter(struct intel_uncore_box *box,
return box->pmu->type->ops->read_counter(box, event); return box->pmu->type->ops->read_counter(box, event);
} }
static inline void uncore_box_init(struct intel_uncore_box *box)
{
if (!test_and_set_bit(UNCORE_BOX_FLAG_INITIATED, &box->flags)) {
if (box->pmu->type->ops->init_box)
box->pmu->type->ops->init_box(box);
}
}
static inline bool uncore_box_is_fake(struct intel_uncore_box *box) static inline bool uncore_box_is_fake(struct intel_uncore_box *box)
{ {
return (box->phys_id < 0); return (box->phys_id < 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment