Skip to content

Commit

Permalink
retention: Allow disabling mutex support
Browse files Browse the repository at this point in the history
Changes the Kconfig option to allow disabling mutex support, this
is to allow other Kconfig options to disable the feature. Also
adds an optional dts option which can be used to disable muted
support for a specific retention area.

Signed-off-by: Jamie McCrae <[email protected]>
  • Loading branch information
nordicjm committed Jun 15, 2023
1 parent bab35a5 commit 5b34cb5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
6 changes: 6 additions & 0 deletions dts/bindings/retention/zephyr,retention.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,9 @@ properties:
16-bit CRC, 4 for 32-bit CRC). Default is to not use a checksum.
type: int
default: 0

no-mutex:
description: |
If specified, will disable mutex protection, should only be enabled if
this is a requirement for a particular retention area.
type: boolean
17 changes: 13 additions & 4 deletions subsys/retention/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,22 @@ config RETENTION_INIT_PRIORITY
priorities for retained memory drivers.

config RETENTION_MUTEXES
bool "Retention mutex support"
bool
default y
depends on MULTITHREADING
depends on !RETENTION_MUTEX_FORCE_DISABLE

config RETENTION_MUTEX_FORCE_DISABLE
bool "Disable retention mutex support"
depends on MULTITHREADING
help
Use mutexes to prevent issues with concurrent retention device
access. Should only be disabled whereby retained memory access is
required in an ISR or for special use cases.
Disable use of mutexes which prevent issues with concurrent retention
device access. This option should should only be enabled when
retention device access is required in an ISR or for special use
cases.

Note that this can also be enforced on a per-partition basis by
setting the ``no-mutex;`` device tree property instead.

config RETENTION_BUFFER_SIZE
int "Retention stack buffer sizes"
Expand Down
21 changes: 19 additions & 2 deletions subsys/retention/retention.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ struct retention_config {
size_t offset;
size_t size;
size_t reserved_size;
#ifdef CONFIG_RETENTION_MUTEXES
bool mutex;
#endif
uint8_t checksum_size;
uint8_t prefix_len;
uint8_t prefix[];
Expand All @@ -50,8 +53,11 @@ static inline void retention_lock_take(const struct device *dev)
{
#ifdef CONFIG_RETENTION_MUTEXES
struct retention_data *data = dev->data;
const struct retention_config *config = dev->config;

k_mutex_lock(&data->lock, K_FOREVER);
if (config->mutex) {
k_mutex_lock(&data->lock, K_FOREVER);
}
#else
ARG_UNUSED(dev);
#endif
Expand All @@ -61,8 +67,11 @@ static inline void retention_lock_release(const struct device *dev)
{
#ifdef CONFIG_RETENTION_MUTEXES
struct retention_data *data = dev->data;
const struct retention_config *config = dev->config;

k_mutex_unlock(&data->lock);
if (config->mutex) {
k_mutex_unlock(&data->lock);
}
#else
ARG_UNUSED(dev);
#endif
Expand Down Expand Up @@ -376,6 +385,13 @@ static const struct retention_api retention_api = {
.clear = retention_clear,
};

#ifdef CONFIG_RETENTION_MUTEXES
#define RETENTION_MUTEX(inst) \
.mutex = COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, no_mutex), (false), (true))
#else
#define RETENTION_MUTEX(inst)
#endif

#define RETENTION_DEVICE(inst) \
static struct retention_data \
retention_data_##inst = { \
Expand All @@ -393,6 +409,7 @@ static const struct retention_api retention_api = {
.prefix_len = COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, prefix), \
(DT_INST_PROP_LEN(inst, prefix)), (0)), \
.prefix = DT_INST_PROP_OR(inst, prefix, {0}), \
RETENTION_MUTEX(inst) \
}; \
DEVICE_DT_INST_DEFINE(inst, \
&retention_init, \
Expand Down

0 comments on commit 5b34cb5

Please sign in to comment.