aboutsummaryrefslogtreecommitdiff
path: root/include/lib/bakery_lock.h
diff options
context:
space:
mode:
authorSoby Mathew <soby.mathew@arm.com>2015-02-19 16:23:51 +0000
committerSoby Mathew <soby.mathew@arm.com>2015-03-27 10:20:32 +0000
commit1c9573a157f0d6d76ded5e651bb3f0b9f3a3c9ec (patch)
tree3d7c8c3a34a958a94abaffcf570eb4da12adbb7d /include/lib/bakery_lock.h
parent3b982be3b374cdc4947e23dd122f748dc7680d09 (diff)
downloadarm-trusted-firmware-1c9573a157f0d6d76ded5e651bb3f0b9f3a3c9ec.tar.gz
Optimize the bakery lock structure for coherent memory
This patch optimizes the data structure used with the bakery lock implementation for coherent memory to save memory and minimize memory accesses. These optimizations were already part of the bakery lock implementation for normal memory and this patch now implements it for the coherent memory implementation as well. Also included in the patch is a cleanup to use the do-while loop while waiting for other contenders to finish choosing their tickets. Change-Id: Iedb305473133dc8f12126726d8329b67888b70f1
Diffstat (limited to 'include/lib/bakery_lock.h')
-rw-r--r--include/lib/bakery_lock.h28
1 files changed, 25 insertions, 3 deletions
diff --git a/include/lib/bakery_lock.h b/include/lib/bakery_lock.h
index 9736f850a..eaefecd9e 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,12 +38,34 @@
#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)