You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/07/12 08:42:48 UTC

[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #6601: usbdev/usbmsc: introduce USBMSC_WRMULTIPLE for faster writes

xiaoxiang781216 commented on code in PR #6601:
URL: https://github.com/apache/incubator-nuttx/pull/6601#discussion_r918680277


##########
drivers/usbdev/usbmsc_scsi.c:
##########
@@ -2444,8 +2444,24 @@ static int usbmsc_cmdwritestate(FAR struct usbmsc_dev_s *priv)
           src  = &req->buf[xfrd - priv->nreqbytes];
           dest = &priv->iobuffer[priv->nsectbytes];
 
-          nbytes = MIN(lun->sectorsize - priv->nsectbytes, priv->nreqbytes);
+#ifdef CONFIG_USBMSC_WRMULTIPLE
+          /* nbytes may end up being zero, after which the loop no longer
+           * proceeds but will be stuck forever.  Make sure nbytes isn't
+           * zero.
+           */
 
+          if (lun->sectorsize > priv->nsectbytes)
+            {
+              nbytes = MIN(lun->sectorsize - priv->nsectbytes,
+                           priv->nreqbytes);
+            }
+          else
+            {
+              nbytes = priv->nreqbytes;
+            }
+#else
+          nbytes = MIN(lun->sectorsize - priv->nsectbytes, priv->nreqbytes);

Review Comment:
   why the old code doesn't suffer this issue?



##########
drivers/usbdev/usbmsc_scsi.c:
##########
@@ -2454,9 +2470,34 @@ static int usbmsc_cmdwritestate(FAR struct usbmsc_dev_s *priv)
           priv->nsectbytes += nbytes;
           priv->nreqbytes  -= nbytes;
 
+#ifdef CONFIG_USBMSC_WRMULTIPLE
+          uint32_t nrbufs = MIN(priv->u.xfrlen, CONFIG_USBMSC_NWRREQS);
+
           /* Is the I/O buffer full? */
 
-          if (priv->nsectbytes >= lun->sectorsize)
+          if ((priv->nsectbytes >= lun->sectorsize * priv->u.xfrlen) ||
+              (priv->nsectbytes >= lun->sectorsize * CONFIG_USBMSC_NWRREQS))
+            {
+              /* Yes.. Write next sectors */
+
+              nwritten = USBMSC_DRVR_WRITE(lun, priv->iobuffer,
+                                           priv->sector, nrbufs);
+              if (nwritten < 0)
+                {
+                  usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_CMDWRITEWRITEFAIL),
+                           -nwritten);
+                  lun->sd     = SCSI_KCQME_WRITEFAULTAUTOREALLOCFAILED;
+                  lun->sdinfo = priv->sector;
+                  goto errout;
+                }
+
+              priv->nsectbytes = 0;
+              priv->residue   -= lun->sectorsize * nrbufs;
+              priv->u.xfrlen  -= nrbufs;
+              priv->sector    += nrbufs;
+            }

Review Comment:
   ```suggestion
               }
             else
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org