Skip to contentSkip to conversation

perf_events: improve DS/BTS/PEBS buffer allocation (v2)

PATCH New Stephane Eranian 1 participant 1 message Sep 17, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf_events: improve DS/BTS/PEBS buffer allocation (v2)

The DS, BTS, and PEBS memory regions were allocated using kzalloc(), i.e., requesting contiguous physical memory. There is no such restriction on DS, PEBS and BTS buffers.

Using kzalloc() could lead to error in case no contiguous physical memory is available. BTS is requesting 64KB, thus it can cause issues. PEBS is currently only requesting one page. Both PEBS and BTS are static buffers allocated for each CPU at the first user. When the last user exists, the buffers are released.

All buffers are only accessed on the CPU they are attached to. kzalloc() does not take into account NUMA, thus all allocations are taking place on the NUMA node where the first perf_event_open() is made.

This second version of the patch switches the allocation to kmalloc_node() to fix the NUMA imbalance. Because of current limitations on vmalloc(), we cannot use it to avoid allocating contiguous physical memory.

This patch also avoids failure perf_event_open() in case DS, PEBS, or BTS buffer cannot be allocated AND the event does not need those HW features.

--

arch/x86/kernel/cpu/perf_event.c +13 -14
index 0fb1705..c289c2c 100644
@@ -237,6 +237,7 @@ struct x86_pmu {
 	 * Intel DebugStore bits
 	 */
 	int		bts, pebs;
+	int		bts_activated, pebs_activated;
 	int		pebs_record_size;
 	void		(*drain_pebs)(struct pt_regs *regs);
 	struct event_constraint *pebs_constraints;
@@ -380,7 +381,7 @@ static void release_pmc_hardware(void) {}
 
 #endif
 
-static int reserve_ds_buffers(void);
+static void reserve_ds_buffers(void);
 static void release_ds_buffers(void);
 
 static void hw_perf_event_destroy(struct perf_event *event)
@@ -477,7 +478,7 @@ static int x86_setup_perfctr(struct perf_event *event)
 	if ((attr->config == PERF_COUNT_HW_BRANCH_INSTRUCTIONS) &&
 	    (hwc->sample_period == 1)) {
 		/* BTS is not supported by this architecture. */
-		if (!x86_pmu.bts)
+		if (!x86_pmu.bts_activated)
 			return -EOPNOTSUPP;
 
 		/* BTS is currently only allowed for user-mode. */
@@ -492,18 +493,19 @@ static int x86_setup_perfctr(struct perf_event *event)
 
 static int x86_pmu_hw_config(struct perf_event *event)
 {
-	if (event->attr.precise_ip) {
-		int precise = 0;
+	int p = event->attr.precise_ip;
 
+	if (p) {
 		/* Support for constant skid */
-		if (x86_pmu.pebs)
-			precise++;
+		if (p < 3 && !x86_pmu.pebs_activated)
+			return -EOPNOTSUPP;
 
 		/* Support for IP fixup */
-		if (x86_pmu.lbr_nr)
-			precise++;
+		if (p == 2 && !x86_pmu.lbr_nr)
+			return -EOPNOTSUPP;
 
-		if (event->attr.precise_ip > precise)
+		/* Support for zero skid */
+		if (p > 2)
 			return -EOPNOTSUPP;
 	}
 
@@ -543,11 +545,8 @@ static int __x86_pmu_event_init(struct perf_event *event)
 		if (atomic_read(&active_events) == 0) {
 			if (!reserve_pmc_hardware())
 				err = -EBUSY;
-			else {
-				err = reserve_ds_buffers();
-				if (err)
-					release_pmc_hardware();
-			}
+			else
+				reserve_ds_buffers();
 		}
 		if (!err)
 			atomic_inc(&active_events);
arch/x86/kernel/cpu/perf_event_intel_ds.c +145 -44

245 lines not on this page · raw message