arcmsr: simplify ioctl data read/write
PATCH v4 1/2 arcmsr: simplify ioctl data read/write
From: Ching Huang <[email protected]>
This patch is to modify previous patch 13/17 and it is relative to
http://git.infradead.org/users/hch/scsi-queue.git/tree/arcmsr-for-3.18:/drivers/scsi/arcmsr
change in v4:
1. for readability, rename firstindex to getIndex, rename lastindex to putIndex
2. define ARCMSR_API_DATA_BUFLEN as 1032
3. simplify ioctl data read by macro CIRC_CNT_TO_END and CIRC_CNT
---
drivers/scsi/arcmsr/arcmsr_attr.c +32 -67
@@ -50,6 +50,7 @@#include <linux/errno.h> #include <linux/delay.h> #include <linux/pci.h> +#include <linux/circ_buf.h> #include <scsi/scsi_cmnd.h> #include <scsi/scsi_device.h>
@@ -68,7 +69,7 @@ static ssize_t arcmsr_sysfs_iop_message_ struct device *dev = container_of(kobj,struct device,kobj);struct Scsi_Host *host =class_to_shost (dev);struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; -uint8_t *pQbuffer,*ptmpQbuffer; +uint8_t *ptmpQbuffer;int32_t allxfer_len =0 ;unsigned long flags;
@@ -78,57 +79,22 @@ static ssize_t arcmsr_sysfs_iop_message_/* do message unit read. */ ptmpQbuffer = (uint8_t *)buf;spin_lock_irqsave (&acb->rqbuffer_lock, flags); -if (acb->rqbuf_firstindex != acb->rqbuf_lastindex) { - pQbuffer = &acb->rqbuffer[acb->rqbuf_firstindex]; -if (acb->rqbuf_firstindex > acb->rqbuf_lastindex) { -if ((ARCMSR_MAX_QBUFFER - acb->rqbuf_firstindex) >=1032 ) { -memcpy (ptmpQbuffer, pQbuffer,1032 ); - acb->rqbuf_firstindex +=1032 ; - acb->rqbuf_firstindex %=ARCMSR_MAX_QBUFFER ; - allxfer_len =1032 ; - }else { -if (((ARCMSR_MAX_QBUFFER - acb->rqbuf_firstindex) - + acb->rqbuf_lastindex) >1032 ) { -memcpy (ptmpQbuffer, pQbuffer, -ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex); - ptmpQbuffer +=ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex; -memcpy (ptmpQbuffer, acb->rqbuffer,1032 - - (ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex)); - acb->rqbuf_firstindex =1032 - - (ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex); - allxfer_len =1032 ; - }else { -memcpy (ptmpQbuffer, pQbuffer, -ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex); - ptmpQbuffer +=ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex; -memcpy (ptmpQbuffer, acb->rqbuffer, - acb->rqbuf_lastindex); - allxfer_len =ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex + - acb->rqbuf_lastindex; - acb->rqbuf_firstindex = - acb->rqbuf_lastindex; - } - } - }else { -if ((acb->rqbuf_lastindex - acb->rqbuf_firstindex) >1032 ) { -memcpy (ptmpQbuffer, pQbuffer,1032 ); - acb->rqbuf_firstindex +=1032 ; - allxfer_len =1032 ; - }else { -memcpy (ptmpQbuffer, pQbuffer, acb->rqbuf_lastindex - - acb->rqbuf_firstindex); - allxfer_len = acb->rqbuf_lastindex - - acb->rqbuf_firstindex; - acb->rqbuf_firstindex = acb->rqbuf_lastindex; - } +if (acb->rqbuf_getIndex != acb->rqbuf_putIndex) { +unsigned int tail = acb->rqbuf_getIndex; +unsigned int head = acb->rqbuf_putIndex; +unsigned int cnt_to_end =CIRC_CNT_TO_END (head, tail,ARCMSR_MAX_QBUFFER ); + + allxfer_len =CIRC_CNT (head, tail,ARCMSR_MAX_QBUFFER ); +if (allxfer_len >ARCMSR_API_DATA_BUFLEN ) + allxfer_len =ARCMSR_API_DATA_BUFLEN ; + +if (allxfer_len <= cnt_to_end) +memcpy (ptmpQbuffer, acb->rqbuffer + tail, allxfer_len); +else { +memcpy (ptmpQbuffer, acb->rqbuffer + tail, cnt_to_end); +memcpy (ptmpQbuffer + cnt_to_end, acb->rqbuffer, allxfer_len - cnt_to_end); } + acb->rqbuf_getIndex = (acb->rqbuf_getIndex + allxfer_len) %ARCMSR_MAX_QBUFFER ; }if (acb->acb_flags &ACB_F_IOPDATA_OVERFLOW ) {struct QBUFFER __iomem *prbuffer;
@@ -150,33 +116,32 @@ static ssize_t arcmsr_sysfs_iop_message_ struct device *dev = container_of(kobj,struct device,kobj);struct Scsi_Host *host =class_to_shost (dev);struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; -int32_t my_empty_len, user_len, wqbuf_firstindex, wqbuf_lastindex; +int32_t my_empty_len, user_len, wqbuf_getIndex, wqbuf_putIndex;uint8_t *pQbuffer, *ptmpuserbuffer;unsigned long flags;if (!capable (CAP_SYS_ADMIN ))return -EACCES ; -if (count >1032 ) +if (count >ARCMSR_API_DATA_BUFLEN )return -EINVAL ;/* do message unit write. */ ptmpuserbuffer = (uint8_t *)buf; user_len = (int32_t )count;spin_lock_irqsave (&acb->wqbuffer_lock, flags); - wqbuf_lastindex = acb->wqbuf_lastindex; - wqbuf_firstindex = acb->wqbuf_firstindex; -if (wqbuf_lastindex != wqbuf_firstindex) { + wqbuf_putIndex = acb->wqbuf_putIndex; + wqbuf_getIndex = acb->wqbuf_getIndex; +if (wqbuf_putIndex != wqbuf_getIndex) {arcmsr_write_ioctldata2iop (acb);spin_unlock_irqrestore (&acb->wqbuffer_lock, flags);return 0 ;/*need retry*/ }else { - my_empty_len = (wqbuf_firstindex-wqbuf_lastindex -1 ) - &(ARCMSR_MAX_QBUFFER -1 ); + my_empty_len =ARCMSR_MAX_QBUFFER -1 ;if (my_empty_len >= user_len) {while (user_len >0 ) { - pQbuffer = &acb->wqbuffer[acb->wqbuf_lastindex]; + pQbuffer = &acb->wqbuffer[acb->wqbuf_putIndex];memcpy (pQbuffer, ptmpuserbuffer,1 ); - acb->wqbuf_lastindex++; - acb->wqbuf_lastindex %=ARCMSR_MAX_QBUFFER ; + acb->wqbuf_putIndex++; + acb->wqbuf_putIndex %=ARCMSR_MAX_QBUFFER ; ptmpuserbuffer++; user_len--; }
@@ -215,12 +180,12 @@ static ssize_t arcmsr_sysfs_iop_message_ | ACB_F_MESSAGE_RQBUFFER_CLEARED | ACB_F_MESSAGE_WQBUFFER_READED);spin_lock_irqsave (&acb->rqbuffer_lock, flags); - acb->rqbuf_firstindex =0 ; - acb->rqbuf_lastindex =0 ; + acb->rqbuf_getIndex =0 ; + acb->rqbuf_putIndex =0 ;spin_unlock_irqrestore (&acb->rqbuffer_lock, flags);spin_lock_irqsave (&acb->wqbuffer_lock, flags); - acb->wqbuf_firstindex =0 ; - acb->wqbuf_lastindex =0 ; + acb->wqbuf_getIndex =0 ; + acb->wqbuf_putIndex =0 ;spin_unlock_irqrestore (&acb->wqbuffer_lock, flags); pQbuffer = acb->rqbuffer;memset (pQbuffer,0 ,sizeof (struct QBUFFER ));
@@ -234,7 +199,7 @@ static struct bin_attribute arcmsr_sysfs .name = "mu_read", .mode = S_IRUSR , }, - .size = 1032, + .size = ARCMSR_API_DATA_BUFLEN, .read = arcmsr_sysfs_iop_message_read, };
@@ -243,7 +208,7 @@ static struct bin_attribute arcmsr_sysfs .name = "mu_write", .mode = S_IWUSR, }, - .size = 1032, + .size = ARCMSR_API_DATA_BUFLEN, .write = arcmsr_sysfs_iop_message_write, };
drivers/scsi/arcmsr/arcmsr.h +6 -5
@@ -107,10 +107,11 @@ struct CMD_MESSAGE** IOP Message Transfer Data for user space ******************************************************************************* */ +#define ARCMSR_API_DATA_BUFLEN 1032struct CMD_MESSAGE_FIELD {struct CMD_MESSAGE cmdmessage; -uint8_t messagedatabuffer[1032 ]; +uint8_t messagedatabuffer[ARCMSR_API_DATA_BUFLEN ]; };/* IOP message transfer */ #define ARCMSR_MESSAGE_FAIL 0x0001
@@ -678,15 +679,15 @@ struct AdapterControlBlockunsigned int uncache_size;uint8_t rqbuffer[ARCMSR_MAX_QBUFFER ];/* data collection buffer for read from 80331 */ -int32_t rqbuf_firstindex; +int32_t rqbuf_getIndex;/* first of read buffer */ -int32_t rqbuf_lastindex; +int32_t rqbuf_putIndex;/* last of read buffer */ uint8_t wqbuffer[ARCMSR_MAX_QBUFFER ];/* data collection buffer for write to 80331 */ -int32_t wqbuf_firstindex; +int32_t wqbuf_getIndex;/* first of write buffer */ -int32_t wqbuf_lastindex; +int32_t wqbuf_putIndex;/* last of write buffer */ uint8_t devstate[ARCMSR_MAX_TARGETID ][ARCMSR_MAX_TARGETLUN ];/* id0 ..... id15, lun0...lun7 */
drivers/scsi/arcmsr/arcmsr_hba.c +66 -113
304 lines not on this page · raw message
Quoted 7 lines · Ching Huang
From: Ching Huang <[email protected]>
This patch is to modify previous patch 13/17 and it is relative to
http://git.infradead.org/users/hch/scsi-queue.git/tree/arcmsr-for-3.18:/drivers/scsi/arcmsrchange in v4:
1. for readability, rename firstindex to getIndex, rename lastindex to putIndex
For some reason, the names head+tail areusual for a circular buffer. But let us ignore the names, I don't care.
Quoted 2 lines
2. define
ARCMSR_API_DATA_BUFLENas 1032
3. simplify ioctl data read by macroCIRC_CNT_TO_ENDandCIRC_CNT
It's definitely better when you post renames and other non-functional changes in separate patches, it's easier for the reviewer.
Quoted 118 lines
Signed-off-by Ching Huang <[email protected]>---
diff -uprN
a/drivers/scsi/arcmsr/arcmsr_attr.cb/drivers/scsi/arcmsr/arcmsr_attr.cdrivers/scsi/arcmsr/arcmsr_attr.c +19
-56@@ -50,6 +50,7 @@#include <linux/errno.h> #include <linux/delay.h> #include <linux/pci.h> +#include <linux/circ_buf.h> #include <scsi/scsi_cmnd.h> #include <scsi/scsi_device.h> @@ -68,7 +69,7 @@ static ssize_t arcmsr_sysfs_iop_message_ struct device *dev = container_of(kobj,struct device,kobj);struct Scsi_Host *host =class_to_shost (dev);struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; -uint8_t *pQbuffer,*ptmpQbuffer; +uint8_t *ptmpQbuffer;int32_t allxfer_len =0 ;unsigned long flags;@@ -78,57 +79,22 @@ static ssize_t arcmsr_sysfs_iop_message_/* do message unit read. */ ptmpQbuffer = (uint8_t *)buf;spin_lock_irqsave (&acb->rqbuffer_lock, flags); -if (acb->rqbuf_firstindex != acb->rqbuf_lastindex) { - pQbuffer = &acb->rqbuffer[acb->rqbuf_firstindex]; -if (acb->rqbuf_firstindex > acb->rqbuf_lastindex) { -if ((ARCMSR_MAX_QBUFFER - acb->rqbuf_firstindex) >=1032 ) { -memcpy (ptmpQbuffer, pQbuffer,1032 ); - acb->rqbuf_firstindex +=1032 ; - acb->rqbuf_firstindex %=ARCMSR_MAX_QBUFFER ; - allxfer_len =1032 ; - }else { -if (((ARCMSR_MAX_QBUFFER - acb->rqbuf_firstindex) - + acb->rqbuf_lastindex) >1032 ) { -memcpy (ptmpQbuffer, pQbuffer, -ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex); - ptmpQbuffer +=ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex; -memcpy (ptmpQbuffer, acb->rqbuffer,1032 - - (ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex)); - acb->rqbuf_firstindex =1032 - - (ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex); - allxfer_len =1032 ; - }else { -memcpy (ptmpQbuffer, pQbuffer, -ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex); - ptmpQbuffer +=ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex; -memcpy (ptmpQbuffer, acb->rqbuffer, - acb->rqbuf_lastindex); - allxfer_len =ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex + - acb->rqbuf_lastindex; - acb->rqbuf_firstindex = - acb->rqbuf_lastindex; - } - } - }else { -if ((acb->rqbuf_lastindex - acb->rqbuf_firstindex) >1032 ) { -memcpy (ptmpQbuffer, pQbuffer,1032 ); - acb->rqbuf_firstindex +=1032 ; - allxfer_len =1032 ; - }else { -memcpy (ptmpQbuffer, pQbuffer, acb->rqbuf_lastindex - - acb->rqbuf_firstindex); - allxfer_len = acb->rqbuf_lastindex - - acb->rqbuf_firstindex; - acb->rqbuf_firstindex = acb->rqbuf_lastindex; - } +if (acb->rqbuf_getIndex != acb->rqbuf_putIndex) { +unsigned int tail = acb->rqbuf_getIndex; +unsigned int head = acb->rqbuf_putIndex; +unsigned int cnt_to_end =CIRC_CNT_TO_END (head, tail,ARCMSR_MAX_QBUFFER ); + + allxfer_len =CIRC_CNT (head, tail,ARCMSR_MAX_QBUFFER ); +if (allxfer_len >ARCMSR_API_DATA_BUFLEN ) + allxfer_len =ARCMSR_API_DATA_BUFLEN ; + +if (allxfer_len <= cnt_to_end) +memcpy (ptmpQbuffer, acb->rqbuffer + tail, allxfer_len); +else { +memcpy (ptmpQbuffer, acb->rqbuffer + tail, cnt_to_end); +memcpy (ptmpQbuffer + cnt_to_end, acb->rqbuffer, allxfer_len - cnt_to_end); } + acb->rqbuf_getIndex = (acb->rqbuf_getIndex + allxfer_len) %ARCMSR_MAX_QBUFFER ; }if (acb->acb_flags &ACB_F_IOPDATA_OVERFLOW ) {struct QBUFFER __iomem *prbuffer;@@ -150,33 +116,32 @@ static ssize_t arcmsr_sysfs_iop_message_ struct device *dev = container_of(kobj,struct device,kobj);struct Scsi_Host *host =class_to_shost (dev);struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; -int32_t my_empty_len, user_len, wqbuf_firstindex, wqbuf_lastindex; +int32_t my_empty_len, user_len, wqbuf_getIndex, wqbuf_putIndex;uint8_t *pQbuffer, *ptmpuserbuffer;unsigned long flags;if (!capable (CAP_SYS_ADMIN ))return -EACCES ; -if (count >1032 ) +if (count >ARCMSR_API_DATA_BUFLEN )return -EINVAL ;/* do message unit write. */ ptmpuserbuffer = (uint8_t *)buf; user_len = (int32_t )count;spin_lock_irqsave (&acb->wqbuffer_lock, flags); - wqbuf_lastindex = acb->wqbuf_lastindex; - wqbuf_firstindex = acb->wqbuf_firstindex; -if (wqbuf_lastindex != wqbuf_firstindex) {
drivers/scsi/arcmsr/arcmsr_attr.c static ssize_t arcmsr_sysfs_iop_message_ · line 138
Quoted 10 lines
drivers/scsi/arcmsr/arcmsr_attr.c +4
-2+ wqbuf_putIndex = acb->wqbuf_putIndex; + wqbuf_getIndex = acb->wqbuf_getIndex; +if (wqbuf_putIndex != wqbuf_getIndex) {arcmsr_write_ioctldata2iop (acb);spin_unlock_irqrestore (&acb->wqbuffer_lock, flags);return 0 ;/*need retry*/ }else { - my_empty_len = (wqbuf_firstindex-wqbuf_lastindex -1 ) - &(ARCMSR_MAX_QBUFFER -1 ); + my_empty_len =ARCMSR_MAX_QBUFFER -1 ;
This^ doesn't look like like an rename can you explain?
Let us stop here, or we end in an endless loop of corrections. The original 13/17
you are trying to improve here was at least without bugs (better said I haven't noticed) so improving it now only complicates the process.
My suggestion is -let us skip this patch and focus only on fixing the spinlock problem found in 16/17. OKay?
Cheers,
Tomas
Quoted 135 lines · Tomas Henzl
Quoted 7 lines · Ching Huang
From: Ching Huang <[email protected]>
This patch is to modify previous patch 13/17 and it is relative to
http://git.infradead.org/users/hch/scsi-queue.git/tree/arcmsr-for-3.18:/drivers/scsi/arcmsrchange in v4:
1. for readability, rename firstindex to getIndex, rename lastindex to putIndexFor some reason, the names head+tail areusual for a circular buffer. But let us ignore the names, I don't care.
Quoted 2 lines
2. define
ARCMSR_API_DATA_BUFLENas 1032
3. simplify ioctl data read by macroCIRC_CNT_TO_ENDandCIRC_CNTIt's definitely better when you post renames and other non-functional changes in separate patches, it's easier for the reviewer.
Quoted 121 lines
Signed-off-by Ching Huang <[email protected]>---
diff -uprN
a/drivers/scsi/arcmsr/arcmsr_attr.cb/drivers/scsi/arcmsr/arcmsr_attr.cdrivers/scsi/arcmsr/arcmsr_attr.c +22
-56@@ -50,6 +50,7 @@#include <linux/errno.h> #include <linux/delay.h> #include <linux/pci.h> +#include <linux/circ_buf.h> #include <scsi/scsi_cmnd.h> #include <scsi/scsi_device.h> @@ -68,7 +69,7 @@ static ssize_t arcmsr_sysfs_iop_message_ struct device *dev = container_of(kobj,struct device,kobj);struct Scsi_Host *host =class_to_shost (dev);struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; -uint8_t *pQbuffer,*ptmpQbuffer; +uint8_t *ptmpQbuffer;int32_t allxfer_len =0 ;unsigned long flags;@@ -78,57 +79,22 @@ static ssize_t arcmsr_sysfs_iop_message_/* do message unit read. */ ptmpQbuffer = (uint8_t *)buf;spin_lock_irqsave (&acb->rqbuffer_lock, flags); -if (acb->rqbuf_firstindex != acb->rqbuf_lastindex) { - pQbuffer = &acb->rqbuffer[acb->rqbuf_firstindex]; -if (acb->rqbuf_firstindex > acb->rqbuf_lastindex) { -if ((ARCMSR_MAX_QBUFFER - acb->rqbuf_firstindex) >=1032 ) { -memcpy (ptmpQbuffer, pQbuffer,1032 ); - acb->rqbuf_firstindex +=1032 ; - acb->rqbuf_firstindex %=ARCMSR_MAX_QBUFFER ; - allxfer_len =1032 ; - }else { -if (((ARCMSR_MAX_QBUFFER - acb->rqbuf_firstindex) - + acb->rqbuf_lastindex) >1032 ) { -memcpy (ptmpQbuffer, pQbuffer, -ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex); - ptmpQbuffer +=ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex; -memcpy (ptmpQbuffer, acb->rqbuffer,1032 - - (ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex)); - acb->rqbuf_firstindex =1032 - - (ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex); - allxfer_len =1032 ; - }else { -memcpy (ptmpQbuffer, pQbuffer, -ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex); - ptmpQbuffer +=ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex; -memcpy (ptmpQbuffer, acb->rqbuffer, - acb->rqbuf_lastindex); - allxfer_len =ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex + - acb->rqbuf_lastindex; - acb->rqbuf_firstindex = - acb->rqbuf_lastindex; - } - } - }else { -if ((acb->rqbuf_lastindex - acb->rqbuf_firstindex) >1032 ) { -memcpy (ptmpQbuffer, pQbuffer,1032 ); - acb->rqbuf_firstindex +=1032 ; - allxfer_len =1032 ; - }else { -memcpy (ptmpQbuffer, pQbuffer, acb->rqbuf_lastindex - - acb->rqbuf_firstindex); - allxfer_len = acb->rqbuf_lastindex - - acb->rqbuf_firstindex; - acb->rqbuf_firstindex = acb->rqbuf_lastindex; - } +if (acb->rqbuf_getIndex != acb->rqbuf_putIndex) { +unsigned int tail = acb->rqbuf_getIndex; +unsigned int head = acb->rqbuf_putIndex; +unsigned int cnt_to_end =CIRC_CNT_TO_END (head, tail,ARCMSR_MAX_QBUFFER ); + + allxfer_len =CIRC_CNT (head, tail,ARCMSR_MAX_QBUFFER ); +if (allxfer_len >ARCMSR_API_DATA_BUFLEN ) + allxfer_len =ARCMSR_API_DATA_BUFLEN ; + +if (allxfer_len <= cnt_to_end) +memcpy (ptmpQbuffer, acb->rqbuffer + tail, allxfer_len); +else { +memcpy (ptmpQbuffer, acb->rqbuffer + tail, cnt_to_end); +memcpy (ptmpQbuffer + cnt_to_end, acb->rqbuffer, allxfer_len - cnt_to_end); } + acb->rqbuf_getIndex = (acb->rqbuf_getIndex + allxfer_len) %ARCMSR_MAX_QBUFFER ; }if (acb->acb_flags &ACB_F_IOPDATA_OVERFLOW ) {struct QBUFFER __iomem *prbuffer;@@ -150,33 +116,32 @@ static ssize_t arcmsr_sysfs_iop_message_ struct device *dev = container_of(kobj,struct device,kobj);struct Scsi_Host *host =class_to_shost (dev);struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; -int32_t my_empty_len, user_len, wqbuf_firstindex, wqbuf_lastindex; +int32_t my_empty_len, user_len, wqbuf_getIndex, wqbuf_putIndex;uint8_t *pQbuffer, *ptmpuserbuffer;unsigned long flags;if (!capable (CAP_SYS_ADMIN ))return -EACCES ; -if (count >1032 ) +if (count >ARCMSR_API_DATA_BUFLEN )return -EINVAL ;/* do message unit write. */ ptmpuserbuffer = (uint8_t *)buf; user_len = (int32_t )count;spin_lock_irqsave (&acb->wqbuffer_lock, flags); - wqbuf_lastindex = acb->wqbuf_lastindex; - wqbuf_firstindex = acb->wqbuf_firstindex; -if (wqbuf_lastindex != wqbuf_firstindex) { + wqbuf_putIndex = acb->wqbuf_putIndex; + wqbuf_getIndex = acb->wqbuf_getIndex; +if (wqbuf_putIndex != wqbuf_getIndex) {
Quoted 8 lines
drivers/scsi/arcmsr/arcmsr_attr.c static ssize_t arcmsr_sysfs_iop_message_ · line 138
Quoted 7 lines
drivers/scsi/arcmsr/arcmsr_attr.c +1
-2arcmsr_write_ioctldata2iop (acb);spin_unlock_irqrestore (&acb->wqbuffer_lock, flags);return 0 ;/*need retry*/ }else { - my_empty_len = (wqbuf_firstindex-wqbuf_lastindex -1 ) - &(ARCMSR_MAX_QBUFFER -1 ); + my_empty_len =ARCMSR_MAX_QBUFFER -1 ;This^ doesn't look like like an rename can you explain?
It is just a code simplification.
Quoted 6 lines
Let us stop here, or we end in an endless loop of corrections. The original 13/17
you are trying to improve here was at least without bugs (better said I haven't noticed) so improving it now only complicates the process.
My suggestion is -let us skip this patch and focus only on fixing the spinlock problem found in 16/17. OKay?
Agree.
Quoted 4 lines
Cheers,
Tomas
Quoted 143 lines · Ching Huang
Quoted 134 lines · Tomas Henzl
Quoted 7 lines · Ching Huang
From: Ching Huang <[email protected]>
This patch is to modify previous patch 13/17 and it is relative to
http://git.infradead.org/users/hch/scsi-queue.git/tree/arcmsr-for-3.18:/drivers/scsi/arcmsrchange in v4:
1. for readability, rename firstindex to getIndex, rename lastindex to putIndexFor some reason, the names head+tail areusual for a circular buffer. But let us ignore the names, I don't care.
Quoted 2 lines
2. define
ARCMSR_API_DATA_BUFLENas 1032
3. simplify ioctl data read by macroCIRC_CNT_TO_ENDandCIRC_CNTIt's definitely better when you post renames and other non-functional changes in separate patches, it's easier for the reviewer.
Quoted 120 lines
Signed-off-by Ching Huang <[email protected]>---
diff -uprN
a/drivers/scsi/arcmsr/arcmsr_attr.cb/drivers/scsi/arcmsr/arcmsr_attr.cdrivers/scsi/arcmsr/arcmsr_attr.c +22
-56@@ -50,6 +50,7 @@#include <linux/errno.h> #include <linux/delay.h> #include <linux/pci.h> +#include <linux/circ_buf.h> #include <scsi/scsi_cmnd.h> #include <scsi/scsi_device.h> @@ -68,7 +69,7 @@ static ssize_t arcmsr_sysfs_iop_message_ struct device *dev = container_of(kobj,struct device,kobj);struct Scsi_Host *host =class_to_shost (dev);struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; -uint8_t *pQbuffer,*ptmpQbuffer; +uint8_t *ptmpQbuffer;int32_t allxfer_len =0 ;unsigned long flags;@@ -78,57 +79,22 @@ static ssize_t arcmsr_sysfs_iop_message_/* do message unit read. */ ptmpQbuffer = (uint8_t *)buf;spin_lock_irqsave (&acb->rqbuffer_lock, flags); -if (acb->rqbuf_firstindex != acb->rqbuf_lastindex) { - pQbuffer = &acb->rqbuffer[acb->rqbuf_firstindex]; -if (acb->rqbuf_firstindex > acb->rqbuf_lastindex) { -if ((ARCMSR_MAX_QBUFFER - acb->rqbuf_firstindex) >=1032 ) { -memcpy (ptmpQbuffer, pQbuffer,1032 ); - acb->rqbuf_firstindex +=1032 ; - acb->rqbuf_firstindex %=ARCMSR_MAX_QBUFFER ; - allxfer_len =1032 ; - }else { -if (((ARCMSR_MAX_QBUFFER - acb->rqbuf_firstindex) - + acb->rqbuf_lastindex) >1032 ) { -memcpy (ptmpQbuffer, pQbuffer, -ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex); - ptmpQbuffer +=ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex; -memcpy (ptmpQbuffer, acb->rqbuffer,1032 - - (ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex)); - acb->rqbuf_firstindex =1032 - - (ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex); - allxfer_len =1032 ; - }else { -memcpy (ptmpQbuffer, pQbuffer, -ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex); - ptmpQbuffer +=ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex; -memcpy (ptmpQbuffer, acb->rqbuffer, - acb->rqbuf_lastindex); - allxfer_len =ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex + - acb->rqbuf_lastindex; - acb->rqbuf_firstindex = - acb->rqbuf_lastindex; - } - } - }else { -if ((acb->rqbuf_lastindex - acb->rqbuf_firstindex) >1032 ) { -memcpy (ptmpQbuffer, pQbuffer,1032 ); - acb->rqbuf_firstindex +=1032 ; - allxfer_len =1032 ; - }else { -memcpy (ptmpQbuffer, pQbuffer, acb->rqbuf_lastindex - - acb->rqbuf_firstindex); - allxfer_len = acb->rqbuf_lastindex - - acb->rqbuf_firstindex; - acb->rqbuf_firstindex = acb->rqbuf_lastindex; - } +if (acb->rqbuf_getIndex != acb->rqbuf_putIndex) { +unsigned int tail = acb->rqbuf_getIndex; +unsigned int head = acb->rqbuf_putIndex; +unsigned int cnt_to_end =CIRC_CNT_TO_END (head, tail,ARCMSR_MAX_QBUFFER ); + + allxfer_len =CIRC_CNT (head, tail,ARCMSR_MAX_QBUFFER ); +if (allxfer_len >ARCMSR_API_DATA_BUFLEN ) + allxfer_len =ARCMSR_API_DATA_BUFLEN ; + +if (allxfer_len <= cnt_to_end) +memcpy (ptmpQbuffer, acb->rqbuffer + tail, allxfer_len); +else { +memcpy (ptmpQbuffer, acb->rqbuffer + tail, cnt_to_end); +memcpy (ptmpQbuffer + cnt_to_end, acb->rqbuffer, allxfer_len - cnt_to_end); } + acb->rqbuf_getIndex = (acb->rqbuf_getIndex + allxfer_len) %ARCMSR_MAX_QBUFFER ; }if (acb->acb_flags &ACB_F_IOPDATA_OVERFLOW ) {struct QBUFFER __iomem *prbuffer;@@ -150,33 +116,32 @@ static ssize_t arcmsr_sysfs_iop_message_ struct device *dev = container_of(kobj,struct device,kobj);struct Scsi_Host *host =class_to_shost (dev);struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; -int32_t my_empty_len, user_len, wqbuf_firstindex, wqbuf_lastindex; +int32_t my_empty_len, user_len, wqbuf_getIndex, wqbuf_putIndex;uint8_t *pQbuffer, *ptmpuserbuffer;unsigned long flags;if (!capable (CAP_SYS_ADMIN ))return -EACCES ; -if (count >1032 ) +if (count >ARCMSR_API_DATA_BUFLEN )return -EINVAL ;/* do message unit write. */ ptmpuserbuffer = (uint8_t *)buf; user_len = (int32_t )count;spin_lock_irqsave (&acb->wqbuffer_lock, flags); - wqbuf_lastindex = acb->wqbuf_lastindex; - wqbuf_firstindex = acb->wqbuf_firstindex; -if (wqbuf_lastindex != wqbuf_firstindex) { + wqbuf_putIndex = acb->wqbuf_putIndex; + wqbuf_getIndex = acb->wqbuf_getIndex; +if (wqbuf_putIndex != wqbuf_getIndex) {Quoted 8 lines
drivers/scsi/arcmsr/arcmsr_attr.c static ssize_t arcmsr_sysfs_iop_message_ · line 138
Quoted 7 lines
drivers/scsi/arcmsr/arcmsr_attr.c +1
-2arcmsr_write_ioctldata2iop (acb);spin_unlock_irqrestore (&acb->wqbuffer_lock, flags);return 0 ;/*need retry*/ }else { - my_empty_len = (wqbuf_firstindex-wqbuf_lastindex -1 ) - &(ARCMSR_MAX_QBUFFER -1 ); + my_empty_len =ARCMSR_MAX_QBUFFER -1 ;This^ doesn't look like like an rename can you explain?
Quoted 1 line
It is just a code simplification.
Yes it is of some kind. But I think it's also a bug, because you have replaced 'firstindex - lastindex' with nothing.
Quoted 14 lines
Quoted 5 lines
Let us stop here, or we end in an endless loop of corrections. The original 13/17
you are trying to improve here was at least without bugs (better said I haven't noticed) so improving it now only complicates the process.
My suggestion is -let us skip this patch and focus only on fixing the spinlock problem found in 16/17. OKay?Agree.
Quoted 3 lines
Cheers,
Tomas--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 144 lines · Tomas Henzl
Quoted 143 lines · Ching Huang
Quoted 142 lines · Tomas Henzl
Quoted 7 lines · Ching Huang
From: Ching Huang <[email protected]>
This patch is to modify previous patch 13/17 and it is relative to
http://git.infradead.org/users/hch/scsi-queue.git/tree/arcmsr-for-3.18:/drivers/scsi/arcmsrchange in v4:
1. for readability, rename firstindex to getIndex, rename lastindex to putIndexFor some reason, the names head+tail areusual for a circular buffer. But let us ignore the names, I don't care.
Quoted 2 lines
2. define
ARCMSR_API_DATA_BUFLENas 1032
3. simplify ioctl data read by macroCIRC_CNT_TO_ENDandCIRC_CNTIt's definitely better when you post renames and other non-functional changes in separate patches, it's easier for the reviewer.
Quoted 117 lines
Signed-off-by Ching Huang <[email protected]>---
diff -uprN
a/drivers/scsi/arcmsr/arcmsr_attr.cb/drivers/scsi/arcmsr/arcmsr_attr.cdrivers/scsi/arcmsr/arcmsr_attr.c +19
-56@@ -50,6 +50,7 @@#include <linux/errno.h> #include <linux/delay.h> #include <linux/pci.h> +#include <linux/circ_buf.h> #include <scsi/scsi_cmnd.h> #include <scsi/scsi_device.h> @@ -68,7 +69,7 @@ static ssize_t arcmsr_sysfs_iop_message_ struct device *dev = container_of(kobj,struct device,kobj);struct Scsi_Host *host =class_to_shost (dev);struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; -uint8_t *pQbuffer,*ptmpQbuffer; +uint8_t *ptmpQbuffer;int32_t allxfer_len =0 ;unsigned long flags;@@ -78,57 +79,22 @@ static ssize_t arcmsr_sysfs_iop_message_/* do message unit read. */ ptmpQbuffer = (uint8_t *)buf;spin_lock_irqsave (&acb->rqbuffer_lock, flags); -if (acb->rqbuf_firstindex != acb->rqbuf_lastindex) { - pQbuffer = &acb->rqbuffer[acb->rqbuf_firstindex]; -if (acb->rqbuf_firstindex > acb->rqbuf_lastindex) { -if ((ARCMSR_MAX_QBUFFER - acb->rqbuf_firstindex) >=1032 ) { -memcpy (ptmpQbuffer, pQbuffer,1032 ); - acb->rqbuf_firstindex +=1032 ; - acb->rqbuf_firstindex %=ARCMSR_MAX_QBUFFER ; - allxfer_len =1032 ; - }else { -if (((ARCMSR_MAX_QBUFFER - acb->rqbuf_firstindex) - + acb->rqbuf_lastindex) >1032 ) { -memcpy (ptmpQbuffer, pQbuffer, -ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex); - ptmpQbuffer +=ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex; -memcpy (ptmpQbuffer, acb->rqbuffer,1032 - - (ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex)); - acb->rqbuf_firstindex =1032 - - (ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex); - allxfer_len =1032 ; - }else { -memcpy (ptmpQbuffer, pQbuffer, -ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex); - ptmpQbuffer +=ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex; -memcpy (ptmpQbuffer, acb->rqbuffer, - acb->rqbuf_lastindex); - allxfer_len =ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex + - acb->rqbuf_lastindex; - acb->rqbuf_firstindex = - acb->rqbuf_lastindex; - } - } - }else { -if ((acb->rqbuf_lastindex - acb->rqbuf_firstindex) >1032 ) { -memcpy (ptmpQbuffer, pQbuffer,1032 ); - acb->rqbuf_firstindex +=1032 ; - allxfer_len =1032 ; - }else { -memcpy (ptmpQbuffer, pQbuffer, acb->rqbuf_lastindex - - acb->rqbuf_firstindex); - allxfer_len = acb->rqbuf_lastindex - - acb->rqbuf_firstindex; - acb->rqbuf_firstindex = acb->rqbuf_lastindex; - } +if (acb->rqbuf_getIndex != acb->rqbuf_putIndex) { +unsigned int tail = acb->rqbuf_getIndex; +unsigned int head = acb->rqbuf_putIndex; +unsigned int cnt_to_end =CIRC_CNT_TO_END (head, tail,ARCMSR_MAX_QBUFFER ); + + allxfer_len =CIRC_CNT (head, tail,ARCMSR_MAX_QBUFFER ); +if (allxfer_len >ARCMSR_API_DATA_BUFLEN ) + allxfer_len =ARCMSR_API_DATA_BUFLEN ; + +if (allxfer_len <= cnt_to_end) +memcpy (ptmpQbuffer, acb->rqbuffer + tail, allxfer_len); +else { +memcpy (ptmpQbuffer, acb->rqbuffer + tail, cnt_to_end); +memcpy (ptmpQbuffer + cnt_to_end, acb->rqbuffer, allxfer_len - cnt_to_end); } + acb->rqbuf_getIndex = (acb->rqbuf_getIndex + allxfer_len) %ARCMSR_MAX_QBUFFER ; }if (acb->acb_flags &ACB_F_IOPDATA_OVERFLOW ) {struct QBUFFER __iomem *prbuffer;@@ -150,33 +116,32 @@ static ssize_t arcmsr_sysfs_iop_message_ struct device *dev = container_of(kobj,struct device,kobj);struct Scsi_Host *host =class_to_shost (dev);struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; -int32_t my_empty_len, user_len, wqbuf_firstindex, wqbuf_lastindex; +int32_t my_empty_len, user_len, wqbuf_getIndex, wqbuf_putIndex;uint8_t *pQbuffer, *ptmpuserbuffer;unsigned long flags;if (!capable (CAP_SYS_ADMIN ))return -EACCES ; -if (count >1032 ) +if (count >ARCMSR_API_DATA_BUFLEN )return -EINVAL ;/* do message unit write. */ ptmpuserbuffer = (uint8_t *)buf; user_len = (int32_t )count;spin_lock_irqsave (&acb->wqbuffer_lock, flags); - wqbuf_lastindex = acb->wqbuf_lastindex; - wqbuf_firstindex = acb->wqbuf_firstindex; -if (wqbuf_lastindex != wqbuf_firstindex) {drivers/scsi/arcmsr/arcmsr_attr.c static ssize_t arcmsr_sysfs_iop_message_ · line 138
Quoted 10 lines
drivers/scsi/arcmsr/arcmsr_attr.c +4
-2+ wqbuf_putIndex = acb->wqbuf_putIndex; + wqbuf_getIndex = acb->wqbuf_getIndex; +if (wqbuf_putIndex != wqbuf_getIndex) {arcmsr_write_ioctldata2iop (acb);spin_unlock_irqrestore (&acb->wqbuffer_lock, flags);return 0 ;/*need retry*/ }else { - my_empty_len = (wqbuf_firstindex-wqbuf_lastindex -1 ) - &(ARCMSR_MAX_QBUFFER -1 ); + my_empty_len =ARCMSR_MAX_QBUFFER -1 ;This^ doesn't look like like an rename can you explain?
Quoted 4 lines
Quoted 1 line
It is just a code simplification.
Yes it is of some kind. But I think it's also a bug, because you have replaced 'firstindex - lastindex' with nothing.
It will be not a bug. At here, firstindex == lastindex, so firstindex-lastindex is 0
Quoted 16 lines
Quoted 15 lines
Quoted 6 lines
Let us stop here, or we end in an endless loop of corrections. The original 13/17
you are trying to improve here was at least without bugs (better said I haven't noticed) so improving it now only complicates the process.
My suggestion is -let us skip this patch and focus only on fixing the spinlock problem found in 16/17. OKay?Agree.
Quoted 3 lines
Cheers,
Tomas--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 145 lines · Ching Huang
Quoted 144 lines · Tomas Henzl
Quoted 143 lines · Ching Huang
Quoted 142 lines · Tomas Henzl
Quoted 7 lines · Ching Huang
From: Ching Huang <[email protected]>
This patch is to modify previous patch 13/17 and it is relative to
http://git.infradead.org/users/hch/scsi-queue.git/tree/arcmsr-for-3.18:/drivers/scsi/arcmsrchange in v4:
1. for readability, rename firstindex to getIndex, rename lastindex to putIndexFor some reason, the names head+tail areusual for a circular buffer. But let us ignore the names, I don't care.
Quoted 2 lines
2. define
ARCMSR_API_DATA_BUFLENas 1032
3. simplify ioctl data read by macroCIRC_CNT_TO_ENDandCIRC_CNTIt's definitely better when you post renames and other non-functional changes in separate patches, it's easier for the reviewer.
Quoted 117 lines
Signed-off-by Ching Huang <[email protected]>---
diff -uprN
a/drivers/scsi/arcmsr/arcmsr_attr.cb/drivers/scsi/arcmsr/arcmsr_attr.cdrivers/scsi/arcmsr/arcmsr_attr.c +19
-56@@ -50,6 +50,7 @@#include <linux/errno.h> #include <linux/delay.h> #include <linux/pci.h> +#include <linux/circ_buf.h> #include <scsi/scsi_cmnd.h> #include <scsi/scsi_device.h> @@ -68,7 +69,7 @@ static ssize_t arcmsr_sysfs_iop_message_ struct device *dev = container_of(kobj,struct device,kobj);struct Scsi_Host *host =class_to_shost (dev);struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; -uint8_t *pQbuffer,*ptmpQbuffer; +uint8_t *ptmpQbuffer;int32_t allxfer_len =0 ;unsigned long flags;@@ -78,57 +79,22 @@ static ssize_t arcmsr_sysfs_iop_message_/* do message unit read. */ ptmpQbuffer = (uint8_t *)buf;spin_lock_irqsave (&acb->rqbuffer_lock, flags); -if (acb->rqbuf_firstindex != acb->rqbuf_lastindex) { - pQbuffer = &acb->rqbuffer[acb->rqbuf_firstindex]; -if (acb->rqbuf_firstindex > acb->rqbuf_lastindex) { -if ((ARCMSR_MAX_QBUFFER - acb->rqbuf_firstindex) >=1032 ) { -memcpy (ptmpQbuffer, pQbuffer,1032 ); - acb->rqbuf_firstindex +=1032 ; - acb->rqbuf_firstindex %=ARCMSR_MAX_QBUFFER ; - allxfer_len =1032 ; - }else { -if (((ARCMSR_MAX_QBUFFER - acb->rqbuf_firstindex) - + acb->rqbuf_lastindex) >1032 ) { -memcpy (ptmpQbuffer, pQbuffer, -ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex); - ptmpQbuffer +=ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex; -memcpy (ptmpQbuffer, acb->rqbuffer,1032 - - (ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex)); - acb->rqbuf_firstindex =1032 - - (ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex); - allxfer_len =1032 ; - }else { -memcpy (ptmpQbuffer, pQbuffer, -ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex); - ptmpQbuffer +=ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex; -memcpy (ptmpQbuffer, acb->rqbuffer, - acb->rqbuf_lastindex); - allxfer_len =ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex + - acb->rqbuf_lastindex; - acb->rqbuf_firstindex = - acb->rqbuf_lastindex; - } - } - }else { -if ((acb->rqbuf_lastindex - acb->rqbuf_firstindex) >1032 ) { -memcpy (ptmpQbuffer, pQbuffer,1032 ); - acb->rqbuf_firstindex +=1032 ; - allxfer_len =1032 ; - }else { -memcpy (ptmpQbuffer, pQbuffer, acb->rqbuf_lastindex - - acb->rqbuf_firstindex); - allxfer_len = acb->rqbuf_lastindex - - acb->rqbuf_firstindex; - acb->rqbuf_firstindex = acb->rqbuf_lastindex; - } +if (acb->rqbuf_getIndex != acb->rqbuf_putIndex) { +unsigned int tail = acb->rqbuf_getIndex; +unsigned int head = acb->rqbuf_putIndex; +unsigned int cnt_to_end =CIRC_CNT_TO_END (head, tail,ARCMSR_MAX_QBUFFER ); + + allxfer_len =CIRC_CNT (head, tail,ARCMSR_MAX_QBUFFER ); +if (allxfer_len >ARCMSR_API_DATA_BUFLEN ) + allxfer_len =ARCMSR_API_DATA_BUFLEN ; + +if (allxfer_len <= cnt_to_end) +memcpy (ptmpQbuffer, acb->rqbuffer + tail, allxfer_len); +else { +memcpy (ptmpQbuffer, acb->rqbuffer + tail, cnt_to_end); +memcpy (ptmpQbuffer + cnt_to_end, acb->rqbuffer, allxfer_len - cnt_to_end); } + acb->rqbuf_getIndex = (acb->rqbuf_getIndex + allxfer_len) %ARCMSR_MAX_QBUFFER ; }if (acb->acb_flags &ACB_F_IOPDATA_OVERFLOW ) {struct QBUFFER __iomem *prbuffer;@@ -150,33 +116,32 @@ static ssize_t arcmsr_sysfs_iop_message_ struct device *dev = container_of(kobj,struct device,kobj);struct Scsi_Host *host =class_to_shost (dev);struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; -int32_t my_empty_len, user_len, wqbuf_firstindex, wqbuf_lastindex; +int32_t my_empty_len, user_len, wqbuf_getIndex, wqbuf_putIndex;uint8_t *pQbuffer, *ptmpuserbuffer;unsigned long flags;if (!capable (CAP_SYS_ADMIN ))return -EACCES ; -if (count >1032 ) +if (count >ARCMSR_API_DATA_BUFLEN )return -EINVAL ;/* do message unit write. */ ptmpuserbuffer = (uint8_t *)buf; user_len = (int32_t )count;spin_lock_irqsave (&acb->wqbuffer_lock, flags); - wqbuf_lastindex = acb->wqbuf_lastindex; - wqbuf_firstindex = acb->wqbuf_firstindex; -if (wqbuf_lastindex != wqbuf_firstindex) {drivers/scsi/arcmsr/arcmsr_attr.c static ssize_t arcmsr_sysfs_iop_message_ · line 138
Quoted 10 lines
drivers/scsi/arcmsr/arcmsr_attr.c +4
-2+ wqbuf_putIndex = acb->wqbuf_putIndex; + wqbuf_getIndex = acb->wqbuf_getIndex; +if (wqbuf_putIndex != wqbuf_getIndex) {arcmsr_write_ioctldata2iop (acb);spin_unlock_irqrestore (&acb->wqbuffer_lock, flags);return 0 ;/*need retry*/ }else { - my_empty_len = (wqbuf_firstindex-wqbuf_lastindex -1 ) - &(ARCMSR_MAX_QBUFFER -1 ); + my_empty_len =ARCMSR_MAX_QBUFFER -1 ;This^ doesn't look like like an rename can you explain?
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
It is just a code simplification.
Yes it is of some kind. But I think it's also a bug, because you have replaced 'firstindex - lastindex' with nothing.
It will be not a bug. At here, firstindex == lastindex, so firstindex-lastindex is 0
Thanks, I haven't seen it before. In that case because user_len is max 1032 and ARCMSR_MAX_QBUFFER is 4k the next if statement '(my_empty_len >= user_len)' will be true for any user_len (<1032), and it looks like you could remove my_empty_len completely.
Quoted 18 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Let us stop here, or we end in an endless loop of corrections. The original 13/17
you are trying to improve here was at least without bugs (better said I haven't noticed) so improving it now only complicates the process.
My suggestion is -let us skip this patch and focus only on fixing the spinlock problem found in 16/17. OKay?Quoted 8 lines
Quoted 8 lines
Agree.
Quoted 3 lines
Cheers,
Tomas--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 146 lines · Tomas Henzl
Quoted 145 lines · Ching Huang
Quoted 144 lines · Tomas Henzl
Quoted 143 lines · Ching Huang
Quoted 142 lines · Tomas Henzl
Quoted 7 lines · Ching Huang
From: Ching Huang <[email protected]>
This patch is to modify previous patch 13/17 and it is relative to
http://git.infradead.org/users/hch/scsi-queue.git/tree/arcmsr-for-3.18:/drivers/scsi/arcmsrchange in v4:
1. for readability, rename firstindex to getIndex, rename lastindex to putIndexFor some reason, the names head+tail areusual for a circular buffer. But let us ignore the names, I don't care.
Quoted 2 lines
2. define
ARCMSR_API_DATA_BUFLENas 1032
3. simplify ioctl data read by macroCIRC_CNT_TO_ENDandCIRC_CNTIt's definitely better when you post renames and other non-functional changes in separate patches, it's easier for the reviewer.
Quoted 117 lines
Signed-off-by Ching Huang <[email protected]>---
diff -uprN
a/drivers/scsi/arcmsr/arcmsr_attr.cb/drivers/scsi/arcmsr/arcmsr_attr.cdrivers/scsi/arcmsr/arcmsr_attr.c +19
-56@@ -50,6 +50,7 @@#include <linux/errno.h> #include <linux/delay.h> #include <linux/pci.h> +#include <linux/circ_buf.h> #include <scsi/scsi_cmnd.h> #include <scsi/scsi_device.h> @@ -68,7 +69,7 @@ static ssize_t arcmsr_sysfs_iop_message_ struct device *dev = container_of(kobj,struct device,kobj);struct Scsi_Host *host =class_to_shost (dev);struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; -uint8_t *pQbuffer,*ptmpQbuffer; +uint8_t *ptmpQbuffer;int32_t allxfer_len =0 ;unsigned long flags;@@ -78,57 +79,22 @@ static ssize_t arcmsr_sysfs_iop_message_/* do message unit read. */ ptmpQbuffer = (uint8_t *)buf;spin_lock_irqsave (&acb->rqbuffer_lock, flags); -if (acb->rqbuf_firstindex != acb->rqbuf_lastindex) { - pQbuffer = &acb->rqbuffer[acb->rqbuf_firstindex]; -if (acb->rqbuf_firstindex > acb->rqbuf_lastindex) { -if ((ARCMSR_MAX_QBUFFER - acb->rqbuf_firstindex) >=1032 ) { -memcpy (ptmpQbuffer, pQbuffer,1032 ); - acb->rqbuf_firstindex +=1032 ; - acb->rqbuf_firstindex %=ARCMSR_MAX_QBUFFER ; - allxfer_len =1032 ; - }else { -if (((ARCMSR_MAX_QBUFFER - acb->rqbuf_firstindex) - + acb->rqbuf_lastindex) >1032 ) { -memcpy (ptmpQbuffer, pQbuffer, -ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex); - ptmpQbuffer +=ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex; -memcpy (ptmpQbuffer, acb->rqbuffer,1032 - - (ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex)); - acb->rqbuf_firstindex =1032 - - (ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex); - allxfer_len =1032 ; - }else { -memcpy (ptmpQbuffer, pQbuffer, -ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex); - ptmpQbuffer +=ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex; -memcpy (ptmpQbuffer, acb->rqbuffer, - acb->rqbuf_lastindex); - allxfer_len =ARCMSR_MAX_QBUFFER - - acb->rqbuf_firstindex + - acb->rqbuf_lastindex; - acb->rqbuf_firstindex = - acb->rqbuf_lastindex; - } - } - }else { -if ((acb->rqbuf_lastindex - acb->rqbuf_firstindex) >1032 ) { -memcpy (ptmpQbuffer, pQbuffer,1032 ); - acb->rqbuf_firstindex +=1032 ; - allxfer_len =1032 ; - }else { -memcpy (ptmpQbuffer, pQbuffer, acb->rqbuf_lastindex - - acb->rqbuf_firstindex); - allxfer_len = acb->rqbuf_lastindex - - acb->rqbuf_firstindex; - acb->rqbuf_firstindex = acb->rqbuf_lastindex; - } +if (acb->rqbuf_getIndex != acb->rqbuf_putIndex) { +unsigned int tail = acb->rqbuf_getIndex; +unsigned int head = acb->rqbuf_putIndex; +unsigned int cnt_to_end =CIRC_CNT_TO_END (head, tail,ARCMSR_MAX_QBUFFER ); + + allxfer_len =CIRC_CNT (head, tail,ARCMSR_MAX_QBUFFER ); +if (allxfer_len >ARCMSR_API_DATA_BUFLEN ) + allxfer_len =ARCMSR_API_DATA_BUFLEN ; + +if (allxfer_len <= cnt_to_end) +memcpy (ptmpQbuffer, acb->rqbuffer + tail, allxfer_len); +else { +memcpy (ptmpQbuffer, acb->rqbuffer + tail, cnt_to_end); +memcpy (ptmpQbuffer + cnt_to_end, acb->rqbuffer, allxfer_len - cnt_to_end); } + acb->rqbuf_getIndex = (acb->rqbuf_getIndex + allxfer_len) %ARCMSR_MAX_QBUFFER ; }if (acb->acb_flags &ACB_F_IOPDATA_OVERFLOW ) {struct QBUFFER __iomem *prbuffer;@@ -150,33 +116,32 @@ static ssize_t arcmsr_sysfs_iop_message_ struct device *dev = container_of(kobj,struct device,kobj);struct Scsi_Host *host =class_to_shost (dev);struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; -int32_t my_empty_len, user_len, wqbuf_firstindex, wqbuf_lastindex; +int32_t my_empty_len, user_len, wqbuf_getIndex, wqbuf_putIndex;uint8_t *pQbuffer, *ptmpuserbuffer;unsigned long flags;if (!capable (CAP_SYS_ADMIN ))return -EACCES ; -if (count >1032 ) +if (count >ARCMSR_API_DATA_BUFLEN )return -EINVAL ;/* do message unit write. */ ptmpuserbuffer = (uint8_t *)buf; user_len = (int32_t )count;spin_lock_irqsave (&acb->wqbuffer_lock, flags); - wqbuf_lastindex = acb->wqbuf_lastindex; - wqbuf_firstindex = acb->wqbuf_firstindex; -if (wqbuf_lastindex != wqbuf_firstindex) {drivers/scsi/arcmsr/arcmsr_attr.c static ssize_t arcmsr_sysfs_iop_message_ · line 138
Quoted 10 lines
drivers/scsi/arcmsr/arcmsr_attr.c +4
-2+ wqbuf_putIndex = acb->wqbuf_putIndex; + wqbuf_getIndex = acb->wqbuf_getIndex; +if (wqbuf_putIndex != wqbuf_getIndex) {arcmsr_write_ioctldata2iop (acb);spin_unlock_irqrestore (&acb->wqbuffer_lock, flags);return 0 ;/*need retry*/ }else { - my_empty_len = (wqbuf_firstindex-wqbuf_lastindex -1 ) - &(ARCMSR_MAX_QBUFFER -1 ); + my_empty_len =ARCMSR_MAX_QBUFFER -1 ;This^ doesn't look like like an rename can you explain?
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
It is just a code simplification.
Yes it is of some kind. But I think it's also a bug, because you have replaced 'firstindex - lastindex' with nothing.
It will be not a bug. At here, firstindex == lastindex, so firstindex-lastindex is 0
Thanks, I haven't seen it before. In that case because
user_lenis max 1032 andARCMSR_MAX_QBUFFERis 4k the next if statement '(my_empty_len>=user_len)' will be true for anyuser_len(<1032), and it looks like you could removemy_empty_lencompletely.
Yes. You are right. thanks
Quoted 20 lines
Quoted 19 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Let us stop here, or we end in an endless loop of corrections. The original 13/17
you are trying to improve here was at least without bugs (better said I haven't noticed) so improving it now only complicates the process.
My suggestion is -let us skip this patch and focus only on fixing the spinlock problem found in 16/17. OKay?Quoted 8 lines
Quoted 8 lines
Agree.
Quoted 3 lines
Cheers,
Tomas--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html