* [PATCH 1/3] drm/panic: Check QR alignment centers one axis at a time
2026-11-26 16:53 [PATCH 0/3] drm/panic: Speed up QR code encoding Peder Bergan via B4 Relay
@ 2026-11-26 16:53 ` Peder Bergan via B4 Relay
2026-11-27 12:41 ` Jocelyn Falempe
2026-11-26 16:53 ` [PATCH 2/3] drm/panic: Apply the QR mask while drawing data modules Peder Bergan via B4 Relay
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Peder Bergan via B4 Relay @ 2026-11-26 16:53 UTC (permalink / raw)
To: Jocelyn Falempe, Javier Martinez Canillas
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, dri-devel,
rust-for-linux, linux-kernel
From: Peder Bergan <peder.bergan@gmail.com>
is_alignment() scans pairs of alignment centers each time it tests
whether a module is reserved. At version 40 there are seven centers
per axis, so a lookup can visit 49 pairs.
Each center covers a five-module span, and adjacent centers are at
least 12 modules apart. Find the unique matching center on each axis
and apply the existing finder-pattern exclusion to that pair. The
lookup now needs at most 14 center tests.
Signed-off-by: Peder Bergan <peder.bergan@gmail.com>
---
drivers/gpu/drm/drm_panic_helper_qr.rs | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/drivers/gpu/drm/drm_panic_helper_qr.rs b/drivers/gpu/drm/drm_panic_helper_qr.rs
index 4941731fb60fa..c6ed395c05bd2 100644
--- a/drivers/gpu/drm/drm_panic_helper_qr.rs
+++ b/drivers/gpu/drm/drm_panic_helper_qr.rs
@@ -746,17 +746,14 @@ fn draw_alignments(&mut self) {
fn is_alignment(&self, x: u8, y: u8) -> bool {
let positions = self.version.alignment_pattern();
- for &ax in positions.iter() {
- for &ay in positions.iter() {
- if self.is_finder(ax, ay) {
- continue;
- }
- if x >= ax - 2 && x <= ax + 2 && y >= ay - 2 && y <= ay + 2 {
- return true;
- }
- }
- }
- false
+ // Centers are at least 12 modules apart, so their five-module spans are disjoint.
+ let Some(&ax) = positions.iter().find(|&¢er| x.abs_diff(center) <= 2) else {
+ return false;
+ };
+ let Some(&ay) = positions.iter().find(|&¢er| y.abs_diff(center) <= 2) else {
+ return false;
+ };
+ !self.is_finder(ax, ay)
}
// Timing pattern: 2 dotted line between the finder patterns.
--
2.56.1
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 1/3] drm/panic: Check QR alignment centers one axis at a time
2026-11-26 16:53 ` [PATCH 1/3] drm/panic: Check QR alignment centers one axis at a time Peder Bergan via B4 Relay
@ 2026-11-27 12:41 ` Jocelyn Falempe
0 siblings, 0 replies; 8+ messages in thread
From: Jocelyn Falempe @ 2026-11-27 12:41 UTC (permalink / raw)
To: peder.bergan, Javier Martinez Canillas
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, dri-devel,
rust-for-linux, linux-kernel
On 11/26/26 17:53, Peder Bergan via B4 Relay wrote:
> From: Peder Bergan <peder.bergan@gmail.com>
>
> is_alignment() scans pairs of alignment centers each time it tests
> whether a module is reserved. At version 40 there are seven centers
> per axis, so a lookup can visit 49 pairs.
>
> Each center covers a five-module span, and adjacent centers are at
> least 12 modules apart. Find the unique matching center on each axis
> and apply the existing finder-pattern exclusion to that pair. The
> lookup now needs at most 14 center tests.
Thanks for your contribution.
This code is executed only once when a panic occurs, so optimizations
are clearly not a priority.
But this series looks good, and keeps the code simple.
Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com>
>
> Signed-off-by: Peder Bergan <peder.bergan@gmail.com>
> ---
> drivers/gpu/drm/drm_panic_helper_qr.rs | 19 ++++++++-----------
> 1 file changed, 8 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_panic_helper_qr.rs b/drivers/gpu/drm/drm_panic_helper_qr.rs
> index 4941731fb60fa..c6ed395c05bd2 100644
> --- a/drivers/gpu/drm/drm_panic_helper_qr.rs
> +++ b/drivers/gpu/drm/drm_panic_helper_qr.rs
> @@ -746,17 +746,14 @@ fn draw_alignments(&mut self) {
>
> fn is_alignment(&self, x: u8, y: u8) -> bool {
> let positions = self.version.alignment_pattern();
> - for &ax in positions.iter() {
> - for &ay in positions.iter() {
> - if self.is_finder(ax, ay) {
> - continue;
> - }
> - if x >= ax - 2 && x <= ax + 2 && y >= ay - 2 && y <= ay + 2 {
> - return true;
> - }
> - }
> - }
> - false
> + // Centers are at least 12 modules apart, so their five-module spans are disjoint.
> + let Some(&ax) = positions.iter().find(|&¢er| x.abs_diff(center) <= 2) else {
> + return false;
> + };
> + let Some(&ay) = positions.iter().find(|&¢er| y.abs_diff(center) <= 2) else {
> + return false;
> + };
> + !self.is_finder(ax, ay)
> }
>
> // Timing pattern: 2 dotted line between the finder patterns.
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/3] drm/panic: Apply the QR mask while drawing data modules
2026-11-26 16:53 [PATCH 0/3] drm/panic: Speed up QR code encoding Peder Bergan via B4 Relay
2026-11-26 16:53 ` [PATCH 1/3] drm/panic: Check QR alignment centers one axis at a time Peder Bergan via B4 Relay
@ 2026-11-26 16:53 ` Peder Bergan via B4 Relay
2026-11-27 12:42 ` Jocelyn Falempe
2026-11-26 16:53 ` [PATCH 3/3] drm/panic: Simplify QR error correction exponent reduction Peder Bergan via B4 Relay
2026-12-03 14:50 ` [PATCH 0/3] drm/panic: Speed up QR code encoding Jocelyn Falempe
3 siblings, 1 reply; 8+ messages in thread
From: Peder Bergan via B4 Relay @ 2026-11-26 16:53 UTC (permalink / raw)
To: Jocelyn Falempe, Javier Martinez Canillas
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, dri-devel,
rust-for-linux, linux-kernel
From: Peder Bergan <peder.bergan@gmail.com>
After placing data and remainder modules, apply_mask() scans the whole
image to invert the unreserved modules covered by checkerboard mask 0.
Data placement already visits every unreserved module once.
Apply mask 0 while drawing each data module and each zero-valued
remainder module. This removes the separate image pass and its buffer
read-modify-write operations. The format information still advertises
mask 0.
Signed-off-by: Peder Bergan <peder.bergan@gmail.com>
---
drivers/gpu/drm/drm_panic_helper_qr.rs | 35 +++++++++++-----------------------
1 file changed, 11 insertions(+), 24 deletions(-)
diff --git a/drivers/gpu/drm/drm_panic_helper_qr.rs b/drivers/gpu/drm/drm_panic_helper_qr.rs
index c6ed395c05bd2..1d96ae855052a 100644
--- a/drivers/gpu/drm/drm_panic_helper_qr.rs
+++ b/drivers/gpu/drm/drm_panic_helper_qr.rs
@@ -691,12 +691,6 @@ fn set(&mut self, x: u8, y: u8) {
self.data[off] = v;
}
- /// Invert a module color.
- fn xor(&mut self, x: u8, y: u8) {
- let off = y as usize * self.stride as usize + x as usize / 8;
- self.data[off] ^= 0x80 >> (x % 8);
- }
-
/// Draw a light square at (x, y) top left corner.
fn draw_square(&mut self, x: u8, y: u8, size: u8) {
for k in 0..size {
@@ -864,37 +858,31 @@ fn next_available(&self, x: u8, y: u8) -> (u8, u8) {
(x, y)
}
+ /// Draw an unreserved module with checkerboard mask 0.
+ fn draw_data_module(&mut self, x: u8, y: u8, bit: bool) {
+ let invert = (x ^ y) % 2 == 0;
+ if !(bit ^ invert) {
+ self.set(x, y);
+ }
+ }
+
fn draw_data(&mut self, data: impl Iterator<Item = u8>) {
let (mut x, mut y) = (self.width - 1, self.width - 1);
for byte in data {
for s in 0..8 {
- if byte & (0x80 >> s) == 0 {
- self.set(x, y);
- }
+ self.draw_data_module(x, y, byte & (0x80 >> s) != 0);
(x, y) = self.next_available(x, y);
}
}
- // Set the remaining modules (0, 3 or 7 depending on version).
- // because 0 correspond to a light module.
+ // The remaining modules encode zero before masking.
while !self.is_last(x, y) {
if !self.is_reserved(x, y) {
- self.set(x, y);
+ self.draw_data_module(x, y, false);
}
(x, y) = self.next(x, y);
}
}
- /// Apply checkerboard mask to all non-reserved modules.
- fn apply_mask(&mut self) {
- for x in 0..self.width {
- for y in 0..self.width {
- if (x ^ y) % 2 == 0 && !self.is_reserved(x, y) {
- self.xor(x, y);
- }
- }
- }
- }
-
/// Draw the QR code with the provided data iterator.
fn draw_all(&mut self, data: impl Iterator<Item = u8>) {
// First clear the table, as it may have already some data.
@@ -905,7 +893,6 @@ fn draw_all(&mut self, data: impl Iterator<Item = u8>) {
self.draw_version_info();
self.draw_data(data);
self.draw_maskinfo();
- self.apply_mask();
}
}
--
2.56.1
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 2/3] drm/panic: Apply the QR mask while drawing data modules
2026-11-26 16:53 ` [PATCH 2/3] drm/panic: Apply the QR mask while drawing data modules Peder Bergan via B4 Relay
@ 2026-11-27 12:42 ` Jocelyn Falempe
0 siblings, 0 replies; 8+ messages in thread
From: Jocelyn Falempe @ 2026-11-27 12:42 UTC (permalink / raw)
To: peder.bergan, Javier Martinez Canillas
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, dri-devel,
rust-for-linux, linux-kernel
On 11/26/26 17:53, Peder Bergan via B4 Relay wrote:
> From: Peder Bergan <peder.bergan@gmail.com>
>
> After placing data and remainder modules, apply_mask() scans the whole
> image to invert the unreserved modules covered by checkerboard mask 0.
> Data placement already visits every unreserved module once.
>
> Apply mask 0 while drawing each data module and each zero-valued
> remainder module. This removes the separate image pass and its buffer
> read-modify-write operations. The format information still advertises
> mask 0.
>
Thanks for your contribution.
This code is executed only once when a panic occurs, so optimizations
are clearly not a priority.
But this series looks good, and keeps the code simple.
Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com>
> Signed-off-by: Peder Bergan <peder.bergan@gmail.com>
> ---
> drivers/gpu/drm/drm_panic_helper_qr.rs | 35 +++++++++++-----------------------
> 1 file changed, 11 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_panic_helper_qr.rs b/drivers/gpu/drm/drm_panic_helper_qr.rs
> index c6ed395c05bd2..1d96ae855052a 100644
> --- a/drivers/gpu/drm/drm_panic_helper_qr.rs
> +++ b/drivers/gpu/drm/drm_panic_helper_qr.rs
> @@ -691,12 +691,6 @@ fn set(&mut self, x: u8, y: u8) {
> self.data[off] = v;
> }
>
> - /// Invert a module color.
> - fn xor(&mut self, x: u8, y: u8) {
> - let off = y as usize * self.stride as usize + x as usize / 8;
> - self.data[off] ^= 0x80 >> (x % 8);
> - }
> -
> /// Draw a light square at (x, y) top left corner.
> fn draw_square(&mut self, x: u8, y: u8, size: u8) {
> for k in 0..size {
> @@ -864,37 +858,31 @@ fn next_available(&self, x: u8, y: u8) -> (u8, u8) {
> (x, y)
> }
>
> + /// Draw an unreserved module with checkerboard mask 0.
> + fn draw_data_module(&mut self, x: u8, y: u8, bit: bool) {
> + let invert = (x ^ y) % 2 == 0;
> + if !(bit ^ invert) {
> + self.set(x, y);
> + }
> + }
> +
> fn draw_data(&mut self, data: impl Iterator<Item = u8>) {
> let (mut x, mut y) = (self.width - 1, self.width - 1);
> for byte in data {
> for s in 0..8 {
> - if byte & (0x80 >> s) == 0 {
> - self.set(x, y);
> - }
> + self.draw_data_module(x, y, byte & (0x80 >> s) != 0);
> (x, y) = self.next_available(x, y);
> }
> }
> - // Set the remaining modules (0, 3 or 7 depending on version).
> - // because 0 correspond to a light module.
> + // The remaining modules encode zero before masking.
> while !self.is_last(x, y) {
> if !self.is_reserved(x, y) {
> - self.set(x, y);
> + self.draw_data_module(x, y, false);
> }
> (x, y) = self.next(x, y);
> }
> }
>
> - /// Apply checkerboard mask to all non-reserved modules.
> - fn apply_mask(&mut self) {
> - for x in 0..self.width {
> - for y in 0..self.width {
> - if (x ^ y) % 2 == 0 && !self.is_reserved(x, y) {
> - self.xor(x, y);
> - }
> - }
> - }
> - }
> -
> /// Draw the QR code with the provided data iterator.
> fn draw_all(&mut self, data: impl Iterator<Item = u8>) {
> // First clear the table, as it may have already some data.
> @@ -905,7 +893,6 @@ fn draw_all(&mut self, data: impl Iterator<Item = u8>) {
> self.draw_version_info();
> self.draw_data(data);
> self.draw_maskinfo();
> - self.apply_mask();
> }
> }
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/3] drm/panic: Simplify QR error correction exponent reduction
2026-11-26 16:53 [PATCH 0/3] drm/panic: Speed up QR code encoding Peder Bergan via B4 Relay
2026-11-26 16:53 ` [PATCH 1/3] drm/panic: Check QR alignment centers one axis at a time Peder Bergan via B4 Relay
2026-11-26 16:53 ` [PATCH 2/3] drm/panic: Apply the QR mask while drawing data modules Peder Bergan via B4 Relay
@ 2026-11-26 16:53 ` Peder Bergan via B4 Relay
2026-11-27 12:42 ` Jocelyn Falempe
2026-12-03 14:50 ` [PATCH 0/3] drm/panic: Speed up QR code encoding Jocelyn Falempe
3 siblings, 1 reply; 8+ messages in thread
From: Peder Bergan via B4 Relay @ 2026-11-26 16:53 UTC (permalink / raw)
To: Jocelyn Falempe, Javier Martinez Canillas
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, dri-devel,
rust-for-linux, linux-kernel
From: Peder Bergan <peder.bergan@gmail.com>
Reed-Solomon error correction reduces the sum of two GF(256) exponents
modulo 255 for each generator coefficient. Both exponents are below
255, so the sum needs at most one subtraction.
Use a conditional subtraction for the reduction. In the x86-64
userspace benchmark, this replaces a multiply-and-shift sequence with
a comparison and conditional moves. On top of the first two patches,
the change saved about 32 us per version-40 encode with raw input and
31 us with a URL.
Signed-off-by: Peder Bergan <peder.bergan@gmail.com>
---
drivers/gpu/drm/drm_panic_helper_qr.rs | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/drm_panic_helper_qr.rs b/drivers/gpu/drm/drm_panic_helper_qr.rs
index 1d96ae855052a..4ba2e3de5a6b6 100644
--- a/drivers/gpu/drm/drm_panic_helper_qr.rs
+++ b/drivers/gpu/drm/drm_panic_helper_qr.rs
@@ -569,7 +569,10 @@ fn error_code_for_blocks(&mut self, offset: usize, size: usize, ec_offset: usize
}
let log_lead_coeff = usize::from(LOG_TABLE[lead_coeff]);
for (u, &v) in tmp[i + 1..].iter_mut().zip(self.poly.iter()) {
- *u ^= EXP_TABLE[(usize::from(v) + log_lead_coeff) % 255];
+ // Both exponents are below 255, so at most one subtraction is needed.
+ let sum = usize::from(v) + log_lead_coeff;
+ let index = if sum >= 255 { sum - 255 } else { sum };
+ *u ^= EXP_TABLE[index];
}
}
self.data[ec_offset..ec_offset + self.ec_size]
--
2.56.1
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 3/3] drm/panic: Simplify QR error correction exponent reduction
2026-11-26 16:53 ` [PATCH 3/3] drm/panic: Simplify QR error correction exponent reduction Peder Bergan via B4 Relay
@ 2026-11-27 12:42 ` Jocelyn Falempe
0 siblings, 0 replies; 8+ messages in thread
From: Jocelyn Falempe @ 2026-11-27 12:42 UTC (permalink / raw)
To: peder.bergan, Javier Martinez Canillas
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, dri-devel,
rust-for-linux, linux-kernel
On 11/26/26 17:53, Peder Bergan via B4 Relay wrote:
> From: Peder Bergan <peder.bergan@gmail.com>
>
> Reed-Solomon error correction reduces the sum of two GF(256) exponents
> modulo 255 for each generator coefficient. Both exponents are below
> 255, so the sum needs at most one subtraction.
>
> Use a conditional subtraction for the reduction. In the x86-64
> userspace benchmark, this replaces a multiply-and-shift sequence with
> a comparison and conditional moves. On top of the first two patches,
> the change saved about 32 us per version-40 encode with raw input and
> 31 us with a URL.
Thanks for your contribution.
This code is executed only once when a panic occurs, so optimizations
are clearly not a priority.
But this series looks good, and keep the code simple.
Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com>
>
> Signed-off-by: Peder Bergan <peder.bergan@gmail.com>
> ---
> drivers/gpu/drm/drm_panic_helper_qr.rs | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_panic_helper_qr.rs b/drivers/gpu/drm/drm_panic_helper_qr.rs
> index 1d96ae855052a..4ba2e3de5a6b6 100644
> --- a/drivers/gpu/drm/drm_panic_helper_qr.rs
> +++ b/drivers/gpu/drm/drm_panic_helper_qr.rs
> @@ -569,7 +569,10 @@ fn error_code_for_blocks(&mut self, offset: usize, size: usize, ec_offset: usize
> }
> let log_lead_coeff = usize::from(LOG_TABLE[lead_coeff]);
> for (u, &v) in tmp[i + 1..].iter_mut().zip(self.poly.iter()) {
> - *u ^= EXP_TABLE[(usize::from(v) + log_lead_coeff) % 255];
> + // Both exponents are below 255, so at most one subtraction is needed.
> + let sum = usize::from(v) + log_lead_coeff;
> + let index = if sum >= 255 { sum - 255 } else { sum };
> + *u ^= EXP_TABLE[index];
> }
> }
> self.data[ec_offset..ec_offset + self.ec_size]
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/3] drm/panic: Speed up QR code encoding
2026-11-26 16:53 [PATCH 0/3] drm/panic: Speed up QR code encoding Peder Bergan via B4 Relay
` (2 preceding siblings ...)
2026-11-26 16:53 ` [PATCH 3/3] drm/panic: Simplify QR error correction exponent reduction Peder Bergan via B4 Relay
@ 2026-12-03 14:50 ` Jocelyn Falempe
3 siblings, 0 replies; 8+ messages in thread
From: Jocelyn Falempe @ 2026-12-03 14:50 UTC (permalink / raw)
To: peder.bergan, Javier Martinez Canillas
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, dri-devel,
rust-for-linux, linux-kernel
On 11/26/26 17:53, Peder Bergan via B4 Relay wrote:
> The DRM panic helper encodes kernel log data into a QR code. Speed up
> encoding by searching alignment centers per axis, applying fixed mask 0
> during data placement, and simplifying exponent reduction in
> Reed-Solomon error correction.
>
> I benchmarked the extracted encoder with Rust 1.100.0 on an x86-64
> Ryzen 7 9800X3D. Across 12 paired warm runs per workload, median
> version-40 encoding time fell from 1.778 ms to 0.277 ms with a
> 2,900-byte raw payload and from 1.782 ms to 0.284 ms with a URL and
> a 2,800-byte payload encoded in numeric mode. Both workloads produced
> identical QR images. The timings cover encoding only. Log collection,
> compression and framebuffer drawing were outside the benchmark.
>
> In the differential checks, each patch preserved the returned width
> and all output bytes across 6,002 raw and URL test inputs. The mask
> traversal check covered all 40 QR versions, including the remainder
> modules.
>
> I also ran the drm_panic_helper KUnit suite in x86-64 QEMU/KVM with
> the QR URL empty and with a URL configured. Both runs passed all 45
> checks, including 15 QR cases.
I pushed it to drm-misc-next.
Thanks for your contribution.
Best regards,
--
Jocelyn>
> ---
> OpenAI Codex assisted with coding and testing.
>
> ---
> Peder Bergan (3):
> drm/panic: Check QR alignment centers one axis at a time
> drm/panic: Apply the QR mask while drawing data modules
> drm/panic: Simplify QR error correction exponent reduction
>
> drivers/gpu/drm/drm_panic_helper_qr.rs | 59 +++++++++++++---------------------
> 1 file changed, 23 insertions(+), 36 deletions(-)
> ---
> base-commit: 5ce32a0c94a827ff44ee60898c28060714dcff75
> change-id: 20261126-perf-drm-panic-qr-58b69ed0f455
>
> Best regards,
> --
> Peder Bergan <peder.bergan@gmail.com>
^ permalink raw reply [flat|nested] 8+ messages in thread