diff options
Diffstat (limited to 'kernel/rcutree_plugin.h')
| -rw-r--r-- | kernel/rcutree_plugin.h | 477 |
1 files changed, 452 insertions, 25 deletions
diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h index c8bff3099a89..8aafbb80b8b0 100644 --- a/kernel/rcutree_plugin.h +++ b/kernel/rcutree_plugin.h | |||
| @@ -68,6 +68,7 @@ struct rcu_state rcu_preempt_state = RCU_STATE_INITIALIZER(rcu_preempt_state); | |||
| 68 | DEFINE_PER_CPU(struct rcu_data, rcu_preempt_data); | 68 | DEFINE_PER_CPU(struct rcu_data, rcu_preempt_data); |
| 69 | static struct rcu_state *rcu_state = &rcu_preempt_state; | 69 | static struct rcu_state *rcu_state = &rcu_preempt_state; |
| 70 | 70 | ||
| 71 | static void rcu_read_unlock_special(struct task_struct *t); | ||
| 71 | static int rcu_preempted_readers_exp(struct rcu_node *rnp); | 72 | static int rcu_preempted_readers_exp(struct rcu_node *rnp); |
| 72 | 73 | ||
| 73 | /* | 74 | /* |
| @@ -147,7 +148,7 @@ static void rcu_preempt_note_context_switch(int cpu) | |||
| 147 | struct rcu_data *rdp; | 148 | struct rcu_data *rdp; |
| 148 | struct rcu_node *rnp; | 149 | struct rcu_node *rnp; |
| 149 | 150 | ||
| 150 | if (t->rcu_read_lock_nesting && | 151 | if (t->rcu_read_lock_nesting > 0 && |
| 151 | (t->rcu_read_unlock_special & RCU_READ_UNLOCK_BLOCKED) == 0) { | 152 | (t->rcu_read_unlock_special & RCU_READ_UNLOCK_BLOCKED) == 0) { |
| 152 | 153 | ||
| 153 | /* Possibly blocking in an RCU read-side critical section. */ | 154 | /* Possibly blocking in an RCU read-side critical section. */ |
| @@ -190,6 +191,14 @@ static void rcu_preempt_note_context_switch(int cpu) | |||
| 190 | rnp->gp_tasks = &t->rcu_node_entry; | 191 | rnp->gp_tasks = &t->rcu_node_entry; |
| 191 | } | 192 | } |
| 192 | raw_spin_unlock_irqrestore(&rnp->lock, flags); | 193 | raw_spin_unlock_irqrestore(&rnp->lock, flags); |
| 194 | } else if (t->rcu_read_lock_nesting < 0 && | ||
| 195 | t->rcu_read_unlock_special) { | ||
| 196 | |||
| 197 | /* | ||
| 198 | * Complete exit from RCU read-side critical section on | ||
| 199 | * behalf of preempted instance of __rcu_read_unlock(). | ||
| 200 | */ | ||
| 201 | rcu_read_unlock_special(t); | ||
| 193 | } | 202 | } |
| 194 | 203 | ||
| 195 | /* | 204 | /* |
| @@ -284,7 +293,7 @@ static struct list_head *rcu_next_node_entry(struct task_struct *t, | |||
| 284 | * notify RCU core processing or task having blocked during the RCU | 293 | * notify RCU core processing or task having blocked during the RCU |
| 285 | * read-side critical section. | 294 | * read-side critical section. |
| 286 | */ | 295 | */ |
| 287 | static void rcu_read_unlock_special(struct task_struct *t) | 296 | static noinline void rcu_read_unlock_special(struct task_struct *t) |
| 288 | { | 297 | { |
| 289 | int empty; | 298 | int empty; |
| 290 | int empty_exp; | 299 | int empty_exp; |
| @@ -309,7 +318,7 @@ static void rcu_read_unlock_special(struct task_struct *t) | |||
| 309 | } | 318 | } |
| 310 | 319 | ||
| 311 | /* Hardware IRQ handlers cannot block. */ | 320 | /* Hardware IRQ handlers cannot block. */ |
| 312 | if (in_irq()) { | 321 | if (in_irq() || in_serving_softirq()) { |
| 313 | local_irq_restore(flags); | 322 | local_irq_restore(flags); |
| 314 | return; | 323 | return; |
| 315 | } | 324 | } |
| @@ -342,6 +351,11 @@ static void rcu_read_unlock_special(struct task_struct *t) | |||
| 342 | #ifdef CONFIG_RCU_BOOST | 351 | #ifdef CONFIG_RCU_BOOST |
| 343 | if (&t->rcu_node_entry == rnp->boost_tasks) | 352 | if (&t->rcu_node_entry == rnp->boost_tasks) |
| 344 | rnp->boost_tasks = np; | 353 | rnp->boost_tasks = np; |
| 354 | /* Snapshot and clear ->rcu_boosted with rcu_node lock held. */ | ||
| 355 | if (t->rcu_boosted) { | ||
| 356 | special |= RCU_READ_UNLOCK_BOOSTED; | ||
| 357 | t->rcu_boosted = 0; | ||
| 358 | } | ||
| 345 | #endif /* #ifdef CONFIG_RCU_BOOST */ | 359 | #endif /* #ifdef CONFIG_RCU_BOOST */ |
| 346 | t->rcu_blocked_node = NULL; | 360 | t->rcu_blocked_node = NULL; |
| 347 | 361 | ||
| @@ -358,7 +372,6 @@ static void rcu_read_unlock_special(struct task_struct *t) | |||
| 358 | #ifdef CONFIG_RCU_BOOST | 372 | #ifdef CONFIG_RCU_BOOST |
| 359 | /* Unboost if we were boosted. */ | 373 | /* Unboost if we were boosted. */ |
| 360 | if (special & RCU_READ_UNLOCK_BOOSTED) { | 374 | if (special & RCU_READ_UNLOCK_BOOSTED) { |
| 361 | t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_BOOSTED; | ||
| 362 | rt_mutex_unlock(t->rcu_boost_mutex); | 375 | rt_mutex_unlock(t->rcu_boost_mutex); |
| 363 | t->rcu_boost_mutex = NULL; | 376 | t->rcu_boost_mutex = NULL; |
| 364 | } | 377 | } |
| @@ -387,13 +400,22 @@ void __rcu_read_unlock(void) | |||
| 387 | struct task_struct *t = current; | 400 | struct task_struct *t = current; |
| 388 | 401 | ||
| 389 | barrier(); /* needed if we ever invoke rcu_read_unlock in rcutree.c */ | 402 | barrier(); /* needed if we ever invoke rcu_read_unlock in rcutree.c */ |
| 390 | --t->rcu_read_lock_nesting; | 403 | if (t->rcu_read_lock_nesting != 1) |
| 391 | barrier(); /* decrement before load of ->rcu_read_unlock_special */ | 404 | --t->rcu_read_lock_nesting; |
| 392 | if (t->rcu_read_lock_nesting == 0 && | 405 | else { |
| 393 | unlikely(ACCESS_ONCE(t->rcu_read_unlock_special))) | 406 | t->rcu_read_lock_nesting = INT_MIN; |
| 394 | rcu_read_unlock_special(t); | 407 | barrier(); /* assign before ->rcu_read_unlock_special load */ |
| 408 | if (unlikely(ACCESS_ONCE(t->rcu_read_unlock_special))) | ||
| 409 | rcu_read_unlock_special(t); | ||
| 410 | barrier(); /* ->rcu_read_unlock_special load before assign */ | ||
| 411 | t->rcu_read_lock_nesting = 0; | ||
| 412 | } | ||
| 395 | #ifdef CONFIG_PROVE_LOCKING | 413 | #ifdef CONFIG_PROVE_LOCKING |
| 396 | WARN_ON_ONCE(ACCESS_ONCE(t->rcu_read_lock_nesting) < 0); | 414 | { |
| 415 | int rrln = ACCESS_ONCE(t->rcu_read_lock_nesting); | ||
| 416 | |||
| 417 | WARN_ON_ONCE(rrln < 0 && rrln > INT_MIN / 2); | ||
| 418 | } | ||
| 397 | #endif /* #ifdef CONFIG_PROVE_LOCKING */ | 419 | #endif /* #ifdef CONFIG_PROVE_LOCKING */ |
| 398 | } | 420 | } |
| 399 | EXPORT_SYMBOL_GPL(__rcu_read_unlock); | 421 | EXPORT_SYMBOL_GPL(__rcu_read_unlock); |
| @@ -589,7 +611,8 @@ static void rcu_preempt_check_callbacks(int cpu) | |||
| 589 | rcu_preempt_qs(cpu); | 611 | rcu_preempt_qs(cpu); |
| 590 | return; | 612 | return; |
| 591 | } | 613 | } |
| 592 | if (per_cpu(rcu_preempt_data, cpu).qs_pending) | 614 | if (t->rcu_read_lock_nesting > 0 && |
| 615 | per_cpu(rcu_preempt_data, cpu).qs_pending) | ||
| 593 | t->rcu_read_unlock_special |= RCU_READ_UNLOCK_NEED_QS; | 616 | t->rcu_read_unlock_special |= RCU_READ_UNLOCK_NEED_QS; |
| 594 | } | 617 | } |
| 595 | 618 | ||
| @@ -602,6 +625,15 @@ static void rcu_preempt_process_callbacks(void) | |||
| 602 | &__get_cpu_var(rcu_preempt_data)); | 625 | &__get_cpu_var(rcu_preempt_data)); |
| 603 | } | 626 | } |
| 604 | 627 | ||
| 628 | #ifdef CONFIG_RCU_BOOST | ||
| 629 | |||
| 630 | static void rcu_preempt_do_callbacks(void) | ||
| 631 | { | ||
| 632 | rcu_do_batch(&rcu_preempt_state, &__get_cpu_var(rcu_preempt_data)); | ||
| 633 | } | ||
| 634 | |||
| 635 | #endif /* #ifdef CONFIG_RCU_BOOST */ | ||
| 636 | |||
| 605 | /* | 637 | /* |
| 606 | * Queue a preemptible-RCU callback for invocation after a grace period. | 638 | * Queue a preemptible-RCU callback for invocation after a grace period. |
| 607 | */ | 639 | */ |
| @@ -686,9 +718,12 @@ static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp) | |||
| 686 | 718 | ||
| 687 | raw_spin_lock_irqsave(&rnp->lock, flags); | 719 | raw_spin_lock_irqsave(&rnp->lock, flags); |
| 688 | for (;;) { | 720 | for (;;) { |
| 689 | if (!sync_rcu_preempt_exp_done(rnp)) | 721 | if (!sync_rcu_preempt_exp_done(rnp)) { |
| 722 | raw_spin_unlock_irqrestore(&rnp->lock, flags); | ||
| 690 | break; | 723 | break; |
| 724 | } | ||
| 691 | if (rnp->parent == NULL) { | 725 | if (rnp->parent == NULL) { |
| 726 | raw_spin_unlock_irqrestore(&rnp->lock, flags); | ||
| 692 | wake_up(&sync_rcu_preempt_exp_wq); | 727 | wake_up(&sync_rcu_preempt_exp_wq); |
| 693 | break; | 728 | break; |
| 694 | } | 729 | } |
| @@ -698,7 +733,6 @@ static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp) | |||
| 698 | raw_spin_lock(&rnp->lock); /* irqs already disabled */ | 733 | raw_spin_lock(&rnp->lock); /* irqs already disabled */ |
| 699 | rnp->expmask &= ~mask; | 734 | rnp->expmask &= ~mask; |
| 700 | } | 735 | } |
| 701 | raw_spin_unlock_irqrestore(&rnp->lock, flags); | ||
| 702 | } | 736 | } |
| 703 | 737 | ||
| 704 | /* | 738 | /* |
| @@ -1165,7 +1199,7 @@ static int rcu_boost(struct rcu_node *rnp) | |||
| 1165 | t = container_of(tb, struct task_struct, rcu_node_entry); | 1199 | t = container_of(tb, struct task_struct, rcu_node_entry); |
| 1166 | rt_mutex_init_proxy_locked(&mtx, t); | 1200 | rt_mutex_init_proxy_locked(&mtx, t); |
| 1167 | t->rcu_boost_mutex = &mtx; | 1201 | t->rcu_boost_mutex = &mtx; |
| 1168 | t->rcu_read_unlock_special |= RCU_READ_UNLOCK_BOOSTED; | 1202 | t->rcu_boosted = 1; |
| 1169 | raw_spin_unlock_irqrestore(&rnp->lock, flags); | 1203 | raw_spin_unlock_irqrestore(&rnp->lock, flags); |
| 1170 | rt_mutex_lock(&mtx); /* Side effect: boosts task t's priority. */ | 1204 | rt_mutex_lock(&mtx); /* Side effect: boosts task t's priority. */ |
| 1171 | rt_mutex_unlock(&mtx); /* Keep lockdep happy. */ | 1205 | rt_mutex_unlock(&mtx); /* Keep lockdep happy. */ |
| @@ -1249,6 +1283,23 @@ static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags) | |||
| 1249 | } | 1283 | } |
| 1250 | 1284 | ||
| 1251 | /* | 1285 | /* |
| 1286 | * Wake up the per-CPU kthread to invoke RCU callbacks. | ||
| 1287 | */ | ||
| 1288 | static void invoke_rcu_callbacks_kthread(void) | ||
| 1289 | { | ||
| 1290 | unsigned long flags; | ||
| 1291 | |||
| 1292 | local_irq_save(flags); | ||
| 1293 | __this_cpu_write(rcu_cpu_has_work, 1); | ||
| 1294 | if (__this_cpu_read(rcu_cpu_kthread_task) == NULL) { | ||
| 1295 | local_irq_restore(flags); | ||
| 1296 | return; | ||
| 1297 | } | ||
| 1298 | wake_up_process(__this_cpu_read(rcu_cpu_kthread_task)); | ||
| 1299 | local_irq_restore(flags); | ||
| 1300 | } | ||
| 1301 | |||
| 1302 | /* | ||
| 1252 | * Set the affinity of the boost kthread. The CPU-hotplug locks are | 1303 | * Set the affinity of the boost kthread. The CPU-hotplug locks are |
| 1253 | * held, so no one should be messing with the existence of the boost | 1304 | * held, so no one should be messing with the existence of the boost |
| 1254 | * kthread. | 1305 | * kthread. |
| @@ -1288,6 +1339,7 @@ static int __cpuinit rcu_spawn_one_boost_kthread(struct rcu_state *rsp, | |||
| 1288 | 1339 | ||
| 1289 | if (&rcu_preempt_state != rsp) | 1340 | if (&rcu_preempt_state != rsp) |
| 1290 | return 0; | 1341 | return 0; |
| 1342 | rsp->boost = 1; | ||
| 1291 | if (rnp->boost_kthread_task != NULL) | 1343 | if (rnp->boost_kthread_task != NULL) |
| 1292 | return 0; | 1344 | return 0; |
| 1293 | t = kthread_create(rcu_boost_kthread, (void *)rnp, | 1345 | t = kthread_create(rcu_boost_kthread, (void *)rnp, |
| @@ -1299,13 +1351,372 @@ static int __cpuinit rcu_spawn_one_boost_kthread(struct rcu_state *rsp, | |||
| 1299 | raw_spin_unlock_irqrestore(&rnp->lock, flags); | 1351 | raw_spin_unlock_irqrestore(&rnp->lock, flags); |
| 1300 | sp.sched_priority = RCU_KTHREAD_PRIO; | 1352 | sp.sched_priority = RCU_KTHREAD_PRIO; |
| 1301 | sched_setscheduler_nocheck(t, SCHED_FIFO, &sp); | 1353 | sched_setscheduler_nocheck(t, SCHED_FIFO, &sp); |
| 1354 | wake_up_process(t); /* get to TASK_INTERRUPTIBLE quickly. */ | ||
| 1302 | return 0; | 1355 | return 0; |
| 1303 | } | 1356 | } |
| 1304 | 1357 | ||
| 1305 | static void __cpuinit rcu_wake_one_boost_kthread(struct rcu_node *rnp) | 1358 | #ifdef CONFIG_HOTPLUG_CPU |
| 1359 | |||
| 1360 | /* | ||
| 1361 | * Stop the RCU's per-CPU kthread when its CPU goes offline,. | ||
| 1362 | */ | ||
| 1363 | static void rcu_stop_cpu_kthread(int cpu) | ||
| 1364 | { | ||
| 1365 | struct task_struct *t; | ||
| 1366 | |||
| 1367 | /* Stop the CPU's kthread. */ | ||
| 1368 | t = per_cpu(rcu_cpu_kthread_task, cpu); | ||
| 1369 | if (t != NULL) { | ||
| 1370 | per_cpu(rcu_cpu_kthread_task, cpu) = NULL; | ||
| 1371 | kthread_stop(t); | ||
| 1372 | } | ||
| 1373 | } | ||
| 1374 | |||
| 1375 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ | ||
| 1376 | |||
| 1377 | static void rcu_kthread_do_work(void) | ||
| 1306 | { | 1378 | { |
| 1307 | if (rnp->boost_kthread_task) | 1379 | rcu_do_batch(&rcu_sched_state, &__get_cpu_var(rcu_sched_data)); |
| 1308 | wake_up_process(rnp->boost_kthread_task); | 1380 | rcu_do_batch(&rcu_bh_state, &__get_cpu_var(rcu_bh_data)); |
| 1381 | rcu_preempt_do_callbacks(); | ||
| 1382 | } | ||
| 1383 | |||
| 1384 | /* | ||
| 1385 | * Wake up the specified per-rcu_node-structure kthread. | ||
| 1386 | * Because the per-rcu_node kthreads are immortal, we don't need | ||
| 1387 | * to do anything to keep them alive. | ||
| 1388 | */ | ||
| 1389 | static void invoke_rcu_node_kthread(struct rcu_node *rnp) | ||
| 1390 | { | ||
| 1391 | struct task_struct *t; | ||
| 1392 | |||
| 1393 | t = rnp->node_kthread_task; | ||
| 1394 | if (t != NULL) | ||
| 1395 | wake_up_process(t); | ||
| 1396 | } | ||
| 1397 | |||
| 1398 | /* | ||
| 1399 | * Set the specified CPU's kthread to run RT or not, as specified by | ||
| 1400 | * the to_rt argument. The CPU-hotplug locks are held, so the task | ||
| 1401 | * is not going away. | ||
| 1402 | */ | ||
| 1403 | static void rcu_cpu_kthread_setrt(int cpu, int to_rt) | ||
| 1404 | { | ||
| 1405 | int policy; | ||
| 1406 | struct sched_param sp; | ||
| 1407 | struct task_struct *t; | ||
| 1408 | |||
| 1409 | t = per_cpu(rcu_cpu_kthread_task, cpu); | ||
| 1410 | if (t == NULL) | ||
| 1411 | return; | ||
| 1412 | if (to_rt) { | ||
| 1413 | policy = SCHED_FIFO; | ||
| 1414 | sp.sched_priority = RCU_KTHREAD_PRIO; | ||
| 1415 | } else { | ||
| 1416 | policy = SCHED_NORMAL; | ||
| 1417 | sp.sched_priority = 0; | ||
| 1418 | } | ||
| 1419 | sched_setscheduler_nocheck(t, policy, &sp); | ||
| 1420 | } | ||
| 1421 | |||
| 1422 | /* | ||
| 1423 | * Timer handler to initiate the waking up of per-CPU kthreads that | ||
| 1424 | * have yielded the CPU due to excess numbers of RCU callbacks. | ||
| 1425 | * We wake up the per-rcu_node kthread, which in turn will wake up | ||
| 1426 | * the booster kthread. | ||
| 1427 | */ | ||
| 1428 | static void rcu_cpu_kthread_timer(unsigned long arg) | ||
| 1429 | { | ||
| 1430 | struct rcu_data *rdp = per_cpu_ptr(rcu_state->rda, arg); | ||
| 1431 | struct rcu_node *rnp = rdp->mynode; | ||
| 1432 | |||
| 1433 | atomic_or(rdp->grpmask, &rnp->wakemask); | ||
| 1434 | invoke_rcu_node_kthread(rnp); | ||
| 1435 | } | ||
| 1436 | |||
| 1437 | /* | ||
| 1438 | * Drop to non-real-time priority and yield, but only after posting a | ||
| 1439 | * timer that will cause us to regain our real-time priority if we | ||
| 1440 | * remain preempted. Either way, we restore our real-time priority | ||
| 1441 | * before returning. | ||
| 1442 | */ | ||
| 1443 | static void rcu_yield(void (*f)(unsigned long), unsigned long arg) | ||
| 1444 | { | ||
| 1445 | struct sched_param sp; | ||
| 1446 | struct timer_list yield_timer; | ||
| 1447 | |||
| 1448 | setup_timer_on_stack(&yield_timer, f, arg); | ||
| 1449 | mod_timer(&yield_timer, jiffies + 2); | ||
| 1450 | sp.sched_priority = 0; | ||
| 1451 | sched_setscheduler_nocheck(current, SCHED_NORMAL, &sp); | ||
| 1452 | set_user_nice(current, 19); | ||
| 1453 | schedule(); | ||
| 1454 | sp.sched_priority = RCU_KTHREAD_PRIO; | ||
| 1455 | sched_setscheduler_nocheck(current, SCHED_FIFO, &sp); | ||
| 1456 | del_timer(&yield_timer); | ||
| 1457 | } | ||
| 1458 | |||
| 1459 | /* | ||
| 1460 | * Handle cases where the rcu_cpu_kthread() ends up on the wrong CPU. | ||
| 1461 | * This can happen while the corresponding CPU is either coming online | ||
| 1462 | * or going offline. We cannot wait until the CPU is fully online | ||
| 1463 | * before starting the kthread, because the various notifier functions | ||
| 1464 | * can wait for RCU grace periods. So we park rcu_cpu_kthread() until | ||
| 1465 | * the corresponding CPU is online. | ||
| 1466 | * | ||
| 1467 | * Return 1 if the kthread needs to stop, 0 otherwise. | ||
| 1468 | * | ||
| 1469 | * Caller must disable bh. This function can momentarily enable it. | ||
| 1470 | */ | ||
| 1471 | static int rcu_cpu_kthread_should_stop(int cpu) | ||
| 1472 | { | ||
| 1473 | while (cpu_is_offline(cpu) || | ||
| 1474 | !cpumask_equal(¤t->cpus_allowed, cpumask_of(cpu)) || | ||
| 1475 | smp_processor_id() != cpu) { | ||
| 1476 | if (kthread_should_stop()) | ||
| 1477 | return 1; | ||
| 1478 | per_cpu(rcu_cpu_kthread_status, cpu) = RCU_KTHREAD_OFFCPU; | ||
| 1479 | per_cpu(rcu_cpu_kthread_cpu, cpu) = raw_smp_processor_id(); | ||
| 1480 | local_bh_enable(); | ||
| 1481 | schedule_timeout_uninterruptible(1); | ||
| 1482 | if (!cpumask_equal(¤t->cpus_allowed, cpumask_of(cpu))) | ||
| 1483 | set_cpus_allowed_ptr(current, cpumask_of(cpu)); | ||
| 1484 | local_bh_disable(); | ||
| 1485 | } | ||
| 1486 | per_cpu(rcu_cpu_kthread_cpu, cpu) = cpu; | ||
| 1487 | return 0; | ||
| 1488 | } | ||
| 1489 | |||
| 1490 | /* | ||
| 1491 | * Per-CPU kernel thread that invokes RCU callbacks. This replaces the | ||
| 1492 | * earlier RCU softirq. | ||
| 1493 | */ | ||
| 1494 | static int rcu_cpu_kthread(void *arg) | ||
| 1495 | { | ||
| 1496 | int cpu = (int)(long)arg; | ||
| 1497 | unsigned long flags; | ||
| 1498 | int spincnt = 0; | ||
| 1499 | unsigned int *statusp = &per_cpu(rcu_cpu_kthread_status, cpu); | ||
| 1500 | char work; | ||
| 1501 | char *workp = &per_cpu(rcu_cpu_has_work, cpu); | ||
| 1502 | |||
| 1503 | for (;;) { | ||
| 1504 | *statusp = RCU_KTHREAD_WAITING; | ||
| 1505 | rcu_wait(*workp != 0 || kthread_should_stop()); | ||
| 1506 | local_bh_disable(); | ||
| 1507 | if (rcu_cpu_kthread_should_stop(cpu)) { | ||
| 1508 | local_bh_enable(); | ||
| 1509 | break; | ||
| 1510 | } | ||
| 1511 | *statusp = RCU_KTHREAD_RUNNING; | ||
| 1512 | per_cpu(rcu_cpu_kthread_loops, cpu)++; | ||
| 1513 | local_irq_save(flags); | ||
| 1514 | work = *workp; | ||
| 1515 | *workp = 0; | ||
| 1516 | local_irq_restore(flags); | ||
| 1517 | if (work) | ||
| 1518 | rcu_kthread_do_work(); | ||
| 1519 | local_bh_enable(); | ||
| 1520 | if (*workp != 0) | ||
| 1521 | spincnt++; | ||
| 1522 | else | ||
| 1523 | spincnt = 0; | ||
| 1524 | if (spincnt > 10) { | ||
| 1525 | *statusp = RCU_KTHREAD_YIELDING; | ||
| 1526 | rcu_yield(rcu_cpu_kthread_timer, (unsigned long)cpu); | ||
| 1527 | spincnt = 0; | ||
| 1528 | } | ||
| 1529 | } | ||
| 1530 | *statusp = RCU_KTHREAD_STOPPED; | ||
| 1531 | return 0; | ||
| 1532 | } | ||
| 1533 | |||
| 1534 | /* | ||
| 1535 | * Spawn a per-CPU kthread, setting up affinity and priority. | ||
| 1536 | * Because the CPU hotplug lock is held, no other CPU will be attempting | ||
| 1537 | * to manipulate rcu_cpu_kthread_task. There might be another CPU | ||
| 1538 | * attempting to access it during boot, but the locking in kthread_bind() | ||
| 1539 | * will enforce sufficient ordering. | ||
| 1540 | * | ||
| 1541 | * Please note that we cannot simply refuse to wake up the per-CPU | ||
| 1542 | * kthread because kthreads are created in TASK_UNINTERRUPTIBLE state, | ||
| 1543 | * which can result in softlockup complaints if the task ends up being | ||
| 1544 | * idle for more than a couple of minutes. | ||
| 1545 | * | ||
| 1546 | * However, please note also that we cannot bind the per-CPU kthread to its | ||
| 1547 | * CPU until that CPU is fully online. We also cannot wait until the | ||
| 1548 | * CPU is fully online before we create its per-CPU kthread, as this would | ||
| 1549 | * deadlock the system when CPU notifiers tried waiting for grace | ||
| 1550 | * periods. So we bind the per-CPU kthread to its CPU only if the CPU | ||
| 1551 | * is online. If its CPU is not yet fully online, then the code in | ||
| 1552 | * rcu_cpu_kthread() will wait until it is fully online, and then do | ||
| 1553 | * the binding. | ||
| 1554 | */ | ||
| 1555 | static int __cpuinit rcu_spawn_one_cpu_kthread(int cpu) | ||
| 1556 | { | ||
| 1557 | struct sched_param sp; | ||
| 1558 | struct task_struct *t; | ||
| 1559 | |||
| 1560 | if (!rcu_scheduler_fully_active || | ||
| 1561 | per_cpu(rcu_cpu_kthread_task, cpu) != NULL) | ||
| 1562 | return 0; | ||
| 1563 | t = kthread_create(rcu_cpu_kthread, (void *)(long)cpu, "rcuc%d", cpu); | ||
| 1564 | if (IS_ERR(t)) | ||
| 1565 | return PTR_ERR(t); | ||
| 1566 | if (cpu_online(cpu)) | ||
| 1567 | kthread_bind(t, cpu); | ||
| 1568 | per_cpu(rcu_cpu_kthread_cpu, cpu) = cpu; | ||
| 1569 | WARN_ON_ONCE(per_cpu(rcu_cpu_kthread_task, cpu) != NULL); | ||
| 1570 | sp.sched_priority = RCU_KTHREAD_PRIO; | ||
| 1571 | sched_setscheduler_nocheck(t, SCHED_FIFO, &sp); | ||
| 1572 | per_cpu(rcu_cpu_kthread_task, cpu) = t; | ||
| 1573 | wake_up_process(t); /* Get to TASK_INTERRUPTIBLE quickly. */ | ||
| 1574 | return 0; | ||
| 1575 | } | ||
| 1576 | |||
| 1577 | /* | ||
| 1578 | * Per-rcu_node kthread, which is in charge of waking up the per-CPU | ||
| 1579 | * kthreads when needed. We ignore requests to wake up kthreads | ||
| 1580 | * for offline CPUs, which is OK because force_quiescent_state() | ||
| 1581 | * takes care of this case. | ||
| 1582 | */ | ||
| 1583 | static int rcu_node_kthread(void *arg) | ||
| 1584 | { | ||
| 1585 | int cpu; | ||
| 1586 | unsigned long flags; | ||
| 1587 | unsigned long mask; | ||
| 1588 | struct rcu_node *rnp = (struct rcu_node *)arg; | ||
| 1589 | struct sched_param sp; | ||
| 1590 | struct task_struct *t; | ||
| 1591 | |||
| 1592 | for (;;) { | ||
| 1593 | rnp->node_kthread_status = RCU_KTHREAD_WAITING; | ||
| 1594 | rcu_wait(atomic_read(&rnp->wakemask) != 0); | ||
| 1595 | rnp->node_kthread_status = RCU_KTHREAD_RUNNING; | ||
| 1596 | raw_spin_lock_irqsave(&rnp->lock, flags); | ||
| 1597 | mask = atomic_xchg(&rnp->wakemask, 0); | ||
| 1598 | rcu_initiate_boost(rnp, flags); /* releases rnp->lock. */ | ||
| 1599 | for (cpu = rnp->grplo; cpu <= rnp->grphi; cpu++, mask >>= 1) { | ||
| 1600 | if ((mask & 0x1) == 0) | ||
| 1601 | continue; | ||
| 1602 | preempt_disable(); | ||
| 1603 | t = per_cpu(rcu_cpu_kthread_task, cpu); | ||
| 1604 | if (!cpu_online(cpu) || t == NULL) { | ||
| 1605 | preempt_enable(); | ||
| 1606 | continue; | ||
| 1607 | } | ||
| 1608 | per_cpu(rcu_cpu_has_work, cpu) = 1; | ||
| 1609 | sp.sched_priority = RCU_KTHREAD_PRIO; | ||
| 1610 | sched_setscheduler_nocheck(t, SCHED_FIFO, &sp); | ||
| 1611 | preempt_enable(); | ||
| 1612 | } | ||
| 1613 | } | ||
| 1614 | /* NOTREACHED */ | ||
| 1615 | rnp->node_kthread_status = RCU_KTHREAD_STOPPED; | ||
| 1616 | return 0; | ||
| 1617 | } | ||
| 1618 | |||
| 1619 | /* | ||
| 1620 | * Set the per-rcu_node kthread's affinity to cover all CPUs that are | ||
| 1621 | * served by the rcu_node in question. The CPU hotplug lock is still | ||
| 1622 | * held, so the value of rnp->qsmaskinit will be stable. | ||
| 1623 | * | ||
| 1624 | * We don't include outgoingcpu in the affinity set, use -1 if there is | ||
| 1625 | * no outgoing CPU. If there are no CPUs left in the affinity set, | ||
| 1626 | * this function allows the kthread to execute on any CPU. | ||
| 1627 | */ | ||
| 1628 | static void rcu_node_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu) | ||
| 1629 | { | ||
| 1630 | cpumask_var_t cm; | ||
| 1631 | int cpu; | ||
| 1632 | unsigned long mask = rnp->qsmaskinit; | ||
| 1633 | |||
| 1634 | if (rnp->node_kthread_task == NULL) | ||
| 1635 | return; | ||
| 1636 | if (!alloc_cpumask_var(&cm, GFP_KERNEL)) | ||
| 1637 | return; | ||
| 1638 | cpumask_clear(cm); | ||
| 1639 | for (cpu = rnp->grplo; cpu <= rnp->grphi; cpu++, mask >>= 1) | ||
| 1640 | if ((mask & 0x1) && cpu != outgoingcpu) | ||
| 1641 | cpumask_set_cpu(cpu, cm); | ||
| 1642 | if (cpumask_weight(cm) == 0) { | ||
| 1643 | cpumask_setall(cm); | ||
| 1644 | for (cpu = rnp->grplo; cpu <= rnp->grphi; cpu++) | ||
| 1645 | cpumask_clear_cpu(cpu, cm); | ||
| 1646 | WARN_ON_ONCE(cpumask_weight(cm) == 0); | ||
| 1647 | } | ||
| 1648 | set_cpus_allowed_ptr(rnp->node_kthread_task, cm); | ||
| 1649 | rcu_boost_kthread_setaffinity(rnp, cm); | ||
| 1650 | free_cpumask_var(cm); | ||
| 1651 | } | ||
| 1652 | |||
| 1653 | /* | ||
| 1654 | * Spawn a per-rcu_node kthread, setting priority and affinity. | ||
| 1655 | * Called during boot before online/offline can happen, or, if | ||
| 1656 | * during runtime, with the main CPU-hotplug locks held. So only | ||
| 1657 | * one of these can be executing at a time. | ||
| 1658 | */ | ||
| 1659 | static int __cpuinit rcu_spawn_one_node_kthread(struct rcu_state *rsp, | ||
| 1660 | struct rcu_node *rnp) | ||
| 1661 | { | ||
| 1662 | unsigned long flags; | ||
| 1663 | int rnp_index = rnp - &rsp->node[0]; | ||
| 1664 | struct sched_param sp; | ||
| 1665 | struct task_struct *t; | ||
| 1666 | |||
| 1667 | if (!rcu_scheduler_fully_active || | ||
| 1668 | rnp->qsmaskinit == 0) | ||
| 1669 | return 0; | ||
| 1670 | if (rnp->node_kthread_task == NULL) { | ||
| 1671 | t = kthread_create(rcu_node_kthread, (void *)rnp, | ||
| 1672 | "rcun%d", rnp_index); | ||
| 1673 | if (IS_ERR(t)) | ||
| 1674 | return PTR_ERR(t); | ||
| 1675 | raw_spin_lock_irqsave(&rnp->lock, flags); | ||
| 1676 | rnp->node_kthread_task = t; | ||
| 1677 | raw_spin_unlock_irqrestore(&rnp->lock, flags); | ||
| 1678 | sp.sched_priority = 99; | ||
| 1679 | sched_setscheduler_nocheck(t, SCHED_FIFO, &sp); | ||
| 1680 | wake_up_process(t); /* get to TASK_INTERRUPTIBLE quickly. */ | ||
| 1681 | } | ||
| 1682 | return rcu_spawn_one_boost_kthread(rsp, rnp, rnp_index); | ||
| 1683 | } | ||
| 1684 | |||
| 1685 | /* | ||
| 1686 | * Spawn all kthreads -- called as soon as the scheduler is running. | ||
| 1687 | */ | ||
| 1688 | static int __init rcu_spawn_kthreads(void) | ||
| 1689 | { | ||
| 1690 | int cpu; | ||
| 1691 | struct rcu_node *rnp; | ||
| 1692 | |||
| 1693 | rcu_scheduler_fully_active = 1; | ||
| 1694 | for_each_possible_cpu(cpu) { | ||
| 1695 | per_cpu(rcu_cpu_has_work, cpu) = 0; | ||
| 1696 | if (cpu_online(cpu)) | ||
| 1697 | (void)rcu_spawn_one_cpu_kthread(cpu); | ||
| 1698 | } | ||
| 1699 | rnp = rcu_get_root(rcu_state); | ||
| 1700 | (void)rcu_spawn_one_node_kthread(rcu_state, rnp); | ||
| 1701 | if (NUM_RCU_NODES > 1) { | ||
| 1702 | rcu_for_each_leaf_node(rcu_state, rnp) | ||
| 1703 | (void)rcu_spawn_one_node_kthread(rcu_state, rnp); | ||
| 1704 | } | ||
| 1705 | return 0; | ||
| 1706 | } | ||
| 1707 | early_initcall(rcu_spawn_kthreads); | ||
| 1708 | |||
| 1709 | static void __cpuinit rcu_prepare_kthreads(int cpu) | ||
| 1710 | { | ||
| 1711 | struct rcu_data *rdp = per_cpu_ptr(rcu_state->rda, cpu); | ||
| 1712 | struct rcu_node *rnp = rdp->mynode; | ||
| 1713 | |||
| 1714 | /* Fire up the incoming CPU's kthread and leaf rcu_node kthread. */ | ||
| 1715 | if (rcu_scheduler_fully_active) { | ||
| 1716 | (void)rcu_spawn_one_cpu_kthread(cpu); | ||
| 1717 | if (rnp->node_kthread_task == NULL) | ||
| 1718 | (void)rcu_spawn_one_node_kthread(rcu_state, rnp); | ||
| 1719 | } | ||
| 1309 | } | 1720 | } |
| 1310 | 1721 | ||
| 1311 | #else /* #ifdef CONFIG_RCU_BOOST */ | 1722 | #else /* #ifdef CONFIG_RCU_BOOST */ |
| @@ -1315,23 +1726,39 @@ static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags) | |||
| 1315 | raw_spin_unlock_irqrestore(&rnp->lock, flags); | 1726 | raw_spin_unlock_irqrestore(&rnp->lock, flags); |
| 1316 | } | 1727 | } |
| 1317 | 1728 | ||
| 1318 | static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, | 1729 | static void invoke_rcu_callbacks_kthread(void) |
| 1319 | cpumask_var_t cm) | ||
| 1320 | { | 1730 | { |
| 1731 | WARN_ON_ONCE(1); | ||
| 1321 | } | 1732 | } |
| 1322 | 1733 | ||
| 1323 | static void rcu_preempt_boost_start_gp(struct rcu_node *rnp) | 1734 | static void rcu_preempt_boost_start_gp(struct rcu_node *rnp) |
| 1324 | { | 1735 | { |
| 1325 | } | 1736 | } |
| 1326 | 1737 | ||
| 1327 | static int __cpuinit rcu_spawn_one_boost_kthread(struct rcu_state *rsp, | 1738 | #ifdef CONFIG_HOTPLUG_CPU |
| 1328 | struct rcu_node *rnp, | 1739 | |
| 1329 | int rnp_index) | 1740 | static void rcu_stop_cpu_kthread(int cpu) |
| 1741 | { | ||
| 1742 | } | ||
| 1743 | |||
| 1744 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ | ||
| 1745 | |||
| 1746 | static void rcu_node_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu) | ||
| 1747 | { | ||
| 1748 | } | ||
| 1749 | |||
| 1750 | static void rcu_cpu_kthread_setrt(int cpu, int to_rt) | ||
| 1751 | { | ||
| 1752 | } | ||
| 1753 | |||
| 1754 | static int __init rcu_scheduler_really_started(void) | ||
| 1330 | { | 1755 | { |
| 1756 | rcu_scheduler_fully_active = 1; | ||
| 1331 | return 0; | 1757 | return 0; |
| 1332 | } | 1758 | } |
| 1759 | early_initcall(rcu_scheduler_really_started); | ||
| 1333 | 1760 | ||
| 1334 | static void __cpuinit rcu_wake_one_boost_kthread(struct rcu_node *rnp) | 1761 | static void __cpuinit rcu_prepare_kthreads(int cpu) |
| 1335 | { | 1762 | { |
| 1336 | } | 1763 | } |
| 1337 | 1764 | ||
| @@ -1509,7 +1936,7 @@ static DEFINE_PER_CPU(unsigned long, rcu_dyntick_holdoff); | |||
| 1509 | * | 1936 | * |
| 1510 | * Because it is not legal to invoke rcu_process_callbacks() with irqs | 1937 | * Because it is not legal to invoke rcu_process_callbacks() with irqs |
| 1511 | * disabled, we do one pass of force_quiescent_state(), then do a | 1938 | * disabled, we do one pass of force_quiescent_state(), then do a |
| 1512 | * invoke_rcu_cpu_kthread() to cause rcu_process_callbacks() to be invoked | 1939 | * invoke_rcu_core() to cause rcu_process_callbacks() to be invoked |
| 1513 | * later. The per-cpu rcu_dyntick_drain variable controls the sequencing. | 1940 | * later. The per-cpu rcu_dyntick_drain variable controls the sequencing. |
| 1514 | */ | 1941 | */ |
| 1515 | int rcu_needs_cpu(int cpu) | 1942 | int rcu_needs_cpu(int cpu) |
| @@ -1560,7 +1987,7 @@ int rcu_needs_cpu(int cpu) | |||
| 1560 | 1987 | ||
| 1561 | /* If RCU callbacks are still pending, RCU still needs this CPU. */ | 1988 | /* If RCU callbacks are still pending, RCU still needs this CPU. */ |
| 1562 | if (c) | 1989 | if (c) |
| 1563 | invoke_rcu_cpu_kthread(); | 1990 | invoke_rcu_core(); |
| 1564 | return c; | 1991 | return c; |
| 1565 | } | 1992 | } |
| 1566 | 1993 | ||
