Skip to content

Commit a289e60

Browse files
committed
rcutorture: Pull callback forward-progress data into rcu_fwd struct
Now that RCU behaves reasonably well with the current single-kthread call_rcu() forward-progress testing, it is time to add more kthreads. This commit takes a first step towards that goal by wrapping what will be the per-kthread data into a new rcu_fwd structure. Signed-off-by: Paul E. McKenney <[email protected]>
1 parent ebfbaa8 commit a289e60

File tree

1 file changed

+58
-45
lines changed

1 file changed

+58
-45
lines changed

kernel/rcu/rcutorture.c

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,23 +1663,34 @@ struct rcu_fwd_cb {
16631663
struct rcu_fwd_cb *rfc_next;
16641664
int rfc_gps;
16651665
};
1666-
static DEFINE_SPINLOCK(rcu_fwd_lock);
1667-
static struct rcu_fwd_cb *rcu_fwd_cb_head;
1668-
static struct rcu_fwd_cb **rcu_fwd_cb_tail = &rcu_fwd_cb_head;
1669-
static long n_launders_cb;
1670-
static unsigned long rcu_fwd_startat;
1671-
static bool rcu_fwd_emergency_stop;
1666+
16721667
#define MAX_FWD_CB_JIFFIES (8 * HZ) /* Maximum CB test duration. */
16731668
#define MIN_FWD_CB_LAUNDERS 3 /* This many CB invocations to count. */
16741669
#define MIN_FWD_CBS_LAUNDERED 100 /* Number of counted CBs. */
16751670
#define FWD_CBS_HIST_DIV 10 /* Histogram buckets/second. */
1671+
#define N_LAUNDERS_HIST (2 * MAX_FWD_CB_JIFFIES / (HZ / FWD_CBS_HIST_DIV))
1672+
16761673
struct rcu_launder_hist {
16771674
long n_launders;
16781675
unsigned long launder_gp_seq;
16791676
};
1680-
#define N_LAUNDERS_HIST (2 * MAX_FWD_CB_JIFFIES / (HZ / FWD_CBS_HIST_DIV))
1681-
static struct rcu_launder_hist n_launders_hist[N_LAUNDERS_HIST];
1682-
static unsigned long rcu_launder_gp_seq_start;
1677+
1678+
struct rcu_fwd {
1679+
spinlock_t rcu_fwd_lock;
1680+
struct rcu_fwd_cb *rcu_fwd_cb_head;
1681+
struct rcu_fwd_cb **rcu_fwd_cb_tail;
1682+
long n_launders_cb;
1683+
unsigned long rcu_fwd_startat;
1684+
struct rcu_launder_hist n_launders_hist[N_LAUNDERS_HIST];
1685+
unsigned long rcu_launder_gp_seq_start;
1686+
};
1687+
1688+
struct rcu_fwd rcu_fwds = {
1689+
.rcu_fwd_lock = __SPIN_LOCK_UNLOCKED(rcu_fwds.rcu_fwd_lock),
1690+
.rcu_fwd_cb_tail = &rcu_fwds.rcu_fwd_cb_head,
1691+
};
1692+
1693+
bool rcu_fwd_emergency_stop;
16831694

16841695
static void rcu_torture_fwd_cb_hist(void)
16851696
{
@@ -1688,16 +1699,17 @@ static void rcu_torture_fwd_cb_hist(void)
16881699
int i;
16891700
int j;
16901701

1691-
for (i = ARRAY_SIZE(n_launders_hist) - 1; i > 0; i--)
1692-
if (n_launders_hist[i].n_launders > 0)
1702+
for (i = ARRAY_SIZE(rcu_fwds.n_launders_hist) - 1; i > 0; i--)
1703+
if (rcu_fwds.n_launders_hist[i].n_launders > 0)
16931704
break;
16941705
pr_alert("%s: Callback-invocation histogram (duration %lu jiffies):",
1695-
__func__, jiffies - rcu_fwd_startat);
1696-
gps_old = rcu_launder_gp_seq_start;
1706+
__func__, jiffies - rcu_fwds.rcu_fwd_startat);
1707+
gps_old = rcu_fwds.rcu_launder_gp_seq_start;
16971708
for (j = 0; j <= i; j++) {
1698-
gps = n_launders_hist[j].launder_gp_seq;
1709+
gps = rcu_fwds.n_launders_hist[j].launder_gp_seq;
16991710
pr_cont(" %ds/%d: %ld:%ld",
1700-
j + 1, FWD_CBS_HIST_DIV, n_launders_hist[j].n_launders,
1711+
j + 1, FWD_CBS_HIST_DIV,
1712+
rcu_fwds.n_launders_hist[j].n_launders,
17011713
rcutorture_seq_diff(gps, gps_old));
17021714
gps_old = gps;
17031715
}
@@ -1714,17 +1726,17 @@ static void rcu_torture_fwd_cb_cr(struct rcu_head *rhp)
17141726

17151727
rfcp->rfc_next = NULL;
17161728
rfcp->rfc_gps++;
1717-
spin_lock_irqsave(&rcu_fwd_lock, flags);
1718-
rfcpp = rcu_fwd_cb_tail;
1719-
rcu_fwd_cb_tail = &rfcp->rfc_next;
1729+
spin_lock_irqsave(&rcu_fwds.rcu_fwd_lock, flags);
1730+
rfcpp = rcu_fwds.rcu_fwd_cb_tail;
1731+
rcu_fwds.rcu_fwd_cb_tail = &rfcp->rfc_next;
17201732
WRITE_ONCE(*rfcpp, rfcp);
1721-
WRITE_ONCE(n_launders_cb, n_launders_cb + 1);
1722-
i = ((jiffies - rcu_fwd_startat) / (HZ / FWD_CBS_HIST_DIV));
1723-
if (i >= ARRAY_SIZE(n_launders_hist))
1724-
i = ARRAY_SIZE(n_launders_hist) - 1;
1725-
n_launders_hist[i].n_launders++;
1726-
n_launders_hist[i].launder_gp_seq = cur_ops->get_gp_seq();
1727-
spin_unlock_irqrestore(&rcu_fwd_lock, flags);
1733+
WRITE_ONCE(rcu_fwds.n_launders_cb, rcu_fwds.n_launders_cb + 1);
1734+
i = ((jiffies - rcu_fwds.rcu_fwd_startat) / (HZ / FWD_CBS_HIST_DIV));
1735+
if (i >= ARRAY_SIZE(rcu_fwds.n_launders_hist))
1736+
i = ARRAY_SIZE(rcu_fwds.n_launders_hist) - 1;
1737+
rcu_fwds.n_launders_hist[i].n_launders++;
1738+
rcu_fwds.n_launders_hist[i].launder_gp_seq = cur_ops->get_gp_seq();
1739+
spin_unlock_irqrestore(&rcu_fwds.rcu_fwd_lock, flags);
17281740
}
17291741

17301742
// Give the scheduler a chance, even on nohz_full CPUs.
@@ -1751,16 +1763,16 @@ static unsigned long rcu_torture_fwd_prog_cbfree(void)
17511763
struct rcu_fwd_cb *rfcp;
17521764

17531765
for (;;) {
1754-
spin_lock_irqsave(&rcu_fwd_lock, flags);
1755-
rfcp = rcu_fwd_cb_head;
1766+
spin_lock_irqsave(&rcu_fwds.rcu_fwd_lock, flags);
1767+
rfcp = rcu_fwds.rcu_fwd_cb_head;
17561768
if (!rfcp) {
1757-
spin_unlock_irqrestore(&rcu_fwd_lock, flags);
1769+
spin_unlock_irqrestore(&rcu_fwds.rcu_fwd_lock, flags);
17581770
break;
17591771
}
1760-
rcu_fwd_cb_head = rfcp->rfc_next;
1761-
if (!rcu_fwd_cb_head)
1762-
rcu_fwd_cb_tail = &rcu_fwd_cb_head;
1763-
spin_unlock_irqrestore(&rcu_fwd_lock, flags);
1772+
rcu_fwds.rcu_fwd_cb_head = rfcp->rfc_next;
1773+
if (!rcu_fwds.rcu_fwd_cb_head)
1774+
rcu_fwds.rcu_fwd_cb_tail = &rcu_fwds.rcu_fwd_cb_head;
1775+
spin_unlock_irqrestore(&rcu_fwds.rcu_fwd_lock, flags);
17641776
kfree(rfcp);
17651777
freed++;
17661778
rcu_torture_fwd_prog_cond_resched(freed);
@@ -1804,8 +1816,8 @@ static void rcu_torture_fwd_prog_nr(int *tested, int *tested_tries)
18041816
sd = cur_ops->stall_dur() + 1;
18051817
sd4 = (sd + fwd_progress_div - 1) / fwd_progress_div;
18061818
dur = sd4 + torture_random(&trs) % (sd - sd4);
1807-
WRITE_ONCE(rcu_fwd_startat, jiffies);
1808-
stopat = rcu_fwd_startat + dur;
1819+
WRITE_ONCE(rcu_fwds.rcu_fwd_startat, jiffies);
1820+
stopat = rcu_fwds.rcu_fwd_startat + dur;
18091821
while (time_before(jiffies, stopat) &&
18101822
!shutdown_time_arrived() &&
18111823
!READ_ONCE(rcu_fwd_emergency_stop) && !torture_must_stop()) {
@@ -1864,31 +1876,31 @@ static void rcu_torture_fwd_prog_cr(void)
18641876
/* Loop continuously posting RCU callbacks. */
18651877
WRITE_ONCE(rcu_fwd_cb_nodelay, true);
18661878
cur_ops->sync(); /* Later readers see above write. */
1867-
WRITE_ONCE(rcu_fwd_startat, jiffies);
1868-
stopat = rcu_fwd_startat + MAX_FWD_CB_JIFFIES;
1879+
WRITE_ONCE(rcu_fwds.rcu_fwd_startat, jiffies);
1880+
stopat = rcu_fwds.rcu_fwd_startat + MAX_FWD_CB_JIFFIES;
18691881
n_launders = 0;
1870-
n_launders_cb = 0;
1882+
rcu_fwds.n_launders_cb = 0; // Hoist initialization for multi-kthread
18711883
n_launders_sa = 0;
18721884
n_max_cbs = 0;
18731885
n_max_gps = 0;
1874-
for (i = 0; i < ARRAY_SIZE(n_launders_hist); i++)
1875-
n_launders_hist[i].n_launders = 0;
1886+
for (i = 0; i < ARRAY_SIZE(rcu_fwds.n_launders_hist); i++)
1887+
rcu_fwds.n_launders_hist[i].n_launders = 0;
18761888
cver = READ_ONCE(rcu_torture_current_version);
18771889
gps = cur_ops->get_gp_seq();
1878-
rcu_launder_gp_seq_start = gps;
1890+
rcu_fwds.rcu_launder_gp_seq_start = gps;
18791891
tick_dep_set_task(current, TICK_DEP_BIT_RCU);
18801892
while (time_before(jiffies, stopat) &&
18811893
!shutdown_time_arrived() &&
18821894
!READ_ONCE(rcu_fwd_emergency_stop) && !torture_must_stop()) {
1883-
rfcp = READ_ONCE(rcu_fwd_cb_head);
1895+
rfcp = READ_ONCE(rcu_fwds.rcu_fwd_cb_head);
18841896
rfcpn = NULL;
18851897
if (rfcp)
18861898
rfcpn = READ_ONCE(rfcp->rfc_next);
18871899
if (rfcpn) {
18881900
if (rfcp->rfc_gps >= MIN_FWD_CB_LAUNDERS &&
18891901
++n_max_gps >= MIN_FWD_CBS_LAUNDERED)
18901902
break;
1891-
rcu_fwd_cb_head = rfcpn;
1903+
rcu_fwds.rcu_fwd_cb_head = rfcpn;
18921904
n_launders++;
18931905
n_launders_sa++;
18941906
} else {
@@ -1910,7 +1922,7 @@ static void rcu_torture_fwd_prog_cr(void)
19101922
}
19111923
}
19121924
stoppedat = jiffies;
1913-
n_launders_cb_snap = READ_ONCE(n_launders_cb);
1925+
n_launders_cb_snap = READ_ONCE(rcu_fwds.n_launders_cb);
19141926
cver = READ_ONCE(rcu_torture_current_version) - cver;
19151927
gps = rcutorture_seq_diff(cur_ops->get_gp_seq(), gps);
19161928
cur_ops->cb_barrier(); /* Wait for callbacks to be invoked. */
@@ -1921,7 +1933,8 @@ static void rcu_torture_fwd_prog_cr(void)
19211933
WARN_ON(n_max_gps < MIN_FWD_CBS_LAUNDERED);
19221934
pr_alert("%s Duration %lu barrier: %lu pending %ld n_launders: %ld n_launders_sa: %ld n_max_gps: %ld n_max_cbs: %ld cver %ld gps %ld\n",
19231935
__func__,
1924-
stoppedat - rcu_fwd_startat, jiffies - stoppedat,
1936+
stoppedat - rcu_fwds.rcu_fwd_startat,
1937+
jiffies - stoppedat,
19251938
n_launders + n_max_cbs - n_launders_cb_snap,
19261939
n_launders, n_launders_sa,
19271940
n_max_gps, n_max_cbs, cver, gps);
@@ -1943,7 +1956,7 @@ static int rcutorture_oom_notify(struct notifier_block *self,
19431956
WARN(1, "%s invoked upon OOM during forward-progress testing.\n",
19441957
__func__);
19451958
rcu_torture_fwd_cb_hist();
1946-
rcu_fwd_progress_check(1 + (jiffies - READ_ONCE(rcu_fwd_startat)) / 2);
1959+
rcu_fwd_progress_check(1 + (jiffies - READ_ONCE(rcu_fwds.rcu_fwd_startat)) / 2);
19471960
WRITE_ONCE(rcu_fwd_emergency_stop, true);
19481961
smp_mb(); /* Emergency stop before free and wait to avoid hangs. */
19491962
pr_info("%s: Freed %lu RCU callbacks.\n",

0 commit comments

Comments
 (0)