Skip to contentSkip to conversation

query about locking in IIO

DISCUSSION Rohit Sarkar 3 participants 6 messages Feb 25, 2020 – Feb 28, 2020 IIO

lore
Share & tools
lore
#0 lore raw

Hi,
Could someone explain why using indio_dev->mlock directly is a bad idea? Further examples of cases where it cannot be replaced will be helpful

Thanks,
Rohit

#1 lore raw
Quoted 4 lines · Rohit Sarkar

Hi,
Could someone explain why using indio_dev->mlock directly is a bad idea? Further examples of cases where it cannot be replaced will be helpful

Jonathan may add more here.

But in general, each driver should define it's own explicit lock if it needs to. Some drivers need explicit locking, some don't.

A lot of other frameworks already define locks already.
Like, for example, when an IIO driver uses some SPI transfers, the SPI framework already uses some locks. So, you don't typically need extra locking; which for some IIO drivers translates to: no extra explicit locking.

I guess Jonathan also wants to move the mlock to be used only in the IIO framework.
In some cases, if drivers use this mlock, and the framework uses it, you can end up trying to acquire the same mlock twice, which can end-up in a deadlock. These things can sometimes slip through the code-review.

I guess the docs need a bit of update.
Because:

* @mlock: [DRIVER] lock used to prevent simultaneous device state
* changes

I think it should be converted to [INTERN]

Quoted 3 lines

Thanks,
Rohit

#2 lore raw
Quoted 16 lines · Alexandru
Quoted 4 lines · Rohit Sarkar

Hi,
Could someone explain why using indio_dev->mlock directly is a bad idea? Further examples of cases where it cannot be replaced will be helpful

Jonathan may add more here.

But in general, each driver should define it's own explicit lock if it needs to. Some drivers need explicit locking, some don't.

A lot of other frameworks already define locks already.
Like, for example, when an IIO driver uses some SPI transfers, the SPI framework already uses some locks. So, you don't typically need extra locking; which for some IIO drivers translates to: no extra explicit locking.

Quoted 5 lines

I guess Jonathan also wants to move the mlock to be used only in the IIO framework.
In some cases, if drivers use this mlock, and the framework uses it, you can end up trying to acquire the same mlock twice, which can end-up in a deadlock. These things can sometimes slip through the code-review.

This makes sense

Quoted 11 lines

I guess the docs need a bit of update.
Because:

* @mlock: [DRIVER] lock used to prevent simultaneous device state
* changes

I think it should be converted to [INTERN]

Quoted 3 lines

Thanks,
Rohit

As a follow up would I be right to assume that as long as the mlock is not being in the IIO framework, explicit locking should be the way to go?

Thanks,
Rohit

#3 lore raw
Quoted 40 lines · Rohit Sarkar

[External]

Quoted 19 lines · Alexandru
Quoted 4 lines · Rohit Sarkar

Hi,
Could someone explain why using indio_dev->mlock directly is a bad idea? Further examples of cases where it cannot be replaced will be helpful

Jonathan may add more here.

But in general, each driver should define it's own explicit lock if it needs to.
Some drivers need explicit locking, some don't.

A lot of other frameworks already define locks already.
Like, for example, when an IIO driver uses some SPI transfers, the SPI framework
already uses some locks. So, you don't typically need extra locking; which for
some IIO drivers translates to: no extra explicit locking.

Quoted 6 lines

I guess Jonathan also wants to move the mlock to be used only in the IIO framework.
In some cases, if drivers use this mlock, and the framework uses it, you can end
up trying to acquire the same mlock twice, which can end-up in a deadlock. These things can sometimes slip through the code-review.

This makes sense

Quoted 9 lines

I guess the docs need a bit of update.
Because:

* @mlock: [DRIVER] lock used to prevent simultaneous device
state
* changes

I think it should be converted to [INTERN]

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

Thanks,
Rohit

As a follow up would I be right to assume that as long as the mlock is not being in the IIO framework, explicit locking should be the way to go?

The question sounds a bit hard to follow.
Each driver should define it's own locking if it needs it.
mlock will continued to be used only in the IIO framework; it won't be removed. [INTERN] is just a marker in the doc-string to make sure people don't use these fields in drivers.

Quoted 2 lines

Thanks,
Rohit

#4 lore raw
Quoted 49 lines · Alexandru
Quoted 40 lines · Rohit Sarkar

[External]

Quoted 19 lines · Alexandru
Quoted 4 lines · Rohit Sarkar

Hi,
Could someone explain why using indio_dev->mlock directly is a bad idea? Further examples of cases where it cannot be replaced will be helpful

Jonathan may add more here.

But in general, each driver should define it's own explicit lock if it needs to.
Some drivers need explicit locking, some don't.

A lot of other frameworks already define locks already.
Like, for example, when an IIO driver uses some SPI transfers, the SPI framework
already uses some locks. So, you don't typically need extra locking; which for
some IIO drivers translates to: no extra explicit locking.

Quoted 6 lines

I guess Jonathan also wants to move the mlock to be used only in the IIO framework.
In some cases, if drivers use this mlock, and the framework uses it, you can end
up trying to acquire the same mlock twice, which can end-up in a deadlock. These things can sometimes slip through the code-review.

This makes sense

Quoted 9 lines

I guess the docs need a bit of update.
Because:

* @mlock: [DRIVER] lock used to prevent simultaneous device
state
* changes

I think it should be converted to [INTERN]

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

Thanks,
Rohit

As a follow up would I be right to assume that as long as the mlock is not being in the IIO framework, explicit locking should be the way to go?

Quoted 5 lines

The question sounds a bit hard to follow.
Each driver should define it's own locking if it needs it.
mlock will continued to be used only in the IIO framework; it won't be removed. [INTERN] is just a marker in the doc-string to make sure people don't use these fields in drivers.

Yes. That's basically it. mlock is a framework internal lock and we may change how it is implemented at any time.

Various drivers using it make any such changes impossible and are much harder to reason about because the mlock uses in the core aren't visible within the driver.

So basically its a software architecture problem rather than there being any known bugs!

Thanks,

Jonathan

Quoted 4 lines
Quoted 4 lines

Thanks,
Rohit

#5 lore raw
Quoted 61 lines · Jonathan Cameron
Quoted 49 lines · Alexandru
Quoted 40 lines · Rohit Sarkar

[External]

Quoted 19 lines · Alexandru
Quoted 4 lines · Rohit Sarkar

Hi,
Could someone explain why using indio_dev->mlock directly is a bad idea? Further examples of cases where it cannot be replaced will be helpful

Jonathan may add more here.

But in general, each driver should define it's own explicit lock if it needs to.
Some drivers need explicit locking, some don't.

A lot of other frameworks already define locks already.
Like, for example, when an IIO driver uses some SPI transfers, the SPI framework
already uses some locks. So, you don't typically need extra locking; which for
some IIO drivers translates to: no extra explicit locking.

Quoted 6 lines

I guess Jonathan also wants to move the mlock to be used only in the IIO framework.
In some cases, if drivers use this mlock, and the framework uses it, you can end
up trying to acquire the same mlock twice, which can end-up in a deadlock. These things can sometimes slip through the code-review.

This makes sense

Quoted 9 lines

I guess the docs need a bit of update.
Because:

* @mlock: [DRIVER] lock used to prevent simultaneous device
state
* changes

I think it should be converted to [INTERN]

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

Thanks,
Rohit

As a follow up would I be right to assume that as long as the mlock is not being in the IIO framework, explicit locking should be the way to go?

Quoted 5 lines

The question sounds a bit hard to follow.
Each driver should define it's own locking if it needs it.
mlock will continued to be used only in the IIO framework; it won't be removed. [INTERN] is just a marker in the doc-string to make sure people don't use these fields in drivers.

Yes. That's basically it. mlock is a framework internal lock and we may change how it is implemented at any time.

Quoted 6 lines

Various drivers using it make any such changes impossible and are much harder to reason about because the mlock uses in the core aren't visible within the driver.

So basically its a software architecture problem rather than there being any known bugs!

Got it, Thanks

Quoted 10 lines

Thanks,

Jonathan

Quoted 4 lines
Quoted 4 lines

Thanks,
Rohit