net/mlx5: Added cond_resched() to crdump collection
Subsystems (4)
v2 cover net/mlx5: Added cond_resched() to crdump collection
Changes in v2:
- Removed cond_resched() in mlx5_vsc_wait_on_flag(). The idea is that usleep_range() should be enough.
- Updated cond_resched() in mlx5_vsc_gw_read_block_fast every 128 iterations.
v1: https://lore.kernel.org/all/[email protected]/
Mohamed Khalfella (1):
net/mlx5: Added cond_resched() to crdump collection
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c | 4 ++++ 1 file changed, 4 insertions(+)
Signature · 1 line
2.45.2
PATCH v2 1/1 net/mlx5: Added cond_resched() to crdump collection
Collecting crdump involves reading vsc registers from pci config space of mlx device, which can take long time to complete. This might result in starving other threads waiting to run on the cpu.
Numbers I got from testing ConnectX-5 Ex MCX516A-CDAT in the lab:
- mlx5_vsc_gw_read_block_fast() was called with length = 1310716.
- mlx5_vsc_gw_read_fast() reads 4 bytes at a time. It was not used to read the entire 1310716 bytes. It was called 53813 times because there are jumps in read_addr.
- On average mlx5_vsc_gw_read_fast() took 35284.4ns.
- In total mlx5_vsc_wait_on_flag() called vsc_read() 54707 times. The average time for each call was 17548.3ns. In some instances vsc_read() was called more than one time when the flag was not set. As expected the thread released the cpu after 16 iterations in mlx5_vsc_wait_on_flag().
- Total time to read crdump was 35284.4ns * 53813 ~= 1.898s.
It was seen in the field that crdump can take more than 5 seconds to complete. During that time mlx5_vsc_wait_on_flag() did not release the cpu because it did not complete 16 iterations. It is believed that pci config reads were slow. This change adds conditional reschedule call every 128 register read to release the cpu if needed.
--- drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +4 -0
@@ -269,6 +269,7 @@ int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data, {unsigned int next_read_addr =0 ;unsigned int read_addr =0 ; +unsigned int count =0 ;while (read_addr < length) { if (mlx5_vsc_gw_read_fast(dev, read_addr, &next_read_addr,
@@ -276,6 +277,9 @@ int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data,return read_addr; read_addr = next_read_addr; +/* Yield the cpu every 128 register read */ +if ((++count &0x7f ) ==0 ) +cond_resched (); }return length; }
Signature · 1 line
2.45.2
From: Mohamed Khalfella <[email protected]>
Date: Thu, 29 Aug 2024 15:38:56 -0600
Quoted 43 lines
Collecting crdump involves reading vsc registers from pci config space of mlx device, which can take long time to complete. This might result in starving other threads waiting to run on the cpu.
Numbers I got from testing ConnectX-5 Ex MCX516A-CDAT in the lab:
-
mlx5_vsc_gw_read_block_fast()was called with length = 1310716.
-mlx5_vsc_gw_read_fast()reads 4 bytes at a time. It was not used to read the entire 1310716 bytes. It was called 53813 times because there are jumps inread_addr.
- On averagemlx5_vsc_gw_read_fast()took 35284.4ns.
- In totalmlx5_vsc_wait_on_flag()calledvsc_read()54707 times. The average time for each call was 17548.3ns. In some instancesvsc_read()was called more than one time when the flag was not set. As expected the thread released the cpu after 16 iterations inmlx5_vsc_wait_on_flag().
- Total time to read crdump was 35284.4ns * 53813 ~= 1.898s.It was seen in the field that crdump can take more than 5 seconds to complete. During that time
mlx5_vsc_wait_on_flag()did not release the cpu because it did not complete 16 iterations. It is believed that pci config reads were slow. This change adds conditional reschedule call every 128 register read to release the cpu if needed.Reviewed-by Yuanyuan Zhong <[email protected]>Signed-off-by Mohamed Khalfella <[email protected]>--- drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +1
-0@@ -269,6 +269,7 @@ int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data, {unsigned int next_read_addr =0 ;unsigned int read_addr =0 ; +unsigned int count =0 ;while (read_addr < length) { if (mlx5_vsc_gw_read_fast(dev, read_addr, &next_read_addr,
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data, · line 282
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +3
-0@@ -276,6 +277,9 @@ int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data,return read_addr; read_addr = next_read_addr; +/* Yield the cpu every 128 register read */ +if ((++count &0x7f ) ==0 ) +cond_resched ();
Why & 0x7f, could it be written more clearly?
if (++count == 128) {
cond_resched();
count = 0;
}Also, I'd make this open-coded value a #define somewhere at the beginning of the file with a comment with a short explanation.
BTW, why 128? Not 64, not 256 etc? You just picked it, I don't see any explanation in the commitmsg or here in the code why exactly 128. Have you tried different values?
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data, · line 285
Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +0
-0}return length; }
Thanks,
Olek
Quoted 24 lines · Alexander Lobakin
From: Mohamed Khalfella <[email protected]>
Date: Thu, 29 Aug 2024 15:38:56 -0600Quoted 13 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +1
-0@@ -269,6 +269,7 @@ int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data, {unsigned int next_read_addr =0 ;unsigned int read_addr =0 ; +unsigned int count =0 ;while (read_addr < length) { if (mlx5_vsc_gw_read_fast(dev, read_addr, &next_read_addr,drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data, · line 282
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +3
-0@@ -276,6 +277,9 @@ int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data,return read_addr; read_addr = next_read_addr; +/* Yield the cpu every 128 register read */ +if ((++count &0x7f ) ==0 ) +cond_resched ();Why &
0x7f, could it be written more clearly?
Quoted 7 lines
if (++count == 128) { cond_resched(); count = 0; }Also, I'd make this open-coded value a #define somewhere at the beginning of the file with a comment with a short explanation.
What you are suggesting should work also. I copied the style from mlx5_vsc_wait_on_flag() to keep the code consistent. The comment above the line should make it clear.
Quoted 4 lines
BTW, why 128? Not 64, not 256 etc? You just picked it, I don't see any explanation in the commitmsg or here in the code why exactly 128. Have you tried different values?
This mostly subjective. For the numbers I saw in the lab, this will release the cpu after ~4.51ms. If crdump takes ~5s, the code should release the cpu after ~18.0ms. These numbers look reasonable to me.
From: Mohamed Khalfella <[email protected]>
Date: Fri, 30 Aug 2024 11:01:19 -0700
Quoted 25 lines · Alexander Lobakin
Quoted 24 lines
From: Mohamed Khalfella <[email protected]>
Date: Thu, 29 Aug 2024 15:38:56 -0600Quoted 13 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +1
-0@@ -269,6 +269,7 @@ int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data, {unsigned int next_read_addr =0 ;unsigned int read_addr =0 ; +unsigned int count =0 ;while (read_addr < length) { if (mlx5_vsc_gw_read_fast(dev, read_addr, &next_read_addr,drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data, · line 282
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +3
-0@@ -276,6 +277,9 @@ int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data,return read_addr; read_addr = next_read_addr; +/* Yield the cpu every 128 register read */ +if ((++count &0x7f ) ==0 ) +cond_resched ();Why &
0x7f, could it be written more clearly?
Quoted 7 lines
Quoted 7 lines
if (++count == 128) { cond_resched(); count = 0; }Also, I'd make this open-coded value a #define somewhere at the beginning of the file with a comment with a short explanation.
This is still valid.
Quoted 4 lines
What you are suggesting should work also. I copied the style from
mlx5_vsc_wait_on_flag()to keep the code consistent. The comment above the line should make it clear.
I just don't see a reason to make the code less readable.
Quoted 9 lines
Quoted 5 lines
BTW, why 128? Not 64, not 256 etc? You just picked it, I don't see any explanation in the commitmsg or here in the code why exactly 128. Have you tried different values?
This mostly subjective. For the numbers I saw in the lab, this will release the cpu after ~4.51ms. If crdump takes ~5s, the code should release the cpu after ~18.0ms. These numbers look reasonable to me.
So just mention in the commit message that you tried different values and 128 gave you the best results.
Thanks,
Olek
Quoted 33 lines · Alexander Lobakin
From: Mohamed Khalfella <[email protected]>
Date: Fri, 30 Aug 2024 11:01:19 -0700Quoted 30 lines · Alexander Lobakin
Quoted 29 lines
From: Mohamed Khalfella <[email protected]>
Date: Thu, 29 Aug 2024 15:38:56 -0600Quoted 13 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +1
-0@@ -269,6 +269,7 @@ int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data, {unsigned int next_read_addr =0 ;unsigned int read_addr =0 ; +unsigned int count =0 ;while (read_addr < length) { if (mlx5_vsc_gw_read_fast(dev, read_addr, &next_read_addr,drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data, · line 282
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +3
-0@@ -276,6 +277,9 @@ int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data,return read_addr; read_addr = next_read_addr; +/* Yield the cpu every 128 register read */ +if ((++count &0x7f ) ==0 ) +cond_resched ();Why &
0x7f, could it be written more clearly?if (++count == 128) { cond_resched(); count = 0; }
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Also, I'd make this open-coded value a #define somewhere at the beginning of the file with a comment with a short explanation.
This is still valid.
Done. See <1>.
Quoted 7 lines
Quoted 5 lines
What you are suggesting should work also. I copied the style from
mlx5_vsc_wait_on_flag()to keep the code consistent. The comment above the line should make it clear.I just don't see a reason to make the code less readable.
<1> Now I am looking at mlx5_vsc_wait_on_flag() again, I realized the code does not want to reset retries to 0 because it needs to check when it reaches VSC_MAX_RETRIES. This is not the case here. I will update the code as suggested.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
BTW, why 128? Not 64, not 256 etc? You just picked it, I don't see any explanation in the commitmsg or here in the code why exactly 128. Have you tried different values?
Quoted 6 lines
Quoted 3 lines
This mostly subjective. For the numbers I saw in the lab, this will release the cpu after ~4.51ms. If crdump takes ~5s, the code should release the cpu after ~18.0ms. These numbers look reasonable to me.
So just mention in the commit message that you tried different values and 128 gave you the best results.
I will update the commit message in v3.
Quoted 6 lines · Mohamed Khalfella
Changes in v2:
- Removedcond_resched()inmlx5_vsc_wait_on_flag(). The idea is thatusleep_range()should be enough.
- Updatedcond_resched()inmlx5_vsc_gw_read_block_fastevery 128 iterations.
Quoted 11 lines
v1: https://lore.kernel.org/all/[email protected]/
Mohamed Khalfella (1):
net/mlx5: Addedcond_resched()to crdump collectiondrivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c | 4 ++++ 1 file changed, 4 insertions(+)Signature · 1 line
2.45.2
Some how I missed to add reviewers were on v1 of this patch.
Przemek Kitszel
Reviewed-byQuoted 12 lines · Mohamed Khalfella
Quoted 11 lines · Mohamed Khalfella
Changes in v2:
- Removedcond_resched()inmlx5_vsc_wait_on_flag(). The idea is thatusleep_range()should be enough.
- Updatedcond_resched()inmlx5_vsc_gw_read_block_fastevery 128 iterations.v1: https://lore.kernel.org/all/[email protected]/
Mohamed Khalfella (1):
net/mlx5: Addedcond_resched()to crdump collection
Quoted 9 lines
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c | 4 ++++ 1 file changed, 4 insertions(+)Signature · 1 line
2.45.2Some how I missed to add reviewers were on v1 of this patch.
You did it right, there is need to provide explicit tag, just engaging in the discussion is not enough. v2 is fine, so:
Moshe Shemesh
Reviewed-byQuoted 21 lines · Przemek Kitszel
Quoted 19 lines · Mohamed Khalfella
Quoted 17 lines · Mohamed Khalfella
Changes in v2:
- Removedcond_resched()inmlx5_vsc_wait_on_flag(). The idea is thatusleep_range()should be enough.
- Updatedcond_resched()inmlx5_vsc_gw_read_block_fastevery 128 iterations.v1: https://lore.kernel.org/all/[email protected]/
Mohamed Khalfella (1):
net/mlx5: Addedcond_resched()to crdump collection
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c| 4 ++++1 file changed, 4 insertions(+)Signature · 1 line
2.45.2
Quoted 6 lines
Quoted 2 lines
Some how I missed to add reviewers were on v1 of this patch.
You did it right, there is need to provide explicit tag, just engaging in the discussion is not enough. v2 is fine, so:
Reviewed-by Przemek Kitszel <[email protected]>
And fixes tag should be:
Thanks.
Quoted 29 lines · Moshe Shemesh
Quoted 25 lines · Przemek Kitszel
Quoted 22 lines · Mohamed Khalfella
Quoted 6 lines · Mohamed Khalfella
Changes in v2:
- Removedcond_resched()inmlx5_vsc_wait_on_flag(). The idea is thatusleep_range()should be enough.
- Updatedcond_resched()inmlx5_vsc_gw_read_block_fastevery 128 iterations.Quoted 12 lines
v1:
https://lore.kernel.org/all/[email protected]/Mohamed Khalfella (1):
net/mlx5: Addedcond_resched()to crdump collection
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c| 4 ++++1 file changed, 4 insertions(+)Signature · 1 line
2.45.2Some how I missed to add reviewers were on v1 of this patch.
Quoted 7 lines
Quoted 3 lines
You did it right, there is need to provide explicit tag, just engaging in the discussion is not enough. v2 is fine, so:
Reviewed-by Przemek Kitszel <[email protected]>Reviewed-by Moshe Shemesh <[email protected]>And fixes tag should be:
Fixes 8b9d8baae1de ("net/mlx5: Add Crdump support")
Will add the tag in v3.
Quoted 34 lines · Mohamed Khalfella
Quoted 33 lines · Moshe Shemesh
Quoted 28 lines · Przemek Kitszel
Quoted 13 lines · Mohamed Khalfella
Quoted 12 lines · Mohamed Khalfella
Changes in v2:
- Removedcond_resched()inmlx5_vsc_wait_on_flag(). The idea is thatusleep_range()should be enough.
- Updatedcond_resched()inmlx5_vsc_gw_read_block_fastevery 128 iterations.v1:
https://lore.kernel.org/all/[email protected]/Mohamed Khalfella (1):
net/mlx5: Addedcond_resched()to crdump collectionQuoted 9 lines
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c| 4 ++++1 file changed, 4 insertions(+)Signature · 1 line
2.45.2Some how I missed to add reviewers were on v1 of this patch.
You did it right, there is need to provide explicit tag, just engaging in the discussion is not enough. v2 is fine, so:
Reviewed-by Przemek Kitszel <[email protected]>
Quoted 5 lines
Quoted 3 lines
Reviewed-by Moshe Shemesh <[email protected]>And fixes tag should be:
Fixes 8b9d8baae1de ("net/mlx5: Add Crdump support")Will add the tag in v3.
A quick follow up on this patch. I posted v3 [1] of this patch with minor changes. There are no functional differences between v2 and v3 of this patch. The commit messsage on v3 has information why call cond_resched() every 128 iterations, so that could be useful to add.
Is there anything I need to do to get v2 or v3 of this patch merged?
Quoted 40 lines · Mohamed Khalfella
Quoted 38 lines · Mohamed Khalfella
Quoted 36 lines · Moshe Shemesh
Quoted 22 lines · Przemek Kitszel
Quoted 20 lines · Mohamed Khalfella
Quoted 18 lines · Mohamed Khalfella
Changes in v2:
- Removedcond_resched()inmlx5_vsc_wait_on_flag(). The idea is thatusleep_range()should be enough.
- Updatedcond_resched()inmlx5_vsc_gw_read_block_fastevery 128 iterations.v1:
https://lore.kernel.org/all/[email protected]/Mohamed Khalfella (1):
net/mlx5: Addedcond_resched()to crdump collectiondrivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c | 4 ++++ 1 file changed, 4 insertions(+)--
2.45.2Quoted 6 lines
Quoted 2 lines
Some how I missed to add reviewers were on v1 of this patch.
You did it right, there is need to provide explicit tag, just engaging in the discussion is not enough. v2 is fine, so:
Reviewed-by Przemek Kitszel <[email protected]>Reviewed-by Moshe Shemesh <[email protected]>And fixes tag should be:
Fixes 8b9d8baae1de ("net/mlx5: Add Crdump support")
Quoted 8 lines
Quoted 1 line
Will add the tag in v3.
A quick follow up on this patch. I posted v3 [1] of this patch with minor changes. There are no functional differences between v2 and v3 of this patch. The commit messsage on v3 has information why call
cond_resched()every 128 iterations, so that could be useful to add.Is there anything I need to do to get v2 or v3 of this patch merged?
I already added my reviewed-by tag on this patch you can see up here, same goes to v3. Thanks.
Quoted 2 lines
Quoted 50 lines · Moshe Shemesh
Quoted 47 lines · Mohamed Khalfella
Quoted 34 lines · Mohamed Khalfella
Quoted 33 lines · Moshe Shemesh
Quoted 28 lines · Przemek Kitszel
Quoted 13 lines · Mohamed Khalfella
Quoted 12 lines · Mohamed Khalfella
Changes in v2:
- Removedcond_resched()inmlx5_vsc_wait_on_flag(). The idea is thatusleep_range()should be enough.
- Updatedcond_resched()inmlx5_vsc_gw_read_block_fastevery 128 iterations.v1:
https://lore.kernel.org/all/[email protected]/Mohamed Khalfella (1):
net/mlx5: Addedcond_resched()to crdump collectionQuoted 9 lines
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c | 4 ++++ 1 file changed, 4 insertions(+)--
2.45.2Some how I missed to add reviewers were on v1 of this patch.
You did it right, there is need to provide explicit tag, just engaging in the discussion is not enough. v2 is fine, so:
Reviewed-by Przemek Kitszel <[email protected]>Quoted 5 lines
Quoted 3 lines
Reviewed-by Moshe Shemesh <[email protected]>And fixes tag should be:
Fixes 8b9d8baae1de ("net/mlx5: Add Crdump support")Will add the tag in v3.
A quick follow up on this patch. I posted v3 [1] of this patch with minor changes. There are no functional differences between v2 and v3 of this patch. The commit messsage on v3 has information why call
cond_resched()every 128 iterations, so that could be useful to add.
Quoted 5 lines
Quoted 1 line
Is there anything I need to do to get v2 or v3 of this patch merged?
I already added my reviewed-by tag on this patch you can see up here, same goes to v3.
Thanks.
Thank you.