usb: gadget: f_mass_storage: Optimize CTRL-C responsiveness
PATCH 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.
Tested on STM32MP157C-DK board.
--- drivers/usb/gadget/f_mass_storage.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-)
drivers/usb/gadget/f_mass_storage.c +10 -15
@@ -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,24 +661,19 @@ 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 ; +/* Handle START-STOP UNIT */ +if (common->eject) +return -EPIPE ; -/* Handle CTRL+C */ -if (ctrlc ()) -return -EPIPE ; +/* Handle CTRL+C */ +if (ctrlc ()) +return -EPIPE ; -/* Check cable connection */ -if (!g_dnl_board_usb_cable_connected ()) -return -EIO ; - - k =0 ; - } +/* Check cable connection */ +if (!g_dnl_board_usb_cable_connected ()) +return -EIO ;schedule ();dm_usb_gadget_handle_interrupts (udcdev);
---
base-commit: b4ac71db13a33c4e6532c60a781ddf34b7f4375a
change-id: 20260917-ums_increase_ctrl-c_responsiveness-0824bf3ede7b
Best regards,
Signature · 1 line
Patrice Chotard <[email protected]>
Quoted 7 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.
Tested on STM32MP157C-DK board.
I still have two questions:
First, do you have actual timing figures here -- how long did it take from one ctrl_c() invocation to the next ctrl_c() invocation. Use e.g. get_timer_us() to time this.
Second, does this increase in break condition checking impact throughput of the UMS ?
Quoted 5 lines · Marek Vasut
Quoted 4 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.
Quoted 8 lines
Quoted 3 lines
By removing the if (k == 10) test, it increases the CTRL+C responsiveness.
Tested on STM32MP157C-DK board.
I still have two questions:
First, do you have actual timing figures here -- how long did it take from one
ctrl_c()invocation to the nextctrl_c()invocation. Use e.g.get_timer_us()to time this.Second, does this increase in break condition checking impact throughput of the UMS ?
Hi Marek
Time between 2 ctrl_c() invocation is around 100us, way to fast in my opinion.
UMS throughput is slightly impacted :
before : 7.35 MB/s
after : 7.17 MB/s
A better balance can be obtained with the following update :
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 (;;) {
if (common->thread_wakeup_needed)
break;
if (++i == 20000) {
busy_indicator();
i = 0;
- k++;
- }
- if (k == 10) {
/* Handle START-STOP UNIT */ if (common->eject)
return -EPIPE;
/* Handle CTRL+C */
if (ctrlc())
return -EPIPE;
/* Check cable connection */ if (!g_dnl_board_usb_cable_connected())
return -EIO;
-
- k = 0;
}
schedule(); dm_usb_gadget_handle_interrupts(udcdev);
}
Time between 2 ctrl_c() invocation is around 28ms. UMS throughput is not impacted (still around 7.35 MB/s)
I will send a v2.
Patrice
Quoted 48 lines · Patrice CHOTARD
Quoted 5 lines · Marek Vasut
Quoted 4 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.
Quoted 8 lines
Quoted 3 lines
By removing the if (k == 10) test, it increases the CTRL+C responsiveness.
Tested on STM32MP157C-DK board.
I still have two questions:
First, do you have actual timing figures here -- how long did it take from one
ctrl_c()invocation to the nextctrl_c()invocation. Use e.g.get_timer_us()to time this.Second, does this increase in break condition checking impact throughput of the UMS ?
Hi Marek
Time between 2
ctrl_c()invocation is around 100us, way to fast in my opinion.UMS throughput is slightly impacted :
before : 7.35 MB/s
after : 7.17 MB/sA better balance can be obtained with the following update :
static int
sleep_thread(struct fsg_common *common)
{
int rc = 0;(quoted diff) +1
-4- int i = 0, k = 0; + int i = 0; /* Wait until a signal arrives or we are woken up */ for (;;) { if (common->thread_wakeup_needed) break; if (++i == 20000) { busy_indicator(); i = 0; - k++; - } - if (k == 10) { /* Handle START-STOP UNIT */ if (common->eject) return -EPIPE;
Review
Quoted 10 lines
(quoted diff) +0
-2/* Handle CTRL+C */ if (ctrlc()) return -EPIPE; /* Check cable connection */ if (!g_dnl_board_usb_cable_connected()) return -EIO; - - k = 0;
If k is not reset here, then the ++i==20000 above triggers only once ?
Quoted 11 lines
} schedule(); dm_usb_gadget_handle_interrupts(udcdev); }Time between 2
ctrl_c()invocation is around 28ms. UMS throughput is not impacted (still around 7.35 MB/s)I will send a v2.
Patrice
Signature · 2 lines
Best regards, Marek Vasut
Quoted 55 lines · Marek Vasut
Quoted 45 lines · Patrice CHOTARD
Quoted 5 lines · Marek Vasut
Quoted 4 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.
Quoted 8 lines
Quoted 3 lines
By removing the if (k == 10) test, it increases the CTRL+C responsiveness.
Tested on STM32MP157C-DK board.
I still have two questions:
First, do you have actual timing figures here -- how long did it take from one
ctrl_c()invocation to the nextctrl_c()invocation. Use e.g.get_timer_us()to time this.Second, does this increase in break condition checking impact throughput of the UMS ?
Hi Marek
Time between 2
ctrl_c()invocation is around 100us, way to fast in my opinion.UMS throughput is slightly impacted :
before : 7.35 MB/s
after : 7.17 MB/sA better balance can be obtained with the following update :
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 (;;) {
if (common->thread_wakeup_needed)
break;
if (++i == 20000) {
busy_indicator();
i = 0;
- k++;
- }
- if (k == 10) {
/* Handle START-STOP UNIT */
if (common->eject)
return-EPIPE;Quoted 8 lines
/* Handle CTRL+C */
if (ctrlc())
return-EPIPE;
/* Check cable connection */ if (!g_dnl_board_usb_cable_connected()) return-EIO;
-
- k = 0;
Quoted 1 line
If k is not reset here, then the ++i==20000 above triggers only once ?
variable k is no more used, everything is triggered when ++i==20000.
Quoted 14 lines
Quoted 12 lines
}
schedule();dm_usb_gadget_handle_interrupts(udcdev); }Time between 2
ctrl_c()invocation is around 28ms. UMS throughput is not impacted (still around 7.35 MB/s)I will send a v2.
Patrice
Quoted 58 lines · Patrice CHOTARD
Quoted 55 lines · Marek Vasut
Quoted 53 lines · Patrice CHOTARD
Quoted 5 lines · Marek Vasut
Quoted 4 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.
Quoted 8 lines
Quoted 3 lines
By removing the if (k == 10) test, it increases the CTRL+C responsiveness.
Tested on STM32MP157C-DK board.
I still have two questions:
First, do you have actual timing figures here -- how long did it take from one
ctrl_c()invocation to the nextctrl_c()invocation. Use e.g.get_timer_us()to time this.Second, does this increase in break condition checking impact throughput of the UMS ?
Hi Marek
Time between 2
ctrl_c()invocation is around 100us, way to fast in my opinion.UMS throughput is slightly impacted :
before : 7.35 MB/s
after : 7.17 MB/sA better balance can be obtained with the following update :
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 (;;) {
if (common->thread_wakeup_needed)
break;
if (++i == 20000) {
busy_indicator();
i = 0;
- k++;
- }
- if (k == 10) {
/* Handle START-STOP UNIT */
if (common->eject)
return-EPIPE;
/* Handle CTRL+C */
if (ctrlc())
return-EPIPE;
/* Check cable connection */
if (!g_dnl_board_usb_cable_connected()) return-EIO;
-
- k = 0;
Quoted 3 lines
Quoted 1 line
If k is not reset here, then the ++i==20000 above triggers only once ?
variable k is no more used, everything is triggered when ++i==20000.
Uh, right, I misread that, thanks. Please send a V2.