Skip to contentSkip to conversation

usb: gadget: f_mass_storage: Optimize CTRL-C responsiveness

PATCH In review Patrice Chotard 2 participants 3 messages Sep 29 – Oct 20 USB

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 usb: gadget: f_mass_storage: Optimize CTRL-C responsiveness

On STM32MP157C-DK2, when aborting the command "ums" using CTRL-C it may take a while to get the control back on the console, sometimes around 1 second.

By removing the if (k == 10) test, it increases the CTRL+C responsiveness (around 28 ms between 2 ctrl_c() calls) and UMS throughthput is not impacted.

Tested on STM32MP157C-DK board

---
Changes in v2:
- Decrease ctrl_c() call frequency to restore ums throughput
- Link to v1: https://patch.msgid.link/20260917-ums_increase_ctrl-c_responsiveness-v1-1-95305f044ec2@foss.st.com

To: [email protected]
Cc: Lukasz Majewski <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: Patrice Chotard <[email protected]>

---
 drivers/usb/gadget/f_mass_storage.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/usb/gadget/f_mass_storage.c +1 -6
index 7eb667c130d..96581792031 100644
@@ -651,7 +651,7 @@ static void busy_indicator(void)
 static int sleep_thread(struct fsg_common *common)
 {
 	int	rc = 0;
-	int i = 0, k = 0;
+	int i = 0;
 
 	/* Wait until a signal arrives or we are woken up */
 	for (;;) {
@@ -661,10 +661,7 @@ static int sleep_thread(struct fsg_common *common)
 		if (++i == 20000) {
 			busy_indicator();
 			i = 0;
-			k++;
-		}
 
-		if (k == 10) {
 			/* Handle START-STOP UNIT */
 			if (common->eject)
 				return -EPIPE;
@@ -676,8 +673,6 @@ static int sleep_thread(struct fsg_common *common)
 			/* Check cable connection */
 			if (!g_dnl_board_usb_cable_connected())
 				return -EIO;
-
-			k = 0;
 		}
 
 		schedule();

---
base-commit: b4ac71db13a33c4e6532c60a781ddf34b7f4375a
change-id: 20260917-ums_increase_ctrl-c_responsiveness-0824bf3ede7b

Best regards,

Signature · 1 line
Patrice Chotard <[email protected]>
Reviewed-by on v2 1/1
#1 lore raw

Hi Patrice,

Thank you for the patch.
Sorry for the delay in reviewing this.

Quoted 11 lines · Patrice Chotard

On STM32MP157C-DK2, when aborting the command "ums" using CTRL-C it may take a while to get the control back on the console, sometimes around 1 second.

By removing the if (k == 10) test, it increases the CTRL+C responsiveness (around 28 ms between 2 ctrl_c() calls) and UMS throughthput is not impacted.

Tested on STM32MP157C-DK board

This looks good to me. The change is quite simple (we check for exit conditions in the for loop more frequently)

Since you tested this and posted some numbers in v1, I'm happy with this

Quoted 56 lines

---
Changes in v2:
- Decrease ctrl_c() call frequency to restore ums throughput
- Link to v1: https://patch.msgid.link/20260917-ums_increase_ctrl-c_responsiveness-v1-1-95305f044ec2@foss.st.com

To: [email protected]
Cc: Lukasz Majewski <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: Patrice Chotard <[email protected]>

---
 drivers/usb/gadget/f_mass_storage.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/usb/gadget/f_mass_storage.c +1 -7
index 7eb667c130d..96581792031 100644
@@ -651,7 +651,7 @@ static void busy_indicator(void)
 static int sleep_thread(struct fsg_common *common)
 {
 	int	rc = 0;
-	int i = 0, k = 0;
+	int i = 0;
 
 	/* Wait until a signal arrives or we are woken up */
 	for (;;) {
@@ -661,10 +661,7 @@ static int sleep_thread(struct fsg_common *common)
 		if (++i == 20000) {
 			busy_indicator();
 			i = 0;
-			k++;
-		}
 
-		if (k == 10) {
 			/* Handle START-STOP UNIT */
 			if (common->eject)
 				return -EPIPE;
@@ -676,8 +673,6 @@ static int sleep_thread(struct fsg_common *common)
 			/* Check cable connection */
 			if (!g_dnl_board_usb_cable_connected())
 				return -EIO;
-
-			k = 0;
 		}
 
 		schedule();
 
---

base-commit: b4ac71db13a33c4e6532c60a781ddf34b7f4375a
change-id: 20260917-ums_increase_ctrl-c_responsiveness-0824bf3ede7b

Best regards,

Signature · 1 line
Patrice Chotard <[email protected]>
#2 lore raw
In reply to Patrice Chotard

Hi,

Quoted 9 lines · Patrice Chotard

On STM32MP157C-DK2, when aborting the command "ums" using CTRL-C it may take a while to get the control back on the console, sometimes around 1 second.

By removing the if (k == 10) test, it increases the CTRL+C responsiveness (around 28 ms between 2 ctrl_c() calls) and UMS throughthput is not impacted.

[...]

Thanks, Applied to https://git.u-boot-project.org/u-boot/custodians/u-boot-dfu (u-boot-dfu)

[1/1] usb: gadget: f_mass_storage: Optimize CTRL-C responsiveness

      https://git.u-boot-project.org/u-boot/custodians/u-boot-dfu/-/commit/f1364f69907148907b6947e40f8b045a1105ddc5

--
Mattijs