summaryrefslogtreecommitdiff
path: root/lib/locks/bakery/bakery_lock_normal.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/locks/bakery/bakery_lock_normal.c')
-rw-r--r--lib/locks/bakery/bakery_lock_normal.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/lib/locks/bakery/bakery_lock_normal.c b/lib/locks/bakery/bakery_lock_normal.c
index a325fd4f..5439271e 100644
--- a/lib/locks/bakery/bakery_lock_normal.c
+++ b/lib/locks/bakery/bakery_lock_normal.c
@@ -56,17 +56,6 @@
* accesses regardless of status of address translation.
*/
-/* Convert a ticket to priority */
-#define PRIORITY(t, pos) (((t) << 8) | (pos))
-
-#define CHOOSING_TICKET 0x1
-#define CHOOSING_DONE 0x0
-
-#define bakery_is_choosing(info) (info & 0x1)
-#define bakery_ticket_number(info) ((info >> 1) & 0x7FFF)
-#define make_bakery_data(choosing, number) \
- (((choosing & 0x1) | (number << 1)) & 0xFFFF)
-
/* This macro assumes that the bakery_info array is located at the offset specified */
#define get_my_bakery_info(offset, id) \
(((bakery_info_t *) (((uint8_t *)_cpu_data()) + offset)) + id)
@@ -99,6 +88,13 @@ static unsigned int bakery_get_ticket(int id, unsigned int offset,
assert(my_bakery_info);
/*
+ * Prevent recursive acquisition.
+ * Since lock data is written to and cleaned by the owning cpu, it
+ * doesn't require any cache operations prior to reading the lock data.
+ */
+ assert(!bakery_ticket_number(my_bakery_info->lock_data));
+
+ /*
* Tell other contenders that we are through the bakery doorway i.e.
* going to allocate a ticket for this cpu.
*/
@@ -138,7 +134,7 @@ static unsigned int bakery_get_ticket(int id, unsigned int offset,
* finish calculating our ticket value that we're done
*/
++my_ticket;
- my_bakery_info->lock_data = make_bakery_data(CHOOSING_DONE, my_ticket);
+ my_bakery_info->lock_data = make_bakery_data(CHOSEN_TICKET, my_ticket);
write_cache_op(my_bakery_info, is_cached);
@@ -150,7 +146,7 @@ void bakery_lock_get(unsigned int id, unsigned int offset)
unsigned int they, me, is_cached;
unsigned int my_ticket, my_prio, their_ticket;
bakery_info_t *their_bakery_info;
- uint16_t their_bakery_data;
+ unsigned int their_bakery_data;
me = platform_get_core_pos(read_mpidr_el1());
@@ -174,15 +170,12 @@ void bakery_lock_get(unsigned int id, unsigned int offset)
*/
their_bakery_info = get_bakery_info_by_index(offset, id, they);
assert(their_bakery_info);
- read_cache_op(their_bakery_info, is_cached);
-
- their_bakery_data = their_bakery_info->lock_data;
/* Wait for the contender to get their ticket */
- while (bakery_is_choosing(their_bakery_data)) {
+ do {
read_cache_op(their_bakery_info, is_cached);
their_bakery_data = their_bakery_info->lock_data;
- }
+ } while (bakery_is_choosing(their_bakery_data));
/*
* If the other party is a contender, they'll have non-zero
@@ -203,6 +196,7 @@ void bakery_lock_get(unsigned int id, unsigned int offset)
== bakery_ticket_number(their_bakery_info->lock_data));
}
}
+ /* Lock acquired */
}
void bakery_lock_release(unsigned int id, unsigned int offset)
@@ -211,6 +205,8 @@ void bakery_lock_release(unsigned int id, unsigned int offset)
unsigned int is_cached = read_sctlr_el3() & SCTLR_C_BIT;
my_bakery_info = get_my_bakery_info(offset, id);
+ assert(bakery_ticket_number(my_bakery_info->lock_data));
+
my_bakery_info->lock_data = 0;
write_cache_op(my_bakery_info, is_cached);
sev();