Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rcu/nocb: Consolidate rcu_nocb_cpu_offload/deoffload functions

The rcu_nocb_cpu_offload() and rcu_nocb_cpu_deoffload() functions are
nearly duplicates.

Therefore, extract the common logic into rcu_nocb_cpu_toggle_offload()
which takes an 'offload' boolean, and make both exported functions
simple wrappers.

This eliminates a bunch of duplicate code at the call sites, namely
mutex locking, CPU hotplug locking and CPU online checks.

Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>

+35 -35
+35 -35
kernel/rcu/tree_nocb.h
··· 1081 1081 return 0; 1082 1082 } 1083 1083 1084 - int rcu_nocb_cpu_deoffload(int cpu) 1085 - { 1086 - struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu); 1087 - int ret = 0; 1088 - 1089 - cpus_read_lock(); 1090 - mutex_lock(&rcu_state.nocb_mutex); 1091 - if (rcu_rdp_is_offloaded(rdp)) { 1092 - if (!cpu_online(cpu)) { 1093 - ret = rcu_nocb_rdp_deoffload(rdp); 1094 - if (!ret) 1095 - cpumask_clear_cpu(cpu, rcu_nocb_mask); 1096 - } else { 1097 - pr_info("NOCB: Cannot CB-deoffload online CPU %d\n", rdp->cpu); 1098 - ret = -EINVAL; 1099 - } 1100 - } 1101 - mutex_unlock(&rcu_state.nocb_mutex); 1102 - cpus_read_unlock(); 1103 - 1104 - return ret; 1105 - } 1106 - EXPORT_SYMBOL_GPL(rcu_nocb_cpu_deoffload); 1107 - 1108 1084 static bool rcu_nocb_rdp_offload_wait_cond(struct rcu_data *rdp) 1109 1085 { 1110 1086 unsigned long flags; ··· 1125 1149 return 0; 1126 1150 } 1127 1151 1128 - int rcu_nocb_cpu_offload(int cpu) 1152 + /* Common helper for CPU offload/deoffload operations. */ 1153 + static int rcu_nocb_cpu_toggle_offload(int cpu, bool offload) 1129 1154 { 1130 1155 struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu); 1131 1156 int ret = 0; 1132 1157 1133 1158 cpus_read_lock(); 1134 1159 mutex_lock(&rcu_state.nocb_mutex); 1135 - if (!rcu_rdp_is_offloaded(rdp)) { 1136 - if (!cpu_online(cpu)) { 1137 - ret = rcu_nocb_rdp_offload(rdp); 1138 - if (!ret) 1139 - cpumask_set_cpu(cpu, rcu_nocb_mask); 1140 - } else { 1141 - pr_info("NOCB: Cannot CB-offload online CPU %d\n", rdp->cpu); 1142 - ret = -EINVAL; 1143 - } 1160 + 1161 + /* Already in desired state, nothing to do. */ 1162 + if (rcu_rdp_is_offloaded(rdp) == offload) 1163 + goto out_unlock; 1164 + 1165 + if (cpu_online(cpu)) { 1166 + pr_info("NOCB: Cannot CB-%soffload online CPU %d\n", 1167 + offload ? "" : "de", rdp->cpu); 1168 + ret = -EINVAL; 1169 + goto out_unlock; 1144 1170 } 1171 + 1172 + if (offload) { 1173 + ret = rcu_nocb_rdp_offload(rdp); 1174 + if (!ret) 1175 + cpumask_set_cpu(cpu, rcu_nocb_mask); 1176 + } else { 1177 + ret = rcu_nocb_rdp_deoffload(rdp); 1178 + if (!ret) 1179 + cpumask_clear_cpu(cpu, rcu_nocb_mask); 1180 + } 1181 + 1182 + out_unlock: 1145 1183 mutex_unlock(&rcu_state.nocb_mutex); 1146 1184 cpus_read_unlock(); 1147 - 1148 1185 return ret; 1186 + } 1187 + 1188 + int rcu_nocb_cpu_deoffload(int cpu) 1189 + { 1190 + return rcu_nocb_cpu_toggle_offload(cpu, false /* de-offload */); 1191 + } 1192 + EXPORT_SYMBOL_GPL(rcu_nocb_cpu_deoffload); 1193 + 1194 + int rcu_nocb_cpu_offload(int cpu) 1195 + { 1196 + return rcu_nocb_cpu_toggle_offload(cpu, true /* offload */); 1149 1197 } 1150 1198 EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload); 1151 1199