Message ID | 20190620150013.13462-6-narmstrong@baylibre.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | arm64: g12a: add support for DVFS | expand |
Quoting Neil Armstrong (2019-06-20 08:00:04) > In order to protect clock measuring when multiple process asks for > a mesure, protect the main measure function with mutexes. > > Signed-off-by: Neil Armstrong <narmstrong@baylibre.com> > --- > drivers/soc/amlogic/meson-clk-measure.c | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/drivers/soc/amlogic/meson-clk-measure.c b/drivers/soc/amlogic/meson-clk-measure.c > index 19d4cbc93a17..c470e24f1dfa 100644 > --- a/drivers/soc/amlogic/meson-clk-measure.c > +++ b/drivers/soc/amlogic/meson-clk-measure.c > @@ -11,6 +11,8 @@ > #include <linux/debugfs.h> > #include <linux/regmap.h> > > +static DEFINE_MUTEX(measure_lock); > + > #define MSR_CLK_DUTY 0x0 > #define MSR_CLK_REG0 0x4 > #define MSR_CLK_REG1 0x8 > @@ -360,6 +362,10 @@ static int meson_measure_id(struct meson_msr_id *clk_msr_id, > unsigned int val; > int ret; > > + ret = mutex_lock_interruptible(&measure_lock); Why interruptible? > + if (ret) > + return ret; > + > regmap_write(priv->regmap, MSR_CLK_REG0, 0); > > /* Set measurement duration */
On 25/06/2019 22:27, Stephen Boyd wrote: > Quoting Neil Armstrong (2019-06-20 08:00:04) >> In order to protect clock measuring when multiple process asks for >> a mesure, protect the main measure function with mutexes. >> >> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com> >> --- >> drivers/soc/amlogic/meson-clk-measure.c | 12 +++++++++++- >> 1 file changed, 11 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/soc/amlogic/meson-clk-measure.c b/drivers/soc/amlogic/meson-clk-measure.c >> index 19d4cbc93a17..c470e24f1dfa 100644 >> --- a/drivers/soc/amlogic/meson-clk-measure.c >> +++ b/drivers/soc/amlogic/meson-clk-measure.c >> @@ -11,6 +11,8 @@ >> #include <linux/debugfs.h> >> #include <linux/regmap.h> >> >> +static DEFINE_MUTEX(measure_lock); >> + >> #define MSR_CLK_DUTY 0x0 >> #define MSR_CLK_REG0 0x4 >> #define MSR_CLK_REG1 0x8 >> @@ -360,6 +362,10 @@ static int meson_measure_id(struct meson_msr_id *clk_msr_id, >> unsigned int val; >> int ret; >> >> + ret = mutex_lock_interruptible(&measure_lock); > > Why interruptible? I supposed _interruptible was needed since it's called from userspace via debugfs, locking indefinitely isn't wanted, no ? or maybe I missed something... Neil > >> + if (ret) >> + return ret; >> + >> regmap_write(priv->regmap, MSR_CLK_REG0, 0); >> >> /* Set measurement duration */
Quoting Neil Armstrong (2019-06-26 01:24:47) > On 25/06/2019 22:27, Stephen Boyd wrote: > > Quoting Neil Armstrong (2019-06-20 08:00:04) > >> In order to protect clock measuring when multiple process asks for > >> a mesure, protect the main measure function with mutexes. s/mesure/measure/ > >> > >> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com> > >> --- > >> drivers/soc/amlogic/meson-clk-measure.c | 12 +++++++++++- > >> 1 file changed, 11 insertions(+), 1 deletion(-) > >> > >> diff --git a/drivers/soc/amlogic/meson-clk-measure.c b/drivers/soc/amlogic/meson-clk-measure.c > >> index 19d4cbc93a17..c470e24f1dfa 100644 > >> --- a/drivers/soc/amlogic/meson-clk-measure.c > >> +++ b/drivers/soc/amlogic/meson-clk-measure.c > >> @@ -11,6 +11,8 @@ > >> #include <linux/debugfs.h> > >> #include <linux/regmap.h> > >> > >> +static DEFINE_MUTEX(measure_lock); > >> + > >> #define MSR_CLK_DUTY 0x0 > >> #define MSR_CLK_REG0 0x4 > >> #define MSR_CLK_REG1 0x8 > >> @@ -360,6 +362,10 @@ static int meson_measure_id(struct meson_msr_id *clk_msr_id, > >> unsigned int val; > >> int ret; > >> > >> + ret = mutex_lock_interruptible(&measure_lock); > > > > Why interruptible? > > > I supposed _interruptible was needed since it's called from userspace via > debugfs, locking indefinitely isn't wanted, no ? or maybe I missed something... > Sounds plausible to me.
diff --git a/drivers/soc/amlogic/meson-clk-measure.c b/drivers/soc/amlogic/meson-clk-measure.c index 19d4cbc93a17..c470e24f1dfa 100644 --- a/drivers/soc/amlogic/meson-clk-measure.c +++ b/drivers/soc/amlogic/meson-clk-measure.c @@ -11,6 +11,8 @@ #include <linux/debugfs.h> #include <linux/regmap.h> +static DEFINE_MUTEX(measure_lock); + #define MSR_CLK_DUTY 0x0 #define MSR_CLK_REG0 0x4 #define MSR_CLK_REG1 0x8 @@ -360,6 +362,10 @@ static int meson_measure_id(struct meson_msr_id *clk_msr_id, unsigned int val; int ret; + ret = mutex_lock_interruptible(&measure_lock); + if (ret) + return ret; + regmap_write(priv->regmap, MSR_CLK_REG0, 0); /* Set measurement duration */ @@ -377,8 +383,10 @@ static int meson_measure_id(struct meson_msr_id *clk_msr_id, ret = regmap_read_poll_timeout(priv->regmap, MSR_CLK_REG0, val, !(val & MSR_BUSY), 10, 10000); - if (ret) + if (ret) { + mutex_unlock(&measure_lock); return ret; + } /* Disable */ regmap_update_bits(priv->regmap, MSR_CLK_REG0, MSR_ENABLE, 0); @@ -386,6 +394,8 @@ static int meson_measure_id(struct meson_msr_id *clk_msr_id, /* Get the value in multiple of gate time counts */ regmap_read(priv->regmap, MSR_CLK_REG2, &val); + mutex_unlock(&measure_lock); + if (val >= MSR_VAL_MASK) return -EINVAL;
In order to protect clock measuring when multiple process asks for a mesure, protect the main measure function with mutexes. Signed-off-by: Neil Armstrong <narmstrong@baylibre.com> --- drivers/soc/amlogic/meson-clk-measure.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)