summaryrefslogtreecommitdiff
path: root/lib/locks
diff options
context:
space:
mode:
authorSoby Mathew <soby.mathew@arm.com>2015-02-20 16:04:17 +0000
committerSoby Mathew <soby.mathew@arm.com>2015-03-27 10:20:32 +0000
commit548579f56eb95d3d4ba1484a8922a9f6e0a03c73 (patch)
treef3aeac2b4605b0f8ee56a6d12f0ca6c4e4d5b0a6 /lib/locks
parent1c9573a157f0d6d76ded5e651bb3f0b9f3a3c9ec (diff)
Remove the `owner` field in bakery_lock_t data structure
This patch removes the `owner` field in bakery_lock_t structure which is the data structure used in the bakery lock implementation that uses coherent memory. The assertions to protect against recursive lock acquisition were based on the 'owner' field. They are now done based on the bakery lock ticket number. These assertions are also added to the bakery lock implementation that uses normal memory as well. Change-Id: If4850a00dffd3977e218c0f0a8d145808f36b470
Diffstat (limited to 'lib/locks')
-rw-r--r--lib/locks/bakery/bakery_lock_coherent.c16
-rw-r--r--lib/locks/bakery/bakery_lock_normal.c10
2 files changed, 16 insertions, 10 deletions
diff --git a/lib/locks/bakery/bakery_lock_coherent.c b/lib/locks/bakery/bakery_lock_coherent.c
index 02d31d64..fd871053 100644
--- a/lib/locks/bakery/bakery_lock_coherent.c
+++ b/lib/locks/bakery/bakery_lock_coherent.c
@@ -63,14 +63,13 @@
assert(entry < BAKERY_LOCK_MAX_CPUS); \
} while (0)
-/* Initialize Bakery Lock to reset ownership and all ticket values */
+/* Initialize Bakery Lock to reset all ticket values */
void bakery_lock_init(bakery_lock_t *bakery)
{
assert(bakery);
/* All ticket values need to be 0 */
memset(bakery, 0, sizeof(*bakery));
- bakery->owner = NO_OWNER;
}
@@ -80,6 +79,9 @@ static unsigned int bakery_get_ticket(bakery_lock_t *bakery, unsigned int me)
unsigned int my_ticket, their_ticket;
unsigned int they;
+ /* Prevent recursive acquisition */
+ assert(!bakery_ticket_number(bakery->lock_data[me]));
+
/*
* Flag that we're busy getting our ticket. All CPUs are iterated in the
* order of their ordinal position to decide the maximum ticket value
@@ -130,9 +132,6 @@ void bakery_lock_get(bakery_lock_t *bakery)
assert_bakery_entry_valid(me, bakery);
- /* Prevent recursive acquisition */
- assert(bakery->owner != me);
-
/* Get a ticket */
my_ticket = bakery_get_ticket(bakery, me);
@@ -168,9 +167,7 @@ void bakery_lock_get(bakery_lock_t *bakery)
bakery_ticket_number(bakery->lock_data[they]));
}
}
-
/* Lock acquired */
- bakery->owner = me;
}
@@ -180,13 +177,12 @@ void bakery_lock_release(bakery_lock_t *bakery)
unsigned int me = platform_get_core_pos(read_mpidr_el1());
assert_bakery_entry_valid(me, bakery);
- assert(bakery->owner == me);
+ assert(bakery_ticket_number(bakery->lock_data[me]));
/*
- * Release lock by resetting ownership and ticket. Then signal other
+ * Release lock by resetting ticket. Then signal other
* waiting contenders
*/
- bakery->owner = NO_OWNER;
bakery->lock_data[me] = 0;
dsb();
sev();
diff --git a/lib/locks/bakery/bakery_lock_normal.c b/lib/locks/bakery/bakery_lock_normal.c
index 4503ae09..5439271e 100644
--- a/lib/locks/bakery/bakery_lock_normal.c
+++ b/lib/locks/bakery/bakery_lock_normal.c
@@ -88,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.
*/
@@ -189,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)
@@ -197,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();