Skip to contentSkip to conversation

perf/x86: Add cond_resched() when allocate/release DS buffers

PATCH In review Namhyung Kim 3 participants 7 messages Oct 27, 2025 – Oct 29, 2025

Subsystems (2)
lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/1 perf/x86: Add cond_resched() when allocate/release DS buffers

On large systems, it's possible to trigger sched latency warning during the DS buffer allocation or release. Add cond_resched() to avoid it.

---
 arch/x86/events/intel/ds.c | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/events/intel/ds.c +3 -0
index c0b7ac1c7594ea92..c8e90c5a8d3390ab 100644
@@ -754,6 +754,7 @@ void release_ds_buffers(void)
 		if (x86_pmu.ds_pebs)
 			release_pebs_buffer(cpu);
 		release_bts_buffer(cpu);
+		cond_resched();
 	}
 }
 
@@ -791,6 +792,8 @@ void reserve_ds_buffers(void)
 
 		if (bts_err && pebs_err)
 			break;
+
+		cond_resched();
 	}
 
 	if (bts_err) {
Signature · 1 line
2.51.1.838.g19442a804e-goog
maintainer
#1 lore raw
Quoted 2 lines · Namhyung Kim

On large systems, it's possible to trigger sched latency warning during the DS buffer allocation or release. Add cond_resched() to avoid it.

We're >.< close to deleting cond_resched(), it makes absolutely no sense adding more.

maintainer
#2 lore raw
Quoted 6 lines · Peter Zijlstra
Quoted 2 lines · Namhyung Kim

On large systems, it's possible to trigger sched latency warning during the DS buffer allocation or release. Add cond_resched() to avoid it.

We're >.< close to deleting cond_resched(), it makes absolutely no sense adding more.

Specifically, IIRC the plan was to do something like the below after the next LTS release, and then continue to remove VOLUNTARY in subsequent releases, leaving NONE the only option for the legacy architectures that do not support preemption.

kernel/Kconfig.preempt +3 -2
index da326800c1c9..db4ae53c1d49 100644
@@ -16,11 +16,12 @@ config ARCH_HAS_PREEMPT_LAZY
 
 choice
 	prompt "Preemption Model"
-	default PREEMPT_NONE
+	default PREEMPT_LAZY
 
 config PREEMPT_NONE
 	bool "No Forced Preemption (Server)"
 	depends on !PREEMPT_RT
+	depends on ARCH_NO_PREEMPT
 	select PREEMPT_NONE_BUILD if !PREEMPT_DYNAMIC
 	help
 	  This is the traditional Linux preemption model, geared towards
@@ -35,8 +36,8 @@ config PREEMPT_NONE
 
 config PREEMPT_VOLUNTARY
 	bool "Voluntary Kernel Preemption (Desktop)"
-	depends on !ARCH_NO_PREEMPT
 	depends on !PREEMPT_RT
+	depends on ARCH_NO_PREEMPT
 	select PREEMPT_VOLUNTARY_BUILD if !PREEMPT_DYNAMIC
 	help
 	  This option reduces the latency of the kernel by adding more
author maintainer
#3 lore raw

Hi Peter,

Quoted 5 lines · Peter Zijlstra
Quoted 4 lines · Peter Zijlstra
Quoted 2 lines · Namhyung Kim

On large systems, it's possible to trigger sched latency warning during the DS buffer allocation or release. Add cond_resched() to avoid it.

Quoted 7 lines
Quoted 2 lines

We're >.< close to deleting cond_resched(), it makes absolutely no sense adding more.

Specifically, IIRC the plan was to do something like the below after the next LTS release, and then continue to remove VOLUNTARY in subsequent releases, leaving NONE the only option for the legacy architectures that do not support preemption.

Thanks for your review!

I haven't followed the work in this area so was not aware of the PREEMPT_LAZY. Looks great! I hope it'll work well on server platforms with many batch jobs and interactive tasks.

I will drop my patch then.

Thanks,
Namhyung

Quoted 30 lines
kernel/Kconfig.preempt +3 -2
index da326800c1c9..db4ae53c1d49 100644
@@ -16,11 +16,12 @@ config ARCH_HAS_PREEMPT_LAZY
 
 choice
 	prompt "Preemption Model"
-	default PREEMPT_NONE
+	default PREEMPT_LAZY
 
 config PREEMPT_NONE
 	bool "No Forced Preemption (Server)"
 	depends on !PREEMPT_RT
+	depends on ARCH_NO_PREEMPT
 	select PREEMPT_NONE_BUILD if !PREEMPT_DYNAMIC
 	help
 	  This is the traditional Linux preemption model, geared towards
@@ -35,8 +36,8 @@ config PREEMPT_NONE
 
 config PREEMPT_VOLUNTARY
 	bool "Voluntary Kernel Preemption (Desktop)"
-	depends on !ARCH_NO_PREEMPT
 	depends on !PREEMPT_RT
+	depends on ARCH_NO_PREEMPT
 	select PREEMPT_VOLUNTARY_BUILD if !PREEMPT_DYNAMIC
 	help
 	  This option reduces the latency of the kernel by adding more
maintainer
#4 lore raw
Quoted 16 lines · Namhyung Kim

Hi Peter,

Quoted 5 lines · Peter Zijlstra
Quoted 4 lines · Peter Zijlstra
Quoted 2 lines · Namhyung Kim

On large systems, it's possible to trigger sched latency warning during the DS buffer allocation or release. Add cond_resched() to avoid it.

Quoted 7 lines
Quoted 2 lines

We're >.< close to deleting cond_resched(), it makes absolutely no sense adding more.

Specifically, IIRC the plan was to do something like the below after the next LTS release, and then continue to remove VOLUNTARY in subsequent releases, leaving NONE the only option for the legacy architectures that do not support preemption.

Quoted 7 lines

Thanks for your review!

I haven't followed the work in this area so was not aware of the PREEMPT_LAZY. Looks great! I hope it'll work well on server platforms with many batch jobs and interactive tasks.

I will drop my patch then.

Well, we've been trying to get people to test things... But realistically people will only test once you force them. So we'll see.

#5 lore raw
Quoted 2 lines · Peter Zijlstra

Well, we've been trying to get people to test things... But realistically people will only test once you force them. So we'll see.

| grep CONFIG_PREEMPT_LAZY /boot/config-6.16.12+deb14+1-amd64 | CONFIG_PREEMPT_LAZY=y

Debian has it enabled by default in current testing/ unstable distro. \o/

Sebastian

maintainer
#6 lore raw
Quoted 9 lines · Sebastian Andrzej Siewior
Quoted 2 lines · Peter Zijlstra

Well, we've been trying to get people to test things... But realistically people will only test once you force them. So we'll see.

| grep CONFIG_PREEMPT_LAZY /boot/config-6.16.12+deb14+1-amd64 | CONFIG_PREEMPT_LAZY=y

Debian has it enabled by default in current testing/ unstable distro. \o/

Yes, I noticed, thanks!