From 1c9573a157f0d6d76ded5e651bb3f0b9f3a3c9ec Mon Sep 17 00:00:00 2001 From: Soby Mathew Date: Thu, 19 Feb 2015 16:23:51 +0000 Subject: 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 --- include/lib/bakery_lock.h | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/lib/bakery_lock.h b/include/lib/bakery_lock.h index 9736f850..eaefecd9 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 +/***************************************************************************** + * 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) -- cgit From 548579f56eb95d3d4ba1484a8922a9f6e0a03c73 Mon Sep 17 00:00:00 2001 From: Soby Mathew Date: Fri, 20 Feb 2015 16:04:17 +0000 Subject: 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 --- include/lib/bakery_lock.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'include') diff --git a/include/lib/bakery_lock.h b/include/lib/bakery_lock.h index eaefecd9..2e1afa21 100644 --- a/include/lib/bakery_lock.h +++ b/include/lib/bakery_lock.h @@ -58,7 +58,6 @@ #if USE_COHERENT_MEM typedef struct bakery_lock { - int owner; /* * The lock_data is a bit-field of 2 members: * Bit[0] : choosing. This field is set when the CPU is @@ -68,8 +67,6 @@ typedef struct bakery_lock { 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); -- cgit