Skip to content

Commit 6b1b832

Browse files
committed
rcutorture: Thread rcu_fwd pointer through forward-progress functions
In order to add multiple kthreads, it will be necessary to allow the various functions to operate on a pointer to their kthread's rcu_fwd structure. This commit therefore starts the process of adding the needed "struct rcu_fwd" parameters and arguments to the various callback forward-progress functions. Note that rcutorture_oom_notify() and rcu_torture_fwd_cb_hist() will eventually need to iterate over all kthreads' rcu_fwd structures. Signed-off-by: Paul E. McKenney <[email protected]>
1 parent a289e60 commit 6b1b832

File tree

1 file changed

+41
-37
lines changed

1 file changed

+41
-37
lines changed

kernel/rcu/rcutorture.c

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,7 @@ static void rcu_torture_fwd_prog_cb(struct rcu_head *rhp)
16611661
struct rcu_fwd_cb {
16621662
struct rcu_head rh;
16631663
struct rcu_fwd_cb *rfc_next;
1664+
struct rcu_fwd *rfc_rfp;
16641665
int rfc_gps;
16651666
};
16661667

@@ -1692,24 +1693,24 @@ struct rcu_fwd rcu_fwds = {
16921693

16931694
bool rcu_fwd_emergency_stop;
16941695

1695-
static void rcu_torture_fwd_cb_hist(void)
1696+
static void rcu_torture_fwd_cb_hist(struct rcu_fwd *rfp)
16961697
{
16971698
unsigned long gps;
16981699
unsigned long gps_old;
16991700
int i;
17001701
int j;
17011702

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)
1703+
for (i = ARRAY_SIZE(rfp->n_launders_hist) - 1; i > 0; i--)
1704+
if (rfp->n_launders_hist[i].n_launders > 0)
17041705
break;
17051706
pr_alert("%s: Callback-invocation histogram (duration %lu jiffies):",
1706-
__func__, jiffies - rcu_fwds.rcu_fwd_startat);
1707-
gps_old = rcu_fwds.rcu_launder_gp_seq_start;
1707+
__func__, jiffies - rfp->rcu_fwd_startat);
1708+
gps_old = rfp->rcu_launder_gp_seq_start;
17081709
for (j = 0; j <= i; j++) {
1709-
gps = rcu_fwds.n_launders_hist[j].launder_gp_seq;
1710+
gps = rfp->n_launders_hist[j].launder_gp_seq;
17101711
pr_cont(" %ds/%d: %ld:%ld",
17111712
j + 1, FWD_CBS_HIST_DIV,
1712-
rcu_fwds.n_launders_hist[j].n_launders,
1713+
rfp->n_launders_hist[j].n_launders,
17131714
rcutorture_seq_diff(gps, gps_old));
17141715
gps_old = gps;
17151716
}
@@ -1723,20 +1724,21 @@ static void rcu_torture_fwd_cb_cr(struct rcu_head *rhp)
17231724
int i;
17241725
struct rcu_fwd_cb *rfcp = container_of(rhp, struct rcu_fwd_cb, rh);
17251726
struct rcu_fwd_cb **rfcpp;
1727+
struct rcu_fwd *rfp = rfcp->rfc_rfp;
17261728

17271729
rfcp->rfc_next = NULL;
17281730
rfcp->rfc_gps++;
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;
1731+
spin_lock_irqsave(&rfp->rcu_fwd_lock, flags);
1732+
rfcpp = rfp->rcu_fwd_cb_tail;
1733+
rfp->rcu_fwd_cb_tail = &rfcp->rfc_next;
17321734
WRITE_ONCE(*rfcpp, rfcp);
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);
1735+
WRITE_ONCE(rfp->n_launders_cb, rfp->n_launders_cb + 1);
1736+
i = ((jiffies - rfp->rcu_fwd_startat) / (HZ / FWD_CBS_HIST_DIV));
1737+
if (i >= ARRAY_SIZE(rfp->n_launders_hist))
1738+
i = ARRAY_SIZE(rfp->n_launders_hist) - 1;
1739+
rfp->n_launders_hist[i].n_launders++;
1740+
rfp->n_launders_hist[i].launder_gp_seq = cur_ops->get_gp_seq();
1741+
spin_unlock_irqrestore(&rfp->rcu_fwd_lock, flags);
17401742
}
17411743

17421744
// Give the scheduler a chance, even on nohz_full CPUs.
@@ -1786,7 +1788,8 @@ static unsigned long rcu_torture_fwd_prog_cbfree(void)
17861788
}
17871789

17881790
/* Carry out need_resched()/cond_resched() forward-progress testing. */
1789-
static void rcu_torture_fwd_prog_nr(int *tested, int *tested_tries)
1791+
static void rcu_torture_fwd_prog_nr(struct rcu_fwd *rfp,
1792+
int *tested, int *tested_tries)
17901793
{
17911794
unsigned long cver;
17921795
unsigned long dur;
@@ -1816,8 +1819,8 @@ static void rcu_torture_fwd_prog_nr(int *tested, int *tested_tries)
18161819
sd = cur_ops->stall_dur() + 1;
18171820
sd4 = (sd + fwd_progress_div - 1) / fwd_progress_div;
18181821
dur = sd4 + torture_random(&trs) % (sd - sd4);
1819-
WRITE_ONCE(rcu_fwds.rcu_fwd_startat, jiffies);
1820-
stopat = rcu_fwds.rcu_fwd_startat + dur;
1822+
WRITE_ONCE(rfp->rcu_fwd_startat, jiffies);
1823+
stopat = rfp->rcu_fwd_startat + dur;
18211824
while (time_before(jiffies, stopat) &&
18221825
!shutdown_time_arrived() &&
18231826
!READ_ONCE(rcu_fwd_emergency_stop) && !torture_must_stop()) {
@@ -1852,7 +1855,7 @@ static void rcu_torture_fwd_prog_nr(int *tested, int *tested_tries)
18521855
}
18531856

18541857
/* Carry out call_rcu() forward-progress testing. */
1855-
static void rcu_torture_fwd_prog_cr(void)
1858+
static void rcu_torture_fwd_prog_cr(struct rcu_fwd *rfp)
18561859
{
18571860
unsigned long cver;
18581861
unsigned long flags;
@@ -1876,31 +1879,31 @@ static void rcu_torture_fwd_prog_cr(void)
18761879
/* Loop continuously posting RCU callbacks. */
18771880
WRITE_ONCE(rcu_fwd_cb_nodelay, true);
18781881
cur_ops->sync(); /* Later readers see above write. */
1879-
WRITE_ONCE(rcu_fwds.rcu_fwd_startat, jiffies);
1880-
stopat = rcu_fwds.rcu_fwd_startat + MAX_FWD_CB_JIFFIES;
1882+
WRITE_ONCE(rfp->rcu_fwd_startat, jiffies);
1883+
stopat = rfp->rcu_fwd_startat + MAX_FWD_CB_JIFFIES;
18811884
n_launders = 0;
1882-
rcu_fwds.n_launders_cb = 0; // Hoist initialization for multi-kthread
1885+
rfp->n_launders_cb = 0; // Hoist initialization for multi-kthread
18831886
n_launders_sa = 0;
18841887
n_max_cbs = 0;
18851888
n_max_gps = 0;
1886-
for (i = 0; i < ARRAY_SIZE(rcu_fwds.n_launders_hist); i++)
1887-
rcu_fwds.n_launders_hist[i].n_launders = 0;
1889+
for (i = 0; i < ARRAY_SIZE(rfp->n_launders_hist); i++)
1890+
rfp->n_launders_hist[i].n_launders = 0;
18881891
cver = READ_ONCE(rcu_torture_current_version);
18891892
gps = cur_ops->get_gp_seq();
1890-
rcu_fwds.rcu_launder_gp_seq_start = gps;
1893+
rfp->rcu_launder_gp_seq_start = gps;
18911894
tick_dep_set_task(current, TICK_DEP_BIT_RCU);
18921895
while (time_before(jiffies, stopat) &&
18931896
!shutdown_time_arrived() &&
18941897
!READ_ONCE(rcu_fwd_emergency_stop) && !torture_must_stop()) {
1895-
rfcp = READ_ONCE(rcu_fwds.rcu_fwd_cb_head);
1898+
rfcp = READ_ONCE(rfp->rcu_fwd_cb_head);
18961899
rfcpn = NULL;
18971900
if (rfcp)
18981901
rfcpn = READ_ONCE(rfcp->rfc_next);
18991902
if (rfcpn) {
19001903
if (rfcp->rfc_gps >= MIN_FWD_CB_LAUNDERS &&
19011904
++n_max_gps >= MIN_FWD_CBS_LAUNDERED)
19021905
break;
1903-
rcu_fwds.rcu_fwd_cb_head = rfcpn;
1906+
rfp->rcu_fwd_cb_head = rfcpn;
19041907
n_launders++;
19051908
n_launders_sa++;
19061909
} else {
@@ -1912,6 +1915,7 @@ static void rcu_torture_fwd_prog_cr(void)
19121915
n_max_cbs++;
19131916
n_launders_sa = 0;
19141917
rfcp->rfc_gps = 0;
1918+
rfcp->rfc_rfp = rfp;
19151919
}
19161920
cur_ops->call(&rfcp->rh, rcu_torture_fwd_cb_cr);
19171921
rcu_torture_fwd_prog_cond_resched(n_launders + n_max_cbs);
@@ -1922,7 +1926,7 @@ static void rcu_torture_fwd_prog_cr(void)
19221926
}
19231927
}
19241928
stoppedat = jiffies;
1925-
n_launders_cb_snap = READ_ONCE(rcu_fwds.n_launders_cb);
1929+
n_launders_cb_snap = READ_ONCE(rfp->n_launders_cb);
19261930
cver = READ_ONCE(rcu_torture_current_version) - cver;
19271931
gps = rcutorture_seq_diff(cur_ops->get_gp_seq(), gps);
19281932
cur_ops->cb_barrier(); /* Wait for callbacks to be invoked. */
@@ -1933,12 +1937,11 @@ static void rcu_torture_fwd_prog_cr(void)
19331937
WARN_ON(n_max_gps < MIN_FWD_CBS_LAUNDERED);
19341938
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",
19351939
__func__,
1936-
stoppedat - rcu_fwds.rcu_fwd_startat,
1937-
jiffies - stoppedat,
1940+
stoppedat - rfp->rcu_fwd_startat, jiffies - stoppedat,
19381941
n_launders + n_max_cbs - n_launders_cb_snap,
19391942
n_launders, n_launders_sa,
19401943
n_max_gps, n_max_cbs, cver, gps);
1941-
rcu_torture_fwd_cb_hist();
1944+
rcu_torture_fwd_cb_hist(rfp);
19421945
}
19431946
schedule_timeout_uninterruptible(HZ); /* Let CBs drain. */
19441947
tick_dep_clear_task(current, TICK_DEP_BIT_RCU);
@@ -1955,7 +1958,7 @@ static int rcutorture_oom_notify(struct notifier_block *self,
19551958
{
19561959
WARN(1, "%s invoked upon OOM during forward-progress testing.\n",
19571960
__func__);
1958-
rcu_torture_fwd_cb_hist();
1961+
rcu_torture_fwd_cb_hist(&rcu_fwds);
19591962
rcu_fwd_progress_check(1 + (jiffies - READ_ONCE(rcu_fwds.rcu_fwd_startat)) / 2);
19601963
WRITE_ONCE(rcu_fwd_emergency_stop, true);
19611964
smp_mb(); /* Emergency stop before free and wait to avoid hangs. */
@@ -1980,6 +1983,7 @@ static struct notifier_block rcutorture_oom_nb = {
19801983
/* Carry out grace-period forward-progress testing. */
19811984
static int rcu_torture_fwd_prog(void *args)
19821985
{
1986+
struct rcu_fwd *rfp = args;
19831987
int tested = 0;
19841988
int tested_tries = 0;
19851989

@@ -1991,8 +1995,8 @@ static int rcu_torture_fwd_prog(void *args)
19911995
schedule_timeout_interruptible(fwd_progress_holdoff * HZ);
19921996
WRITE_ONCE(rcu_fwd_emergency_stop, false);
19931997
register_oom_notifier(&rcutorture_oom_nb);
1994-
rcu_torture_fwd_prog_nr(&tested, &tested_tries);
1995-
rcu_torture_fwd_prog_cr();
1998+
rcu_torture_fwd_prog_nr(rfp, &tested, &tested_tries);
1999+
rcu_torture_fwd_prog_cr(rfp);
19962000
unregister_oom_notifier(&rcutorture_oom_nb);
19972001

19982002
/* Avoid slow periods, better to test when busy. */
@@ -2027,7 +2031,7 @@ static int __init rcu_torture_fwd_prog_init(void)
20272031
if (fwd_progress_div <= 0)
20282032
fwd_progress_div = 4;
20292033
return torture_create_kthread(rcu_torture_fwd_prog,
2030-
NULL, fwd_prog_task);
2034+
&rcu_fwds, fwd_prog_task);
20312035
}
20322036

20332037
/* Callback function for RCU barrier testing. */

0 commit comments

Comments
 (0)