public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jean Delvare <khali@linux-fr.org>
To: Pavel Machek <pavel@ucw.cz>, Len Brown <len.brown@intel.com>
Cc: Matthew Garrett <mjg59@srcf.ucam.org>,
	Chuck Ebbert <cebbert@redhat.com>,
	Rudolf Marek <r.marek@assembler.cz>,
	linux-acpi@vger.kernel.org,
	linux-kernel <linux-kernel@vger.kernel.org>,
	lm-sensors@lm-sensors.org
Subject: Re: Could the k8temp driver be interfering with ACPI?
Date: Mon, 2 Apr 2007 17:48:59 +0200	[thread overview]
Message-ID: <20070402174859.80b74b05.khali@linux-fr.org> (raw)
In-Reply-To: <20070401153951.GE5095@ucw.cz>

Hi Pavel, Len,

On Sun, 1 Apr 2007 15:39:52 +0000, Pavel Machek wrote:
> > > Actually for the acpi stuff... we might wrap ACPI interpretter with a
> > > semaphore that needs to be taken before starting any AML code. Then
> > > just make sure sensors take same semaphore?
> > 
> > I like the idea, it should work as long as we are guaranteed that all
> > the hwmon device accesses happen in the AML code? I'm not familiar with
> > ACPI, so you tell me.
> > 
> > In practice it's rather the SMBus drivers which will need to take the
> > lock, as this is what the AML code will access (for SMBus-based
> > hardware monitoring drivers.) For non-SMBus based hardware monitoring
> > drivers, indeed the driver itself should take it. We will have to pay
> > attention to deadlocks on systems with multiple hardware monitoring
> > chips and/or SMBus channels.
> > 
> > Can you please provide a patch implementing your proposal in acpi? Then
> > I could implement the i2c/hwmon part on some selected drivers and start
> > testing real world scenarii.
> 
> I'm sorry, but I do not have time for a patch.... and I'm not really
> acpi expert, anyway. Ask Len?

Meanwhile Alexey Starikovskiy pointed me to the
acpi_ex_enter/exit_interpreter functions, which take an ACPI mutex
(ACPI_MTX_INTERPRETER). As the mutex already exists, it sounds more
efficient to just reuse it rather than introducing a new one. I made an
experiment with the f71805f driver on a machine where ACPI is accessing
the F71805F chip, and it appears to work fine; patch at the end of this
post is someone wants to take a look and/or comment.

Looking at the comment before acpi_ex_exit_interpreter raises two
questions though:

>  * Cases where the interpreter is unlocked:
>  *      1) Completion of the execution of a control method
>  *      2) Method blocked on a Sleep() AML opcode
>  *      3) Method blocked on an Acquire() AML opcode
>  *      4) Method blocked on a Wait() AML opcode
>  *      5) Method blocked to acquire the global lock
>  *      6) Method blocked to execute a serialized control method that is
>  *          already executing
>  *      7) About to invoke a user-installed opregion handler

1* This suggests that the mutex could be released by the AML
interpreter in the middle of an SMBus transaction. If so, and if it
happens in practice, this means that we unfortunately cannot use this
mutex to reliably protect the SMBus drivers from concurrent accesses.
This even suggests that it's simply not possible to have a mutex we
take at the beginning when entering the AML interpreter and we release
when leaving the AML interpreter, as it looks like ACPI itself allows
interlaced execution of AML functions. Len, is this true?

What is the purpose of the ACPI_MTX_INTERPRETER mutex in the first
place, given that it seems it will be released on numerous occasions?
Is it to prevent concurrent AML execution while still allowing
interlaced execution?

2* What are "user-installed opregion handlers"? Are they something that
could help solve the ACPI vs. other drivers problem?

Thanks.

---
 drivers/acpi/utilities/utmutex.c |    2 ++
 drivers/hwmon/f71805f.c          |   32 +++++++++++++++++++++++++++++++-
 2 files changed, 33 insertions(+), 1 deletion(-)

--- linux-2.6.21-rc5.orig/drivers/acpi/utilities/utmutex.c	2007-02-21 08:34:20.000000000 +0100
+++ linux-2.6.21-rc5/drivers/acpi/utilities/utmutex.c	2007-04-02 15:48:41.000000000 +0200
@@ -265,6 +265,7 @@ acpi_status acpi_ut_acquire_mutex(acpi_m
 
 	return (status);
 }
+EXPORT_SYMBOL_GPL(acpi_ut_acquire_mutex);
 
 /*******************************************************************************
  *
@@ -339,3 +340,4 @@ acpi_status acpi_ut_release_mutex(acpi_m
 	acpi_os_release_mutex(acpi_gbl_mutex_info[mutex_id].mutex);
 	return (AE_OK);
 }
+EXPORT_SYMBOL_GPL(acpi_ut_release_mutex);
--- linux-2.6.21-rc5.orig/drivers/hwmon/f71805f.c	2007-04-02 15:20:46.000000000 +0200
+++ linux-2.6.21-rc5/drivers/hwmon/f71805f.c	2007-04-02 17:15:46.000000000 +0200
@@ -37,6 +37,10 @@
 #include <linux/sysfs.h>
 #include <asm/io.h>
 
+#ifdef CONFIG_ACPI
+#include <acpi/acpi.h>
+#endif
+
 static struct platform_device *pdev;
 
 #define DRVNAME "f71805f"
@@ -273,15 +277,29 @@ static inline u8 temp_to_reg(long val)
 /* Must be called with data->update_lock held, except during initialization */
 static u8 f71805f_read8(struct f71805f_data *data, u8 reg)
 {
+	u8  val;
+#ifdef CONFIG_ACPI
+	acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
+#endif
 	outb(reg, data->addr + ADDR_REG_OFFSET);
-	return inb(data->addr + DATA_REG_OFFSET);
+	val = inb(data->addr + DATA_REG_OFFSET);
+#ifdef CONFIG_ACPI
+	acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
+#endif
+	return val;
 }
 
 /* Must be called with data->update_lock held, except during initialization */
 static void f71805f_write8(struct f71805f_data *data, u8 reg, u8 val)
 {
+#ifdef CONFIG_ACPI
+	acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
+#endif
 	outb(reg, data->addr + ADDR_REG_OFFSET);
 	outb(val, data->addr + DATA_REG_OFFSET);
+#ifdef CONFIG_ACPI
+	acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
+#endif
 }
 
 /* It is important to read the MSB first, because doing so latches the
@@ -291,10 +309,16 @@ static u16 f71805f_read16(struct f71805f
 {
 	u16 val;
 
+#ifdef CONFIG_ACPI
+	acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
+#endif
 	outb(reg, data->addr + ADDR_REG_OFFSET);
 	val = inb(data->addr + DATA_REG_OFFSET) << 8;
 	outb(++reg, data->addr + ADDR_REG_OFFSET);
 	val |= inb(data->addr + DATA_REG_OFFSET);
+#ifdef CONFIG_ACPI
+	acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
+#endif
 
 	return val;
 }
@@ -302,10 +326,16 @@ static u16 f71805f_read16(struct f71805f
 /* Must be called with data->update_lock held, except during initialization */
 static void f71805f_write16(struct f71805f_data *data, u8 reg, u16 val)
 {
+#ifdef CONFIG_ACPI
+	acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
+#endif
 	outb(reg, data->addr + ADDR_REG_OFFSET);
 	outb(val >> 8, data->addr + DATA_REG_OFFSET);
 	outb(++reg, data->addr + ADDR_REG_OFFSET);
 	outb(val & 0xff, data->addr + DATA_REG_OFFSET);
+#ifdef CONFIG_ACPI
+	acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
+#endif
 }
 
 static struct f71805f_data *f71805f_update_device(struct device *dev)


-- 
Jean Delvare

  reply	other threads:[~2007-04-02 15:51 UTC|newest]

Thread overview: 96+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-16 17:31 Could the k8temp driver be interfering with ACPI? Chuck Ebbert
2007-02-16 17:57 ` Len Brown
2007-02-16 18:14   ` Chuck Ebbert
2007-02-16 19:59 ` Andi Kleen
2007-02-16 19:31   ` Chuck Ebbert
2007-02-18 17:32     ` [lm-sensors] " Jean Delvare
2007-02-18 23:22       ` Andi Kleen
2007-02-17 10:49 ` Rudolf Marek
2007-02-17 18:14   ` Chuck Ebbert
2007-02-18 17:38     ` Jean Delvare
2007-02-20 15:18       ` Matthew Garrett
2007-02-20 15:33         ` Luca Tettamanti
2007-02-21 14:59           ` Jean Delvare
2007-02-21 15:07         ` Jean Delvare
2007-02-28 21:38       ` Pavel Machek
2007-03-01 14:26         ` Jean Delvare
2007-03-01 17:48           ` Dave Jones
2007-03-02 11:27             ` Jean Delvare
2007-03-02 11:31               ` Pavel Machek
2007-03-02 13:37                 ` Jean Delvare
2007-03-02 13:47                   ` Henrique de Moraes Holschuh
2007-03-02 13:57                   ` Pavel Machek
2007-03-03  6:44                     ` Jean Delvare
2007-03-02 11:40           ` Pavel Machek
2007-03-02 11:47             ` Matthew Garrett
2007-03-02 13:58               ` Pavel Machek
2007-03-02 21:00                 ` Jean Delvare
2007-03-02 21:22                   ` Henrique de Moraes Holschuh
2007-04-01 15:39                   ` Pavel Machek
2007-04-02 15:48                     ` Jean Delvare [this message]
2007-04-02 19:22                       ` Dave Jones
2007-04-03  5:49                         ` Jean Delvare
2007-04-02 20:55                       ` Moore, Robert
2007-04-03  7:21                         ` Jean Delvare
2007-04-04 21:35                           ` Moore, Robert
2007-03-02 14:10               ` [lm-sensors] " Jean Delvare
2007-03-02 14:18                 ` Matthew Garrett
2007-03-02 21:04                   ` Jean Delvare
2007-03-02 21:12                     ` Matthew Garrett
2007-03-03  9:53                       ` Jean Delvare
2007-03-03 15:47                         ` David Hubbard
2007-03-03 15:50                           ` Matthew Garrett
2007-03-03 17:08                             ` Rudolf Marek
2007-03-04 17:29                               ` Rudolf Marek
2007-03-05 21:16                                 ` Jean Delvare
2007-03-05 21:35                                   ` David Hubbard
2007-03-06 15:10                                     ` Jean Delvare
2007-03-04 10:54                           ` Jean Delvare
2007-03-05 22:25                         ` Pavel Machek
2007-03-06  7:55                           ` Benny Amorsen
2007-03-06 15:26                           ` Jean Delvare
2007-03-06 20:07                             ` Stefan Monnier
2007-03-06 21:20                             ` Pavel Machek
2007-03-06 21:25                               ` Moore, Robert
2007-03-18 19:36                         ` richardvoigt
2007-03-19  7:08                           ` Jean Delvare
2007-03-02 22:07                     ` Moore, Robert
2007-03-09  7:18                       ` Pavel Machek
2007-03-09 10:24                         ` Jean Delvare
2007-03-09 10:39                           ` Alexey Starikovskiy
2007-03-09 11:21                             ` Pavel Machek
2007-03-09 17:23                             ` Jean Delvare
2007-03-09 17:35                               ` Alexey Starikovskiy
2007-03-09 21:03                                 ` Moore, Robert
2007-03-09 20:56                         ` Moore, Robert
2007-03-02 14:22                 ` Pavel Machek
2007-03-02 14:03             ` Jean Delvare
2007-03-02 14:24               ` Pavel Machek
2007-03-02 14:57               ` Matthew Garrett
2007-03-02 21:41                 ` Jean Delvare
2007-03-02 21:46                   ` Matthew Garrett
2007-03-06 21:28                     ` Jean Delvare
2007-04-13 18:18               ` Bjorn Helgaas
2007-04-13 20:07                 ` Pavel Machek
2007-04-13 20:59                   ` Bjorn Helgaas
2007-04-15  9:41                     ` Jean Delvare
2007-04-15 20:31                       ` Bjorn Helgaas
2007-04-15 20:59                         ` Luca Tettamanti
2007-04-16  0:57                           ` Bjorn Helgaas
2007-04-16 21:14                             ` Luca Tettamanti
2007-04-16 22:28                               ` Bjorn Helgaas
2007-04-17 23:50                                 ` Luca Tettamanti
2007-04-22 16:55                                   ` Luca Tettamanti
2007-04-17 10:03                               ` Jean Delvare
2007-02-18 22:43     ` Rudolf Marek
2007-02-20 15:08       ` Chuck Ebbert
2007-02-20 19:11         ` Dave Jones
2007-02-21 16:17           ` Jean Delvare
2007-02-21 17:37             ` Dave Jones
2007-02-21 20:19               ` Dave Jones
2007-02-22 16:37                 ` Jean Delvare
2007-02-23  7:13                   ` Hans de Goede
2007-02-23  7:47                     ` Jean Delvare
2007-02-21 14:54         ` Jean Delvare
2007-02-21 16:03           ` Chuck Ebbert
2007-02-21 16:22             ` Jean Delvare

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070402174859.80b74b05.khali@linux-fr.org \
    --to=khali@linux-fr.org \
    --cc=cebbert@redhat.com \
    --cc=len.brown@intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lm-sensors@lm-sensors.org \
    --cc=mjg59@srcf.ucam.org \
    --cc=pavel@ucw.cz \
    --cc=r.marek@assembler.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox