2019-01-18 02:39:22 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2017-03-26 00:59:38 +08:00
|
|
|
/*
|
|
|
|
* Sleepable Read-Copy Update mechanism for mutual exclusion,
|
|
|
|
* tiny variant.
|
|
|
|
*
|
|
|
|
* Copyright (C) IBM Corporation, 2017
|
|
|
|
*
|
2019-01-18 02:39:22 +08:00
|
|
|
* Author: Paul McKenney <paulmck@linux.ibm.com>
|
2017-03-26 00:59:38 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LINUX_SRCU_TINY_H
|
|
|
|
#define _LINUX_SRCU_TINY_H
|
|
|
|
|
|
|
|
#include <linux/swait.h>
|
|
|
|
|
|
|
|
struct srcu_struct {
|
2017-04-22 04:33:20 +08:00
|
|
|
short srcu_lock_nesting[2]; /* srcu_read_lock() nesting depth. */
|
2020-11-13 08:34:09 +08:00
|
|
|
unsigned short srcu_idx; /* Current reader array element in bit 0x2. */
|
2020-11-14 04:54:48 +08:00
|
|
|
unsigned short srcu_idx_max; /* Furthest future srcu_idx request. */
|
2017-04-22 04:33:20 +08:00
|
|
|
u8 srcu_gp_running; /* GP workqueue running? */
|
|
|
|
u8 srcu_gp_waiting; /* GP waiting for readers? */
|
2017-03-26 00:59:38 +08:00
|
|
|
struct swait_queue_head srcu_wq;
|
|
|
|
/* Last srcu_read_unlock() wakes GP. */
|
2017-05-05 05:29:16 +08:00
|
|
|
struct rcu_head *srcu_cb_head; /* Pending callbacks: Head. */
|
|
|
|
struct rcu_head **srcu_cb_tail; /* Pending callbacks: Tail. */
|
2017-03-26 00:59:38 +08:00
|
|
|
struct work_struct srcu_work; /* For driving grace periods. */
|
|
|
|
#ifdef CONFIG_DEBUG_LOCK_ALLOC
|
|
|
|
struct lockdep_map dep_map;
|
|
|
|
#endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
|
|
|
|
};
|
|
|
|
|
|
|
|
void srcu_drive_gp(struct work_struct *wp);
|
|
|
|
|
2018-05-25 18:19:57 +08:00
|
|
|
#define __SRCU_STRUCT_INIT(name, __ignored) \
|
2017-03-26 00:59:38 +08:00
|
|
|
{ \
|
|
|
|
.srcu_wq = __SWAIT_QUEUE_HEAD_INITIALIZER(name.srcu_wq), \
|
2017-05-05 05:29:16 +08:00
|
|
|
.srcu_cb_tail = &name.srcu_cb_head, \
|
2017-03-26 00:59:38 +08:00
|
|
|
.srcu_work = __WORK_INITIALIZER(name.srcu_work, srcu_drive_gp), \
|
|
|
|
__SRCU_DEP_MAP_INIT(name) \
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This odd _STATIC_ arrangement is needed for API compatibility with
|
|
|
|
* Tree SRCU, which needs some per-CPU data.
|
|
|
|
*/
|
|
|
|
#define DEFINE_SRCU(name) \
|
2018-05-25 18:19:57 +08:00
|
|
|
struct srcu_struct name = __SRCU_STRUCT_INIT(name, name)
|
2017-03-26 00:59:38 +08:00
|
|
|
#define DEFINE_STATIC_SRCU(name) \
|
2018-05-25 18:19:57 +08:00
|
|
|
static struct srcu_struct name = __SRCU_STRUCT_INIT(name, name)
|
2017-03-26 00:59:38 +08:00
|
|
|
|
2018-10-29 01:32:51 +08:00
|
|
|
void synchronize_srcu(struct srcu_struct *ssp);
|
2017-03-26 00:59:38 +08:00
|
|
|
|
2017-04-29 05:16:16 +08:00
|
|
|
/*
|
|
|
|
* Counts the new reader in the appropriate per-CPU element of the
|
|
|
|
* srcu_struct. Can be invoked from irq/bh handlers, but the matching
|
|
|
|
* __srcu_read_unlock() must be in the same handler instance. Returns an
|
|
|
|
* index that must be passed to the matching srcu_read_unlock().
|
|
|
|
*/
|
2018-10-29 01:32:51 +08:00
|
|
|
static inline int __srcu_read_lock(struct srcu_struct *ssp)
|
2017-04-29 05:16:16 +08:00
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
|
2020-11-13 08:34:09 +08:00
|
|
|
idx = ((READ_ONCE(ssp->srcu_idx) + 1) & 0x2) >> 1;
|
2018-10-29 01:32:51 +08:00
|
|
|
WRITE_ONCE(ssp->srcu_lock_nesting[idx], ssp->srcu_lock_nesting[idx] + 1);
|
2017-04-29 05:16:16 +08:00
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
2018-10-29 01:32:51 +08:00
|
|
|
static inline void synchronize_srcu_expedited(struct srcu_struct *ssp)
|
2017-03-26 00:59:38 +08:00
|
|
|
{
|
2018-10-29 01:32:51 +08:00
|
|
|
synchronize_srcu(ssp);
|
2017-03-26 00:59:38 +08:00
|
|
|
}
|
|
|
|
|
2018-10-29 01:32:51 +08:00
|
|
|
static inline void srcu_barrier(struct srcu_struct *ssp)
|
2017-03-26 00:59:38 +08:00
|
|
|
{
|
2018-10-29 01:32:51 +08:00
|
|
|
synchronize_srcu(ssp);
|
2017-03-26 00:59:38 +08:00
|
|
|
}
|
|
|
|
|
2017-05-23 04:31:03 +08:00
|
|
|
/* Defined here to avoid size increase for non-torture kernels. */
|
2018-10-29 01:32:51 +08:00
|
|
|
static inline void srcu_torture_stats_print(struct srcu_struct *ssp,
|
2017-05-23 04:31:03 +08:00
|
|
|
char *tt, char *tf)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
|
2020-11-13 08:34:09 +08:00
|
|
|
idx = ((READ_ONCE(ssp->srcu_idx) + 1) & 0x2) >> 1;
|
2017-05-23 04:31:03 +08:00
|
|
|
pr_alert("%s%s Tiny SRCU per-CPU(idx=%d): (%hd,%hd)\n",
|
|
|
|
tt, tf, idx,
|
2018-10-29 01:32:51 +08:00
|
|
|
READ_ONCE(ssp->srcu_lock_nesting[!idx]),
|
|
|
|
READ_ONCE(ssp->srcu_lock_nesting[idx]));
|
2017-05-23 04:31:03 +08:00
|
|
|
}
|
|
|
|
|
2017-03-26 00:59:38 +08:00
|
|
|
#endif
|