Skip to contentSkip to conversation

i2c: stm32f7_i2c: save some ms in stm32_i2c_choose_solution

PATCH In review Richard Genoud 2 participants 3 messages Dec 5, 2025 – Dec 6, 2025

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

PATCH 1/1 i2c: stm32f7_i2c: save some ms in stm32_i2c_choose_solution

In stm32_i2c_choose_solution, the double loop continues even after a solution is found.

Breaking out of this double loop once a solution is found permits to gain some precious ms.

This saves about 13ms in U-Boot.

---
 drivers/i2c/stm32f7_i2c.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/i2c/stm32f7_i2c.c +2 -0
index 3f51b1dd1db4..cb5e2c0e31e5 100644
@@ -651,11 +651,13 @@ static int stm32_i2c_choose_solution(u32 i2cclk,
 						v->sclh = h;
 						sol_found = true;
 						memcpy(s, v, sizeof(*s));
+						goto end_loop;
 					}
 				}
 			}
 		}
 	}
+end_loop:
 
 	if (!sol_found) {
 		log_err("no solution at all\n");

base-commit: c5e6d2ab7eba68cbfb600cdc131c0c375ced2ec9

Signature · 1 line
2.47.3
#1 lore raw
Quoted 32 lines · Richard Genoud

In stm32_i2c_choose_solution, the double loop continues even after a solution is found.

Breaking out of this double loop once a solution is found permits to gain some precious ms.

This saves about 13ms in U-Boot.

---
 drivers/i2c/stm32f7_i2c.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/i2c/stm32f7_i2c.c +2 -0
index 3f51b1dd1db4..cb5e2c0e31e5 100644
@@ -651,11 +651,13 @@ static int stm32_i2c_choose_solution(u32 i2cclk,
 						v->sclh = h;
 						sol_found = true;
 						memcpy(s, v, sizeof(*s));
+						goto end_loop;
 					}
 				}
 			}
 		}
 	}
+end_loop:
 
 	if (!sol_found) {
 		log_err("no solution at all\n");
Quoted 1 line

base-commit: c5e6d2ab7eba68cbfb600cdc131c0c375ced2ec9

Hi Richard

If i have well understood the algorithm, the original implementation selects the *best* solution whereas with your patch, the algorithm selects the *first* solution.

Patrice

#2 lore raw

Le 05/12/2025 à 17:49, Patrice CHOTARD a écrit :

Quoted 40 lines · Richard Genoud
Quoted 32 lines

In stm32_i2c_choose_solution, the double loop continues even after a solution is found.

Breaking out of this double loop once a solution is found permits to gain some precious ms.

This saves about 13ms in U-Boot.

---
  drivers/i2c/stm32f7_i2c.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/i2c/stm32f7_i2c.c +2 -0
index 3f51b1dd1db4..cb5e2c0e31e5 100644
@@ -651,11 +651,13 @@ static int stm32_i2c_choose_solution(u32 i2cclk,
  						v->sclh = h;
  						sol_found = true;
  						memcpy(s, v, sizeof(*s));
+						goto end_loop;
  					}
  				}
  			}
  		}
  	}
+end_loop:
 
  	if (!sol_found) {
  		log_err("no solution at all\n");
Quoted 1 line

base-commit: c5e6d2ab7eba68cbfb600cdc131c0c375ced2ec9

Hi Richard

Quoted 4 lines

If i have well understood the algorithm, the original implementation selects the *best* solution whereas with your patch, the algorithm selects the *first* solution.

Patrice

Hum, indeed. The solution with the lesser error is selected.
I'll have to study this algorithm a little bit more to see it we can take some shortcut.

Thanks!

Regards,
Richard