summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2013-09-09 12:17:47 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2013-09-09 20:01:14 +0000
commit6412d099521e30025f6f91931f323e2fe057d9f0 (patch)
treebea606ac8c4966d32ead48d6f569512af75c4803
parent5025ff0db9895382af0e97f84b925edf65971216 (diff)
downloadchrome-ec-6412d099521e30025f6f91931f323e2fe057d9f0.tar.gz
Add mutex around chipset_throttle_cpu() (BRANCH ONLY)
This adds a mutex around chipset_throttle_cpu(), so that multiple tasks don't interfere with each other. BUG=chromium:287985 BRANCH=Falco TEST=none We've never observed any problems here, but it could have happened. This should prevent it. Everything should continue to work as before. Change-Id: I2170a1b7af244c894100e525ed73a1b068d21e5b Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/168579 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--common/chipset.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/common/chipset.c b/common/chipset.c
index 760c1dd1f4..40f02d30bb 100644
--- a/common/chipset.c
+++ b/common/chipset.c
@@ -8,6 +8,7 @@
#include "chipset.h"
#include "common.h"
#include "console.h"
+#include "task.h"
#include "util.h"
/* Console output macros */
@@ -17,15 +18,21 @@
/*****************************************************************************/
/* This enforces the virtual OR of all throttling sources. */
+static struct mutex throttle_mutex;
static uint32_t throttle_request;
+
void chipset_throttle_cpu(int throttle, enum throttle_sources source)
{
+ mutex_lock(&throttle_mutex);
+
if (throttle)
throttle_request |= source;
else
throttle_request &= ~source;
chipset_throttle_cpu_implementation(throttle_request);
+
+ mutex_unlock(&throttle_mutex);
}
/*****************************************************************************/
@@ -33,18 +40,26 @@ void chipset_throttle_cpu(int throttle, enum throttle_sources source)
static int command_apthrottle(int argc, char **argv)
{
- uint32_t newval;
+ uint32_t tmpval;
char *e;
if (argc > 1) {
- newval = strtoi(argv[1], &e, 0);
+ tmpval = strtoi(argv[1], &e, 0);
if (*e)
return EC_ERROR_PARAM1;
- throttle_request = newval;
- chipset_throttle_cpu_implementation(throttle_request);
+
+ mutex_lock(&throttle_mutex);
+ throttle_request = tmpval; /* force source */
+ mutex_unlock(&throttle_mutex);
+
+ chipset_throttle_cpu(0, 0); /* make it so */
}
+ mutex_lock(&throttle_mutex);
+ tmpval = throttle_request; /* read current value */
+ mutex_unlock(&throttle_mutex);
+
ccprintf("AP throttling is %s (0x%08x)\n",
- throttle_request ? "on" : "off", throttle_request);
+ tmpval ? "on" : "off", tmpval);
return EC_SUCCESS;
}