intel_pmu_lbr_del(event);
        if (event->attr.precise_ip)
                intel_pmu_pebs_del(event);
+       if (is_pebs_counter_event_group(event))
+               this_cpu_ptr(&cpu_hw_events)->n_late_setup--;
 }
 
 static int icl_set_topdown_event_period(struct perf_event *event)
        }
 }
 
+void intel_pmu_late_setup(void)
+{
+       struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
+
+       if (!cpuc->n_late_setup)
+               return;
+
+       intel_pmu_pebs_late_setup(cpuc);
+}
+
 static void intel_pmu_add_event(struct perf_event *event)
 {
        if (event->attr.precise_ip)
                intel_pmu_pebs_add(event);
        if (intel_pmu_needs_branch_stack(event))
                intel_pmu_lbr_add(event);
+       if (is_pebs_counter_event_group(event))
+               this_cpu_ptr(&cpu_hw_events)->n_late_setup++;
 }
 
 /*
 
 }
 
 
-static void intel_pmu_late_setup(void)
+void intel_pmu_pebs_late_setup(struct cpu_hw_events *cpuc)
 {
-       struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
        struct perf_event *event;
        u64 pebs_data_cfg = 0;
        int i;
 
        struct event_constraint *event_constraint[X86_PMC_IDX_MAX];
 
        int                     n_excl; /* the number of exclusive events */
+       int                     n_late_setup; /* the num of events needs late setup */
 
        unsigned int            txn_flags;
        int                     is_fake;
 
 int intel_pmu_drain_bts_buffer(void);
 
+void intel_pmu_late_setup(void);
+
 u64 grt_latency_data(struct perf_event *event, u64 status);
 
 u64 cmt_latency_data(struct perf_event *event, u64 status);
 
 void intel_pmu_pebs_sched_task(struct perf_event_pmu_context *pmu_ctx, bool sched_in);
 
+void intel_pmu_pebs_late_setup(struct cpu_hw_events *cpuc);
+
 void intel_pmu_drain_pebs_buffer(void);
 
 void intel_pmu_store_pebs_lbrs(struct lbr_entry *lbr);