diff options
Diffstat (limited to 'kernel/timer.c')
-rw-r--r-- | kernel/timer.c | 203 |
1 files changed, 144 insertions, 59 deletions
diff --git a/kernel/timer.c b/kernel/timer.c index dee3f641a7a7..cffffad01c31 100644 --- a/kernel/timer.c +++ b/kernel/timer.c | |||
@@ -491,14 +491,18 @@ static inline void debug_timer_free(struct timer_list *timer) | |||
491 | debug_object_free(timer, &timer_debug_descr); | 491 | debug_object_free(timer, &timer_debug_descr); |
492 | } | 492 | } |
493 | 493 | ||
494 | static void __init_timer(struct timer_list *timer); | 494 | static void __init_timer(struct timer_list *timer, |
495 | const char *name, | ||
496 | struct lock_class_key *key); | ||
495 | 497 | ||
496 | void init_timer_on_stack(struct timer_list *timer) | 498 | void init_timer_on_stack_key(struct timer_list *timer, |
499 | const char *name, | ||
500 | struct lock_class_key *key) | ||
497 | { | 501 | { |
498 | debug_object_init_on_stack(timer, &timer_debug_descr); | 502 | debug_object_init_on_stack(timer, &timer_debug_descr); |
499 | __init_timer(timer); | 503 | __init_timer(timer, name, key); |
500 | } | 504 | } |
501 | EXPORT_SYMBOL_GPL(init_timer_on_stack); | 505 | EXPORT_SYMBOL_GPL(init_timer_on_stack_key); |
502 | 506 | ||
503 | void destroy_timer_on_stack(struct timer_list *timer) | 507 | void destroy_timer_on_stack(struct timer_list *timer) |
504 | { | 508 | { |
@@ -512,7 +516,9 @@ static inline void debug_timer_activate(struct timer_list *timer) { } | |||
512 | static inline void debug_timer_deactivate(struct timer_list *timer) { } | 516 | static inline void debug_timer_deactivate(struct timer_list *timer) { } |
513 | #endif | 517 | #endif |
514 | 518 | ||
515 | static void __init_timer(struct timer_list *timer) | 519 | static void __init_timer(struct timer_list *timer, |
520 | const char *name, | ||
521 | struct lock_class_key *key) | ||
516 | { | 522 | { |
517 | timer->entry.next = NULL; | 523 | timer->entry.next = NULL; |
518 | timer->base = __raw_get_cpu_var(tvec_bases); | 524 | timer->base = __raw_get_cpu_var(tvec_bases); |
@@ -521,28 +527,36 @@ static void __init_timer(struct timer_list *timer) | |||
521 | timer->start_pid = -1; | 527 | timer->start_pid = -1; |
522 | memset(timer->start_comm, 0, TASK_COMM_LEN); | 528 | memset(timer->start_comm, 0, TASK_COMM_LEN); |
523 | #endif | 529 | #endif |
530 | lockdep_init_map(&timer->lockdep_map, name, key, 0); | ||
524 | } | 531 | } |
525 | 532 | ||
526 | /** | 533 | /** |
527 | * init_timer - initialize a timer. | 534 | * init_timer_key - initialize a timer |
528 | * @timer: the timer to be initialized | 535 | * @timer: the timer to be initialized |
536 | * @name: name of the timer | ||
537 | * @key: lockdep class key of the fake lock used for tracking timer | ||
538 | * sync lock dependencies | ||
529 | * | 539 | * |
530 | * init_timer() must be done to a timer prior calling *any* of the | 540 | * init_timer_key() must be done to a timer prior calling *any* of the |
531 | * other timer functions. | 541 | * other timer functions. |
532 | */ | 542 | */ |
533 | void init_timer(struct timer_list *timer) | 543 | void init_timer_key(struct timer_list *timer, |
544 | const char *name, | ||
545 | struct lock_class_key *key) | ||
534 | { | 546 | { |
535 | debug_timer_init(timer); | 547 | debug_timer_init(timer); |
536 | __init_timer(timer); | 548 | __init_timer(timer, name, key); |
537 | } | 549 | } |
538 | EXPORT_SYMBOL(init_timer); | 550 | EXPORT_SYMBOL(init_timer_key); |
539 | 551 | ||
540 | void init_timer_deferrable(struct timer_list *timer) | 552 | void init_timer_deferrable_key(struct timer_list *timer, |
553 | const char *name, | ||
554 | struct lock_class_key *key) | ||
541 | { | 555 | { |
542 | init_timer(timer); | 556 | init_timer_key(timer, name, key); |
543 | timer_set_deferrable(timer); | 557 | timer_set_deferrable(timer); |
544 | } | 558 | } |
545 | EXPORT_SYMBOL(init_timer_deferrable); | 559 | EXPORT_SYMBOL(init_timer_deferrable_key); |
546 | 560 | ||
547 | static inline void detach_timer(struct timer_list *timer, | 561 | static inline void detach_timer(struct timer_list *timer, |
548 | int clear_pending) | 562 | int clear_pending) |
@@ -589,11 +603,14 @@ static struct tvec_base *lock_timer_base(struct timer_list *timer, | |||
589 | } | 603 | } |
590 | } | 604 | } |
591 | 605 | ||
592 | int __mod_timer(struct timer_list *timer, unsigned long expires) | 606 | static inline int |
607 | __mod_timer(struct timer_list *timer, unsigned long expires, bool pending_only) | ||
593 | { | 608 | { |
594 | struct tvec_base *base, *new_base; | 609 | struct tvec_base *base, *new_base; |
595 | unsigned long flags; | 610 | unsigned long flags; |
596 | int ret = 0; | 611 | int ret; |
612 | |||
613 | ret = 0; | ||
597 | 614 | ||
598 | timer_stats_timer_set_start_info(timer); | 615 | timer_stats_timer_set_start_info(timer); |
599 | BUG_ON(!timer->function); | 616 | BUG_ON(!timer->function); |
@@ -603,6 +620,9 @@ int __mod_timer(struct timer_list *timer, unsigned long expires) | |||
603 | if (timer_pending(timer)) { | 620 | if (timer_pending(timer)) { |
604 | detach_timer(timer, 0); | 621 | detach_timer(timer, 0); |
605 | ret = 1; | 622 | ret = 1; |
623 | } else { | ||
624 | if (pending_only) | ||
625 | goto out_unlock; | ||
606 | } | 626 | } |
607 | 627 | ||
608 | debug_timer_activate(timer); | 628 | debug_timer_activate(timer); |
@@ -629,42 +649,28 @@ int __mod_timer(struct timer_list *timer, unsigned long expires) | |||
629 | 649 | ||
630 | timer->expires = expires; | 650 | timer->expires = expires; |
631 | internal_add_timer(base, timer); | 651 | internal_add_timer(base, timer); |
652 | |||
653 | out_unlock: | ||
632 | spin_unlock_irqrestore(&base->lock, flags); | 654 | spin_unlock_irqrestore(&base->lock, flags); |
633 | 655 | ||
634 | return ret; | 656 | return ret; |
635 | } | 657 | } |
636 | 658 | ||
637 | EXPORT_SYMBOL(__mod_timer); | ||
638 | |||
639 | /** | 659 | /** |
640 | * add_timer_on - start a timer on a particular CPU | 660 | * mod_timer_pending - modify a pending timer's timeout |
641 | * @timer: the timer to be added | 661 | * @timer: the pending timer to be modified |
642 | * @cpu: the CPU to start it on | 662 | * @expires: new timeout in jiffies |
643 | * | 663 | * |
644 | * This is not very scalable on SMP. Double adds are not possible. | 664 | * mod_timer_pending() is the same for pending timers as mod_timer(), |
665 | * but will not re-activate and modify already deleted timers. | ||
666 | * | ||
667 | * It is useful for unserialized use of timers. | ||
645 | */ | 668 | */ |
646 | void add_timer_on(struct timer_list *timer, int cpu) | 669 | int mod_timer_pending(struct timer_list *timer, unsigned long expires) |
647 | { | 670 | { |
648 | struct tvec_base *base = per_cpu(tvec_bases, cpu); | 671 | return __mod_timer(timer, expires, true); |
649 | unsigned long flags; | ||
650 | |||
651 | timer_stats_timer_set_start_info(timer); | ||
652 | BUG_ON(timer_pending(timer) || !timer->function); | ||
653 | spin_lock_irqsave(&base->lock, flags); | ||
654 | timer_set_base(timer, base); | ||
655 | debug_timer_activate(timer); | ||
656 | internal_add_timer(base, timer); | ||
657 | /* | ||
658 | * Check whether the other CPU is idle and needs to be | ||
659 | * triggered to reevaluate the timer wheel when nohz is | ||
660 | * active. We are protected against the other CPU fiddling | ||
661 | * with the timer by holding the timer base lock. This also | ||
662 | * makes sure that a CPU on the way to idle can not evaluate | ||
663 | * the timer wheel. | ||
664 | */ | ||
665 | wake_up_idle_cpu(cpu); | ||
666 | spin_unlock_irqrestore(&base->lock, flags); | ||
667 | } | 672 | } |
673 | EXPORT_SYMBOL(mod_timer_pending); | ||
668 | 674 | ||
669 | /** | 675 | /** |
670 | * mod_timer - modify a timer's timeout | 676 | * mod_timer - modify a timer's timeout |
@@ -688,9 +694,6 @@ void add_timer_on(struct timer_list *timer, int cpu) | |||
688 | */ | 694 | */ |
689 | int mod_timer(struct timer_list *timer, unsigned long expires) | 695 | int mod_timer(struct timer_list *timer, unsigned long expires) |
690 | { | 696 | { |
691 | BUG_ON(!timer->function); | ||
692 | |||
693 | timer_stats_timer_set_start_info(timer); | ||
694 | /* | 697 | /* |
695 | * This is a common optimization triggered by the | 698 | * This is a common optimization triggered by the |
696 | * networking code - if the timer is re-modified | 699 | * networking code - if the timer is re-modified |
@@ -699,12 +702,62 @@ int mod_timer(struct timer_list *timer, unsigned long expires) | |||
699 | if (timer->expires == expires && timer_pending(timer)) | 702 | if (timer->expires == expires && timer_pending(timer)) |
700 | return 1; | 703 | return 1; |
701 | 704 | ||
702 | return __mod_timer(timer, expires); | 705 | return __mod_timer(timer, expires, false); |
703 | } | 706 | } |
704 | |||
705 | EXPORT_SYMBOL(mod_timer); | 707 | EXPORT_SYMBOL(mod_timer); |
706 | 708 | ||
707 | /** | 709 | /** |
710 | * add_timer - start a timer | ||
711 | * @timer: the timer to be added | ||
712 | * | ||
713 | * The kernel will do a ->function(->data) callback from the | ||
714 | * timer interrupt at the ->expires point in the future. The | ||
715 | * current time is 'jiffies'. | ||
716 | * | ||
717 | * The timer's ->expires, ->function (and if the handler uses it, ->data) | ||
718 | * fields must be set prior calling this function. | ||
719 | * | ||
720 | * Timers with an ->expires field in the past will be executed in the next | ||
721 | * timer tick. | ||
722 | */ | ||
723 | void add_timer(struct timer_list *timer) | ||
724 | { | ||
725 | BUG_ON(timer_pending(timer)); | ||
726 | mod_timer(timer, timer->expires); | ||
727 | } | ||
728 | EXPORT_SYMBOL(add_timer); | ||
729 | |||
730 | /** | ||
731 | * add_timer_on - start a timer on a particular CPU | ||
732 | * @timer: the timer to be added | ||
733 | * @cpu: the CPU to start it on | ||
734 | * | ||
735 | * This is not very scalable on SMP. Double adds are not possible. | ||
736 | */ | ||
737 | void add_timer_on(struct timer_list *timer, int cpu) | ||
738 | { | ||
739 | struct tvec_base *base = per_cpu(tvec_bases, cpu); | ||
740 | unsigned long flags; | ||
741 | |||
742 | timer_stats_timer_set_start_info(timer); | ||
743 | BUG_ON(timer_pending(timer) || !timer->function); | ||
744 | spin_lock_irqsave(&base->lock, flags); | ||
745 | timer_set_base(timer, base); | ||
746 | debug_timer_activate(timer); | ||
747 | internal_add_timer(base, timer); | ||
748 | /* | ||
749 | * Check whether the other CPU is idle and needs to be | ||
750 | * triggered to reevaluate the timer wheel when nohz is | ||
751 | * active. We are protected against the other CPU fiddling | ||
752 | * with the timer by holding the timer base lock. This also | ||
753 | * makes sure that a CPU on the way to idle can not evaluate | ||
754 | * the timer wheel. | ||
755 | */ | ||
756 | wake_up_idle_cpu(cpu); | ||
757 | spin_unlock_irqrestore(&base->lock, flags); | ||
758 | } | ||
759 | |||
760 | /** | ||
708 | * del_timer - deactive a timer. | 761 | * del_timer - deactive a timer. |
709 | * @timer: the timer to be deactivated | 762 | * @timer: the timer to be deactivated |
710 | * | 763 | * |
@@ -733,7 +786,6 @@ int del_timer(struct timer_list *timer) | |||
733 | 786 | ||
734 | return ret; | 787 | return ret; |
735 | } | 788 | } |
736 | |||
737 | EXPORT_SYMBOL(del_timer); | 789 | EXPORT_SYMBOL(del_timer); |
738 | 790 | ||
739 | #ifdef CONFIG_SMP | 791 | #ifdef CONFIG_SMP |
@@ -767,7 +819,6 @@ out: | |||
767 | 819 | ||
768 | return ret; | 820 | return ret; |
769 | } | 821 | } |
770 | |||
771 | EXPORT_SYMBOL(try_to_del_timer_sync); | 822 | EXPORT_SYMBOL(try_to_del_timer_sync); |
772 | 823 | ||
773 | /** | 824 | /** |
@@ -789,6 +840,15 @@ EXPORT_SYMBOL(try_to_del_timer_sync); | |||
789 | */ | 840 | */ |
790 | int del_timer_sync(struct timer_list *timer) | 841 | int del_timer_sync(struct timer_list *timer) |
791 | { | 842 | { |
843 | #ifdef CONFIG_LOCKDEP | ||
844 | unsigned long flags; | ||
845 | |||
846 | local_irq_save(flags); | ||
847 | lock_map_acquire(&timer->lockdep_map); | ||
848 | lock_map_release(&timer->lockdep_map); | ||
849 | local_irq_restore(flags); | ||
850 | #endif | ||
851 | |||
792 | for (;;) { | 852 | for (;;) { |
793 | int ret = try_to_del_timer_sync(timer); | 853 | int ret = try_to_del_timer_sync(timer); |
794 | if (ret >= 0) | 854 | if (ret >= 0) |
@@ -796,7 +856,6 @@ int del_timer_sync(struct timer_list *timer) | |||
796 | cpu_relax(); | 856 | cpu_relax(); |
797 | } | 857 | } |
798 | } | 858 | } |
799 | |||
800 | EXPORT_SYMBOL(del_timer_sync); | 859 | EXPORT_SYMBOL(del_timer_sync); |
801 | #endif | 860 | #endif |
802 | 861 | ||
@@ -861,10 +920,36 @@ static inline void __run_timers(struct tvec_base *base) | |||
861 | 920 | ||
862 | set_running_timer(base, timer); | 921 | set_running_timer(base, timer); |
863 | detach_timer(timer, 1); | 922 | detach_timer(timer, 1); |
923 | |||
864 | spin_unlock_irq(&base->lock); | 924 | spin_unlock_irq(&base->lock); |
865 | { | 925 | { |
866 | int preempt_count = preempt_count(); | 926 | int preempt_count = preempt_count(); |
927 | |||
928 | #ifdef CONFIG_LOCKDEP | ||
929 | /* | ||
930 | * It is permissible to free the timer from | ||
931 | * inside the function that is called from | ||
932 | * it, this we need to take into account for | ||
933 | * lockdep too. To avoid bogus "held lock | ||
934 | * freed" warnings as well as problems when | ||
935 | * looking into timer->lockdep_map, make a | ||
936 | * copy and use that here. | ||
937 | */ | ||
938 | struct lockdep_map lockdep_map = | ||
939 | timer->lockdep_map; | ||
940 | #endif | ||
941 | /* | ||
942 | * Couple the lock chain with the lock chain at | ||
943 | * del_timer_sync() by acquiring the lock_map | ||
944 | * around the fn() call here and in | ||
945 | * del_timer_sync(). | ||
946 | */ | ||
947 | lock_map_acquire(&lockdep_map); | ||
948 | |||
867 | fn(data); | 949 | fn(data); |
950 | |||
951 | lock_map_release(&lockdep_map); | ||
952 | |||
868 | if (preempt_count != preempt_count()) { | 953 | if (preempt_count != preempt_count()) { |
869 | printk(KERN_ERR "huh, entered %p " | 954 | printk(KERN_ERR "huh, entered %p " |
870 | "with preempt_count %08x, exited" | 955 | "with preempt_count %08x, exited" |
@@ -1129,7 +1214,7 @@ void do_timer(unsigned long ticks) | |||
1129 | * For backwards compatibility? This can be done in libc so Alpha | 1214 | * For backwards compatibility? This can be done in libc so Alpha |
1130 | * and all newer ports shouldn't need it. | 1215 | * and all newer ports shouldn't need it. |
1131 | */ | 1216 | */ |
1132 | asmlinkage unsigned long sys_alarm(unsigned int seconds) | 1217 | SYSCALL_DEFINE1(alarm, unsigned int, seconds) |
1133 | { | 1218 | { |
1134 | return alarm_setitimer(seconds); | 1219 | return alarm_setitimer(seconds); |
1135 | } | 1220 | } |
@@ -1152,7 +1237,7 @@ asmlinkage unsigned long sys_alarm(unsigned int seconds) | |||
1152 | * | 1237 | * |
1153 | * This is SMP safe as current->tgid does not change. | 1238 | * This is SMP safe as current->tgid does not change. |
1154 | */ | 1239 | */ |
1155 | asmlinkage long sys_getpid(void) | 1240 | SYSCALL_DEFINE0(getpid) |
1156 | { | 1241 | { |
1157 | return task_tgid_vnr(current); | 1242 | return task_tgid_vnr(current); |
1158 | } | 1243 | } |
@@ -1163,7 +1248,7 @@ asmlinkage long sys_getpid(void) | |||
1163 | * value of ->real_parent under rcu_read_lock(), see | 1248 | * value of ->real_parent under rcu_read_lock(), see |
1164 | * release_task()->call_rcu(delayed_put_task_struct). | 1249 | * release_task()->call_rcu(delayed_put_task_struct). |
1165 | */ | 1250 | */ |
1166 | asmlinkage long sys_getppid(void) | 1251 | SYSCALL_DEFINE0(getppid) |
1167 | { | 1252 | { |
1168 | int pid; | 1253 | int pid; |
1169 | 1254 | ||
@@ -1174,25 +1259,25 @@ asmlinkage long sys_getppid(void) | |||
1174 | return pid; | 1259 | return pid; |
1175 | } | 1260 | } |
1176 | 1261 | ||
1177 | asmlinkage long sys_getuid(void) | 1262 | SYSCALL_DEFINE0(getuid) |
1178 | { | 1263 | { |
1179 | /* Only we change this so SMP safe */ | 1264 | /* Only we change this so SMP safe */ |
1180 | return current_uid(); | 1265 | return current_uid(); |
1181 | } | 1266 | } |
1182 | 1267 | ||
1183 | asmlinkage long sys_geteuid(void) | 1268 | SYSCALL_DEFINE0(geteuid) |
1184 | { | 1269 | { |
1185 | /* Only we change this so SMP safe */ | 1270 | /* Only we change this so SMP safe */ |
1186 | return current_euid(); | 1271 | return current_euid(); |
1187 | } | 1272 | } |
1188 | 1273 | ||
1189 | asmlinkage long sys_getgid(void) | 1274 | SYSCALL_DEFINE0(getgid) |
1190 | { | 1275 | { |
1191 | /* Only we change this so SMP safe */ | 1276 | /* Only we change this so SMP safe */ |
1192 | return current_gid(); | 1277 | return current_gid(); |
1193 | } | 1278 | } |
1194 | 1279 | ||
1195 | asmlinkage long sys_getegid(void) | 1280 | SYSCALL_DEFINE0(getegid) |
1196 | { | 1281 | { |
1197 | /* Only we change this so SMP safe */ | 1282 | /* Only we change this so SMP safe */ |
1198 | return current_egid(); | 1283 | return current_egid(); |
@@ -1268,7 +1353,7 @@ signed long __sched schedule_timeout(signed long timeout) | |||
1268 | expire = timeout + jiffies; | 1353 | expire = timeout + jiffies; |
1269 | 1354 | ||
1270 | setup_timer_on_stack(&timer, process_timeout, (unsigned long)current); | 1355 | setup_timer_on_stack(&timer, process_timeout, (unsigned long)current); |
1271 | __mod_timer(&timer, expire); | 1356 | __mod_timer(&timer, expire, false); |
1272 | schedule(); | 1357 | schedule(); |
1273 | del_singleshot_timer_sync(&timer); | 1358 | del_singleshot_timer_sync(&timer); |
1274 | 1359 | ||
@@ -1308,7 +1393,7 @@ signed long __sched schedule_timeout_uninterruptible(signed long timeout) | |||
1308 | EXPORT_SYMBOL(schedule_timeout_uninterruptible); | 1393 | EXPORT_SYMBOL(schedule_timeout_uninterruptible); |
1309 | 1394 | ||
1310 | /* Thread ID - the internal kernel "pid" */ | 1395 | /* Thread ID - the internal kernel "pid" */ |
1311 | asmlinkage long sys_gettid(void) | 1396 | SYSCALL_DEFINE0(gettid) |
1312 | { | 1397 | { |
1313 | return task_pid_vnr(current); | 1398 | return task_pid_vnr(current); |
1314 | } | 1399 | } |
@@ -1400,7 +1485,7 @@ out: | |||
1400 | return 0; | 1485 | return 0; |
1401 | } | 1486 | } |
1402 | 1487 | ||
1403 | asmlinkage long sys_sysinfo(struct sysinfo __user *info) | 1488 | SYSCALL_DEFINE1(sysinfo, struct sysinfo __user *, info) |
1404 | { | 1489 | { |
1405 | struct sysinfo val; | 1490 | struct sysinfo val; |
1406 | 1491 | ||