Skip to contentSkip to conversation

Could the k8temp driver be interfering with ACPI?

lm-sensors Bodo Eggert 3 participants 6 messages Mar 5, 2007 – Mar 7, 2007 11 messages not in the archive ACPI

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#11 lore raw
Quoted 18 lines · David Hubbard

For I/O and memory that ACPI accesses and has not reserved, the AML interpreter could allocate at run-time.

I'm not sure how to implement exactly. For example, it would be bad to have a /proc/ioports that had a lot of single ports allocated, for example:
1000-107f : 0000:00:1f.0
1000-1000 : ACPI PM1a_EVT_BLK
1001-1001 : ACPI PM1a_EVT_BLK
1002-1002 : ACPI PM1a_EVT_BLK
1003-1003 : ACPI PM1a_EVT_BLK

Thus the AML interpreter would need to have some reasonable intelligence when allocating regions. Conflict resolution would also be more difficult, e.g. if a hwmon driver was loaded first and then acpi as a module, ACPI could not allocate the region. Maybe run-time allocating won't work.

Quoted 4 lines

And then, how would ACPI release a region after it has used it? The easiest method would be to never release anything used even once.

Thoughts?

1) Make a general resource allocation lock, if there is none.
2) make ACPI take this lock whenever it touches ports not allocated by itself and release it on function return.
3) Make ACPI callback the allocating device if it touches allocated ranges, and on function return.

1 + 2 will replace allocating single ports and freeing them again (so ACPI won't prevent e.g. the display driver from loading just because it turned on the backlight) while preventing races with newly allocated ranges, and 3 allows coexistence with other drivers.

Signature · 4 lines
The problem with the easy way out is that it has already been mined. 

Fri?, Spammer: TKF8 at jQXoImLG.7eggert.dyndns.org
 lG at aOkf0g.7eggert.dyndns.org hffltUu at 6au8pBwc.7eggert.dyndns.org
#12 lore raw

Hi Bodo,

Quoted 1 line · Bodo Eggert

1) Make a general resource allocation lock, if there is none.

Such a lock certainly exists, but I doubt it is public at the moment.

Quoted 2 lines

2) make ACPI take this lock whenever it touches ports not allocated by itself and release it on function return.

This is costly.

Quoted 2 lines

3) Make ACPI callback the allocating device if it touches allocated ranges, and on function return.

By callback, do you mean port forwarding as Rudolf Marek did, or more simple "stop touching the device" and "you can touch the device again" sort of signals? If the latter, this is no different from a mutex.

Quoted 4 lines

1 + 2 will replace allocating single ports and freeing them again (so ACPI won't prevent e.g. the display driver from loading just because it turned on the backlight) while preventing races with newly allocated ranges, and 3 allows coexistence with other drivers.

What benefit do you see compared to a lock taken by both AML and the hardware monitoring drivers?

Care to submit a sample implementation?

Thanks,

Signature · 1 line
Jean Delvare
#13 lore raw
Quoted 6 lines · Jean Delvare
Quoted 2 lines · Bodo Eggert

2) make ACPI take this lock whenever it touches ports not allocated by itself and release it on function return.

This is costly.

TANSTAAFL. You'll need to take some lock, and if you want port emulation or per-device-mutex, you'll have to pay the price.

Quoted 6 lines
Quoted 2 lines

3) Make ACPI callback the allocating device if it touches allocated ranges, and on function return.

By callback, do you mean port forwarding as Rudolf Marek did, or more simple "stop touching the device" and "you can touch the device again" sort of signals? If the latter, this is no different from a mutex.

It may be the described port emulation callback (which is very nice and possibly desired for some devices), but if you add an "I am done tampering with your hardware" callback, the driver can also implement the mutex.

Some drivers will not understand all possible access patterns, they may try to emulate first, and if they fail, fall back to taking the mutex and passing the raw port access.

Quoted 7 lines
Quoted 4 lines

1 + 2 will replace allocating single ports and freeing them again (so ACPI won't prevent e.g. the display driver from loading just because it turned on the backlight) while preventing races with newly allocated ranges, and 3 allows coexistence with other drivers.

What benefit do you see compared to a lock taken by both AML and the hardware monitoring drivers?

1) I asume port allocations or ACPI foreign port acces to be rare, so there would be little impact on (un)registering hardware. Off cause there are some long ACPI calls (like reading the battery?), in these cases it might be beneficial to release the global allocation lock after gaining exclusive access to the driver's port range. (This can only be done if the device driver is loaded.)

2) If there is a global lock for accessing ACPI-tampered hardware, each driver that *might* conflict with ACPI _must_ take it on each access. This would seialize unrelated sensor busses, IDE, graphics ... (AFAI can imagine.) A callback allows using a per-(device|bus)-mutex instead.

Quoted 1 line

Care to submit a sample implementation?

I think somebody experienced with the internals should do this.

Rudolph's implementation is close enough to imagine what would be done, the changes would be:

- Add a "done" call to resource_ops

in ACPI:
- Check for own region first and do raw access there
- get the lock before __request_region
- s/__request/__check/

in driver:
- If emulation fails, get the local lock and switch to passthrough mode
- if in passthrough mode and done is called, release the lock

Signature · 1 line
Those who hesitate under fire usually do not end up KIA or WIA. 
#14 lore raw

Hi Bodo,

Quoted 10 lines · Bodo Eggert
Quoted 6 lines · Jean Delvare
Quoted 2 lines · Bodo Eggert

2) make ACPI take this lock whenever it touches ports not allocated by itself and release it on function return.

This is costly.

TANSTAAFL. You'll need to take some lock, and if you want port emulation or per-device-mutex, you'll have to pay the price.

True, but precisely, I wonder what will perform the best in practice, a single semaphore that is unconditionally taken by ACPI/AML, or your finer-grained approach and its many additional tests.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

3) Make ACPI callback the allocating device if it touches allocated ranges, and on function return.

By callback, do you mean port forwarding as Rudolf Marek did, or more simple "stop touching the device" and "you can touch the device again" sort of signals? If the latter, this is no different from a mutex.

Quoted 7 lines

It may be the described port emulation callback (which is very nice and possibly desired for some devices), but if you add an "I am done tampering with your hardware" callback, the driver can also implement the mutex.

Some drivers will not understand all possible access patterns, they may try to emulate first, and if they fail, fall back to taking the mutex and passing the raw port access.

Good point.

Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

1 + 2 will replace allocating single ports and freeing them again (so ACPI won't prevent e.g. the display driver from loading just because it turned on the backlight) while preventing races with newly allocated ranges, and 3 allows coexistence with other drivers.

What benefit do you see compared to a lock taken by both AML and the hardware monitoring drivers?

Quoted 6 lines

1) I asume port allocations or ACPI foreign port acces to be rare, so there would be little impact on (un)registering hardware. Off cause there are some long ACPI calls (like reading the battery?), in these cases it might be beneficial to release the global allocation lock after gaining exclusive access to the driver's port range. (This can only be done if the device driver is loaded.)

The problem is that the rarity of ACPI foreign port access doesn't matter much, as you have to do all the tests first to find out that it was a foreign port, and I suspect that these tests will cost more than taking the lock itself.

Quoted 4 lines

2) If there is a global lock for accessing ACPI-tampered hardware, each driver that *might* conflict with ACPI _must_ take it on each access. This would seialize unrelated sensor busses, IDE, graphics ... (AFAI can imagine.) A callback allows using a per-(device|bus)-mutex instead.

True, this is the problem with having a single mutex: everything gets serialized. I have no idea how often we are running AML code though, so I don't know if this is a real problem in practice.

We may be able to workaround the inter-driver exclusion though, if we use a semaphore initialized to N, have ACPI take N, but other drivers take just one. This would let ACPI be exclusive with all the other drivers, but drivers themselves could otherwise run concurrently. That being said, we do not appear to have the required primitives to take more than 1 semaphore resource at once at the moment, so we'd need to do that first.

OTOH, I certainly hope that not that many drivers are affected on a given system, so maybe serialization is acceptable. We'll need some field experimentation to find out.

Quoted 5 lines

Rudolph's implementation is close enough to imagine what would be done, the changes would be:

- Add a "done" call to resource_ops

Quoted 8 lines

in ACPI:
- Check for own region first and do raw access there
- get the lock before __request_region
- s/__request/__check/

in driver:
- If emulation fails, get the local lock and switch to passthrough mode
- if in passthrough mode and done is called, release the lock

Yep, that's a bit complex, but should work, thanks for sketching this.

Signature · 1 line
Jean Delvare
#15 lore raw

Hi!

Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

2) make ACPI take this lock whenever it touches ports not allocated by itself and release it on function return.

This is costly.

TANSTAAFL. You'll need to take some lock, and if you want port emulation or per-device-mutex, you'll have to pay the price.

True, but precisely, I wonder what will perform the best in practice, a single semaphore that is unconditionally taken by ACPI/AML, or your finer-grained approach and its many additional tests.

I'd say mutexes are not that bad. ... i/o accesses are expensive, anyway, right?

Quoted 7 lines

We may be able to workaround the inter-driver exclusion though, if we use a semaphore initialized to N, have ACPI take N, but other drivers take just one. This would let ACPI be exclusive with all the other drivers, but drivers themselves could otherwise run concurrently. That being said, we do not appear to have the required primitives to take more than 1 semaphore resource at once at the moment, so we'd need to do that first.

Hmm, nice hack. Yes, driver-driver serialization would be nasty.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#16 lore raw
In reply to Jean Delvare
Quoted 9 lines · Jean Delvare
Quoted 6 lines · Bodo Eggert

1) I asume port allocations or ACPI foreign port acces to be rare, so there would be little impact on (un)registering hardware. Off cause there are some long ACPI calls (like reading the battery?), in these cases it might be beneficial to release the global allocation lock after gaining exclusive access to the driver's port range. (This can only be done if the device driver is loaded.)

Quoted 4 lines

The problem is that the rarity of ACPI foreign port access doesn't matter much, as you have to do all the tests first to find out that it was a foreign port, and I suspect that these tests will cost more than taking the lock itself.

Testing for the internal ranges can be done by searching a list of about five ranges, that should be not much slower than taking an uncontended lock, and very much faster than waiting for smbus to finish it's current task in case the lock is contended. I'm more concerned about driver (un)loading being slowed down by ACPI.

[...]

Quoted 7 lines

We may be able to workaround the inter-driver exclusion though, if we use a semaphore initialized to N, have ACPI take N, but other drivers take just one. This would let ACPI be exclusive with all the other drivers, but drivers themselves could otherwise run concurrently. That being said, we do not appear to have the required primitives to take more than 1 semaphore resource at once at the moment, so we'd need to do that first.

worst case I can imagine: IDE/graphic stalles while ACPI takes a second to read the battery state.

Signature · 2 lines
Top 100 things you don't want the sysadmin to say:
82. Where's the DIR command?