summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2014-11-21 10:29:29 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-11-22 09:34:23 +0000
commit3483f0b1dd368a3f250b24ce0a0920e1627a5592 (patch)
treecd3f6a7707fe8fb3037feb028e8f56f15b8bc0e1
parentafc9090d7e7742cf770a25318514a05325b2bdcc (diff)
downloadchrome-ec-3483f0b1dd368a3f250b24ce0a0920e1627a5592.tar.gz
Stop mutex_lock() from eating pending events
When another task is holding the lock, mutex_lock() should call task_wait_event_mask() to wait only for TASK_EVENT_MUTEX events. If it calls task_wait_event(), any pending events are silently discarded while its waiting for the the lock. BUG=chromium:435611 BRANCH=ToT,samus TEST=make buildall -j, and: Before this change, I watched the EC console while shutting down and rebooting Samus. I saw the request event arrive: [37.576295 LB lightbar_resume() requests 5 S3S0] [46.055725 LB_version] But the lightbar task never saw it. Adding a bunch of debug messages showed that it was being lost in mutex_lock(). After this change, the event is delivered: [30.167670 LB lightbar_resume() requests 5 S3S0] [30.171009 LB cur_seq 2 S3 returned pending msg 5 S3S0] [30.173816 LB running cur_seq 5 S3S0. prev_seq 2 S3] [32.410073 LB cur_seq 5 S3S0 returned value 0] [32.410865 LB running cur_seq 3 S0. prev_seq 2 S3] [39.938388 LB_version] Signed-off-by: Bill Richardson <wfrichar@chromium.org> Change-Id: I011838538960cc57171f0a3c4cdee113d156e9ff Reviewed-on: https://chromium-review.googlesource.com/231370 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--core/cortex-m/task.c3
-rw-r--r--core/cortex-m0/task.c2
-rw-r--r--core/host/task.c3
-rw-r--r--core/nds32/task.c2
4 files changed, 9 insertions, 1 deletions
diff --git a/core/cortex-m/task.c b/core/cortex-m/task.c
index de690ad007..7f667b3f4a 100644
--- a/core/cortex-m/task.c
+++ b/core/cortex-m/task.c
@@ -481,7 +481,8 @@ void mutex_lock(struct mutex *mtx)
* 2 if somebody else owns the mutex, 0 else.
*/
if (value == 2)
- task_wait_event(0); /* Contention on the mutex */
+ /* Contention on the mutex */
+ task_wait_event_mask(TASK_EVENT_MUTEX, 0);
} while (value);
atomic_clear(&mtx->waiters, id);
diff --git a/core/cortex-m0/task.c b/core/cortex-m0/task.c
index b30cab5c98..af3a4e2277 100644
--- a/core/cortex-m0/task.c
+++ b/core/cortex-m0/task.c
@@ -451,6 +451,8 @@ void mutex_lock(struct mutex *mtx)
if (mtx->lock == 0)
break;
__asm__ __volatile__("cpsie i");
+ /* TODO(crbug.com/435612, crbug.com/435611)
+ * This discards any pending events! */
task_wait_event(0); /* Contention on the mutex */
}
mtx->lock = 2;
diff --git a/core/host/task.c b/core/host/task.c
index 5bff856def..98a77b8e41 100644
--- a/core/host/task.c
+++ b/core/host/task.c
@@ -210,6 +210,9 @@ void mutex_lock(struct mutex *mtx)
}
if (!value)
+ /* Contention on the mutex */
+ /* TODO(crbug.com/435612, crbug.com/435611)
+ * This discards any pending events! */
task_wait_event(-1);
} while (!value);
diff --git a/core/nds32/task.c b/core/nds32/task.c
index fc167da878..1725f2b498 100644
--- a/core/nds32/task.c
+++ b/core/nds32/task.c
@@ -381,6 +381,8 @@ void mutex_lock(struct mutex *mtx)
/* end of critical section : re-enable interrupts */
asm volatile ("setgie.e");
/* Sleep waiting for our turn */
+ /* TODO(crbug.com/435612, crbug.com/435611)
+ * This discards any pending events! */
task_wait_event(0);
/* re-enter critical section */
asm volatile ("setgie.d ; dsb");