From: Tomas Henzl <thenzl@redhat.com>
To: Ching Huang <ching2048@areca.com.tw>
Cc: hch@infradead.org, jbottomley@parallels.com,
dan.carpenter@oracle.com, agordeev@redhat.com,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 1/2] arcmsr: simplify ioctl data read/write
Date: Mon, 15 Sep 2014 12:25:29 +0200 [thread overview]
Message-ID: <5416BE99.3000409@redhat.com> (raw)
In-Reply-To: <1410749808.4764.5.camel@Centos6.3-64>
On 09/15/2014 04:56 AM, Ching Huang wrote:
> On Fri, 2014-09-12 at 15:34 +0200, Tomas Henzl wrote:
>> On 09/12/2014 09:29 AM, Ching Huang wrote:
>>> From: Ching Huang <ching2048@areca.com.tw>
>>>
>>> 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
>> For some reason, the names head+tail areusual for a circular buffer.
>> But let us ignore the names, I don't care.
>>> 2. define ARCMSR_API_DATA_BUFLEN as 1032
>>> 3. simplify ioctl data read by macro CIRC_CNT_TO_END and CIRC_CNT
>> It's definitely better when you post renames and other non-functional changes in separate
>> patches, it's easier for the reviewer.
>>> Signed-off-by: Ching Huang <ching2048@areca.com.tw>
>>> ---
>>>
>>> diff -uprN a/drivers/scsi/arcmsr/arcmsr_attr.c b/drivers/scsi/arcmsr/arcmsr_attr.c
>>> --- a/drivers/scsi/arcmsr/arcmsr_attr.c 2014-08-21 12:14:27.000000000 +0800
>>> +++ b/drivers/scsi/arcmsr/arcmsr_attr.c 2014-09-12 15:18:46.659125000 +0800
>>> @@ -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;
>> This^ doesn't look like like an rename can you explain?
> 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.
>> 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.
>> Cheers,
>> Tomas
>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2014-09-15 10:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-12 7:29 [PATCH v4 1/2] arcmsr: simplify ioctl data read/write Ching Huang
2014-09-12 13:34 ` Tomas Henzl
2014-09-15 2:56 ` Ching Huang
2014-09-15 10:25 ` Tomas Henzl [this message]
2014-09-15 10:36 ` Ching Huang
2014-09-15 11:50 ` Tomas Henzl
2014-09-15 12:03 ` Ching Huang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5416BE99.3000409@redhat.com \
--to=thenzl@redhat.com \
--cc=agordeev@redhat.com \
--cc=ching2048@areca.com.tw \
--cc=dan.carpenter@oracle.com \
--cc=hch@infradead.org \
--cc=jbottomley@parallels.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.