diff options
Diffstat (limited to 'kernel')
71 files changed, 6001 insertions, 5168 deletions
diff --git a/kernel/Makefile b/kernel/Makefile index 2093a691f1c2..b833bd5cc127 100644 --- a/kernel/Makefile +++ b/kernel/Makefile | |||
| @@ -80,11 +80,9 @@ obj-$(CONFIG_DETECT_HUNG_TASK) += hung_task.o | |||
| 80 | obj-$(CONFIG_GENERIC_HARDIRQS) += irq/ | 80 | obj-$(CONFIG_GENERIC_HARDIRQS) += irq/ |
| 81 | obj-$(CONFIG_SECCOMP) += seccomp.o | 81 | obj-$(CONFIG_SECCOMP) += seccomp.o |
| 82 | obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o | 82 | obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o |
| 83 | obj-$(CONFIG_CLASSIC_RCU) += rcuclassic.o | ||
| 84 | obj-$(CONFIG_TREE_RCU) += rcutree.o | 83 | obj-$(CONFIG_TREE_RCU) += rcutree.o |
| 85 | obj-$(CONFIG_PREEMPT_RCU) += rcupreempt.o | 84 | obj-$(CONFIG_TREE_PREEMPT_RCU) += rcutree.o |
| 86 | obj-$(CONFIG_TREE_RCU_TRACE) += rcutree_trace.o | 85 | obj-$(CONFIG_TREE_RCU_TRACE) += rcutree_trace.o |
| 87 | obj-$(CONFIG_PREEMPT_RCU_TRACE) += rcupreempt_trace.o | ||
| 88 | obj-$(CONFIG_RELAY) += relay.o | 86 | obj-$(CONFIG_RELAY) += relay.o |
| 89 | obj-$(CONFIG_SYSCTL) += utsname_sysctl.o | 87 | obj-$(CONFIG_SYSCTL) += utsname_sysctl.o |
| 90 | obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o | 88 | obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o |
diff --git a/kernel/acct.c b/kernel/acct.c index 9f3391090b3e..9a4715a2f6bf 100644 --- a/kernel/acct.c +++ b/kernel/acct.c | |||
| @@ -491,13 +491,17 @@ static void do_acct_process(struct bsd_acct_struct *acct, | |||
| 491 | u64 run_time; | 491 | u64 run_time; |
| 492 | struct timespec uptime; | 492 | struct timespec uptime; |
| 493 | struct tty_struct *tty; | 493 | struct tty_struct *tty; |
| 494 | const struct cred *orig_cred; | ||
| 495 | |||
| 496 | /* Perform file operations on behalf of whoever enabled accounting */ | ||
| 497 | orig_cred = override_creds(file->f_cred); | ||
| 494 | 498 | ||
| 495 | /* | 499 | /* |
| 496 | * First check to see if there is enough free_space to continue | 500 | * First check to see if there is enough free_space to continue |
| 497 | * the process accounting system. | 501 | * the process accounting system. |
| 498 | */ | 502 | */ |
| 499 | if (!check_free_space(acct, file)) | 503 | if (!check_free_space(acct, file)) |
| 500 | return; | 504 | goto out; |
| 501 | 505 | ||
| 502 | /* | 506 | /* |
| 503 | * Fill the accounting struct with the needed info as recorded | 507 | * Fill the accounting struct with the needed info as recorded |
| @@ -578,6 +582,8 @@ static void do_acct_process(struct bsd_acct_struct *acct, | |||
| 578 | sizeof(acct_t), &file->f_pos); | 582 | sizeof(acct_t), &file->f_pos); |
| 579 | current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim; | 583 | current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim; |
| 580 | set_fs(fs); | 584 | set_fs(fs); |
| 585 | out: | ||
| 586 | revert_creds(orig_cred); | ||
| 581 | } | 587 | } |
| 582 | 588 | ||
| 583 | /** | 589 | /** |
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index b6eadfe30e7b..c7ece8f027f2 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
| @@ -600,6 +600,7 @@ static struct inode_operations cgroup_dir_inode_operations; | |||
| 600 | static struct file_operations proc_cgroupstats_operations; | 600 | static struct file_operations proc_cgroupstats_operations; |
| 601 | 601 | ||
| 602 | static struct backing_dev_info cgroup_backing_dev_info = { | 602 | static struct backing_dev_info cgroup_backing_dev_info = { |
| 603 | .name = "cgroup", | ||
| 603 | .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK, | 604 | .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK, |
| 604 | }; | 605 | }; |
| 605 | 606 | ||
diff --git a/kernel/cred.c b/kernel/cred.c index 1bb4d7e5d616..006fcab009d5 100644 --- a/kernel/cred.c +++ b/kernel/cred.c | |||
| @@ -18,6 +18,18 @@ | |||
| 18 | #include <linux/cn_proc.h> | 18 | #include <linux/cn_proc.h> |
| 19 | #include "cred-internals.h" | 19 | #include "cred-internals.h" |
| 20 | 20 | ||
| 21 | #if 0 | ||
| 22 | #define kdebug(FMT, ...) \ | ||
| 23 | printk("[%-5.5s%5u] "FMT"\n", current->comm, current->pid ,##__VA_ARGS__) | ||
| 24 | #else | ||
| 25 | static inline __attribute__((format(printf, 1, 2))) | ||
| 26 | void no_printk(const char *fmt, ...) | ||
| 27 | { | ||
| 28 | } | ||
| 29 | #define kdebug(FMT, ...) \ | ||
| 30 | no_printk("[%-5.5s%5u] "FMT"\n", current->comm, current->pid ,##__VA_ARGS__) | ||
| 31 | #endif | ||
| 32 | |||
| 21 | static struct kmem_cache *cred_jar; | 33 | static struct kmem_cache *cred_jar; |
| 22 | 34 | ||
| 23 | /* | 35 | /* |
| @@ -36,6 +48,10 @@ static struct thread_group_cred init_tgcred = { | |||
| 36 | */ | 48 | */ |
| 37 | struct cred init_cred = { | 49 | struct cred init_cred = { |
| 38 | .usage = ATOMIC_INIT(4), | 50 | .usage = ATOMIC_INIT(4), |
| 51 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 52 | .subscribers = ATOMIC_INIT(2), | ||
| 53 | .magic = CRED_MAGIC, | ||
| 54 | #endif | ||
| 39 | .securebits = SECUREBITS_DEFAULT, | 55 | .securebits = SECUREBITS_DEFAULT, |
| 40 | .cap_inheritable = CAP_INIT_INH_SET, | 56 | .cap_inheritable = CAP_INIT_INH_SET, |
| 41 | .cap_permitted = CAP_FULL_SET, | 57 | .cap_permitted = CAP_FULL_SET, |
| @@ -48,6 +64,31 @@ struct cred init_cred = { | |||
| 48 | #endif | 64 | #endif |
| 49 | }; | 65 | }; |
| 50 | 66 | ||
| 67 | static inline void set_cred_subscribers(struct cred *cred, int n) | ||
| 68 | { | ||
| 69 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 70 | atomic_set(&cred->subscribers, n); | ||
| 71 | #endif | ||
| 72 | } | ||
| 73 | |||
| 74 | static inline int read_cred_subscribers(const struct cred *cred) | ||
| 75 | { | ||
| 76 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 77 | return atomic_read(&cred->subscribers); | ||
| 78 | #else | ||
| 79 | return 0; | ||
| 80 | #endif | ||
| 81 | } | ||
| 82 | |||
| 83 | static inline void alter_cred_subscribers(const struct cred *_cred, int n) | ||
| 84 | { | ||
| 85 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 86 | struct cred *cred = (struct cred *) _cred; | ||
| 87 | |||
| 88 | atomic_add(n, &cred->subscribers); | ||
| 89 | #endif | ||
| 90 | } | ||
| 91 | |||
| 51 | /* | 92 | /* |
| 52 | * Dispose of the shared task group credentials | 93 | * Dispose of the shared task group credentials |
| 53 | */ | 94 | */ |
| @@ -85,9 +126,22 @@ static void put_cred_rcu(struct rcu_head *rcu) | |||
| 85 | { | 126 | { |
| 86 | struct cred *cred = container_of(rcu, struct cred, rcu); | 127 | struct cred *cred = container_of(rcu, struct cred, rcu); |
| 87 | 128 | ||
| 129 | kdebug("put_cred_rcu(%p)", cred); | ||
| 130 | |||
| 131 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 132 | if (cred->magic != CRED_MAGIC_DEAD || | ||
| 133 | atomic_read(&cred->usage) != 0 || | ||
| 134 | read_cred_subscribers(cred) != 0) | ||
| 135 | panic("CRED: put_cred_rcu() sees %p with" | ||
| 136 | " mag %x, put %p, usage %d, subscr %d\n", | ||
| 137 | cred, cred->magic, cred->put_addr, | ||
| 138 | atomic_read(&cred->usage), | ||
| 139 | read_cred_subscribers(cred)); | ||
| 140 | #else | ||
| 88 | if (atomic_read(&cred->usage) != 0) | 141 | if (atomic_read(&cred->usage) != 0) |
| 89 | panic("CRED: put_cred_rcu() sees %p with usage %d\n", | 142 | panic("CRED: put_cred_rcu() sees %p with usage %d\n", |
| 90 | cred, atomic_read(&cred->usage)); | 143 | cred, atomic_read(&cred->usage)); |
| 144 | #endif | ||
| 91 | 145 | ||
| 92 | security_cred_free(cred); | 146 | security_cred_free(cred); |
| 93 | key_put(cred->thread_keyring); | 147 | key_put(cred->thread_keyring); |
| @@ -106,12 +160,90 @@ static void put_cred_rcu(struct rcu_head *rcu) | |||
| 106 | */ | 160 | */ |
| 107 | void __put_cred(struct cred *cred) | 161 | void __put_cred(struct cred *cred) |
| 108 | { | 162 | { |
| 163 | kdebug("__put_cred(%p{%d,%d})", cred, | ||
| 164 | atomic_read(&cred->usage), | ||
| 165 | read_cred_subscribers(cred)); | ||
| 166 | |||
| 109 | BUG_ON(atomic_read(&cred->usage) != 0); | 167 | BUG_ON(atomic_read(&cred->usage) != 0); |
| 168 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 169 | BUG_ON(read_cred_subscribers(cred) != 0); | ||
| 170 | cred->magic = CRED_MAGIC_DEAD; | ||
| 171 | cred->put_addr = __builtin_return_address(0); | ||
| 172 | #endif | ||
| 173 | BUG_ON(cred == current->cred); | ||
| 174 | BUG_ON(cred == current->real_cred); | ||
| 110 | 175 | ||
| 111 | call_rcu(&cred->rcu, put_cred_rcu); | 176 | call_rcu(&cred->rcu, put_cred_rcu); |
| 112 | } | 177 | } |
| 113 | EXPORT_SYMBOL(__put_cred); | 178 | EXPORT_SYMBOL(__put_cred); |
| 114 | 179 | ||
| 180 | /* | ||
| 181 | * Clean up a task's credentials when it exits | ||
| 182 | */ | ||
| 183 | void exit_creds(struct task_struct *tsk) | ||
| 184 | { | ||
| 185 | struct cred *cred; | ||
| 186 | |||
| 187 | kdebug("exit_creds(%u,%p,%p,{%d,%d})", tsk->pid, tsk->real_cred, tsk->cred, | ||
| 188 | atomic_read(&tsk->cred->usage), | ||
| 189 | read_cred_subscribers(tsk->cred)); | ||
| 190 | |||
| 191 | cred = (struct cred *) tsk->real_cred; | ||
| 192 | tsk->real_cred = NULL; | ||
| 193 | validate_creds(cred); | ||
| 194 | alter_cred_subscribers(cred, -1); | ||
| 195 | put_cred(cred); | ||
| 196 | |||
| 197 | cred = (struct cred *) tsk->cred; | ||
| 198 | tsk->cred = NULL; | ||
| 199 | validate_creds(cred); | ||
| 200 | alter_cred_subscribers(cred, -1); | ||
| 201 | put_cred(cred); | ||
| 202 | |||
| 203 | cred = (struct cred *) tsk->replacement_session_keyring; | ||
| 204 | if (cred) { | ||
| 205 | tsk->replacement_session_keyring = NULL; | ||
| 206 | validate_creds(cred); | ||
| 207 | put_cred(cred); | ||
| 208 | } | ||
| 209 | } | ||
| 210 | |||
| 211 | /* | ||
| 212 | * Allocate blank credentials, such that the credentials can be filled in at a | ||
| 213 | * later date without risk of ENOMEM. | ||
| 214 | */ | ||
| 215 | struct cred *cred_alloc_blank(void) | ||
| 216 | { | ||
| 217 | struct cred *new; | ||
| 218 | |||
| 219 | new = kmem_cache_zalloc(cred_jar, GFP_KERNEL); | ||
| 220 | if (!new) | ||
| 221 | return NULL; | ||
| 222 | |||
| 223 | #ifdef CONFIG_KEYS | ||
| 224 | new->tgcred = kzalloc(sizeof(*new->tgcred), GFP_KERNEL); | ||
| 225 | if (!new->tgcred) { | ||
| 226 | kfree(new); | ||
| 227 | return NULL; | ||
| 228 | } | ||
| 229 | atomic_set(&new->tgcred->usage, 1); | ||
| 230 | #endif | ||
| 231 | |||
| 232 | atomic_set(&new->usage, 1); | ||
| 233 | |||
| 234 | if (security_cred_alloc_blank(new, GFP_KERNEL) < 0) | ||
| 235 | goto error; | ||
| 236 | |||
| 237 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 238 | new->magic = CRED_MAGIC; | ||
| 239 | #endif | ||
| 240 | return new; | ||
| 241 | |||
| 242 | error: | ||
| 243 | abort_creds(new); | ||
| 244 | return NULL; | ||
| 245 | } | ||
| 246 | |||
| 115 | /** | 247 | /** |
| 116 | * prepare_creds - Prepare a new set of credentials for modification | 248 | * prepare_creds - Prepare a new set of credentials for modification |
| 117 | * | 249 | * |
| @@ -132,16 +264,19 @@ struct cred *prepare_creds(void) | |||
| 132 | const struct cred *old; | 264 | const struct cred *old; |
| 133 | struct cred *new; | 265 | struct cred *new; |
| 134 | 266 | ||
| 135 | BUG_ON(atomic_read(&task->real_cred->usage) < 1); | 267 | validate_process_creds(); |
| 136 | 268 | ||
| 137 | new = kmem_cache_alloc(cred_jar, GFP_KERNEL); | 269 | new = kmem_cache_alloc(cred_jar, GFP_KERNEL); |
| 138 | if (!new) | 270 | if (!new) |
| 139 | return NULL; | 271 | return NULL; |
| 140 | 272 | ||
| 273 | kdebug("prepare_creds() alloc %p", new); | ||
| 274 | |||
| 141 | old = task->cred; | 275 | old = task->cred; |
| 142 | memcpy(new, old, sizeof(struct cred)); | 276 | memcpy(new, old, sizeof(struct cred)); |
| 143 | 277 | ||
| 144 | atomic_set(&new->usage, 1); | 278 | atomic_set(&new->usage, 1); |
| 279 | set_cred_subscribers(new, 0); | ||
| 145 | get_group_info(new->group_info); | 280 | get_group_info(new->group_info); |
| 146 | get_uid(new->user); | 281 | get_uid(new->user); |
| 147 | 282 | ||
| @@ -157,6 +292,7 @@ struct cred *prepare_creds(void) | |||
| 157 | 292 | ||
| 158 | if (security_prepare_creds(new, old, GFP_KERNEL) < 0) | 293 | if (security_prepare_creds(new, old, GFP_KERNEL) < 0) |
| 159 | goto error; | 294 | goto error; |
| 295 | validate_creds(new); | ||
| 160 | return new; | 296 | return new; |
| 161 | 297 | ||
| 162 | error: | 298 | error: |
| @@ -229,9 +365,12 @@ struct cred *prepare_usermodehelper_creds(void) | |||
| 229 | if (!new) | 365 | if (!new) |
| 230 | return NULL; | 366 | return NULL; |
| 231 | 367 | ||
| 368 | kdebug("prepare_usermodehelper_creds() alloc %p", new); | ||
| 369 | |||
| 232 | memcpy(new, &init_cred, sizeof(struct cred)); | 370 | memcpy(new, &init_cred, sizeof(struct cred)); |
| 233 | 371 | ||
| 234 | atomic_set(&new->usage, 1); | 372 | atomic_set(&new->usage, 1); |
| 373 | set_cred_subscribers(new, 0); | ||
| 235 | get_group_info(new->group_info); | 374 | get_group_info(new->group_info); |
| 236 | get_uid(new->user); | 375 | get_uid(new->user); |
| 237 | 376 | ||
| @@ -250,6 +389,7 @@ struct cred *prepare_usermodehelper_creds(void) | |||
| 250 | #endif | 389 | #endif |
| 251 | if (security_prepare_creds(new, &init_cred, GFP_ATOMIC) < 0) | 390 | if (security_prepare_creds(new, &init_cred, GFP_ATOMIC) < 0) |
| 252 | goto error; | 391 | goto error; |
| 392 | validate_creds(new); | ||
| 253 | 393 | ||
| 254 | BUG_ON(atomic_read(&new->usage) != 1); | 394 | BUG_ON(atomic_read(&new->usage) != 1); |
| 255 | return new; | 395 | return new; |
| @@ -286,6 +426,10 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags) | |||
| 286 | ) { | 426 | ) { |
| 287 | p->real_cred = get_cred(p->cred); | 427 | p->real_cred = get_cred(p->cred); |
| 288 | get_cred(p->cred); | 428 | get_cred(p->cred); |
| 429 | alter_cred_subscribers(p->cred, 2); | ||
| 430 | kdebug("share_creds(%p{%d,%d})", | ||
| 431 | p->cred, atomic_read(&p->cred->usage), | ||
| 432 | read_cred_subscribers(p->cred)); | ||
| 289 | atomic_inc(&p->cred->user->processes); | 433 | atomic_inc(&p->cred->user->processes); |
| 290 | return 0; | 434 | return 0; |
| 291 | } | 435 | } |
| @@ -331,6 +475,8 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags) | |||
| 331 | 475 | ||
| 332 | atomic_inc(&new->user->processes); | 476 | atomic_inc(&new->user->processes); |
| 333 | p->cred = p->real_cred = get_cred(new); | 477 | p->cred = p->real_cred = get_cred(new); |
| 478 | alter_cred_subscribers(new, 2); | ||
| 479 | validate_creds(new); | ||
| 334 | return 0; | 480 | return 0; |
| 335 | 481 | ||
| 336 | error_put: | 482 | error_put: |
| @@ -355,13 +501,20 @@ error_put: | |||
| 355 | int commit_creds(struct cred *new) | 501 | int commit_creds(struct cred *new) |
| 356 | { | 502 | { |
| 357 | struct task_struct *task = current; | 503 | struct task_struct *task = current; |
| 358 | const struct cred *old; | 504 | const struct cred *old = task->real_cred; |
| 359 | 505 | ||
| 360 | BUG_ON(task->cred != task->real_cred); | 506 | kdebug("commit_creds(%p{%d,%d})", new, |
| 361 | BUG_ON(atomic_read(&task->real_cred->usage) < 2); | 507 | atomic_read(&new->usage), |
| 508 | read_cred_subscribers(new)); | ||
| 509 | |||
| 510 | BUG_ON(task->cred != old); | ||
| 511 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 512 | BUG_ON(read_cred_subscribers(old) < 2); | ||
| 513 | validate_creds(old); | ||
| 514 | validate_creds(new); | ||
| 515 | #endif | ||
| 362 | BUG_ON(atomic_read(&new->usage) < 1); | 516 | BUG_ON(atomic_read(&new->usage) < 1); |
| 363 | 517 | ||
| 364 | old = task->real_cred; | ||
| 365 | security_commit_creds(new, old); | 518 | security_commit_creds(new, old); |
| 366 | 519 | ||
| 367 | get_cred(new); /* we will require a ref for the subj creds too */ | 520 | get_cred(new); /* we will require a ref for the subj creds too */ |
| @@ -390,12 +543,14 @@ int commit_creds(struct cred *new) | |||
| 390 | * cheaply with the new uid cache, so if it matters | 543 | * cheaply with the new uid cache, so if it matters |
| 391 | * we should be checking for it. -DaveM | 544 | * we should be checking for it. -DaveM |
| 392 | */ | 545 | */ |
| 546 | alter_cred_subscribers(new, 2); | ||
| 393 | if (new->user != old->user) | 547 | if (new->user != old->user) |
| 394 | atomic_inc(&new->user->processes); | 548 | atomic_inc(&new->user->processes); |
| 395 | rcu_assign_pointer(task->real_cred, new); | 549 | rcu_assign_pointer(task->real_cred, new); |
| 396 | rcu_assign_pointer(task->cred, new); | 550 | rcu_assign_pointer(task->cred, new); |
| 397 | if (new->user != old->user) | 551 | if (new->user != old->user) |
| 398 | atomic_dec(&old->user->processes); | 552 | atomic_dec(&old->user->processes); |
| 553 | alter_cred_subscribers(old, -2); | ||
| 399 | 554 | ||
| 400 | sched_switch_user(task); | 555 | sched_switch_user(task); |
| 401 | 556 | ||
| @@ -428,6 +583,13 @@ EXPORT_SYMBOL(commit_creds); | |||
| 428 | */ | 583 | */ |
| 429 | void abort_creds(struct cred *new) | 584 | void abort_creds(struct cred *new) |
| 430 | { | 585 | { |
| 586 | kdebug("abort_creds(%p{%d,%d})", new, | ||
| 587 | atomic_read(&new->usage), | ||
| 588 | read_cred_subscribers(new)); | ||
| 589 | |||
| 590 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 591 | BUG_ON(read_cred_subscribers(new) != 0); | ||
| 592 | #endif | ||
| 431 | BUG_ON(atomic_read(&new->usage) < 1); | 593 | BUG_ON(atomic_read(&new->usage) < 1); |
| 432 | put_cred(new); | 594 | put_cred(new); |
| 433 | } | 595 | } |
| @@ -444,7 +606,20 @@ const struct cred *override_creds(const struct cred *new) | |||
| 444 | { | 606 | { |
| 445 | const struct cred *old = current->cred; | 607 | const struct cred *old = current->cred; |
| 446 | 608 | ||
| 447 | rcu_assign_pointer(current->cred, get_cred(new)); | 609 | kdebug("override_creds(%p{%d,%d})", new, |
| 610 | atomic_read(&new->usage), | ||
| 611 | read_cred_subscribers(new)); | ||
| 612 | |||
| 613 | validate_creds(old); | ||
| 614 | validate_creds(new); | ||
| 615 | get_cred(new); | ||
| 616 | alter_cred_subscribers(new, 1); | ||
| 617 | rcu_assign_pointer(current->cred, new); | ||
| 618 | alter_cred_subscribers(old, -1); | ||
| 619 | |||
| 620 | kdebug("override_creds() = %p{%d,%d}", old, | ||
| 621 | atomic_read(&old->usage), | ||
| 622 | read_cred_subscribers(old)); | ||
| 448 | return old; | 623 | return old; |
| 449 | } | 624 | } |
| 450 | EXPORT_SYMBOL(override_creds); | 625 | EXPORT_SYMBOL(override_creds); |
| @@ -460,7 +635,15 @@ void revert_creds(const struct cred *old) | |||
| 460 | { | 635 | { |
| 461 | const struct cred *override = current->cred; | 636 | const struct cred *override = current->cred; |
| 462 | 637 | ||
| 638 | kdebug("revert_creds(%p{%d,%d})", old, | ||
| 639 | atomic_read(&old->usage), | ||
| 640 | read_cred_subscribers(old)); | ||
| 641 | |||
| 642 | validate_creds(old); | ||
| 643 | validate_creds(override); | ||
| 644 | alter_cred_subscribers(old, 1); | ||
| 463 | rcu_assign_pointer(current->cred, old); | 645 | rcu_assign_pointer(current->cred, old); |
| 646 | alter_cred_subscribers(override, -1); | ||
| 464 | put_cred(override); | 647 | put_cred(override); |
| 465 | } | 648 | } |
| 466 | EXPORT_SYMBOL(revert_creds); | 649 | EXPORT_SYMBOL(revert_creds); |
| @@ -502,11 +685,15 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon) | |||
| 502 | if (!new) | 685 | if (!new) |
| 503 | return NULL; | 686 | return NULL; |
| 504 | 687 | ||
| 688 | kdebug("prepare_kernel_cred() alloc %p", new); | ||
| 689 | |||
| 505 | if (daemon) | 690 | if (daemon) |
| 506 | old = get_task_cred(daemon); | 691 | old = get_task_cred(daemon); |
| 507 | else | 692 | else |
| 508 | old = get_cred(&init_cred); | 693 | old = get_cred(&init_cred); |
| 509 | 694 | ||
| 695 | validate_creds(old); | ||
| 696 | |||
| 510 | *new = *old; | 697 | *new = *old; |
| 511 | get_uid(new->user); | 698 | get_uid(new->user); |
| 512 | get_group_info(new->group_info); | 699 | get_group_info(new->group_info); |
| @@ -526,7 +713,9 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon) | |||
| 526 | goto error; | 713 | goto error; |
| 527 | 714 | ||
| 528 | atomic_set(&new->usage, 1); | 715 | atomic_set(&new->usage, 1); |
| 716 | set_cred_subscribers(new, 0); | ||
| 529 | put_cred(old); | 717 | put_cred(old); |
| 718 | validate_creds(new); | ||
| 530 | return new; | 719 | return new; |
| 531 | 720 | ||
| 532 | error: | 721 | error: |
| @@ -589,3 +778,95 @@ int set_create_files_as(struct cred *new, struct inode *inode) | |||
| 589 | return security_kernel_create_files_as(new, inode); | 778 | return security_kernel_create_files_as(new, inode); |
| 590 | } | 779 | } |
| 591 | EXPORT_SYMBOL(set_create_files_as); | 780 | EXPORT_SYMBOL(set_create_files_as); |
| 781 | |||
| 782 | #ifdef CONFIG_DEBUG_CREDENTIALS | ||
| 783 | |||
| 784 | /* | ||
| 785 | * dump invalid credentials | ||
| 786 | */ | ||
| 787 | static void dump_invalid_creds(const struct cred *cred, const char *label, | ||
| 788 | const struct task_struct *tsk) | ||
| 789 | { | ||
| 790 | printk(KERN_ERR "CRED: %s credentials: %p %s%s%s\n", | ||
| 791 | label, cred, | ||
| 792 | cred == &init_cred ? "[init]" : "", | ||
| 793 | cred == tsk->real_cred ? "[real]" : "", | ||
| 794 | cred == tsk->cred ? "[eff]" : ""); | ||
| 795 | printk(KERN_ERR "CRED: ->magic=%x, put_addr=%p\n", | ||
| 796 | cred->magic, cred->put_addr); | ||
| 797 | printk(KERN_ERR "CRED: ->usage=%d, subscr=%d\n", | ||
| 798 | atomic_read(&cred->usage), | ||
| 799 | read_cred_subscribers(cred)); | ||
| 800 | printk(KERN_ERR "CRED: ->*uid = { %d,%d,%d,%d }\n", | ||
| 801 | cred->uid, cred->euid, cred->suid, cred->fsuid); | ||
| 802 | printk(KERN_ERR "CRED: ->*gid = { %d,%d,%d,%d }\n", | ||
| 803 | cred->gid, cred->egid, cred->sgid, cred->fsgid); | ||
| 804 | #ifdef CONFIG_SECURITY | ||
| 805 | printk(KERN_ERR "CRED: ->security is %p\n", cred->security); | ||
| 806 | if ((unsigned long) cred->security >= PAGE_SIZE && | ||
| 807 | (((unsigned long) cred->security & 0xffffff00) != | ||
| 808 | (POISON_FREE << 24 | POISON_FREE << 16 | POISON_FREE << 8))) | ||
| 809 | printk(KERN_ERR "CRED: ->security {%x, %x}\n", | ||
| 810 | ((u32*)cred->security)[0], | ||
| 811 | ((u32*)cred->security)[1]); | ||
| 812 | #endif | ||
| 813 | } | ||
| 814 | |||
| 815 | /* | ||
| 816 | * report use of invalid credentials | ||
| 817 | */ | ||
| 818 | void __invalid_creds(const struct cred *cred, const char *file, unsigned line) | ||
| 819 | { | ||
| 820 | printk(KERN_ERR "CRED: Invalid credentials\n"); | ||
| 821 | printk(KERN_ERR "CRED: At %s:%u\n", file, line); | ||
| 822 | dump_invalid_creds(cred, "Specified", current); | ||
| 823 | BUG(); | ||
| 824 | } | ||
| 825 | EXPORT_SYMBOL(__invalid_creds); | ||
| 826 | |||
| 827 | /* | ||
| 828 | * check the credentials on a process | ||
| 829 | */ | ||
| 830 | void __validate_process_creds(struct task_struct *tsk, | ||
| 831 | const char *file, unsigned line) | ||
| 832 | { | ||
| 833 | if (tsk->cred == tsk->real_cred) { | ||
| 834 | if (unlikely(read_cred_subscribers(tsk->cred) < 2 || | ||
| 835 | creds_are_invalid(tsk->cred))) | ||
| 836 | goto invalid_creds; | ||
| 837 | } else { | ||
| 838 | if (unlikely(read_cred_subscribers(tsk->real_cred) < 1 || | ||
| 839 | read_cred_subscribers(tsk->cred) < 1 || | ||
| 840 | creds_are_invalid(tsk->real_cred) || | ||
| 841 | creds_are_invalid(tsk->cred))) | ||
| 842 | goto invalid_creds; | ||
| 843 | } | ||
| 844 | return; | ||
| 845 | |||
| 846 | invalid_creds: | ||
| 847 | printk(KERN_ERR "CRED: Invalid process credentials\n"); | ||
| 848 | printk(KERN_ERR "CRED: At %s:%u\n", file, line); | ||
| 849 | |||
| 850 | dump_invalid_creds(tsk->real_cred, "Real", tsk); | ||
| 851 | if (tsk->cred != tsk->real_cred) | ||
| 852 | dump_invalid_creds(tsk->cred, "Effective", tsk); | ||
| 853 | else | ||
| 854 | printk(KERN_ERR "CRED: Effective creds == Real creds\n"); | ||
| 855 | BUG(); | ||
| 856 | } | ||
| 857 | EXPORT_SYMBOL(__validate_process_creds); | ||
| 858 | |||
| 859 | /* | ||
| 860 | * check creds for do_exit() | ||
| 861 | */ | ||
| 862 | void validate_creds_for_do_exit(struct task_struct *tsk) | ||
| 863 | { | ||
| 864 | kdebug("validate_creds_for_do_exit(%p,%p{%d,%d})", | ||
| 865 | tsk->real_cred, tsk->cred, | ||
| 866 | atomic_read(&tsk->cred->usage), | ||
| 867 | read_cred_subscribers(tsk->cred)); | ||
| 868 | |||
| 869 | __validate_process_creds(tsk, __FILE__, __LINE__); | ||
| 870 | } | ||
| 871 | |||
| 872 | #endif /* CONFIG_DEBUG_CREDENTIALS */ | ||
diff --git a/kernel/exit.c b/kernel/exit.c index 869dc221733e..ae5d8660ddff 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
| @@ -901,6 +901,8 @@ NORET_TYPE void do_exit(long code) | |||
| 901 | 901 | ||
| 902 | tracehook_report_exit(&code); | 902 | tracehook_report_exit(&code); |
| 903 | 903 | ||
| 904 | validate_creds_for_do_exit(tsk); | ||
| 905 | |||
| 904 | /* | 906 | /* |
| 905 | * We're taking recursive faults here in do_exit. Safest is to just | 907 | * We're taking recursive faults here in do_exit. Safest is to just |
| 906 | * leave this task alone and wait for reboot. | 908 | * leave this task alone and wait for reboot. |
| @@ -1009,7 +1011,10 @@ NORET_TYPE void do_exit(long code) | |||
| 1009 | if (tsk->splice_pipe) | 1011 | if (tsk->splice_pipe) |
| 1010 | __free_pipe_info(tsk->splice_pipe); | 1012 | __free_pipe_info(tsk->splice_pipe); |
| 1011 | 1013 | ||
| 1014 | validate_creds_for_do_exit(tsk); | ||
| 1015 | |||
| 1012 | preempt_disable(); | 1016 | preempt_disable(); |
| 1017 | exit_rcu(); | ||
| 1013 | /* causes final put_task_struct in finish_task_switch(). */ | 1018 | /* causes final put_task_struct in finish_task_switch(). */ |
| 1014 | tsk->state = TASK_DEAD; | 1019 | tsk->state = TASK_DEAD; |
| 1015 | schedule(); | 1020 | schedule(); |
diff --git a/kernel/fork.c b/kernel/fork.c index e6c04d462ab2..bfee931ee3fb 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
| @@ -152,8 +152,7 @@ void __put_task_struct(struct task_struct *tsk) | |||
| 152 | WARN_ON(atomic_read(&tsk->usage)); | 152 | WARN_ON(atomic_read(&tsk->usage)); |
| 153 | WARN_ON(tsk == current); | 153 | WARN_ON(tsk == current); |
| 154 | 154 | ||
| 155 | put_cred(tsk->real_cred); | 155 | exit_creds(tsk); |
| 156 | put_cred(tsk->cred); | ||
| 157 | delayacct_tsk_free(tsk); | 156 | delayacct_tsk_free(tsk); |
| 158 | 157 | ||
| 159 | if (!profile_handoff_task(tsk)) | 158 | if (!profile_handoff_task(tsk)) |
| @@ -1008,10 +1007,7 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
| 1008 | copy_flags(clone_flags, p); | 1007 | copy_flags(clone_flags, p); |
| 1009 | INIT_LIST_HEAD(&p->children); | 1008 | INIT_LIST_HEAD(&p->children); |
| 1010 | INIT_LIST_HEAD(&p->sibling); | 1009 | INIT_LIST_HEAD(&p->sibling); |
| 1011 | #ifdef CONFIG_PREEMPT_RCU | 1010 | rcu_copy_process(p); |
| 1012 | p->rcu_read_lock_nesting = 0; | ||
| 1013 | p->rcu_flipctr_idx = 0; | ||
| 1014 | #endif /* #ifdef CONFIG_PREEMPT_RCU */ | ||
| 1015 | p->vfork_done = NULL; | 1011 | p->vfork_done = NULL; |
| 1016 | spin_lock_init(&p->alloc_lock); | 1012 | spin_lock_init(&p->alloc_lock); |
| 1017 | 1013 | ||
| @@ -1297,8 +1293,7 @@ bad_fork_cleanup_put_domain: | |||
| 1297 | module_put(task_thread_info(p)->exec_domain->module); | 1293 | module_put(task_thread_info(p)->exec_domain->module); |
| 1298 | bad_fork_cleanup_count: | 1294 | bad_fork_cleanup_count: |
| 1299 | atomic_dec(&p->cred->user->processes); | 1295 | atomic_dec(&p->cred->user->processes); |
| 1300 | put_cred(p->real_cred); | 1296 | exit_creds(p); |
| 1301 | put_cred(p->cred); | ||
| 1302 | bad_fork_free: | 1297 | bad_fork_free: |
| 1303 | free_task(p); | 1298 | free_task(p); |
| 1304 | fork_out: | 1299 | fork_out: |
diff --git a/kernel/futex.c b/kernel/futex.c index e18cfbdc7190..248dd119a86e 100644 --- a/kernel/futex.c +++ b/kernel/futex.c | |||
| @@ -115,6 +115,9 @@ struct futex_q { | |||
| 115 | /* rt_waiter storage for requeue_pi: */ | 115 | /* rt_waiter storage for requeue_pi: */ |
| 116 | struct rt_mutex_waiter *rt_waiter; | 116 | struct rt_mutex_waiter *rt_waiter; |
| 117 | 117 | ||
| 118 | /* The expected requeue pi target futex key: */ | ||
| 119 | union futex_key *requeue_pi_key; | ||
| 120 | |||
| 118 | /* Bitset for the optional bitmasked wakeup */ | 121 | /* Bitset for the optional bitmasked wakeup */ |
| 119 | u32 bitset; | 122 | u32 bitset; |
| 120 | }; | 123 | }; |
| @@ -1089,6 +1092,10 @@ static int futex_proxy_trylock_atomic(u32 __user *pifutex, | |||
| 1089 | if (!top_waiter) | 1092 | if (!top_waiter) |
| 1090 | return 0; | 1093 | return 0; |
| 1091 | 1094 | ||
| 1095 | /* Ensure we requeue to the expected futex. */ | ||
| 1096 | if (!match_futex(top_waiter->requeue_pi_key, key2)) | ||
| 1097 | return -EINVAL; | ||
| 1098 | |||
| 1092 | /* | 1099 | /* |
| 1093 | * Try to take the lock for top_waiter. Set the FUTEX_WAITERS bit in | 1100 | * Try to take the lock for top_waiter. Set the FUTEX_WAITERS bit in |
| 1094 | * the contended case or if set_waiters is 1. The pi_state is returned | 1101 | * the contended case or if set_waiters is 1. The pi_state is returned |
| @@ -1276,6 +1283,12 @@ retry_private: | |||
| 1276 | continue; | 1283 | continue; |
| 1277 | } | 1284 | } |
| 1278 | 1285 | ||
| 1286 | /* Ensure we requeue to the expected futex for requeue_pi. */ | ||
| 1287 | if (requeue_pi && !match_futex(this->requeue_pi_key, &key2)) { | ||
| 1288 | ret = -EINVAL; | ||
| 1289 | break; | ||
| 1290 | } | ||
| 1291 | |||
| 1279 | /* | 1292 | /* |
| 1280 | * Requeue nr_requeue waiters and possibly one more in the case | 1293 | * Requeue nr_requeue waiters and possibly one more in the case |
| 1281 | * of requeue_pi if we couldn't acquire the lock atomically. | 1294 | * of requeue_pi if we couldn't acquire the lock atomically. |
| @@ -1751,6 +1764,7 @@ static int futex_wait(u32 __user *uaddr, int fshared, | |||
| 1751 | q.pi_state = NULL; | 1764 | q.pi_state = NULL; |
| 1752 | q.bitset = bitset; | 1765 | q.bitset = bitset; |
| 1753 | q.rt_waiter = NULL; | 1766 | q.rt_waiter = NULL; |
| 1767 | q.requeue_pi_key = NULL; | ||
| 1754 | 1768 | ||
| 1755 | if (abs_time) { | 1769 | if (abs_time) { |
| 1756 | to = &timeout; | 1770 | to = &timeout; |
| @@ -1858,6 +1872,7 @@ static int futex_lock_pi(u32 __user *uaddr, int fshared, | |||
| 1858 | 1872 | ||
| 1859 | q.pi_state = NULL; | 1873 | q.pi_state = NULL; |
| 1860 | q.rt_waiter = NULL; | 1874 | q.rt_waiter = NULL; |
| 1875 | q.requeue_pi_key = NULL; | ||
| 1861 | retry: | 1876 | retry: |
| 1862 | q.key = FUTEX_KEY_INIT; | 1877 | q.key = FUTEX_KEY_INIT; |
| 1863 | ret = get_futex_key(uaddr, fshared, &q.key, VERIFY_WRITE); | 1878 | ret = get_futex_key(uaddr, fshared, &q.key, VERIFY_WRITE); |
| @@ -2118,11 +2133,11 @@ int handle_early_requeue_pi_wakeup(struct futex_hash_bucket *hb, | |||
| 2118 | * We call schedule in futex_wait_queue_me() when we enqueue and return there | 2133 | * We call schedule in futex_wait_queue_me() when we enqueue and return there |
| 2119 | * via the following: | 2134 | * via the following: |
| 2120 | * 1) wakeup on uaddr2 after an atomic lock acquisition by futex_requeue() | 2135 | * 1) wakeup on uaddr2 after an atomic lock acquisition by futex_requeue() |
| 2121 | * 2) wakeup on uaddr2 after a requeue and subsequent unlock | 2136 | * 2) wakeup on uaddr2 after a requeue |
| 2122 | * 3) signal (before or after requeue) | 2137 | * 3) signal |
| 2123 | * 4) timeout (before or after requeue) | 2138 | * 4) timeout |
| 2124 | * | 2139 | * |
| 2125 | * If 3, we setup a restart_block with futex_wait_requeue_pi() as the function. | 2140 | * If 3, cleanup and return -ERESTARTNOINTR. |
| 2126 | * | 2141 | * |
| 2127 | * If 2, we may then block on trying to take the rt_mutex and return via: | 2142 | * If 2, we may then block on trying to take the rt_mutex and return via: |
| 2128 | * 5) successful lock | 2143 | * 5) successful lock |
| @@ -2130,7 +2145,7 @@ int handle_early_requeue_pi_wakeup(struct futex_hash_bucket *hb, | |||
| 2130 | * 7) timeout | 2145 | * 7) timeout |
| 2131 | * 8) other lock acquisition failure | 2146 | * 8) other lock acquisition failure |
| 2132 | * | 2147 | * |
| 2133 | * If 6, we setup a restart_block with futex_lock_pi() as the function. | 2148 | * If 6, return -EWOULDBLOCK (restarting the syscall would do the same). |
| 2134 | * | 2149 | * |
| 2135 | * If 4 or 7, we cleanup and return with -ETIMEDOUT. | 2150 | * If 4 or 7, we cleanup and return with -ETIMEDOUT. |
| 2136 | * | 2151 | * |
| @@ -2169,15 +2184,16 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, int fshared, | |||
| 2169 | debug_rt_mutex_init_waiter(&rt_waiter); | 2184 | debug_rt_mutex_init_waiter(&rt_waiter); |
| 2170 | rt_waiter.task = NULL; | 2185 | rt_waiter.task = NULL; |
| 2171 | 2186 | ||
| 2172 | q.pi_state = NULL; | ||
| 2173 | q.bitset = bitset; | ||
| 2174 | q.rt_waiter = &rt_waiter; | ||
| 2175 | |||
| 2176 | key2 = FUTEX_KEY_INIT; | 2187 | key2 = FUTEX_KEY_INIT; |
| 2177 | ret = get_futex_key(uaddr2, fshared, &key2, VERIFY_WRITE); | 2188 | ret = get_futex_key(uaddr2, fshared, &key2, VERIFY_WRITE); |
| 2178 | if (unlikely(ret != 0)) | 2189 | if (unlikely(ret != 0)) |
| 2179 | goto out; | 2190 | goto out; |
| 2180 | 2191 | ||
| 2192 | q.pi_state = NULL; | ||
| 2193 | q.bitset = bitset; | ||
| 2194 | q.rt_waiter = &rt_waiter; | ||
| 2195 | q.requeue_pi_key = &key2; | ||
| 2196 | |||
| 2181 | /* Prepare to wait on uaddr. */ | 2197 | /* Prepare to wait on uaddr. */ |
| 2182 | ret = futex_wait_setup(uaddr, val, fshared, &q, &hb); | 2198 | ret = futex_wait_setup(uaddr, val, fshared, &q, &hb); |
| 2183 | if (ret) | 2199 | if (ret) |
| @@ -2248,14 +2264,11 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, int fshared, | |||
| 2248 | rt_mutex_unlock(pi_mutex); | 2264 | rt_mutex_unlock(pi_mutex); |
| 2249 | } else if (ret == -EINTR) { | 2265 | } else if (ret == -EINTR) { |
| 2250 | /* | 2266 | /* |
| 2251 | * We've already been requeued, but we have no way to | 2267 | * We've already been requeued, but cannot restart by calling |
| 2252 | * restart by calling futex_lock_pi() directly. We | 2268 | * futex_lock_pi() directly. We could restart this syscall, but |
| 2253 | * could restart the syscall, but that will look at | 2269 | * it would detect that the user space "val" changed and return |
| 2254 | * the user space value and return right away. So we | 2270 | * -EWOULDBLOCK. Save the overhead of the restart and return |
| 2255 | * drop back with EWOULDBLOCK to tell user space that | 2271 | * -EWOULDBLOCK directly. |
| 2256 | * "val" has been changed. That's the same what the | ||
| 2257 | * restart of the syscall would do in | ||
| 2258 | * futex_wait_setup(). | ||
| 2259 | */ | 2272 | */ |
| 2260 | ret = -EWOULDBLOCK; | 2273 | ret = -EWOULDBLOCK; |
| 2261 | } | 2274 | } |
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c index 49da79ab8486..05071bf6a37b 100644 --- a/kernel/hrtimer.c +++ b/kernel/hrtimer.c | |||
| @@ -485,6 +485,7 @@ void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t clock_id, | |||
| 485 | debug_object_init_on_stack(timer, &hrtimer_debug_descr); | 485 | debug_object_init_on_stack(timer, &hrtimer_debug_descr); |
| 486 | __hrtimer_init(timer, clock_id, mode); | 486 | __hrtimer_init(timer, clock_id, mode); |
| 487 | } | 487 | } |
| 488 | EXPORT_SYMBOL_GPL(hrtimer_init_on_stack); | ||
| 488 | 489 | ||
| 489 | void destroy_hrtimer_on_stack(struct hrtimer *timer) | 490 | void destroy_hrtimer_on_stack(struct hrtimer *timer) |
| 490 | { | 491 | { |
| @@ -1477,6 +1478,7 @@ void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, struct task_struct *task) | |||
| 1477 | sl->timer.function = hrtimer_wakeup; | 1478 | sl->timer.function = hrtimer_wakeup; |
| 1478 | sl->task = task; | 1479 | sl->task = task; |
| 1479 | } | 1480 | } |
| 1481 | EXPORT_SYMBOL_GPL(hrtimer_init_sleeper); | ||
| 1480 | 1482 | ||
| 1481 | static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mode) | 1483 | static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mode) |
| 1482 | { | 1484 | { |
diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c index 13c68e71b726..c1660194d115 100644 --- a/kernel/irq/chip.c +++ b/kernel/irq/chip.c | |||
| @@ -222,6 +222,34 @@ int set_irq_chip_data(unsigned int irq, void *data) | |||
| 222 | } | 222 | } |
| 223 | EXPORT_SYMBOL(set_irq_chip_data); | 223 | EXPORT_SYMBOL(set_irq_chip_data); |
| 224 | 224 | ||
| 225 | /** | ||
| 226 | * set_irq_nested_thread - Set/Reset the IRQ_NESTED_THREAD flag of an irq | ||
| 227 | * | ||
| 228 | * @irq: Interrupt number | ||
| 229 | * @nest: 0 to clear / 1 to set the IRQ_NESTED_THREAD flag | ||
| 230 | * | ||
| 231 | * The IRQ_NESTED_THREAD flag indicates that on | ||
| 232 | * request_threaded_irq() no separate interrupt thread should be | ||
| 233 | * created for the irq as the handler are called nested in the | ||
| 234 | * context of a demultiplexing interrupt handler thread. | ||
| 235 | */ | ||
| 236 | void set_irq_nested_thread(unsigned int irq, int nest) | ||
| 237 | { | ||
| 238 | struct irq_desc *desc = irq_to_desc(irq); | ||
| 239 | unsigned long flags; | ||
| 240 | |||
| 241 | if (!desc) | ||
| 242 | return; | ||
| 243 | |||
| 244 | spin_lock_irqsave(&desc->lock, flags); | ||
| 245 | if (nest) | ||
| 246 | desc->status |= IRQ_NESTED_THREAD; | ||
| 247 | else | ||
| 248 | desc->status &= ~IRQ_NESTED_THREAD; | ||
| 249 | spin_unlock_irqrestore(&desc->lock, flags); | ||
| 250 | } | ||
| 251 | EXPORT_SYMBOL_GPL(set_irq_nested_thread); | ||
| 252 | |||
| 225 | /* | 253 | /* |
| 226 | * default enable function | 254 | * default enable function |
| 227 | */ | 255 | */ |
| @@ -299,6 +327,45 @@ static inline void mask_ack_irq(struct irq_desc *desc, int irq) | |||
| 299 | } | 327 | } |
| 300 | } | 328 | } |
| 301 | 329 | ||
| 330 | /* | ||
| 331 | * handle_nested_irq - Handle a nested irq from a irq thread | ||
| 332 | * @irq: the interrupt number | ||
| 333 | * | ||
| 334 | * Handle interrupts which are nested into a threaded interrupt | ||
| 335 | * handler. The handler function is called inside the calling | ||
| 336 | * threads context. | ||
| 337 | */ | ||
| 338 | void handle_nested_irq(unsigned int irq) | ||
| 339 | { | ||
| 340 | struct irq_desc *desc = irq_to_desc(irq); | ||
| 341 | struct irqaction *action; | ||
| 342 | irqreturn_t action_ret; | ||
| 343 | |||
| 344 | might_sleep(); | ||
| 345 | |||
| 346 | spin_lock_irq(&desc->lock); | ||
| 347 | |||
| 348 | kstat_incr_irqs_this_cpu(irq, desc); | ||
| 349 | |||
| 350 | action = desc->action; | ||
| 351 | if (unlikely(!action || (desc->status & IRQ_DISABLED))) | ||
| 352 | goto out_unlock; | ||
| 353 | |||
| 354 | desc->status |= IRQ_INPROGRESS; | ||
| 355 | spin_unlock_irq(&desc->lock); | ||
| 356 | |||
| 357 | action_ret = action->thread_fn(action->irq, action->dev_id); | ||
| 358 | if (!noirqdebug) | ||
| 359 | note_interrupt(irq, desc, action_ret); | ||
| 360 | |||
| 361 | spin_lock_irq(&desc->lock); | ||
| 362 | desc->status &= ~IRQ_INPROGRESS; | ||
| 363 | |||
| 364 | out_unlock: | ||
| 365 | spin_unlock_irq(&desc->lock); | ||
| 366 | } | ||
| 367 | EXPORT_SYMBOL_GPL(handle_nested_irq); | ||
| 368 | |||
| 302 | /** | 369 | /** |
| 303 | * handle_simple_irq - Simple and software-decoded IRQs. | 370 | * handle_simple_irq - Simple and software-decoded IRQs. |
| 304 | * @irq: the interrupt number | 371 | * @irq: the interrupt number |
| @@ -382,7 +449,10 @@ handle_level_irq(unsigned int irq, struct irq_desc *desc) | |||
| 382 | 449 | ||
| 383 | spin_lock(&desc->lock); | 450 | spin_lock(&desc->lock); |
| 384 | desc->status &= ~IRQ_INPROGRESS; | 451 | desc->status &= ~IRQ_INPROGRESS; |
| 385 | if (!(desc->status & IRQ_DISABLED) && desc->chip->unmask) | 452 | |
| 453 | if (unlikely(desc->status & IRQ_ONESHOT)) | ||
| 454 | desc->status |= IRQ_MASKED; | ||
| 455 | else if (!(desc->status & IRQ_DISABLED) && desc->chip->unmask) | ||
| 386 | desc->chip->unmask(irq); | 456 | desc->chip->unmask(irq); |
| 387 | out_unlock: | 457 | out_unlock: |
| 388 | spin_unlock(&desc->lock); | 458 | spin_unlock(&desc->lock); |
| @@ -572,6 +642,7 @@ __set_irq_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained, | |||
| 572 | desc->chip = &dummy_irq_chip; | 642 | desc->chip = &dummy_irq_chip; |
| 573 | } | 643 | } |
| 574 | 644 | ||
| 645 | chip_bus_lock(irq, desc); | ||
| 575 | spin_lock_irqsave(&desc->lock, flags); | 646 | spin_lock_irqsave(&desc->lock, flags); |
| 576 | 647 | ||
| 577 | /* Uninstall? */ | 648 | /* Uninstall? */ |
| @@ -591,6 +662,7 @@ __set_irq_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained, | |||
| 591 | desc->chip->startup(irq); | 662 | desc->chip->startup(irq); |
| 592 | } | 663 | } |
| 593 | spin_unlock_irqrestore(&desc->lock, flags); | 664 | spin_unlock_irqrestore(&desc->lock, flags); |
| 665 | chip_bus_sync_unlock(irq, desc); | ||
| 594 | } | 666 | } |
| 595 | EXPORT_SYMBOL_GPL(__set_irq_handler); | 667 | EXPORT_SYMBOL_GPL(__set_irq_handler); |
| 596 | 668 | ||
diff --git a/kernel/irq/handle.c b/kernel/irq/handle.c index 065205bdd920..a81cf80554db 100644 --- a/kernel/irq/handle.c +++ b/kernel/irq/handle.c | |||
| @@ -161,7 +161,7 @@ int __init early_irq_init(void) | |||
| 161 | 161 | ||
| 162 | desc = irq_desc_legacy; | 162 | desc = irq_desc_legacy; |
| 163 | legacy_count = ARRAY_SIZE(irq_desc_legacy); | 163 | legacy_count = ARRAY_SIZE(irq_desc_legacy); |
| 164 | node = first_online_node; | 164 | node = first_online_node; |
| 165 | 165 | ||
| 166 | /* allocate irq_desc_ptrs array based on nr_irqs */ | 166 | /* allocate irq_desc_ptrs array based on nr_irqs */ |
| 167 | irq_desc_ptrs = kcalloc(nr_irqs, sizeof(void *), GFP_NOWAIT); | 167 | irq_desc_ptrs = kcalloc(nr_irqs, sizeof(void *), GFP_NOWAIT); |
| @@ -172,6 +172,9 @@ int __init early_irq_init(void) | |||
| 172 | 172 | ||
| 173 | for (i = 0; i < legacy_count; i++) { | 173 | for (i = 0; i < legacy_count; i++) { |
| 174 | desc[i].irq = i; | 174 | desc[i].irq = i; |
| 175 | #ifdef CONFIG_SMP | ||
| 176 | desc[i].node = node; | ||
| 177 | #endif | ||
| 175 | desc[i].kstat_irqs = kstat_irqs_legacy + i * nr_cpu_ids; | 178 | desc[i].kstat_irqs = kstat_irqs_legacy + i * nr_cpu_ids; |
| 176 | lockdep_set_class(&desc[i].lock, &irq_desc_lock_class); | 179 | lockdep_set_class(&desc[i].lock, &irq_desc_lock_class); |
| 177 | alloc_desc_masks(&desc[i], node, true); | 180 | alloc_desc_masks(&desc[i], node, true); |
diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h index e70ed5592eb9..1b5d742c6a77 100644 --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h | |||
| @@ -44,6 +44,19 @@ extern int irq_select_affinity_usr(unsigned int irq); | |||
| 44 | 44 | ||
| 45 | extern void irq_set_thread_affinity(struct irq_desc *desc); | 45 | extern void irq_set_thread_affinity(struct irq_desc *desc); |
| 46 | 46 | ||
| 47 | /* Inline functions for support of irq chips on slow busses */ | ||
| 48 | static inline void chip_bus_lock(unsigned int irq, struct irq_desc *desc) | ||
| 49 | { | ||
| 50 | if (unlikely(desc->chip->bus_lock)) | ||
| 51 | desc->chip->bus_lock(irq); | ||
| 52 | } | ||
| 53 | |||
| 54 | static inline void chip_bus_sync_unlock(unsigned int irq, struct irq_desc *desc) | ||
| 55 | { | ||
| 56 | if (unlikely(desc->chip->bus_sync_unlock)) | ||
| 57 | desc->chip->bus_sync_unlock(irq); | ||
| 58 | } | ||
| 59 | |||
| 47 | /* | 60 | /* |
| 48 | * Debugging printout: | 61 | * Debugging printout: |
| 49 | */ | 62 | */ |
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index 0ec9ed831737..bde4c667d24d 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c | |||
| @@ -230,9 +230,11 @@ void disable_irq_nosync(unsigned int irq) | |||
| 230 | if (!desc) | 230 | if (!desc) |
| 231 | return; | 231 | return; |
| 232 | 232 | ||
| 233 | chip_bus_lock(irq, desc); | ||
| 233 | spin_lock_irqsave(&desc->lock, flags); | 234 | spin_lock_irqsave(&desc->lock, flags); |
| 234 | __disable_irq(desc, irq, false); | 235 | __disable_irq(desc, irq, false); |
| 235 | spin_unlock_irqrestore(&desc->lock, flags); | 236 | spin_unlock_irqrestore(&desc->lock, flags); |
| 237 | chip_bus_sync_unlock(irq, desc); | ||
| 236 | } | 238 | } |
| 237 | EXPORT_SYMBOL(disable_irq_nosync); | 239 | EXPORT_SYMBOL(disable_irq_nosync); |
| 238 | 240 | ||
| @@ -294,7 +296,8 @@ void __enable_irq(struct irq_desc *desc, unsigned int irq, bool resume) | |||
| 294 | * matches the last disable, processing of interrupts on this | 296 | * matches the last disable, processing of interrupts on this |
| 295 | * IRQ line is re-enabled. | 297 | * IRQ line is re-enabled. |
| 296 | * | 298 | * |
| 297 | * This function may be called from IRQ context. | 299 | * This function may be called from IRQ context only when |
| 300 | * desc->chip->bus_lock and desc->chip->bus_sync_unlock are NULL ! | ||
| 298 | */ | 301 | */ |
| 299 | void enable_irq(unsigned int irq) | 302 | void enable_irq(unsigned int irq) |
| 300 | { | 303 | { |
| @@ -304,9 +307,11 @@ void enable_irq(unsigned int irq) | |||
| 304 | if (!desc) | 307 | if (!desc) |
| 305 | return; | 308 | return; |
| 306 | 309 | ||
| 310 | chip_bus_lock(irq, desc); | ||
| 307 | spin_lock_irqsave(&desc->lock, flags); | 311 | spin_lock_irqsave(&desc->lock, flags); |
| 308 | __enable_irq(desc, irq, false); | 312 | __enable_irq(desc, irq, false); |
| 309 | spin_unlock_irqrestore(&desc->lock, flags); | 313 | spin_unlock_irqrestore(&desc->lock, flags); |
| 314 | chip_bus_sync_unlock(irq, desc); | ||
| 310 | } | 315 | } |
| 311 | EXPORT_SYMBOL(enable_irq); | 316 | EXPORT_SYMBOL(enable_irq); |
| 312 | 317 | ||
| @@ -436,6 +441,26 @@ int __irq_set_trigger(struct irq_desc *desc, unsigned int irq, | |||
| 436 | return ret; | 441 | return ret; |
| 437 | } | 442 | } |
| 438 | 443 | ||
| 444 | /* | ||
| 445 | * Default primary interrupt handler for threaded interrupts. Is | ||
| 446 | * assigned as primary handler when request_threaded_irq is called | ||
| 447 | * with handler == NULL. Useful for oneshot interrupts. | ||
| 448 | */ | ||
| 449 | static irqreturn_t irq_default_primary_handler(int irq, void *dev_id) | ||
| 450 | { | ||
| 451 | return IRQ_WAKE_THREAD; | ||
| 452 | } | ||
| 453 | |||
| 454 | /* | ||
| 455 | * Primary handler for nested threaded interrupts. Should never be | ||
| 456 | * called. | ||
| 457 | */ | ||
| 458 | static irqreturn_t irq_nested_primary_handler(int irq, void *dev_id) | ||
| 459 | { | ||
| 460 | WARN(1, "Primary handler called for nested irq %d\n", irq); | ||
| 461 | return IRQ_NONE; | ||
| 462 | } | ||
| 463 | |||
| 439 | static int irq_wait_for_interrupt(struct irqaction *action) | 464 | static int irq_wait_for_interrupt(struct irqaction *action) |
| 440 | { | 465 | { |
| 441 | while (!kthread_should_stop()) { | 466 | while (!kthread_should_stop()) { |
| @@ -451,6 +476,23 @@ static int irq_wait_for_interrupt(struct irqaction *action) | |||
| 451 | return -1; | 476 | return -1; |
| 452 | } | 477 | } |
| 453 | 478 | ||
| 479 | /* | ||
| 480 | * Oneshot interrupts keep the irq line masked until the threaded | ||
| 481 | * handler finished. unmask if the interrupt has not been disabled and | ||
| 482 | * is marked MASKED. | ||
| 483 | */ | ||
| 484 | static void irq_finalize_oneshot(unsigned int irq, struct irq_desc *desc) | ||
| 485 | { | ||
| 486 | chip_bus_lock(irq, desc); | ||
| 487 | spin_lock_irq(&desc->lock); | ||
| 488 | if (!(desc->status & IRQ_DISABLED) && (desc->status & IRQ_MASKED)) { | ||
| 489 | desc->status &= ~IRQ_MASKED; | ||
| 490 | desc->chip->unmask(irq); | ||
| 491 | } | ||
| 492 | spin_unlock_irq(&desc->lock); | ||
| 493 | chip_bus_sync_unlock(irq, desc); | ||
| 494 | } | ||
| 495 | |||
| 454 | #ifdef CONFIG_SMP | 496 | #ifdef CONFIG_SMP |
| 455 | /* | 497 | /* |
| 456 | * Check whether we need to change the affinity of the interrupt thread. | 498 | * Check whether we need to change the affinity of the interrupt thread. |
| @@ -492,7 +534,7 @@ static int irq_thread(void *data) | |||
| 492 | struct sched_param param = { .sched_priority = MAX_USER_RT_PRIO/2, }; | 534 | struct sched_param param = { .sched_priority = MAX_USER_RT_PRIO/2, }; |
| 493 | struct irqaction *action = data; | 535 | struct irqaction *action = data; |
| 494 | struct irq_desc *desc = irq_to_desc(action->irq); | 536 | struct irq_desc *desc = irq_to_desc(action->irq); |
| 495 | int wake; | 537 | int wake, oneshot = desc->status & IRQ_ONESHOT; |
| 496 | 538 | ||
| 497 | sched_setscheduler(current, SCHED_FIFO, ¶m); | 539 | sched_setscheduler(current, SCHED_FIFO, ¶m); |
| 498 | current->irqaction = action; | 540 | current->irqaction = action; |
| @@ -518,6 +560,9 @@ static int irq_thread(void *data) | |||
| 518 | spin_unlock_irq(&desc->lock); | 560 | spin_unlock_irq(&desc->lock); |
| 519 | 561 | ||
| 520 | action->thread_fn(action->irq, action->dev_id); | 562 | action->thread_fn(action->irq, action->dev_id); |
| 563 | |||
| 564 | if (oneshot) | ||
| 565 | irq_finalize_oneshot(action->irq, desc); | ||
| 521 | } | 566 | } |
| 522 | 567 | ||
| 523 | wake = atomic_dec_and_test(&desc->threads_active); | 568 | wake = atomic_dec_and_test(&desc->threads_active); |
| @@ -565,7 +610,7 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new) | |||
| 565 | struct irqaction *old, **old_ptr; | 610 | struct irqaction *old, **old_ptr; |
| 566 | const char *old_name = NULL; | 611 | const char *old_name = NULL; |
| 567 | unsigned long flags; | 612 | unsigned long flags; |
| 568 | int shared = 0; | 613 | int nested, shared = 0; |
| 569 | int ret; | 614 | int ret; |
| 570 | 615 | ||
| 571 | if (!desc) | 616 | if (!desc) |
| @@ -590,10 +635,32 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new) | |||
| 590 | rand_initialize_irq(irq); | 635 | rand_initialize_irq(irq); |
| 591 | } | 636 | } |
| 592 | 637 | ||
| 638 | /* Oneshot interrupts are not allowed with shared */ | ||
| 639 | if ((new->flags & IRQF_ONESHOT) && (new->flags & IRQF_SHARED)) | ||
| 640 | return -EINVAL; | ||
| 641 | |||
| 642 | /* | ||
| 643 | * Check whether the interrupt nests into another interrupt | ||
| 644 | * thread. | ||
| 645 | */ | ||
| 646 | nested = desc->status & IRQ_NESTED_THREAD; | ||
| 647 | if (nested) { | ||
| 648 | if (!new->thread_fn) | ||
| 649 | return -EINVAL; | ||
| 650 | /* | ||
| 651 | * Replace the primary handler which was provided from | ||
| 652 | * the driver for non nested interrupt handling by the | ||
| 653 | * dummy function which warns when called. | ||
| 654 | */ | ||
| 655 | new->handler = irq_nested_primary_handler; | ||
| 656 | } | ||
| 657 | |||
| 593 | /* | 658 | /* |
| 594 | * Threaded handler ? | 659 | * Create a handler thread when a thread function is supplied |
| 660 | * and the interrupt does not nest into another interrupt | ||
| 661 | * thread. | ||
| 595 | */ | 662 | */ |
| 596 | if (new->thread_fn) { | 663 | if (new->thread_fn && !nested) { |
| 597 | struct task_struct *t; | 664 | struct task_struct *t; |
| 598 | 665 | ||
| 599 | t = kthread_create(irq_thread, new, "irq/%d-%s", irq, | 666 | t = kthread_create(irq_thread, new, "irq/%d-%s", irq, |
| @@ -662,9 +729,12 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new) | |||
| 662 | desc->status |= IRQ_PER_CPU; | 729 | desc->status |= IRQ_PER_CPU; |
| 663 | #endif | 730 | #endif |
| 664 | 731 | ||
| 665 | desc->status &= ~(IRQ_AUTODETECT | IRQ_WAITING | | 732 | desc->status &= ~(IRQ_AUTODETECT | IRQ_WAITING | IRQ_ONESHOT | |
| 666 | IRQ_INPROGRESS | IRQ_SPURIOUS_DISABLED); | 733 | IRQ_INPROGRESS | IRQ_SPURIOUS_DISABLED); |
| 667 | 734 | ||
| 735 | if (new->flags & IRQF_ONESHOT) | ||
| 736 | desc->status |= IRQ_ONESHOT; | ||
| 737 | |||
| 668 | if (!(desc->status & IRQ_NOAUTOEN)) { | 738 | if (!(desc->status & IRQ_NOAUTOEN)) { |
| 669 | desc->depth = 0; | 739 | desc->depth = 0; |
| 670 | desc->status &= ~IRQ_DISABLED; | 740 | desc->status &= ~IRQ_DISABLED; |
| @@ -875,7 +945,14 @@ EXPORT_SYMBOL_GPL(remove_irq); | |||
| 875 | */ | 945 | */ |
| 876 | void free_irq(unsigned int irq, void *dev_id) | 946 | void free_irq(unsigned int irq, void *dev_id) |
| 877 | { | 947 | { |
| 948 | struct irq_desc *desc = irq_to_desc(irq); | ||
| 949 | |||
| 950 | if (!desc) | ||
| 951 | return; | ||
| 952 | |||
| 953 | chip_bus_lock(irq, desc); | ||
| 878 | kfree(__free_irq(irq, dev_id)); | 954 | kfree(__free_irq(irq, dev_id)); |
| 955 | chip_bus_sync_unlock(irq, desc); | ||
| 879 | } | 956 | } |
| 880 | EXPORT_SYMBOL(free_irq); | 957 | EXPORT_SYMBOL(free_irq); |
| 881 | 958 | ||
| @@ -884,6 +961,8 @@ EXPORT_SYMBOL(free_irq); | |||
| 884 | * @irq: Interrupt line to allocate | 961 | * @irq: Interrupt line to allocate |
| 885 | * @handler: Function to be called when the IRQ occurs. | 962 | * @handler: Function to be called when the IRQ occurs. |
| 886 | * Primary handler for threaded interrupts | 963 | * Primary handler for threaded interrupts |
| 964 | * If NULL and thread_fn != NULL the default | ||
| 965 | * primary handler is installed | ||
| 887 | * @thread_fn: Function called from the irq handler thread | 966 | * @thread_fn: Function called from the irq handler thread |
| 888 | * If NULL, no irq thread is created | 967 | * If NULL, no irq thread is created |
| 889 | * @irqflags: Interrupt type flags | 968 | * @irqflags: Interrupt type flags |
| @@ -963,8 +1042,12 @@ int request_threaded_irq(unsigned int irq, irq_handler_t handler, | |||
| 963 | 1042 | ||
| 964 | if (desc->status & IRQ_NOREQUEST) | 1043 | if (desc->status & IRQ_NOREQUEST) |
| 965 | return -EINVAL; | 1044 | return -EINVAL; |
| 966 | if (!handler) | 1045 | |
| 967 | return -EINVAL; | 1046 | if (!handler) { |
| 1047 | if (!thread_fn) | ||
| 1048 | return -EINVAL; | ||
| 1049 | handler = irq_default_primary_handler; | ||
| 1050 | } | ||
| 968 | 1051 | ||
| 969 | action = kzalloc(sizeof(struct irqaction), GFP_KERNEL); | 1052 | action = kzalloc(sizeof(struct irqaction), GFP_KERNEL); |
| 970 | if (!action) | 1053 | if (!action) |
| @@ -976,7 +1059,10 @@ int request_threaded_irq(unsigned int irq, irq_handler_t handler, | |||
| 976 | action->name = devname; | 1059 | action->name = devname; |
| 977 | action->dev_id = dev_id; | 1060 | action->dev_id = dev_id; |
| 978 | 1061 | ||
| 1062 | chip_bus_lock(irq, desc); | ||
| 979 | retval = __setup_irq(irq, desc, action); | 1063 | retval = __setup_irq(irq, desc, action); |
| 1064 | chip_bus_sync_unlock(irq, desc); | ||
| 1065 | |||
| 980 | if (retval) | 1066 | if (retval) |
| 981 | kfree(action); | 1067 | kfree(action); |
| 982 | 1068 | ||
diff --git a/kernel/irq/pm.c b/kernel/irq/pm.c index 638d8bedec14..a0bb09e79867 100644 --- a/kernel/irq/pm.c +++ b/kernel/irq/pm.c | |||
| @@ -15,10 +15,10 @@ | |||
| 15 | /** | 15 | /** |
| 16 | * suspend_device_irqs - disable all currently enabled interrupt lines | 16 | * suspend_device_irqs - disable all currently enabled interrupt lines |
| 17 | * | 17 | * |
| 18 | * During system-wide suspend or hibernation device interrupts need to be | 18 | * During system-wide suspend or hibernation device drivers need to be prevented |
| 19 | * disabled at the chip level and this function is provided for this purpose. | 19 | * from receiving interrupts and this function is provided for this purpose. |
| 20 | * It disables all interrupt lines that are enabled at the moment and sets the | 20 | * It marks all interrupt lines in use, except for the timer ones, as disabled |
| 21 | * IRQ_SUSPENDED flag for them. | 21 | * and sets the IRQ_SUSPENDED flag for each of them. |
| 22 | */ | 22 | */ |
| 23 | void suspend_device_irqs(void) | 23 | void suspend_device_irqs(void) |
| 24 | { | 24 | { |
diff --git a/kernel/irq/resend.c b/kernel/irq/resend.c index 89c7117acf2b..090c3763f3a2 100644 --- a/kernel/irq/resend.c +++ b/kernel/irq/resend.c | |||
| @@ -70,8 +70,7 @@ void check_irq_resend(struct irq_desc *desc, unsigned int irq) | |||
| 70 | if ((status & (IRQ_LEVEL | IRQ_PENDING | IRQ_REPLAY)) == IRQ_PENDING) { | 70 | if ((status & (IRQ_LEVEL | IRQ_PENDING | IRQ_REPLAY)) == IRQ_PENDING) { |
| 71 | desc->status = (status & ~IRQ_PENDING) | IRQ_REPLAY; | 71 | desc->status = (status & ~IRQ_PENDING) | IRQ_REPLAY; |
| 72 | 72 | ||
| 73 | if (!desc->chip || !desc->chip->retrigger || | 73 | if (!desc->chip->retrigger || !desc->chip->retrigger(irq)) { |
| 74 | !desc->chip->retrigger(irq)) { | ||
| 75 | #ifdef CONFIG_HARDIRQS_SW_RESEND | 74 | #ifdef CONFIG_HARDIRQS_SW_RESEND |
| 76 | /* Set it pending and activate the softirq: */ | 75 | /* Set it pending and activate the softirq: */ |
| 77 | set_bit(irq, irqs_resend); | 76 | set_bit(irq, irqs_resend); |
diff --git a/kernel/irq/spurious.c b/kernel/irq/spurious.c index 4d568294de3e..114e704760fe 100644 --- a/kernel/irq/spurious.c +++ b/kernel/irq/spurious.c | |||
| @@ -297,7 +297,6 @@ static int __init irqfixup_setup(char *str) | |||
| 297 | 297 | ||
| 298 | __setup("irqfixup", irqfixup_setup); | 298 | __setup("irqfixup", irqfixup_setup); |
| 299 | module_param(irqfixup, int, 0644); | 299 | module_param(irqfixup, int, 0644); |
| 300 | MODULE_PARM_DESC("irqfixup", "0: No fixup, 1: irqfixup mode, 2: irqpoll mode"); | ||
| 301 | 300 | ||
| 302 | static int __init irqpoll_setup(char *str) | 301 | static int __init irqpoll_setup(char *str) |
| 303 | { | 302 | { |
diff --git a/kernel/kmod.c b/kernel/kmod.c index 385c31a1bdbf..9fcb53a11f87 100644 --- a/kernel/kmod.c +++ b/kernel/kmod.c | |||
| @@ -37,6 +37,8 @@ | |||
| 37 | #include <linux/suspend.h> | 37 | #include <linux/suspend.h> |
| 38 | #include <asm/uaccess.h> | 38 | #include <asm/uaccess.h> |
| 39 | 39 | ||
| 40 | #include <trace/events/module.h> | ||
| 41 | |||
| 40 | extern int max_threads; | 42 | extern int max_threads; |
| 41 | 43 | ||
| 42 | static struct workqueue_struct *khelper_wq; | 44 | static struct workqueue_struct *khelper_wq; |
| @@ -78,6 +80,10 @@ int __request_module(bool wait, const char *fmt, ...) | |||
| 78 | #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */ | 80 | #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */ |
| 79 | static int kmod_loop_msg; | 81 | static int kmod_loop_msg; |
| 80 | 82 | ||
| 83 | ret = security_kernel_module_request(); | ||
| 84 | if (ret) | ||
| 85 | return ret; | ||
| 86 | |||
| 81 | va_start(args, fmt); | 87 | va_start(args, fmt); |
| 82 | ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args); | 88 | ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args); |
| 83 | va_end(args); | 89 | va_end(args); |
| @@ -108,6 +114,8 @@ int __request_module(bool wait, const char *fmt, ...) | |||
| 108 | return -ENOMEM; | 114 | return -ENOMEM; |
| 109 | } | 115 | } |
| 110 | 116 | ||
| 117 | trace_module_request(module_name, wait, _RET_IP_); | ||
| 118 | |||
| 111 | ret = call_usermodehelper(modprobe_path, argv, envp, | 119 | ret = call_usermodehelper(modprobe_path, argv, envp, |
| 112 | wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC); | 120 | wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC); |
| 113 | atomic_dec(&kmod_concurrent); | 121 | atomic_dec(&kmod_concurrent); |
| @@ -462,6 +470,7 @@ int call_usermodehelper_exec(struct subprocess_info *sub_info, | |||
| 462 | int retval = 0; | 470 | int retval = 0; |
| 463 | 471 | ||
| 464 | BUG_ON(atomic_read(&sub_info->cred->usage) != 1); | 472 | BUG_ON(atomic_read(&sub_info->cred->usage) != 1); |
| 473 | validate_creds(sub_info->cred); | ||
| 465 | 474 | ||
| 466 | helper_lock(); | 475 | helper_lock(); |
| 467 | if (sub_info->path[0] == '\0') | 476 | if (sub_info->path[0] == '\0') |
diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 0540948e29ab..ef177d653b2c 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c | |||
| @@ -103,7 +103,7 @@ static struct kprobe_blackpoint kprobe_blacklist[] = { | |||
| 103 | #define INSNS_PER_PAGE (PAGE_SIZE/(MAX_INSN_SIZE * sizeof(kprobe_opcode_t))) | 103 | #define INSNS_PER_PAGE (PAGE_SIZE/(MAX_INSN_SIZE * sizeof(kprobe_opcode_t))) |
| 104 | 104 | ||
| 105 | struct kprobe_insn_page { | 105 | struct kprobe_insn_page { |
| 106 | struct hlist_node hlist; | 106 | struct list_head list; |
| 107 | kprobe_opcode_t *insns; /* Page of instruction slots */ | 107 | kprobe_opcode_t *insns; /* Page of instruction slots */ |
| 108 | char slot_used[INSNS_PER_PAGE]; | 108 | char slot_used[INSNS_PER_PAGE]; |
| 109 | int nused; | 109 | int nused; |
| @@ -117,7 +117,7 @@ enum kprobe_slot_state { | |||
| 117 | }; | 117 | }; |
| 118 | 118 | ||
| 119 | static DEFINE_MUTEX(kprobe_insn_mutex); /* Protects kprobe_insn_pages */ | 119 | static DEFINE_MUTEX(kprobe_insn_mutex); /* Protects kprobe_insn_pages */ |
| 120 | static struct hlist_head kprobe_insn_pages; | 120 | static LIST_HEAD(kprobe_insn_pages); |
| 121 | static int kprobe_garbage_slots; | 121 | static int kprobe_garbage_slots; |
| 122 | static int collect_garbage_slots(void); | 122 | static int collect_garbage_slots(void); |
| 123 | 123 | ||
| @@ -152,10 +152,9 @@ loop_end: | |||
| 152 | static kprobe_opcode_t __kprobes *__get_insn_slot(void) | 152 | static kprobe_opcode_t __kprobes *__get_insn_slot(void) |
| 153 | { | 153 | { |
| 154 | struct kprobe_insn_page *kip; | 154 | struct kprobe_insn_page *kip; |
| 155 | struct hlist_node *pos; | ||
| 156 | 155 | ||
| 157 | retry: | 156 | retry: |
| 158 | hlist_for_each_entry(kip, pos, &kprobe_insn_pages, hlist) { | 157 | list_for_each_entry(kip, &kprobe_insn_pages, list) { |
| 159 | if (kip->nused < INSNS_PER_PAGE) { | 158 | if (kip->nused < INSNS_PER_PAGE) { |
| 160 | int i; | 159 | int i; |
| 161 | for (i = 0; i < INSNS_PER_PAGE; i++) { | 160 | for (i = 0; i < INSNS_PER_PAGE; i++) { |
| @@ -189,8 +188,8 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(void) | |||
| 189 | kfree(kip); | 188 | kfree(kip); |
| 190 | return NULL; | 189 | return NULL; |
| 191 | } | 190 | } |
| 192 | INIT_HLIST_NODE(&kip->hlist); | 191 | INIT_LIST_HEAD(&kip->list); |
| 193 | hlist_add_head(&kip->hlist, &kprobe_insn_pages); | 192 | list_add(&kip->list, &kprobe_insn_pages); |
| 194 | memset(kip->slot_used, SLOT_CLEAN, INSNS_PER_PAGE); | 193 | memset(kip->slot_used, SLOT_CLEAN, INSNS_PER_PAGE); |
| 195 | kip->slot_used[0] = SLOT_USED; | 194 | kip->slot_used[0] = SLOT_USED; |
| 196 | kip->nused = 1; | 195 | kip->nused = 1; |
| @@ -219,12 +218,8 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx) | |||
| 219 | * so as not to have to set it up again the | 218 | * so as not to have to set it up again the |
| 220 | * next time somebody inserts a probe. | 219 | * next time somebody inserts a probe. |
| 221 | */ | 220 | */ |
| 222 | hlist_del(&kip->hlist); | 221 | if (!list_is_singular(&kprobe_insn_pages)) { |
| 223 | if (hlist_empty(&kprobe_insn_pages)) { | 222 | list_del(&kip->list); |
| 224 | INIT_HLIST_NODE(&kip->hlist); | ||
| 225 | hlist_add_head(&kip->hlist, | ||
| 226 | &kprobe_insn_pages); | ||
| 227 | } else { | ||
| 228 | module_free(NULL, kip->insns); | 223 | module_free(NULL, kip->insns); |
| 229 | kfree(kip); | 224 | kfree(kip); |
| 230 | } | 225 | } |
| @@ -235,14 +230,13 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx) | |||
| 235 | 230 | ||
| 236 | static int __kprobes collect_garbage_slots(void) | 231 | static int __kprobes collect_garbage_slots(void) |
| 237 | { | 232 | { |
| 238 | struct kprobe_insn_page *kip; | 233 | struct kprobe_insn_page *kip, *next; |
| 239 | struct hlist_node *pos, *next; | ||
| 240 | 234 | ||
| 241 | /* Ensure no-one is preepmted on the garbages */ | 235 | /* Ensure no-one is preepmted on the garbages */ |
| 242 | if (check_safety()) | 236 | if (check_safety()) |
| 243 | return -EAGAIN; | 237 | return -EAGAIN; |
| 244 | 238 | ||
| 245 | hlist_for_each_entry_safe(kip, pos, next, &kprobe_insn_pages, hlist) { | 239 | list_for_each_entry_safe(kip, next, &kprobe_insn_pages, list) { |
| 246 | int i; | 240 | int i; |
| 247 | if (kip->ngarbage == 0) | 241 | if (kip->ngarbage == 0) |
| 248 | continue; | 242 | continue; |
| @@ -260,19 +254,17 @@ static int __kprobes collect_garbage_slots(void) | |||
| 260 | void __kprobes free_insn_slot(kprobe_opcode_t * slot, int dirty) | 254 | void __kprobes free_insn_slot(kprobe_opcode_t * slot, int dirty) |
| 261 | { | 255 | { |
| 262 | struct kprobe_insn_page *kip; | 256 | struct kprobe_insn_page *kip; |
| 263 | struct hlist_node *pos; | ||
| 264 | 257 | ||
| 265 | mutex_lock(&kprobe_insn_mutex); | 258 | mutex_lock(&kprobe_insn_mutex); |
| 266 | hlist_for_each_entry(kip, pos, &kprobe_insn_pages, hlist) { | 259 | list_for_each_entry(kip, &kprobe_insn_pages, list) { |
| 267 | if (kip->insns <= slot && | 260 | if (kip->insns <= slot && |
| 268 | slot < kip->insns + (INSNS_PER_PAGE * MAX_INSN_SIZE)) { | 261 | slot < kip->insns + (INSNS_PER_PAGE * MAX_INSN_SIZE)) { |
| 269 | int i = (slot - kip->insns) / MAX_INSN_SIZE; | 262 | int i = (slot - kip->insns) / MAX_INSN_SIZE; |
| 270 | if (dirty) { | 263 | if (dirty) { |
| 271 | kip->slot_used[i] = SLOT_DIRTY; | 264 | kip->slot_used[i] = SLOT_DIRTY; |
| 272 | kip->ngarbage++; | 265 | kip->ngarbage++; |
| 273 | } else { | 266 | } else |
| 274 | collect_one_slot(kip, i); | 267 | collect_one_slot(kip, i); |
| 275 | } | ||
| 276 | break; | 268 | break; |
| 277 | } | 269 | } |
| 278 | } | 270 | } |
diff --git a/kernel/kthread.c b/kernel/kthread.c index eb8751aa0418..5fe709982caa 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c | |||
| @@ -16,8 +16,6 @@ | |||
| 16 | #include <linux/mutex.h> | 16 | #include <linux/mutex.h> |
| 17 | #include <trace/events/sched.h> | 17 | #include <trace/events/sched.h> |
| 18 | 18 | ||
| 19 | #define KTHREAD_NICE_LEVEL (-5) | ||
| 20 | |||
| 21 | static DEFINE_SPINLOCK(kthread_create_lock); | 19 | static DEFINE_SPINLOCK(kthread_create_lock); |
| 22 | static LIST_HEAD(kthread_create_list); | 20 | static LIST_HEAD(kthread_create_list); |
| 23 | struct task_struct *kthreadd_task; | 21 | struct task_struct *kthreadd_task; |
| @@ -145,7 +143,6 @@ struct task_struct *kthread_create(int (*threadfn)(void *data), | |||
| 145 | * The kernel thread should not inherit these properties. | 143 | * The kernel thread should not inherit these properties. |
| 146 | */ | 144 | */ |
| 147 | sched_setscheduler_nocheck(create.result, SCHED_NORMAL, ¶m); | 145 | sched_setscheduler_nocheck(create.result, SCHED_NORMAL, ¶m); |
| 148 | set_user_nice(create.result, KTHREAD_NICE_LEVEL); | ||
| 149 | set_cpus_allowed_ptr(create.result, cpu_all_mask); | 146 | set_cpus_allowed_ptr(create.result, cpu_all_mask); |
| 150 | } | 147 | } |
| 151 | return create.result; | 148 | return create.result; |
| @@ -221,7 +218,6 @@ int kthreadd(void *unused) | |||
| 221 | /* Setup a clean context for our children to inherit. */ | 218 | /* Setup a clean context for our children to inherit. */ |
| 222 | set_task_comm(tsk, "kthreadd"); | 219 | set_task_comm(tsk, "kthreadd"); |
| 223 | ignore_signals(tsk); | 220 | ignore_signals(tsk); |
| 224 | set_user_nice(tsk, KTHREAD_NICE_LEVEL); | ||
| 225 | set_cpus_allowed_ptr(tsk, cpu_all_mask); | 221 | set_cpus_allowed_ptr(tsk, cpu_all_mask); |
| 226 | set_mems_allowed(node_possible_map); | 222 | set_mems_allowed(node_possible_map); |
| 227 | 223 | ||
diff --git a/kernel/lockdep.c b/kernel/lockdep.c index 8bbeef996c76..f74d2d7aa605 100644 --- a/kernel/lockdep.c +++ b/kernel/lockdep.c | |||
| @@ -42,6 +42,7 @@ | |||
| 42 | #include <linux/hash.h> | 42 | #include <linux/hash.h> |
| 43 | #include <linux/ftrace.h> | 43 | #include <linux/ftrace.h> |
| 44 | #include <linux/stringify.h> | 44 | #include <linux/stringify.h> |
| 45 | #include <linux/bitops.h> | ||
| 45 | 46 | ||
| 46 | #include <asm/sections.h> | 47 | #include <asm/sections.h> |
| 47 | 48 | ||
| @@ -366,11 +367,21 @@ static int save_trace(struct stack_trace *trace) | |||
| 366 | 367 | ||
| 367 | save_stack_trace(trace); | 368 | save_stack_trace(trace); |
| 368 | 369 | ||
| 370 | /* | ||
| 371 | * Some daft arches put -1 at the end to indicate its a full trace. | ||
| 372 | * | ||
| 373 | * <rant> this is buggy anyway, since it takes a whole extra entry so a | ||
| 374 | * complete trace that maxes out the entries provided will be reported | ||
| 375 | * as incomplete, friggin useless </rant> | ||
| 376 | */ | ||
| 377 | if (trace->entries[trace->nr_entries-1] == ULONG_MAX) | ||
| 378 | trace->nr_entries--; | ||
| 379 | |||
| 369 | trace->max_entries = trace->nr_entries; | 380 | trace->max_entries = trace->nr_entries; |
| 370 | 381 | ||
| 371 | nr_stack_trace_entries += trace->nr_entries; | 382 | nr_stack_trace_entries += trace->nr_entries; |
| 372 | 383 | ||
| 373 | if (nr_stack_trace_entries == MAX_STACK_TRACE_ENTRIES) { | 384 | if (nr_stack_trace_entries >= MAX_STACK_TRACE_ENTRIES-1) { |
| 374 | if (!debug_locks_off_graph_unlock()) | 385 | if (!debug_locks_off_graph_unlock()) |
| 375 | return 0; | 386 | return 0; |
| 376 | 387 | ||
| @@ -388,20 +399,6 @@ unsigned int nr_hardirq_chains; | |||
| 388 | unsigned int nr_softirq_chains; | 399 | unsigned int nr_softirq_chains; |
| 389 | unsigned int nr_process_chains; | 400 | unsigned int nr_process_chains; |
| 390 | unsigned int max_lockdep_depth; | 401 | unsigned int max_lockdep_depth; |
| 391 | unsigned int max_recursion_depth; | ||
| 392 | |||
| 393 | static unsigned int lockdep_dependency_gen_id; | ||
| 394 | |||
| 395 | static bool lockdep_dependency_visit(struct lock_class *source, | ||
| 396 | unsigned int depth) | ||
| 397 | { | ||
| 398 | if (!depth) | ||
| 399 | lockdep_dependency_gen_id++; | ||
| 400 | if (source->dep_gen_id == lockdep_dependency_gen_id) | ||
| 401 | return true; | ||
| 402 | source->dep_gen_id = lockdep_dependency_gen_id; | ||
| 403 | return false; | ||
| 404 | } | ||
| 405 | 402 | ||
| 406 | #ifdef CONFIG_DEBUG_LOCKDEP | 403 | #ifdef CONFIG_DEBUG_LOCKDEP |
| 407 | /* | 404 | /* |
| @@ -431,11 +428,8 @@ atomic_t redundant_softirqs_on; | |||
| 431 | atomic_t redundant_softirqs_off; | 428 | atomic_t redundant_softirqs_off; |
| 432 | atomic_t nr_unused_locks; | 429 | atomic_t nr_unused_locks; |
| 433 | atomic_t nr_cyclic_checks; | 430 | atomic_t nr_cyclic_checks; |
| 434 | atomic_t nr_cyclic_check_recursions; | ||
| 435 | atomic_t nr_find_usage_forwards_checks; | 431 | atomic_t nr_find_usage_forwards_checks; |
| 436 | atomic_t nr_find_usage_forwards_recursions; | ||
| 437 | atomic_t nr_find_usage_backwards_checks; | 432 | atomic_t nr_find_usage_backwards_checks; |
| 438 | atomic_t nr_find_usage_backwards_recursions; | ||
| 439 | #endif | 433 | #endif |
| 440 | 434 | ||
| 441 | /* | 435 | /* |
| @@ -551,58 +545,6 @@ static void lockdep_print_held_locks(struct task_struct *curr) | |||
| 551 | } | 545 | } |
| 552 | } | 546 | } |
| 553 | 547 | ||
| 554 | static void print_lock_class_header(struct lock_class *class, int depth) | ||
| 555 | { | ||
| 556 | int bit; | ||
| 557 | |||
| 558 | printk("%*s->", depth, ""); | ||
| 559 | print_lock_name(class); | ||
| 560 | printk(" ops: %lu", class->ops); | ||
| 561 | printk(" {\n"); | ||
| 562 | |||
| 563 | for (bit = 0; bit < LOCK_USAGE_STATES; bit++) { | ||
| 564 | if (class->usage_mask & (1 << bit)) { | ||
| 565 | int len = depth; | ||
| 566 | |||
| 567 | len += printk("%*s %s", depth, "", usage_str[bit]); | ||
| 568 | len += printk(" at:\n"); | ||
| 569 | print_stack_trace(class->usage_traces + bit, len); | ||
| 570 | } | ||
| 571 | } | ||
| 572 | printk("%*s }\n", depth, ""); | ||
| 573 | |||
| 574 | printk("%*s ... key at: ",depth,""); | ||
| 575 | print_ip_sym((unsigned long)class->key); | ||
| 576 | } | ||
| 577 | |||
| 578 | /* | ||
| 579 | * printk all lock dependencies starting at <entry>: | ||
| 580 | */ | ||
| 581 | static void __used | ||
| 582 | print_lock_dependencies(struct lock_class *class, int depth) | ||
| 583 | { | ||
| 584 | struct lock_list *entry; | ||
| 585 | |||
| 586 | if (lockdep_dependency_visit(class, depth)) | ||
| 587 | return; | ||
| 588 | |||
| 589 | if (DEBUG_LOCKS_WARN_ON(depth >= 20)) | ||
| 590 | return; | ||
| 591 | |||
| 592 | print_lock_class_header(class, depth); | ||
| 593 | |||
| 594 | list_for_each_entry(entry, &class->locks_after, entry) { | ||
| 595 | if (DEBUG_LOCKS_WARN_ON(!entry->class)) | ||
| 596 | return; | ||
| 597 | |||
| 598 | print_lock_dependencies(entry->class, depth + 1); | ||
| 599 | |||
| 600 | printk("%*s ... acquired at:\n",depth,""); | ||
| 601 | print_stack_trace(&entry->trace, 2); | ||
| 602 | printk("\n"); | ||
| 603 | } | ||
| 604 | } | ||
| 605 | |||
| 606 | static void print_kernel_version(void) | 548 | static void print_kernel_version(void) |
| 607 | { | 549 | { |
| 608 | printk("%s %.*s\n", init_utsname()->release, | 550 | printk("%s %.*s\n", init_utsname()->release, |
| @@ -898,22 +840,203 @@ static int add_lock_to_list(struct lock_class *class, struct lock_class *this, | |||
| 898 | } | 840 | } |
| 899 | 841 | ||
| 900 | /* | 842 | /* |
| 843 | * For good efficiency of modular, we use power of 2 | ||
| 844 | */ | ||
| 845 | #define MAX_CIRCULAR_QUEUE_SIZE 4096UL | ||
| 846 | #define CQ_MASK (MAX_CIRCULAR_QUEUE_SIZE-1) | ||
| 847 | |||
| 848 | /* | ||
| 849 | * The circular_queue and helpers is used to implement the | ||
| 850 | * breadth-first search(BFS)algorithem, by which we can build | ||
| 851 | * the shortest path from the next lock to be acquired to the | ||
| 852 | * previous held lock if there is a circular between them. | ||
| 853 | */ | ||
| 854 | struct circular_queue { | ||
| 855 | unsigned long element[MAX_CIRCULAR_QUEUE_SIZE]; | ||
| 856 | unsigned int front, rear; | ||
| 857 | }; | ||
| 858 | |||
| 859 | static struct circular_queue lock_cq; | ||
| 860 | |||
| 861 | unsigned int max_bfs_queue_depth; | ||
| 862 | |||
| 863 | static unsigned int lockdep_dependency_gen_id; | ||
| 864 | |||
| 865 | static inline void __cq_init(struct circular_queue *cq) | ||
| 866 | { | ||
| 867 | cq->front = cq->rear = 0; | ||
| 868 | lockdep_dependency_gen_id++; | ||
| 869 | } | ||
| 870 | |||
| 871 | static inline int __cq_empty(struct circular_queue *cq) | ||
| 872 | { | ||
| 873 | return (cq->front == cq->rear); | ||
| 874 | } | ||
| 875 | |||
| 876 | static inline int __cq_full(struct circular_queue *cq) | ||
| 877 | { | ||
| 878 | return ((cq->rear + 1) & CQ_MASK) == cq->front; | ||
| 879 | } | ||
| 880 | |||
| 881 | static inline int __cq_enqueue(struct circular_queue *cq, unsigned long elem) | ||
| 882 | { | ||
| 883 | if (__cq_full(cq)) | ||
| 884 | return -1; | ||
| 885 | |||
| 886 | cq->element[cq->rear] = elem; | ||
| 887 | cq->rear = (cq->rear + 1) & CQ_MASK; | ||
| 888 | return 0; | ||
| 889 | } | ||
| 890 | |||
| 891 | static inline int __cq_dequeue(struct circular_queue *cq, unsigned long *elem) | ||
| 892 | { | ||
| 893 | if (__cq_empty(cq)) | ||
| 894 | return -1; | ||
| 895 | |||
| 896 | *elem = cq->element[cq->front]; | ||
| 897 | cq->front = (cq->front + 1) & CQ_MASK; | ||
| 898 | return 0; | ||
| 899 | } | ||
| 900 | |||
| 901 | static inline unsigned int __cq_get_elem_count(struct circular_queue *cq) | ||
| 902 | { | ||
| 903 | return (cq->rear - cq->front) & CQ_MASK; | ||
| 904 | } | ||
| 905 | |||
| 906 | static inline void mark_lock_accessed(struct lock_list *lock, | ||
| 907 | struct lock_list *parent) | ||
| 908 | { | ||
| 909 | unsigned long nr; | ||
| 910 | |||
| 911 | nr = lock - list_entries; | ||
| 912 | WARN_ON(nr >= nr_list_entries); | ||
| 913 | lock->parent = parent; | ||
| 914 | lock->class->dep_gen_id = lockdep_dependency_gen_id; | ||
| 915 | } | ||
| 916 | |||
| 917 | static inline unsigned long lock_accessed(struct lock_list *lock) | ||
| 918 | { | ||
| 919 | unsigned long nr; | ||
| 920 | |||
| 921 | nr = lock - list_entries; | ||
| 922 | WARN_ON(nr >= nr_list_entries); | ||
| 923 | return lock->class->dep_gen_id == lockdep_dependency_gen_id; | ||
| 924 | } | ||
| 925 | |||
| 926 | static inline struct lock_list *get_lock_parent(struct lock_list *child) | ||
| 927 | { | ||
| 928 | return child->parent; | ||
| 929 | } | ||
| 930 | |||
| 931 | static inline int get_lock_depth(struct lock_list *child) | ||
| 932 | { | ||
| 933 | int depth = 0; | ||
| 934 | struct lock_list *parent; | ||
| 935 | |||
| 936 | while ((parent = get_lock_parent(child))) { | ||
| 937 | child = parent; | ||
| 938 | depth++; | ||
| 939 | } | ||
| 940 | return depth; | ||
| 941 | } | ||
| 942 | |||
| 943 | static int __bfs(struct lock_list *source_entry, | ||
| 944 | void *data, | ||
| 945 | int (*match)(struct lock_list *entry, void *data), | ||
| 946 | struct lock_list **target_entry, | ||
| 947 | int forward) | ||
| 948 | { | ||
| 949 | struct lock_list *entry; | ||
| 950 | struct list_head *head; | ||
| 951 | struct circular_queue *cq = &lock_cq; | ||
| 952 | int ret = 1; | ||
| 953 | |||
| 954 | if (match(source_entry, data)) { | ||
| 955 | *target_entry = source_entry; | ||
| 956 | ret = 0; | ||
| 957 | goto exit; | ||
| 958 | } | ||
| 959 | |||
| 960 | if (forward) | ||
| 961 | head = &source_entry->class->locks_after; | ||
| 962 | else | ||
| 963 | head = &source_entry->class->locks_before; | ||
| 964 | |||
| 965 | if (list_empty(head)) | ||
| 966 | goto exit; | ||
| 967 | |||
| 968 | __cq_init(cq); | ||
| 969 | __cq_enqueue(cq, (unsigned long)source_entry); | ||
| 970 | |||
| 971 | while (!__cq_empty(cq)) { | ||
| 972 | struct lock_list *lock; | ||
| 973 | |||
| 974 | __cq_dequeue(cq, (unsigned long *)&lock); | ||
| 975 | |||
| 976 | if (!lock->class) { | ||
| 977 | ret = -2; | ||
| 978 | goto exit; | ||
| 979 | } | ||
| 980 | |||
| 981 | if (forward) | ||
| 982 | head = &lock->class->locks_after; | ||
| 983 | else | ||
| 984 | head = &lock->class->locks_before; | ||
| 985 | |||
| 986 | list_for_each_entry(entry, head, entry) { | ||
| 987 | if (!lock_accessed(entry)) { | ||
| 988 | unsigned int cq_depth; | ||
| 989 | mark_lock_accessed(entry, lock); | ||
| 990 | if (match(entry, data)) { | ||
| 991 | *target_entry = entry; | ||
| 992 | ret = 0; | ||
| 993 | goto exit; | ||
| 994 | } | ||
| 995 | |||
| 996 | if (__cq_enqueue(cq, (unsigned long)entry)) { | ||
| 997 | ret = -1; | ||
| 998 | goto exit; | ||
| 999 | } | ||
| 1000 | cq_depth = __cq_get_elem_count(cq); | ||
| 1001 | if (max_bfs_queue_depth < cq_depth) | ||
| 1002 | max_bfs_queue_depth = cq_depth; | ||
| 1003 | } | ||
| 1004 | } | ||
| 1005 | } | ||
| 1006 | exit: | ||
| 1007 | return ret; | ||
| 1008 | } | ||
| 1009 | |||
| 1010 | static inline int __bfs_forwards(struct lock_list *src_entry, | ||
| 1011 | void *data, | ||
| 1012 | int (*match)(struct lock_list *entry, void *data), | ||
| 1013 | struct lock_list **target_entry) | ||
| 1014 | { | ||
| 1015 | return __bfs(src_entry, data, match, target_entry, 1); | ||
| 1016 | |||
| 1017 | } | ||
| 1018 | |||
| 1019 | static inline int __bfs_backwards(struct lock_list *src_entry, | ||
| 1020 | void *data, | ||
| 1021 | int (*match)(struct lock_list *entry, void *data), | ||
| 1022 | struct lock_list **target_entry) | ||
| 1023 | { | ||
| 1024 | return __bfs(src_entry, data, match, target_entry, 0); | ||
| 1025 | |||
| 1026 | } | ||
| 1027 | |||
| 1028 | /* | ||
| 901 | * Recursive, forwards-direction lock-dependency checking, used for | 1029 | * Recursive, forwards-direction lock-dependency checking, used for |
| 902 | * both noncyclic checking and for hardirq-unsafe/softirq-unsafe | 1030 | * both noncyclic checking and for hardirq-unsafe/softirq-unsafe |
| 903 | * checking. | 1031 | * checking. |
| 904 | * | ||
| 905 | * (to keep the stackframe of the recursive functions small we | ||
| 906 | * use these global variables, and we also mark various helper | ||
| 907 | * functions as noinline.) | ||
| 908 | */ | 1032 | */ |
| 909 | static struct held_lock *check_source, *check_target; | ||
| 910 | 1033 | ||
| 911 | /* | 1034 | /* |
| 912 | * Print a dependency chain entry (this is only done when a deadlock | 1035 | * Print a dependency chain entry (this is only done when a deadlock |
| 913 | * has been detected): | 1036 | * has been detected): |
| 914 | */ | 1037 | */ |
| 915 | static noinline int | 1038 | static noinline int |
| 916 | print_circular_bug_entry(struct lock_list *target, unsigned int depth) | 1039 | print_circular_bug_entry(struct lock_list *target, int depth) |
| 917 | { | 1040 | { |
| 918 | if (debug_locks_silent) | 1041 | if (debug_locks_silent) |
| 919 | return 0; | 1042 | return 0; |
| @@ -930,11 +1053,13 @@ print_circular_bug_entry(struct lock_list *target, unsigned int depth) | |||
| 930 | * header first: | 1053 | * header first: |
| 931 | */ | 1054 | */ |
| 932 | static noinline int | 1055 | static noinline int |
| 933 | print_circular_bug_header(struct lock_list *entry, unsigned int depth) | 1056 | print_circular_bug_header(struct lock_list *entry, unsigned int depth, |
| 1057 | struct held_lock *check_src, | ||
| 1058 | struct held_lock *check_tgt) | ||
| 934 | { | 1059 | { |
| 935 | struct task_struct *curr = current; | 1060 | struct task_struct *curr = current; |
| 936 | 1061 | ||
| 937 | if (!debug_locks_off_graph_unlock() || debug_locks_silent) | 1062 | if (debug_locks_silent) |
| 938 | return 0; | 1063 | return 0; |
| 939 | 1064 | ||
| 940 | printk("\n=======================================================\n"); | 1065 | printk("\n=======================================================\n"); |
| @@ -943,9 +1068,9 @@ print_circular_bug_header(struct lock_list *entry, unsigned int depth) | |||
| 943 | printk( "-------------------------------------------------------\n"); | 1068 | printk( "-------------------------------------------------------\n"); |
| 944 | printk("%s/%d is trying to acquire lock:\n", | 1069 | printk("%s/%d is trying to acquire lock:\n", |
| 945 | curr->comm, task_pid_nr(curr)); | 1070 | curr->comm, task_pid_nr(curr)); |
| 946 | print_lock(check_source); | 1071 | print_lock(check_src); |
| 947 | printk("\nbut task is already holding lock:\n"); | 1072 | printk("\nbut task is already holding lock:\n"); |
| 948 | print_lock(check_target); | 1073 | print_lock(check_tgt); |
| 949 | printk("\nwhich lock already depends on the new lock.\n\n"); | 1074 | printk("\nwhich lock already depends on the new lock.\n\n"); |
| 950 | printk("\nthe existing dependency chain (in reverse order) is:\n"); | 1075 | printk("\nthe existing dependency chain (in reverse order) is:\n"); |
| 951 | 1076 | ||
| @@ -954,19 +1079,36 @@ print_circular_bug_header(struct lock_list *entry, unsigned int depth) | |||
| 954 | return 0; | 1079 | return 0; |
| 955 | } | 1080 | } |
| 956 | 1081 | ||
| 957 | static noinline int print_circular_bug_tail(void) | 1082 | static inline int class_equal(struct lock_list *entry, void *data) |
| 1083 | { | ||
| 1084 | return entry->class == data; | ||
| 1085 | } | ||
| 1086 | |||
| 1087 | static noinline int print_circular_bug(struct lock_list *this, | ||
| 1088 | struct lock_list *target, | ||
| 1089 | struct held_lock *check_src, | ||
| 1090 | struct held_lock *check_tgt) | ||
| 958 | { | 1091 | { |
| 959 | struct task_struct *curr = current; | 1092 | struct task_struct *curr = current; |
| 960 | struct lock_list this; | 1093 | struct lock_list *parent; |
| 1094 | int depth; | ||
| 961 | 1095 | ||
| 962 | if (debug_locks_silent) | 1096 | if (!debug_locks_off_graph_unlock() || debug_locks_silent) |
| 963 | return 0; | 1097 | return 0; |
| 964 | 1098 | ||
| 965 | this.class = hlock_class(check_source); | 1099 | if (!save_trace(&this->trace)) |
| 966 | if (!save_trace(&this.trace)) | ||
| 967 | return 0; | 1100 | return 0; |
| 968 | 1101 | ||
| 969 | print_circular_bug_entry(&this, 0); | 1102 | depth = get_lock_depth(target); |
| 1103 | |||
| 1104 | print_circular_bug_header(target, depth, check_src, check_tgt); | ||
| 1105 | |||
| 1106 | parent = get_lock_parent(target); | ||
| 1107 | |||
| 1108 | while (parent) { | ||
| 1109 | print_circular_bug_entry(parent, --depth); | ||
| 1110 | parent = get_lock_parent(parent); | ||
| 1111 | } | ||
| 970 | 1112 | ||
| 971 | printk("\nother info that might help us debug this:\n\n"); | 1113 | printk("\nother info that might help us debug this:\n\n"); |
| 972 | lockdep_print_held_locks(curr); | 1114 | lockdep_print_held_locks(curr); |
| @@ -977,73 +1119,69 @@ static noinline int print_circular_bug_tail(void) | |||
| 977 | return 0; | 1119 | return 0; |
| 978 | } | 1120 | } |
| 979 | 1121 | ||
| 980 | #define RECURSION_LIMIT 40 | 1122 | static noinline int print_bfs_bug(int ret) |
| 981 | |||
| 982 | static int noinline print_infinite_recursion_bug(void) | ||
| 983 | { | 1123 | { |
| 984 | if (!debug_locks_off_graph_unlock()) | 1124 | if (!debug_locks_off_graph_unlock()) |
| 985 | return 0; | 1125 | return 0; |
| 986 | 1126 | ||
| 987 | WARN_ON(1); | 1127 | WARN(1, "lockdep bfs error:%d\n", ret); |
| 988 | 1128 | ||
| 989 | return 0; | 1129 | return 0; |
| 990 | } | 1130 | } |
| 991 | 1131 | ||
| 992 | unsigned long __lockdep_count_forward_deps(struct lock_class *class, | 1132 | static int noop_count(struct lock_list *entry, void *data) |
| 993 | unsigned int depth) | ||
| 994 | { | 1133 | { |
| 995 | struct lock_list *entry; | 1134 | (*(unsigned long *)data)++; |
| 996 | unsigned long ret = 1; | 1135 | return 0; |
| 1136 | } | ||
| 997 | 1137 | ||
| 998 | if (lockdep_dependency_visit(class, depth)) | 1138 | unsigned long __lockdep_count_forward_deps(struct lock_list *this) |
| 999 | return 0; | 1139 | { |
| 1140 | unsigned long count = 0; | ||
| 1141 | struct lock_list *uninitialized_var(target_entry); | ||
| 1000 | 1142 | ||
| 1001 | /* | 1143 | __bfs_forwards(this, (void *)&count, noop_count, &target_entry); |
| 1002 | * Recurse this class's dependency list: | ||
| 1003 | */ | ||
| 1004 | list_for_each_entry(entry, &class->locks_after, entry) | ||
| 1005 | ret += __lockdep_count_forward_deps(entry->class, depth + 1); | ||
| 1006 | 1144 | ||
| 1007 | return ret; | 1145 | return count; |
| 1008 | } | 1146 | } |
| 1009 | |||
| 1010 | unsigned long lockdep_count_forward_deps(struct lock_class *class) | 1147 | unsigned long lockdep_count_forward_deps(struct lock_class *class) |
| 1011 | { | 1148 | { |
| 1012 | unsigned long ret, flags; | 1149 | unsigned long ret, flags; |
| 1150 | struct lock_list this; | ||
| 1151 | |||
| 1152 | this.parent = NULL; | ||
| 1153 | this.class = class; | ||
| 1013 | 1154 | ||
| 1014 | local_irq_save(flags); | 1155 | local_irq_save(flags); |
| 1015 | __raw_spin_lock(&lockdep_lock); | 1156 | __raw_spin_lock(&lockdep_lock); |
| 1016 | ret = __lockdep_count_forward_deps(class, 0); | 1157 | ret = __lockdep_count_forward_deps(&this); |
| 1017 | __raw_spin_unlock(&lockdep_lock); | 1158 | __raw_spin_unlock(&lockdep_lock); |
| 1018 | local_irq_restore(flags); | 1159 | local_irq_restore(flags); |
| 1019 | 1160 | ||
| 1020 | return ret; | 1161 | return ret; |
| 1021 | } | 1162 | } |
| 1022 | 1163 | ||
| 1023 | unsigned long __lockdep_count_backward_deps(struct lock_class *class, | 1164 | unsigned long __lockdep_count_backward_deps(struct lock_list *this) |
| 1024 | unsigned int depth) | ||
| 1025 | { | 1165 | { |
| 1026 | struct lock_list *entry; | 1166 | unsigned long count = 0; |
| 1027 | unsigned long ret = 1; | 1167 | struct lock_list *uninitialized_var(target_entry); |
| 1028 | 1168 | ||
| 1029 | if (lockdep_dependency_visit(class, depth)) | 1169 | __bfs_backwards(this, (void *)&count, noop_count, &target_entry); |
| 1030 | return 0; | ||
| 1031 | /* | ||
| 1032 | * Recurse this class's dependency list: | ||
| 1033 | */ | ||
| 1034 | list_for_each_entry(entry, &class->locks_before, entry) | ||
| 1035 | ret += __lockdep_count_backward_deps(entry->class, depth + 1); | ||
| 1036 | 1170 | ||
| 1037 | return ret; | 1171 | return count; |
| 1038 | } | 1172 | } |
| 1039 | 1173 | ||
| 1040 | unsigned long lockdep_count_backward_deps(struct lock_class *class) | 1174 | unsigned long lockdep_count_backward_deps(struct lock_class *class) |
| 1041 | { | 1175 | { |
| 1042 | unsigned long ret, flags; | 1176 | unsigned long ret, flags; |
| 1177 | struct lock_list this; | ||
| 1178 | |||
| 1179 | this.parent = NULL; | ||
| 1180 | this.class = class; | ||
| 1043 | 1181 | ||
| 1044 | local_irq_save(flags); | 1182 | local_irq_save(flags); |
| 1045 | __raw_spin_lock(&lockdep_lock); | 1183 | __raw_spin_lock(&lockdep_lock); |
| 1046 | ret = __lockdep_count_backward_deps(class, 0); | 1184 | ret = __lockdep_count_backward_deps(&this); |
| 1047 | __raw_spin_unlock(&lockdep_lock); | 1185 | __raw_spin_unlock(&lockdep_lock); |
| 1048 | local_irq_restore(flags); | 1186 | local_irq_restore(flags); |
| 1049 | 1187 | ||
| @@ -1055,29 +1193,16 @@ unsigned long lockdep_count_backward_deps(struct lock_class *class) | |||
| 1055 | * lead to <target>. Print an error and return 0 if it does. | 1193 | * lead to <target>. Print an error and return 0 if it does. |
| 1056 | */ | 1194 | */ |
| 1057 | static noinline int | 1195 | static noinline int |
| 1058 | check_noncircular(struct lock_class *source, unsigned int depth) | 1196 | check_noncircular(struct lock_list *root, struct lock_class *target, |
| 1197 | struct lock_list **target_entry) | ||
| 1059 | { | 1198 | { |
| 1060 | struct lock_list *entry; | 1199 | int result; |
| 1061 | 1200 | ||
| 1062 | if (lockdep_dependency_visit(source, depth)) | 1201 | debug_atomic_inc(&nr_cyclic_checks); |
| 1063 | return 1; | ||
| 1064 | 1202 | ||
| 1065 | debug_atomic_inc(&nr_cyclic_check_recursions); | 1203 | result = __bfs_forwards(root, target, class_equal, target_entry); |
| 1066 | if (depth > max_recursion_depth) | 1204 | |
| 1067 | max_recursion_depth = depth; | 1205 | return result; |
| 1068 | if (depth >= RECURSION_LIMIT) | ||
| 1069 | return print_infinite_recursion_bug(); | ||
| 1070 | /* | ||
| 1071 | * Check this lock's dependency list: | ||
| 1072 | */ | ||
| 1073 | list_for_each_entry(entry, &source->locks_after, entry) { | ||
| 1074 | if (entry->class == hlock_class(check_target)) | ||
| 1075 | return print_circular_bug_header(entry, depth+1); | ||
| 1076 | debug_atomic_inc(&nr_cyclic_checks); | ||
| 1077 | if (!check_noncircular(entry->class, depth+1)) | ||
| 1078 | return print_circular_bug_entry(entry, depth+1); | ||
| 1079 | } | ||
| 1080 | return 1; | ||
| 1081 | } | 1206 | } |
| 1082 | 1207 | ||
| 1083 | #if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_PROVE_LOCKING) | 1208 | #if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_PROVE_LOCKING) |
| @@ -1086,103 +1211,121 @@ check_noncircular(struct lock_class *source, unsigned int depth) | |||
| 1086 | * proving that two subgraphs can be connected by a new dependency | 1211 | * proving that two subgraphs can be connected by a new dependency |
| 1087 | * without creating any illegal irq-safe -> irq-unsafe lock dependency. | 1212 | * without creating any illegal irq-safe -> irq-unsafe lock dependency. |
| 1088 | */ | 1213 | */ |
| 1089 | static enum lock_usage_bit find_usage_bit; | 1214 | |
| 1090 | static struct lock_class *forwards_match, *backwards_match; | 1215 | static inline int usage_match(struct lock_list *entry, void *bit) |
| 1216 | { | ||
| 1217 | return entry->class->usage_mask & (1 << (enum lock_usage_bit)bit); | ||
| 1218 | } | ||
| 1219 | |||
| 1220 | |||
| 1091 | 1221 | ||
| 1092 | /* | 1222 | /* |
| 1093 | * Find a node in the forwards-direction dependency sub-graph starting | 1223 | * Find a node in the forwards-direction dependency sub-graph starting |
| 1094 | * at <source> that matches <find_usage_bit>. | 1224 | * at @root->class that matches @bit. |
| 1095 | * | 1225 | * |
| 1096 | * Return 2 if such a node exists in the subgraph, and put that node | 1226 | * Return 0 if such a node exists in the subgraph, and put that node |
| 1097 | * into <forwards_match>. | 1227 | * into *@target_entry. |
| 1098 | * | 1228 | * |
| 1099 | * Return 1 otherwise and keep <forwards_match> unchanged. | 1229 | * Return 1 otherwise and keep *@target_entry unchanged. |
| 1100 | * Return 0 on error. | 1230 | * Return <0 on error. |
| 1101 | */ | 1231 | */ |
| 1102 | static noinline int | 1232 | static int |
| 1103 | find_usage_forwards(struct lock_class *source, unsigned int depth) | 1233 | find_usage_forwards(struct lock_list *root, enum lock_usage_bit bit, |
| 1234 | struct lock_list **target_entry) | ||
| 1104 | { | 1235 | { |
| 1105 | struct lock_list *entry; | 1236 | int result; |
| 1106 | int ret; | ||
| 1107 | |||
| 1108 | if (lockdep_dependency_visit(source, depth)) | ||
| 1109 | return 1; | ||
| 1110 | |||
| 1111 | if (depth > max_recursion_depth) | ||
| 1112 | max_recursion_depth = depth; | ||
| 1113 | if (depth >= RECURSION_LIMIT) | ||
| 1114 | return print_infinite_recursion_bug(); | ||
| 1115 | 1237 | ||
| 1116 | debug_atomic_inc(&nr_find_usage_forwards_checks); | 1238 | debug_atomic_inc(&nr_find_usage_forwards_checks); |
| 1117 | if (source->usage_mask & (1 << find_usage_bit)) { | ||
| 1118 | forwards_match = source; | ||
| 1119 | return 2; | ||
| 1120 | } | ||
| 1121 | 1239 | ||
| 1122 | /* | 1240 | result = __bfs_forwards(root, (void *)bit, usage_match, target_entry); |
| 1123 | * Check this lock's dependency list: | 1241 | |
| 1124 | */ | 1242 | return result; |
| 1125 | list_for_each_entry(entry, &source->locks_after, entry) { | ||
| 1126 | debug_atomic_inc(&nr_find_usage_forwards_recursions); | ||
| 1127 | ret = find_usage_forwards(entry->class, depth+1); | ||
| 1128 | if (ret == 2 || ret == 0) | ||
| 1129 | return ret; | ||
| 1130 | } | ||
| 1131 | return 1; | ||
| 1132 | } | 1243 | } |
| 1133 | 1244 | ||
| 1134 | /* | 1245 | /* |
| 1135 | * Find a node in the backwards-direction dependency sub-graph starting | 1246 | * Find a node in the backwards-direction dependency sub-graph starting |
| 1136 | * at <source> that matches <find_usage_bit>. | 1247 | * at @root->class that matches @bit. |
| 1137 | * | 1248 | * |
| 1138 | * Return 2 if such a node exists in the subgraph, and put that node | 1249 | * Return 0 if such a node exists in the subgraph, and put that node |
| 1139 | * into <backwards_match>. | 1250 | * into *@target_entry. |
| 1140 | * | 1251 | * |
| 1141 | * Return 1 otherwise and keep <backwards_match> unchanged. | 1252 | * Return 1 otherwise and keep *@target_entry unchanged. |
| 1142 | * Return 0 on error. | 1253 | * Return <0 on error. |
| 1143 | */ | 1254 | */ |
| 1144 | static noinline int | 1255 | static int |
| 1145 | find_usage_backwards(struct lock_class *source, unsigned int depth) | 1256 | find_usage_backwards(struct lock_list *root, enum lock_usage_bit bit, |
| 1257 | struct lock_list **target_entry) | ||
| 1146 | { | 1258 | { |
| 1147 | struct lock_list *entry; | 1259 | int result; |
| 1148 | int ret; | ||
| 1149 | 1260 | ||
| 1150 | if (lockdep_dependency_visit(source, depth)) | 1261 | debug_atomic_inc(&nr_find_usage_backwards_checks); |
| 1151 | return 1; | ||
| 1152 | 1262 | ||
| 1153 | if (!__raw_spin_is_locked(&lockdep_lock)) | 1263 | result = __bfs_backwards(root, (void *)bit, usage_match, target_entry); |
| 1154 | return DEBUG_LOCKS_WARN_ON(1); | ||
| 1155 | 1264 | ||
| 1156 | if (depth > max_recursion_depth) | 1265 | return result; |
| 1157 | max_recursion_depth = depth; | 1266 | } |
| 1158 | if (depth >= RECURSION_LIMIT) | ||
| 1159 | return print_infinite_recursion_bug(); | ||
| 1160 | 1267 | ||
| 1161 | debug_atomic_inc(&nr_find_usage_backwards_checks); | 1268 | static void print_lock_class_header(struct lock_class *class, int depth) |
| 1162 | if (source->usage_mask & (1 << find_usage_bit)) { | 1269 | { |
| 1163 | backwards_match = source; | 1270 | int bit; |
| 1164 | return 2; | ||
| 1165 | } | ||
| 1166 | 1271 | ||
| 1167 | if (!source && debug_locks_off_graph_unlock()) { | 1272 | printk("%*s->", depth, ""); |
| 1168 | WARN_ON(1); | 1273 | print_lock_name(class); |
| 1169 | return 0; | 1274 | printk(" ops: %lu", class->ops); |
| 1170 | } | 1275 | printk(" {\n"); |
| 1171 | 1276 | ||
| 1172 | /* | 1277 | for (bit = 0; bit < LOCK_USAGE_STATES; bit++) { |
| 1173 | * Check this lock's dependency list: | 1278 | if (class->usage_mask & (1 << bit)) { |
| 1174 | */ | 1279 | int len = depth; |
| 1175 | list_for_each_entry(entry, &source->locks_before, entry) { | 1280 | |
| 1176 | debug_atomic_inc(&nr_find_usage_backwards_recursions); | 1281 | len += printk("%*s %s", depth, "", usage_str[bit]); |
| 1177 | ret = find_usage_backwards(entry->class, depth+1); | 1282 | len += printk(" at:\n"); |
| 1178 | if (ret == 2 || ret == 0) | 1283 | print_stack_trace(class->usage_traces + bit, len); |
| 1179 | return ret; | 1284 | } |
| 1180 | } | 1285 | } |
| 1181 | return 1; | 1286 | printk("%*s }\n", depth, ""); |
| 1287 | |||
| 1288 | printk("%*s ... key at: ",depth,""); | ||
| 1289 | print_ip_sym((unsigned long)class->key); | ||
| 1290 | } | ||
| 1291 | |||
| 1292 | /* | ||
| 1293 | * printk the shortest lock dependencies from @start to @end in reverse order: | ||
| 1294 | */ | ||
| 1295 | static void __used | ||
| 1296 | print_shortest_lock_dependencies(struct lock_list *leaf, | ||
| 1297 | struct lock_list *root) | ||
| 1298 | { | ||
| 1299 | struct lock_list *entry = leaf; | ||
| 1300 | int depth; | ||
| 1301 | |||
| 1302 | /*compute depth from generated tree by BFS*/ | ||
| 1303 | depth = get_lock_depth(leaf); | ||
| 1304 | |||
| 1305 | do { | ||
| 1306 | print_lock_class_header(entry->class, depth); | ||
| 1307 | printk("%*s ... acquired at:\n", depth, ""); | ||
| 1308 | print_stack_trace(&entry->trace, 2); | ||
| 1309 | printk("\n"); | ||
| 1310 | |||
| 1311 | if (depth == 0 && (entry != root)) { | ||
| 1312 | printk("lockdep:%s bad BFS generated tree\n", __func__); | ||
| 1313 | break; | ||
| 1314 | } | ||
| 1315 | |||
| 1316 | entry = get_lock_parent(entry); | ||
| 1317 | depth--; | ||
| 1318 | } while (entry && (depth >= 0)); | ||
| 1319 | |||
| 1320 | return; | ||
| 1182 | } | 1321 | } |
| 1183 | 1322 | ||
| 1184 | static int | 1323 | static int |
| 1185 | print_bad_irq_dependency(struct task_struct *curr, | 1324 | print_bad_irq_dependency(struct task_struct *curr, |
| 1325 | struct lock_list *prev_root, | ||
| 1326 | struct lock_list *next_root, | ||
| 1327 | struct lock_list *backwards_entry, | ||
| 1328 | struct lock_list *forwards_entry, | ||
| 1186 | struct held_lock *prev, | 1329 | struct held_lock *prev, |
| 1187 | struct held_lock *next, | 1330 | struct held_lock *next, |
| 1188 | enum lock_usage_bit bit1, | 1331 | enum lock_usage_bit bit1, |
| @@ -1215,26 +1358,32 @@ print_bad_irq_dependency(struct task_struct *curr, | |||
| 1215 | 1358 | ||
| 1216 | printk("\nbut this new dependency connects a %s-irq-safe lock:\n", | 1359 | printk("\nbut this new dependency connects a %s-irq-safe lock:\n", |
| 1217 | irqclass); | 1360 | irqclass); |
| 1218 | print_lock_name(backwards_match); | 1361 | print_lock_name(backwards_entry->class); |
| 1219 | printk("\n... which became %s-irq-safe at:\n", irqclass); | 1362 | printk("\n... which became %s-irq-safe at:\n", irqclass); |
| 1220 | 1363 | ||
| 1221 | print_stack_trace(backwards_match->usage_traces + bit1, 1); | 1364 | print_stack_trace(backwards_entry->class->usage_traces + bit1, 1); |
| 1222 | 1365 | ||
| 1223 | printk("\nto a %s-irq-unsafe lock:\n", irqclass); | 1366 | printk("\nto a %s-irq-unsafe lock:\n", irqclass); |
| 1224 | print_lock_name(forwards_match); | 1367 | print_lock_name(forwards_entry->class); |
| 1225 | printk("\n... which became %s-irq-unsafe at:\n", irqclass); | 1368 | printk("\n... which became %s-irq-unsafe at:\n", irqclass); |
| 1226 | printk("..."); | 1369 | printk("..."); |
| 1227 | 1370 | ||
| 1228 | print_stack_trace(forwards_match->usage_traces + bit2, 1); | 1371 | print_stack_trace(forwards_entry->class->usage_traces + bit2, 1); |
| 1229 | 1372 | ||
| 1230 | printk("\nother info that might help us debug this:\n\n"); | 1373 | printk("\nother info that might help us debug this:\n\n"); |
| 1231 | lockdep_print_held_locks(curr); | 1374 | lockdep_print_held_locks(curr); |
| 1232 | 1375 | ||
| 1233 | printk("\nthe %s-irq-safe lock's dependencies:\n", irqclass); | 1376 | printk("\nthe dependencies between %s-irq-safe lock", irqclass); |
| 1234 | print_lock_dependencies(backwards_match, 0); | 1377 | printk(" and the holding lock:\n"); |
| 1378 | if (!save_trace(&prev_root->trace)) | ||
| 1379 | return 0; | ||
| 1380 | print_shortest_lock_dependencies(backwards_entry, prev_root); | ||
| 1235 | 1381 | ||
| 1236 | printk("\nthe %s-irq-unsafe lock's dependencies:\n", irqclass); | 1382 | printk("\nthe dependencies between the lock to be acquired"); |
| 1237 | print_lock_dependencies(forwards_match, 0); | 1383 | printk(" and %s-irq-unsafe lock:\n", irqclass); |
| 1384 | if (!save_trace(&next_root->trace)) | ||
| 1385 | return 0; | ||
| 1386 | print_shortest_lock_dependencies(forwards_entry, next_root); | ||
| 1238 | 1387 | ||
| 1239 | printk("\nstack backtrace:\n"); | 1388 | printk("\nstack backtrace:\n"); |
| 1240 | dump_stack(); | 1389 | dump_stack(); |
| @@ -1248,19 +1397,30 @@ check_usage(struct task_struct *curr, struct held_lock *prev, | |||
| 1248 | enum lock_usage_bit bit_forwards, const char *irqclass) | 1397 | enum lock_usage_bit bit_forwards, const char *irqclass) |
| 1249 | { | 1398 | { |
| 1250 | int ret; | 1399 | int ret; |
| 1400 | struct lock_list this, that; | ||
| 1401 | struct lock_list *uninitialized_var(target_entry); | ||
| 1402 | struct lock_list *uninitialized_var(target_entry1); | ||
| 1251 | 1403 | ||
| 1252 | find_usage_bit = bit_backwards; | 1404 | this.parent = NULL; |
| 1253 | /* fills in <backwards_match> */ | 1405 | |
| 1254 | ret = find_usage_backwards(hlock_class(prev), 0); | 1406 | this.class = hlock_class(prev); |
| 1255 | if (!ret || ret == 1) | 1407 | ret = find_usage_backwards(&this, bit_backwards, &target_entry); |
| 1408 | if (ret < 0) | ||
| 1409 | return print_bfs_bug(ret); | ||
| 1410 | if (ret == 1) | ||
| 1256 | return ret; | 1411 | return ret; |
| 1257 | 1412 | ||
| 1258 | find_usage_bit = bit_forwards; | 1413 | that.parent = NULL; |
| 1259 | ret = find_usage_forwards(hlock_class(next), 0); | 1414 | that.class = hlock_class(next); |
| 1260 | if (!ret || ret == 1) | 1415 | ret = find_usage_forwards(&that, bit_forwards, &target_entry1); |
| 1416 | if (ret < 0) | ||
| 1417 | return print_bfs_bug(ret); | ||
| 1418 | if (ret == 1) | ||
| 1261 | return ret; | 1419 | return ret; |
| 1262 | /* ret == 2 */ | 1420 | |
| 1263 | return print_bad_irq_dependency(curr, prev, next, | 1421 | return print_bad_irq_dependency(curr, &this, &that, |
| 1422 | target_entry, target_entry1, | ||
| 1423 | prev, next, | ||
| 1264 | bit_backwards, bit_forwards, irqclass); | 1424 | bit_backwards, bit_forwards, irqclass); |
| 1265 | } | 1425 | } |
| 1266 | 1426 | ||
| @@ -1472,6 +1632,8 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev, | |||
| 1472 | { | 1632 | { |
| 1473 | struct lock_list *entry; | 1633 | struct lock_list *entry; |
| 1474 | int ret; | 1634 | int ret; |
| 1635 | struct lock_list this; | ||
| 1636 | struct lock_list *uninitialized_var(target_entry); | ||
| 1475 | 1637 | ||
| 1476 | /* | 1638 | /* |
| 1477 | * Prove that the new <prev> -> <next> dependency would not | 1639 | * Prove that the new <prev> -> <next> dependency would not |
| @@ -1482,10 +1644,13 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev, | |||
| 1482 | * We are using global variables to control the recursion, to | 1644 | * We are using global variables to control the recursion, to |
| 1483 | * keep the stackframe size of the recursive functions low: | 1645 | * keep the stackframe size of the recursive functions low: |
| 1484 | */ | 1646 | */ |
| 1485 | check_source = next; | 1647 | this.class = hlock_class(next); |
| 1486 | check_target = prev; | 1648 | this.parent = NULL; |
| 1487 | if (!(check_noncircular(hlock_class(next), 0))) | 1649 | ret = check_noncircular(&this, hlock_class(prev), &target_entry); |
| 1488 | return print_circular_bug_tail(); | 1650 | if (unlikely(!ret)) |
| 1651 | return print_circular_bug(&this, target_entry, next, prev); | ||
| 1652 | else if (unlikely(ret < 0)) | ||
| 1653 | return print_bfs_bug(ret); | ||
| 1489 | 1654 | ||
| 1490 | if (!check_prev_add_irq(curr, prev, next)) | 1655 | if (!check_prev_add_irq(curr, prev, next)) |
| 1491 | return 0; | 1656 | return 0; |
| @@ -1884,7 +2049,8 @@ static int mark_lock(struct task_struct *curr, struct held_lock *this, | |||
| 1884 | * print irq inversion bug: | 2049 | * print irq inversion bug: |
| 1885 | */ | 2050 | */ |
| 1886 | static int | 2051 | static int |
| 1887 | print_irq_inversion_bug(struct task_struct *curr, struct lock_class *other, | 2052 | print_irq_inversion_bug(struct task_struct *curr, |
| 2053 | struct lock_list *root, struct lock_list *other, | ||
| 1888 | struct held_lock *this, int forwards, | 2054 | struct held_lock *this, int forwards, |
| 1889 | const char *irqclass) | 2055 | const char *irqclass) |
| 1890 | { | 2056 | { |
| @@ -1902,17 +2068,16 @@ print_irq_inversion_bug(struct task_struct *curr, struct lock_class *other, | |||
| 1902 | printk("but this lock took another, %s-unsafe lock in the past:\n", irqclass); | 2068 | printk("but this lock took another, %s-unsafe lock in the past:\n", irqclass); |
| 1903 | else | 2069 | else |
| 1904 | printk("but this lock was taken by another, %s-safe lock in the past:\n", irqclass); | 2070 | printk("but this lock was taken by another, %s-safe lock in the past:\n", irqclass); |
| 1905 | print_lock_name(other); | 2071 | print_lock_name(other->class); |
| 1906 | printk("\n\nand interrupts could create inverse lock ordering between them.\n\n"); | 2072 | printk("\n\nand interrupts could create inverse lock ordering between them.\n\n"); |
| 1907 | 2073 | ||
| 1908 | printk("\nother info that might help us debug this:\n"); | 2074 | printk("\nother info that might help us debug this:\n"); |
| 1909 | lockdep_print_held_locks(curr); | 2075 | lockdep_print_held_locks(curr); |
| 1910 | 2076 | ||
| 1911 | printk("\nthe first lock's dependencies:\n"); | 2077 | printk("\nthe shortest dependencies between 2nd lock and 1st lock:\n"); |
| 1912 | print_lock_dependencies(hlock_class(this), 0); | 2078 | if (!save_trace(&root->trace)) |
| 1913 | 2079 | return 0; | |
| 1914 | printk("\nthe second lock's dependencies:\n"); | 2080 | print_shortest_lock_dependencies(other, root); |
| 1915 | print_lock_dependencies(other, 0); | ||
| 1916 | 2081 | ||
| 1917 | printk("\nstack backtrace:\n"); | 2082 | printk("\nstack backtrace:\n"); |
| 1918 | dump_stack(); | 2083 | dump_stack(); |
| @@ -1929,14 +2094,19 @@ check_usage_forwards(struct task_struct *curr, struct held_lock *this, | |||
| 1929 | enum lock_usage_bit bit, const char *irqclass) | 2094 | enum lock_usage_bit bit, const char *irqclass) |
| 1930 | { | 2095 | { |
| 1931 | int ret; | 2096 | int ret; |
| 1932 | 2097 | struct lock_list root; | |
| 1933 | find_usage_bit = bit; | 2098 | struct lock_list *uninitialized_var(target_entry); |
| 1934 | /* fills in <forwards_match> */ | 2099 | |
| 1935 | ret = find_usage_forwards(hlock_class(this), 0); | 2100 | root.parent = NULL; |
| 1936 | if (!ret || ret == 1) | 2101 | root.class = hlock_class(this); |
| 2102 | ret = find_usage_forwards(&root, bit, &target_entry); | ||
| 2103 | if (ret < 0) | ||
| 2104 | return print_bfs_bug(ret); | ||
| 2105 | if (ret == 1) | ||
| 1937 | return ret; | 2106 | return ret; |
| 1938 | 2107 | ||
| 1939 | return print_irq_inversion_bug(curr, forwards_match, this, 1, irqclass); | 2108 | return print_irq_inversion_bug(curr, &root, target_entry, |
| 2109 | this, 1, irqclass); | ||
| 1940 | } | 2110 | } |
| 1941 | 2111 | ||
| 1942 | /* | 2112 | /* |
| @@ -1948,14 +2118,19 @@ check_usage_backwards(struct task_struct *curr, struct held_lock *this, | |||
| 1948 | enum lock_usage_bit bit, const char *irqclass) | 2118 | enum lock_usage_bit bit, const char *irqclass) |
| 1949 | { | 2119 | { |
| 1950 | int ret; | 2120 | int ret; |
| 1951 | 2121 | struct lock_list root; | |
| 1952 | find_usage_bit = bit; | 2122 | struct lock_list *uninitialized_var(target_entry); |
| 1953 | /* fills in <backwards_match> */ | 2123 | |
| 1954 | ret = find_usage_backwards(hlock_class(this), 0); | 2124 | root.parent = NULL; |
| 1955 | if (!ret || ret == 1) | 2125 | root.class = hlock_class(this); |
| 2126 | ret = find_usage_backwards(&root, bit, &target_entry); | ||
| 2127 | if (ret < 0) | ||
| 2128 | return print_bfs_bug(ret); | ||
| 2129 | if (ret == 1) | ||
| 1956 | return ret; | 2130 | return ret; |
| 1957 | 2131 | ||
| 1958 | return print_irq_inversion_bug(curr, backwards_match, this, 0, irqclass); | 2132 | return print_irq_inversion_bug(curr, &root, target_entry, |
| 2133 | this, 1, irqclass); | ||
| 1959 | } | 2134 | } |
| 1960 | 2135 | ||
| 1961 | void print_irqtrace_events(struct task_struct *curr) | 2136 | void print_irqtrace_events(struct task_struct *curr) |
| @@ -2530,13 +2705,15 @@ EXPORT_SYMBOL_GPL(lockdep_init_map); | |||
| 2530 | */ | 2705 | */ |
| 2531 | static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | 2706 | static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, |
| 2532 | int trylock, int read, int check, int hardirqs_off, | 2707 | int trylock, int read, int check, int hardirqs_off, |
| 2533 | struct lockdep_map *nest_lock, unsigned long ip) | 2708 | struct lockdep_map *nest_lock, unsigned long ip, |
| 2709 | int references) | ||
| 2534 | { | 2710 | { |
| 2535 | struct task_struct *curr = current; | 2711 | struct task_struct *curr = current; |
| 2536 | struct lock_class *class = NULL; | 2712 | struct lock_class *class = NULL; |
| 2537 | struct held_lock *hlock; | 2713 | struct held_lock *hlock; |
| 2538 | unsigned int depth, id; | 2714 | unsigned int depth, id; |
| 2539 | int chain_head = 0; | 2715 | int chain_head = 0; |
| 2716 | int class_idx; | ||
| 2540 | u64 chain_key; | 2717 | u64 chain_key; |
| 2541 | 2718 | ||
| 2542 | if (!prove_locking) | 2719 | if (!prove_locking) |
| @@ -2584,10 +2761,24 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
| 2584 | if (DEBUG_LOCKS_WARN_ON(depth >= MAX_LOCK_DEPTH)) | 2761 | if (DEBUG_LOCKS_WARN_ON(depth >= MAX_LOCK_DEPTH)) |
| 2585 | return 0; | 2762 | return 0; |
| 2586 | 2763 | ||
| 2764 | class_idx = class - lock_classes + 1; | ||
| 2765 | |||
| 2766 | if (depth) { | ||
| 2767 | hlock = curr->held_locks + depth - 1; | ||
| 2768 | if (hlock->class_idx == class_idx && nest_lock) { | ||
| 2769 | if (hlock->references) | ||
| 2770 | hlock->references++; | ||
| 2771 | else | ||
| 2772 | hlock->references = 2; | ||
| 2773 | |||
| 2774 | return 1; | ||
| 2775 | } | ||
| 2776 | } | ||
| 2777 | |||
| 2587 | hlock = curr->held_locks + depth; | 2778 | hlock = curr->held_locks + depth; |
| 2588 | if (DEBUG_LOCKS_WARN_ON(!class)) | 2779 | if (DEBUG_LOCKS_WARN_ON(!class)) |
| 2589 | return 0; | 2780 | return 0; |
| 2590 | hlock->class_idx = class - lock_classes + 1; | 2781 | hlock->class_idx = class_idx; |
| 2591 | hlock->acquire_ip = ip; | 2782 | hlock->acquire_ip = ip; |
| 2592 | hlock->instance = lock; | 2783 | hlock->instance = lock; |
| 2593 | hlock->nest_lock = nest_lock; | 2784 | hlock->nest_lock = nest_lock; |
| @@ -2595,6 +2786,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
| 2595 | hlock->read = read; | 2786 | hlock->read = read; |
| 2596 | hlock->check = check; | 2787 | hlock->check = check; |
| 2597 | hlock->hardirqs_off = !!hardirqs_off; | 2788 | hlock->hardirqs_off = !!hardirqs_off; |
| 2789 | hlock->references = references; | ||
| 2598 | #ifdef CONFIG_LOCK_STAT | 2790 | #ifdef CONFIG_LOCK_STAT |
| 2599 | hlock->waittime_stamp = 0; | 2791 | hlock->waittime_stamp = 0; |
| 2600 | hlock->holdtime_stamp = sched_clock(); | 2792 | hlock->holdtime_stamp = sched_clock(); |
| @@ -2703,6 +2895,30 @@ static int check_unlock(struct task_struct *curr, struct lockdep_map *lock, | |||
| 2703 | return 1; | 2895 | return 1; |
| 2704 | } | 2896 | } |
| 2705 | 2897 | ||
| 2898 | static int match_held_lock(struct held_lock *hlock, struct lockdep_map *lock) | ||
| 2899 | { | ||
| 2900 | if (hlock->instance == lock) | ||
| 2901 | return 1; | ||
| 2902 | |||
| 2903 | if (hlock->references) { | ||
| 2904 | struct lock_class *class = lock->class_cache; | ||
| 2905 | |||
| 2906 | if (!class) | ||
| 2907 | class = look_up_lock_class(lock, 0); | ||
| 2908 | |||
| 2909 | if (DEBUG_LOCKS_WARN_ON(!class)) | ||
| 2910 | return 0; | ||
| 2911 | |||
| 2912 | if (DEBUG_LOCKS_WARN_ON(!hlock->nest_lock)) | ||
| 2913 | return 0; | ||
| 2914 | |||
| 2915 | if (hlock->class_idx == class - lock_classes + 1) | ||
| 2916 | return 1; | ||
| 2917 | } | ||
| 2918 | |||
| 2919 | return 0; | ||
| 2920 | } | ||
| 2921 | |||
| 2706 | static int | 2922 | static int |
| 2707 | __lock_set_class(struct lockdep_map *lock, const char *name, | 2923 | __lock_set_class(struct lockdep_map *lock, const char *name, |
| 2708 | struct lock_class_key *key, unsigned int subclass, | 2924 | struct lock_class_key *key, unsigned int subclass, |
| @@ -2726,7 +2942,7 @@ __lock_set_class(struct lockdep_map *lock, const char *name, | |||
| 2726 | */ | 2942 | */ |
| 2727 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) | 2943 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) |
| 2728 | break; | 2944 | break; |
| 2729 | if (hlock->instance == lock) | 2945 | if (match_held_lock(hlock, lock)) |
| 2730 | goto found_it; | 2946 | goto found_it; |
| 2731 | prev_hlock = hlock; | 2947 | prev_hlock = hlock; |
| 2732 | } | 2948 | } |
| @@ -2745,7 +2961,8 @@ found_it: | |||
| 2745 | if (!__lock_acquire(hlock->instance, | 2961 | if (!__lock_acquire(hlock->instance, |
| 2746 | hlock_class(hlock)->subclass, hlock->trylock, | 2962 | hlock_class(hlock)->subclass, hlock->trylock, |
| 2747 | hlock->read, hlock->check, hlock->hardirqs_off, | 2963 | hlock->read, hlock->check, hlock->hardirqs_off, |
| 2748 | hlock->nest_lock, hlock->acquire_ip)) | 2964 | hlock->nest_lock, hlock->acquire_ip, |
| 2965 | hlock->references)) | ||
| 2749 | return 0; | 2966 | return 0; |
| 2750 | } | 2967 | } |
| 2751 | 2968 | ||
| @@ -2784,20 +3001,34 @@ lock_release_non_nested(struct task_struct *curr, | |||
| 2784 | */ | 3001 | */ |
| 2785 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) | 3002 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) |
| 2786 | break; | 3003 | break; |
| 2787 | if (hlock->instance == lock) | 3004 | if (match_held_lock(hlock, lock)) |
| 2788 | goto found_it; | 3005 | goto found_it; |
| 2789 | prev_hlock = hlock; | 3006 | prev_hlock = hlock; |
| 2790 | } | 3007 | } |
| 2791 | return print_unlock_inbalance_bug(curr, lock, ip); | 3008 | return print_unlock_inbalance_bug(curr, lock, ip); |
| 2792 | 3009 | ||
| 2793 | found_it: | 3010 | found_it: |
| 2794 | lock_release_holdtime(hlock); | 3011 | if (hlock->instance == lock) |
| 3012 | lock_release_holdtime(hlock); | ||
| 3013 | |||
| 3014 | if (hlock->references) { | ||
| 3015 | hlock->references--; | ||
| 3016 | if (hlock->references) { | ||
| 3017 | /* | ||
| 3018 | * We had, and after removing one, still have | ||
| 3019 | * references, the current lock stack is still | ||
| 3020 | * valid. We're done! | ||
| 3021 | */ | ||
| 3022 | return 1; | ||
| 3023 | } | ||
| 3024 | } | ||
| 2795 | 3025 | ||
| 2796 | /* | 3026 | /* |
| 2797 | * We have the right lock to unlock, 'hlock' points to it. | 3027 | * We have the right lock to unlock, 'hlock' points to it. |
| 2798 | * Now we remove it from the stack, and add back the other | 3028 | * Now we remove it from the stack, and add back the other |
| 2799 | * entries (if any), recalculating the hash along the way: | 3029 | * entries (if any), recalculating the hash along the way: |
| 2800 | */ | 3030 | */ |
| 3031 | |||
| 2801 | curr->lockdep_depth = i; | 3032 | curr->lockdep_depth = i; |
| 2802 | curr->curr_chain_key = hlock->prev_chain_key; | 3033 | curr->curr_chain_key = hlock->prev_chain_key; |
| 2803 | 3034 | ||
| @@ -2806,7 +3037,8 @@ found_it: | |||
| 2806 | if (!__lock_acquire(hlock->instance, | 3037 | if (!__lock_acquire(hlock->instance, |
| 2807 | hlock_class(hlock)->subclass, hlock->trylock, | 3038 | hlock_class(hlock)->subclass, hlock->trylock, |
| 2808 | hlock->read, hlock->check, hlock->hardirqs_off, | 3039 | hlock->read, hlock->check, hlock->hardirqs_off, |
| 2809 | hlock->nest_lock, hlock->acquire_ip)) | 3040 | hlock->nest_lock, hlock->acquire_ip, |
| 3041 | hlock->references)) | ||
| 2810 | return 0; | 3042 | return 0; |
| 2811 | } | 3043 | } |
| 2812 | 3044 | ||
| @@ -2836,7 +3068,7 @@ static int lock_release_nested(struct task_struct *curr, | |||
| 2836 | /* | 3068 | /* |
| 2837 | * Is the unlock non-nested: | 3069 | * Is the unlock non-nested: |
| 2838 | */ | 3070 | */ |
| 2839 | if (hlock->instance != lock) | 3071 | if (hlock->instance != lock || hlock->references) |
| 2840 | return lock_release_non_nested(curr, lock, ip); | 3072 | return lock_release_non_nested(curr, lock, ip); |
| 2841 | curr->lockdep_depth--; | 3073 | curr->lockdep_depth--; |
| 2842 | 3074 | ||
| @@ -2881,6 +3113,21 @@ __lock_release(struct lockdep_map *lock, int nested, unsigned long ip) | |||
| 2881 | check_chain_key(curr); | 3113 | check_chain_key(curr); |
| 2882 | } | 3114 | } |
| 2883 | 3115 | ||
| 3116 | static int __lock_is_held(struct lockdep_map *lock) | ||
| 3117 | { | ||
| 3118 | struct task_struct *curr = current; | ||
| 3119 | int i; | ||
| 3120 | |||
| 3121 | for (i = 0; i < curr->lockdep_depth; i++) { | ||
| 3122 | struct held_lock *hlock = curr->held_locks + i; | ||
| 3123 | |||
| 3124 | if (match_held_lock(hlock, lock)) | ||
| 3125 | return 1; | ||
| 3126 | } | ||
| 3127 | |||
| 3128 | return 0; | ||
| 3129 | } | ||
| 3130 | |||
| 2884 | /* | 3131 | /* |
| 2885 | * Check whether we follow the irq-flags state precisely: | 3132 | * Check whether we follow the irq-flags state precisely: |
| 2886 | */ | 3133 | */ |
| @@ -2957,7 +3204,7 @@ void lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
| 2957 | 3204 | ||
| 2958 | current->lockdep_recursion = 1; | 3205 | current->lockdep_recursion = 1; |
| 2959 | __lock_acquire(lock, subclass, trylock, read, check, | 3206 | __lock_acquire(lock, subclass, trylock, read, check, |
| 2960 | irqs_disabled_flags(flags), nest_lock, ip); | 3207 | irqs_disabled_flags(flags), nest_lock, ip, 0); |
| 2961 | current->lockdep_recursion = 0; | 3208 | current->lockdep_recursion = 0; |
| 2962 | raw_local_irq_restore(flags); | 3209 | raw_local_irq_restore(flags); |
| 2963 | } | 3210 | } |
| @@ -2982,6 +3229,26 @@ void lock_release(struct lockdep_map *lock, int nested, | |||
| 2982 | } | 3229 | } |
| 2983 | EXPORT_SYMBOL_GPL(lock_release); | 3230 | EXPORT_SYMBOL_GPL(lock_release); |
| 2984 | 3231 | ||
| 3232 | int lock_is_held(struct lockdep_map *lock) | ||
| 3233 | { | ||
| 3234 | unsigned long flags; | ||
| 3235 | int ret = 0; | ||
| 3236 | |||
| 3237 | if (unlikely(current->lockdep_recursion)) | ||
| 3238 | return ret; | ||
| 3239 | |||
| 3240 | raw_local_irq_save(flags); | ||
| 3241 | check_flags(flags); | ||
| 3242 | |||
| 3243 | current->lockdep_recursion = 1; | ||
| 3244 | ret = __lock_is_held(lock); | ||
| 3245 | current->lockdep_recursion = 0; | ||
| 3246 | raw_local_irq_restore(flags); | ||
| 3247 | |||
| 3248 | return ret; | ||
| 3249 | } | ||
| 3250 | EXPORT_SYMBOL_GPL(lock_is_held); | ||
| 3251 | |||
| 2985 | void lockdep_set_current_reclaim_state(gfp_t gfp_mask) | 3252 | void lockdep_set_current_reclaim_state(gfp_t gfp_mask) |
| 2986 | { | 3253 | { |
| 2987 | current->lockdep_reclaim_gfp = gfp_mask; | 3254 | current->lockdep_reclaim_gfp = gfp_mask; |
| @@ -3041,7 +3308,7 @@ __lock_contended(struct lockdep_map *lock, unsigned long ip) | |||
| 3041 | */ | 3308 | */ |
| 3042 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) | 3309 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) |
| 3043 | break; | 3310 | break; |
| 3044 | if (hlock->instance == lock) | 3311 | if (match_held_lock(hlock, lock)) |
| 3045 | goto found_it; | 3312 | goto found_it; |
| 3046 | prev_hlock = hlock; | 3313 | prev_hlock = hlock; |
| 3047 | } | 3314 | } |
| @@ -3049,6 +3316,9 @@ __lock_contended(struct lockdep_map *lock, unsigned long ip) | |||
| 3049 | return; | 3316 | return; |
| 3050 | 3317 | ||
| 3051 | found_it: | 3318 | found_it: |
| 3319 | if (hlock->instance != lock) | ||
| 3320 | return; | ||
| 3321 | |||
| 3052 | hlock->waittime_stamp = sched_clock(); | 3322 | hlock->waittime_stamp = sched_clock(); |
| 3053 | 3323 | ||
| 3054 | contention_point = lock_point(hlock_class(hlock)->contention_point, ip); | 3324 | contention_point = lock_point(hlock_class(hlock)->contention_point, ip); |
| @@ -3088,7 +3358,7 @@ __lock_acquired(struct lockdep_map *lock, unsigned long ip) | |||
| 3088 | */ | 3358 | */ |
| 3089 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) | 3359 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) |
| 3090 | break; | 3360 | break; |
| 3091 | if (hlock->instance == lock) | 3361 | if (match_held_lock(hlock, lock)) |
| 3092 | goto found_it; | 3362 | goto found_it; |
| 3093 | prev_hlock = hlock; | 3363 | prev_hlock = hlock; |
| 3094 | } | 3364 | } |
| @@ -3096,6 +3366,9 @@ __lock_acquired(struct lockdep_map *lock, unsigned long ip) | |||
| 3096 | return; | 3366 | return; |
| 3097 | 3367 | ||
| 3098 | found_it: | 3368 | found_it: |
| 3369 | if (hlock->instance != lock) | ||
| 3370 | return; | ||
| 3371 | |||
| 3099 | cpu = smp_processor_id(); | 3372 | cpu = smp_processor_id(); |
| 3100 | if (hlock->waittime_stamp) { | 3373 | if (hlock->waittime_stamp) { |
| 3101 | now = sched_clock(); | 3374 | now = sched_clock(); |
| @@ -3326,7 +3599,12 @@ void __init lockdep_info(void) | |||
| 3326 | sizeof(struct list_head) * CLASSHASH_SIZE + | 3599 | sizeof(struct list_head) * CLASSHASH_SIZE + |
| 3327 | sizeof(struct lock_list) * MAX_LOCKDEP_ENTRIES + | 3600 | sizeof(struct lock_list) * MAX_LOCKDEP_ENTRIES + |
| 3328 | sizeof(struct lock_chain) * MAX_LOCKDEP_CHAINS + | 3601 | sizeof(struct lock_chain) * MAX_LOCKDEP_CHAINS + |
| 3329 | sizeof(struct list_head) * CHAINHASH_SIZE) / 1024); | 3602 | sizeof(struct list_head) * CHAINHASH_SIZE |
| 3603 | #ifdef CONFIG_PROVE_LOCKING | ||
| 3604 | + sizeof(struct circular_queue) | ||
| 3605 | #endif | ||
| 3606 | ) / 1024 | ||
| 3607 | ); | ||
| 3330 | 3608 | ||
| 3331 | printk(" per task-struct memory footprint: %lu bytes\n", | 3609 | printk(" per task-struct memory footprint: %lu bytes\n", |
| 3332 | sizeof(struct held_lock) * MAX_LOCK_DEPTH); | 3610 | sizeof(struct held_lock) * MAX_LOCK_DEPTH); |
diff --git a/kernel/lockdep_internals.h b/kernel/lockdep_internals.h index 699a2ac3a0d7..a2ee95ad1313 100644 --- a/kernel/lockdep_internals.h +++ b/kernel/lockdep_internals.h | |||
| @@ -91,6 +91,8 @@ extern unsigned int nr_process_chains; | |||
| 91 | extern unsigned int max_lockdep_depth; | 91 | extern unsigned int max_lockdep_depth; |
| 92 | extern unsigned int max_recursion_depth; | 92 | extern unsigned int max_recursion_depth; |
| 93 | 93 | ||
| 94 | extern unsigned int max_bfs_queue_depth; | ||
| 95 | |||
| 94 | #ifdef CONFIG_PROVE_LOCKING | 96 | #ifdef CONFIG_PROVE_LOCKING |
| 95 | extern unsigned long lockdep_count_forward_deps(struct lock_class *); | 97 | extern unsigned long lockdep_count_forward_deps(struct lock_class *); |
| 96 | extern unsigned long lockdep_count_backward_deps(struct lock_class *); | 98 | extern unsigned long lockdep_count_backward_deps(struct lock_class *); |
diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c index e94caa666dba..d4b3dbc79fdb 100644 --- a/kernel/lockdep_proc.c +++ b/kernel/lockdep_proc.c | |||
| @@ -25,38 +25,12 @@ | |||
| 25 | 25 | ||
| 26 | static void *l_next(struct seq_file *m, void *v, loff_t *pos) | 26 | static void *l_next(struct seq_file *m, void *v, loff_t *pos) |
| 27 | { | 27 | { |
| 28 | struct lock_class *class; | 28 | return seq_list_next(v, &all_lock_classes, pos); |
| 29 | |||
| 30 | (*pos)++; | ||
| 31 | |||
| 32 | if (v == SEQ_START_TOKEN) | ||
| 33 | class = m->private; | ||
| 34 | else { | ||
| 35 | class = v; | ||
| 36 | |||
| 37 | if (class->lock_entry.next != &all_lock_classes) | ||
| 38 | class = list_entry(class->lock_entry.next, | ||
| 39 | struct lock_class, lock_entry); | ||
| 40 | else | ||
| 41 | class = NULL; | ||
| 42 | } | ||
| 43 | |||
| 44 | return class; | ||
| 45 | } | 29 | } |
| 46 | 30 | ||
| 47 | static void *l_start(struct seq_file *m, loff_t *pos) | 31 | static void *l_start(struct seq_file *m, loff_t *pos) |
| 48 | { | 32 | { |
| 49 | struct lock_class *class; | 33 | return seq_list_start_head(&all_lock_classes, *pos); |
| 50 | loff_t i = 0; | ||
| 51 | |||
| 52 | if (*pos == 0) | ||
| 53 | return SEQ_START_TOKEN; | ||
| 54 | |||
| 55 | list_for_each_entry(class, &all_lock_classes, lock_entry) { | ||
| 56 | if (++i == *pos) | ||
| 57 | return class; | ||
| 58 | } | ||
| 59 | return NULL; | ||
| 60 | } | 34 | } |
| 61 | 35 | ||
| 62 | static void l_stop(struct seq_file *m, void *v) | 36 | static void l_stop(struct seq_file *m, void *v) |
| @@ -82,11 +56,11 @@ static void print_name(struct seq_file *m, struct lock_class *class) | |||
| 82 | 56 | ||
| 83 | static int l_show(struct seq_file *m, void *v) | 57 | static int l_show(struct seq_file *m, void *v) |
| 84 | { | 58 | { |
| 85 | struct lock_class *class = v; | 59 | struct lock_class *class = list_entry(v, struct lock_class, lock_entry); |
| 86 | struct lock_list *entry; | 60 | struct lock_list *entry; |
| 87 | char usage[LOCK_USAGE_CHARS]; | 61 | char usage[LOCK_USAGE_CHARS]; |
| 88 | 62 | ||
| 89 | if (v == SEQ_START_TOKEN) { | 63 | if (v == &all_lock_classes) { |
| 90 | seq_printf(m, "all lock classes:\n"); | 64 | seq_printf(m, "all lock classes:\n"); |
| 91 | return 0; | 65 | return 0; |
| 92 | } | 66 | } |
| @@ -128,17 +102,7 @@ static const struct seq_operations lockdep_ops = { | |||
| 128 | 102 | ||
| 129 | static int lockdep_open(struct inode *inode, struct file *file) | 103 | static int lockdep_open(struct inode *inode, struct file *file) |
| 130 | { | 104 | { |
| 131 | int res = seq_open(file, &lockdep_ops); | 105 | return seq_open(file, &lockdep_ops); |
| 132 | if (!res) { | ||
| 133 | struct seq_file *m = file->private_data; | ||
| 134 | |||
| 135 | if (!list_empty(&all_lock_classes)) | ||
| 136 | m->private = list_entry(all_lock_classes.next, | ||
| 137 | struct lock_class, lock_entry); | ||
| 138 | else | ||
| 139 | m->private = NULL; | ||
| 140 | } | ||
| 141 | return res; | ||
| 142 | } | 106 | } |
| 143 | 107 | ||
| 144 | static const struct file_operations proc_lockdep_operations = { | 108 | static const struct file_operations proc_lockdep_operations = { |
| @@ -149,37 +113,23 @@ static const struct file_operations proc_lockdep_operations = { | |||
| 149 | }; | 113 | }; |
| 150 | 114 | ||
| 151 | #ifdef CONFIG_PROVE_LOCKING | 115 | #ifdef CONFIG_PROVE_LOCKING |
| 152 | static void *lc_next(struct seq_file *m, void *v, loff_t *pos) | ||
| 153 | { | ||
| 154 | struct lock_chain *chain; | ||
| 155 | |||
| 156 | (*pos)++; | ||
| 157 | |||
| 158 | if (v == SEQ_START_TOKEN) | ||
| 159 | chain = m->private; | ||
| 160 | else { | ||
| 161 | chain = v; | ||
| 162 | |||
| 163 | if (*pos < nr_lock_chains) | ||
| 164 | chain = lock_chains + *pos; | ||
| 165 | else | ||
| 166 | chain = NULL; | ||
| 167 | } | ||
| 168 | |||
| 169 | return chain; | ||
| 170 | } | ||
| 171 | |||
| 172 | static void *lc_start(struct seq_file *m, loff_t *pos) | 116 | static void *lc_start(struct seq_file *m, loff_t *pos) |
| 173 | { | 117 | { |
| 174 | if (*pos == 0) | 118 | if (*pos == 0) |
| 175 | return SEQ_START_TOKEN; | 119 | return SEQ_START_TOKEN; |
| 176 | 120 | ||
| 177 | if (*pos < nr_lock_chains) | 121 | if (*pos - 1 < nr_lock_chains) |
| 178 | return lock_chains + *pos; | 122 | return lock_chains + (*pos - 1); |
| 179 | 123 | ||
| 180 | return NULL; | 124 | return NULL; |
| 181 | } | 125 | } |
| 182 | 126 | ||
| 127 | static void *lc_next(struct seq_file *m, void *v, loff_t *pos) | ||
| 128 | { | ||
| 129 | (*pos)++; | ||
| 130 | return lc_start(m, pos); | ||
| 131 | } | ||
| 132 | |||
| 183 | static void lc_stop(struct seq_file *m, void *v) | 133 | static void lc_stop(struct seq_file *m, void *v) |
| 184 | { | 134 | { |
| 185 | } | 135 | } |
| @@ -220,16 +170,7 @@ static const struct seq_operations lockdep_chains_ops = { | |||
| 220 | 170 | ||
| 221 | static int lockdep_chains_open(struct inode *inode, struct file *file) | 171 | static int lockdep_chains_open(struct inode *inode, struct file *file) |
| 222 | { | 172 | { |
| 223 | int res = seq_open(file, &lockdep_chains_ops); | 173 | return seq_open(file, &lockdep_chains_ops); |
| 224 | if (!res) { | ||
| 225 | struct seq_file *m = file->private_data; | ||
| 226 | |||
| 227 | if (nr_lock_chains) | ||
| 228 | m->private = lock_chains; | ||
| 229 | else | ||
| 230 | m->private = NULL; | ||
| 231 | } | ||
| 232 | return res; | ||
| 233 | } | 174 | } |
| 234 | 175 | ||
| 235 | static const struct file_operations proc_lockdep_chains_operations = { | 176 | static const struct file_operations proc_lockdep_chains_operations = { |
| @@ -258,16 +199,10 @@ static void lockdep_stats_debug_show(struct seq_file *m) | |||
| 258 | debug_atomic_read(&chain_lookup_hits)); | 199 | debug_atomic_read(&chain_lookup_hits)); |
| 259 | seq_printf(m, " cyclic checks: %11u\n", | 200 | seq_printf(m, " cyclic checks: %11u\n", |
| 260 | debug_atomic_read(&nr_cyclic_checks)); | 201 | debug_atomic_read(&nr_cyclic_checks)); |
| 261 | seq_printf(m, " cyclic-check recursions: %11u\n", | ||
| 262 | debug_atomic_read(&nr_cyclic_check_recursions)); | ||
| 263 | seq_printf(m, " find-mask forwards checks: %11u\n", | 202 | seq_printf(m, " find-mask forwards checks: %11u\n", |
| 264 | debug_atomic_read(&nr_find_usage_forwards_checks)); | 203 | debug_atomic_read(&nr_find_usage_forwards_checks)); |
| 265 | seq_printf(m, " find-mask forwards recursions: %11u\n", | ||
| 266 | debug_atomic_read(&nr_find_usage_forwards_recursions)); | ||
| 267 | seq_printf(m, " find-mask backwards checks: %11u\n", | 204 | seq_printf(m, " find-mask backwards checks: %11u\n", |
| 268 | debug_atomic_read(&nr_find_usage_backwards_checks)); | 205 | debug_atomic_read(&nr_find_usage_backwards_checks)); |
| 269 | seq_printf(m, " find-mask backwards recursions:%11u\n", | ||
| 270 | debug_atomic_read(&nr_find_usage_backwards_recursions)); | ||
| 271 | 206 | ||
| 272 | seq_printf(m, " hardirq on events: %11u\n", hi1); | 207 | seq_printf(m, " hardirq on events: %11u\n", hi1); |
| 273 | seq_printf(m, " hardirq off events: %11u\n", hi2); | 208 | seq_printf(m, " hardirq off events: %11u\n", hi2); |
| @@ -409,8 +344,10 @@ static int lockdep_stats_show(struct seq_file *m, void *v) | |||
| 409 | nr_unused); | 344 | nr_unused); |
| 410 | seq_printf(m, " max locking depth: %11u\n", | 345 | seq_printf(m, " max locking depth: %11u\n", |
| 411 | max_lockdep_depth); | 346 | max_lockdep_depth); |
| 412 | seq_printf(m, " max recursion depth: %11u\n", | 347 | #ifdef CONFIG_PROVE_LOCKING |
| 413 | max_recursion_depth); | 348 | seq_printf(m, " max bfs queue depth: %11u\n", |
| 349 | max_bfs_queue_depth); | ||
| 350 | #endif | ||
| 414 | lockdep_stats_debug_show(m); | 351 | lockdep_stats_debug_show(m); |
| 415 | seq_printf(m, " debug_locks: %11u\n", | 352 | seq_printf(m, " debug_locks: %11u\n", |
| 416 | debug_locks); | 353 | debug_locks); |
| @@ -438,7 +375,6 @@ struct lock_stat_data { | |||
| 438 | }; | 375 | }; |
| 439 | 376 | ||
| 440 | struct lock_stat_seq { | 377 | struct lock_stat_seq { |
| 441 | struct lock_stat_data *iter; | ||
| 442 | struct lock_stat_data *iter_end; | 378 | struct lock_stat_data *iter_end; |
| 443 | struct lock_stat_data stats[MAX_LOCKDEP_KEYS]; | 379 | struct lock_stat_data stats[MAX_LOCKDEP_KEYS]; |
| 444 | }; | 380 | }; |
| @@ -626,34 +562,22 @@ static void seq_header(struct seq_file *m) | |||
| 626 | static void *ls_start(struct seq_file *m, loff_t *pos) | 562 | static void *ls_start(struct seq_file *m, loff_t *pos) |
| 627 | { | 563 | { |
| 628 | struct lock_stat_seq *data = m->private; | 564 | struct lock_stat_seq *data = m->private; |
| 565 | struct lock_stat_data *iter; | ||
| 629 | 566 | ||
| 630 | if (*pos == 0) | 567 | if (*pos == 0) |
| 631 | return SEQ_START_TOKEN; | 568 | return SEQ_START_TOKEN; |
| 632 | 569 | ||
| 633 | data->iter = data->stats + *pos; | 570 | iter = data->stats + (*pos - 1); |
| 634 | if (data->iter >= data->iter_end) | 571 | if (iter >= data->iter_end) |
| 635 | data->iter = NULL; | 572 | iter = NULL; |
| 636 | 573 | ||
| 637 | return data->iter; | 574 | return iter; |
| 638 | } | 575 | } |
| 639 | 576 | ||
| 640 | static void *ls_next(struct seq_file *m, void *v, loff_t *pos) | 577 | static void *ls_next(struct seq_file *m, void *v, loff_t *pos) |
| 641 | { | 578 | { |
| 642 | struct lock_stat_seq *data = m->private; | ||
| 643 | |||
| 644 | (*pos)++; | 579 | (*pos)++; |
| 645 | 580 | return ls_start(m, pos); | |
| 646 | if (v == SEQ_START_TOKEN) | ||
| 647 | data->iter = data->stats; | ||
| 648 | else { | ||
| 649 | data->iter = v; | ||
| 650 | data->iter++; | ||
| 651 | } | ||
| 652 | |||
| 653 | if (data->iter == data->iter_end) | ||
| 654 | data->iter = NULL; | ||
| 655 | |||
| 656 | return data->iter; | ||
| 657 | } | 581 | } |
| 658 | 582 | ||
| 659 | static void ls_stop(struct seq_file *m, void *v) | 583 | static void ls_stop(struct seq_file *m, void *v) |
| @@ -691,7 +615,6 @@ static int lock_stat_open(struct inode *inode, struct file *file) | |||
| 691 | struct lock_stat_data *iter = data->stats; | 615 | struct lock_stat_data *iter = data->stats; |
| 692 | struct seq_file *m = file->private_data; | 616 | struct seq_file *m = file->private_data; |
| 693 | 617 | ||
| 694 | data->iter = iter; | ||
| 695 | list_for_each_entry(class, &all_lock_classes, lock_entry) { | 618 | list_for_each_entry(class, &all_lock_classes, lock_entry) { |
| 696 | iter->class = class; | 619 | iter->class = class; |
| 697 | iter->stats = lock_stats(class); | 620 | iter->stats = lock_stats(class); |
| @@ -699,7 +622,7 @@ static int lock_stat_open(struct inode *inode, struct file *file) | |||
| 699 | } | 622 | } |
| 700 | data->iter_end = iter; | 623 | data->iter_end = iter; |
| 701 | 624 | ||
| 702 | sort(data->stats, data->iter_end - data->iter, | 625 | sort(data->stats, data->iter_end - data->stats, |
| 703 | sizeof(struct lock_stat_data), | 626 | sizeof(struct lock_stat_data), |
| 704 | lock_stat_cmp, NULL); | 627 | lock_stat_cmp, NULL); |
| 705 | 628 | ||
| @@ -734,7 +657,6 @@ static int lock_stat_release(struct inode *inode, struct file *file) | |||
| 734 | struct seq_file *seq = file->private_data; | 657 | struct seq_file *seq = file->private_data; |
| 735 | 658 | ||
| 736 | vfree(seq->private); | 659 | vfree(seq->private); |
| 737 | seq->private = NULL; | ||
| 738 | return seq_release(inode, file); | 660 | return seq_release(inode, file); |
| 739 | } | 661 | } |
| 740 | 662 | ||
diff --git a/kernel/module.c b/kernel/module.c index 2d537186191f..46580edff0cb 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
| @@ -55,6 +55,11 @@ | |||
| 55 | #include <linux/percpu.h> | 55 | #include <linux/percpu.h> |
| 56 | #include <linux/kmemleak.h> | 56 | #include <linux/kmemleak.h> |
| 57 | 57 | ||
| 58 | #define CREATE_TRACE_POINTS | ||
| 59 | #include <trace/events/module.h> | ||
| 60 | |||
| 61 | EXPORT_TRACEPOINT_SYMBOL(module_get); | ||
| 62 | |||
| 58 | #if 0 | 63 | #if 0 |
| 59 | #define DEBUGP printk | 64 | #define DEBUGP printk |
| 60 | #else | 65 | #else |
| @@ -942,6 +947,8 @@ void module_put(struct module *module) | |||
| 942 | if (module) { | 947 | if (module) { |
| 943 | unsigned int cpu = get_cpu(); | 948 | unsigned int cpu = get_cpu(); |
| 944 | local_dec(__module_ref_addr(module, cpu)); | 949 | local_dec(__module_ref_addr(module, cpu)); |
| 950 | trace_module_put(module, _RET_IP_, | ||
| 951 | local_read(__module_ref_addr(module, cpu))); | ||
| 945 | /* Maybe they're waiting for us to drop reference? */ | 952 | /* Maybe they're waiting for us to drop reference? */ |
| 946 | if (unlikely(!module_is_live(module))) | 953 | if (unlikely(!module_is_live(module))) |
| 947 | wake_up_process(module->waiter); | 954 | wake_up_process(module->waiter); |
| @@ -1497,6 +1504,8 @@ static int __unlink_module(void *_mod) | |||
| 1497 | /* Free a module, remove from lists, etc (must hold module_mutex). */ | 1504 | /* Free a module, remove from lists, etc (must hold module_mutex). */ |
| 1498 | static void free_module(struct module *mod) | 1505 | static void free_module(struct module *mod) |
| 1499 | { | 1506 | { |
| 1507 | trace_module_free(mod); | ||
| 1508 | |||
| 1500 | /* Delete from various lists */ | 1509 | /* Delete from various lists */ |
| 1501 | stop_machine(__unlink_module, mod, NULL); | 1510 | stop_machine(__unlink_module, mod, NULL); |
| 1502 | remove_notes_attrs(mod); | 1511 | remove_notes_attrs(mod); |
| @@ -2364,6 +2373,8 @@ static noinline struct module *load_module(void __user *umod, | |||
| 2364 | /* Get rid of temporary copy */ | 2373 | /* Get rid of temporary copy */ |
| 2365 | vfree(hdr); | 2374 | vfree(hdr); |
| 2366 | 2375 | ||
| 2376 | trace_module_load(mod); | ||
| 2377 | |||
| 2367 | /* Done! */ | 2378 | /* Done! */ |
| 2368 | return mod; | 2379 | return mod; |
| 2369 | 2380 | ||
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c index d7cbc579fc80..e0d91fdf0c3c 100644 --- a/kernel/perf_counter.c +++ b/kernel/perf_counter.c | |||
| @@ -46,12 +46,18 @@ static atomic_t nr_task_counters __read_mostly; | |||
| 46 | 46 | ||
| 47 | /* | 47 | /* |
| 48 | * perf counter paranoia level: | 48 | * perf counter paranoia level: |
| 49 | * 0 - not paranoid | 49 | * -1 - not paranoid at all |
| 50 | * 1 - disallow cpu counters to unpriv | 50 | * 0 - disallow raw tracepoint access for unpriv |
| 51 | * 2 - disallow kernel profiling to unpriv | 51 | * 1 - disallow cpu counters for unpriv |
| 52 | * 2 - disallow kernel profiling for unpriv | ||
| 52 | */ | 53 | */ |
| 53 | int sysctl_perf_counter_paranoid __read_mostly = 1; | 54 | int sysctl_perf_counter_paranoid __read_mostly = 1; |
| 54 | 55 | ||
| 56 | static inline bool perf_paranoid_tracepoint_raw(void) | ||
| 57 | { | ||
| 58 | return sysctl_perf_counter_paranoid > -1; | ||
| 59 | } | ||
| 60 | |||
| 55 | static inline bool perf_paranoid_cpu(void) | 61 | static inline bool perf_paranoid_cpu(void) |
| 56 | { | 62 | { |
| 57 | return sysctl_perf_counter_paranoid > 0; | 63 | return sysctl_perf_counter_paranoid > 0; |
| @@ -469,7 +475,8 @@ static void update_counter_times(struct perf_counter *counter) | |||
| 469 | struct perf_counter_context *ctx = counter->ctx; | 475 | struct perf_counter_context *ctx = counter->ctx; |
| 470 | u64 run_end; | 476 | u64 run_end; |
| 471 | 477 | ||
| 472 | if (counter->state < PERF_COUNTER_STATE_INACTIVE) | 478 | if (counter->state < PERF_COUNTER_STATE_INACTIVE || |
| 479 | counter->group_leader->state < PERF_COUNTER_STATE_INACTIVE) | ||
| 473 | return; | 480 | return; |
| 474 | 481 | ||
| 475 | counter->total_time_enabled = ctx->time - counter->tstamp_enabled; | 482 | counter->total_time_enabled = ctx->time - counter->tstamp_enabled; |
| @@ -518,7 +525,7 @@ static void __perf_counter_disable(void *info) | |||
| 518 | */ | 525 | */ |
| 519 | if (counter->state >= PERF_COUNTER_STATE_INACTIVE) { | 526 | if (counter->state >= PERF_COUNTER_STATE_INACTIVE) { |
| 520 | update_context_time(ctx); | 527 | update_context_time(ctx); |
| 521 | update_counter_times(counter); | 528 | update_group_times(counter); |
| 522 | if (counter == counter->group_leader) | 529 | if (counter == counter->group_leader) |
| 523 | group_sched_out(counter, cpuctx, ctx); | 530 | group_sched_out(counter, cpuctx, ctx); |
| 524 | else | 531 | else |
| @@ -573,7 +580,7 @@ static void perf_counter_disable(struct perf_counter *counter) | |||
| 573 | * in, so we can change the state safely. | 580 | * in, so we can change the state safely. |
| 574 | */ | 581 | */ |
| 575 | if (counter->state == PERF_COUNTER_STATE_INACTIVE) { | 582 | if (counter->state == PERF_COUNTER_STATE_INACTIVE) { |
| 576 | update_counter_times(counter); | 583 | update_group_times(counter); |
| 577 | counter->state = PERF_COUNTER_STATE_OFF; | 584 | counter->state = PERF_COUNTER_STATE_OFF; |
| 578 | } | 585 | } |
| 579 | 586 | ||
| @@ -851,6 +858,27 @@ retry: | |||
| 851 | } | 858 | } |
| 852 | 859 | ||
| 853 | /* | 860 | /* |
| 861 | * Put a counter into inactive state and update time fields. | ||
| 862 | * Enabling the leader of a group effectively enables all | ||
| 863 | * the group members that aren't explicitly disabled, so we | ||
| 864 | * have to update their ->tstamp_enabled also. | ||
| 865 | * Note: this works for group members as well as group leaders | ||
| 866 | * since the non-leader members' sibling_lists will be empty. | ||
| 867 | */ | ||
| 868 | static void __perf_counter_mark_enabled(struct perf_counter *counter, | ||
| 869 | struct perf_counter_context *ctx) | ||
| 870 | { | ||
| 871 | struct perf_counter *sub; | ||
| 872 | |||
| 873 | counter->state = PERF_COUNTER_STATE_INACTIVE; | ||
| 874 | counter->tstamp_enabled = ctx->time - counter->total_time_enabled; | ||
| 875 | list_for_each_entry(sub, &counter->sibling_list, list_entry) | ||
| 876 | if (sub->state >= PERF_COUNTER_STATE_INACTIVE) | ||
| 877 | sub->tstamp_enabled = | ||
| 878 | ctx->time - sub->total_time_enabled; | ||
| 879 | } | ||
| 880 | |||
| 881 | /* | ||
| 854 | * Cross CPU call to enable a performance counter | 882 | * Cross CPU call to enable a performance counter |
| 855 | */ | 883 | */ |
| 856 | static void __perf_counter_enable(void *info) | 884 | static void __perf_counter_enable(void *info) |
| @@ -877,8 +905,7 @@ static void __perf_counter_enable(void *info) | |||
| 877 | 905 | ||
| 878 | if (counter->state >= PERF_COUNTER_STATE_INACTIVE) | 906 | if (counter->state >= PERF_COUNTER_STATE_INACTIVE) |
| 879 | goto unlock; | 907 | goto unlock; |
| 880 | counter->state = PERF_COUNTER_STATE_INACTIVE; | 908 | __perf_counter_mark_enabled(counter, ctx); |
| 881 | counter->tstamp_enabled = ctx->time - counter->total_time_enabled; | ||
| 882 | 909 | ||
| 883 | /* | 910 | /* |
| 884 | * If the counter is in a group and isn't the group leader, | 911 | * If the counter is in a group and isn't the group leader, |
| @@ -971,11 +998,9 @@ static void perf_counter_enable(struct perf_counter *counter) | |||
| 971 | * Since we have the lock this context can't be scheduled | 998 | * Since we have the lock this context can't be scheduled |
| 972 | * in, so we can change the state safely. | 999 | * in, so we can change the state safely. |
| 973 | */ | 1000 | */ |
| 974 | if (counter->state == PERF_COUNTER_STATE_OFF) { | 1001 | if (counter->state == PERF_COUNTER_STATE_OFF) |
| 975 | counter->state = PERF_COUNTER_STATE_INACTIVE; | 1002 | __perf_counter_mark_enabled(counter, ctx); |
| 976 | counter->tstamp_enabled = | 1003 | |
| 977 | ctx->time - counter->total_time_enabled; | ||
| 978 | } | ||
| 979 | out: | 1004 | out: |
| 980 | spin_unlock_irq(&ctx->lock); | 1005 | spin_unlock_irq(&ctx->lock); |
| 981 | } | 1006 | } |
| @@ -1479,9 +1504,7 @@ static void perf_counter_enable_on_exec(struct task_struct *task) | |||
| 1479 | counter->attr.enable_on_exec = 0; | 1504 | counter->attr.enable_on_exec = 0; |
| 1480 | if (counter->state >= PERF_COUNTER_STATE_INACTIVE) | 1505 | if (counter->state >= PERF_COUNTER_STATE_INACTIVE) |
| 1481 | continue; | 1506 | continue; |
| 1482 | counter->state = PERF_COUNTER_STATE_INACTIVE; | 1507 | __perf_counter_mark_enabled(counter, ctx); |
| 1483 | counter->tstamp_enabled = | ||
| 1484 | ctx->time - counter->total_time_enabled; | ||
| 1485 | enabled = 1; | 1508 | enabled = 1; |
| 1486 | } | 1509 | } |
| 1487 | 1510 | ||
| @@ -1675,6 +1698,11 @@ static void free_counter(struct perf_counter *counter) | |||
| 1675 | atomic_dec(&nr_task_counters); | 1698 | atomic_dec(&nr_task_counters); |
| 1676 | } | 1699 | } |
| 1677 | 1700 | ||
| 1701 | if (counter->output) { | ||
| 1702 | fput(counter->output->filp); | ||
| 1703 | counter->output = NULL; | ||
| 1704 | } | ||
| 1705 | |||
| 1678 | if (counter->destroy) | 1706 | if (counter->destroy) |
| 1679 | counter->destroy(counter); | 1707 | counter->destroy(counter); |
| 1680 | 1708 | ||
| @@ -1960,6 +1988,8 @@ unlock: | |||
| 1960 | return ret; | 1988 | return ret; |
| 1961 | } | 1989 | } |
| 1962 | 1990 | ||
| 1991 | int perf_counter_set_output(struct perf_counter *counter, int output_fd); | ||
| 1992 | |||
| 1963 | static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | 1993 | static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 1964 | { | 1994 | { |
| 1965 | struct perf_counter *counter = file->private_data; | 1995 | struct perf_counter *counter = file->private_data; |
| @@ -1983,6 +2013,9 @@ static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
| 1983 | case PERF_COUNTER_IOC_PERIOD: | 2013 | case PERF_COUNTER_IOC_PERIOD: |
| 1984 | return perf_counter_period(counter, (u64 __user *)arg); | 2014 | return perf_counter_period(counter, (u64 __user *)arg); |
| 1985 | 2015 | ||
| 2016 | case PERF_COUNTER_IOC_SET_OUTPUT: | ||
| 2017 | return perf_counter_set_output(counter, arg); | ||
| 2018 | |||
| 1986 | default: | 2019 | default: |
| 1987 | return -ENOTTY; | 2020 | return -ENOTTY; |
| 1988 | } | 2021 | } |
| @@ -2253,6 +2286,11 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma) | |||
| 2253 | 2286 | ||
| 2254 | WARN_ON_ONCE(counter->ctx->parent_ctx); | 2287 | WARN_ON_ONCE(counter->ctx->parent_ctx); |
| 2255 | mutex_lock(&counter->mmap_mutex); | 2288 | mutex_lock(&counter->mmap_mutex); |
| 2289 | if (counter->output) { | ||
| 2290 | ret = -EINVAL; | ||
| 2291 | goto unlock; | ||
| 2292 | } | ||
| 2293 | |||
| 2256 | if (atomic_inc_not_zero(&counter->mmap_count)) { | 2294 | if (atomic_inc_not_zero(&counter->mmap_count)) { |
| 2257 | if (nr_pages != counter->data->nr_pages) | 2295 | if (nr_pages != counter->data->nr_pages) |
| 2258 | ret = -EINVAL; | 2296 | ret = -EINVAL; |
| @@ -2638,6 +2676,7 @@ static int perf_output_begin(struct perf_output_handle *handle, | |||
| 2638 | struct perf_counter *counter, unsigned int size, | 2676 | struct perf_counter *counter, unsigned int size, |
| 2639 | int nmi, int sample) | 2677 | int nmi, int sample) |
| 2640 | { | 2678 | { |
| 2679 | struct perf_counter *output_counter; | ||
| 2641 | struct perf_mmap_data *data; | 2680 | struct perf_mmap_data *data; |
| 2642 | unsigned int offset, head; | 2681 | unsigned int offset, head; |
| 2643 | int have_lost; | 2682 | int have_lost; |
| @@ -2647,13 +2686,17 @@ static int perf_output_begin(struct perf_output_handle *handle, | |||
| 2647 | u64 lost; | 2686 | u64 lost; |
| 2648 | } lost_event; | 2687 | } lost_event; |
| 2649 | 2688 | ||
| 2689 | rcu_read_lock(); | ||
| 2650 | /* | 2690 | /* |
| 2651 | * For inherited counters we send all the output towards the parent. | 2691 | * For inherited counters we send all the output towards the parent. |
| 2652 | */ | 2692 | */ |
| 2653 | if (counter->parent) | 2693 | if (counter->parent) |
| 2654 | counter = counter->parent; | 2694 | counter = counter->parent; |
| 2655 | 2695 | ||
| 2656 | rcu_read_lock(); | 2696 | output_counter = rcu_dereference(counter->output); |
| 2697 | if (output_counter) | ||
| 2698 | counter = output_counter; | ||
| 2699 | |||
| 2657 | data = rcu_dereference(counter->data); | 2700 | data = rcu_dereference(counter->data); |
| 2658 | if (!data) | 2701 | if (!data) |
| 2659 | goto out; | 2702 | goto out; |
| @@ -3934,6 +3977,7 @@ static const struct pmu *tp_perf_counter_init(struct perf_counter *counter) | |||
| 3934 | * have these. | 3977 | * have these. |
| 3935 | */ | 3978 | */ |
| 3936 | if ((counter->attr.sample_type & PERF_SAMPLE_RAW) && | 3979 | if ((counter->attr.sample_type & PERF_SAMPLE_RAW) && |
| 3980 | perf_paranoid_tracepoint_raw() && | ||
| 3937 | !capable(CAP_SYS_ADMIN)) | 3981 | !capable(CAP_SYS_ADMIN)) |
| 3938 | return ERR_PTR(-EPERM); | 3982 | return ERR_PTR(-EPERM); |
| 3939 | 3983 | ||
| @@ -4202,6 +4246,57 @@ err_size: | |||
| 4202 | goto out; | 4246 | goto out; |
| 4203 | } | 4247 | } |
| 4204 | 4248 | ||
| 4249 | int perf_counter_set_output(struct perf_counter *counter, int output_fd) | ||
| 4250 | { | ||
| 4251 | struct perf_counter *output_counter = NULL; | ||
| 4252 | struct file *output_file = NULL; | ||
| 4253 | struct perf_counter *old_output; | ||
| 4254 | int fput_needed = 0; | ||
| 4255 | int ret = -EINVAL; | ||
| 4256 | |||
| 4257 | if (!output_fd) | ||
| 4258 | goto set; | ||
| 4259 | |||
| 4260 | output_file = fget_light(output_fd, &fput_needed); | ||
| 4261 | if (!output_file) | ||
| 4262 | return -EBADF; | ||
| 4263 | |||
| 4264 | if (output_file->f_op != &perf_fops) | ||
| 4265 | goto out; | ||
| 4266 | |||
| 4267 | output_counter = output_file->private_data; | ||
| 4268 | |||
| 4269 | /* Don't chain output fds */ | ||
| 4270 | if (output_counter->output) | ||
| 4271 | goto out; | ||
| 4272 | |||
| 4273 | /* Don't set an output fd when we already have an output channel */ | ||
| 4274 | if (counter->data) | ||
| 4275 | goto out; | ||
| 4276 | |||
| 4277 | atomic_long_inc(&output_file->f_count); | ||
| 4278 | |||
| 4279 | set: | ||
| 4280 | mutex_lock(&counter->mmap_mutex); | ||
| 4281 | old_output = counter->output; | ||
| 4282 | rcu_assign_pointer(counter->output, output_counter); | ||
| 4283 | mutex_unlock(&counter->mmap_mutex); | ||
| 4284 | |||
| 4285 | if (old_output) { | ||
| 4286 | /* | ||
| 4287 | * we need to make sure no existing perf_output_*() | ||
| 4288 | * is still referencing this counter. | ||
| 4289 | */ | ||
| 4290 | synchronize_rcu(); | ||
| 4291 | fput(old_output->filp); | ||
| 4292 | } | ||
| 4293 | |||
| 4294 | ret = 0; | ||
| 4295 | out: | ||
| 4296 | fput_light(output_file, fput_needed); | ||
| 4297 | return ret; | ||
| 4298 | } | ||
| 4299 | |||
| 4205 | /** | 4300 | /** |
| 4206 | * sys_perf_counter_open - open a performance counter, associate it to a task/cpu | 4301 | * sys_perf_counter_open - open a performance counter, associate it to a task/cpu |
| 4207 | * | 4302 | * |
| @@ -4221,15 +4316,15 @@ SYSCALL_DEFINE5(perf_counter_open, | |||
| 4221 | struct file *group_file = NULL; | 4316 | struct file *group_file = NULL; |
| 4222 | int fput_needed = 0; | 4317 | int fput_needed = 0; |
| 4223 | int fput_needed2 = 0; | 4318 | int fput_needed2 = 0; |
| 4224 | int ret; | 4319 | int err; |
| 4225 | 4320 | ||
| 4226 | /* for future expandability... */ | 4321 | /* for future expandability... */ |
| 4227 | if (flags) | 4322 | if (flags & ~(PERF_FLAG_FD_NO_GROUP | PERF_FLAG_FD_OUTPUT)) |
| 4228 | return -EINVAL; | 4323 | return -EINVAL; |
| 4229 | 4324 | ||
| 4230 | ret = perf_copy_attr(attr_uptr, &attr); | 4325 | err = perf_copy_attr(attr_uptr, &attr); |
| 4231 | if (ret) | 4326 | if (err) |
| 4232 | return ret; | 4327 | return err; |
| 4233 | 4328 | ||
| 4234 | if (!attr.exclude_kernel) { | 4329 | if (!attr.exclude_kernel) { |
| 4235 | if (perf_paranoid_kernel() && !capable(CAP_SYS_ADMIN)) | 4330 | if (perf_paranoid_kernel() && !capable(CAP_SYS_ADMIN)) |
| @@ -4252,8 +4347,8 @@ SYSCALL_DEFINE5(perf_counter_open, | |||
| 4252 | * Look up the group leader (we will attach this counter to it): | 4347 | * Look up the group leader (we will attach this counter to it): |
| 4253 | */ | 4348 | */ |
| 4254 | group_leader = NULL; | 4349 | group_leader = NULL; |
| 4255 | if (group_fd != -1) { | 4350 | if (group_fd != -1 && !(flags & PERF_FLAG_FD_NO_GROUP)) { |
| 4256 | ret = -EINVAL; | 4351 | err = -EINVAL; |
| 4257 | group_file = fget_light(group_fd, &fput_needed); | 4352 | group_file = fget_light(group_fd, &fput_needed); |
| 4258 | if (!group_file) | 4353 | if (!group_file) |
| 4259 | goto err_put_context; | 4354 | goto err_put_context; |
| @@ -4282,18 +4377,24 @@ SYSCALL_DEFINE5(perf_counter_open, | |||
| 4282 | 4377 | ||
| 4283 | counter = perf_counter_alloc(&attr, cpu, ctx, group_leader, | 4378 | counter = perf_counter_alloc(&attr, cpu, ctx, group_leader, |
| 4284 | NULL, GFP_KERNEL); | 4379 | NULL, GFP_KERNEL); |
| 4285 | ret = PTR_ERR(counter); | 4380 | err = PTR_ERR(counter); |
| 4286 | if (IS_ERR(counter)) | 4381 | if (IS_ERR(counter)) |
| 4287 | goto err_put_context; | 4382 | goto err_put_context; |
| 4288 | 4383 | ||
| 4289 | ret = anon_inode_getfd("[perf_counter]", &perf_fops, counter, 0); | 4384 | err = anon_inode_getfd("[perf_counter]", &perf_fops, counter, 0); |
| 4290 | if (ret < 0) | 4385 | if (err < 0) |
| 4291 | goto err_free_put_context; | 4386 | goto err_free_put_context; |
| 4292 | 4387 | ||
| 4293 | counter_file = fget_light(ret, &fput_needed2); | 4388 | counter_file = fget_light(err, &fput_needed2); |
| 4294 | if (!counter_file) | 4389 | if (!counter_file) |
| 4295 | goto err_free_put_context; | 4390 | goto err_free_put_context; |
| 4296 | 4391 | ||
| 4392 | if (flags & PERF_FLAG_FD_OUTPUT) { | ||
| 4393 | err = perf_counter_set_output(counter, group_fd); | ||
| 4394 | if (err) | ||
| 4395 | goto err_fput_free_put_context; | ||
| 4396 | } | ||
| 4397 | |||
| 4297 | counter->filp = counter_file; | 4398 | counter->filp = counter_file; |
| 4298 | WARN_ON_ONCE(ctx->parent_ctx); | 4399 | WARN_ON_ONCE(ctx->parent_ctx); |
| 4299 | mutex_lock(&ctx->mutex); | 4400 | mutex_lock(&ctx->mutex); |
| @@ -4307,20 +4408,20 @@ SYSCALL_DEFINE5(perf_counter_open, | |||
| 4307 | list_add_tail(&counter->owner_entry, ¤t->perf_counter_list); | 4408 | list_add_tail(&counter->owner_entry, ¤t->perf_counter_list); |
| 4308 | mutex_unlock(¤t->perf_counter_mutex); | 4409 | mutex_unlock(¤t->perf_counter_mutex); |
| 4309 | 4410 | ||
| 4411 | err_fput_free_put_context: | ||
| 4310 | fput_light(counter_file, fput_needed2); | 4412 | fput_light(counter_file, fput_needed2); |
| 4311 | 4413 | ||
| 4312 | out_fput: | ||
| 4313 | fput_light(group_file, fput_needed); | ||
| 4314 | |||
| 4315 | return ret; | ||
| 4316 | |||
| 4317 | err_free_put_context: | 4414 | err_free_put_context: |
| 4318 | kfree(counter); | 4415 | if (err < 0) |
| 4416 | kfree(counter); | ||
| 4319 | 4417 | ||
| 4320 | err_put_context: | 4418 | err_put_context: |
| 4321 | put_ctx(ctx); | 4419 | if (err < 0) |
| 4420 | put_ctx(ctx); | ||
| 4421 | |||
| 4422 | fput_light(group_file, fput_needed); | ||
| 4322 | 4423 | ||
| 4323 | goto out_fput; | 4424 | return err; |
| 4324 | } | 4425 | } |
| 4325 | 4426 | ||
| 4326 | /* | 4427 | /* |
diff --git a/kernel/printk.c b/kernel/printk.c index b4d97b54c1ec..602033acd6c7 100644 --- a/kernel/printk.c +++ b/kernel/printk.c | |||
| @@ -37,6 +37,12 @@ | |||
| 37 | #include <asm/uaccess.h> | 37 | #include <asm/uaccess.h> |
| 38 | 38 | ||
| 39 | /* | 39 | /* |
| 40 | * for_each_console() allows you to iterate on each console | ||
| 41 | */ | ||
| 42 | #define for_each_console(con) \ | ||
| 43 | for (con = console_drivers; con != NULL; con = con->next) | ||
| 44 | |||
| 45 | /* | ||
| 40 | * Architectures can override it: | 46 | * Architectures can override it: |
| 41 | */ | 47 | */ |
| 42 | void asmlinkage __attribute__((weak)) early_printk(const char *fmt, ...) | 48 | void asmlinkage __attribute__((weak)) early_printk(const char *fmt, ...) |
| @@ -61,6 +67,8 @@ int console_printk[4] = { | |||
| 61 | DEFAULT_CONSOLE_LOGLEVEL, /* default_console_loglevel */ | 67 | DEFAULT_CONSOLE_LOGLEVEL, /* default_console_loglevel */ |
| 62 | }; | 68 | }; |
| 63 | 69 | ||
| 70 | static int saved_console_loglevel = -1; | ||
| 71 | |||
| 64 | /* | 72 | /* |
| 65 | * Low level drivers may need that to know if they can schedule in | 73 | * Low level drivers may need that to know if they can schedule in |
| 66 | * their unblank() callback or not. So let's export it. | 74 | * their unblank() callback or not. So let's export it. |
| @@ -372,10 +380,15 @@ int do_syslog(int type, char __user *buf, int len) | |||
| 372 | logged_chars = 0; | 380 | logged_chars = 0; |
| 373 | break; | 381 | break; |
| 374 | case 6: /* Disable logging to console */ | 382 | case 6: /* Disable logging to console */ |
| 383 | if (saved_console_loglevel == -1) | ||
| 384 | saved_console_loglevel = console_loglevel; | ||
| 375 | console_loglevel = minimum_console_loglevel; | 385 | console_loglevel = minimum_console_loglevel; |
| 376 | break; | 386 | break; |
| 377 | case 7: /* Enable logging to console */ | 387 | case 7: /* Enable logging to console */ |
| 378 | console_loglevel = default_console_loglevel; | 388 | if (saved_console_loglevel != -1) { |
| 389 | console_loglevel = saved_console_loglevel; | ||
| 390 | saved_console_loglevel = -1; | ||
| 391 | } | ||
| 379 | break; | 392 | break; |
| 380 | case 8: /* Set level of messages printed to console */ | 393 | case 8: /* Set level of messages printed to console */ |
| 381 | error = -EINVAL; | 394 | error = -EINVAL; |
| @@ -384,6 +397,8 @@ int do_syslog(int type, char __user *buf, int len) | |||
| 384 | if (len < minimum_console_loglevel) | 397 | if (len < minimum_console_loglevel) |
| 385 | len = minimum_console_loglevel; | 398 | len = minimum_console_loglevel; |
| 386 | console_loglevel = len; | 399 | console_loglevel = len; |
| 400 | /* Implicitly re-enable logging to console */ | ||
| 401 | saved_console_loglevel = -1; | ||
| 387 | error = 0; | 402 | error = 0; |
| 388 | break; | 403 | break; |
| 389 | case 9: /* Number of chars in the log buffer */ | 404 | case 9: /* Number of chars in the log buffer */ |
| @@ -412,7 +427,7 @@ static void __call_console_drivers(unsigned start, unsigned end) | |||
| 412 | { | 427 | { |
| 413 | struct console *con; | 428 | struct console *con; |
| 414 | 429 | ||
| 415 | for (con = console_drivers; con; con = con->next) { | 430 | for_each_console(con) { |
| 416 | if ((con->flags & CON_ENABLED) && con->write && | 431 | if ((con->flags & CON_ENABLED) && con->write && |
| 417 | (cpu_online(smp_processor_id()) || | 432 | (cpu_online(smp_processor_id()) || |
| 418 | (con->flags & CON_ANYTIME))) | 433 | (con->flags & CON_ANYTIME))) |
| @@ -544,7 +559,7 @@ static int have_callable_console(void) | |||
| 544 | { | 559 | { |
| 545 | struct console *con; | 560 | struct console *con; |
| 546 | 561 | ||
| 547 | for (con = console_drivers; con; con = con->next) | 562 | for_each_console(con) |
| 548 | if (con->flags & CON_ANYTIME) | 563 | if (con->flags & CON_ANYTIME) |
| 549 | return 1; | 564 | return 1; |
| 550 | 565 | ||
| @@ -1060,12 +1075,6 @@ void __sched console_conditional_schedule(void) | |||
| 1060 | } | 1075 | } |
| 1061 | EXPORT_SYMBOL(console_conditional_schedule); | 1076 | EXPORT_SYMBOL(console_conditional_schedule); |
| 1062 | 1077 | ||
| 1063 | void console_print(const char *s) | ||
| 1064 | { | ||
| 1065 | printk(KERN_EMERG "%s", s); | ||
| 1066 | } | ||
| 1067 | EXPORT_SYMBOL(console_print); | ||
| 1068 | |||
| 1069 | void console_unblank(void) | 1078 | void console_unblank(void) |
| 1070 | { | 1079 | { |
| 1071 | struct console *c; | 1080 | struct console *c; |
| @@ -1082,7 +1091,7 @@ void console_unblank(void) | |||
| 1082 | 1091 | ||
| 1083 | console_locked = 1; | 1092 | console_locked = 1; |
| 1084 | console_may_schedule = 0; | 1093 | console_may_schedule = 0; |
| 1085 | for (c = console_drivers; c != NULL; c = c->next) | 1094 | for_each_console(c) |
| 1086 | if ((c->flags & CON_ENABLED) && c->unblank) | 1095 | if ((c->flags & CON_ENABLED) && c->unblank) |
| 1087 | c->unblank(); | 1096 | c->unblank(); |
| 1088 | release_console_sem(); | 1097 | release_console_sem(); |
| @@ -1097,7 +1106,7 @@ struct tty_driver *console_device(int *index) | |||
| 1097 | struct tty_driver *driver = NULL; | 1106 | struct tty_driver *driver = NULL; |
| 1098 | 1107 | ||
| 1099 | acquire_console_sem(); | 1108 | acquire_console_sem(); |
| 1100 | for (c = console_drivers; c != NULL; c = c->next) { | 1109 | for_each_console(c) { |
| 1101 | if (!c->device) | 1110 | if (!c->device) |
| 1102 | continue; | 1111 | continue; |
| 1103 | driver = c->device(c, index); | 1112 | driver = c->device(c, index); |
| @@ -1134,25 +1143,49 @@ EXPORT_SYMBOL(console_start); | |||
| 1134 | * to register the console printing procedure with printk() and to | 1143 | * to register the console printing procedure with printk() and to |
| 1135 | * print any messages that were printed by the kernel before the | 1144 | * print any messages that were printed by the kernel before the |
| 1136 | * console driver was initialized. | 1145 | * console driver was initialized. |
| 1146 | * | ||
| 1147 | * This can happen pretty early during the boot process (because of | ||
| 1148 | * early_printk) - sometimes before setup_arch() completes - be careful | ||
| 1149 | * of what kernel features are used - they may not be initialised yet. | ||
| 1150 | * | ||
| 1151 | * There are two types of consoles - bootconsoles (early_printk) and | ||
| 1152 | * "real" consoles (everything which is not a bootconsole) which are | ||
| 1153 | * handled differently. | ||
| 1154 | * - Any number of bootconsoles can be registered at any time. | ||
| 1155 | * - As soon as a "real" console is registered, all bootconsoles | ||
| 1156 | * will be unregistered automatically. | ||
| 1157 | * - Once a "real" console is registered, any attempt to register a | ||
| 1158 | * bootconsoles will be rejected | ||
| 1137 | */ | 1159 | */ |
| 1138 | void register_console(struct console *console) | 1160 | void register_console(struct console *newcon) |
| 1139 | { | 1161 | { |
| 1140 | int i; | 1162 | int i; |
| 1141 | unsigned long flags; | 1163 | unsigned long flags; |
| 1142 | struct console *bootconsole = NULL; | 1164 | struct console *bcon = NULL; |
| 1143 | 1165 | ||
| 1144 | if (console_drivers) { | 1166 | /* |
| 1145 | if (console->flags & CON_BOOT) | 1167 | * before we register a new CON_BOOT console, make sure we don't |
| 1146 | return; | 1168 | * already have a valid console |
| 1147 | if (console_drivers->flags & CON_BOOT) | 1169 | */ |
| 1148 | bootconsole = console_drivers; | 1170 | if (console_drivers && newcon->flags & CON_BOOT) { |
| 1171 | /* find the last or real console */ | ||
| 1172 | for_each_console(bcon) { | ||
| 1173 | if (!(bcon->flags & CON_BOOT)) { | ||
| 1174 | printk(KERN_INFO "Too late to register bootconsole %s%d\n", | ||
| 1175 | newcon->name, newcon->index); | ||
| 1176 | return; | ||
| 1177 | } | ||
| 1178 | } | ||
| 1149 | } | 1179 | } |
| 1150 | 1180 | ||
| 1151 | if (preferred_console < 0 || bootconsole || !console_drivers) | 1181 | if (console_drivers && console_drivers->flags & CON_BOOT) |
| 1182 | bcon = console_drivers; | ||
| 1183 | |||
| 1184 | if (preferred_console < 0 || bcon || !console_drivers) | ||
| 1152 | preferred_console = selected_console; | 1185 | preferred_console = selected_console; |
| 1153 | 1186 | ||
| 1154 | if (console->early_setup) | 1187 | if (newcon->early_setup) |
| 1155 | console->early_setup(); | 1188 | newcon->early_setup(); |
| 1156 | 1189 | ||
| 1157 | /* | 1190 | /* |
| 1158 | * See if we want to use this console driver. If we | 1191 | * See if we want to use this console driver. If we |
| @@ -1160,13 +1193,13 @@ void register_console(struct console *console) | |||
| 1160 | * that registers here. | 1193 | * that registers here. |
| 1161 | */ | 1194 | */ |
| 1162 | if (preferred_console < 0) { | 1195 | if (preferred_console < 0) { |
| 1163 | if (console->index < 0) | 1196 | if (newcon->index < 0) |
| 1164 | console->index = 0; | 1197 | newcon->index = 0; |
| 1165 | if (console->setup == NULL || | 1198 | if (newcon->setup == NULL || |
| 1166 | console->setup(console, NULL) == 0) { | 1199 | newcon->setup(newcon, NULL) == 0) { |
| 1167 | console->flags |= CON_ENABLED; | 1200 | newcon->flags |= CON_ENABLED; |
| 1168 | if (console->device) { | 1201 | if (newcon->device) { |
| 1169 | console->flags |= CON_CONSDEV; | 1202 | newcon->flags |= CON_CONSDEV; |
| 1170 | preferred_console = 0; | 1203 | preferred_console = 0; |
| 1171 | } | 1204 | } |
| 1172 | } | 1205 | } |
| @@ -1178,64 +1211,62 @@ void register_console(struct console *console) | |||
| 1178 | */ | 1211 | */ |
| 1179 | for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; | 1212 | for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; |
| 1180 | i++) { | 1213 | i++) { |
| 1181 | if (strcmp(console_cmdline[i].name, console->name) != 0) | 1214 | if (strcmp(console_cmdline[i].name, newcon->name) != 0) |
| 1182 | continue; | 1215 | continue; |
| 1183 | if (console->index >= 0 && | 1216 | if (newcon->index >= 0 && |
| 1184 | console->index != console_cmdline[i].index) | 1217 | newcon->index != console_cmdline[i].index) |
| 1185 | continue; | 1218 | continue; |
| 1186 | if (console->index < 0) | 1219 | if (newcon->index < 0) |
| 1187 | console->index = console_cmdline[i].index; | 1220 | newcon->index = console_cmdline[i].index; |
| 1188 | #ifdef CONFIG_A11Y_BRAILLE_CONSOLE | 1221 | #ifdef CONFIG_A11Y_BRAILLE_CONSOLE |
| 1189 | if (console_cmdline[i].brl_options) { | 1222 | if (console_cmdline[i].brl_options) { |
| 1190 | console->flags |= CON_BRL; | 1223 | newcon->flags |= CON_BRL; |
| 1191 | braille_register_console(console, | 1224 | braille_register_console(newcon, |
| 1192 | console_cmdline[i].index, | 1225 | console_cmdline[i].index, |
| 1193 | console_cmdline[i].options, | 1226 | console_cmdline[i].options, |
| 1194 | console_cmdline[i].brl_options); | 1227 | console_cmdline[i].brl_options); |
| 1195 | return; | 1228 | return; |
| 1196 | } | 1229 | } |
| 1197 | #endif | 1230 | #endif |
| 1198 | if (console->setup && | 1231 | if (newcon->setup && |
| 1199 | console->setup(console, console_cmdline[i].options) != 0) | 1232 | newcon->setup(newcon, console_cmdline[i].options) != 0) |
| 1200 | break; | 1233 | break; |
| 1201 | console->flags |= CON_ENABLED; | 1234 | newcon->flags |= CON_ENABLED; |
| 1202 | console->index = console_cmdline[i].index; | 1235 | newcon->index = console_cmdline[i].index; |
| 1203 | if (i == selected_console) { | 1236 | if (i == selected_console) { |
| 1204 | console->flags |= CON_CONSDEV; | 1237 | newcon->flags |= CON_CONSDEV; |
| 1205 | preferred_console = selected_console; | 1238 | preferred_console = selected_console; |
| 1206 | } | 1239 | } |
| 1207 | break; | 1240 | break; |
| 1208 | } | 1241 | } |
| 1209 | 1242 | ||
| 1210 | if (!(console->flags & CON_ENABLED)) | 1243 | if (!(newcon->flags & CON_ENABLED)) |
| 1211 | return; | 1244 | return; |
| 1212 | 1245 | ||
| 1213 | if (bootconsole && (console->flags & CON_CONSDEV)) { | 1246 | /* |
| 1214 | printk(KERN_INFO "console handover: boot [%s%d] -> real [%s%d]\n", | 1247 | * If we have a bootconsole, and are switching to a real console, |
| 1215 | bootconsole->name, bootconsole->index, | 1248 | * don't print everything out again, since when the boot console, and |
| 1216 | console->name, console->index); | 1249 | * the real console are the same physical device, it's annoying to |
| 1217 | unregister_console(bootconsole); | 1250 | * see the beginning boot messages twice |
| 1218 | console->flags &= ~CON_PRINTBUFFER; | 1251 | */ |
| 1219 | } else { | 1252 | if (bcon && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV)) |
| 1220 | printk(KERN_INFO "console [%s%d] enabled\n", | 1253 | newcon->flags &= ~CON_PRINTBUFFER; |
| 1221 | console->name, console->index); | ||
| 1222 | } | ||
| 1223 | 1254 | ||
| 1224 | /* | 1255 | /* |
| 1225 | * Put this console in the list - keep the | 1256 | * Put this console in the list - keep the |
| 1226 | * preferred driver at the head of the list. | 1257 | * preferred driver at the head of the list. |
| 1227 | */ | 1258 | */ |
| 1228 | acquire_console_sem(); | 1259 | acquire_console_sem(); |
| 1229 | if ((console->flags & CON_CONSDEV) || console_drivers == NULL) { | 1260 | if ((newcon->flags & CON_CONSDEV) || console_drivers == NULL) { |
| 1230 | console->next = console_drivers; | 1261 | newcon->next = console_drivers; |
| 1231 | console_drivers = console; | 1262 | console_drivers = newcon; |
| 1232 | if (console->next) | 1263 | if (newcon->next) |
| 1233 | console->next->flags &= ~CON_CONSDEV; | 1264 | newcon->next->flags &= ~CON_CONSDEV; |
| 1234 | } else { | 1265 | } else { |
| 1235 | console->next = console_drivers->next; | 1266 | newcon->next = console_drivers->next; |
| 1236 | console_drivers->next = console; | 1267 | console_drivers->next = newcon; |
| 1237 | } | 1268 | } |
| 1238 | if (console->flags & CON_PRINTBUFFER) { | 1269 | if (newcon->flags & CON_PRINTBUFFER) { |
| 1239 | /* | 1270 | /* |
| 1240 | * release_console_sem() will print out the buffered messages | 1271 | * release_console_sem() will print out the buffered messages |
| 1241 | * for us. | 1272 | * for us. |
| @@ -1245,6 +1276,28 @@ void register_console(struct console *console) | |||
| 1245 | spin_unlock_irqrestore(&logbuf_lock, flags); | 1276 | spin_unlock_irqrestore(&logbuf_lock, flags); |
| 1246 | } | 1277 | } |
| 1247 | release_console_sem(); | 1278 | release_console_sem(); |
| 1279 | |||
| 1280 | /* | ||
| 1281 | * By unregistering the bootconsoles after we enable the real console | ||
| 1282 | * we get the "console xxx enabled" message on all the consoles - | ||
| 1283 | * boot consoles, real consoles, etc - this is to ensure that end | ||
| 1284 | * users know there might be something in the kernel's log buffer that | ||
| 1285 | * went to the bootconsole (that they do not see on the real console) | ||
| 1286 | */ | ||
| 1287 | if (bcon && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV)) { | ||
| 1288 | /* we need to iterate through twice, to make sure we print | ||
| 1289 | * everything out, before we unregister the console(s) | ||
| 1290 | */ | ||
| 1291 | printk(KERN_INFO "console [%s%d] enabled, bootconsole disabled\n", | ||
| 1292 | newcon->name, newcon->index); | ||
| 1293 | for_each_console(bcon) | ||
| 1294 | if (bcon->flags & CON_BOOT) | ||
| 1295 | unregister_console(bcon); | ||
| 1296 | } else { | ||
| 1297 | printk(KERN_INFO "%sconsole [%s%d] enabled\n", | ||
| 1298 | (newcon->flags & CON_BOOT) ? "boot" : "" , | ||
| 1299 | newcon->name, newcon->index); | ||
| 1300 | } | ||
| 1248 | } | 1301 | } |
| 1249 | EXPORT_SYMBOL(register_console); | 1302 | EXPORT_SYMBOL(register_console); |
| 1250 | 1303 | ||
| @@ -1287,11 +1340,13 @@ EXPORT_SYMBOL(unregister_console); | |||
| 1287 | 1340 | ||
| 1288 | static int __init disable_boot_consoles(void) | 1341 | static int __init disable_boot_consoles(void) |
| 1289 | { | 1342 | { |
| 1290 | if (console_drivers != NULL) { | 1343 | struct console *con; |
| 1291 | if (console_drivers->flags & CON_BOOT) { | 1344 | |
| 1345 | for_each_console(con) { | ||
| 1346 | if (con->flags & CON_BOOT) { | ||
| 1292 | printk(KERN_INFO "turn off boot console %s%d\n", | 1347 | printk(KERN_INFO "turn off boot console %s%d\n", |
| 1293 | console_drivers->name, console_drivers->index); | 1348 | con->name, con->index); |
| 1294 | return unregister_console(console_drivers); | 1349 | unregister_console(con); |
| 1295 | } | 1350 | } |
| 1296 | } | 1351 | } |
| 1297 | return 0; | 1352 | return 0; |
diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 082c320e4dbf..307c285af59e 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c | |||
| @@ -152,7 +152,7 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode) | |||
| 152 | if (!dumpable && !capable(CAP_SYS_PTRACE)) | 152 | if (!dumpable && !capable(CAP_SYS_PTRACE)) |
| 153 | return -EPERM; | 153 | return -EPERM; |
| 154 | 154 | ||
| 155 | return security_ptrace_may_access(task, mode); | 155 | return security_ptrace_access_check(task, mode); |
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | bool ptrace_may_access(struct task_struct *task, unsigned int mode) | 158 | bool ptrace_may_access(struct task_struct *task, unsigned int mode) |
diff --git a/kernel/rcuclassic.c b/kernel/rcuclassic.c deleted file mode 100644 index 0f2b0b311304..000000000000 --- a/kernel/rcuclassic.c +++ /dev/null | |||
| @@ -1,807 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Read-Copy Update mechanism for mutual exclusion | ||
| 3 | * | ||
| 4 | * This program is free software; you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License as published by | ||
| 6 | * the Free Software Foundation; either version 2 of the License, or | ||
| 7 | * (at your option) any later version. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 17 | * | ||
| 18 | * Copyright IBM Corporation, 2001 | ||
| 19 | * | ||
| 20 | * Authors: Dipankar Sarma <dipankar@in.ibm.com> | ||
| 21 | * Manfred Spraul <manfred@colorfullife.com> | ||
| 22 | * | ||
| 23 | * Based on the original work by Paul McKenney <paulmck@us.ibm.com> | ||
| 24 | * and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen. | ||
| 25 | * Papers: | ||
| 26 | * http://www.rdrop.com/users/paulmck/paper/rclockpdcsproof.pdf | ||
| 27 | * http://lse.sourceforge.net/locking/rclock_OLS.2001.05.01c.sc.pdf (OLS2001) | ||
| 28 | * | ||
| 29 | * For detailed explanation of Read-Copy Update mechanism see - | ||
| 30 | * Documentation/RCU | ||
| 31 | * | ||
| 32 | */ | ||
| 33 | #include <linux/types.h> | ||
| 34 | #include <linux/kernel.h> | ||
| 35 | #include <linux/init.h> | ||
| 36 | #include <linux/spinlock.h> | ||
| 37 | #include <linux/smp.h> | ||
| 38 | #include <linux/rcupdate.h> | ||
| 39 | #include <linux/interrupt.h> | ||
| 40 | #include <linux/sched.h> | ||
| 41 | #include <asm/atomic.h> | ||
| 42 | #include <linux/bitops.h> | ||
| 43 | #include <linux/module.h> | ||
| 44 | #include <linux/completion.h> | ||
| 45 | #include <linux/moduleparam.h> | ||
| 46 | #include <linux/percpu.h> | ||
| 47 | #include <linux/notifier.h> | ||
| 48 | #include <linux/cpu.h> | ||
| 49 | #include <linux/mutex.h> | ||
| 50 | #include <linux/time.h> | ||
| 51 | |||
| 52 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | ||
| 53 | static struct lock_class_key rcu_lock_key; | ||
| 54 | struct lockdep_map rcu_lock_map = | ||
| 55 | STATIC_LOCKDEP_MAP_INIT("rcu_read_lock", &rcu_lock_key); | ||
| 56 | EXPORT_SYMBOL_GPL(rcu_lock_map); | ||
| 57 | #endif | ||
| 58 | |||
| 59 | |||
| 60 | /* Definition for rcupdate control block. */ | ||
| 61 | static struct rcu_ctrlblk rcu_ctrlblk = { | ||
| 62 | .cur = -300, | ||
| 63 | .completed = -300, | ||
| 64 | .pending = -300, | ||
| 65 | .lock = __SPIN_LOCK_UNLOCKED(&rcu_ctrlblk.lock), | ||
| 66 | .cpumask = CPU_BITS_NONE, | ||
| 67 | }; | ||
| 68 | |||
| 69 | static struct rcu_ctrlblk rcu_bh_ctrlblk = { | ||
| 70 | .cur = -300, | ||
| 71 | .completed = -300, | ||
| 72 | .pending = -300, | ||
| 73 | .lock = __SPIN_LOCK_UNLOCKED(&rcu_bh_ctrlblk.lock), | ||
| 74 | .cpumask = CPU_BITS_NONE, | ||
| 75 | }; | ||
| 76 | |||
| 77 | static DEFINE_PER_CPU(struct rcu_data, rcu_data); | ||
| 78 | static DEFINE_PER_CPU(struct rcu_data, rcu_bh_data); | ||
| 79 | |||
| 80 | /* | ||
| 81 | * Increment the quiescent state counter. | ||
| 82 | * The counter is a bit degenerated: We do not need to know | ||
| 83 | * how many quiescent states passed, just if there was at least | ||
| 84 | * one since the start of the grace period. Thus just a flag. | ||
| 85 | */ | ||
| 86 | void rcu_qsctr_inc(int cpu) | ||
| 87 | { | ||
| 88 | struct rcu_data *rdp = &per_cpu(rcu_data, cpu); | ||
| 89 | rdp->passed_quiesc = 1; | ||
| 90 | } | ||
| 91 | |||
| 92 | void rcu_bh_qsctr_inc(int cpu) | ||
| 93 | { | ||
| 94 | struct rcu_data *rdp = &per_cpu(rcu_bh_data, cpu); | ||
| 95 | rdp->passed_quiesc = 1; | ||
| 96 | } | ||
| 97 | |||
| 98 | static int blimit = 10; | ||
| 99 | static int qhimark = 10000; | ||
| 100 | static int qlowmark = 100; | ||
| 101 | |||
| 102 | #ifdef CONFIG_SMP | ||
| 103 | static void force_quiescent_state(struct rcu_data *rdp, | ||
| 104 | struct rcu_ctrlblk *rcp) | ||
| 105 | { | ||
| 106 | int cpu; | ||
| 107 | unsigned long flags; | ||
| 108 | |||
| 109 | set_need_resched(); | ||
| 110 | spin_lock_irqsave(&rcp->lock, flags); | ||
| 111 | if (unlikely(!rcp->signaled)) { | ||
| 112 | rcp->signaled = 1; | ||
| 113 | /* | ||
| 114 | * Don't send IPI to itself. With irqs disabled, | ||
| 115 | * rdp->cpu is the current cpu. | ||
| 116 | * | ||
| 117 | * cpu_online_mask is updated by the _cpu_down() | ||
| 118 | * using __stop_machine(). Since we're in irqs disabled | ||
| 119 | * section, __stop_machine() is not exectuting, hence | ||
| 120 | * the cpu_online_mask is stable. | ||
| 121 | * | ||
| 122 | * However, a cpu might have been offlined _just_ before | ||
| 123 | * we disabled irqs while entering here. | ||
| 124 | * And rcu subsystem might not yet have handled the CPU_DEAD | ||
| 125 | * notification, leading to the offlined cpu's bit | ||
| 126 | * being set in the rcp->cpumask. | ||
| 127 | * | ||
| 128 | * Hence cpumask = (rcp->cpumask & cpu_online_mask) to prevent | ||
| 129 | * sending smp_reschedule() to an offlined CPU. | ||
| 130 | */ | ||
| 131 | for_each_cpu_and(cpu, | ||
| 132 | to_cpumask(rcp->cpumask), cpu_online_mask) { | ||
| 133 | if (cpu != rdp->cpu) | ||
| 134 | smp_send_reschedule(cpu); | ||
| 135 | } | ||
| 136 | } | ||
| 137 | spin_unlock_irqrestore(&rcp->lock, flags); | ||
| 138 | } | ||
| 139 | #else | ||
| 140 | static inline void force_quiescent_state(struct rcu_data *rdp, | ||
| 141 | struct rcu_ctrlblk *rcp) | ||
| 142 | { | ||
| 143 | set_need_resched(); | ||
| 144 | } | ||
| 145 | #endif | ||
| 146 | |||
| 147 | static void __call_rcu(struct rcu_head *head, struct rcu_ctrlblk *rcp, | ||
| 148 | struct rcu_data *rdp) | ||
| 149 | { | ||
| 150 | long batch; | ||
| 151 | |||
| 152 | head->next = NULL; | ||
| 153 | smp_mb(); /* Read of rcu->cur must happen after any change by caller. */ | ||
| 154 | |||
| 155 | /* | ||
| 156 | * Determine the batch number of this callback. | ||
| 157 | * | ||
| 158 | * Using ACCESS_ONCE to avoid the following error when gcc eliminates | ||
| 159 | * local variable "batch" and emits codes like this: | ||
| 160 | * 1) rdp->batch = rcp->cur + 1 # gets old value | ||
| 161 | * ...... | ||
| 162 | * 2)rcu_batch_after(rcp->cur + 1, rdp->batch) # gets new value | ||
| 163 | * then [*nxttail[0], *nxttail[1]) may contain callbacks | ||
| 164 | * that batch# = rdp->batch, see the comment of struct rcu_data. | ||
| 165 | */ | ||
| 166 | batch = ACCESS_ONCE(rcp->cur) + 1; | ||
| 167 | |||
| 168 | if (rdp->nxtlist && rcu_batch_after(batch, rdp->batch)) { | ||
| 169 | /* process callbacks */ | ||
| 170 | rdp->nxttail[0] = rdp->nxttail[1]; | ||
| 171 | rdp->nxttail[1] = rdp->nxttail[2]; | ||
| 172 | if (rcu_batch_after(batch - 1, rdp->batch)) | ||
| 173 | rdp->nxttail[0] = rdp->nxttail[2]; | ||
| 174 | } | ||
| 175 | |||
| 176 | rdp->batch = batch; | ||
| 177 | *rdp->nxttail[2] = head; | ||
| 178 | rdp->nxttail[2] = &head->next; | ||
| 179 | |||
| 180 | if (unlikely(++rdp->qlen > qhimark)) { | ||
| 181 | rdp->blimit = INT_MAX; | ||
| 182 | force_quiescent_state(rdp, &rcu_ctrlblk); | ||
| 183 | } | ||
| 184 | } | ||
| 185 | |||
| 186 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | ||
| 187 | |||
| 188 | static void record_gp_stall_check_time(struct rcu_ctrlblk *rcp) | ||
| 189 | { | ||
| 190 | rcp->gp_start = jiffies; | ||
| 191 | rcp->jiffies_stall = jiffies + RCU_SECONDS_TILL_STALL_CHECK; | ||
| 192 | } | ||
| 193 | |||
| 194 | static void print_other_cpu_stall(struct rcu_ctrlblk *rcp) | ||
| 195 | { | ||
| 196 | int cpu; | ||
| 197 | long delta; | ||
| 198 | unsigned long flags; | ||
| 199 | |||
| 200 | /* Only let one CPU complain about others per time interval. */ | ||
| 201 | |||
| 202 | spin_lock_irqsave(&rcp->lock, flags); | ||
| 203 | delta = jiffies - rcp->jiffies_stall; | ||
| 204 | if (delta < 2 || rcp->cur != rcp->completed) { | ||
| 205 | spin_unlock_irqrestore(&rcp->lock, flags); | ||
| 206 | return; | ||
| 207 | } | ||
| 208 | rcp->jiffies_stall = jiffies + RCU_SECONDS_TILL_STALL_RECHECK; | ||
| 209 | spin_unlock_irqrestore(&rcp->lock, flags); | ||
| 210 | |||
| 211 | /* OK, time to rat on our buddy... */ | ||
| 212 | |||
| 213 | printk(KERN_ERR "INFO: RCU detected CPU stalls:"); | ||
| 214 | for_each_possible_cpu(cpu) { | ||
| 215 | if (cpumask_test_cpu(cpu, to_cpumask(rcp->cpumask))) | ||
| 216 | printk(" %d", cpu); | ||
| 217 | } | ||
| 218 | printk(" (detected by %d, t=%ld jiffies)\n", | ||
| 219 | smp_processor_id(), (long)(jiffies - rcp->gp_start)); | ||
| 220 | } | ||
| 221 | |||
| 222 | static void print_cpu_stall(struct rcu_ctrlblk *rcp) | ||
| 223 | { | ||
| 224 | unsigned long flags; | ||
| 225 | |||
| 226 | printk(KERN_ERR "INFO: RCU detected CPU %d stall (t=%lu/%lu jiffies)\n", | ||
| 227 | smp_processor_id(), jiffies, | ||
| 228 | jiffies - rcp->gp_start); | ||
| 229 | dump_stack(); | ||
| 230 | spin_lock_irqsave(&rcp->lock, flags); | ||
| 231 | if ((long)(jiffies - rcp->jiffies_stall) >= 0) | ||
| 232 | rcp->jiffies_stall = | ||
| 233 | jiffies + RCU_SECONDS_TILL_STALL_RECHECK; | ||
| 234 | spin_unlock_irqrestore(&rcp->lock, flags); | ||
| 235 | set_need_resched(); /* kick ourselves to get things going. */ | ||
| 236 | } | ||
| 237 | |||
| 238 | static void check_cpu_stall(struct rcu_ctrlblk *rcp) | ||
| 239 | { | ||
| 240 | long delta; | ||
| 241 | |||
| 242 | delta = jiffies - rcp->jiffies_stall; | ||
| 243 | if (cpumask_test_cpu(smp_processor_id(), to_cpumask(rcp->cpumask)) && | ||
| 244 | delta >= 0) { | ||
| 245 | |||
| 246 | /* We haven't checked in, so go dump stack. */ | ||
| 247 | print_cpu_stall(rcp); | ||
| 248 | |||
| 249 | } else if (rcp->cur != rcp->completed && delta >= 2) { | ||
| 250 | |||
| 251 | /* They had two seconds to dump stack, so complain. */ | ||
| 252 | print_other_cpu_stall(rcp); | ||
| 253 | } | ||
| 254 | } | ||
| 255 | |||
| 256 | #else /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | ||
| 257 | |||
| 258 | static void record_gp_stall_check_time(struct rcu_ctrlblk *rcp) | ||
| 259 | { | ||
| 260 | } | ||
| 261 | |||
| 262 | static inline void check_cpu_stall(struct rcu_ctrlblk *rcp) | ||
| 263 | { | ||
| 264 | } | ||
| 265 | |||
| 266 | #endif /* #else #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | ||
| 267 | |||
| 268 | /** | ||
| 269 | * call_rcu - Queue an RCU callback for invocation after a grace period. | ||
| 270 | * @head: structure to be used for queueing the RCU updates. | ||
| 271 | * @func: actual update function to be invoked after the grace period | ||
| 272 | * | ||
| 273 | * The update function will be invoked some time after a full grace | ||
| 274 | * period elapses, in other words after all currently executing RCU | ||
| 275 | * read-side critical sections have completed. RCU read-side critical | ||
| 276 | * sections are delimited by rcu_read_lock() and rcu_read_unlock(), | ||
| 277 | * and may be nested. | ||
| 278 | */ | ||
| 279 | void call_rcu(struct rcu_head *head, | ||
| 280 | void (*func)(struct rcu_head *rcu)) | ||
| 281 | { | ||
| 282 | unsigned long flags; | ||
| 283 | |||
| 284 | head->func = func; | ||
| 285 | local_irq_save(flags); | ||
| 286 | __call_rcu(head, &rcu_ctrlblk, &__get_cpu_var(rcu_data)); | ||
| 287 | local_irq_restore(flags); | ||
| 288 | } | ||
| 289 | EXPORT_SYMBOL_GPL(call_rcu); | ||
| 290 | |||
| 291 | /** | ||
| 292 | * call_rcu_bh - Queue an RCU for invocation after a quicker grace period. | ||
| 293 | * @head: structure to be used for queueing the RCU updates. | ||
| 294 | * @func: actual update function to be invoked after the grace period | ||
| 295 | * | ||
| 296 | * The update function will be invoked some time after a full grace | ||
| 297 | * period elapses, in other words after all currently executing RCU | ||
| 298 | * read-side critical sections have completed. call_rcu_bh() assumes | ||
| 299 | * that the read-side critical sections end on completion of a softirq | ||
| 300 | * handler. This means that read-side critical sections in process | ||
| 301 | * context must not be interrupted by softirqs. This interface is to be | ||
| 302 | * used when most of the read-side critical sections are in softirq context. | ||
| 303 | * RCU read-side critical sections are delimited by rcu_read_lock() and | ||
| 304 | * rcu_read_unlock(), * if in interrupt context or rcu_read_lock_bh() | ||
| 305 | * and rcu_read_unlock_bh(), if in process context. These may be nested. | ||
| 306 | */ | ||
| 307 | void call_rcu_bh(struct rcu_head *head, | ||
| 308 | void (*func)(struct rcu_head *rcu)) | ||
| 309 | { | ||
| 310 | unsigned long flags; | ||
| 311 | |||
| 312 | head->func = func; | ||
| 313 | local_irq_save(flags); | ||
| 314 | __call_rcu(head, &rcu_bh_ctrlblk, &__get_cpu_var(rcu_bh_data)); | ||
| 315 | local_irq_restore(flags); | ||
| 316 | } | ||
| 317 | EXPORT_SYMBOL_GPL(call_rcu_bh); | ||
| 318 | |||
| 319 | /* | ||
| 320 | * Return the number of RCU batches processed thus far. Useful | ||
| 321 | * for debug and statistics. | ||
| 322 | */ | ||
| 323 | long rcu_batches_completed(void) | ||
| 324 | { | ||
| 325 | return rcu_ctrlblk.completed; | ||
| 326 | } | ||
| 327 | EXPORT_SYMBOL_GPL(rcu_batches_completed); | ||
| 328 | |||
| 329 | /* | ||
| 330 | * Return the number of RCU batches processed thus far. Useful | ||
| 331 | * for debug and statistics. | ||
| 332 | */ | ||
| 333 | long rcu_batches_completed_bh(void) | ||
| 334 | { | ||
| 335 | return rcu_bh_ctrlblk.completed; | ||
| 336 | } | ||
| 337 | EXPORT_SYMBOL_GPL(rcu_batches_completed_bh); | ||
| 338 | |||
| 339 | /* Raises the softirq for processing rcu_callbacks. */ | ||
| 340 | static inline void raise_rcu_softirq(void) | ||
| 341 | { | ||
| 342 | raise_softirq(RCU_SOFTIRQ); | ||
| 343 | } | ||
| 344 | |||
| 345 | /* | ||
| 346 | * Invoke the completed RCU callbacks. They are expected to be in | ||
| 347 | * a per-cpu list. | ||
| 348 | */ | ||
| 349 | static void rcu_do_batch(struct rcu_data *rdp) | ||
| 350 | { | ||
| 351 | unsigned long flags; | ||
| 352 | struct rcu_head *next, *list; | ||
| 353 | int count = 0; | ||
| 354 | |||
| 355 | list = rdp->donelist; | ||
| 356 | while (list) { | ||
| 357 | next = list->next; | ||
| 358 | prefetch(next); | ||
| 359 | list->func(list); | ||
| 360 | list = next; | ||
| 361 | if (++count >= rdp->blimit) | ||
| 362 | break; | ||
| 363 | } | ||
| 364 | rdp->donelist = list; | ||
| 365 | |||
| 366 | local_irq_save(flags); | ||
| 367 | rdp->qlen -= count; | ||
| 368 | local_irq_restore(flags); | ||
| 369 | if (rdp->blimit == INT_MAX && rdp->qlen <= qlowmark) | ||
| 370 | rdp->blimit = blimit; | ||
| 371 | |||
| 372 | if (!rdp->donelist) | ||
| 373 | rdp->donetail = &rdp->donelist; | ||
| 374 | else | ||
| 375 | raise_rcu_softirq(); | ||
| 376 | } | ||
| 377 | |||
| 378 | /* | ||
| 379 | * Grace period handling: | ||
| 380 | * The grace period handling consists out of two steps: | ||
| 381 | * - A new grace period is started. | ||
| 382 | * This is done by rcu_start_batch. The start is not broadcasted to | ||
| 383 | * all cpus, they must pick this up by comparing rcp->cur with | ||
| 384 | * rdp->quiescbatch. All cpus are recorded in the | ||
| 385 | * rcu_ctrlblk.cpumask bitmap. | ||
| 386 | * - All cpus must go through a quiescent state. | ||
| 387 | * Since the start of the grace period is not broadcasted, at least two | ||
| 388 | * calls to rcu_check_quiescent_state are required: | ||
| 389 | * The first call just notices that a new grace period is running. The | ||
| 390 | * following calls check if there was a quiescent state since the beginning | ||
| 391 | * of the grace period. If so, it updates rcu_ctrlblk.cpumask. If | ||
| 392 | * the bitmap is empty, then the grace period is completed. | ||
| 393 | * rcu_check_quiescent_state calls rcu_start_batch(0) to start the next grace | ||
| 394 | * period (if necessary). | ||
| 395 | */ | ||
| 396 | |||
| 397 | /* | ||
| 398 | * Register a new batch of callbacks, and start it up if there is currently no | ||
| 399 | * active batch and the batch to be registered has not already occurred. | ||
| 400 | * Caller must hold rcu_ctrlblk.lock. | ||
| 401 | */ | ||
| 402 | static void rcu_start_batch(struct rcu_ctrlblk *rcp) | ||
| 403 | { | ||
| 404 | if (rcp->cur != rcp->pending && | ||
| 405 | rcp->completed == rcp->cur) { | ||
| 406 | rcp->cur++; | ||
| 407 | record_gp_stall_check_time(rcp); | ||
| 408 | |||
| 409 | /* | ||
| 410 | * Accessing nohz_cpu_mask before incrementing rcp->cur needs a | ||
| 411 | * Barrier Otherwise it can cause tickless idle CPUs to be | ||
| 412 | * included in rcp->cpumask, which will extend graceperiods | ||
| 413 | * unnecessarily. | ||
| 414 | */ | ||
| 415 | smp_mb(); | ||
| 416 | cpumask_andnot(to_cpumask(rcp->cpumask), | ||
| 417 | cpu_online_mask, nohz_cpu_mask); | ||
| 418 | |||
| 419 | rcp->signaled = 0; | ||
| 420 | } | ||
| 421 | } | ||
| 422 | |||
| 423 | /* | ||
| 424 | * cpu went through a quiescent state since the beginning of the grace period. | ||
| 425 | * Clear it from the cpu mask and complete the grace period if it was the last | ||
| 426 | * cpu. Start another grace period if someone has further entries pending | ||
| 427 | */ | ||
| 428 | static void cpu_quiet(int cpu, struct rcu_ctrlblk *rcp) | ||
| 429 | { | ||
| 430 | cpumask_clear_cpu(cpu, to_cpumask(rcp->cpumask)); | ||
| 431 | if (cpumask_empty(to_cpumask(rcp->cpumask))) { | ||
| 432 | /* batch completed ! */ | ||
| 433 | rcp->completed = rcp->cur; | ||
| 434 | rcu_start_batch(rcp); | ||
| 435 | } | ||
| 436 | } | ||
| 437 | |||
| 438 | /* | ||
| 439 | * Check if the cpu has gone through a quiescent state (say context | ||
| 440 | * switch). If so and if it already hasn't done so in this RCU | ||
| 441 | * quiescent cycle, then indicate that it has done so. | ||
| 442 | */ | ||
| 443 | static void rcu_check_quiescent_state(struct rcu_ctrlblk *rcp, | ||
| 444 | struct rcu_data *rdp) | ||
| 445 | { | ||
| 446 | unsigned long flags; | ||
| 447 | |||
| 448 | if (rdp->quiescbatch != rcp->cur) { | ||
| 449 | /* start new grace period: */ | ||
| 450 | rdp->qs_pending = 1; | ||
| 451 | rdp->passed_quiesc = 0; | ||
| 452 | rdp->quiescbatch = rcp->cur; | ||
| 453 | return; | ||
| 454 | } | ||
| 455 | |||
| 456 | /* Grace period already completed for this cpu? | ||
| 457 | * qs_pending is checked instead of the actual bitmap to avoid | ||
| 458 | * cacheline trashing. | ||
| 459 | */ | ||
| 460 | if (!rdp->qs_pending) | ||
| 461 | return; | ||
| 462 | |||
| 463 | /* | ||
| 464 | * Was there a quiescent state since the beginning of the grace | ||
| 465 | * period? If no, then exit and wait for the next call. | ||
| 466 | */ | ||
| 467 | if (!rdp->passed_quiesc) | ||
| 468 | return; | ||
| 469 | rdp->qs_pending = 0; | ||
| 470 | |||
| 471 | spin_lock_irqsave(&rcp->lock, flags); | ||
| 472 | /* | ||
| 473 | * rdp->quiescbatch/rcp->cur and the cpu bitmap can come out of sync | ||
| 474 | * during cpu startup. Ignore the quiescent state. | ||
| 475 | */ | ||
| 476 | if (likely(rdp->quiescbatch == rcp->cur)) | ||
| 477 | cpu_quiet(rdp->cpu, rcp); | ||
| 478 | |||
| 479 | spin_unlock_irqrestore(&rcp->lock, flags); | ||
| 480 | } | ||
| 481 | |||
| 482 | |||
| 483 | #ifdef CONFIG_HOTPLUG_CPU | ||
| 484 | |||
| 485 | /* warning! helper for rcu_offline_cpu. do not use elsewhere without reviewing | ||
| 486 | * locking requirements, the list it's pulling from has to belong to a cpu | ||
| 487 | * which is dead and hence not processing interrupts. | ||
| 488 | */ | ||
| 489 | static void rcu_move_batch(struct rcu_data *this_rdp, struct rcu_head *list, | ||
| 490 | struct rcu_head **tail, long batch) | ||
| 491 | { | ||
| 492 | unsigned long flags; | ||
| 493 | |||
| 494 | if (list) { | ||
| 495 | local_irq_save(flags); | ||
| 496 | this_rdp->batch = batch; | ||
| 497 | *this_rdp->nxttail[2] = list; | ||
| 498 | this_rdp->nxttail[2] = tail; | ||
| 499 | local_irq_restore(flags); | ||
| 500 | } | ||
| 501 | } | ||
| 502 | |||
| 503 | static void __rcu_offline_cpu(struct rcu_data *this_rdp, | ||
| 504 | struct rcu_ctrlblk *rcp, struct rcu_data *rdp) | ||
| 505 | { | ||
| 506 | unsigned long flags; | ||
| 507 | |||
| 508 | /* | ||
| 509 | * if the cpu going offline owns the grace period | ||
| 510 | * we can block indefinitely waiting for it, so flush | ||
| 511 | * it here | ||
| 512 | */ | ||
| 513 | spin_lock_irqsave(&rcp->lock, flags); | ||
| 514 | if (rcp->cur != rcp->completed) | ||
| 515 | cpu_quiet(rdp->cpu, rcp); | ||
| 516 | rcu_move_batch(this_rdp, rdp->donelist, rdp->donetail, rcp->cur + 1); | ||
| 517 | rcu_move_batch(this_rdp, rdp->nxtlist, rdp->nxttail[2], rcp->cur + 1); | ||
| 518 | spin_unlock(&rcp->lock); | ||
| 519 | |||
| 520 | this_rdp->qlen += rdp->qlen; | ||
| 521 | local_irq_restore(flags); | ||
| 522 | } | ||
| 523 | |||
| 524 | static void rcu_offline_cpu(int cpu) | ||
| 525 | { | ||
| 526 | struct rcu_data *this_rdp = &get_cpu_var(rcu_data); | ||
| 527 | struct rcu_data *this_bh_rdp = &get_cpu_var(rcu_bh_data); | ||
| 528 | |||
| 529 | __rcu_offline_cpu(this_rdp, &rcu_ctrlblk, | ||
| 530 | &per_cpu(rcu_data, cpu)); | ||
| 531 | __rcu_offline_cpu(this_bh_rdp, &rcu_bh_ctrlblk, | ||
| 532 | &per_cpu(rcu_bh_data, cpu)); | ||
| 533 | put_cpu_var(rcu_data); | ||
| 534 | put_cpu_var(rcu_bh_data); | ||
| 535 | } | ||
| 536 | |||
| 537 | #else | ||
| 538 | |||
| 539 | static void rcu_offline_cpu(int cpu) | ||
| 540 | { | ||
| 541 | } | ||
| 542 | |||
| 543 | #endif | ||
| 544 | |||
| 545 | /* | ||
| 546 | * This does the RCU processing work from softirq context. | ||
| 547 | */ | ||
| 548 | static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp, | ||
| 549 | struct rcu_data *rdp) | ||
| 550 | { | ||
| 551 | unsigned long flags; | ||
| 552 | long completed_snap; | ||
| 553 | |||
| 554 | if (rdp->nxtlist) { | ||
| 555 | local_irq_save(flags); | ||
| 556 | completed_snap = ACCESS_ONCE(rcp->completed); | ||
| 557 | |||
| 558 | /* | ||
| 559 | * move the other grace-period-completed entries to | ||
| 560 | * [rdp->nxtlist, *rdp->nxttail[0]) temporarily | ||
| 561 | */ | ||
| 562 | if (!rcu_batch_before(completed_snap, rdp->batch)) | ||
| 563 | rdp->nxttail[0] = rdp->nxttail[1] = rdp->nxttail[2]; | ||
| 564 | else if (!rcu_batch_before(completed_snap, rdp->batch - 1)) | ||
| 565 | rdp->nxttail[0] = rdp->nxttail[1]; | ||
| 566 | |||
| 567 | /* | ||
| 568 | * the grace period for entries in | ||
| 569 | * [rdp->nxtlist, *rdp->nxttail[0]) has completed and | ||
| 570 | * move these entries to donelist | ||
| 571 | */ | ||
| 572 | if (rdp->nxttail[0] != &rdp->nxtlist) { | ||
| 573 | *rdp->donetail = rdp->nxtlist; | ||
| 574 | rdp->donetail = rdp->nxttail[0]; | ||
| 575 | rdp->nxtlist = *rdp->nxttail[0]; | ||
| 576 | *rdp->donetail = NULL; | ||
| 577 | |||
| 578 | if (rdp->nxttail[1] == rdp->nxttail[0]) | ||
| 579 | rdp->nxttail[1] = &rdp->nxtlist; | ||
| 580 | if (rdp->nxttail[2] == rdp->nxttail[0]) | ||
| 581 | rdp->nxttail[2] = &rdp->nxtlist; | ||
| 582 | rdp->nxttail[0] = &rdp->nxtlist; | ||
| 583 | } | ||
| 584 | |||
| 585 | local_irq_restore(flags); | ||
| 586 | |||
| 587 | if (rcu_batch_after(rdp->batch, rcp->pending)) { | ||
| 588 | unsigned long flags2; | ||
| 589 | |||
| 590 | /* and start it/schedule start if it's a new batch */ | ||
| 591 | spin_lock_irqsave(&rcp->lock, flags2); | ||
| 592 | if (rcu_batch_after(rdp->batch, rcp->pending)) { | ||
| 593 | rcp->pending = rdp->batch; | ||
| 594 | rcu_start_batch(rcp); | ||
| 595 | } | ||
| 596 | spin_unlock_irqrestore(&rcp->lock, flags2); | ||
| 597 | } | ||
| 598 | } | ||
| 599 | |||
| 600 | rcu_check_quiescent_state(rcp, rdp); | ||
| 601 | if (rdp->donelist) | ||
| 602 | rcu_do_batch(rdp); | ||
| 603 | } | ||
| 604 | |||
| 605 | static void rcu_process_callbacks(struct softirq_action *unused) | ||
| 606 | { | ||
| 607 | /* | ||
| 608 | * Memory references from any prior RCU read-side critical sections | ||
| 609 | * executed by the interrupted code must be see before any RCU | ||
| 610 | * grace-period manupulations below. | ||
| 611 | */ | ||
| 612 | |||
| 613 | smp_mb(); /* See above block comment. */ | ||
| 614 | |||
| 615 | __rcu_process_callbacks(&rcu_ctrlblk, &__get_cpu_var(rcu_data)); | ||
| 616 | __rcu_process_callbacks(&rcu_bh_ctrlblk, &__get_cpu_var(rcu_bh_data)); | ||
| 617 | |||
| 618 | /* | ||
| 619 | * Memory references from any later RCU read-side critical sections | ||
| 620 | * executed by the interrupted code must be see after any RCU | ||
| 621 | * grace-period manupulations above. | ||
| 622 | */ | ||
| 623 | |||
| 624 | smp_mb(); /* See above block comment. */ | ||
| 625 | } | ||
| 626 | |||
| 627 | static int __rcu_pending(struct rcu_ctrlblk *rcp, struct rcu_data *rdp) | ||
| 628 | { | ||
| 629 | /* Check for CPU stalls, if enabled. */ | ||
| 630 | check_cpu_stall(rcp); | ||
| 631 | |||
| 632 | if (rdp->nxtlist) { | ||
| 633 | long completed_snap = ACCESS_ONCE(rcp->completed); | ||
| 634 | |||
| 635 | /* | ||
| 636 | * This cpu has pending rcu entries and the grace period | ||
| 637 | * for them has completed. | ||
| 638 | */ | ||
| 639 | if (!rcu_batch_before(completed_snap, rdp->batch)) | ||
| 640 | return 1; | ||
| 641 | if (!rcu_batch_before(completed_snap, rdp->batch - 1) && | ||
| 642 | rdp->nxttail[0] != rdp->nxttail[1]) | ||
| 643 | return 1; | ||
| 644 | if (rdp->nxttail[0] != &rdp->nxtlist) | ||
| 645 | return 1; | ||
| 646 | |||
| 647 | /* | ||
| 648 | * This cpu has pending rcu entries and the new batch | ||
| 649 | * for then hasn't been started nor scheduled start | ||
| 650 | */ | ||
| 651 | if (rcu_batch_after(rdp->batch, rcp->pending)) | ||
| 652 | return 1; | ||
| 653 | } | ||
| 654 | |||
| 655 | /* This cpu has finished callbacks to invoke */ | ||
| 656 | if (rdp->donelist) | ||
| 657 | return 1; | ||
| 658 | |||
| 659 | /* The rcu core waits for a quiescent state from the cpu */ | ||
| 660 | if (rdp->quiescbatch != rcp->cur || rdp->qs_pending) | ||
| 661 | return 1; | ||
| 662 | |||
| 663 | /* nothing to do */ | ||
| 664 | return 0; | ||
| 665 | } | ||
| 666 | |||
| 667 | /* | ||
| 668 | * Check to see if there is any immediate RCU-related work to be done | ||
| 669 | * by the current CPU, returning 1 if so. This function is part of the | ||
| 670 | * RCU implementation; it is -not- an exported member of the RCU API. | ||
| 671 | */ | ||
| 672 | int rcu_pending(int cpu) | ||
| 673 | { | ||
| 674 | return __rcu_pending(&rcu_ctrlblk, &per_cpu(rcu_data, cpu)) || | ||
| 675 | __rcu_pending(&rcu_bh_ctrlblk, &per_cpu(rcu_bh_data, cpu)); | ||
| 676 | } | ||
| 677 | |||
| 678 | /* | ||
| 679 | * Check to see if any future RCU-related work will need to be done | ||
| 680 | * by the current CPU, even if none need be done immediately, returning | ||
| 681 | * 1 if so. This function is part of the RCU implementation; it is -not- | ||
| 682 | * an exported member of the RCU API. | ||
| 683 | */ | ||
| 684 | int rcu_needs_cpu(int cpu) | ||
| 685 | { | ||
| 686 | struct rcu_data *rdp = &per_cpu(rcu_data, cpu); | ||
| 687 | struct rcu_data *rdp_bh = &per_cpu(rcu_bh_data, cpu); | ||
| 688 | |||
| 689 | return !!rdp->nxtlist || !!rdp_bh->nxtlist || rcu_pending(cpu); | ||
| 690 | } | ||
| 691 | |||
| 692 | /* | ||
| 693 | * Top-level function driving RCU grace-period detection, normally | ||
| 694 | * invoked from the scheduler-clock interrupt. This function simply | ||
| 695 | * increments counters that are read only from softirq by this same | ||
| 696 | * CPU, so there are no memory barriers required. | ||
| 697 | */ | ||
| 698 | void rcu_check_callbacks(int cpu, int user) | ||
| 699 | { | ||
| 700 | if (user || | ||
| 701 | (idle_cpu(cpu) && rcu_scheduler_active && | ||
| 702 | !in_softirq() && hardirq_count() <= (1 << HARDIRQ_SHIFT))) { | ||
| 703 | |||
| 704 | /* | ||
| 705 | * Get here if this CPU took its interrupt from user | ||
| 706 | * mode or from the idle loop, and if this is not a | ||
| 707 | * nested interrupt. In this case, the CPU is in | ||
| 708 | * a quiescent state, so count it. | ||
| 709 | * | ||
| 710 | * Also do a memory barrier. This is needed to handle | ||
| 711 | * the case where writes from a preempt-disable section | ||
| 712 | * of code get reordered into schedule() by this CPU's | ||
| 713 | * write buffer. The memory barrier makes sure that | ||
| 714 | * the rcu_qsctr_inc() and rcu_bh_qsctr_inc() are see | ||
| 715 | * by other CPUs to happen after any such write. | ||
| 716 | */ | ||
| 717 | |||
| 718 | smp_mb(); /* See above block comment. */ | ||
| 719 | rcu_qsctr_inc(cpu); | ||
| 720 | rcu_bh_qsctr_inc(cpu); | ||
| 721 | |||
| 722 | } else if (!in_softirq()) { | ||
| 723 | |||
| 724 | /* | ||
| 725 | * Get here if this CPU did not take its interrupt from | ||
| 726 | * softirq, in other words, if it is not interrupting | ||
| 727 | * a rcu_bh read-side critical section. This is an _bh | ||
| 728 | * critical section, so count it. The memory barrier | ||
| 729 | * is needed for the same reason as is the above one. | ||
| 730 | */ | ||
| 731 | |||
| 732 | smp_mb(); /* See above block comment. */ | ||
| 733 | rcu_bh_qsctr_inc(cpu); | ||
| 734 | } | ||
| 735 | raise_rcu_softirq(); | ||
| 736 | } | ||
| 737 | |||
| 738 | static void __cpuinit rcu_init_percpu_data(int cpu, struct rcu_ctrlblk *rcp, | ||
| 739 | struct rcu_data *rdp) | ||
| 740 | { | ||
| 741 | unsigned long flags; | ||
| 742 | |||
| 743 | spin_lock_irqsave(&rcp->lock, flags); | ||
| 744 | memset(rdp, 0, sizeof(*rdp)); | ||
| 745 | rdp->nxttail[0] = rdp->nxttail[1] = rdp->nxttail[2] = &rdp->nxtlist; | ||
| 746 | rdp->donetail = &rdp->donelist; | ||
| 747 | rdp->quiescbatch = rcp->completed; | ||
| 748 | rdp->qs_pending = 0; | ||
| 749 | rdp->cpu = cpu; | ||
| 750 | rdp->blimit = blimit; | ||
| 751 | spin_unlock_irqrestore(&rcp->lock, flags); | ||
| 752 | } | ||
| 753 | |||
| 754 | static void __cpuinit rcu_online_cpu(int cpu) | ||
| 755 | { | ||
| 756 | struct rcu_data *rdp = &per_cpu(rcu_data, cpu); | ||
| 757 | struct rcu_data *bh_rdp = &per_cpu(rcu_bh_data, cpu); | ||
| 758 | |||
| 759 | rcu_init_percpu_data(cpu, &rcu_ctrlblk, rdp); | ||
| 760 | rcu_init_percpu_data(cpu, &rcu_bh_ctrlblk, bh_rdp); | ||
| 761 | open_softirq(RCU_SOFTIRQ, rcu_process_callbacks); | ||
| 762 | } | ||
| 763 | |||
| 764 | static int __cpuinit rcu_cpu_notify(struct notifier_block *self, | ||
| 765 | unsigned long action, void *hcpu) | ||
| 766 | { | ||
| 767 | long cpu = (long)hcpu; | ||
| 768 | |||
| 769 | switch (action) { | ||
| 770 | case CPU_UP_PREPARE: | ||
| 771 | case CPU_UP_PREPARE_FROZEN: | ||
| 772 | rcu_online_cpu(cpu); | ||
| 773 | break; | ||
| 774 | case CPU_DEAD: | ||
| 775 | case CPU_DEAD_FROZEN: | ||
| 776 | rcu_offline_cpu(cpu); | ||
| 777 | break; | ||
| 778 | default: | ||
| 779 | break; | ||
| 780 | } | ||
| 781 | return NOTIFY_OK; | ||
| 782 | } | ||
| 783 | |||
| 784 | static struct notifier_block __cpuinitdata rcu_nb = { | ||
| 785 | .notifier_call = rcu_cpu_notify, | ||
| 786 | }; | ||
| 787 | |||
| 788 | /* | ||
| 789 | * Initializes rcu mechanism. Assumed to be called early. | ||
| 790 | * That is before local timer(SMP) or jiffie timer (uniproc) is setup. | ||
| 791 | * Note that rcu_qsctr and friends are implicitly | ||
| 792 | * initialized due to the choice of ``0'' for RCU_CTR_INVALID. | ||
| 793 | */ | ||
| 794 | void __init __rcu_init(void) | ||
| 795 | { | ||
| 796 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | ||
| 797 | printk(KERN_INFO "RCU-based detection of stalled CPUs is enabled.\n"); | ||
| 798 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | ||
| 799 | rcu_cpu_notify(&rcu_nb, CPU_UP_PREPARE, | ||
| 800 | (void *)(long)smp_processor_id()); | ||
| 801 | /* Register notifier for non-boot CPUs */ | ||
| 802 | register_cpu_notifier(&rcu_nb); | ||
| 803 | } | ||
| 804 | |||
| 805 | module_param(blimit, int, 0); | ||
| 806 | module_param(qhimark, int, 0); | ||
| 807 | module_param(qlowmark, int, 0); | ||
diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c index a967c9feb90a..bd5d5c8e5140 100644 --- a/kernel/rcupdate.c +++ b/kernel/rcupdate.c | |||
| @@ -98,6 +98,30 @@ void synchronize_rcu(void) | |||
| 98 | } | 98 | } |
| 99 | EXPORT_SYMBOL_GPL(synchronize_rcu); | 99 | EXPORT_SYMBOL_GPL(synchronize_rcu); |
| 100 | 100 | ||
| 101 | /** | ||
| 102 | * synchronize_rcu_bh - wait until an rcu_bh grace period has elapsed. | ||
| 103 | * | ||
| 104 | * Control will return to the caller some time after a full rcu_bh grace | ||
| 105 | * period has elapsed, in other words after all currently executing rcu_bh | ||
| 106 | * read-side critical sections have completed. RCU read-side critical | ||
| 107 | * sections are delimited by rcu_read_lock_bh() and rcu_read_unlock_bh(), | ||
| 108 | * and may be nested. | ||
| 109 | */ | ||
| 110 | void synchronize_rcu_bh(void) | ||
| 111 | { | ||
| 112 | struct rcu_synchronize rcu; | ||
| 113 | |||
| 114 | if (rcu_blocking_is_gp()) | ||
| 115 | return; | ||
| 116 | |||
| 117 | init_completion(&rcu.completion); | ||
| 118 | /* Will wake me after RCU finished. */ | ||
| 119 | call_rcu_bh(&rcu.head, wakeme_after_rcu); | ||
| 120 | /* Wait for it. */ | ||
| 121 | wait_for_completion(&rcu.completion); | ||
| 122 | } | ||
| 123 | EXPORT_SYMBOL_GPL(synchronize_rcu_bh); | ||
| 124 | |||
| 101 | static void rcu_barrier_callback(struct rcu_head *notused) | 125 | static void rcu_barrier_callback(struct rcu_head *notused) |
| 102 | { | 126 | { |
| 103 | if (atomic_dec_and_test(&rcu_barrier_cpu_count)) | 127 | if (atomic_dec_and_test(&rcu_barrier_cpu_count)) |
| @@ -129,6 +153,7 @@ static void rcu_barrier_func(void *type) | |||
| 129 | static inline void wait_migrated_callbacks(void) | 153 | static inline void wait_migrated_callbacks(void) |
| 130 | { | 154 | { |
| 131 | wait_event(rcu_migrate_wq, !atomic_read(&rcu_migrate_type_count)); | 155 | wait_event(rcu_migrate_wq, !atomic_read(&rcu_migrate_type_count)); |
| 156 | smp_mb(); /* In case we didn't sleep. */ | ||
| 132 | } | 157 | } |
| 133 | 158 | ||
| 134 | /* | 159 | /* |
| @@ -192,9 +217,13 @@ static void rcu_migrate_callback(struct rcu_head *notused) | |||
| 192 | wake_up(&rcu_migrate_wq); | 217 | wake_up(&rcu_migrate_wq); |
| 193 | } | 218 | } |
| 194 | 219 | ||
| 220 | extern int rcu_cpu_notify(struct notifier_block *self, | ||
| 221 | unsigned long action, void *hcpu); | ||
| 222 | |||
| 195 | static int __cpuinit rcu_barrier_cpu_hotplug(struct notifier_block *self, | 223 | static int __cpuinit rcu_barrier_cpu_hotplug(struct notifier_block *self, |
| 196 | unsigned long action, void *hcpu) | 224 | unsigned long action, void *hcpu) |
| 197 | { | 225 | { |
| 226 | rcu_cpu_notify(self, action, hcpu); | ||
| 198 | if (action == CPU_DYING) { | 227 | if (action == CPU_DYING) { |
| 199 | /* | 228 | /* |
| 200 | * preempt_disable() in on_each_cpu() prevents stop_machine(), | 229 | * preempt_disable() in on_each_cpu() prevents stop_machine(), |
| @@ -209,7 +238,8 @@ static int __cpuinit rcu_barrier_cpu_hotplug(struct notifier_block *self, | |||
| 209 | call_rcu_bh(rcu_migrate_head, rcu_migrate_callback); | 238 | call_rcu_bh(rcu_migrate_head, rcu_migrate_callback); |
| 210 | call_rcu_sched(rcu_migrate_head + 1, rcu_migrate_callback); | 239 | call_rcu_sched(rcu_migrate_head + 1, rcu_migrate_callback); |
| 211 | call_rcu(rcu_migrate_head + 2, rcu_migrate_callback); | 240 | call_rcu(rcu_migrate_head + 2, rcu_migrate_callback); |
| 212 | } else if (action == CPU_POST_DEAD) { | 241 | } else if (action == CPU_DOWN_PREPARE) { |
| 242 | /* Don't need to wait until next removal operation. */ | ||
| 213 | /* rcu_migrate_head is protected by cpu_add_remove_lock */ | 243 | /* rcu_migrate_head is protected by cpu_add_remove_lock */ |
| 214 | wait_migrated_callbacks(); | 244 | wait_migrated_callbacks(); |
| 215 | } | 245 | } |
| @@ -219,8 +249,18 @@ static int __cpuinit rcu_barrier_cpu_hotplug(struct notifier_block *self, | |||
| 219 | 249 | ||
| 220 | void __init rcu_init(void) | 250 | void __init rcu_init(void) |
| 221 | { | 251 | { |
| 252 | int i; | ||
| 253 | |||
| 222 | __rcu_init(); | 254 | __rcu_init(); |
| 223 | hotcpu_notifier(rcu_barrier_cpu_hotplug, 0); | 255 | cpu_notifier(rcu_barrier_cpu_hotplug, 0); |
| 256 | |||
| 257 | /* | ||
| 258 | * We don't need protection against CPU-hotplug here because | ||
| 259 | * this is called early in boot, before either interrupts | ||
| 260 | * or the scheduler are operational. | ||
| 261 | */ | ||
| 262 | for_each_online_cpu(i) | ||
| 263 | rcu_barrier_cpu_hotplug(NULL, CPU_UP_PREPARE, (void *)(long)i); | ||
| 224 | } | 264 | } |
| 225 | 265 | ||
| 226 | void rcu_scheduler_starting(void) | 266 | void rcu_scheduler_starting(void) |
diff --git a/kernel/rcupreempt.c b/kernel/rcupreempt.c deleted file mode 100644 index beb0e659adcc..000000000000 --- a/kernel/rcupreempt.c +++ /dev/null | |||
| @@ -1,1539 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Read-Copy Update mechanism for mutual exclusion, realtime implementation | ||
| 3 | * | ||
| 4 | * This program is free software; you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License as published by | ||
| 6 | * the Free Software Foundation; either version 2 of the License, or | ||
| 7 | * (at your option) any later version. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 17 | * | ||
| 18 | * Copyright IBM Corporation, 2006 | ||
| 19 | * | ||
| 20 | * Authors: Paul E. McKenney <paulmck@us.ibm.com> | ||
| 21 | * With thanks to Esben Nielsen, Bill Huey, and Ingo Molnar | ||
| 22 | * for pushing me away from locks and towards counters, and | ||
| 23 | * to Suparna Bhattacharya for pushing me completely away | ||
| 24 | * from atomic instructions on the read side. | ||
| 25 | * | ||
| 26 | * - Added handling of Dynamic Ticks | ||
| 27 | * Copyright 2007 - Paul E. Mckenney <paulmck@us.ibm.com> | ||
| 28 | * - Steven Rostedt <srostedt@redhat.com> | ||
| 29 | * | ||
| 30 | * Papers: http://www.rdrop.com/users/paulmck/RCU | ||
| 31 | * | ||
| 32 | * Design Document: http://lwn.net/Articles/253651/ | ||
| 33 | * | ||
| 34 | * For detailed explanation of Read-Copy Update mechanism see - | ||
| 35 | * Documentation/RCU/ *.txt | ||
| 36 | * | ||
| 37 | */ | ||
| 38 | #include <linux/types.h> | ||
| 39 | #include <linux/kernel.h> | ||
| 40 | #include <linux/init.h> | ||
| 41 | #include <linux/spinlock.h> | ||
| 42 | #include <linux/smp.h> | ||
| 43 | #include <linux/rcupdate.h> | ||
| 44 | #include <linux/interrupt.h> | ||
| 45 | #include <linux/sched.h> | ||
| 46 | #include <asm/atomic.h> | ||
| 47 | #include <linux/bitops.h> | ||
| 48 | #include <linux/module.h> | ||
| 49 | #include <linux/kthread.h> | ||
| 50 | #include <linux/completion.h> | ||
| 51 | #include <linux/moduleparam.h> | ||
| 52 | #include <linux/percpu.h> | ||
| 53 | #include <linux/notifier.h> | ||
| 54 | #include <linux/cpu.h> | ||
| 55 | #include <linux/random.h> | ||
| 56 | #include <linux/delay.h> | ||
| 57 | #include <linux/cpumask.h> | ||
| 58 | #include <linux/rcupreempt_trace.h> | ||
| 59 | #include <asm/byteorder.h> | ||
| 60 | |||
| 61 | /* | ||
| 62 | * PREEMPT_RCU data structures. | ||
| 63 | */ | ||
| 64 | |||
| 65 | /* | ||
| 66 | * GP_STAGES specifies the number of times the state machine has | ||
| 67 | * to go through the all the rcu_try_flip_states (see below) | ||
| 68 | * in a single Grace Period. | ||
| 69 | * | ||
| 70 | * GP in GP_STAGES stands for Grace Period ;) | ||
| 71 | */ | ||
| 72 | #define GP_STAGES 2 | ||
| 73 | struct rcu_data { | ||
| 74 | spinlock_t lock; /* Protect rcu_data fields. */ | ||
| 75 | long completed; /* Number of last completed batch. */ | ||
| 76 | int waitlistcount; | ||
| 77 | struct rcu_head *nextlist; | ||
| 78 | struct rcu_head **nexttail; | ||
| 79 | struct rcu_head *waitlist[GP_STAGES]; | ||
| 80 | struct rcu_head **waittail[GP_STAGES]; | ||
| 81 | struct rcu_head *donelist; /* from waitlist & waitschedlist */ | ||
| 82 | struct rcu_head **donetail; | ||
| 83 | long rcu_flipctr[2]; | ||
| 84 | struct rcu_head *nextschedlist; | ||
| 85 | struct rcu_head **nextschedtail; | ||
| 86 | struct rcu_head *waitschedlist; | ||
| 87 | struct rcu_head **waitschedtail; | ||
| 88 | int rcu_sched_sleeping; | ||
| 89 | #ifdef CONFIG_RCU_TRACE | ||
| 90 | struct rcupreempt_trace trace; | ||
| 91 | #endif /* #ifdef CONFIG_RCU_TRACE */ | ||
| 92 | }; | ||
| 93 | |||
| 94 | /* | ||
| 95 | * States for rcu_try_flip() and friends. | ||
| 96 | */ | ||
| 97 | |||
| 98 | enum rcu_try_flip_states { | ||
| 99 | |||
| 100 | /* | ||
| 101 | * Stay here if nothing is happening. Flip the counter if somthing | ||
| 102 | * starts happening. Denoted by "I" | ||
| 103 | */ | ||
| 104 | rcu_try_flip_idle_state, | ||
| 105 | |||
| 106 | /* | ||
| 107 | * Wait here for all CPUs to notice that the counter has flipped. This | ||
| 108 | * prevents the old set of counters from ever being incremented once | ||
| 109 | * we leave this state, which in turn is necessary because we cannot | ||
| 110 | * test any individual counter for zero -- we can only check the sum. | ||
| 111 | * Denoted by "A". | ||
| 112 | */ | ||
| 113 | rcu_try_flip_waitack_state, | ||
| 114 | |||
| 115 | /* | ||
| 116 | * Wait here for the sum of the old per-CPU counters to reach zero. | ||
| 117 | * Denoted by "Z". | ||
| 118 | */ | ||
| 119 | rcu_try_flip_waitzero_state, | ||
| 120 | |||
| 121 | /* | ||
| 122 | * Wait here for each of the other CPUs to execute a memory barrier. | ||
| 123 | * This is necessary to ensure that these other CPUs really have | ||
| 124 | * completed executing their RCU read-side critical sections, despite | ||
| 125 | * their CPUs wildly reordering memory. Denoted by "M". | ||
| 126 | */ | ||
| 127 | rcu_try_flip_waitmb_state, | ||
| 128 | }; | ||
| 129 | |||
| 130 | /* | ||
| 131 | * States for rcu_ctrlblk.rcu_sched_sleep. | ||
| 132 | */ | ||
| 133 | |||
| 134 | enum rcu_sched_sleep_states { | ||
| 135 | rcu_sched_not_sleeping, /* Not sleeping, callbacks need GP. */ | ||
| 136 | rcu_sched_sleep_prep, /* Thinking of sleeping, rechecking. */ | ||
| 137 | rcu_sched_sleeping, /* Sleeping, awaken if GP needed. */ | ||
| 138 | }; | ||
| 139 | |||
| 140 | struct rcu_ctrlblk { | ||
| 141 | spinlock_t fliplock; /* Protect state-machine transitions. */ | ||
| 142 | long completed; /* Number of last completed batch. */ | ||
| 143 | enum rcu_try_flip_states rcu_try_flip_state; /* The current state of | ||
| 144 | the rcu state machine */ | ||
| 145 | spinlock_t schedlock; /* Protect rcu_sched sleep state. */ | ||
| 146 | enum rcu_sched_sleep_states sched_sleep; /* rcu_sched state. */ | ||
| 147 | wait_queue_head_t sched_wq; /* Place for rcu_sched to sleep. */ | ||
| 148 | }; | ||
| 149 | |||
| 150 | struct rcu_dyntick_sched { | ||
| 151 | int dynticks; | ||
| 152 | int dynticks_snap; | ||
| 153 | int sched_qs; | ||
| 154 | int sched_qs_snap; | ||
| 155 | int sched_dynticks_snap; | ||
| 156 | }; | ||
| 157 | |||
| 158 | static DEFINE_PER_CPU_SHARED_ALIGNED(struct rcu_dyntick_sched, rcu_dyntick_sched) = { | ||
| 159 | .dynticks = 1, | ||
| 160 | }; | ||
| 161 | |||
| 162 | void rcu_qsctr_inc(int cpu) | ||
| 163 | { | ||
| 164 | struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu); | ||
| 165 | |||
| 166 | rdssp->sched_qs++; | ||
| 167 | } | ||
| 168 | |||
| 169 | #ifdef CONFIG_NO_HZ | ||
| 170 | |||
| 171 | void rcu_enter_nohz(void) | ||
| 172 | { | ||
| 173 | static DEFINE_RATELIMIT_STATE(rs, 10 * HZ, 1); | ||
| 174 | |||
| 175 | smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */ | ||
| 176 | __get_cpu_var(rcu_dyntick_sched).dynticks++; | ||
| 177 | WARN_ON_RATELIMIT(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1, &rs); | ||
| 178 | } | ||
| 179 | |||
| 180 | void rcu_exit_nohz(void) | ||
| 181 | { | ||
| 182 | static DEFINE_RATELIMIT_STATE(rs, 10 * HZ, 1); | ||
| 183 | |||
| 184 | __get_cpu_var(rcu_dyntick_sched).dynticks++; | ||
| 185 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ | ||
| 186 | WARN_ON_RATELIMIT(!(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1), | ||
| 187 | &rs); | ||
| 188 | } | ||
| 189 | |||
| 190 | #endif /* CONFIG_NO_HZ */ | ||
| 191 | |||
| 192 | |||
| 193 | static DEFINE_PER_CPU(struct rcu_data, rcu_data); | ||
| 194 | |||
| 195 | static struct rcu_ctrlblk rcu_ctrlblk = { | ||
| 196 | .fliplock = __SPIN_LOCK_UNLOCKED(rcu_ctrlblk.fliplock), | ||
| 197 | .completed = 0, | ||
| 198 | .rcu_try_flip_state = rcu_try_flip_idle_state, | ||
| 199 | .schedlock = __SPIN_LOCK_UNLOCKED(rcu_ctrlblk.schedlock), | ||
| 200 | .sched_sleep = rcu_sched_not_sleeping, | ||
| 201 | .sched_wq = __WAIT_QUEUE_HEAD_INITIALIZER(rcu_ctrlblk.sched_wq), | ||
| 202 | }; | ||
| 203 | |||
| 204 | static struct task_struct *rcu_sched_grace_period_task; | ||
| 205 | |||
| 206 | #ifdef CONFIG_RCU_TRACE | ||
| 207 | static char *rcu_try_flip_state_names[] = | ||
| 208 | { "idle", "waitack", "waitzero", "waitmb" }; | ||
| 209 | #endif /* #ifdef CONFIG_RCU_TRACE */ | ||
| 210 | |||
| 211 | static DECLARE_BITMAP(rcu_cpu_online_map, NR_CPUS) __read_mostly | ||
| 212 | = CPU_BITS_NONE; | ||
| 213 | |||
| 214 | /* | ||
| 215 | * Enum and per-CPU flag to determine when each CPU has seen | ||
| 216 | * the most recent counter flip. | ||
| 217 | */ | ||
| 218 | |||
| 219 | enum rcu_flip_flag_values { | ||
| 220 | rcu_flip_seen, /* Steady/initial state, last flip seen. */ | ||
| 221 | /* Only GP detector can update. */ | ||
| 222 | rcu_flipped /* Flip just completed, need confirmation. */ | ||
| 223 | /* Only corresponding CPU can update. */ | ||
| 224 | }; | ||
| 225 | static DEFINE_PER_CPU_SHARED_ALIGNED(enum rcu_flip_flag_values, rcu_flip_flag) | ||
| 226 | = rcu_flip_seen; | ||
| 227 | |||
| 228 | /* | ||
| 229 | * Enum and per-CPU flag to determine when each CPU has executed the | ||
| 230 | * needed memory barrier to fence in memory references from its last RCU | ||
| 231 | * read-side critical section in the just-completed grace period. | ||
| 232 | */ | ||
| 233 | |||
| 234 | enum rcu_mb_flag_values { | ||
| 235 | rcu_mb_done, /* Steady/initial state, no mb()s required. */ | ||
| 236 | /* Only GP detector can update. */ | ||
| 237 | rcu_mb_needed /* Flip just completed, need an mb(). */ | ||
| 238 | /* Only corresponding CPU can update. */ | ||
| 239 | }; | ||
| 240 | static DEFINE_PER_CPU_SHARED_ALIGNED(enum rcu_mb_flag_values, rcu_mb_flag) | ||
| 241 | = rcu_mb_done; | ||
| 242 | |||
| 243 | /* | ||
| 244 | * RCU_DATA_ME: find the current CPU's rcu_data structure. | ||
| 245 | * RCU_DATA_CPU: find the specified CPU's rcu_data structure. | ||
| 246 | */ | ||
| 247 | #define RCU_DATA_ME() (&__get_cpu_var(rcu_data)) | ||
| 248 | #define RCU_DATA_CPU(cpu) (&per_cpu(rcu_data, cpu)) | ||
| 249 | |||
| 250 | /* | ||
| 251 | * Helper macro for tracing when the appropriate rcu_data is not | ||
| 252 | * cached in a local variable, but where the CPU number is so cached. | ||
| 253 | */ | ||
| 254 | #define RCU_TRACE_CPU(f, cpu) RCU_TRACE(f, &(RCU_DATA_CPU(cpu)->trace)); | ||
| 255 | |||
| 256 | /* | ||
| 257 | * Helper macro for tracing when the appropriate rcu_data is not | ||
| 258 | * cached in a local variable. | ||
| 259 | */ | ||
| 260 | #define RCU_TRACE_ME(f) RCU_TRACE(f, &(RCU_DATA_ME()->trace)); | ||
| 261 | |||
| 262 | /* | ||
| 263 | * Helper macro for tracing when the appropriate rcu_data is pointed | ||
| 264 | * to by a local variable. | ||
| 265 | */ | ||
| 266 | #define RCU_TRACE_RDP(f, rdp) RCU_TRACE(f, &((rdp)->trace)); | ||
| 267 | |||
| 268 | #define RCU_SCHED_BATCH_TIME (HZ / 50) | ||
| 269 | |||
| 270 | /* | ||
| 271 | * Return the number of RCU batches processed thus far. Useful | ||
| 272 | * for debug and statistics. | ||
| 273 | */ | ||
| 274 | long rcu_batches_completed(void) | ||
| 275 | { | ||
| 276 | return rcu_ctrlblk.completed; | ||
| 277 | } | ||
| 278 | EXPORT_SYMBOL_GPL(rcu_batches_completed); | ||
| 279 | |||
| 280 | void __rcu_read_lock(void) | ||
| 281 | { | ||
| 282 | int idx; | ||
| 283 | struct task_struct *t = current; | ||
| 284 | int nesting; | ||
| 285 | |||
| 286 | nesting = ACCESS_ONCE(t->rcu_read_lock_nesting); | ||
| 287 | if (nesting != 0) { | ||
| 288 | |||
| 289 | /* An earlier rcu_read_lock() covers us, just count it. */ | ||
| 290 | |||
| 291 | t->rcu_read_lock_nesting = nesting + 1; | ||
| 292 | |||
| 293 | } else { | ||
| 294 | unsigned long flags; | ||
| 295 | |||
| 296 | /* | ||
| 297 | * We disable interrupts for the following reasons: | ||
| 298 | * - If we get scheduling clock interrupt here, and we | ||
| 299 | * end up acking the counter flip, it's like a promise | ||
| 300 | * that we will never increment the old counter again. | ||
| 301 | * Thus we will break that promise if that | ||
| 302 | * scheduling clock interrupt happens between the time | ||
| 303 | * we pick the .completed field and the time that we | ||
| 304 | * increment our counter. | ||
| 305 | * | ||
| 306 | * - We don't want to be preempted out here. | ||
| 307 | * | ||
| 308 | * NMIs can still occur, of course, and might themselves | ||
| 309 | * contain rcu_read_lock(). | ||
| 310 | */ | ||
| 311 | |||
| 312 | local_irq_save(flags); | ||
| 313 | |||
| 314 | /* | ||
| 315 | * Outermost nesting of rcu_read_lock(), so increment | ||
| 316 | * the current counter for the current CPU. Use volatile | ||
| 317 | * casts to prevent the compiler from reordering. | ||
| 318 | */ | ||
| 319 | |||
| 320 | idx = ACCESS_ONCE(rcu_ctrlblk.completed) & 0x1; | ||
| 321 | ACCESS_ONCE(RCU_DATA_ME()->rcu_flipctr[idx])++; | ||
| 322 | |||
| 323 | /* | ||
| 324 | * Now that the per-CPU counter has been incremented, we | ||
| 325 | * are protected from races with rcu_read_lock() invoked | ||
| 326 | * from NMI handlers on this CPU. We can therefore safely | ||
| 327 | * increment the nesting counter, relieving further NMIs | ||
| 328 | * of the need to increment the per-CPU counter. | ||
| 329 | */ | ||
| 330 | |||
| 331 | ACCESS_ONCE(t->rcu_read_lock_nesting) = nesting + 1; | ||
| 332 | |||
| 333 | /* | ||
| 334 | * Now that we have preventing any NMIs from storing | ||
| 335 | * to the ->rcu_flipctr_idx, we can safely use it to | ||
| 336 | * remember which counter to decrement in the matching | ||
| 337 | * rcu_read_unlock(). | ||
| 338 | */ | ||
| 339 | |||
| 340 | ACCESS_ONCE(t->rcu_flipctr_idx) = idx; | ||
| 341 | local_irq_restore(flags); | ||
| 342 | } | ||
| 343 | } | ||
| 344 | EXPORT_SYMBOL_GPL(__rcu_read_lock); | ||
| 345 | |||
| 346 | void __rcu_read_unlock(void) | ||
| 347 | { | ||
| 348 | int idx; | ||
| 349 | struct task_struct *t = current; | ||
| 350 | int nesting; | ||
| 351 | |||
| 352 | nesting = ACCESS_ONCE(t->rcu_read_lock_nesting); | ||
| 353 | if (nesting > 1) { | ||
| 354 | |||
| 355 | /* | ||
| 356 | * We are still protected by the enclosing rcu_read_lock(), | ||
| 357 | * so simply decrement the counter. | ||
| 358 | */ | ||
| 359 | |||
| 360 | t->rcu_read_lock_nesting = nesting - 1; | ||
| 361 | |||
| 362 | } else { | ||
| 363 | unsigned long flags; | ||
| 364 | |||
| 365 | /* | ||
| 366 | * Disable local interrupts to prevent the grace-period | ||
| 367 | * detection state machine from seeing us half-done. | ||
| 368 | * NMIs can still occur, of course, and might themselves | ||
| 369 | * contain rcu_read_lock() and rcu_read_unlock(). | ||
| 370 | */ | ||
| 371 | |||
| 372 | local_irq_save(flags); | ||
| 373 | |||
| 374 | /* | ||
| 375 | * Outermost nesting of rcu_read_unlock(), so we must | ||
| 376 | * decrement the current counter for the current CPU. | ||
| 377 | * This must be done carefully, because NMIs can | ||
| 378 | * occur at any point in this code, and any rcu_read_lock() | ||
| 379 | * and rcu_read_unlock() pairs in the NMI handlers | ||
| 380 | * must interact non-destructively with this code. | ||
| 381 | * Lots of volatile casts, and -very- careful ordering. | ||
| 382 | * | ||
| 383 | * Changes to this code, including this one, must be | ||
| 384 | * inspected, validated, and tested extremely carefully!!! | ||
| 385 | */ | ||
| 386 | |||
| 387 | /* | ||
| 388 | * First, pick up the index. | ||
| 389 | */ | ||
| 390 | |||
| 391 | idx = ACCESS_ONCE(t->rcu_flipctr_idx); | ||
| 392 | |||
| 393 | /* | ||
| 394 | * Now that we have fetched the counter index, it is | ||
| 395 | * safe to decrement the per-task RCU nesting counter. | ||
| 396 | * After this, any interrupts or NMIs will increment and | ||
| 397 | * decrement the per-CPU counters. | ||
| 398 | */ | ||
| 399 | ACCESS_ONCE(t->rcu_read_lock_nesting) = nesting - 1; | ||
| 400 | |||
| 401 | /* | ||
| 402 | * It is now safe to decrement this task's nesting count. | ||
| 403 | * NMIs that occur after this statement will route their | ||
| 404 | * rcu_read_lock() calls through this "else" clause, and | ||
| 405 | * will thus start incrementing the per-CPU counter on | ||
| 406 | * their own. They will also clobber ->rcu_flipctr_idx, | ||
| 407 | * but that is OK, since we have already fetched it. | ||
| 408 | */ | ||
| 409 | |||
| 410 | ACCESS_ONCE(RCU_DATA_ME()->rcu_flipctr[idx])--; | ||
| 411 | local_irq_restore(flags); | ||
| 412 | } | ||
| 413 | } | ||
| 414 | EXPORT_SYMBOL_GPL(__rcu_read_unlock); | ||
| 415 | |||
| 416 | /* | ||
| 417 | * If a global counter flip has occurred since the last time that we | ||
| 418 | * advanced callbacks, advance them. Hardware interrupts must be | ||
| 419 | * disabled when calling this function. | ||
| 420 | */ | ||
| 421 | static void __rcu_advance_callbacks(struct rcu_data *rdp) | ||
| 422 | { | ||
| 423 | int cpu; | ||
| 424 | int i; | ||
| 425 | int wlc = 0; | ||
| 426 | |||
| 427 | if (rdp->completed != rcu_ctrlblk.completed) { | ||
| 428 | if (rdp->waitlist[GP_STAGES - 1] != NULL) { | ||
| 429 | *rdp->donetail = rdp->waitlist[GP_STAGES - 1]; | ||
| 430 | rdp->donetail = rdp->waittail[GP_STAGES - 1]; | ||
| 431 | RCU_TRACE_RDP(rcupreempt_trace_move2done, rdp); | ||
| 432 | } | ||
| 433 | for (i = GP_STAGES - 2; i >= 0; i--) { | ||
| 434 | if (rdp->waitlist[i] != NULL) { | ||
| 435 | rdp->waitlist[i + 1] = rdp->waitlist[i]; | ||
| 436 | rdp->waittail[i + 1] = rdp->waittail[i]; | ||
| 437 | wlc++; | ||
| 438 | } else { | ||
| 439 | rdp->waitlist[i + 1] = NULL; | ||
| 440 | rdp->waittail[i + 1] = | ||
| 441 | &rdp->waitlist[i + 1]; | ||
| 442 | } | ||
| 443 | } | ||
| 444 | if (rdp->nextlist != NULL) { | ||
| 445 | rdp->waitlist[0] = rdp->nextlist; | ||
| 446 | rdp->waittail[0] = rdp->nexttail; | ||
| 447 | wlc++; | ||
| 448 | rdp->nextlist = NULL; | ||
| 449 | rdp->nexttail = &rdp->nextlist; | ||
| 450 | RCU_TRACE_RDP(rcupreempt_trace_move2wait, rdp); | ||
| 451 | } else { | ||
| 452 | rdp->waitlist[0] = NULL; | ||
| 453 | rdp->waittail[0] = &rdp->waitlist[0]; | ||
| 454 | } | ||
| 455 | rdp->waitlistcount = wlc; | ||
| 456 | rdp->completed = rcu_ctrlblk.completed; | ||
| 457 | } | ||
| 458 | |||
| 459 | /* | ||
| 460 | * Check to see if this CPU needs to report that it has seen | ||
| 461 | * the most recent counter flip, thereby declaring that all | ||
| 462 | * subsequent rcu_read_lock() invocations will respect this flip. | ||
| 463 | */ | ||
| 464 | |||
| 465 | cpu = raw_smp_processor_id(); | ||
| 466 | if (per_cpu(rcu_flip_flag, cpu) == rcu_flipped) { | ||
| 467 | smp_mb(); /* Subsequent counter accesses must see new value */ | ||
| 468 | per_cpu(rcu_flip_flag, cpu) = rcu_flip_seen; | ||
| 469 | smp_mb(); /* Subsequent RCU read-side critical sections */ | ||
| 470 | /* seen -after- acknowledgement. */ | ||
| 471 | } | ||
| 472 | } | ||
| 473 | |||
| 474 | #ifdef CONFIG_NO_HZ | ||
| 475 | static DEFINE_PER_CPU(int, rcu_update_flag); | ||
| 476 | |||
| 477 | /** | ||
| 478 | * rcu_irq_enter - Called from Hard irq handlers and NMI/SMI. | ||
| 479 | * | ||
| 480 | * If the CPU was idle with dynamic ticks active, this updates the | ||
| 481 | * rcu_dyntick_sched.dynticks to let the RCU handling know that the | ||
| 482 | * CPU is active. | ||
| 483 | */ | ||
| 484 | void rcu_irq_enter(void) | ||
| 485 | { | ||
| 486 | int cpu = smp_processor_id(); | ||
| 487 | struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu); | ||
| 488 | |||
| 489 | if (per_cpu(rcu_update_flag, cpu)) | ||
| 490 | per_cpu(rcu_update_flag, cpu)++; | ||
| 491 | |||
| 492 | /* | ||
| 493 | * Only update if we are coming from a stopped ticks mode | ||
| 494 | * (rcu_dyntick_sched.dynticks is even). | ||
| 495 | */ | ||
| 496 | if (!in_interrupt() && | ||
| 497 | (rdssp->dynticks & 0x1) == 0) { | ||
| 498 | /* | ||
| 499 | * The following might seem like we could have a race | ||
| 500 | * with NMI/SMIs. But this really isn't a problem. | ||
| 501 | * Here we do a read/modify/write, and the race happens | ||
| 502 | * when an NMI/SMI comes in after the read and before | ||
| 503 | * the write. But NMI/SMIs will increment this counter | ||
| 504 | * twice before returning, so the zero bit will not | ||
| 505 | * be corrupted by the NMI/SMI which is the most important | ||
| 506 | * part. | ||
| 507 | * | ||
| 508 | * The only thing is that we would bring back the counter | ||
| 509 | * to a postion that it was in during the NMI/SMI. | ||
| 510 | * But the zero bit would be set, so the rest of the | ||
| 511 | * counter would again be ignored. | ||
| 512 | * | ||
| 513 | * On return from the IRQ, the counter may have the zero | ||
| 514 | * bit be 0 and the counter the same as the return from | ||
| 515 | * the NMI/SMI. If the state machine was so unlucky to | ||
| 516 | * see that, it still doesn't matter, since all | ||
| 517 | * RCU read-side critical sections on this CPU would | ||
| 518 | * have already completed. | ||
| 519 | */ | ||
| 520 | rdssp->dynticks++; | ||
| 521 | /* | ||
| 522 | * The following memory barrier ensures that any | ||
| 523 | * rcu_read_lock() primitives in the irq handler | ||
| 524 | * are seen by other CPUs to follow the above | ||
| 525 | * increment to rcu_dyntick_sched.dynticks. This is | ||
| 526 | * required in order for other CPUs to correctly | ||
| 527 | * determine when it is safe to advance the RCU | ||
| 528 | * grace-period state machine. | ||
| 529 | */ | ||
| 530 | smp_mb(); /* see above block comment. */ | ||
| 531 | /* | ||
| 532 | * Since we can't determine the dynamic tick mode from | ||
| 533 | * the rcu_dyntick_sched.dynticks after this routine, | ||
| 534 | * we use a second flag to acknowledge that we came | ||
| 535 | * from an idle state with ticks stopped. | ||
| 536 | */ | ||
| 537 | per_cpu(rcu_update_flag, cpu)++; | ||
| 538 | /* | ||
| 539 | * If we take an NMI/SMI now, they will also increment | ||
| 540 | * the rcu_update_flag, and will not update the | ||
| 541 | * rcu_dyntick_sched.dynticks on exit. That is for | ||
| 542 | * this IRQ to do. | ||
| 543 | */ | ||
| 544 | } | ||
| 545 | } | ||
| 546 | |||
| 547 | /** | ||
| 548 | * rcu_irq_exit - Called from exiting Hard irq context. | ||
| 549 | * | ||
| 550 | * If the CPU was idle with dynamic ticks active, update the | ||
| 551 | * rcu_dyntick_sched.dynticks to put let the RCU handling be | ||
| 552 | * aware that the CPU is going back to idle with no ticks. | ||
| 553 | */ | ||
| 554 | void rcu_irq_exit(void) | ||
| 555 | { | ||
| 556 | int cpu = smp_processor_id(); | ||
| 557 | struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu); | ||
| 558 | |||
| 559 | /* | ||
| 560 | * rcu_update_flag is set if we interrupted the CPU | ||
| 561 | * when it was idle with ticks stopped. | ||
| 562 | * Once this occurs, we keep track of interrupt nesting | ||
| 563 | * because a NMI/SMI could also come in, and we still | ||
| 564 | * only want the IRQ that started the increment of the | ||
| 565 | * rcu_dyntick_sched.dynticks to be the one that modifies | ||
| 566 | * it on exit. | ||
| 567 | */ | ||
| 568 | if (per_cpu(rcu_update_flag, cpu)) { | ||
| 569 | if (--per_cpu(rcu_update_flag, cpu)) | ||
| 570 | return; | ||
| 571 | |||
| 572 | /* This must match the interrupt nesting */ | ||
| 573 | WARN_ON(in_interrupt()); | ||
| 574 | |||
| 575 | /* | ||
| 576 | * If an NMI/SMI happens now we are still | ||
| 577 | * protected by the rcu_dyntick_sched.dynticks being odd. | ||
| 578 | */ | ||
| 579 | |||
| 580 | /* | ||
| 581 | * The following memory barrier ensures that any | ||
| 582 | * rcu_read_unlock() primitives in the irq handler | ||
| 583 | * are seen by other CPUs to preceed the following | ||
| 584 | * increment to rcu_dyntick_sched.dynticks. This | ||
| 585 | * is required in order for other CPUs to determine | ||
| 586 | * when it is safe to advance the RCU grace-period | ||
| 587 | * state machine. | ||
| 588 | */ | ||
| 589 | smp_mb(); /* see above block comment. */ | ||
| 590 | rdssp->dynticks++; | ||
| 591 | WARN_ON(rdssp->dynticks & 0x1); | ||
| 592 | } | ||
| 593 | } | ||
| 594 | |||
| 595 | void rcu_nmi_enter(void) | ||
| 596 | { | ||
| 597 | rcu_irq_enter(); | ||
| 598 | } | ||
| 599 | |||
| 600 | void rcu_nmi_exit(void) | ||
| 601 | { | ||
| 602 | rcu_irq_exit(); | ||
| 603 | } | ||
| 604 | |||
| 605 | static void dyntick_save_progress_counter(int cpu) | ||
| 606 | { | ||
| 607 | struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu); | ||
| 608 | |||
| 609 | rdssp->dynticks_snap = rdssp->dynticks; | ||
| 610 | } | ||
| 611 | |||
| 612 | static inline int | ||
| 613 | rcu_try_flip_waitack_needed(int cpu) | ||
| 614 | { | ||
| 615 | long curr; | ||
| 616 | long snap; | ||
| 617 | struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu); | ||
| 618 | |||
| 619 | curr = rdssp->dynticks; | ||
| 620 | snap = rdssp->dynticks_snap; | ||
| 621 | smp_mb(); /* force ordering with cpu entering/leaving dynticks. */ | ||
| 622 | |||
| 623 | /* | ||
| 624 | * If the CPU remained in dynticks mode for the entire time | ||
| 625 | * and didn't take any interrupts, NMIs, SMIs, or whatever, | ||
| 626 | * then it cannot be in the middle of an rcu_read_lock(), so | ||
| 627 | * the next rcu_read_lock() it executes must use the new value | ||
| 628 | * of the counter. So we can safely pretend that this CPU | ||
| 629 | * already acknowledged the counter. | ||
| 630 | */ | ||
| 631 | |||
| 632 | if ((curr == snap) && ((curr & 0x1) == 0)) | ||
| 633 | return 0; | ||
| 634 | |||
| 635 | /* | ||
| 636 | * If the CPU passed through or entered a dynticks idle phase with | ||
| 637 | * no active irq handlers, then, as above, we can safely pretend | ||
| 638 | * that this CPU already acknowledged the counter. | ||
| 639 | */ | ||
| 640 | |||
| 641 | if ((curr - snap) > 2 || (curr & 0x1) == 0) | ||
| 642 | return 0; | ||
| 643 | |||
| 644 | /* We need this CPU to explicitly acknowledge the counter flip. */ | ||
| 645 | |||
| 646 | return 1; | ||
| 647 | } | ||
| 648 | |||
| 649 | static inline int | ||
| 650 | rcu_try_flip_waitmb_needed(int cpu) | ||
| 651 | { | ||
| 652 | long curr; | ||
| 653 | long snap; | ||
| 654 | struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu); | ||
| 655 | |||
| 656 | curr = rdssp->dynticks; | ||
| 657 | snap = rdssp->dynticks_snap; | ||
| 658 | smp_mb(); /* force ordering with cpu entering/leaving dynticks. */ | ||
| 659 | |||
| 660 | /* | ||
| 661 | * If the CPU remained in dynticks mode for the entire time | ||
| 662 | * and didn't take any interrupts, NMIs, SMIs, or whatever, | ||
| 663 | * then it cannot have executed an RCU read-side critical section | ||
| 664 | * during that time, so there is no need for it to execute a | ||
| 665 | * memory barrier. | ||
| 666 | */ | ||
| 667 | |||
| 668 | if ((curr == snap) && ((curr & 0x1) == 0)) | ||
| 669 | return 0; | ||
| 670 | |||
| 671 | /* | ||
| 672 | * If the CPU either entered or exited an outermost interrupt, | ||
| 673 | * SMI, NMI, or whatever handler, then we know that it executed | ||
| 674 | * a memory barrier when doing so. So we don't need another one. | ||
| 675 | */ | ||
| 676 | if (curr != snap) | ||
| 677 | return 0; | ||
| 678 | |||
| 679 | /* We need the CPU to execute a memory barrier. */ | ||
| 680 | |||
| 681 | return 1; | ||
| 682 | } | ||
| 683 | |||
| 684 | static void dyntick_save_progress_counter_sched(int cpu) | ||
| 685 | { | ||
| 686 | struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu); | ||
| 687 | |||
| 688 | rdssp->sched_dynticks_snap = rdssp->dynticks; | ||
| 689 | } | ||
| 690 | |||
| 691 | static int rcu_qsctr_inc_needed_dyntick(int cpu) | ||
| 692 | { | ||
| 693 | long curr; | ||
| 694 | long snap; | ||
| 695 | struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu); | ||
| 696 | |||
| 697 | curr = rdssp->dynticks; | ||
| 698 | snap = rdssp->sched_dynticks_snap; | ||
| 699 | smp_mb(); /* force ordering with cpu entering/leaving dynticks. */ | ||
| 700 | |||
| 701 | /* | ||
| 702 | * If the CPU remained in dynticks mode for the entire time | ||
| 703 | * and didn't take any interrupts, NMIs, SMIs, or whatever, | ||
| 704 | * then it cannot be in the middle of an rcu_read_lock(), so | ||
| 705 | * the next rcu_read_lock() it executes must use the new value | ||
| 706 | * of the counter. Therefore, this CPU has been in a quiescent | ||
| 707 | * state the entire time, and we don't need to wait for it. | ||
| 708 | */ | ||
| 709 | |||
| 710 | if ((curr == snap) && ((curr & 0x1) == 0)) | ||
| 711 | return 0; | ||
| 712 | |||
| 713 | /* | ||
| 714 | * If the CPU passed through or entered a dynticks idle phase with | ||
| 715 | * no active irq handlers, then, as above, this CPU has already | ||
| 716 | * passed through a quiescent state. | ||
| 717 | */ | ||
| 718 | |||
| 719 | if ((curr - snap) > 2 || (snap & 0x1) == 0) | ||
| 720 | return 0; | ||
| 721 | |||
| 722 | /* We need this CPU to go through a quiescent state. */ | ||
| 723 | |||
| 724 | return 1; | ||
| 725 | } | ||
| 726 | |||
| 727 | #else /* !CONFIG_NO_HZ */ | ||
| 728 | |||
| 729 | # define dyntick_save_progress_counter(cpu) do { } while (0) | ||
| 730 | # define rcu_try_flip_waitack_needed(cpu) (1) | ||
| 731 | # define rcu_try_flip_waitmb_needed(cpu) (1) | ||
| 732 | |||
| 733 | # define dyntick_save_progress_counter_sched(cpu) do { } while (0) | ||
| 734 | # define rcu_qsctr_inc_needed_dyntick(cpu) (1) | ||
| 735 | |||
| 736 | #endif /* CONFIG_NO_HZ */ | ||
| 737 | |||
| 738 | static void save_qsctr_sched(int cpu) | ||
| 739 | { | ||
| 740 | struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu); | ||
| 741 | |||
| 742 | rdssp->sched_qs_snap = rdssp->sched_qs; | ||
| 743 | } | ||
| 744 | |||
| 745 | static inline int rcu_qsctr_inc_needed(int cpu) | ||
| 746 | { | ||
| 747 | struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu); | ||
| 748 | |||
| 749 | /* | ||
| 750 | * If there has been a quiescent state, no more need to wait | ||
| 751 | * on this CPU. | ||
| 752 | */ | ||
| 753 | |||
| 754 | if (rdssp->sched_qs != rdssp->sched_qs_snap) { | ||
| 755 | smp_mb(); /* force ordering with cpu entering schedule(). */ | ||
| 756 | return 0; | ||
| 757 | } | ||
| 758 | |||
| 759 | /* We need this CPU to go through a quiescent state. */ | ||
| 760 | |||
| 761 | return 1; | ||
| 762 | } | ||
| 763 | |||
| 764 | /* | ||
| 765 | * Get here when RCU is idle. Decide whether we need to | ||
| 766 | * move out of idle state, and return non-zero if so. | ||
| 767 | * "Straightforward" approach for the moment, might later | ||
| 768 | * use callback-list lengths, grace-period duration, or | ||
| 769 | * some such to determine when to exit idle state. | ||
| 770 | * Might also need a pre-idle test that does not acquire | ||
| 771 | * the lock, but let's get the simple case working first... | ||
| 772 | */ | ||
| 773 | |||
| 774 | static int | ||
| 775 | rcu_try_flip_idle(void) | ||
| 776 | { | ||
| 777 | int cpu; | ||
| 778 | |||
| 779 | RCU_TRACE_ME(rcupreempt_trace_try_flip_i1); | ||
| 780 | if (!rcu_pending(smp_processor_id())) { | ||
| 781 | RCU_TRACE_ME(rcupreempt_trace_try_flip_ie1); | ||
| 782 | return 0; | ||
| 783 | } | ||
| 784 | |||
| 785 | /* | ||
| 786 | * Do the flip. | ||
| 787 | */ | ||
| 788 | |||
| 789 | RCU_TRACE_ME(rcupreempt_trace_try_flip_g1); | ||
| 790 | rcu_ctrlblk.completed++; /* stands in for rcu_try_flip_g2 */ | ||
| 791 | |||
| 792 | /* | ||
| 793 | * Need a memory barrier so that other CPUs see the new | ||
| 794 | * counter value before they see the subsequent change of all | ||
| 795 | * the rcu_flip_flag instances to rcu_flipped. | ||
| 796 | */ | ||
| 797 | |||
| 798 | smp_mb(); /* see above block comment. */ | ||
| 799 | |||
| 800 | /* Now ask each CPU for acknowledgement of the flip. */ | ||
| 801 | |||
| 802 | for_each_cpu(cpu, to_cpumask(rcu_cpu_online_map)) { | ||
| 803 | per_cpu(rcu_flip_flag, cpu) = rcu_flipped; | ||
| 804 | dyntick_save_progress_counter(cpu); | ||
| 805 | } | ||
| 806 | |||
| 807 | return 1; | ||
| 808 | } | ||
| 809 | |||
| 810 | /* | ||
| 811 | * Wait for CPUs to acknowledge the flip. | ||
| 812 | */ | ||
| 813 | |||
| 814 | static int | ||
| 815 | rcu_try_flip_waitack(void) | ||
| 816 | { | ||
| 817 | int cpu; | ||
| 818 | |||
| 819 | RCU_TRACE_ME(rcupreempt_trace_try_flip_a1); | ||
| 820 | for_each_cpu(cpu, to_cpumask(rcu_cpu_online_map)) | ||
| 821 | if (rcu_try_flip_waitack_needed(cpu) && | ||
| 822 | per_cpu(rcu_flip_flag, cpu) != rcu_flip_seen) { | ||
| 823 | RCU_TRACE_ME(rcupreempt_trace_try_flip_ae1); | ||
| 824 | return 0; | ||
| 825 | } | ||
| 826 | |||
| 827 | /* | ||
| 828 | * Make sure our checks above don't bleed into subsequent | ||
| 829 | * waiting for the sum of the counters to reach zero. | ||
| 830 | */ | ||
| 831 | |||
| 832 | smp_mb(); /* see above block comment. */ | ||
| 833 | RCU_TRACE_ME(rcupreempt_trace_try_flip_a2); | ||
| 834 | return 1; | ||
| 835 | } | ||
| 836 | |||
| 837 | /* | ||
| 838 | * Wait for collective ``last'' counter to reach zero, | ||
| 839 | * then tell all CPUs to do an end-of-grace-period memory barrier. | ||
| 840 | */ | ||
| 841 | |||
| 842 | static int | ||
| 843 | rcu_try_flip_waitzero(void) | ||
| 844 | { | ||
| 845 | int cpu; | ||
| 846 | int lastidx = !(rcu_ctrlblk.completed & 0x1); | ||
| 847 | int sum = 0; | ||
| 848 | |||
| 849 | /* Check to see if the sum of the "last" counters is zero. */ | ||
| 850 | |||
| 851 | RCU_TRACE_ME(rcupreempt_trace_try_flip_z1); | ||
| 852 | for_each_cpu(cpu, to_cpumask(rcu_cpu_online_map)) | ||
| 853 | sum += RCU_DATA_CPU(cpu)->rcu_flipctr[lastidx]; | ||
| 854 | if (sum != 0) { | ||
| 855 | RCU_TRACE_ME(rcupreempt_trace_try_flip_ze1); | ||
| 856 | return 0; | ||
| 857 | } | ||
| 858 | |||
| 859 | /* | ||
| 860 | * This ensures that the other CPUs see the call for | ||
| 861 | * memory barriers -after- the sum to zero has been | ||
| 862 | * detected here | ||
| 863 | */ | ||
| 864 | smp_mb(); /* ^^^^^^^^^^^^ */ | ||
| 865 | |||
| 866 | /* Call for a memory barrier from each CPU. */ | ||
| 867 | for_each_cpu(cpu, to_cpumask(rcu_cpu_online_map)) { | ||
| 868 | per_cpu(rcu_mb_flag, cpu) = rcu_mb_needed; | ||
| 869 | dyntick_save_progress_counter(cpu); | ||
| 870 | } | ||
| 871 | |||
| 872 | RCU_TRACE_ME(rcupreempt_trace_try_flip_z2); | ||
| 873 | return 1; | ||
| 874 | } | ||
| 875 | |||
| 876 | /* | ||
| 877 | * Wait for all CPUs to do their end-of-grace-period memory barrier. | ||
| 878 | * Return 0 once all CPUs have done so. | ||
| 879 | */ | ||
| 880 | |||
| 881 | static int | ||
| 882 | rcu_try_flip_waitmb(void) | ||
| 883 | { | ||
| 884 | int cpu; | ||
| 885 | |||
| 886 | RCU_TRACE_ME(rcupreempt_trace_try_flip_m1); | ||
| 887 | for_each_cpu(cpu, to_cpumask(rcu_cpu_online_map)) | ||
| 888 | if (rcu_try_flip_waitmb_needed(cpu) && | ||
| 889 | per_cpu(rcu_mb_flag, cpu) != rcu_mb_done) { | ||
| 890 | RCU_TRACE_ME(rcupreempt_trace_try_flip_me1); | ||
| 891 | return 0; | ||
| 892 | } | ||
| 893 | |||
| 894 | smp_mb(); /* Ensure that the above checks precede any following flip. */ | ||
| 895 | RCU_TRACE_ME(rcupreempt_trace_try_flip_m2); | ||
| 896 | return 1; | ||
| 897 | } | ||
| 898 | |||
| 899 | /* | ||
| 900 | * Attempt a single flip of the counters. Remember, a single flip does | ||
| 901 | * -not- constitute a grace period. Instead, the interval between | ||
| 902 | * at least GP_STAGES consecutive flips is a grace period. | ||
| 903 | * | ||
| 904 | * If anyone is nuts enough to run this CONFIG_PREEMPT_RCU implementation | ||
| 905 | * on a large SMP, they might want to use a hierarchical organization of | ||
| 906 | * the per-CPU-counter pairs. | ||
| 907 | */ | ||
| 908 | static void rcu_try_flip(void) | ||
| 909 | { | ||
| 910 | unsigned long flags; | ||
| 911 | |||
| 912 | RCU_TRACE_ME(rcupreempt_trace_try_flip_1); | ||
| 913 | if (unlikely(!spin_trylock_irqsave(&rcu_ctrlblk.fliplock, flags))) { | ||
| 914 | RCU_TRACE_ME(rcupreempt_trace_try_flip_e1); | ||
| 915 | return; | ||
| 916 | } | ||
| 917 | |||
| 918 | /* | ||
| 919 | * Take the next transition(s) through the RCU grace-period | ||
| 920 | * flip-counter state machine. | ||
| 921 | */ | ||
| 922 | |||
| 923 | switch (rcu_ctrlblk.rcu_try_flip_state) { | ||
| 924 | case rcu_try_flip_idle_state: | ||
| 925 | if (rcu_try_flip_idle()) | ||
| 926 | rcu_ctrlblk.rcu_try_flip_state = | ||
| 927 | rcu_try_flip_waitack_state; | ||
| 928 | break; | ||
| 929 | case rcu_try_flip_waitack_state: | ||
| 930 | if (rcu_try_flip_waitack()) | ||
| 931 | rcu_ctrlblk.rcu_try_flip_state = | ||
| 932 | rcu_try_flip_waitzero_state; | ||
| 933 | break; | ||
| 934 | case rcu_try_flip_waitzero_state: | ||
| 935 | if (rcu_try_flip_waitzero()) | ||
| 936 | rcu_ctrlblk.rcu_try_flip_state = | ||
| 937 | rcu_try_flip_waitmb_state; | ||
| 938 | break; | ||
| 939 | case rcu_try_flip_waitmb_state: | ||
| 940 | if (rcu_try_flip_waitmb()) | ||
| 941 | rcu_ctrlblk.rcu_try_flip_state = | ||
| 942 | rcu_try_flip_idle_state; | ||
| 943 | } | ||
| 944 | spin_unlock_irqrestore(&rcu_ctrlblk.fliplock, flags); | ||
| 945 | } | ||
| 946 | |||
| 947 | /* | ||
| 948 | * Check to see if this CPU needs to do a memory barrier in order to | ||
| 949 | * ensure that any prior RCU read-side critical sections have committed | ||
| 950 | * their counter manipulations and critical-section memory references | ||
| 951 | * before declaring the grace period to be completed. | ||
| 952 | */ | ||
| 953 | static void rcu_check_mb(int cpu) | ||
| 954 | { | ||
| 955 | if (per_cpu(rcu_mb_flag, cpu) == rcu_mb_needed) { | ||
| 956 | smp_mb(); /* Ensure RCU read-side accesses are visible. */ | ||
| 957 | per_cpu(rcu_mb_flag, cpu) = rcu_mb_done; | ||
| 958 | } | ||
| 959 | } | ||
| 960 | |||
| 961 | void rcu_check_callbacks(int cpu, int user) | ||
| 962 | { | ||
| 963 | unsigned long flags; | ||
| 964 | struct rcu_data *rdp = RCU_DATA_CPU(cpu); | ||
| 965 | |||
| 966 | /* | ||
| 967 | * If this CPU took its interrupt from user mode or from the | ||
| 968 | * idle loop, and this is not a nested interrupt, then | ||
| 969 | * this CPU has to have exited all prior preept-disable | ||
| 970 | * sections of code. So increment the counter to note this. | ||
| 971 | * | ||
| 972 | * The memory barrier is needed to handle the case where | ||
| 973 | * writes from a preempt-disable section of code get reordered | ||
| 974 | * into schedule() by this CPU's write buffer. So the memory | ||
| 975 | * barrier makes sure that the rcu_qsctr_inc() is seen by other | ||
| 976 | * CPUs to happen after any such write. | ||
| 977 | */ | ||
| 978 | |||
| 979 | if (user || | ||
| 980 | (idle_cpu(cpu) && !in_softirq() && | ||
| 981 | hardirq_count() <= (1 << HARDIRQ_SHIFT))) { | ||
| 982 | smp_mb(); /* Guard against aggressive schedule(). */ | ||
| 983 | rcu_qsctr_inc(cpu); | ||
| 984 | } | ||
| 985 | |||
| 986 | rcu_check_mb(cpu); | ||
| 987 | if (rcu_ctrlblk.completed == rdp->completed) | ||
| 988 | rcu_try_flip(); | ||
| 989 | spin_lock_irqsave(&rdp->lock, flags); | ||
| 990 | RCU_TRACE_RDP(rcupreempt_trace_check_callbacks, rdp); | ||
| 991 | __rcu_advance_callbacks(rdp); | ||
| 992 | if (rdp->donelist == NULL) { | ||
| 993 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 994 | } else { | ||
| 995 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 996 | raise_softirq(RCU_SOFTIRQ); | ||
| 997 | } | ||
| 998 | } | ||
| 999 | |||
| 1000 | /* | ||
| 1001 | * Needed by dynticks, to make sure all RCU processing has finished | ||
| 1002 | * when we go idle: | ||
| 1003 | */ | ||
| 1004 | void rcu_advance_callbacks(int cpu, int user) | ||
| 1005 | { | ||
| 1006 | unsigned long flags; | ||
| 1007 | struct rcu_data *rdp = RCU_DATA_CPU(cpu); | ||
| 1008 | |||
| 1009 | if (rcu_ctrlblk.completed == rdp->completed) { | ||
| 1010 | rcu_try_flip(); | ||
| 1011 | if (rcu_ctrlblk.completed == rdp->completed) | ||
| 1012 | return; | ||
| 1013 | } | ||
| 1014 | spin_lock_irqsave(&rdp->lock, flags); | ||
| 1015 | RCU_TRACE_RDP(rcupreempt_trace_check_callbacks, rdp); | ||
| 1016 | __rcu_advance_callbacks(rdp); | ||
| 1017 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 1018 | } | ||
| 1019 | |||
| 1020 | #ifdef CONFIG_HOTPLUG_CPU | ||
| 1021 | #define rcu_offline_cpu_enqueue(srclist, srctail, dstlist, dsttail) do { \ | ||
| 1022 | *dsttail = srclist; \ | ||
| 1023 | if (srclist != NULL) { \ | ||
| 1024 | dsttail = srctail; \ | ||
| 1025 | srclist = NULL; \ | ||
| 1026 | srctail = &srclist;\ | ||
| 1027 | } \ | ||
| 1028 | } while (0) | ||
| 1029 | |||
| 1030 | void rcu_offline_cpu(int cpu) | ||
| 1031 | { | ||
| 1032 | int i; | ||
| 1033 | struct rcu_head *list = NULL; | ||
| 1034 | unsigned long flags; | ||
| 1035 | struct rcu_data *rdp = RCU_DATA_CPU(cpu); | ||
| 1036 | struct rcu_head *schedlist = NULL; | ||
| 1037 | struct rcu_head **schedtail = &schedlist; | ||
| 1038 | struct rcu_head **tail = &list; | ||
| 1039 | |||
| 1040 | /* | ||
| 1041 | * Remove all callbacks from the newly dead CPU, retaining order. | ||
| 1042 | * Otherwise rcu_barrier() will fail | ||
| 1043 | */ | ||
| 1044 | |||
| 1045 | spin_lock_irqsave(&rdp->lock, flags); | ||
| 1046 | rcu_offline_cpu_enqueue(rdp->donelist, rdp->donetail, list, tail); | ||
| 1047 | for (i = GP_STAGES - 1; i >= 0; i--) | ||
| 1048 | rcu_offline_cpu_enqueue(rdp->waitlist[i], rdp->waittail[i], | ||
| 1049 | list, tail); | ||
| 1050 | rcu_offline_cpu_enqueue(rdp->nextlist, rdp->nexttail, list, tail); | ||
| 1051 | rcu_offline_cpu_enqueue(rdp->waitschedlist, rdp->waitschedtail, | ||
| 1052 | schedlist, schedtail); | ||
| 1053 | rcu_offline_cpu_enqueue(rdp->nextschedlist, rdp->nextschedtail, | ||
| 1054 | schedlist, schedtail); | ||
| 1055 | rdp->rcu_sched_sleeping = 0; | ||
| 1056 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 1057 | rdp->waitlistcount = 0; | ||
| 1058 | |||
| 1059 | /* Disengage the newly dead CPU from the grace-period computation. */ | ||
| 1060 | |||
| 1061 | spin_lock_irqsave(&rcu_ctrlblk.fliplock, flags); | ||
| 1062 | rcu_check_mb(cpu); | ||
| 1063 | if (per_cpu(rcu_flip_flag, cpu) == rcu_flipped) { | ||
| 1064 | smp_mb(); /* Subsequent counter accesses must see new value */ | ||
| 1065 | per_cpu(rcu_flip_flag, cpu) = rcu_flip_seen; | ||
| 1066 | smp_mb(); /* Subsequent RCU read-side critical sections */ | ||
| 1067 | /* seen -after- acknowledgement. */ | ||
| 1068 | } | ||
| 1069 | |||
| 1070 | RCU_DATA_ME()->rcu_flipctr[0] += RCU_DATA_CPU(cpu)->rcu_flipctr[0]; | ||
| 1071 | RCU_DATA_ME()->rcu_flipctr[1] += RCU_DATA_CPU(cpu)->rcu_flipctr[1]; | ||
| 1072 | |||
| 1073 | RCU_DATA_CPU(cpu)->rcu_flipctr[0] = 0; | ||
| 1074 | RCU_DATA_CPU(cpu)->rcu_flipctr[1] = 0; | ||
| 1075 | |||
| 1076 | cpumask_clear_cpu(cpu, to_cpumask(rcu_cpu_online_map)); | ||
| 1077 | |||
| 1078 | spin_unlock_irqrestore(&rcu_ctrlblk.fliplock, flags); | ||
| 1079 | |||
| 1080 | /* | ||
| 1081 | * Place the removed callbacks on the current CPU's queue. | ||
| 1082 | * Make them all start a new grace period: simple approach, | ||
| 1083 | * in theory could starve a given set of callbacks, but | ||
| 1084 | * you would need to be doing some serious CPU hotplugging | ||
| 1085 | * to make this happen. If this becomes a problem, adding | ||
| 1086 | * a synchronize_rcu() to the hotplug path would be a simple | ||
| 1087 | * fix. | ||
| 1088 | */ | ||
| 1089 | |||
| 1090 | local_irq_save(flags); /* disable preempt till we know what lock. */ | ||
| 1091 | rdp = RCU_DATA_ME(); | ||
| 1092 | spin_lock(&rdp->lock); | ||
| 1093 | *rdp->nexttail = list; | ||
| 1094 | if (list) | ||
| 1095 | rdp->nexttail = tail; | ||
| 1096 | *rdp->nextschedtail = schedlist; | ||
| 1097 | if (schedlist) | ||
| 1098 | rdp->nextschedtail = schedtail; | ||
| 1099 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 1100 | } | ||
| 1101 | |||
| 1102 | #else /* #ifdef CONFIG_HOTPLUG_CPU */ | ||
| 1103 | |||
| 1104 | void rcu_offline_cpu(int cpu) | ||
| 1105 | { | ||
| 1106 | } | ||
| 1107 | |||
| 1108 | #endif /* #else #ifdef CONFIG_HOTPLUG_CPU */ | ||
| 1109 | |||
| 1110 | void __cpuinit rcu_online_cpu(int cpu) | ||
| 1111 | { | ||
| 1112 | unsigned long flags; | ||
| 1113 | struct rcu_data *rdp; | ||
| 1114 | |||
| 1115 | spin_lock_irqsave(&rcu_ctrlblk.fliplock, flags); | ||
| 1116 | cpumask_set_cpu(cpu, to_cpumask(rcu_cpu_online_map)); | ||
| 1117 | spin_unlock_irqrestore(&rcu_ctrlblk.fliplock, flags); | ||
| 1118 | |||
| 1119 | /* | ||
| 1120 | * The rcu_sched grace-period processing might have bypassed | ||
| 1121 | * this CPU, given that it was not in the rcu_cpu_online_map | ||
| 1122 | * when the grace-period scan started. This means that the | ||
| 1123 | * grace-period task might sleep. So make sure that if this | ||
| 1124 | * should happen, the first callback posted to this CPU will | ||
| 1125 | * wake up the grace-period task if need be. | ||
| 1126 | */ | ||
| 1127 | |||
| 1128 | rdp = RCU_DATA_CPU(cpu); | ||
| 1129 | spin_lock_irqsave(&rdp->lock, flags); | ||
| 1130 | rdp->rcu_sched_sleeping = 1; | ||
| 1131 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 1132 | } | ||
| 1133 | |||
| 1134 | static void rcu_process_callbacks(struct softirq_action *unused) | ||
| 1135 | { | ||
| 1136 | unsigned long flags; | ||
| 1137 | struct rcu_head *next, *list; | ||
| 1138 | struct rcu_data *rdp; | ||
| 1139 | |||
| 1140 | local_irq_save(flags); | ||
| 1141 | rdp = RCU_DATA_ME(); | ||
| 1142 | spin_lock(&rdp->lock); | ||
| 1143 | list = rdp->donelist; | ||
| 1144 | if (list == NULL) { | ||
| 1145 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 1146 | return; | ||
| 1147 | } | ||
| 1148 | rdp->donelist = NULL; | ||
| 1149 | rdp->donetail = &rdp->donelist; | ||
| 1150 | RCU_TRACE_RDP(rcupreempt_trace_done_remove, rdp); | ||
| 1151 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 1152 | while (list) { | ||
| 1153 | next = list->next; | ||
| 1154 | list->func(list); | ||
| 1155 | list = next; | ||
| 1156 | RCU_TRACE_ME(rcupreempt_trace_invoke); | ||
| 1157 | } | ||
| 1158 | } | ||
| 1159 | |||
| 1160 | void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) | ||
| 1161 | { | ||
| 1162 | unsigned long flags; | ||
| 1163 | struct rcu_data *rdp; | ||
| 1164 | |||
| 1165 | head->func = func; | ||
| 1166 | head->next = NULL; | ||
| 1167 | local_irq_save(flags); | ||
| 1168 | rdp = RCU_DATA_ME(); | ||
| 1169 | spin_lock(&rdp->lock); | ||
| 1170 | __rcu_advance_callbacks(rdp); | ||
| 1171 | *rdp->nexttail = head; | ||
| 1172 | rdp->nexttail = &head->next; | ||
| 1173 | RCU_TRACE_RDP(rcupreempt_trace_next_add, rdp); | ||
| 1174 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 1175 | } | ||
| 1176 | EXPORT_SYMBOL_GPL(call_rcu); | ||
| 1177 | |||
| 1178 | void call_rcu_sched(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) | ||
| 1179 | { | ||
| 1180 | unsigned long flags; | ||
| 1181 | struct rcu_data *rdp; | ||
| 1182 | int wake_gp = 0; | ||
| 1183 | |||
| 1184 | head->func = func; | ||
| 1185 | head->next = NULL; | ||
| 1186 | local_irq_save(flags); | ||
| 1187 | rdp = RCU_DATA_ME(); | ||
| 1188 | spin_lock(&rdp->lock); | ||
| 1189 | *rdp->nextschedtail = head; | ||
| 1190 | rdp->nextschedtail = &head->next; | ||
| 1191 | if (rdp->rcu_sched_sleeping) { | ||
| 1192 | |||
| 1193 | /* Grace-period processing might be sleeping... */ | ||
| 1194 | |||
| 1195 | rdp->rcu_sched_sleeping = 0; | ||
| 1196 | wake_gp = 1; | ||
| 1197 | } | ||
| 1198 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 1199 | if (wake_gp) { | ||
| 1200 | |||
| 1201 | /* Wake up grace-period processing, unless someone beat us. */ | ||
| 1202 | |||
| 1203 | spin_lock_irqsave(&rcu_ctrlblk.schedlock, flags); | ||
| 1204 | if (rcu_ctrlblk.sched_sleep != rcu_sched_sleeping) | ||
| 1205 | wake_gp = 0; | ||
| 1206 | rcu_ctrlblk.sched_sleep = rcu_sched_not_sleeping; | ||
| 1207 | spin_unlock_irqrestore(&rcu_ctrlblk.schedlock, flags); | ||
| 1208 | if (wake_gp) | ||
| 1209 | wake_up_interruptible(&rcu_ctrlblk.sched_wq); | ||
| 1210 | } | ||
| 1211 | } | ||
| 1212 | EXPORT_SYMBOL_GPL(call_rcu_sched); | ||
| 1213 | |||
| 1214 | /* | ||
| 1215 | * Wait until all currently running preempt_disable() code segments | ||
| 1216 | * (including hardware-irq-disable segments) complete. Note that | ||
| 1217 | * in -rt this does -not- necessarily result in all currently executing | ||
| 1218 | * interrupt -handlers- having completed. | ||
| 1219 | */ | ||
| 1220 | void __synchronize_sched(void) | ||
| 1221 | { | ||
| 1222 | struct rcu_synchronize rcu; | ||
| 1223 | |||
| 1224 | if (num_online_cpus() == 1) | ||
| 1225 | return; /* blocking is gp if only one CPU! */ | ||
| 1226 | |||
| 1227 | init_completion(&rcu.completion); | ||
| 1228 | /* Will wake me after RCU finished. */ | ||
| 1229 | call_rcu_sched(&rcu.head, wakeme_after_rcu); | ||
| 1230 | /* Wait for it. */ | ||
| 1231 | wait_for_completion(&rcu.completion); | ||
| 1232 | } | ||
| 1233 | EXPORT_SYMBOL_GPL(__synchronize_sched); | ||
| 1234 | |||
| 1235 | /* | ||
| 1236 | * kthread function that manages call_rcu_sched grace periods. | ||
| 1237 | */ | ||
| 1238 | static int rcu_sched_grace_period(void *arg) | ||
| 1239 | { | ||
| 1240 | int couldsleep; /* might sleep after current pass. */ | ||
| 1241 | int couldsleepnext = 0; /* might sleep after next pass. */ | ||
| 1242 | int cpu; | ||
| 1243 | unsigned long flags; | ||
| 1244 | struct rcu_data *rdp; | ||
| 1245 | int ret; | ||
| 1246 | |||
| 1247 | /* | ||
| 1248 | * Each pass through the following loop handles one | ||
| 1249 | * rcu_sched grace period cycle. | ||
| 1250 | */ | ||
| 1251 | do { | ||
| 1252 | /* Save each CPU's current state. */ | ||
| 1253 | |||
| 1254 | for_each_online_cpu(cpu) { | ||
| 1255 | dyntick_save_progress_counter_sched(cpu); | ||
| 1256 | save_qsctr_sched(cpu); | ||
| 1257 | } | ||
| 1258 | |||
| 1259 | /* | ||
| 1260 | * Sleep for about an RCU grace-period's worth to | ||
| 1261 | * allow better batching and to consume less CPU. | ||
| 1262 | */ | ||
| 1263 | schedule_timeout_interruptible(RCU_SCHED_BATCH_TIME); | ||
| 1264 | |||
| 1265 | /* | ||
| 1266 | * If there was nothing to do last time, prepare to | ||
| 1267 | * sleep at the end of the current grace period cycle. | ||
| 1268 | */ | ||
| 1269 | couldsleep = couldsleepnext; | ||
| 1270 | couldsleepnext = 1; | ||
| 1271 | if (couldsleep) { | ||
| 1272 | spin_lock_irqsave(&rcu_ctrlblk.schedlock, flags); | ||
| 1273 | rcu_ctrlblk.sched_sleep = rcu_sched_sleep_prep; | ||
| 1274 | spin_unlock_irqrestore(&rcu_ctrlblk.schedlock, flags); | ||
| 1275 | } | ||
| 1276 | |||
| 1277 | /* | ||
| 1278 | * Wait on each CPU in turn to have either visited | ||
| 1279 | * a quiescent state or been in dynticks-idle mode. | ||
| 1280 | */ | ||
| 1281 | for_each_online_cpu(cpu) { | ||
| 1282 | while (rcu_qsctr_inc_needed(cpu) && | ||
| 1283 | rcu_qsctr_inc_needed_dyntick(cpu)) { | ||
| 1284 | /* resched_cpu(cpu); @@@ */ | ||
| 1285 | schedule_timeout_interruptible(1); | ||
| 1286 | } | ||
| 1287 | } | ||
| 1288 | |||
| 1289 | /* Advance callbacks for each CPU. */ | ||
| 1290 | |||
| 1291 | for_each_online_cpu(cpu) { | ||
| 1292 | |||
| 1293 | rdp = RCU_DATA_CPU(cpu); | ||
| 1294 | spin_lock_irqsave(&rdp->lock, flags); | ||
| 1295 | |||
| 1296 | /* | ||
| 1297 | * We are running on this CPU irq-disabled, so no | ||
| 1298 | * CPU can go offline until we re-enable irqs. | ||
| 1299 | * The current CPU might have already gone | ||
| 1300 | * offline (between the for_each_offline_cpu and | ||
| 1301 | * the spin_lock_irqsave), but in that case all its | ||
| 1302 | * callback lists will be empty, so no harm done. | ||
| 1303 | * | ||
| 1304 | * Advance the callbacks! We share normal RCU's | ||
| 1305 | * donelist, since callbacks are invoked the | ||
| 1306 | * same way in either case. | ||
| 1307 | */ | ||
| 1308 | if (rdp->waitschedlist != NULL) { | ||
| 1309 | *rdp->donetail = rdp->waitschedlist; | ||
| 1310 | rdp->donetail = rdp->waitschedtail; | ||
| 1311 | |||
| 1312 | /* | ||
| 1313 | * Next rcu_check_callbacks() will | ||
| 1314 | * do the required raise_softirq(). | ||
| 1315 | */ | ||
| 1316 | } | ||
| 1317 | if (rdp->nextschedlist != NULL) { | ||
| 1318 | rdp->waitschedlist = rdp->nextschedlist; | ||
| 1319 | rdp->waitschedtail = rdp->nextschedtail; | ||
| 1320 | couldsleep = 0; | ||
| 1321 | couldsleepnext = 0; | ||
| 1322 | } else { | ||
| 1323 | rdp->waitschedlist = NULL; | ||
| 1324 | rdp->waitschedtail = &rdp->waitschedlist; | ||
| 1325 | } | ||
| 1326 | rdp->nextschedlist = NULL; | ||
| 1327 | rdp->nextschedtail = &rdp->nextschedlist; | ||
| 1328 | |||
| 1329 | /* Mark sleep intention. */ | ||
| 1330 | |||
| 1331 | rdp->rcu_sched_sleeping = couldsleep; | ||
| 1332 | |||
| 1333 | spin_unlock_irqrestore(&rdp->lock, flags); | ||
| 1334 | } | ||
| 1335 | |||
| 1336 | /* If we saw callbacks on the last scan, go deal with them. */ | ||
| 1337 | |||
| 1338 | if (!couldsleep) | ||
| 1339 | continue; | ||
| 1340 | |||
| 1341 | /* Attempt to block... */ | ||
| 1342 | |||
| 1343 | spin_lock_irqsave(&rcu_ctrlblk.schedlock, flags); | ||
| 1344 | if (rcu_ctrlblk.sched_sleep != rcu_sched_sleep_prep) { | ||
| 1345 | |||
| 1346 | /* | ||
| 1347 | * Someone posted a callback after we scanned. | ||
| 1348 | * Go take care of it. | ||
| 1349 | */ | ||
| 1350 | spin_unlock_irqrestore(&rcu_ctrlblk.schedlock, flags); | ||
| 1351 | couldsleepnext = 0; | ||
| 1352 | continue; | ||
| 1353 | } | ||
| 1354 | |||
| 1355 | /* Block until the next person posts a callback. */ | ||
| 1356 | |||
| 1357 | rcu_ctrlblk.sched_sleep = rcu_sched_sleeping; | ||
| 1358 | spin_unlock_irqrestore(&rcu_ctrlblk.schedlock, flags); | ||
| 1359 | ret = 0; /* unused */ | ||
| 1360 | __wait_event_interruptible(rcu_ctrlblk.sched_wq, | ||
| 1361 | rcu_ctrlblk.sched_sleep != rcu_sched_sleeping, | ||
| 1362 | ret); | ||
| 1363 | |||
| 1364 | couldsleepnext = 0; | ||
| 1365 | |||
| 1366 | } while (!kthread_should_stop()); | ||
| 1367 | |||
| 1368 | return (0); | ||
| 1369 | } | ||
| 1370 | |||
| 1371 | /* | ||
| 1372 | * Check to see if any future RCU-related work will need to be done | ||
| 1373 | * by the current CPU, even if none need be done immediately, returning | ||
| 1374 | * 1 if so. Assumes that notifiers would take care of handling any | ||
| 1375 | * outstanding requests from the RCU core. | ||
| 1376 | * | ||
| 1377 | * This function is part of the RCU implementation; it is -not- | ||
| 1378 | * an exported member of the RCU API. | ||
| 1379 | */ | ||
| 1380 | int rcu_needs_cpu(int cpu) | ||
| 1381 | { | ||
| 1382 | struct rcu_data *rdp = RCU_DATA_CPU(cpu); | ||
| 1383 | |||
| 1384 | return (rdp->donelist != NULL || | ||
| 1385 | !!rdp->waitlistcount || | ||
| 1386 | rdp->nextlist != NULL || | ||
| 1387 | rdp->nextschedlist != NULL || | ||
| 1388 | rdp->waitschedlist != NULL); | ||
| 1389 | } | ||
| 1390 | |||
| 1391 | int rcu_pending(int cpu) | ||
| 1392 | { | ||
| 1393 | struct rcu_data *rdp = RCU_DATA_CPU(cpu); | ||
| 1394 | |||
| 1395 | /* The CPU has at least one callback queued somewhere. */ | ||
| 1396 | |||
| 1397 | if (rdp->donelist != NULL || | ||
| 1398 | !!rdp->waitlistcount || | ||
| 1399 | rdp->nextlist != NULL || | ||
| 1400 | rdp->nextschedlist != NULL || | ||
| 1401 | rdp->waitschedlist != NULL) | ||
| 1402 | return 1; | ||
| 1403 | |||
| 1404 | /* The RCU core needs an acknowledgement from this CPU. */ | ||
| 1405 | |||
| 1406 | if ((per_cpu(rcu_flip_flag, cpu) == rcu_flipped) || | ||
| 1407 | (per_cpu(rcu_mb_flag, cpu) == rcu_mb_needed)) | ||
| 1408 | return 1; | ||
| 1409 | |||
| 1410 | /* This CPU has fallen behind the global grace-period number. */ | ||
| 1411 | |||
| 1412 | if (rdp->completed != rcu_ctrlblk.completed) | ||
| 1413 | return 1; | ||
| 1414 | |||
| 1415 | /* Nothing needed from this CPU. */ | ||
| 1416 | |||
| 1417 | return 0; | ||
| 1418 | } | ||
| 1419 | |||
| 1420 | static int __cpuinit rcu_cpu_notify(struct notifier_block *self, | ||
| 1421 | unsigned long action, void *hcpu) | ||
| 1422 | { | ||
| 1423 | long cpu = (long)hcpu; | ||
| 1424 | |||
| 1425 | switch (action) { | ||
| 1426 | case CPU_UP_PREPARE: | ||
| 1427 | case CPU_UP_PREPARE_FROZEN: | ||
| 1428 | rcu_online_cpu(cpu); | ||
| 1429 | break; | ||
| 1430 | case CPU_UP_CANCELED: | ||
| 1431 | case CPU_UP_CANCELED_FROZEN: | ||
| 1432 | case CPU_DEAD: | ||
| 1433 | case CPU_DEAD_FROZEN: | ||
| 1434 | rcu_offline_cpu(cpu); | ||
| 1435 | break; | ||
| 1436 | default: | ||
| 1437 | break; | ||
| 1438 | } | ||
| 1439 | return NOTIFY_OK; | ||
| 1440 | } | ||
| 1441 | |||
| 1442 | static struct notifier_block __cpuinitdata rcu_nb = { | ||
| 1443 | .notifier_call = rcu_cpu_notify, | ||
| 1444 | }; | ||
| 1445 | |||
| 1446 | void __init __rcu_init(void) | ||
| 1447 | { | ||
| 1448 | int cpu; | ||
| 1449 | int i; | ||
| 1450 | struct rcu_data *rdp; | ||
| 1451 | |||
| 1452 | printk(KERN_NOTICE "Preemptible RCU implementation.\n"); | ||
| 1453 | for_each_possible_cpu(cpu) { | ||
| 1454 | rdp = RCU_DATA_CPU(cpu); | ||
| 1455 | spin_lock_init(&rdp->lock); | ||
| 1456 | rdp->completed = 0; | ||
| 1457 | rdp->waitlistcount = 0; | ||
| 1458 | rdp->nextlist = NULL; | ||
| 1459 | rdp->nexttail = &rdp->nextlist; | ||
| 1460 | for (i = 0; i < GP_STAGES; i++) { | ||
| 1461 | rdp->waitlist[i] = NULL; | ||
| 1462 | rdp->waittail[i] = &rdp->waitlist[i]; | ||
| 1463 | } | ||
| 1464 | rdp->donelist = NULL; | ||
| 1465 | rdp->donetail = &rdp->donelist; | ||
| 1466 | rdp->rcu_flipctr[0] = 0; | ||
| 1467 | rdp->rcu_flipctr[1] = 0; | ||
| 1468 | rdp->nextschedlist = NULL; | ||
| 1469 | rdp->nextschedtail = &rdp->nextschedlist; | ||
| 1470 | rdp->waitschedlist = NULL; | ||
| 1471 | rdp->waitschedtail = &rdp->waitschedlist; | ||
| 1472 | rdp->rcu_sched_sleeping = 0; | ||
| 1473 | } | ||
| 1474 | register_cpu_notifier(&rcu_nb); | ||
| 1475 | |||
| 1476 | /* | ||
| 1477 | * We don't need protection against CPU-Hotplug here | ||
| 1478 | * since | ||
| 1479 | * a) If a CPU comes online while we are iterating over the | ||
| 1480 | * cpu_online_mask below, we would only end up making a | ||
| 1481 | * duplicate call to rcu_online_cpu() which sets the corresponding | ||
| 1482 | * CPU's mask in the rcu_cpu_online_map. | ||
| 1483 | * | ||
| 1484 | * b) A CPU cannot go offline at this point in time since the user | ||
| 1485 | * does not have access to the sysfs interface, nor do we | ||
| 1486 | * suspend the system. | ||
| 1487 | */ | ||
| 1488 | for_each_online_cpu(cpu) | ||
| 1489 | rcu_cpu_notify(&rcu_nb, CPU_UP_PREPARE, (void *)(long) cpu); | ||
| 1490 | |||
| 1491 | open_softirq(RCU_SOFTIRQ, rcu_process_callbacks); | ||
| 1492 | } | ||
| 1493 | |||
| 1494 | /* | ||
| 1495 | * Late-boot-time RCU initialization that must wait until after scheduler | ||
| 1496 | * has been initialized. | ||
| 1497 | */ | ||
| 1498 | void __init rcu_init_sched(void) | ||
| 1499 | { | ||
| 1500 | rcu_sched_grace_period_task = kthread_run(rcu_sched_grace_period, | ||
| 1501 | NULL, | ||
| 1502 | "rcu_sched_grace_period"); | ||
| 1503 | WARN_ON(IS_ERR(rcu_sched_grace_period_task)); | ||
| 1504 | } | ||
| 1505 | |||
| 1506 | #ifdef CONFIG_RCU_TRACE | ||
| 1507 | long *rcupreempt_flipctr(int cpu) | ||
| 1508 | { | ||
| 1509 | return &RCU_DATA_CPU(cpu)->rcu_flipctr[0]; | ||
| 1510 | } | ||
| 1511 | EXPORT_SYMBOL_GPL(rcupreempt_flipctr); | ||
| 1512 | |||
| 1513 | int rcupreempt_flip_flag(int cpu) | ||
| 1514 | { | ||
| 1515 | return per_cpu(rcu_flip_flag, cpu); | ||
| 1516 | } | ||
| 1517 | EXPORT_SYMBOL_GPL(rcupreempt_flip_flag); | ||
| 1518 | |||
| 1519 | int rcupreempt_mb_flag(int cpu) | ||
| 1520 | { | ||
| 1521 | return per_cpu(rcu_mb_flag, cpu); | ||
| 1522 | } | ||
| 1523 | EXPORT_SYMBOL_GPL(rcupreempt_mb_flag); | ||
| 1524 | |||
| 1525 | char *rcupreempt_try_flip_state_name(void) | ||
| 1526 | { | ||
| 1527 | return rcu_try_flip_state_names[rcu_ctrlblk.rcu_try_flip_state]; | ||
| 1528 | } | ||
| 1529 | EXPORT_SYMBOL_GPL(rcupreempt_try_flip_state_name); | ||
| 1530 | |||
| 1531 | struct rcupreempt_trace *rcupreempt_trace_cpu(int cpu) | ||
| 1532 | { | ||
| 1533 | struct rcu_data *rdp = RCU_DATA_CPU(cpu); | ||
| 1534 | |||
| 1535 | return &rdp->trace; | ||
| 1536 | } | ||
| 1537 | EXPORT_SYMBOL_GPL(rcupreempt_trace_cpu); | ||
| 1538 | |||
| 1539 | #endif /* #ifdef RCU_TRACE */ | ||
diff --git a/kernel/rcupreempt_trace.c b/kernel/rcupreempt_trace.c deleted file mode 100644 index 7c2665cac172..000000000000 --- a/kernel/rcupreempt_trace.c +++ /dev/null | |||
| @@ -1,334 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Read-Copy Update tracing for realtime implementation | ||
| 3 | * | ||
| 4 | * This program is free software; you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License as published by | ||
| 6 | * the Free Software Foundation; either version 2 of the License, or | ||
| 7 | * (at your option) any later version. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 17 | * | ||
| 18 | * Copyright IBM Corporation, 2006 | ||
| 19 | * | ||
| 20 | * Papers: http://www.rdrop.com/users/paulmck/RCU | ||
| 21 | * | ||
| 22 | * For detailed explanation of Read-Copy Update mechanism see - | ||
| 23 | * Documentation/RCU/ *.txt | ||
| 24 | * | ||
| 25 | */ | ||
| 26 | #include <linux/types.h> | ||
| 27 | #include <linux/kernel.h> | ||
| 28 | #include <linux/init.h> | ||
| 29 | #include <linux/spinlock.h> | ||
| 30 | #include <linux/smp.h> | ||
| 31 | #include <linux/rcupdate.h> | ||
| 32 | #include <linux/interrupt.h> | ||
| 33 | #include <linux/sched.h> | ||
| 34 | #include <asm/atomic.h> | ||
| 35 | #include <linux/bitops.h> | ||
| 36 | #include <linux/module.h> | ||
| 37 | #include <linux/completion.h> | ||
| 38 | #include <linux/moduleparam.h> | ||
| 39 | #include <linux/percpu.h> | ||
| 40 | #include <linux/notifier.h> | ||
| 41 | #include <linux/cpu.h> | ||
| 42 | #include <linux/mutex.h> | ||
| 43 | #include <linux/rcupreempt_trace.h> | ||
| 44 | #include <linux/debugfs.h> | ||
| 45 | |||
| 46 | static struct mutex rcupreempt_trace_mutex; | ||
| 47 | static char *rcupreempt_trace_buf; | ||
| 48 | #define RCUPREEMPT_TRACE_BUF_SIZE 4096 | ||
| 49 | |||
| 50 | void rcupreempt_trace_move2done(struct rcupreempt_trace *trace) | ||
| 51 | { | ||
| 52 | trace->done_length += trace->wait_length; | ||
| 53 | trace->done_add += trace->wait_length; | ||
| 54 | trace->wait_length = 0; | ||
| 55 | } | ||
| 56 | void rcupreempt_trace_move2wait(struct rcupreempt_trace *trace) | ||
| 57 | { | ||
| 58 | trace->wait_length += trace->next_length; | ||
| 59 | trace->wait_add += trace->next_length; | ||
| 60 | trace->next_length = 0; | ||
| 61 | } | ||
| 62 | void rcupreempt_trace_try_flip_1(struct rcupreempt_trace *trace) | ||
| 63 | { | ||
| 64 | atomic_inc(&trace->rcu_try_flip_1); | ||
| 65 | } | ||
| 66 | void rcupreempt_trace_try_flip_e1(struct rcupreempt_trace *trace) | ||
| 67 | { | ||
| 68 | atomic_inc(&trace->rcu_try_flip_e1); | ||
| 69 | } | ||
| 70 | void rcupreempt_trace_try_flip_i1(struct rcupreempt_trace *trace) | ||
| 71 | { | ||
| 72 | trace->rcu_try_flip_i1++; | ||
| 73 | } | ||
| 74 | void rcupreempt_trace_try_flip_ie1(struct rcupreempt_trace *trace) | ||
| 75 | { | ||
| 76 | trace->rcu_try_flip_ie1++; | ||
| 77 | } | ||
| 78 | void rcupreempt_trace_try_flip_g1(struct rcupreempt_trace *trace) | ||
| 79 | { | ||
| 80 | trace->rcu_try_flip_g1++; | ||
| 81 | } | ||
| 82 | void rcupreempt_trace_try_flip_a1(struct rcupreempt_trace *trace) | ||
| 83 | { | ||
| 84 | trace->rcu_try_flip_a1++; | ||
| 85 | } | ||
| 86 | void rcupreempt_trace_try_flip_ae1(struct rcupreempt_trace *trace) | ||
| 87 | { | ||
| 88 | trace->rcu_try_flip_ae1++; | ||
| 89 | } | ||
| 90 | void rcupreempt_trace_try_flip_a2(struct rcupreempt_trace *trace) | ||
| 91 | { | ||
| 92 | trace->rcu_try_flip_a2++; | ||
| 93 | } | ||
| 94 | void rcupreempt_trace_try_flip_z1(struct rcupreempt_trace *trace) | ||
| 95 | { | ||
| 96 | trace->rcu_try_flip_z1++; | ||
| 97 | } | ||
| 98 | void rcupreempt_trace_try_flip_ze1(struct rcupreempt_trace *trace) | ||
| 99 | { | ||
| 100 | trace->rcu_try_flip_ze1++; | ||
| 101 | } | ||
| 102 | void rcupreempt_trace_try_flip_z2(struct rcupreempt_trace *trace) | ||
| 103 | { | ||
| 104 | trace->rcu_try_flip_z2++; | ||
| 105 | } | ||
| 106 | void rcupreempt_trace_try_flip_m1(struct rcupreempt_trace *trace) | ||
| 107 | { | ||
| 108 | trace->rcu_try_flip_m1++; | ||
| 109 | } | ||
| 110 | void rcupreempt_trace_try_flip_me1(struct rcupreempt_trace *trace) | ||
| 111 | { | ||
| 112 | trace->rcu_try_flip_me1++; | ||
| 113 | } | ||
| 114 | void rcupreempt_trace_try_flip_m2(struct rcupreempt_trace *trace) | ||
| 115 | { | ||
| 116 | trace->rcu_try_flip_m2++; | ||
| 117 | } | ||
| 118 | void rcupreempt_trace_check_callbacks(struct rcupreempt_trace *trace) | ||
| 119 | { | ||
| 120 | trace->rcu_check_callbacks++; | ||
| 121 | } | ||
| 122 | void rcupreempt_trace_done_remove(struct rcupreempt_trace *trace) | ||
| 123 | { | ||
| 124 | trace->done_remove += trace->done_length; | ||
| 125 | trace->done_length = 0; | ||
| 126 | } | ||
| 127 | void rcupreempt_trace_invoke(struct rcupreempt_trace *trace) | ||
| 128 | { | ||
| 129 | atomic_inc(&trace->done_invoked); | ||
| 130 | } | ||
| 131 | void rcupreempt_trace_next_add(struct rcupreempt_trace *trace) | ||
| 132 | { | ||
| 133 | trace->next_add++; | ||
| 134 | trace->next_length++; | ||
| 135 | } | ||
| 136 | |||
| 137 | static void rcupreempt_trace_sum(struct rcupreempt_trace *sp) | ||
| 138 | { | ||
| 139 | struct rcupreempt_trace *cp; | ||
| 140 | int cpu; | ||
| 141 | |||
| 142 | memset(sp, 0, sizeof(*sp)); | ||
| 143 | for_each_possible_cpu(cpu) { | ||
| 144 | cp = rcupreempt_trace_cpu(cpu); | ||
| 145 | sp->next_length += cp->next_length; | ||
| 146 | sp->next_add += cp->next_add; | ||
| 147 | sp->wait_length += cp->wait_length; | ||
| 148 | sp->wait_add += cp->wait_add; | ||
| 149 | sp->done_length += cp->done_length; | ||
| 150 | sp->done_add += cp->done_add; | ||
| 151 | sp->done_remove += cp->done_remove; | ||
| 152 | atomic_add(atomic_read(&cp->done_invoked), &sp->done_invoked); | ||
| 153 | sp->rcu_check_callbacks += cp->rcu_check_callbacks; | ||
| 154 | atomic_add(atomic_read(&cp->rcu_try_flip_1), | ||
| 155 | &sp->rcu_try_flip_1); | ||
| 156 | atomic_add(atomic_read(&cp->rcu_try_flip_e1), | ||
| 157 | &sp->rcu_try_flip_e1); | ||
| 158 | sp->rcu_try_flip_i1 += cp->rcu_try_flip_i1; | ||
| 159 | sp->rcu_try_flip_ie1 += cp->rcu_try_flip_ie1; | ||
| 160 | sp->rcu_try_flip_g1 += cp->rcu_try_flip_g1; | ||
| 161 | sp->rcu_try_flip_a1 += cp->rcu_try_flip_a1; | ||
| 162 | sp->rcu_try_flip_ae1 += cp->rcu_try_flip_ae1; | ||
| 163 | sp->rcu_try_flip_a2 += cp->rcu_try_flip_a2; | ||
| 164 | sp->rcu_try_flip_z1 += cp->rcu_try_flip_z1; | ||
| 165 | sp->rcu_try_flip_ze1 += cp->rcu_try_flip_ze1; | ||
| 166 | sp->rcu_try_flip_z2 += cp->rcu_try_flip_z2; | ||
| 167 | sp->rcu_try_flip_m1 += cp->rcu_try_flip_m1; | ||
| 168 | sp->rcu_try_flip_me1 += cp->rcu_try_flip_me1; | ||
| 169 | sp->rcu_try_flip_m2 += cp->rcu_try_flip_m2; | ||
| 170 | } | ||
| 171 | } | ||
| 172 | |||
| 173 | static ssize_t rcustats_read(struct file *filp, char __user *buffer, | ||
| 174 | size_t count, loff_t *ppos) | ||
| 175 | { | ||
| 176 | struct rcupreempt_trace trace; | ||
| 177 | ssize_t bcount; | ||
| 178 | int cnt = 0; | ||
| 179 | |||
| 180 | rcupreempt_trace_sum(&trace); | ||
| 181 | mutex_lock(&rcupreempt_trace_mutex); | ||
| 182 | snprintf(&rcupreempt_trace_buf[cnt], RCUPREEMPT_TRACE_BUF_SIZE - cnt, | ||
| 183 | "ggp=%ld rcc=%ld\n", | ||
| 184 | rcu_batches_completed(), | ||
| 185 | trace.rcu_check_callbacks); | ||
| 186 | snprintf(&rcupreempt_trace_buf[cnt], RCUPREEMPT_TRACE_BUF_SIZE - cnt, | ||
| 187 | "na=%ld nl=%ld wa=%ld wl=%ld da=%ld dl=%ld dr=%ld di=%d\n" | ||
| 188 | "1=%d e1=%d i1=%ld ie1=%ld g1=%ld a1=%ld ae1=%ld a2=%ld\n" | ||
| 189 | "z1=%ld ze1=%ld z2=%ld m1=%ld me1=%ld m2=%ld\n", | ||
| 190 | |||
| 191 | trace.next_add, trace.next_length, | ||
| 192 | trace.wait_add, trace.wait_length, | ||
| 193 | trace.done_add, trace.done_length, | ||
| 194 | trace.done_remove, atomic_read(&trace.done_invoked), | ||
| 195 | atomic_read(&trace.rcu_try_flip_1), | ||
| 196 | atomic_read(&trace.rcu_try_flip_e1), | ||
| 197 | trace.rcu_try_flip_i1, trace.rcu_try_flip_ie1, | ||
| 198 | trace.rcu_try_flip_g1, | ||
| 199 | trace.rcu_try_flip_a1, trace.rcu_try_flip_ae1, | ||
| 200 | trace.rcu_try_flip_a2, | ||
| 201 | trace.rcu_try_flip_z1, trace.rcu_try_flip_ze1, | ||
| 202 | trace.rcu_try_flip_z2, | ||
| 203 | trace.rcu_try_flip_m1, trace.rcu_try_flip_me1, | ||
| 204 | trace.rcu_try_flip_m2); | ||
| 205 | bcount = simple_read_from_buffer(buffer, count, ppos, | ||
| 206 | rcupreempt_trace_buf, strlen(rcupreempt_trace_buf)); | ||
| 207 | mutex_unlock(&rcupreempt_trace_mutex); | ||
| 208 | return bcount; | ||
| 209 | } | ||
| 210 | |||
| 211 | static ssize_t rcugp_read(struct file *filp, char __user *buffer, | ||
| 212 | size_t count, loff_t *ppos) | ||
| 213 | { | ||
| 214 | long oldgp = rcu_batches_completed(); | ||
| 215 | ssize_t bcount; | ||
| 216 | |||
| 217 | mutex_lock(&rcupreempt_trace_mutex); | ||
| 218 | synchronize_rcu(); | ||
| 219 | snprintf(rcupreempt_trace_buf, RCUPREEMPT_TRACE_BUF_SIZE, | ||
| 220 | "oldggp=%ld newggp=%ld\n", oldgp, rcu_batches_completed()); | ||
| 221 | bcount = simple_read_from_buffer(buffer, count, ppos, | ||
| 222 | rcupreempt_trace_buf, strlen(rcupreempt_trace_buf)); | ||
| 223 | mutex_unlock(&rcupreempt_trace_mutex); | ||
| 224 | return bcount; | ||
| 225 | } | ||
| 226 | |||
| 227 | static ssize_t rcuctrs_read(struct file *filp, char __user *buffer, | ||
| 228 | size_t count, loff_t *ppos) | ||
| 229 | { | ||
| 230 | int cnt = 0; | ||
| 231 | int cpu; | ||
| 232 | int f = rcu_batches_completed() & 0x1; | ||
| 233 | ssize_t bcount; | ||
| 234 | |||
| 235 | mutex_lock(&rcupreempt_trace_mutex); | ||
| 236 | |||
| 237 | cnt += snprintf(&rcupreempt_trace_buf[cnt], RCUPREEMPT_TRACE_BUF_SIZE, | ||
| 238 | "CPU last cur F M\n"); | ||
| 239 | for_each_online_cpu(cpu) { | ||
| 240 | long *flipctr = rcupreempt_flipctr(cpu); | ||
| 241 | cnt += snprintf(&rcupreempt_trace_buf[cnt], | ||
| 242 | RCUPREEMPT_TRACE_BUF_SIZE - cnt, | ||
| 243 | "%3d %4ld %3ld %d %d\n", | ||
| 244 | cpu, | ||
| 245 | flipctr[!f], | ||
| 246 | flipctr[f], | ||
| 247 | rcupreempt_flip_flag(cpu), | ||
| 248 | rcupreempt_mb_flag(cpu)); | ||
| 249 | } | ||
| 250 | cnt += snprintf(&rcupreempt_trace_buf[cnt], | ||
| 251 | RCUPREEMPT_TRACE_BUF_SIZE - cnt, | ||
| 252 | "ggp = %ld, state = %s\n", | ||
| 253 | rcu_batches_completed(), | ||
| 254 | rcupreempt_try_flip_state_name()); | ||
| 255 | cnt += snprintf(&rcupreempt_trace_buf[cnt], | ||
| 256 | RCUPREEMPT_TRACE_BUF_SIZE - cnt, | ||
| 257 | "\n"); | ||
| 258 | bcount = simple_read_from_buffer(buffer, count, ppos, | ||
| 259 | rcupreempt_trace_buf, strlen(rcupreempt_trace_buf)); | ||
| 260 | mutex_unlock(&rcupreempt_trace_mutex); | ||
| 261 | return bcount; | ||
| 262 | } | ||
| 263 | |||
| 264 | static struct file_operations rcustats_fops = { | ||
| 265 | .owner = THIS_MODULE, | ||
| 266 | .read = rcustats_read, | ||
| 267 | }; | ||
| 268 | |||
| 269 | static struct file_operations rcugp_fops = { | ||
| 270 | .owner = THIS_MODULE, | ||
| 271 | .read = rcugp_read, | ||
| 272 | }; | ||
| 273 | |||
| 274 | static struct file_operations rcuctrs_fops = { | ||
| 275 | .owner = THIS_MODULE, | ||
| 276 | .read = rcuctrs_read, | ||
| 277 | }; | ||
| 278 | |||
| 279 | static struct dentry *rcudir, *statdir, *ctrsdir, *gpdir; | ||
| 280 | static int rcupreempt_debugfs_init(void) | ||
| 281 | { | ||
| 282 | rcudir = debugfs_create_dir("rcu", NULL); | ||
| 283 | if (!rcudir) | ||
| 284 | goto out; | ||
| 285 | statdir = debugfs_create_file("rcustats", 0444, rcudir, | ||
| 286 | NULL, &rcustats_fops); | ||
| 287 | if (!statdir) | ||
| 288 | goto free_out; | ||
| 289 | |||
| 290 | gpdir = debugfs_create_file("rcugp", 0444, rcudir, NULL, &rcugp_fops); | ||
| 291 | if (!gpdir) | ||
| 292 | goto free_out; | ||
| 293 | |||
| 294 | ctrsdir = debugfs_create_file("rcuctrs", 0444, rcudir, | ||
| 295 | NULL, &rcuctrs_fops); | ||
| 296 | if (!ctrsdir) | ||
| 297 | goto free_out; | ||
| 298 | return 0; | ||
| 299 | free_out: | ||
| 300 | if (statdir) | ||
| 301 | debugfs_remove(statdir); | ||
| 302 | if (gpdir) | ||
| 303 | debugfs_remove(gpdir); | ||
| 304 | debugfs_remove(rcudir); | ||
| 305 | out: | ||
| 306 | return 1; | ||
| 307 | } | ||
| 308 | |||
| 309 | static int __init rcupreempt_trace_init(void) | ||
| 310 | { | ||
| 311 | int ret; | ||
| 312 | |||
| 313 | mutex_init(&rcupreempt_trace_mutex); | ||
| 314 | rcupreempt_trace_buf = kmalloc(RCUPREEMPT_TRACE_BUF_SIZE, GFP_KERNEL); | ||
| 315 | if (!rcupreempt_trace_buf) | ||
| 316 | return 1; | ||
| 317 | ret = rcupreempt_debugfs_init(); | ||
| 318 | if (ret) | ||
| 319 | kfree(rcupreempt_trace_buf); | ||
| 320 | return ret; | ||
| 321 | } | ||
| 322 | |||
| 323 | static void __exit rcupreempt_trace_cleanup(void) | ||
| 324 | { | ||
| 325 | debugfs_remove(statdir); | ||
| 326 | debugfs_remove(gpdir); | ||
| 327 | debugfs_remove(ctrsdir); | ||
| 328 | debugfs_remove(rcudir); | ||
| 329 | kfree(rcupreempt_trace_buf); | ||
| 330 | } | ||
| 331 | |||
| 332 | |||
| 333 | module_init(rcupreempt_trace_init); | ||
| 334 | module_exit(rcupreempt_trace_cleanup); | ||
diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c index 9b4a975a4b4a..b33db539a8ad 100644 --- a/kernel/rcutorture.c +++ b/kernel/rcutorture.c | |||
| @@ -257,14 +257,14 @@ struct rcu_torture_ops { | |||
| 257 | void (*init)(void); | 257 | void (*init)(void); |
| 258 | void (*cleanup)(void); | 258 | void (*cleanup)(void); |
| 259 | int (*readlock)(void); | 259 | int (*readlock)(void); |
| 260 | void (*readdelay)(struct rcu_random_state *rrsp); | 260 | void (*read_delay)(struct rcu_random_state *rrsp); |
| 261 | void (*readunlock)(int idx); | 261 | void (*readunlock)(int idx); |
| 262 | int (*completed)(void); | 262 | int (*completed)(void); |
| 263 | void (*deferredfree)(struct rcu_torture *p); | 263 | void (*deferred_free)(struct rcu_torture *p); |
| 264 | void (*sync)(void); | 264 | void (*sync)(void); |
| 265 | void (*cb_barrier)(void); | 265 | void (*cb_barrier)(void); |
| 266 | int (*stats)(char *page); | 266 | int (*stats)(char *page); |
| 267 | int irqcapable; | 267 | int irq_capable; |
| 268 | char *name; | 268 | char *name; |
| 269 | }; | 269 | }; |
| 270 | static struct rcu_torture_ops *cur_ops = NULL; | 270 | static struct rcu_torture_ops *cur_ops = NULL; |
| @@ -320,7 +320,7 @@ rcu_torture_cb(struct rcu_head *p) | |||
| 320 | rp->rtort_mbtest = 0; | 320 | rp->rtort_mbtest = 0; |
| 321 | rcu_torture_free(rp); | 321 | rcu_torture_free(rp); |
| 322 | } else | 322 | } else |
| 323 | cur_ops->deferredfree(rp); | 323 | cur_ops->deferred_free(rp); |
| 324 | } | 324 | } |
| 325 | 325 | ||
| 326 | static void rcu_torture_deferred_free(struct rcu_torture *p) | 326 | static void rcu_torture_deferred_free(struct rcu_torture *p) |
| @@ -329,18 +329,18 @@ static void rcu_torture_deferred_free(struct rcu_torture *p) | |||
| 329 | } | 329 | } |
| 330 | 330 | ||
| 331 | static struct rcu_torture_ops rcu_ops = { | 331 | static struct rcu_torture_ops rcu_ops = { |
| 332 | .init = NULL, | 332 | .init = NULL, |
| 333 | .cleanup = NULL, | 333 | .cleanup = NULL, |
| 334 | .readlock = rcu_torture_read_lock, | 334 | .readlock = rcu_torture_read_lock, |
| 335 | .readdelay = rcu_read_delay, | 335 | .read_delay = rcu_read_delay, |
| 336 | .readunlock = rcu_torture_read_unlock, | 336 | .readunlock = rcu_torture_read_unlock, |
| 337 | .completed = rcu_torture_completed, | 337 | .completed = rcu_torture_completed, |
| 338 | .deferredfree = rcu_torture_deferred_free, | 338 | .deferred_free = rcu_torture_deferred_free, |
| 339 | .sync = synchronize_rcu, | 339 | .sync = synchronize_rcu, |
| 340 | .cb_barrier = rcu_barrier, | 340 | .cb_barrier = rcu_barrier, |
| 341 | .stats = NULL, | 341 | .stats = NULL, |
| 342 | .irqcapable = 1, | 342 | .irq_capable = 1, |
| 343 | .name = "rcu" | 343 | .name = "rcu" |
| 344 | }; | 344 | }; |
| 345 | 345 | ||
| 346 | static void rcu_sync_torture_deferred_free(struct rcu_torture *p) | 346 | static void rcu_sync_torture_deferred_free(struct rcu_torture *p) |
| @@ -370,18 +370,18 @@ static void rcu_sync_torture_init(void) | |||
| 370 | } | 370 | } |
| 371 | 371 | ||
| 372 | static struct rcu_torture_ops rcu_sync_ops = { | 372 | static struct rcu_torture_ops rcu_sync_ops = { |
| 373 | .init = rcu_sync_torture_init, | 373 | .init = rcu_sync_torture_init, |
| 374 | .cleanup = NULL, | 374 | .cleanup = NULL, |
| 375 | .readlock = rcu_torture_read_lock, | 375 | .readlock = rcu_torture_read_lock, |
| 376 | .readdelay = rcu_read_delay, | 376 | .read_delay = rcu_read_delay, |
| 377 | .readunlock = rcu_torture_read_unlock, | 377 | .readunlock = rcu_torture_read_unlock, |
| 378 | .completed = rcu_torture_completed, | 378 | .completed = rcu_torture_completed, |
| 379 | .deferredfree = rcu_sync_torture_deferred_free, | 379 | .deferred_free = rcu_sync_torture_deferred_free, |
| 380 | .sync = synchronize_rcu, | 380 | .sync = synchronize_rcu, |
| 381 | .cb_barrier = NULL, | 381 | .cb_barrier = NULL, |
| 382 | .stats = NULL, | 382 | .stats = NULL, |
| 383 | .irqcapable = 1, | 383 | .irq_capable = 1, |
| 384 | .name = "rcu_sync" | 384 | .name = "rcu_sync" |
| 385 | }; | 385 | }; |
| 386 | 386 | ||
| 387 | /* | 387 | /* |
| @@ -432,33 +432,33 @@ static void rcu_bh_torture_synchronize(void) | |||
| 432 | } | 432 | } |
| 433 | 433 | ||
| 434 | static struct rcu_torture_ops rcu_bh_ops = { | 434 | static struct rcu_torture_ops rcu_bh_ops = { |
| 435 | .init = NULL, | 435 | .init = NULL, |
| 436 | .cleanup = NULL, | 436 | .cleanup = NULL, |
| 437 | .readlock = rcu_bh_torture_read_lock, | 437 | .readlock = rcu_bh_torture_read_lock, |
| 438 | .readdelay = rcu_read_delay, /* just reuse rcu's version. */ | 438 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ |
| 439 | .readunlock = rcu_bh_torture_read_unlock, | 439 | .readunlock = rcu_bh_torture_read_unlock, |
| 440 | .completed = rcu_bh_torture_completed, | 440 | .completed = rcu_bh_torture_completed, |
| 441 | .deferredfree = rcu_bh_torture_deferred_free, | 441 | .deferred_free = rcu_bh_torture_deferred_free, |
| 442 | .sync = rcu_bh_torture_synchronize, | 442 | .sync = rcu_bh_torture_synchronize, |
| 443 | .cb_barrier = rcu_barrier_bh, | 443 | .cb_barrier = rcu_barrier_bh, |
| 444 | .stats = NULL, | 444 | .stats = NULL, |
| 445 | .irqcapable = 1, | 445 | .irq_capable = 1, |
| 446 | .name = "rcu_bh" | 446 | .name = "rcu_bh" |
| 447 | }; | 447 | }; |
| 448 | 448 | ||
| 449 | static struct rcu_torture_ops rcu_bh_sync_ops = { | 449 | static struct rcu_torture_ops rcu_bh_sync_ops = { |
| 450 | .init = rcu_sync_torture_init, | 450 | .init = rcu_sync_torture_init, |
| 451 | .cleanup = NULL, | 451 | .cleanup = NULL, |
| 452 | .readlock = rcu_bh_torture_read_lock, | 452 | .readlock = rcu_bh_torture_read_lock, |
| 453 | .readdelay = rcu_read_delay, /* just reuse rcu's version. */ | 453 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ |
| 454 | .readunlock = rcu_bh_torture_read_unlock, | 454 | .readunlock = rcu_bh_torture_read_unlock, |
| 455 | .completed = rcu_bh_torture_completed, | 455 | .completed = rcu_bh_torture_completed, |
| 456 | .deferredfree = rcu_sync_torture_deferred_free, | 456 | .deferred_free = rcu_sync_torture_deferred_free, |
| 457 | .sync = rcu_bh_torture_synchronize, | 457 | .sync = rcu_bh_torture_synchronize, |
| 458 | .cb_barrier = NULL, | 458 | .cb_barrier = NULL, |
| 459 | .stats = NULL, | 459 | .stats = NULL, |
| 460 | .irqcapable = 1, | 460 | .irq_capable = 1, |
| 461 | .name = "rcu_bh_sync" | 461 | .name = "rcu_bh_sync" |
| 462 | }; | 462 | }; |
| 463 | 463 | ||
| 464 | /* | 464 | /* |
| @@ -530,17 +530,17 @@ static int srcu_torture_stats(char *page) | |||
| 530 | } | 530 | } |
| 531 | 531 | ||
| 532 | static struct rcu_torture_ops srcu_ops = { | 532 | static struct rcu_torture_ops srcu_ops = { |
| 533 | .init = srcu_torture_init, | 533 | .init = srcu_torture_init, |
| 534 | .cleanup = srcu_torture_cleanup, | 534 | .cleanup = srcu_torture_cleanup, |
| 535 | .readlock = srcu_torture_read_lock, | 535 | .readlock = srcu_torture_read_lock, |
| 536 | .readdelay = srcu_read_delay, | 536 | .read_delay = srcu_read_delay, |
| 537 | .readunlock = srcu_torture_read_unlock, | 537 | .readunlock = srcu_torture_read_unlock, |
| 538 | .completed = srcu_torture_completed, | 538 | .completed = srcu_torture_completed, |
| 539 | .deferredfree = rcu_sync_torture_deferred_free, | 539 | .deferred_free = rcu_sync_torture_deferred_free, |
| 540 | .sync = srcu_torture_synchronize, | 540 | .sync = srcu_torture_synchronize, |
| 541 | .cb_barrier = NULL, | 541 | .cb_barrier = NULL, |
| 542 | .stats = srcu_torture_stats, | 542 | .stats = srcu_torture_stats, |
| 543 | .name = "srcu" | 543 | .name = "srcu" |
| 544 | }; | 544 | }; |
| 545 | 545 | ||
| 546 | /* | 546 | /* |
| @@ -574,32 +574,49 @@ static void sched_torture_synchronize(void) | |||
| 574 | } | 574 | } |
| 575 | 575 | ||
| 576 | static struct rcu_torture_ops sched_ops = { | 576 | static struct rcu_torture_ops sched_ops = { |
| 577 | .init = rcu_sync_torture_init, | 577 | .init = rcu_sync_torture_init, |
| 578 | .cleanup = NULL, | 578 | .cleanup = NULL, |
| 579 | .readlock = sched_torture_read_lock, | 579 | .readlock = sched_torture_read_lock, |
| 580 | .readdelay = rcu_read_delay, /* just reuse rcu's version. */ | 580 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ |
| 581 | .readunlock = sched_torture_read_unlock, | 581 | .readunlock = sched_torture_read_unlock, |
| 582 | .completed = sched_torture_completed, | 582 | .completed = sched_torture_completed, |
| 583 | .deferredfree = rcu_sched_torture_deferred_free, | 583 | .deferred_free = rcu_sched_torture_deferred_free, |
| 584 | .sync = sched_torture_synchronize, | 584 | .sync = sched_torture_synchronize, |
| 585 | .cb_barrier = rcu_barrier_sched, | 585 | .cb_barrier = rcu_barrier_sched, |
| 586 | .stats = NULL, | 586 | .stats = NULL, |
| 587 | .irqcapable = 1, | 587 | .irq_capable = 1, |
| 588 | .name = "sched" | 588 | .name = "sched" |
| 589 | }; | 589 | }; |
| 590 | 590 | ||
| 591 | static struct rcu_torture_ops sched_ops_sync = { | 591 | static struct rcu_torture_ops sched_ops_sync = { |
| 592 | .init = rcu_sync_torture_init, | 592 | .init = rcu_sync_torture_init, |
| 593 | .cleanup = NULL, | 593 | .cleanup = NULL, |
| 594 | .readlock = sched_torture_read_lock, | 594 | .readlock = sched_torture_read_lock, |
| 595 | .readdelay = rcu_read_delay, /* just reuse rcu's version. */ | 595 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ |
| 596 | .readunlock = sched_torture_read_unlock, | 596 | .readunlock = sched_torture_read_unlock, |
| 597 | .completed = sched_torture_completed, | 597 | .completed = sched_torture_completed, |
| 598 | .deferredfree = rcu_sync_torture_deferred_free, | 598 | .deferred_free = rcu_sync_torture_deferred_free, |
| 599 | .sync = sched_torture_synchronize, | 599 | .sync = sched_torture_synchronize, |
| 600 | .cb_barrier = NULL, | 600 | .cb_barrier = NULL, |
| 601 | .stats = NULL, | 601 | .stats = NULL, |
| 602 | .name = "sched_sync" | 602 | .name = "sched_sync" |
| 603 | }; | ||
| 604 | |||
| 605 | extern int rcu_expedited_torture_stats(char *page); | ||
| 606 | |||
| 607 | static struct rcu_torture_ops sched_expedited_ops = { | ||
| 608 | .init = rcu_sync_torture_init, | ||
| 609 | .cleanup = NULL, | ||
| 610 | .readlock = sched_torture_read_lock, | ||
| 611 | .read_delay = rcu_read_delay, /* just reuse rcu's version. */ | ||
| 612 | .readunlock = sched_torture_read_unlock, | ||
| 613 | .completed = sched_torture_completed, | ||
| 614 | .deferred_free = rcu_sync_torture_deferred_free, | ||
| 615 | .sync = synchronize_sched_expedited, | ||
| 616 | .cb_barrier = NULL, | ||
| 617 | .stats = rcu_expedited_torture_stats, | ||
| 618 | .irq_capable = 1, | ||
| 619 | .name = "sched_expedited" | ||
| 603 | }; | 620 | }; |
| 604 | 621 | ||
| 605 | /* | 622 | /* |
| @@ -635,7 +652,7 @@ rcu_torture_writer(void *arg) | |||
| 635 | i = RCU_TORTURE_PIPE_LEN; | 652 | i = RCU_TORTURE_PIPE_LEN; |
| 636 | atomic_inc(&rcu_torture_wcount[i]); | 653 | atomic_inc(&rcu_torture_wcount[i]); |
| 637 | old_rp->rtort_pipe_count++; | 654 | old_rp->rtort_pipe_count++; |
| 638 | cur_ops->deferredfree(old_rp); | 655 | cur_ops->deferred_free(old_rp); |
| 639 | } | 656 | } |
| 640 | rcu_torture_current_version++; | 657 | rcu_torture_current_version++; |
| 641 | oldbatch = cur_ops->completed(); | 658 | oldbatch = cur_ops->completed(); |
| @@ -700,7 +717,7 @@ static void rcu_torture_timer(unsigned long unused) | |||
| 700 | if (p->rtort_mbtest == 0) | 717 | if (p->rtort_mbtest == 0) |
| 701 | atomic_inc(&n_rcu_torture_mberror); | 718 | atomic_inc(&n_rcu_torture_mberror); |
| 702 | spin_lock(&rand_lock); | 719 | spin_lock(&rand_lock); |
| 703 | cur_ops->readdelay(&rand); | 720 | cur_ops->read_delay(&rand); |
| 704 | n_rcu_torture_timers++; | 721 | n_rcu_torture_timers++; |
| 705 | spin_unlock(&rand_lock); | 722 | spin_unlock(&rand_lock); |
| 706 | preempt_disable(); | 723 | preempt_disable(); |
| @@ -738,11 +755,11 @@ rcu_torture_reader(void *arg) | |||
| 738 | 755 | ||
| 739 | VERBOSE_PRINTK_STRING("rcu_torture_reader task started"); | 756 | VERBOSE_PRINTK_STRING("rcu_torture_reader task started"); |
| 740 | set_user_nice(current, 19); | 757 | set_user_nice(current, 19); |
| 741 | if (irqreader && cur_ops->irqcapable) | 758 | if (irqreader && cur_ops->irq_capable) |
| 742 | setup_timer_on_stack(&t, rcu_torture_timer, 0); | 759 | setup_timer_on_stack(&t, rcu_torture_timer, 0); |
| 743 | 760 | ||
| 744 | do { | 761 | do { |
| 745 | if (irqreader && cur_ops->irqcapable) { | 762 | if (irqreader && cur_ops->irq_capable) { |
| 746 | if (!timer_pending(&t)) | 763 | if (!timer_pending(&t)) |
| 747 | mod_timer(&t, 1); | 764 | mod_timer(&t, 1); |
| 748 | } | 765 | } |
| @@ -757,7 +774,7 @@ rcu_torture_reader(void *arg) | |||
| 757 | } | 774 | } |
| 758 | if (p->rtort_mbtest == 0) | 775 | if (p->rtort_mbtest == 0) |
| 759 | atomic_inc(&n_rcu_torture_mberror); | 776 | atomic_inc(&n_rcu_torture_mberror); |
| 760 | cur_ops->readdelay(&rand); | 777 | cur_ops->read_delay(&rand); |
| 761 | preempt_disable(); | 778 | preempt_disable(); |
| 762 | pipe_count = p->rtort_pipe_count; | 779 | pipe_count = p->rtort_pipe_count; |
| 763 | if (pipe_count > RCU_TORTURE_PIPE_LEN) { | 780 | if (pipe_count > RCU_TORTURE_PIPE_LEN) { |
| @@ -778,7 +795,7 @@ rcu_torture_reader(void *arg) | |||
| 778 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); | 795 | } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP); |
| 779 | VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping"); | 796 | VERBOSE_PRINTK_STRING("rcu_torture_reader task stopping"); |
| 780 | rcutorture_shutdown_absorb("rcu_torture_reader"); | 797 | rcutorture_shutdown_absorb("rcu_torture_reader"); |
| 781 | if (irqreader && cur_ops->irqcapable) | 798 | if (irqreader && cur_ops->irq_capable) |
| 782 | del_timer_sync(&t); | 799 | del_timer_sync(&t); |
| 783 | while (!kthread_should_stop()) | 800 | while (!kthread_should_stop()) |
| 784 | schedule_timeout_uninterruptible(1); | 801 | schedule_timeout_uninterruptible(1); |
| @@ -1078,6 +1095,7 @@ rcu_torture_init(void) | |||
| 1078 | int firsterr = 0; | 1095 | int firsterr = 0; |
| 1079 | static struct rcu_torture_ops *torture_ops[] = | 1096 | static struct rcu_torture_ops *torture_ops[] = |
| 1080 | { &rcu_ops, &rcu_sync_ops, &rcu_bh_ops, &rcu_bh_sync_ops, | 1097 | { &rcu_ops, &rcu_sync_ops, &rcu_bh_ops, &rcu_bh_sync_ops, |
| 1098 | &sched_expedited_ops, | ||
| 1081 | &srcu_ops, &sched_ops, &sched_ops_sync, }; | 1099 | &srcu_ops, &sched_ops, &sched_ops_sync, }; |
| 1082 | 1100 | ||
| 1083 | mutex_lock(&fullstop_mutex); | 1101 | mutex_lock(&fullstop_mutex); |
diff --git a/kernel/rcutree.c b/kernel/rcutree.c index 7717b95c2027..6b11b07cfe7f 100644 --- a/kernel/rcutree.c +++ b/kernel/rcutree.c | |||
| @@ -35,6 +35,7 @@ | |||
| 35 | #include <linux/rcupdate.h> | 35 | #include <linux/rcupdate.h> |
| 36 | #include <linux/interrupt.h> | 36 | #include <linux/interrupt.h> |
| 37 | #include <linux/sched.h> | 37 | #include <linux/sched.h> |
| 38 | #include <linux/nmi.h> | ||
| 38 | #include <asm/atomic.h> | 39 | #include <asm/atomic.h> |
| 39 | #include <linux/bitops.h> | 40 | #include <linux/bitops.h> |
| 40 | #include <linux/module.h> | 41 | #include <linux/module.h> |
| @@ -46,6 +47,8 @@ | |||
| 46 | #include <linux/mutex.h> | 47 | #include <linux/mutex.h> |
| 47 | #include <linux/time.h> | 48 | #include <linux/time.h> |
| 48 | 49 | ||
| 50 | #include "rcutree.h" | ||
| 51 | |||
| 49 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | 52 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 50 | static struct lock_class_key rcu_lock_key; | 53 | static struct lock_class_key rcu_lock_key; |
| 51 | struct lockdep_map rcu_lock_map = | 54 | struct lockdep_map rcu_lock_map = |
| @@ -72,30 +75,59 @@ EXPORT_SYMBOL_GPL(rcu_lock_map); | |||
| 72 | .n_force_qs_ngp = 0, \ | 75 | .n_force_qs_ngp = 0, \ |
| 73 | } | 76 | } |
| 74 | 77 | ||
| 75 | struct rcu_state rcu_state = RCU_STATE_INITIALIZER(rcu_state); | 78 | struct rcu_state rcu_sched_state = RCU_STATE_INITIALIZER(rcu_sched_state); |
| 76 | DEFINE_PER_CPU(struct rcu_data, rcu_data); | 79 | DEFINE_PER_CPU(struct rcu_data, rcu_sched_data); |
| 77 | 80 | ||
| 78 | struct rcu_state rcu_bh_state = RCU_STATE_INITIALIZER(rcu_bh_state); | 81 | struct rcu_state rcu_bh_state = RCU_STATE_INITIALIZER(rcu_bh_state); |
| 79 | DEFINE_PER_CPU(struct rcu_data, rcu_bh_data); | 82 | DEFINE_PER_CPU(struct rcu_data, rcu_bh_data); |
| 80 | 83 | ||
| 84 | extern long rcu_batches_completed_sched(void); | ||
| 85 | static struct rcu_node *rcu_get_root(struct rcu_state *rsp); | ||
| 86 | static void cpu_quiet_msk(unsigned long mask, struct rcu_state *rsp, | ||
| 87 | struct rcu_node *rnp, unsigned long flags); | ||
| 88 | static void cpu_quiet_msk_finish(struct rcu_state *rsp, unsigned long flags); | ||
| 89 | #ifdef CONFIG_HOTPLUG_CPU | ||
| 90 | static void __rcu_offline_cpu(int cpu, struct rcu_state *rsp); | ||
| 91 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ | ||
| 92 | static void __rcu_process_callbacks(struct rcu_state *rsp, | ||
| 93 | struct rcu_data *rdp); | ||
| 94 | static void __call_rcu(struct rcu_head *head, | ||
| 95 | void (*func)(struct rcu_head *rcu), | ||
| 96 | struct rcu_state *rsp); | ||
| 97 | static int __rcu_pending(struct rcu_state *rsp, struct rcu_data *rdp); | ||
| 98 | static void __cpuinit rcu_init_percpu_data(int cpu, struct rcu_state *rsp, | ||
| 99 | int preemptable); | ||
| 100 | |||
| 101 | #include "rcutree_plugin.h" | ||
| 102 | |||
| 81 | /* | 103 | /* |
| 82 | * Increment the quiescent state counter. | 104 | * Note a quiescent state. Because we do not need to know |
| 83 | * The counter is a bit degenerated: We do not need to know | ||
| 84 | * how many quiescent states passed, just if there was at least | 105 | * how many quiescent states passed, just if there was at least |
| 85 | * one since the start of the grace period. Thus just a flag. | 106 | * one since the start of the grace period, this just sets a flag. |
| 86 | */ | 107 | */ |
| 87 | void rcu_qsctr_inc(int cpu) | 108 | void rcu_sched_qs(int cpu) |
| 88 | { | 109 | { |
| 89 | struct rcu_data *rdp = &per_cpu(rcu_data, cpu); | 110 | unsigned long flags; |
| 111 | struct rcu_data *rdp; | ||
| 112 | |||
| 113 | local_irq_save(flags); | ||
| 114 | rdp = &per_cpu(rcu_sched_data, cpu); | ||
| 90 | rdp->passed_quiesc = 1; | 115 | rdp->passed_quiesc = 1; |
| 91 | rdp->passed_quiesc_completed = rdp->completed; | 116 | rdp->passed_quiesc_completed = rdp->completed; |
| 117 | rcu_preempt_qs(cpu); | ||
| 118 | local_irq_restore(flags); | ||
| 92 | } | 119 | } |
| 93 | 120 | ||
| 94 | void rcu_bh_qsctr_inc(int cpu) | 121 | void rcu_bh_qs(int cpu) |
| 95 | { | 122 | { |
| 96 | struct rcu_data *rdp = &per_cpu(rcu_bh_data, cpu); | 123 | unsigned long flags; |
| 124 | struct rcu_data *rdp; | ||
| 125 | |||
| 126 | local_irq_save(flags); | ||
| 127 | rdp = &per_cpu(rcu_bh_data, cpu); | ||
| 97 | rdp->passed_quiesc = 1; | 128 | rdp->passed_quiesc = 1; |
| 98 | rdp->passed_quiesc_completed = rdp->completed; | 129 | rdp->passed_quiesc_completed = rdp->completed; |
| 130 | local_irq_restore(flags); | ||
| 99 | } | 131 | } |
| 100 | 132 | ||
| 101 | #ifdef CONFIG_NO_HZ | 133 | #ifdef CONFIG_NO_HZ |
| @@ -110,15 +142,16 @@ static int qhimark = 10000; /* If this many pending, ignore blimit. */ | |||
| 110 | static int qlowmark = 100; /* Once only this many pending, use blimit. */ | 142 | static int qlowmark = 100; /* Once only this many pending, use blimit. */ |
| 111 | 143 | ||
| 112 | static void force_quiescent_state(struct rcu_state *rsp, int relaxed); | 144 | static void force_quiescent_state(struct rcu_state *rsp, int relaxed); |
| 145 | static int rcu_pending(int cpu); | ||
| 113 | 146 | ||
| 114 | /* | 147 | /* |
| 115 | * Return the number of RCU batches processed thus far for debug & stats. | 148 | * Return the number of RCU-sched batches processed thus far for debug & stats. |
| 116 | */ | 149 | */ |
| 117 | long rcu_batches_completed(void) | 150 | long rcu_batches_completed_sched(void) |
| 118 | { | 151 | { |
| 119 | return rcu_state.completed; | 152 | return rcu_sched_state.completed; |
| 120 | } | 153 | } |
| 121 | EXPORT_SYMBOL_GPL(rcu_batches_completed); | 154 | EXPORT_SYMBOL_GPL(rcu_batches_completed_sched); |
| 122 | 155 | ||
| 123 | /* | 156 | /* |
| 124 | * Return the number of RCU BH batches processed thus far for debug & stats. | 157 | * Return the number of RCU BH batches processed thus far for debug & stats. |
| @@ -181,6 +214,10 @@ static int rcu_implicit_offline_qs(struct rcu_data *rdp) | |||
| 181 | return 1; | 214 | return 1; |
| 182 | } | 215 | } |
| 183 | 216 | ||
| 217 | /* If preemptable RCU, no point in sending reschedule IPI. */ | ||
| 218 | if (rdp->preemptable) | ||
| 219 | return 0; | ||
| 220 | |||
| 184 | /* The CPU is online, so send it a reschedule IPI. */ | 221 | /* The CPU is online, so send it a reschedule IPI. */ |
| 185 | if (rdp->cpu != smp_processor_id()) | 222 | if (rdp->cpu != smp_processor_id()) |
| 186 | smp_send_reschedule(rdp->cpu); | 223 | smp_send_reschedule(rdp->cpu); |
| @@ -193,7 +230,6 @@ static int rcu_implicit_offline_qs(struct rcu_data *rdp) | |||
| 193 | #endif /* #ifdef CONFIG_SMP */ | 230 | #endif /* #ifdef CONFIG_SMP */ |
| 194 | 231 | ||
| 195 | #ifdef CONFIG_NO_HZ | 232 | #ifdef CONFIG_NO_HZ |
| 196 | static DEFINE_RATELIMIT_STATE(rcu_rs, 10 * HZ, 5); | ||
| 197 | 233 | ||
| 198 | /** | 234 | /** |
| 199 | * rcu_enter_nohz - inform RCU that current CPU is entering nohz | 235 | * rcu_enter_nohz - inform RCU that current CPU is entering nohz |
| @@ -213,7 +249,7 @@ void rcu_enter_nohz(void) | |||
| 213 | rdtp = &__get_cpu_var(rcu_dynticks); | 249 | rdtp = &__get_cpu_var(rcu_dynticks); |
| 214 | rdtp->dynticks++; | 250 | rdtp->dynticks++; |
| 215 | rdtp->dynticks_nesting--; | 251 | rdtp->dynticks_nesting--; |
| 216 | WARN_ON_RATELIMIT(rdtp->dynticks & 0x1, &rcu_rs); | 252 | WARN_ON_ONCE(rdtp->dynticks & 0x1); |
| 217 | local_irq_restore(flags); | 253 | local_irq_restore(flags); |
| 218 | } | 254 | } |
| 219 | 255 | ||
| @@ -232,7 +268,7 @@ void rcu_exit_nohz(void) | |||
| 232 | rdtp = &__get_cpu_var(rcu_dynticks); | 268 | rdtp = &__get_cpu_var(rcu_dynticks); |
| 233 | rdtp->dynticks++; | 269 | rdtp->dynticks++; |
| 234 | rdtp->dynticks_nesting++; | 270 | rdtp->dynticks_nesting++; |
| 235 | WARN_ON_RATELIMIT(!(rdtp->dynticks & 0x1), &rcu_rs); | 271 | WARN_ON_ONCE(!(rdtp->dynticks & 0x1)); |
| 236 | local_irq_restore(flags); | 272 | local_irq_restore(flags); |
| 237 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ | 273 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ |
| 238 | } | 274 | } |
| @@ -251,7 +287,7 @@ void rcu_nmi_enter(void) | |||
| 251 | if (rdtp->dynticks & 0x1) | 287 | if (rdtp->dynticks & 0x1) |
| 252 | return; | 288 | return; |
| 253 | rdtp->dynticks_nmi++; | 289 | rdtp->dynticks_nmi++; |
| 254 | WARN_ON_RATELIMIT(!(rdtp->dynticks_nmi & 0x1), &rcu_rs); | 290 | WARN_ON_ONCE(!(rdtp->dynticks_nmi & 0x1)); |
| 255 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ | 291 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ |
| 256 | } | 292 | } |
| 257 | 293 | ||
| @@ -270,7 +306,7 @@ void rcu_nmi_exit(void) | |||
| 270 | return; | 306 | return; |
| 271 | smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */ | 307 | smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */ |
| 272 | rdtp->dynticks_nmi++; | 308 | rdtp->dynticks_nmi++; |
| 273 | WARN_ON_RATELIMIT(rdtp->dynticks_nmi & 0x1, &rcu_rs); | 309 | WARN_ON_ONCE(rdtp->dynticks_nmi & 0x1); |
| 274 | } | 310 | } |
| 275 | 311 | ||
| 276 | /** | 312 | /** |
| @@ -286,7 +322,7 @@ void rcu_irq_enter(void) | |||
| 286 | if (rdtp->dynticks_nesting++) | 322 | if (rdtp->dynticks_nesting++) |
| 287 | return; | 323 | return; |
| 288 | rdtp->dynticks++; | 324 | rdtp->dynticks++; |
| 289 | WARN_ON_RATELIMIT(!(rdtp->dynticks & 0x1), &rcu_rs); | 325 | WARN_ON_ONCE(!(rdtp->dynticks & 0x1)); |
| 290 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ | 326 | smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ |
| 291 | } | 327 | } |
| 292 | 328 | ||
| @@ -305,10 +341,10 @@ void rcu_irq_exit(void) | |||
| 305 | return; | 341 | return; |
| 306 | smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */ | 342 | smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */ |
| 307 | rdtp->dynticks++; | 343 | rdtp->dynticks++; |
| 308 | WARN_ON_RATELIMIT(rdtp->dynticks & 0x1, &rcu_rs); | 344 | WARN_ON_ONCE(rdtp->dynticks & 0x1); |
| 309 | 345 | ||
| 310 | /* If the interrupt queued a callback, get out of dyntick mode. */ | 346 | /* If the interrupt queued a callback, get out of dyntick mode. */ |
| 311 | if (__get_cpu_var(rcu_data).nxtlist || | 347 | if (__get_cpu_var(rcu_sched_data).nxtlist || |
| 312 | __get_cpu_var(rcu_bh_data).nxtlist) | 348 | __get_cpu_var(rcu_bh_data).nxtlist) |
| 313 | set_need_resched(); | 349 | set_need_resched(); |
| 314 | } | 350 | } |
| @@ -461,6 +497,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp) | |||
| 461 | 497 | ||
| 462 | printk(KERN_ERR "INFO: RCU detected CPU stalls:"); | 498 | printk(KERN_ERR "INFO: RCU detected CPU stalls:"); |
| 463 | for (; rnp_cur < rnp_end; rnp_cur++) { | 499 | for (; rnp_cur < rnp_end; rnp_cur++) { |
| 500 | rcu_print_task_stall(rnp); | ||
| 464 | if (rnp_cur->qsmask == 0) | 501 | if (rnp_cur->qsmask == 0) |
| 465 | continue; | 502 | continue; |
| 466 | for (cpu = 0; cpu <= rnp_cur->grphi - rnp_cur->grplo; cpu++) | 503 | for (cpu = 0; cpu <= rnp_cur->grphi - rnp_cur->grplo; cpu++) |
| @@ -469,6 +506,8 @@ static void print_other_cpu_stall(struct rcu_state *rsp) | |||
| 469 | } | 506 | } |
| 470 | printk(" (detected by %d, t=%ld jiffies)\n", | 507 | printk(" (detected by %d, t=%ld jiffies)\n", |
| 471 | smp_processor_id(), (long)(jiffies - rsp->gp_start)); | 508 | smp_processor_id(), (long)(jiffies - rsp->gp_start)); |
| 509 | trigger_all_cpu_backtrace(); | ||
| 510 | |||
| 472 | force_quiescent_state(rsp, 0); /* Kick them all. */ | 511 | force_quiescent_state(rsp, 0); /* Kick them all. */ |
| 473 | } | 512 | } |
| 474 | 513 | ||
| @@ -479,12 +518,14 @@ static void print_cpu_stall(struct rcu_state *rsp) | |||
| 479 | 518 | ||
| 480 | printk(KERN_ERR "INFO: RCU detected CPU %d stall (t=%lu jiffies)\n", | 519 | printk(KERN_ERR "INFO: RCU detected CPU %d stall (t=%lu jiffies)\n", |
| 481 | smp_processor_id(), jiffies - rsp->gp_start); | 520 | smp_processor_id(), jiffies - rsp->gp_start); |
| 482 | dump_stack(); | 521 | trigger_all_cpu_backtrace(); |
| 522 | |||
| 483 | spin_lock_irqsave(&rnp->lock, flags); | 523 | spin_lock_irqsave(&rnp->lock, flags); |
| 484 | if ((long)(jiffies - rsp->jiffies_stall) >= 0) | 524 | if ((long)(jiffies - rsp->jiffies_stall) >= 0) |
| 485 | rsp->jiffies_stall = | 525 | rsp->jiffies_stall = |
| 486 | jiffies + RCU_SECONDS_TILL_STALL_RECHECK; | 526 | jiffies + RCU_SECONDS_TILL_STALL_RECHECK; |
| 487 | spin_unlock_irqrestore(&rnp->lock, flags); | 527 | spin_unlock_irqrestore(&rnp->lock, flags); |
| 528 | |||
| 488 | set_need_resched(); /* kick ourselves to get things going. */ | 529 | set_need_resched(); /* kick ourselves to get things going. */ |
| 489 | } | 530 | } |
| 490 | 531 | ||
| @@ -674,6 +715,19 @@ rcu_process_gp_end(struct rcu_state *rsp, struct rcu_data *rdp) | |||
| 674 | } | 715 | } |
| 675 | 716 | ||
| 676 | /* | 717 | /* |
| 718 | * Clean up after the prior grace period and let rcu_start_gp() start up | ||
| 719 | * the next grace period if one is needed. Note that the caller must | ||
| 720 | * hold rnp->lock, as required by rcu_start_gp(), which will release it. | ||
| 721 | */ | ||
| 722 | static void cpu_quiet_msk_finish(struct rcu_state *rsp, unsigned long flags) | ||
| 723 | __releases(rnp->lock) | ||
| 724 | { | ||
| 725 | rsp->completed = rsp->gpnum; | ||
| 726 | rcu_process_gp_end(rsp, rsp->rda[smp_processor_id()]); | ||
| 727 | rcu_start_gp(rsp, flags); /* releases root node's rnp->lock. */ | ||
| 728 | } | ||
| 729 | |||
| 730 | /* | ||
| 677 | * Similar to cpu_quiet(), for which it is a helper function. Allows | 731 | * Similar to cpu_quiet(), for which it is a helper function. Allows |
| 678 | * a group of CPUs to be quieted at one go, though all the CPUs in the | 732 | * a group of CPUs to be quieted at one go, though all the CPUs in the |
| 679 | * group must be represented by the same leaf rcu_node structure. | 733 | * group must be represented by the same leaf rcu_node structure. |
| @@ -694,7 +748,7 @@ cpu_quiet_msk(unsigned long mask, struct rcu_state *rsp, struct rcu_node *rnp, | |||
| 694 | return; | 748 | return; |
| 695 | } | 749 | } |
| 696 | rnp->qsmask &= ~mask; | 750 | rnp->qsmask &= ~mask; |
| 697 | if (rnp->qsmask != 0) { | 751 | if (rnp->qsmask != 0 || rcu_preempted_readers(rnp)) { |
| 698 | 752 | ||
| 699 | /* Other bits still set at this level, so done. */ | 753 | /* Other bits still set at this level, so done. */ |
| 700 | spin_unlock_irqrestore(&rnp->lock, flags); | 754 | spin_unlock_irqrestore(&rnp->lock, flags); |
| @@ -714,14 +768,10 @@ cpu_quiet_msk(unsigned long mask, struct rcu_state *rsp, struct rcu_node *rnp, | |||
| 714 | 768 | ||
| 715 | /* | 769 | /* |
| 716 | * Get here if we are the last CPU to pass through a quiescent | 770 | * Get here if we are the last CPU to pass through a quiescent |
| 717 | * state for this grace period. Clean up and let rcu_start_gp() | 771 | * state for this grace period. Invoke cpu_quiet_msk_finish() |
| 718 | * start up the next grace period if one is needed. Note that | 772 | * to clean up and start the next grace period if one is needed. |
| 719 | * we still hold rnp->lock, as required by rcu_start_gp(), which | ||
| 720 | * will release it. | ||
| 721 | */ | 773 | */ |
| 722 | rsp->completed = rsp->gpnum; | 774 | cpu_quiet_msk_finish(rsp, flags); /* releases rnp->lock. */ |
| 723 | rcu_process_gp_end(rsp, rsp->rda[smp_processor_id()]); | ||
| 724 | rcu_start_gp(rsp, flags); /* releases rnp->lock. */ | ||
| 725 | } | 775 | } |
| 726 | 776 | ||
| 727 | /* | 777 | /* |
| @@ -828,11 +878,12 @@ static void __rcu_offline_cpu(int cpu, struct rcu_state *rsp) | |||
| 828 | spin_lock(&rnp->lock); /* irqs already disabled. */ | 878 | spin_lock(&rnp->lock); /* irqs already disabled. */ |
| 829 | rnp->qsmaskinit &= ~mask; | 879 | rnp->qsmaskinit &= ~mask; |
| 830 | if (rnp->qsmaskinit != 0) { | 880 | if (rnp->qsmaskinit != 0) { |
| 831 | spin_unlock(&rnp->lock); /* irqs already disabled. */ | 881 | spin_unlock(&rnp->lock); /* irqs remain disabled. */ |
| 832 | break; | 882 | break; |
| 833 | } | 883 | } |
| 884 | rcu_preempt_offline_tasks(rsp, rnp); | ||
| 834 | mask = rnp->grpmask; | 885 | mask = rnp->grpmask; |
| 835 | spin_unlock(&rnp->lock); /* irqs already disabled. */ | 886 | spin_unlock(&rnp->lock); /* irqs remain disabled. */ |
| 836 | rnp = rnp->parent; | 887 | rnp = rnp->parent; |
| 837 | } while (rnp != NULL); | 888 | } while (rnp != NULL); |
| 838 | lastcomp = rsp->completed; | 889 | lastcomp = rsp->completed; |
| @@ -845,7 +896,7 @@ static void __rcu_offline_cpu(int cpu, struct rcu_state *rsp) | |||
| 845 | /* | 896 | /* |
| 846 | * Move callbacks from the outgoing CPU to the running CPU. | 897 | * Move callbacks from the outgoing CPU to the running CPU. |
| 847 | * Note that the outgoing CPU is now quiscent, so it is now | 898 | * Note that the outgoing CPU is now quiscent, so it is now |
| 848 | * (uncharacteristically) safe to access it rcu_data structure. | 899 | * (uncharacteristically) safe to access its rcu_data structure. |
| 849 | * Note also that we must carefully retain the order of the | 900 | * Note also that we must carefully retain the order of the |
| 850 | * outgoing CPU's callbacks in order for rcu_barrier() to work | 901 | * outgoing CPU's callbacks in order for rcu_barrier() to work |
| 851 | * correctly. Finally, note that we start all the callbacks | 902 | * correctly. Finally, note that we start all the callbacks |
| @@ -876,8 +927,9 @@ static void __rcu_offline_cpu(int cpu, struct rcu_state *rsp) | |||
| 876 | */ | 927 | */ |
| 877 | static void rcu_offline_cpu(int cpu) | 928 | static void rcu_offline_cpu(int cpu) |
| 878 | { | 929 | { |
| 879 | __rcu_offline_cpu(cpu, &rcu_state); | 930 | __rcu_offline_cpu(cpu, &rcu_sched_state); |
| 880 | __rcu_offline_cpu(cpu, &rcu_bh_state); | 931 | __rcu_offline_cpu(cpu, &rcu_bh_state); |
| 932 | rcu_preempt_offline_cpu(cpu); | ||
| 881 | } | 933 | } |
| 882 | 934 | ||
| 883 | #else /* #ifdef CONFIG_HOTPLUG_CPU */ | 935 | #else /* #ifdef CONFIG_HOTPLUG_CPU */ |
| @@ -963,6 +1015,8 @@ static void rcu_do_batch(struct rcu_data *rdp) | |||
| 963 | */ | 1015 | */ |
| 964 | void rcu_check_callbacks(int cpu, int user) | 1016 | void rcu_check_callbacks(int cpu, int user) |
| 965 | { | 1017 | { |
| 1018 | if (!rcu_pending(cpu)) | ||
| 1019 | return; /* if nothing for RCU to do. */ | ||
| 966 | if (user || | 1020 | if (user || |
| 967 | (idle_cpu(cpu) && rcu_scheduler_active && | 1021 | (idle_cpu(cpu) && rcu_scheduler_active && |
| 968 | !in_softirq() && hardirq_count() <= (1 << HARDIRQ_SHIFT))) { | 1022 | !in_softirq() && hardirq_count() <= (1 << HARDIRQ_SHIFT))) { |
| @@ -971,17 +1025,16 @@ void rcu_check_callbacks(int cpu, int user) | |||
| 971 | * Get here if this CPU took its interrupt from user | 1025 | * Get here if this CPU took its interrupt from user |
| 972 | * mode or from the idle loop, and if this is not a | 1026 | * mode or from the idle loop, and if this is not a |
| 973 | * nested interrupt. In this case, the CPU is in | 1027 | * nested interrupt. In this case, the CPU is in |
| 974 | * a quiescent state, so count it. | 1028 | * a quiescent state, so note it. |
| 975 | * | 1029 | * |
| 976 | * No memory barrier is required here because both | 1030 | * No memory barrier is required here because both |
| 977 | * rcu_qsctr_inc() and rcu_bh_qsctr_inc() reference | 1031 | * rcu_sched_qs() and rcu_bh_qs() reference only CPU-local |
| 978 | * only CPU-local variables that other CPUs neither | 1032 | * variables that other CPUs neither access nor modify, |
| 979 | * access nor modify, at least not while the corresponding | 1033 | * at least not while the corresponding CPU is online. |
| 980 | * CPU is online. | ||
| 981 | */ | 1034 | */ |
| 982 | 1035 | ||
| 983 | rcu_qsctr_inc(cpu); | 1036 | rcu_sched_qs(cpu); |
| 984 | rcu_bh_qsctr_inc(cpu); | 1037 | rcu_bh_qs(cpu); |
| 985 | 1038 | ||
| 986 | } else if (!in_softirq()) { | 1039 | } else if (!in_softirq()) { |
| 987 | 1040 | ||
| @@ -989,11 +1042,12 @@ void rcu_check_callbacks(int cpu, int user) | |||
| 989 | * Get here if this CPU did not take its interrupt from | 1042 | * Get here if this CPU did not take its interrupt from |
| 990 | * softirq, in other words, if it is not interrupting | 1043 | * softirq, in other words, if it is not interrupting |
| 991 | * a rcu_bh read-side critical section. This is an _bh | 1044 | * a rcu_bh read-side critical section. This is an _bh |
| 992 | * critical section, so count it. | 1045 | * critical section, so note it. |
| 993 | */ | 1046 | */ |
| 994 | 1047 | ||
| 995 | rcu_bh_qsctr_inc(cpu); | 1048 | rcu_bh_qs(cpu); |
| 996 | } | 1049 | } |
| 1050 | rcu_preempt_check_callbacks(cpu); | ||
| 997 | raise_softirq(RCU_SOFTIRQ); | 1051 | raise_softirq(RCU_SOFTIRQ); |
| 998 | } | 1052 | } |
| 999 | 1053 | ||
| @@ -1132,6 +1186,8 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp) | |||
| 1132 | { | 1186 | { |
| 1133 | unsigned long flags; | 1187 | unsigned long flags; |
| 1134 | 1188 | ||
| 1189 | WARN_ON_ONCE(rdp->beenonline == 0); | ||
| 1190 | |||
| 1135 | /* | 1191 | /* |
| 1136 | * If an RCU GP has gone long enough, go check for dyntick | 1192 | * If an RCU GP has gone long enough, go check for dyntick |
| 1137 | * idle CPUs and, if needed, send resched IPIs. | 1193 | * idle CPUs and, if needed, send resched IPIs. |
| @@ -1170,8 +1226,10 @@ static void rcu_process_callbacks(struct softirq_action *unused) | |||
| 1170 | */ | 1226 | */ |
| 1171 | smp_mb(); /* See above block comment. */ | 1227 | smp_mb(); /* See above block comment. */ |
| 1172 | 1228 | ||
| 1173 | __rcu_process_callbacks(&rcu_state, &__get_cpu_var(rcu_data)); | 1229 | __rcu_process_callbacks(&rcu_sched_state, |
| 1230 | &__get_cpu_var(rcu_sched_data)); | ||
| 1174 | __rcu_process_callbacks(&rcu_bh_state, &__get_cpu_var(rcu_bh_data)); | 1231 | __rcu_process_callbacks(&rcu_bh_state, &__get_cpu_var(rcu_bh_data)); |
| 1232 | rcu_preempt_process_callbacks(); | ||
| 1175 | 1233 | ||
| 1176 | /* | 1234 | /* |
| 1177 | * Memory references from any later RCU read-side critical sections | 1235 | * Memory references from any later RCU read-side critical sections |
| @@ -1227,13 +1285,13 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu), | |||
| 1227 | } | 1285 | } |
| 1228 | 1286 | ||
| 1229 | /* | 1287 | /* |
| 1230 | * Queue an RCU callback for invocation after a grace period. | 1288 | * Queue an RCU-sched callback for invocation after a grace period. |
| 1231 | */ | 1289 | */ |
| 1232 | void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) | 1290 | void call_rcu_sched(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) |
| 1233 | { | 1291 | { |
| 1234 | __call_rcu(head, func, &rcu_state); | 1292 | __call_rcu(head, func, &rcu_sched_state); |
| 1235 | } | 1293 | } |
| 1236 | EXPORT_SYMBOL_GPL(call_rcu); | 1294 | EXPORT_SYMBOL_GPL(call_rcu_sched); |
| 1237 | 1295 | ||
| 1238 | /* | 1296 | /* |
| 1239 | * Queue an RCU for invocation after a quicker grace period. | 1297 | * Queue an RCU for invocation after a quicker grace period. |
| @@ -1305,10 +1363,11 @@ static int __rcu_pending(struct rcu_state *rsp, struct rcu_data *rdp) | |||
| 1305 | * by the current CPU, returning 1 if so. This function is part of the | 1363 | * by the current CPU, returning 1 if so. This function is part of the |
| 1306 | * RCU implementation; it is -not- an exported member of the RCU API. | 1364 | * RCU implementation; it is -not- an exported member of the RCU API. |
| 1307 | */ | 1365 | */ |
| 1308 | int rcu_pending(int cpu) | 1366 | static int rcu_pending(int cpu) |
| 1309 | { | 1367 | { |
| 1310 | return __rcu_pending(&rcu_state, &per_cpu(rcu_data, cpu)) || | 1368 | return __rcu_pending(&rcu_sched_state, &per_cpu(rcu_sched_data, cpu)) || |
| 1311 | __rcu_pending(&rcu_bh_state, &per_cpu(rcu_bh_data, cpu)); | 1369 | __rcu_pending(&rcu_bh_state, &per_cpu(rcu_bh_data, cpu)) || |
| 1370 | rcu_preempt_pending(cpu); | ||
| 1312 | } | 1371 | } |
| 1313 | 1372 | ||
| 1314 | /* | 1373 | /* |
| @@ -1320,27 +1379,46 @@ int rcu_pending(int cpu) | |||
| 1320 | int rcu_needs_cpu(int cpu) | 1379 | int rcu_needs_cpu(int cpu) |
| 1321 | { | 1380 | { |
| 1322 | /* RCU callbacks either ready or pending? */ | 1381 | /* RCU callbacks either ready or pending? */ |
| 1323 | return per_cpu(rcu_data, cpu).nxtlist || | 1382 | return per_cpu(rcu_sched_data, cpu).nxtlist || |
| 1324 | per_cpu(rcu_bh_data, cpu).nxtlist; | 1383 | per_cpu(rcu_bh_data, cpu).nxtlist || |
| 1384 | rcu_preempt_needs_cpu(cpu); | ||
| 1325 | } | 1385 | } |
| 1326 | 1386 | ||
| 1327 | /* | 1387 | /* |
| 1328 | * Initialize a CPU's per-CPU RCU data. We take this "scorched earth" | 1388 | * Do boot-time initialization of a CPU's per-CPU RCU data. |
| 1329 | * approach so that we don't have to worry about how long the CPU has | ||
| 1330 | * been gone, or whether it ever was online previously. We do trust the | ||
| 1331 | * ->mynode field, as it is constant for a given struct rcu_data and | ||
| 1332 | * initialized during early boot. | ||
| 1333 | * | ||
| 1334 | * Note that only one online or offline event can be happening at a given | ||
| 1335 | * time. Note also that we can accept some slop in the rsp->completed | ||
| 1336 | * access due to the fact that this CPU cannot possibly have any RCU | ||
| 1337 | * callbacks in flight yet. | ||
| 1338 | */ | 1389 | */ |
| 1339 | static void __cpuinit | 1390 | static void __init |
| 1340 | rcu_init_percpu_data(int cpu, struct rcu_state *rsp) | 1391 | rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp) |
| 1341 | { | 1392 | { |
| 1342 | unsigned long flags; | 1393 | unsigned long flags; |
| 1343 | int i; | 1394 | int i; |
| 1395 | struct rcu_data *rdp = rsp->rda[cpu]; | ||
| 1396 | struct rcu_node *rnp = rcu_get_root(rsp); | ||
| 1397 | |||
| 1398 | /* Set up local state, ensuring consistent view of global state. */ | ||
| 1399 | spin_lock_irqsave(&rnp->lock, flags); | ||
| 1400 | rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo); | ||
| 1401 | rdp->nxtlist = NULL; | ||
| 1402 | for (i = 0; i < RCU_NEXT_SIZE; i++) | ||
| 1403 | rdp->nxttail[i] = &rdp->nxtlist; | ||
| 1404 | rdp->qlen = 0; | ||
| 1405 | #ifdef CONFIG_NO_HZ | ||
| 1406 | rdp->dynticks = &per_cpu(rcu_dynticks, cpu); | ||
| 1407 | #endif /* #ifdef CONFIG_NO_HZ */ | ||
| 1408 | rdp->cpu = cpu; | ||
| 1409 | spin_unlock_irqrestore(&rnp->lock, flags); | ||
| 1410 | } | ||
| 1411 | |||
| 1412 | /* | ||
| 1413 | * Initialize a CPU's per-CPU RCU data. Note that only one online or | ||
| 1414 | * offline event can be happening at a given time. Note also that we | ||
| 1415 | * can accept some slop in the rsp->completed access due to the fact | ||
| 1416 | * that this CPU cannot possibly have any RCU callbacks in flight yet. | ||
| 1417 | */ | ||
| 1418 | static void __cpuinit | ||
| 1419 | rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptable) | ||
| 1420 | { | ||
| 1421 | unsigned long flags; | ||
| 1344 | long lastcomp; | 1422 | long lastcomp; |
| 1345 | unsigned long mask; | 1423 | unsigned long mask; |
| 1346 | struct rcu_data *rdp = rsp->rda[cpu]; | 1424 | struct rcu_data *rdp = rsp->rda[cpu]; |
| @@ -1354,17 +1432,9 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp) | |||
| 1354 | rdp->passed_quiesc = 0; /* We could be racing with new GP, */ | 1432 | rdp->passed_quiesc = 0; /* We could be racing with new GP, */ |
| 1355 | rdp->qs_pending = 1; /* so set up to respond to current GP. */ | 1433 | rdp->qs_pending = 1; /* so set up to respond to current GP. */ |
| 1356 | rdp->beenonline = 1; /* We have now been online. */ | 1434 | rdp->beenonline = 1; /* We have now been online. */ |
| 1435 | rdp->preemptable = preemptable; | ||
| 1357 | rdp->passed_quiesc_completed = lastcomp - 1; | 1436 | rdp->passed_quiesc_completed = lastcomp - 1; |
| 1358 | rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo); | ||
| 1359 | rdp->nxtlist = NULL; | ||
| 1360 | for (i = 0; i < RCU_NEXT_SIZE; i++) | ||
| 1361 | rdp->nxttail[i] = &rdp->nxtlist; | ||
| 1362 | rdp->qlen = 0; | ||
| 1363 | rdp->blimit = blimit; | 1437 | rdp->blimit = blimit; |
| 1364 | #ifdef CONFIG_NO_HZ | ||
| 1365 | rdp->dynticks = &per_cpu(rcu_dynticks, cpu); | ||
| 1366 | #endif /* #ifdef CONFIG_NO_HZ */ | ||
| 1367 | rdp->cpu = cpu; | ||
| 1368 | spin_unlock(&rnp->lock); /* irqs remain disabled. */ | 1438 | spin_unlock(&rnp->lock); /* irqs remain disabled. */ |
| 1369 | 1439 | ||
| 1370 | /* | 1440 | /* |
| @@ -1405,16 +1475,16 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp) | |||
| 1405 | 1475 | ||
| 1406 | static void __cpuinit rcu_online_cpu(int cpu) | 1476 | static void __cpuinit rcu_online_cpu(int cpu) |
| 1407 | { | 1477 | { |
| 1408 | rcu_init_percpu_data(cpu, &rcu_state); | 1478 | rcu_init_percpu_data(cpu, &rcu_sched_state, 0); |
| 1409 | rcu_init_percpu_data(cpu, &rcu_bh_state); | 1479 | rcu_init_percpu_data(cpu, &rcu_bh_state, 0); |
| 1410 | open_softirq(RCU_SOFTIRQ, rcu_process_callbacks); | 1480 | rcu_preempt_init_percpu_data(cpu); |
| 1411 | } | 1481 | } |
| 1412 | 1482 | ||
| 1413 | /* | 1483 | /* |
| 1414 | * Handle CPU online/offline notifcation events. | 1484 | * Handle CPU online/offline notification events. |
| 1415 | */ | 1485 | */ |
| 1416 | static int __cpuinit rcu_cpu_notify(struct notifier_block *self, | 1486 | int __cpuinit rcu_cpu_notify(struct notifier_block *self, |
| 1417 | unsigned long action, void *hcpu) | 1487 | unsigned long action, void *hcpu) |
| 1418 | { | 1488 | { |
| 1419 | long cpu = (long)hcpu; | 1489 | long cpu = (long)hcpu; |
| 1420 | 1490 | ||
| @@ -1486,6 +1556,7 @@ static void __init rcu_init_one(struct rcu_state *rsp) | |||
| 1486 | rnp = rsp->level[i]; | 1556 | rnp = rsp->level[i]; |
| 1487 | for (j = 0; j < rsp->levelcnt[i]; j++, rnp++) { | 1557 | for (j = 0; j < rsp->levelcnt[i]; j++, rnp++) { |
| 1488 | spin_lock_init(&rnp->lock); | 1558 | spin_lock_init(&rnp->lock); |
| 1559 | rnp->gpnum = 0; | ||
| 1489 | rnp->qsmask = 0; | 1560 | rnp->qsmask = 0; |
| 1490 | rnp->qsmaskinit = 0; | 1561 | rnp->qsmaskinit = 0; |
| 1491 | rnp->grplo = j * cpustride; | 1562 | rnp->grplo = j * cpustride; |
| @@ -1503,16 +1574,20 @@ static void __init rcu_init_one(struct rcu_state *rsp) | |||
| 1503 | j / rsp->levelspread[i - 1]; | 1574 | j / rsp->levelspread[i - 1]; |
| 1504 | } | 1575 | } |
| 1505 | rnp->level = i; | 1576 | rnp->level = i; |
| 1577 | INIT_LIST_HEAD(&rnp->blocked_tasks[0]); | ||
| 1578 | INIT_LIST_HEAD(&rnp->blocked_tasks[1]); | ||
| 1506 | } | 1579 | } |
| 1507 | } | 1580 | } |
| 1508 | } | 1581 | } |
| 1509 | 1582 | ||
| 1510 | /* | 1583 | /* |
| 1511 | * Helper macro for __rcu_init(). To be used nowhere else! | 1584 | * Helper macro for __rcu_init() and __rcu_init_preempt(). To be used |
| 1512 | * Assigns leaf node pointers into each CPU's rcu_data structure. | 1585 | * nowhere else! Assigns leaf node pointers into each CPU's rcu_data |
| 1586 | * structure. | ||
| 1513 | */ | 1587 | */ |
| 1514 | #define RCU_DATA_PTR_INIT(rsp, rcu_data) \ | 1588 | #define RCU_INIT_FLAVOR(rsp, rcu_data) \ |
| 1515 | do { \ | 1589 | do { \ |
| 1590 | rcu_init_one(rsp); \ | ||
| 1516 | rnp = (rsp)->level[NUM_RCU_LVLS - 1]; \ | 1591 | rnp = (rsp)->level[NUM_RCU_LVLS - 1]; \ |
| 1517 | j = 0; \ | 1592 | j = 0; \ |
| 1518 | for_each_possible_cpu(i) { \ | 1593 | for_each_possible_cpu(i) { \ |
| @@ -1520,32 +1595,43 @@ do { \ | |||
| 1520 | j++; \ | 1595 | j++; \ |
| 1521 | per_cpu(rcu_data, i).mynode = &rnp[j]; \ | 1596 | per_cpu(rcu_data, i).mynode = &rnp[j]; \ |
| 1522 | (rsp)->rda[i] = &per_cpu(rcu_data, i); \ | 1597 | (rsp)->rda[i] = &per_cpu(rcu_data, i); \ |
| 1598 | rcu_boot_init_percpu_data(i, rsp); \ | ||
| 1523 | } \ | 1599 | } \ |
| 1524 | } while (0) | 1600 | } while (0) |
| 1525 | 1601 | ||
| 1526 | static struct notifier_block __cpuinitdata rcu_nb = { | 1602 | #ifdef CONFIG_TREE_PREEMPT_RCU |
| 1527 | .notifier_call = rcu_cpu_notify, | 1603 | |
| 1528 | }; | 1604 | void __init __rcu_init_preempt(void) |
| 1605 | { | ||
| 1606 | int i; /* All used by RCU_INIT_FLAVOR(). */ | ||
| 1607 | int j; | ||
| 1608 | struct rcu_node *rnp; | ||
| 1609 | |||
| 1610 | RCU_INIT_FLAVOR(&rcu_preempt_state, rcu_preempt_data); | ||
| 1611 | } | ||
| 1612 | |||
| 1613 | #else /* #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
| 1614 | |||
| 1615 | void __init __rcu_init_preempt(void) | ||
| 1616 | { | ||
| 1617 | } | ||
| 1618 | |||
| 1619 | #endif /* #else #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
| 1529 | 1620 | ||
| 1530 | void __init __rcu_init(void) | 1621 | void __init __rcu_init(void) |
| 1531 | { | 1622 | { |
| 1532 | int i; /* All used by RCU_DATA_PTR_INIT(). */ | 1623 | int i; /* All used by RCU_INIT_FLAVOR(). */ |
| 1533 | int j; | 1624 | int j; |
| 1534 | struct rcu_node *rnp; | 1625 | struct rcu_node *rnp; |
| 1535 | 1626 | ||
| 1536 | printk(KERN_INFO "Hierarchical RCU implementation.\n"); | 1627 | rcu_bootup_announce(); |
| 1537 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | 1628 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR |
| 1538 | printk(KERN_INFO "RCU-based detection of stalled CPUs is enabled.\n"); | 1629 | printk(KERN_INFO "RCU-based detection of stalled CPUs is enabled.\n"); |
| 1539 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | 1630 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ |
| 1540 | rcu_init_one(&rcu_state); | 1631 | RCU_INIT_FLAVOR(&rcu_sched_state, rcu_sched_data); |
| 1541 | RCU_DATA_PTR_INIT(&rcu_state, rcu_data); | 1632 | RCU_INIT_FLAVOR(&rcu_bh_state, rcu_bh_data); |
| 1542 | rcu_init_one(&rcu_bh_state); | 1633 | __rcu_init_preempt(); |
| 1543 | RCU_DATA_PTR_INIT(&rcu_bh_state, rcu_bh_data); | 1634 | open_softirq(RCU_SOFTIRQ, rcu_process_callbacks); |
| 1544 | |||
| 1545 | for_each_online_cpu(i) | ||
| 1546 | rcu_cpu_notify(&rcu_nb, CPU_UP_PREPARE, (void *)(long)i); | ||
| 1547 | /* Register notifier for non-boot CPUs */ | ||
| 1548 | register_cpu_notifier(&rcu_nb); | ||
| 1549 | } | 1635 | } |
| 1550 | 1636 | ||
| 1551 | module_param(blimit, int, 0); | 1637 | module_param(blimit, int, 0); |
diff --git a/kernel/rcutree.h b/kernel/rcutree.h index 5e872bbf07f5..bf8a6f9f134d 100644 --- a/kernel/rcutree.h +++ b/kernel/rcutree.h | |||
| @@ -1,10 +1,259 @@ | |||
| 1 | /* | ||
| 2 | * Read-Copy Update mechanism for mutual exclusion (tree-based version) | ||
| 3 | * Internal non-public definitions. | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation; either version 2 of the License, or | ||
| 8 | * (at your option) any later version. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with this program; if not, write to the Free Software | ||
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 18 | * | ||
| 19 | * Copyright IBM Corporation, 2008 | ||
| 20 | * | ||
| 21 | * Author: Ingo Molnar <mingo@elte.hu> | ||
| 22 | * Paul E. McKenney <paulmck@linux.vnet.ibm.com> | ||
| 23 | */ | ||
| 24 | |||
| 25 | #include <linux/cache.h> | ||
| 26 | #include <linux/spinlock.h> | ||
| 27 | #include <linux/threads.h> | ||
| 28 | #include <linux/cpumask.h> | ||
| 29 | #include <linux/seqlock.h> | ||
| 30 | |||
| 31 | /* | ||
| 32 | * Define shape of hierarchy based on NR_CPUS and CONFIG_RCU_FANOUT. | ||
| 33 | * In theory, it should be possible to add more levels straightforwardly. | ||
| 34 | * In practice, this has not been tested, so there is probably some | ||
| 35 | * bug somewhere. | ||
| 36 | */ | ||
| 37 | #define MAX_RCU_LVLS 3 | ||
| 38 | #define RCU_FANOUT (CONFIG_RCU_FANOUT) | ||
| 39 | #define RCU_FANOUT_SQ (RCU_FANOUT * RCU_FANOUT) | ||
| 40 | #define RCU_FANOUT_CUBE (RCU_FANOUT_SQ * RCU_FANOUT) | ||
| 41 | |||
| 42 | #if NR_CPUS <= RCU_FANOUT | ||
| 43 | # define NUM_RCU_LVLS 1 | ||
| 44 | # define NUM_RCU_LVL_0 1 | ||
| 45 | # define NUM_RCU_LVL_1 (NR_CPUS) | ||
| 46 | # define NUM_RCU_LVL_2 0 | ||
| 47 | # define NUM_RCU_LVL_3 0 | ||
| 48 | #elif NR_CPUS <= RCU_FANOUT_SQ | ||
| 49 | # define NUM_RCU_LVLS 2 | ||
| 50 | # define NUM_RCU_LVL_0 1 | ||
| 51 | # define NUM_RCU_LVL_1 (((NR_CPUS) + RCU_FANOUT - 1) / RCU_FANOUT) | ||
| 52 | # define NUM_RCU_LVL_2 (NR_CPUS) | ||
| 53 | # define NUM_RCU_LVL_3 0 | ||
| 54 | #elif NR_CPUS <= RCU_FANOUT_CUBE | ||
| 55 | # define NUM_RCU_LVLS 3 | ||
| 56 | # define NUM_RCU_LVL_0 1 | ||
| 57 | # define NUM_RCU_LVL_1 (((NR_CPUS) + RCU_FANOUT_SQ - 1) / RCU_FANOUT_SQ) | ||
| 58 | # define NUM_RCU_LVL_2 (((NR_CPUS) + (RCU_FANOUT) - 1) / (RCU_FANOUT)) | ||
| 59 | # define NUM_RCU_LVL_3 NR_CPUS | ||
| 60 | #else | ||
| 61 | # error "CONFIG_RCU_FANOUT insufficient for NR_CPUS" | ||
| 62 | #endif /* #if (NR_CPUS) <= RCU_FANOUT */ | ||
| 63 | |||
| 64 | #define RCU_SUM (NUM_RCU_LVL_0 + NUM_RCU_LVL_1 + NUM_RCU_LVL_2 + NUM_RCU_LVL_3) | ||
| 65 | #define NUM_RCU_NODES (RCU_SUM - NR_CPUS) | ||
| 66 | |||
| 67 | /* | ||
| 68 | * Dynticks per-CPU state. | ||
| 69 | */ | ||
| 70 | struct rcu_dynticks { | ||
| 71 | int dynticks_nesting; /* Track nesting level, sort of. */ | ||
| 72 | int dynticks; /* Even value for dynticks-idle, else odd. */ | ||
| 73 | int dynticks_nmi; /* Even value for either dynticks-idle or */ | ||
| 74 | /* not in nmi handler, else odd. So this */ | ||
| 75 | /* remains even for nmi from irq handler. */ | ||
| 76 | }; | ||
| 77 | |||
| 78 | /* | ||
| 79 | * Definition for node within the RCU grace-period-detection hierarchy. | ||
| 80 | */ | ||
| 81 | struct rcu_node { | ||
| 82 | spinlock_t lock; | ||
| 83 | long gpnum; /* Current grace period for this node. */ | ||
| 84 | /* This will either be equal to or one */ | ||
| 85 | /* behind the root rcu_node's gpnum. */ | ||
| 86 | unsigned long qsmask; /* CPUs or groups that need to switch in */ | ||
| 87 | /* order for current grace period to proceed.*/ | ||
| 88 | unsigned long qsmaskinit; | ||
| 89 | /* Per-GP initialization for qsmask. */ | ||
| 90 | unsigned long grpmask; /* Mask to apply to parent qsmask. */ | ||
| 91 | int grplo; /* lowest-numbered CPU or group here. */ | ||
| 92 | int grphi; /* highest-numbered CPU or group here. */ | ||
| 93 | u8 grpnum; /* CPU/group number for next level up. */ | ||
| 94 | u8 level; /* root is at level 0. */ | ||
| 95 | struct rcu_node *parent; | ||
| 96 | struct list_head blocked_tasks[2]; | ||
| 97 | /* Tasks blocked in RCU read-side critsect. */ | ||
| 98 | } ____cacheline_internodealigned_in_smp; | ||
| 99 | |||
| 100 | /* Index values for nxttail array in struct rcu_data. */ | ||
| 101 | #define RCU_DONE_TAIL 0 /* Also RCU_WAIT head. */ | ||
| 102 | #define RCU_WAIT_TAIL 1 /* Also RCU_NEXT_READY head. */ | ||
| 103 | #define RCU_NEXT_READY_TAIL 2 /* Also RCU_NEXT head. */ | ||
| 104 | #define RCU_NEXT_TAIL 3 | ||
| 105 | #define RCU_NEXT_SIZE 4 | ||
| 106 | |||
| 107 | /* Per-CPU data for read-copy update. */ | ||
| 108 | struct rcu_data { | ||
| 109 | /* 1) quiescent-state and grace-period handling : */ | ||
| 110 | long completed; /* Track rsp->completed gp number */ | ||
| 111 | /* in order to detect GP end. */ | ||
| 112 | long gpnum; /* Highest gp number that this CPU */ | ||
| 113 | /* is aware of having started. */ | ||
| 114 | long passed_quiesc_completed; | ||
| 115 | /* Value of completed at time of qs. */ | ||
| 116 | bool passed_quiesc; /* User-mode/idle loop etc. */ | ||
| 117 | bool qs_pending; /* Core waits for quiesc state. */ | ||
| 118 | bool beenonline; /* CPU online at least once. */ | ||
| 119 | bool preemptable; /* Preemptable RCU? */ | ||
| 120 | struct rcu_node *mynode; /* This CPU's leaf of hierarchy */ | ||
| 121 | unsigned long grpmask; /* Mask to apply to leaf qsmask. */ | ||
| 122 | |||
| 123 | /* 2) batch handling */ | ||
| 124 | /* | ||
| 125 | * If nxtlist is not NULL, it is partitioned as follows. | ||
| 126 | * Any of the partitions might be empty, in which case the | ||
| 127 | * pointer to that partition will be equal to the pointer for | ||
| 128 | * the following partition. When the list is empty, all of | ||
| 129 | * the nxttail elements point to nxtlist, which is NULL. | ||
| 130 | * | ||
| 131 | * [*nxttail[RCU_NEXT_READY_TAIL], NULL = *nxttail[RCU_NEXT_TAIL]): | ||
| 132 | * Entries that might have arrived after current GP ended | ||
| 133 | * [*nxttail[RCU_WAIT_TAIL], *nxttail[RCU_NEXT_READY_TAIL]): | ||
| 134 | * Entries known to have arrived before current GP ended | ||
| 135 | * [*nxttail[RCU_DONE_TAIL], *nxttail[RCU_WAIT_TAIL]): | ||
| 136 | * Entries that batch # <= ->completed - 1: waiting for current GP | ||
| 137 | * [nxtlist, *nxttail[RCU_DONE_TAIL]): | ||
| 138 | * Entries that batch # <= ->completed | ||
| 139 | * The grace period for these entries has completed, and | ||
| 140 | * the other grace-period-completed entries may be moved | ||
| 141 | * here temporarily in rcu_process_callbacks(). | ||
| 142 | */ | ||
| 143 | struct rcu_head *nxtlist; | ||
| 144 | struct rcu_head **nxttail[RCU_NEXT_SIZE]; | ||
| 145 | long qlen; /* # of queued callbacks */ | ||
| 146 | long blimit; /* Upper limit on a processed batch */ | ||
| 147 | |||
| 148 | #ifdef CONFIG_NO_HZ | ||
| 149 | /* 3) dynticks interface. */ | ||
| 150 | struct rcu_dynticks *dynticks; /* Shared per-CPU dynticks state. */ | ||
| 151 | int dynticks_snap; /* Per-GP tracking for dynticks. */ | ||
| 152 | int dynticks_nmi_snap; /* Per-GP tracking for dynticks_nmi. */ | ||
| 153 | #endif /* #ifdef CONFIG_NO_HZ */ | ||
| 154 | |||
| 155 | /* 4) reasons this CPU needed to be kicked by force_quiescent_state */ | ||
| 156 | #ifdef CONFIG_NO_HZ | ||
| 157 | unsigned long dynticks_fqs; /* Kicked due to dynticks idle. */ | ||
| 158 | #endif /* #ifdef CONFIG_NO_HZ */ | ||
| 159 | unsigned long offline_fqs; /* Kicked due to being offline. */ | ||
| 160 | unsigned long resched_ipi; /* Sent a resched IPI. */ | ||
| 161 | |||
| 162 | /* 5) __rcu_pending() statistics. */ | ||
| 163 | long n_rcu_pending; /* rcu_pending() calls since boot. */ | ||
| 164 | long n_rp_qs_pending; | ||
| 165 | long n_rp_cb_ready; | ||
| 166 | long n_rp_cpu_needs_gp; | ||
| 167 | long n_rp_gp_completed; | ||
| 168 | long n_rp_gp_started; | ||
| 169 | long n_rp_need_fqs; | ||
| 170 | long n_rp_need_nothing; | ||
| 171 | |||
| 172 | int cpu; | ||
| 173 | }; | ||
| 174 | |||
| 175 | /* Values for signaled field in struct rcu_state. */ | ||
| 176 | #define RCU_GP_INIT 0 /* Grace period being initialized. */ | ||
| 177 | #define RCU_SAVE_DYNTICK 1 /* Need to scan dyntick state. */ | ||
| 178 | #define RCU_FORCE_QS 2 /* Need to force quiescent state. */ | ||
| 179 | #ifdef CONFIG_NO_HZ | ||
| 180 | #define RCU_SIGNAL_INIT RCU_SAVE_DYNTICK | ||
| 181 | #else /* #ifdef CONFIG_NO_HZ */ | ||
| 182 | #define RCU_SIGNAL_INIT RCU_FORCE_QS | ||
| 183 | #endif /* #else #ifdef CONFIG_NO_HZ */ | ||
| 184 | |||
| 185 | #define RCU_JIFFIES_TILL_FORCE_QS 3 /* for rsp->jiffies_force_qs */ | ||
| 186 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | ||
| 187 | #define RCU_SECONDS_TILL_STALL_CHECK (10 * HZ) /* for rsp->jiffies_stall */ | ||
| 188 | #define RCU_SECONDS_TILL_STALL_RECHECK (30 * HZ) /* for rsp->jiffies_stall */ | ||
| 189 | #define RCU_STALL_RAT_DELAY 2 /* Allow other CPUs time */ | ||
| 190 | /* to take at least one */ | ||
| 191 | /* scheduling clock irq */ | ||
| 192 | /* before ratting on them. */ | ||
| 193 | |||
| 194 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | ||
| 195 | |||
| 196 | /* | ||
| 197 | * RCU global state, including node hierarchy. This hierarchy is | ||
| 198 | * represented in "heap" form in a dense array. The root (first level) | ||
| 199 | * of the hierarchy is in ->node[0] (referenced by ->level[0]), the second | ||
| 200 | * level in ->node[1] through ->node[m] (->node[1] referenced by ->level[1]), | ||
| 201 | * and the third level in ->node[m+1] and following (->node[m+1] referenced | ||
| 202 | * by ->level[2]). The number of levels is determined by the number of | ||
| 203 | * CPUs and by CONFIG_RCU_FANOUT. Small systems will have a "hierarchy" | ||
| 204 | * consisting of a single rcu_node. | ||
| 205 | */ | ||
| 206 | struct rcu_state { | ||
| 207 | struct rcu_node node[NUM_RCU_NODES]; /* Hierarchy. */ | ||
| 208 | struct rcu_node *level[NUM_RCU_LVLS]; /* Hierarchy levels. */ | ||
| 209 | u32 levelcnt[MAX_RCU_LVLS + 1]; /* # nodes in each level. */ | ||
| 210 | u8 levelspread[NUM_RCU_LVLS]; /* kids/node in each level. */ | ||
| 211 | struct rcu_data *rda[NR_CPUS]; /* array of rdp pointers. */ | ||
| 212 | |||
| 213 | /* The following fields are guarded by the root rcu_node's lock. */ | ||
| 214 | |||
| 215 | u8 signaled ____cacheline_internodealigned_in_smp; | ||
| 216 | /* Force QS state. */ | ||
| 217 | long gpnum; /* Current gp number. */ | ||
| 218 | long completed; /* # of last completed gp. */ | ||
| 219 | spinlock_t onofflock; /* exclude on/offline and */ | ||
| 220 | /* starting new GP. */ | ||
| 221 | spinlock_t fqslock; /* Only one task forcing */ | ||
| 222 | /* quiescent states. */ | ||
| 223 | unsigned long jiffies_force_qs; /* Time at which to invoke */ | ||
| 224 | /* force_quiescent_state(). */ | ||
| 225 | unsigned long n_force_qs; /* Number of calls to */ | ||
| 226 | /* force_quiescent_state(). */ | ||
| 227 | unsigned long n_force_qs_lh; /* ~Number of calls leaving */ | ||
| 228 | /* due to lock unavailable. */ | ||
| 229 | unsigned long n_force_qs_ngp; /* Number of calls leaving */ | ||
| 230 | /* due to no GP active. */ | ||
| 231 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | ||
| 232 | unsigned long gp_start; /* Time at which GP started, */ | ||
| 233 | /* but in jiffies. */ | ||
| 234 | unsigned long jiffies_stall; /* Time at which to check */ | ||
| 235 | /* for CPU stalls. */ | ||
| 236 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | ||
| 237 | #ifdef CONFIG_NO_HZ | ||
| 238 | long dynticks_completed; /* Value of completed @ snap. */ | ||
| 239 | #endif /* #ifdef CONFIG_NO_HZ */ | ||
| 240 | }; | ||
| 241 | |||
| 242 | #ifdef RCU_TREE_NONCORE | ||
| 1 | 243 | ||
| 2 | /* | 244 | /* |
| 3 | * RCU implementation internal declarations: | 245 | * RCU implementation internal declarations: |
| 4 | */ | 246 | */ |
| 5 | extern struct rcu_state rcu_state; | 247 | extern struct rcu_state rcu_sched_state; |
| 6 | DECLARE_PER_CPU(struct rcu_data, rcu_data); | 248 | DECLARE_PER_CPU(struct rcu_data, rcu_sched_data); |
| 7 | 249 | ||
| 8 | extern struct rcu_state rcu_bh_state; | 250 | extern struct rcu_state rcu_bh_state; |
| 9 | DECLARE_PER_CPU(struct rcu_data, rcu_bh_data); | 251 | DECLARE_PER_CPU(struct rcu_data, rcu_bh_data); |
| 10 | 252 | ||
| 253 | #ifdef CONFIG_TREE_PREEMPT_RCU | ||
| 254 | extern struct rcu_state rcu_preempt_state; | ||
| 255 | DECLARE_PER_CPU(struct rcu_data, rcu_preempt_data); | ||
| 256 | #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
| 257 | |||
| 258 | #endif /* #ifdef RCU_TREE_NONCORE */ | ||
| 259 | |||
diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h new file mode 100644 index 000000000000..47789369ea59 --- /dev/null +++ b/kernel/rcutree_plugin.h | |||
| @@ -0,0 +1,532 @@ | |||
| 1 | /* | ||
| 2 | * Read-Copy Update mechanism for mutual exclusion (tree-based version) | ||
| 3 | * Internal non-public definitions that provide either classic | ||
| 4 | * or preemptable semantics. | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 19 | * | ||
| 20 | * Copyright Red Hat, 2009 | ||
| 21 | * Copyright IBM Corporation, 2009 | ||
| 22 | * | ||
| 23 | * Author: Ingo Molnar <mingo@elte.hu> | ||
| 24 | * Paul E. McKenney <paulmck@linux.vnet.ibm.com> | ||
| 25 | */ | ||
| 26 | |||
| 27 | |||
| 28 | #ifdef CONFIG_TREE_PREEMPT_RCU | ||
| 29 | |||
| 30 | struct rcu_state rcu_preempt_state = RCU_STATE_INITIALIZER(rcu_preempt_state); | ||
| 31 | DEFINE_PER_CPU(struct rcu_data, rcu_preempt_data); | ||
| 32 | |||
| 33 | /* | ||
| 34 | * Tell them what RCU they are running. | ||
| 35 | */ | ||
| 36 | static inline void rcu_bootup_announce(void) | ||
| 37 | { | ||
| 38 | printk(KERN_INFO | ||
| 39 | "Experimental preemptable hierarchical RCU implementation.\n"); | ||
| 40 | } | ||
| 41 | |||
| 42 | /* | ||
| 43 | * Return the number of RCU-preempt batches processed thus far | ||
| 44 | * for debug and statistics. | ||
| 45 | */ | ||
| 46 | long rcu_batches_completed_preempt(void) | ||
| 47 | { | ||
| 48 | return rcu_preempt_state.completed; | ||
| 49 | } | ||
| 50 | EXPORT_SYMBOL_GPL(rcu_batches_completed_preempt); | ||
| 51 | |||
| 52 | /* | ||
| 53 | * Return the number of RCU batches processed thus far for debug & stats. | ||
| 54 | */ | ||
| 55 | long rcu_batches_completed(void) | ||
| 56 | { | ||
| 57 | return rcu_batches_completed_preempt(); | ||
| 58 | } | ||
| 59 | EXPORT_SYMBOL_GPL(rcu_batches_completed); | ||
| 60 | |||
| 61 | /* | ||
| 62 | * Record a preemptable-RCU quiescent state for the specified CPU. Note | ||
| 63 | * that this just means that the task currently running on the CPU is | ||
| 64 | * not in a quiescent state. There might be any number of tasks blocked | ||
| 65 | * while in an RCU read-side critical section. | ||
| 66 | */ | ||
| 67 | static void rcu_preempt_qs_record(int cpu) | ||
| 68 | { | ||
| 69 | struct rcu_data *rdp = &per_cpu(rcu_preempt_data, cpu); | ||
| 70 | rdp->passed_quiesc = 1; | ||
| 71 | rdp->passed_quiesc_completed = rdp->completed; | ||
| 72 | } | ||
| 73 | |||
| 74 | /* | ||
| 75 | * We have entered the scheduler or are between softirqs in ksoftirqd. | ||
| 76 | * If we are in an RCU read-side critical section, we need to reflect | ||
| 77 | * that in the state of the rcu_node structure corresponding to this CPU. | ||
| 78 | * Caller must disable hardirqs. | ||
| 79 | */ | ||
| 80 | static void rcu_preempt_qs(int cpu) | ||
| 81 | { | ||
| 82 | struct task_struct *t = current; | ||
| 83 | int phase; | ||
| 84 | struct rcu_data *rdp; | ||
| 85 | struct rcu_node *rnp; | ||
| 86 | |||
| 87 | if (t->rcu_read_lock_nesting && | ||
| 88 | (t->rcu_read_unlock_special & RCU_READ_UNLOCK_BLOCKED) == 0) { | ||
| 89 | |||
| 90 | /* Possibly blocking in an RCU read-side critical section. */ | ||
| 91 | rdp = rcu_preempt_state.rda[cpu]; | ||
| 92 | rnp = rdp->mynode; | ||
| 93 | spin_lock(&rnp->lock); | ||
| 94 | t->rcu_read_unlock_special |= RCU_READ_UNLOCK_BLOCKED; | ||
| 95 | t->rcu_blocked_node = rnp; | ||
| 96 | |||
| 97 | /* | ||
| 98 | * If this CPU has already checked in, then this task | ||
| 99 | * will hold up the next grace period rather than the | ||
| 100 | * current grace period. Queue the task accordingly. | ||
| 101 | * If the task is queued for the current grace period | ||
| 102 | * (i.e., this CPU has not yet passed through a quiescent | ||
| 103 | * state for the current grace period), then as long | ||
| 104 | * as that task remains queued, the current grace period | ||
| 105 | * cannot end. | ||
| 106 | */ | ||
| 107 | phase = !(rnp->qsmask & rdp->grpmask) ^ (rnp->gpnum & 0x1); | ||
| 108 | list_add(&t->rcu_node_entry, &rnp->blocked_tasks[phase]); | ||
| 109 | smp_mb(); /* Ensure later ctxt swtch seen after above. */ | ||
| 110 | spin_unlock(&rnp->lock); | ||
| 111 | } | ||
| 112 | |||
| 113 | /* | ||
| 114 | * Either we were not in an RCU read-side critical section to | ||
| 115 | * begin with, or we have now recorded that critical section | ||
| 116 | * globally. Either way, we can now note a quiescent state | ||
| 117 | * for this CPU. Again, if we were in an RCU read-side critical | ||
| 118 | * section, and if that critical section was blocking the current | ||
| 119 | * grace period, then the fact that the task has been enqueued | ||
| 120 | * means that we continue to block the current grace period. | ||
| 121 | */ | ||
| 122 | rcu_preempt_qs_record(cpu); | ||
| 123 | t->rcu_read_unlock_special &= ~(RCU_READ_UNLOCK_NEED_QS | | ||
| 124 | RCU_READ_UNLOCK_GOT_QS); | ||
| 125 | } | ||
| 126 | |||
| 127 | /* | ||
| 128 | * Tree-preemptable RCU implementation for rcu_read_lock(). | ||
| 129 | * Just increment ->rcu_read_lock_nesting, shared state will be updated | ||
| 130 | * if we block. | ||
| 131 | */ | ||
| 132 | void __rcu_read_lock(void) | ||
| 133 | { | ||
| 134 | ACCESS_ONCE(current->rcu_read_lock_nesting)++; | ||
| 135 | barrier(); /* needed if we ever invoke rcu_read_lock in rcutree.c */ | ||
| 136 | } | ||
| 137 | EXPORT_SYMBOL_GPL(__rcu_read_lock); | ||
| 138 | |||
| 139 | static void rcu_read_unlock_special(struct task_struct *t) | ||
| 140 | { | ||
| 141 | int empty; | ||
| 142 | unsigned long flags; | ||
| 143 | unsigned long mask; | ||
| 144 | struct rcu_node *rnp; | ||
| 145 | int special; | ||
| 146 | |||
| 147 | /* NMI handlers cannot block and cannot safely manipulate state. */ | ||
| 148 | if (in_nmi()) | ||
| 149 | return; | ||
| 150 | |||
| 151 | local_irq_save(flags); | ||
| 152 | |||
| 153 | /* | ||
| 154 | * If RCU core is waiting for this CPU to exit critical section, | ||
| 155 | * let it know that we have done so. | ||
| 156 | */ | ||
| 157 | special = t->rcu_read_unlock_special; | ||
| 158 | if (special & RCU_READ_UNLOCK_NEED_QS) { | ||
| 159 | t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS; | ||
| 160 | t->rcu_read_unlock_special |= RCU_READ_UNLOCK_GOT_QS; | ||
| 161 | } | ||
| 162 | |||
| 163 | /* Hardware IRQ handlers cannot block. */ | ||
| 164 | if (in_irq()) { | ||
| 165 | local_irq_restore(flags); | ||
| 166 | return; | ||
| 167 | } | ||
| 168 | |||
| 169 | /* Clean up if blocked during RCU read-side critical section. */ | ||
| 170 | if (special & RCU_READ_UNLOCK_BLOCKED) { | ||
| 171 | t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_BLOCKED; | ||
| 172 | |||
| 173 | /* | ||
| 174 | * Remove this task from the list it blocked on. The | ||
| 175 | * task can migrate while we acquire the lock, but at | ||
| 176 | * most one time. So at most two passes through loop. | ||
| 177 | */ | ||
| 178 | for (;;) { | ||
| 179 | rnp = t->rcu_blocked_node; | ||
| 180 | spin_lock(&rnp->lock); | ||
| 181 | if (rnp == t->rcu_blocked_node) | ||
| 182 | break; | ||
| 183 | spin_unlock(&rnp->lock); | ||
| 184 | } | ||
| 185 | empty = list_empty(&rnp->blocked_tasks[rnp->gpnum & 0x1]); | ||
| 186 | list_del_init(&t->rcu_node_entry); | ||
| 187 | t->rcu_blocked_node = NULL; | ||
| 188 | |||
| 189 | /* | ||
| 190 | * If this was the last task on the current list, and if | ||
| 191 | * we aren't waiting on any CPUs, report the quiescent state. | ||
| 192 | * Note that both cpu_quiet_msk_finish() and cpu_quiet_msk() | ||
| 193 | * drop rnp->lock and restore irq. | ||
| 194 | */ | ||
| 195 | if (!empty && rnp->qsmask == 0 && | ||
| 196 | list_empty(&rnp->blocked_tasks[rnp->gpnum & 0x1])) { | ||
| 197 | t->rcu_read_unlock_special &= | ||
| 198 | ~(RCU_READ_UNLOCK_NEED_QS | | ||
| 199 | RCU_READ_UNLOCK_GOT_QS); | ||
| 200 | if (rnp->parent == NULL) { | ||
| 201 | /* Only one rcu_node in the tree. */ | ||
| 202 | cpu_quiet_msk_finish(&rcu_preempt_state, flags); | ||
| 203 | return; | ||
| 204 | } | ||
| 205 | /* Report up the rest of the hierarchy. */ | ||
| 206 | mask = rnp->grpmask; | ||
| 207 | spin_unlock_irqrestore(&rnp->lock, flags); | ||
| 208 | rnp = rnp->parent; | ||
| 209 | spin_lock_irqsave(&rnp->lock, flags); | ||
| 210 | cpu_quiet_msk(mask, &rcu_preempt_state, rnp, flags); | ||
| 211 | return; | ||
| 212 | } | ||
| 213 | spin_unlock(&rnp->lock); | ||
| 214 | } | ||
| 215 | local_irq_restore(flags); | ||
| 216 | } | ||
| 217 | |||
| 218 | /* | ||
| 219 | * Tree-preemptable RCU implementation for rcu_read_unlock(). | ||
| 220 | * Decrement ->rcu_read_lock_nesting. If the result is zero (outermost | ||
| 221 | * rcu_read_unlock()) and ->rcu_read_unlock_special is non-zero, then | ||
| 222 | * invoke rcu_read_unlock_special() to clean up after a context switch | ||
| 223 | * in an RCU read-side critical section and other special cases. | ||
| 224 | */ | ||
| 225 | void __rcu_read_unlock(void) | ||
| 226 | { | ||
| 227 | struct task_struct *t = current; | ||
| 228 | |||
| 229 | barrier(); /* needed if we ever invoke rcu_read_unlock in rcutree.c */ | ||
| 230 | if (--ACCESS_ONCE(t->rcu_read_lock_nesting) == 0 && | ||
| 231 | unlikely(ACCESS_ONCE(t->rcu_read_unlock_special))) | ||
| 232 | rcu_read_unlock_special(t); | ||
| 233 | } | ||
| 234 | EXPORT_SYMBOL_GPL(__rcu_read_unlock); | ||
| 235 | |||
| 236 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | ||
| 237 | |||
| 238 | /* | ||
| 239 | * Scan the current list of tasks blocked within RCU read-side critical | ||
| 240 | * sections, printing out the tid of each. | ||
| 241 | */ | ||
| 242 | static void rcu_print_task_stall(struct rcu_node *rnp) | ||
| 243 | { | ||
| 244 | unsigned long flags; | ||
| 245 | struct list_head *lp; | ||
| 246 | int phase = rnp->gpnum & 0x1; | ||
| 247 | struct task_struct *t; | ||
| 248 | |||
| 249 | if (!list_empty(&rnp->blocked_tasks[phase])) { | ||
| 250 | spin_lock_irqsave(&rnp->lock, flags); | ||
| 251 | phase = rnp->gpnum & 0x1; /* re-read under lock. */ | ||
| 252 | lp = &rnp->blocked_tasks[phase]; | ||
| 253 | list_for_each_entry(t, lp, rcu_node_entry) | ||
| 254 | printk(" P%d", t->pid); | ||
| 255 | spin_unlock_irqrestore(&rnp->lock, flags); | ||
| 256 | } | ||
| 257 | } | ||
| 258 | |||
| 259 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | ||
| 260 | |||
| 261 | /* | ||
| 262 | * Check for preempted RCU readers for the specified rcu_node structure. | ||
| 263 | * If the caller needs a reliable answer, it must hold the rcu_node's | ||
| 264 | * >lock. | ||
| 265 | */ | ||
| 266 | static int rcu_preempted_readers(struct rcu_node *rnp) | ||
| 267 | { | ||
| 268 | return !list_empty(&rnp->blocked_tasks[rnp->gpnum & 0x1]); | ||
| 269 | } | ||
| 270 | |||
| 271 | #ifdef CONFIG_HOTPLUG_CPU | ||
| 272 | |||
| 273 | /* | ||
| 274 | * Handle tasklist migration for case in which all CPUs covered by the | ||
| 275 | * specified rcu_node have gone offline. Move them up to the root | ||
| 276 | * rcu_node. The reason for not just moving them to the immediate | ||
| 277 | * parent is to remove the need for rcu_read_unlock_special() to | ||
| 278 | * make more than two attempts to acquire the target rcu_node's lock. | ||
| 279 | * | ||
| 280 | * The caller must hold rnp->lock with irqs disabled. | ||
| 281 | */ | ||
| 282 | static void rcu_preempt_offline_tasks(struct rcu_state *rsp, | ||
| 283 | struct rcu_node *rnp) | ||
| 284 | { | ||
| 285 | int i; | ||
| 286 | struct list_head *lp; | ||
| 287 | struct list_head *lp_root; | ||
| 288 | struct rcu_node *rnp_root = rcu_get_root(rsp); | ||
| 289 | struct task_struct *tp; | ||
| 290 | |||
| 291 | if (rnp == rnp_root) { | ||
| 292 | WARN_ONCE(1, "Last CPU thought to be offlined?"); | ||
| 293 | return; /* Shouldn't happen: at least one CPU online. */ | ||
| 294 | } | ||
| 295 | |||
| 296 | /* | ||
| 297 | * Move tasks up to root rcu_node. Rely on the fact that the | ||
| 298 | * root rcu_node can be at most one ahead of the rest of the | ||
| 299 | * rcu_nodes in terms of gp_num value. This fact allows us to | ||
| 300 | * move the blocked_tasks[] array directly, element by element. | ||
| 301 | */ | ||
| 302 | for (i = 0; i < 2; i++) { | ||
| 303 | lp = &rnp->blocked_tasks[i]; | ||
| 304 | lp_root = &rnp_root->blocked_tasks[i]; | ||
| 305 | while (!list_empty(lp)) { | ||
| 306 | tp = list_entry(lp->next, typeof(*tp), rcu_node_entry); | ||
| 307 | spin_lock(&rnp_root->lock); /* irqs already disabled */ | ||
| 308 | list_del(&tp->rcu_node_entry); | ||
| 309 | tp->rcu_blocked_node = rnp_root; | ||
| 310 | list_add(&tp->rcu_node_entry, lp_root); | ||
| 311 | spin_unlock(&rnp_root->lock); /* irqs remain disabled */ | ||
| 312 | } | ||
| 313 | } | ||
| 314 | } | ||
| 315 | |||
| 316 | /* | ||
| 317 | * Do CPU-offline processing for preemptable RCU. | ||
| 318 | */ | ||
| 319 | static void rcu_preempt_offline_cpu(int cpu) | ||
| 320 | { | ||
| 321 | __rcu_offline_cpu(cpu, &rcu_preempt_state); | ||
| 322 | } | ||
| 323 | |||
| 324 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ | ||
| 325 | |||
| 326 | /* | ||
| 327 | * Check for a quiescent state from the current CPU. When a task blocks, | ||
| 328 | * the task is recorded in the corresponding CPU's rcu_node structure, | ||
| 329 | * which is checked elsewhere. | ||
| 330 | * | ||
| 331 | * Caller must disable hard irqs. | ||
| 332 | */ | ||
| 333 | static void rcu_preempt_check_callbacks(int cpu) | ||
| 334 | { | ||
| 335 | struct task_struct *t = current; | ||
| 336 | |||
| 337 | if (t->rcu_read_lock_nesting == 0) { | ||
| 338 | t->rcu_read_unlock_special &= | ||
| 339 | ~(RCU_READ_UNLOCK_NEED_QS | RCU_READ_UNLOCK_GOT_QS); | ||
| 340 | rcu_preempt_qs_record(cpu); | ||
| 341 | return; | ||
| 342 | } | ||
| 343 | if (per_cpu(rcu_preempt_data, cpu).qs_pending) { | ||
| 344 | if (t->rcu_read_unlock_special & RCU_READ_UNLOCK_GOT_QS) { | ||
| 345 | rcu_preempt_qs_record(cpu); | ||
| 346 | t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_GOT_QS; | ||
| 347 | } else if (!(t->rcu_read_unlock_special & | ||
| 348 | RCU_READ_UNLOCK_NEED_QS)) { | ||
| 349 | t->rcu_read_unlock_special |= RCU_READ_UNLOCK_NEED_QS; | ||
| 350 | } | ||
| 351 | } | ||
| 352 | } | ||
| 353 | |||
| 354 | /* | ||
| 355 | * Process callbacks for preemptable RCU. | ||
| 356 | */ | ||
| 357 | static void rcu_preempt_process_callbacks(void) | ||
| 358 | { | ||
| 359 | __rcu_process_callbacks(&rcu_preempt_state, | ||
| 360 | &__get_cpu_var(rcu_preempt_data)); | ||
| 361 | } | ||
| 362 | |||
| 363 | /* | ||
| 364 | * Queue a preemptable-RCU callback for invocation after a grace period. | ||
| 365 | */ | ||
| 366 | void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) | ||
| 367 | { | ||
| 368 | __call_rcu(head, func, &rcu_preempt_state); | ||
| 369 | } | ||
| 370 | EXPORT_SYMBOL_GPL(call_rcu); | ||
| 371 | |||
| 372 | /* | ||
| 373 | * Check to see if there is any immediate preemptable-RCU-related work | ||
| 374 | * to be done. | ||
| 375 | */ | ||
| 376 | static int rcu_preempt_pending(int cpu) | ||
| 377 | { | ||
| 378 | return __rcu_pending(&rcu_preempt_state, | ||
| 379 | &per_cpu(rcu_preempt_data, cpu)); | ||
| 380 | } | ||
| 381 | |||
| 382 | /* | ||
| 383 | * Does preemptable RCU need the CPU to stay out of dynticks mode? | ||
| 384 | */ | ||
| 385 | static int rcu_preempt_needs_cpu(int cpu) | ||
| 386 | { | ||
| 387 | return !!per_cpu(rcu_preempt_data, cpu).nxtlist; | ||
| 388 | } | ||
| 389 | |||
| 390 | /* | ||
| 391 | * Initialize preemptable RCU's per-CPU data. | ||
| 392 | */ | ||
| 393 | static void __cpuinit rcu_preempt_init_percpu_data(int cpu) | ||
| 394 | { | ||
| 395 | rcu_init_percpu_data(cpu, &rcu_preempt_state, 1); | ||
| 396 | } | ||
| 397 | |||
| 398 | /* | ||
| 399 | * Check for a task exiting while in a preemptable-RCU read-side | ||
| 400 | * critical section, clean up if so. No need to issue warnings, | ||
| 401 | * as debug_check_no_locks_held() already does this if lockdep | ||
| 402 | * is enabled. | ||
| 403 | */ | ||
| 404 | void exit_rcu(void) | ||
| 405 | { | ||
| 406 | struct task_struct *t = current; | ||
| 407 | |||
| 408 | if (t->rcu_read_lock_nesting == 0) | ||
| 409 | return; | ||
| 410 | t->rcu_read_lock_nesting = 1; | ||
| 411 | rcu_read_unlock(); | ||
| 412 | } | ||
| 413 | |||
| 414 | #else /* #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
| 415 | |||
| 416 | /* | ||
| 417 | * Tell them what RCU they are running. | ||
| 418 | */ | ||
| 419 | static inline void rcu_bootup_announce(void) | ||
| 420 | { | ||
| 421 | printk(KERN_INFO "Hierarchical RCU implementation.\n"); | ||
| 422 | } | ||
| 423 | |||
| 424 | /* | ||
| 425 | * Return the number of RCU batches processed thus far for debug & stats. | ||
| 426 | */ | ||
| 427 | long rcu_batches_completed(void) | ||
| 428 | { | ||
| 429 | return rcu_batches_completed_sched(); | ||
| 430 | } | ||
| 431 | EXPORT_SYMBOL_GPL(rcu_batches_completed); | ||
| 432 | |||
| 433 | /* | ||
| 434 | * Because preemptable RCU does not exist, we never have to check for | ||
| 435 | * CPUs being in quiescent states. | ||
| 436 | */ | ||
| 437 | static void rcu_preempt_qs(int cpu) | ||
| 438 | { | ||
| 439 | } | ||
| 440 | |||
| 441 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | ||
| 442 | |||
| 443 | /* | ||
| 444 | * Because preemptable RCU does not exist, we never have to check for | ||
| 445 | * tasks blocked within RCU read-side critical sections. | ||
| 446 | */ | ||
| 447 | static void rcu_print_task_stall(struct rcu_node *rnp) | ||
| 448 | { | ||
| 449 | } | ||
| 450 | |||
| 451 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | ||
| 452 | |||
| 453 | /* | ||
| 454 | * Because preemptable RCU does not exist, there are never any preempted | ||
| 455 | * RCU readers. | ||
| 456 | */ | ||
| 457 | static int rcu_preempted_readers(struct rcu_node *rnp) | ||
| 458 | { | ||
| 459 | return 0; | ||
| 460 | } | ||
| 461 | |||
| 462 | #ifdef CONFIG_HOTPLUG_CPU | ||
| 463 | |||
| 464 | /* | ||
| 465 | * Because preemptable RCU does not exist, it never needs to migrate | ||
| 466 | * tasks that were blocked within RCU read-side critical sections. | ||
| 467 | */ | ||
| 468 | static void rcu_preempt_offline_tasks(struct rcu_state *rsp, | ||
| 469 | struct rcu_node *rnp) | ||
| 470 | { | ||
| 471 | } | ||
| 472 | |||
| 473 | /* | ||
| 474 | * Because preemptable RCU does not exist, it never needs CPU-offline | ||
| 475 | * processing. | ||
| 476 | */ | ||
| 477 | static void rcu_preempt_offline_cpu(int cpu) | ||
| 478 | { | ||
| 479 | } | ||
| 480 | |||
| 481 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ | ||
| 482 | |||
| 483 | /* | ||
| 484 | * Because preemptable RCU does not exist, it never has any callbacks | ||
| 485 | * to check. | ||
| 486 | */ | ||
| 487 | void rcu_preempt_check_callbacks(int cpu) | ||
| 488 | { | ||
| 489 | } | ||
| 490 | |||
| 491 | /* | ||
| 492 | * Because preemptable RCU does not exist, it never has any callbacks | ||
| 493 | * to process. | ||
| 494 | */ | ||
| 495 | void rcu_preempt_process_callbacks(void) | ||
| 496 | { | ||
| 497 | } | ||
| 498 | |||
| 499 | /* | ||
| 500 | * In classic RCU, call_rcu() is just call_rcu_sched(). | ||
| 501 | */ | ||
| 502 | void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) | ||
| 503 | { | ||
| 504 | call_rcu_sched(head, func); | ||
| 505 | } | ||
| 506 | EXPORT_SYMBOL_GPL(call_rcu); | ||
| 507 | |||
| 508 | /* | ||
| 509 | * Because preemptable RCU does not exist, it never has any work to do. | ||
| 510 | */ | ||
| 511 | static int rcu_preempt_pending(int cpu) | ||
| 512 | { | ||
| 513 | return 0; | ||
| 514 | } | ||
| 515 | |||
| 516 | /* | ||
| 517 | * Because preemptable RCU does not exist, it never needs any CPU. | ||
| 518 | */ | ||
| 519 | static int rcu_preempt_needs_cpu(int cpu) | ||
| 520 | { | ||
| 521 | return 0; | ||
| 522 | } | ||
| 523 | |||
| 524 | /* | ||
| 525 | * Because preemptable RCU does not exist, there is no per-CPU | ||
| 526 | * data to initialize. | ||
| 527 | */ | ||
| 528 | static void __cpuinit rcu_preempt_init_percpu_data(int cpu) | ||
| 529 | { | ||
| 530 | } | ||
| 531 | |||
| 532 | #endif /* #else #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c index fe1dcdbf1ca3..0ea1bff69727 100644 --- a/kernel/rcutree_trace.c +++ b/kernel/rcutree_trace.c | |||
| @@ -43,6 +43,7 @@ | |||
| 43 | #include <linux/debugfs.h> | 43 | #include <linux/debugfs.h> |
| 44 | #include <linux/seq_file.h> | 44 | #include <linux/seq_file.h> |
| 45 | 45 | ||
| 46 | #define RCU_TREE_NONCORE | ||
| 46 | #include "rcutree.h" | 47 | #include "rcutree.h" |
| 47 | 48 | ||
| 48 | static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp) | 49 | static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp) |
| @@ -76,8 +77,12 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp) | |||
| 76 | 77 | ||
| 77 | static int show_rcudata(struct seq_file *m, void *unused) | 78 | static int show_rcudata(struct seq_file *m, void *unused) |
| 78 | { | 79 | { |
| 79 | seq_puts(m, "rcu:\n"); | 80 | #ifdef CONFIG_TREE_PREEMPT_RCU |
| 80 | PRINT_RCU_DATA(rcu_data, print_one_rcu_data, m); | 81 | seq_puts(m, "rcu_preempt:\n"); |
| 82 | PRINT_RCU_DATA(rcu_preempt_data, print_one_rcu_data, m); | ||
| 83 | #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
| 84 | seq_puts(m, "rcu_sched:\n"); | ||
| 85 | PRINT_RCU_DATA(rcu_sched_data, print_one_rcu_data, m); | ||
| 81 | seq_puts(m, "rcu_bh:\n"); | 86 | seq_puts(m, "rcu_bh:\n"); |
| 82 | PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data, m); | 87 | PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data, m); |
| 83 | return 0; | 88 | return 0; |
| @@ -102,7 +107,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp) | |||
| 102 | return; | 107 | return; |
| 103 | seq_printf(m, "%d,%s,%ld,%ld,%d,%ld,%d", | 108 | seq_printf(m, "%d,%s,%ld,%ld,%d,%ld,%d", |
| 104 | rdp->cpu, | 109 | rdp->cpu, |
| 105 | cpu_is_offline(rdp->cpu) ? "\"Y\"" : "\"N\"", | 110 | cpu_is_offline(rdp->cpu) ? "\"N\"" : "\"Y\"", |
| 106 | rdp->completed, rdp->gpnum, | 111 | rdp->completed, rdp->gpnum, |
| 107 | rdp->passed_quiesc, rdp->passed_quiesc_completed, | 112 | rdp->passed_quiesc, rdp->passed_quiesc_completed, |
| 108 | rdp->qs_pending); | 113 | rdp->qs_pending); |
| @@ -124,8 +129,12 @@ static int show_rcudata_csv(struct seq_file *m, void *unused) | |||
| 124 | seq_puts(m, "\"dt\",\"dt nesting\",\"dn\",\"df\","); | 129 | seq_puts(m, "\"dt\",\"dt nesting\",\"dn\",\"df\","); |
| 125 | #endif /* #ifdef CONFIG_NO_HZ */ | 130 | #endif /* #ifdef CONFIG_NO_HZ */ |
| 126 | seq_puts(m, "\"of\",\"ri\",\"ql\",\"b\"\n"); | 131 | seq_puts(m, "\"of\",\"ri\",\"ql\",\"b\"\n"); |
| 127 | seq_puts(m, "\"rcu:\"\n"); | 132 | #ifdef CONFIG_TREE_PREEMPT_RCU |
| 128 | PRINT_RCU_DATA(rcu_data, print_one_rcu_data_csv, m); | 133 | seq_puts(m, "\"rcu_preempt:\"\n"); |
| 134 | PRINT_RCU_DATA(rcu_preempt_data, print_one_rcu_data_csv, m); | ||
| 135 | #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
| 136 | seq_puts(m, "\"rcu_sched:\"\n"); | ||
| 137 | PRINT_RCU_DATA(rcu_sched_data, print_one_rcu_data_csv, m); | ||
| 129 | seq_puts(m, "\"rcu_bh:\"\n"); | 138 | seq_puts(m, "\"rcu_bh:\"\n"); |
| 130 | PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data_csv, m); | 139 | PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data_csv, m); |
| 131 | return 0; | 140 | return 0; |
| @@ -171,8 +180,12 @@ static void print_one_rcu_state(struct seq_file *m, struct rcu_state *rsp) | |||
| 171 | 180 | ||
| 172 | static int show_rcuhier(struct seq_file *m, void *unused) | 181 | static int show_rcuhier(struct seq_file *m, void *unused) |
| 173 | { | 182 | { |
| 174 | seq_puts(m, "rcu:\n"); | 183 | #ifdef CONFIG_TREE_PREEMPT_RCU |
| 175 | print_one_rcu_state(m, &rcu_state); | 184 | seq_puts(m, "rcu_preempt:\n"); |
| 185 | print_one_rcu_state(m, &rcu_preempt_state); | ||
| 186 | #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
| 187 | seq_puts(m, "rcu_sched:\n"); | ||
| 188 | print_one_rcu_state(m, &rcu_sched_state); | ||
| 176 | seq_puts(m, "rcu_bh:\n"); | 189 | seq_puts(m, "rcu_bh:\n"); |
| 177 | print_one_rcu_state(m, &rcu_bh_state); | 190 | print_one_rcu_state(m, &rcu_bh_state); |
| 178 | return 0; | 191 | return 0; |
| @@ -193,8 +206,12 @@ static struct file_operations rcuhier_fops = { | |||
| 193 | 206 | ||
| 194 | static int show_rcugp(struct seq_file *m, void *unused) | 207 | static int show_rcugp(struct seq_file *m, void *unused) |
| 195 | { | 208 | { |
| 196 | seq_printf(m, "rcu: completed=%ld gpnum=%ld\n", | 209 | #ifdef CONFIG_TREE_PREEMPT_RCU |
| 197 | rcu_state.completed, rcu_state.gpnum); | 210 | seq_printf(m, "rcu_preempt: completed=%ld gpnum=%ld\n", |
| 211 | rcu_preempt_state.completed, rcu_preempt_state.gpnum); | ||
| 212 | #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
| 213 | seq_printf(m, "rcu_sched: completed=%ld gpnum=%ld\n", | ||
| 214 | rcu_sched_state.completed, rcu_sched_state.gpnum); | ||
| 198 | seq_printf(m, "rcu_bh: completed=%ld gpnum=%ld\n", | 215 | seq_printf(m, "rcu_bh: completed=%ld gpnum=%ld\n", |
| 199 | rcu_bh_state.completed, rcu_bh_state.gpnum); | 216 | rcu_bh_state.completed, rcu_bh_state.gpnum); |
| 200 | return 0; | 217 | return 0; |
| @@ -243,8 +260,12 @@ static void print_rcu_pendings(struct seq_file *m, struct rcu_state *rsp) | |||
| 243 | 260 | ||
| 244 | static int show_rcu_pending(struct seq_file *m, void *unused) | 261 | static int show_rcu_pending(struct seq_file *m, void *unused) |
| 245 | { | 262 | { |
| 246 | seq_puts(m, "rcu:\n"); | 263 | #ifdef CONFIG_TREE_PREEMPT_RCU |
| 247 | print_rcu_pendings(m, &rcu_state); | 264 | seq_puts(m, "rcu_preempt:\n"); |
| 265 | print_rcu_pendings(m, &rcu_preempt_state); | ||
| 266 | #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
| 267 | seq_puts(m, "rcu_sched:\n"); | ||
| 268 | print_rcu_pendings(m, &rcu_sched_state); | ||
| 248 | seq_puts(m, "rcu_bh:\n"); | 269 | seq_puts(m, "rcu_bh:\n"); |
| 249 | print_rcu_pendings(m, &rcu_bh_state); | 270 | print_rcu_pendings(m, &rcu_bh_state); |
| 250 | return 0; | 271 | return 0; |
| @@ -264,62 +285,47 @@ static struct file_operations rcu_pending_fops = { | |||
| 264 | }; | 285 | }; |
| 265 | 286 | ||
| 266 | static struct dentry *rcudir; | 287 | static struct dentry *rcudir; |
| 267 | static struct dentry *datadir; | ||
| 268 | static struct dentry *datadir_csv; | ||
| 269 | static struct dentry *gpdir; | ||
| 270 | static struct dentry *hierdir; | ||
| 271 | static struct dentry *rcu_pendingdir; | ||
| 272 | 288 | ||
| 273 | static int __init rcuclassic_trace_init(void) | 289 | static int __init rcuclassic_trace_init(void) |
| 274 | { | 290 | { |
| 291 | struct dentry *retval; | ||
| 292 | |||
| 275 | rcudir = debugfs_create_dir("rcu", NULL); | 293 | rcudir = debugfs_create_dir("rcu", NULL); |
| 276 | if (!rcudir) | 294 | if (!rcudir) |
| 277 | goto out; | 295 | goto free_out; |
| 278 | 296 | ||
| 279 | datadir = debugfs_create_file("rcudata", 0444, rcudir, | 297 | retval = debugfs_create_file("rcudata", 0444, rcudir, |
| 280 | NULL, &rcudata_fops); | 298 | NULL, &rcudata_fops); |
| 281 | if (!datadir) | 299 | if (!retval) |
| 282 | goto free_out; | 300 | goto free_out; |
| 283 | 301 | ||
| 284 | datadir_csv = debugfs_create_file("rcudata.csv", 0444, rcudir, | 302 | retval = debugfs_create_file("rcudata.csv", 0444, rcudir, |
| 285 | NULL, &rcudata_csv_fops); | 303 | NULL, &rcudata_csv_fops); |
| 286 | if (!datadir_csv) | 304 | if (!retval) |
| 287 | goto free_out; | 305 | goto free_out; |
| 288 | 306 | ||
| 289 | gpdir = debugfs_create_file("rcugp", 0444, rcudir, NULL, &rcugp_fops); | 307 | retval = debugfs_create_file("rcugp", 0444, rcudir, NULL, &rcugp_fops); |
| 290 | if (!gpdir) | 308 | if (!retval) |
| 291 | goto free_out; | 309 | goto free_out; |
| 292 | 310 | ||
| 293 | hierdir = debugfs_create_file("rcuhier", 0444, rcudir, | 311 | retval = debugfs_create_file("rcuhier", 0444, rcudir, |
| 294 | NULL, &rcuhier_fops); | 312 | NULL, &rcuhier_fops); |
| 295 | if (!hierdir) | 313 | if (!retval) |
| 296 | goto free_out; | 314 | goto free_out; |
| 297 | 315 | ||
| 298 | rcu_pendingdir = debugfs_create_file("rcu_pending", 0444, rcudir, | 316 | retval = debugfs_create_file("rcu_pending", 0444, rcudir, |
| 299 | NULL, &rcu_pending_fops); | 317 | NULL, &rcu_pending_fops); |
| 300 | if (!rcu_pendingdir) | 318 | if (!retval) |
| 301 | goto free_out; | 319 | goto free_out; |
| 302 | return 0; | 320 | return 0; |
| 303 | free_out: | 321 | free_out: |
| 304 | if (datadir) | 322 | debugfs_remove_recursive(rcudir); |
| 305 | debugfs_remove(datadir); | ||
| 306 | if (datadir_csv) | ||
| 307 | debugfs_remove(datadir_csv); | ||
| 308 | if (gpdir) | ||
| 309 | debugfs_remove(gpdir); | ||
| 310 | debugfs_remove(rcudir); | ||
| 311 | out: | ||
| 312 | return 1; | 323 | return 1; |
| 313 | } | 324 | } |
| 314 | 325 | ||
| 315 | static void __exit rcuclassic_trace_cleanup(void) | 326 | static void __exit rcuclassic_trace_cleanup(void) |
| 316 | { | 327 | { |
| 317 | debugfs_remove(datadir); | 328 | debugfs_remove_recursive(rcudir); |
| 318 | debugfs_remove(datadir_csv); | ||
| 319 | debugfs_remove(gpdir); | ||
| 320 | debugfs_remove(hierdir); | ||
| 321 | debugfs_remove(rcu_pendingdir); | ||
| 322 | debugfs_remove(rcudir); | ||
| 323 | } | 329 | } |
| 324 | 330 | ||
| 325 | 331 | ||
diff --git a/kernel/sched.c b/kernel/sched.c index 1b59e265273b..e27a53685ed9 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
| @@ -64,7 +64,6 @@ | |||
| 64 | #include <linux/tsacct_kern.h> | 64 | #include <linux/tsacct_kern.h> |
| 65 | #include <linux/kprobes.h> | 65 | #include <linux/kprobes.h> |
| 66 | #include <linux/delayacct.h> | 66 | #include <linux/delayacct.h> |
| 67 | #include <linux/reciprocal_div.h> | ||
| 68 | #include <linux/unistd.h> | 67 | #include <linux/unistd.h> |
| 69 | #include <linux/pagemap.h> | 68 | #include <linux/pagemap.h> |
| 70 | #include <linux/hrtimer.h> | 69 | #include <linux/hrtimer.h> |
| @@ -120,30 +119,8 @@ | |||
| 120 | */ | 119 | */ |
| 121 | #define RUNTIME_INF ((u64)~0ULL) | 120 | #define RUNTIME_INF ((u64)~0ULL) |
| 122 | 121 | ||
| 123 | #ifdef CONFIG_SMP | ||
| 124 | |||
| 125 | static void double_rq_lock(struct rq *rq1, struct rq *rq2); | 122 | static void double_rq_lock(struct rq *rq1, struct rq *rq2); |
| 126 | 123 | ||
| 127 | /* | ||
| 128 | * Divide a load by a sched group cpu_power : (load / sg->__cpu_power) | ||
| 129 | * Since cpu_power is a 'constant', we can use a reciprocal divide. | ||
| 130 | */ | ||
| 131 | static inline u32 sg_div_cpu_power(const struct sched_group *sg, u32 load) | ||
| 132 | { | ||
| 133 | return reciprocal_divide(load, sg->reciprocal_cpu_power); | ||
| 134 | } | ||
| 135 | |||
| 136 | /* | ||
| 137 | * Each time a sched group cpu_power is changed, | ||
| 138 | * we must compute its reciprocal value | ||
| 139 | */ | ||
| 140 | static inline void sg_inc_cpu_power(struct sched_group *sg, u32 val) | ||
| 141 | { | ||
| 142 | sg->__cpu_power += val; | ||
| 143 | sg->reciprocal_cpu_power = reciprocal_value(sg->__cpu_power); | ||
| 144 | } | ||
| 145 | #endif | ||
| 146 | |||
| 147 | static inline int rt_policy(int policy) | 124 | static inline int rt_policy(int policy) |
| 148 | { | 125 | { |
| 149 | if (unlikely(policy == SCHED_FIFO || policy == SCHED_RR)) | 126 | if (unlikely(policy == SCHED_FIFO || policy == SCHED_RR)) |
| @@ -309,8 +286,8 @@ void set_tg_uid(struct user_struct *user) | |||
| 309 | 286 | ||
| 310 | /* | 287 | /* |
| 311 | * Root task group. | 288 | * Root task group. |
| 312 | * Every UID task group (including init_task_group aka UID-0) will | 289 | * Every UID task group (including init_task_group aka UID-0) will |
| 313 | * be a child to this group. | 290 | * be a child to this group. |
| 314 | */ | 291 | */ |
| 315 | struct task_group root_task_group; | 292 | struct task_group root_task_group; |
| 316 | 293 | ||
| @@ -318,7 +295,7 @@ struct task_group root_task_group; | |||
| 318 | /* Default task group's sched entity on each cpu */ | 295 | /* Default task group's sched entity on each cpu */ |
| 319 | static DEFINE_PER_CPU(struct sched_entity, init_sched_entity); | 296 | static DEFINE_PER_CPU(struct sched_entity, init_sched_entity); |
| 320 | /* Default task group's cfs_rq on each cpu */ | 297 | /* Default task group's cfs_rq on each cpu */ |
| 321 | static DEFINE_PER_CPU(struct cfs_rq, init_cfs_rq) ____cacheline_aligned_in_smp; | 298 | static DEFINE_PER_CPU(struct cfs_rq, init_tg_cfs_rq) ____cacheline_aligned_in_smp; |
| 322 | #endif /* CONFIG_FAIR_GROUP_SCHED */ | 299 | #endif /* CONFIG_FAIR_GROUP_SCHED */ |
| 323 | 300 | ||
| 324 | #ifdef CONFIG_RT_GROUP_SCHED | 301 | #ifdef CONFIG_RT_GROUP_SCHED |
| @@ -616,6 +593,7 @@ struct rq { | |||
| 616 | 593 | ||
| 617 | unsigned char idle_at_tick; | 594 | unsigned char idle_at_tick; |
| 618 | /* For active balancing */ | 595 | /* For active balancing */ |
| 596 | int post_schedule; | ||
| 619 | int active_balance; | 597 | int active_balance; |
| 620 | int push_cpu; | 598 | int push_cpu; |
| 621 | /* cpu of this runqueue: */ | 599 | /* cpu of this runqueue: */ |
| @@ -626,6 +604,9 @@ struct rq { | |||
| 626 | 604 | ||
| 627 | struct task_struct *migration_thread; | 605 | struct task_struct *migration_thread; |
| 628 | struct list_head migration_queue; | 606 | struct list_head migration_queue; |
| 607 | |||
| 608 | u64 rt_avg; | ||
| 609 | u64 age_stamp; | ||
| 629 | #endif | 610 | #endif |
| 630 | 611 | ||
| 631 | /* calc_load related fields */ | 612 | /* calc_load related fields */ |
| @@ -693,6 +674,7 @@ static inline int cpu_of(struct rq *rq) | |||
| 693 | #define this_rq() (&__get_cpu_var(runqueues)) | 674 | #define this_rq() (&__get_cpu_var(runqueues)) |
| 694 | #define task_rq(p) cpu_rq(task_cpu(p)) | 675 | #define task_rq(p) cpu_rq(task_cpu(p)) |
| 695 | #define cpu_curr(cpu) (cpu_rq(cpu)->curr) | 676 | #define cpu_curr(cpu) (cpu_rq(cpu)->curr) |
| 677 | #define raw_rq() (&__raw_get_cpu_var(runqueues)) | ||
| 696 | 678 | ||
| 697 | inline void update_rq_clock(struct rq *rq) | 679 | inline void update_rq_clock(struct rq *rq) |
| 698 | { | 680 | { |
| @@ -861,6 +843,14 @@ unsigned int sysctl_sched_shares_ratelimit = 250000; | |||
| 861 | unsigned int sysctl_sched_shares_thresh = 4; | 843 | unsigned int sysctl_sched_shares_thresh = 4; |
| 862 | 844 | ||
| 863 | /* | 845 | /* |
| 846 | * period over which we average the RT time consumption, measured | ||
| 847 | * in ms. | ||
| 848 | * | ||
| 849 | * default: 1s | ||
| 850 | */ | ||
| 851 | const_debug unsigned int sysctl_sched_time_avg = MSEC_PER_SEC; | ||
| 852 | |||
| 853 | /* | ||
| 864 | * period over which we measure -rt task cpu usage in us. | 854 | * period over which we measure -rt task cpu usage in us. |
| 865 | * default: 1s | 855 | * default: 1s |
| 866 | */ | 856 | */ |
| @@ -1278,12 +1268,37 @@ void wake_up_idle_cpu(int cpu) | |||
| 1278 | } | 1268 | } |
| 1279 | #endif /* CONFIG_NO_HZ */ | 1269 | #endif /* CONFIG_NO_HZ */ |
| 1280 | 1270 | ||
| 1271 | static u64 sched_avg_period(void) | ||
| 1272 | { | ||
| 1273 | return (u64)sysctl_sched_time_avg * NSEC_PER_MSEC / 2; | ||
| 1274 | } | ||
| 1275 | |||
| 1276 | static void sched_avg_update(struct rq *rq) | ||
| 1277 | { | ||
| 1278 | s64 period = sched_avg_period(); | ||
| 1279 | |||
| 1280 | while ((s64)(rq->clock - rq->age_stamp) > period) { | ||
| 1281 | rq->age_stamp += period; | ||
| 1282 | rq->rt_avg /= 2; | ||
| 1283 | } | ||
| 1284 | } | ||
| 1285 | |||
| 1286 | static void sched_rt_avg_update(struct rq *rq, u64 rt_delta) | ||
| 1287 | { | ||
| 1288 | rq->rt_avg += rt_delta; | ||
| 1289 | sched_avg_update(rq); | ||
| 1290 | } | ||
| 1291 | |||
| 1281 | #else /* !CONFIG_SMP */ | 1292 | #else /* !CONFIG_SMP */ |
| 1282 | static void resched_task(struct task_struct *p) | 1293 | static void resched_task(struct task_struct *p) |
| 1283 | { | 1294 | { |
| 1284 | assert_spin_locked(&task_rq(p)->lock); | 1295 | assert_spin_locked(&task_rq(p)->lock); |
| 1285 | set_tsk_need_resched(p); | 1296 | set_tsk_need_resched(p); |
| 1286 | } | 1297 | } |
| 1298 | |||
| 1299 | static void sched_rt_avg_update(struct rq *rq, u64 rt_delta) | ||
| 1300 | { | ||
| 1301 | } | ||
| 1287 | #endif /* CONFIG_SMP */ | 1302 | #endif /* CONFIG_SMP */ |
| 1288 | 1303 | ||
| 1289 | #if BITS_PER_LONG == 32 | 1304 | #if BITS_PER_LONG == 32 |
| @@ -1513,28 +1528,35 @@ static unsigned long cpu_avg_load_per_task(int cpu) | |||
| 1513 | 1528 | ||
| 1514 | #ifdef CONFIG_FAIR_GROUP_SCHED | 1529 | #ifdef CONFIG_FAIR_GROUP_SCHED |
| 1515 | 1530 | ||
| 1531 | struct update_shares_data { | ||
| 1532 | unsigned long rq_weight[NR_CPUS]; | ||
| 1533 | }; | ||
| 1534 | |||
| 1535 | static DEFINE_PER_CPU(struct update_shares_data, update_shares_data); | ||
| 1536 | |||
| 1516 | static void __set_se_shares(struct sched_entity *se, unsigned long shares); | 1537 | static void __set_se_shares(struct sched_entity *se, unsigned long shares); |
| 1517 | 1538 | ||
| 1518 | /* | 1539 | /* |
| 1519 | * Calculate and set the cpu's group shares. | 1540 | * Calculate and set the cpu's group shares. |
| 1520 | */ | 1541 | */ |
| 1521 | static void | 1542 | static void update_group_shares_cpu(struct task_group *tg, int cpu, |
| 1522 | update_group_shares_cpu(struct task_group *tg, int cpu, | 1543 | unsigned long sd_shares, |
| 1523 | unsigned long sd_shares, unsigned long sd_rq_weight) | 1544 | unsigned long sd_rq_weight, |
| 1545 | struct update_shares_data *usd) | ||
| 1524 | { | 1546 | { |
| 1525 | unsigned long shares; | 1547 | unsigned long shares, rq_weight; |
| 1526 | unsigned long rq_weight; | 1548 | int boost = 0; |
| 1527 | |||
| 1528 | if (!tg->se[cpu]) | ||
| 1529 | return; | ||
| 1530 | 1549 | ||
| 1531 | rq_weight = tg->cfs_rq[cpu]->rq_weight; | 1550 | rq_weight = usd->rq_weight[cpu]; |
| 1551 | if (!rq_weight) { | ||
| 1552 | boost = 1; | ||
| 1553 | rq_weight = NICE_0_LOAD; | ||
| 1554 | } | ||
| 1532 | 1555 | ||
| 1533 | /* | 1556 | /* |
| 1534 | * \Sum shares * rq_weight | 1557 | * \Sum_j shares_j * rq_weight_i |
| 1535 | * shares = ----------------------- | 1558 | * shares_i = ----------------------------- |
| 1536 | * \Sum rq_weight | 1559 | * \Sum_j rq_weight_j |
| 1537 | * | ||
| 1538 | */ | 1560 | */ |
| 1539 | shares = (sd_shares * rq_weight) / sd_rq_weight; | 1561 | shares = (sd_shares * rq_weight) / sd_rq_weight; |
| 1540 | shares = clamp_t(unsigned long, shares, MIN_SHARES, MAX_SHARES); | 1562 | shares = clamp_t(unsigned long, shares, MIN_SHARES, MAX_SHARES); |
| @@ -1545,8 +1567,8 @@ update_group_shares_cpu(struct task_group *tg, int cpu, | |||
| 1545 | unsigned long flags; | 1567 | unsigned long flags; |
| 1546 | 1568 | ||
| 1547 | spin_lock_irqsave(&rq->lock, flags); | 1569 | spin_lock_irqsave(&rq->lock, flags); |
| 1548 | tg->cfs_rq[cpu]->shares = shares; | 1570 | tg->cfs_rq[cpu]->rq_weight = boost ? 0 : rq_weight; |
| 1549 | 1571 | tg->cfs_rq[cpu]->shares = boost ? 0 : shares; | |
| 1550 | __set_se_shares(tg->se[cpu], shares); | 1572 | __set_se_shares(tg->se[cpu], shares); |
| 1551 | spin_unlock_irqrestore(&rq->lock, flags); | 1573 | spin_unlock_irqrestore(&rq->lock, flags); |
| 1552 | } | 1574 | } |
| @@ -1559,22 +1581,30 @@ update_group_shares_cpu(struct task_group *tg, int cpu, | |||
| 1559 | */ | 1581 | */ |
| 1560 | static int tg_shares_up(struct task_group *tg, void *data) | 1582 | static int tg_shares_up(struct task_group *tg, void *data) |
| 1561 | { | 1583 | { |
| 1562 | unsigned long weight, rq_weight = 0; | 1584 | unsigned long weight, rq_weight = 0, shares = 0; |
| 1563 | unsigned long shares = 0; | 1585 | struct update_shares_data *usd; |
| 1564 | struct sched_domain *sd = data; | 1586 | struct sched_domain *sd = data; |
| 1587 | unsigned long flags; | ||
| 1565 | int i; | 1588 | int i; |
| 1566 | 1589 | ||
| 1590 | if (!tg->se[0]) | ||
| 1591 | return 0; | ||
| 1592 | |||
| 1593 | local_irq_save(flags); | ||
| 1594 | usd = &__get_cpu_var(update_shares_data); | ||
| 1595 | |||
| 1567 | for_each_cpu(i, sched_domain_span(sd)) { | 1596 | for_each_cpu(i, sched_domain_span(sd)) { |
| 1597 | weight = tg->cfs_rq[i]->load.weight; | ||
| 1598 | usd->rq_weight[i] = weight; | ||
| 1599 | |||
| 1568 | /* | 1600 | /* |
| 1569 | * If there are currently no tasks on the cpu pretend there | 1601 | * If there are currently no tasks on the cpu pretend there |
| 1570 | * is one of average load so that when a new task gets to | 1602 | * is one of average load so that when a new task gets to |
| 1571 | * run here it will not get delayed by group starvation. | 1603 | * run here it will not get delayed by group starvation. |
| 1572 | */ | 1604 | */ |
| 1573 | weight = tg->cfs_rq[i]->load.weight; | ||
| 1574 | if (!weight) | 1605 | if (!weight) |
| 1575 | weight = NICE_0_LOAD; | 1606 | weight = NICE_0_LOAD; |
| 1576 | 1607 | ||
| 1577 | tg->cfs_rq[i]->rq_weight = weight; | ||
| 1578 | rq_weight += weight; | 1608 | rq_weight += weight; |
| 1579 | shares += tg->cfs_rq[i]->shares; | 1609 | shares += tg->cfs_rq[i]->shares; |
| 1580 | } | 1610 | } |
| @@ -1586,7 +1616,9 @@ static int tg_shares_up(struct task_group *tg, void *data) | |||
| 1586 | shares = tg->shares; | 1616 | shares = tg->shares; |
| 1587 | 1617 | ||
| 1588 | for_each_cpu(i, sched_domain_span(sd)) | 1618 | for_each_cpu(i, sched_domain_span(sd)) |
| 1589 | update_group_shares_cpu(tg, i, shares, rq_weight); | 1619 | update_group_shares_cpu(tg, i, shares, rq_weight, usd); |
| 1620 | |||
| 1621 | local_irq_restore(flags); | ||
| 1590 | 1622 | ||
| 1591 | return 0; | 1623 | return 0; |
| 1592 | } | 1624 | } |
| @@ -1616,8 +1648,14 @@ static int tg_load_down(struct task_group *tg, void *data) | |||
| 1616 | 1648 | ||
| 1617 | static void update_shares(struct sched_domain *sd) | 1649 | static void update_shares(struct sched_domain *sd) |
| 1618 | { | 1650 | { |
| 1619 | u64 now = cpu_clock(raw_smp_processor_id()); | 1651 | s64 elapsed; |
| 1620 | s64 elapsed = now - sd->last_update; | 1652 | u64 now; |
| 1653 | |||
| 1654 | if (root_task_group_empty()) | ||
| 1655 | return; | ||
| 1656 | |||
| 1657 | now = cpu_clock(raw_smp_processor_id()); | ||
| 1658 | elapsed = now - sd->last_update; | ||
| 1621 | 1659 | ||
| 1622 | if (elapsed >= (s64)(u64)sysctl_sched_shares_ratelimit) { | 1660 | if (elapsed >= (s64)(u64)sysctl_sched_shares_ratelimit) { |
| 1623 | sd->last_update = now; | 1661 | sd->last_update = now; |
| @@ -1627,6 +1665,9 @@ static void update_shares(struct sched_domain *sd) | |||
| 1627 | 1665 | ||
| 1628 | static void update_shares_locked(struct rq *rq, struct sched_domain *sd) | 1666 | static void update_shares_locked(struct rq *rq, struct sched_domain *sd) |
| 1629 | { | 1667 | { |
| 1668 | if (root_task_group_empty()) | ||
| 1669 | return; | ||
| 1670 | |||
| 1630 | spin_unlock(&rq->lock); | 1671 | spin_unlock(&rq->lock); |
| 1631 | update_shares(sd); | 1672 | update_shares(sd); |
| 1632 | spin_lock(&rq->lock); | 1673 | spin_lock(&rq->lock); |
| @@ -1634,6 +1675,9 @@ static void update_shares_locked(struct rq *rq, struct sched_domain *sd) | |||
| 1634 | 1675 | ||
| 1635 | static void update_h_load(long cpu) | 1676 | static void update_h_load(long cpu) |
| 1636 | { | 1677 | { |
| 1678 | if (root_task_group_empty()) | ||
| 1679 | return; | ||
| 1680 | |||
| 1637 | walk_tg_tree(tg_load_down, tg_nop, (void *)cpu); | 1681 | walk_tg_tree(tg_load_down, tg_nop, (void *)cpu); |
| 1638 | } | 1682 | } |
| 1639 | 1683 | ||
| @@ -2268,8 +2312,7 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p, int this_cpu) | |||
| 2268 | } | 2312 | } |
| 2269 | 2313 | ||
| 2270 | /* Adjust by relative CPU power of the group */ | 2314 | /* Adjust by relative CPU power of the group */ |
| 2271 | avg_load = sg_div_cpu_power(group, | 2315 | avg_load = (avg_load * SCHED_LOAD_SCALE) / group->cpu_power; |
| 2272 | avg_load * SCHED_LOAD_SCALE); | ||
| 2273 | 2316 | ||
| 2274 | if (local_group) { | 2317 | if (local_group) { |
| 2275 | this_load = avg_load; | 2318 | this_load = avg_load; |
| @@ -2637,9 +2680,32 @@ void sched_fork(struct task_struct *p, int clone_flags) | |||
| 2637 | set_task_cpu(p, cpu); | 2680 | set_task_cpu(p, cpu); |
| 2638 | 2681 | ||
| 2639 | /* | 2682 | /* |
| 2640 | * Make sure we do not leak PI boosting priority to the child: | 2683 | * Make sure we do not leak PI boosting priority to the child. |
| 2641 | */ | 2684 | */ |
| 2642 | p->prio = current->normal_prio; | 2685 | p->prio = current->normal_prio; |
| 2686 | |||
| 2687 | /* | ||
| 2688 | * Revert to default priority/policy on fork if requested. | ||
| 2689 | */ | ||
| 2690 | if (unlikely(p->sched_reset_on_fork)) { | ||
| 2691 | if (p->policy == SCHED_FIFO || p->policy == SCHED_RR) | ||
| 2692 | p->policy = SCHED_NORMAL; | ||
| 2693 | |||
| 2694 | if (p->normal_prio < DEFAULT_PRIO) | ||
| 2695 | p->prio = DEFAULT_PRIO; | ||
| 2696 | |||
| 2697 | if (PRIO_TO_NICE(p->static_prio) < 0) { | ||
| 2698 | p->static_prio = NICE_TO_PRIO(0); | ||
| 2699 | set_load_weight(p); | ||
| 2700 | } | ||
| 2701 | |||
| 2702 | /* | ||
| 2703 | * We don't need the reset flag anymore after the fork. It has | ||
| 2704 | * fulfilled its duty: | ||
| 2705 | */ | ||
| 2706 | p->sched_reset_on_fork = 0; | ||
| 2707 | } | ||
| 2708 | |||
| 2643 | if (!rt_prio(p->prio)) | 2709 | if (!rt_prio(p->prio)) |
| 2644 | p->sched_class = &fair_sched_class; | 2710 | p->sched_class = &fair_sched_class; |
| 2645 | 2711 | ||
| @@ -2796,12 +2862,6 @@ static void finish_task_switch(struct rq *rq, struct task_struct *prev) | |||
| 2796 | { | 2862 | { |
| 2797 | struct mm_struct *mm = rq->prev_mm; | 2863 | struct mm_struct *mm = rq->prev_mm; |
| 2798 | long prev_state; | 2864 | long prev_state; |
| 2799 | #ifdef CONFIG_SMP | ||
| 2800 | int post_schedule = 0; | ||
| 2801 | |||
| 2802 | if (current->sched_class->needs_post_schedule) | ||
| 2803 | post_schedule = current->sched_class->needs_post_schedule(rq); | ||
| 2804 | #endif | ||
| 2805 | 2865 | ||
| 2806 | rq->prev_mm = NULL; | 2866 | rq->prev_mm = NULL; |
| 2807 | 2867 | ||
| @@ -2820,10 +2880,6 @@ static void finish_task_switch(struct rq *rq, struct task_struct *prev) | |||
| 2820 | finish_arch_switch(prev); | 2880 | finish_arch_switch(prev); |
| 2821 | perf_counter_task_sched_in(current, cpu_of(rq)); | 2881 | perf_counter_task_sched_in(current, cpu_of(rq)); |
| 2822 | finish_lock_switch(rq, prev); | 2882 | finish_lock_switch(rq, prev); |
| 2823 | #ifdef CONFIG_SMP | ||
| 2824 | if (post_schedule) | ||
| 2825 | current->sched_class->post_schedule(rq); | ||
| 2826 | #endif | ||
| 2827 | 2883 | ||
| 2828 | fire_sched_in_preempt_notifiers(current); | 2884 | fire_sched_in_preempt_notifiers(current); |
| 2829 | if (mm) | 2885 | if (mm) |
| @@ -2838,6 +2894,42 @@ static void finish_task_switch(struct rq *rq, struct task_struct *prev) | |||
| 2838 | } | 2894 | } |
| 2839 | } | 2895 | } |
| 2840 | 2896 | ||
| 2897 | #ifdef CONFIG_SMP | ||
| 2898 | |||
| 2899 | /* assumes rq->lock is held */ | ||
| 2900 | static inline void pre_schedule(struct rq *rq, struct task_struct *prev) | ||
| 2901 | { | ||
| 2902 | if (prev->sched_class->pre_schedule) | ||
| 2903 | prev->sched_class->pre_schedule(rq, prev); | ||
| 2904 | } | ||
| 2905 | |||
| 2906 | /* rq->lock is NOT held, but preemption is disabled */ | ||
| 2907 | static inline void post_schedule(struct rq *rq) | ||
| 2908 | { | ||
| 2909 | if (rq->post_schedule) { | ||
| 2910 | unsigned long flags; | ||
| 2911 | |||
| 2912 | spin_lock_irqsave(&rq->lock, flags); | ||
| 2913 | if (rq->curr->sched_class->post_schedule) | ||
| 2914 | rq->curr->sched_class->post_schedule(rq); | ||
| 2915 | spin_unlock_irqrestore(&rq->lock, flags); | ||
| 2916 | |||
| 2917 | rq->post_schedule = 0; | ||
| 2918 | } | ||
| 2919 | } | ||
| 2920 | |||
| 2921 | #else | ||
| 2922 | |||
| 2923 | static inline void pre_schedule(struct rq *rq, struct task_struct *p) | ||
| 2924 | { | ||
| 2925 | } | ||
| 2926 | |||
| 2927 | static inline void post_schedule(struct rq *rq) | ||
| 2928 | { | ||
| 2929 | } | ||
| 2930 | |||
| 2931 | #endif | ||
| 2932 | |||
| 2841 | /** | 2933 | /** |
| 2842 | * schedule_tail - first thing a freshly forked thread must call. | 2934 | * schedule_tail - first thing a freshly forked thread must call. |
| 2843 | * @prev: the thread we just switched away from. | 2935 | * @prev: the thread we just switched away from. |
| @@ -2848,6 +2940,13 @@ asmlinkage void schedule_tail(struct task_struct *prev) | |||
| 2848 | struct rq *rq = this_rq(); | 2940 | struct rq *rq = this_rq(); |
| 2849 | 2941 | ||
| 2850 | finish_task_switch(rq, prev); | 2942 | finish_task_switch(rq, prev); |
| 2943 | |||
| 2944 | /* | ||
| 2945 | * FIXME: do we need to worry about rq being invalidated by the | ||
| 2946 | * task_switch? | ||
| 2947 | */ | ||
| 2948 | post_schedule(rq); | ||
| 2949 | |||
| 2851 | #ifdef __ARCH_WANT_UNLOCKED_CTXSW | 2950 | #ifdef __ARCH_WANT_UNLOCKED_CTXSW |
| 2852 | /* In this case, finish_task_switch does not reenable preemption */ | 2951 | /* In this case, finish_task_switch does not reenable preemption */ |
| 2853 | preempt_enable(); | 2952 | preempt_enable(); |
| @@ -3379,9 +3478,10 @@ static int move_one_task(struct rq *this_rq, int this_cpu, struct rq *busiest, | |||
| 3379 | { | 3478 | { |
| 3380 | const struct sched_class *class; | 3479 | const struct sched_class *class; |
| 3381 | 3480 | ||
| 3382 | for (class = sched_class_highest; class; class = class->next) | 3481 | for_each_class(class) { |
| 3383 | if (class->move_one_task(this_rq, this_cpu, busiest, sd, idle)) | 3482 | if (class->move_one_task(this_rq, this_cpu, busiest, sd, idle)) |
| 3384 | return 1; | 3483 | return 1; |
| 3484 | } | ||
| 3385 | 3485 | ||
| 3386 | return 0; | 3486 | return 0; |
| 3387 | } | 3487 | } |
| @@ -3544,7 +3644,7 @@ static inline void update_sd_power_savings_stats(struct sched_group *group, | |||
| 3544 | * capacity but still has some space to pick up some load | 3644 | * capacity but still has some space to pick up some load |
| 3545 | * from other group and save more power | 3645 | * from other group and save more power |
| 3546 | */ | 3646 | */ |
| 3547 | if (sgs->sum_nr_running > sgs->group_capacity - 1) | 3647 | if (sgs->sum_nr_running + 1 > sgs->group_capacity) |
| 3548 | return; | 3648 | return; |
| 3549 | 3649 | ||
| 3550 | if (sgs->sum_nr_running > sds->leader_nr_running || | 3650 | if (sgs->sum_nr_running > sds->leader_nr_running || |
| @@ -3611,6 +3711,77 @@ static inline int check_power_save_busiest_group(struct sd_lb_stats *sds, | |||
| 3611 | } | 3711 | } |
| 3612 | #endif /* CONFIG_SCHED_MC || CONFIG_SCHED_SMT */ | 3712 | #endif /* CONFIG_SCHED_MC || CONFIG_SCHED_SMT */ |
| 3613 | 3713 | ||
| 3714 | unsigned long __weak arch_scale_smt_power(struct sched_domain *sd, int cpu) | ||
| 3715 | { | ||
| 3716 | unsigned long weight = cpumask_weight(sched_domain_span(sd)); | ||
| 3717 | unsigned long smt_gain = sd->smt_gain; | ||
| 3718 | |||
| 3719 | smt_gain /= weight; | ||
| 3720 | |||
| 3721 | return smt_gain; | ||
| 3722 | } | ||
| 3723 | |||
| 3724 | unsigned long scale_rt_power(int cpu) | ||
| 3725 | { | ||
| 3726 | struct rq *rq = cpu_rq(cpu); | ||
| 3727 | u64 total, available; | ||
| 3728 | |||
| 3729 | sched_avg_update(rq); | ||
| 3730 | |||
| 3731 | total = sched_avg_period() + (rq->clock - rq->age_stamp); | ||
| 3732 | available = total - rq->rt_avg; | ||
| 3733 | |||
| 3734 | if (unlikely((s64)total < SCHED_LOAD_SCALE)) | ||
| 3735 | total = SCHED_LOAD_SCALE; | ||
| 3736 | |||
| 3737 | total >>= SCHED_LOAD_SHIFT; | ||
| 3738 | |||
| 3739 | return div_u64(available, total); | ||
| 3740 | } | ||
| 3741 | |||
| 3742 | static void update_cpu_power(struct sched_domain *sd, int cpu) | ||
| 3743 | { | ||
| 3744 | unsigned long weight = cpumask_weight(sched_domain_span(sd)); | ||
| 3745 | unsigned long power = SCHED_LOAD_SCALE; | ||
| 3746 | struct sched_group *sdg = sd->groups; | ||
| 3747 | |||
| 3748 | /* here we could scale based on cpufreq */ | ||
| 3749 | |||
| 3750 | if ((sd->flags & SD_SHARE_CPUPOWER) && weight > 1) { | ||
| 3751 | power *= arch_scale_smt_power(sd, cpu); | ||
| 3752 | power >>= SCHED_LOAD_SHIFT; | ||
| 3753 | } | ||
| 3754 | |||
| 3755 | power *= scale_rt_power(cpu); | ||
| 3756 | power >>= SCHED_LOAD_SHIFT; | ||
| 3757 | |||
| 3758 | if (!power) | ||
| 3759 | power = 1; | ||
| 3760 | |||
| 3761 | sdg->cpu_power = power; | ||
| 3762 | } | ||
| 3763 | |||
| 3764 | static void update_group_power(struct sched_domain *sd, int cpu) | ||
| 3765 | { | ||
| 3766 | struct sched_domain *child = sd->child; | ||
| 3767 | struct sched_group *group, *sdg = sd->groups; | ||
| 3768 | unsigned long power; | ||
| 3769 | |||
| 3770 | if (!child) { | ||
| 3771 | update_cpu_power(sd, cpu); | ||
| 3772 | return; | ||
| 3773 | } | ||
| 3774 | |||
| 3775 | power = 0; | ||
| 3776 | |||
| 3777 | group = child->groups; | ||
| 3778 | do { | ||
| 3779 | power += group->cpu_power; | ||
| 3780 | group = group->next; | ||
| 3781 | } while (group != child->groups); | ||
| 3782 | |||
| 3783 | sdg->cpu_power = power; | ||
| 3784 | } | ||
| 3614 | 3785 | ||
| 3615 | /** | 3786 | /** |
| 3616 | * update_sg_lb_stats - Update sched_group's statistics for load balancing. | 3787 | * update_sg_lb_stats - Update sched_group's statistics for load balancing. |
| @@ -3624,7 +3795,8 @@ static inline int check_power_save_busiest_group(struct sd_lb_stats *sds, | |||
| 3624 | * @balance: Should we balance. | 3795 | * @balance: Should we balance. |
| 3625 | * @sgs: variable to hold the statistics for this group. | 3796 | * @sgs: variable to hold the statistics for this group. |
| 3626 | */ | 3797 | */ |
| 3627 | static inline void update_sg_lb_stats(struct sched_group *group, int this_cpu, | 3798 | static inline void update_sg_lb_stats(struct sched_domain *sd, |
| 3799 | struct sched_group *group, int this_cpu, | ||
| 3628 | enum cpu_idle_type idle, int load_idx, int *sd_idle, | 3800 | enum cpu_idle_type idle, int load_idx, int *sd_idle, |
| 3629 | int local_group, const struct cpumask *cpus, | 3801 | int local_group, const struct cpumask *cpus, |
| 3630 | int *balance, struct sg_lb_stats *sgs) | 3802 | int *balance, struct sg_lb_stats *sgs) |
| @@ -3635,8 +3807,11 @@ static inline void update_sg_lb_stats(struct sched_group *group, int this_cpu, | |||
| 3635 | unsigned long sum_avg_load_per_task; | 3807 | unsigned long sum_avg_load_per_task; |
| 3636 | unsigned long avg_load_per_task; | 3808 | unsigned long avg_load_per_task; |
| 3637 | 3809 | ||
| 3638 | if (local_group) | 3810 | if (local_group) { |
| 3639 | balance_cpu = group_first_cpu(group); | 3811 | balance_cpu = group_first_cpu(group); |
| 3812 | if (balance_cpu == this_cpu) | ||
| 3813 | update_group_power(sd, this_cpu); | ||
| 3814 | } | ||
| 3640 | 3815 | ||
| 3641 | /* Tally up the load of all CPUs in the group */ | 3816 | /* Tally up the load of all CPUs in the group */ |
| 3642 | sum_avg_load_per_task = avg_load_per_task = 0; | 3817 | sum_avg_load_per_task = avg_load_per_task = 0; |
| @@ -3685,8 +3860,7 @@ static inline void update_sg_lb_stats(struct sched_group *group, int this_cpu, | |||
| 3685 | } | 3860 | } |
| 3686 | 3861 | ||
| 3687 | /* Adjust by relative CPU power of the group */ | 3862 | /* Adjust by relative CPU power of the group */ |
| 3688 | sgs->avg_load = sg_div_cpu_power(group, | 3863 | sgs->avg_load = (sgs->group_load * SCHED_LOAD_SCALE) / group->cpu_power; |
| 3689 | sgs->group_load * SCHED_LOAD_SCALE); | ||
| 3690 | 3864 | ||
| 3691 | 3865 | ||
| 3692 | /* | 3866 | /* |
| @@ -3698,14 +3872,14 @@ static inline void update_sg_lb_stats(struct sched_group *group, int this_cpu, | |||
| 3698 | * normalized nr_running number somewhere that negates | 3872 | * normalized nr_running number somewhere that negates |
| 3699 | * the hierarchy? | 3873 | * the hierarchy? |
| 3700 | */ | 3874 | */ |
| 3701 | avg_load_per_task = sg_div_cpu_power(group, | 3875 | avg_load_per_task = (sum_avg_load_per_task * SCHED_LOAD_SCALE) / |
| 3702 | sum_avg_load_per_task * SCHED_LOAD_SCALE); | 3876 | group->cpu_power; |
| 3703 | 3877 | ||
| 3704 | if ((max_cpu_load - min_cpu_load) > 2*avg_load_per_task) | 3878 | if ((max_cpu_load - min_cpu_load) > 2*avg_load_per_task) |
| 3705 | sgs->group_imb = 1; | 3879 | sgs->group_imb = 1; |
| 3706 | 3880 | ||
| 3707 | sgs->group_capacity = group->__cpu_power / SCHED_LOAD_SCALE; | 3881 | sgs->group_capacity = |
| 3708 | 3882 | DIV_ROUND_CLOSEST(group->cpu_power, SCHED_LOAD_SCALE); | |
| 3709 | } | 3883 | } |
| 3710 | 3884 | ||
| 3711 | /** | 3885 | /** |
| @@ -3723,9 +3897,13 @@ static inline void update_sd_lb_stats(struct sched_domain *sd, int this_cpu, | |||
| 3723 | const struct cpumask *cpus, int *balance, | 3897 | const struct cpumask *cpus, int *balance, |
| 3724 | struct sd_lb_stats *sds) | 3898 | struct sd_lb_stats *sds) |
| 3725 | { | 3899 | { |
| 3900 | struct sched_domain *child = sd->child; | ||
| 3726 | struct sched_group *group = sd->groups; | 3901 | struct sched_group *group = sd->groups; |
| 3727 | struct sg_lb_stats sgs; | 3902 | struct sg_lb_stats sgs; |
| 3728 | int load_idx; | 3903 | int load_idx, prefer_sibling = 0; |
| 3904 | |||
| 3905 | if (child && child->flags & SD_PREFER_SIBLING) | ||
| 3906 | prefer_sibling = 1; | ||
| 3729 | 3907 | ||
| 3730 | init_sd_power_savings_stats(sd, sds, idle); | 3908 | init_sd_power_savings_stats(sd, sds, idle); |
| 3731 | load_idx = get_sd_load_idx(sd, idle); | 3909 | load_idx = get_sd_load_idx(sd, idle); |
| @@ -3736,14 +3914,22 @@ static inline void update_sd_lb_stats(struct sched_domain *sd, int this_cpu, | |||
| 3736 | local_group = cpumask_test_cpu(this_cpu, | 3914 | local_group = cpumask_test_cpu(this_cpu, |
| 3737 | sched_group_cpus(group)); | 3915 | sched_group_cpus(group)); |
| 3738 | memset(&sgs, 0, sizeof(sgs)); | 3916 | memset(&sgs, 0, sizeof(sgs)); |
| 3739 | update_sg_lb_stats(group, this_cpu, idle, load_idx, sd_idle, | 3917 | update_sg_lb_stats(sd, group, this_cpu, idle, load_idx, sd_idle, |
| 3740 | local_group, cpus, balance, &sgs); | 3918 | local_group, cpus, balance, &sgs); |
| 3741 | 3919 | ||
| 3742 | if (local_group && balance && !(*balance)) | 3920 | if (local_group && balance && !(*balance)) |
| 3743 | return; | 3921 | return; |
| 3744 | 3922 | ||
| 3745 | sds->total_load += sgs.group_load; | 3923 | sds->total_load += sgs.group_load; |
| 3746 | sds->total_pwr += group->__cpu_power; | 3924 | sds->total_pwr += group->cpu_power; |
| 3925 | |||
| 3926 | /* | ||
| 3927 | * In case the child domain prefers tasks go to siblings | ||
| 3928 | * first, lower the group capacity to one so that we'll try | ||
| 3929 | * and move all the excess tasks away. | ||
| 3930 | */ | ||
| 3931 | if (prefer_sibling) | ||
| 3932 | sgs.group_capacity = min(sgs.group_capacity, 1UL); | ||
| 3747 | 3933 | ||
| 3748 | if (local_group) { | 3934 | if (local_group) { |
| 3749 | sds->this_load = sgs.avg_load; | 3935 | sds->this_load = sgs.avg_load; |
| @@ -3763,7 +3949,6 @@ static inline void update_sd_lb_stats(struct sched_domain *sd, int this_cpu, | |||
| 3763 | update_sd_power_savings_stats(group, sds, local_group, &sgs); | 3949 | update_sd_power_savings_stats(group, sds, local_group, &sgs); |
| 3764 | group = group->next; | 3950 | group = group->next; |
| 3765 | } while (group != sd->groups); | 3951 | } while (group != sd->groups); |
| 3766 | |||
| 3767 | } | 3952 | } |
| 3768 | 3953 | ||
| 3769 | /** | 3954 | /** |
| @@ -3801,28 +3986,28 @@ static inline void fix_small_imbalance(struct sd_lb_stats *sds, | |||
| 3801 | * moving them. | 3986 | * moving them. |
| 3802 | */ | 3987 | */ |
| 3803 | 3988 | ||
| 3804 | pwr_now += sds->busiest->__cpu_power * | 3989 | pwr_now += sds->busiest->cpu_power * |
| 3805 | min(sds->busiest_load_per_task, sds->max_load); | 3990 | min(sds->busiest_load_per_task, sds->max_load); |
| 3806 | pwr_now += sds->this->__cpu_power * | 3991 | pwr_now += sds->this->cpu_power * |
| 3807 | min(sds->this_load_per_task, sds->this_load); | 3992 | min(sds->this_load_per_task, sds->this_load); |
| 3808 | pwr_now /= SCHED_LOAD_SCALE; | 3993 | pwr_now /= SCHED_LOAD_SCALE; |
| 3809 | 3994 | ||
| 3810 | /* Amount of load we'd subtract */ | 3995 | /* Amount of load we'd subtract */ |
| 3811 | tmp = sg_div_cpu_power(sds->busiest, | 3996 | tmp = (sds->busiest_load_per_task * SCHED_LOAD_SCALE) / |
| 3812 | sds->busiest_load_per_task * SCHED_LOAD_SCALE); | 3997 | sds->busiest->cpu_power; |
| 3813 | if (sds->max_load > tmp) | 3998 | if (sds->max_load > tmp) |
| 3814 | pwr_move += sds->busiest->__cpu_power * | 3999 | pwr_move += sds->busiest->cpu_power * |
| 3815 | min(sds->busiest_load_per_task, sds->max_load - tmp); | 4000 | min(sds->busiest_load_per_task, sds->max_load - tmp); |
| 3816 | 4001 | ||
| 3817 | /* Amount of load we'd add */ | 4002 | /* Amount of load we'd add */ |
| 3818 | if (sds->max_load * sds->busiest->__cpu_power < | 4003 | if (sds->max_load * sds->busiest->cpu_power < |
| 3819 | sds->busiest_load_per_task * SCHED_LOAD_SCALE) | 4004 | sds->busiest_load_per_task * SCHED_LOAD_SCALE) |
| 3820 | tmp = sg_div_cpu_power(sds->this, | 4005 | tmp = (sds->max_load * sds->busiest->cpu_power) / |
| 3821 | sds->max_load * sds->busiest->__cpu_power); | 4006 | sds->this->cpu_power; |
| 3822 | else | 4007 | else |
| 3823 | tmp = sg_div_cpu_power(sds->this, | 4008 | tmp = (sds->busiest_load_per_task * SCHED_LOAD_SCALE) / |
| 3824 | sds->busiest_load_per_task * SCHED_LOAD_SCALE); | 4009 | sds->this->cpu_power; |
| 3825 | pwr_move += sds->this->__cpu_power * | 4010 | pwr_move += sds->this->cpu_power * |
| 3826 | min(sds->this_load_per_task, sds->this_load + tmp); | 4011 | min(sds->this_load_per_task, sds->this_load + tmp); |
| 3827 | pwr_move /= SCHED_LOAD_SCALE; | 4012 | pwr_move /= SCHED_LOAD_SCALE; |
| 3828 | 4013 | ||
| @@ -3857,8 +4042,8 @@ static inline void calculate_imbalance(struct sd_lb_stats *sds, int this_cpu, | |||
| 3857 | sds->max_load - sds->busiest_load_per_task); | 4042 | sds->max_load - sds->busiest_load_per_task); |
| 3858 | 4043 | ||
| 3859 | /* How much load to actually move to equalise the imbalance */ | 4044 | /* How much load to actually move to equalise the imbalance */ |
| 3860 | *imbalance = min(max_pull * sds->busiest->__cpu_power, | 4045 | *imbalance = min(max_pull * sds->busiest->cpu_power, |
| 3861 | (sds->avg_load - sds->this_load) * sds->this->__cpu_power) | 4046 | (sds->avg_load - sds->this_load) * sds->this->cpu_power) |
| 3862 | / SCHED_LOAD_SCALE; | 4047 | / SCHED_LOAD_SCALE; |
| 3863 | 4048 | ||
| 3864 | /* | 4049 | /* |
| @@ -3976,6 +4161,26 @@ ret: | |||
| 3976 | return NULL; | 4161 | return NULL; |
| 3977 | } | 4162 | } |
| 3978 | 4163 | ||
| 4164 | static struct sched_group *group_of(int cpu) | ||
| 4165 | { | ||
| 4166 | struct sched_domain *sd = rcu_dereference(cpu_rq(cpu)->sd); | ||
| 4167 | |||
| 4168 | if (!sd) | ||
| 4169 | return NULL; | ||
| 4170 | |||
| 4171 | return sd->groups; | ||
| 4172 | } | ||
| 4173 | |||
| 4174 | static unsigned long power_of(int cpu) | ||
| 4175 | { | ||
| 4176 | struct sched_group *group = group_of(cpu); | ||
| 4177 | |||
| 4178 | if (!group) | ||
| 4179 | return SCHED_LOAD_SCALE; | ||
| 4180 | |||
| 4181 | return group->cpu_power; | ||
| 4182 | } | ||
| 4183 | |||
| 3979 | /* | 4184 | /* |
| 3980 | * find_busiest_queue - find the busiest runqueue among the cpus in group. | 4185 | * find_busiest_queue - find the busiest runqueue among the cpus in group. |
| 3981 | */ | 4186 | */ |
| @@ -3988,15 +4193,18 @@ find_busiest_queue(struct sched_group *group, enum cpu_idle_type idle, | |||
| 3988 | int i; | 4193 | int i; |
| 3989 | 4194 | ||
| 3990 | for_each_cpu(i, sched_group_cpus(group)) { | 4195 | for_each_cpu(i, sched_group_cpus(group)) { |
| 4196 | unsigned long power = power_of(i); | ||
| 4197 | unsigned long capacity = DIV_ROUND_CLOSEST(power, SCHED_LOAD_SCALE); | ||
| 3991 | unsigned long wl; | 4198 | unsigned long wl; |
| 3992 | 4199 | ||
| 3993 | if (!cpumask_test_cpu(i, cpus)) | 4200 | if (!cpumask_test_cpu(i, cpus)) |
| 3994 | continue; | 4201 | continue; |
| 3995 | 4202 | ||
| 3996 | rq = cpu_rq(i); | 4203 | rq = cpu_rq(i); |
| 3997 | wl = weighted_cpuload(i); | 4204 | wl = weighted_cpuload(i) * SCHED_LOAD_SCALE; |
| 4205 | wl /= power; | ||
| 3998 | 4206 | ||
| 3999 | if (rq->nr_running == 1 && wl > imbalance) | 4207 | if (capacity && rq->nr_running == 1 && wl > imbalance) |
| 4000 | continue; | 4208 | continue; |
| 4001 | 4209 | ||
| 4002 | if (wl > max_load) { | 4210 | if (wl > max_load) { |
| @@ -5325,7 +5533,7 @@ need_resched: | |||
| 5325 | preempt_disable(); | 5533 | preempt_disable(); |
| 5326 | cpu = smp_processor_id(); | 5534 | cpu = smp_processor_id(); |
| 5327 | rq = cpu_rq(cpu); | 5535 | rq = cpu_rq(cpu); |
| 5328 | rcu_qsctr_inc(cpu); | 5536 | rcu_sched_qs(cpu); |
| 5329 | prev = rq->curr; | 5537 | prev = rq->curr; |
| 5330 | switch_count = &prev->nivcsw; | 5538 | switch_count = &prev->nivcsw; |
| 5331 | 5539 | ||
| @@ -5349,10 +5557,7 @@ need_resched_nonpreemptible: | |||
| 5349 | switch_count = &prev->nvcsw; | 5557 | switch_count = &prev->nvcsw; |
| 5350 | } | 5558 | } |
| 5351 | 5559 | ||
| 5352 | #ifdef CONFIG_SMP | 5560 | pre_schedule(rq, prev); |
| 5353 | if (prev->sched_class->pre_schedule) | ||
| 5354 | prev->sched_class->pre_schedule(rq, prev); | ||
| 5355 | #endif | ||
| 5356 | 5561 | ||
| 5357 | if (unlikely(!rq->nr_running)) | 5562 | if (unlikely(!rq->nr_running)) |
| 5358 | idle_balance(cpu, rq); | 5563 | idle_balance(cpu, rq); |
| @@ -5378,6 +5583,8 @@ need_resched_nonpreemptible: | |||
| 5378 | } else | 5583 | } else |
| 5379 | spin_unlock_irq(&rq->lock); | 5584 | spin_unlock_irq(&rq->lock); |
| 5380 | 5585 | ||
| 5586 | post_schedule(rq); | ||
| 5587 | |||
| 5381 | if (unlikely(reacquire_kernel_lock(current) < 0)) | 5588 | if (unlikely(reacquire_kernel_lock(current) < 0)) |
| 5382 | goto need_resched_nonpreemptible; | 5589 | goto need_resched_nonpreemptible; |
| 5383 | 5590 | ||
| @@ -6123,17 +6330,25 @@ static int __sched_setscheduler(struct task_struct *p, int policy, | |||
| 6123 | unsigned long flags; | 6330 | unsigned long flags; |
| 6124 | const struct sched_class *prev_class = p->sched_class; | 6331 | const struct sched_class *prev_class = p->sched_class; |
| 6125 | struct rq *rq; | 6332 | struct rq *rq; |
| 6333 | int reset_on_fork; | ||
| 6126 | 6334 | ||
| 6127 | /* may grab non-irq protected spin_locks */ | 6335 | /* may grab non-irq protected spin_locks */ |
| 6128 | BUG_ON(in_interrupt()); | 6336 | BUG_ON(in_interrupt()); |
| 6129 | recheck: | 6337 | recheck: |
| 6130 | /* double check policy once rq lock held */ | 6338 | /* double check policy once rq lock held */ |
| 6131 | if (policy < 0) | 6339 | if (policy < 0) { |
| 6340 | reset_on_fork = p->sched_reset_on_fork; | ||
| 6132 | policy = oldpolicy = p->policy; | 6341 | policy = oldpolicy = p->policy; |
| 6133 | else if (policy != SCHED_FIFO && policy != SCHED_RR && | 6342 | } else { |
| 6134 | policy != SCHED_NORMAL && policy != SCHED_BATCH && | 6343 | reset_on_fork = !!(policy & SCHED_RESET_ON_FORK); |
| 6135 | policy != SCHED_IDLE) | 6344 | policy &= ~SCHED_RESET_ON_FORK; |
| 6136 | return -EINVAL; | 6345 | |
| 6346 | if (policy != SCHED_FIFO && policy != SCHED_RR && | ||
| 6347 | policy != SCHED_NORMAL && policy != SCHED_BATCH && | ||
| 6348 | policy != SCHED_IDLE) | ||
| 6349 | return -EINVAL; | ||
| 6350 | } | ||
| 6351 | |||
| 6137 | /* | 6352 | /* |
| 6138 | * Valid priorities for SCHED_FIFO and SCHED_RR are | 6353 | * Valid priorities for SCHED_FIFO and SCHED_RR are |
| 6139 | * 1..MAX_USER_RT_PRIO-1, valid priority for SCHED_NORMAL, | 6354 | * 1..MAX_USER_RT_PRIO-1, valid priority for SCHED_NORMAL, |
| @@ -6177,6 +6392,10 @@ recheck: | |||
| 6177 | /* can't change other user's priorities */ | 6392 | /* can't change other user's priorities */ |
| 6178 | if (!check_same_owner(p)) | 6393 | if (!check_same_owner(p)) |
| 6179 | return -EPERM; | 6394 | return -EPERM; |
| 6395 | |||
| 6396 | /* Normal users shall not reset the sched_reset_on_fork flag */ | ||
| 6397 | if (p->sched_reset_on_fork && !reset_on_fork) | ||
| 6398 | return -EPERM; | ||
| 6180 | } | 6399 | } |
| 6181 | 6400 | ||
| 6182 | if (user) { | 6401 | if (user) { |
| @@ -6220,6 +6439,8 @@ recheck: | |||
| 6220 | if (running) | 6439 | if (running) |
| 6221 | p->sched_class->put_prev_task(rq, p); | 6440 | p->sched_class->put_prev_task(rq, p); |
| 6222 | 6441 | ||
| 6442 | p->sched_reset_on_fork = reset_on_fork; | ||
| 6443 | |||
| 6223 | oldprio = p->prio; | 6444 | oldprio = p->prio; |
| 6224 | __setscheduler(rq, p, policy, param->sched_priority); | 6445 | __setscheduler(rq, p, policy, param->sched_priority); |
| 6225 | 6446 | ||
| @@ -6336,14 +6557,15 @@ SYSCALL_DEFINE1(sched_getscheduler, pid_t, pid) | |||
| 6336 | if (p) { | 6557 | if (p) { |
| 6337 | retval = security_task_getscheduler(p); | 6558 | retval = security_task_getscheduler(p); |
| 6338 | if (!retval) | 6559 | if (!retval) |
| 6339 | retval = p->policy; | 6560 | retval = p->policy |
| 6561 | | (p->sched_reset_on_fork ? SCHED_RESET_ON_FORK : 0); | ||
| 6340 | } | 6562 | } |
| 6341 | read_unlock(&tasklist_lock); | 6563 | read_unlock(&tasklist_lock); |
| 6342 | return retval; | 6564 | return retval; |
| 6343 | } | 6565 | } |
| 6344 | 6566 | ||
| 6345 | /** | 6567 | /** |
| 6346 | * sys_sched_getscheduler - get the RT priority of a thread | 6568 | * sys_sched_getparam - get the RT priority of a thread |
| 6347 | * @pid: the pid in question. | 6569 | * @pid: the pid in question. |
| 6348 | * @param: structure containing the RT priority. | 6570 | * @param: structure containing the RT priority. |
| 6349 | */ | 6571 | */ |
| @@ -6571,19 +6793,9 @@ static inline int should_resched(void) | |||
| 6571 | 6793 | ||
| 6572 | static void __cond_resched(void) | 6794 | static void __cond_resched(void) |
| 6573 | { | 6795 | { |
| 6574 | #ifdef CONFIG_DEBUG_SPINLOCK_SLEEP | 6796 | add_preempt_count(PREEMPT_ACTIVE); |
| 6575 | __might_sleep(__FILE__, __LINE__); | 6797 | schedule(); |
| 6576 | #endif | 6798 | sub_preempt_count(PREEMPT_ACTIVE); |
| 6577 | /* | ||
| 6578 | * The BKS might be reacquired before we have dropped | ||
| 6579 | * PREEMPT_ACTIVE, which could trigger a second | ||
| 6580 | * cond_resched() call. | ||
| 6581 | */ | ||
| 6582 | do { | ||
| 6583 | add_preempt_count(PREEMPT_ACTIVE); | ||
| 6584 | schedule(); | ||
| 6585 | sub_preempt_count(PREEMPT_ACTIVE); | ||
| 6586 | } while (need_resched()); | ||
| 6587 | } | 6799 | } |
| 6588 | 6800 | ||
| 6589 | int __sched _cond_resched(void) | 6801 | int __sched _cond_resched(void) |
| @@ -6597,18 +6809,20 @@ int __sched _cond_resched(void) | |||
| 6597 | EXPORT_SYMBOL(_cond_resched); | 6809 | EXPORT_SYMBOL(_cond_resched); |
| 6598 | 6810 | ||
| 6599 | /* | 6811 | /* |
| 6600 | * cond_resched_lock() - if a reschedule is pending, drop the given lock, | 6812 | * __cond_resched_lock() - if a reschedule is pending, drop the given lock, |
| 6601 | * call schedule, and on return reacquire the lock. | 6813 | * call schedule, and on return reacquire the lock. |
| 6602 | * | 6814 | * |
| 6603 | * This works OK both with and without CONFIG_PREEMPT. We do strange low-level | 6815 | * This works OK both with and without CONFIG_PREEMPT. We do strange low-level |
| 6604 | * operations here to prevent schedule() from being called twice (once via | 6816 | * operations here to prevent schedule() from being called twice (once via |
| 6605 | * spin_unlock(), once by hand). | 6817 | * spin_unlock(), once by hand). |
| 6606 | */ | 6818 | */ |
| 6607 | int cond_resched_lock(spinlock_t *lock) | 6819 | int __cond_resched_lock(spinlock_t *lock) |
| 6608 | { | 6820 | { |
| 6609 | int resched = should_resched(); | 6821 | int resched = should_resched(); |
| 6610 | int ret = 0; | 6822 | int ret = 0; |
| 6611 | 6823 | ||
| 6824 | lockdep_assert_held(lock); | ||
| 6825 | |||
| 6612 | if (spin_needbreak(lock) || resched) { | 6826 | if (spin_needbreak(lock) || resched) { |
| 6613 | spin_unlock(lock); | 6827 | spin_unlock(lock); |
| 6614 | if (resched) | 6828 | if (resched) |
| @@ -6620,9 +6834,9 @@ int cond_resched_lock(spinlock_t *lock) | |||
| 6620 | } | 6834 | } |
| 6621 | return ret; | 6835 | return ret; |
| 6622 | } | 6836 | } |
| 6623 | EXPORT_SYMBOL(cond_resched_lock); | 6837 | EXPORT_SYMBOL(__cond_resched_lock); |
| 6624 | 6838 | ||
| 6625 | int __sched cond_resched_softirq(void) | 6839 | int __sched __cond_resched_softirq(void) |
| 6626 | { | 6840 | { |
| 6627 | BUG_ON(!in_softirq()); | 6841 | BUG_ON(!in_softirq()); |
| 6628 | 6842 | ||
| @@ -6634,7 +6848,7 @@ int __sched cond_resched_softirq(void) | |||
| 6634 | } | 6848 | } |
| 6635 | return 0; | 6849 | return 0; |
| 6636 | } | 6850 | } |
| 6637 | EXPORT_SYMBOL(cond_resched_softirq); | 6851 | EXPORT_SYMBOL(__cond_resched_softirq); |
| 6638 | 6852 | ||
| 6639 | /** | 6853 | /** |
| 6640 | * yield - yield the current processor to other threads. | 6854 | * yield - yield the current processor to other threads. |
| @@ -6658,11 +6872,13 @@ EXPORT_SYMBOL(yield); | |||
| 6658 | */ | 6872 | */ |
| 6659 | void __sched io_schedule(void) | 6873 | void __sched io_schedule(void) |
| 6660 | { | 6874 | { |
| 6661 | struct rq *rq = &__raw_get_cpu_var(runqueues); | 6875 | struct rq *rq = raw_rq(); |
| 6662 | 6876 | ||
| 6663 | delayacct_blkio_start(); | 6877 | delayacct_blkio_start(); |
| 6664 | atomic_inc(&rq->nr_iowait); | 6878 | atomic_inc(&rq->nr_iowait); |
| 6879 | current->in_iowait = 1; | ||
| 6665 | schedule(); | 6880 | schedule(); |
| 6881 | current->in_iowait = 0; | ||
| 6666 | atomic_dec(&rq->nr_iowait); | 6882 | atomic_dec(&rq->nr_iowait); |
| 6667 | delayacct_blkio_end(); | 6883 | delayacct_blkio_end(); |
| 6668 | } | 6884 | } |
| @@ -6670,12 +6886,14 @@ EXPORT_SYMBOL(io_schedule); | |||
| 6670 | 6886 | ||
| 6671 | long __sched io_schedule_timeout(long timeout) | 6887 | long __sched io_schedule_timeout(long timeout) |
| 6672 | { | 6888 | { |
| 6673 | struct rq *rq = &__raw_get_cpu_var(runqueues); | 6889 | struct rq *rq = raw_rq(); |
| 6674 | long ret; | 6890 | long ret; |
| 6675 | 6891 | ||
| 6676 | delayacct_blkio_start(); | 6892 | delayacct_blkio_start(); |
| 6677 | atomic_inc(&rq->nr_iowait); | 6893 | atomic_inc(&rq->nr_iowait); |
| 6894 | current->in_iowait = 1; | ||
| 6678 | ret = schedule_timeout(timeout); | 6895 | ret = schedule_timeout(timeout); |
| 6896 | current->in_iowait = 0; | ||
| 6679 | atomic_dec(&rq->nr_iowait); | 6897 | atomic_dec(&rq->nr_iowait); |
| 6680 | delayacct_blkio_end(); | 6898 | delayacct_blkio_end(); |
| 6681 | return ret; | 6899 | return ret; |
| @@ -6992,8 +7210,12 @@ int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask) | |||
| 6992 | 7210 | ||
| 6993 | if (migrate_task(p, cpumask_any_and(cpu_online_mask, new_mask), &req)) { | 7211 | if (migrate_task(p, cpumask_any_and(cpu_online_mask, new_mask), &req)) { |
| 6994 | /* Need help from migration thread: drop lock and wait. */ | 7212 | /* Need help from migration thread: drop lock and wait. */ |
| 7213 | struct task_struct *mt = rq->migration_thread; | ||
| 7214 | |||
| 7215 | get_task_struct(mt); | ||
| 6995 | task_rq_unlock(rq, &flags); | 7216 | task_rq_unlock(rq, &flags); |
| 6996 | wake_up_process(rq->migration_thread); | 7217 | wake_up_process(rq->migration_thread); |
| 7218 | put_task_struct(mt); | ||
| 6997 | wait_for_completion(&req.done); | 7219 | wait_for_completion(&req.done); |
| 6998 | tlb_migrate_finish(p->mm); | 7220 | tlb_migrate_finish(p->mm); |
| 6999 | return 0; | 7221 | return 0; |
| @@ -7051,6 +7273,11 @@ fail: | |||
| 7051 | return ret; | 7273 | return ret; |
| 7052 | } | 7274 | } |
| 7053 | 7275 | ||
| 7276 | #define RCU_MIGRATION_IDLE 0 | ||
| 7277 | #define RCU_MIGRATION_NEED_QS 1 | ||
| 7278 | #define RCU_MIGRATION_GOT_QS 2 | ||
| 7279 | #define RCU_MIGRATION_MUST_SYNC 3 | ||
| 7280 | |||
| 7054 | /* | 7281 | /* |
| 7055 | * migration_thread - this is a highprio system thread that performs | 7282 | * migration_thread - this is a highprio system thread that performs |
| 7056 | * thread migration by bumping thread off CPU then 'pushing' onto | 7283 | * thread migration by bumping thread off CPU then 'pushing' onto |
| @@ -7058,6 +7285,7 @@ fail: | |||
| 7058 | */ | 7285 | */ |
| 7059 | static int migration_thread(void *data) | 7286 | static int migration_thread(void *data) |
| 7060 | { | 7287 | { |
| 7288 | int badcpu; | ||
| 7061 | int cpu = (long)data; | 7289 | int cpu = (long)data; |
| 7062 | struct rq *rq; | 7290 | struct rq *rq; |
| 7063 | 7291 | ||
| @@ -7092,8 +7320,17 @@ static int migration_thread(void *data) | |||
| 7092 | req = list_entry(head->next, struct migration_req, list); | 7320 | req = list_entry(head->next, struct migration_req, list); |
| 7093 | list_del_init(head->next); | 7321 | list_del_init(head->next); |
| 7094 | 7322 | ||
| 7095 | spin_unlock(&rq->lock); | 7323 | if (req->task != NULL) { |
| 7096 | __migrate_task(req->task, cpu, req->dest_cpu); | 7324 | spin_unlock(&rq->lock); |
| 7325 | __migrate_task(req->task, cpu, req->dest_cpu); | ||
| 7326 | } else if (likely(cpu == (badcpu = smp_processor_id()))) { | ||
| 7327 | req->dest_cpu = RCU_MIGRATION_GOT_QS; | ||
| 7328 | spin_unlock(&rq->lock); | ||
| 7329 | } else { | ||
| 7330 | req->dest_cpu = RCU_MIGRATION_MUST_SYNC; | ||
| 7331 | spin_unlock(&rq->lock); | ||
| 7332 | WARN_ONCE(1, "migration_thread() on CPU %d, expected %d\n", badcpu, cpu); | ||
| 7333 | } | ||
| 7097 | local_irq_enable(); | 7334 | local_irq_enable(); |
| 7098 | 7335 | ||
| 7099 | complete(&req->done); | 7336 | complete(&req->done); |
| @@ -7625,7 +7862,7 @@ static int __init migration_init(void) | |||
| 7625 | migration_call(&migration_notifier, CPU_ONLINE, cpu); | 7862 | migration_call(&migration_notifier, CPU_ONLINE, cpu); |
| 7626 | register_cpu_notifier(&migration_notifier); | 7863 | register_cpu_notifier(&migration_notifier); |
| 7627 | 7864 | ||
| 7628 | return err; | 7865 | return 0; |
| 7629 | } | 7866 | } |
| 7630 | early_initcall(migration_init); | 7867 | early_initcall(migration_init); |
| 7631 | #endif | 7868 | #endif |
| @@ -7672,7 +7909,7 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, | |||
| 7672 | break; | 7909 | break; |
| 7673 | } | 7910 | } |
| 7674 | 7911 | ||
| 7675 | if (!group->__cpu_power) { | 7912 | if (!group->cpu_power) { |
| 7676 | printk(KERN_CONT "\n"); | 7913 | printk(KERN_CONT "\n"); |
| 7677 | printk(KERN_ERR "ERROR: domain->cpu_power not " | 7914 | printk(KERN_ERR "ERROR: domain->cpu_power not " |
| 7678 | "set\n"); | 7915 | "set\n"); |
| @@ -7696,9 +7933,9 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, | |||
| 7696 | cpulist_scnprintf(str, sizeof(str), sched_group_cpus(group)); | 7933 | cpulist_scnprintf(str, sizeof(str), sched_group_cpus(group)); |
| 7697 | 7934 | ||
| 7698 | printk(KERN_CONT " %s", str); | 7935 | printk(KERN_CONT " %s", str); |
| 7699 | if (group->__cpu_power != SCHED_LOAD_SCALE) { | 7936 | if (group->cpu_power != SCHED_LOAD_SCALE) { |
| 7700 | printk(KERN_CONT " (__cpu_power = %d)", | 7937 | printk(KERN_CONT " (cpu_power = %d)", |
| 7701 | group->__cpu_power); | 7938 | group->cpu_power); |
| 7702 | } | 7939 | } |
| 7703 | 7940 | ||
| 7704 | group = group->next; | 7941 | group = group->next; |
| @@ -7841,7 +8078,7 @@ static void rq_attach_root(struct rq *rq, struct root_domain *rd) | |||
| 7841 | rq->rd = rd; | 8078 | rq->rd = rd; |
| 7842 | 8079 | ||
| 7843 | cpumask_set_cpu(rq->cpu, rd->span); | 8080 | cpumask_set_cpu(rq->cpu, rd->span); |
| 7844 | if (cpumask_test_cpu(rq->cpu, cpu_online_mask)) | 8081 | if (cpumask_test_cpu(rq->cpu, cpu_active_mask)) |
| 7845 | set_rq_online(rq); | 8082 | set_rq_online(rq); |
| 7846 | 8083 | ||
| 7847 | spin_unlock_irqrestore(&rq->lock, flags); | 8084 | spin_unlock_irqrestore(&rq->lock, flags); |
| @@ -7983,7 +8220,7 @@ init_sched_build_groups(const struct cpumask *span, | |||
| 7983 | continue; | 8220 | continue; |
| 7984 | 8221 | ||
| 7985 | cpumask_clear(sched_group_cpus(sg)); | 8222 | cpumask_clear(sched_group_cpus(sg)); |
| 7986 | sg->__cpu_power = 0; | 8223 | sg->cpu_power = 0; |
| 7987 | 8224 | ||
| 7988 | for_each_cpu(j, span) { | 8225 | for_each_cpu(j, span) { |
| 7989 | if (group_fn(j, cpu_map, NULL, tmpmask) != group) | 8226 | if (group_fn(j, cpu_map, NULL, tmpmask) != group) |
| @@ -8091,6 +8328,39 @@ struct static_sched_domain { | |||
| 8091 | DECLARE_BITMAP(span, CONFIG_NR_CPUS); | 8328 | DECLARE_BITMAP(span, CONFIG_NR_CPUS); |
| 8092 | }; | 8329 | }; |
| 8093 | 8330 | ||
| 8331 | struct s_data { | ||
| 8332 | #ifdef CONFIG_NUMA | ||
| 8333 | int sd_allnodes; | ||
| 8334 | cpumask_var_t domainspan; | ||
| 8335 | cpumask_var_t covered; | ||
| 8336 | cpumask_var_t notcovered; | ||
| 8337 | #endif | ||
| 8338 | cpumask_var_t nodemask; | ||
| 8339 | cpumask_var_t this_sibling_map; | ||
| 8340 | cpumask_var_t this_core_map; | ||
| 8341 | cpumask_var_t send_covered; | ||
| 8342 | cpumask_var_t tmpmask; | ||
| 8343 | struct sched_group **sched_group_nodes; | ||
| 8344 | struct root_domain *rd; | ||
| 8345 | }; | ||
| 8346 | |||
| 8347 | enum s_alloc { | ||
| 8348 | sa_sched_groups = 0, | ||
| 8349 | sa_rootdomain, | ||
| 8350 | sa_tmpmask, | ||
| 8351 | sa_send_covered, | ||
| 8352 | sa_this_core_map, | ||
| 8353 | sa_this_sibling_map, | ||
| 8354 | sa_nodemask, | ||
| 8355 | sa_sched_group_nodes, | ||
| 8356 | #ifdef CONFIG_NUMA | ||
| 8357 | sa_notcovered, | ||
| 8358 | sa_covered, | ||
| 8359 | sa_domainspan, | ||
| 8360 | #endif | ||
| 8361 | sa_none, | ||
| 8362 | }; | ||
| 8363 | |||
| 8094 | /* | 8364 | /* |
| 8095 | * SMT sched-domains: | 8365 | * SMT sched-domains: |
| 8096 | */ | 8366 | */ |
| @@ -8208,11 +8478,76 @@ static void init_numa_sched_groups_power(struct sched_group *group_head) | |||
| 8208 | continue; | 8478 | continue; |
| 8209 | } | 8479 | } |
| 8210 | 8480 | ||
| 8211 | sg_inc_cpu_power(sg, sd->groups->__cpu_power); | 8481 | sg->cpu_power += sd->groups->cpu_power; |
| 8212 | } | 8482 | } |
| 8213 | sg = sg->next; | 8483 | sg = sg->next; |
| 8214 | } while (sg != group_head); | 8484 | } while (sg != group_head); |
| 8215 | } | 8485 | } |
| 8486 | |||
| 8487 | static int build_numa_sched_groups(struct s_data *d, | ||
| 8488 | const struct cpumask *cpu_map, int num) | ||
| 8489 | { | ||
| 8490 | struct sched_domain *sd; | ||
| 8491 | struct sched_group *sg, *prev; | ||
| 8492 | int n, j; | ||
| 8493 | |||
| 8494 | cpumask_clear(d->covered); | ||
| 8495 | cpumask_and(d->nodemask, cpumask_of_node(num), cpu_map); | ||
| 8496 | if (cpumask_empty(d->nodemask)) { | ||
| 8497 | d->sched_group_nodes[num] = NULL; | ||
| 8498 | goto out; | ||
| 8499 | } | ||
| 8500 | |||
| 8501 | sched_domain_node_span(num, d->domainspan); | ||
| 8502 | cpumask_and(d->domainspan, d->domainspan, cpu_map); | ||
| 8503 | |||
| 8504 | sg = kmalloc_node(sizeof(struct sched_group) + cpumask_size(), | ||
| 8505 | GFP_KERNEL, num); | ||
| 8506 | if (!sg) { | ||
| 8507 | printk(KERN_WARNING "Can not alloc domain group for node %d\n", | ||
| 8508 | num); | ||
| 8509 | return -ENOMEM; | ||
| 8510 | } | ||
| 8511 | d->sched_group_nodes[num] = sg; | ||
| 8512 | |||
| 8513 | for_each_cpu(j, d->nodemask) { | ||
| 8514 | sd = &per_cpu(node_domains, j).sd; | ||
| 8515 | sd->groups = sg; | ||
| 8516 | } | ||
| 8517 | |||
| 8518 | sg->cpu_power = 0; | ||
| 8519 | cpumask_copy(sched_group_cpus(sg), d->nodemask); | ||
| 8520 | sg->next = sg; | ||
| 8521 | cpumask_or(d->covered, d->covered, d->nodemask); | ||
| 8522 | |||
| 8523 | prev = sg; | ||
| 8524 | for (j = 0; j < nr_node_ids; j++) { | ||
| 8525 | n = (num + j) % nr_node_ids; | ||
| 8526 | cpumask_complement(d->notcovered, d->covered); | ||
| 8527 | cpumask_and(d->tmpmask, d->notcovered, cpu_map); | ||
| 8528 | cpumask_and(d->tmpmask, d->tmpmask, d->domainspan); | ||
| 8529 | if (cpumask_empty(d->tmpmask)) | ||
| 8530 | break; | ||
| 8531 | cpumask_and(d->tmpmask, d->tmpmask, cpumask_of_node(n)); | ||
| 8532 | if (cpumask_empty(d->tmpmask)) | ||
| 8533 | continue; | ||
| 8534 | sg = kmalloc_node(sizeof(struct sched_group) + cpumask_size(), | ||
| 8535 | GFP_KERNEL, num); | ||
| 8536 | if (!sg) { | ||
| 8537 | printk(KERN_WARNING | ||
| 8538 | "Can not alloc domain group for node %d\n", j); | ||
| 8539 | return -ENOMEM; | ||
| 8540 | } | ||
| 8541 | sg->cpu_power = 0; | ||
| 8542 | cpumask_copy(sched_group_cpus(sg), d->tmpmask); | ||
| 8543 | sg->next = prev->next; | ||
| 8544 | cpumask_or(d->covered, d->covered, d->tmpmask); | ||
| 8545 | prev->next = sg; | ||
| 8546 | prev = sg; | ||
| 8547 | } | ||
| 8548 | out: | ||
| 8549 | return 0; | ||
| 8550 | } | ||
| 8216 | #endif /* CONFIG_NUMA */ | 8551 | #endif /* CONFIG_NUMA */ |
| 8217 | 8552 | ||
| 8218 | #ifdef CONFIG_NUMA | 8553 | #ifdef CONFIG_NUMA |
| @@ -8266,15 +8601,13 @@ static void free_sched_groups(const struct cpumask *cpu_map, | |||
| 8266 | * there are asymmetries in the topology. If there are asymmetries, group | 8601 | * there are asymmetries in the topology. If there are asymmetries, group |
| 8267 | * having more cpu_power will pickup more load compared to the group having | 8602 | * having more cpu_power will pickup more load compared to the group having |
| 8268 | * less cpu_power. | 8603 | * less cpu_power. |
| 8269 | * | ||
| 8270 | * cpu_power will be a multiple of SCHED_LOAD_SCALE. This multiple represents | ||
| 8271 | * the maximum number of tasks a group can handle in the presence of other idle | ||
| 8272 | * or lightly loaded groups in the same sched domain. | ||
| 8273 | */ | 8604 | */ |
| 8274 | static void init_sched_groups_power(int cpu, struct sched_domain *sd) | 8605 | static void init_sched_groups_power(int cpu, struct sched_domain *sd) |
| 8275 | { | 8606 | { |
| 8276 | struct sched_domain *child; | 8607 | struct sched_domain *child; |
| 8277 | struct sched_group *group; | 8608 | struct sched_group *group; |
| 8609 | long power; | ||
| 8610 | int weight; | ||
| 8278 | 8611 | ||
| 8279 | WARN_ON(!sd || !sd->groups); | 8612 | WARN_ON(!sd || !sd->groups); |
| 8280 | 8613 | ||
| @@ -8283,28 +8616,32 @@ static void init_sched_groups_power(int cpu, struct sched_domain *sd) | |||
| 8283 | 8616 | ||
| 8284 | child = sd->child; | 8617 | child = sd->child; |
| 8285 | 8618 | ||
| 8286 | sd->groups->__cpu_power = 0; | 8619 | sd->groups->cpu_power = 0; |
| 8287 | 8620 | ||
| 8288 | /* | 8621 | if (!child) { |
| 8289 | * For perf policy, if the groups in child domain share resources | 8622 | power = SCHED_LOAD_SCALE; |
| 8290 | * (for example cores sharing some portions of the cache hierarchy | 8623 | weight = cpumask_weight(sched_domain_span(sd)); |
| 8291 | * or SMT), then set this domain groups cpu_power such that each group | 8624 | /* |
| 8292 | * can handle only one task, when there are other idle groups in the | 8625 | * SMT siblings share the power of a single core. |
| 8293 | * same sched domain. | 8626 | * Usually multiple threads get a better yield out of |
| 8294 | */ | 8627 | * that one core than a single thread would have, |
| 8295 | if (!child || (!(sd->flags & SD_POWERSAVINGS_BALANCE) && | 8628 | * reflect that in sd->smt_gain. |
| 8296 | (child->flags & | 8629 | */ |
| 8297 | (SD_SHARE_CPUPOWER | SD_SHARE_PKG_RESOURCES)))) { | 8630 | if ((sd->flags & SD_SHARE_CPUPOWER) && weight > 1) { |
| 8298 | sg_inc_cpu_power(sd->groups, SCHED_LOAD_SCALE); | 8631 | power *= sd->smt_gain; |
| 8632 | power /= weight; | ||
| 8633 | power >>= SCHED_LOAD_SHIFT; | ||
| 8634 | } | ||
| 8635 | sd->groups->cpu_power += power; | ||
| 8299 | return; | 8636 | return; |
| 8300 | } | 8637 | } |
| 8301 | 8638 | ||
| 8302 | /* | 8639 | /* |
| 8303 | * add cpu_power of each child group to this groups cpu_power | 8640 | * Add cpu_power of each child group to this groups cpu_power. |
| 8304 | */ | 8641 | */ |
| 8305 | group = child->groups; | 8642 | group = child->groups; |
| 8306 | do { | 8643 | do { |
| 8307 | sg_inc_cpu_power(sd->groups, group->__cpu_power); | 8644 | sd->groups->cpu_power += group->cpu_power; |
| 8308 | group = group->next; | 8645 | group = group->next; |
| 8309 | } while (group != child->groups); | 8646 | } while (group != child->groups); |
| 8310 | } | 8647 | } |
| @@ -8378,280 +8715,285 @@ static void set_domain_attribute(struct sched_domain *sd, | |||
| 8378 | } | 8715 | } |
| 8379 | } | 8716 | } |
| 8380 | 8717 | ||
| 8381 | /* | 8718 | static void __free_domain_allocs(struct s_data *d, enum s_alloc what, |
| 8382 | * Build sched domains for a given set of cpus and attach the sched domains | 8719 | const struct cpumask *cpu_map) |
| 8383 | * to the individual cpus | 8720 | { |
| 8384 | */ | 8721 | switch (what) { |
| 8385 | static int __build_sched_domains(const struct cpumask *cpu_map, | 8722 | case sa_sched_groups: |
| 8386 | struct sched_domain_attr *attr) | 8723 | free_sched_groups(cpu_map, d->tmpmask); /* fall through */ |
| 8387 | { | 8724 | d->sched_group_nodes = NULL; |
| 8388 | int i, err = -ENOMEM; | 8725 | case sa_rootdomain: |
| 8389 | struct root_domain *rd; | 8726 | free_rootdomain(d->rd); /* fall through */ |
| 8390 | cpumask_var_t nodemask, this_sibling_map, this_core_map, send_covered, | 8727 | case sa_tmpmask: |
| 8391 | tmpmask; | 8728 | free_cpumask_var(d->tmpmask); /* fall through */ |
| 8729 | case sa_send_covered: | ||
| 8730 | free_cpumask_var(d->send_covered); /* fall through */ | ||
| 8731 | case sa_this_core_map: | ||
| 8732 | free_cpumask_var(d->this_core_map); /* fall through */ | ||
| 8733 | case sa_this_sibling_map: | ||
| 8734 | free_cpumask_var(d->this_sibling_map); /* fall through */ | ||
| 8735 | case sa_nodemask: | ||
| 8736 | free_cpumask_var(d->nodemask); /* fall through */ | ||
| 8737 | case sa_sched_group_nodes: | ||
| 8392 | #ifdef CONFIG_NUMA | 8738 | #ifdef CONFIG_NUMA |
| 8393 | cpumask_var_t domainspan, covered, notcovered; | 8739 | kfree(d->sched_group_nodes); /* fall through */ |
| 8394 | struct sched_group **sched_group_nodes = NULL; | 8740 | case sa_notcovered: |
| 8395 | int sd_allnodes = 0; | 8741 | free_cpumask_var(d->notcovered); /* fall through */ |
| 8396 | 8742 | case sa_covered: | |
| 8397 | if (!alloc_cpumask_var(&domainspan, GFP_KERNEL)) | 8743 | free_cpumask_var(d->covered); /* fall through */ |
| 8398 | goto out; | 8744 | case sa_domainspan: |
| 8399 | if (!alloc_cpumask_var(&covered, GFP_KERNEL)) | 8745 | free_cpumask_var(d->domainspan); /* fall through */ |
| 8400 | goto free_domainspan; | 8746 | #endif |
| 8401 | if (!alloc_cpumask_var(¬covered, GFP_KERNEL)) | 8747 | case sa_none: |
| 8402 | goto free_covered; | 8748 | break; |
| 8403 | #endif | 8749 | } |
| 8404 | 8750 | } | |
| 8405 | if (!alloc_cpumask_var(&nodemask, GFP_KERNEL)) | ||
| 8406 | goto free_notcovered; | ||
| 8407 | if (!alloc_cpumask_var(&this_sibling_map, GFP_KERNEL)) | ||
| 8408 | goto free_nodemask; | ||
| 8409 | if (!alloc_cpumask_var(&this_core_map, GFP_KERNEL)) | ||
| 8410 | goto free_this_sibling_map; | ||
| 8411 | if (!alloc_cpumask_var(&send_covered, GFP_KERNEL)) | ||
| 8412 | goto free_this_core_map; | ||
| 8413 | if (!alloc_cpumask_var(&tmpmask, GFP_KERNEL)) | ||
| 8414 | goto free_send_covered; | ||
| 8415 | 8751 | ||
| 8752 | static enum s_alloc __visit_domain_allocation_hell(struct s_data *d, | ||
| 8753 | const struct cpumask *cpu_map) | ||
| 8754 | { | ||
| 8416 | #ifdef CONFIG_NUMA | 8755 | #ifdef CONFIG_NUMA |
| 8417 | /* | 8756 | if (!alloc_cpumask_var(&d->domainspan, GFP_KERNEL)) |
| 8418 | * Allocate the per-node list of sched groups | 8757 | return sa_none; |
| 8419 | */ | 8758 | if (!alloc_cpumask_var(&d->covered, GFP_KERNEL)) |
| 8420 | sched_group_nodes = kcalloc(nr_node_ids, sizeof(struct sched_group *), | 8759 | return sa_domainspan; |
| 8421 | GFP_KERNEL); | 8760 | if (!alloc_cpumask_var(&d->notcovered, GFP_KERNEL)) |
| 8422 | if (!sched_group_nodes) { | 8761 | return sa_covered; |
| 8762 | /* Allocate the per-node list of sched groups */ | ||
| 8763 | d->sched_group_nodes = kcalloc(nr_node_ids, | ||
| 8764 | sizeof(struct sched_group *), GFP_KERNEL); | ||
| 8765 | if (!d->sched_group_nodes) { | ||
| 8423 | printk(KERN_WARNING "Can not alloc sched group node list\n"); | 8766 | printk(KERN_WARNING "Can not alloc sched group node list\n"); |
| 8424 | goto free_tmpmask; | 8767 | return sa_notcovered; |
| 8425 | } | 8768 | } |
| 8426 | #endif | 8769 | sched_group_nodes_bycpu[cpumask_first(cpu_map)] = d->sched_group_nodes; |
| 8427 | 8770 | #endif | |
| 8428 | rd = alloc_rootdomain(); | 8771 | if (!alloc_cpumask_var(&d->nodemask, GFP_KERNEL)) |
| 8429 | if (!rd) { | 8772 | return sa_sched_group_nodes; |
| 8773 | if (!alloc_cpumask_var(&d->this_sibling_map, GFP_KERNEL)) | ||
| 8774 | return sa_nodemask; | ||
| 8775 | if (!alloc_cpumask_var(&d->this_core_map, GFP_KERNEL)) | ||
| 8776 | return sa_this_sibling_map; | ||
| 8777 | if (!alloc_cpumask_var(&d->send_covered, GFP_KERNEL)) | ||
| 8778 | return sa_this_core_map; | ||
| 8779 | if (!alloc_cpumask_var(&d->tmpmask, GFP_KERNEL)) | ||
| 8780 | return sa_send_covered; | ||
| 8781 | d->rd = alloc_rootdomain(); | ||
| 8782 | if (!d->rd) { | ||
| 8430 | printk(KERN_WARNING "Cannot alloc root domain\n"); | 8783 | printk(KERN_WARNING "Cannot alloc root domain\n"); |
| 8431 | goto free_sched_groups; | 8784 | return sa_tmpmask; |
| 8432 | } | 8785 | } |
| 8786 | return sa_rootdomain; | ||
| 8787 | } | ||
| 8433 | 8788 | ||
| 8789 | static struct sched_domain *__build_numa_sched_domains(struct s_data *d, | ||
| 8790 | const struct cpumask *cpu_map, struct sched_domain_attr *attr, int i) | ||
| 8791 | { | ||
| 8792 | struct sched_domain *sd = NULL; | ||
| 8434 | #ifdef CONFIG_NUMA | 8793 | #ifdef CONFIG_NUMA |
| 8435 | sched_group_nodes_bycpu[cpumask_first(cpu_map)] = sched_group_nodes; | 8794 | struct sched_domain *parent; |
| 8436 | #endif | ||
| 8437 | |||
| 8438 | /* | ||
| 8439 | * Set up domains for cpus specified by the cpu_map. | ||
| 8440 | */ | ||
| 8441 | for_each_cpu(i, cpu_map) { | ||
| 8442 | struct sched_domain *sd = NULL, *p; | ||
| 8443 | |||
| 8444 | cpumask_and(nodemask, cpumask_of_node(cpu_to_node(i)), cpu_map); | ||
| 8445 | |||
| 8446 | #ifdef CONFIG_NUMA | ||
| 8447 | if (cpumask_weight(cpu_map) > | ||
| 8448 | SD_NODES_PER_DOMAIN*cpumask_weight(nodemask)) { | ||
| 8449 | sd = &per_cpu(allnodes_domains, i).sd; | ||
| 8450 | SD_INIT(sd, ALLNODES); | ||
| 8451 | set_domain_attribute(sd, attr); | ||
| 8452 | cpumask_copy(sched_domain_span(sd), cpu_map); | ||
| 8453 | cpu_to_allnodes_group(i, cpu_map, &sd->groups, tmpmask); | ||
| 8454 | p = sd; | ||
| 8455 | sd_allnodes = 1; | ||
| 8456 | } else | ||
| 8457 | p = NULL; | ||
| 8458 | 8795 | ||
| 8459 | sd = &per_cpu(node_domains, i).sd; | 8796 | d->sd_allnodes = 0; |
| 8460 | SD_INIT(sd, NODE); | 8797 | if (cpumask_weight(cpu_map) > |
| 8798 | SD_NODES_PER_DOMAIN * cpumask_weight(d->nodemask)) { | ||
| 8799 | sd = &per_cpu(allnodes_domains, i).sd; | ||
| 8800 | SD_INIT(sd, ALLNODES); | ||
| 8461 | set_domain_attribute(sd, attr); | 8801 | set_domain_attribute(sd, attr); |
| 8462 | sched_domain_node_span(cpu_to_node(i), sched_domain_span(sd)); | 8802 | cpumask_copy(sched_domain_span(sd), cpu_map); |
| 8463 | sd->parent = p; | 8803 | cpu_to_allnodes_group(i, cpu_map, &sd->groups, d->tmpmask); |
| 8464 | if (p) | 8804 | d->sd_allnodes = 1; |
| 8465 | p->child = sd; | 8805 | } |
| 8466 | cpumask_and(sched_domain_span(sd), | 8806 | parent = sd; |
| 8467 | sched_domain_span(sd), cpu_map); | 8807 | |
| 8808 | sd = &per_cpu(node_domains, i).sd; | ||
| 8809 | SD_INIT(sd, NODE); | ||
| 8810 | set_domain_attribute(sd, attr); | ||
| 8811 | sched_domain_node_span(cpu_to_node(i), sched_domain_span(sd)); | ||
| 8812 | sd->parent = parent; | ||
| 8813 | if (parent) | ||
| 8814 | parent->child = sd; | ||
| 8815 | cpumask_and(sched_domain_span(sd), sched_domain_span(sd), cpu_map); | ||
| 8468 | #endif | 8816 | #endif |
| 8817 | return sd; | ||
| 8818 | } | ||
| 8469 | 8819 | ||
| 8470 | p = sd; | 8820 | static struct sched_domain *__build_cpu_sched_domain(struct s_data *d, |
| 8471 | sd = &per_cpu(phys_domains, i).sd; | 8821 | const struct cpumask *cpu_map, struct sched_domain_attr *attr, |
| 8472 | SD_INIT(sd, CPU); | 8822 | struct sched_domain *parent, int i) |
| 8473 | set_domain_attribute(sd, attr); | 8823 | { |
| 8474 | cpumask_copy(sched_domain_span(sd), nodemask); | 8824 | struct sched_domain *sd; |
| 8475 | sd->parent = p; | 8825 | sd = &per_cpu(phys_domains, i).sd; |
| 8476 | if (p) | 8826 | SD_INIT(sd, CPU); |
| 8477 | p->child = sd; | 8827 | set_domain_attribute(sd, attr); |
| 8478 | cpu_to_phys_group(i, cpu_map, &sd->groups, tmpmask); | 8828 | cpumask_copy(sched_domain_span(sd), d->nodemask); |
| 8829 | sd->parent = parent; | ||
| 8830 | if (parent) | ||
| 8831 | parent->child = sd; | ||
| 8832 | cpu_to_phys_group(i, cpu_map, &sd->groups, d->tmpmask); | ||
| 8833 | return sd; | ||
| 8834 | } | ||
| 8479 | 8835 | ||
| 8836 | static struct sched_domain *__build_mc_sched_domain(struct s_data *d, | ||
| 8837 | const struct cpumask *cpu_map, struct sched_domain_attr *attr, | ||
| 8838 | struct sched_domain *parent, int i) | ||
| 8839 | { | ||
| 8840 | struct sched_domain *sd = parent; | ||
| 8480 | #ifdef CONFIG_SCHED_MC | 8841 | #ifdef CONFIG_SCHED_MC |
| 8481 | p = sd; | 8842 | sd = &per_cpu(core_domains, i).sd; |
| 8482 | sd = &per_cpu(core_domains, i).sd; | 8843 | SD_INIT(sd, MC); |
| 8483 | SD_INIT(sd, MC); | 8844 | set_domain_attribute(sd, attr); |
| 8484 | set_domain_attribute(sd, attr); | 8845 | cpumask_and(sched_domain_span(sd), cpu_map, cpu_coregroup_mask(i)); |
| 8485 | cpumask_and(sched_domain_span(sd), cpu_map, | 8846 | sd->parent = parent; |
| 8486 | cpu_coregroup_mask(i)); | 8847 | parent->child = sd; |
| 8487 | sd->parent = p; | 8848 | cpu_to_core_group(i, cpu_map, &sd->groups, d->tmpmask); |
| 8488 | p->child = sd; | ||
| 8489 | cpu_to_core_group(i, cpu_map, &sd->groups, tmpmask); | ||
| 8490 | #endif | 8849 | #endif |
| 8850 | return sd; | ||
| 8851 | } | ||
| 8491 | 8852 | ||
| 8853 | static struct sched_domain *__build_smt_sched_domain(struct s_data *d, | ||
| 8854 | const struct cpumask *cpu_map, struct sched_domain_attr *attr, | ||
| 8855 | struct sched_domain *parent, int i) | ||
| 8856 | { | ||
| 8857 | struct sched_domain *sd = parent; | ||
| 8492 | #ifdef CONFIG_SCHED_SMT | 8858 | #ifdef CONFIG_SCHED_SMT |
| 8493 | p = sd; | 8859 | sd = &per_cpu(cpu_domains, i).sd; |
| 8494 | sd = &per_cpu(cpu_domains, i).sd; | 8860 | SD_INIT(sd, SIBLING); |
| 8495 | SD_INIT(sd, SIBLING); | 8861 | set_domain_attribute(sd, attr); |
| 8496 | set_domain_attribute(sd, attr); | 8862 | cpumask_and(sched_domain_span(sd), cpu_map, topology_thread_cpumask(i)); |
| 8497 | cpumask_and(sched_domain_span(sd), | 8863 | sd->parent = parent; |
| 8498 | topology_thread_cpumask(i), cpu_map); | 8864 | parent->child = sd; |
| 8499 | sd->parent = p; | 8865 | cpu_to_cpu_group(i, cpu_map, &sd->groups, d->tmpmask); |
| 8500 | p->child = sd; | ||
| 8501 | cpu_to_cpu_group(i, cpu_map, &sd->groups, tmpmask); | ||
| 8502 | #endif | 8866 | #endif |
| 8503 | } | 8867 | return sd; |
| 8868 | } | ||
| 8504 | 8869 | ||
| 8870 | static void build_sched_groups(struct s_data *d, enum sched_domain_level l, | ||
| 8871 | const struct cpumask *cpu_map, int cpu) | ||
| 8872 | { | ||
| 8873 | switch (l) { | ||
| 8505 | #ifdef CONFIG_SCHED_SMT | 8874 | #ifdef CONFIG_SCHED_SMT |
| 8506 | /* Set up CPU (sibling) groups */ | 8875 | case SD_LV_SIBLING: /* set up CPU (sibling) groups */ |
| 8507 | for_each_cpu(i, cpu_map) { | 8876 | cpumask_and(d->this_sibling_map, cpu_map, |
| 8508 | cpumask_and(this_sibling_map, | 8877 | topology_thread_cpumask(cpu)); |
| 8509 | topology_thread_cpumask(i), cpu_map); | 8878 | if (cpu == cpumask_first(d->this_sibling_map)) |
| 8510 | if (i != cpumask_first(this_sibling_map)) | 8879 | init_sched_build_groups(d->this_sibling_map, cpu_map, |
| 8511 | continue; | 8880 | &cpu_to_cpu_group, |
| 8512 | 8881 | d->send_covered, d->tmpmask); | |
| 8513 | init_sched_build_groups(this_sibling_map, cpu_map, | 8882 | break; |
| 8514 | &cpu_to_cpu_group, | ||
| 8515 | send_covered, tmpmask); | ||
| 8516 | } | ||
| 8517 | #endif | 8883 | #endif |
| 8518 | |||
| 8519 | #ifdef CONFIG_SCHED_MC | 8884 | #ifdef CONFIG_SCHED_MC |
| 8520 | /* Set up multi-core groups */ | 8885 | case SD_LV_MC: /* set up multi-core groups */ |
| 8521 | for_each_cpu(i, cpu_map) { | 8886 | cpumask_and(d->this_core_map, cpu_map, cpu_coregroup_mask(cpu)); |
| 8522 | cpumask_and(this_core_map, cpu_coregroup_mask(i), cpu_map); | 8887 | if (cpu == cpumask_first(d->this_core_map)) |
| 8523 | if (i != cpumask_first(this_core_map)) | 8888 | init_sched_build_groups(d->this_core_map, cpu_map, |
| 8524 | continue; | 8889 | &cpu_to_core_group, |
| 8525 | 8890 | d->send_covered, d->tmpmask); | |
| 8526 | init_sched_build_groups(this_core_map, cpu_map, | 8891 | break; |
| 8527 | &cpu_to_core_group, | ||
| 8528 | send_covered, tmpmask); | ||
| 8529 | } | ||
| 8530 | #endif | 8892 | #endif |
| 8531 | 8893 | case SD_LV_CPU: /* set up physical groups */ | |
| 8532 | /* Set up physical groups */ | 8894 | cpumask_and(d->nodemask, cpumask_of_node(cpu), cpu_map); |
| 8533 | for (i = 0; i < nr_node_ids; i++) { | 8895 | if (!cpumask_empty(d->nodemask)) |
| 8534 | cpumask_and(nodemask, cpumask_of_node(i), cpu_map); | 8896 | init_sched_build_groups(d->nodemask, cpu_map, |
| 8535 | if (cpumask_empty(nodemask)) | 8897 | &cpu_to_phys_group, |
| 8536 | continue; | 8898 | d->send_covered, d->tmpmask); |
| 8537 | 8899 | break; | |
| 8538 | init_sched_build_groups(nodemask, cpu_map, | ||
| 8539 | &cpu_to_phys_group, | ||
| 8540 | send_covered, tmpmask); | ||
| 8541 | } | ||
| 8542 | |||
| 8543 | #ifdef CONFIG_NUMA | 8900 | #ifdef CONFIG_NUMA |
| 8544 | /* Set up node groups */ | 8901 | case SD_LV_ALLNODES: |
| 8545 | if (sd_allnodes) { | 8902 | init_sched_build_groups(cpu_map, cpu_map, &cpu_to_allnodes_group, |
| 8546 | init_sched_build_groups(cpu_map, cpu_map, | 8903 | d->send_covered, d->tmpmask); |
| 8547 | &cpu_to_allnodes_group, | 8904 | break; |
| 8548 | send_covered, tmpmask); | 8905 | #endif |
| 8906 | default: | ||
| 8907 | break; | ||
| 8549 | } | 8908 | } |
| 8909 | } | ||
| 8550 | 8910 | ||
| 8551 | for (i = 0; i < nr_node_ids; i++) { | 8911 | /* |
| 8552 | /* Set up node groups */ | 8912 | * Build sched domains for a given set of cpus and attach the sched domains |
| 8553 | struct sched_group *sg, *prev; | 8913 | * to the individual cpus |
| 8554 | int j; | 8914 | */ |
| 8555 | 8915 | static int __build_sched_domains(const struct cpumask *cpu_map, | |
| 8556 | cpumask_clear(covered); | 8916 | struct sched_domain_attr *attr) |
| 8557 | cpumask_and(nodemask, cpumask_of_node(i), cpu_map); | 8917 | { |
| 8558 | if (cpumask_empty(nodemask)) { | 8918 | enum s_alloc alloc_state = sa_none; |
| 8559 | sched_group_nodes[i] = NULL; | 8919 | struct s_data d; |
| 8560 | continue; | 8920 | struct sched_domain *sd; |
| 8561 | } | 8921 | int i; |
| 8922 | #ifdef CONFIG_NUMA | ||
| 8923 | d.sd_allnodes = 0; | ||
| 8924 | #endif | ||
| 8562 | 8925 | ||
| 8563 | sched_domain_node_span(i, domainspan); | 8926 | alloc_state = __visit_domain_allocation_hell(&d, cpu_map); |
| 8564 | cpumask_and(domainspan, domainspan, cpu_map); | 8927 | if (alloc_state != sa_rootdomain) |
| 8928 | goto error; | ||
| 8929 | alloc_state = sa_sched_groups; | ||
| 8565 | 8930 | ||
| 8566 | sg = kmalloc_node(sizeof(struct sched_group) + cpumask_size(), | 8931 | /* |
| 8567 | GFP_KERNEL, i); | 8932 | * Set up domains for cpus specified by the cpu_map. |
| 8568 | if (!sg) { | 8933 | */ |
| 8569 | printk(KERN_WARNING "Can not alloc domain group for " | 8934 | for_each_cpu(i, cpu_map) { |
| 8570 | "node %d\n", i); | 8935 | cpumask_and(d.nodemask, cpumask_of_node(cpu_to_node(i)), |
| 8571 | goto error; | 8936 | cpu_map); |
| 8572 | } | ||
| 8573 | sched_group_nodes[i] = sg; | ||
| 8574 | for_each_cpu(j, nodemask) { | ||
| 8575 | struct sched_domain *sd; | ||
| 8576 | 8937 | ||
| 8577 | sd = &per_cpu(node_domains, j).sd; | 8938 | sd = __build_numa_sched_domains(&d, cpu_map, attr, i); |
| 8578 | sd->groups = sg; | 8939 | sd = __build_cpu_sched_domain(&d, cpu_map, attr, sd, i); |
| 8579 | } | 8940 | sd = __build_mc_sched_domain(&d, cpu_map, attr, sd, i); |
| 8580 | sg->__cpu_power = 0; | 8941 | sd = __build_smt_sched_domain(&d, cpu_map, attr, sd, i); |
| 8581 | cpumask_copy(sched_group_cpus(sg), nodemask); | 8942 | } |
| 8582 | sg->next = sg; | ||
| 8583 | cpumask_or(covered, covered, nodemask); | ||
| 8584 | prev = sg; | ||
| 8585 | 8943 | ||
| 8586 | for (j = 0; j < nr_node_ids; j++) { | 8944 | for_each_cpu(i, cpu_map) { |
| 8587 | int n = (i + j) % nr_node_ids; | 8945 | build_sched_groups(&d, SD_LV_SIBLING, cpu_map, i); |
| 8946 | build_sched_groups(&d, SD_LV_MC, cpu_map, i); | ||
| 8947 | } | ||
| 8588 | 8948 | ||
| 8589 | cpumask_complement(notcovered, covered); | 8949 | /* Set up physical groups */ |
| 8590 | cpumask_and(tmpmask, notcovered, cpu_map); | 8950 | for (i = 0; i < nr_node_ids; i++) |
| 8591 | cpumask_and(tmpmask, tmpmask, domainspan); | 8951 | build_sched_groups(&d, SD_LV_CPU, cpu_map, i); |
| 8592 | if (cpumask_empty(tmpmask)) | ||
| 8593 | break; | ||
| 8594 | 8952 | ||
| 8595 | cpumask_and(tmpmask, tmpmask, cpumask_of_node(n)); | 8953 | #ifdef CONFIG_NUMA |
| 8596 | if (cpumask_empty(tmpmask)) | 8954 | /* Set up node groups */ |
| 8597 | continue; | 8955 | if (d.sd_allnodes) |
| 8956 | build_sched_groups(&d, SD_LV_ALLNODES, cpu_map, 0); | ||
| 8598 | 8957 | ||
| 8599 | sg = kmalloc_node(sizeof(struct sched_group) + | 8958 | for (i = 0; i < nr_node_ids; i++) |
| 8600 | cpumask_size(), | 8959 | if (build_numa_sched_groups(&d, cpu_map, i)) |
| 8601 | GFP_KERNEL, i); | 8960 | goto error; |
| 8602 | if (!sg) { | ||
| 8603 | printk(KERN_WARNING | ||
| 8604 | "Can not alloc domain group for node %d\n", j); | ||
| 8605 | goto error; | ||
| 8606 | } | ||
| 8607 | sg->__cpu_power = 0; | ||
| 8608 | cpumask_copy(sched_group_cpus(sg), tmpmask); | ||
| 8609 | sg->next = prev->next; | ||
| 8610 | cpumask_or(covered, covered, tmpmask); | ||
| 8611 | prev->next = sg; | ||
| 8612 | prev = sg; | ||
| 8613 | } | ||
| 8614 | } | ||
| 8615 | #endif | 8961 | #endif |
| 8616 | 8962 | ||
| 8617 | /* Calculate CPU power for physical packages and nodes */ | 8963 | /* Calculate CPU power for physical packages and nodes */ |
| 8618 | #ifdef CONFIG_SCHED_SMT | 8964 | #ifdef CONFIG_SCHED_SMT |
| 8619 | for_each_cpu(i, cpu_map) { | 8965 | for_each_cpu(i, cpu_map) { |
| 8620 | struct sched_domain *sd = &per_cpu(cpu_domains, i).sd; | 8966 | sd = &per_cpu(cpu_domains, i).sd; |
| 8621 | |||
| 8622 | init_sched_groups_power(i, sd); | 8967 | init_sched_groups_power(i, sd); |
| 8623 | } | 8968 | } |
| 8624 | #endif | 8969 | #endif |
| 8625 | #ifdef CONFIG_SCHED_MC | 8970 | #ifdef CONFIG_SCHED_MC |
| 8626 | for_each_cpu(i, cpu_map) { | 8971 | for_each_cpu(i, cpu_map) { |
| 8627 | struct sched_domain *sd = &per_cpu(core_domains, i).sd; | 8972 | sd = &per_cpu(core_domains, i).sd; |
| 8628 | |||
| 8629 | init_sched_groups_power(i, sd); | 8973 | init_sched_groups_power(i, sd); |
| 8630 | } | 8974 | } |
| 8631 | #endif | 8975 | #endif |
| 8632 | 8976 | ||
| 8633 | for_each_cpu(i, cpu_map) { | 8977 | for_each_cpu(i, cpu_map) { |
| 8634 | struct sched_domain *sd = &per_cpu(phys_domains, i).sd; | 8978 | sd = &per_cpu(phys_domains, i).sd; |
| 8635 | |||
| 8636 | init_sched_groups_power(i, sd); | 8979 | init_sched_groups_power(i, sd); |
| 8637 | } | 8980 | } |
| 8638 | 8981 | ||
| 8639 | #ifdef CONFIG_NUMA | 8982 | #ifdef CONFIG_NUMA |
| 8640 | for (i = 0; i < nr_node_ids; i++) | 8983 | for (i = 0; i < nr_node_ids; i++) |
| 8641 | init_numa_sched_groups_power(sched_group_nodes[i]); | 8984 | init_numa_sched_groups_power(d.sched_group_nodes[i]); |
| 8642 | 8985 | ||
| 8643 | if (sd_allnodes) { | 8986 | if (d.sd_allnodes) { |
| 8644 | struct sched_group *sg; | 8987 | struct sched_group *sg; |
| 8645 | 8988 | ||
| 8646 | cpu_to_allnodes_group(cpumask_first(cpu_map), cpu_map, &sg, | 8989 | cpu_to_allnodes_group(cpumask_first(cpu_map), cpu_map, &sg, |
| 8647 | tmpmask); | 8990 | d.tmpmask); |
| 8648 | init_numa_sched_groups_power(sg); | 8991 | init_numa_sched_groups_power(sg); |
| 8649 | } | 8992 | } |
| 8650 | #endif | 8993 | #endif |
| 8651 | 8994 | ||
| 8652 | /* Attach the domains */ | 8995 | /* Attach the domains */ |
| 8653 | for_each_cpu(i, cpu_map) { | 8996 | for_each_cpu(i, cpu_map) { |
| 8654 | struct sched_domain *sd; | ||
| 8655 | #ifdef CONFIG_SCHED_SMT | 8997 | #ifdef CONFIG_SCHED_SMT |
| 8656 | sd = &per_cpu(cpu_domains, i).sd; | 8998 | sd = &per_cpu(cpu_domains, i).sd; |
| 8657 | #elif defined(CONFIG_SCHED_MC) | 8999 | #elif defined(CONFIG_SCHED_MC) |
| @@ -8659,44 +9001,16 @@ static int __build_sched_domains(const struct cpumask *cpu_map, | |||
| 8659 | #else | 9001 | #else |
| 8660 | sd = &per_cpu(phys_domains, i).sd; | 9002 | sd = &per_cpu(phys_domains, i).sd; |
| 8661 | #endif | 9003 | #endif |
| 8662 | cpu_attach_domain(sd, rd, i); | 9004 | cpu_attach_domain(sd, d.rd, i); |
| 8663 | } | 9005 | } |
| 8664 | 9006 | ||
| 8665 | err = 0; | 9007 | d.sched_group_nodes = NULL; /* don't free this we still need it */ |
| 8666 | 9008 | __free_domain_allocs(&d, sa_tmpmask, cpu_map); | |
| 8667 | free_tmpmask: | 9009 | return 0; |
| 8668 | free_cpumask_var(tmpmask); | ||
| 8669 | free_send_covered: | ||
| 8670 | free_cpumask_var(send_covered); | ||
| 8671 | free_this_core_map: | ||
| 8672 | free_cpumask_var(this_core_map); | ||
| 8673 | free_this_sibling_map: | ||
| 8674 | free_cpumask_var(this_sibling_map); | ||
| 8675 | free_nodemask: | ||
| 8676 | free_cpumask_var(nodemask); | ||
| 8677 | free_notcovered: | ||
| 8678 | #ifdef CONFIG_NUMA | ||
| 8679 | free_cpumask_var(notcovered); | ||
| 8680 | free_covered: | ||
| 8681 | free_cpumask_var(covered); | ||
| 8682 | free_domainspan: | ||
| 8683 | free_cpumask_var(domainspan); | ||
| 8684 | out: | ||
| 8685 | #endif | ||
| 8686 | return err; | ||
| 8687 | |||
| 8688 | free_sched_groups: | ||
| 8689 | #ifdef CONFIG_NUMA | ||
| 8690 | kfree(sched_group_nodes); | ||
| 8691 | #endif | ||
| 8692 | goto free_tmpmask; | ||
| 8693 | 9010 | ||
| 8694 | #ifdef CONFIG_NUMA | ||
| 8695 | error: | 9011 | error: |
| 8696 | free_sched_groups(cpu_map, tmpmask); | 9012 | __free_domain_allocs(&d, alloc_state, cpu_map); |
| 8697 | free_rootdomain(rd); | 9013 | return -ENOMEM; |
| 8698 | goto free_tmpmask; | ||
| 8699 | #endif | ||
| 8700 | } | 9014 | } |
| 8701 | 9015 | ||
| 8702 | static int build_sched_domains(const struct cpumask *cpu_map) | 9016 | static int build_sched_domains(const struct cpumask *cpu_map) |
| @@ -9304,11 +9618,11 @@ void __init sched_init(void) | |||
| 9304 | * system cpu resource, based on the weight assigned to root | 9618 | * system cpu resource, based on the weight assigned to root |
| 9305 | * user's cpu share (INIT_TASK_GROUP_LOAD). This is accomplished | 9619 | * user's cpu share (INIT_TASK_GROUP_LOAD). This is accomplished |
| 9306 | * by letting tasks of init_task_group sit in a separate cfs_rq | 9620 | * by letting tasks of init_task_group sit in a separate cfs_rq |
| 9307 | * (init_cfs_rq) and having one entity represent this group of | 9621 | * (init_tg_cfs_rq) and having one entity represent this group of |
| 9308 | * tasks in rq->cfs (i.e init_task_group->se[] != NULL). | 9622 | * tasks in rq->cfs (i.e init_task_group->se[] != NULL). |
| 9309 | */ | 9623 | */ |
| 9310 | init_tg_cfs_entry(&init_task_group, | 9624 | init_tg_cfs_entry(&init_task_group, |
| 9311 | &per_cpu(init_cfs_rq, i), | 9625 | &per_cpu(init_tg_cfs_rq, i), |
| 9312 | &per_cpu(init_sched_entity, i), i, 1, | 9626 | &per_cpu(init_sched_entity, i), i, 1, |
| 9313 | root_task_group.se[i]); | 9627 | root_task_group.se[i]); |
| 9314 | 9628 | ||
| @@ -9334,6 +9648,7 @@ void __init sched_init(void) | |||
| 9334 | #ifdef CONFIG_SMP | 9648 | #ifdef CONFIG_SMP |
| 9335 | rq->sd = NULL; | 9649 | rq->sd = NULL; |
| 9336 | rq->rd = NULL; | 9650 | rq->rd = NULL; |
| 9651 | rq->post_schedule = 0; | ||
| 9337 | rq->active_balance = 0; | 9652 | rq->active_balance = 0; |
| 9338 | rq->next_balance = jiffies; | 9653 | rq->next_balance = jiffies; |
| 9339 | rq->push_cpu = 0; | 9654 | rq->push_cpu = 0; |
| @@ -9398,13 +9713,20 @@ void __init sched_init(void) | |||
| 9398 | } | 9713 | } |
| 9399 | 9714 | ||
| 9400 | #ifdef CONFIG_DEBUG_SPINLOCK_SLEEP | 9715 | #ifdef CONFIG_DEBUG_SPINLOCK_SLEEP |
| 9401 | void __might_sleep(char *file, int line) | 9716 | static inline int preempt_count_equals(int preempt_offset) |
| 9717 | { | ||
| 9718 | int nested = preempt_count() & ~PREEMPT_ACTIVE; | ||
| 9719 | |||
| 9720 | return (nested == PREEMPT_INATOMIC_BASE + preempt_offset); | ||
| 9721 | } | ||
| 9722 | |||
| 9723 | void __might_sleep(char *file, int line, int preempt_offset) | ||
| 9402 | { | 9724 | { |
| 9403 | #ifdef in_atomic | 9725 | #ifdef in_atomic |
| 9404 | static unsigned long prev_jiffy; /* ratelimiting */ | 9726 | static unsigned long prev_jiffy; /* ratelimiting */ |
| 9405 | 9727 | ||
| 9406 | if ((!in_atomic() && !irqs_disabled()) || | 9728 | if ((preempt_count_equals(preempt_offset) && !irqs_disabled()) || |
| 9407 | system_state != SYSTEM_RUNNING || oops_in_progress) | 9729 | system_state != SYSTEM_RUNNING || oops_in_progress) |
| 9408 | return; | 9730 | return; |
| 9409 | if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy) | 9731 | if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy) |
| 9410 | return; | 9732 | return; |
| @@ -10581,3 +10903,113 @@ struct cgroup_subsys cpuacct_subsys = { | |||
| 10581 | .subsys_id = cpuacct_subsys_id, | 10903 | .subsys_id = cpuacct_subsys_id, |
| 10582 | }; | 10904 | }; |
| 10583 | #endif /* CONFIG_CGROUP_CPUACCT */ | 10905 | #endif /* CONFIG_CGROUP_CPUACCT */ |
| 10906 | |||
| 10907 | #ifndef CONFIG_SMP | ||
| 10908 | |||
| 10909 | int rcu_expedited_torture_stats(char *page) | ||
| 10910 | { | ||
| 10911 | return 0; | ||
| 10912 | } | ||
| 10913 | EXPORT_SYMBOL_GPL(rcu_expedited_torture_stats); | ||
| 10914 | |||
| 10915 | void synchronize_sched_expedited(void) | ||
| 10916 | { | ||
| 10917 | } | ||
| 10918 | EXPORT_SYMBOL_GPL(synchronize_sched_expedited); | ||
| 10919 | |||
| 10920 | #else /* #ifndef CONFIG_SMP */ | ||
| 10921 | |||
| 10922 | static DEFINE_PER_CPU(struct migration_req, rcu_migration_req); | ||
| 10923 | static DEFINE_MUTEX(rcu_sched_expedited_mutex); | ||
| 10924 | |||
| 10925 | #define RCU_EXPEDITED_STATE_POST -2 | ||
| 10926 | #define RCU_EXPEDITED_STATE_IDLE -1 | ||
| 10927 | |||
| 10928 | static int rcu_expedited_state = RCU_EXPEDITED_STATE_IDLE; | ||
| 10929 | |||
| 10930 | int rcu_expedited_torture_stats(char *page) | ||
| 10931 | { | ||
| 10932 | int cnt = 0; | ||
| 10933 | int cpu; | ||
| 10934 | |||
| 10935 | cnt += sprintf(&page[cnt], "state: %d /", rcu_expedited_state); | ||
| 10936 | for_each_online_cpu(cpu) { | ||
| 10937 | cnt += sprintf(&page[cnt], " %d:%d", | ||
| 10938 | cpu, per_cpu(rcu_migration_req, cpu).dest_cpu); | ||
| 10939 | } | ||
| 10940 | cnt += sprintf(&page[cnt], "\n"); | ||
| 10941 | return cnt; | ||
| 10942 | } | ||
| 10943 | EXPORT_SYMBOL_GPL(rcu_expedited_torture_stats); | ||
| 10944 | |||
| 10945 | static long synchronize_sched_expedited_count; | ||
| 10946 | |||
| 10947 | /* | ||
| 10948 | * Wait for an rcu-sched grace period to elapse, but use "big hammer" | ||
| 10949 | * approach to force grace period to end quickly. This consumes | ||
| 10950 | * significant time on all CPUs, and is thus not recommended for | ||
| 10951 | * any sort of common-case code. | ||
| 10952 | * | ||
| 10953 | * Note that it is illegal to call this function while holding any | ||
| 10954 | * lock that is acquired by a CPU-hotplug notifier. Failing to | ||
| 10955 | * observe this restriction will result in deadlock. | ||
| 10956 | */ | ||
| 10957 | void synchronize_sched_expedited(void) | ||
| 10958 | { | ||
| 10959 | int cpu; | ||
| 10960 | unsigned long flags; | ||
| 10961 | bool need_full_sync = 0; | ||
| 10962 | struct rq *rq; | ||
| 10963 | struct migration_req *req; | ||
| 10964 | long snap; | ||
| 10965 | int trycount = 0; | ||
| 10966 | |||
| 10967 | smp_mb(); /* ensure prior mod happens before capturing snap. */ | ||
| 10968 | snap = ACCESS_ONCE(synchronize_sched_expedited_count) + 1; | ||
| 10969 | get_online_cpus(); | ||
| 10970 | while (!mutex_trylock(&rcu_sched_expedited_mutex)) { | ||
| 10971 | put_online_cpus(); | ||
| 10972 | if (trycount++ < 10) | ||
| 10973 | udelay(trycount * num_online_cpus()); | ||
| 10974 | else { | ||
| 10975 | synchronize_sched(); | ||
| 10976 | return; | ||
| 10977 | } | ||
| 10978 | if (ACCESS_ONCE(synchronize_sched_expedited_count) - snap > 0) { | ||
| 10979 | smp_mb(); /* ensure test happens before caller kfree */ | ||
| 10980 | return; | ||
| 10981 | } | ||
| 10982 | get_online_cpus(); | ||
| 10983 | } | ||
| 10984 | rcu_expedited_state = RCU_EXPEDITED_STATE_POST; | ||
| 10985 | for_each_online_cpu(cpu) { | ||
| 10986 | rq = cpu_rq(cpu); | ||
| 10987 | req = &per_cpu(rcu_migration_req, cpu); | ||
| 10988 | init_completion(&req->done); | ||
| 10989 | req->task = NULL; | ||
| 10990 | req->dest_cpu = RCU_MIGRATION_NEED_QS; | ||
| 10991 | spin_lock_irqsave(&rq->lock, flags); | ||
| 10992 | list_add(&req->list, &rq->migration_queue); | ||
| 10993 | spin_unlock_irqrestore(&rq->lock, flags); | ||
| 10994 | wake_up_process(rq->migration_thread); | ||
| 10995 | } | ||
| 10996 | for_each_online_cpu(cpu) { | ||
| 10997 | rcu_expedited_state = cpu; | ||
| 10998 | req = &per_cpu(rcu_migration_req, cpu); | ||
| 10999 | rq = cpu_rq(cpu); | ||
| 11000 | wait_for_completion(&req->done); | ||
| 11001 | spin_lock_irqsave(&rq->lock, flags); | ||
| 11002 | if (unlikely(req->dest_cpu == RCU_MIGRATION_MUST_SYNC)) | ||
| 11003 | need_full_sync = 1; | ||
| 11004 | req->dest_cpu = RCU_MIGRATION_IDLE; | ||
| 11005 | spin_unlock_irqrestore(&rq->lock, flags); | ||
| 11006 | } | ||
| 11007 | rcu_expedited_state = RCU_EXPEDITED_STATE_IDLE; | ||
| 11008 | mutex_unlock(&rcu_sched_expedited_mutex); | ||
| 11009 | put_online_cpus(); | ||
| 11010 | if (need_full_sync) | ||
| 11011 | synchronize_sched(); | ||
| 11012 | } | ||
| 11013 | EXPORT_SYMBOL_GPL(synchronize_sched_expedited); | ||
| 11014 | |||
| 11015 | #endif /* #else #ifndef CONFIG_SMP */ | ||
diff --git a/kernel/sched_cpupri.c b/kernel/sched_cpupri.c index d014efbf947a..0f052fc674d5 100644 --- a/kernel/sched_cpupri.c +++ b/kernel/sched_cpupri.c | |||
| @@ -127,21 +127,11 @@ void cpupri_set(struct cpupri *cp, int cpu, int newpri) | |||
| 127 | 127 | ||
| 128 | /* | 128 | /* |
| 129 | * If the cpu was currently mapped to a different value, we | 129 | * If the cpu was currently mapped to a different value, we |
| 130 | * first need to unmap the old value | 130 | * need to map it to the new value then remove the old value. |
| 131 | * Note, we must add the new value first, otherwise we risk the | ||
| 132 | * cpu being cleared from pri_active, and this cpu could be | ||
| 133 | * missed for a push or pull. | ||
| 131 | */ | 134 | */ |
| 132 | if (likely(oldpri != CPUPRI_INVALID)) { | ||
| 133 | struct cpupri_vec *vec = &cp->pri_to_cpu[oldpri]; | ||
| 134 | |||
| 135 | spin_lock_irqsave(&vec->lock, flags); | ||
| 136 | |||
| 137 | vec->count--; | ||
| 138 | if (!vec->count) | ||
| 139 | clear_bit(oldpri, cp->pri_active); | ||
| 140 | cpumask_clear_cpu(cpu, vec->mask); | ||
| 141 | |||
| 142 | spin_unlock_irqrestore(&vec->lock, flags); | ||
| 143 | } | ||
| 144 | |||
| 145 | if (likely(newpri != CPUPRI_INVALID)) { | 135 | if (likely(newpri != CPUPRI_INVALID)) { |
| 146 | struct cpupri_vec *vec = &cp->pri_to_cpu[newpri]; | 136 | struct cpupri_vec *vec = &cp->pri_to_cpu[newpri]; |
| 147 | 137 | ||
| @@ -154,6 +144,18 @@ void cpupri_set(struct cpupri *cp, int cpu, int newpri) | |||
| 154 | 144 | ||
| 155 | spin_unlock_irqrestore(&vec->lock, flags); | 145 | spin_unlock_irqrestore(&vec->lock, flags); |
| 156 | } | 146 | } |
| 147 | if (likely(oldpri != CPUPRI_INVALID)) { | ||
| 148 | struct cpupri_vec *vec = &cp->pri_to_cpu[oldpri]; | ||
| 149 | |||
| 150 | spin_lock_irqsave(&vec->lock, flags); | ||
| 151 | |||
| 152 | vec->count--; | ||
| 153 | if (!vec->count) | ||
| 154 | clear_bit(oldpri, cp->pri_active); | ||
| 155 | cpumask_clear_cpu(cpu, vec->mask); | ||
| 156 | |||
| 157 | spin_unlock_irqrestore(&vec->lock, flags); | ||
| 158 | } | ||
| 157 | 159 | ||
| 158 | *currpri = newpri; | 160 | *currpri = newpri; |
| 159 | } | 161 | } |
diff --git a/kernel/sched_debug.c b/kernel/sched_debug.c index 70c7e0b79946..5ddbd0891267 100644 --- a/kernel/sched_debug.c +++ b/kernel/sched_debug.c | |||
| @@ -409,6 +409,8 @@ void proc_sched_show_task(struct task_struct *p, struct seq_file *m) | |||
| 409 | PN(se.wait_max); | 409 | PN(se.wait_max); |
| 410 | PN(se.wait_sum); | 410 | PN(se.wait_sum); |
| 411 | P(se.wait_count); | 411 | P(se.wait_count); |
| 412 | PN(se.iowait_sum); | ||
| 413 | P(se.iowait_count); | ||
| 412 | P(sched_info.bkl_count); | 414 | P(sched_info.bkl_count); |
| 413 | P(se.nr_migrations); | 415 | P(se.nr_migrations); |
| 414 | P(se.nr_migrations_cold); | 416 | P(se.nr_migrations_cold); |
| @@ -479,6 +481,8 @@ void proc_sched_set_task(struct task_struct *p) | |||
| 479 | p->se.wait_max = 0; | 481 | p->se.wait_max = 0; |
| 480 | p->se.wait_sum = 0; | 482 | p->se.wait_sum = 0; |
| 481 | p->se.wait_count = 0; | 483 | p->se.wait_count = 0; |
| 484 | p->se.iowait_sum = 0; | ||
| 485 | p->se.iowait_count = 0; | ||
| 482 | p->se.sleep_max = 0; | 486 | p->se.sleep_max = 0; |
| 483 | p->se.sum_sleep_runtime = 0; | 487 | p->se.sum_sleep_runtime = 0; |
| 484 | p->se.block_max = 0; | 488 | p->se.block_max = 0; |
diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c index 652e8bdef9aa..aa7f84121016 100644 --- a/kernel/sched_fair.c +++ b/kernel/sched_fair.c | |||
| @@ -24,7 +24,7 @@ | |||
| 24 | 24 | ||
| 25 | /* | 25 | /* |
| 26 | * Targeted preemption latency for CPU-bound tasks: | 26 | * Targeted preemption latency for CPU-bound tasks: |
| 27 | * (default: 20ms * (1 + ilog(ncpus)), units: nanoseconds) | 27 | * (default: 5ms * (1 + ilog(ncpus)), units: nanoseconds) |
| 28 | * | 28 | * |
| 29 | * NOTE: this latency value is not the same as the concept of | 29 | * NOTE: this latency value is not the same as the concept of |
| 30 | * 'timeslice length' - timeslices in CFS are of variable length | 30 | * 'timeslice length' - timeslices in CFS are of variable length |
| @@ -34,13 +34,13 @@ | |||
| 34 | * (to see the precise effective timeslice length of your workload, | 34 | * (to see the precise effective timeslice length of your workload, |
| 35 | * run vmstat and monitor the context-switches (cs) field) | 35 | * run vmstat and monitor the context-switches (cs) field) |
| 36 | */ | 36 | */ |
| 37 | unsigned int sysctl_sched_latency = 20000000ULL; | 37 | unsigned int sysctl_sched_latency = 5000000ULL; |
| 38 | 38 | ||
| 39 | /* | 39 | /* |
| 40 | * Minimal preemption granularity for CPU-bound tasks: | 40 | * Minimal preemption granularity for CPU-bound tasks: |
| 41 | * (default: 4 msec * (1 + ilog(ncpus)), units: nanoseconds) | 41 | * (default: 1 msec * (1 + ilog(ncpus)), units: nanoseconds) |
| 42 | */ | 42 | */ |
| 43 | unsigned int sysctl_sched_min_granularity = 4000000ULL; | 43 | unsigned int sysctl_sched_min_granularity = 1000000ULL; |
| 44 | 44 | ||
| 45 | /* | 45 | /* |
| 46 | * is kept at sysctl_sched_latency / sysctl_sched_min_granularity | 46 | * is kept at sysctl_sched_latency / sysctl_sched_min_granularity |
| @@ -48,10 +48,10 @@ unsigned int sysctl_sched_min_granularity = 4000000ULL; | |||
| 48 | static unsigned int sched_nr_latency = 5; | 48 | static unsigned int sched_nr_latency = 5; |
| 49 | 49 | ||
| 50 | /* | 50 | /* |
| 51 | * After fork, child runs first. (default) If set to 0 then | 51 | * After fork, child runs first. If set to 0 (default) then |
| 52 | * parent will (try to) run first. | 52 | * parent will (try to) run first. |
| 53 | */ | 53 | */ |
| 54 | const_debug unsigned int sysctl_sched_child_runs_first = 1; | 54 | unsigned int sysctl_sched_child_runs_first __read_mostly; |
| 55 | 55 | ||
| 56 | /* | 56 | /* |
| 57 | * sys_sched_yield() compat mode | 57 | * sys_sched_yield() compat mode |
| @@ -63,13 +63,13 @@ unsigned int __read_mostly sysctl_sched_compat_yield; | |||
| 63 | 63 | ||
| 64 | /* | 64 | /* |
| 65 | * SCHED_OTHER wake-up granularity. | 65 | * SCHED_OTHER wake-up granularity. |
| 66 | * (default: 5 msec * (1 + ilog(ncpus)), units: nanoseconds) | 66 | * (default: 1 msec * (1 + ilog(ncpus)), units: nanoseconds) |
| 67 | * | 67 | * |
| 68 | * This option delays the preemption effects of decoupled workloads | 68 | * This option delays the preemption effects of decoupled workloads |
| 69 | * and reduces their over-scheduling. Synchronous workloads will still | 69 | * and reduces their over-scheduling. Synchronous workloads will still |
| 70 | * have immediate wakeup/sleep latencies. | 70 | * have immediate wakeup/sleep latencies. |
| 71 | */ | 71 | */ |
| 72 | unsigned int sysctl_sched_wakeup_granularity = 5000000UL; | 72 | unsigned int sysctl_sched_wakeup_granularity = 1000000UL; |
| 73 | 73 | ||
| 74 | const_debug unsigned int sysctl_sched_migration_cost = 500000UL; | 74 | const_debug unsigned int sysctl_sched_migration_cost = 500000UL; |
| 75 | 75 | ||
| @@ -79,11 +79,6 @@ static const struct sched_class fair_sched_class; | |||
| 79 | * CFS operations on generic schedulable entities: | 79 | * CFS operations on generic schedulable entities: |
| 80 | */ | 80 | */ |
| 81 | 81 | ||
| 82 | static inline struct task_struct *task_of(struct sched_entity *se) | ||
| 83 | { | ||
| 84 | return container_of(se, struct task_struct, se); | ||
| 85 | } | ||
| 86 | |||
| 87 | #ifdef CONFIG_FAIR_GROUP_SCHED | 82 | #ifdef CONFIG_FAIR_GROUP_SCHED |
| 88 | 83 | ||
| 89 | /* cpu runqueue to which this cfs_rq is attached */ | 84 | /* cpu runqueue to which this cfs_rq is attached */ |
| @@ -95,6 +90,14 @@ static inline struct rq *rq_of(struct cfs_rq *cfs_rq) | |||
| 95 | /* An entity is a task if it doesn't "own" a runqueue */ | 90 | /* An entity is a task if it doesn't "own" a runqueue */ |
| 96 | #define entity_is_task(se) (!se->my_q) | 91 | #define entity_is_task(se) (!se->my_q) |
| 97 | 92 | ||
| 93 | static inline struct task_struct *task_of(struct sched_entity *se) | ||
| 94 | { | ||
| 95 | #ifdef CONFIG_SCHED_DEBUG | ||
| 96 | WARN_ON_ONCE(!entity_is_task(se)); | ||
| 97 | #endif | ||
| 98 | return container_of(se, struct task_struct, se); | ||
| 99 | } | ||
| 100 | |||
| 98 | /* Walk up scheduling entities hierarchy */ | 101 | /* Walk up scheduling entities hierarchy */ |
| 99 | #define for_each_sched_entity(se) \ | 102 | #define for_each_sched_entity(se) \ |
| 100 | for (; se; se = se->parent) | 103 | for (; se; se = se->parent) |
| @@ -186,7 +189,12 @@ find_matching_se(struct sched_entity **se, struct sched_entity **pse) | |||
| 186 | } | 189 | } |
| 187 | } | 190 | } |
| 188 | 191 | ||
| 189 | #else /* CONFIG_FAIR_GROUP_SCHED */ | 192 | #else /* !CONFIG_FAIR_GROUP_SCHED */ |
| 193 | |||
| 194 | static inline struct task_struct *task_of(struct sched_entity *se) | ||
| 195 | { | ||
| 196 | return container_of(se, struct task_struct, se); | ||
| 197 | } | ||
| 190 | 198 | ||
| 191 | static inline struct rq *rq_of(struct cfs_rq *cfs_rq) | 199 | static inline struct rq *rq_of(struct cfs_rq *cfs_rq) |
| 192 | { | 200 | { |
| @@ -537,6 +545,12 @@ update_stats_wait_end(struct cfs_rq *cfs_rq, struct sched_entity *se) | |||
| 537 | schedstat_set(se->wait_count, se->wait_count + 1); | 545 | schedstat_set(se->wait_count, se->wait_count + 1); |
| 538 | schedstat_set(se->wait_sum, se->wait_sum + | 546 | schedstat_set(se->wait_sum, se->wait_sum + |
| 539 | rq_of(cfs_rq)->clock - se->wait_start); | 547 | rq_of(cfs_rq)->clock - se->wait_start); |
| 548 | #ifdef CONFIG_SCHEDSTATS | ||
| 549 | if (entity_is_task(se)) { | ||
| 550 | trace_sched_stat_wait(task_of(se), | ||
| 551 | rq_of(cfs_rq)->clock - se->wait_start); | ||
| 552 | } | ||
| 553 | #endif | ||
| 540 | schedstat_set(se->wait_start, 0); | 554 | schedstat_set(se->wait_start, 0); |
| 541 | } | 555 | } |
| 542 | 556 | ||
| @@ -628,8 +642,10 @@ static void enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se) | |||
| 628 | se->sleep_start = 0; | 642 | se->sleep_start = 0; |
| 629 | se->sum_sleep_runtime += delta; | 643 | se->sum_sleep_runtime += delta; |
| 630 | 644 | ||
| 631 | if (tsk) | 645 | if (tsk) { |
| 632 | account_scheduler_latency(tsk, delta >> 10, 1); | 646 | account_scheduler_latency(tsk, delta >> 10, 1); |
| 647 | trace_sched_stat_sleep(tsk, delta); | ||
| 648 | } | ||
| 633 | } | 649 | } |
| 634 | if (se->block_start) { | 650 | if (se->block_start) { |
| 635 | u64 delta = rq_of(cfs_rq)->clock - se->block_start; | 651 | u64 delta = rq_of(cfs_rq)->clock - se->block_start; |
| @@ -644,6 +660,12 @@ static void enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se) | |||
| 644 | se->sum_sleep_runtime += delta; | 660 | se->sum_sleep_runtime += delta; |
| 645 | 661 | ||
| 646 | if (tsk) { | 662 | if (tsk) { |
| 663 | if (tsk->in_iowait) { | ||
| 664 | se->iowait_sum += delta; | ||
| 665 | se->iowait_count++; | ||
| 666 | trace_sched_stat_iowait(tsk, delta); | ||
| 667 | } | ||
| 668 | |||
| 647 | /* | 669 | /* |
| 648 | * Blocking time is in units of nanosecs, so shift by | 670 | * Blocking time is in units of nanosecs, so shift by |
| 649 | * 20 to get a milliseconds-range estimation of the | 671 | * 20 to get a milliseconds-range estimation of the |
| @@ -705,11 +727,11 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial) | |||
| 705 | 727 | ||
| 706 | vruntime -= thresh; | 728 | vruntime -= thresh; |
| 707 | } | 729 | } |
| 708 | |||
| 709 | /* ensure we never gain time by being placed backwards. */ | ||
| 710 | vruntime = max_vruntime(se->vruntime, vruntime); | ||
| 711 | } | 730 | } |
| 712 | 731 | ||
| 732 | /* ensure we never gain time by being placed backwards. */ | ||
| 733 | vruntime = max_vruntime(se->vruntime, vruntime); | ||
| 734 | |||
| 713 | se->vruntime = vruntime; | 735 | se->vruntime = vruntime; |
| 714 | } | 736 | } |
| 715 | 737 | ||
| @@ -1046,17 +1068,21 @@ static void yield_task_fair(struct rq *rq) | |||
| 1046 | * search starts with cpus closest then further out as needed, | 1068 | * search starts with cpus closest then further out as needed, |
| 1047 | * so we always favor a closer, idle cpu. | 1069 | * so we always favor a closer, idle cpu. |
| 1048 | * Domains may include CPUs that are not usable for migration, | 1070 | * Domains may include CPUs that are not usable for migration, |
| 1049 | * hence we need to mask them out (cpu_active_mask) | 1071 | * hence we need to mask them out (rq->rd->online) |
| 1050 | * | 1072 | * |
| 1051 | * Returns the CPU we should wake onto. | 1073 | * Returns the CPU we should wake onto. |
| 1052 | */ | 1074 | */ |
| 1053 | #if defined(ARCH_HAS_SCHED_WAKE_IDLE) | 1075 | #if defined(ARCH_HAS_SCHED_WAKE_IDLE) |
| 1076 | |||
| 1077 | #define cpu_rd_active(cpu, rq) cpumask_test_cpu(cpu, rq->rd->online) | ||
| 1078 | |||
| 1054 | static int wake_idle(int cpu, struct task_struct *p) | 1079 | static int wake_idle(int cpu, struct task_struct *p) |
| 1055 | { | 1080 | { |
| 1056 | struct sched_domain *sd; | 1081 | struct sched_domain *sd; |
| 1057 | int i; | 1082 | int i; |
| 1058 | unsigned int chosen_wakeup_cpu; | 1083 | unsigned int chosen_wakeup_cpu; |
| 1059 | int this_cpu; | 1084 | int this_cpu; |
| 1085 | struct rq *task_rq = task_rq(p); | ||
| 1060 | 1086 | ||
| 1061 | /* | 1087 | /* |
| 1062 | * At POWERSAVINGS_BALANCE_WAKEUP level, if both this_cpu and prev_cpu | 1088 | * At POWERSAVINGS_BALANCE_WAKEUP level, if both this_cpu and prev_cpu |
| @@ -1089,10 +1115,10 @@ static int wake_idle(int cpu, struct task_struct *p) | |||
| 1089 | for_each_domain(cpu, sd) { | 1115 | for_each_domain(cpu, sd) { |
| 1090 | if ((sd->flags & SD_WAKE_IDLE) | 1116 | if ((sd->flags & SD_WAKE_IDLE) |
| 1091 | || ((sd->flags & SD_WAKE_IDLE_FAR) | 1117 | || ((sd->flags & SD_WAKE_IDLE_FAR) |
| 1092 | && !task_hot(p, task_rq(p)->clock, sd))) { | 1118 | && !task_hot(p, task_rq->clock, sd))) { |
| 1093 | for_each_cpu_and(i, sched_domain_span(sd), | 1119 | for_each_cpu_and(i, sched_domain_span(sd), |
| 1094 | &p->cpus_allowed) { | 1120 | &p->cpus_allowed) { |
| 1095 | if (cpu_active(i) && idle_cpu(i)) { | 1121 | if (cpu_rd_active(i, task_rq) && idle_cpu(i)) { |
| 1096 | if (i != task_cpu(p)) { | 1122 | if (i != task_cpu(p)) { |
| 1097 | schedstat_inc(p, | 1123 | schedstat_inc(p, |
| 1098 | se.nr_wakeups_idle); | 1124 | se.nr_wakeups_idle); |
| @@ -1235,7 +1261,17 @@ wake_affine(struct sched_domain *this_sd, struct rq *this_rq, | |||
| 1235 | tg = task_group(p); | 1261 | tg = task_group(p); |
| 1236 | weight = p->se.load.weight; | 1262 | weight = p->se.load.weight; |
| 1237 | 1263 | ||
| 1238 | balanced = 100*(tl + effective_load(tg, this_cpu, weight, weight)) <= | 1264 | /* |
| 1265 | * In low-load situations, where prev_cpu is idle and this_cpu is idle | ||
| 1266 | * due to the sync cause above having dropped tl to 0, we'll always have | ||
| 1267 | * an imbalance, but there's really nothing you can do about that, so | ||
| 1268 | * that's good too. | ||
| 1269 | * | ||
| 1270 | * Otherwise check if either cpus are near enough in load to allow this | ||
| 1271 | * task to be woken on this_cpu. | ||
| 1272 | */ | ||
| 1273 | balanced = !tl || | ||
| 1274 | 100*(tl + effective_load(tg, this_cpu, weight, weight)) <= | ||
| 1239 | imbalance*(load + effective_load(tg, prev_cpu, 0, weight)); | 1275 | imbalance*(load + effective_load(tg, prev_cpu, 0, weight)); |
| 1240 | 1276 | ||
| 1241 | /* | 1277 | /* |
| @@ -1278,8 +1314,6 @@ static int select_task_rq_fair(struct task_struct *p, int sync) | |||
| 1278 | this_rq = cpu_rq(this_cpu); | 1314 | this_rq = cpu_rq(this_cpu); |
| 1279 | new_cpu = prev_cpu; | 1315 | new_cpu = prev_cpu; |
| 1280 | 1316 | ||
| 1281 | if (prev_cpu == this_cpu) | ||
| 1282 | goto out; | ||
| 1283 | /* | 1317 | /* |
| 1284 | * 'this_sd' is the first domain that both | 1318 | * 'this_sd' is the first domain that both |
| 1285 | * this_cpu and prev_cpu are present in: | 1319 | * this_cpu and prev_cpu are present in: |
| @@ -1721,6 +1755,8 @@ static void task_new_fair(struct rq *rq, struct task_struct *p) | |||
| 1721 | sched_info_queued(p); | 1755 | sched_info_queued(p); |
| 1722 | 1756 | ||
| 1723 | update_curr(cfs_rq); | 1757 | update_curr(cfs_rq); |
| 1758 | if (curr) | ||
| 1759 | se->vruntime = curr->vruntime; | ||
| 1724 | place_entity(cfs_rq, se, 1); | 1760 | place_entity(cfs_rq, se, 1); |
| 1725 | 1761 | ||
| 1726 | /* 'curr' will be NULL if the child belongs to a different group */ | 1762 | /* 'curr' will be NULL if the child belongs to a different group */ |
diff --git a/kernel/sched_features.h b/kernel/sched_features.h index 4569bfa7df9b..e2dc63a5815d 100644 --- a/kernel/sched_features.h +++ b/kernel/sched_features.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | SCHED_FEAT(NEW_FAIR_SLEEPERS, 1) | 1 | SCHED_FEAT(NEW_FAIR_SLEEPERS, 0) |
| 2 | SCHED_FEAT(NORMALIZED_SLEEPER, 0) | 2 | SCHED_FEAT(NORMALIZED_SLEEPER, 0) |
| 3 | SCHED_FEAT(ADAPTIVE_GRAN, 1) | 3 | SCHED_FEAT(ADAPTIVE_GRAN, 1) |
| 4 | SCHED_FEAT(WAKEUP_PREEMPT, 1) | 4 | SCHED_FEAT(WAKEUP_PREEMPT, 1) |
diff --git a/kernel/sched_rt.c b/kernel/sched_rt.c index 3918e01994e0..2eb4bd6a526c 100644 --- a/kernel/sched_rt.c +++ b/kernel/sched_rt.c | |||
| @@ -3,15 +3,18 @@ | |||
| 3 | * policies) | 3 | * policies) |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | #ifdef CONFIG_RT_GROUP_SCHED | ||
| 7 | |||
| 8 | #define rt_entity_is_task(rt_se) (!(rt_se)->my_q) | ||
| 9 | |||
| 6 | static inline struct task_struct *rt_task_of(struct sched_rt_entity *rt_se) | 10 | static inline struct task_struct *rt_task_of(struct sched_rt_entity *rt_se) |
| 7 | { | 11 | { |
| 12 | #ifdef CONFIG_SCHED_DEBUG | ||
| 13 | WARN_ON_ONCE(!rt_entity_is_task(rt_se)); | ||
| 14 | #endif | ||
| 8 | return container_of(rt_se, struct task_struct, rt); | 15 | return container_of(rt_se, struct task_struct, rt); |
| 9 | } | 16 | } |
| 10 | 17 | ||
| 11 | #ifdef CONFIG_RT_GROUP_SCHED | ||
| 12 | |||
| 13 | #define rt_entity_is_task(rt_se) (!(rt_se)->my_q) | ||
| 14 | |||
| 15 | static inline struct rq *rq_of_rt_rq(struct rt_rq *rt_rq) | 18 | static inline struct rq *rq_of_rt_rq(struct rt_rq *rt_rq) |
| 16 | { | 19 | { |
| 17 | return rt_rq->rq; | 20 | return rt_rq->rq; |
| @@ -26,6 +29,11 @@ static inline struct rt_rq *rt_rq_of_se(struct sched_rt_entity *rt_se) | |||
| 26 | 29 | ||
| 27 | #define rt_entity_is_task(rt_se) (1) | 30 | #define rt_entity_is_task(rt_se) (1) |
| 28 | 31 | ||
| 32 | static inline struct task_struct *rt_task_of(struct sched_rt_entity *rt_se) | ||
| 33 | { | ||
| 34 | return container_of(rt_se, struct task_struct, rt); | ||
| 35 | } | ||
| 36 | |||
| 29 | static inline struct rq *rq_of_rt_rq(struct rt_rq *rt_rq) | 37 | static inline struct rq *rq_of_rt_rq(struct rt_rq *rt_rq) |
| 30 | { | 38 | { |
| 31 | return container_of(rt_rq, struct rq, rt); | 39 | return container_of(rt_rq, struct rq, rt); |
| @@ -128,6 +136,11 @@ static void dequeue_pushable_task(struct rq *rq, struct task_struct *p) | |||
| 128 | plist_del(&p->pushable_tasks, &rq->rt.pushable_tasks); | 136 | plist_del(&p->pushable_tasks, &rq->rt.pushable_tasks); |
| 129 | } | 137 | } |
| 130 | 138 | ||
| 139 | static inline int has_pushable_tasks(struct rq *rq) | ||
| 140 | { | ||
| 141 | return !plist_head_empty(&rq->rt.pushable_tasks); | ||
| 142 | } | ||
| 143 | |||
| 131 | #else | 144 | #else |
| 132 | 145 | ||
| 133 | static inline void enqueue_pushable_task(struct rq *rq, struct task_struct *p) | 146 | static inline void enqueue_pushable_task(struct rq *rq, struct task_struct *p) |
| @@ -602,6 +615,8 @@ static void update_curr_rt(struct rq *rq) | |||
| 602 | curr->se.exec_start = rq->clock; | 615 | curr->se.exec_start = rq->clock; |
| 603 | cpuacct_charge(curr, delta_exec); | 616 | cpuacct_charge(curr, delta_exec); |
| 604 | 617 | ||
| 618 | sched_rt_avg_update(rq, delta_exec); | ||
| 619 | |||
| 605 | if (!rt_bandwidth_enabled()) | 620 | if (!rt_bandwidth_enabled()) |
| 606 | return; | 621 | return; |
| 607 | 622 | ||
| @@ -874,8 +889,6 @@ static void enqueue_task_rt(struct rq *rq, struct task_struct *p, int wakeup) | |||
| 874 | 889 | ||
| 875 | if (!task_current(rq, p) && p->rt.nr_cpus_allowed > 1) | 890 | if (!task_current(rq, p) && p->rt.nr_cpus_allowed > 1) |
| 876 | enqueue_pushable_task(rq, p); | 891 | enqueue_pushable_task(rq, p); |
| 877 | |||
| 878 | inc_cpu_load(rq, p->se.load.weight); | ||
| 879 | } | 892 | } |
| 880 | 893 | ||
| 881 | static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int sleep) | 894 | static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int sleep) |
| @@ -886,8 +899,6 @@ static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int sleep) | |||
| 886 | dequeue_rt_entity(rt_se); | 899 | dequeue_rt_entity(rt_se); |
| 887 | 900 | ||
| 888 | dequeue_pushable_task(rq, p); | 901 | dequeue_pushable_task(rq, p); |
| 889 | |||
| 890 | dec_cpu_load(rq, p->se.load.weight); | ||
| 891 | } | 902 | } |
| 892 | 903 | ||
| 893 | /* | 904 | /* |
| @@ -1064,6 +1075,14 @@ static struct task_struct *pick_next_task_rt(struct rq *rq) | |||
| 1064 | if (p) | 1075 | if (p) |
| 1065 | dequeue_pushable_task(rq, p); | 1076 | dequeue_pushable_task(rq, p); |
| 1066 | 1077 | ||
| 1078 | #ifdef CONFIG_SMP | ||
| 1079 | /* | ||
| 1080 | * We detect this state here so that we can avoid taking the RQ | ||
| 1081 | * lock again later if there is no need to push | ||
| 1082 | */ | ||
| 1083 | rq->post_schedule = has_pushable_tasks(rq); | ||
| 1084 | #endif | ||
| 1085 | |||
| 1067 | return p; | 1086 | return p; |
| 1068 | } | 1087 | } |
| 1069 | 1088 | ||
| @@ -1162,13 +1181,6 @@ static int find_lowest_rq(struct task_struct *task) | |||
| 1162 | return -1; /* No targets found */ | 1181 | return -1; /* No targets found */ |
| 1163 | 1182 | ||
| 1164 | /* | 1183 | /* |
| 1165 | * Only consider CPUs that are usable for migration. | ||
| 1166 | * I guess we might want to change cpupri_find() to ignore those | ||
| 1167 | * in the first place. | ||
| 1168 | */ | ||
| 1169 | cpumask_and(lowest_mask, lowest_mask, cpu_active_mask); | ||
| 1170 | |||
| 1171 | /* | ||
| 1172 | * At this point we have built a mask of cpus representing the | 1184 | * At this point we have built a mask of cpus representing the |
| 1173 | * lowest priority tasks in the system. Now we want to elect | 1185 | * lowest priority tasks in the system. Now we want to elect |
| 1174 | * the best one based on our affinity and topology. | 1186 | * the best one based on our affinity and topology. |
| @@ -1262,11 +1274,6 @@ static struct rq *find_lock_lowest_rq(struct task_struct *task, struct rq *rq) | |||
| 1262 | return lowest_rq; | 1274 | return lowest_rq; |
| 1263 | } | 1275 | } |
| 1264 | 1276 | ||
| 1265 | static inline int has_pushable_tasks(struct rq *rq) | ||
| 1266 | { | ||
| 1267 | return !plist_head_empty(&rq->rt.pushable_tasks); | ||
| 1268 | } | ||
| 1269 | |||
| 1270 | static struct task_struct *pick_next_pushable_task(struct rq *rq) | 1277 | static struct task_struct *pick_next_pushable_task(struct rq *rq) |
| 1271 | { | 1278 | { |
| 1272 | struct task_struct *p; | 1279 | struct task_struct *p; |
| @@ -1466,23 +1473,9 @@ static void pre_schedule_rt(struct rq *rq, struct task_struct *prev) | |||
| 1466 | pull_rt_task(rq); | 1473 | pull_rt_task(rq); |
| 1467 | } | 1474 | } |
| 1468 | 1475 | ||
| 1469 | /* | ||
| 1470 | * assumes rq->lock is held | ||
| 1471 | */ | ||
| 1472 | static int needs_post_schedule_rt(struct rq *rq) | ||
| 1473 | { | ||
| 1474 | return has_pushable_tasks(rq); | ||
| 1475 | } | ||
| 1476 | |||
| 1477 | static void post_schedule_rt(struct rq *rq) | 1476 | static void post_schedule_rt(struct rq *rq) |
| 1478 | { | 1477 | { |
| 1479 | /* | ||
| 1480 | * This is only called if needs_post_schedule_rt() indicates that | ||
| 1481 | * we need to push tasks away | ||
| 1482 | */ | ||
| 1483 | spin_lock_irq(&rq->lock); | ||
| 1484 | push_rt_tasks(rq); | 1478 | push_rt_tasks(rq); |
| 1485 | spin_unlock_irq(&rq->lock); | ||
| 1486 | } | 1479 | } |
| 1487 | 1480 | ||
| 1488 | /* | 1481 | /* |
| @@ -1758,7 +1751,6 @@ static const struct sched_class rt_sched_class = { | |||
| 1758 | .rq_online = rq_online_rt, | 1751 | .rq_online = rq_online_rt, |
| 1759 | .rq_offline = rq_offline_rt, | 1752 | .rq_offline = rq_offline_rt, |
| 1760 | .pre_schedule = pre_schedule_rt, | 1753 | .pre_schedule = pre_schedule_rt, |
| 1761 | .needs_post_schedule = needs_post_schedule_rt, | ||
| 1762 | .post_schedule = post_schedule_rt, | 1754 | .post_schedule = post_schedule_rt, |
| 1763 | .task_wake_up = task_wake_up_rt, | 1755 | .task_wake_up = task_wake_up_rt, |
| 1764 | .switched_from = switched_from_rt, | 1756 | .switched_from = switched_from_rt, |
diff --git a/kernel/softirq.c b/kernel/softirq.c index eb5e131a0485..7db25067cd2d 100644 --- a/kernel/softirq.c +++ b/kernel/softirq.c | |||
| @@ -227,7 +227,7 @@ restart: | |||
| 227 | preempt_count() = prev_count; | 227 | preempt_count() = prev_count; |
| 228 | } | 228 | } |
| 229 | 229 | ||
| 230 | rcu_bh_qsctr_inc(cpu); | 230 | rcu_bh_qs(cpu); |
| 231 | } | 231 | } |
| 232 | h++; | 232 | h++; |
| 233 | pending >>= 1; | 233 | pending >>= 1; |
| @@ -721,7 +721,7 @@ static int ksoftirqd(void * __bind_cpu) | |||
| 721 | preempt_enable_no_resched(); | 721 | preempt_enable_no_resched(); |
| 722 | cond_resched(); | 722 | cond_resched(); |
| 723 | preempt_disable(); | 723 | preempt_disable(); |
| 724 | rcu_qsctr_inc((long)__bind_cpu); | 724 | rcu_sched_qs((long)__bind_cpu); |
| 725 | } | 725 | } |
| 726 | preempt_enable(); | 726 | preempt_enable(); |
| 727 | set_current_state(TASK_INTERRUPTIBLE); | 727 | set_current_state(TASK_INTERRUPTIBLE); |
diff --git a/kernel/spinlock.c b/kernel/spinlock.c index 7932653c4ebd..5ddab730cb2f 100644 --- a/kernel/spinlock.c +++ b/kernel/spinlock.c | |||
| @@ -21,44 +21,29 @@ | |||
| 21 | #include <linux/debug_locks.h> | 21 | #include <linux/debug_locks.h> |
| 22 | #include <linux/module.h> | 22 | #include <linux/module.h> |
| 23 | 23 | ||
| 24 | #ifndef _spin_trylock | ||
| 24 | int __lockfunc _spin_trylock(spinlock_t *lock) | 25 | int __lockfunc _spin_trylock(spinlock_t *lock) |
| 25 | { | 26 | { |
| 26 | preempt_disable(); | 27 | return __spin_trylock(lock); |
| 27 | if (_raw_spin_trylock(lock)) { | ||
| 28 | spin_acquire(&lock->dep_map, 0, 1, _RET_IP_); | ||
| 29 | return 1; | ||
| 30 | } | ||
| 31 | |||
| 32 | preempt_enable(); | ||
| 33 | return 0; | ||
| 34 | } | 28 | } |
| 35 | EXPORT_SYMBOL(_spin_trylock); | 29 | EXPORT_SYMBOL(_spin_trylock); |
| 30 | #endif | ||
| 36 | 31 | ||
| 32 | #ifndef _read_trylock | ||
| 37 | int __lockfunc _read_trylock(rwlock_t *lock) | 33 | int __lockfunc _read_trylock(rwlock_t *lock) |
| 38 | { | 34 | { |
| 39 | preempt_disable(); | 35 | return __read_trylock(lock); |
| 40 | if (_raw_read_trylock(lock)) { | ||
| 41 | rwlock_acquire_read(&lock->dep_map, 0, 1, _RET_IP_); | ||
| 42 | return 1; | ||
| 43 | } | ||
| 44 | |||
| 45 | preempt_enable(); | ||
| 46 | return 0; | ||
| 47 | } | 36 | } |
| 48 | EXPORT_SYMBOL(_read_trylock); | 37 | EXPORT_SYMBOL(_read_trylock); |
| 38 | #endif | ||
| 49 | 39 | ||
| 40 | #ifndef _write_trylock | ||
| 50 | int __lockfunc _write_trylock(rwlock_t *lock) | 41 | int __lockfunc _write_trylock(rwlock_t *lock) |
| 51 | { | 42 | { |
| 52 | preempt_disable(); | 43 | return __write_trylock(lock); |
| 53 | if (_raw_write_trylock(lock)) { | ||
| 54 | rwlock_acquire(&lock->dep_map, 0, 1, _RET_IP_); | ||
| 55 | return 1; | ||
| 56 | } | ||
| 57 | |||
| 58 | preempt_enable(); | ||
| 59 | return 0; | ||
| 60 | } | 44 | } |
| 61 | EXPORT_SYMBOL(_write_trylock); | 45 | EXPORT_SYMBOL(_write_trylock); |
| 46 | #endif | ||
| 62 | 47 | ||
| 63 | /* | 48 | /* |
| 64 | * If lockdep is enabled then we use the non-preemption spin-ops | 49 | * If lockdep is enabled then we use the non-preemption spin-ops |
| @@ -67,132 +52,101 @@ EXPORT_SYMBOL(_write_trylock); | |||
| 67 | */ | 52 | */ |
| 68 | #if !defined(CONFIG_GENERIC_LOCKBREAK) || defined(CONFIG_DEBUG_LOCK_ALLOC) | 53 | #if !defined(CONFIG_GENERIC_LOCKBREAK) || defined(CONFIG_DEBUG_LOCK_ALLOC) |
| 69 | 54 | ||
| 55 | #ifndef _read_lock | ||
| 70 | void __lockfunc _read_lock(rwlock_t *lock) | 56 | void __lockfunc _read_lock(rwlock_t *lock) |
| 71 | { | 57 | { |
| 72 | preempt_disable(); | 58 | __read_lock(lock); |
| 73 | rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 74 | LOCK_CONTENDED(lock, _raw_read_trylock, _raw_read_lock); | ||
| 75 | } | 59 | } |
| 76 | EXPORT_SYMBOL(_read_lock); | 60 | EXPORT_SYMBOL(_read_lock); |
| 61 | #endif | ||
| 77 | 62 | ||
| 63 | #ifndef _spin_lock_irqsave | ||
| 78 | unsigned long __lockfunc _spin_lock_irqsave(spinlock_t *lock) | 64 | unsigned long __lockfunc _spin_lock_irqsave(spinlock_t *lock) |
| 79 | { | 65 | { |
| 80 | unsigned long flags; | 66 | return __spin_lock_irqsave(lock); |
| 81 | |||
| 82 | local_irq_save(flags); | ||
| 83 | preempt_disable(); | ||
| 84 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 85 | /* | ||
| 86 | * On lockdep we dont want the hand-coded irq-enable of | ||
| 87 | * _raw_spin_lock_flags() code, because lockdep assumes | ||
| 88 | * that interrupts are not re-enabled during lock-acquire: | ||
| 89 | */ | ||
| 90 | #ifdef CONFIG_LOCKDEP | ||
| 91 | LOCK_CONTENDED(lock, _raw_spin_trylock, _raw_spin_lock); | ||
| 92 | #else | ||
| 93 | _raw_spin_lock_flags(lock, &flags); | ||
| 94 | #endif | ||
| 95 | return flags; | ||
| 96 | } | 67 | } |
| 97 | EXPORT_SYMBOL(_spin_lock_irqsave); | 68 | EXPORT_SYMBOL(_spin_lock_irqsave); |
| 69 | #endif | ||
| 98 | 70 | ||
| 71 | #ifndef _spin_lock_irq | ||
| 99 | void __lockfunc _spin_lock_irq(spinlock_t *lock) | 72 | void __lockfunc _spin_lock_irq(spinlock_t *lock) |
| 100 | { | 73 | { |
| 101 | local_irq_disable(); | 74 | __spin_lock_irq(lock); |
| 102 | preempt_disable(); | ||
| 103 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 104 | LOCK_CONTENDED(lock, _raw_spin_trylock, _raw_spin_lock); | ||
| 105 | } | 75 | } |
| 106 | EXPORT_SYMBOL(_spin_lock_irq); | 76 | EXPORT_SYMBOL(_spin_lock_irq); |
| 77 | #endif | ||
| 107 | 78 | ||
| 79 | #ifndef _spin_lock_bh | ||
| 108 | void __lockfunc _spin_lock_bh(spinlock_t *lock) | 80 | void __lockfunc _spin_lock_bh(spinlock_t *lock) |
| 109 | { | 81 | { |
| 110 | local_bh_disable(); | 82 | __spin_lock_bh(lock); |
| 111 | preempt_disable(); | ||
| 112 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 113 | LOCK_CONTENDED(lock, _raw_spin_trylock, _raw_spin_lock); | ||
| 114 | } | 83 | } |
| 115 | EXPORT_SYMBOL(_spin_lock_bh); | 84 | EXPORT_SYMBOL(_spin_lock_bh); |
| 85 | #endif | ||
| 116 | 86 | ||
| 87 | #ifndef _read_lock_irqsave | ||
| 117 | unsigned long __lockfunc _read_lock_irqsave(rwlock_t *lock) | 88 | unsigned long __lockfunc _read_lock_irqsave(rwlock_t *lock) |
| 118 | { | 89 | { |
| 119 | unsigned long flags; | 90 | return __read_lock_irqsave(lock); |
| 120 | |||
| 121 | local_irq_save(flags); | ||
| 122 | preempt_disable(); | ||
| 123 | rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 124 | LOCK_CONTENDED_FLAGS(lock, _raw_read_trylock, _raw_read_lock, | ||
| 125 | _raw_read_lock_flags, &flags); | ||
| 126 | return flags; | ||
| 127 | } | 91 | } |
| 128 | EXPORT_SYMBOL(_read_lock_irqsave); | 92 | EXPORT_SYMBOL(_read_lock_irqsave); |
| 93 | #endif | ||
| 129 | 94 | ||
| 95 | #ifndef _read_lock_irq | ||
| 130 | void __lockfunc _read_lock_irq(rwlock_t *lock) | 96 | void __lockfunc _read_lock_irq(rwlock_t *lock) |
| 131 | { | 97 | { |
| 132 | local_irq_disable(); | 98 | __read_lock_irq(lock); |
| 133 | preempt_disable(); | ||
| 134 | rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 135 | LOCK_CONTENDED(lock, _raw_read_trylock, _raw_read_lock); | ||
| 136 | } | 99 | } |
| 137 | EXPORT_SYMBOL(_read_lock_irq); | 100 | EXPORT_SYMBOL(_read_lock_irq); |
| 101 | #endif | ||
| 138 | 102 | ||
| 103 | #ifndef _read_lock_bh | ||
| 139 | void __lockfunc _read_lock_bh(rwlock_t *lock) | 104 | void __lockfunc _read_lock_bh(rwlock_t *lock) |
| 140 | { | 105 | { |
| 141 | local_bh_disable(); | 106 | __read_lock_bh(lock); |
| 142 | preempt_disable(); | ||
| 143 | rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 144 | LOCK_CONTENDED(lock, _raw_read_trylock, _raw_read_lock); | ||
| 145 | } | 107 | } |
| 146 | EXPORT_SYMBOL(_read_lock_bh); | 108 | EXPORT_SYMBOL(_read_lock_bh); |
| 109 | #endif | ||
| 147 | 110 | ||
| 111 | #ifndef _write_lock_irqsave | ||
| 148 | unsigned long __lockfunc _write_lock_irqsave(rwlock_t *lock) | 112 | unsigned long __lockfunc _write_lock_irqsave(rwlock_t *lock) |
| 149 | { | 113 | { |
| 150 | unsigned long flags; | 114 | return __write_lock_irqsave(lock); |
| 151 | |||
| 152 | local_irq_save(flags); | ||
| 153 | preempt_disable(); | ||
| 154 | rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 155 | LOCK_CONTENDED_FLAGS(lock, _raw_write_trylock, _raw_write_lock, | ||
| 156 | _raw_write_lock_flags, &flags); | ||
| 157 | return flags; | ||
| 158 | } | 115 | } |
| 159 | EXPORT_SYMBOL(_write_lock_irqsave); | 116 | EXPORT_SYMBOL(_write_lock_irqsave); |
| 117 | #endif | ||
| 160 | 118 | ||
| 119 | #ifndef _write_lock_irq | ||
| 161 | void __lockfunc _write_lock_irq(rwlock_t *lock) | 120 | void __lockfunc _write_lock_irq(rwlock_t *lock) |
| 162 | { | 121 | { |
| 163 | local_irq_disable(); | 122 | __write_lock_irq(lock); |
| 164 | preempt_disable(); | ||
| 165 | rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 166 | LOCK_CONTENDED(lock, _raw_write_trylock, _raw_write_lock); | ||
| 167 | } | 123 | } |
| 168 | EXPORT_SYMBOL(_write_lock_irq); | 124 | EXPORT_SYMBOL(_write_lock_irq); |
| 125 | #endif | ||
| 169 | 126 | ||
| 127 | #ifndef _write_lock_bh | ||
| 170 | void __lockfunc _write_lock_bh(rwlock_t *lock) | 128 | void __lockfunc _write_lock_bh(rwlock_t *lock) |
| 171 | { | 129 | { |
| 172 | local_bh_disable(); | 130 | __write_lock_bh(lock); |
| 173 | preempt_disable(); | ||
| 174 | rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 175 | LOCK_CONTENDED(lock, _raw_write_trylock, _raw_write_lock); | ||
| 176 | } | 131 | } |
| 177 | EXPORT_SYMBOL(_write_lock_bh); | 132 | EXPORT_SYMBOL(_write_lock_bh); |
| 133 | #endif | ||
| 178 | 134 | ||
| 135 | #ifndef _spin_lock | ||
| 179 | void __lockfunc _spin_lock(spinlock_t *lock) | 136 | void __lockfunc _spin_lock(spinlock_t *lock) |
| 180 | { | 137 | { |
| 181 | preempt_disable(); | 138 | __spin_lock(lock); |
| 182 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 183 | LOCK_CONTENDED(lock, _raw_spin_trylock, _raw_spin_lock); | ||
| 184 | } | 139 | } |
| 185 | |||
| 186 | EXPORT_SYMBOL(_spin_lock); | 140 | EXPORT_SYMBOL(_spin_lock); |
| 141 | #endif | ||
| 187 | 142 | ||
| 143 | #ifndef _write_lock | ||
| 188 | void __lockfunc _write_lock(rwlock_t *lock) | 144 | void __lockfunc _write_lock(rwlock_t *lock) |
| 189 | { | 145 | { |
| 190 | preempt_disable(); | 146 | __write_lock(lock); |
| 191 | rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_); | ||
| 192 | LOCK_CONTENDED(lock, _raw_write_trylock, _raw_write_lock); | ||
| 193 | } | 147 | } |
| 194 | |||
| 195 | EXPORT_SYMBOL(_write_lock); | 148 | EXPORT_SYMBOL(_write_lock); |
| 149 | #endif | ||
| 196 | 150 | ||
| 197 | #else /* CONFIG_PREEMPT: */ | 151 | #else /* CONFIG_PREEMPT: */ |
| 198 | 152 | ||
| @@ -318,125 +272,109 @@ EXPORT_SYMBOL(_spin_lock_nest_lock); | |||
| 318 | 272 | ||
| 319 | #endif | 273 | #endif |
| 320 | 274 | ||
| 275 | #ifndef _spin_unlock | ||
| 321 | void __lockfunc _spin_unlock(spinlock_t *lock) | 276 | void __lockfunc _spin_unlock(spinlock_t *lock) |
| 322 | { | 277 | { |
| 323 | spin_release(&lock->dep_map, 1, _RET_IP_); | 278 | __spin_unlock(lock); |
| 324 | _raw_spin_unlock(lock); | ||
| 325 | preempt_enable(); | ||
| 326 | } | 279 | } |
| 327 | EXPORT_SYMBOL(_spin_unlock); | 280 | EXPORT_SYMBOL(_spin_unlock); |
| 281 | #endif | ||
| 328 | 282 | ||
| 283 | #ifndef _write_unlock | ||
| 329 | void __lockfunc _write_unlock(rwlock_t *lock) | 284 | void __lockfunc _write_unlock(rwlock_t *lock) |
| 330 | { | 285 | { |
| 331 | rwlock_release(&lock->dep_map, 1, _RET_IP_); | 286 | __write_unlock(lock); |
| 332 | _raw_write_unlock(lock); | ||
| 333 | preempt_enable(); | ||
| 334 | } | 287 | } |
| 335 | EXPORT_SYMBOL(_write_unlock); | 288 | EXPORT_SYMBOL(_write_unlock); |
| 289 | #endif | ||
| 336 | 290 | ||
| 291 | #ifndef _read_unlock | ||
| 337 | void __lockfunc _read_unlock(rwlock_t *lock) | 292 | void __lockfunc _read_unlock(rwlock_t *lock) |
| 338 | { | 293 | { |
| 339 | rwlock_release(&lock->dep_map, 1, _RET_IP_); | 294 | __read_unlock(lock); |
| 340 | _raw_read_unlock(lock); | ||
| 341 | preempt_enable(); | ||
| 342 | } | 295 | } |
| 343 | EXPORT_SYMBOL(_read_unlock); | 296 | EXPORT_SYMBOL(_read_unlock); |
| 297 | #endif | ||
| 344 | 298 | ||
| 299 | #ifndef _spin_unlock_irqrestore | ||
| 345 | void __lockfunc _spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags) | 300 | void __lockfunc _spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags) |
| 346 | { | 301 | { |
| 347 | spin_release(&lock->dep_map, 1, _RET_IP_); | 302 | __spin_unlock_irqrestore(lock, flags); |
| 348 | _raw_spin_unlock(lock); | ||
| 349 | local_irq_restore(flags); | ||
| 350 | preempt_enable(); | ||
| 351 | } | 303 | } |
| 352 | EXPORT_SYMBOL(_spin_unlock_irqrestore); | 304 | EXPORT_SYMBOL(_spin_unlock_irqrestore); |
| 305 | #endif | ||
| 353 | 306 | ||
| 307 | #ifndef _spin_unlock_irq | ||
| 354 | void __lockfunc _spin_unlock_irq(spinlock_t *lock) | 308 | void __lockfunc _spin_unlock_irq(spinlock_t *lock) |
| 355 | { | 309 | { |
| 356 | spin_release(&lock->dep_map, 1, _RET_IP_); | 310 | __spin_unlock_irq(lock); |
| 357 | _raw_spin_unlock(lock); | ||
| 358 | local_irq_enable(); | ||
| 359 | preempt_enable(); | ||
| 360 | } | 311 | } |
| 361 | EXPORT_SYMBOL(_spin_unlock_irq); | 312 | EXPORT_SYMBOL(_spin_unlock_irq); |
| 313 | #endif | ||
| 362 | 314 | ||
| 315 | #ifndef _spin_unlock_bh | ||
| 363 | void __lockfunc _spin_unlock_bh(spinlock_t *lock) | 316 | void __lockfunc _spin_unlock_bh(spinlock_t *lock) |
| 364 | { | 317 | { |
| 365 | spin_release(&lock->dep_map, 1, _RET_IP_); | 318 | __spin_unlock_bh(lock); |
| 366 | _raw_spin_unlock(lock); | ||
| 367 | preempt_enable_no_resched(); | ||
| 368 | local_bh_enable_ip((unsigned long)__builtin_return_address(0)); | ||
| 369 | } | 319 | } |
| 370 | EXPORT_SYMBOL(_spin_unlock_bh); | 320 | EXPORT_SYMBOL(_spin_unlock_bh); |
| 321 | #endif | ||
| 371 | 322 | ||
| 323 | #ifndef _read_unlock_irqrestore | ||
| 372 | void __lockfunc _read_unlock_irqrestore(rwlock_t *lock, unsigned long flags) | 324 | void __lockfunc _read_unlock_irqrestore(rwlock_t *lock, unsigned long flags) |
| 373 | { | 325 | { |
| 374 | rwlock_release(&lock->dep_map, 1, _RET_IP_); | 326 | __read_unlock_irqrestore(lock, flags); |
| 375 | _raw_read_unlock(lock); | ||
| 376 | local_irq_restore(flags); | ||
| 377 | preempt_enable(); | ||
| 378 | } | 327 | } |
| 379 | EXPORT_SYMBOL(_read_unlock_irqrestore); | 328 | EXPORT_SYMBOL(_read_unlock_irqrestore); |
| 329 | #endif | ||
| 380 | 330 | ||
| 331 | #ifndef _read_unlock_irq | ||
| 381 | void __lockfunc _read_unlock_irq(rwlock_t *lock) | 332 | void __lockfunc _read_unlock_irq(rwlock_t *lock) |
| 382 | { | 333 | { |
| 383 | rwlock_release(&lock->dep_map, 1, _RET_IP_); | 334 | __read_unlock_irq(lock); |
| 384 | _raw_read_unlock(lock); | ||
| 385 | local_irq_enable(); | ||
| 386 | preempt_enable(); | ||
| 387 | } | 335 | } |
| 388 | EXPORT_SYMBOL(_read_unlock_irq); | 336 | EXPORT_SYMBOL(_read_unlock_irq); |
| 337 | #endif | ||
| 389 | 338 | ||
| 339 | #ifndef _read_unlock_bh | ||
| 390 | void __lockfunc _read_unlock_bh(rwlock_t *lock) | 340 | void __lockfunc _read_unlock_bh(rwlock_t *lock) |
| 391 | { | 341 | { |
| 392 | rwlock_release(&lock->dep_map, 1, _RET_IP_); | 342 | __read_unlock_bh(lock); |
| 393 | _raw_read_unlock(lock); | ||
| 394 | preempt_enable_no_resched(); | ||
| 395 | local_bh_enable_ip((unsigned long)__builtin_return_address(0)); | ||
| 396 | } | 343 | } |
| 397 | EXPORT_SYMBOL(_read_unlock_bh); | 344 | EXPORT_SYMBOL(_read_unlock_bh); |
| 345 | #endif | ||
| 398 | 346 | ||
| 347 | #ifndef _write_unlock_irqrestore | ||
| 399 | void __lockfunc _write_unlock_irqrestore(rwlock_t *lock, unsigned long flags) | 348 | void __lockfunc _write_unlock_irqrestore(rwlock_t *lock, unsigned long flags) |
| 400 | { | 349 | { |
| 401 | rwlock_release(&lock->dep_map, 1, _RET_IP_); | 350 | __write_unlock_irqrestore(lock, flags); |
| 402 | _raw_write_unlock(lock); | ||
| 403 | local_irq_restore(flags); | ||
| 404 | preempt_enable(); | ||
| 405 | } | 351 | } |
| 406 | EXPORT_SYMBOL(_write_unlock_irqrestore); | 352 | EXPORT_SYMBOL(_write_unlock_irqrestore); |
| 353 | #endif | ||
| 407 | 354 | ||
| 355 | #ifndef _write_unlock_irq | ||
| 408 | void __lockfunc _write_unlock_irq(rwlock_t *lock) | 356 | void __lockfunc _write_unlock_irq(rwlock_t *lock) |
| 409 | { | 357 | { |
| 410 | rwlock_release(&lock->dep_map, 1, _RET_IP_); | 358 | __write_unlock_irq(lock); |
| 411 | _raw_write_unlock(lock); | ||
| 412 | local_irq_enable(); | ||
| 413 | preempt_enable(); | ||
| 414 | } | 359 | } |
| 415 | EXPORT_SYMBOL(_write_unlock_irq); | 360 | EXPORT_SYMBOL(_write_unlock_irq); |
| 361 | #endif | ||
| 416 | 362 | ||
| 363 | #ifndef _write_unlock_bh | ||
| 417 | void __lockfunc _write_unlock_bh(rwlock_t *lock) | 364 | void __lockfunc _write_unlock_bh(rwlock_t *lock) |
| 418 | { | 365 | { |
| 419 | rwlock_release(&lock->dep_map, 1, _RET_IP_); | 366 | __write_unlock_bh(lock); |
| 420 | _raw_write_unlock(lock); | ||
| 421 | preempt_enable_no_resched(); | ||
| 422 | local_bh_enable_ip((unsigned long)__builtin_return_address(0)); | ||
| 423 | } | 367 | } |
| 424 | EXPORT_SYMBOL(_write_unlock_bh); | 368 | EXPORT_SYMBOL(_write_unlock_bh); |
| 369 | #endif | ||
| 425 | 370 | ||
| 371 | #ifndef _spin_trylock_bh | ||
| 426 | int __lockfunc _spin_trylock_bh(spinlock_t *lock) | 372 | int __lockfunc _spin_trylock_bh(spinlock_t *lock) |
| 427 | { | 373 | { |
| 428 | local_bh_disable(); | 374 | return __spin_trylock_bh(lock); |
| 429 | preempt_disable(); | ||
| 430 | if (_raw_spin_trylock(lock)) { | ||
| 431 | spin_acquire(&lock->dep_map, 0, 1, _RET_IP_); | ||
| 432 | return 1; | ||
| 433 | } | ||
| 434 | |||
| 435 | preempt_enable_no_resched(); | ||
| 436 | local_bh_enable_ip((unsigned long)__builtin_return_address(0)); | ||
| 437 | return 0; | ||
| 438 | } | 375 | } |
| 439 | EXPORT_SYMBOL(_spin_trylock_bh); | 376 | EXPORT_SYMBOL(_spin_trylock_bh); |
| 377 | #endif | ||
| 440 | 378 | ||
| 441 | notrace int in_lock_functions(unsigned long addr) | 379 | notrace int in_lock_functions(unsigned long addr) |
| 442 | { | 380 | { |
diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 58be76017fd0..3125cff1c570 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c | |||
| @@ -49,7 +49,6 @@ | |||
| 49 | #include <linux/acpi.h> | 49 | #include <linux/acpi.h> |
| 50 | #include <linux/reboot.h> | 50 | #include <linux/reboot.h> |
| 51 | #include <linux/ftrace.h> | 51 | #include <linux/ftrace.h> |
| 52 | #include <linux/security.h> | ||
| 53 | #include <linux/slow-work.h> | 52 | #include <linux/slow-work.h> |
| 54 | #include <linux/perf_counter.h> | 53 | #include <linux/perf_counter.h> |
| 55 | 54 | ||
| @@ -246,6 +245,14 @@ static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */ | |||
| 246 | #endif | 245 | #endif |
| 247 | 246 | ||
| 248 | static struct ctl_table kern_table[] = { | 247 | static struct ctl_table kern_table[] = { |
| 248 | { | ||
| 249 | .ctl_name = CTL_UNNUMBERED, | ||
| 250 | .procname = "sched_child_runs_first", | ||
| 251 | .data = &sysctl_sched_child_runs_first, | ||
| 252 | .maxlen = sizeof(unsigned int), | ||
| 253 | .mode = 0644, | ||
| 254 | .proc_handler = &proc_dointvec, | ||
| 255 | }, | ||
| 249 | #ifdef CONFIG_SCHED_DEBUG | 256 | #ifdef CONFIG_SCHED_DEBUG |
| 250 | { | 257 | { |
| 251 | .ctl_name = CTL_UNNUMBERED, | 258 | .ctl_name = CTL_UNNUMBERED, |
| @@ -300,14 +307,6 @@ static struct ctl_table kern_table[] = { | |||
| 300 | }, | 307 | }, |
| 301 | { | 308 | { |
| 302 | .ctl_name = CTL_UNNUMBERED, | 309 | .ctl_name = CTL_UNNUMBERED, |
| 303 | .procname = "sched_child_runs_first", | ||
| 304 | .data = &sysctl_sched_child_runs_first, | ||
| 305 | .maxlen = sizeof(unsigned int), | ||
| 306 | .mode = 0644, | ||
| 307 | .proc_handler = &proc_dointvec, | ||
| 308 | }, | ||
| 309 | { | ||
| 310 | .ctl_name = CTL_UNNUMBERED, | ||
| 311 | .procname = "sched_features", | 310 | .procname = "sched_features", |
| 312 | .data = &sysctl_sched_features, | 311 | .data = &sysctl_sched_features, |
| 313 | .maxlen = sizeof(unsigned int), | 312 | .maxlen = sizeof(unsigned int), |
| @@ -332,6 +331,14 @@ static struct ctl_table kern_table[] = { | |||
| 332 | }, | 331 | }, |
| 333 | { | 332 | { |
| 334 | .ctl_name = CTL_UNNUMBERED, | 333 | .ctl_name = CTL_UNNUMBERED, |
| 334 | .procname = "sched_time_avg", | ||
| 335 | .data = &sysctl_sched_time_avg, | ||
| 336 | .maxlen = sizeof(unsigned int), | ||
| 337 | .mode = 0644, | ||
| 338 | .proc_handler = &proc_dointvec, | ||
| 339 | }, | ||
| 340 | { | ||
| 341 | .ctl_name = CTL_UNNUMBERED, | ||
| 335 | .procname = "timer_migration", | 342 | .procname = "timer_migration", |
| 336 | .data = &sysctl_timer_migration, | 343 | .data = &sysctl_timer_migration, |
| 337 | .maxlen = sizeof(unsigned int), | 344 | .maxlen = sizeof(unsigned int), |
diff --git a/kernel/taskstats.c b/kernel/taskstats.c index 888adbcca30c..ea8384d3caa7 100644 --- a/kernel/taskstats.c +++ b/kernel/taskstats.c | |||
| @@ -108,7 +108,7 @@ static int prepare_reply(struct genl_info *info, u8 cmd, struct sk_buff **skbp, | |||
| 108 | /* | 108 | /* |
| 109 | * Send taskstats data in @skb to listener with nl_pid @pid | 109 | * Send taskstats data in @skb to listener with nl_pid @pid |
| 110 | */ | 110 | */ |
| 111 | static int send_reply(struct sk_buff *skb, pid_t pid) | 111 | static int send_reply(struct sk_buff *skb, struct genl_info *info) |
| 112 | { | 112 | { |
| 113 | struct genlmsghdr *genlhdr = nlmsg_data(nlmsg_hdr(skb)); | 113 | struct genlmsghdr *genlhdr = nlmsg_data(nlmsg_hdr(skb)); |
| 114 | void *reply = genlmsg_data(genlhdr); | 114 | void *reply = genlmsg_data(genlhdr); |
| @@ -120,7 +120,7 @@ static int send_reply(struct sk_buff *skb, pid_t pid) | |||
| 120 | return rc; | 120 | return rc; |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | return genlmsg_unicast(skb, pid); | 123 | return genlmsg_reply(skb, info); |
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | /* | 126 | /* |
| @@ -150,7 +150,7 @@ static void send_cpu_listeners(struct sk_buff *skb, | |||
| 150 | if (!skb_next) | 150 | if (!skb_next) |
| 151 | break; | 151 | break; |
| 152 | } | 152 | } |
| 153 | rc = genlmsg_unicast(skb_cur, s->pid); | 153 | rc = genlmsg_unicast(&init_net, skb_cur, s->pid); |
| 154 | if (rc == -ECONNREFUSED) { | 154 | if (rc == -ECONNREFUSED) { |
| 155 | s->valid = 0; | 155 | s->valid = 0; |
| 156 | delcount++; | 156 | delcount++; |
| @@ -418,7 +418,7 @@ static int cgroupstats_user_cmd(struct sk_buff *skb, struct genl_info *info) | |||
| 418 | goto err; | 418 | goto err; |
| 419 | } | 419 | } |
| 420 | 420 | ||
| 421 | rc = send_reply(rep_skb, info->snd_pid); | 421 | rc = send_reply(rep_skb, info); |
| 422 | 422 | ||
| 423 | err: | 423 | err: |
| 424 | fput_light(file, fput_needed); | 424 | fput_light(file, fput_needed); |
| @@ -487,7 +487,7 @@ free_return_rc: | |||
| 487 | } else | 487 | } else |
| 488 | goto err; | 488 | goto err; |
| 489 | 489 | ||
| 490 | return send_reply(rep_skb, info->snd_pid); | 490 | return send_reply(rep_skb, info); |
| 491 | err: | 491 | err: |
| 492 | nlmsg_free(rep_skb); | 492 | nlmsg_free(rep_skb); |
| 493 | return rc; | 493 | return rc; |
diff --git a/kernel/timer.c b/kernel/timer.c index a7f07d5a6241..a3d25f415019 100644 --- a/kernel/timer.c +++ b/kernel/timer.c | |||
| @@ -1156,8 +1156,7 @@ void update_process_times(int user_tick) | |||
| 1156 | /* Note: this timer irq context must be accounted for as well. */ | 1156 | /* Note: this timer irq context must be accounted for as well. */ |
| 1157 | account_process_tick(p, user_tick); | 1157 | account_process_tick(p, user_tick); |
| 1158 | run_local_timers(); | 1158 | run_local_timers(); |
| 1159 | if (rcu_pending(cpu)) | 1159 | rcu_check_callbacks(cpu, user_tick); |
| 1160 | rcu_check_callbacks(cpu, user_tick); | ||
| 1161 | printk_tick(); | 1160 | printk_tick(); |
| 1162 | scheduler_tick(); | 1161 | scheduler_tick(); |
| 1163 | run_posix_cpu_timers(p); | 1162 | run_posix_cpu_timers(p); |
diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig index 019f380fd764..1ea0d1234f4a 100644 --- a/kernel/trace/Kconfig +++ b/kernel/trace/Kconfig | |||
| @@ -41,7 +41,7 @@ config HAVE_FTRACE_MCOUNT_RECORD | |||
| 41 | config HAVE_HW_BRANCH_TRACER | 41 | config HAVE_HW_BRANCH_TRACER |
| 42 | bool | 42 | bool |
| 43 | 43 | ||
| 44 | config HAVE_FTRACE_SYSCALLS | 44 | config HAVE_SYSCALL_TRACEPOINTS |
| 45 | bool | 45 | bool |
| 46 | 46 | ||
| 47 | config TRACER_MAX_TRACE | 47 | config TRACER_MAX_TRACE |
| @@ -60,9 +60,14 @@ config EVENT_TRACING | |||
| 60 | bool | 60 | bool |
| 61 | 61 | ||
| 62 | config CONTEXT_SWITCH_TRACER | 62 | config CONTEXT_SWITCH_TRACER |
| 63 | select MARKERS | ||
| 64 | bool | 63 | bool |
| 65 | 64 | ||
| 65 | config RING_BUFFER_ALLOW_SWAP | ||
| 66 | bool | ||
| 67 | help | ||
| 68 | Allow the use of ring_buffer_swap_cpu. | ||
| 69 | Adds a very slight overhead to tracing when enabled. | ||
| 70 | |||
| 66 | # All tracer options should select GENERIC_TRACER. For those options that are | 71 | # All tracer options should select GENERIC_TRACER. For those options that are |
| 67 | # enabled by all tracers (context switch and event tracer) they select TRACING. | 72 | # enabled by all tracers (context switch and event tracer) they select TRACING. |
| 68 | # This allows those options to appear when no other tracer is selected. But the | 73 | # This allows those options to appear when no other tracer is selected. But the |
| @@ -147,6 +152,7 @@ config IRQSOFF_TRACER | |||
| 147 | select TRACE_IRQFLAGS | 152 | select TRACE_IRQFLAGS |
| 148 | select GENERIC_TRACER | 153 | select GENERIC_TRACER |
| 149 | select TRACER_MAX_TRACE | 154 | select TRACER_MAX_TRACE |
| 155 | select RING_BUFFER_ALLOW_SWAP | ||
| 150 | help | 156 | help |
| 151 | This option measures the time spent in irqs-off critical | 157 | This option measures the time spent in irqs-off critical |
| 152 | sections, with microsecond accuracy. | 158 | sections, with microsecond accuracy. |
| @@ -168,6 +174,7 @@ config PREEMPT_TRACER | |||
| 168 | depends on PREEMPT | 174 | depends on PREEMPT |
| 169 | select GENERIC_TRACER | 175 | select GENERIC_TRACER |
| 170 | select TRACER_MAX_TRACE | 176 | select TRACER_MAX_TRACE |
| 177 | select RING_BUFFER_ALLOW_SWAP | ||
| 171 | help | 178 | help |
| 172 | This option measures the time spent in preemption off critical | 179 | This option measures the time spent in preemption off critical |
| 173 | sections, with microsecond accuracy. | 180 | sections, with microsecond accuracy. |
| @@ -211,7 +218,7 @@ config ENABLE_DEFAULT_TRACERS | |||
| 211 | 218 | ||
| 212 | config FTRACE_SYSCALLS | 219 | config FTRACE_SYSCALLS |
| 213 | bool "Trace syscalls" | 220 | bool "Trace syscalls" |
| 214 | depends on HAVE_FTRACE_SYSCALLS | 221 | depends on HAVE_SYSCALL_TRACEPOINTS |
| 215 | select GENERIC_TRACER | 222 | select GENERIC_TRACER |
| 216 | select KALLSYMS | 223 | select KALLSYMS |
| 217 | help | 224 | help |
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index 7a34cb563fec..3eb159c277c8 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c | |||
| @@ -65,13 +65,15 @@ static void trace_note(struct blk_trace *bt, pid_t pid, int action, | |||
| 65 | { | 65 | { |
| 66 | struct blk_io_trace *t; | 66 | struct blk_io_trace *t; |
| 67 | struct ring_buffer_event *event = NULL; | 67 | struct ring_buffer_event *event = NULL; |
| 68 | struct ring_buffer *buffer = NULL; | ||
| 68 | int pc = 0; | 69 | int pc = 0; |
| 69 | int cpu = smp_processor_id(); | 70 | int cpu = smp_processor_id(); |
| 70 | bool blk_tracer = blk_tracer_enabled; | 71 | bool blk_tracer = blk_tracer_enabled; |
| 71 | 72 | ||
| 72 | if (blk_tracer) { | 73 | if (blk_tracer) { |
| 74 | buffer = blk_tr->buffer; | ||
| 73 | pc = preempt_count(); | 75 | pc = preempt_count(); |
| 74 | event = trace_buffer_lock_reserve(blk_tr, TRACE_BLK, | 76 | event = trace_buffer_lock_reserve(buffer, TRACE_BLK, |
| 75 | sizeof(*t) + len, | 77 | sizeof(*t) + len, |
| 76 | 0, pc); | 78 | 0, pc); |
| 77 | if (!event) | 79 | if (!event) |
| @@ -96,7 +98,7 @@ record_it: | |||
| 96 | memcpy((void *) t + sizeof(*t), data, len); | 98 | memcpy((void *) t + sizeof(*t), data, len); |
| 97 | 99 | ||
| 98 | if (blk_tracer) | 100 | if (blk_tracer) |
| 99 | trace_buffer_unlock_commit(blk_tr, event, 0, pc); | 101 | trace_buffer_unlock_commit(buffer, event, 0, pc); |
| 100 | } | 102 | } |
| 101 | } | 103 | } |
| 102 | 104 | ||
| @@ -179,6 +181,7 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes, | |||
| 179 | { | 181 | { |
| 180 | struct task_struct *tsk = current; | 182 | struct task_struct *tsk = current; |
| 181 | struct ring_buffer_event *event = NULL; | 183 | struct ring_buffer_event *event = NULL; |
| 184 | struct ring_buffer *buffer = NULL; | ||
| 182 | struct blk_io_trace *t; | 185 | struct blk_io_trace *t; |
| 183 | unsigned long flags = 0; | 186 | unsigned long flags = 0; |
| 184 | unsigned long *sequence; | 187 | unsigned long *sequence; |
| @@ -204,8 +207,9 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes, | |||
| 204 | if (blk_tracer) { | 207 | if (blk_tracer) { |
| 205 | tracing_record_cmdline(current); | 208 | tracing_record_cmdline(current); |
| 206 | 209 | ||
| 210 | buffer = blk_tr->buffer; | ||
| 207 | pc = preempt_count(); | 211 | pc = preempt_count(); |
| 208 | event = trace_buffer_lock_reserve(blk_tr, TRACE_BLK, | 212 | event = trace_buffer_lock_reserve(buffer, TRACE_BLK, |
| 209 | sizeof(*t) + pdu_len, | 213 | sizeof(*t) + pdu_len, |
| 210 | 0, pc); | 214 | 0, pc); |
| 211 | if (!event) | 215 | if (!event) |
| @@ -252,7 +256,7 @@ record_it: | |||
| 252 | memcpy((void *) t + sizeof(*t), pdu_data, pdu_len); | 256 | memcpy((void *) t + sizeof(*t), pdu_data, pdu_len); |
| 253 | 257 | ||
| 254 | if (blk_tracer) { | 258 | if (blk_tracer) { |
| 255 | trace_buffer_unlock_commit(blk_tr, event, 0, pc); | 259 | trace_buffer_unlock_commit(buffer, event, 0, pc); |
| 256 | return; | 260 | return; |
| 257 | } | 261 | } |
| 258 | } | 262 | } |
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 25edd5cc5935..8c804e24f96f 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c | |||
| @@ -1016,71 +1016,35 @@ static int | |||
| 1016 | __ftrace_replace_code(struct dyn_ftrace *rec, int enable) | 1016 | __ftrace_replace_code(struct dyn_ftrace *rec, int enable) |
| 1017 | { | 1017 | { |
| 1018 | unsigned long ftrace_addr; | 1018 | unsigned long ftrace_addr; |
| 1019 | unsigned long ip, fl; | 1019 | unsigned long flag = 0UL; |
| 1020 | 1020 | ||
| 1021 | ftrace_addr = (unsigned long)FTRACE_ADDR; | 1021 | ftrace_addr = (unsigned long)FTRACE_ADDR; |
| 1022 | 1022 | ||
| 1023 | ip = rec->ip; | ||
| 1024 | |||
| 1025 | /* | 1023 | /* |
| 1026 | * If this record is not to be traced and | 1024 | * If this record is not to be traced or we want to disable it, |
| 1027 | * it is not enabled then do nothing. | 1025 | * then disable it. |
| 1028 | * | 1026 | * |
| 1029 | * If this record is not to be traced and | 1027 | * If we want to enable it and filtering is off, then enable it. |
| 1030 | * it is enabled then disable it. | ||
| 1031 | * | 1028 | * |
| 1029 | * If we want to enable it and filtering is on, enable it only if | ||
| 1030 | * it's filtered | ||
| 1032 | */ | 1031 | */ |
| 1033 | if (rec->flags & FTRACE_FL_NOTRACE) { | 1032 | if (enable && !(rec->flags & FTRACE_FL_NOTRACE)) { |
| 1034 | if (rec->flags & FTRACE_FL_ENABLED) | 1033 | if (!ftrace_filtered || (rec->flags & FTRACE_FL_FILTER)) |
| 1035 | rec->flags &= ~FTRACE_FL_ENABLED; | 1034 | flag = FTRACE_FL_ENABLED; |
| 1036 | else | 1035 | } |
| 1037 | return 0; | ||
| 1038 | |||
| 1039 | } else if (ftrace_filtered && enable) { | ||
| 1040 | /* | ||
| 1041 | * Filtering is on: | ||
| 1042 | */ | ||
| 1043 | |||
| 1044 | fl = rec->flags & (FTRACE_FL_FILTER | FTRACE_FL_ENABLED); | ||
| 1045 | |||
| 1046 | /* Record is filtered and enabled, do nothing */ | ||
| 1047 | if (fl == (FTRACE_FL_FILTER | FTRACE_FL_ENABLED)) | ||
| 1048 | return 0; | ||
| 1049 | |||
| 1050 | /* Record is not filtered or enabled, do nothing */ | ||
| 1051 | if (!fl) | ||
| 1052 | return 0; | ||
| 1053 | |||
| 1054 | /* Record is not filtered but enabled, disable it */ | ||
| 1055 | if (fl == FTRACE_FL_ENABLED) | ||
| 1056 | rec->flags &= ~FTRACE_FL_ENABLED; | ||
| 1057 | else | ||
| 1058 | /* Otherwise record is filtered but not enabled, enable it */ | ||
| 1059 | rec->flags |= FTRACE_FL_ENABLED; | ||
| 1060 | } else { | ||
| 1061 | /* Disable or not filtered */ | ||
| 1062 | |||
| 1063 | if (enable) { | ||
| 1064 | /* if record is enabled, do nothing */ | ||
| 1065 | if (rec->flags & FTRACE_FL_ENABLED) | ||
| 1066 | return 0; | ||
| 1067 | |||
| 1068 | rec->flags |= FTRACE_FL_ENABLED; | ||
| 1069 | |||
| 1070 | } else { | ||
| 1071 | 1036 | ||
| 1072 | /* if record is not enabled, do nothing */ | 1037 | /* If the state of this record hasn't changed, then do nothing */ |
| 1073 | if (!(rec->flags & FTRACE_FL_ENABLED)) | 1038 | if ((rec->flags & FTRACE_FL_ENABLED) == flag) |
| 1074 | return 0; | 1039 | return 0; |
| 1075 | 1040 | ||
| 1076 | rec->flags &= ~FTRACE_FL_ENABLED; | 1041 | if (flag) { |
| 1077 | } | 1042 | rec->flags |= FTRACE_FL_ENABLED; |
| 1043 | return ftrace_make_call(rec, ftrace_addr); | ||
| 1078 | } | 1044 | } |
| 1079 | 1045 | ||
| 1080 | if (rec->flags & FTRACE_FL_ENABLED) | 1046 | rec->flags &= ~FTRACE_FL_ENABLED; |
| 1081 | return ftrace_make_call(rec, ftrace_addr); | 1047 | return ftrace_make_nop(NULL, rec, ftrace_addr); |
| 1082 | else | ||
| 1083 | return ftrace_make_nop(NULL, rec, ftrace_addr); | ||
| 1084 | } | 1048 | } |
| 1085 | 1049 | ||
| 1086 | static void ftrace_replace_code(int enable) | 1050 | static void ftrace_replace_code(int enable) |
| @@ -1375,7 +1339,6 @@ struct ftrace_iterator { | |||
| 1375 | unsigned flags; | 1339 | unsigned flags; |
| 1376 | unsigned char buffer[FTRACE_BUFF_MAX+1]; | 1340 | unsigned char buffer[FTRACE_BUFF_MAX+1]; |
| 1377 | unsigned buffer_idx; | 1341 | unsigned buffer_idx; |
| 1378 | unsigned filtered; | ||
| 1379 | }; | 1342 | }; |
| 1380 | 1343 | ||
| 1381 | static void * | 1344 | static void * |
| @@ -1438,18 +1401,13 @@ static int t_hash_show(struct seq_file *m, void *v) | |||
| 1438 | { | 1401 | { |
| 1439 | struct ftrace_func_probe *rec; | 1402 | struct ftrace_func_probe *rec; |
| 1440 | struct hlist_node *hnd = v; | 1403 | struct hlist_node *hnd = v; |
| 1441 | char str[KSYM_SYMBOL_LEN]; | ||
| 1442 | 1404 | ||
| 1443 | rec = hlist_entry(hnd, struct ftrace_func_probe, node); | 1405 | rec = hlist_entry(hnd, struct ftrace_func_probe, node); |
| 1444 | 1406 | ||
| 1445 | if (rec->ops->print) | 1407 | if (rec->ops->print) |
| 1446 | return rec->ops->print(m, rec->ip, rec->ops, rec->data); | 1408 | return rec->ops->print(m, rec->ip, rec->ops, rec->data); |
| 1447 | 1409 | ||
| 1448 | kallsyms_lookup(rec->ip, NULL, NULL, NULL, str); | 1410 | seq_printf(m, "%pf:%pf", (void *)rec->ip, (void *)rec->ops->func); |
| 1449 | seq_printf(m, "%s:", str); | ||
| 1450 | |||
| 1451 | kallsyms_lookup((unsigned long)rec->ops->func, NULL, NULL, NULL, str); | ||
| 1452 | seq_printf(m, "%s", str); | ||
| 1453 | 1411 | ||
| 1454 | if (rec->data) | 1412 | if (rec->data) |
| 1455 | seq_printf(m, ":%p", rec->data); | 1413 | seq_printf(m, ":%p", rec->data); |
| @@ -1547,7 +1505,6 @@ static int t_show(struct seq_file *m, void *v) | |||
| 1547 | { | 1505 | { |
| 1548 | struct ftrace_iterator *iter = m->private; | 1506 | struct ftrace_iterator *iter = m->private; |
| 1549 | struct dyn_ftrace *rec = v; | 1507 | struct dyn_ftrace *rec = v; |
| 1550 | char str[KSYM_SYMBOL_LEN]; | ||
| 1551 | 1508 | ||
| 1552 | if (iter->flags & FTRACE_ITER_HASH) | 1509 | if (iter->flags & FTRACE_ITER_HASH) |
| 1553 | return t_hash_show(m, v); | 1510 | return t_hash_show(m, v); |
| @@ -1560,9 +1517,7 @@ static int t_show(struct seq_file *m, void *v) | |||
| 1560 | if (!rec) | 1517 | if (!rec) |
| 1561 | return 0; | 1518 | return 0; |
| 1562 | 1519 | ||
| 1563 | kallsyms_lookup(rec->ip, NULL, NULL, NULL, str); | 1520 | seq_printf(m, "%pf\n", (void *)rec->ip); |
| 1564 | |||
| 1565 | seq_printf(m, "%s\n", str); | ||
| 1566 | 1521 | ||
| 1567 | return 0; | 1522 | return 0; |
| 1568 | } | 1523 | } |
| @@ -1601,17 +1556,6 @@ ftrace_avail_open(struct inode *inode, struct file *file) | |||
| 1601 | return ret; | 1556 | return ret; |
| 1602 | } | 1557 | } |
| 1603 | 1558 | ||
| 1604 | int ftrace_avail_release(struct inode *inode, struct file *file) | ||
| 1605 | { | ||
| 1606 | struct seq_file *m = (struct seq_file *)file->private_data; | ||
| 1607 | struct ftrace_iterator *iter = m->private; | ||
| 1608 | |||
| 1609 | seq_release(inode, file); | ||
| 1610 | kfree(iter); | ||
| 1611 | |||
| 1612 | return 0; | ||
| 1613 | } | ||
| 1614 | |||
| 1615 | static int | 1559 | static int |
| 1616 | ftrace_failures_open(struct inode *inode, struct file *file) | 1560 | ftrace_failures_open(struct inode *inode, struct file *file) |
| 1617 | { | 1561 | { |
| @@ -2317,7 +2261,6 @@ ftrace_regex_write(struct file *file, const char __user *ubuf, | |||
| 2317 | } | 2261 | } |
| 2318 | 2262 | ||
| 2319 | if (isspace(ch)) { | 2263 | if (isspace(ch)) { |
| 2320 | iter->filtered++; | ||
| 2321 | iter->buffer[iter->buffer_idx] = 0; | 2264 | iter->buffer[iter->buffer_idx] = 0; |
| 2322 | ret = ftrace_process_regex(iter->buffer, | 2265 | ret = ftrace_process_regex(iter->buffer, |
| 2323 | iter->buffer_idx, enable); | 2266 | iter->buffer_idx, enable); |
| @@ -2448,7 +2391,6 @@ ftrace_regex_release(struct inode *inode, struct file *file, int enable) | |||
| 2448 | iter = file->private_data; | 2391 | iter = file->private_data; |
| 2449 | 2392 | ||
| 2450 | if (iter->buffer_idx) { | 2393 | if (iter->buffer_idx) { |
| 2451 | iter->filtered++; | ||
| 2452 | iter->buffer[iter->buffer_idx] = 0; | 2394 | iter->buffer[iter->buffer_idx] = 0; |
| 2453 | ftrace_match_records(iter->buffer, iter->buffer_idx, enable); | 2395 | ftrace_match_records(iter->buffer, iter->buffer_idx, enable); |
| 2454 | } | 2396 | } |
| @@ -2479,14 +2421,14 @@ static const struct file_operations ftrace_avail_fops = { | |||
| 2479 | .open = ftrace_avail_open, | 2421 | .open = ftrace_avail_open, |
| 2480 | .read = seq_read, | 2422 | .read = seq_read, |
| 2481 | .llseek = seq_lseek, | 2423 | .llseek = seq_lseek, |
| 2482 | .release = ftrace_avail_release, | 2424 | .release = seq_release_private, |
| 2483 | }; | 2425 | }; |
| 2484 | 2426 | ||
| 2485 | static const struct file_operations ftrace_failures_fops = { | 2427 | static const struct file_operations ftrace_failures_fops = { |
| 2486 | .open = ftrace_failures_open, | 2428 | .open = ftrace_failures_open, |
| 2487 | .read = seq_read, | 2429 | .read = seq_read, |
| 2488 | .llseek = seq_lseek, | 2430 | .llseek = seq_lseek, |
| 2489 | .release = ftrace_avail_release, | 2431 | .release = seq_release_private, |
| 2490 | }; | 2432 | }; |
| 2491 | 2433 | ||
| 2492 | static const struct file_operations ftrace_filter_fops = { | 2434 | static const struct file_operations ftrace_filter_fops = { |
| @@ -2548,7 +2490,6 @@ static void g_stop(struct seq_file *m, void *p) | |||
| 2548 | static int g_show(struct seq_file *m, void *v) | 2490 | static int g_show(struct seq_file *m, void *v) |
| 2549 | { | 2491 | { |
| 2550 | unsigned long *ptr = v; | 2492 | unsigned long *ptr = v; |
| 2551 | char str[KSYM_SYMBOL_LEN]; | ||
| 2552 | 2493 | ||
| 2553 | if (!ptr) | 2494 | if (!ptr) |
| 2554 | return 0; | 2495 | return 0; |
| @@ -2558,9 +2499,7 @@ static int g_show(struct seq_file *m, void *v) | |||
| 2558 | return 0; | 2499 | return 0; |
| 2559 | } | 2500 | } |
| 2560 | 2501 | ||
| 2561 | kallsyms_lookup(*ptr, NULL, NULL, NULL, str); | 2502 | seq_printf(m, "%pf\n", v); |
| 2562 | |||
| 2563 | seq_printf(m, "%s\n", str); | ||
| 2564 | 2503 | ||
| 2565 | return 0; | 2504 | return 0; |
| 2566 | } | 2505 | } |
diff --git a/kernel/trace/kmemtrace.c b/kernel/trace/kmemtrace.c index 1edaa9516e81..81b1645c8549 100644 --- a/kernel/trace/kmemtrace.c +++ b/kernel/trace/kmemtrace.c | |||
| @@ -183,11 +183,9 @@ static void kmemtrace_stop_probes(void) | |||
| 183 | 183 | ||
| 184 | static int kmem_trace_init(struct trace_array *tr) | 184 | static int kmem_trace_init(struct trace_array *tr) |
| 185 | { | 185 | { |
| 186 | int cpu; | ||
| 187 | kmemtrace_array = tr; | 186 | kmemtrace_array = tr; |
| 188 | 187 | ||
| 189 | for_each_cpu(cpu, cpu_possible_mask) | 188 | tracing_reset_online_cpus(tr); |
| 190 | tracing_reset(tr, cpu); | ||
| 191 | 189 | ||
| 192 | kmemtrace_start_probes(); | 190 | kmemtrace_start_probes(); |
| 193 | 191 | ||
| @@ -239,12 +237,52 @@ struct kmemtrace_user_event_alloc { | |||
| 239 | }; | 237 | }; |
| 240 | 238 | ||
| 241 | static enum print_line_t | 239 | static enum print_line_t |
| 242 | kmemtrace_print_alloc_user(struct trace_iterator *iter, | 240 | kmemtrace_print_alloc(struct trace_iterator *iter, int flags) |
| 243 | struct kmemtrace_alloc_entry *entry) | ||
| 244 | { | 241 | { |
| 245 | struct kmemtrace_user_event_alloc *ev_alloc; | ||
| 246 | struct trace_seq *s = &iter->seq; | 242 | struct trace_seq *s = &iter->seq; |
| 243 | struct kmemtrace_alloc_entry *entry; | ||
| 244 | int ret; | ||
| 245 | |||
| 246 | trace_assign_type(entry, iter->ent); | ||
| 247 | |||
| 248 | ret = trace_seq_printf(s, "type_id %d call_site %pF ptr %lu " | ||
| 249 | "bytes_req %lu bytes_alloc %lu gfp_flags %lu node %d\n", | ||
| 250 | entry->type_id, (void *)entry->call_site, (unsigned long)entry->ptr, | ||
| 251 | (unsigned long)entry->bytes_req, (unsigned long)entry->bytes_alloc, | ||
| 252 | (unsigned long)entry->gfp_flags, entry->node); | ||
| 253 | |||
| 254 | if (!ret) | ||
| 255 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 256 | return TRACE_TYPE_HANDLED; | ||
| 257 | } | ||
| 258 | |||
| 259 | static enum print_line_t | ||
| 260 | kmemtrace_print_free(struct trace_iterator *iter, int flags) | ||
| 261 | { | ||
| 262 | struct trace_seq *s = &iter->seq; | ||
| 263 | struct kmemtrace_free_entry *entry; | ||
| 264 | int ret; | ||
| 265 | |||
| 266 | trace_assign_type(entry, iter->ent); | ||
| 267 | |||
| 268 | ret = trace_seq_printf(s, "type_id %d call_site %pF ptr %lu\n", | ||
| 269 | entry->type_id, (void *)entry->call_site, | ||
| 270 | (unsigned long)entry->ptr); | ||
| 271 | |||
| 272 | if (!ret) | ||
| 273 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 274 | return TRACE_TYPE_HANDLED; | ||
| 275 | } | ||
| 276 | |||
| 277 | static enum print_line_t | ||
| 278 | kmemtrace_print_alloc_user(struct trace_iterator *iter, int flags) | ||
| 279 | { | ||
| 280 | struct trace_seq *s = &iter->seq; | ||
| 281 | struct kmemtrace_alloc_entry *entry; | ||
| 247 | struct kmemtrace_user_event *ev; | 282 | struct kmemtrace_user_event *ev; |
| 283 | struct kmemtrace_user_event_alloc *ev_alloc; | ||
| 284 | |||
| 285 | trace_assign_type(entry, iter->ent); | ||
| 248 | 286 | ||
| 249 | ev = trace_seq_reserve(s, sizeof(*ev)); | 287 | ev = trace_seq_reserve(s, sizeof(*ev)); |
| 250 | if (!ev) | 288 | if (!ev) |
| @@ -271,12 +309,14 @@ kmemtrace_print_alloc_user(struct trace_iterator *iter, | |||
| 271 | } | 309 | } |
| 272 | 310 | ||
| 273 | static enum print_line_t | 311 | static enum print_line_t |
| 274 | kmemtrace_print_free_user(struct trace_iterator *iter, | 312 | kmemtrace_print_free_user(struct trace_iterator *iter, int flags) |
| 275 | struct kmemtrace_free_entry *entry) | ||
| 276 | { | 313 | { |
| 277 | struct trace_seq *s = &iter->seq; | 314 | struct trace_seq *s = &iter->seq; |
| 315 | struct kmemtrace_free_entry *entry; | ||
| 278 | struct kmemtrace_user_event *ev; | 316 | struct kmemtrace_user_event *ev; |
| 279 | 317 | ||
| 318 | trace_assign_type(entry, iter->ent); | ||
| 319 | |||
| 280 | ev = trace_seq_reserve(s, sizeof(*ev)); | 320 | ev = trace_seq_reserve(s, sizeof(*ev)); |
| 281 | if (!ev) | 321 | if (!ev) |
| 282 | return TRACE_TYPE_PARTIAL_LINE; | 322 | return TRACE_TYPE_PARTIAL_LINE; |
| @@ -294,12 +334,14 @@ kmemtrace_print_free_user(struct trace_iterator *iter, | |||
| 294 | 334 | ||
| 295 | /* The two other following provide a more minimalistic output */ | 335 | /* The two other following provide a more minimalistic output */ |
| 296 | static enum print_line_t | 336 | static enum print_line_t |
| 297 | kmemtrace_print_alloc_compress(struct trace_iterator *iter, | 337 | kmemtrace_print_alloc_compress(struct trace_iterator *iter) |
| 298 | struct kmemtrace_alloc_entry *entry) | ||
| 299 | { | 338 | { |
| 339 | struct kmemtrace_alloc_entry *entry; | ||
| 300 | struct trace_seq *s = &iter->seq; | 340 | struct trace_seq *s = &iter->seq; |
| 301 | int ret; | 341 | int ret; |
| 302 | 342 | ||
| 343 | trace_assign_type(entry, iter->ent); | ||
| 344 | |||
| 303 | /* Alloc entry */ | 345 | /* Alloc entry */ |
| 304 | ret = trace_seq_printf(s, " + "); | 346 | ret = trace_seq_printf(s, " + "); |
| 305 | if (!ret) | 347 | if (!ret) |
| @@ -345,29 +387,24 @@ kmemtrace_print_alloc_compress(struct trace_iterator *iter, | |||
| 345 | if (!ret) | 387 | if (!ret) |
| 346 | return TRACE_TYPE_PARTIAL_LINE; | 388 | return TRACE_TYPE_PARTIAL_LINE; |
| 347 | 389 | ||
| 348 | /* Node */ | 390 | /* Node and call site*/ |
| 349 | ret = trace_seq_printf(s, "%4d ", entry->node); | 391 | ret = trace_seq_printf(s, "%4d %pf\n", entry->node, |
| 350 | if (!ret) | 392 | (void *)entry->call_site); |
| 351 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 352 | |||
| 353 | /* Call site */ | ||
| 354 | ret = seq_print_ip_sym(s, entry->call_site, 0); | ||
| 355 | if (!ret) | 393 | if (!ret) |
| 356 | return TRACE_TYPE_PARTIAL_LINE; | 394 | return TRACE_TYPE_PARTIAL_LINE; |
| 357 | 395 | ||
| 358 | if (!trace_seq_printf(s, "\n")) | ||
| 359 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 360 | |||
| 361 | return TRACE_TYPE_HANDLED; | 396 | return TRACE_TYPE_HANDLED; |
| 362 | } | 397 | } |
| 363 | 398 | ||
| 364 | static enum print_line_t | 399 | static enum print_line_t |
| 365 | kmemtrace_print_free_compress(struct trace_iterator *iter, | 400 | kmemtrace_print_free_compress(struct trace_iterator *iter) |
| 366 | struct kmemtrace_free_entry *entry) | ||
| 367 | { | 401 | { |
| 402 | struct kmemtrace_free_entry *entry; | ||
| 368 | struct trace_seq *s = &iter->seq; | 403 | struct trace_seq *s = &iter->seq; |
| 369 | int ret; | 404 | int ret; |
| 370 | 405 | ||
| 406 | trace_assign_type(entry, iter->ent); | ||
| 407 | |||
| 371 | /* Free entry */ | 408 | /* Free entry */ |
| 372 | ret = trace_seq_printf(s, " - "); | 409 | ret = trace_seq_printf(s, " - "); |
| 373 | if (!ret) | 410 | if (!ret) |
| @@ -401,19 +438,11 @@ kmemtrace_print_free_compress(struct trace_iterator *iter, | |||
| 401 | if (!ret) | 438 | if (!ret) |
| 402 | return TRACE_TYPE_PARTIAL_LINE; | 439 | return TRACE_TYPE_PARTIAL_LINE; |
| 403 | 440 | ||
| 404 | /* Skip node */ | 441 | /* Skip node and print call site*/ |
| 405 | ret = trace_seq_printf(s, " "); | 442 | ret = trace_seq_printf(s, " %pf\n", (void *)entry->call_site); |
| 406 | if (!ret) | 443 | if (!ret) |
| 407 | return TRACE_TYPE_PARTIAL_LINE; | 444 | return TRACE_TYPE_PARTIAL_LINE; |
| 408 | 445 | ||
| 409 | /* Call site */ | ||
| 410 | ret = seq_print_ip_sym(s, entry->call_site, 0); | ||
| 411 | if (!ret) | ||
| 412 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 413 | |||
| 414 | if (!trace_seq_printf(s, "\n")) | ||
| 415 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 416 | |||
| 417 | return TRACE_TYPE_HANDLED; | 446 | return TRACE_TYPE_HANDLED; |
| 418 | } | 447 | } |
| 419 | 448 | ||
| @@ -421,32 +450,31 @@ static enum print_line_t kmemtrace_print_line(struct trace_iterator *iter) | |||
| 421 | { | 450 | { |
| 422 | struct trace_entry *entry = iter->ent; | 451 | struct trace_entry *entry = iter->ent; |
| 423 | 452 | ||
| 424 | switch (entry->type) { | 453 | if (!(kmem_tracer_flags.val & TRACE_KMEM_OPT_MINIMAL)) |
| 425 | case TRACE_KMEM_ALLOC: { | 454 | return TRACE_TYPE_UNHANDLED; |
| 426 | struct kmemtrace_alloc_entry *field; | ||
| 427 | |||
| 428 | trace_assign_type(field, entry); | ||
| 429 | if (kmem_tracer_flags.val & TRACE_KMEM_OPT_MINIMAL) | ||
| 430 | return kmemtrace_print_alloc_compress(iter, field); | ||
| 431 | else | ||
| 432 | return kmemtrace_print_alloc_user(iter, field); | ||
| 433 | } | ||
| 434 | |||
| 435 | case TRACE_KMEM_FREE: { | ||
| 436 | struct kmemtrace_free_entry *field; | ||
| 437 | |||
| 438 | trace_assign_type(field, entry); | ||
| 439 | if (kmem_tracer_flags.val & TRACE_KMEM_OPT_MINIMAL) | ||
| 440 | return kmemtrace_print_free_compress(iter, field); | ||
| 441 | else | ||
| 442 | return kmemtrace_print_free_user(iter, field); | ||
| 443 | } | ||
| 444 | 455 | ||
| 456 | switch (entry->type) { | ||
| 457 | case TRACE_KMEM_ALLOC: | ||
| 458 | return kmemtrace_print_alloc_compress(iter); | ||
| 459 | case TRACE_KMEM_FREE: | ||
| 460 | return kmemtrace_print_free_compress(iter); | ||
| 445 | default: | 461 | default: |
| 446 | return TRACE_TYPE_UNHANDLED; | 462 | return TRACE_TYPE_UNHANDLED; |
| 447 | } | 463 | } |
| 448 | } | 464 | } |
| 449 | 465 | ||
| 466 | static struct trace_event kmem_trace_alloc = { | ||
| 467 | .type = TRACE_KMEM_ALLOC, | ||
| 468 | .trace = kmemtrace_print_alloc, | ||
| 469 | .binary = kmemtrace_print_alloc_user, | ||
| 470 | }; | ||
| 471 | |||
| 472 | static struct trace_event kmem_trace_free = { | ||
| 473 | .type = TRACE_KMEM_FREE, | ||
| 474 | .trace = kmemtrace_print_free, | ||
| 475 | .binary = kmemtrace_print_free_user, | ||
| 476 | }; | ||
| 477 | |||
| 450 | static struct tracer kmem_tracer __read_mostly = { | 478 | static struct tracer kmem_tracer __read_mostly = { |
| 451 | .name = "kmemtrace", | 479 | .name = "kmemtrace", |
| 452 | .init = kmem_trace_init, | 480 | .init = kmem_trace_init, |
| @@ -463,6 +491,21 @@ void kmemtrace_init(void) | |||
| 463 | 491 | ||
| 464 | static int __init init_kmem_tracer(void) | 492 | static int __init init_kmem_tracer(void) |
| 465 | { | 493 | { |
| 466 | return register_tracer(&kmem_tracer); | 494 | if (!register_ftrace_event(&kmem_trace_alloc)) { |
| 495 | pr_warning("Warning: could not register kmem events\n"); | ||
| 496 | return 1; | ||
| 497 | } | ||
| 498 | |||
| 499 | if (!register_ftrace_event(&kmem_trace_free)) { | ||
| 500 | pr_warning("Warning: could not register kmem events\n"); | ||
| 501 | return 1; | ||
| 502 | } | ||
| 503 | |||
| 504 | if (!register_tracer(&kmem_tracer)) { | ||
| 505 | pr_warning("Warning: could not register the kmem tracer\n"); | ||
| 506 | return 1; | ||
| 507 | } | ||
| 508 | |||
| 509 | return 0; | ||
| 467 | } | 510 | } |
| 468 | device_initcall(init_kmem_tracer); | 511 | device_initcall(init_kmem_tracer); |
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index a330513d96ce..454e74e718cf 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c | |||
| @@ -218,17 +218,12 @@ enum { | |||
| 218 | 218 | ||
| 219 | static inline int rb_null_event(struct ring_buffer_event *event) | 219 | static inline int rb_null_event(struct ring_buffer_event *event) |
| 220 | { | 220 | { |
| 221 | return event->type_len == RINGBUF_TYPE_PADDING | 221 | return event->type_len == RINGBUF_TYPE_PADDING && !event->time_delta; |
| 222 | && event->time_delta == 0; | ||
| 223 | } | ||
| 224 | |||
| 225 | static inline int rb_discarded_event(struct ring_buffer_event *event) | ||
| 226 | { | ||
| 227 | return event->type_len == RINGBUF_TYPE_PADDING && event->time_delta; | ||
| 228 | } | 222 | } |
| 229 | 223 | ||
| 230 | static void rb_event_set_padding(struct ring_buffer_event *event) | 224 | static void rb_event_set_padding(struct ring_buffer_event *event) |
| 231 | { | 225 | { |
| 226 | /* padding has a NULL time_delta */ | ||
| 232 | event->type_len = RINGBUF_TYPE_PADDING; | 227 | event->type_len = RINGBUF_TYPE_PADDING; |
| 233 | event->time_delta = 0; | 228 | event->time_delta = 0; |
| 234 | } | 229 | } |
| @@ -322,6 +317,14 @@ struct buffer_data_page { | |||
| 322 | unsigned char data[]; /* data of buffer page */ | 317 | unsigned char data[]; /* data of buffer page */ |
| 323 | }; | 318 | }; |
| 324 | 319 | ||
| 320 | /* | ||
| 321 | * Note, the buffer_page list must be first. The buffer pages | ||
| 322 | * are allocated in cache lines, which means that each buffer | ||
| 323 | * page will be at the beginning of a cache line, and thus | ||
| 324 | * the least significant bits will be zero. We use this to | ||
| 325 | * add flags in the list struct pointers, to make the ring buffer | ||
| 326 | * lockless. | ||
| 327 | */ | ||
| 325 | struct buffer_page { | 328 | struct buffer_page { |
| 326 | struct list_head list; /* list of buffer pages */ | 329 | struct list_head list; /* list of buffer pages */ |
| 327 | local_t write; /* index for next write */ | 330 | local_t write; /* index for next write */ |
| @@ -330,6 +333,21 @@ struct buffer_page { | |||
| 330 | struct buffer_data_page *page; /* Actual data page */ | 333 | struct buffer_data_page *page; /* Actual data page */ |
| 331 | }; | 334 | }; |
| 332 | 335 | ||
| 336 | /* | ||
| 337 | * The buffer page counters, write and entries, must be reset | ||
| 338 | * atomically when crossing page boundaries. To synchronize this | ||
| 339 | * update, two counters are inserted into the number. One is | ||
| 340 | * the actual counter for the write position or count on the page. | ||
| 341 | * | ||
| 342 | * The other is a counter of updaters. Before an update happens | ||
| 343 | * the update partition of the counter is incremented. This will | ||
| 344 | * allow the updater to update the counter atomically. | ||
| 345 | * | ||
| 346 | * The counter is 20 bits, and the state data is 12. | ||
| 347 | */ | ||
| 348 | #define RB_WRITE_MASK 0xfffff | ||
| 349 | #define RB_WRITE_INTCNT (1 << 20) | ||
| 350 | |||
| 333 | static void rb_init_page(struct buffer_data_page *bpage) | 351 | static void rb_init_page(struct buffer_data_page *bpage) |
| 334 | { | 352 | { |
| 335 | local_set(&bpage->commit, 0); | 353 | local_set(&bpage->commit, 0); |
| @@ -403,21 +421,20 @@ int ring_buffer_print_page_header(struct trace_seq *s) | |||
| 403 | struct ring_buffer_per_cpu { | 421 | struct ring_buffer_per_cpu { |
| 404 | int cpu; | 422 | int cpu; |
| 405 | struct ring_buffer *buffer; | 423 | struct ring_buffer *buffer; |
| 406 | spinlock_t reader_lock; /* serialize readers */ | 424 | spinlock_t reader_lock; /* serialize readers */ |
| 407 | raw_spinlock_t lock; | 425 | raw_spinlock_t lock; |
| 408 | struct lock_class_key lock_key; | 426 | struct lock_class_key lock_key; |
| 409 | struct list_head pages; | 427 | struct list_head *pages; |
| 410 | struct buffer_page *head_page; /* read from head */ | 428 | struct buffer_page *head_page; /* read from head */ |
| 411 | struct buffer_page *tail_page; /* write to tail */ | 429 | struct buffer_page *tail_page; /* write to tail */ |
| 412 | struct buffer_page *commit_page; /* committed pages */ | 430 | struct buffer_page *commit_page; /* committed pages */ |
| 413 | struct buffer_page *reader_page; | 431 | struct buffer_page *reader_page; |
| 414 | unsigned long nmi_dropped; | 432 | local_t commit_overrun; |
| 415 | unsigned long commit_overrun; | 433 | local_t overrun; |
| 416 | unsigned long overrun; | ||
| 417 | unsigned long read; | ||
| 418 | local_t entries; | 434 | local_t entries; |
| 419 | local_t committing; | 435 | local_t committing; |
| 420 | local_t commits; | 436 | local_t commits; |
| 437 | unsigned long read; | ||
| 421 | u64 write_stamp; | 438 | u64 write_stamp; |
| 422 | u64 read_stamp; | 439 | u64 read_stamp; |
| 423 | atomic_t record_disabled; | 440 | atomic_t record_disabled; |
| @@ -450,14 +467,19 @@ struct ring_buffer_iter { | |||
| 450 | }; | 467 | }; |
| 451 | 468 | ||
| 452 | /* buffer may be either ring_buffer or ring_buffer_per_cpu */ | 469 | /* buffer may be either ring_buffer or ring_buffer_per_cpu */ |
| 453 | #define RB_WARN_ON(buffer, cond) \ | 470 | #define RB_WARN_ON(b, cond) \ |
| 454 | ({ \ | 471 | ({ \ |
| 455 | int _____ret = unlikely(cond); \ | 472 | int _____ret = unlikely(cond); \ |
| 456 | if (_____ret) { \ | 473 | if (_____ret) { \ |
| 457 | atomic_inc(&buffer->record_disabled); \ | 474 | if (__same_type(*(b), struct ring_buffer_per_cpu)) { \ |
| 458 | WARN_ON(1); \ | 475 | struct ring_buffer_per_cpu *__b = \ |
| 459 | } \ | 476 | (void *)b; \ |
| 460 | _____ret; \ | 477 | atomic_inc(&__b->buffer->record_disabled); \ |
| 478 | } else \ | ||
| 479 | atomic_inc(&b->record_disabled); \ | ||
| 480 | WARN_ON(1); \ | ||
| 481 | } \ | ||
| 482 | _____ret; \ | ||
| 461 | }) | 483 | }) |
| 462 | 484 | ||
| 463 | /* Up this if you want to test the TIME_EXTENTS and normalization */ | 485 | /* Up this if you want to test the TIME_EXTENTS and normalization */ |
| @@ -489,6 +511,390 @@ void ring_buffer_normalize_time_stamp(struct ring_buffer *buffer, | |||
| 489 | } | 511 | } |
| 490 | EXPORT_SYMBOL_GPL(ring_buffer_normalize_time_stamp); | 512 | EXPORT_SYMBOL_GPL(ring_buffer_normalize_time_stamp); |
| 491 | 513 | ||
| 514 | /* | ||
| 515 | * Making the ring buffer lockless makes things tricky. | ||
| 516 | * Although writes only happen on the CPU that they are on, | ||
| 517 | * and they only need to worry about interrupts. Reads can | ||
| 518 | * happen on any CPU. | ||
| 519 | * | ||
| 520 | * The reader page is always off the ring buffer, but when the | ||
| 521 | * reader finishes with a page, it needs to swap its page with | ||
| 522 | * a new one from the buffer. The reader needs to take from | ||
| 523 | * the head (writes go to the tail). But if a writer is in overwrite | ||
| 524 | * mode and wraps, it must push the head page forward. | ||
| 525 | * | ||
| 526 | * Here lies the problem. | ||
| 527 | * | ||
| 528 | * The reader must be careful to replace only the head page, and | ||
| 529 | * not another one. As described at the top of the file in the | ||
| 530 | * ASCII art, the reader sets its old page to point to the next | ||
| 531 | * page after head. It then sets the page after head to point to | ||
| 532 | * the old reader page. But if the writer moves the head page | ||
| 533 | * during this operation, the reader could end up with the tail. | ||
| 534 | * | ||
| 535 | * We use cmpxchg to help prevent this race. We also do something | ||
| 536 | * special with the page before head. We set the LSB to 1. | ||
| 537 | * | ||
| 538 | * When the writer must push the page forward, it will clear the | ||
| 539 | * bit that points to the head page, move the head, and then set | ||
| 540 | * the bit that points to the new head page. | ||
| 541 | * | ||
| 542 | * We also don't want an interrupt coming in and moving the head | ||
| 543 | * page on another writer. Thus we use the second LSB to catch | ||
| 544 | * that too. Thus: | ||
| 545 | * | ||
| 546 | * head->list->prev->next bit 1 bit 0 | ||
| 547 | * ------- ------- | ||
| 548 | * Normal page 0 0 | ||
| 549 | * Points to head page 0 1 | ||
| 550 | * New head page 1 0 | ||
| 551 | * | ||
| 552 | * Note we can not trust the prev pointer of the head page, because: | ||
| 553 | * | ||
| 554 | * +----+ +-----+ +-----+ | ||
| 555 | * | |------>| T |---X--->| N | | ||
| 556 | * | |<------| | | | | ||
| 557 | * +----+ +-----+ +-----+ | ||
| 558 | * ^ ^ | | ||
| 559 | * | +-----+ | | | ||
| 560 | * +----------| R |----------+ | | ||
| 561 | * | |<-----------+ | ||
| 562 | * +-----+ | ||
| 563 | * | ||
| 564 | * Key: ---X--> HEAD flag set in pointer | ||
| 565 | * T Tail page | ||
| 566 | * R Reader page | ||
| 567 | * N Next page | ||
| 568 | * | ||
| 569 | * (see __rb_reserve_next() to see where this happens) | ||
| 570 | * | ||
| 571 | * What the above shows is that the reader just swapped out | ||
| 572 | * the reader page with a page in the buffer, but before it | ||
| 573 | * could make the new header point back to the new page added | ||
| 574 | * it was preempted by a writer. The writer moved forward onto | ||
| 575 | * the new page added by the reader and is about to move forward | ||
| 576 | * again. | ||
| 577 | * | ||
| 578 | * You can see, it is legitimate for the previous pointer of | ||
| 579 | * the head (or any page) not to point back to itself. But only | ||
| 580 | * temporarially. | ||
| 581 | */ | ||
| 582 | |||
| 583 | #define RB_PAGE_NORMAL 0UL | ||
| 584 | #define RB_PAGE_HEAD 1UL | ||
| 585 | #define RB_PAGE_UPDATE 2UL | ||
| 586 | |||
| 587 | |||
| 588 | #define RB_FLAG_MASK 3UL | ||
| 589 | |||
| 590 | /* PAGE_MOVED is not part of the mask */ | ||
| 591 | #define RB_PAGE_MOVED 4UL | ||
| 592 | |||
| 593 | /* | ||
| 594 | * rb_list_head - remove any bit | ||
| 595 | */ | ||
| 596 | static struct list_head *rb_list_head(struct list_head *list) | ||
| 597 | { | ||
| 598 | unsigned long val = (unsigned long)list; | ||
| 599 | |||
| 600 | return (struct list_head *)(val & ~RB_FLAG_MASK); | ||
| 601 | } | ||
| 602 | |||
| 603 | /* | ||
| 604 | * rb_is_head_page - test if the give page is the head page | ||
| 605 | * | ||
| 606 | * Because the reader may move the head_page pointer, we can | ||
| 607 | * not trust what the head page is (it may be pointing to | ||
| 608 | * the reader page). But if the next page is a header page, | ||
| 609 | * its flags will be non zero. | ||
| 610 | */ | ||
| 611 | static int inline | ||
| 612 | rb_is_head_page(struct ring_buffer_per_cpu *cpu_buffer, | ||
| 613 | struct buffer_page *page, struct list_head *list) | ||
| 614 | { | ||
| 615 | unsigned long val; | ||
| 616 | |||
| 617 | val = (unsigned long)list->next; | ||
| 618 | |||
| 619 | if ((val & ~RB_FLAG_MASK) != (unsigned long)&page->list) | ||
| 620 | return RB_PAGE_MOVED; | ||
| 621 | |||
| 622 | return val & RB_FLAG_MASK; | ||
| 623 | } | ||
| 624 | |||
| 625 | /* | ||
| 626 | * rb_is_reader_page | ||
| 627 | * | ||
| 628 | * The unique thing about the reader page, is that, if the | ||
| 629 | * writer is ever on it, the previous pointer never points | ||
| 630 | * back to the reader page. | ||
| 631 | */ | ||
| 632 | static int rb_is_reader_page(struct buffer_page *page) | ||
| 633 | { | ||
| 634 | struct list_head *list = page->list.prev; | ||
| 635 | |||
| 636 | return rb_list_head(list->next) != &page->list; | ||
| 637 | } | ||
| 638 | |||
| 639 | /* | ||
| 640 | * rb_set_list_to_head - set a list_head to be pointing to head. | ||
| 641 | */ | ||
| 642 | static void rb_set_list_to_head(struct ring_buffer_per_cpu *cpu_buffer, | ||
| 643 | struct list_head *list) | ||
| 644 | { | ||
| 645 | unsigned long *ptr; | ||
| 646 | |||
| 647 | ptr = (unsigned long *)&list->next; | ||
| 648 | *ptr |= RB_PAGE_HEAD; | ||
| 649 | *ptr &= ~RB_PAGE_UPDATE; | ||
| 650 | } | ||
| 651 | |||
| 652 | /* | ||
| 653 | * rb_head_page_activate - sets up head page | ||
| 654 | */ | ||
| 655 | static void rb_head_page_activate(struct ring_buffer_per_cpu *cpu_buffer) | ||
| 656 | { | ||
| 657 | struct buffer_page *head; | ||
| 658 | |||
| 659 | head = cpu_buffer->head_page; | ||
| 660 | if (!head) | ||
| 661 | return; | ||
| 662 | |||
| 663 | /* | ||
| 664 | * Set the previous list pointer to have the HEAD flag. | ||
| 665 | */ | ||
| 666 | rb_set_list_to_head(cpu_buffer, head->list.prev); | ||
| 667 | } | ||
| 668 | |||
| 669 | static void rb_list_head_clear(struct list_head *list) | ||
| 670 | { | ||
| 671 | unsigned long *ptr = (unsigned long *)&list->next; | ||
| 672 | |||
| 673 | *ptr &= ~RB_FLAG_MASK; | ||
| 674 | } | ||
| 675 | |||
| 676 | /* | ||
| 677 | * rb_head_page_dactivate - clears head page ptr (for free list) | ||
| 678 | */ | ||
| 679 | static void | ||
| 680 | rb_head_page_deactivate(struct ring_buffer_per_cpu *cpu_buffer) | ||
| 681 | { | ||
| 682 | struct list_head *hd; | ||
| 683 | |||
| 684 | /* Go through the whole list and clear any pointers found. */ | ||
| 685 | rb_list_head_clear(cpu_buffer->pages); | ||
| 686 | |||
| 687 | list_for_each(hd, cpu_buffer->pages) | ||
| 688 | rb_list_head_clear(hd); | ||
| 689 | } | ||
| 690 | |||
| 691 | static int rb_head_page_set(struct ring_buffer_per_cpu *cpu_buffer, | ||
| 692 | struct buffer_page *head, | ||
| 693 | struct buffer_page *prev, | ||
| 694 | int old_flag, int new_flag) | ||
| 695 | { | ||
| 696 | struct list_head *list; | ||
| 697 | unsigned long val = (unsigned long)&head->list; | ||
| 698 | unsigned long ret; | ||
| 699 | |||
| 700 | list = &prev->list; | ||
| 701 | |||
| 702 | val &= ~RB_FLAG_MASK; | ||
| 703 | |||
| 704 | ret = (unsigned long)cmpxchg(&list->next, | ||
| 705 | val | old_flag, val | new_flag); | ||
| 706 | |||
| 707 | /* check if the reader took the page */ | ||
| 708 | if ((ret & ~RB_FLAG_MASK) != val) | ||
| 709 | return RB_PAGE_MOVED; | ||
| 710 | |||
| 711 | return ret & RB_FLAG_MASK; | ||
| 712 | } | ||
| 713 | |||
| 714 | static int rb_head_page_set_update(struct ring_buffer_per_cpu *cpu_buffer, | ||
| 715 | struct buffer_page *head, | ||
| 716 | struct buffer_page *prev, | ||
| 717 | int old_flag) | ||
| 718 | { | ||
| 719 | return rb_head_page_set(cpu_buffer, head, prev, | ||
| 720 | old_flag, RB_PAGE_UPDATE); | ||
| 721 | } | ||
| 722 | |||
| 723 | static int rb_head_page_set_head(struct ring_buffer_per_cpu *cpu_buffer, | ||
| 724 | struct buffer_page *head, | ||
| 725 | struct buffer_page *prev, | ||
| 726 | int old_flag) | ||
| 727 | { | ||
| 728 | return rb_head_page_set(cpu_buffer, head, prev, | ||
| 729 | old_flag, RB_PAGE_HEAD); | ||
| 730 | } | ||
| 731 | |||
| 732 | static int rb_head_page_set_normal(struct ring_buffer_per_cpu *cpu_buffer, | ||
| 733 | struct buffer_page *head, | ||
| 734 | struct buffer_page *prev, | ||
| 735 | int old_flag) | ||
| 736 | { | ||
| 737 | return rb_head_page_set(cpu_buffer, head, prev, | ||
| 738 | old_flag, RB_PAGE_NORMAL); | ||
| 739 | } | ||
| 740 | |||
| 741 | static inline void rb_inc_page(struct ring_buffer_per_cpu *cpu_buffer, | ||
| 742 | struct buffer_page **bpage) | ||
| 743 | { | ||
| 744 | struct list_head *p = rb_list_head((*bpage)->list.next); | ||
| 745 | |||
| 746 | *bpage = list_entry(p, struct buffer_page, list); | ||
| 747 | } | ||
| 748 | |||
| 749 | static struct buffer_page * | ||
| 750 | rb_set_head_page(struct ring_buffer_per_cpu *cpu_buffer) | ||
| 751 | { | ||
| 752 | struct buffer_page *head; | ||
| 753 | struct buffer_page *page; | ||
| 754 | struct list_head *list; | ||
| 755 | int i; | ||
| 756 | |||
| 757 | if (RB_WARN_ON(cpu_buffer, !cpu_buffer->head_page)) | ||
| 758 | return NULL; | ||
| 759 | |||
| 760 | /* sanity check */ | ||
| 761 | list = cpu_buffer->pages; | ||
| 762 | if (RB_WARN_ON(cpu_buffer, rb_list_head(list->prev->next) != list)) | ||
| 763 | return NULL; | ||
| 764 | |||
| 765 | page = head = cpu_buffer->head_page; | ||
| 766 | /* | ||
| 767 | * It is possible that the writer moves the header behind | ||
| 768 | * where we started, and we miss in one loop. | ||
| 769 | * A second loop should grab the header, but we'll do | ||
| 770 | * three loops just because I'm paranoid. | ||
| 771 | */ | ||
| 772 | for (i = 0; i < 3; i++) { | ||
| 773 | do { | ||
| 774 | if (rb_is_head_page(cpu_buffer, page, page->list.prev)) { | ||
| 775 | cpu_buffer->head_page = page; | ||
| 776 | return page; | ||
| 777 | } | ||
| 778 | rb_inc_page(cpu_buffer, &page); | ||
| 779 | } while (page != head); | ||
| 780 | } | ||
| 781 | |||
| 782 | RB_WARN_ON(cpu_buffer, 1); | ||
| 783 | |||
| 784 | return NULL; | ||
| 785 | } | ||
| 786 | |||
| 787 | static int rb_head_page_replace(struct buffer_page *old, | ||
| 788 | struct buffer_page *new) | ||
| 789 | { | ||
| 790 | unsigned long *ptr = (unsigned long *)&old->list.prev->next; | ||
| 791 | unsigned long val; | ||
| 792 | unsigned long ret; | ||
| 793 | |||
| 794 | val = *ptr & ~RB_FLAG_MASK; | ||
| 795 | val |= RB_PAGE_HEAD; | ||
| 796 | |||
| 797 | ret = cmpxchg(ptr, val, &new->list); | ||
| 798 | |||
| 799 | return ret == val; | ||
| 800 | } | ||
| 801 | |||
| 802 | /* | ||
| 803 | * rb_tail_page_update - move the tail page forward | ||
| 804 | * | ||
| 805 | * Returns 1 if moved tail page, 0 if someone else did. | ||
| 806 | */ | ||
| 807 | static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer, | ||
| 808 | struct buffer_page *tail_page, | ||
| 809 | struct buffer_page *next_page) | ||
| 810 | { | ||
| 811 | struct buffer_page *old_tail; | ||
| 812 | unsigned long old_entries; | ||
| 813 | unsigned long old_write; | ||
| 814 | int ret = 0; | ||
| 815 | |||
| 816 | /* | ||
| 817 | * The tail page now needs to be moved forward. | ||
| 818 | * | ||
| 819 | * We need to reset the tail page, but without messing | ||
| 820 | * with possible erasing of data brought in by interrupts | ||
| 821 | * that have moved the tail page and are currently on it. | ||
| 822 | * | ||
| 823 | * We add a counter to the write field to denote this. | ||
| 824 | */ | ||
| 825 | old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write); | ||
| 826 | old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries); | ||
| 827 | |||
| 828 | /* | ||
| 829 | * Just make sure we have seen our old_write and synchronize | ||
| 830 | * with any interrupts that come in. | ||
| 831 | */ | ||
| 832 | barrier(); | ||
| 833 | |||
| 834 | /* | ||
| 835 | * If the tail page is still the same as what we think | ||
| 836 | * it is, then it is up to us to update the tail | ||
| 837 | * pointer. | ||
| 838 | */ | ||
| 839 | if (tail_page == cpu_buffer->tail_page) { | ||
| 840 | /* Zero the write counter */ | ||
| 841 | unsigned long val = old_write & ~RB_WRITE_MASK; | ||
| 842 | unsigned long eval = old_entries & ~RB_WRITE_MASK; | ||
| 843 | |||
| 844 | /* | ||
| 845 | * This will only succeed if an interrupt did | ||
| 846 | * not come in and change it. In which case, we | ||
| 847 | * do not want to modify it. | ||
| 848 | * | ||
| 849 | * We add (void) to let the compiler know that we do not care | ||
| 850 | * about the return value of these functions. We use the | ||
| 851 | * cmpxchg to only update if an interrupt did not already | ||
| 852 | * do it for us. If the cmpxchg fails, we don't care. | ||
| 853 | */ | ||
| 854 | (void)local_cmpxchg(&next_page->write, old_write, val); | ||
| 855 | (void)local_cmpxchg(&next_page->entries, old_entries, eval); | ||
| 856 | |||
| 857 | /* | ||
| 858 | * No need to worry about races with clearing out the commit. | ||
| 859 | * it only can increment when a commit takes place. But that | ||
| 860 | * only happens in the outer most nested commit. | ||
| 861 | */ | ||
| 862 | local_set(&next_page->page->commit, 0); | ||
| 863 | |||
| 864 | old_tail = cmpxchg(&cpu_buffer->tail_page, | ||
| 865 | tail_page, next_page); | ||
| 866 | |||
| 867 | if (old_tail == tail_page) | ||
| 868 | ret = 1; | ||
| 869 | } | ||
| 870 | |||
| 871 | return ret; | ||
| 872 | } | ||
| 873 | |||
| 874 | static int rb_check_bpage(struct ring_buffer_per_cpu *cpu_buffer, | ||
| 875 | struct buffer_page *bpage) | ||
| 876 | { | ||
| 877 | unsigned long val = (unsigned long)bpage; | ||
| 878 | |||
| 879 | if (RB_WARN_ON(cpu_buffer, val & RB_FLAG_MASK)) | ||
| 880 | return 1; | ||
| 881 | |||
| 882 | return 0; | ||
| 883 | } | ||
| 884 | |||
| 885 | /** | ||
| 886 | * rb_check_list - make sure a pointer to a list has the last bits zero | ||
| 887 | */ | ||
| 888 | static int rb_check_list(struct ring_buffer_per_cpu *cpu_buffer, | ||
| 889 | struct list_head *list) | ||
| 890 | { | ||
| 891 | if (RB_WARN_ON(cpu_buffer, rb_list_head(list->prev) != list->prev)) | ||
| 892 | return 1; | ||
| 893 | if (RB_WARN_ON(cpu_buffer, rb_list_head(list->next) != list->next)) | ||
| 894 | return 1; | ||
| 895 | return 0; | ||
| 896 | } | ||
| 897 | |||
| 492 | /** | 898 | /** |
| 493 | * check_pages - integrity check of buffer pages | 899 | * check_pages - integrity check of buffer pages |
| 494 | * @cpu_buffer: CPU buffer with pages to test | 900 | * @cpu_buffer: CPU buffer with pages to test |
| @@ -498,14 +904,19 @@ EXPORT_SYMBOL_GPL(ring_buffer_normalize_time_stamp); | |||
| 498 | */ | 904 | */ |
| 499 | static int rb_check_pages(struct ring_buffer_per_cpu *cpu_buffer) | 905 | static int rb_check_pages(struct ring_buffer_per_cpu *cpu_buffer) |
| 500 | { | 906 | { |
| 501 | struct list_head *head = &cpu_buffer->pages; | 907 | struct list_head *head = cpu_buffer->pages; |
| 502 | struct buffer_page *bpage, *tmp; | 908 | struct buffer_page *bpage, *tmp; |
| 503 | 909 | ||
| 910 | rb_head_page_deactivate(cpu_buffer); | ||
| 911 | |||
| 504 | if (RB_WARN_ON(cpu_buffer, head->next->prev != head)) | 912 | if (RB_WARN_ON(cpu_buffer, head->next->prev != head)) |
| 505 | return -1; | 913 | return -1; |
| 506 | if (RB_WARN_ON(cpu_buffer, head->prev->next != head)) | 914 | if (RB_WARN_ON(cpu_buffer, head->prev->next != head)) |
| 507 | return -1; | 915 | return -1; |
| 508 | 916 | ||
| 917 | if (rb_check_list(cpu_buffer, head)) | ||
| 918 | return -1; | ||
| 919 | |||
| 509 | list_for_each_entry_safe(bpage, tmp, head, list) { | 920 | list_for_each_entry_safe(bpage, tmp, head, list) { |
| 510 | if (RB_WARN_ON(cpu_buffer, | 921 | if (RB_WARN_ON(cpu_buffer, |
| 511 | bpage->list.next->prev != &bpage->list)) | 922 | bpage->list.next->prev != &bpage->list)) |
| @@ -513,25 +924,33 @@ static int rb_check_pages(struct ring_buffer_per_cpu *cpu_buffer) | |||
| 513 | if (RB_WARN_ON(cpu_buffer, | 924 | if (RB_WARN_ON(cpu_buffer, |
| 514 | bpage->list.prev->next != &bpage->list)) | 925 | bpage->list.prev->next != &bpage->list)) |
| 515 | return -1; | 926 | return -1; |
| 927 | if (rb_check_list(cpu_buffer, &bpage->list)) | ||
| 928 | return -1; | ||
| 516 | } | 929 | } |
| 517 | 930 | ||
| 931 | rb_head_page_activate(cpu_buffer); | ||
| 932 | |||
| 518 | return 0; | 933 | return 0; |
| 519 | } | 934 | } |
| 520 | 935 | ||
| 521 | static int rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer, | 936 | static int rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer, |
| 522 | unsigned nr_pages) | 937 | unsigned nr_pages) |
| 523 | { | 938 | { |
| 524 | struct list_head *head = &cpu_buffer->pages; | ||
| 525 | struct buffer_page *bpage, *tmp; | 939 | struct buffer_page *bpage, *tmp; |
| 526 | unsigned long addr; | 940 | unsigned long addr; |
| 527 | LIST_HEAD(pages); | 941 | LIST_HEAD(pages); |
| 528 | unsigned i; | 942 | unsigned i; |
| 529 | 943 | ||
| 944 | WARN_ON(!nr_pages); | ||
| 945 | |||
| 530 | for (i = 0; i < nr_pages; i++) { | 946 | for (i = 0; i < nr_pages; i++) { |
| 531 | bpage = kzalloc_node(ALIGN(sizeof(*bpage), cache_line_size()), | 947 | bpage = kzalloc_node(ALIGN(sizeof(*bpage), cache_line_size()), |
| 532 | GFP_KERNEL, cpu_to_node(cpu_buffer->cpu)); | 948 | GFP_KERNEL, cpu_to_node(cpu_buffer->cpu)); |
| 533 | if (!bpage) | 949 | if (!bpage) |
| 534 | goto free_pages; | 950 | goto free_pages; |
| 951 | |||
| 952 | rb_check_bpage(cpu_buffer, bpage); | ||
| 953 | |||
| 535 | list_add(&bpage->list, &pages); | 954 | list_add(&bpage->list, &pages); |
| 536 | 955 | ||
| 537 | addr = __get_free_page(GFP_KERNEL); | 956 | addr = __get_free_page(GFP_KERNEL); |
| @@ -541,7 +960,13 @@ static int rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer, | |||
| 541 | rb_init_page(bpage->page); | 960 | rb_init_page(bpage->page); |
| 542 | } | 961 | } |
| 543 | 962 | ||
| 544 | list_splice(&pages, head); | 963 | /* |
| 964 | * The ring buffer page list is a circular list that does not | ||
| 965 | * start and end with a list head. All page list items point to | ||
| 966 | * other pages. | ||
| 967 | */ | ||
| 968 | cpu_buffer->pages = pages.next; | ||
| 969 | list_del(&pages); | ||
| 545 | 970 | ||
| 546 | rb_check_pages(cpu_buffer); | 971 | rb_check_pages(cpu_buffer); |
| 547 | 972 | ||
| @@ -573,13 +998,14 @@ rb_allocate_cpu_buffer(struct ring_buffer *buffer, int cpu) | |||
| 573 | spin_lock_init(&cpu_buffer->reader_lock); | 998 | spin_lock_init(&cpu_buffer->reader_lock); |
| 574 | lockdep_set_class(&cpu_buffer->reader_lock, buffer->reader_lock_key); | 999 | lockdep_set_class(&cpu_buffer->reader_lock, buffer->reader_lock_key); |
| 575 | cpu_buffer->lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED; | 1000 | cpu_buffer->lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED; |
| 576 | INIT_LIST_HEAD(&cpu_buffer->pages); | ||
| 577 | 1001 | ||
| 578 | bpage = kzalloc_node(ALIGN(sizeof(*bpage), cache_line_size()), | 1002 | bpage = kzalloc_node(ALIGN(sizeof(*bpage), cache_line_size()), |
| 579 | GFP_KERNEL, cpu_to_node(cpu)); | 1003 | GFP_KERNEL, cpu_to_node(cpu)); |
| 580 | if (!bpage) | 1004 | if (!bpage) |
| 581 | goto fail_free_buffer; | 1005 | goto fail_free_buffer; |
| 582 | 1006 | ||
| 1007 | rb_check_bpage(cpu_buffer, bpage); | ||
| 1008 | |||
| 583 | cpu_buffer->reader_page = bpage; | 1009 | cpu_buffer->reader_page = bpage; |
| 584 | addr = __get_free_page(GFP_KERNEL); | 1010 | addr = __get_free_page(GFP_KERNEL); |
| 585 | if (!addr) | 1011 | if (!addr) |
| @@ -594,9 +1020,11 @@ rb_allocate_cpu_buffer(struct ring_buffer *buffer, int cpu) | |||
| 594 | goto fail_free_reader; | 1020 | goto fail_free_reader; |
| 595 | 1021 | ||
| 596 | cpu_buffer->head_page | 1022 | cpu_buffer->head_page |
| 597 | = list_entry(cpu_buffer->pages.next, struct buffer_page, list); | 1023 | = list_entry(cpu_buffer->pages, struct buffer_page, list); |
| 598 | cpu_buffer->tail_page = cpu_buffer->commit_page = cpu_buffer->head_page; | 1024 | cpu_buffer->tail_page = cpu_buffer->commit_page = cpu_buffer->head_page; |
| 599 | 1025 | ||
| 1026 | rb_head_page_activate(cpu_buffer); | ||
| 1027 | |||
| 600 | return cpu_buffer; | 1028 | return cpu_buffer; |
| 601 | 1029 | ||
| 602 | fail_free_reader: | 1030 | fail_free_reader: |
| @@ -609,15 +1037,22 @@ rb_allocate_cpu_buffer(struct ring_buffer *buffer, int cpu) | |||
| 609 | 1037 | ||
| 610 | static void rb_free_cpu_buffer(struct ring_buffer_per_cpu *cpu_buffer) | 1038 | static void rb_free_cpu_buffer(struct ring_buffer_per_cpu *cpu_buffer) |
| 611 | { | 1039 | { |
| 612 | struct list_head *head = &cpu_buffer->pages; | 1040 | struct list_head *head = cpu_buffer->pages; |
| 613 | struct buffer_page *bpage, *tmp; | 1041 | struct buffer_page *bpage, *tmp; |
| 614 | 1042 | ||
| 615 | free_buffer_page(cpu_buffer->reader_page); | 1043 | free_buffer_page(cpu_buffer->reader_page); |
| 616 | 1044 | ||
| 617 | list_for_each_entry_safe(bpage, tmp, head, list) { | 1045 | rb_head_page_deactivate(cpu_buffer); |
| 618 | list_del_init(&bpage->list); | 1046 | |
| 1047 | if (head) { | ||
| 1048 | list_for_each_entry_safe(bpage, tmp, head, list) { | ||
| 1049 | list_del_init(&bpage->list); | ||
| 1050 | free_buffer_page(bpage); | ||
| 1051 | } | ||
| 1052 | bpage = list_entry(head, struct buffer_page, list); | ||
| 619 | free_buffer_page(bpage); | 1053 | free_buffer_page(bpage); |
| 620 | } | 1054 | } |
| 1055 | |||
| 621 | kfree(cpu_buffer); | 1056 | kfree(cpu_buffer); |
| 622 | } | 1057 | } |
| 623 | 1058 | ||
| @@ -760,15 +1195,17 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned nr_pages) | |||
| 760 | atomic_inc(&cpu_buffer->record_disabled); | 1195 | atomic_inc(&cpu_buffer->record_disabled); |
| 761 | synchronize_sched(); | 1196 | synchronize_sched(); |
| 762 | 1197 | ||
| 1198 | rb_head_page_deactivate(cpu_buffer); | ||
| 1199 | |||
| 763 | for (i = 0; i < nr_pages; i++) { | 1200 | for (i = 0; i < nr_pages; i++) { |
| 764 | if (RB_WARN_ON(cpu_buffer, list_empty(&cpu_buffer->pages))) | 1201 | if (RB_WARN_ON(cpu_buffer, list_empty(cpu_buffer->pages))) |
| 765 | return; | 1202 | return; |
| 766 | p = cpu_buffer->pages.next; | 1203 | p = cpu_buffer->pages->next; |
| 767 | bpage = list_entry(p, struct buffer_page, list); | 1204 | bpage = list_entry(p, struct buffer_page, list); |
| 768 | list_del_init(&bpage->list); | 1205 | list_del_init(&bpage->list); |
| 769 | free_buffer_page(bpage); | 1206 | free_buffer_page(bpage); |
| 770 | } | 1207 | } |
| 771 | if (RB_WARN_ON(cpu_buffer, list_empty(&cpu_buffer->pages))) | 1208 | if (RB_WARN_ON(cpu_buffer, list_empty(cpu_buffer->pages))) |
| 772 | return; | 1209 | return; |
| 773 | 1210 | ||
| 774 | rb_reset_cpu(cpu_buffer); | 1211 | rb_reset_cpu(cpu_buffer); |
| @@ -790,15 +1227,19 @@ rb_insert_pages(struct ring_buffer_per_cpu *cpu_buffer, | |||
| 790 | atomic_inc(&cpu_buffer->record_disabled); | 1227 | atomic_inc(&cpu_buffer->record_disabled); |
| 791 | synchronize_sched(); | 1228 | synchronize_sched(); |
| 792 | 1229 | ||
| 1230 | spin_lock_irq(&cpu_buffer->reader_lock); | ||
| 1231 | rb_head_page_deactivate(cpu_buffer); | ||
| 1232 | |||
| 793 | for (i = 0; i < nr_pages; i++) { | 1233 | for (i = 0; i < nr_pages; i++) { |
| 794 | if (RB_WARN_ON(cpu_buffer, list_empty(pages))) | 1234 | if (RB_WARN_ON(cpu_buffer, list_empty(pages))) |
| 795 | return; | 1235 | return; |
| 796 | p = pages->next; | 1236 | p = pages->next; |
| 797 | bpage = list_entry(p, struct buffer_page, list); | 1237 | bpage = list_entry(p, struct buffer_page, list); |
| 798 | list_del_init(&bpage->list); | 1238 | list_del_init(&bpage->list); |
| 799 | list_add_tail(&bpage->list, &cpu_buffer->pages); | 1239 | list_add_tail(&bpage->list, cpu_buffer->pages); |
| 800 | } | 1240 | } |
| 801 | rb_reset_cpu(cpu_buffer); | 1241 | rb_reset_cpu(cpu_buffer); |
| 1242 | spin_unlock_irq(&cpu_buffer->reader_lock); | ||
| 802 | 1243 | ||
| 803 | rb_check_pages(cpu_buffer); | 1244 | rb_check_pages(cpu_buffer); |
| 804 | 1245 | ||
| @@ -949,21 +1390,14 @@ rb_reader_event(struct ring_buffer_per_cpu *cpu_buffer) | |||
| 949 | } | 1390 | } |
| 950 | 1391 | ||
| 951 | static inline struct ring_buffer_event * | 1392 | static inline struct ring_buffer_event * |
| 952 | rb_head_event(struct ring_buffer_per_cpu *cpu_buffer) | ||
| 953 | { | ||
| 954 | return __rb_page_index(cpu_buffer->head_page, | ||
| 955 | cpu_buffer->head_page->read); | ||
| 956 | } | ||
| 957 | |||
| 958 | static inline struct ring_buffer_event * | ||
| 959 | rb_iter_head_event(struct ring_buffer_iter *iter) | 1393 | rb_iter_head_event(struct ring_buffer_iter *iter) |
| 960 | { | 1394 | { |
| 961 | return __rb_page_index(iter->head_page, iter->head); | 1395 | return __rb_page_index(iter->head_page, iter->head); |
| 962 | } | 1396 | } |
| 963 | 1397 | ||
| 964 | static inline unsigned rb_page_write(struct buffer_page *bpage) | 1398 | static inline unsigned long rb_page_write(struct buffer_page *bpage) |
| 965 | { | 1399 | { |
| 966 | return local_read(&bpage->write); | 1400 | return local_read(&bpage->write) & RB_WRITE_MASK; |
| 967 | } | 1401 | } |
| 968 | 1402 | ||
| 969 | static inline unsigned rb_page_commit(struct buffer_page *bpage) | 1403 | static inline unsigned rb_page_commit(struct buffer_page *bpage) |
| @@ -971,6 +1405,11 @@ static inline unsigned rb_page_commit(struct buffer_page *bpage) | |||
| 971 | return local_read(&bpage->page->commit); | 1405 | return local_read(&bpage->page->commit); |
| 972 | } | 1406 | } |
| 973 | 1407 | ||
| 1408 | static inline unsigned long rb_page_entries(struct buffer_page *bpage) | ||
| 1409 | { | ||
| 1410 | return local_read(&bpage->entries) & RB_WRITE_MASK; | ||
| 1411 | } | ||
| 1412 | |||
| 974 | /* Size is determined by what has been commited */ | 1413 | /* Size is determined by what has been commited */ |
| 975 | static inline unsigned rb_page_size(struct buffer_page *bpage) | 1414 | static inline unsigned rb_page_size(struct buffer_page *bpage) |
| 976 | { | 1415 | { |
| @@ -983,22 +1422,6 @@ rb_commit_index(struct ring_buffer_per_cpu *cpu_buffer) | |||
| 983 | return rb_page_commit(cpu_buffer->commit_page); | 1422 | return rb_page_commit(cpu_buffer->commit_page); |
| 984 | } | 1423 | } |
| 985 | 1424 | ||
| 986 | static inline unsigned rb_head_size(struct ring_buffer_per_cpu *cpu_buffer) | ||
| 987 | { | ||
| 988 | return rb_page_commit(cpu_buffer->head_page); | ||
| 989 | } | ||
| 990 | |||
| 991 | static inline void rb_inc_page(struct ring_buffer_per_cpu *cpu_buffer, | ||
| 992 | struct buffer_page **bpage) | ||
| 993 | { | ||
| 994 | struct list_head *p = (*bpage)->list.next; | ||
| 995 | |||
| 996 | if (p == &cpu_buffer->pages) | ||
| 997 | p = p->next; | ||
| 998 | |||
| 999 | *bpage = list_entry(p, struct buffer_page, list); | ||
| 1000 | } | ||
| 1001 | |||
| 1002 | static inline unsigned | 1425 | static inline unsigned |
| 1003 | rb_event_index(struct ring_buffer_event *event) | 1426 | rb_event_index(struct ring_buffer_event *event) |
| 1004 | { | 1427 | { |
| @@ -1024,6 +1447,8 @@ rb_event_is_commit(struct ring_buffer_per_cpu *cpu_buffer, | |||
| 1024 | static void | 1447 | static void |
| 1025 | rb_set_commit_to_write(struct ring_buffer_per_cpu *cpu_buffer) | 1448 | rb_set_commit_to_write(struct ring_buffer_per_cpu *cpu_buffer) |
| 1026 | { | 1449 | { |
| 1450 | unsigned long max_count; | ||
| 1451 | |||
| 1027 | /* | 1452 | /* |
| 1028 | * We only race with interrupts and NMIs on this CPU. | 1453 | * We only race with interrupts and NMIs on this CPU. |
| 1029 | * If we own the commit event, then we can commit | 1454 | * If we own the commit event, then we can commit |
| @@ -1033,9 +1458,16 @@ rb_set_commit_to_write(struct ring_buffer_per_cpu *cpu_buffer) | |||
| 1033 | * assign the commit to the tail. | 1458 | * assign the commit to the tail. |
| 1034 | */ | 1459 | */ |
| 1035 | again: | 1460 | again: |
| 1461 | max_count = cpu_buffer->buffer->pages * 100; | ||
| 1462 | |||
| 1036 | while (cpu_buffer->commit_page != cpu_buffer->tail_page) { | 1463 | while (cpu_buffer->commit_page != cpu_buffer->tail_page) { |
| 1037 | cpu_buffer->commit_page->page->commit = | 1464 | if (RB_WARN_ON(cpu_buffer, !(--max_count))) |
| 1038 | cpu_buffer->commit_page->write; | 1465 | return; |
| 1466 | if (RB_WARN_ON(cpu_buffer, | ||
| 1467 | rb_is_reader_page(cpu_buffer->tail_page))) | ||
| 1468 | return; | ||
| 1469 | local_set(&cpu_buffer->commit_page->page->commit, | ||
| 1470 | rb_page_write(cpu_buffer->commit_page)); | ||
| 1039 | rb_inc_page(cpu_buffer, &cpu_buffer->commit_page); | 1471 | rb_inc_page(cpu_buffer, &cpu_buffer->commit_page); |
| 1040 | cpu_buffer->write_stamp = | 1472 | cpu_buffer->write_stamp = |
| 1041 | cpu_buffer->commit_page->page->time_stamp; | 1473 | cpu_buffer->commit_page->page->time_stamp; |
| @@ -1044,8 +1476,12 @@ rb_set_commit_to_write(struct ring_buffer_per_cpu *cpu_buffer) | |||
| 1044 | } | 1476 | } |
| 1045 | while (rb_commit_index(cpu_buffer) != | 1477 | while (rb_commit_index(cpu_buffer) != |
| 1046 | rb_page_write(cpu_buffer->commit_page)) { | 1478 | rb_page_write(cpu_buffer->commit_page)) { |
| 1047 | cpu_buffer->commit_page->page->commit = | 1479 | |
| 1048 | cpu_buffer->commit_page->write; | 1480 | local_set(&cpu_buffer->commit_page->page->commit, |
| 1481 | rb_page_write(cpu_buffer->commit_page)); | ||
| 1482 | RB_WARN_ON(cpu_buffer, | ||
| 1483 | local_read(&cpu_buffer->commit_page->page->commit) & | ||
| 1484 | ~RB_WRITE_MASK); | ||
| 1049 | barrier(); | 1485 | barrier(); |
| 1050 | } | 1486 | } |
| 1051 | 1487 | ||
| @@ -1078,7 +1514,7 @@ static void rb_inc_iter(struct ring_buffer_iter *iter) | |||
| 1078 | * to the head page instead of next. | 1514 | * to the head page instead of next. |
| 1079 | */ | 1515 | */ |
| 1080 | if (iter->head_page == cpu_buffer->reader_page) | 1516 | if (iter->head_page == cpu_buffer->reader_page) |
| 1081 | iter->head_page = cpu_buffer->head_page; | 1517 | iter->head_page = rb_set_head_page(cpu_buffer); |
| 1082 | else | 1518 | else |
| 1083 | rb_inc_page(cpu_buffer, &iter->head_page); | 1519 | rb_inc_page(cpu_buffer, &iter->head_page); |
| 1084 | 1520 | ||
| @@ -1122,6 +1558,163 @@ rb_update_event(struct ring_buffer_event *event, | |||
| 1122 | } | 1558 | } |
| 1123 | } | 1559 | } |
| 1124 | 1560 | ||
| 1561 | /* | ||
| 1562 | * rb_handle_head_page - writer hit the head page | ||
| 1563 | * | ||
| 1564 | * Returns: +1 to retry page | ||
| 1565 | * 0 to continue | ||
| 1566 | * -1 on error | ||
| 1567 | */ | ||
| 1568 | static int | ||
| 1569 | rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer, | ||
| 1570 | struct buffer_page *tail_page, | ||
| 1571 | struct buffer_page *next_page) | ||
| 1572 | { | ||
| 1573 | struct buffer_page *new_head; | ||
| 1574 | int entries; | ||
| 1575 | int type; | ||
| 1576 | int ret; | ||
| 1577 | |||
| 1578 | entries = rb_page_entries(next_page); | ||
| 1579 | |||
| 1580 | /* | ||
| 1581 | * The hard part is here. We need to move the head | ||
| 1582 | * forward, and protect against both readers on | ||
| 1583 | * other CPUs and writers coming in via interrupts. | ||
| 1584 | */ | ||
| 1585 | type = rb_head_page_set_update(cpu_buffer, next_page, tail_page, | ||
| 1586 | RB_PAGE_HEAD); | ||
| 1587 | |||
| 1588 | /* | ||
| 1589 | * type can be one of four: | ||
| 1590 | * NORMAL - an interrupt already moved it for us | ||
| 1591 | * HEAD - we are the first to get here. | ||
| 1592 | * UPDATE - we are the interrupt interrupting | ||
| 1593 | * a current move. | ||
| 1594 | * MOVED - a reader on another CPU moved the next | ||
| 1595 | * pointer to its reader page. Give up | ||
| 1596 | * and try again. | ||
| 1597 | */ | ||
| 1598 | |||
| 1599 | switch (type) { | ||
| 1600 | case RB_PAGE_HEAD: | ||
| 1601 | /* | ||
| 1602 | * We changed the head to UPDATE, thus | ||
| 1603 | * it is our responsibility to update | ||
| 1604 | * the counters. | ||
| 1605 | */ | ||
| 1606 | local_add(entries, &cpu_buffer->overrun); | ||
| 1607 | |||
| 1608 | /* | ||
| 1609 | * The entries will be zeroed out when we move the | ||
| 1610 | * tail page. | ||
| 1611 | */ | ||
| 1612 | |||
| 1613 | /* still more to do */ | ||
| 1614 | break; | ||
| 1615 | |||
| 1616 | case RB_PAGE_UPDATE: | ||
| 1617 | /* | ||
| 1618 | * This is an interrupt that interrupt the | ||
| 1619 | * previous update. Still more to do. | ||
| 1620 | */ | ||
| 1621 | break; | ||
| 1622 | case RB_PAGE_NORMAL: | ||
| 1623 | /* | ||
| 1624 | * An interrupt came in before the update | ||
| 1625 | * and processed this for us. | ||
| 1626 | * Nothing left to do. | ||
| 1627 | */ | ||
| 1628 | return 1; | ||
| 1629 | case RB_PAGE_MOVED: | ||
| 1630 | /* | ||
| 1631 | * The reader is on another CPU and just did | ||
| 1632 | * a swap with our next_page. | ||
| 1633 | * Try again. | ||
| 1634 | */ | ||
| 1635 | return 1; | ||
| 1636 | default: | ||
| 1637 | RB_WARN_ON(cpu_buffer, 1); /* WTF??? */ | ||
| 1638 | return -1; | ||
| 1639 | } | ||
| 1640 | |||
| 1641 | /* | ||
| 1642 | * Now that we are here, the old head pointer is | ||
| 1643 | * set to UPDATE. This will keep the reader from | ||
| 1644 | * swapping the head page with the reader page. | ||
| 1645 | * The reader (on another CPU) will spin till | ||
| 1646 | * we are finished. | ||
| 1647 | * | ||
| 1648 | * We just need to protect against interrupts | ||
| 1649 | * doing the job. We will set the next pointer | ||
| 1650 | * to HEAD. After that, we set the old pointer | ||
| 1651 | * to NORMAL, but only if it was HEAD before. | ||
| 1652 | * otherwise we are an interrupt, and only | ||
| 1653 | * want the outer most commit to reset it. | ||
| 1654 | */ | ||
| 1655 | new_head = next_page; | ||
| 1656 | rb_inc_page(cpu_buffer, &new_head); | ||
| 1657 | |||
| 1658 | ret = rb_head_page_set_head(cpu_buffer, new_head, next_page, | ||
| 1659 | RB_PAGE_NORMAL); | ||
| 1660 | |||
| 1661 | /* | ||
| 1662 | * Valid returns are: | ||
| 1663 | * HEAD - an interrupt came in and already set it. | ||
| 1664 | * NORMAL - One of two things: | ||
| 1665 | * 1) We really set it. | ||
| 1666 | * 2) A bunch of interrupts came in and moved | ||
| 1667 | * the page forward again. | ||
| 1668 | */ | ||
| 1669 | switch (ret) { | ||
| 1670 | case RB_PAGE_HEAD: | ||
| 1671 | case RB_PAGE_NORMAL: | ||
| 1672 | /* OK */ | ||
| 1673 | break; | ||
| 1674 | default: | ||
| 1675 | RB_WARN_ON(cpu_buffer, 1); | ||
| 1676 | return -1; | ||
| 1677 | } | ||
| 1678 | |||
| 1679 | /* | ||
| 1680 | * It is possible that an interrupt came in, | ||
| 1681 | * set the head up, then more interrupts came in | ||
| 1682 | * and moved it again. When we get back here, | ||
| 1683 | * the page would have been set to NORMAL but we | ||
| 1684 | * just set it back to HEAD. | ||
| 1685 | * | ||
| 1686 | * How do you detect this? Well, if that happened | ||
| 1687 | * the tail page would have moved. | ||
| 1688 | */ | ||
| 1689 | if (ret == RB_PAGE_NORMAL) { | ||
| 1690 | /* | ||
| 1691 | * If the tail had moved passed next, then we need | ||
| 1692 | * to reset the pointer. | ||
| 1693 | */ | ||
| 1694 | if (cpu_buffer->tail_page != tail_page && | ||
| 1695 | cpu_buffer->tail_page != next_page) | ||
| 1696 | rb_head_page_set_normal(cpu_buffer, new_head, | ||
| 1697 | next_page, | ||
| 1698 | RB_PAGE_HEAD); | ||
| 1699 | } | ||
| 1700 | |||
| 1701 | /* | ||
| 1702 | * If this was the outer most commit (the one that | ||
| 1703 | * changed the original pointer from HEAD to UPDATE), | ||
| 1704 | * then it is up to us to reset it to NORMAL. | ||
| 1705 | */ | ||
| 1706 | if (type == RB_PAGE_HEAD) { | ||
| 1707 | ret = rb_head_page_set_normal(cpu_buffer, next_page, | ||
| 1708 | tail_page, | ||
| 1709 | RB_PAGE_UPDATE); | ||
| 1710 | if (RB_WARN_ON(cpu_buffer, | ||
| 1711 | ret != RB_PAGE_UPDATE)) | ||
| 1712 | return -1; | ||
| 1713 | } | ||
| 1714 | |||
| 1715 | return 0; | ||
| 1716 | } | ||
| 1717 | |||
| 1125 | static unsigned rb_calculate_event_length(unsigned length) | 1718 | static unsigned rb_calculate_event_length(unsigned length) |
| 1126 | { | 1719 | { |
| 1127 | struct ring_buffer_event event; /* Used only for sizeof array */ | 1720 | struct ring_buffer_event event; /* Used only for sizeof array */ |
| @@ -1185,9 +1778,6 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer, | |||
| 1185 | event->type_len = RINGBUF_TYPE_PADDING; | 1778 | event->type_len = RINGBUF_TYPE_PADDING; |
| 1186 | /* time delta must be non zero */ | 1779 | /* time delta must be non zero */ |
| 1187 | event->time_delta = 1; | 1780 | event->time_delta = 1; |
| 1188 | /* Account for this as an entry */ | ||
| 1189 | local_inc(&tail_page->entries); | ||
| 1190 | local_inc(&cpu_buffer->entries); | ||
| 1191 | 1781 | ||
| 1192 | /* Set write to end of buffer */ | 1782 | /* Set write to end of buffer */ |
| 1193 | length = (tail + length) - BUF_PAGE_SIZE; | 1783 | length = (tail + length) - BUF_PAGE_SIZE; |
| @@ -1200,96 +1790,93 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer, | |||
| 1200 | struct buffer_page *commit_page, | 1790 | struct buffer_page *commit_page, |
| 1201 | struct buffer_page *tail_page, u64 *ts) | 1791 | struct buffer_page *tail_page, u64 *ts) |
| 1202 | { | 1792 | { |
| 1203 | struct buffer_page *next_page, *head_page, *reader_page; | ||
| 1204 | struct ring_buffer *buffer = cpu_buffer->buffer; | 1793 | struct ring_buffer *buffer = cpu_buffer->buffer; |
| 1205 | bool lock_taken = false; | 1794 | struct buffer_page *next_page; |
| 1206 | unsigned long flags; | 1795 | int ret; |
| 1207 | 1796 | ||
| 1208 | next_page = tail_page; | 1797 | next_page = tail_page; |
| 1209 | 1798 | ||
| 1210 | local_irq_save(flags); | ||
| 1211 | /* | ||
| 1212 | * Since the write to the buffer is still not | ||
| 1213 | * fully lockless, we must be careful with NMIs. | ||
| 1214 | * The locks in the writers are taken when a write | ||
| 1215 | * crosses to a new page. The locks protect against | ||
| 1216 | * races with the readers (this will soon be fixed | ||
| 1217 | * with a lockless solution). | ||
| 1218 | * | ||
| 1219 | * Because we can not protect against NMIs, and we | ||
| 1220 | * want to keep traces reentrant, we need to manage | ||
| 1221 | * what happens when we are in an NMI. | ||
| 1222 | * | ||
| 1223 | * NMIs can happen after we take the lock. | ||
| 1224 | * If we are in an NMI, only take the lock | ||
| 1225 | * if it is not already taken. Otherwise | ||
| 1226 | * simply fail. | ||
| 1227 | */ | ||
| 1228 | if (unlikely(in_nmi())) { | ||
| 1229 | if (!__raw_spin_trylock(&cpu_buffer->lock)) { | ||
| 1230 | cpu_buffer->nmi_dropped++; | ||
| 1231 | goto out_reset; | ||
| 1232 | } | ||
| 1233 | } else | ||
| 1234 | __raw_spin_lock(&cpu_buffer->lock); | ||
| 1235 | |||
| 1236 | lock_taken = true; | ||
| 1237 | |||
| 1238 | rb_inc_page(cpu_buffer, &next_page); | 1799 | rb_inc_page(cpu_buffer, &next_page); |
| 1239 | 1800 | ||
| 1240 | head_page = cpu_buffer->head_page; | ||
| 1241 | reader_page = cpu_buffer->reader_page; | ||
| 1242 | |||
| 1243 | /* we grabbed the lock before incrementing */ | ||
| 1244 | if (RB_WARN_ON(cpu_buffer, next_page == reader_page)) | ||
| 1245 | goto out_reset; | ||
| 1246 | |||
| 1247 | /* | 1801 | /* |
| 1248 | * If for some reason, we had an interrupt storm that made | 1802 | * If for some reason, we had an interrupt storm that made |
| 1249 | * it all the way around the buffer, bail, and warn | 1803 | * it all the way around the buffer, bail, and warn |
| 1250 | * about it. | 1804 | * about it. |
| 1251 | */ | 1805 | */ |
| 1252 | if (unlikely(next_page == commit_page)) { | 1806 | if (unlikely(next_page == commit_page)) { |
| 1253 | cpu_buffer->commit_overrun++; | 1807 | local_inc(&cpu_buffer->commit_overrun); |
| 1254 | goto out_reset; | 1808 | goto out_reset; |
| 1255 | } | 1809 | } |
| 1256 | 1810 | ||
| 1257 | if (next_page == head_page) { | 1811 | /* |
| 1258 | if (!(buffer->flags & RB_FL_OVERWRITE)) | 1812 | * This is where the fun begins! |
| 1259 | goto out_reset; | 1813 | * |
| 1260 | 1814 | * We are fighting against races between a reader that | |
| 1261 | /* tail_page has not moved yet? */ | 1815 | * could be on another CPU trying to swap its reader |
| 1262 | if (tail_page == cpu_buffer->tail_page) { | 1816 | * page with the buffer head. |
| 1263 | /* count overflows */ | 1817 | * |
| 1264 | cpu_buffer->overrun += | 1818 | * We are also fighting against interrupts coming in and |
| 1265 | local_read(&head_page->entries); | 1819 | * moving the head or tail on us as well. |
| 1820 | * | ||
| 1821 | * If the next page is the head page then we have filled | ||
| 1822 | * the buffer, unless the commit page is still on the | ||
| 1823 | * reader page. | ||
| 1824 | */ | ||
| 1825 | if (rb_is_head_page(cpu_buffer, next_page, &tail_page->list)) { | ||
| 1266 | 1826 | ||
| 1267 | rb_inc_page(cpu_buffer, &head_page); | 1827 | /* |
| 1268 | cpu_buffer->head_page = head_page; | 1828 | * If the commit is not on the reader page, then |
| 1269 | cpu_buffer->head_page->read = 0; | 1829 | * move the header page. |
| 1830 | */ | ||
| 1831 | if (!rb_is_reader_page(cpu_buffer->commit_page)) { | ||
| 1832 | /* | ||
| 1833 | * If we are not in overwrite mode, | ||
| 1834 | * this is easy, just stop here. | ||
| 1835 | */ | ||
| 1836 | if (!(buffer->flags & RB_FL_OVERWRITE)) | ||
| 1837 | goto out_reset; | ||
| 1838 | |||
| 1839 | ret = rb_handle_head_page(cpu_buffer, | ||
| 1840 | tail_page, | ||
| 1841 | next_page); | ||
| 1842 | if (ret < 0) | ||
| 1843 | goto out_reset; | ||
| 1844 | if (ret) | ||
| 1845 | goto out_again; | ||
| 1846 | } else { | ||
| 1847 | /* | ||
| 1848 | * We need to be careful here too. The | ||
| 1849 | * commit page could still be on the reader | ||
| 1850 | * page. We could have a small buffer, and | ||
| 1851 | * have filled up the buffer with events | ||
| 1852 | * from interrupts and such, and wrapped. | ||
| 1853 | * | ||
| 1854 | * Note, if the tail page is also the on the | ||
| 1855 | * reader_page, we let it move out. | ||
| 1856 | */ | ||
| 1857 | if (unlikely((cpu_buffer->commit_page != | ||
| 1858 | cpu_buffer->tail_page) && | ||
| 1859 | (cpu_buffer->commit_page == | ||
| 1860 | cpu_buffer->reader_page))) { | ||
| 1861 | local_inc(&cpu_buffer->commit_overrun); | ||
| 1862 | goto out_reset; | ||
| 1863 | } | ||
| 1270 | } | 1864 | } |
| 1271 | } | 1865 | } |
| 1272 | 1866 | ||
| 1273 | /* | 1867 | ret = rb_tail_page_update(cpu_buffer, tail_page, next_page); |
| 1274 | * If the tail page is still the same as what we think | 1868 | if (ret) { |
| 1275 | * it is, then it is up to us to update the tail | 1869 | /* |
| 1276 | * pointer. | 1870 | * Nested commits always have zero deltas, so |
| 1277 | */ | 1871 | * just reread the time stamp |
| 1278 | if (tail_page == cpu_buffer->tail_page) { | 1872 | */ |
| 1279 | local_set(&next_page->write, 0); | ||
| 1280 | local_set(&next_page->entries, 0); | ||
| 1281 | local_set(&next_page->page->commit, 0); | ||
| 1282 | cpu_buffer->tail_page = next_page; | ||
| 1283 | |||
| 1284 | /* reread the time stamp */ | ||
| 1285 | *ts = rb_time_stamp(buffer, cpu_buffer->cpu); | 1873 | *ts = rb_time_stamp(buffer, cpu_buffer->cpu); |
| 1286 | cpu_buffer->tail_page->page->time_stamp = *ts; | 1874 | next_page->page->time_stamp = *ts; |
| 1287 | } | 1875 | } |
| 1288 | 1876 | ||
| 1289 | rb_reset_tail(cpu_buffer, tail_page, tail, length); | 1877 | out_again: |
| 1290 | 1878 | ||
| 1291 | __raw_spin_unlock(&cpu_buffer->lock); | 1879 | rb_reset_tail(cpu_buffer, tail_page, tail, length); |
| 1292 | local_irq_restore(flags); | ||
| 1293 | 1880 | ||
| 1294 | /* fail and let the caller try again */ | 1881 | /* fail and let the caller try again */ |
| 1295 | return ERR_PTR(-EAGAIN); | 1882 | return ERR_PTR(-EAGAIN); |
| @@ -1298,9 +1885,6 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer, | |||
| 1298 | /* reset write */ | 1885 | /* reset write */ |
| 1299 | rb_reset_tail(cpu_buffer, tail_page, tail, length); | 1886 | rb_reset_tail(cpu_buffer, tail_page, tail, length); |
| 1300 | 1887 | ||
| 1301 | if (likely(lock_taken)) | ||
| 1302 | __raw_spin_unlock(&cpu_buffer->lock); | ||
| 1303 | local_irq_restore(flags); | ||
| 1304 | return NULL; | 1888 | return NULL; |
| 1305 | } | 1889 | } |
| 1306 | 1890 | ||
| @@ -1317,6 +1901,9 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer, | |||
| 1317 | barrier(); | 1901 | barrier(); |
| 1318 | tail_page = cpu_buffer->tail_page; | 1902 | tail_page = cpu_buffer->tail_page; |
| 1319 | write = local_add_return(length, &tail_page->write); | 1903 | write = local_add_return(length, &tail_page->write); |
| 1904 | |||
| 1905 | /* set write to only the index of the write */ | ||
| 1906 | write &= RB_WRITE_MASK; | ||
| 1320 | tail = write - length; | 1907 | tail = write - length; |
| 1321 | 1908 | ||
| 1322 | /* See if we shot pass the end of this buffer page */ | 1909 | /* See if we shot pass the end of this buffer page */ |
| @@ -1361,12 +1948,16 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer, | |||
| 1361 | bpage = cpu_buffer->tail_page; | 1948 | bpage = cpu_buffer->tail_page; |
| 1362 | 1949 | ||
| 1363 | if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) { | 1950 | if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) { |
| 1951 | unsigned long write_mask = | ||
| 1952 | local_read(&bpage->write) & ~RB_WRITE_MASK; | ||
| 1364 | /* | 1953 | /* |
| 1365 | * This is on the tail page. It is possible that | 1954 | * This is on the tail page. It is possible that |
| 1366 | * a write could come in and move the tail page | 1955 | * a write could come in and move the tail page |
| 1367 | * and write to the next page. That is fine | 1956 | * and write to the next page. That is fine |
| 1368 | * because we just shorten what is on this page. | 1957 | * because we just shorten what is on this page. |
| 1369 | */ | 1958 | */ |
| 1959 | old_index += write_mask; | ||
| 1960 | new_index += write_mask; | ||
| 1370 | index = local_cmpxchg(&bpage->write, old_index, new_index); | 1961 | index = local_cmpxchg(&bpage->write, old_index, new_index); |
| 1371 | if (index == old_index) | 1962 | if (index == old_index) |
| 1372 | return 1; | 1963 | return 1; |
| @@ -1482,7 +2073,8 @@ static void rb_end_commit(struct ring_buffer_per_cpu *cpu_buffer) | |||
| 1482 | } | 2073 | } |
| 1483 | 2074 | ||
| 1484 | static struct ring_buffer_event * | 2075 | static struct ring_buffer_event * |
| 1485 | rb_reserve_next_event(struct ring_buffer_per_cpu *cpu_buffer, | 2076 | rb_reserve_next_event(struct ring_buffer *buffer, |
| 2077 | struct ring_buffer_per_cpu *cpu_buffer, | ||
| 1486 | unsigned long length) | 2078 | unsigned long length) |
| 1487 | { | 2079 | { |
| 1488 | struct ring_buffer_event *event; | 2080 | struct ring_buffer_event *event; |
| @@ -1492,6 +2084,21 @@ rb_reserve_next_event(struct ring_buffer_per_cpu *cpu_buffer, | |||
| 1492 | 2084 | ||
| 1493 | rb_start_commit(cpu_buffer); | 2085 | rb_start_commit(cpu_buffer); |
| 1494 | 2086 | ||
| 2087 | #ifdef CONFIG_RING_BUFFER_ALLOW_SWAP | ||
| 2088 | /* | ||
| 2089 | * Due to the ability to swap a cpu buffer from a buffer | ||
| 2090 | * it is possible it was swapped before we committed. | ||
| 2091 | * (committing stops a swap). We check for it here and | ||
| 2092 | * if it happened, we have to fail the write. | ||
| 2093 | */ | ||
| 2094 | barrier(); | ||
| 2095 | if (unlikely(ACCESS_ONCE(cpu_buffer->buffer) != buffer)) { | ||
| 2096 | local_dec(&cpu_buffer->committing); | ||
| 2097 | local_dec(&cpu_buffer->commits); | ||
| 2098 | return NULL; | ||
| 2099 | } | ||
| 2100 | #endif | ||
| 2101 | |||
| 1495 | length = rb_calculate_event_length(length); | 2102 | length = rb_calculate_event_length(length); |
| 1496 | again: | 2103 | again: |
| 1497 | /* | 2104 | /* |
| @@ -1652,7 +2259,7 @@ ring_buffer_lock_reserve(struct ring_buffer *buffer, unsigned long length) | |||
| 1652 | if (length > BUF_MAX_DATA_SIZE) | 2259 | if (length > BUF_MAX_DATA_SIZE) |
| 1653 | goto out; | 2260 | goto out; |
| 1654 | 2261 | ||
| 1655 | event = rb_reserve_next_event(cpu_buffer, length); | 2262 | event = rb_reserve_next_event(buffer, cpu_buffer, length); |
| 1656 | if (!event) | 2263 | if (!event) |
| 1657 | goto out; | 2264 | goto out; |
| 1658 | 2265 | ||
| @@ -1675,18 +2282,23 @@ ring_buffer_lock_reserve(struct ring_buffer *buffer, unsigned long length) | |||
| 1675 | } | 2282 | } |
| 1676 | EXPORT_SYMBOL_GPL(ring_buffer_lock_reserve); | 2283 | EXPORT_SYMBOL_GPL(ring_buffer_lock_reserve); |
| 1677 | 2284 | ||
| 1678 | static void rb_commit(struct ring_buffer_per_cpu *cpu_buffer, | 2285 | static void |
| 2286 | rb_update_write_stamp(struct ring_buffer_per_cpu *cpu_buffer, | ||
| 1679 | struct ring_buffer_event *event) | 2287 | struct ring_buffer_event *event) |
| 1680 | { | 2288 | { |
| 1681 | local_inc(&cpu_buffer->entries); | ||
| 1682 | |||
| 1683 | /* | 2289 | /* |
| 1684 | * The event first in the commit queue updates the | 2290 | * The event first in the commit queue updates the |
| 1685 | * time stamp. | 2291 | * time stamp. |
| 1686 | */ | 2292 | */ |
| 1687 | if (rb_event_is_commit(cpu_buffer, event)) | 2293 | if (rb_event_is_commit(cpu_buffer, event)) |
| 1688 | cpu_buffer->write_stamp += event->time_delta; | 2294 | cpu_buffer->write_stamp += event->time_delta; |
| 2295 | } | ||
| 1689 | 2296 | ||
| 2297 | static void rb_commit(struct ring_buffer_per_cpu *cpu_buffer, | ||
| 2298 | struct ring_buffer_event *event) | ||
| 2299 | { | ||
| 2300 | local_inc(&cpu_buffer->entries); | ||
| 2301 | rb_update_write_stamp(cpu_buffer, event); | ||
| 1690 | rb_end_commit(cpu_buffer); | 2302 | rb_end_commit(cpu_buffer); |
| 1691 | } | 2303 | } |
| 1692 | 2304 | ||
| @@ -1733,32 +2345,57 @@ static inline void rb_event_discard(struct ring_buffer_event *event) | |||
| 1733 | event->time_delta = 1; | 2345 | event->time_delta = 1; |
| 1734 | } | 2346 | } |
| 1735 | 2347 | ||
| 1736 | /** | 2348 | /* |
| 1737 | * ring_buffer_event_discard - discard any event in the ring buffer | 2349 | * Decrement the entries to the page that an event is on. |
| 1738 | * @event: the event to discard | 2350 | * The event does not even need to exist, only the pointer |
| 1739 | * | 2351 | * to the page it is on. This may only be called before the commit |
| 1740 | * Sometimes a event that is in the ring buffer needs to be ignored. | 2352 | * takes place. |
| 1741 | * This function lets the user discard an event in the ring buffer | ||
| 1742 | * and then that event will not be read later. | ||
| 1743 | * | ||
| 1744 | * Note, it is up to the user to be careful with this, and protect | ||
| 1745 | * against races. If the user discards an event that has been consumed | ||
| 1746 | * it is possible that it could corrupt the ring buffer. | ||
| 1747 | */ | 2353 | */ |
| 1748 | void ring_buffer_event_discard(struct ring_buffer_event *event) | 2354 | static inline void |
| 2355 | rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer, | ||
| 2356 | struct ring_buffer_event *event) | ||
| 1749 | { | 2357 | { |
| 1750 | rb_event_discard(event); | 2358 | unsigned long addr = (unsigned long)event; |
| 2359 | struct buffer_page *bpage = cpu_buffer->commit_page; | ||
| 2360 | struct buffer_page *start; | ||
| 2361 | |||
| 2362 | addr &= PAGE_MASK; | ||
| 2363 | |||
| 2364 | /* Do the likely case first */ | ||
| 2365 | if (likely(bpage->page == (void *)addr)) { | ||
| 2366 | local_dec(&bpage->entries); | ||
| 2367 | return; | ||
| 2368 | } | ||
| 2369 | |||
| 2370 | /* | ||
| 2371 | * Because the commit page may be on the reader page we | ||
| 2372 | * start with the next page and check the end loop there. | ||
| 2373 | */ | ||
| 2374 | rb_inc_page(cpu_buffer, &bpage); | ||
| 2375 | start = bpage; | ||
| 2376 | do { | ||
| 2377 | if (bpage->page == (void *)addr) { | ||
| 2378 | local_dec(&bpage->entries); | ||
| 2379 | return; | ||
| 2380 | } | ||
| 2381 | rb_inc_page(cpu_buffer, &bpage); | ||
| 2382 | } while (bpage != start); | ||
| 2383 | |||
| 2384 | /* commit not part of this buffer?? */ | ||
| 2385 | RB_WARN_ON(cpu_buffer, 1); | ||
| 1751 | } | 2386 | } |
| 1752 | EXPORT_SYMBOL_GPL(ring_buffer_event_discard); | ||
| 1753 | 2387 | ||
| 1754 | /** | 2388 | /** |
| 1755 | * ring_buffer_commit_discard - discard an event that has not been committed | 2389 | * ring_buffer_commit_discard - discard an event that has not been committed |
| 1756 | * @buffer: the ring buffer | 2390 | * @buffer: the ring buffer |
| 1757 | * @event: non committed event to discard | 2391 | * @event: non committed event to discard |
| 1758 | * | 2392 | * |
| 1759 | * This is similar to ring_buffer_event_discard but must only be | 2393 | * Sometimes an event that is in the ring buffer needs to be ignored. |
| 1760 | * performed on an event that has not been committed yet. The difference | 2394 | * This function lets the user discard an event in the ring buffer |
| 1761 | * is that this will also try to free the event from the ring buffer | 2395 | * and then that event will not be read later. |
| 2396 | * | ||
| 2397 | * This function only works if it is called before the the item has been | ||
| 2398 | * committed. It will try to free the event from the ring buffer | ||
| 1762 | * if another event has not been added behind it. | 2399 | * if another event has not been added behind it. |
| 1763 | * | 2400 | * |
| 1764 | * If another event has been added behind it, it will set the event | 2401 | * If another event has been added behind it, it will set the event |
| @@ -1786,14 +2423,15 @@ void ring_buffer_discard_commit(struct ring_buffer *buffer, | |||
| 1786 | */ | 2423 | */ |
| 1787 | RB_WARN_ON(buffer, !local_read(&cpu_buffer->committing)); | 2424 | RB_WARN_ON(buffer, !local_read(&cpu_buffer->committing)); |
| 1788 | 2425 | ||
| 2426 | rb_decrement_entry(cpu_buffer, event); | ||
| 1789 | if (rb_try_to_discard(cpu_buffer, event)) | 2427 | if (rb_try_to_discard(cpu_buffer, event)) |
| 1790 | goto out; | 2428 | goto out; |
| 1791 | 2429 | ||
| 1792 | /* | 2430 | /* |
| 1793 | * The commit is still visible by the reader, so we | 2431 | * The commit is still visible by the reader, so we |
| 1794 | * must increment entries. | 2432 | * must still update the timestamp. |
| 1795 | */ | 2433 | */ |
| 1796 | local_inc(&cpu_buffer->entries); | 2434 | rb_update_write_stamp(cpu_buffer, event); |
| 1797 | out: | 2435 | out: |
| 1798 | rb_end_commit(cpu_buffer); | 2436 | rb_end_commit(cpu_buffer); |
| 1799 | 2437 | ||
| @@ -1854,7 +2492,7 @@ int ring_buffer_write(struct ring_buffer *buffer, | |||
| 1854 | if (length > BUF_MAX_DATA_SIZE) | 2492 | if (length > BUF_MAX_DATA_SIZE) |
| 1855 | goto out; | 2493 | goto out; |
| 1856 | 2494 | ||
| 1857 | event = rb_reserve_next_event(cpu_buffer, length); | 2495 | event = rb_reserve_next_event(buffer, cpu_buffer, length); |
| 1858 | if (!event) | 2496 | if (!event) |
| 1859 | goto out; | 2497 | goto out; |
| 1860 | 2498 | ||
| @@ -1875,9 +2513,13 @@ EXPORT_SYMBOL_GPL(ring_buffer_write); | |||
| 1875 | static int rb_per_cpu_empty(struct ring_buffer_per_cpu *cpu_buffer) | 2513 | static int rb_per_cpu_empty(struct ring_buffer_per_cpu *cpu_buffer) |
| 1876 | { | 2514 | { |
| 1877 | struct buffer_page *reader = cpu_buffer->reader_page; | 2515 | struct buffer_page *reader = cpu_buffer->reader_page; |
| 1878 | struct buffer_page *head = cpu_buffer->head_page; | 2516 | struct buffer_page *head = rb_set_head_page(cpu_buffer); |
| 1879 | struct buffer_page *commit = cpu_buffer->commit_page; | 2517 | struct buffer_page *commit = cpu_buffer->commit_page; |
| 1880 | 2518 | ||
| 2519 | /* In case of error, head will be NULL */ | ||
| 2520 | if (unlikely(!head)) | ||
| 2521 | return 1; | ||
| 2522 | |||
| 1881 | return reader->read == rb_page_commit(reader) && | 2523 | return reader->read == rb_page_commit(reader) && |
| 1882 | (commit == reader || | 2524 | (commit == reader || |
| 1883 | (commit == head && | 2525 | (commit == head && |
| @@ -1968,7 +2610,7 @@ unsigned long ring_buffer_entries_cpu(struct ring_buffer *buffer, int cpu) | |||
| 1968 | return 0; | 2610 | return 0; |
| 1969 | 2611 | ||
| 1970 | cpu_buffer = buffer->buffers[cpu]; | 2612 | cpu_buffer = buffer->buffers[cpu]; |
| 1971 | ret = (local_read(&cpu_buffer->entries) - cpu_buffer->overrun) | 2613 | ret = (local_read(&cpu_buffer->entries) - local_read(&cpu_buffer->overrun)) |
| 1972 | - cpu_buffer->read; | 2614 | - cpu_buffer->read; |
| 1973 | 2615 | ||
| 1974 | return ret; | 2616 | return ret; |
| @@ -1989,33 +2631,13 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu) | |||
| 1989 | return 0; | 2631 | return 0; |
| 1990 | 2632 | ||
| 1991 | cpu_buffer = buffer->buffers[cpu]; | 2633 | cpu_buffer = buffer->buffers[cpu]; |
| 1992 | ret = cpu_buffer->overrun; | 2634 | ret = local_read(&cpu_buffer->overrun); |
| 1993 | 2635 | ||
| 1994 | return ret; | 2636 | return ret; |
| 1995 | } | 2637 | } |
| 1996 | EXPORT_SYMBOL_GPL(ring_buffer_overrun_cpu); | 2638 | EXPORT_SYMBOL_GPL(ring_buffer_overrun_cpu); |
| 1997 | 2639 | ||
| 1998 | /** | 2640 | /** |
| 1999 | * ring_buffer_nmi_dropped_cpu - get the number of nmis that were dropped | ||
| 2000 | * @buffer: The ring buffer | ||
| 2001 | * @cpu: The per CPU buffer to get the number of overruns from | ||
| 2002 | */ | ||
| 2003 | unsigned long ring_buffer_nmi_dropped_cpu(struct ring_buffer *buffer, int cpu) | ||
| 2004 | { | ||
| 2005 | struct ring_buffer_per_cpu *cpu_buffer; | ||
| 2006 | unsigned long ret; | ||
| 2007 | |||
| 2008 | if (!cpumask_test_cpu(cpu, buffer->cpumask)) | ||
| 2009 | return 0; | ||
| 2010 | |||
| 2011 | cpu_buffer = buffer->buffers[cpu]; | ||
| 2012 | ret = cpu_buffer->nmi_dropped; | ||
| 2013 | |||
| 2014 | return ret; | ||
| 2015 | } | ||
| 2016 | EXPORT_SYMBOL_GPL(ring_buffer_nmi_dropped_cpu); | ||
| 2017 | |||
| 2018 | /** | ||
| 2019 | * ring_buffer_commit_overrun_cpu - get the number of overruns caused by commits | 2641 | * ring_buffer_commit_overrun_cpu - get the number of overruns caused by commits |
| 2020 | * @buffer: The ring buffer | 2642 | * @buffer: The ring buffer |
| 2021 | * @cpu: The per CPU buffer to get the number of overruns from | 2643 | * @cpu: The per CPU buffer to get the number of overruns from |
| @@ -2030,7 +2652,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu) | |||
| 2030 | return 0; | 2652 | return 0; |
| 2031 | 2653 | ||
| 2032 | cpu_buffer = buffer->buffers[cpu]; | 2654 | cpu_buffer = buffer->buffers[cpu]; |
| 2033 | ret = cpu_buffer->commit_overrun; | 2655 | ret = local_read(&cpu_buffer->commit_overrun); |
| 2034 | 2656 | ||
| 2035 | return ret; | 2657 | return ret; |
| 2036 | } | 2658 | } |
| @@ -2053,7 +2675,7 @@ unsigned long ring_buffer_entries(struct ring_buffer *buffer) | |||
| 2053 | for_each_buffer_cpu(buffer, cpu) { | 2675 | for_each_buffer_cpu(buffer, cpu) { |
| 2054 | cpu_buffer = buffer->buffers[cpu]; | 2676 | cpu_buffer = buffer->buffers[cpu]; |
| 2055 | entries += (local_read(&cpu_buffer->entries) - | 2677 | entries += (local_read(&cpu_buffer->entries) - |
| 2056 | cpu_buffer->overrun) - cpu_buffer->read; | 2678 | local_read(&cpu_buffer->overrun)) - cpu_buffer->read; |
| 2057 | } | 2679 | } |
| 2058 | 2680 | ||
| 2059 | return entries; | 2681 | return entries; |
| @@ -2076,7 +2698,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer) | |||
| 2076 | /* if you care about this being correct, lock the buffer */ | 2698 | /* if you care about this being correct, lock the buffer */ |
| 2077 | for_each_buffer_cpu(buffer, cpu) { | 2699 | for_each_buffer_cpu(buffer, cpu) { |
| 2078 | cpu_buffer = buffer->buffers[cpu]; | 2700 | cpu_buffer = buffer->buffers[cpu]; |
| 2079 | overruns += cpu_buffer->overrun; | 2701 | overruns += local_read(&cpu_buffer->overrun); |
| 2080 | } | 2702 | } |
| 2081 | 2703 | ||
| 2082 | return overruns; | 2704 | return overruns; |
| @@ -2089,8 +2711,10 @@ static void rb_iter_reset(struct ring_buffer_iter *iter) | |||
| 2089 | 2711 | ||
| 2090 | /* Iterator usage is expected to have record disabled */ | 2712 | /* Iterator usage is expected to have record disabled */ |
| 2091 | if (list_empty(&cpu_buffer->reader_page->list)) { | 2713 | if (list_empty(&cpu_buffer->reader_page->list)) { |
| 2092 | iter->head_page = cpu_buffer->head_page; | 2714 | iter->head_page = rb_set_head_page(cpu_buffer); |
| 2093 | iter->head = cpu_buffer->head_page->read; | 2715 | if (unlikely(!iter->head_page)) |
| 2716 | return; | ||
| 2717 | iter->head = iter->head_page->read; | ||
| 2094 | } else { | 2718 | } else { |
| 2095 | iter->head_page = cpu_buffer->reader_page; | 2719 | iter->head_page = cpu_buffer->reader_page; |
| 2096 | iter->head = cpu_buffer->reader_page->read; | 2720 | iter->head = cpu_buffer->reader_page->read; |
| @@ -2207,6 +2831,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer) | |||
| 2207 | struct buffer_page *reader = NULL; | 2831 | struct buffer_page *reader = NULL; |
| 2208 | unsigned long flags; | 2832 | unsigned long flags; |
| 2209 | int nr_loops = 0; | 2833 | int nr_loops = 0; |
| 2834 | int ret; | ||
| 2210 | 2835 | ||
| 2211 | local_irq_save(flags); | 2836 | local_irq_save(flags); |
| 2212 | __raw_spin_lock(&cpu_buffer->lock); | 2837 | __raw_spin_lock(&cpu_buffer->lock); |
| @@ -2240,30 +2865,56 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer) | |||
| 2240 | goto out; | 2865 | goto out; |
| 2241 | 2866 | ||
| 2242 | /* | 2867 | /* |
| 2243 | * Splice the empty reader page into the list around the head. | ||
| 2244 | * Reset the reader page to size zero. | 2868 | * Reset the reader page to size zero. |
| 2245 | */ | 2869 | */ |
| 2870 | local_set(&cpu_buffer->reader_page->write, 0); | ||
| 2871 | local_set(&cpu_buffer->reader_page->entries, 0); | ||
| 2872 | local_set(&cpu_buffer->reader_page->page->commit, 0); | ||
| 2246 | 2873 | ||
| 2247 | reader = cpu_buffer->head_page; | 2874 | spin: |
| 2875 | /* | ||
| 2876 | * Splice the empty reader page into the list around the head. | ||
| 2877 | */ | ||
| 2878 | reader = rb_set_head_page(cpu_buffer); | ||
| 2248 | cpu_buffer->reader_page->list.next = reader->list.next; | 2879 | cpu_buffer->reader_page->list.next = reader->list.next; |
| 2249 | cpu_buffer->reader_page->list.prev = reader->list.prev; | 2880 | cpu_buffer->reader_page->list.prev = reader->list.prev; |
| 2250 | 2881 | ||
| 2251 | local_set(&cpu_buffer->reader_page->write, 0); | 2882 | /* |
| 2252 | local_set(&cpu_buffer->reader_page->entries, 0); | 2883 | * cpu_buffer->pages just needs to point to the buffer, it |
| 2253 | local_set(&cpu_buffer->reader_page->page->commit, 0); | 2884 | * has no specific buffer page to point to. Lets move it out |
| 2885 | * of our way so we don't accidently swap it. | ||
| 2886 | */ | ||
| 2887 | cpu_buffer->pages = reader->list.prev; | ||
| 2254 | 2888 | ||
| 2255 | /* Make the reader page now replace the head */ | 2889 | /* The reader page will be pointing to the new head */ |
| 2256 | reader->list.prev->next = &cpu_buffer->reader_page->list; | 2890 | rb_set_list_to_head(cpu_buffer, &cpu_buffer->reader_page->list); |
| 2257 | reader->list.next->prev = &cpu_buffer->reader_page->list; | ||
| 2258 | 2891 | ||
| 2259 | /* | 2892 | /* |
| 2260 | * If the tail is on the reader, then we must set the head | 2893 | * Here's the tricky part. |
| 2261 | * to the inserted page, otherwise we set it one before. | 2894 | * |
| 2895 | * We need to move the pointer past the header page. | ||
| 2896 | * But we can only do that if a writer is not currently | ||
| 2897 | * moving it. The page before the header page has the | ||
| 2898 | * flag bit '1' set if it is pointing to the page we want. | ||
| 2899 | * but if the writer is in the process of moving it | ||
| 2900 | * than it will be '2' or already moved '0'. | ||
| 2262 | */ | 2901 | */ |
| 2263 | cpu_buffer->head_page = cpu_buffer->reader_page; | ||
| 2264 | 2902 | ||
| 2265 | if (cpu_buffer->commit_page != reader) | 2903 | ret = rb_head_page_replace(reader, cpu_buffer->reader_page); |
| 2266 | rb_inc_page(cpu_buffer, &cpu_buffer->head_page); | 2904 | |
| 2905 | /* | ||
| 2906 | * If we did not convert it, then we must try again. | ||
| 2907 | */ | ||
| 2908 | if (!ret) | ||
| 2909 | goto spin; | ||
| 2910 | |||
| 2911 | /* | ||
| 2912 | * Yeah! We succeeded in replacing the page. | ||
| 2913 | * | ||
| 2914 | * Now make the new head point back to the reader page. | ||
| 2915 | */ | ||
| 2916 | reader->list.next->prev = &cpu_buffer->reader_page->list; | ||
| 2917 | rb_inc_page(cpu_buffer, &cpu_buffer->head_page); | ||
| 2267 | 2918 | ||
| 2268 | /* Finally update the reader page to the new head */ | 2919 | /* Finally update the reader page to the new head */ |
| 2269 | cpu_buffer->reader_page = reader; | 2920 | cpu_buffer->reader_page = reader; |
| @@ -2292,8 +2943,7 @@ static void rb_advance_reader(struct ring_buffer_per_cpu *cpu_buffer) | |||
| 2292 | 2943 | ||
| 2293 | event = rb_reader_event(cpu_buffer); | 2944 | event = rb_reader_event(cpu_buffer); |
| 2294 | 2945 | ||
| 2295 | if (event->type_len <= RINGBUF_TYPE_DATA_TYPE_LEN_MAX | 2946 | if (event->type_len <= RINGBUF_TYPE_DATA_TYPE_LEN_MAX) |
| 2296 | || rb_discarded_event(event)) | ||
| 2297 | cpu_buffer->read++; | 2947 | cpu_buffer->read++; |
| 2298 | 2948 | ||
| 2299 | rb_update_read_stamp(cpu_buffer, event); | 2949 | rb_update_read_stamp(cpu_buffer, event); |
| @@ -2525,10 +3175,8 @@ ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts) | |||
| 2525 | spin_unlock(&cpu_buffer->reader_lock); | 3175 | spin_unlock(&cpu_buffer->reader_lock); |
| 2526 | local_irq_restore(flags); | 3176 | local_irq_restore(flags); |
| 2527 | 3177 | ||
| 2528 | if (event && event->type_len == RINGBUF_TYPE_PADDING) { | 3178 | if (event && event->type_len == RINGBUF_TYPE_PADDING) |
| 2529 | cpu_relax(); | ||
| 2530 | goto again; | 3179 | goto again; |
| 2531 | } | ||
| 2532 | 3180 | ||
| 2533 | return event; | 3181 | return event; |
| 2534 | } | 3182 | } |
| @@ -2553,10 +3201,8 @@ ring_buffer_iter_peek(struct ring_buffer_iter *iter, u64 *ts) | |||
| 2553 | event = rb_iter_peek(iter, ts); | 3201 | event = rb_iter_peek(iter, ts); |
| 2554 | spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); | 3202 | spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); |
| 2555 | 3203 | ||
| 2556 | if (event && event->type_len == RINGBUF_TYPE_PADDING) { | 3204 | if (event && event->type_len == RINGBUF_TYPE_PADDING) |
| 2557 | cpu_relax(); | ||
| 2558 | goto again; | 3205 | goto again; |
| 2559 | } | ||
| 2560 | 3206 | ||
| 2561 | return event; | 3207 | return event; |
| 2562 | } | 3208 | } |
| @@ -2602,10 +3248,8 @@ ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts) | |||
| 2602 | out: | 3248 | out: |
| 2603 | preempt_enable(); | 3249 | preempt_enable(); |
| 2604 | 3250 | ||
| 2605 | if (event && event->type_len == RINGBUF_TYPE_PADDING) { | 3251 | if (event && event->type_len == RINGBUF_TYPE_PADDING) |
| 2606 | cpu_relax(); | ||
| 2607 | goto again; | 3252 | goto again; |
| 2608 | } | ||
| 2609 | 3253 | ||
| 2610 | return event; | 3254 | return event; |
| 2611 | } | 3255 | } |
| @@ -2685,21 +3329,19 @@ ring_buffer_read(struct ring_buffer_iter *iter, u64 *ts) | |||
| 2685 | struct ring_buffer_per_cpu *cpu_buffer = iter->cpu_buffer; | 3329 | struct ring_buffer_per_cpu *cpu_buffer = iter->cpu_buffer; |
| 2686 | unsigned long flags; | 3330 | unsigned long flags; |
| 2687 | 3331 | ||
| 2688 | again: | ||
| 2689 | spin_lock_irqsave(&cpu_buffer->reader_lock, flags); | 3332 | spin_lock_irqsave(&cpu_buffer->reader_lock, flags); |
| 3333 | again: | ||
| 2690 | event = rb_iter_peek(iter, ts); | 3334 | event = rb_iter_peek(iter, ts); |
| 2691 | if (!event) | 3335 | if (!event) |
| 2692 | goto out; | 3336 | goto out; |
| 2693 | 3337 | ||
| 3338 | if (event->type_len == RINGBUF_TYPE_PADDING) | ||
| 3339 | goto again; | ||
| 3340 | |||
| 2694 | rb_advance_iter(iter); | 3341 | rb_advance_iter(iter); |
| 2695 | out: | 3342 | out: |
| 2696 | spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); | 3343 | spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); |
| 2697 | 3344 | ||
| 2698 | if (event && event->type_len == RINGBUF_TYPE_PADDING) { | ||
| 2699 | cpu_relax(); | ||
| 2700 | goto again; | ||
| 2701 | } | ||
| 2702 | |||
| 2703 | return event; | 3345 | return event; |
| 2704 | } | 3346 | } |
| 2705 | EXPORT_SYMBOL_GPL(ring_buffer_read); | 3347 | EXPORT_SYMBOL_GPL(ring_buffer_read); |
| @@ -2717,8 +3359,10 @@ EXPORT_SYMBOL_GPL(ring_buffer_size); | |||
| 2717 | static void | 3359 | static void |
| 2718 | rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer) | 3360 | rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer) |
| 2719 | { | 3361 | { |
| 3362 | rb_head_page_deactivate(cpu_buffer); | ||
| 3363 | |||
| 2720 | cpu_buffer->head_page | 3364 | cpu_buffer->head_page |
| 2721 | = list_entry(cpu_buffer->pages.next, struct buffer_page, list); | 3365 | = list_entry(cpu_buffer->pages, struct buffer_page, list); |
| 2722 | local_set(&cpu_buffer->head_page->write, 0); | 3366 | local_set(&cpu_buffer->head_page->write, 0); |
| 2723 | local_set(&cpu_buffer->head_page->entries, 0); | 3367 | local_set(&cpu_buffer->head_page->entries, 0); |
| 2724 | local_set(&cpu_buffer->head_page->page->commit, 0); | 3368 | local_set(&cpu_buffer->head_page->page->commit, 0); |
| @@ -2734,16 +3378,17 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer) | |||
| 2734 | local_set(&cpu_buffer->reader_page->page->commit, 0); | 3378 | local_set(&cpu_buffer->reader_page->page->commit, 0); |
| 2735 | cpu_buffer->reader_page->read = 0; | 3379 | cpu_buffer->reader_page->read = 0; |
| 2736 | 3380 | ||
| 2737 | cpu_buffer->nmi_dropped = 0; | 3381 | local_set(&cpu_buffer->commit_overrun, 0); |
| 2738 | cpu_buffer->commit_overrun = 0; | 3382 | local_set(&cpu_buffer->overrun, 0); |
| 2739 | cpu_buffer->overrun = 0; | ||
| 2740 | cpu_buffer->read = 0; | ||
| 2741 | local_set(&cpu_buffer->entries, 0); | 3383 | local_set(&cpu_buffer->entries, 0); |
| 2742 | local_set(&cpu_buffer->committing, 0); | 3384 | local_set(&cpu_buffer->committing, 0); |
| 2743 | local_set(&cpu_buffer->commits, 0); | 3385 | local_set(&cpu_buffer->commits, 0); |
| 3386 | cpu_buffer->read = 0; | ||
| 2744 | 3387 | ||
| 2745 | cpu_buffer->write_stamp = 0; | 3388 | cpu_buffer->write_stamp = 0; |
| 2746 | cpu_buffer->read_stamp = 0; | 3389 | cpu_buffer->read_stamp = 0; |
| 3390 | |||
| 3391 | rb_head_page_activate(cpu_buffer); | ||
| 2747 | } | 3392 | } |
| 2748 | 3393 | ||
| 2749 | /** | 3394 | /** |
| @@ -2763,12 +3408,16 @@ void ring_buffer_reset_cpu(struct ring_buffer *buffer, int cpu) | |||
| 2763 | 3408 | ||
| 2764 | spin_lock_irqsave(&cpu_buffer->reader_lock, flags); | 3409 | spin_lock_irqsave(&cpu_buffer->reader_lock, flags); |
| 2765 | 3410 | ||
| 3411 | if (RB_WARN_ON(cpu_buffer, local_read(&cpu_buffer->committing))) | ||
| 3412 | goto out; | ||
| 3413 | |||
| 2766 | __raw_spin_lock(&cpu_buffer->lock); | 3414 | __raw_spin_lock(&cpu_buffer->lock); |
| 2767 | 3415 | ||
| 2768 | rb_reset_cpu(cpu_buffer); | 3416 | rb_reset_cpu(cpu_buffer); |
| 2769 | 3417 | ||
| 2770 | __raw_spin_unlock(&cpu_buffer->lock); | 3418 | __raw_spin_unlock(&cpu_buffer->lock); |
| 2771 | 3419 | ||
| 3420 | out: | ||
| 2772 | spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); | 3421 | spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); |
| 2773 | 3422 | ||
| 2774 | atomic_dec(&cpu_buffer->record_disabled); | 3423 | atomic_dec(&cpu_buffer->record_disabled); |
| @@ -2851,6 +3500,7 @@ int ring_buffer_empty_cpu(struct ring_buffer *buffer, int cpu) | |||
| 2851 | } | 3500 | } |
| 2852 | EXPORT_SYMBOL_GPL(ring_buffer_empty_cpu); | 3501 | EXPORT_SYMBOL_GPL(ring_buffer_empty_cpu); |
| 2853 | 3502 | ||
| 3503 | #ifdef CONFIG_RING_BUFFER_ALLOW_SWAP | ||
| 2854 | /** | 3504 | /** |
| 2855 | * ring_buffer_swap_cpu - swap a CPU buffer between two ring buffers | 3505 | * ring_buffer_swap_cpu - swap a CPU buffer between two ring buffers |
| 2856 | * @buffer_a: One buffer to swap with | 3506 | * @buffer_a: One buffer to swap with |
| @@ -2905,20 +3555,28 @@ int ring_buffer_swap_cpu(struct ring_buffer *buffer_a, | |||
| 2905 | atomic_inc(&cpu_buffer_a->record_disabled); | 3555 | atomic_inc(&cpu_buffer_a->record_disabled); |
| 2906 | atomic_inc(&cpu_buffer_b->record_disabled); | 3556 | atomic_inc(&cpu_buffer_b->record_disabled); |
| 2907 | 3557 | ||
| 3558 | ret = -EBUSY; | ||
| 3559 | if (local_read(&cpu_buffer_a->committing)) | ||
| 3560 | goto out_dec; | ||
| 3561 | if (local_read(&cpu_buffer_b->committing)) | ||
| 3562 | goto out_dec; | ||
| 3563 | |||
| 2908 | buffer_a->buffers[cpu] = cpu_buffer_b; | 3564 | buffer_a->buffers[cpu] = cpu_buffer_b; |
| 2909 | buffer_b->buffers[cpu] = cpu_buffer_a; | 3565 | buffer_b->buffers[cpu] = cpu_buffer_a; |
| 2910 | 3566 | ||
| 2911 | cpu_buffer_b->buffer = buffer_a; | 3567 | cpu_buffer_b->buffer = buffer_a; |
| 2912 | cpu_buffer_a->buffer = buffer_b; | 3568 | cpu_buffer_a->buffer = buffer_b; |
| 2913 | 3569 | ||
| 3570 | ret = 0; | ||
| 3571 | |||
| 3572 | out_dec: | ||
| 2914 | atomic_dec(&cpu_buffer_a->record_disabled); | 3573 | atomic_dec(&cpu_buffer_a->record_disabled); |
| 2915 | atomic_dec(&cpu_buffer_b->record_disabled); | 3574 | atomic_dec(&cpu_buffer_b->record_disabled); |
| 2916 | |||
| 2917 | ret = 0; | ||
| 2918 | out: | 3575 | out: |
| 2919 | return ret; | 3576 | return ret; |
| 2920 | } | 3577 | } |
| 2921 | EXPORT_SYMBOL_GPL(ring_buffer_swap_cpu); | 3578 | EXPORT_SYMBOL_GPL(ring_buffer_swap_cpu); |
| 3579 | #endif /* CONFIG_RING_BUFFER_ALLOW_SWAP */ | ||
| 2922 | 3580 | ||
| 2923 | /** | 3581 | /** |
| 2924 | * ring_buffer_alloc_read_page - allocate a page to read from buffer | 3582 | * ring_buffer_alloc_read_page - allocate a page to read from buffer |
| @@ -3091,7 +3749,7 @@ int ring_buffer_read_page(struct ring_buffer *buffer, | |||
| 3091 | read = 0; | 3749 | read = 0; |
| 3092 | } else { | 3750 | } else { |
| 3093 | /* update the entry counter */ | 3751 | /* update the entry counter */ |
| 3094 | cpu_buffer->read += local_read(&reader->entries); | 3752 | cpu_buffer->read += rb_page_entries(reader); |
| 3095 | 3753 | ||
| 3096 | /* swap the pages */ | 3754 | /* swap the pages */ |
| 3097 | rb_init_page(bpage); | 3755 | rb_init_page(bpage); |
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 8c358395d338..5c75deeefe30 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
| @@ -43,14 +43,11 @@ | |||
| 43 | 43 | ||
| 44 | #define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE) | 44 | #define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE) |
| 45 | 45 | ||
| 46 | unsigned long __read_mostly tracing_max_latency; | ||
| 47 | unsigned long __read_mostly tracing_thresh; | ||
| 48 | |||
| 49 | /* | 46 | /* |
| 50 | * On boot up, the ring buffer is set to the minimum size, so that | 47 | * On boot up, the ring buffer is set to the minimum size, so that |
| 51 | * we do not waste memory on systems that are not using tracing. | 48 | * we do not waste memory on systems that are not using tracing. |
| 52 | */ | 49 | */ |
| 53 | static int ring_buffer_expanded; | 50 | int ring_buffer_expanded; |
| 54 | 51 | ||
| 55 | /* | 52 | /* |
| 56 | * We need to change this state when a selftest is running. | 53 | * We need to change this state when a selftest is running. |
| @@ -64,7 +61,7 @@ static bool __read_mostly tracing_selftest_running; | |||
| 64 | /* | 61 | /* |
| 65 | * If a tracer is running, we do not want to run SELFTEST. | 62 | * If a tracer is running, we do not want to run SELFTEST. |
| 66 | */ | 63 | */ |
| 67 | static bool __read_mostly tracing_selftest_disabled; | 64 | bool __read_mostly tracing_selftest_disabled; |
| 68 | 65 | ||
| 69 | /* For tracers that don't implement custom flags */ | 66 | /* For tracers that don't implement custom flags */ |
| 70 | static struct tracer_opt dummy_tracer_opt[] = { | 67 | static struct tracer_opt dummy_tracer_opt[] = { |
| @@ -89,7 +86,7 @@ static int dummy_set_flag(u32 old_flags, u32 bit, int set) | |||
| 89 | */ | 86 | */ |
| 90 | static int tracing_disabled = 1; | 87 | static int tracing_disabled = 1; |
| 91 | 88 | ||
| 92 | static DEFINE_PER_CPU(local_t, ftrace_cpu_disabled); | 89 | DEFINE_PER_CPU(local_t, ftrace_cpu_disabled); |
| 93 | 90 | ||
| 94 | static inline void ftrace_disable_cpu(void) | 91 | static inline void ftrace_disable_cpu(void) |
| 95 | { | 92 | { |
| @@ -172,10 +169,11 @@ static struct trace_array global_trace; | |||
| 172 | 169 | ||
| 173 | static DEFINE_PER_CPU(struct trace_array_cpu, global_trace_cpu); | 170 | static DEFINE_PER_CPU(struct trace_array_cpu, global_trace_cpu); |
| 174 | 171 | ||
| 175 | int filter_current_check_discard(struct ftrace_event_call *call, void *rec, | 172 | int filter_current_check_discard(struct ring_buffer *buffer, |
| 173 | struct ftrace_event_call *call, void *rec, | ||
| 176 | struct ring_buffer_event *event) | 174 | struct ring_buffer_event *event) |
| 177 | { | 175 | { |
| 178 | return filter_check_discard(call, rec, global_trace.buffer, event); | 176 | return filter_check_discard(call, rec, buffer, event); |
| 179 | } | 177 | } |
| 180 | EXPORT_SYMBOL_GPL(filter_current_check_discard); | 178 | EXPORT_SYMBOL_GPL(filter_current_check_discard); |
| 181 | 179 | ||
| @@ -266,6 +264,9 @@ unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | | |||
| 266 | TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME | | 264 | TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME | |
| 267 | TRACE_ITER_GRAPH_TIME; | 265 | TRACE_ITER_GRAPH_TIME; |
| 268 | 266 | ||
| 267 | static int trace_stop_count; | ||
| 268 | static DEFINE_SPINLOCK(tracing_start_lock); | ||
| 269 | |||
| 269 | /** | 270 | /** |
| 270 | * trace_wake_up - wake up tasks waiting for trace input | 271 | * trace_wake_up - wake up tasks waiting for trace input |
| 271 | * | 272 | * |
| @@ -323,50 +324,20 @@ static const char *trace_options[] = { | |||
| 323 | "printk-msg-only", | 324 | "printk-msg-only", |
| 324 | "context-info", | 325 | "context-info", |
| 325 | "latency-format", | 326 | "latency-format", |
| 326 | "global-clock", | ||
| 327 | "sleep-time", | 327 | "sleep-time", |
| 328 | "graph-time", | 328 | "graph-time", |
| 329 | NULL | 329 | NULL |
| 330 | }; | 330 | }; |
| 331 | 331 | ||
| 332 | /* | 332 | static struct { |
| 333 | * ftrace_max_lock is used to protect the swapping of buffers | 333 | u64 (*func)(void); |
| 334 | * when taking a max snapshot. The buffers themselves are | 334 | const char *name; |
| 335 | * protected by per_cpu spinlocks. But the action of the swap | 335 | } trace_clocks[] = { |
| 336 | * needs its own lock. | 336 | { trace_clock_local, "local" }, |
| 337 | * | 337 | { trace_clock_global, "global" }, |
| 338 | * This is defined as a raw_spinlock_t in order to help | 338 | }; |
| 339 | * with performance when lockdep debugging is enabled. | ||
| 340 | */ | ||
| 341 | static raw_spinlock_t ftrace_max_lock = | ||
| 342 | (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED; | ||
| 343 | |||
| 344 | /* | ||
| 345 | * Copy the new maximum trace into the separate maximum-trace | ||
| 346 | * structure. (this way the maximum trace is permanently saved, | ||
| 347 | * for later retrieval via /sys/kernel/debug/tracing/latency_trace) | ||
| 348 | */ | ||
| 349 | static void | ||
| 350 | __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) | ||
| 351 | { | ||
| 352 | struct trace_array_cpu *data = tr->data[cpu]; | ||
| 353 | |||
| 354 | max_tr.cpu = cpu; | ||
| 355 | max_tr.time_start = data->preempt_timestamp; | ||
| 356 | 339 | ||
| 357 | data = max_tr.data[cpu]; | 340 | int trace_clock_id; |
| 358 | data->saved_latency = tracing_max_latency; | ||
| 359 | |||
| 360 | memcpy(data->comm, tsk->comm, TASK_COMM_LEN); | ||
| 361 | data->pid = tsk->pid; | ||
| 362 | data->uid = task_uid(tsk); | ||
| 363 | data->nice = tsk->static_prio - 20 - MAX_RT_PRIO; | ||
| 364 | data->policy = tsk->policy; | ||
| 365 | data->rt_priority = tsk->rt_priority; | ||
| 366 | |||
| 367 | /* record this tasks comm */ | ||
| 368 | tracing_record_cmdline(tsk); | ||
| 369 | } | ||
| 370 | 341 | ||
| 371 | ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt) | 342 | ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt) |
| 372 | { | 343 | { |
| @@ -411,6 +382,56 @@ static ssize_t trace_seq_to_buffer(struct trace_seq *s, void *buf, size_t cnt) | |||
| 411 | return cnt; | 382 | return cnt; |
| 412 | } | 383 | } |
| 413 | 384 | ||
| 385 | /* | ||
| 386 | * ftrace_max_lock is used to protect the swapping of buffers | ||
| 387 | * when taking a max snapshot. The buffers themselves are | ||
| 388 | * protected by per_cpu spinlocks. But the action of the swap | ||
| 389 | * needs its own lock. | ||
| 390 | * | ||
| 391 | * This is defined as a raw_spinlock_t in order to help | ||
| 392 | * with performance when lockdep debugging is enabled. | ||
| 393 | * | ||
| 394 | * It is also used in other places outside the update_max_tr | ||
| 395 | * so it needs to be defined outside of the | ||
| 396 | * CONFIG_TRACER_MAX_TRACE. | ||
| 397 | */ | ||
| 398 | static raw_spinlock_t ftrace_max_lock = | ||
| 399 | (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED; | ||
| 400 | |||
| 401 | #ifdef CONFIG_TRACER_MAX_TRACE | ||
| 402 | unsigned long __read_mostly tracing_max_latency; | ||
| 403 | unsigned long __read_mostly tracing_thresh; | ||
| 404 | |||
| 405 | /* | ||
| 406 | * Copy the new maximum trace into the separate maximum-trace | ||
| 407 | * structure. (this way the maximum trace is permanently saved, | ||
| 408 | * for later retrieval via /sys/kernel/debug/tracing/latency_trace) | ||
| 409 | */ | ||
| 410 | static void | ||
| 411 | __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) | ||
| 412 | { | ||
| 413 | struct trace_array_cpu *data = tr->data[cpu]; | ||
| 414 | struct trace_array_cpu *max_data = tr->data[cpu]; | ||
| 415 | |||
| 416 | max_tr.cpu = cpu; | ||
| 417 | max_tr.time_start = data->preempt_timestamp; | ||
| 418 | |||
| 419 | max_data = max_tr.data[cpu]; | ||
| 420 | max_data->saved_latency = tracing_max_latency; | ||
| 421 | max_data->critical_start = data->critical_start; | ||
| 422 | max_data->critical_end = data->critical_end; | ||
| 423 | |||
| 424 | memcpy(data->comm, tsk->comm, TASK_COMM_LEN); | ||
| 425 | max_data->pid = tsk->pid; | ||
| 426 | max_data->uid = task_uid(tsk); | ||
| 427 | max_data->nice = tsk->static_prio - 20 - MAX_RT_PRIO; | ||
| 428 | max_data->policy = tsk->policy; | ||
| 429 | max_data->rt_priority = tsk->rt_priority; | ||
| 430 | |||
| 431 | /* record this tasks comm */ | ||
| 432 | tracing_record_cmdline(tsk); | ||
| 433 | } | ||
| 434 | |||
| 414 | /** | 435 | /** |
| 415 | * update_max_tr - snapshot all trace buffers from global_trace to max_tr | 436 | * update_max_tr - snapshot all trace buffers from global_trace to max_tr |
| 416 | * @tr: tracer | 437 | * @tr: tracer |
| @@ -425,16 +446,15 @@ update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) | |||
| 425 | { | 446 | { |
| 426 | struct ring_buffer *buf = tr->buffer; | 447 | struct ring_buffer *buf = tr->buffer; |
| 427 | 448 | ||
| 449 | if (trace_stop_count) | ||
| 450 | return; | ||
| 451 | |||
| 428 | WARN_ON_ONCE(!irqs_disabled()); | 452 | WARN_ON_ONCE(!irqs_disabled()); |
| 429 | __raw_spin_lock(&ftrace_max_lock); | 453 | __raw_spin_lock(&ftrace_max_lock); |
| 430 | 454 | ||
| 431 | tr->buffer = max_tr.buffer; | 455 | tr->buffer = max_tr.buffer; |
| 432 | max_tr.buffer = buf; | 456 | max_tr.buffer = buf; |
| 433 | 457 | ||
| 434 | ftrace_disable_cpu(); | ||
| 435 | ring_buffer_reset(tr->buffer); | ||
| 436 | ftrace_enable_cpu(); | ||
| 437 | |||
| 438 | __update_max_tr(tr, tsk, cpu); | 458 | __update_max_tr(tr, tsk, cpu); |
| 439 | __raw_spin_unlock(&ftrace_max_lock); | 459 | __raw_spin_unlock(&ftrace_max_lock); |
| 440 | } | 460 | } |
| @@ -452,21 +472,35 @@ update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu) | |||
| 452 | { | 472 | { |
| 453 | int ret; | 473 | int ret; |
| 454 | 474 | ||
| 475 | if (trace_stop_count) | ||
| 476 | return; | ||
| 477 | |||
| 455 | WARN_ON_ONCE(!irqs_disabled()); | 478 | WARN_ON_ONCE(!irqs_disabled()); |
| 456 | __raw_spin_lock(&ftrace_max_lock); | 479 | __raw_spin_lock(&ftrace_max_lock); |
| 457 | 480 | ||
| 458 | ftrace_disable_cpu(); | 481 | ftrace_disable_cpu(); |
| 459 | 482 | ||
| 460 | ring_buffer_reset(max_tr.buffer); | ||
| 461 | ret = ring_buffer_swap_cpu(max_tr.buffer, tr->buffer, cpu); | 483 | ret = ring_buffer_swap_cpu(max_tr.buffer, tr->buffer, cpu); |
| 462 | 484 | ||
| 485 | if (ret == -EBUSY) { | ||
| 486 | /* | ||
| 487 | * We failed to swap the buffer due to a commit taking | ||
| 488 | * place on this CPU. We fail to record, but we reset | ||
| 489 | * the max trace buffer (no one writes directly to it) | ||
| 490 | * and flag that it failed. | ||
| 491 | */ | ||
| 492 | trace_array_printk(&max_tr, _THIS_IP_, | ||
| 493 | "Failed to swap buffers due to commit in progress\n"); | ||
| 494 | } | ||
| 495 | |||
| 463 | ftrace_enable_cpu(); | 496 | ftrace_enable_cpu(); |
| 464 | 497 | ||
| 465 | WARN_ON_ONCE(ret && ret != -EAGAIN); | 498 | WARN_ON_ONCE(ret && ret != -EAGAIN && ret != -EBUSY); |
| 466 | 499 | ||
| 467 | __update_max_tr(tr, tsk, cpu); | 500 | __update_max_tr(tr, tsk, cpu); |
| 468 | __raw_spin_unlock(&ftrace_max_lock); | 501 | __raw_spin_unlock(&ftrace_max_lock); |
| 469 | } | 502 | } |
| 503 | #endif /* CONFIG_TRACER_MAX_TRACE */ | ||
| 470 | 504 | ||
| 471 | /** | 505 | /** |
| 472 | * register_tracer - register a tracer with the ftrace system. | 506 | * register_tracer - register a tracer with the ftrace system. |
| @@ -523,7 +557,6 @@ __acquires(kernel_lock) | |||
| 523 | if (type->selftest && !tracing_selftest_disabled) { | 557 | if (type->selftest && !tracing_selftest_disabled) { |
| 524 | struct tracer *saved_tracer = current_trace; | 558 | struct tracer *saved_tracer = current_trace; |
| 525 | struct trace_array *tr = &global_trace; | 559 | struct trace_array *tr = &global_trace; |
| 526 | int i; | ||
| 527 | 560 | ||
| 528 | /* | 561 | /* |
| 529 | * Run a selftest on this tracer. | 562 | * Run a selftest on this tracer. |
| @@ -532,8 +565,7 @@ __acquires(kernel_lock) | |||
| 532 | * internal tracing to verify that everything is in order. | 565 | * internal tracing to verify that everything is in order. |
| 533 | * If we fail, we do not register this tracer. | 566 | * If we fail, we do not register this tracer. |
| 534 | */ | 567 | */ |
| 535 | for_each_tracing_cpu(i) | 568 | tracing_reset_online_cpus(tr); |
| 536 | tracing_reset(tr, i); | ||
| 537 | 569 | ||
| 538 | current_trace = type; | 570 | current_trace = type; |
| 539 | /* the test is responsible for initializing and enabling */ | 571 | /* the test is responsible for initializing and enabling */ |
| @@ -546,8 +578,7 @@ __acquires(kernel_lock) | |||
| 546 | goto out; | 578 | goto out; |
| 547 | } | 579 | } |
| 548 | /* Only reset on passing, to avoid touching corrupted buffers */ | 580 | /* Only reset on passing, to avoid touching corrupted buffers */ |
| 549 | for_each_tracing_cpu(i) | 581 | tracing_reset_online_cpus(tr); |
| 550 | tracing_reset(tr, i); | ||
| 551 | 582 | ||
| 552 | printk(KERN_CONT "PASSED\n"); | 583 | printk(KERN_CONT "PASSED\n"); |
| 553 | } | 584 | } |
| @@ -622,21 +653,42 @@ void unregister_tracer(struct tracer *type) | |||
| 622 | mutex_unlock(&trace_types_lock); | 653 | mutex_unlock(&trace_types_lock); |
| 623 | } | 654 | } |
| 624 | 655 | ||
| 625 | void tracing_reset(struct trace_array *tr, int cpu) | 656 | static void __tracing_reset(struct trace_array *tr, int cpu) |
| 626 | { | 657 | { |
| 627 | ftrace_disable_cpu(); | 658 | ftrace_disable_cpu(); |
| 628 | ring_buffer_reset_cpu(tr->buffer, cpu); | 659 | ring_buffer_reset_cpu(tr->buffer, cpu); |
| 629 | ftrace_enable_cpu(); | 660 | ftrace_enable_cpu(); |
| 630 | } | 661 | } |
| 631 | 662 | ||
| 663 | void tracing_reset(struct trace_array *tr, int cpu) | ||
| 664 | { | ||
| 665 | struct ring_buffer *buffer = tr->buffer; | ||
| 666 | |||
| 667 | ring_buffer_record_disable(buffer); | ||
| 668 | |||
| 669 | /* Make sure all commits have finished */ | ||
| 670 | synchronize_sched(); | ||
| 671 | __tracing_reset(tr, cpu); | ||
| 672 | |||
| 673 | ring_buffer_record_enable(buffer); | ||
| 674 | } | ||
| 675 | |||
| 632 | void tracing_reset_online_cpus(struct trace_array *tr) | 676 | void tracing_reset_online_cpus(struct trace_array *tr) |
| 633 | { | 677 | { |
| 678 | struct ring_buffer *buffer = tr->buffer; | ||
| 634 | int cpu; | 679 | int cpu; |
| 635 | 680 | ||
| 681 | ring_buffer_record_disable(buffer); | ||
| 682 | |||
| 683 | /* Make sure all commits have finished */ | ||
| 684 | synchronize_sched(); | ||
| 685 | |||
| 636 | tr->time_start = ftrace_now(tr->cpu); | 686 | tr->time_start = ftrace_now(tr->cpu); |
| 637 | 687 | ||
| 638 | for_each_online_cpu(cpu) | 688 | for_each_online_cpu(cpu) |
| 639 | tracing_reset(tr, cpu); | 689 | __tracing_reset(tr, cpu); |
| 690 | |||
| 691 | ring_buffer_record_enable(buffer); | ||
| 640 | } | 692 | } |
| 641 | 693 | ||
| 642 | void tracing_reset_current(int cpu) | 694 | void tracing_reset_current(int cpu) |
| @@ -667,9 +719,6 @@ static void trace_init_cmdlines(void) | |||
| 667 | cmdline_idx = 0; | 719 | cmdline_idx = 0; |
| 668 | } | 720 | } |
| 669 | 721 | ||
| 670 | static int trace_stop_count; | ||
| 671 | static DEFINE_SPINLOCK(tracing_start_lock); | ||
| 672 | |||
| 673 | /** | 722 | /** |
| 674 | * ftrace_off_permanent - disable all ftrace code permanently | 723 | * ftrace_off_permanent - disable all ftrace code permanently |
| 675 | * | 724 | * |
| @@ -850,14 +899,15 @@ tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags, | |||
| 850 | } | 899 | } |
| 851 | EXPORT_SYMBOL_GPL(tracing_generic_entry_update); | 900 | EXPORT_SYMBOL_GPL(tracing_generic_entry_update); |
| 852 | 901 | ||
| 853 | struct ring_buffer_event *trace_buffer_lock_reserve(struct trace_array *tr, | 902 | struct ring_buffer_event * |
| 854 | int type, | 903 | trace_buffer_lock_reserve(struct ring_buffer *buffer, |
| 855 | unsigned long len, | 904 | int type, |
| 856 | unsigned long flags, int pc) | 905 | unsigned long len, |
| 906 | unsigned long flags, int pc) | ||
| 857 | { | 907 | { |
| 858 | struct ring_buffer_event *event; | 908 | struct ring_buffer_event *event; |
| 859 | 909 | ||
| 860 | event = ring_buffer_lock_reserve(tr->buffer, len); | 910 | event = ring_buffer_lock_reserve(buffer, len); |
| 861 | if (event != NULL) { | 911 | if (event != NULL) { |
| 862 | struct trace_entry *ent = ring_buffer_event_data(event); | 912 | struct trace_entry *ent = ring_buffer_event_data(event); |
| 863 | 913 | ||
| @@ -867,58 +917,60 @@ struct ring_buffer_event *trace_buffer_lock_reserve(struct trace_array *tr, | |||
| 867 | 917 | ||
| 868 | return event; | 918 | return event; |
| 869 | } | 919 | } |
| 870 | static void ftrace_trace_stack(struct trace_array *tr, | ||
| 871 | unsigned long flags, int skip, int pc); | ||
| 872 | static void ftrace_trace_userstack(struct trace_array *tr, | ||
| 873 | unsigned long flags, int pc); | ||
| 874 | 920 | ||
| 875 | static inline void __trace_buffer_unlock_commit(struct trace_array *tr, | 921 | static inline void |
| 876 | struct ring_buffer_event *event, | 922 | __trace_buffer_unlock_commit(struct ring_buffer *buffer, |
| 877 | unsigned long flags, int pc, | 923 | struct ring_buffer_event *event, |
| 878 | int wake) | 924 | unsigned long flags, int pc, |
| 925 | int wake) | ||
| 879 | { | 926 | { |
| 880 | ring_buffer_unlock_commit(tr->buffer, event); | 927 | ring_buffer_unlock_commit(buffer, event); |
| 881 | 928 | ||
| 882 | ftrace_trace_stack(tr, flags, 6, pc); | 929 | ftrace_trace_stack(buffer, flags, 6, pc); |
| 883 | ftrace_trace_userstack(tr, flags, pc); | 930 | ftrace_trace_userstack(buffer, flags, pc); |
| 884 | 931 | ||
| 885 | if (wake) | 932 | if (wake) |
| 886 | trace_wake_up(); | 933 | trace_wake_up(); |
| 887 | } | 934 | } |
| 888 | 935 | ||
| 889 | void trace_buffer_unlock_commit(struct trace_array *tr, | 936 | void trace_buffer_unlock_commit(struct ring_buffer *buffer, |
| 890 | struct ring_buffer_event *event, | 937 | struct ring_buffer_event *event, |
| 891 | unsigned long flags, int pc) | 938 | unsigned long flags, int pc) |
| 892 | { | 939 | { |
| 893 | __trace_buffer_unlock_commit(tr, event, flags, pc, 1); | 940 | __trace_buffer_unlock_commit(buffer, event, flags, pc, 1); |
| 894 | } | 941 | } |
| 895 | 942 | ||
| 896 | struct ring_buffer_event * | 943 | struct ring_buffer_event * |
| 897 | trace_current_buffer_lock_reserve(int type, unsigned long len, | 944 | trace_current_buffer_lock_reserve(struct ring_buffer **current_rb, |
| 945 | int type, unsigned long len, | ||
| 898 | unsigned long flags, int pc) | 946 | unsigned long flags, int pc) |
| 899 | { | 947 | { |
| 900 | return trace_buffer_lock_reserve(&global_trace, | 948 | *current_rb = global_trace.buffer; |
| 949 | return trace_buffer_lock_reserve(*current_rb, | ||
| 901 | type, len, flags, pc); | 950 | type, len, flags, pc); |
| 902 | } | 951 | } |
| 903 | EXPORT_SYMBOL_GPL(trace_current_buffer_lock_reserve); | 952 | EXPORT_SYMBOL_GPL(trace_current_buffer_lock_reserve); |
| 904 | 953 | ||
| 905 | void trace_current_buffer_unlock_commit(struct ring_buffer_event *event, | 954 | void trace_current_buffer_unlock_commit(struct ring_buffer *buffer, |
| 955 | struct ring_buffer_event *event, | ||
| 906 | unsigned long flags, int pc) | 956 | unsigned long flags, int pc) |
| 907 | { | 957 | { |
| 908 | __trace_buffer_unlock_commit(&global_trace, event, flags, pc, 1); | 958 | __trace_buffer_unlock_commit(buffer, event, flags, pc, 1); |
| 909 | } | 959 | } |
| 910 | EXPORT_SYMBOL_GPL(trace_current_buffer_unlock_commit); | 960 | EXPORT_SYMBOL_GPL(trace_current_buffer_unlock_commit); |
| 911 | 961 | ||
| 912 | void trace_nowake_buffer_unlock_commit(struct ring_buffer_event *event, | 962 | void trace_nowake_buffer_unlock_commit(struct ring_buffer *buffer, |
| 913 | unsigned long flags, int pc) | 963 | struct ring_buffer_event *event, |
| 964 | unsigned long flags, int pc) | ||
| 914 | { | 965 | { |
| 915 | __trace_buffer_unlock_commit(&global_trace, event, flags, pc, 0); | 966 | __trace_buffer_unlock_commit(buffer, event, flags, pc, 0); |
| 916 | } | 967 | } |
| 917 | EXPORT_SYMBOL_GPL(trace_nowake_buffer_unlock_commit); | 968 | EXPORT_SYMBOL_GPL(trace_nowake_buffer_unlock_commit); |
| 918 | 969 | ||
| 919 | void trace_current_buffer_discard_commit(struct ring_buffer_event *event) | 970 | void trace_current_buffer_discard_commit(struct ring_buffer *buffer, |
| 971 | struct ring_buffer_event *event) | ||
| 920 | { | 972 | { |
| 921 | ring_buffer_discard_commit(global_trace.buffer, event); | 973 | ring_buffer_discard_commit(buffer, event); |
| 922 | } | 974 | } |
| 923 | EXPORT_SYMBOL_GPL(trace_current_buffer_discard_commit); | 975 | EXPORT_SYMBOL_GPL(trace_current_buffer_discard_commit); |
| 924 | 976 | ||
| @@ -928,6 +980,7 @@ trace_function(struct trace_array *tr, | |||
| 928 | int pc) | 980 | int pc) |
| 929 | { | 981 | { |
| 930 | struct ftrace_event_call *call = &event_function; | 982 | struct ftrace_event_call *call = &event_function; |
| 983 | struct ring_buffer *buffer = tr->buffer; | ||
| 931 | struct ring_buffer_event *event; | 984 | struct ring_buffer_event *event; |
| 932 | struct ftrace_entry *entry; | 985 | struct ftrace_entry *entry; |
| 933 | 986 | ||
| @@ -935,7 +988,7 @@ trace_function(struct trace_array *tr, | |||
| 935 | if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) | 988 | if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) |
| 936 | return; | 989 | return; |
| 937 | 990 | ||
| 938 | event = trace_buffer_lock_reserve(tr, TRACE_FN, sizeof(*entry), | 991 | event = trace_buffer_lock_reserve(buffer, TRACE_FN, sizeof(*entry), |
| 939 | flags, pc); | 992 | flags, pc); |
| 940 | if (!event) | 993 | if (!event) |
| 941 | return; | 994 | return; |
| @@ -943,58 +996,10 @@ trace_function(struct trace_array *tr, | |||
| 943 | entry->ip = ip; | 996 | entry->ip = ip; |
| 944 | entry->parent_ip = parent_ip; | 997 | entry->parent_ip = parent_ip; |
| 945 | 998 | ||
| 946 | if (!filter_check_discard(call, entry, tr->buffer, event)) | 999 | if (!filter_check_discard(call, entry, buffer, event)) |
| 947 | ring_buffer_unlock_commit(tr->buffer, event); | 1000 | ring_buffer_unlock_commit(buffer, event); |
| 948 | } | ||
| 949 | |||
| 950 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | ||
| 951 | static int __trace_graph_entry(struct trace_array *tr, | ||
| 952 | struct ftrace_graph_ent *trace, | ||
| 953 | unsigned long flags, | ||
| 954 | int pc) | ||
| 955 | { | ||
| 956 | struct ftrace_event_call *call = &event_funcgraph_entry; | ||
| 957 | struct ring_buffer_event *event; | ||
| 958 | struct ftrace_graph_ent_entry *entry; | ||
| 959 | |||
| 960 | if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) | ||
| 961 | return 0; | ||
| 962 | |||
| 963 | event = trace_buffer_lock_reserve(&global_trace, TRACE_GRAPH_ENT, | ||
| 964 | sizeof(*entry), flags, pc); | ||
| 965 | if (!event) | ||
| 966 | return 0; | ||
| 967 | entry = ring_buffer_event_data(event); | ||
| 968 | entry->graph_ent = *trace; | ||
| 969 | if (!filter_current_check_discard(call, entry, event)) | ||
| 970 | ring_buffer_unlock_commit(global_trace.buffer, event); | ||
| 971 | |||
| 972 | return 1; | ||
| 973 | } | 1001 | } |
| 974 | 1002 | ||
| 975 | static void __trace_graph_return(struct trace_array *tr, | ||
| 976 | struct ftrace_graph_ret *trace, | ||
| 977 | unsigned long flags, | ||
| 978 | int pc) | ||
| 979 | { | ||
| 980 | struct ftrace_event_call *call = &event_funcgraph_exit; | ||
| 981 | struct ring_buffer_event *event; | ||
| 982 | struct ftrace_graph_ret_entry *entry; | ||
| 983 | |||
| 984 | if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) | ||
| 985 | return; | ||
| 986 | |||
| 987 | event = trace_buffer_lock_reserve(&global_trace, TRACE_GRAPH_RET, | ||
| 988 | sizeof(*entry), flags, pc); | ||
| 989 | if (!event) | ||
| 990 | return; | ||
| 991 | entry = ring_buffer_event_data(event); | ||
| 992 | entry->ret = *trace; | ||
| 993 | if (!filter_current_check_discard(call, entry, event)) | ||
| 994 | ring_buffer_unlock_commit(global_trace.buffer, event); | ||
| 995 | } | ||
| 996 | #endif | ||
| 997 | |||
| 998 | void | 1003 | void |
| 999 | ftrace(struct trace_array *tr, struct trace_array_cpu *data, | 1004 | ftrace(struct trace_array *tr, struct trace_array_cpu *data, |
| 1000 | unsigned long ip, unsigned long parent_ip, unsigned long flags, | 1005 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
| @@ -1004,17 +1009,17 @@ ftrace(struct trace_array *tr, struct trace_array_cpu *data, | |||
| 1004 | trace_function(tr, ip, parent_ip, flags, pc); | 1009 | trace_function(tr, ip, parent_ip, flags, pc); |
| 1005 | } | 1010 | } |
| 1006 | 1011 | ||
| 1007 | static void __ftrace_trace_stack(struct trace_array *tr, | 1012 | #ifdef CONFIG_STACKTRACE |
| 1013 | static void __ftrace_trace_stack(struct ring_buffer *buffer, | ||
| 1008 | unsigned long flags, | 1014 | unsigned long flags, |
| 1009 | int skip, int pc) | 1015 | int skip, int pc) |
| 1010 | { | 1016 | { |
| 1011 | #ifdef CONFIG_STACKTRACE | ||
| 1012 | struct ftrace_event_call *call = &event_kernel_stack; | 1017 | struct ftrace_event_call *call = &event_kernel_stack; |
| 1013 | struct ring_buffer_event *event; | 1018 | struct ring_buffer_event *event; |
| 1014 | struct stack_entry *entry; | 1019 | struct stack_entry *entry; |
| 1015 | struct stack_trace trace; | 1020 | struct stack_trace trace; |
| 1016 | 1021 | ||
| 1017 | event = trace_buffer_lock_reserve(tr, TRACE_STACK, | 1022 | event = trace_buffer_lock_reserve(buffer, TRACE_STACK, |
| 1018 | sizeof(*entry), flags, pc); | 1023 | sizeof(*entry), flags, pc); |
| 1019 | if (!event) | 1024 | if (!event) |
| 1020 | return; | 1025 | return; |
| @@ -1027,32 +1032,28 @@ static void __ftrace_trace_stack(struct trace_array *tr, | |||
| 1027 | trace.entries = entry->caller; | 1032 | trace.entries = entry->caller; |
| 1028 | 1033 | ||
| 1029 | save_stack_trace(&trace); | 1034 | save_stack_trace(&trace); |
| 1030 | if (!filter_check_discard(call, entry, tr->buffer, event)) | 1035 | if (!filter_check_discard(call, entry, buffer, event)) |
| 1031 | ring_buffer_unlock_commit(tr->buffer, event); | 1036 | ring_buffer_unlock_commit(buffer, event); |
| 1032 | #endif | ||
| 1033 | } | 1037 | } |
| 1034 | 1038 | ||
| 1035 | static void ftrace_trace_stack(struct trace_array *tr, | 1039 | void ftrace_trace_stack(struct ring_buffer *buffer, unsigned long flags, |
| 1036 | unsigned long flags, | 1040 | int skip, int pc) |
| 1037 | int skip, int pc) | ||
| 1038 | { | 1041 | { |
| 1039 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) | 1042 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) |
| 1040 | return; | 1043 | return; |
| 1041 | 1044 | ||
| 1042 | __ftrace_trace_stack(tr, flags, skip, pc); | 1045 | __ftrace_trace_stack(buffer, flags, skip, pc); |
| 1043 | } | 1046 | } |
| 1044 | 1047 | ||
| 1045 | void __trace_stack(struct trace_array *tr, | 1048 | void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, |
| 1046 | unsigned long flags, | 1049 | int pc) |
| 1047 | int skip, int pc) | ||
| 1048 | { | 1050 | { |
| 1049 | __ftrace_trace_stack(tr, flags, skip, pc); | 1051 | __ftrace_trace_stack(tr->buffer, flags, skip, pc); |
| 1050 | } | 1052 | } |
| 1051 | 1053 | ||
| 1052 | static void ftrace_trace_userstack(struct trace_array *tr, | 1054 | void |
| 1053 | unsigned long flags, int pc) | 1055 | ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, int pc) |
| 1054 | { | 1056 | { |
| 1055 | #ifdef CONFIG_STACKTRACE | ||
| 1056 | struct ftrace_event_call *call = &event_user_stack; | 1057 | struct ftrace_event_call *call = &event_user_stack; |
| 1057 | struct ring_buffer_event *event; | 1058 | struct ring_buffer_event *event; |
| 1058 | struct userstack_entry *entry; | 1059 | struct userstack_entry *entry; |
| @@ -1061,7 +1062,7 @@ static void ftrace_trace_userstack(struct trace_array *tr, | |||
| 1061 | if (!(trace_flags & TRACE_ITER_USERSTACKTRACE)) | 1062 | if (!(trace_flags & TRACE_ITER_USERSTACKTRACE)) |
| 1062 | return; | 1063 | return; |
| 1063 | 1064 | ||
| 1064 | event = trace_buffer_lock_reserve(tr, TRACE_USER_STACK, | 1065 | event = trace_buffer_lock_reserve(buffer, TRACE_USER_STACK, |
| 1065 | sizeof(*entry), flags, pc); | 1066 | sizeof(*entry), flags, pc); |
| 1066 | if (!event) | 1067 | if (!event) |
| 1067 | return; | 1068 | return; |
| @@ -1075,9 +1076,8 @@ static void ftrace_trace_userstack(struct trace_array *tr, | |||
| 1075 | trace.entries = entry->caller; | 1076 | trace.entries = entry->caller; |
| 1076 | 1077 | ||
| 1077 | save_stack_trace_user(&trace); | 1078 | save_stack_trace_user(&trace); |
| 1078 | if (!filter_check_discard(call, entry, tr->buffer, event)) | 1079 | if (!filter_check_discard(call, entry, buffer, event)) |
| 1079 | ring_buffer_unlock_commit(tr->buffer, event); | 1080 | ring_buffer_unlock_commit(buffer, event); |
| 1080 | #endif | ||
| 1081 | } | 1081 | } |
| 1082 | 1082 | ||
| 1083 | #ifdef UNUSED | 1083 | #ifdef UNUSED |
| @@ -1087,6 +1087,8 @@ static void __trace_userstack(struct trace_array *tr, unsigned long flags) | |||
| 1087 | } | 1087 | } |
| 1088 | #endif /* UNUSED */ | 1088 | #endif /* UNUSED */ |
| 1089 | 1089 | ||
| 1090 | #endif /* CONFIG_STACKTRACE */ | ||
| 1091 | |||
| 1090 | static void | 1092 | static void |
| 1091 | ftrace_trace_special(void *__tr, | 1093 | ftrace_trace_special(void *__tr, |
| 1092 | unsigned long arg1, unsigned long arg2, unsigned long arg3, | 1094 | unsigned long arg1, unsigned long arg2, unsigned long arg3, |
| @@ -1094,9 +1096,10 @@ ftrace_trace_special(void *__tr, | |||
| 1094 | { | 1096 | { |
| 1095 | struct ring_buffer_event *event; | 1097 | struct ring_buffer_event *event; |
| 1096 | struct trace_array *tr = __tr; | 1098 | struct trace_array *tr = __tr; |
| 1099 | struct ring_buffer *buffer = tr->buffer; | ||
| 1097 | struct special_entry *entry; | 1100 | struct special_entry *entry; |
| 1098 | 1101 | ||
| 1099 | event = trace_buffer_lock_reserve(tr, TRACE_SPECIAL, | 1102 | event = trace_buffer_lock_reserve(buffer, TRACE_SPECIAL, |
| 1100 | sizeof(*entry), 0, pc); | 1103 | sizeof(*entry), 0, pc); |
| 1101 | if (!event) | 1104 | if (!event) |
| 1102 | return; | 1105 | return; |
| @@ -1104,7 +1107,7 @@ ftrace_trace_special(void *__tr, | |||
| 1104 | entry->arg1 = arg1; | 1107 | entry->arg1 = arg1; |
| 1105 | entry->arg2 = arg2; | 1108 | entry->arg2 = arg2; |
| 1106 | entry->arg3 = arg3; | 1109 | entry->arg3 = arg3; |
| 1107 | trace_buffer_unlock_commit(tr, event, 0, pc); | 1110 | trace_buffer_unlock_commit(buffer, event, 0, pc); |
| 1108 | } | 1111 | } |
| 1109 | 1112 | ||
| 1110 | void | 1113 | void |
| @@ -1115,62 +1118,6 @@ __trace_special(void *__tr, void *__data, | |||
| 1115 | } | 1118 | } |
| 1116 | 1119 | ||
| 1117 | void | 1120 | void |
| 1118 | tracing_sched_switch_trace(struct trace_array *tr, | ||
| 1119 | struct task_struct *prev, | ||
| 1120 | struct task_struct *next, | ||
| 1121 | unsigned long flags, int pc) | ||
| 1122 | { | ||
| 1123 | struct ftrace_event_call *call = &event_context_switch; | ||
| 1124 | struct ring_buffer_event *event; | ||
| 1125 | struct ctx_switch_entry *entry; | ||
| 1126 | |||
| 1127 | event = trace_buffer_lock_reserve(tr, TRACE_CTX, | ||
| 1128 | sizeof(*entry), flags, pc); | ||
| 1129 | if (!event) | ||
| 1130 | return; | ||
| 1131 | entry = ring_buffer_event_data(event); | ||
| 1132 | entry->prev_pid = prev->pid; | ||
| 1133 | entry->prev_prio = prev->prio; | ||
| 1134 | entry->prev_state = prev->state; | ||
| 1135 | entry->next_pid = next->pid; | ||
| 1136 | entry->next_prio = next->prio; | ||
| 1137 | entry->next_state = next->state; | ||
| 1138 | entry->next_cpu = task_cpu(next); | ||
| 1139 | |||
| 1140 | if (!filter_check_discard(call, entry, tr->buffer, event)) | ||
| 1141 | trace_buffer_unlock_commit(tr, event, flags, pc); | ||
| 1142 | } | ||
| 1143 | |||
| 1144 | void | ||
| 1145 | tracing_sched_wakeup_trace(struct trace_array *tr, | ||
| 1146 | struct task_struct *wakee, | ||
| 1147 | struct task_struct *curr, | ||
| 1148 | unsigned long flags, int pc) | ||
| 1149 | { | ||
| 1150 | struct ftrace_event_call *call = &event_wakeup; | ||
| 1151 | struct ring_buffer_event *event; | ||
| 1152 | struct ctx_switch_entry *entry; | ||
| 1153 | |||
| 1154 | event = trace_buffer_lock_reserve(tr, TRACE_WAKE, | ||
| 1155 | sizeof(*entry), flags, pc); | ||
| 1156 | if (!event) | ||
| 1157 | return; | ||
| 1158 | entry = ring_buffer_event_data(event); | ||
| 1159 | entry->prev_pid = curr->pid; | ||
| 1160 | entry->prev_prio = curr->prio; | ||
| 1161 | entry->prev_state = curr->state; | ||
| 1162 | entry->next_pid = wakee->pid; | ||
| 1163 | entry->next_prio = wakee->prio; | ||
| 1164 | entry->next_state = wakee->state; | ||
| 1165 | entry->next_cpu = task_cpu(wakee); | ||
| 1166 | |||
| 1167 | if (!filter_check_discard(call, entry, tr->buffer, event)) | ||
| 1168 | ring_buffer_unlock_commit(tr->buffer, event); | ||
| 1169 | ftrace_trace_stack(tr, flags, 6, pc); | ||
| 1170 | ftrace_trace_userstack(tr, flags, pc); | ||
| 1171 | } | ||
| 1172 | |||
| 1173 | void | ||
| 1174 | ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) | 1121 | ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) |
| 1175 | { | 1122 | { |
| 1176 | struct trace_array *tr = &global_trace; | 1123 | struct trace_array *tr = &global_trace; |
| @@ -1194,68 +1141,6 @@ ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) | |||
| 1194 | local_irq_restore(flags); | 1141 | local_irq_restore(flags); |
| 1195 | } | 1142 | } |
| 1196 | 1143 | ||
| 1197 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | ||
| 1198 | int trace_graph_entry(struct ftrace_graph_ent *trace) | ||
| 1199 | { | ||
| 1200 | struct trace_array *tr = &global_trace; | ||
| 1201 | struct trace_array_cpu *data; | ||
| 1202 | unsigned long flags; | ||
| 1203 | long disabled; | ||
| 1204 | int ret; | ||
| 1205 | int cpu; | ||
| 1206 | int pc; | ||
| 1207 | |||
| 1208 | if (!ftrace_trace_task(current)) | ||
| 1209 | return 0; | ||
| 1210 | |||
| 1211 | if (!ftrace_graph_addr(trace->func)) | ||
| 1212 | return 0; | ||
| 1213 | |||
| 1214 | local_irq_save(flags); | ||
| 1215 | cpu = raw_smp_processor_id(); | ||
| 1216 | data = tr->data[cpu]; | ||
| 1217 | disabled = atomic_inc_return(&data->disabled); | ||
| 1218 | if (likely(disabled == 1)) { | ||
| 1219 | pc = preempt_count(); | ||
| 1220 | ret = __trace_graph_entry(tr, trace, flags, pc); | ||
| 1221 | } else { | ||
| 1222 | ret = 0; | ||
| 1223 | } | ||
| 1224 | /* Only do the atomic if it is not already set */ | ||
| 1225 | if (!test_tsk_trace_graph(current)) | ||
| 1226 | set_tsk_trace_graph(current); | ||
| 1227 | |||
| 1228 | atomic_dec(&data->disabled); | ||
| 1229 | local_irq_restore(flags); | ||
| 1230 | |||
| 1231 | return ret; | ||
| 1232 | } | ||
| 1233 | |||
| 1234 | void trace_graph_return(struct ftrace_graph_ret *trace) | ||
| 1235 | { | ||
| 1236 | struct trace_array *tr = &global_trace; | ||
| 1237 | struct trace_array_cpu *data; | ||
| 1238 | unsigned long flags; | ||
| 1239 | long disabled; | ||
| 1240 | int cpu; | ||
| 1241 | int pc; | ||
| 1242 | |||
| 1243 | local_irq_save(flags); | ||
| 1244 | cpu = raw_smp_processor_id(); | ||
| 1245 | data = tr->data[cpu]; | ||
| 1246 | disabled = atomic_inc_return(&data->disabled); | ||
| 1247 | if (likely(disabled == 1)) { | ||
| 1248 | pc = preempt_count(); | ||
| 1249 | __trace_graph_return(tr, trace, flags, pc); | ||
| 1250 | } | ||
| 1251 | if (!trace->depth) | ||
| 1252 | clear_tsk_trace_graph(current); | ||
| 1253 | atomic_dec(&data->disabled); | ||
| 1254 | local_irq_restore(flags); | ||
| 1255 | } | ||
| 1256 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ | ||
| 1257 | |||
| 1258 | |||
| 1259 | /** | 1144 | /** |
| 1260 | * trace_vbprintk - write binary msg to tracing buffer | 1145 | * trace_vbprintk - write binary msg to tracing buffer |
| 1261 | * | 1146 | * |
| @@ -1268,6 +1153,7 @@ int trace_vbprintk(unsigned long ip, const char *fmt, va_list args) | |||
| 1268 | 1153 | ||
| 1269 | struct ftrace_event_call *call = &event_bprint; | 1154 | struct ftrace_event_call *call = &event_bprint; |
| 1270 | struct ring_buffer_event *event; | 1155 | struct ring_buffer_event *event; |
| 1156 | struct ring_buffer *buffer; | ||
| 1271 | struct trace_array *tr = &global_trace; | 1157 | struct trace_array *tr = &global_trace; |
| 1272 | struct trace_array_cpu *data; | 1158 | struct trace_array_cpu *data; |
| 1273 | struct bprint_entry *entry; | 1159 | struct bprint_entry *entry; |
| @@ -1300,7 +1186,9 @@ int trace_vbprintk(unsigned long ip, const char *fmt, va_list args) | |||
| 1300 | goto out_unlock; | 1186 | goto out_unlock; |
| 1301 | 1187 | ||
| 1302 | size = sizeof(*entry) + sizeof(u32) * len; | 1188 | size = sizeof(*entry) + sizeof(u32) * len; |
| 1303 | event = trace_buffer_lock_reserve(tr, TRACE_BPRINT, size, flags, pc); | 1189 | buffer = tr->buffer; |
| 1190 | event = trace_buffer_lock_reserve(buffer, TRACE_BPRINT, size, | ||
| 1191 | flags, pc); | ||
| 1304 | if (!event) | 1192 | if (!event) |
| 1305 | goto out_unlock; | 1193 | goto out_unlock; |
| 1306 | entry = ring_buffer_event_data(event); | 1194 | entry = ring_buffer_event_data(event); |
| @@ -1308,8 +1196,8 @@ int trace_vbprintk(unsigned long ip, const char *fmt, va_list args) | |||
| 1308 | entry->fmt = fmt; | 1196 | entry->fmt = fmt; |
| 1309 | 1197 | ||
| 1310 | memcpy(entry->buf, trace_buf, sizeof(u32) * len); | 1198 | memcpy(entry->buf, trace_buf, sizeof(u32) * len); |
| 1311 | if (!filter_check_discard(call, entry, tr->buffer, event)) | 1199 | if (!filter_check_discard(call, entry, buffer, event)) |
| 1312 | ring_buffer_unlock_commit(tr->buffer, event); | 1200 | ring_buffer_unlock_commit(buffer, event); |
| 1313 | 1201 | ||
| 1314 | out_unlock: | 1202 | out_unlock: |
| 1315 | __raw_spin_unlock(&trace_buf_lock); | 1203 | __raw_spin_unlock(&trace_buf_lock); |
| @@ -1324,14 +1212,30 @@ out: | |||
| 1324 | } | 1212 | } |
| 1325 | EXPORT_SYMBOL_GPL(trace_vbprintk); | 1213 | EXPORT_SYMBOL_GPL(trace_vbprintk); |
| 1326 | 1214 | ||
| 1327 | int trace_vprintk(unsigned long ip, const char *fmt, va_list args) | 1215 | int trace_array_printk(struct trace_array *tr, |
| 1216 | unsigned long ip, const char *fmt, ...) | ||
| 1217 | { | ||
| 1218 | int ret; | ||
| 1219 | va_list ap; | ||
| 1220 | |||
| 1221 | if (!(trace_flags & TRACE_ITER_PRINTK)) | ||
| 1222 | return 0; | ||
| 1223 | |||
| 1224 | va_start(ap, fmt); | ||
| 1225 | ret = trace_array_vprintk(tr, ip, fmt, ap); | ||
| 1226 | va_end(ap); | ||
| 1227 | return ret; | ||
| 1228 | } | ||
| 1229 | |||
| 1230 | int trace_array_vprintk(struct trace_array *tr, | ||
| 1231 | unsigned long ip, const char *fmt, va_list args) | ||
| 1328 | { | 1232 | { |
| 1329 | static raw_spinlock_t trace_buf_lock = __RAW_SPIN_LOCK_UNLOCKED; | 1233 | static raw_spinlock_t trace_buf_lock = __RAW_SPIN_LOCK_UNLOCKED; |
| 1330 | static char trace_buf[TRACE_BUF_SIZE]; | 1234 | static char trace_buf[TRACE_BUF_SIZE]; |
| 1331 | 1235 | ||
| 1332 | struct ftrace_event_call *call = &event_print; | 1236 | struct ftrace_event_call *call = &event_print; |
| 1333 | struct ring_buffer_event *event; | 1237 | struct ring_buffer_event *event; |
| 1334 | struct trace_array *tr = &global_trace; | 1238 | struct ring_buffer *buffer; |
| 1335 | struct trace_array_cpu *data; | 1239 | struct trace_array_cpu *data; |
| 1336 | int cpu, len = 0, size, pc; | 1240 | int cpu, len = 0, size, pc; |
| 1337 | struct print_entry *entry; | 1241 | struct print_entry *entry; |
| @@ -1359,7 +1263,9 @@ int trace_vprintk(unsigned long ip, const char *fmt, va_list args) | |||
| 1359 | trace_buf[len] = 0; | 1263 | trace_buf[len] = 0; |
| 1360 | 1264 | ||
| 1361 | size = sizeof(*entry) + len + 1; | 1265 | size = sizeof(*entry) + len + 1; |
| 1362 | event = trace_buffer_lock_reserve(tr, TRACE_PRINT, size, irq_flags, pc); | 1266 | buffer = tr->buffer; |
| 1267 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, | ||
| 1268 | irq_flags, pc); | ||
| 1363 | if (!event) | 1269 | if (!event) |
| 1364 | goto out_unlock; | 1270 | goto out_unlock; |
| 1365 | entry = ring_buffer_event_data(event); | 1271 | entry = ring_buffer_event_data(event); |
| @@ -1367,8 +1273,8 @@ int trace_vprintk(unsigned long ip, const char *fmt, va_list args) | |||
| 1367 | 1273 | ||
| 1368 | memcpy(&entry->buf, trace_buf, len); | 1274 | memcpy(&entry->buf, trace_buf, len); |
| 1369 | entry->buf[len] = 0; | 1275 | entry->buf[len] = 0; |
| 1370 | if (!filter_check_discard(call, entry, tr->buffer, event)) | 1276 | if (!filter_check_discard(call, entry, buffer, event)) |
| 1371 | ring_buffer_unlock_commit(tr->buffer, event); | 1277 | ring_buffer_unlock_commit(buffer, event); |
| 1372 | 1278 | ||
| 1373 | out_unlock: | 1279 | out_unlock: |
| 1374 | __raw_spin_unlock(&trace_buf_lock); | 1280 | __raw_spin_unlock(&trace_buf_lock); |
| @@ -1380,6 +1286,11 @@ int trace_vprintk(unsigned long ip, const char *fmt, va_list args) | |||
| 1380 | 1286 | ||
| 1381 | return len; | 1287 | return len; |
| 1382 | } | 1288 | } |
| 1289 | |||
| 1290 | int trace_vprintk(unsigned long ip, const char *fmt, va_list args) | ||
| 1291 | { | ||
| 1292 | return trace_array_printk(&global_trace, ip, fmt, args); | ||
| 1293 | } | ||
| 1383 | EXPORT_SYMBOL_GPL(trace_vprintk); | 1294 | EXPORT_SYMBOL_GPL(trace_vprintk); |
| 1384 | 1295 | ||
| 1385 | enum trace_file_type { | 1296 | enum trace_file_type { |
| @@ -1519,6 +1430,37 @@ static void *s_next(struct seq_file *m, void *v, loff_t *pos) | |||
| 1519 | return ent; | 1430 | return ent; |
| 1520 | } | 1431 | } |
| 1521 | 1432 | ||
| 1433 | static void tracing_iter_reset(struct trace_iterator *iter, int cpu) | ||
| 1434 | { | ||
| 1435 | struct trace_array *tr = iter->tr; | ||
| 1436 | struct ring_buffer_event *event; | ||
| 1437 | struct ring_buffer_iter *buf_iter; | ||
| 1438 | unsigned long entries = 0; | ||
| 1439 | u64 ts; | ||
| 1440 | |||
| 1441 | tr->data[cpu]->skipped_entries = 0; | ||
| 1442 | |||
| 1443 | if (!iter->buffer_iter[cpu]) | ||
| 1444 | return; | ||
| 1445 | |||
| 1446 | buf_iter = iter->buffer_iter[cpu]; | ||
| 1447 | ring_buffer_iter_reset(buf_iter); | ||
| 1448 | |||
| 1449 | /* | ||
| 1450 | * We could have the case with the max latency tracers | ||
| 1451 | * that a reset never took place on a cpu. This is evident | ||
| 1452 | * by the timestamp being before the start of the buffer. | ||
| 1453 | */ | ||
| 1454 | while ((event = ring_buffer_iter_peek(buf_iter, &ts))) { | ||
| 1455 | if (ts >= iter->tr->time_start) | ||
| 1456 | break; | ||
| 1457 | entries++; | ||
| 1458 | ring_buffer_read(buf_iter, NULL); | ||
| 1459 | } | ||
| 1460 | |||
| 1461 | tr->data[cpu]->skipped_entries = entries; | ||
| 1462 | } | ||
| 1463 | |||
| 1522 | /* | 1464 | /* |
| 1523 | * No necessary locking here. The worst thing which can | 1465 | * No necessary locking here. The worst thing which can |
| 1524 | * happen is loosing events consumed at the same time | 1466 | * happen is loosing events consumed at the same time |
| @@ -1557,10 +1499,9 @@ static void *s_start(struct seq_file *m, loff_t *pos) | |||
| 1557 | 1499 | ||
| 1558 | if (cpu_file == TRACE_PIPE_ALL_CPU) { | 1500 | if (cpu_file == TRACE_PIPE_ALL_CPU) { |
| 1559 | for_each_tracing_cpu(cpu) | 1501 | for_each_tracing_cpu(cpu) |
| 1560 | ring_buffer_iter_reset(iter->buffer_iter[cpu]); | 1502 | tracing_iter_reset(iter, cpu); |
| 1561 | } else | 1503 | } else |
| 1562 | ring_buffer_iter_reset(iter->buffer_iter[cpu_file]); | 1504 | tracing_iter_reset(iter, cpu_file); |
| 1563 | |||
| 1564 | 1505 | ||
| 1565 | ftrace_enable_cpu(); | 1506 | ftrace_enable_cpu(); |
| 1566 | 1507 | ||
| @@ -1609,16 +1550,32 @@ print_trace_header(struct seq_file *m, struct trace_iterator *iter) | |||
| 1609 | struct trace_array *tr = iter->tr; | 1550 | struct trace_array *tr = iter->tr; |
| 1610 | struct trace_array_cpu *data = tr->data[tr->cpu]; | 1551 | struct trace_array_cpu *data = tr->data[tr->cpu]; |
| 1611 | struct tracer *type = current_trace; | 1552 | struct tracer *type = current_trace; |
| 1612 | unsigned long total; | 1553 | unsigned long entries = 0; |
| 1613 | unsigned long entries; | 1554 | unsigned long total = 0; |
| 1555 | unsigned long count; | ||
| 1614 | const char *name = "preemption"; | 1556 | const char *name = "preemption"; |
| 1557 | int cpu; | ||
| 1615 | 1558 | ||
| 1616 | if (type) | 1559 | if (type) |
| 1617 | name = type->name; | 1560 | name = type->name; |
| 1618 | 1561 | ||
| 1619 | entries = ring_buffer_entries(iter->tr->buffer); | 1562 | |
| 1620 | total = entries + | 1563 | for_each_tracing_cpu(cpu) { |
| 1621 | ring_buffer_overruns(iter->tr->buffer); | 1564 | count = ring_buffer_entries_cpu(tr->buffer, cpu); |
| 1565 | /* | ||
| 1566 | * If this buffer has skipped entries, then we hold all | ||
| 1567 | * entries for the trace and we need to ignore the | ||
| 1568 | * ones before the time stamp. | ||
| 1569 | */ | ||
| 1570 | if (tr->data[cpu]->skipped_entries) { | ||
| 1571 | count -= tr->data[cpu]->skipped_entries; | ||
| 1572 | /* total is the same as the entries */ | ||
| 1573 | total += count; | ||
| 1574 | } else | ||
| 1575 | total += count + | ||
| 1576 | ring_buffer_overrun_cpu(tr->buffer, cpu); | ||
| 1577 | entries += count; | ||
| 1578 | } | ||
| 1622 | 1579 | ||
| 1623 | seq_printf(m, "# %s latency trace v1.1.5 on %s\n", | 1580 | seq_printf(m, "# %s latency trace v1.1.5 on %s\n", |
| 1624 | name, UTS_RELEASE); | 1581 | name, UTS_RELEASE); |
| @@ -1660,7 +1617,7 @@ print_trace_header(struct seq_file *m, struct trace_iterator *iter) | |||
| 1660 | seq_puts(m, "\n# => ended at: "); | 1617 | seq_puts(m, "\n# => ended at: "); |
| 1661 | seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags); | 1618 | seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags); |
| 1662 | trace_print_seq(m, &iter->seq); | 1619 | trace_print_seq(m, &iter->seq); |
| 1663 | seq_puts(m, "#\n"); | 1620 | seq_puts(m, "\n#\n"); |
| 1664 | } | 1621 | } |
| 1665 | 1622 | ||
| 1666 | seq_puts(m, "#\n"); | 1623 | seq_puts(m, "#\n"); |
| @@ -1679,6 +1636,9 @@ static void test_cpu_buff_start(struct trace_iterator *iter) | |||
| 1679 | if (cpumask_test_cpu(iter->cpu, iter->started)) | 1636 | if (cpumask_test_cpu(iter->cpu, iter->started)) |
| 1680 | return; | 1637 | return; |
| 1681 | 1638 | ||
| 1639 | if (iter->tr->data[iter->cpu]->skipped_entries) | ||
| 1640 | return; | ||
| 1641 | |||
| 1682 | cpumask_set_cpu(iter->cpu, iter->started); | 1642 | cpumask_set_cpu(iter->cpu, iter->started); |
| 1683 | 1643 | ||
| 1684 | /* Don't print started cpu buffer for the first entry of the trace */ | 1644 | /* Don't print started cpu buffer for the first entry of the trace */ |
| @@ -1941,19 +1901,23 @@ __tracing_open(struct inode *inode, struct file *file) | |||
| 1941 | if (ring_buffer_overruns(iter->tr->buffer)) | 1901 | if (ring_buffer_overruns(iter->tr->buffer)) |
| 1942 | iter->iter_flags |= TRACE_FILE_ANNOTATE; | 1902 | iter->iter_flags |= TRACE_FILE_ANNOTATE; |
| 1943 | 1903 | ||
| 1904 | /* stop the trace while dumping */ | ||
| 1905 | tracing_stop(); | ||
| 1906 | |||
| 1944 | if (iter->cpu_file == TRACE_PIPE_ALL_CPU) { | 1907 | if (iter->cpu_file == TRACE_PIPE_ALL_CPU) { |
| 1945 | for_each_tracing_cpu(cpu) { | 1908 | for_each_tracing_cpu(cpu) { |
| 1946 | 1909 | ||
| 1947 | iter->buffer_iter[cpu] = | 1910 | iter->buffer_iter[cpu] = |
| 1948 | ring_buffer_read_start(iter->tr->buffer, cpu); | 1911 | ring_buffer_read_start(iter->tr->buffer, cpu); |
| 1912 | tracing_iter_reset(iter, cpu); | ||
| 1949 | } | 1913 | } |
| 1950 | } else { | 1914 | } else { |
| 1951 | cpu = iter->cpu_file; | 1915 | cpu = iter->cpu_file; |
| 1952 | iter->buffer_iter[cpu] = | 1916 | iter->buffer_iter[cpu] = |
| 1953 | ring_buffer_read_start(iter->tr->buffer, cpu); | 1917 | ring_buffer_read_start(iter->tr->buffer, cpu); |
| 1918 | tracing_iter_reset(iter, cpu); | ||
| 1954 | } | 1919 | } |
| 1955 | 1920 | ||
| 1956 | /* TODO stop tracer */ | ||
| 1957 | ret = seq_open(file, &tracer_seq_ops); | 1921 | ret = seq_open(file, &tracer_seq_ops); |
| 1958 | if (ret < 0) { | 1922 | if (ret < 0) { |
| 1959 | fail_ret = ERR_PTR(ret); | 1923 | fail_ret = ERR_PTR(ret); |
| @@ -1963,9 +1927,6 @@ __tracing_open(struct inode *inode, struct file *file) | |||
| 1963 | m = file->private_data; | 1927 | m = file->private_data; |
| 1964 | m->private = iter; | 1928 | m->private = iter; |
| 1965 | 1929 | ||
| 1966 | /* stop the trace while dumping */ | ||
| 1967 | tracing_stop(); | ||
| 1968 | |||
| 1969 | mutex_unlock(&trace_types_lock); | 1930 | mutex_unlock(&trace_types_lock); |
| 1970 | 1931 | ||
| 1971 | return iter; | 1932 | return iter; |
| @@ -1976,6 +1937,7 @@ __tracing_open(struct inode *inode, struct file *file) | |||
| 1976 | ring_buffer_read_finish(iter->buffer_iter[cpu]); | 1937 | ring_buffer_read_finish(iter->buffer_iter[cpu]); |
| 1977 | } | 1938 | } |
| 1978 | free_cpumask_var(iter->started); | 1939 | free_cpumask_var(iter->started); |
| 1940 | tracing_start(); | ||
| 1979 | fail: | 1941 | fail: |
| 1980 | mutex_unlock(&trace_types_lock); | 1942 | mutex_unlock(&trace_types_lock); |
| 1981 | kfree(iter->trace); | 1943 | kfree(iter->trace); |
| @@ -2257,8 +2219,8 @@ tracing_trace_options_read(struct file *filp, char __user *ubuf, | |||
| 2257 | len += 3; /* "no" and newline */ | 2219 | len += 3; /* "no" and newline */ |
| 2258 | } | 2220 | } |
| 2259 | 2221 | ||
| 2260 | /* +2 for \n and \0 */ | 2222 | /* +1 for \0 */ |
| 2261 | buf = kmalloc(len + 2, GFP_KERNEL); | 2223 | buf = kmalloc(len + 1, GFP_KERNEL); |
| 2262 | if (!buf) { | 2224 | if (!buf) { |
| 2263 | mutex_unlock(&trace_types_lock); | 2225 | mutex_unlock(&trace_types_lock); |
| 2264 | return -ENOMEM; | 2226 | return -ENOMEM; |
| @@ -2281,7 +2243,7 @@ tracing_trace_options_read(struct file *filp, char __user *ubuf, | |||
| 2281 | } | 2243 | } |
| 2282 | mutex_unlock(&trace_types_lock); | 2244 | mutex_unlock(&trace_types_lock); |
| 2283 | 2245 | ||
| 2284 | WARN_ON(r >= len + 2); | 2246 | WARN_ON(r >= len + 1); |
| 2285 | 2247 | ||
| 2286 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); | 2248 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 2287 | 2249 | ||
| @@ -2292,23 +2254,23 @@ tracing_trace_options_read(struct file *filp, char __user *ubuf, | |||
| 2292 | /* Try to assign a tracer specific option */ | 2254 | /* Try to assign a tracer specific option */ |
| 2293 | static int set_tracer_option(struct tracer *trace, char *cmp, int neg) | 2255 | static int set_tracer_option(struct tracer *trace, char *cmp, int neg) |
| 2294 | { | 2256 | { |
| 2295 | struct tracer_flags *trace_flags = trace->flags; | 2257 | struct tracer_flags *tracer_flags = trace->flags; |
| 2296 | struct tracer_opt *opts = NULL; | 2258 | struct tracer_opt *opts = NULL; |
| 2297 | int ret = 0, i = 0; | 2259 | int ret = 0, i = 0; |
| 2298 | int len; | 2260 | int len; |
| 2299 | 2261 | ||
| 2300 | for (i = 0; trace_flags->opts[i].name; i++) { | 2262 | for (i = 0; tracer_flags->opts[i].name; i++) { |
| 2301 | opts = &trace_flags->opts[i]; | 2263 | opts = &tracer_flags->opts[i]; |
| 2302 | len = strlen(opts->name); | 2264 | len = strlen(opts->name); |
| 2303 | 2265 | ||
| 2304 | if (strncmp(cmp, opts->name, len) == 0) { | 2266 | if (strncmp(cmp, opts->name, len) == 0) { |
| 2305 | ret = trace->set_flag(trace_flags->val, | 2267 | ret = trace->set_flag(tracer_flags->val, |
| 2306 | opts->bit, !neg); | 2268 | opts->bit, !neg); |
| 2307 | break; | 2269 | break; |
| 2308 | } | 2270 | } |
| 2309 | } | 2271 | } |
| 2310 | /* Not found */ | 2272 | /* Not found */ |
| 2311 | if (!trace_flags->opts[i].name) | 2273 | if (!tracer_flags->opts[i].name) |
| 2312 | return -EINVAL; | 2274 | return -EINVAL; |
| 2313 | 2275 | ||
| 2314 | /* Refused to handle */ | 2276 | /* Refused to handle */ |
| @@ -2316,9 +2278,9 @@ static int set_tracer_option(struct tracer *trace, char *cmp, int neg) | |||
| 2316 | return ret; | 2278 | return ret; |
| 2317 | 2279 | ||
| 2318 | if (neg) | 2280 | if (neg) |
| 2319 | trace_flags->val &= ~opts->bit; | 2281 | tracer_flags->val &= ~opts->bit; |
| 2320 | else | 2282 | else |
| 2321 | trace_flags->val |= opts->bit; | 2283 | tracer_flags->val |= opts->bit; |
| 2322 | 2284 | ||
| 2323 | return 0; | 2285 | return 0; |
| 2324 | } | 2286 | } |
| @@ -2333,22 +2295,6 @@ static void set_tracer_flags(unsigned int mask, int enabled) | |||
| 2333 | trace_flags |= mask; | 2295 | trace_flags |= mask; |
| 2334 | else | 2296 | else |
| 2335 | trace_flags &= ~mask; | 2297 | trace_flags &= ~mask; |
| 2336 | |||
| 2337 | if (mask == TRACE_ITER_GLOBAL_CLK) { | ||
| 2338 | u64 (*func)(void); | ||
| 2339 | |||
| 2340 | if (enabled) | ||
| 2341 | func = trace_clock_global; | ||
| 2342 | else | ||
| 2343 | func = trace_clock_local; | ||
| 2344 | |||
| 2345 | mutex_lock(&trace_types_lock); | ||
| 2346 | ring_buffer_set_clock(global_trace.buffer, func); | ||
| 2347 | |||
| 2348 | if (max_tr.buffer) | ||
| 2349 | ring_buffer_set_clock(max_tr.buffer, func); | ||
| 2350 | mutex_unlock(&trace_types_lock); | ||
| 2351 | } | ||
| 2352 | } | 2298 | } |
| 2353 | 2299 | ||
| 2354 | static ssize_t | 2300 | static ssize_t |
| @@ -3316,6 +3262,62 @@ tracing_mark_write(struct file *filp, const char __user *ubuf, | |||
| 3316 | return cnt; | 3262 | return cnt; |
| 3317 | } | 3263 | } |
| 3318 | 3264 | ||
| 3265 | static ssize_t tracing_clock_read(struct file *filp, char __user *ubuf, | ||
| 3266 | size_t cnt, loff_t *ppos) | ||
| 3267 | { | ||
| 3268 | char buf[64]; | ||
| 3269 | int bufiter = 0; | ||
| 3270 | int i; | ||
| 3271 | |||
| 3272 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) | ||
| 3273 | bufiter += snprintf(buf + bufiter, sizeof(buf) - bufiter, | ||
| 3274 | "%s%s%s%s", i ? " " : "", | ||
| 3275 | i == trace_clock_id ? "[" : "", trace_clocks[i].name, | ||
| 3276 | i == trace_clock_id ? "]" : ""); | ||
| 3277 | bufiter += snprintf(buf + bufiter, sizeof(buf) - bufiter, "\n"); | ||
| 3278 | |||
| 3279 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, bufiter); | ||
| 3280 | } | ||
| 3281 | |||
| 3282 | static ssize_t tracing_clock_write(struct file *filp, const char __user *ubuf, | ||
| 3283 | size_t cnt, loff_t *fpos) | ||
| 3284 | { | ||
| 3285 | char buf[64]; | ||
| 3286 | const char *clockstr; | ||
| 3287 | int i; | ||
| 3288 | |||
| 3289 | if (cnt >= sizeof(buf)) | ||
| 3290 | return -EINVAL; | ||
| 3291 | |||
| 3292 | if (copy_from_user(&buf, ubuf, cnt)) | ||
| 3293 | return -EFAULT; | ||
| 3294 | |||
| 3295 | buf[cnt] = 0; | ||
| 3296 | |||
| 3297 | clockstr = strstrip(buf); | ||
| 3298 | |||
| 3299 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) { | ||
| 3300 | if (strcmp(trace_clocks[i].name, clockstr) == 0) | ||
| 3301 | break; | ||
| 3302 | } | ||
| 3303 | if (i == ARRAY_SIZE(trace_clocks)) | ||
| 3304 | return -EINVAL; | ||
| 3305 | |||
| 3306 | trace_clock_id = i; | ||
| 3307 | |||
| 3308 | mutex_lock(&trace_types_lock); | ||
| 3309 | |||
| 3310 | ring_buffer_set_clock(global_trace.buffer, trace_clocks[i].func); | ||
| 3311 | if (max_tr.buffer) | ||
| 3312 | ring_buffer_set_clock(max_tr.buffer, trace_clocks[i].func); | ||
| 3313 | |||
| 3314 | mutex_unlock(&trace_types_lock); | ||
| 3315 | |||
| 3316 | *fpos += cnt; | ||
| 3317 | |||
| 3318 | return cnt; | ||
| 3319 | } | ||
| 3320 | |||
| 3319 | static const struct file_operations tracing_max_lat_fops = { | 3321 | static const struct file_operations tracing_max_lat_fops = { |
| 3320 | .open = tracing_open_generic, | 3322 | .open = tracing_open_generic, |
| 3321 | .read = tracing_max_lat_read, | 3323 | .read = tracing_max_lat_read, |
| @@ -3353,6 +3355,12 @@ static const struct file_operations tracing_mark_fops = { | |||
| 3353 | .write = tracing_mark_write, | 3355 | .write = tracing_mark_write, |
| 3354 | }; | 3356 | }; |
| 3355 | 3357 | ||
| 3358 | static const struct file_operations trace_clock_fops = { | ||
| 3359 | .open = tracing_open_generic, | ||
| 3360 | .read = tracing_clock_read, | ||
| 3361 | .write = tracing_clock_write, | ||
| 3362 | }; | ||
| 3363 | |||
| 3356 | struct ftrace_buffer_info { | 3364 | struct ftrace_buffer_info { |
| 3357 | struct trace_array *tr; | 3365 | struct trace_array *tr; |
| 3358 | void *spare; | 3366 | void *spare; |
| @@ -3633,9 +3641,6 @@ tracing_stats_read(struct file *filp, char __user *ubuf, | |||
| 3633 | cnt = ring_buffer_commit_overrun_cpu(tr->buffer, cpu); | 3641 | cnt = ring_buffer_commit_overrun_cpu(tr->buffer, cpu); |
| 3634 | trace_seq_printf(s, "commit overrun: %ld\n", cnt); | 3642 | trace_seq_printf(s, "commit overrun: %ld\n", cnt); |
| 3635 | 3643 | ||
| 3636 | cnt = ring_buffer_nmi_dropped_cpu(tr->buffer, cpu); | ||
| 3637 | trace_seq_printf(s, "nmi dropped: %ld\n", cnt); | ||
| 3638 | |||
| 3639 | count = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len); | 3644 | count = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len); |
| 3640 | 3645 | ||
| 3641 | kfree(s); | 3646 | kfree(s); |
| @@ -4066,11 +4071,13 @@ static __init int tracer_init_debugfs(void) | |||
| 4066 | trace_create_file("current_tracer", 0644, d_tracer, | 4071 | trace_create_file("current_tracer", 0644, d_tracer, |
| 4067 | &global_trace, &set_tracer_fops); | 4072 | &global_trace, &set_tracer_fops); |
| 4068 | 4073 | ||
| 4074 | #ifdef CONFIG_TRACER_MAX_TRACE | ||
| 4069 | trace_create_file("tracing_max_latency", 0644, d_tracer, | 4075 | trace_create_file("tracing_max_latency", 0644, d_tracer, |
| 4070 | &tracing_max_latency, &tracing_max_lat_fops); | 4076 | &tracing_max_latency, &tracing_max_lat_fops); |
| 4071 | 4077 | ||
| 4072 | trace_create_file("tracing_thresh", 0644, d_tracer, | 4078 | trace_create_file("tracing_thresh", 0644, d_tracer, |
| 4073 | &tracing_thresh, &tracing_max_lat_fops); | 4079 | &tracing_thresh, &tracing_max_lat_fops); |
| 4080 | #endif | ||
| 4074 | 4081 | ||
| 4075 | trace_create_file("README", 0444, d_tracer, | 4082 | trace_create_file("README", 0444, d_tracer, |
| 4076 | NULL, &tracing_readme_fops); | 4083 | NULL, &tracing_readme_fops); |
| @@ -4087,6 +4094,9 @@ static __init int tracer_init_debugfs(void) | |||
| 4087 | trace_create_file("saved_cmdlines", 0444, d_tracer, | 4094 | trace_create_file("saved_cmdlines", 0444, d_tracer, |
| 4088 | NULL, &tracing_saved_cmdlines_fops); | 4095 | NULL, &tracing_saved_cmdlines_fops); |
| 4089 | 4096 | ||
| 4097 | trace_create_file("trace_clock", 0644, d_tracer, NULL, | ||
| 4098 | &trace_clock_fops); | ||
| 4099 | |||
| 4090 | #ifdef CONFIG_DYNAMIC_FTRACE | 4100 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 4091 | trace_create_file("dyn_ftrace_total_info", 0444, d_tracer, | 4101 | trace_create_file("dyn_ftrace_total_info", 0444, d_tracer, |
| 4092 | &ftrace_update_tot_cnt, &tracing_dyn_info_fops); | 4102 | &ftrace_update_tot_cnt, &tracing_dyn_info_fops); |
| @@ -4265,7 +4275,6 @@ void ftrace_dump(void) | |||
| 4265 | 4275 | ||
| 4266 | __init static int tracer_alloc_buffers(void) | 4276 | __init static int tracer_alloc_buffers(void) |
| 4267 | { | 4277 | { |
| 4268 | struct trace_array_cpu *data; | ||
| 4269 | int ring_buf_size; | 4278 | int ring_buf_size; |
| 4270 | int i; | 4279 | int i; |
| 4271 | int ret = -ENOMEM; | 4280 | int ret = -ENOMEM; |
| @@ -4315,7 +4324,7 @@ __init static int tracer_alloc_buffers(void) | |||
| 4315 | 4324 | ||
| 4316 | /* Allocate the first page for all buffers */ | 4325 | /* Allocate the first page for all buffers */ |
| 4317 | for_each_tracing_cpu(i) { | 4326 | for_each_tracing_cpu(i) { |
| 4318 | data = global_trace.data[i] = &per_cpu(global_trace_cpu, i); | 4327 | global_trace.data[i] = &per_cpu(global_trace_cpu, i); |
| 4319 | max_tr.data[i] = &per_cpu(max_data, i); | 4328 | max_tr.data[i] = &per_cpu(max_data, i); |
| 4320 | } | 4329 | } |
| 4321 | 4330 | ||
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 8b9f4f6e9559..fa1dccb579d5 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h | |||
| @@ -34,8 +34,6 @@ enum trace_type { | |||
| 34 | TRACE_GRAPH_ENT, | 34 | TRACE_GRAPH_ENT, |
| 35 | TRACE_USER_STACK, | 35 | TRACE_USER_STACK, |
| 36 | TRACE_HW_BRANCHES, | 36 | TRACE_HW_BRANCHES, |
| 37 | TRACE_SYSCALL_ENTER, | ||
| 38 | TRACE_SYSCALL_EXIT, | ||
| 39 | TRACE_KMEM_ALLOC, | 37 | TRACE_KMEM_ALLOC, |
| 40 | TRACE_KMEM_FREE, | 38 | TRACE_KMEM_FREE, |
| 41 | TRACE_POWER, | 39 | TRACE_POWER, |
| @@ -236,9 +234,6 @@ struct trace_array_cpu { | |||
| 236 | atomic_t disabled; | 234 | atomic_t disabled; |
| 237 | void *buffer_page; /* ring buffer spare */ | 235 | void *buffer_page; /* ring buffer spare */ |
| 238 | 236 | ||
| 239 | /* these fields get copied into max-trace: */ | ||
| 240 | unsigned long trace_idx; | ||
| 241 | unsigned long overrun; | ||
| 242 | unsigned long saved_latency; | 237 | unsigned long saved_latency; |
| 243 | unsigned long critical_start; | 238 | unsigned long critical_start; |
| 244 | unsigned long critical_end; | 239 | unsigned long critical_end; |
| @@ -246,6 +241,7 @@ struct trace_array_cpu { | |||
| 246 | unsigned long nice; | 241 | unsigned long nice; |
| 247 | unsigned long policy; | 242 | unsigned long policy; |
| 248 | unsigned long rt_priority; | 243 | unsigned long rt_priority; |
| 244 | unsigned long skipped_entries; | ||
| 249 | cycle_t preempt_timestamp; | 245 | cycle_t preempt_timestamp; |
| 250 | pid_t pid; | 246 | pid_t pid; |
| 251 | uid_t uid; | 247 | uid_t uid; |
| @@ -319,10 +315,6 @@ extern void __ftrace_bad_type(void); | |||
| 319 | TRACE_KMEM_ALLOC); \ | 315 | TRACE_KMEM_ALLOC); \ |
| 320 | IF_ASSIGN(var, ent, struct kmemtrace_free_entry, \ | 316 | IF_ASSIGN(var, ent, struct kmemtrace_free_entry, \ |
| 321 | TRACE_KMEM_FREE); \ | 317 | TRACE_KMEM_FREE); \ |
| 322 | IF_ASSIGN(var, ent, struct syscall_trace_enter, \ | ||
| 323 | TRACE_SYSCALL_ENTER); \ | ||
| 324 | IF_ASSIGN(var, ent, struct syscall_trace_exit, \ | ||
| 325 | TRACE_SYSCALL_EXIT); \ | ||
| 326 | __ftrace_bad_type(); \ | 318 | __ftrace_bad_type(); \ |
| 327 | } while (0) | 319 | } while (0) |
| 328 | 320 | ||
| @@ -423,12 +415,13 @@ void init_tracer_sysprof_debugfs(struct dentry *d_tracer); | |||
| 423 | 415 | ||
| 424 | struct ring_buffer_event; | 416 | struct ring_buffer_event; |
| 425 | 417 | ||
| 426 | struct ring_buffer_event *trace_buffer_lock_reserve(struct trace_array *tr, | 418 | struct ring_buffer_event * |
| 427 | int type, | 419 | trace_buffer_lock_reserve(struct ring_buffer *buffer, |
| 428 | unsigned long len, | 420 | int type, |
| 429 | unsigned long flags, | 421 | unsigned long len, |
| 430 | int pc); | 422 | unsigned long flags, |
| 431 | void trace_buffer_unlock_commit(struct trace_array *tr, | 423 | int pc); |
| 424 | void trace_buffer_unlock_commit(struct ring_buffer *buffer, | ||
| 432 | struct ring_buffer_event *event, | 425 | struct ring_buffer_event *event, |
| 433 | unsigned long flags, int pc); | 426 | unsigned long flags, int pc); |
| 434 | 427 | ||
| @@ -467,6 +460,7 @@ void trace_function(struct trace_array *tr, | |||
| 467 | 460 | ||
| 468 | void trace_graph_return(struct ftrace_graph_ret *trace); | 461 | void trace_graph_return(struct ftrace_graph_ret *trace); |
| 469 | int trace_graph_entry(struct ftrace_graph_ent *trace); | 462 | int trace_graph_entry(struct ftrace_graph_ent *trace); |
| 463 | void set_graph_array(struct trace_array *tr); | ||
| 470 | 464 | ||
| 471 | void tracing_start_cmdline_record(void); | 465 | void tracing_start_cmdline_record(void); |
| 472 | void tracing_stop_cmdline_record(void); | 466 | void tracing_stop_cmdline_record(void); |
| @@ -478,16 +472,40 @@ void unregister_tracer(struct tracer *type); | |||
| 478 | 472 | ||
| 479 | extern unsigned long nsecs_to_usecs(unsigned long nsecs); | 473 | extern unsigned long nsecs_to_usecs(unsigned long nsecs); |
| 480 | 474 | ||
| 475 | #ifdef CONFIG_TRACER_MAX_TRACE | ||
| 481 | extern unsigned long tracing_max_latency; | 476 | extern unsigned long tracing_max_latency; |
| 482 | extern unsigned long tracing_thresh; | 477 | extern unsigned long tracing_thresh; |
| 483 | 478 | ||
| 484 | void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu); | 479 | void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu); |
| 485 | void update_max_tr_single(struct trace_array *tr, | 480 | void update_max_tr_single(struct trace_array *tr, |
| 486 | struct task_struct *tsk, int cpu); | 481 | struct task_struct *tsk, int cpu); |
| 482 | #endif /* CONFIG_TRACER_MAX_TRACE */ | ||
| 487 | 483 | ||
| 488 | void __trace_stack(struct trace_array *tr, | 484 | #ifdef CONFIG_STACKTRACE |
| 489 | unsigned long flags, | 485 | void ftrace_trace_stack(struct ring_buffer *buffer, unsigned long flags, |
| 490 | int skip, int pc); | 486 | int skip, int pc); |
| 487 | |||
| 488 | void ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, | ||
| 489 | int pc); | ||
| 490 | |||
| 491 | void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, | ||
| 492 | int pc); | ||
| 493 | #else | ||
| 494 | static inline void ftrace_trace_stack(struct trace_array *tr, | ||
| 495 | unsigned long flags, int skip, int pc) | ||
| 496 | { | ||
| 497 | } | ||
| 498 | |||
| 499 | static inline void ftrace_trace_userstack(struct trace_array *tr, | ||
| 500 | unsigned long flags, int pc) | ||
| 501 | { | ||
| 502 | } | ||
| 503 | |||
| 504 | static inline void __trace_stack(struct trace_array *tr, unsigned long flags, | ||
| 505 | int skip, int pc) | ||
| 506 | { | ||
| 507 | } | ||
| 508 | #endif /* CONFIG_STACKTRACE */ | ||
| 491 | 509 | ||
| 492 | extern cycle_t ftrace_now(int cpu); | 510 | extern cycle_t ftrace_now(int cpu); |
| 493 | 511 | ||
| @@ -513,6 +531,10 @@ extern unsigned long ftrace_update_tot_cnt; | |||
| 513 | extern int DYN_FTRACE_TEST_NAME(void); | 531 | extern int DYN_FTRACE_TEST_NAME(void); |
| 514 | #endif | 532 | #endif |
| 515 | 533 | ||
| 534 | extern int ring_buffer_expanded; | ||
| 535 | extern bool tracing_selftest_disabled; | ||
| 536 | DECLARE_PER_CPU(local_t, ftrace_cpu_disabled); | ||
| 537 | |||
| 516 | #ifdef CONFIG_FTRACE_STARTUP_TEST | 538 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 517 | extern int trace_selftest_startup_function(struct tracer *trace, | 539 | extern int trace_selftest_startup_function(struct tracer *trace, |
| 518 | struct trace_array *tr); | 540 | struct trace_array *tr); |
| @@ -544,9 +566,16 @@ extern int | |||
| 544 | trace_vbprintk(unsigned long ip, const char *fmt, va_list args); | 566 | trace_vbprintk(unsigned long ip, const char *fmt, va_list args); |
| 545 | extern int | 567 | extern int |
| 546 | trace_vprintk(unsigned long ip, const char *fmt, va_list args); | 568 | trace_vprintk(unsigned long ip, const char *fmt, va_list args); |
| 569 | extern int | ||
| 570 | trace_array_vprintk(struct trace_array *tr, | ||
| 571 | unsigned long ip, const char *fmt, va_list args); | ||
| 572 | int trace_array_printk(struct trace_array *tr, | ||
| 573 | unsigned long ip, const char *fmt, ...); | ||
| 547 | 574 | ||
| 548 | extern unsigned long trace_flags; | 575 | extern unsigned long trace_flags; |
| 549 | 576 | ||
| 577 | extern int trace_clock_id; | ||
| 578 | |||
| 550 | /* Standard output formatting function used for function return traces */ | 579 | /* Standard output formatting function used for function return traces */ |
| 551 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | 580 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 552 | extern enum print_line_t print_graph_function(struct trace_iterator *iter); | 581 | extern enum print_line_t print_graph_function(struct trace_iterator *iter); |
| @@ -635,9 +664,8 @@ enum trace_iterator_flags { | |||
| 635 | TRACE_ITER_PRINTK_MSGONLY = 0x10000, | 664 | TRACE_ITER_PRINTK_MSGONLY = 0x10000, |
| 636 | TRACE_ITER_CONTEXT_INFO = 0x20000, /* Print pid/cpu/time */ | 665 | TRACE_ITER_CONTEXT_INFO = 0x20000, /* Print pid/cpu/time */ |
| 637 | TRACE_ITER_LATENCY_FMT = 0x40000, | 666 | TRACE_ITER_LATENCY_FMT = 0x40000, |
| 638 | TRACE_ITER_GLOBAL_CLK = 0x80000, | 667 | TRACE_ITER_SLEEP_TIME = 0x80000, |
| 639 | TRACE_ITER_SLEEP_TIME = 0x100000, | 668 | TRACE_ITER_GRAPH_TIME = 0x100000, |
| 640 | TRACE_ITER_GRAPH_TIME = 0x200000, | ||
| 641 | }; | 669 | }; |
| 642 | 670 | ||
| 643 | /* | 671 | /* |
| @@ -734,6 +762,7 @@ struct ftrace_event_field { | |||
| 734 | struct list_head link; | 762 | struct list_head link; |
| 735 | char *name; | 763 | char *name; |
| 736 | char *type; | 764 | char *type; |
| 765 | int filter_type; | ||
| 737 | int offset; | 766 | int offset; |
| 738 | int size; | 767 | int size; |
| 739 | int is_signed; | 768 | int is_signed; |
| @@ -743,13 +772,15 @@ struct event_filter { | |||
| 743 | int n_preds; | 772 | int n_preds; |
| 744 | struct filter_pred **preds; | 773 | struct filter_pred **preds; |
| 745 | char *filter_string; | 774 | char *filter_string; |
| 775 | bool no_reset; | ||
| 746 | }; | 776 | }; |
| 747 | 777 | ||
| 748 | struct event_subsystem { | 778 | struct event_subsystem { |
| 749 | struct list_head list; | 779 | struct list_head list; |
| 750 | const char *name; | 780 | const char *name; |
| 751 | struct dentry *entry; | 781 | struct dentry *entry; |
| 752 | void *filter; | 782 | struct event_filter *filter; |
| 783 | int nr_events; | ||
| 753 | }; | 784 | }; |
| 754 | 785 | ||
| 755 | struct filter_pred; | 786 | struct filter_pred; |
| @@ -777,6 +808,7 @@ extern int apply_subsystem_event_filter(struct event_subsystem *system, | |||
| 777 | char *filter_string); | 808 | char *filter_string); |
| 778 | extern void print_subsystem_event_filter(struct event_subsystem *system, | 809 | extern void print_subsystem_event_filter(struct event_subsystem *system, |
| 779 | struct trace_seq *s); | 810 | struct trace_seq *s); |
| 811 | extern int filter_assign_type(const char *type); | ||
| 780 | 812 | ||
| 781 | static inline int | 813 | static inline int |
| 782 | filter_check_discard(struct ftrace_event_call *call, void *rec, | 814 | filter_check_discard(struct ftrace_event_call *call, void *rec, |
diff --git a/kernel/trace/trace_boot.c b/kernel/trace/trace_boot.c index a29ef23ffb47..19bfc75d467e 100644 --- a/kernel/trace/trace_boot.c +++ b/kernel/trace/trace_boot.c | |||
| @@ -41,14 +41,12 @@ void disable_boot_trace(void) | |||
| 41 | 41 | ||
| 42 | static int boot_trace_init(struct trace_array *tr) | 42 | static int boot_trace_init(struct trace_array *tr) |
| 43 | { | 43 | { |
| 44 | int cpu; | ||
| 45 | boot_trace = tr; | 44 | boot_trace = tr; |
| 46 | 45 | ||
| 47 | if (!tr) | 46 | if (!tr) |
| 48 | return 0; | 47 | return 0; |
| 49 | 48 | ||
| 50 | for_each_cpu(cpu, cpu_possible_mask) | 49 | tracing_reset_online_cpus(tr); |
| 51 | tracing_reset(tr, cpu); | ||
| 52 | 50 | ||
| 53 | tracing_sched_switch_assign_trace(tr); | 51 | tracing_sched_switch_assign_trace(tr); |
| 54 | return 0; | 52 | return 0; |
| @@ -132,6 +130,7 @@ struct tracer boot_tracer __read_mostly = | |||
| 132 | void trace_boot_call(struct boot_trace_call *bt, initcall_t fn) | 130 | void trace_boot_call(struct boot_trace_call *bt, initcall_t fn) |
| 133 | { | 131 | { |
| 134 | struct ring_buffer_event *event; | 132 | struct ring_buffer_event *event; |
| 133 | struct ring_buffer *buffer; | ||
| 135 | struct trace_boot_call *entry; | 134 | struct trace_boot_call *entry; |
| 136 | struct trace_array *tr = boot_trace; | 135 | struct trace_array *tr = boot_trace; |
| 137 | 136 | ||
| @@ -144,13 +143,14 @@ void trace_boot_call(struct boot_trace_call *bt, initcall_t fn) | |||
| 144 | sprint_symbol(bt->func, (unsigned long)fn); | 143 | sprint_symbol(bt->func, (unsigned long)fn); |
| 145 | preempt_disable(); | 144 | preempt_disable(); |
| 146 | 145 | ||
| 147 | event = trace_buffer_lock_reserve(tr, TRACE_BOOT_CALL, | 146 | buffer = tr->buffer; |
| 147 | event = trace_buffer_lock_reserve(buffer, TRACE_BOOT_CALL, | ||
| 148 | sizeof(*entry), 0, 0); | 148 | sizeof(*entry), 0, 0); |
| 149 | if (!event) | 149 | if (!event) |
| 150 | goto out; | 150 | goto out; |
| 151 | entry = ring_buffer_event_data(event); | 151 | entry = ring_buffer_event_data(event); |
| 152 | entry->boot_call = *bt; | 152 | entry->boot_call = *bt; |
| 153 | trace_buffer_unlock_commit(tr, event, 0, 0); | 153 | trace_buffer_unlock_commit(buffer, event, 0, 0); |
| 154 | out: | 154 | out: |
| 155 | preempt_enable(); | 155 | preempt_enable(); |
| 156 | } | 156 | } |
| @@ -158,6 +158,7 @@ void trace_boot_call(struct boot_trace_call *bt, initcall_t fn) | |||
| 158 | void trace_boot_ret(struct boot_trace_ret *bt, initcall_t fn) | 158 | void trace_boot_ret(struct boot_trace_ret *bt, initcall_t fn) |
| 159 | { | 159 | { |
| 160 | struct ring_buffer_event *event; | 160 | struct ring_buffer_event *event; |
| 161 | struct ring_buffer *buffer; | ||
| 161 | struct trace_boot_ret *entry; | 162 | struct trace_boot_ret *entry; |
| 162 | struct trace_array *tr = boot_trace; | 163 | struct trace_array *tr = boot_trace; |
| 163 | 164 | ||
| @@ -167,13 +168,14 @@ void trace_boot_ret(struct boot_trace_ret *bt, initcall_t fn) | |||
| 167 | sprint_symbol(bt->func, (unsigned long)fn); | 168 | sprint_symbol(bt->func, (unsigned long)fn); |
| 168 | preempt_disable(); | 169 | preempt_disable(); |
| 169 | 170 | ||
| 170 | event = trace_buffer_lock_reserve(tr, TRACE_BOOT_RET, | 171 | buffer = tr->buffer; |
| 172 | event = trace_buffer_lock_reserve(buffer, TRACE_BOOT_RET, | ||
| 171 | sizeof(*entry), 0, 0); | 173 | sizeof(*entry), 0, 0); |
| 172 | if (!event) | 174 | if (!event) |
| 173 | goto out; | 175 | goto out; |
| 174 | entry = ring_buffer_event_data(event); | 176 | entry = ring_buffer_event_data(event); |
| 175 | entry->boot_ret = *bt; | 177 | entry->boot_ret = *bt; |
| 176 | trace_buffer_unlock_commit(tr, event, 0, 0); | 178 | trace_buffer_unlock_commit(buffer, event, 0, 0); |
| 177 | out: | 179 | out: |
| 178 | preempt_enable(); | 180 | preempt_enable(); |
| 179 | } | 181 | } |
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index e75276a49cf5..78b1ed230177 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c | |||
| @@ -17,6 +17,8 @@ | |||
| 17 | #include <linux/ctype.h> | 17 | #include <linux/ctype.h> |
| 18 | #include <linux/delay.h> | 18 | #include <linux/delay.h> |
| 19 | 19 | ||
| 20 | #include <asm/setup.h> | ||
| 21 | |||
| 20 | #include "trace_output.h" | 22 | #include "trace_output.h" |
| 21 | 23 | ||
| 22 | #define TRACE_SYSTEM "TRACE_SYSTEM" | 24 | #define TRACE_SYSTEM "TRACE_SYSTEM" |
| @@ -25,8 +27,9 @@ DEFINE_MUTEX(event_mutex); | |||
| 25 | 27 | ||
| 26 | LIST_HEAD(ftrace_events); | 28 | LIST_HEAD(ftrace_events); |
| 27 | 29 | ||
| 28 | int trace_define_field(struct ftrace_event_call *call, char *type, | 30 | int trace_define_field(struct ftrace_event_call *call, const char *type, |
| 29 | char *name, int offset, int size, int is_signed) | 31 | const char *name, int offset, int size, int is_signed, |
| 32 | int filter_type) | ||
| 30 | { | 33 | { |
| 31 | struct ftrace_event_field *field; | 34 | struct ftrace_event_field *field; |
| 32 | 35 | ||
| @@ -42,9 +45,15 @@ int trace_define_field(struct ftrace_event_call *call, char *type, | |||
| 42 | if (!field->type) | 45 | if (!field->type) |
| 43 | goto err; | 46 | goto err; |
| 44 | 47 | ||
| 48 | if (filter_type == FILTER_OTHER) | ||
| 49 | field->filter_type = filter_assign_type(type); | ||
| 50 | else | ||
| 51 | field->filter_type = filter_type; | ||
| 52 | |||
| 45 | field->offset = offset; | 53 | field->offset = offset; |
| 46 | field->size = size; | 54 | field->size = size; |
| 47 | field->is_signed = is_signed; | 55 | field->is_signed = is_signed; |
| 56 | |||
| 48 | list_add(&field->link, &call->fields); | 57 | list_add(&field->link, &call->fields); |
| 49 | 58 | ||
| 50 | return 0; | 59 | return 0; |
| @@ -60,6 +69,29 @@ err: | |||
| 60 | } | 69 | } |
| 61 | EXPORT_SYMBOL_GPL(trace_define_field); | 70 | EXPORT_SYMBOL_GPL(trace_define_field); |
| 62 | 71 | ||
| 72 | #define __common_field(type, item) \ | ||
| 73 | ret = trace_define_field(call, #type, "common_" #item, \ | ||
| 74 | offsetof(typeof(ent), item), \ | ||
| 75 | sizeof(ent.item), \ | ||
| 76 | is_signed_type(type), FILTER_OTHER); \ | ||
| 77 | if (ret) \ | ||
| 78 | return ret; | ||
| 79 | |||
| 80 | int trace_define_common_fields(struct ftrace_event_call *call) | ||
| 81 | { | ||
| 82 | int ret; | ||
| 83 | struct trace_entry ent; | ||
| 84 | |||
| 85 | __common_field(unsigned short, type); | ||
| 86 | __common_field(unsigned char, flags); | ||
| 87 | __common_field(unsigned char, preempt_count); | ||
| 88 | __common_field(int, pid); | ||
| 89 | __common_field(int, tgid); | ||
| 90 | |||
| 91 | return ret; | ||
| 92 | } | ||
| 93 | EXPORT_SYMBOL_GPL(trace_define_common_fields); | ||
| 94 | |||
| 63 | #ifdef CONFIG_MODULES | 95 | #ifdef CONFIG_MODULES |
| 64 | 96 | ||
| 65 | static void trace_destroy_fields(struct ftrace_event_call *call) | 97 | static void trace_destroy_fields(struct ftrace_event_call *call) |
| @@ -84,14 +116,14 @@ static void ftrace_event_enable_disable(struct ftrace_event_call *call, | |||
| 84 | if (call->enabled) { | 116 | if (call->enabled) { |
| 85 | call->enabled = 0; | 117 | call->enabled = 0; |
| 86 | tracing_stop_cmdline_record(); | 118 | tracing_stop_cmdline_record(); |
| 87 | call->unregfunc(); | 119 | call->unregfunc(call->data); |
| 88 | } | 120 | } |
| 89 | break; | 121 | break; |
| 90 | case 1: | 122 | case 1: |
| 91 | if (!call->enabled) { | 123 | if (!call->enabled) { |
| 92 | call->enabled = 1; | 124 | call->enabled = 1; |
| 93 | tracing_start_cmdline_record(); | 125 | tracing_start_cmdline_record(); |
| 94 | call->regfunc(); | 126 | call->regfunc(call->data); |
| 95 | } | 127 | } |
| 96 | break; | 128 | break; |
| 97 | } | 129 | } |
| @@ -574,7 +606,7 @@ event_format_read(struct file *filp, char __user *ubuf, size_t cnt, | |||
| 574 | trace_seq_printf(s, "format:\n"); | 606 | trace_seq_printf(s, "format:\n"); |
| 575 | trace_write_header(s); | 607 | trace_write_header(s); |
| 576 | 608 | ||
| 577 | r = call->show_format(s); | 609 | r = call->show_format(call, s); |
| 578 | if (!r) { | 610 | if (!r) { |
| 579 | /* | 611 | /* |
| 580 | * ug! The format output is bigger than a PAGE!! | 612 | * ug! The format output is bigger than a PAGE!! |
| @@ -849,8 +881,10 @@ event_subsystem_dir(const char *name, struct dentry *d_events) | |||
| 849 | 881 | ||
| 850 | /* First see if we did not already create this dir */ | 882 | /* First see if we did not already create this dir */ |
| 851 | list_for_each_entry(system, &event_subsystems, list) { | 883 | list_for_each_entry(system, &event_subsystems, list) { |
| 852 | if (strcmp(system->name, name) == 0) | 884 | if (strcmp(system->name, name) == 0) { |
| 885 | system->nr_events++; | ||
| 853 | return system->entry; | 886 | return system->entry; |
| 887 | } | ||
| 854 | } | 888 | } |
| 855 | 889 | ||
| 856 | /* need to create new entry */ | 890 | /* need to create new entry */ |
| @@ -869,6 +903,7 @@ event_subsystem_dir(const char *name, struct dentry *d_events) | |||
| 869 | return d_events; | 903 | return d_events; |
| 870 | } | 904 | } |
| 871 | 905 | ||
| 906 | system->nr_events = 1; | ||
| 872 | system->name = kstrdup(name, GFP_KERNEL); | 907 | system->name = kstrdup(name, GFP_KERNEL); |
| 873 | if (!system->name) { | 908 | if (!system->name) { |
| 874 | debugfs_remove(system->entry); | 909 | debugfs_remove(system->entry); |
| @@ -920,15 +955,6 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events, | |||
| 920 | if (strcmp(call->system, TRACE_SYSTEM) != 0) | 955 | if (strcmp(call->system, TRACE_SYSTEM) != 0) |
| 921 | d_events = event_subsystem_dir(call->system, d_events); | 956 | d_events = event_subsystem_dir(call->system, d_events); |
| 922 | 957 | ||
| 923 | if (call->raw_init) { | ||
| 924 | ret = call->raw_init(); | ||
| 925 | if (ret < 0) { | ||
| 926 | pr_warning("Could not initialize trace point" | ||
| 927 | " events/%s\n", call->name); | ||
| 928 | return ret; | ||
| 929 | } | ||
| 930 | } | ||
| 931 | |||
| 932 | call->dir = debugfs_create_dir(call->name, d_events); | 958 | call->dir = debugfs_create_dir(call->name, d_events); |
| 933 | if (!call->dir) { | 959 | if (!call->dir) { |
| 934 | pr_warning("Could not create debugfs " | 960 | pr_warning("Could not create debugfs " |
| @@ -945,7 +971,7 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events, | |||
| 945 | id); | 971 | id); |
| 946 | 972 | ||
| 947 | if (call->define_fields) { | 973 | if (call->define_fields) { |
| 948 | ret = call->define_fields(); | 974 | ret = call->define_fields(call); |
| 949 | if (ret < 0) { | 975 | if (ret < 0) { |
| 950 | pr_warning("Could not initialize trace point" | 976 | pr_warning("Could not initialize trace point" |
| 951 | " events/%s\n", call->name); | 977 | " events/%s\n", call->name); |
| @@ -987,6 +1013,32 @@ struct ftrace_module_file_ops { | |||
| 987 | struct file_operations filter; | 1013 | struct file_operations filter; |
| 988 | }; | 1014 | }; |
| 989 | 1015 | ||
| 1016 | static void remove_subsystem_dir(const char *name) | ||
| 1017 | { | ||
| 1018 | struct event_subsystem *system; | ||
| 1019 | |||
| 1020 | if (strcmp(name, TRACE_SYSTEM) == 0) | ||
| 1021 | return; | ||
| 1022 | |||
| 1023 | list_for_each_entry(system, &event_subsystems, list) { | ||
| 1024 | if (strcmp(system->name, name) == 0) { | ||
| 1025 | if (!--system->nr_events) { | ||
| 1026 | struct event_filter *filter = system->filter; | ||
| 1027 | |||
| 1028 | debugfs_remove_recursive(system->entry); | ||
| 1029 | list_del(&system->list); | ||
| 1030 | if (filter) { | ||
| 1031 | kfree(filter->filter_string); | ||
| 1032 | kfree(filter); | ||
| 1033 | } | ||
| 1034 | kfree(system->name); | ||
| 1035 | kfree(system); | ||
| 1036 | } | ||
| 1037 | break; | ||
| 1038 | } | ||
| 1039 | } | ||
| 1040 | } | ||
| 1041 | |||
| 990 | static struct ftrace_module_file_ops * | 1042 | static struct ftrace_module_file_ops * |
| 991 | trace_create_file_ops(struct module *mod) | 1043 | trace_create_file_ops(struct module *mod) |
| 992 | { | 1044 | { |
| @@ -1027,6 +1079,7 @@ static void trace_module_add_events(struct module *mod) | |||
| 1027 | struct ftrace_module_file_ops *file_ops = NULL; | 1079 | struct ftrace_module_file_ops *file_ops = NULL; |
| 1028 | struct ftrace_event_call *call, *start, *end; | 1080 | struct ftrace_event_call *call, *start, *end; |
| 1029 | struct dentry *d_events; | 1081 | struct dentry *d_events; |
| 1082 | int ret; | ||
| 1030 | 1083 | ||
| 1031 | start = mod->trace_events; | 1084 | start = mod->trace_events; |
| 1032 | end = mod->trace_events + mod->num_trace_events; | 1085 | end = mod->trace_events + mod->num_trace_events; |
| @@ -1042,7 +1095,15 @@ static void trace_module_add_events(struct module *mod) | |||
| 1042 | /* The linker may leave blanks */ | 1095 | /* The linker may leave blanks */ |
| 1043 | if (!call->name) | 1096 | if (!call->name) |
| 1044 | continue; | 1097 | continue; |
| 1045 | 1098 | if (call->raw_init) { | |
| 1099 | ret = call->raw_init(); | ||
| 1100 | if (ret < 0) { | ||
| 1101 | if (ret != -ENOSYS) | ||
| 1102 | pr_warning("Could not initialize trace " | ||
| 1103 | "point events/%s\n", call->name); | ||
| 1104 | continue; | ||
| 1105 | } | ||
| 1106 | } | ||
| 1046 | /* | 1107 | /* |
| 1047 | * This module has events, create file ops for this module | 1108 | * This module has events, create file ops for this module |
| 1048 | * if not already done. | 1109 | * if not already done. |
| @@ -1077,6 +1138,7 @@ static void trace_module_remove_events(struct module *mod) | |||
| 1077 | list_del(&call->list); | 1138 | list_del(&call->list); |
| 1078 | trace_destroy_fields(call); | 1139 | trace_destroy_fields(call); |
| 1079 | destroy_preds(call); | 1140 | destroy_preds(call); |
| 1141 | remove_subsystem_dir(call->system); | ||
| 1080 | } | 1142 | } |
| 1081 | } | 1143 | } |
| 1082 | 1144 | ||
| @@ -1133,6 +1195,18 @@ struct notifier_block trace_module_nb = { | |||
| 1133 | extern struct ftrace_event_call __start_ftrace_events[]; | 1195 | extern struct ftrace_event_call __start_ftrace_events[]; |
| 1134 | extern struct ftrace_event_call __stop_ftrace_events[]; | 1196 | extern struct ftrace_event_call __stop_ftrace_events[]; |
| 1135 | 1197 | ||
| 1198 | static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata; | ||
| 1199 | |||
| 1200 | static __init int setup_trace_event(char *str) | ||
| 1201 | { | ||
| 1202 | strlcpy(bootup_event_buf, str, COMMAND_LINE_SIZE); | ||
| 1203 | ring_buffer_expanded = 1; | ||
| 1204 | tracing_selftest_disabled = 1; | ||
| 1205 | |||
| 1206 | return 1; | ||
| 1207 | } | ||
| 1208 | __setup("trace_event=", setup_trace_event); | ||
| 1209 | |||
| 1136 | static __init int event_trace_init(void) | 1210 | static __init int event_trace_init(void) |
| 1137 | { | 1211 | { |
| 1138 | struct ftrace_event_call *call; | 1212 | struct ftrace_event_call *call; |
| @@ -1140,6 +1214,8 @@ static __init int event_trace_init(void) | |||
| 1140 | struct dentry *entry; | 1214 | struct dentry *entry; |
| 1141 | struct dentry *d_events; | 1215 | struct dentry *d_events; |
| 1142 | int ret; | 1216 | int ret; |
| 1217 | char *buf = bootup_event_buf; | ||
| 1218 | char *token; | ||
| 1143 | 1219 | ||
| 1144 | d_tracer = tracing_init_dentry(); | 1220 | d_tracer = tracing_init_dentry(); |
| 1145 | if (!d_tracer) | 1221 | if (!d_tracer) |
| @@ -1179,12 +1255,34 @@ static __init int event_trace_init(void) | |||
| 1179 | /* The linker may leave blanks */ | 1255 | /* The linker may leave blanks */ |
| 1180 | if (!call->name) | 1256 | if (!call->name) |
| 1181 | continue; | 1257 | continue; |
| 1258 | if (call->raw_init) { | ||
| 1259 | ret = call->raw_init(); | ||
| 1260 | if (ret < 0) { | ||
| 1261 | if (ret != -ENOSYS) | ||
| 1262 | pr_warning("Could not initialize trace " | ||
| 1263 | "point events/%s\n", call->name); | ||
| 1264 | continue; | ||
| 1265 | } | ||
| 1266 | } | ||
| 1182 | list_add(&call->list, &ftrace_events); | 1267 | list_add(&call->list, &ftrace_events); |
| 1183 | event_create_dir(call, d_events, &ftrace_event_id_fops, | 1268 | event_create_dir(call, d_events, &ftrace_event_id_fops, |
| 1184 | &ftrace_enable_fops, &ftrace_event_filter_fops, | 1269 | &ftrace_enable_fops, &ftrace_event_filter_fops, |
| 1185 | &ftrace_event_format_fops); | 1270 | &ftrace_event_format_fops); |
| 1186 | } | 1271 | } |
| 1187 | 1272 | ||
| 1273 | while (true) { | ||
| 1274 | token = strsep(&buf, ","); | ||
| 1275 | |||
| 1276 | if (!token) | ||
| 1277 | break; | ||
| 1278 | if (!*token) | ||
| 1279 | continue; | ||
| 1280 | |||
| 1281 | ret = ftrace_set_clr_event(token, 1); | ||
| 1282 | if (ret) | ||
| 1283 | pr_warning("Failed to enable trace event: %s\n", token); | ||
| 1284 | } | ||
| 1285 | |||
| 1188 | ret = register_module_notifier(&trace_module_nb); | 1286 | ret = register_module_notifier(&trace_module_nb); |
| 1189 | if (ret) | 1287 | if (ret) |
| 1190 | pr_warning("Failed to register trace events module notifier\n"); | 1288 | pr_warning("Failed to register trace events module notifier\n"); |
| @@ -1340,6 +1438,7 @@ static void | |||
| 1340 | function_test_events_call(unsigned long ip, unsigned long parent_ip) | 1438 | function_test_events_call(unsigned long ip, unsigned long parent_ip) |
| 1341 | { | 1439 | { |
| 1342 | struct ring_buffer_event *event; | 1440 | struct ring_buffer_event *event; |
| 1441 | struct ring_buffer *buffer; | ||
| 1343 | struct ftrace_entry *entry; | 1442 | struct ftrace_entry *entry; |
| 1344 | unsigned long flags; | 1443 | unsigned long flags; |
| 1345 | long disabled; | 1444 | long disabled; |
| @@ -1357,7 +1456,8 @@ function_test_events_call(unsigned long ip, unsigned long parent_ip) | |||
| 1357 | 1456 | ||
| 1358 | local_save_flags(flags); | 1457 | local_save_flags(flags); |
| 1359 | 1458 | ||
| 1360 | event = trace_current_buffer_lock_reserve(TRACE_FN, sizeof(*entry), | 1459 | event = trace_current_buffer_lock_reserve(&buffer, |
| 1460 | TRACE_FN, sizeof(*entry), | ||
| 1361 | flags, pc); | 1461 | flags, pc); |
| 1362 | if (!event) | 1462 | if (!event) |
| 1363 | goto out; | 1463 | goto out; |
| @@ -1365,7 +1465,7 @@ function_test_events_call(unsigned long ip, unsigned long parent_ip) | |||
| 1365 | entry->ip = ip; | 1465 | entry->ip = ip; |
| 1366 | entry->parent_ip = parent_ip; | 1466 | entry->parent_ip = parent_ip; |
| 1367 | 1467 | ||
| 1368 | trace_nowake_buffer_unlock_commit(event, flags, pc); | 1468 | trace_nowake_buffer_unlock_commit(buffer, event, flags, pc); |
| 1369 | 1469 | ||
| 1370 | out: | 1470 | out: |
| 1371 | atomic_dec(&per_cpu(test_event_disable, cpu)); | 1471 | atomic_dec(&per_cpu(test_event_disable, cpu)); |
| @@ -1392,10 +1492,10 @@ static __init void event_trace_self_test_with_function(void) | |||
| 1392 | 1492 | ||
| 1393 | static __init int event_trace_self_tests_init(void) | 1493 | static __init int event_trace_self_tests_init(void) |
| 1394 | { | 1494 | { |
| 1395 | 1495 | if (!tracing_selftest_disabled) { | |
| 1396 | event_trace_self_tests(); | 1496 | event_trace_self_tests(); |
| 1397 | 1497 | event_trace_self_test_with_function(); | |
| 1398 | event_trace_self_test_with_function(); | 1498 | } |
| 1399 | 1499 | ||
| 1400 | return 0; | 1500 | return 0; |
| 1401 | } | 1501 | } |
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c index f32dc9d1ea7b..93660fbbf629 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c | |||
| @@ -163,6 +163,20 @@ static int filter_pred_string(struct filter_pred *pred, void *event, | |||
| 163 | return match; | 163 | return match; |
| 164 | } | 164 | } |
| 165 | 165 | ||
| 166 | /* Filter predicate for char * pointers */ | ||
| 167 | static int filter_pred_pchar(struct filter_pred *pred, void *event, | ||
| 168 | int val1, int val2) | ||
| 169 | { | ||
| 170 | char **addr = (char **)(event + pred->offset); | ||
| 171 | int cmp, match; | ||
| 172 | |||
| 173 | cmp = strncmp(*addr, pred->str_val, pred->str_len); | ||
| 174 | |||
| 175 | match = (!cmp) ^ pred->not; | ||
| 176 | |||
| 177 | return match; | ||
| 178 | } | ||
| 179 | |||
| 166 | /* | 180 | /* |
| 167 | * Filter predicate for dynamic sized arrays of characters. | 181 | * Filter predicate for dynamic sized arrays of characters. |
| 168 | * These are implemented through a list of strings at the end | 182 | * These are implemented through a list of strings at the end |
| @@ -176,11 +190,13 @@ static int filter_pred_string(struct filter_pred *pred, void *event, | |||
| 176 | static int filter_pred_strloc(struct filter_pred *pred, void *event, | 190 | static int filter_pred_strloc(struct filter_pred *pred, void *event, |
| 177 | int val1, int val2) | 191 | int val1, int val2) |
| 178 | { | 192 | { |
| 179 | unsigned short str_loc = *(unsigned short *)(event + pred->offset); | 193 | u32 str_item = *(u32 *)(event + pred->offset); |
| 194 | int str_loc = str_item & 0xffff; | ||
| 195 | int str_len = str_item >> 16; | ||
| 180 | char *addr = (char *)(event + str_loc); | 196 | char *addr = (char *)(event + str_loc); |
| 181 | int cmp, match; | 197 | int cmp, match; |
| 182 | 198 | ||
| 183 | cmp = strncmp(addr, pred->str_val, pred->str_len); | 199 | cmp = strncmp(addr, pred->str_val, str_len); |
| 184 | 200 | ||
| 185 | match = (!cmp) ^ pred->not; | 201 | match = (!cmp) ^ pred->not; |
| 186 | 202 | ||
| @@ -293,7 +309,7 @@ void print_event_filter(struct ftrace_event_call *call, struct trace_seq *s) | |||
| 293 | struct event_filter *filter = call->filter; | 309 | struct event_filter *filter = call->filter; |
| 294 | 310 | ||
| 295 | mutex_lock(&event_mutex); | 311 | mutex_lock(&event_mutex); |
| 296 | if (filter->filter_string) | 312 | if (filter && filter->filter_string) |
| 297 | trace_seq_printf(s, "%s\n", filter->filter_string); | 313 | trace_seq_printf(s, "%s\n", filter->filter_string); |
| 298 | else | 314 | else |
| 299 | trace_seq_printf(s, "none\n"); | 315 | trace_seq_printf(s, "none\n"); |
| @@ -306,7 +322,7 @@ void print_subsystem_event_filter(struct event_subsystem *system, | |||
| 306 | struct event_filter *filter = system->filter; | 322 | struct event_filter *filter = system->filter; |
| 307 | 323 | ||
| 308 | mutex_lock(&event_mutex); | 324 | mutex_lock(&event_mutex); |
| 309 | if (filter->filter_string) | 325 | if (filter && filter->filter_string) |
| 310 | trace_seq_printf(s, "%s\n", filter->filter_string); | 326 | trace_seq_printf(s, "%s\n", filter->filter_string); |
| 311 | else | 327 | else |
| 312 | trace_seq_printf(s, "none\n"); | 328 | trace_seq_printf(s, "none\n"); |
| @@ -374,6 +390,9 @@ void destroy_preds(struct ftrace_event_call *call) | |||
| 374 | struct event_filter *filter = call->filter; | 390 | struct event_filter *filter = call->filter; |
| 375 | int i; | 391 | int i; |
| 376 | 392 | ||
| 393 | if (!filter) | ||
| 394 | return; | ||
| 395 | |||
| 377 | for (i = 0; i < MAX_FILTER_PRED; i++) { | 396 | for (i = 0; i < MAX_FILTER_PRED; i++) { |
| 378 | if (filter->preds[i]) | 397 | if (filter->preds[i]) |
| 379 | filter_free_pred(filter->preds[i]); | 398 | filter_free_pred(filter->preds[i]); |
| @@ -384,17 +403,19 @@ void destroy_preds(struct ftrace_event_call *call) | |||
| 384 | call->filter = NULL; | 403 | call->filter = NULL; |
| 385 | } | 404 | } |
| 386 | 405 | ||
| 387 | int init_preds(struct ftrace_event_call *call) | 406 | static int init_preds(struct ftrace_event_call *call) |
| 388 | { | 407 | { |
| 389 | struct event_filter *filter; | 408 | struct event_filter *filter; |
| 390 | struct filter_pred *pred; | 409 | struct filter_pred *pred; |
| 391 | int i; | 410 | int i; |
| 392 | 411 | ||
| 412 | if (call->filter) | ||
| 413 | return 0; | ||
| 414 | |||
| 393 | filter = call->filter = kzalloc(sizeof(*filter), GFP_KERNEL); | 415 | filter = call->filter = kzalloc(sizeof(*filter), GFP_KERNEL); |
| 394 | if (!call->filter) | 416 | if (!call->filter) |
| 395 | return -ENOMEM; | 417 | return -ENOMEM; |
| 396 | 418 | ||
| 397 | call->filter_active = 0; | ||
| 398 | filter->n_preds = 0; | 419 | filter->n_preds = 0; |
| 399 | 420 | ||
| 400 | filter->preds = kzalloc(MAX_FILTER_PRED * sizeof(pred), GFP_KERNEL); | 421 | filter->preds = kzalloc(MAX_FILTER_PRED * sizeof(pred), GFP_KERNEL); |
| @@ -416,30 +437,55 @@ oom: | |||
| 416 | 437 | ||
| 417 | return -ENOMEM; | 438 | return -ENOMEM; |
| 418 | } | 439 | } |
| 419 | EXPORT_SYMBOL_GPL(init_preds); | ||
| 420 | 440 | ||
| 421 | static void filter_free_subsystem_preds(struct event_subsystem *system) | 441 | static int init_subsystem_preds(struct event_subsystem *system) |
| 422 | { | 442 | { |
| 423 | struct event_filter *filter = system->filter; | ||
| 424 | struct ftrace_event_call *call; | 443 | struct ftrace_event_call *call; |
| 425 | int i; | 444 | int err; |
| 426 | 445 | ||
| 427 | if (filter->n_preds) { | 446 | list_for_each_entry(call, &ftrace_events, list) { |
| 428 | for (i = 0; i < filter->n_preds; i++) | 447 | if (!call->define_fields) |
| 429 | filter_free_pred(filter->preds[i]); | 448 | continue; |
| 430 | kfree(filter->preds); | 449 | |
| 431 | filter->preds = NULL; | 450 | if (strcmp(call->system, system->name) != 0) |
| 432 | filter->n_preds = 0; | 451 | continue; |
| 452 | |||
| 453 | err = init_preds(call); | ||
| 454 | if (err) | ||
| 455 | return err; | ||
| 433 | } | 456 | } |
| 434 | 457 | ||
| 458 | return 0; | ||
| 459 | } | ||
| 460 | |||
| 461 | enum { | ||
| 462 | FILTER_DISABLE_ALL, | ||
| 463 | FILTER_INIT_NO_RESET, | ||
| 464 | FILTER_SKIP_NO_RESET, | ||
| 465 | }; | ||
| 466 | |||
| 467 | static void filter_free_subsystem_preds(struct event_subsystem *system, | ||
| 468 | int flag) | ||
| 469 | { | ||
| 470 | struct ftrace_event_call *call; | ||
| 471 | |||
| 435 | list_for_each_entry(call, &ftrace_events, list) { | 472 | list_for_each_entry(call, &ftrace_events, list) { |
| 436 | if (!call->define_fields) | 473 | if (!call->define_fields) |
| 437 | continue; | 474 | continue; |
| 438 | 475 | ||
| 439 | if (!strcmp(call->system, system->name)) { | 476 | if (strcmp(call->system, system->name) != 0) |
| 440 | filter_disable_preds(call); | 477 | continue; |
| 441 | remove_filter_string(call->filter); | 478 | |
| 479 | if (flag == FILTER_INIT_NO_RESET) { | ||
| 480 | call->filter->no_reset = false; | ||
| 481 | continue; | ||
| 442 | } | 482 | } |
| 483 | |||
| 484 | if (flag == FILTER_SKIP_NO_RESET && call->filter->no_reset) | ||
| 485 | continue; | ||
| 486 | |||
| 487 | filter_disable_preds(call); | ||
| 488 | remove_filter_string(call->filter); | ||
| 443 | } | 489 | } |
| 444 | } | 490 | } |
| 445 | 491 | ||
| @@ -468,12 +514,7 @@ static int filter_add_pred_fn(struct filter_parse_state *ps, | |||
| 468 | return 0; | 514 | return 0; |
| 469 | } | 515 | } |
| 470 | 516 | ||
| 471 | enum { | 517 | int filter_assign_type(const char *type) |
| 472 | FILTER_STATIC_STRING = 1, | ||
| 473 | FILTER_DYN_STRING | ||
| 474 | }; | ||
| 475 | |||
| 476 | static int is_string_field(const char *type) | ||
| 477 | { | 518 | { |
| 478 | if (strstr(type, "__data_loc") && strstr(type, "char")) | 519 | if (strstr(type, "__data_loc") && strstr(type, "char")) |
| 479 | return FILTER_DYN_STRING; | 520 | return FILTER_DYN_STRING; |
| @@ -481,12 +522,19 @@ static int is_string_field(const char *type) | |||
| 481 | if (strchr(type, '[') && strstr(type, "char")) | 522 | if (strchr(type, '[') && strstr(type, "char")) |
| 482 | return FILTER_STATIC_STRING; | 523 | return FILTER_STATIC_STRING; |
| 483 | 524 | ||
| 484 | return 0; | 525 | return FILTER_OTHER; |
| 526 | } | ||
| 527 | |||
| 528 | static bool is_string_field(struct ftrace_event_field *field) | ||
| 529 | { | ||
| 530 | return field->filter_type == FILTER_DYN_STRING || | ||
| 531 | field->filter_type == FILTER_STATIC_STRING || | ||
| 532 | field->filter_type == FILTER_PTR_STRING; | ||
| 485 | } | 533 | } |
| 486 | 534 | ||
| 487 | static int is_legal_op(struct ftrace_event_field *field, int op) | 535 | static int is_legal_op(struct ftrace_event_field *field, int op) |
| 488 | { | 536 | { |
| 489 | if (is_string_field(field->type) && (op != OP_EQ && op != OP_NE)) | 537 | if (is_string_field(field) && (op != OP_EQ && op != OP_NE)) |
| 490 | return 0; | 538 | return 0; |
| 491 | 539 | ||
| 492 | return 1; | 540 | return 1; |
| @@ -537,22 +585,24 @@ static filter_pred_fn_t select_comparison_fn(int op, int field_size, | |||
| 537 | 585 | ||
| 538 | static int filter_add_pred(struct filter_parse_state *ps, | 586 | static int filter_add_pred(struct filter_parse_state *ps, |
| 539 | struct ftrace_event_call *call, | 587 | struct ftrace_event_call *call, |
| 540 | struct filter_pred *pred) | 588 | struct filter_pred *pred, |
| 589 | bool dry_run) | ||
| 541 | { | 590 | { |
| 542 | struct ftrace_event_field *field; | 591 | struct ftrace_event_field *field; |
| 543 | filter_pred_fn_t fn; | 592 | filter_pred_fn_t fn; |
| 544 | unsigned long long val; | 593 | unsigned long long val; |
| 545 | int string_type; | ||
| 546 | int ret; | 594 | int ret; |
| 547 | 595 | ||
| 548 | pred->fn = filter_pred_none; | 596 | pred->fn = filter_pred_none; |
| 549 | 597 | ||
| 550 | if (pred->op == OP_AND) { | 598 | if (pred->op == OP_AND) { |
| 551 | pred->pop_n = 2; | 599 | pred->pop_n = 2; |
| 552 | return filter_add_pred_fn(ps, call, pred, filter_pred_and); | 600 | fn = filter_pred_and; |
| 601 | goto add_pred_fn; | ||
| 553 | } else if (pred->op == OP_OR) { | 602 | } else if (pred->op == OP_OR) { |
| 554 | pred->pop_n = 2; | 603 | pred->pop_n = 2; |
| 555 | return filter_add_pred_fn(ps, call, pred, filter_pred_or); | 604 | fn = filter_pred_or; |
| 605 | goto add_pred_fn; | ||
| 556 | } | 606 | } |
| 557 | 607 | ||
| 558 | field = find_event_field(call, pred->field_name); | 608 | field = find_event_field(call, pred->field_name); |
| @@ -568,16 +618,17 @@ static int filter_add_pred(struct filter_parse_state *ps, | |||
| 568 | return -EINVAL; | 618 | return -EINVAL; |
| 569 | } | 619 | } |
| 570 | 620 | ||
| 571 | string_type = is_string_field(field->type); | 621 | if (is_string_field(field)) { |
| 572 | if (string_type) { | 622 | pred->str_len = field->size; |
| 573 | if (string_type == FILTER_STATIC_STRING) | 623 | |
| 624 | if (field->filter_type == FILTER_STATIC_STRING) | ||
| 574 | fn = filter_pred_string; | 625 | fn = filter_pred_string; |
| 575 | else | 626 | else if (field->filter_type == FILTER_DYN_STRING) |
| 576 | fn = filter_pred_strloc; | 627 | fn = filter_pred_strloc; |
| 577 | pred->str_len = field->size; | 628 | else { |
| 578 | if (pred->op == OP_NE) | 629 | fn = filter_pred_pchar; |
| 579 | pred->not = 1; | 630 | pred->str_len = strlen(pred->str_val); |
| 580 | return filter_add_pred_fn(ps, call, pred, fn); | 631 | } |
| 581 | } else { | 632 | } else { |
| 582 | if (field->is_signed) | 633 | if (field->is_signed) |
| 583 | ret = strict_strtoll(pred->str_val, 0, &val); | 634 | ret = strict_strtoll(pred->str_val, 0, &val); |
| @@ -588,41 +639,33 @@ static int filter_add_pred(struct filter_parse_state *ps, | |||
| 588 | return -EINVAL; | 639 | return -EINVAL; |
| 589 | } | 640 | } |
| 590 | pred->val = val; | 641 | pred->val = val; |
| 591 | } | ||
| 592 | 642 | ||
| 593 | fn = select_comparison_fn(pred->op, field->size, field->is_signed); | 643 | fn = select_comparison_fn(pred->op, field->size, |
| 594 | if (!fn) { | 644 | field->is_signed); |
| 595 | parse_error(ps, FILT_ERR_INVALID_OP, 0); | 645 | if (!fn) { |
| 596 | return -EINVAL; | 646 | parse_error(ps, FILT_ERR_INVALID_OP, 0); |
| 647 | return -EINVAL; | ||
| 648 | } | ||
| 597 | } | 649 | } |
| 598 | 650 | ||
| 599 | if (pred->op == OP_NE) | 651 | if (pred->op == OP_NE) |
| 600 | pred->not = 1; | 652 | pred->not = 1; |
| 601 | 653 | ||
| 602 | return filter_add_pred_fn(ps, call, pred, fn); | 654 | add_pred_fn: |
| 655 | if (!dry_run) | ||
| 656 | return filter_add_pred_fn(ps, call, pred, fn); | ||
| 657 | return 0; | ||
| 603 | } | 658 | } |
| 604 | 659 | ||
| 605 | static int filter_add_subsystem_pred(struct filter_parse_state *ps, | 660 | static int filter_add_subsystem_pred(struct filter_parse_state *ps, |
| 606 | struct event_subsystem *system, | 661 | struct event_subsystem *system, |
| 607 | struct filter_pred *pred, | 662 | struct filter_pred *pred, |
| 608 | char *filter_string) | 663 | char *filter_string, |
| 664 | bool dry_run) | ||
| 609 | { | 665 | { |
| 610 | struct event_filter *filter = system->filter; | ||
| 611 | struct ftrace_event_call *call; | 666 | struct ftrace_event_call *call; |
| 612 | int err = 0; | 667 | int err = 0; |
| 613 | 668 | bool fail = true; | |
| 614 | if (!filter->preds) { | ||
| 615 | filter->preds = kzalloc(MAX_FILTER_PRED * sizeof(pred), | ||
| 616 | GFP_KERNEL); | ||
| 617 | |||
| 618 | if (!filter->preds) | ||
| 619 | return -ENOMEM; | ||
| 620 | } | ||
| 621 | |||
| 622 | if (filter->n_preds == MAX_FILTER_PRED) { | ||
| 623 | parse_error(ps, FILT_ERR_TOO_MANY_PREDS, 0); | ||
| 624 | return -ENOSPC; | ||
| 625 | } | ||
| 626 | 669 | ||
| 627 | list_for_each_entry(call, &ftrace_events, list) { | 670 | list_for_each_entry(call, &ftrace_events, list) { |
| 628 | 671 | ||
| @@ -632,19 +675,24 @@ static int filter_add_subsystem_pred(struct filter_parse_state *ps, | |||
| 632 | if (strcmp(call->system, system->name)) | 675 | if (strcmp(call->system, system->name)) |
| 633 | continue; | 676 | continue; |
| 634 | 677 | ||
| 635 | err = filter_add_pred(ps, call, pred); | 678 | if (call->filter->no_reset) |
| 636 | if (err) { | 679 | continue; |
| 637 | filter_free_subsystem_preds(system); | 680 | |
| 638 | parse_error(ps, FILT_ERR_BAD_SUBSYS_FILTER, 0); | 681 | err = filter_add_pred(ps, call, pred, dry_run); |
| 639 | goto out; | 682 | if (err) |
| 640 | } | 683 | call->filter->no_reset = true; |
| 641 | replace_filter_string(call->filter, filter_string); | 684 | else |
| 685 | fail = false; | ||
| 686 | |||
| 687 | if (!dry_run) | ||
| 688 | replace_filter_string(call->filter, filter_string); | ||
| 642 | } | 689 | } |
| 643 | 690 | ||
| 644 | filter->preds[filter->n_preds] = pred; | 691 | if (fail) { |
| 645 | filter->n_preds++; | 692 | parse_error(ps, FILT_ERR_BAD_SUBSYS_FILTER, 0); |
| 646 | out: | 693 | return err; |
| 647 | return err; | 694 | } |
| 695 | return 0; | ||
| 648 | } | 696 | } |
| 649 | 697 | ||
| 650 | static void parse_init(struct filter_parse_state *ps, | 698 | static void parse_init(struct filter_parse_state *ps, |
| @@ -1003,12 +1051,14 @@ static int check_preds(struct filter_parse_state *ps) | |||
| 1003 | static int replace_preds(struct event_subsystem *system, | 1051 | static int replace_preds(struct event_subsystem *system, |
| 1004 | struct ftrace_event_call *call, | 1052 | struct ftrace_event_call *call, |
| 1005 | struct filter_parse_state *ps, | 1053 | struct filter_parse_state *ps, |
| 1006 | char *filter_string) | 1054 | char *filter_string, |
| 1055 | bool dry_run) | ||
| 1007 | { | 1056 | { |
| 1008 | char *operand1 = NULL, *operand2 = NULL; | 1057 | char *operand1 = NULL, *operand2 = NULL; |
| 1009 | struct filter_pred *pred; | 1058 | struct filter_pred *pred; |
| 1010 | struct postfix_elt *elt; | 1059 | struct postfix_elt *elt; |
| 1011 | int err; | 1060 | int err; |
| 1061 | int n_preds = 0; | ||
| 1012 | 1062 | ||
| 1013 | err = check_preds(ps); | 1063 | err = check_preds(ps); |
| 1014 | if (err) | 1064 | if (err) |
| @@ -1027,24 +1077,14 @@ static int replace_preds(struct event_subsystem *system, | |||
| 1027 | continue; | 1077 | continue; |
| 1028 | } | 1078 | } |
| 1029 | 1079 | ||
| 1080 | if (n_preds++ == MAX_FILTER_PRED) { | ||
| 1081 | parse_error(ps, FILT_ERR_TOO_MANY_PREDS, 0); | ||
| 1082 | return -ENOSPC; | ||
| 1083 | } | ||
| 1084 | |||
| 1030 | if (elt->op == OP_AND || elt->op == OP_OR) { | 1085 | if (elt->op == OP_AND || elt->op == OP_OR) { |
| 1031 | pred = create_logical_pred(elt->op); | 1086 | pred = create_logical_pred(elt->op); |
| 1032 | if (!pred) | 1087 | goto add_pred; |
| 1033 | return -ENOMEM; | ||
| 1034 | if (call) { | ||
| 1035 | err = filter_add_pred(ps, call, pred); | ||
| 1036 | filter_free_pred(pred); | ||
| 1037 | } else { | ||
| 1038 | err = filter_add_subsystem_pred(ps, system, | ||
| 1039 | pred, filter_string); | ||
| 1040 | if (err) | ||
| 1041 | filter_free_pred(pred); | ||
| 1042 | } | ||
| 1043 | if (err) | ||
| 1044 | return err; | ||
| 1045 | |||
| 1046 | operand1 = operand2 = NULL; | ||
| 1047 | continue; | ||
| 1048 | } | 1088 | } |
| 1049 | 1089 | ||
| 1050 | if (!operand1 || !operand2) { | 1090 | if (!operand1 || !operand2) { |
| @@ -1053,17 +1093,15 @@ static int replace_preds(struct event_subsystem *system, | |||
| 1053 | } | 1093 | } |
| 1054 | 1094 | ||
| 1055 | pred = create_pred(elt->op, operand1, operand2); | 1095 | pred = create_pred(elt->op, operand1, operand2); |
| 1096 | add_pred: | ||
| 1056 | if (!pred) | 1097 | if (!pred) |
| 1057 | return -ENOMEM; | 1098 | return -ENOMEM; |
| 1058 | if (call) { | 1099 | if (call) |
| 1059 | err = filter_add_pred(ps, call, pred); | 1100 | err = filter_add_pred(ps, call, pred, false); |
| 1060 | filter_free_pred(pred); | 1101 | else |
| 1061 | } else { | ||
| 1062 | err = filter_add_subsystem_pred(ps, system, pred, | 1102 | err = filter_add_subsystem_pred(ps, system, pred, |
| 1063 | filter_string); | 1103 | filter_string, dry_run); |
| 1064 | if (err) | 1104 | filter_free_pred(pred); |
| 1065 | filter_free_pred(pred); | ||
| 1066 | } | ||
| 1067 | if (err) | 1105 | if (err) |
| 1068 | return err; | 1106 | return err; |
| 1069 | 1107 | ||
| @@ -1081,6 +1119,10 @@ int apply_event_filter(struct ftrace_event_call *call, char *filter_string) | |||
| 1081 | 1119 | ||
| 1082 | mutex_lock(&event_mutex); | 1120 | mutex_lock(&event_mutex); |
| 1083 | 1121 | ||
| 1122 | err = init_preds(call); | ||
| 1123 | if (err) | ||
| 1124 | goto out_unlock; | ||
| 1125 | |||
| 1084 | if (!strcmp(strstrip(filter_string), "0")) { | 1126 | if (!strcmp(strstrip(filter_string), "0")) { |
| 1085 | filter_disable_preds(call); | 1127 | filter_disable_preds(call); |
| 1086 | remove_filter_string(call->filter); | 1128 | remove_filter_string(call->filter); |
| @@ -1103,7 +1145,7 @@ int apply_event_filter(struct ftrace_event_call *call, char *filter_string) | |||
| 1103 | goto out; | 1145 | goto out; |
| 1104 | } | 1146 | } |
| 1105 | 1147 | ||
| 1106 | err = replace_preds(NULL, call, ps, filter_string); | 1148 | err = replace_preds(NULL, call, ps, filter_string, false); |
| 1107 | if (err) | 1149 | if (err) |
| 1108 | append_filter_err(ps, call->filter); | 1150 | append_filter_err(ps, call->filter); |
| 1109 | 1151 | ||
| @@ -1126,8 +1168,12 @@ int apply_subsystem_event_filter(struct event_subsystem *system, | |||
| 1126 | 1168 | ||
| 1127 | mutex_lock(&event_mutex); | 1169 | mutex_lock(&event_mutex); |
| 1128 | 1170 | ||
| 1171 | err = init_subsystem_preds(system); | ||
| 1172 | if (err) | ||
| 1173 | goto out_unlock; | ||
| 1174 | |||
| 1129 | if (!strcmp(strstrip(filter_string), "0")) { | 1175 | if (!strcmp(strstrip(filter_string), "0")) { |
| 1130 | filter_free_subsystem_preds(system); | 1176 | filter_free_subsystem_preds(system, FILTER_DISABLE_ALL); |
| 1131 | remove_filter_string(system->filter); | 1177 | remove_filter_string(system->filter); |
| 1132 | mutex_unlock(&event_mutex); | 1178 | mutex_unlock(&event_mutex); |
| 1133 | return 0; | 1179 | return 0; |
| @@ -1138,7 +1184,6 @@ int apply_subsystem_event_filter(struct event_subsystem *system, | |||
| 1138 | if (!ps) | 1184 | if (!ps) |
| 1139 | goto out_unlock; | 1185 | goto out_unlock; |
| 1140 | 1186 | ||
| 1141 | filter_free_subsystem_preds(system); | ||
| 1142 | replace_filter_string(system->filter, filter_string); | 1187 | replace_filter_string(system->filter, filter_string); |
| 1143 | 1188 | ||
| 1144 | parse_init(ps, filter_ops, filter_string); | 1189 | parse_init(ps, filter_ops, filter_string); |
| @@ -1148,9 +1193,23 @@ int apply_subsystem_event_filter(struct event_subsystem *system, | |||
| 1148 | goto out; | 1193 | goto out; |
| 1149 | } | 1194 | } |
| 1150 | 1195 | ||
| 1151 | err = replace_preds(system, NULL, ps, filter_string); | 1196 | filter_free_subsystem_preds(system, FILTER_INIT_NO_RESET); |
| 1152 | if (err) | 1197 | |
| 1198 | /* try to see the filter can be applied to which events */ | ||
| 1199 | err = replace_preds(system, NULL, ps, filter_string, true); | ||
| 1200 | if (err) { | ||
| 1153 | append_filter_err(ps, system->filter); | 1201 | append_filter_err(ps, system->filter); |
| 1202 | goto out; | ||
| 1203 | } | ||
| 1204 | |||
| 1205 | filter_free_subsystem_preds(system, FILTER_SKIP_NO_RESET); | ||
| 1206 | |||
| 1207 | /* really apply the filter to the events */ | ||
| 1208 | err = replace_preds(system, NULL, ps, filter_string, false); | ||
| 1209 | if (err) { | ||
| 1210 | append_filter_err(ps, system->filter); | ||
| 1211 | filter_free_subsystem_preds(system, 2); | ||
| 1212 | } | ||
| 1154 | 1213 | ||
| 1155 | out: | 1214 | out: |
| 1156 | filter_opstack_clear(ps); | 1215 | filter_opstack_clear(ps); |
diff --git a/kernel/trace/trace_export.c b/kernel/trace/trace_export.c index d06cf898dc86..df1bf6e48bb9 100644 --- a/kernel/trace/trace_export.c +++ b/kernel/trace/trace_export.c | |||
| @@ -60,7 +60,8 @@ extern void __bad_type_size(void); | |||
| 60 | #undef TRACE_EVENT_FORMAT | 60 | #undef TRACE_EVENT_FORMAT |
| 61 | #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \ | 61 | #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \ |
| 62 | static int \ | 62 | static int \ |
| 63 | ftrace_format_##call(struct trace_seq *s) \ | 63 | ftrace_format_##call(struct ftrace_event_call *unused, \ |
| 64 | struct trace_seq *s) \ | ||
| 64 | { \ | 65 | { \ |
| 65 | struct args field; \ | 66 | struct args field; \ |
| 66 | int ret; \ | 67 | int ret; \ |
| @@ -76,7 +77,8 @@ ftrace_format_##call(struct trace_seq *s) \ | |||
| 76 | #define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \ | 77 | #define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \ |
| 77 | tpfmt) \ | 78 | tpfmt) \ |
| 78 | static int \ | 79 | static int \ |
| 79 | ftrace_format_##call(struct trace_seq *s) \ | 80 | ftrace_format_##call(struct ftrace_event_call *unused, \ |
| 81 | struct trace_seq *s) \ | ||
| 80 | { \ | 82 | { \ |
| 81 | struct args field; \ | 83 | struct args field; \ |
| 82 | int ret; \ | 84 | int ret; \ |
| @@ -117,7 +119,7 @@ ftrace_format_##call(struct trace_seq *s) \ | |||
| 117 | 119 | ||
| 118 | #undef TRACE_EVENT_FORMAT | 120 | #undef TRACE_EVENT_FORMAT |
| 119 | #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \ | 121 | #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \ |
| 120 | int ftrace_define_fields_##call(void); \ | 122 | int ftrace_define_fields_##call(struct ftrace_event_call *event_call); \ |
| 121 | static int ftrace_raw_init_event_##call(void); \ | 123 | static int ftrace_raw_init_event_##call(void); \ |
| 122 | \ | 124 | \ |
| 123 | struct ftrace_event_call __used \ | 125 | struct ftrace_event_call __used \ |
| @@ -133,7 +135,6 @@ __attribute__((section("_ftrace_events"))) event_##call = { \ | |||
| 133 | static int ftrace_raw_init_event_##call(void) \ | 135 | static int ftrace_raw_init_event_##call(void) \ |
| 134 | { \ | 136 | { \ |
| 135 | INIT_LIST_HEAD(&event_##call.fields); \ | 137 | INIT_LIST_HEAD(&event_##call.fields); \ |
| 136 | init_preds(&event_##call); \ | ||
| 137 | return 0; \ | 138 | return 0; \ |
| 138 | } \ | 139 | } \ |
| 139 | 140 | ||
| @@ -156,7 +157,8 @@ __attribute__((section("_ftrace_events"))) event_##call = { \ | |||
| 156 | #define TRACE_FIELD(type, item, assign) \ | 157 | #define TRACE_FIELD(type, item, assign) \ |
| 157 | ret = trace_define_field(event_call, #type, #item, \ | 158 | ret = trace_define_field(event_call, #type, #item, \ |
| 158 | offsetof(typeof(field), item), \ | 159 | offsetof(typeof(field), item), \ |
| 159 | sizeof(field.item), is_signed_type(type)); \ | 160 | sizeof(field.item), \ |
| 161 | is_signed_type(type), FILTER_OTHER); \ | ||
| 160 | if (ret) \ | 162 | if (ret) \ |
| 161 | return ret; | 163 | return ret; |
| 162 | 164 | ||
| @@ -164,7 +166,7 @@ __attribute__((section("_ftrace_events"))) event_##call = { \ | |||
| 164 | #define TRACE_FIELD_SPECIAL(type, item, len, cmd) \ | 166 | #define TRACE_FIELD_SPECIAL(type, item, len, cmd) \ |
| 165 | ret = trace_define_field(event_call, #type "[" #len "]", #item, \ | 167 | ret = trace_define_field(event_call, #type "[" #len "]", #item, \ |
| 166 | offsetof(typeof(field), item), \ | 168 | offsetof(typeof(field), item), \ |
| 167 | sizeof(field.item), 0); \ | 169 | sizeof(field.item), 0, FILTER_OTHER); \ |
| 168 | if (ret) \ | 170 | if (ret) \ |
| 169 | return ret; | 171 | return ret; |
| 170 | 172 | ||
| @@ -172,7 +174,8 @@ __attribute__((section("_ftrace_events"))) event_##call = { \ | |||
| 172 | #define TRACE_FIELD_SIGN(type, item, assign, is_signed) \ | 174 | #define TRACE_FIELD_SIGN(type, item, assign, is_signed) \ |
| 173 | ret = trace_define_field(event_call, #type, #item, \ | 175 | ret = trace_define_field(event_call, #type, #item, \ |
| 174 | offsetof(typeof(field), item), \ | 176 | offsetof(typeof(field), item), \ |
| 175 | sizeof(field.item), is_signed); \ | 177 | sizeof(field.item), is_signed, \ |
| 178 | FILTER_OTHER); \ | ||
| 176 | if (ret) \ | 179 | if (ret) \ |
| 177 | return ret; | 180 | return ret; |
| 178 | 181 | ||
| @@ -182,17 +185,14 @@ __attribute__((section("_ftrace_events"))) event_##call = { \ | |||
| 182 | #undef TRACE_EVENT_FORMAT | 185 | #undef TRACE_EVENT_FORMAT |
| 183 | #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \ | 186 | #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \ |
| 184 | int \ | 187 | int \ |
| 185 | ftrace_define_fields_##call(void) \ | 188 | ftrace_define_fields_##call(struct ftrace_event_call *event_call) \ |
| 186 | { \ | 189 | { \ |
| 187 | struct ftrace_event_call *event_call = &event_##call; \ | ||
| 188 | struct args field; \ | 190 | struct args field; \ |
| 189 | int ret; \ | 191 | int ret; \ |
| 190 | \ | 192 | \ |
| 191 | __common_field(unsigned char, type, 0); \ | 193 | ret = trace_define_common_fields(event_call); \ |
| 192 | __common_field(unsigned char, flags, 0); \ | 194 | if (ret) \ |
| 193 | __common_field(unsigned char, preempt_count, 0); \ | 195 | return ret; \ |
| 194 | __common_field(int, pid, 1); \ | ||
| 195 | __common_field(int, tgid, 1); \ | ||
| 196 | \ | 196 | \ |
| 197 | tstruct; \ | 197 | tstruct; \ |
| 198 | \ | 198 | \ |
diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c index 75ef000613c3..5b01b94518fc 100644 --- a/kernel/trace/trace_functions.c +++ b/kernel/trace/trace_functions.c | |||
| @@ -288,11 +288,9 @@ static int | |||
| 288 | ftrace_trace_onoff_print(struct seq_file *m, unsigned long ip, | 288 | ftrace_trace_onoff_print(struct seq_file *m, unsigned long ip, |
| 289 | struct ftrace_probe_ops *ops, void *data) | 289 | struct ftrace_probe_ops *ops, void *data) |
| 290 | { | 290 | { |
| 291 | char str[KSYM_SYMBOL_LEN]; | ||
| 292 | long count = (long)data; | 291 | long count = (long)data; |
| 293 | 292 | ||
| 294 | kallsyms_lookup(ip, NULL, NULL, NULL, str); | 293 | seq_printf(m, "%pf:", (void *)ip); |
| 295 | seq_printf(m, "%s:", str); | ||
| 296 | 294 | ||
| 297 | if (ops == &traceon_probe_ops) | 295 | if (ops == &traceon_probe_ops) |
| 298 | seq_printf(m, "traceon"); | 296 | seq_printf(m, "traceon"); |
diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c index 420ec3487579..b3749a2c3132 100644 --- a/kernel/trace/trace_functions_graph.c +++ b/kernel/trace/trace_functions_graph.c | |||
| @@ -52,7 +52,7 @@ static struct tracer_flags tracer_flags = { | |||
| 52 | .opts = trace_opts | 52 | .opts = trace_opts |
| 53 | }; | 53 | }; |
| 54 | 54 | ||
| 55 | /* pid on the last trace processed */ | 55 | static struct trace_array *graph_array; |
| 56 | 56 | ||
| 57 | 57 | ||
| 58 | /* Add a function return address to the trace stack on thread info.*/ | 58 | /* Add a function return address to the trace stack on thread info.*/ |
| @@ -166,10 +166,123 @@ unsigned long ftrace_return_to_handler(unsigned long frame_pointer) | |||
| 166 | return ret; | 166 | return ret; |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | static int __trace_graph_entry(struct trace_array *tr, | ||
| 170 | struct ftrace_graph_ent *trace, | ||
| 171 | unsigned long flags, | ||
| 172 | int pc) | ||
| 173 | { | ||
| 174 | struct ftrace_event_call *call = &event_funcgraph_entry; | ||
| 175 | struct ring_buffer_event *event; | ||
| 176 | struct ring_buffer *buffer = tr->buffer; | ||
| 177 | struct ftrace_graph_ent_entry *entry; | ||
| 178 | |||
| 179 | if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) | ||
| 180 | return 0; | ||
| 181 | |||
| 182 | event = trace_buffer_lock_reserve(buffer, TRACE_GRAPH_ENT, | ||
| 183 | sizeof(*entry), flags, pc); | ||
| 184 | if (!event) | ||
| 185 | return 0; | ||
| 186 | entry = ring_buffer_event_data(event); | ||
| 187 | entry->graph_ent = *trace; | ||
| 188 | if (!filter_current_check_discard(buffer, call, entry, event)) | ||
| 189 | ring_buffer_unlock_commit(buffer, event); | ||
| 190 | |||
| 191 | return 1; | ||
| 192 | } | ||
| 193 | |||
| 194 | int trace_graph_entry(struct ftrace_graph_ent *trace) | ||
| 195 | { | ||
| 196 | struct trace_array *tr = graph_array; | ||
| 197 | struct trace_array_cpu *data; | ||
| 198 | unsigned long flags; | ||
| 199 | long disabled; | ||
| 200 | int ret; | ||
| 201 | int cpu; | ||
| 202 | int pc; | ||
| 203 | |||
| 204 | if (unlikely(!tr)) | ||
| 205 | return 0; | ||
| 206 | |||
| 207 | if (!ftrace_trace_task(current)) | ||
| 208 | return 0; | ||
| 209 | |||
| 210 | if (!ftrace_graph_addr(trace->func)) | ||
| 211 | return 0; | ||
| 212 | |||
| 213 | local_irq_save(flags); | ||
| 214 | cpu = raw_smp_processor_id(); | ||
| 215 | data = tr->data[cpu]; | ||
| 216 | disabled = atomic_inc_return(&data->disabled); | ||
| 217 | if (likely(disabled == 1)) { | ||
| 218 | pc = preempt_count(); | ||
| 219 | ret = __trace_graph_entry(tr, trace, flags, pc); | ||
| 220 | } else { | ||
| 221 | ret = 0; | ||
| 222 | } | ||
| 223 | /* Only do the atomic if it is not already set */ | ||
| 224 | if (!test_tsk_trace_graph(current)) | ||
| 225 | set_tsk_trace_graph(current); | ||
| 226 | |||
| 227 | atomic_dec(&data->disabled); | ||
| 228 | local_irq_restore(flags); | ||
| 229 | |||
| 230 | return ret; | ||
| 231 | } | ||
| 232 | |||
| 233 | static void __trace_graph_return(struct trace_array *tr, | ||
| 234 | struct ftrace_graph_ret *trace, | ||
| 235 | unsigned long flags, | ||
| 236 | int pc) | ||
| 237 | { | ||
| 238 | struct ftrace_event_call *call = &event_funcgraph_exit; | ||
| 239 | struct ring_buffer_event *event; | ||
| 240 | struct ring_buffer *buffer = tr->buffer; | ||
| 241 | struct ftrace_graph_ret_entry *entry; | ||
| 242 | |||
| 243 | if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) | ||
| 244 | return; | ||
| 245 | |||
| 246 | event = trace_buffer_lock_reserve(buffer, TRACE_GRAPH_RET, | ||
| 247 | sizeof(*entry), flags, pc); | ||
| 248 | if (!event) | ||
| 249 | return; | ||
| 250 | entry = ring_buffer_event_data(event); | ||
| 251 | entry->ret = *trace; | ||
| 252 | if (!filter_current_check_discard(buffer, call, entry, event)) | ||
| 253 | ring_buffer_unlock_commit(buffer, event); | ||
| 254 | } | ||
| 255 | |||
| 256 | void trace_graph_return(struct ftrace_graph_ret *trace) | ||
| 257 | { | ||
| 258 | struct trace_array *tr = graph_array; | ||
| 259 | struct trace_array_cpu *data; | ||
| 260 | unsigned long flags; | ||
| 261 | long disabled; | ||
| 262 | int cpu; | ||
| 263 | int pc; | ||
| 264 | |||
| 265 | local_irq_save(flags); | ||
| 266 | cpu = raw_smp_processor_id(); | ||
| 267 | data = tr->data[cpu]; | ||
| 268 | disabled = atomic_inc_return(&data->disabled); | ||
| 269 | if (likely(disabled == 1)) { | ||
| 270 | pc = preempt_count(); | ||
| 271 | __trace_graph_return(tr, trace, flags, pc); | ||
| 272 | } | ||
| 273 | if (!trace->depth) | ||
| 274 | clear_tsk_trace_graph(current); | ||
| 275 | atomic_dec(&data->disabled); | ||
| 276 | local_irq_restore(flags); | ||
| 277 | } | ||
| 278 | |||
| 169 | static int graph_trace_init(struct trace_array *tr) | 279 | static int graph_trace_init(struct trace_array *tr) |
| 170 | { | 280 | { |
| 171 | int ret = register_ftrace_graph(&trace_graph_return, | 281 | int ret; |
| 172 | &trace_graph_entry); | 282 | |
| 283 | graph_array = tr; | ||
| 284 | ret = register_ftrace_graph(&trace_graph_return, | ||
| 285 | &trace_graph_entry); | ||
| 173 | if (ret) | 286 | if (ret) |
| 174 | return ret; | 287 | return ret; |
| 175 | tracing_start_cmdline_record(); | 288 | tracing_start_cmdline_record(); |
| @@ -177,49 +290,30 @@ static int graph_trace_init(struct trace_array *tr) | |||
| 177 | return 0; | 290 | return 0; |
| 178 | } | 291 | } |
| 179 | 292 | ||
| 293 | void set_graph_array(struct trace_array *tr) | ||
| 294 | { | ||
| 295 | graph_array = tr; | ||
| 296 | } | ||
| 297 | |||
| 180 | static void graph_trace_reset(struct trace_array *tr) | 298 | static void graph_trace_reset(struct trace_array *tr) |
| 181 | { | 299 | { |
| 182 | tracing_stop_cmdline_record(); | 300 | tracing_stop_cmdline_record(); |
| 183 | unregister_ftrace_graph(); | 301 | unregister_ftrace_graph(); |
| 184 | } | 302 | } |
| 185 | 303 | ||
| 186 | static inline int log10_cpu(int nb) | 304 | static int max_bytes_for_cpu; |
| 187 | { | ||
| 188 | if (nb / 100) | ||
| 189 | return 3; | ||
| 190 | if (nb / 10) | ||
| 191 | return 2; | ||
| 192 | return 1; | ||
| 193 | } | ||
| 194 | 305 | ||
| 195 | static enum print_line_t | 306 | static enum print_line_t |
| 196 | print_graph_cpu(struct trace_seq *s, int cpu) | 307 | print_graph_cpu(struct trace_seq *s, int cpu) |
| 197 | { | 308 | { |
| 198 | int i; | ||
| 199 | int ret; | 309 | int ret; |
| 200 | int log10_this = log10_cpu(cpu); | ||
| 201 | int log10_all = log10_cpu(cpumask_weight(cpu_online_mask)); | ||
| 202 | |||
| 203 | 310 | ||
| 204 | /* | 311 | /* |
| 205 | * Start with a space character - to make it stand out | 312 | * Start with a space character - to make it stand out |
| 206 | * to the right a bit when trace output is pasted into | 313 | * to the right a bit when trace output is pasted into |
| 207 | * email: | 314 | * email: |
| 208 | */ | 315 | */ |
| 209 | ret = trace_seq_printf(s, " "); | 316 | ret = trace_seq_printf(s, " %*d) ", max_bytes_for_cpu, cpu); |
| 210 | |||
| 211 | /* | ||
| 212 | * Tricky - we space the CPU field according to the max | ||
| 213 | * number of online CPUs. On a 2-cpu system it would take | ||
| 214 | * a maximum of 1 digit - on a 128 cpu system it would | ||
| 215 | * take up to 3 digits: | ||
| 216 | */ | ||
| 217 | for (i = 0; i < log10_all - log10_this; i++) { | ||
| 218 | ret = trace_seq_printf(s, " "); | ||
| 219 | if (!ret) | ||
| 220 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 221 | } | ||
| 222 | ret = trace_seq_printf(s, "%d) ", cpu); | ||
| 223 | if (!ret) | 317 | if (!ret) |
| 224 | return TRACE_TYPE_PARTIAL_LINE; | 318 | return TRACE_TYPE_PARTIAL_LINE; |
| 225 | 319 | ||
| @@ -565,11 +659,7 @@ print_graph_entry_leaf(struct trace_iterator *iter, | |||
| 565 | return TRACE_TYPE_PARTIAL_LINE; | 659 | return TRACE_TYPE_PARTIAL_LINE; |
| 566 | } | 660 | } |
| 567 | 661 | ||
| 568 | ret = seq_print_ip_sym(s, call->func, 0); | 662 | ret = trace_seq_printf(s, "%pf();\n", (void *)call->func); |
| 569 | if (!ret) | ||
| 570 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 571 | |||
| 572 | ret = trace_seq_printf(s, "();\n"); | ||
| 573 | if (!ret) | 663 | if (!ret) |
| 574 | return TRACE_TYPE_PARTIAL_LINE; | 664 | return TRACE_TYPE_PARTIAL_LINE; |
| 575 | 665 | ||
| @@ -612,11 +702,7 @@ print_graph_entry_nested(struct trace_iterator *iter, | |||
| 612 | return TRACE_TYPE_PARTIAL_LINE; | 702 | return TRACE_TYPE_PARTIAL_LINE; |
| 613 | } | 703 | } |
| 614 | 704 | ||
| 615 | ret = seq_print_ip_sym(s, call->func, 0); | 705 | ret = trace_seq_printf(s, "%pf() {\n", (void *)call->func); |
| 616 | if (!ret) | ||
| 617 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 618 | |||
| 619 | ret = trace_seq_printf(s, "() {\n"); | ||
| 620 | if (!ret) | 706 | if (!ret) |
| 621 | return TRACE_TYPE_PARTIAL_LINE; | 707 | return TRACE_TYPE_PARTIAL_LINE; |
| 622 | 708 | ||
| @@ -934,6 +1020,8 @@ static struct tracer graph_trace __read_mostly = { | |||
| 934 | 1020 | ||
| 935 | static __init int init_graph_trace(void) | 1021 | static __init int init_graph_trace(void) |
| 936 | { | 1022 | { |
| 1023 | max_bytes_for_cpu = snprintf(NULL, 0, "%d", nr_cpu_ids - 1); | ||
| 1024 | |||
| 937 | return register_tracer(&graph_trace); | 1025 | return register_tracer(&graph_trace); |
| 938 | } | 1026 | } |
| 939 | 1027 | ||
diff --git a/kernel/trace/trace_irqsoff.c b/kernel/trace/trace_irqsoff.c index b923d13e2fad..5555b75a0d12 100644 --- a/kernel/trace/trace_irqsoff.c +++ b/kernel/trace/trace_irqsoff.c | |||
| @@ -178,7 +178,6 @@ out_unlock: | |||
| 178 | out: | 178 | out: |
| 179 | data->critical_sequence = max_sequence; | 179 | data->critical_sequence = max_sequence; |
| 180 | data->preempt_timestamp = ftrace_now(cpu); | 180 | data->preempt_timestamp = ftrace_now(cpu); |
| 181 | tracing_reset(tr, cpu); | ||
| 182 | trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc); | 181 | trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc); |
| 183 | } | 182 | } |
| 184 | 183 | ||
| @@ -208,7 +207,6 @@ start_critical_timing(unsigned long ip, unsigned long parent_ip) | |||
| 208 | data->critical_sequence = max_sequence; | 207 | data->critical_sequence = max_sequence; |
| 209 | data->preempt_timestamp = ftrace_now(cpu); | 208 | data->preempt_timestamp = ftrace_now(cpu); |
| 210 | data->critical_start = parent_ip ? : ip; | 209 | data->critical_start = parent_ip ? : ip; |
| 211 | tracing_reset(tr, cpu); | ||
| 212 | 210 | ||
| 213 | local_save_flags(flags); | 211 | local_save_flags(flags); |
| 214 | 212 | ||
| @@ -379,6 +377,7 @@ static void __irqsoff_tracer_init(struct trace_array *tr) | |||
| 379 | irqsoff_trace = tr; | 377 | irqsoff_trace = tr; |
| 380 | /* make sure that the tracer is visible */ | 378 | /* make sure that the tracer is visible */ |
| 381 | smp_wmb(); | 379 | smp_wmb(); |
| 380 | tracing_reset_online_cpus(tr); | ||
| 382 | start_irqsoff_tracer(tr); | 381 | start_irqsoff_tracer(tr); |
| 383 | } | 382 | } |
| 384 | 383 | ||
diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c index d53b45ed0806..c4c9bbda53d3 100644 --- a/kernel/trace/trace_mmiotrace.c +++ b/kernel/trace/trace_mmiotrace.c | |||
| @@ -307,11 +307,12 @@ static void __trace_mmiotrace_rw(struct trace_array *tr, | |||
| 307 | struct trace_array_cpu *data, | 307 | struct trace_array_cpu *data, |
| 308 | struct mmiotrace_rw *rw) | 308 | struct mmiotrace_rw *rw) |
| 309 | { | 309 | { |
| 310 | struct ring_buffer *buffer = tr->buffer; | ||
| 310 | struct ring_buffer_event *event; | 311 | struct ring_buffer_event *event; |
| 311 | struct trace_mmiotrace_rw *entry; | 312 | struct trace_mmiotrace_rw *entry; |
| 312 | int pc = preempt_count(); | 313 | int pc = preempt_count(); |
| 313 | 314 | ||
| 314 | event = trace_buffer_lock_reserve(tr, TRACE_MMIO_RW, | 315 | event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW, |
| 315 | sizeof(*entry), 0, pc); | 316 | sizeof(*entry), 0, pc); |
| 316 | if (!event) { | 317 | if (!event) { |
| 317 | atomic_inc(&dropped_count); | 318 | atomic_inc(&dropped_count); |
| @@ -319,7 +320,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr, | |||
| 319 | } | 320 | } |
| 320 | entry = ring_buffer_event_data(event); | 321 | entry = ring_buffer_event_data(event); |
| 321 | entry->rw = *rw; | 322 | entry->rw = *rw; |
| 322 | trace_buffer_unlock_commit(tr, event, 0, pc); | 323 | trace_buffer_unlock_commit(buffer, event, 0, pc); |
| 323 | } | 324 | } |
| 324 | 325 | ||
| 325 | void mmio_trace_rw(struct mmiotrace_rw *rw) | 326 | void mmio_trace_rw(struct mmiotrace_rw *rw) |
| @@ -333,11 +334,12 @@ static void __trace_mmiotrace_map(struct trace_array *tr, | |||
| 333 | struct trace_array_cpu *data, | 334 | struct trace_array_cpu *data, |
| 334 | struct mmiotrace_map *map) | 335 | struct mmiotrace_map *map) |
| 335 | { | 336 | { |
| 337 | struct ring_buffer *buffer = tr->buffer; | ||
| 336 | struct ring_buffer_event *event; | 338 | struct ring_buffer_event *event; |
| 337 | struct trace_mmiotrace_map *entry; | 339 | struct trace_mmiotrace_map *entry; |
| 338 | int pc = preempt_count(); | 340 | int pc = preempt_count(); |
| 339 | 341 | ||
| 340 | event = trace_buffer_lock_reserve(tr, TRACE_MMIO_MAP, | 342 | event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP, |
| 341 | sizeof(*entry), 0, pc); | 343 | sizeof(*entry), 0, pc); |
| 342 | if (!event) { | 344 | if (!event) { |
| 343 | atomic_inc(&dropped_count); | 345 | atomic_inc(&dropped_count); |
| @@ -345,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr, | |||
| 345 | } | 347 | } |
| 346 | entry = ring_buffer_event_data(event); | 348 | entry = ring_buffer_event_data(event); |
| 347 | entry->map = *map; | 349 | entry->map = *map; |
| 348 | trace_buffer_unlock_commit(tr, event, 0, pc); | 350 | trace_buffer_unlock_commit(buffer, event, 0, pc); |
| 349 | } | 351 | } |
| 350 | 352 | ||
| 351 | void mmio_trace_mapping(struct mmiotrace_map *map) | 353 | void mmio_trace_mapping(struct mmiotrace_map *map) |
diff --git a/kernel/trace/trace_power.c b/kernel/trace/trace_power.c index 8a30d9874cd4..fe1a00f1445a 100644 --- a/kernel/trace/trace_power.c +++ b/kernel/trace/trace_power.c | |||
| @@ -38,6 +38,7 @@ static void probe_power_end(struct power_trace *it) | |||
| 38 | { | 38 | { |
| 39 | struct ftrace_event_call *call = &event_power; | 39 | struct ftrace_event_call *call = &event_power; |
| 40 | struct ring_buffer_event *event; | 40 | struct ring_buffer_event *event; |
| 41 | struct ring_buffer *buffer; | ||
| 41 | struct trace_power *entry; | 42 | struct trace_power *entry; |
| 42 | struct trace_array_cpu *data; | 43 | struct trace_array_cpu *data; |
| 43 | struct trace_array *tr = power_trace; | 44 | struct trace_array *tr = power_trace; |
| @@ -45,18 +46,20 @@ static void probe_power_end(struct power_trace *it) | |||
| 45 | if (!trace_power_enabled) | 46 | if (!trace_power_enabled) |
| 46 | return; | 47 | return; |
| 47 | 48 | ||
| 49 | buffer = tr->buffer; | ||
| 50 | |||
| 48 | preempt_disable(); | 51 | preempt_disable(); |
| 49 | it->end = ktime_get(); | 52 | it->end = ktime_get(); |
| 50 | data = tr->data[smp_processor_id()]; | 53 | data = tr->data[smp_processor_id()]; |
| 51 | 54 | ||
| 52 | event = trace_buffer_lock_reserve(tr, TRACE_POWER, | 55 | event = trace_buffer_lock_reserve(buffer, TRACE_POWER, |
| 53 | sizeof(*entry), 0, 0); | 56 | sizeof(*entry), 0, 0); |
| 54 | if (!event) | 57 | if (!event) |
| 55 | goto out; | 58 | goto out; |
| 56 | entry = ring_buffer_event_data(event); | 59 | entry = ring_buffer_event_data(event); |
| 57 | entry->state_data = *it; | 60 | entry->state_data = *it; |
| 58 | if (!filter_check_discard(call, entry, tr->buffer, event)) | 61 | if (!filter_check_discard(call, entry, buffer, event)) |
| 59 | trace_buffer_unlock_commit(tr, event, 0, 0); | 62 | trace_buffer_unlock_commit(buffer, event, 0, 0); |
| 60 | out: | 63 | out: |
| 61 | preempt_enable(); | 64 | preempt_enable(); |
| 62 | } | 65 | } |
| @@ -66,6 +69,7 @@ static void probe_power_mark(struct power_trace *it, unsigned int type, | |||
| 66 | { | 69 | { |
| 67 | struct ftrace_event_call *call = &event_power; | 70 | struct ftrace_event_call *call = &event_power; |
| 68 | struct ring_buffer_event *event; | 71 | struct ring_buffer_event *event; |
| 72 | struct ring_buffer *buffer; | ||
| 69 | struct trace_power *entry; | 73 | struct trace_power *entry; |
| 70 | struct trace_array_cpu *data; | 74 | struct trace_array_cpu *data; |
| 71 | struct trace_array *tr = power_trace; | 75 | struct trace_array *tr = power_trace; |
| @@ -73,6 +77,8 @@ static void probe_power_mark(struct power_trace *it, unsigned int type, | |||
| 73 | if (!trace_power_enabled) | 77 | if (!trace_power_enabled) |
| 74 | return; | 78 | return; |
| 75 | 79 | ||
| 80 | buffer = tr->buffer; | ||
| 81 | |||
| 76 | memset(it, 0, sizeof(struct power_trace)); | 82 | memset(it, 0, sizeof(struct power_trace)); |
| 77 | it->state = level; | 83 | it->state = level; |
| 78 | it->type = type; | 84 | it->type = type; |
| @@ -81,14 +87,14 @@ static void probe_power_mark(struct power_trace *it, unsigned int type, | |||
| 81 | it->end = it->stamp; | 87 | it->end = it->stamp; |
| 82 | data = tr->data[smp_processor_id()]; | 88 | data = tr->data[smp_processor_id()]; |
| 83 | 89 | ||
| 84 | event = trace_buffer_lock_reserve(tr, TRACE_POWER, | 90 | event = trace_buffer_lock_reserve(buffer, TRACE_POWER, |
| 85 | sizeof(*entry), 0, 0); | 91 | sizeof(*entry), 0, 0); |
| 86 | if (!event) | 92 | if (!event) |
| 87 | goto out; | 93 | goto out; |
| 88 | entry = ring_buffer_event_data(event); | 94 | entry = ring_buffer_event_data(event); |
| 89 | entry->state_data = *it; | 95 | entry->state_data = *it; |
| 90 | if (!filter_check_discard(call, entry, tr->buffer, event)) | 96 | if (!filter_check_discard(call, entry, buffer, event)) |
| 91 | trace_buffer_unlock_commit(tr, event, 0, 0); | 97 | trace_buffer_unlock_commit(buffer, event, 0, 0); |
| 92 | out: | 98 | out: |
| 93 | preempt_enable(); | 99 | preempt_enable(); |
| 94 | } | 100 | } |
| @@ -144,14 +150,12 @@ static void power_trace_reset(struct trace_array *tr) | |||
| 144 | 150 | ||
| 145 | static int power_trace_init(struct trace_array *tr) | 151 | static int power_trace_init(struct trace_array *tr) |
| 146 | { | 152 | { |
| 147 | int cpu; | ||
| 148 | power_trace = tr; | 153 | power_trace = tr; |
| 149 | 154 | ||
| 150 | trace_power_enabled = 1; | 155 | trace_power_enabled = 1; |
| 151 | tracing_power_register(); | 156 | tracing_power_register(); |
| 152 | 157 | ||
| 153 | for_each_cpu(cpu, cpu_possible_mask) | 158 | tracing_reset_online_cpus(tr); |
| 154 | tracing_reset(tr, cpu); | ||
| 155 | return 0; | 159 | return 0; |
| 156 | } | 160 | } |
| 157 | 161 | ||
diff --git a/kernel/trace/trace_sched_switch.c b/kernel/trace/trace_sched_switch.c index a98106dd979c..5fca0f51fde4 100644 --- a/kernel/trace/trace_sched_switch.c +++ b/kernel/trace/trace_sched_switch.c | |||
| @@ -20,6 +20,35 @@ static int sched_ref; | |||
| 20 | static DEFINE_MUTEX(sched_register_mutex); | 20 | static DEFINE_MUTEX(sched_register_mutex); |
| 21 | static int sched_stopped; | 21 | static int sched_stopped; |
| 22 | 22 | ||
| 23 | |||
| 24 | void | ||
| 25 | tracing_sched_switch_trace(struct trace_array *tr, | ||
| 26 | struct task_struct *prev, | ||
| 27 | struct task_struct *next, | ||
| 28 | unsigned long flags, int pc) | ||
| 29 | { | ||
| 30 | struct ftrace_event_call *call = &event_context_switch; | ||
| 31 | struct ring_buffer *buffer = tr->buffer; | ||
| 32 | struct ring_buffer_event *event; | ||
| 33 | struct ctx_switch_entry *entry; | ||
| 34 | |||
| 35 | event = trace_buffer_lock_reserve(buffer, TRACE_CTX, | ||
| 36 | sizeof(*entry), flags, pc); | ||
| 37 | if (!event) | ||
| 38 | return; | ||
| 39 | entry = ring_buffer_event_data(event); | ||
| 40 | entry->prev_pid = prev->pid; | ||
| 41 | entry->prev_prio = prev->prio; | ||
| 42 | entry->prev_state = prev->state; | ||
| 43 | entry->next_pid = next->pid; | ||
| 44 | entry->next_prio = next->prio; | ||
| 45 | entry->next_state = next->state; | ||
| 46 | entry->next_cpu = task_cpu(next); | ||
| 47 | |||
| 48 | if (!filter_check_discard(call, entry, buffer, event)) | ||
| 49 | trace_buffer_unlock_commit(buffer, event, flags, pc); | ||
| 50 | } | ||
| 51 | |||
| 23 | static void | 52 | static void |
| 24 | probe_sched_switch(struct rq *__rq, struct task_struct *prev, | 53 | probe_sched_switch(struct rq *__rq, struct task_struct *prev, |
| 25 | struct task_struct *next) | 54 | struct task_struct *next) |
| @@ -49,6 +78,36 @@ probe_sched_switch(struct rq *__rq, struct task_struct *prev, | |||
| 49 | local_irq_restore(flags); | 78 | local_irq_restore(flags); |
| 50 | } | 79 | } |
| 51 | 80 | ||
| 81 | void | ||
| 82 | tracing_sched_wakeup_trace(struct trace_array *tr, | ||
| 83 | struct task_struct *wakee, | ||
| 84 | struct task_struct *curr, | ||
| 85 | unsigned long flags, int pc) | ||
| 86 | { | ||
| 87 | struct ftrace_event_call *call = &event_wakeup; | ||
| 88 | struct ring_buffer_event *event; | ||
| 89 | struct ctx_switch_entry *entry; | ||
| 90 | struct ring_buffer *buffer = tr->buffer; | ||
| 91 | |||
| 92 | event = trace_buffer_lock_reserve(buffer, TRACE_WAKE, | ||
| 93 | sizeof(*entry), flags, pc); | ||
| 94 | if (!event) | ||
| 95 | return; | ||
| 96 | entry = ring_buffer_event_data(event); | ||
| 97 | entry->prev_pid = curr->pid; | ||
| 98 | entry->prev_prio = curr->prio; | ||
| 99 | entry->prev_state = curr->state; | ||
| 100 | entry->next_pid = wakee->pid; | ||
| 101 | entry->next_prio = wakee->prio; | ||
| 102 | entry->next_state = wakee->state; | ||
| 103 | entry->next_cpu = task_cpu(wakee); | ||
| 104 | |||
| 105 | if (!filter_check_discard(call, entry, buffer, event)) | ||
| 106 | ring_buffer_unlock_commit(buffer, event); | ||
| 107 | ftrace_trace_stack(tr->buffer, flags, 6, pc); | ||
| 108 | ftrace_trace_userstack(tr->buffer, flags, pc); | ||
| 109 | } | ||
| 110 | |||
| 52 | static void | 111 | static void |
| 53 | probe_sched_wakeup(struct rq *__rq, struct task_struct *wakee, int success) | 112 | probe_sched_wakeup(struct rq *__rq, struct task_struct *wakee, int success) |
| 54 | { | 113 | { |
diff --git a/kernel/trace/trace_sched_wakeup.c b/kernel/trace/trace_sched_wakeup.c index eacb27225173..ad69f105a7c6 100644 --- a/kernel/trace/trace_sched_wakeup.c +++ b/kernel/trace/trace_sched_wakeup.c | |||
| @@ -186,11 +186,6 @@ out: | |||
| 186 | 186 | ||
| 187 | static void __wakeup_reset(struct trace_array *tr) | 187 | static void __wakeup_reset(struct trace_array *tr) |
| 188 | { | 188 | { |
| 189 | int cpu; | ||
| 190 | |||
| 191 | for_each_possible_cpu(cpu) | ||
| 192 | tracing_reset(tr, cpu); | ||
| 193 | |||
| 194 | wakeup_cpu = -1; | 189 | wakeup_cpu = -1; |
| 195 | wakeup_prio = -1; | 190 | wakeup_prio = -1; |
| 196 | 191 | ||
| @@ -204,6 +199,8 @@ static void wakeup_reset(struct trace_array *tr) | |||
| 204 | { | 199 | { |
| 205 | unsigned long flags; | 200 | unsigned long flags; |
| 206 | 201 | ||
| 202 | tracing_reset_online_cpus(tr); | ||
| 203 | |||
| 207 | local_irq_save(flags); | 204 | local_irq_save(flags); |
| 208 | __raw_spin_lock(&wakeup_lock); | 205 | __raw_spin_lock(&wakeup_lock); |
| 209 | __wakeup_reset(tr); | 206 | __wakeup_reset(tr); |
diff --git a/kernel/trace/trace_selftest.c b/kernel/trace/trace_selftest.c index 00dd6485bdd7..d2cdbabb4ead 100644 --- a/kernel/trace/trace_selftest.c +++ b/kernel/trace/trace_selftest.c | |||
| @@ -288,6 +288,7 @@ trace_selftest_startup_function_graph(struct tracer *trace, | |||
| 288 | * to detect and recover from possible hangs | 288 | * to detect and recover from possible hangs |
| 289 | */ | 289 | */ |
| 290 | tracing_reset_online_cpus(tr); | 290 | tracing_reset_online_cpus(tr); |
| 291 | set_graph_array(tr); | ||
| 291 | ret = register_ftrace_graph(&trace_graph_return, | 292 | ret = register_ftrace_graph(&trace_graph_return, |
| 292 | &trace_graph_entry_watchdog); | 293 | &trace_graph_entry_watchdog); |
| 293 | if (ret) { | 294 | if (ret) { |
diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c index 6a2a9d484cd6..0f6facb050a1 100644 --- a/kernel/trace/trace_stack.c +++ b/kernel/trace/trace_stack.c | |||
| @@ -186,43 +186,33 @@ static const struct file_operations stack_max_size_fops = { | |||
| 186 | }; | 186 | }; |
| 187 | 187 | ||
| 188 | static void * | 188 | static void * |
| 189 | t_next(struct seq_file *m, void *v, loff_t *pos) | 189 | __next(struct seq_file *m, loff_t *pos) |
| 190 | { | 190 | { |
| 191 | long i; | 191 | long n = *pos - 1; |
| 192 | 192 | ||
| 193 | (*pos)++; | 193 | if (n >= max_stack_trace.nr_entries || stack_dump_trace[n] == ULONG_MAX) |
| 194 | |||
| 195 | if (v == SEQ_START_TOKEN) | ||
| 196 | i = 0; | ||
| 197 | else { | ||
| 198 | i = *(long *)v; | ||
| 199 | i++; | ||
| 200 | } | ||
| 201 | |||
| 202 | if (i >= max_stack_trace.nr_entries || | ||
| 203 | stack_dump_trace[i] == ULONG_MAX) | ||
| 204 | return NULL; | 194 | return NULL; |
| 205 | 195 | ||
| 206 | m->private = (void *)i; | 196 | m->private = (void *)n; |
| 207 | |||
| 208 | return &m->private; | 197 | return &m->private; |
| 209 | } | 198 | } |
| 210 | 199 | ||
| 211 | static void *t_start(struct seq_file *m, loff_t *pos) | 200 | static void * |
| 201 | t_next(struct seq_file *m, void *v, loff_t *pos) | ||
| 212 | { | 202 | { |
| 213 | void *t = SEQ_START_TOKEN; | 203 | (*pos)++; |
| 214 | loff_t l = 0; | 204 | return __next(m, pos); |
| 205 | } | ||
| 215 | 206 | ||
| 207 | static void *t_start(struct seq_file *m, loff_t *pos) | ||
| 208 | { | ||
| 216 | local_irq_disable(); | 209 | local_irq_disable(); |
| 217 | __raw_spin_lock(&max_stack_lock); | 210 | __raw_spin_lock(&max_stack_lock); |
| 218 | 211 | ||
| 219 | if (*pos == 0) | 212 | if (*pos == 0) |
| 220 | return SEQ_START_TOKEN; | 213 | return SEQ_START_TOKEN; |
| 221 | 214 | ||
| 222 | for (; t && l < *pos; t = t_next(m, t, &l)) | 215 | return __next(m, pos); |
| 223 | ; | ||
| 224 | |||
| 225 | return t; | ||
| 226 | } | 216 | } |
| 227 | 217 | ||
| 228 | static void t_stop(struct seq_file *m, void *p) | 218 | static void t_stop(struct seq_file *m, void *p) |
| @@ -234,15 +224,8 @@ static void t_stop(struct seq_file *m, void *p) | |||
| 234 | static int trace_lookup_stack(struct seq_file *m, long i) | 224 | static int trace_lookup_stack(struct seq_file *m, long i) |
| 235 | { | 225 | { |
| 236 | unsigned long addr = stack_dump_trace[i]; | 226 | unsigned long addr = stack_dump_trace[i]; |
| 237 | #ifdef CONFIG_KALLSYMS | ||
| 238 | char str[KSYM_SYMBOL_LEN]; | ||
| 239 | |||
| 240 | sprint_symbol(str, addr); | ||
| 241 | 227 | ||
| 242 | return seq_printf(m, "%s\n", str); | 228 | return seq_printf(m, "%pF\n", (void *)addr); |
| 243 | #else | ||
| 244 | return seq_printf(m, "%p\n", (void*)addr); | ||
| 245 | #endif | ||
| 246 | } | 229 | } |
| 247 | 230 | ||
| 248 | static void print_disabled(struct seq_file *m) | 231 | static void print_disabled(struct seq_file *m) |
diff --git a/kernel/trace/trace_stat.c b/kernel/trace/trace_stat.c index aea321c82fa0..a4bb239eb987 100644 --- a/kernel/trace/trace_stat.c +++ b/kernel/trace/trace_stat.c | |||
| @@ -49,7 +49,8 @@ static struct dentry *stat_dir; | |||
| 49 | * but it will at least advance closer to the next one | 49 | * but it will at least advance closer to the next one |
| 50 | * to be released. | 50 | * to be released. |
| 51 | */ | 51 | */ |
| 52 | static struct rb_node *release_next(struct rb_node *node) | 52 | static struct rb_node *release_next(struct tracer_stat *ts, |
| 53 | struct rb_node *node) | ||
| 53 | { | 54 | { |
| 54 | struct stat_node *snode; | 55 | struct stat_node *snode; |
| 55 | struct rb_node *parent = rb_parent(node); | 56 | struct rb_node *parent = rb_parent(node); |
| @@ -67,6 +68,8 @@ static struct rb_node *release_next(struct rb_node *node) | |||
| 67 | parent->rb_right = NULL; | 68 | parent->rb_right = NULL; |
| 68 | 69 | ||
| 69 | snode = container_of(node, struct stat_node, node); | 70 | snode = container_of(node, struct stat_node, node); |
| 71 | if (ts->stat_release) | ||
| 72 | ts->stat_release(snode->stat); | ||
| 70 | kfree(snode); | 73 | kfree(snode); |
| 71 | 74 | ||
| 72 | return parent; | 75 | return parent; |
| @@ -78,7 +81,7 @@ static void __reset_stat_session(struct stat_session *session) | |||
| 78 | struct rb_node *node = session->stat_root.rb_node; | 81 | struct rb_node *node = session->stat_root.rb_node; |
| 79 | 82 | ||
| 80 | while (node) | 83 | while (node) |
| 81 | node = release_next(node); | 84 | node = release_next(session->ts, node); |
| 82 | 85 | ||
| 83 | session->stat_root = RB_ROOT; | 86 | session->stat_root = RB_ROOT; |
| 84 | } | 87 | } |
| @@ -200,17 +203,21 @@ static void *stat_seq_start(struct seq_file *s, loff_t *pos) | |||
| 200 | { | 203 | { |
| 201 | struct stat_session *session = s->private; | 204 | struct stat_session *session = s->private; |
| 202 | struct rb_node *node; | 205 | struct rb_node *node; |
| 206 | int n = *pos; | ||
| 203 | int i; | 207 | int i; |
| 204 | 208 | ||
| 205 | /* Prevent from tracer switch or rbtree modification */ | 209 | /* Prevent from tracer switch or rbtree modification */ |
| 206 | mutex_lock(&session->stat_mutex); | 210 | mutex_lock(&session->stat_mutex); |
| 207 | 211 | ||
| 208 | /* If we are in the beginning of the file, print the headers */ | 212 | /* If we are in the beginning of the file, print the headers */ |
| 209 | if (!*pos && session->ts->stat_headers) | 213 | if (session->ts->stat_headers) { |
| 210 | return SEQ_START_TOKEN; | 214 | if (n == 0) |
| 215 | return SEQ_START_TOKEN; | ||
| 216 | n--; | ||
| 217 | } | ||
| 211 | 218 | ||
| 212 | node = rb_first(&session->stat_root); | 219 | node = rb_first(&session->stat_root); |
| 213 | for (i = 0; node && i < *pos; i++) | 220 | for (i = 0; node && i < n; i++) |
| 214 | node = rb_next(node); | 221 | node = rb_next(node); |
| 215 | 222 | ||
| 216 | return node; | 223 | return node; |
diff --git a/kernel/trace/trace_stat.h b/kernel/trace/trace_stat.h index f3546a2cd826..8f03914b9a6a 100644 --- a/kernel/trace/trace_stat.h +++ b/kernel/trace/trace_stat.h | |||
| @@ -18,6 +18,8 @@ struct tracer_stat { | |||
| 18 | int (*stat_cmp)(void *p1, void *p2); | 18 | int (*stat_cmp)(void *p1, void *p2); |
| 19 | /* Print a stat entry */ | 19 | /* Print a stat entry */ |
| 20 | int (*stat_show)(struct seq_file *s, void *p); | 20 | int (*stat_show)(struct seq_file *s, void *p); |
| 21 | /* Release an entry */ | ||
| 22 | void (*stat_release)(void *stat); | ||
| 21 | /* Print the headers of your stat entries */ | 23 | /* Print the headers of your stat entries */ |
| 22 | int (*stat_headers)(struct seq_file *s); | 24 | int (*stat_headers)(struct seq_file *s); |
| 23 | }; | 25 | }; |
diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c index 5e579645ac86..8712ce3c6a0e 100644 --- a/kernel/trace/trace_syscalls.c +++ b/kernel/trace/trace_syscalls.c | |||
| @@ -1,30 +1,18 @@ | |||
| 1 | #include <trace/syscall.h> | 1 | #include <trace/syscall.h> |
| 2 | #include <trace/events/syscalls.h> | ||
| 2 | #include <linux/kernel.h> | 3 | #include <linux/kernel.h> |
| 4 | #include <linux/ftrace.h> | ||
| 5 | #include <linux/perf_counter.h> | ||
| 3 | #include <asm/syscall.h> | 6 | #include <asm/syscall.h> |
| 4 | 7 | ||
| 5 | #include "trace_output.h" | 8 | #include "trace_output.h" |
| 6 | #include "trace.h" | 9 | #include "trace.h" |
| 7 | 10 | ||
| 8 | /* Keep a counter of the syscall tracing users */ | ||
| 9 | static int refcount; | ||
| 10 | |||
| 11 | /* Prevent from races on thread flags toggling */ | ||
| 12 | static DEFINE_MUTEX(syscall_trace_lock); | 11 | static DEFINE_MUTEX(syscall_trace_lock); |
| 13 | 12 | static int sys_refcount_enter; | |
| 14 | /* Option to display the parameters types */ | 13 | static int sys_refcount_exit; |
| 15 | enum { | 14 | static DECLARE_BITMAP(enabled_enter_syscalls, NR_syscalls); |
| 16 | TRACE_SYSCALLS_OPT_TYPES = 0x1, | 15 | static DECLARE_BITMAP(enabled_exit_syscalls, NR_syscalls); |
| 17 | }; | ||
| 18 | |||
| 19 | static struct tracer_opt syscalls_opts[] = { | ||
| 20 | { TRACER_OPT(syscall_arg_type, TRACE_SYSCALLS_OPT_TYPES) }, | ||
| 21 | { } | ||
| 22 | }; | ||
| 23 | |||
| 24 | static struct tracer_flags syscalls_flags = { | ||
| 25 | .val = 0, /* By default: no parameters types */ | ||
| 26 | .opts = syscalls_opts | ||
| 27 | }; | ||
| 28 | 16 | ||
| 29 | enum print_line_t | 17 | enum print_line_t |
| 30 | print_syscall_enter(struct trace_iterator *iter, int flags) | 18 | print_syscall_enter(struct trace_iterator *iter, int flags) |
| @@ -35,35 +23,46 @@ print_syscall_enter(struct trace_iterator *iter, int flags) | |||
| 35 | struct syscall_metadata *entry; | 23 | struct syscall_metadata *entry; |
| 36 | int i, ret, syscall; | 24 | int i, ret, syscall; |
| 37 | 25 | ||
| 38 | trace_assign_type(trace, ent); | 26 | trace = (typeof(trace))ent; |
| 39 | |||
| 40 | syscall = trace->nr; | 27 | syscall = trace->nr; |
| 41 | |||
| 42 | entry = syscall_nr_to_meta(syscall); | 28 | entry = syscall_nr_to_meta(syscall); |
| 29 | |||
| 43 | if (!entry) | 30 | if (!entry) |
| 44 | goto end; | 31 | goto end; |
| 45 | 32 | ||
| 33 | if (entry->enter_id != ent->type) { | ||
| 34 | WARN_ON_ONCE(1); | ||
| 35 | goto end; | ||
| 36 | } | ||
| 37 | |||
| 46 | ret = trace_seq_printf(s, "%s(", entry->name); | 38 | ret = trace_seq_printf(s, "%s(", entry->name); |
| 47 | if (!ret) | 39 | if (!ret) |
| 48 | return TRACE_TYPE_PARTIAL_LINE; | 40 | return TRACE_TYPE_PARTIAL_LINE; |
| 49 | 41 | ||
| 50 | for (i = 0; i < entry->nb_args; i++) { | 42 | for (i = 0; i < entry->nb_args; i++) { |
| 51 | /* parameter types */ | 43 | /* parameter types */ |
| 52 | if (syscalls_flags.val & TRACE_SYSCALLS_OPT_TYPES) { | 44 | if (trace_flags & TRACE_ITER_VERBOSE) { |
| 53 | ret = trace_seq_printf(s, "%s ", entry->types[i]); | 45 | ret = trace_seq_printf(s, "%s ", entry->types[i]); |
| 54 | if (!ret) | 46 | if (!ret) |
| 55 | return TRACE_TYPE_PARTIAL_LINE; | 47 | return TRACE_TYPE_PARTIAL_LINE; |
| 56 | } | 48 | } |
| 57 | /* parameter values */ | 49 | /* parameter values */ |
| 58 | ret = trace_seq_printf(s, "%s: %lx%s ", entry->args[i], | 50 | ret = trace_seq_printf(s, "%s: %lx%s", entry->args[i], |
| 59 | trace->args[i], | 51 | trace->args[i], |
| 60 | i == entry->nb_args - 1 ? ")" : ","); | 52 | i == entry->nb_args - 1 ? "" : ", "); |
| 61 | if (!ret) | 53 | if (!ret) |
| 62 | return TRACE_TYPE_PARTIAL_LINE; | 54 | return TRACE_TYPE_PARTIAL_LINE; |
| 63 | } | 55 | } |
| 64 | 56 | ||
| 57 | ret = trace_seq_putc(s, ')'); | ||
| 58 | if (!ret) | ||
| 59 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 60 | |||
| 65 | end: | 61 | end: |
| 66 | trace_seq_printf(s, "\n"); | 62 | ret = trace_seq_putc(s, '\n'); |
| 63 | if (!ret) | ||
| 64 | return TRACE_TYPE_PARTIAL_LINE; | ||
| 65 | |||
| 67 | return TRACE_TYPE_HANDLED; | 66 | return TRACE_TYPE_HANDLED; |
| 68 | } | 67 | } |
| 69 | 68 | ||
| @@ -77,16 +76,20 @@ print_syscall_exit(struct trace_iterator *iter, int flags) | |||
| 77 | struct syscall_metadata *entry; | 76 | struct syscall_metadata *entry; |
| 78 | int ret; | 77 | int ret; |
| 79 | 78 | ||
| 80 | trace_assign_type(trace, ent); | 79 | trace = (typeof(trace))ent; |
| 81 | |||
| 82 | syscall = trace->nr; | 80 | syscall = trace->nr; |
| 83 | |||
| 84 | entry = syscall_nr_to_meta(syscall); | 81 | entry = syscall_nr_to_meta(syscall); |
| 82 | |||
| 85 | if (!entry) { | 83 | if (!entry) { |
| 86 | trace_seq_printf(s, "\n"); | 84 | trace_seq_printf(s, "\n"); |
| 87 | return TRACE_TYPE_HANDLED; | 85 | return TRACE_TYPE_HANDLED; |
| 88 | } | 86 | } |
| 89 | 87 | ||
| 88 | if (entry->exit_id != ent->type) { | ||
| 89 | WARN_ON_ONCE(1); | ||
| 90 | return TRACE_TYPE_UNHANDLED; | ||
| 91 | } | ||
| 92 | |||
| 90 | ret = trace_seq_printf(s, "%s -> 0x%lx\n", entry->name, | 93 | ret = trace_seq_printf(s, "%s -> 0x%lx\n", entry->name, |
| 91 | trace->ret); | 94 | trace->ret); |
| 92 | if (!ret) | 95 | if (!ret) |
| @@ -95,62 +98,140 @@ print_syscall_exit(struct trace_iterator *iter, int flags) | |||
| 95 | return TRACE_TYPE_HANDLED; | 98 | return TRACE_TYPE_HANDLED; |
| 96 | } | 99 | } |
| 97 | 100 | ||
| 98 | void start_ftrace_syscalls(void) | 101 | extern char *__bad_type_size(void); |
| 102 | |||
| 103 | #define SYSCALL_FIELD(type, name) \ | ||
| 104 | sizeof(type) != sizeof(trace.name) ? \ | ||
| 105 | __bad_type_size() : \ | ||
| 106 | #type, #name, offsetof(typeof(trace), name), sizeof(trace.name) | ||
| 107 | |||
| 108 | int syscall_enter_format(struct ftrace_event_call *call, struct trace_seq *s) | ||
| 99 | { | 109 | { |
| 100 | unsigned long flags; | 110 | int i; |
| 101 | struct task_struct *g, *t; | 111 | int nr; |
| 112 | int ret; | ||
| 113 | struct syscall_metadata *entry; | ||
| 114 | struct syscall_trace_enter trace; | ||
| 115 | int offset = offsetof(struct syscall_trace_enter, args); | ||
| 102 | 116 | ||
| 103 | mutex_lock(&syscall_trace_lock); | 117 | nr = syscall_name_to_nr(call->data); |
| 118 | entry = syscall_nr_to_meta(nr); | ||
| 104 | 119 | ||
| 105 | /* Don't enable the flag on the tasks twice */ | 120 | if (!entry) |
| 106 | if (++refcount != 1) | 121 | return 0; |
| 107 | goto unlock; | ||
| 108 | 122 | ||
| 109 | arch_init_ftrace_syscalls(); | 123 | ret = trace_seq_printf(s, "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n", |
| 110 | read_lock_irqsave(&tasklist_lock, flags); | 124 | SYSCALL_FIELD(int, nr)); |
| 125 | if (!ret) | ||
| 126 | return 0; | ||
| 111 | 127 | ||
| 112 | do_each_thread(g, t) { | 128 | for (i = 0; i < entry->nb_args; i++) { |
| 113 | set_tsk_thread_flag(t, TIF_SYSCALL_FTRACE); | 129 | ret = trace_seq_printf(s, "\tfield:%s %s;", entry->types[i], |
| 114 | } while_each_thread(g, t); | 130 | entry->args[i]); |
| 131 | if (!ret) | ||
| 132 | return 0; | ||
| 133 | ret = trace_seq_printf(s, "\toffset:%d;\tsize:%zu;\n", offset, | ||
| 134 | sizeof(unsigned long)); | ||
| 135 | if (!ret) | ||
| 136 | return 0; | ||
| 137 | offset += sizeof(unsigned long); | ||
| 138 | } | ||
| 115 | 139 | ||
| 116 | read_unlock_irqrestore(&tasklist_lock, flags); | 140 | trace_seq_puts(s, "\nprint fmt: \""); |
| 141 | for (i = 0; i < entry->nb_args; i++) { | ||
| 142 | ret = trace_seq_printf(s, "%s: 0x%%0%zulx%s", entry->args[i], | ||
| 143 | sizeof(unsigned long), | ||
| 144 | i == entry->nb_args - 1 ? "" : ", "); | ||
| 145 | if (!ret) | ||
| 146 | return 0; | ||
| 147 | } | ||
| 148 | trace_seq_putc(s, '"'); | ||
| 117 | 149 | ||
| 118 | unlock: | 150 | for (i = 0; i < entry->nb_args; i++) { |
| 119 | mutex_unlock(&syscall_trace_lock); | 151 | ret = trace_seq_printf(s, ", ((unsigned long)(REC->%s))", |
| 152 | entry->args[i]); | ||
| 153 | if (!ret) | ||
| 154 | return 0; | ||
| 155 | } | ||
| 156 | |||
| 157 | return trace_seq_putc(s, '\n'); | ||
| 120 | } | 158 | } |
| 121 | 159 | ||
| 122 | void stop_ftrace_syscalls(void) | 160 | int syscall_exit_format(struct ftrace_event_call *call, struct trace_seq *s) |
| 123 | { | 161 | { |
| 124 | unsigned long flags; | 162 | int ret; |
| 125 | struct task_struct *g, *t; | 163 | struct syscall_trace_exit trace; |
| 126 | 164 | ||
| 127 | mutex_lock(&syscall_trace_lock); | 165 | ret = trace_seq_printf(s, |
| 166 | "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" | ||
| 167 | "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n", | ||
| 168 | SYSCALL_FIELD(int, nr), | ||
| 169 | SYSCALL_FIELD(unsigned long, ret)); | ||
| 170 | if (!ret) | ||
| 171 | return 0; | ||
| 128 | 172 | ||
| 129 | /* There are perhaps still some users */ | 173 | return trace_seq_printf(s, "\nprint fmt: \"0x%%lx\", REC->ret\n"); |
| 130 | if (--refcount) | 174 | } |
| 131 | goto unlock; | ||
| 132 | 175 | ||
| 133 | read_lock_irqsave(&tasklist_lock, flags); | 176 | int syscall_enter_define_fields(struct ftrace_event_call *call) |
| 177 | { | ||
| 178 | struct syscall_trace_enter trace; | ||
| 179 | struct syscall_metadata *meta; | ||
| 180 | int ret; | ||
| 181 | int nr; | ||
| 182 | int i; | ||
| 183 | int offset = offsetof(typeof(trace), args); | ||
| 184 | |||
| 185 | nr = syscall_name_to_nr(call->data); | ||
| 186 | meta = syscall_nr_to_meta(nr); | ||
| 187 | |||
| 188 | if (!meta) | ||
| 189 | return 0; | ||
| 190 | |||
| 191 | ret = trace_define_common_fields(call); | ||
| 192 | if (ret) | ||
| 193 | return ret; | ||
| 194 | |||
| 195 | for (i = 0; i < meta->nb_args; i++) { | ||
| 196 | ret = trace_define_field(call, meta->types[i], | ||
| 197 | meta->args[i], offset, | ||
| 198 | sizeof(unsigned long), 0, | ||
| 199 | FILTER_OTHER); | ||
| 200 | offset += sizeof(unsigned long); | ||
| 201 | } | ||
| 134 | 202 | ||
| 135 | do_each_thread(g, t) { | 203 | return ret; |
| 136 | clear_tsk_thread_flag(t, TIF_SYSCALL_FTRACE); | 204 | } |
| 137 | } while_each_thread(g, t); | ||
| 138 | 205 | ||
| 139 | read_unlock_irqrestore(&tasklist_lock, flags); | 206 | int syscall_exit_define_fields(struct ftrace_event_call *call) |
| 207 | { | ||
| 208 | struct syscall_trace_exit trace; | ||
| 209 | int ret; | ||
| 140 | 210 | ||
| 141 | unlock: | 211 | ret = trace_define_common_fields(call); |
| 142 | mutex_unlock(&syscall_trace_lock); | 212 | if (ret) |
| 213 | return ret; | ||
| 214 | |||
| 215 | ret = trace_define_field(call, SYSCALL_FIELD(unsigned long, ret), 0, | ||
| 216 | FILTER_OTHER); | ||
| 217 | |||
| 218 | return ret; | ||
| 143 | } | 219 | } |
| 144 | 220 | ||
| 145 | void ftrace_syscall_enter(struct pt_regs *regs) | 221 | void ftrace_syscall_enter(struct pt_regs *regs, long id) |
| 146 | { | 222 | { |
| 147 | struct syscall_trace_enter *entry; | 223 | struct syscall_trace_enter *entry; |
| 148 | struct syscall_metadata *sys_data; | 224 | struct syscall_metadata *sys_data; |
| 149 | struct ring_buffer_event *event; | 225 | struct ring_buffer_event *event; |
| 226 | struct ring_buffer *buffer; | ||
| 150 | int size; | 227 | int size; |
| 151 | int syscall_nr; | 228 | int syscall_nr; |
| 152 | 229 | ||
| 153 | syscall_nr = syscall_get_nr(current, regs); | 230 | syscall_nr = syscall_get_nr(current, regs); |
| 231 | if (syscall_nr < 0) | ||
| 232 | return; | ||
| 233 | if (!test_bit(syscall_nr, enabled_enter_syscalls)) | ||
| 234 | return; | ||
| 154 | 235 | ||
| 155 | sys_data = syscall_nr_to_meta(syscall_nr); | 236 | sys_data = syscall_nr_to_meta(syscall_nr); |
| 156 | if (!sys_data) | 237 | if (!sys_data) |
| @@ -158,8 +239,8 @@ void ftrace_syscall_enter(struct pt_regs *regs) | |||
| 158 | 239 | ||
| 159 | size = sizeof(*entry) + sizeof(unsigned long) * sys_data->nb_args; | 240 | size = sizeof(*entry) + sizeof(unsigned long) * sys_data->nb_args; |
| 160 | 241 | ||
| 161 | event = trace_current_buffer_lock_reserve(TRACE_SYSCALL_ENTER, size, | 242 | event = trace_current_buffer_lock_reserve(&buffer, sys_data->enter_id, |
| 162 | 0, 0); | 243 | size, 0, 0); |
| 163 | if (!event) | 244 | if (!event) |
| 164 | return; | 245 | return; |
| 165 | 246 | ||
| @@ -167,24 +248,30 @@ void ftrace_syscall_enter(struct pt_regs *regs) | |||
| 167 | entry->nr = syscall_nr; | 248 | entry->nr = syscall_nr; |
| 168 | syscall_get_arguments(current, regs, 0, sys_data->nb_args, entry->args); | 249 | syscall_get_arguments(current, regs, 0, sys_data->nb_args, entry->args); |
| 169 | 250 | ||
| 170 | trace_current_buffer_unlock_commit(event, 0, 0); | 251 | if (!filter_current_check_discard(buffer, sys_data->enter_event, |
| 171 | trace_wake_up(); | 252 | entry, event)) |
| 253 | trace_current_buffer_unlock_commit(buffer, event, 0, 0); | ||
| 172 | } | 254 | } |
| 173 | 255 | ||
| 174 | void ftrace_syscall_exit(struct pt_regs *regs) | 256 | void ftrace_syscall_exit(struct pt_regs *regs, long ret) |
| 175 | { | 257 | { |
| 176 | struct syscall_trace_exit *entry; | 258 | struct syscall_trace_exit *entry; |
| 177 | struct syscall_metadata *sys_data; | 259 | struct syscall_metadata *sys_data; |
| 178 | struct ring_buffer_event *event; | 260 | struct ring_buffer_event *event; |
| 261 | struct ring_buffer *buffer; | ||
| 179 | int syscall_nr; | 262 | int syscall_nr; |
| 180 | 263 | ||
| 181 | syscall_nr = syscall_get_nr(current, regs); | 264 | syscall_nr = syscall_get_nr(current, regs); |
| 265 | if (syscall_nr < 0) | ||
| 266 | return; | ||
| 267 | if (!test_bit(syscall_nr, enabled_exit_syscalls)) | ||
| 268 | return; | ||
| 182 | 269 | ||
| 183 | sys_data = syscall_nr_to_meta(syscall_nr); | 270 | sys_data = syscall_nr_to_meta(syscall_nr); |
| 184 | if (!sys_data) | 271 | if (!sys_data) |
| 185 | return; | 272 | return; |
| 186 | 273 | ||
| 187 | event = trace_current_buffer_lock_reserve(TRACE_SYSCALL_EXIT, | 274 | event = trace_current_buffer_lock_reserve(&buffer, sys_data->exit_id, |
| 188 | sizeof(*entry), 0, 0); | 275 | sizeof(*entry), 0, 0); |
| 189 | if (!event) | 276 | if (!event) |
| 190 | return; | 277 | return; |
| @@ -193,58 +280,244 @@ void ftrace_syscall_exit(struct pt_regs *regs) | |||
| 193 | entry->nr = syscall_nr; | 280 | entry->nr = syscall_nr; |
| 194 | entry->ret = syscall_get_return_value(current, regs); | 281 | entry->ret = syscall_get_return_value(current, regs); |
| 195 | 282 | ||
| 196 | trace_current_buffer_unlock_commit(event, 0, 0); | 283 | if (!filter_current_check_discard(buffer, sys_data->exit_event, |
| 197 | trace_wake_up(); | 284 | entry, event)) |
| 285 | trace_current_buffer_unlock_commit(buffer, event, 0, 0); | ||
| 198 | } | 286 | } |
| 199 | 287 | ||
| 200 | static int init_syscall_tracer(struct trace_array *tr) | 288 | int reg_event_syscall_enter(void *ptr) |
| 201 | { | 289 | { |
| 202 | start_ftrace_syscalls(); | 290 | int ret = 0; |
| 291 | int num; | ||
| 292 | char *name; | ||
| 293 | |||
| 294 | name = (char *)ptr; | ||
| 295 | num = syscall_name_to_nr(name); | ||
| 296 | if (num < 0 || num >= NR_syscalls) | ||
| 297 | return -ENOSYS; | ||
| 298 | mutex_lock(&syscall_trace_lock); | ||
| 299 | if (!sys_refcount_enter) | ||
| 300 | ret = register_trace_sys_enter(ftrace_syscall_enter); | ||
| 301 | if (ret) { | ||
| 302 | pr_info("event trace: Could not activate" | ||
| 303 | "syscall entry trace point"); | ||
| 304 | } else { | ||
| 305 | set_bit(num, enabled_enter_syscalls); | ||
| 306 | sys_refcount_enter++; | ||
| 307 | } | ||
| 308 | mutex_unlock(&syscall_trace_lock); | ||
| 309 | return ret; | ||
| 310 | } | ||
| 311 | |||
| 312 | void unreg_event_syscall_enter(void *ptr) | ||
| 313 | { | ||
| 314 | int num; | ||
| 315 | char *name; | ||
| 203 | 316 | ||
| 204 | return 0; | 317 | name = (char *)ptr; |
| 318 | num = syscall_name_to_nr(name); | ||
| 319 | if (num < 0 || num >= NR_syscalls) | ||
| 320 | return; | ||
| 321 | mutex_lock(&syscall_trace_lock); | ||
| 322 | sys_refcount_enter--; | ||
| 323 | clear_bit(num, enabled_enter_syscalls); | ||
| 324 | if (!sys_refcount_enter) | ||
| 325 | unregister_trace_sys_enter(ftrace_syscall_enter); | ||
| 326 | mutex_unlock(&syscall_trace_lock); | ||
| 205 | } | 327 | } |
| 206 | 328 | ||
| 207 | static void reset_syscall_tracer(struct trace_array *tr) | 329 | int reg_event_syscall_exit(void *ptr) |
| 208 | { | 330 | { |
| 209 | stop_ftrace_syscalls(); | 331 | int ret = 0; |
| 210 | tracing_reset_online_cpus(tr); | 332 | int num; |
| 333 | char *name; | ||
| 334 | |||
| 335 | name = (char *)ptr; | ||
| 336 | num = syscall_name_to_nr(name); | ||
| 337 | if (num < 0 || num >= NR_syscalls) | ||
| 338 | return -ENOSYS; | ||
| 339 | mutex_lock(&syscall_trace_lock); | ||
| 340 | if (!sys_refcount_exit) | ||
| 341 | ret = register_trace_sys_exit(ftrace_syscall_exit); | ||
| 342 | if (ret) { | ||
| 343 | pr_info("event trace: Could not activate" | ||
| 344 | "syscall exit trace point"); | ||
| 345 | } else { | ||
| 346 | set_bit(num, enabled_exit_syscalls); | ||
| 347 | sys_refcount_exit++; | ||
| 348 | } | ||
| 349 | mutex_unlock(&syscall_trace_lock); | ||
| 350 | return ret; | ||
| 211 | } | 351 | } |
| 212 | 352 | ||
| 213 | static struct trace_event syscall_enter_event = { | 353 | void unreg_event_syscall_exit(void *ptr) |
| 214 | .type = TRACE_SYSCALL_ENTER, | 354 | { |
| 215 | .trace = print_syscall_enter, | 355 | int num; |
| 216 | }; | 356 | char *name; |
| 357 | |||
| 358 | name = (char *)ptr; | ||
| 359 | num = syscall_name_to_nr(name); | ||
| 360 | if (num < 0 || num >= NR_syscalls) | ||
| 361 | return; | ||
| 362 | mutex_lock(&syscall_trace_lock); | ||
| 363 | sys_refcount_exit--; | ||
| 364 | clear_bit(num, enabled_exit_syscalls); | ||
| 365 | if (!sys_refcount_exit) | ||
| 366 | unregister_trace_sys_exit(ftrace_syscall_exit); | ||
| 367 | mutex_unlock(&syscall_trace_lock); | ||
| 368 | } | ||
| 217 | 369 | ||
| 218 | static struct trace_event syscall_exit_event = { | 370 | struct trace_event event_syscall_enter = { |
| 219 | .type = TRACE_SYSCALL_EXIT, | 371 | .trace = print_syscall_enter, |
| 220 | .trace = print_syscall_exit, | ||
| 221 | }; | 372 | }; |
| 222 | 373 | ||
| 223 | static struct tracer syscall_tracer __read_mostly = { | 374 | struct trace_event event_syscall_exit = { |
| 224 | .name = "syscall", | 375 | .trace = print_syscall_exit, |
| 225 | .init = init_syscall_tracer, | ||
| 226 | .reset = reset_syscall_tracer, | ||
| 227 | .flags = &syscalls_flags, | ||
| 228 | }; | 376 | }; |
| 229 | 377 | ||
| 230 | __init int register_ftrace_syscalls(void) | 378 | #ifdef CONFIG_EVENT_PROFILE |
| 379 | |||
| 380 | static DECLARE_BITMAP(enabled_prof_enter_syscalls, NR_syscalls); | ||
| 381 | static DECLARE_BITMAP(enabled_prof_exit_syscalls, NR_syscalls); | ||
| 382 | static int sys_prof_refcount_enter; | ||
| 383 | static int sys_prof_refcount_exit; | ||
| 384 | |||
| 385 | static void prof_syscall_enter(struct pt_regs *regs, long id) | ||
| 231 | { | 386 | { |
| 232 | int ret; | 387 | struct syscall_trace_enter *rec; |
| 388 | struct syscall_metadata *sys_data; | ||
| 389 | int syscall_nr; | ||
| 390 | int size; | ||
| 233 | 391 | ||
| 234 | ret = register_ftrace_event(&syscall_enter_event); | 392 | syscall_nr = syscall_get_nr(current, regs); |
| 235 | if (!ret) { | 393 | if (!test_bit(syscall_nr, enabled_prof_enter_syscalls)) |
| 236 | printk(KERN_WARNING "event %d failed to register\n", | 394 | return; |
| 237 | syscall_enter_event.type); | 395 | |
| 238 | WARN_ON_ONCE(1); | 396 | sys_data = syscall_nr_to_meta(syscall_nr); |
| 397 | if (!sys_data) | ||
| 398 | return; | ||
| 399 | |||
| 400 | /* get the size after alignment with the u32 buffer size field */ | ||
| 401 | size = sizeof(unsigned long) * sys_data->nb_args + sizeof(*rec); | ||
| 402 | size = ALIGN(size + sizeof(u32), sizeof(u64)); | ||
| 403 | size -= sizeof(u32); | ||
| 404 | |||
| 405 | do { | ||
| 406 | char raw_data[size]; | ||
| 407 | |||
| 408 | /* zero the dead bytes from align to not leak stack to user */ | ||
| 409 | *(u64 *)(&raw_data[size - sizeof(u64)]) = 0ULL; | ||
| 410 | |||
| 411 | rec = (struct syscall_trace_enter *) raw_data; | ||
| 412 | tracing_generic_entry_update(&rec->ent, 0, 0); | ||
| 413 | rec->ent.type = sys_data->enter_id; | ||
| 414 | rec->nr = syscall_nr; | ||
| 415 | syscall_get_arguments(current, regs, 0, sys_data->nb_args, | ||
| 416 | (unsigned long *)&rec->args); | ||
| 417 | perf_tpcounter_event(sys_data->enter_id, 0, 1, rec, size); | ||
| 418 | } while(0); | ||
| 419 | } | ||
| 420 | |||
| 421 | int reg_prof_syscall_enter(char *name) | ||
| 422 | { | ||
| 423 | int ret = 0; | ||
| 424 | int num; | ||
| 425 | |||
| 426 | num = syscall_name_to_nr(name); | ||
| 427 | if (num < 0 || num >= NR_syscalls) | ||
| 428 | return -ENOSYS; | ||
| 429 | |||
| 430 | mutex_lock(&syscall_trace_lock); | ||
| 431 | if (!sys_prof_refcount_enter) | ||
| 432 | ret = register_trace_sys_enter(prof_syscall_enter); | ||
| 433 | if (ret) { | ||
| 434 | pr_info("event trace: Could not activate" | ||
| 435 | "syscall entry trace point"); | ||
| 436 | } else { | ||
| 437 | set_bit(num, enabled_prof_enter_syscalls); | ||
| 438 | sys_prof_refcount_enter++; | ||
| 239 | } | 439 | } |
| 440 | mutex_unlock(&syscall_trace_lock); | ||
| 441 | return ret; | ||
| 442 | } | ||
| 240 | 443 | ||
| 241 | ret = register_ftrace_event(&syscall_exit_event); | 444 | void unreg_prof_syscall_enter(char *name) |
| 242 | if (!ret) { | 445 | { |
| 243 | printk(KERN_WARNING "event %d failed to register\n", | 446 | int num; |
| 244 | syscall_exit_event.type); | 447 | |
| 245 | WARN_ON_ONCE(1); | 448 | num = syscall_name_to_nr(name); |
| 449 | if (num < 0 || num >= NR_syscalls) | ||
| 450 | return; | ||
| 451 | |||
| 452 | mutex_lock(&syscall_trace_lock); | ||
| 453 | sys_prof_refcount_enter--; | ||
| 454 | clear_bit(num, enabled_prof_enter_syscalls); | ||
| 455 | if (!sys_prof_refcount_enter) | ||
| 456 | unregister_trace_sys_enter(prof_syscall_enter); | ||
| 457 | mutex_unlock(&syscall_trace_lock); | ||
| 458 | } | ||
| 459 | |||
| 460 | static void prof_syscall_exit(struct pt_regs *regs, long ret) | ||
| 461 | { | ||
| 462 | struct syscall_metadata *sys_data; | ||
| 463 | struct syscall_trace_exit rec; | ||
| 464 | int syscall_nr; | ||
| 465 | |||
| 466 | syscall_nr = syscall_get_nr(current, regs); | ||
| 467 | if (!test_bit(syscall_nr, enabled_prof_exit_syscalls)) | ||
| 468 | return; | ||
| 469 | |||
| 470 | sys_data = syscall_nr_to_meta(syscall_nr); | ||
| 471 | if (!sys_data) | ||
| 472 | return; | ||
| 473 | |||
| 474 | tracing_generic_entry_update(&rec.ent, 0, 0); | ||
| 475 | rec.ent.type = sys_data->exit_id; | ||
| 476 | rec.nr = syscall_nr; | ||
| 477 | rec.ret = syscall_get_return_value(current, regs); | ||
| 478 | |||
| 479 | perf_tpcounter_event(sys_data->exit_id, 0, 1, &rec, sizeof(rec)); | ||
| 480 | } | ||
| 481 | |||
| 482 | int reg_prof_syscall_exit(char *name) | ||
| 483 | { | ||
| 484 | int ret = 0; | ||
| 485 | int num; | ||
| 486 | |||
| 487 | num = syscall_name_to_nr(name); | ||
| 488 | if (num < 0 || num >= NR_syscalls) | ||
| 489 | return -ENOSYS; | ||
| 490 | |||
| 491 | mutex_lock(&syscall_trace_lock); | ||
| 492 | if (!sys_prof_refcount_exit) | ||
| 493 | ret = register_trace_sys_exit(prof_syscall_exit); | ||
| 494 | if (ret) { | ||
| 495 | pr_info("event trace: Could not activate" | ||
| 496 | "syscall entry trace point"); | ||
| 497 | } else { | ||
| 498 | set_bit(num, enabled_prof_exit_syscalls); | ||
| 499 | sys_prof_refcount_exit++; | ||
| 246 | } | 500 | } |
| 501 | mutex_unlock(&syscall_trace_lock); | ||
| 502 | return ret; | ||
| 503 | } | ||
| 247 | 504 | ||
| 248 | return register_tracer(&syscall_tracer); | 505 | void unreg_prof_syscall_exit(char *name) |
| 506 | { | ||
| 507 | int num; | ||
| 508 | |||
| 509 | num = syscall_name_to_nr(name); | ||
| 510 | if (num < 0 || num >= NR_syscalls) | ||
| 511 | return; | ||
| 512 | |||
| 513 | mutex_lock(&syscall_trace_lock); | ||
| 514 | sys_prof_refcount_exit--; | ||
| 515 | clear_bit(num, enabled_prof_exit_syscalls); | ||
| 516 | if (!sys_prof_refcount_exit) | ||
| 517 | unregister_trace_sys_exit(prof_syscall_exit); | ||
| 518 | mutex_unlock(&syscall_trace_lock); | ||
| 249 | } | 519 | } |
| 250 | device_initcall(register_ftrace_syscalls); | 520 | |
| 521 | #endif | ||
| 522 | |||
| 523 | |||
diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c index 97fcea4acce1..40cafb07dffd 100644 --- a/kernel/trace/trace_workqueue.c +++ b/kernel/trace/trace_workqueue.c | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include <trace/events/workqueue.h> | 9 | #include <trace/events/workqueue.h> |
| 10 | #include <linux/list.h> | 10 | #include <linux/list.h> |
| 11 | #include <linux/percpu.h> | 11 | #include <linux/percpu.h> |
| 12 | #include <linux/kref.h> | ||
| 12 | #include "trace_stat.h" | 13 | #include "trace_stat.h" |
| 13 | #include "trace.h" | 14 | #include "trace.h" |
| 14 | 15 | ||
| @@ -16,6 +17,7 @@ | |||
| 16 | /* A cpu workqueue thread */ | 17 | /* A cpu workqueue thread */ |
| 17 | struct cpu_workqueue_stats { | 18 | struct cpu_workqueue_stats { |
| 18 | struct list_head list; | 19 | struct list_head list; |
| 20 | struct kref kref; | ||
| 19 | int cpu; | 21 | int cpu; |
| 20 | pid_t pid; | 22 | pid_t pid; |
| 21 | /* Can be inserted from interrupt or user context, need to be atomic */ | 23 | /* Can be inserted from interrupt or user context, need to be atomic */ |
| @@ -39,6 +41,11 @@ struct workqueue_global_stats { | |||
| 39 | static DEFINE_PER_CPU(struct workqueue_global_stats, all_workqueue_stat); | 41 | static DEFINE_PER_CPU(struct workqueue_global_stats, all_workqueue_stat); |
| 40 | #define workqueue_cpu_stat(cpu) (&per_cpu(all_workqueue_stat, cpu)) | 42 | #define workqueue_cpu_stat(cpu) (&per_cpu(all_workqueue_stat, cpu)) |
| 41 | 43 | ||
| 44 | static void cpu_workqueue_stat_free(struct kref *kref) | ||
| 45 | { | ||
| 46 | kfree(container_of(kref, struct cpu_workqueue_stats, kref)); | ||
| 47 | } | ||
| 48 | |||
| 42 | /* Insertion of a work */ | 49 | /* Insertion of a work */ |
| 43 | static void | 50 | static void |
| 44 | probe_workqueue_insertion(struct task_struct *wq_thread, | 51 | probe_workqueue_insertion(struct task_struct *wq_thread, |
| @@ -96,8 +103,8 @@ static void probe_workqueue_creation(struct task_struct *wq_thread, int cpu) | |||
| 96 | return; | 103 | return; |
| 97 | } | 104 | } |
| 98 | INIT_LIST_HEAD(&cws->list); | 105 | INIT_LIST_HEAD(&cws->list); |
| 106 | kref_init(&cws->kref); | ||
| 99 | cws->cpu = cpu; | 107 | cws->cpu = cpu; |
| 100 | |||
| 101 | cws->pid = wq_thread->pid; | 108 | cws->pid = wq_thread->pid; |
| 102 | 109 | ||
| 103 | spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags); | 110 | spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags); |
| @@ -118,7 +125,7 @@ static void probe_workqueue_destruction(struct task_struct *wq_thread) | |||
| 118 | list) { | 125 | list) { |
| 119 | if (node->pid == wq_thread->pid) { | 126 | if (node->pid == wq_thread->pid) { |
| 120 | list_del(&node->list); | 127 | list_del(&node->list); |
| 121 | kfree(node); | 128 | kref_put(&node->kref, cpu_workqueue_stat_free); |
| 122 | goto found; | 129 | goto found; |
| 123 | } | 130 | } |
| 124 | } | 131 | } |
| @@ -137,9 +144,11 @@ static struct cpu_workqueue_stats *workqueue_stat_start_cpu(int cpu) | |||
| 137 | 144 | ||
| 138 | spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags); | 145 | spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags); |
| 139 | 146 | ||
| 140 | if (!list_empty(&workqueue_cpu_stat(cpu)->list)) | 147 | if (!list_empty(&workqueue_cpu_stat(cpu)->list)) { |
| 141 | ret = list_entry(workqueue_cpu_stat(cpu)->list.next, | 148 | ret = list_entry(workqueue_cpu_stat(cpu)->list.next, |
| 142 | struct cpu_workqueue_stats, list); | 149 | struct cpu_workqueue_stats, list); |
| 150 | kref_get(&ret->kref); | ||
| 151 | } | ||
| 143 | 152 | ||
| 144 | spin_unlock_irqrestore(&workqueue_cpu_stat(cpu)->lock, flags); | 153 | spin_unlock_irqrestore(&workqueue_cpu_stat(cpu)->lock, flags); |
| 145 | 154 | ||
| @@ -162,9 +171,9 @@ static void *workqueue_stat_start(struct tracer_stat *trace) | |||
| 162 | static void *workqueue_stat_next(void *prev, int idx) | 171 | static void *workqueue_stat_next(void *prev, int idx) |
| 163 | { | 172 | { |
| 164 | struct cpu_workqueue_stats *prev_cws = prev; | 173 | struct cpu_workqueue_stats *prev_cws = prev; |
| 174 | struct cpu_workqueue_stats *ret; | ||
| 165 | int cpu = prev_cws->cpu; | 175 | int cpu = prev_cws->cpu; |
| 166 | unsigned long flags; | 176 | unsigned long flags; |
| 167 | void *ret = NULL; | ||
| 168 | 177 | ||
| 169 | spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags); | 178 | spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags); |
| 170 | if (list_is_last(&prev_cws->list, &workqueue_cpu_stat(cpu)->list)) { | 179 | if (list_is_last(&prev_cws->list, &workqueue_cpu_stat(cpu)->list)) { |
| @@ -175,11 +184,14 @@ static void *workqueue_stat_next(void *prev, int idx) | |||
| 175 | return NULL; | 184 | return NULL; |
| 176 | } while (!(ret = workqueue_stat_start_cpu(cpu))); | 185 | } while (!(ret = workqueue_stat_start_cpu(cpu))); |
| 177 | return ret; | 186 | return ret; |
| 187 | } else { | ||
| 188 | ret = list_entry(prev_cws->list.next, | ||
| 189 | struct cpu_workqueue_stats, list); | ||
| 190 | kref_get(&ret->kref); | ||
| 178 | } | 191 | } |
| 179 | spin_unlock_irqrestore(&workqueue_cpu_stat(cpu)->lock, flags); | 192 | spin_unlock_irqrestore(&workqueue_cpu_stat(cpu)->lock, flags); |
| 180 | 193 | ||
| 181 | return list_entry(prev_cws->list.next, struct cpu_workqueue_stats, | 194 | return ret; |
| 182 | list); | ||
| 183 | } | 195 | } |
| 184 | 196 | ||
| 185 | static int workqueue_stat_show(struct seq_file *s, void *p) | 197 | static int workqueue_stat_show(struct seq_file *s, void *p) |
| @@ -203,6 +215,13 @@ static int workqueue_stat_show(struct seq_file *s, void *p) | |||
| 203 | return 0; | 215 | return 0; |
| 204 | } | 216 | } |
| 205 | 217 | ||
| 218 | static void workqueue_stat_release(void *stat) | ||
| 219 | { | ||
| 220 | struct cpu_workqueue_stats *node = stat; | ||
| 221 | |||
| 222 | kref_put(&node->kref, cpu_workqueue_stat_free); | ||
| 223 | } | ||
| 224 | |||
| 206 | static int workqueue_stat_headers(struct seq_file *s) | 225 | static int workqueue_stat_headers(struct seq_file *s) |
| 207 | { | 226 | { |
| 208 | seq_printf(s, "# CPU INSERTED EXECUTED NAME\n"); | 227 | seq_printf(s, "# CPU INSERTED EXECUTED NAME\n"); |
| @@ -215,6 +234,7 @@ struct tracer_stat workqueue_stats __read_mostly = { | |||
| 215 | .stat_start = workqueue_stat_start, | 234 | .stat_start = workqueue_stat_start, |
| 216 | .stat_next = workqueue_stat_next, | 235 | .stat_next = workqueue_stat_next, |
| 217 | .stat_show = workqueue_stat_show, | 236 | .stat_show = workqueue_stat_show, |
| 237 | .stat_release = workqueue_stat_release, | ||
| 218 | .stat_headers = workqueue_stat_headers | 238 | .stat_headers = workqueue_stat_headers |
| 219 | }; | 239 | }; |
| 220 | 240 | ||
diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c index 1ef5d3a601c7..9489a0a9b1be 100644 --- a/kernel/tracepoint.c +++ b/kernel/tracepoint.c | |||
| @@ -24,6 +24,7 @@ | |||
| 24 | #include <linux/tracepoint.h> | 24 | #include <linux/tracepoint.h> |
| 25 | #include <linux/err.h> | 25 | #include <linux/err.h> |
| 26 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
| 27 | #include <linux/sched.h> | ||
| 27 | 28 | ||
| 28 | extern struct tracepoint __start___tracepoints[]; | 29 | extern struct tracepoint __start___tracepoints[]; |
| 29 | extern struct tracepoint __stop___tracepoints[]; | 30 | extern struct tracepoint __stop___tracepoints[]; |
| @@ -242,6 +243,11 @@ static void set_tracepoint(struct tracepoint_entry **entry, | |||
| 242 | { | 243 | { |
| 243 | WARN_ON(strcmp((*entry)->name, elem->name) != 0); | 244 | WARN_ON(strcmp((*entry)->name, elem->name) != 0); |
| 244 | 245 | ||
| 246 | if (elem->regfunc && !elem->state && active) | ||
| 247 | elem->regfunc(); | ||
| 248 | else if (elem->unregfunc && elem->state && !active) | ||
| 249 | elem->unregfunc(); | ||
| 250 | |||
| 245 | /* | 251 | /* |
| 246 | * rcu_assign_pointer has a smp_wmb() which makes sure that the new | 252 | * rcu_assign_pointer has a smp_wmb() which makes sure that the new |
| 247 | * probe callbacks array is consistent before setting a pointer to it. | 253 | * probe callbacks array is consistent before setting a pointer to it. |
| @@ -261,6 +267,9 @@ static void set_tracepoint(struct tracepoint_entry **entry, | |||
| 261 | */ | 267 | */ |
| 262 | static void disable_tracepoint(struct tracepoint *elem) | 268 | static void disable_tracepoint(struct tracepoint *elem) |
| 263 | { | 269 | { |
| 270 | if (elem->unregfunc && elem->state) | ||
| 271 | elem->unregfunc(); | ||
| 272 | |||
| 264 | elem->state = 0; | 273 | elem->state = 0; |
| 265 | rcu_assign_pointer(elem->funcs, NULL); | 274 | rcu_assign_pointer(elem->funcs, NULL); |
| 266 | } | 275 | } |
| @@ -554,9 +563,6 @@ int tracepoint_module_notify(struct notifier_block *self, | |||
| 554 | 563 | ||
| 555 | switch (val) { | 564 | switch (val) { |
| 556 | case MODULE_STATE_COMING: | 565 | case MODULE_STATE_COMING: |
| 557 | tracepoint_update_probe_range(mod->tracepoints, | ||
| 558 | mod->tracepoints + mod->num_tracepoints); | ||
| 559 | break; | ||
| 560 | case MODULE_STATE_GOING: | 566 | case MODULE_STATE_GOING: |
| 561 | tracepoint_update_probe_range(mod->tracepoints, | 567 | tracepoint_update_probe_range(mod->tracepoints, |
| 562 | mod->tracepoints + mod->num_tracepoints); | 568 | mod->tracepoints + mod->num_tracepoints); |
| @@ -577,3 +583,41 @@ static int init_tracepoints(void) | |||
| 577 | __initcall(init_tracepoints); | 583 | __initcall(init_tracepoints); |
| 578 | 584 | ||
| 579 | #endif /* CONFIG_MODULES */ | 585 | #endif /* CONFIG_MODULES */ |
| 586 | |||
| 587 | #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS | ||
| 588 | |||
| 589 | /* NB: reg/unreg are called while guarded with the tracepoints_mutex */ | ||
| 590 | static int sys_tracepoint_refcount; | ||
| 591 | |||
| 592 | void syscall_regfunc(void) | ||
| 593 | { | ||
| 594 | unsigned long flags; | ||
| 595 | struct task_struct *g, *t; | ||
| 596 | |||
| 597 | if (!sys_tracepoint_refcount) { | ||
| 598 | read_lock_irqsave(&tasklist_lock, flags); | ||
| 599 | do_each_thread(g, t) { | ||
| 600 | /* Skip kernel threads. */ | ||
| 601 | if (t->mm) | ||
| 602 | set_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT); | ||
| 603 | } while_each_thread(g, t); | ||
| 604 | read_unlock_irqrestore(&tasklist_lock, flags); | ||
| 605 | } | ||
| 606 | sys_tracepoint_refcount++; | ||
| 607 | } | ||
| 608 | |||
| 609 | void syscall_unregfunc(void) | ||
| 610 | { | ||
| 611 | unsigned long flags; | ||
| 612 | struct task_struct *g, *t; | ||
| 613 | |||
| 614 | sys_tracepoint_refcount--; | ||
| 615 | if (!sys_tracepoint_refcount) { | ||
| 616 | read_lock_irqsave(&tasklist_lock, flags); | ||
| 617 | do_each_thread(g, t) { | ||
| 618 | clear_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT); | ||
| 619 | } while_each_thread(g, t); | ||
| 620 | read_unlock_irqrestore(&tasklist_lock, flags); | ||
| 621 | } | ||
| 622 | } | ||
| 623 | #endif | ||
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 0668795d8818..addfe2df93b1 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c | |||
| @@ -317,8 +317,6 @@ static int worker_thread(void *__cwq) | |||
| 317 | if (cwq->wq->freezeable) | 317 | if (cwq->wq->freezeable) |
| 318 | set_freezable(); | 318 | set_freezable(); |
| 319 | 319 | ||
| 320 | set_user_nice(current, -5); | ||
| 321 | |||
| 322 | for (;;) { | 320 | for (;;) { |
| 323 | prepare_to_wait(&cwq->more_work, &wait, TASK_INTERRUPTIBLE); | 321 | prepare_to_wait(&cwq->more_work, &wait, TASK_INTERRUPTIBLE); |
| 324 | if (!freezing(current) && | 322 | if (!freezing(current) && |
| @@ -600,7 +598,12 @@ static struct workqueue_struct *keventd_wq __read_mostly; | |||
| 600 | * schedule_work - put work task in global workqueue | 598 | * schedule_work - put work task in global workqueue |
| 601 | * @work: job to be done | 599 | * @work: job to be done |
| 602 | * | 600 | * |
| 603 | * This puts a job in the kernel-global workqueue. | 601 | * Returns zero if @work was already on the kernel-global workqueue and |
| 602 | * non-zero otherwise. | ||
| 603 | * | ||
| 604 | * This puts a job in the kernel-global workqueue if it was not already | ||
| 605 | * queued and leaves it in the same position on the kernel-global | ||
| 606 | * workqueue otherwise. | ||
| 604 | */ | 607 | */ |
| 605 | int schedule_work(struct work_struct *work) | 608 | int schedule_work(struct work_struct *work) |
| 606 | { | 609 | { |
