summaryrefslogtreecommitdiff
path: root/include/lib
diff options
context:
space:
mode:
authordanh-arm <dan.handley@arm.com>2015-04-01 11:39:56 +0100
committerdanh-arm <dan.handley@arm.com>2015-04-01 11:39:56 +0100
commitcd319142464907e3760129f3e245a325300eb3c3 (patch)
treea8dc03c0d3f47131330f25c7f800db38518723f6 /include/lib
parent099b6051572674da78aac2e4bc55076fbcdbebc6 (diff)
parent548579f56eb95d3d4ba1484a8922a9f6e0a03c73 (diff)
Merge pull request #277 from soby-mathew/sm/coh_lock_opt
Optimize the bakery lock implementation
Diffstat (limited to 'include/lib')
-rw-r--r--include/lib/bakery_lock.h31
1 files changed, 25 insertions, 6 deletions
diff --git a/include/lib/bakery_lock.h b/include/lib/bakery_lock.h
index 9736f850..2e1afa21 100644
--- a/include/lib/bakery_lock.h
+++ b/include/lib/bakery_lock.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -38,16 +38,35 @@
#ifndef __ASSEMBLY__
#include <stdint.h>
+/*****************************************************************************
+ * Internal helper macros used by the bakery lock implementation.
+ ****************************************************************************/
+/* Convert a ticket to priority */
+#define PRIORITY(t, pos) (((t) << 8) | (pos))
+
+#define CHOOSING_TICKET 0x1
+#define CHOSEN_TICKET 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)
+
+/*****************************************************************************
+ * External bakery lock interface.
+ ****************************************************************************/
#if USE_COHERENT_MEM
typedef struct bakery_lock {
- int owner;
- volatile char entering[BAKERY_LOCK_MAX_CPUS];
- volatile unsigned number[BAKERY_LOCK_MAX_CPUS];
+ /*
+ * The lock_data is a bit-field of 2 members:
+ * Bit[0] : choosing. This field is set when the CPU is
+ * choosing its bakery number.
+ * Bits[1 - 15] : number. This is the bakery number allocated.
+ */
+ volatile uint16_t lock_data[BAKERY_LOCK_MAX_CPUS];
} bakery_lock_t;
-#define NO_OWNER (-1)
-
void bakery_lock_init(bakery_lock_t *bakery);
void bakery_lock_get(bakery_lock_t *bakery);
void bakery_lock_release(bakery_lock_t *bakery);