Merge branch 'x86-cpu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / arch / x86 / events / core.c
index 9c562f5fbde0a7586192c46a2d6a7046b019b78c..106911b603bd95b355ddcf5d16028c4374c17035 100644 (file)
@@ -1033,6 +1033,27 @@ static inline void x86_assign_hw_event(struct perf_event *event,
        }
 }
 
+/**
+ * x86_perf_rdpmc_index - Return PMC counter used for event
+ * @event: the perf_event to which the PMC counter was assigned
+ *
+ * The counter assigned to this performance event may change if interrupts
+ * are enabled. This counter should thus never be used while interrupts are
+ * enabled. Before this function is used to obtain the assigned counter the
+ * event should be checked for validity using, for example,
+ * perf_event_read_local(), within the same interrupt disabled section in
+ * which this counter is planned to be used.
+ *
+ * Return: The index of the performance monitoring counter assigned to
+ * @perf_event.
+ */
+int x86_perf_rdpmc_index(struct perf_event *event)
+{
+       lockdep_assert_irqs_disabled();
+
+       return event->hw.event_base_rdpmc;
+}
+
 static inline int match_prev_assignment(struct hw_perf_event *hwc,
                                        struct cpu_hw_events *cpuc,
                                        int i)
@@ -1584,7 +1605,7 @@ static void __init pmu_check_apic(void)
 
 }
 
-static struct attribute_group x86_pmu_format_group = {
+static struct attribute_group x86_pmu_format_group __ro_after_init = {
        .name = "format",
        .attrs = NULL,
 };
@@ -1631,9 +1652,9 @@ __init struct attribute **merge_attr(struct attribute **a, struct attribute **b)
        struct attribute **new;
        int j, i;
 
-       for (j = 0; a[j]; j++)
+       for (j = 0; a && a[j]; j++)
                ;
-       for (i = 0; b[i]; i++)
+       for (i = 0; b && b[i]; i++)
                j++;
        j++;
 
@@ -1642,9 +1663,9 @@ __init struct attribute **merge_attr(struct attribute **a, struct attribute **b)
                return NULL;
 
        j = 0;
-       for (i = 0; a[i]; i++)
+       for (i = 0; a && a[i]; i++)
                new[j++] = a[i];
-       for (i = 0; b[i]; i++)
+       for (i = 0; b && b[i]; i++)
                new[j++] = b[i];
        new[j] = NULL;
 
@@ -1715,7 +1736,7 @@ static struct attribute *events_attr[] = {
        NULL,
 };
 
-static struct attribute_group x86_pmu_events_group = {
+static struct attribute_group x86_pmu_events_group __ro_after_init = {
        .name = "events",
        .attrs = events_attr,
 };
@@ -2234,7 +2255,7 @@ static struct attribute *x86_pmu_attrs[] = {
        NULL,
 };
 
-static struct attribute_group x86_pmu_attr_group = {
+static struct attribute_group x86_pmu_attr_group __ro_after_init = {
        .attrs = x86_pmu_attrs,
 };
 
@@ -2252,7 +2273,7 @@ static struct attribute *x86_pmu_caps_attrs[] = {
        NULL
 };
 
-static struct attribute_group x86_pmu_caps_group = {
+static struct attribute_group x86_pmu_caps_group __ro_after_init = {
        .name = "caps",
        .attrs = x86_pmu_caps_attrs,
 };