Message ID | 20170113233538.36196-2-briannorris@chromium.org (mailing list archive) |
---|---|
State | Accepted |
Commit | 5d5ddb5e0d9bc3ff3f377c6e03a074d13606a6e5 |
Delegated to: | Kalle Valo |
Headers | show |
On Fri, Jan 13, 2017 at 03:35:37PM -0800, Brian Norris wrote: > The following sequence occurs when using IEEE power-save on 8997: > (a) driver sees SLEEP event > (b) driver issues SLEEP CONFIRM > (c) driver recevies CMD interrupt; within the interrupt processing loop, > we do (d) and (e): > (d) wait for FW sleep cookie (and often time out; it takes a while), FW > is putting card into low power mode > (e) re-check PCIE_HOST_INT_STATUS register; quit loop with 0 value > > But at (e), no one actually signaled an interrupt (i.e., we didn't check > adapter->int_status). And what's more, because the card is going to > sleep, this register read appears to take a very long time in some cases > -- 3 milliseconds in my case! > > Now, I propose that (e) is completely unnecessary. If there were any > additional interrupts signaled after the start of this loop, then the > interrupt handler would have set adapter->int_status to non-zero and > queued more work for the main loop -- and we'd catch it on the next > iteration of the main loop. > > So this patch drops all the looping/re-reading of PCIE_HOST_INT_STATUS, > which avoids the problematic (and slow) register read in step (e). > > Incidentally, this is a very similar issue to the one fixed in commit > ec815dd2a5f1 ("mwifiex: prevent register accesses after host is > sleeping"), except that the register read is just very slow instead of > fatal in this case. > > Tested on 8997 in both MSI and (though not technically supported at the > moment) MSI-X mode. Well, that kills interrupt mitigation and with PCIE that might be somewhat important (SDIO is too slow to be important I think) and might cost you throughput. OTOH maybe Marvell should convert PICE to NAPI to make this more obvious and probably more correct. > > Signed-off-by: Brian Norris <briannorris@chromium.org> > --- > v2: > * new in v2, replacing an attempt to mess with step (d) above > --- > drivers/net/wireless/marvell/mwifiex/pcie.c | 102 +++++++++------------------- > 1 file changed, 32 insertions(+), 70 deletions(-) > > diff --git a/drivers/net/wireless/marvell/mwifiex/pcie.c b/drivers/net/wireless/marvell/mwifiex/pcie.c > index 3f4cda2d3b61..194e0e04c3b1 100644 > --- a/drivers/net/wireless/marvell/mwifiex/pcie.c > +++ b/drivers/net/wireless/marvell/mwifiex/pcie.c > @@ -2332,79 +2332,41 @@ static int mwifiex_process_pcie_int(struct mwifiex_adapter *adapter) > } > } > } > - while (pcie_ireg & HOST_INTR_MASK) { > - if (pcie_ireg & HOST_INTR_DNLD_DONE) { > - pcie_ireg &= ~HOST_INTR_DNLD_DONE; > - mwifiex_dbg(adapter, INTR, > - "info: TX DNLD Done\n"); > - ret = mwifiex_pcie_send_data_complete(adapter); > - if (ret) > - return ret; > - } > - if (pcie_ireg & HOST_INTR_UPLD_RDY) { > - pcie_ireg &= ~HOST_INTR_UPLD_RDY; > - mwifiex_dbg(adapter, INTR, > - "info: Rx DATA\n"); > - ret = mwifiex_pcie_process_recv_data(adapter); > - if (ret) > - return ret; > - } > - if (pcie_ireg & HOST_INTR_EVENT_RDY) { > - pcie_ireg &= ~HOST_INTR_EVENT_RDY; > - mwifiex_dbg(adapter, INTR, > - "info: Rx EVENT\n"); > - ret = mwifiex_pcie_process_event_ready(adapter); > - if (ret) > - return ret; > - } > - > - if (pcie_ireg & HOST_INTR_CMD_DONE) { > - pcie_ireg &= ~HOST_INTR_CMD_DONE; > - if (adapter->cmd_sent) { > - mwifiex_dbg(adapter, INTR, > - "info: CMD sent Interrupt\n"); > - adapter->cmd_sent = false; > - } > - /* Handle command response */ > - ret = mwifiex_pcie_process_cmd_complete(adapter); > - if (ret) > - return ret; > - if (adapter->hs_activated) > - return ret; > - } > - > - if (card->msi_enable) { > - spin_lock_irqsave(&adapter->int_lock, flags); > - adapter->int_status = 0; > - spin_unlock_irqrestore(&adapter->int_lock, flags); > - } > - > - if (mwifiex_pcie_ok_to_access_hw(adapter)) { > - if (mwifiex_read_reg(adapter, PCIE_HOST_INT_STATUS, > - &pcie_ireg)) { > - mwifiex_dbg(adapter, ERROR, > - "Read register failed\n"); > - return -1; > - } > > - if ((pcie_ireg != 0xFFFFFFFF) && (pcie_ireg)) { > - if (mwifiex_write_reg(adapter, > - PCIE_HOST_INT_STATUS, > - ~pcie_ireg)) { > - mwifiex_dbg(adapter, ERROR, > - "Write register failed\n"); > - return -1; > - } > - } > - > - } > - if (!card->msi_enable) { > - spin_lock_irqsave(&adapter->int_lock, flags); > - pcie_ireg |= adapter->int_status; > - adapter->int_status = 0; > - spin_unlock_irqrestore(&adapter->int_lock, flags); > + if (pcie_ireg & HOST_INTR_DNLD_DONE) { > + pcie_ireg &= ~HOST_INTR_DNLD_DONE; > + mwifiex_dbg(adapter, INTR, "info: TX DNLD Done\n"); > + ret = mwifiex_pcie_send_data_complete(adapter); > + if (ret) > + return ret; > + } > + if (pcie_ireg & HOST_INTR_UPLD_RDY) { > + pcie_ireg &= ~HOST_INTR_UPLD_RDY; > + mwifiex_dbg(adapter, INTR, "info: Rx DATA\n"); > + ret = mwifiex_pcie_process_recv_data(adapter); > + if (ret) > + return ret; > + } > + if (pcie_ireg & HOST_INTR_EVENT_RDY) { > + pcie_ireg &= ~HOST_INTR_EVENT_RDY; > + mwifiex_dbg(adapter, INTR, "info: Rx EVENT\n"); > + ret = mwifiex_pcie_process_event_ready(adapter); > + if (ret) > + return ret; > + } > + if (pcie_ireg & HOST_INTR_CMD_DONE) { > + pcie_ireg &= ~HOST_INTR_CMD_DONE; > + if (adapter->cmd_sent) { > + mwifiex_dbg(adapter, INTR, > + "info: CMD sent Interrupt\n"); > + adapter->cmd_sent = false; > } > + /* Handle command response */ > + ret = mwifiex_pcie_process_cmd_complete(adapter); > + if (ret) > + return ret; > } > + > mwifiex_dbg(adapter, INTR, > "info: cmd_sent=%d data_sent=%d\n", > adapter->cmd_sent, adapter->data_sent); > -- > 2.11.0.483.g087da7b7c-goog >
On Sun, Jan 15, 2017 at 04:54:52PM -0800, Dmitry Torokhov wrote: > On Fri, Jan 13, 2017 at 03:35:37PM -0800, Brian Norris wrote: > > The following sequence occurs when using IEEE power-save on 8997: > > (a) driver sees SLEEP event > > (b) driver issues SLEEP CONFIRM > > (c) driver recevies CMD interrupt; within the interrupt processing loop, > > we do (d) and (e): > > (d) wait for FW sleep cookie (and often time out; it takes a while), FW > > is putting card into low power mode > > (e) re-check PCIE_HOST_INT_STATUS register; quit loop with 0 value > > > > But at (e), no one actually signaled an interrupt (i.e., we didn't check > > adapter->int_status). And what's more, because the card is going to > > sleep, this register read appears to take a very long time in some cases > > -- 3 milliseconds in my case! > > > > Now, I propose that (e) is completely unnecessary. If there were any > > additional interrupts signaled after the start of this loop, then the > > interrupt handler would have set adapter->int_status to non-zero and > > queued more work for the main loop -- and we'd catch it on the next > > iteration of the main loop. > > > > So this patch drops all the looping/re-reading of PCIE_HOST_INT_STATUS, > > which avoids the problematic (and slow) register read in step (e). > > > > Incidentally, this is a very similar issue to the one fixed in commit > > ec815dd2a5f1 ("mwifiex: prevent register accesses after host is > > sleeping"), except that the register read is just very slow instead of > > fatal in this case. > > > > Tested on 8997 in both MSI and (though not technically supported at the > > moment) MSI-X mode. > > Well, that kills interrupt mitigation and with PCIE that might be > somewhat important (SDIO is too slow to be important I think) and might > cost you throughput. Hmm, well I don't see us disabling interrupts in here, at least for MSI mode, so it doesn't actually look like a mitigation mechanism. More like a redundancy. But I'm not an expert on MSI, and definitely not on network performance. Also, FWIW, I did some fairly non-scientific tests of this on my systems, and I didn't see much difference. I can run better tests, and even collect data on how often we loop here vs. see new interrupts. > OTOH maybe Marvell should convert PICE to NAPI to make this more > obvious and probably more correct. From my brief reading, that sounds like a better way to make this configurable. So I'm not sure which way you'd suggest then; take a patch like this, which makes the driver more clear and less buggy? Or write some different patch that isolates just the power-save related condition, so we break out of this look [1]? I'm also interested in any opinions from the Marvell side -- potentially testing results, rationale behind this code structure, or even a better alternative patch. Brian [1] i.e., along the lines of commit ec815dd2a5f1 ("mwifiex: prevent register accesses after host is sleeping").
On Tue, Jan 17, 2017 at 11:48:22AM -0800, Brian Norris wrote: > On Sun, Jan 15, 2017 at 04:54:52PM -0800, Dmitry Torokhov wrote: > > On Fri, Jan 13, 2017 at 03:35:37PM -0800, Brian Norris wrote: > > > The following sequence occurs when using IEEE power-save on 8997: > > > (a) driver sees SLEEP event > > > (b) driver issues SLEEP CONFIRM > > > (c) driver recevies CMD interrupt; within the interrupt processing loop, > > > we do (d) and (e): > > > (d) wait for FW sleep cookie (and often time out; it takes a while), FW > > > is putting card into low power mode > > > (e) re-check PCIE_HOST_INT_STATUS register; quit loop with 0 value > > > > > > But at (e), no one actually signaled an interrupt (i.e., we didn't check > > > adapter->int_status). And what's more, because the card is going to > > > sleep, this register read appears to take a very long time in some cases > > > -- 3 milliseconds in my case! > > > > > > Now, I propose that (e) is completely unnecessary. If there were any > > > additional interrupts signaled after the start of this loop, then the > > > interrupt handler would have set adapter->int_status to non-zero and > > > queued more work for the main loop -- and we'd catch it on the next > > > iteration of the main loop. > > > > > > So this patch drops all the looping/re-reading of PCIE_HOST_INT_STATUS, > > > which avoids the problematic (and slow) register read in step (e). > > > > > > Incidentally, this is a very similar issue to the one fixed in commit > > > ec815dd2a5f1 ("mwifiex: prevent register accesses after host is > > > sleeping"), except that the register read is just very slow instead of > > > fatal in this case. > > > > > > Tested on 8997 in both MSI and (though not technically supported at the > > > moment) MSI-X mode. > > > > Well, that kills interrupt mitigation and with PCIE that might be > > somewhat important (SDIO is too slow to be important I think) and might > > cost you throughput. > > Hmm, well I don't see us disabling interrupts in here, at least for MSI > mode, so it doesn't actually look like a mitigation mechanism. More like > a redundancy. But I'm not an expert on MSI, and definitely not on > network performance. Well, right, maybe not mitigation, but at least you have a chance to avoid scheduling latency at times. > > Also, FWIW, I did some fairly non-scientific tests of this on my > systems, and I didn't see much difference. I can run better tests, and > even collect data on how often we loop here vs. see new interrupts. That would be great. Maybe packet aggregation takes care of interrupts arriving "too closely" together most of the time, I dunno. > > > OTOH maybe Marvell should convert PICE to NAPI to make this more > > obvious and probably more correct. > > From my brief reading, that sounds like a better way to make this > configurable. > > So I'm not sure which way you'd suggest then; take a patch like this, > which makes the driver more clear and less buggy? Or write some > different patch that isolates just the power-save related condition, so > we break out of this look [1]? I think it really depends on the test results. If we do not see degradation in both throughput and latency then I think we can take this patch and then see if switching to NAPI would be the ultimate solution. > > I'm also interested in any opinions from the Marvell side -- potentially > testing results, rationale behind this code structure, or even a better > alternative patch. > > Brian > > [1] i.e., along the lines of commit ec815dd2a5f1 ("mwifiex: prevent > register accesses after host is sleeping"). Thanks.
On Tue, Jan 17, 2017 at 12:44:55PM -0800, Dmitry Torokhov wrote: > On Tue, Jan 17, 2017 at 11:48:22AM -0800, Brian Norris wrote: > > Also, FWIW, I did some fairly non-scientific tests of this on my > > systems, and I didn't see much difference. I can run better tests, and > > even collect data on how often we loop here vs. see new interrupts. > > That would be great. Maybe packet aggregation takes care of interrupts > arriving "too closely" together most of the time, I dunno. OK, so I did some basic accounting of how many times this while loop runs in a row. I don't know if they're highly illuminating, but here goes. They're listed as a histogram, where the first column is number of samples that exhibited the behavior and second column is number of times going through the loop before exiting (i.e., seeing no more INT_STATUS): Idle (just scanning for networks occasionally, and loading a web page or two) for a minute or two: 1 265 1 2 2 Downloading a Chrome .deb package via wget, in a loop: 857 0 36406 1 32386 2 2230 3 153 4 11 5 Running a perf client test (i.e., TX traffic) in a loop: 1694 0 247897 1 25530 2 441 3 18 4 So it seems like in some cases, it's at least *possible* to have a little bit of potential savings on 10-50% of interrupts when under load. (i.e., see that ~50% of interrupt checks take 2, 3, 4, or 5 loops in the second example.) Now, I also did some perf numbers with iperf between a Raspberry Pi iperf server and an ARM64 system running mwifiex. On the whole, the TX side was probably bottlenecked by the RPi, but the RX side was pretty good. I'll attach full numbers, but the percentage delta is as follows: Mean Median ------ ------ % change, bi-direction (RX): -0.3 -4.5 % change, bi-direction (TX): 1.034 4.45 % change, TX only: 12.96 13.35 % change, RX only: -6.5 -3 I'm not sure I have a good explanation for the gain in TX performance. Perhaps partly the reduction in complexity (e.g., unnecessary register reads). Perhaps also because I had IEEE power-save enabled, so without this patch, performance could (theoretically) be harmed by the issue mentioned in the commit description (i.e., occasional slow PCIe reads) -- though I guess we probably don't enter power-save often during iperf tests. So, there could definitely be some methodology mistakes or other variables involved, but these don't seem to show any particularly bad performance loss, and if we did, we might consider other approaches like NAPI for tuning them. Brian
Hi Brian, > From: Brian Norris [mailto:briannorris@chromium.org] > Sent: Wednesday, January 18, 2017 1:18 AM > To: Dmitry Torokhov > Cc: Amitkumar Karwar; Nishant Sarmukadam; linux-kernel@vger.kernel.org; > Kalle Valo; linux-wireless@vger.kernel.org; Cathy Luo > Subject: Re: [PATCH v2 2/3] mwifiex: pcie: don't loop/retry > interrupt status checks > > On Sun, Jan 15, 2017 at 04:54:52PM -0800, Dmitry Torokhov wrote: > > On Fri, Jan 13, 2017 at 03:35:37PM -0800, Brian Norris wrote: > > > The following sequence occurs when using IEEE power-save on 8997: > > > (a) driver sees SLEEP event > > > (b) driver issues SLEEP CONFIRM > > > (c) driver recevies CMD interrupt; within the interrupt processing > loop, > > > we do (d) and (e): > > > (d) wait for FW sleep cookie (and often time out; it takes a > while), FW > > > is putting card into low power mode > > > (e) re-check PCIE_HOST_INT_STATUS register; quit loop with 0 value > > > > > > But at (e), no one actually signaled an interrupt (i.e., we didn't > > > check > > > adapter->int_status). And what's more, because the card is going to > > > sleep, this register read appears to take a very long time in some > > > cases > > > -- 3 milliseconds in my case! > > > > > > Now, I propose that (e) is completely unnecessary. If there were > any > > > additional interrupts signaled after the start of this loop, then > > > the interrupt handler would have set adapter->int_status to non- > zero > > > and queued more work for the main loop -- and we'd catch it on the > > > next iteration of the main loop. > > > > > > So this patch drops all the looping/re-reading of > > > PCIE_HOST_INT_STATUS, which avoids the problematic (and slow) > register read in step (e). > > > > > > Incidentally, this is a very similar issue to the one fixed in > > > commit > > > ec815dd2a5f1 ("mwifiex: prevent register accesses after host is > > > sleeping"), except that the register read is just very slow instead > > > of fatal in this case. > > > > > > Tested on 8997 in both MSI and (though not technically supported at > > > the > > > moment) MSI-X mode. > > > > Well, that kills interrupt mitigation and with PCIE that might be > > somewhat important (SDIO is too slow to be important I think) and > > might cost you throughput. > > Hmm, well I don't see us disabling interrupts in here, at least for MSI > mode, so it doesn't actually look like a mitigation mechanism. More > like a redundancy. But I'm not an expert on MSI, and definitely not on > network performance. > > Also, FWIW, I did some fairly non-scientific tests of this on my > systems, and I didn't see much difference. I can run better tests, and > even collect data on how often we loop here vs. see new interrupts. > > > OTOH maybe Marvell should convert PICE to NAPI to make this more > > obvious and probably more correct. > > From my brief reading, that sounds like a better way to make this > configurable. > > So I'm not sure which way you'd suggest then; take a patch like this, > which makes the driver more clear and less buggy? Or write some > different patch that isolates just the power-save related condition, so > we break out of this look [1]? > > I'm also interested in any opinions from the Marvell side -- > potentially testing results, rationale behind this code structure, or > even a better alternative patch. > Thanks for the fix. It looks fine to me. Alternate fix would be below change. We ran throughput tests with your patch vs below change. Results are almost same. -------- @@ -2370,7 +2370,7 @@ static int mwifiex_process_pcie_int(struct mwifiex_adapter *adapter) ret = mwifiex_pcie_process_cmd_complete(adapter); if (ret) return ret; - if (adapter->hs_activated) + if (adapter->hs_activated || adapter->ps_state == PS_STATE_SLEEP) return ret; -------- The logic of having while loop here was to avoid scheduling latency. As Dmitry pointed out in other email packet aggregation takes care of interrupts arriving too closely together. We have Rx buffer ring of size 32. So we may get a single interrupt to deliver 32 Rx packets. Regards, Amitkumar
diff --git a/drivers/net/wireless/marvell/mwifiex/pcie.c b/drivers/net/wireless/marvell/mwifiex/pcie.c index 3f4cda2d3b61..194e0e04c3b1 100644 --- a/drivers/net/wireless/marvell/mwifiex/pcie.c +++ b/drivers/net/wireless/marvell/mwifiex/pcie.c @@ -2332,79 +2332,41 @@ static int mwifiex_process_pcie_int(struct mwifiex_adapter *adapter) } } } - while (pcie_ireg & HOST_INTR_MASK) { - if (pcie_ireg & HOST_INTR_DNLD_DONE) { - pcie_ireg &= ~HOST_INTR_DNLD_DONE; - mwifiex_dbg(adapter, INTR, - "info: TX DNLD Done\n"); - ret = mwifiex_pcie_send_data_complete(adapter); - if (ret) - return ret; - } - if (pcie_ireg & HOST_INTR_UPLD_RDY) { - pcie_ireg &= ~HOST_INTR_UPLD_RDY; - mwifiex_dbg(adapter, INTR, - "info: Rx DATA\n"); - ret = mwifiex_pcie_process_recv_data(adapter); - if (ret) - return ret; - } - if (pcie_ireg & HOST_INTR_EVENT_RDY) { - pcie_ireg &= ~HOST_INTR_EVENT_RDY; - mwifiex_dbg(adapter, INTR, - "info: Rx EVENT\n"); - ret = mwifiex_pcie_process_event_ready(adapter); - if (ret) - return ret; - } - - if (pcie_ireg & HOST_INTR_CMD_DONE) { - pcie_ireg &= ~HOST_INTR_CMD_DONE; - if (adapter->cmd_sent) { - mwifiex_dbg(adapter, INTR, - "info: CMD sent Interrupt\n"); - adapter->cmd_sent = false; - } - /* Handle command response */ - ret = mwifiex_pcie_process_cmd_complete(adapter); - if (ret) - return ret; - if (adapter->hs_activated) - return ret; - } - - if (card->msi_enable) { - spin_lock_irqsave(&adapter->int_lock, flags); - adapter->int_status = 0; - spin_unlock_irqrestore(&adapter->int_lock, flags); - } - - if (mwifiex_pcie_ok_to_access_hw(adapter)) { - if (mwifiex_read_reg(adapter, PCIE_HOST_INT_STATUS, - &pcie_ireg)) { - mwifiex_dbg(adapter, ERROR, - "Read register failed\n"); - return -1; - } - if ((pcie_ireg != 0xFFFFFFFF) && (pcie_ireg)) { - if (mwifiex_write_reg(adapter, - PCIE_HOST_INT_STATUS, - ~pcie_ireg)) { - mwifiex_dbg(adapter, ERROR, - "Write register failed\n"); - return -1; - } - } - - } - if (!card->msi_enable) { - spin_lock_irqsave(&adapter->int_lock, flags); - pcie_ireg |= adapter->int_status; - adapter->int_status = 0; - spin_unlock_irqrestore(&adapter->int_lock, flags); + if (pcie_ireg & HOST_INTR_DNLD_DONE) { + pcie_ireg &= ~HOST_INTR_DNLD_DONE; + mwifiex_dbg(adapter, INTR, "info: TX DNLD Done\n"); + ret = mwifiex_pcie_send_data_complete(adapter); + if (ret) + return ret; + } + if (pcie_ireg & HOST_INTR_UPLD_RDY) { + pcie_ireg &= ~HOST_INTR_UPLD_RDY; + mwifiex_dbg(adapter, INTR, "info: Rx DATA\n"); + ret = mwifiex_pcie_process_recv_data(adapter); + if (ret) + return ret; + } + if (pcie_ireg & HOST_INTR_EVENT_RDY) { + pcie_ireg &= ~HOST_INTR_EVENT_RDY; + mwifiex_dbg(adapter, INTR, "info: Rx EVENT\n"); + ret = mwifiex_pcie_process_event_ready(adapter); + if (ret) + return ret; + } + if (pcie_ireg & HOST_INTR_CMD_DONE) { + pcie_ireg &= ~HOST_INTR_CMD_DONE; + if (adapter->cmd_sent) { + mwifiex_dbg(adapter, INTR, + "info: CMD sent Interrupt\n"); + adapter->cmd_sent = false; } + /* Handle command response */ + ret = mwifiex_pcie_process_cmd_complete(adapter); + if (ret) + return ret; } + mwifiex_dbg(adapter, INTR, "info: cmd_sent=%d data_sent=%d\n", adapter->cmd_sent, adapter->data_sent);
The following sequence occurs when using IEEE power-save on 8997: (a) driver sees SLEEP event (b) driver issues SLEEP CONFIRM (c) driver recevies CMD interrupt; within the interrupt processing loop, we do (d) and (e): (d) wait for FW sleep cookie (and often time out; it takes a while), FW is putting card into low power mode (e) re-check PCIE_HOST_INT_STATUS register; quit loop with 0 value But at (e), no one actually signaled an interrupt (i.e., we didn't check adapter->int_status). And what's more, because the card is going to sleep, this register read appears to take a very long time in some cases -- 3 milliseconds in my case! Now, I propose that (e) is completely unnecessary. If there were any additional interrupts signaled after the start of this loop, then the interrupt handler would have set adapter->int_status to non-zero and queued more work for the main loop -- and we'd catch it on the next iteration of the main loop. So this patch drops all the looping/re-reading of PCIE_HOST_INT_STATUS, which avoids the problematic (and slow) register read in step (e). Incidentally, this is a very similar issue to the one fixed in commit ec815dd2a5f1 ("mwifiex: prevent register accesses after host is sleeping"), except that the register read is just very slow instead of fatal in this case. Tested on 8997 in both MSI and (though not technically supported at the moment) MSI-X mode. Signed-off-by: Brian Norris <briannorris@chromium.org> --- v2: * new in v2, replacing an attempt to mess with step (d) above --- drivers/net/wireless/marvell/mwifiex/pcie.c | 102 +++++++++------------------- 1 file changed, 32 insertions(+), 70 deletions(-)