// SPDX-License-Identifier: GPL-2.0+ /* * RCU-based infrastructure for lightweight reader-writer locking * * Copyright (c) 2015, Red Hat, Inc. * * Author: Oleg Nesterov <[email protected]> */ #include <linux/rcu_sync.h> #include <linux/sched.h> enum { … }; #define rss_lock … /** * rcu_sync_init() - Initialize an rcu_sync structure * @rsp: Pointer to rcu_sync structure to be initialized */ void rcu_sync_init(struct rcu_sync *rsp) { … } static void rcu_sync_func(struct rcu_head *rhp); static void rcu_sync_call(struct rcu_sync *rsp) { … } /** * rcu_sync_func() - Callback function managing reader access to fastpath * @rhp: Pointer to rcu_head in rcu_sync structure to use for synchronization * * This function is passed to call_rcu() function by rcu_sync_enter() and * rcu_sync_exit(), so that it is invoked after a grace period following the * that invocation of enter/exit. * * If it is called by rcu_sync_enter() it signals that all the readers were * switched onto slow path. * * If it is called by rcu_sync_exit() it takes action based on events that * have taken place in the meantime, so that closely spaced rcu_sync_enter() * and rcu_sync_exit() pairs need not wait for a grace period. * * If another rcu_sync_enter() is invoked before the grace period * ended, reset state to allow the next rcu_sync_exit() to let the * readers back onto their fastpaths (after a grace period). If both * another rcu_sync_enter() and its matching rcu_sync_exit() are invoked * before the grace period ended, re-invoke call_rcu() on behalf of that * rcu_sync_exit(). Otherwise, set all state back to idle so that readers * can again use their fastpaths. */ static void rcu_sync_func(struct rcu_head *rhp) { … } /** * rcu_sync_enter() - Force readers onto slowpath * @rsp: Pointer to rcu_sync structure to use for synchronization * * This function is used by updaters who need readers to make use of * a slowpath during the update. After this function returns, all * subsequent calls to rcu_sync_is_idle() will return false, which * tells readers to stay off their fastpaths. A later call to * rcu_sync_exit() re-enables reader fastpaths. * * When called in isolation, rcu_sync_enter() must wait for a grace * period, however, closely spaced calls to rcu_sync_enter() can * optimize away the grace-period wait via a state machine implemented * by rcu_sync_enter(), rcu_sync_exit(), and rcu_sync_func(). */ void rcu_sync_enter(struct rcu_sync *rsp) { … } /** * rcu_sync_exit() - Allow readers back onto fast path after grace period * @rsp: Pointer to rcu_sync structure to use for synchronization * * This function is used by updaters who have completed, and can therefore * now allow readers to make use of their fastpaths after a grace period * has elapsed. After this grace period has completed, all subsequent * calls to rcu_sync_is_idle() will return true, which tells readers that * they can once again use their fastpaths. */ void rcu_sync_exit(struct rcu_sync *rsp) { … } /** * rcu_sync_dtor() - Clean up an rcu_sync structure * @rsp: Pointer to rcu_sync structure to be cleaned up */ void rcu_sync_dtor(struct rcu_sync *rsp) { … }