Skip to contentSkip to conversation

qlcnic: Optimize performance by replacing rw_lock with spinlock

PATCH In review Yu-Chun Lin 2 participants 4 messages Mar 6, 2025 – Mar 11, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qlcnic: Optimize performance by replacing rw_lock with spinlock

The 'crb_lock', an rwlock, is only used by writers, making it functionally equivalent to a spinlock.

According to Documentation/locking/spinlocks.rst:

"Reader-writer locks require more atomic memory operations than simple spinlocks. Unless the reader critical section is long, you are better off just using spinlocks."

Since read_lock() is never called, switching to a spinlock reduces overhead and improves efficiency.

---
 drivers/net/ethernet/qlogic/qlcnic/qlcnic.h      | 2 +-
 drivers/net/ethernet/qlogic/qlcnic/qlcnic_hw.c   | 8 ++++----
 drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/net/ethernet/qlogic/qlcnic/qlcnic.h +1 -1
index 3d0b5cd978cb..b8c8bc572042 100644
@@ -470,7 +470,7 @@ struct qlcnic_hardware_context {
 
 	unsigned long pci_len0;
 
-	rwlock_t crb_lock;
+	spinlock_t crb_lock;
 	struct mutex mem_lock;
 
 	u8 revision_id;
drivers/net/ethernet/qlogic/qlcnic/qlcnic_hw.c +4 -4
index ae4ee0326ee1..7b9bd0938229 100644
@@ -1185,13 +1185,13 @@ int qlcnic_82xx_hw_write_wx_2M(struct qlcnic_adapter *adapter, ulong off,
 
 	if (rv > 0) {
 		/* indirect access */
-		write_lock_irqsave(&adapter->ahw->crb_lock, flags);
+		spin_lock_irqsave(&adapter->ahw->crb_lock, flags);
 		crb_win_lock(adapter);
 		rv = qlcnic_pci_set_crbwindow_2M(adapter, off);
 		if (!rv)
 			writel(data, addr);
 		crb_win_unlock(adapter);
-		write_unlock_irqrestore(&adapter->ahw->crb_lock, flags);
+		spin_unlock_irqrestore(&adapter->ahw->crb_lock, flags);
 		return rv;
 	}
 
@@ -1216,12 +1216,12 @@ int qlcnic_82xx_hw_read_wx_2M(struct qlcnic_adapter *adapter, ulong off,
 
 	if (rv > 0) {
 		/* indirect access */
-		write_lock_irqsave(&adapter->ahw->crb_lock, flags);
+		spin_lock_irqsave(&adapter->ahw->crb_lock, flags);
 		crb_win_lock(adapter);
 		if (!qlcnic_pci_set_crbwindow_2M(adapter, off))
 			data = readl(addr);
 		crb_win_unlock(adapter);
-		write_unlock_irqrestore(&adapter->ahw->crb_lock, flags);
+		spin_unlock_irqrestore(&adapter->ahw->crb_lock, flags);
 		return data;
 	}
 
drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c +1 -1
index eb69121df726..5389e441fdae 100644
@@ -2508,7 +2508,7 @@ qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	else if (qlcnic_mac_learn == DRV_MAC_LEARN)
 		adapter->drv_mac_learn = true;
 
-	rwlock_init(&adapter->ahw->crb_lock);
+	spin_lock_init(&adapter->ahw->crb_lock);
 	mutex_init(&adapter->ahw->mem_lock);
 
 	INIT_LIST_HEAD(&adapter->mac_list);
Signature · 1 line
2.43.0
reviewer
#1 lore raw
Quoted 5 lines · Yu-Chun Lin

The 'crb_lock', an rwlock, is only used by writers, making it functionally equivalent to a spinlock.

According to Documentation/locking/spinlocks.rst:

Quoted 8 lines

"Reader-writer locks require more atomic memory operations than simple spinlocks. Unless the reader critical section is long, you are better off just using spinlocks."

Since read_lock() is never called, switching to a spinlock reduces overhead and improves efficiency.

Hi Yu-Chun Lin,

Thanks for your patch.

My main question is if you have hardware to test this? And if so, was a benefit observed?

If not, my feeling is that although your change looks correct, we'd be better off taking the lower risk option of leaving things be.

#2 lore raw
Quoted 17 lines · Simon Horman
Quoted 5 lines · Yu-Chun Lin

The 'crb_lock', an rwlock, is only used by writers, making it functionally equivalent to a spinlock.

According to Documentation/locking/spinlocks.rst:

Quoted 8 lines

"Reader-writer locks require more atomic memory operations than simple spinlocks. Unless the reader critical section is long, you are better off just using spinlocks."

Since read_lock() is never called, switching to a spinlock reduces overhead and improves efficiency.

Hi Yu-Chun Lin,

Quoted 8 lines

Thanks for your patch.

My main question is if you have hardware to test this? And if so, was a benefit observed?

If not, my feeling is that although your change looks correct, we'd be better off taking the lower risk option of leaving things be.

Hi Simon

I perform a compile test to ensure correctness. But I don't have the hardware to run a full test.

Yu-Chun Lin

reviewer
#3 lore raw
Quoted 23 lines · Yu-Chun Lin
Quoted 22 lines · Simon Horman
Quoted 5 lines · Yu-Chun Lin

The 'crb_lock', an rwlock, is only used by writers, making it functionally equivalent to a spinlock.

According to Documentation/locking/spinlocks.rst:

Quoted 8 lines

"Reader-writer locks require more atomic memory operations than simple spinlocks. Unless the reader critical section is long, you are better off just using spinlocks."

Since read_lock() is never called, switching to a spinlock reduces overhead and improves efficiency.

Hi Yu-Chun Lin,

Thanks for your patch.

My main question is if you have hardware to test this? And if so, was a benefit observed?

Quoted 8 lines
Quoted 3 lines

If not, my feeling is that although your change looks correct, we'd be better off taking the lower risk option of leaving things be.

Hi Simon

I perform a compile test to ensure correctness. But I don't have the hardware to run a full test.

Thanks Yu-Chun Lin,

Unfortunately I think we need hardware testing to accept this kind of change.