@@ -570,11 +570,92 @@ static __initconst const u64 p4_hw_cache_event_ids
570570 },
571571};
572572
573+ /*
574+ * Because of Netburst being quite restricted in now
575+ * many same events can run simultaneously, we use
576+ * event aliases, ie different events which have the
577+ * same functionallity but use non-intersected resources
578+ * (ESCR/CCCR/couter registers). This allow us to run
579+ * two or more semi-same events together. It is done
580+ * transparently to a user space.
581+ *
582+ * Never set any cusom internal bits such as P4_CONFIG_HT,
583+ * P4_CONFIG_ALIASABLE or bits for P4_PEBS_METRIC, they are
584+ * either up-to-dated automatically either not appliable
585+ * at all.
586+ *
587+ * And be really carefull choosing aliases!
588+ */
589+ struct p4_event_alias {
590+ u64 orig ;
591+ u64 alter ;
592+ } p4_event_aliases [] = {
593+ {
594+ /*
595+ * Non-halted cycles can be substituted with
596+ * non-sleeping cycles (see Intel SDM Vol3b for
597+ * details).
598+ */
599+ .orig =
600+ p4_config_pack_escr (P4_ESCR_EVENT (P4_EVENT_GLOBAL_POWER_EVENTS ) |
601+ P4_ESCR_EMASK_BIT (P4_EVENT_GLOBAL_POWER_EVENTS , RUNNING )),
602+ .alter =
603+ p4_config_pack_escr (P4_ESCR_EVENT (P4_EVENT_EXECUTION_EVENT ) |
604+ P4_ESCR_EMASK_BIT (P4_EVENT_EXECUTION_EVENT , NBOGUS0 )|
605+ P4_ESCR_EMASK_BIT (P4_EVENT_EXECUTION_EVENT , NBOGUS1 )|
606+ P4_ESCR_EMASK_BIT (P4_EVENT_EXECUTION_EVENT , NBOGUS2 )|
607+ P4_ESCR_EMASK_BIT (P4_EVENT_EXECUTION_EVENT , NBOGUS3 )|
608+ P4_ESCR_EMASK_BIT (P4_EVENT_EXECUTION_EVENT , BOGUS0 ) |
609+ P4_ESCR_EMASK_BIT (P4_EVENT_EXECUTION_EVENT , BOGUS1 ) |
610+ P4_ESCR_EMASK_BIT (P4_EVENT_EXECUTION_EVENT , BOGUS2 ) |
611+ P4_ESCR_EMASK_BIT (P4_EVENT_EXECUTION_EVENT , BOGUS3 ))|
612+ p4_config_pack_cccr (P4_CCCR_THRESHOLD (15 ) | P4_CCCR_COMPLEMENT |
613+ P4_CCCR_COMPARE ),
614+ },
615+ };
616+
617+ static u64 p4_get_alias_event (u64 config )
618+ {
619+ u64 config_match ;
620+ int i ;
621+
622+ /*
623+ * Probably we're lucky and don't have to do
624+ * matching over all config bits.
625+ */
626+ if (!(config & P4_CONFIG_ALIASABLE ))
627+ return 0 ;
628+
629+ config_match = config & P4_CONFIG_EVENT_ALIAS_MASK ;
630+
631+ /*
632+ * If an event was previously swapped to the alter config
633+ * we should swap it back otherwise contnention on registers
634+ * will return back.
635+ */
636+ for (i = 0 ; i < ARRAY_SIZE (p4_event_aliases ); i ++ ) {
637+ if (config_match == p4_event_aliases [i ].orig ) {
638+ config_match = p4_event_aliases [i ].alter ;
639+ break ;
640+ } else if (config_match == p4_event_aliases [i ].alter ) {
641+ config_match = p4_event_aliases [i ].orig ;
642+ break ;
643+ }
644+ }
645+
646+ if (i >= ARRAY_SIZE (p4_event_aliases ))
647+ return 0 ;
648+
649+ return config_match |
650+ (config & P4_CONFIG_EVENT_ALIAS_IMMUTABLE_BITS );
651+ }
652+
573653static u64 p4_general_events [PERF_COUNT_HW_MAX ] = {
574654 /* non-halted CPU clocks */
575655 [PERF_COUNT_HW_CPU_CYCLES ] =
576656 p4_config_pack_escr (P4_ESCR_EVENT (P4_EVENT_GLOBAL_POWER_EVENTS ) |
577- P4_ESCR_EMASK_BIT (P4_EVENT_GLOBAL_POWER_EVENTS , RUNNING )),
657+ P4_ESCR_EMASK_BIT (P4_EVENT_GLOBAL_POWER_EVENTS , RUNNING )) |
658+ P4_CONFIG_ALIASABLE ,
578659
579660 /*
580661 * retired instructions
@@ -719,31 +800,6 @@ static int p4_validate_raw_event(struct perf_event *event)
719800 return 0 ;
720801}
721802
722- static void p4_hw_watchdog_set_attr (struct perf_event_attr * wd_attr )
723- {
724- /*
725- * Watchdog ticks are special on Netburst, we use
726- * that named "non-sleeping" ticks as recommended
727- * by Intel SDM Vol3b.
728- */
729- WARN_ON_ONCE (wd_attr -> type != PERF_TYPE_HARDWARE ||
730- wd_attr -> config != PERF_COUNT_HW_CPU_CYCLES );
731-
732- wd_attr -> type = PERF_TYPE_RAW ;
733- wd_attr -> config =
734- p4_config_pack_escr (P4_ESCR_EVENT (P4_EVENT_EXECUTION_EVENT ) |
735- P4_ESCR_EMASK_BIT (P4_EVENT_EXECUTION_EVENT , NBOGUS0 ) |
736- P4_ESCR_EMASK_BIT (P4_EVENT_EXECUTION_EVENT , NBOGUS1 ) |
737- P4_ESCR_EMASK_BIT (P4_EVENT_EXECUTION_EVENT , NBOGUS2 ) |
738- P4_ESCR_EMASK_BIT (P4_EVENT_EXECUTION_EVENT , NBOGUS3 ) |
739- P4_ESCR_EMASK_BIT (P4_EVENT_EXECUTION_EVENT , BOGUS0 ) |
740- P4_ESCR_EMASK_BIT (P4_EVENT_EXECUTION_EVENT , BOGUS1 ) |
741- P4_ESCR_EMASK_BIT (P4_EVENT_EXECUTION_EVENT , BOGUS2 ) |
742- P4_ESCR_EMASK_BIT (P4_EVENT_EXECUTION_EVENT , BOGUS3 )) |
743- p4_config_pack_cccr (P4_CCCR_THRESHOLD (15 ) | P4_CCCR_COMPLEMENT |
744- P4_CCCR_COMPARE );
745- }
746-
747803static int p4_hw_config (struct perf_event * event )
748804{
749805 int cpu = get_cpu ();
@@ -1159,6 +1215,8 @@ static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign
11591215 struct p4_event_bind * bind ;
11601216 unsigned int i , thread , num ;
11611217 int cntr_idx , escr_idx ;
1218+ u64 config_alias ;
1219+ int pass ;
11621220
11631221 bitmap_zero (used_mask , X86_PMC_IDX_MAX );
11641222 bitmap_zero (escr_mask , P4_ESCR_MSR_TABLE_SIZE );
@@ -1167,6 +1225,17 @@ static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign
11671225
11681226 hwc = & cpuc -> event_list [i ]-> hw ;
11691227 thread = p4_ht_thread (cpu );
1228+ pass = 0 ;
1229+
1230+ again :
1231+ /*
1232+ * Aliases are swappable so we may hit circular
1233+ * lock if both original config and alias need
1234+ * resources (MSR registers) which already busy.
1235+ */
1236+ if (pass > 2 )
1237+ goto done ;
1238+
11701239 bind = p4_config_get_bind (hwc -> config );
11711240 escr_idx = p4_get_escr_idx (bind -> escr_msr [thread ]);
11721241 if (unlikely (escr_idx == -1 ))
@@ -1180,8 +1249,17 @@ static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign
11801249 }
11811250
11821251 cntr_idx = p4_next_cntr (thread , used_mask , bind );
1183- if (cntr_idx == -1 || test_bit (escr_idx , escr_mask ))
1184- goto done ;
1252+ if (cntr_idx == -1 || test_bit (escr_idx , escr_mask )) {
1253+ /*
1254+ * Probably an event alias is still available.
1255+ */
1256+ config_alias = p4_get_alias_event (hwc -> config );
1257+ if (!config_alias )
1258+ goto done ;
1259+ hwc -> config = config_alias ;
1260+ pass ++ ;
1261+ goto again ;
1262+ }
11851263
11861264 p4_pmu_swap_config_ts (hwc , cpu );
11871265 if (assign )
@@ -1218,7 +1296,6 @@ static __initconst const struct x86_pmu p4_pmu = {
12181296 .cntval_bits = ARCH_P4_CNTRVAL_BITS ,
12191297 .cntval_mask = ARCH_P4_CNTRVAL_MASK ,
12201298 .max_period = (1ULL << (ARCH_P4_CNTRVAL_BITS - 1 )) - 1 ,
1221- .hw_watchdog_set_attr = p4_hw_watchdog_set_attr ,
12221299 .hw_config = p4_hw_config ,
12231300 .schedule_events = p4_pmu_schedule_events ,
12241301 /*
0 commit comments