/* * Grace-period counter management. * * The two least significant bits contain the control flags. * The most significant bits contain the grace-period sequence counter. * * When both control flags are zero, no grace period is in progress. * When either bit is non-zero, a grace period has started and is in * progress. When the grace period completes, the control flags are reset * to 0 and the grace-period sequence counter is incremented. * * However some specific RCU usages make use of custom values. * * SRCU special control values: * * SRCU_SNP_INIT_SEQ : Invalid/init value set when SRCU node * is initialized. * * SRCU_STATE_IDLE : No SRCU gp is in progress * * SRCU_STATE_SCAN1 : State set by rcu_seq_start(). Indicates * we are scanning the readers on the slot * defined as inactive (there might well * be pending readers that will use that * index, but their number is bounded). * * SRCU_STATE_SCAN2 : State set manually via rcu_seq_set_state() * Indicates we are flipping the readers * index and then scanning the readers on the * slot newly designated as inactive (again, * the number of pending readers that will use * this inactive index is bounded). * * RCU polled GP special control value: * * RCU_GET_STATE_COMPLETED : State value indicating an already-completed * polled GP has completed. This value covers * both the state and the counter of the * grace-period sequence number.
*/
/* Low-order bit definition for polled grace-period APIs. */ #define RCU_GET_STATE_COMPLETED 0x1
/* A complete grace period count */ #define RCU_SEQ_GP (RCU_SEQ_STATE_MASK + 1)
externint sysctl_sched_rt_runtime;
/* * Return the counter portion of a sequence number previously returned * by rcu_seq_snap() or rcu_seq_current().
*/ staticinlineunsignedlong rcu_seq_ctr(unsignedlong s)
{ return s >> RCU_SEQ_CTR_SHIFT;
}
/* * Return the state portion of a sequence number previously returned * by rcu_seq_snap() or rcu_seq_current().
*/ staticinlineint rcu_seq_state(unsignedlong s)
{ return s & RCU_SEQ_STATE_MASK;
}
/* * Set the state portion of the pointed-to sequence number. * The caller is responsible for preventing conflicting updates.
*/ staticinlinevoid rcu_seq_set_state(unsignedlong *sp, int newstate)
{
WARN_ON_ONCE(newstate & ~RCU_SEQ_STATE_MASK);
WRITE_ONCE(*sp, (*sp & ~RCU_SEQ_STATE_MASK) + newstate);
}
/* Adjust sequence number for start of update-side operation. */ staticinlinevoid rcu_seq_start(unsignedlong *sp)
{
WRITE_ONCE(*sp, *sp + 1);
smp_mb(); /* Ensure update-side operation after counter increment. */
WARN_ON_ONCE(rcu_seq_state(*sp) != 1);
}
/* Compute the end-of-grace-period value for the specified sequence number. */ staticinlineunsignedlong rcu_seq_endval(unsignedlong *sp)
{ return (*sp | RCU_SEQ_STATE_MASK) + 1;
}
/* Adjust sequence number for end of update-side operation. */ staticinlinevoid rcu_seq_end(unsignedlong *sp)
{
smp_mb(); /* Ensure update-side operation before counter increment. */
WARN_ON_ONCE(!rcu_seq_state(*sp));
WRITE_ONCE(*sp, rcu_seq_endval(sp));
}
/* * rcu_seq_snap - Take a snapshot of the update side's sequence number. * * This function returns the earliest value of the grace-period sequence number * that will indicate that a full grace period has elapsed since the current * time. Once the grace-period sequence number has reached this value, it will * be safe to invoke all callbacks that have been registered prior to the * current time. This value is the current grace-period number plus two to the * power of the number of low-order bits reserved for state, then rounded up to * the next value in which the state bits are all zero.
*/ staticinlineunsignedlong rcu_seq_snap(unsignedlong *sp)
{ unsignedlong s;
s = (READ_ONCE(*sp) + 2 * RCU_SEQ_STATE_MASK + 1) & ~RCU_SEQ_STATE_MASK;
smp_mb(); /* Above access must not bleed into critical section. */ return s;
}
/* Return the current value the update side's sequence number, no ordering. */ staticinlineunsignedlong rcu_seq_current(unsignedlong *sp)
{ return READ_ONCE(*sp);
}
/* * Given a snapshot from rcu_seq_snap(), determine whether or not the * corresponding update-side operation has started.
*/ staticinlinebool rcu_seq_started(unsignedlong *sp, unsignedlong s)
{ return ULONG_CMP_LT((s - 1) & ~RCU_SEQ_STATE_MASK, READ_ONCE(*sp));
}
/* * Given a snapshot from rcu_seq_snap(), determine whether or not a * full update-side operation has occurred.
*/ staticinlinebool rcu_seq_done(unsignedlong *sp, unsignedlong s)
{ return ULONG_CMP_GE(READ_ONCE(*sp), s);
}
/* * Given a snapshot from rcu_seq_snap(), determine whether or not a * full update-side operation has occurred, but do not allow the * (ULONG_MAX / 2) safety-factor/guard-band. * * The token returned by get_state_synchronize_rcu_full() is based on * rcu_state.gp_seq but it is tested in poll_state_synchronize_rcu_full() * against the root rnp->gp_seq. Since rcu_seq_start() is first called * on rcu_state.gp_seq and only later reflected on the root rnp->gp_seq, * it is possible that rcu_seq_snap(rcu_state.gp_seq) returns 2 full grace * periods ahead of the root rnp->gp_seq. To prevent false-positives with the * full polling API that a wrap around instantly completed the GP, when nothing * like that happened, adjust for the 2 GPs in the ULONG_CMP_LT().
*/ staticinlinebool rcu_seq_done_exact(unsignedlong *sp, unsignedlong s)
{ unsignedlong cur_s = READ_ONCE(*sp);
/* * Has a grace period completed since the time the old gp_seq was collected?
*/ staticinlinebool rcu_seq_completed_gp(unsignedlong old, unsignedlongnew)
{ return ULONG_CMP_LT(old, new & ~RCU_SEQ_STATE_MASK);
}
/* * Has a grace period started since the time the old gp_seq was collected?
*/ staticinlinebool rcu_seq_new_gp(unsignedlong old, unsignedlongnew)
{ return ULONG_CMP_LT((old + RCU_SEQ_STATE_MASK) & ~RCU_SEQ_STATE_MASK, new);
}
/* * Roughly how many full grace periods have elapsed between the collection * of the two specified grace periods?
*/ staticinlineunsignedlong rcu_seq_diff(unsignedlongnew, unsignedlong old)
{ unsignedlong rnd_diff;
if (old == new) return 0; /* * Compute the number of grace periods (still shifted up), plus * one if either of new and old is not an exact grace period.
*/
rnd_diff = (new & ~RCU_SEQ_STATE_MASK) -
((old + RCU_SEQ_STATE_MASK) & ~RCU_SEQ_STATE_MASK) +
((new & RCU_SEQ_STATE_MASK) || (old & RCU_SEQ_STATE_MASK)); if (ULONG_CMP_GE(RCU_SEQ_STATE_MASK, rnd_diff)) return 1; /* Definitely no grace period has elapsed. */ return ((rnd_diff - RCU_SEQ_STATE_MASK - 1) >> RCU_SEQ_CTR_SHIFT) + 2;
}
/* * debug_rcu_head_queue()/debug_rcu_head_unqueue() are used internally * by call_rcu() and rcu callback execution, and are therefore not part * of the RCU API. These are in rcupdate.h because they are used by all * RCU implementations.
*/
/* * Strings used in tracepoints need to be exported via the * tracing system such that tools like perf and trace-cmd can * translate the string address pointers to actual text.
*/ #define TPS(x) tracepoint_string(x)
/* * Dump the ftrace buffer, but only one time per callsite per boot.
*/ #define rcu_ftrace_dump(oops_dump_mode) \ do { \ static atomic_t ___rfd_beenhere = ATOMIC_INIT(0); \
\ if (!atomic_read(&___rfd_beenhere) && \
!atomic_xchg(&___rfd_beenhere, 1)) { \
tracing_off(); \
rcu_ftrace_dump_stall_suppress(); \
ftrace_dump(oops_dump_mode); \
rcu_ftrace_dump_stall_unsuppress(); \
} \
} while (0)
/* * This function really isn't for public consumption, but RCU is special in * that context switches can allow the state machine to make progress.
*/ externvoid resched_cpu(int cpu);
/* * Compute the per-level fanout, either using the exact fanout specified * or balancing the tree, depending on the rcu_fanout_exact boot parameter.
*/ staticinlinevoid rcu_init_levelspread(int *levelspread, constint *levelcnt)
{ int i;
for (i = 0; i < RCU_NUM_LVLS; i++)
levelspread[i] = INT_MIN; if (rcu_fanout_exact) {
levelspread[rcu_num_lvls - 1] = rcu_fanout_leaf; for (i = rcu_num_lvls - 2; i >= 0; i--)
levelspread[i] = RCU_FANOUT;
} else { int ccur; int cprv;
/* Returns a pointer to the first leaf rcu_node structure. */ #define rcu_first_leaf_node() (rcu_state.level[rcu_num_lvls - 1])
/* Is this rcu_node a leaf? */ #define rcu_is_leaf_node(rnp) ((rnp)->level == rcu_num_lvls - 1)
/* Is this rcu_node the last leaf? */ #define rcu_is_last_leaf_node(rnp) ((rnp) == &rcu_state.node[rcu_num_nodes - 1])
/* * Do a full breadth-first scan of the {s,}rcu_node structures for the * specified state structure (for SRCU) or the only rcu_state structure * (for RCU).
*/ #define _rcu_for_each_node_breadth_first(sp, rnp) \ for ((rnp) = &(sp)->node[0]; \
(rnp) < &(sp)->node[rcu_num_nodes]; (rnp)++) #define rcu_for_each_node_breadth_first(rnp) \
_rcu_for_each_node_breadth_first(&rcu_state, rnp) #define srcu_for_each_node_breadth_first(ssp, rnp) \
_rcu_for_each_node_breadth_first(ssp->srcu_sup, rnp)
/* * Scan the leaves of the rcu_node hierarchy for the rcu_state structure. * Note that if there is a singleton rcu_node tree with but one rcu_node * structure, this loop -will- visit the rcu_node structure. It is still * a leaf node, even if it is also the root node.
*/ #define rcu_for_each_leaf_node(rnp) \ for ((rnp) = rcu_first_leaf_node(); \
(rnp) < &rcu_state.node[rcu_num_nodes]; (rnp)++)
/* * Iterate over all possible CPUs in a leaf RCU node.
*/ #define for_each_leaf_node_possible_cpu(rnp, cpu) \ for (WARN_ON_ONCE(!rcu_is_leaf_node(rnp)), \
(cpu) = cpumask_next((rnp)->grplo - 1, cpu_possible_mask); \
(cpu) <= rnp->grphi; \
(cpu) = cpumask_next((cpu), cpu_possible_mask))
/* * Wrappers for the rcu_node::lock acquire and release. * * Because the rcu_nodes form a tree, the tree traversal locking will observe * different lock values, this in turn means that an UNLOCK of one level * followed by a LOCK of another level does not imply a full memory barrier; * and most importantly transitivity is lost. * * In order to restore full ordering between tree levels, augment the regular * lock acquire functions with smp_mb__after_unlock_lock(). * * As ->lock of struct rcu_node is a __private field, therefore one should use * these wrappers rather than directly call raw_spin_{lock,unlock}* on ->lock.
*/ #define raw_spin_lock_rcu_node(p) \ do { \
raw_spin_lock(&ACCESS_PRIVATE(p, lock)); \
smp_mb__after_unlock_lock(); \
} while (0)
#define raw_spin_unlock_rcu_node(p) \ do { \
lockdep_assert_irqs_disabled(); \
raw_spin_unlock(&ACCESS_PRIVATE(p, lock)); \
} while (0)
#define raw_spin_lock_irq_rcu_node(p) \ do { \
raw_spin_lock_irq(&ACCESS_PRIVATE(p, lock)); \
smp_mb__after_unlock_lock(); \
} while (0)
#define raw_spin_unlock_irq_rcu_node(p) \ do { \
lockdep_assert_irqs_disabled(); \
raw_spin_unlock_irq(&ACCESS_PRIVATE(p, lock)); \
} while (0)
#define raw_spin_lock_irqsave_rcu_node(p, flags) \ do { \
raw_spin_lock_irqsave(&ACCESS_PRIVATE(p, lock), flags); \
smp_mb__after_unlock_lock(); \
} while (0)
#define raw_spin_unlock_irqrestore_rcu_node(p, flags) \ do { \
lockdep_assert_irqs_disabled(); \
raw_spin_unlock_irqrestore(&ACCESS_PRIVATE(p, lock), flags); \
} while (0)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.