Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d4xx: Locking on open dfu device #226

Merged
merged 1 commit into from
Sep 21, 2024
Merged

Conversation

dmipx
Copy link
Contributor

@dmipx dmipx commented Aug 13, 2024

Fix bus clock restore on dfu open/close.

sometimes we have race condition while running tests

[109371.797365] d4xx 30-001a: ds5_dfu_device_release(): i2c-2 bus_clk 400000, restore to 100000
[109371.807802] d4xx 30-001a: ds5_dfu_device_open(): i2c-2 bus_clk = 100000, set 400000
[109371.814781] d4xx 30-001a: ds5_dfu_device_release(): i2c-2 bus_clk 400000, restore to 100000
[109371.823742] d4xx 30-001a: ds5_dfu_device_open(): i2c-2 bus_clk = 100000, set 400000
[109371.830182] d4xx 30-001a: ds5_dfu_device_open(): i2c-2 bus_clk = 400000, set 400000
[109371.838771] d4xx 30-001a: ds5_dfu_device_release(): i2c-2 bus_clk 400000, restore to 400000
[109371.847535] d4xx 30-001a: ds5_dfu_device_release(): i2c-2 bus_clk 400000, restore to 400000
[109371.855556] d4xx 30-001a: ds5_dfu_device_open(): i2c-2 bus_clk = 400000, set 400000
[109371.862556] d4xx 30-001a: ds5_dfu_device_release(): i2c-2 bus_clk 400000, restore to 400000

@dmipx dmipx marked this pull request as ready for review August 13, 2024 14:39
@@ -4967,26 +4967,29 @@ static int ds5_dfu_device_open(struct inode *inode, struct file *file)
state->client->adapter);
#endif
#endif
mutex_lock(&state->lock);
if (state->dfu_dev.device_open_count)
return -EBUSY;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need mutex_unlock(&state->lock); here right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, this was another adjustment of where mutex should be hold and we missed that.

@@ -4997,6 +5000,7 @@ static int ds5_dfu_device_open(struct inode *inode, struct file *file)
i2c_set_adapter_bus_clk_rate(parent, DFU_I2C_BUS_CLK_RATE);
#endif
#endif
mutex_unlock(&state->lock);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who reads state->dfu_dev.bus_clk_rate?

We set using the i2c API right?
Why do we need to keep the last value? can't we hard coded set 400 on entrance and set 100 on exit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can hard code values

@Nir-Az
Copy link
Collaborator

Nir-Az commented Aug 13, 2024

Nice catch Dima.
Can you write how did you loop enter and exit to DFU mode?
Perhaps this can turn into a unit test for this fix

@Nir-Az
Copy link
Collaborator

Nir-Az commented Aug 13, 2024

@mengyui On your PR you also added lock and said it caused some crash.
Can you specify on which use case so we can double check here?

@Nir-Az
Copy link
Collaborator

Nir-Az commented Aug 13, 2024

Another interesting question is how do we see 2 opens w/o a close in between.
How can this happen? Was it teated on a single camera?

@mengyui
Copy link

mengyui commented Aug 14, 2024

The issue which i'm trying to fix is related to "device_open_count"
when try to update FW on the system with multi-9296/D457, the issue may be found.

BTW, should the lock be unlocked before returning from the function?
https://github.com/dmipx/realsense_mipi_platform_driver/blame/busclk-fix/kernel/realsense/d4xx.c#L4972

@dmipx
Copy link
Contributor Author

dmipx commented Aug 14, 2024

Another interesting question is how do we see 2 opens w/o a close in between. How can this happen? Was it teated on a single camera?

It was tested with unit-tests on single camera.

@dmipx
Copy link
Contributor Author

dmipx commented Aug 14, 2024

The issue which i'm trying to fix is related to "device_open_count" when try to update FW on the system with multi-9296/D457, the issue may be found.

BTW, should the lock be unlocked before returning from the function? https://github.com/dmipx/realsense_mipi_platform_driver/blame/busclk-fix/kernel/realsense/d4xx.c#L4972

Thanks.
Fixed.

@dmipx
Copy link
Contributor Author

dmipx commented Aug 14, 2024

Nice catch Dima. Can you write how did you loop enter and exit to DFU mode? Perhaps this can turn into a unit test for this fix

This is not "enters" dfu mode, it's open dfu device and close dfu device. For Jetson we switch I2C bus speed clock.
The test can be as follows (for jp4/5 only):

  1. verify i2c bus speed 100k
  2. open dfu device file
  3. verify i2c bus speed 400k
  4. close dfu device file
  5. verify i2c bus speed 100k

Copy link

@Arun-Prasad-V Arun-Prasad-V left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@Nir-Az Nir-Az merged commit 47cf14d into IntelRealSense:dev Sep 21, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants