net/mlx5: Added cond_resched() to crdump collection
Subsystems (4)
PATCH 1/1 net/mlx5: Added cond_resched() to crdump collection
Collecting crdump involves dumping vsc registers from pci config space of mlx device. The code can run for long time starving other threads want to run on the cpu. Added conditional reschedule between register reads and while waiting for register value to release the cpu more often.
--- drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +2 -0
@@ -191,6 +191,7 @@ static int mlx5_vsc_wait_on_flag(struct mlx5_core_dev *dev, u8 expected_val)if ((retries &0xf ) ==0 )usleep_range (1000 ,2000 ); +cond_resched (); }while (flag != expected_val);return 0 ;
@@ -280,6 +281,7 @@ int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data,return read_addr; read_addr = next_read_addr; +cond_resched (); }return length; }
Signature · 1 line
2.45.2
Quoted 17 lines · Mohamed Khalfella
Collecting crdump involves dumping vsc registers from pci config space of mlx device. The code can run for long time starving other threads want to run on the cpu. Added conditional reschedule between register reads and while waiting for register value to release the cpu more often.
Reviewed-by Yuanyuan Zhong <[email protected]>Signed-off-by Mohamed Khalfella <[email protected]>--- drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c | 2 ++ 1 file changed, 2 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +0
-0
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c static int mlx5_vsc_wait_on_flag(struct mlx5_core_dev *dev, u8 expected_val) · line 194
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +1
-0@@ -191,6 +191,7 @@ static int mlx5_vsc_wait_on_flag(struct mlx5_core_dev *dev, u8 expected_val)if ((retries &0xf ) ==0 )usleep_range (1000 ,2000 ); +cond_resched ();
the sleeping logic above (including what is out of git diff context) is a bit weird (tight loop with a sleep after each 16 attempts, with an upper bound of 2k attempts!)
My understanding of usleep_range() is that it puts process to sleep (and even leads to sched() call).
So cond_resched() looks redundant here.
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 284
Quoted 8 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +1
-0}while (flag != expected_val);return 0 ;@@ -280,6 +281,7 @@ int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data,return read_addr; read_addr = next_read_addr; +cond_resched ();
Would be great to see how many registers there are/how long it takes to dump them in commit message.
My guess is that a single mlx5_vsc_gw_read_fast() call is very short and there are many. With that cond_resched() should be rather under some if (iterator % XXX == 0) condition.
Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +0
-0}return length; }
Quoted 15 lines · Przemek Kitszel
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c static int mlx5_vsc_wait_on_flag(struct mlx5_core_dev *dev, u8 expected_val) · line 194
Quoted 9 lines · Mohamed Khalfella
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +1
-0@@ -191,6 +191,7 @@ static int mlx5_vsc_wait_on_flag(struct mlx5_core_dev *dev, u8 expected_val)if ((retries &0xf ) ==0 )usleep_range (1000 ,2000 ); +cond_resched ();the sleeping logic above (including what is out of git diff context) is a bit weird (tight loop with a sleep after each 16 attempts, with an upper bound of 2k attempts!)
Quoted 3 lines
My understanding of
usleep_range()is that it puts process to sleep (and even leads tosched()call).
Socond_resched()looks redundant here.
This matches my understanding too. usleep_range() should put the thread to sleep, effectively releasing the cpu to do other work. The reason I put cond_resched() here is that pci_read_config_dword() might take long time when that card sees fatal errors. I was not able to reproduce this so I am okay with removing this cond_resched().
Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +0
-0}while (flag != expected_val);return 0 ;@@ -280,6 +281,7 @@ int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data,return read_addr;
Quoted 7 lines
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 284
Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +1
-0read_addr = next_read_addr; +cond_resched ();Would be great to see how many registers there are/how long it takes to dump them in commit message.
My guess is that a singlemlx5_vsc_gw_read_fast()call is very short and there are many. With thatcond_resched()should be rather under some
I did some testing on ConnectX-5 Ex MCX516A-CDAT and here is what I saw:
- mlx5_vsc_gw_read_block_fast() was called with length = 1310716
- mlx5_vsc_gw_read_fast() does 4 bytes at a time but the did not read full 1310716 bytes. Instead it was called 53813 times only. 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 with average runtime of 17548.3ns for each call. In some instances vsc_read() was called more than once until mlx5_vsc_wait_on_flag() returned. Mostly one time, but I saw 5, 8, and in one instance 16 times. As expected, the thread released the cpu after 16 iterations.
- Total time to read the dump was 35284.4ns * 53813 ~= 1.898s
Quoted 1 line
if (iterator % XXX == 0) condition.
Putting a cond_resched() every 16 register reads, similar to mlx5_vsc_wait_on_flag(), should be okay. With the numbers above, this will result in cond_resched() every ~0.56ms, which is okay IMO.
Quoted 56 lines · Mohamed Khalfella
Quoted 15 lines · Przemek Kitszel
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c static int mlx5_vsc_wait_on_flag(struct mlx5_core_dev *dev, u8 expected_val) · line 194
Quoted 9 lines · Mohamed Khalfella
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +1
-0@@ -191,6 +191,7 @@ static int mlx5_vsc_wait_on_flag(struct mlx5_core_dev *dev, u8 expected_val)if ((retries &0xf ) ==0 )usleep_range (1000 ,2000 ); +cond_resched ();the sleeping logic above (including what is out of git diff context) is a bit weird (tight loop with a sleep after each 16 attempts, with an upper bound of 2k attempts!)
Quoted 3 lines
My understanding of
usleep_range()is that it puts process to sleep (and even leads tosched()call).
Socond_resched()looks redundant here.This matches my understanding too.
usleep_range()should put the thread to sleep, effectively releasing the cpu to do other work. The reason I putcond_resched()here is thatpci_read_config_dword()might take long time when that card sees fatal errors. I was not able to reproduce this so I am okay with removing thiscond_resched().Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +0
-0}while (flag != expected_val);return 0 ;@@ -280,6 +281,7 @@ int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data,return read_addr;Quoted 7 lines
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 284
Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +1
-0read_addr = next_read_addr; +cond_resched ();Would be great to see how many registers there are/how long it takes to dump them in commit message.
My guess is that a singlemlx5_vsc_gw_read_fast()call is very short and there are many. With thatcond_resched()should be rather under someI did some testing on ConnectX-5 Ex MCX516A-CDAT and here is what I saw:
-
mlx5_vsc_gw_read_block_fast()was called with length = 1310716
-mlx5_vsc_gw_read_fast()does 4 bytes at a time but the did not read full 1310716 bytes. Instead it was called 53813 times only. There are jumps inread_addr.
- On averagemlx5_vsc_gw_read_fast()took 35284.4ns
- In totalmlx5_vsc_wait_on_flag()calledvsc_read()54707 times with average runtime of 17548.3ns for each call. In some instancesvsc_read()was called more than once untilmlx5_vsc_wait_on_flag()returned. Mostly one time, but I saw 5, 8, and in one instance 16 times. As expected, the thread released the cpu after 16 iterations.
- Total time to read the dump was 35284.4ns * 53813 ~= 1.898s
Quoted 5 lines
Quoted 1 line
if (iterator % XXX == 0) condition.
Putting a
cond_resched()every 16 register reads, similar tomlx5_vsc_wait_on_flag(), should be okay. With the numbers above, this will result incond_resched()every ~0.56ms, which is okay IMO.
Sorry for the late response, I just got back from vacation.
All your measures looks right.
crdump is the devlink health dump of mlx5 FW fatal health reporter.
In the common case since auto-dump and auto-recover are default for this health reporter, the crdump will be collected on fatal error of the mlx5 device and the recovery flow waits for it and run right after crdump finished. I agree with adding cond_resched(), but I would reduce the frequency, like once in 1024 iterations of register read.mlx5_vsc_wait_on_flag() is a bit different case as the usleep there is after 16 retries waiting for the value to change.
Thanks.
Quoted 65 lines · Moshe Shemesh
Quoted 56 lines · Mohamed Khalfella
Quoted 15 lines · Przemek Kitszel
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c static int mlx5_vsc_wait_on_flag(struct mlx5_core_dev *dev, u8 expected_val) · line 194
Quoted 9 lines · Mohamed Khalfella
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +1
-0@@ -191,6 +191,7 @@ static int mlx5_vsc_wait_on_flag(struct mlx5_core_dev *dev, u8 expected_val)if ((retries &0xf ) ==0 )usleep_range (1000 ,2000 ); +cond_resched ();the sleeping logic above (including what is out of git diff context) is a bit weird (tight loop with a sleep after each 16 attempts, with an upper bound of 2k attempts!)
Quoted 3 lines
My understanding of
usleep_range()is that it puts process to sleep (and even leads tosched()call).
Socond_resched()looks redundant here.This matches my understanding too.
usleep_range()should put the thread to sleep, effectively releasing the cpu to do other work. The reason I putcond_resched()here is thatpci_read_config_dword()might take long time when that card sees fatal errors. I was not able to reproduce this so I am okay with removing thiscond_resched().Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +0
-0}while (flag != expected_val);return 0 ;@@ -280,6 +281,7 @@ int mlx5_vsc_gw_read_block_fast(struct mlx5_core_dev *dev, u32 *data,return read_addr;Quoted 7 lines
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 284
Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/pci_vsc.c +1
-0read_addr = next_read_addr; +cond_resched ();Would be great to see how many registers there are/how long it takes to dump them in commit message.
My guess is that a singlemlx5_vsc_gw_read_fast()call is very short and there are many. With thatcond_resched()should be rather under someI did some testing on ConnectX-5 Ex MCX516A-CDAT and here is what I saw:
-
mlx5_vsc_gw_read_block_fast()was called with length = 1310716
-mlx5_vsc_gw_read_fast()does 4 bytes at a time but the did not read full 1310716 bytes. Instead it was called 53813 times only. There are jumps inread_addr.
- On averagemlx5_vsc_gw_read_fast()took 35284.4ns
- In totalmlx5_vsc_wait_on_flag()calledvsc_read()54707 times with average runtime of 17548.3ns for each call. In some instancesvsc_read()was called more than once untilmlx5_vsc_wait_on_flag()returned. Mostly one time, but I saw 5, 8, and in one instance 16 times. As expected, the thread released the cpu after 16 iterations.
- Total time to read the dump was 35284.4ns * 53813 ~= 1.898sQuoted 5 lines
Quoted 1 line
if (iterator % XXX == 0) condition.
Putting a
cond_resched()every 16 register reads, similar tomlx5_vsc_wait_on_flag(), should be okay. With the numbers above, this will result incond_resched()every ~0.56ms, which is okay IMO.
Quoted 12 lines
Sorry for the late response, I just got back from vacation. All your measures looks right.
crdump is the devlink health dump of mlx5 FW fatal health reporter. In the common case since auto-dump and auto-recover are default for this health reporter, the crdump will be collected on fatal error of the mlx5 device and the recovery flow waits for it and run right after crdump finished.
I agree with addingcond_resched(), but I would reduce the frequency, like once in 1024 iterations of register read.mlx5_vsc_wait_on_flag()is a bit different case as the usleep there is after 16 retries waiting for the value to change.
Thanks.
Thanks for taking a look. Once in every 1024 iterations approximately translates to 35284.4ns * 1024 ~= 36.1ms, which is relatively long time IMO. How about any power-of-two <= 128 (~4.51ms)?
Quoted 27 lines · Mohamed Khalfella
Quoted 13 lines · Moshe Shemesh
Quoted 9 lines · Mohamed Khalfella
Quoted 1 line · Przemek Kitszel
On 8/19/24 23:42, Mohamed Khalfella wrote:
Putting a
cond_resched()every 16 register reads, similar tomlx5_vsc_wait_on_flag(), should be okay. With the numbers above, this will result incond_resched()every ~0.56ms, which is okay IMO.Quoted 12 lines
Sorry for the late response, I just got back from vacation. All your measures looks right.
crdump is the devlink health dump of mlx5 FW fatal health reporter. In the common case since auto-dump and auto-recover are default for this health reporter, the crdump will be collected on fatal error of the mlx5 device and the recovery flow waits for it and run right after crdump finished.
I agree with addingcond_resched(), but I would reduce the frequency, like once in 1024 iterations of register read.mlx5_vsc_wait_on_flag()is a bit different case as the usleep there is after 16 retries waiting for the value to change.
Thanks.
Quoted 3 lines
Thanks for taking a look. Once in every 1024 iterations approximately translates to 35284.4ns * 1024 ~= 36.1ms, which is relatively long time IMO. How about any power-of-two <= 128 (~4.51ms)?
Such tune-up would matter for interactive use of the machine with very little cores, is that the case? Otherwise I see no point [to make it overall a little slower, as that is the tradeoff].
Quoted 29 lines · Przemek Kitszel
Quoted 27 lines · Mohamed Khalfella
Quoted 25 lines · Moshe Shemesh
Quoted 9 lines · Mohamed Khalfella
Quoted 1 line · Przemek Kitszel
On 8/19/24 23:42, Mohamed Khalfella wrote:
Putting a
cond_resched()every 16 register reads, similar tomlx5_vsc_wait_on_flag(), should be okay. With the numbers above, this will result incond_resched()every ~0.56ms, which is okay IMO.Sorry for the late response, I just got back from vacation. All your measures looks right.
crdump is the devlink health dump of mlx5 FW fatal health reporter. In the common case since auto-dump and auto-recover are default for this health reporter, the crdump will be collected on fatal error of the mlx5 device and the recovery flow waits for it and run right after crdump finished.
I agree with addingcond_resched(), but I would reduce the frequency, like once in 1024 iterations of register read.mlx5_vsc_wait_on_flag()is a bit different case as the usleep there is after 16 retries waiting for the value to change.
Thanks.
Quoted 3 lines
Quoted 3 lines
Thanks for taking a look. Once in every 1024 iterations approximately translates to 35284.4ns * 1024 ~= 36.1ms, which is relatively long time IMO. How about any power-of-two <= 128 (~4.51ms)?
OK
Quoted 4 lines
Such tune-up would matter for interactive use of the machine with very little cores, is that the case? Otherwise I see no point [to make it overall a little slower, as that is the tradeoff].
Yes, as I see it, the point here is host with very few cores.
Quoted 36 lines · Moshe Shemesh
Quoted 29 lines · Przemek Kitszel
Quoted 27 lines · Mohamed Khalfella
Quoted 25 lines · Moshe Shemesh
Quoted 9 lines · Mohamed Khalfella
Quoted 1 line · Przemek Kitszel
On 8/19/24 23:42, Mohamed Khalfella wrote:
Putting a
cond_resched()every 16 register reads, similar tomlx5_vsc_wait_on_flag(), should be okay. With the numbers above, this will result incond_resched()every ~0.56ms, which is okay IMO.Sorry for the late response, I just got back from vacation. All your measures looks right.
crdump is the devlink health dump of mlx5 FW fatal health reporter. In the common case since auto-dump and auto-recover are default for this health reporter, the crdump will be collected on fatal error of the mlx5 device and the recovery flow waits for it and run right after crdump finished.
I agree with addingcond_resched(), but I would reduce the frequency, like once in 1024 iterations of register read.mlx5_vsc_wait_on_flag()is a bit different case as the usleep there is after 16 retries waiting for the value to change.
Thanks.Quoted 3 lines
Quoted 3 lines
Thanks for taking a look. Once in every 1024 iterations approximately translates to 35284.4ns * 1024 ~= 36.1ms, which is relatively long time IMO. How about any power-of-two <= 128 (~4.51ms)?
Quoted 7 lines
OK
Quoted 4 lines
Such tune-up would matter for interactive use of the machine with very little cores, is that the case? Otherwise I see no point [to make it overall a little slower, as that is the tradeoff].
Yes, as I see it, the point here is host with very few cores.
It should make a difference for systems with few cores. Add to that the numbers above is what I was able to get from the lab. It has been seen in the field that collecting crdump takes more than 5 seconds causing issues. If this makes sense I will submit v2 with the updated commit message and cond_resched() every 128 iterations of register read.
Quoted 44 lines · Mohamed Khalfella
Quoted 42 lines · Moshe Shemesh
Quoted 29 lines · Przemek Kitszel
Quoted 27 lines · Mohamed Khalfella
Quoted 25 lines · Moshe Shemesh
Quoted 9 lines · Mohamed Khalfella
Quoted 1 line · Przemek Kitszel
On 8/19/24 23:42, Mohamed Khalfella wrote:
Putting a
cond_resched()every 16 register reads, similar tomlx5_vsc_wait_on_flag(), should be okay. With the numbers above, this will result incond_resched()every ~0.56ms, which is okay IMO.Sorry for the late response, I just got back from vacation. All your measures looks right.
crdump is the devlink health dump of mlx5 FW fatal health reporter. In the common case since auto-dump and auto-recover are default for this health reporter, the crdump will be collected on fatal error of the mlx5 device and the recovery flow waits for it and run right after crdump finished.
I agree with addingcond_resched(), but I would reduce the frequency, like once in 1024 iterations of register read.mlx5_vsc_wait_on_flag()is a bit different case as the usleep there is after 16 retries waiting for the value to change.
Thanks.Quoted 3 lines
Quoted 3 lines
Thanks for taking a look. Once in every 1024 iterations approximately translates to 35284.4ns * 1024 ~= 36.1ms, which is relatively long time IMO. How about any power-of-two <= 128 (~4.51ms)?
OK
Quoted 4 lines
Such tune-up would matter for interactive use of the machine with very little cores, is that the case? Otherwise I see no point [to make it overall a little slower, as that is the tradeoff].
Quoted 7 lines
Quoted 1 line
Yes, as I see it, the point here is host with very few cores.
It should make a difference for systems with few cores. Add to that the numbers above is what I was able to get from the lab. It has been seen in the field that collecting crdump takes more than 5 seconds causing issues. If this makes sense I will submit v2 with the updated commit message and
cond_resched()every 128 iterations of register read.
Fine with me.
Thanks.