diff options
author | Chen Gang <gang.chen@asianux.com> | 2013-11-06 21:30:25 -0500 |
---|---|---|
committer | Paul E. McKenney <paulmck@linux.vnet.ibm.com> | 2013-12-12 15:34:16 -0500 |
commit | d10089508613f42b8b54cf33456a821c7cf3d442 (patch) | |
tree | 91e696e6a989ff8a21af20481ac99db40bc2e27f /kernel | |
parent | a096932f0c9c9dca9cce72f1c0fb2395df8f2dff (diff) |
rcu/torture: Dynamically allocate SRCU output buffer to avoid overflow
If the rcutorture SRCU output exceeds 4096 bytes, for example, if you
have more than about 75 CPUs, it will overflow the current statically
allocated buffer. This commit therefore replaces this static buffer
with a dynamically buffer whose size is based on the number of CPUs.
Benefits:
- Avoids both buffer overflow and output truncation.
- Handles an arbitrarily large number of CPUs.
- Straightforward implementation.
Shortcomings:
- Some memory is wasted:
1 cpu now comsumes 50 - 60 bytes, and this patch provides 200 bytes.
Therefore, for 1K CPUs, roughly 100KB of memory will be wasted.
However, the memory is freed immediately after printing, so this
wastage should not be a problem in practice.
Testing (Fedora16 2 CPUs, 2GB RAM x86_64):
- as module, with/without "torture_type=srcu".
- build-in not boot runnable, with/without "torture_type=srcu".
- build-in let boot runnable, with/without "torture_type=srcu".
Signed-off-by: Chen Gang <gang.chen@asianux.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/rcu/torture.c | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c index 69a4ec80a788..732f8ae3086a 100644 --- a/kernel/rcu/torture.c +++ b/kernel/rcu/torture.c | |||
@@ -139,8 +139,6 @@ MODULE_PARM_DESC(verbose, "Enable verbose debugging printk()s"); | |||
139 | #define VERBOSE_PRINTK_ERRSTRING(s) \ | 139 | #define VERBOSE_PRINTK_ERRSTRING(s) \ |
140 | do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0) | 140 | do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! " s "\n", torture_type); } while (0) |
141 | 141 | ||
142 | static char printk_buf[4096]; | ||
143 | |||
144 | static int nrealreaders; | 142 | static int nrealreaders; |
145 | static struct task_struct *writer_task; | 143 | static struct task_struct *writer_task; |
146 | static struct task_struct **fakewriter_tasks; | 144 | static struct task_struct **fakewriter_tasks; |
@@ -376,7 +374,7 @@ struct rcu_torture_ops { | |||
376 | void (*call)(struct rcu_head *head, void (*func)(struct rcu_head *rcu)); | 374 | void (*call)(struct rcu_head *head, void (*func)(struct rcu_head *rcu)); |
377 | void (*cb_barrier)(void); | 375 | void (*cb_barrier)(void); |
378 | void (*fqs)(void); | 376 | void (*fqs)(void); |
379 | int (*stats)(char *page); | 377 | void (*stats)(char *page); |
380 | int irq_capable; | 378 | int irq_capable; |
381 | int can_boost; | 379 | int can_boost; |
382 | const char *name; | 380 | const char *name; |
@@ -578,21 +576,19 @@ static void srcu_torture_barrier(void) | |||
578 | srcu_barrier(&srcu_ctl); | 576 | srcu_barrier(&srcu_ctl); |
579 | } | 577 | } |
580 | 578 | ||
581 | static int srcu_torture_stats(char *page) | 579 | static void srcu_torture_stats(char *page) |
582 | { | 580 | { |
583 | int cnt = 0; | ||
584 | int cpu; | 581 | int cpu; |
585 | int idx = srcu_ctl.completed & 0x1; | 582 | int idx = srcu_ctl.completed & 0x1; |
586 | 583 | ||
587 | cnt += sprintf(&page[cnt], "%s%s per-CPU(idx=%d):", | 584 | page += sprintf(page, "%s%s per-CPU(idx=%d):", |
588 | torture_type, TORTURE_FLAG, idx); | 585 | torture_type, TORTURE_FLAG, idx); |
589 | for_each_possible_cpu(cpu) { | 586 | for_each_possible_cpu(cpu) { |
590 | cnt += sprintf(&page[cnt], " %d(%lu,%lu)", cpu, | 587 | page += sprintf(page, " %d(%lu,%lu)", cpu, |
591 | per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx], | 588 | per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx], |
592 | per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]); | 589 | per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]); |
593 | } | 590 | } |
594 | cnt += sprintf(&page[cnt], "\n"); | 591 | sprintf(page, "\n"); |
595 | return cnt; | ||
596 | } | 592 | } |
597 | 593 | ||
598 | static void srcu_torture_synchronize_expedited(void) | 594 | static void srcu_torture_synchronize_expedited(void) |
@@ -1052,10 +1048,9 @@ rcu_torture_reader(void *arg) | |||
1052 | /* | 1048 | /* |
1053 | * Create an RCU-torture statistics message in the specified buffer. | 1049 | * Create an RCU-torture statistics message in the specified buffer. |
1054 | */ | 1050 | */ |
1055 | static int | 1051 | static void |
1056 | rcu_torture_printk(char *page) | 1052 | rcu_torture_printk(char *page) |
1057 | { | 1053 | { |
1058 | int cnt = 0; | ||
1059 | int cpu; | 1054 | int cpu; |
1060 | int i; | 1055 | int i; |
1061 | long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 }; | 1056 | long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 }; |
@@ -1071,8 +1066,8 @@ rcu_torture_printk(char *page) | |||
1071 | if (pipesummary[i] != 0) | 1066 | if (pipesummary[i] != 0) |
1072 | break; | 1067 | break; |
1073 | } | 1068 | } |
1074 | cnt += sprintf(&page[cnt], "%s%s ", torture_type, TORTURE_FLAG); | 1069 | page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG); |
1075 | cnt += sprintf(&page[cnt], | 1070 | page += sprintf(page, |
1076 | "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ", | 1071 | "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ", |
1077 | rcu_torture_current, | 1072 | rcu_torture_current, |
1078 | rcu_torture_current_version, | 1073 | rcu_torture_current_version, |
@@ -1080,53 +1075,52 @@ rcu_torture_printk(char *page) | |||
1080 | atomic_read(&n_rcu_torture_alloc), | 1075 | atomic_read(&n_rcu_torture_alloc), |
1081 | atomic_read(&n_rcu_torture_alloc_fail), | 1076 | atomic_read(&n_rcu_torture_alloc_fail), |
1082 | atomic_read(&n_rcu_torture_free)); | 1077 | atomic_read(&n_rcu_torture_free)); |
1083 | cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ", | 1078 | page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ", |
1084 | atomic_read(&n_rcu_torture_mberror), | 1079 | atomic_read(&n_rcu_torture_mberror), |
1085 | n_rcu_torture_boost_ktrerror, | 1080 | n_rcu_torture_boost_ktrerror, |
1086 | n_rcu_torture_boost_rterror); | 1081 | n_rcu_torture_boost_rterror); |
1087 | cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ", | 1082 | page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ", |
1088 | n_rcu_torture_boost_failure, | 1083 | n_rcu_torture_boost_failure, |
1089 | n_rcu_torture_boosts, | 1084 | n_rcu_torture_boosts, |
1090 | n_rcu_torture_timers); | 1085 | n_rcu_torture_timers); |
1091 | cnt += sprintf(&page[cnt], | 1086 | page += sprintf(page, |
1092 | "onoff: %ld/%ld:%ld/%ld %d,%d:%d,%d %lu:%lu (HZ=%d) ", | 1087 | "onoff: %ld/%ld:%ld/%ld %d,%d:%d,%d %lu:%lu (HZ=%d) ", |
1093 | n_online_successes, n_online_attempts, | 1088 | n_online_successes, n_online_attempts, |
1094 | n_offline_successes, n_offline_attempts, | 1089 | n_offline_successes, n_offline_attempts, |
1095 | min_online, max_online, | 1090 | min_online, max_online, |
1096 | min_offline, max_offline, | 1091 | min_offline, max_offline, |
1097 | sum_online, sum_offline, HZ); | 1092 | sum_online, sum_offline, HZ); |
1098 | cnt += sprintf(&page[cnt], "barrier: %ld/%ld:%ld", | 1093 | page += sprintf(page, "barrier: %ld/%ld:%ld", |
1099 | n_barrier_successes, | 1094 | n_barrier_successes, |
1100 | n_barrier_attempts, | 1095 | n_barrier_attempts, |
1101 | n_rcu_torture_barrier_error); | 1096 | n_rcu_torture_barrier_error); |
1102 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); | 1097 | page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG); |
1103 | if (atomic_read(&n_rcu_torture_mberror) != 0 || | 1098 | if (atomic_read(&n_rcu_torture_mberror) != 0 || |
1104 | n_rcu_torture_barrier_error != 0 || | 1099 | n_rcu_torture_barrier_error != 0 || |
1105 | n_rcu_torture_boost_ktrerror != 0 || | 1100 | n_rcu_torture_boost_ktrerror != 0 || |
1106 | n_rcu_torture_boost_rterror != 0 || | 1101 | n_rcu_torture_boost_rterror != 0 || |
1107 | n_rcu_torture_boost_failure != 0 || | 1102 | n_rcu_torture_boost_failure != 0 || |
1108 | i > 1) { | 1103 | i > 1) { |
1109 | cnt += sprintf(&page[cnt], "!!! "); | 1104 | page += sprintf(page, "!!! "); |
1110 | atomic_inc(&n_rcu_torture_error); | 1105 | atomic_inc(&n_rcu_torture_error); |
1111 | WARN_ON_ONCE(1); | 1106 | WARN_ON_ONCE(1); |
1112 | } | 1107 | } |
1113 | cnt += sprintf(&page[cnt], "Reader Pipe: "); | 1108 | page += sprintf(page, "Reader Pipe: "); |
1114 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) | 1109 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
1115 | cnt += sprintf(&page[cnt], " %ld", pipesummary[i]); | 1110 | page += sprintf(page, " %ld", pipesummary[i]); |
1116 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); | 1111 | page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG); |
1117 | cnt += sprintf(&page[cnt], "Reader Batch: "); | 1112 | page += sprintf(page, "Reader Batch: "); |
1118 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) | 1113 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) |
1119 | cnt += sprintf(&page[cnt], " %ld", batchsummary[i]); | 1114 | page += sprintf(page, " %ld", batchsummary[i]); |
1120 | cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG); | 1115 | page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG); |
1121 | cnt += sprintf(&page[cnt], "Free-Block Circulation: "); | 1116 | page += sprintf(page, "Free-Block Circulation: "); |
1122 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { | 1117 | for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { |
1123 | cnt += sprintf(&page[cnt], " %d", | 1118 | page += sprintf(page, " %d", |
1124 | atomic_read(&rcu_torture_wcount[i])); | 1119 | atomic_read(&rcu_torture_wcount[i])); |
1125 | } | 1120 | } |
1126 | cnt += sprintf(&page[cnt], "\n"); | 1121 | page += sprintf(page, "\n"); |
1127 | if (cur_ops->stats) | 1122 | if (cur_ops->stats) |
1128 | cnt += cur_ops->stats(&page[cnt]); | 1123 | cur_ops->stats(page); |
1129 | return cnt; | ||
1130 | } | 1124 | } |
1131 | 1125 | ||
1132 | /* | 1126 | /* |
@@ -1140,10 +1134,17 @@ rcu_torture_printk(char *page) | |||
1140 | static void | 1134 | static void |
1141 | rcu_torture_stats_print(void) | 1135 | rcu_torture_stats_print(void) |
1142 | { | 1136 | { |
1143 | int cnt; | 1137 | int size = nr_cpu_ids * 200 + 8192; |
1138 | char *buf; | ||
1144 | 1139 | ||
1145 | cnt = rcu_torture_printk(printk_buf); | 1140 | buf = kmalloc(size, GFP_KERNEL); |
1146 | pr_alert("%s", printk_buf); | 1141 | if (!buf) { |
1142 | pr_err("rcu-torture: Out of memory, need: %d", size); | ||
1143 | return; | ||
1144 | } | ||
1145 | rcu_torture_printk(buf); | ||
1146 | pr_alert("%s", buf); | ||
1147 | kfree(buf); | ||
1147 | } | 1148 | } |
1148 | 1149 | ||
1149 | /* | 1150 | /* |