History

debugobjects: Move printk out of db->lock critical sections

The db->lock is a raw spinlock and so the lock hold time is supposed to be short. This will not be the case when printk() is being involved in some of the critical sections. In order to avoid the long hold time, in case some messages need to be printed, the debug_object_is_on_stack() and debug_print_object() calls are now moved out of those critical sections.

Waiman Long committed 7 years ago

Commit d5f34151 parent a7344a61 file · +39 −19Browse files

Showing the changes to lib/debugobjects.c (1 of 1 file). Show all

Unified · Split

lib/debugobjects.c+39−19
@@ -528,6 +528,7 @@ static void · 527 unmodified lines
528__debug_object_init(void *addr, struct debug_obj_descr *descr, int onstack)528__debug_object_init(void *addr, struct debug_obj_descr *descr, int onstack)
529{529{
530 enum debug_obj_state state;530 enum debug_obj_state state;
531 bool check_stack = false;
531 struct debug_bucket *db;532 struct debug_bucket *db;
532 struct debug_obj *obj;533 struct debug_obj *obj;
533 unsigned long flags;534 unsigned long flags;
@@ -547,7 +548,7 @@ __debug_object_init(void *addr, struct debug_obj_descr *descr, int onstack) · 13 unmodified lines
547 debug_objects_oom();548 debug_objects_oom();
548 return;549 return;
549 }550 }
550 debug_object_is_on_stack(addr, onstack);551 check_stack = true;
551 }552 }
552 553
553 switch (obj->state) {554 switch (obj->state) {
@@ -558,20 +559,23 @@ __debug_object_init(void *addr, struct debug_obj_descr *descr, int onstack) · 4 unmodified lines
558 break;559 break;
559 560
560 case ODEBUG_STATE_ACTIVE:561 case ODEBUG_STATE_ACTIVE:
561 debug_print_object(obj, "init");
562 state = obj->state;562 state = obj->state;
563 raw_spin_unlock_irqrestore(&db->lock, flags);563 raw_spin_unlock_irqrestore(&db->lock, flags);
564 debug_print_object(obj, "init");
564 debug_object_fixup(descr->fixup_init, addr, state);565 debug_object_fixup(descr->fixup_init, addr, state);
565 return;566 return;
566 567
567 case ODEBUG_STATE_DESTROYED:568 case ODEBUG_STATE_DESTROYED:
569 raw_spin_unlock_irqrestore(&db->lock, flags);
568 debug_print_object(obj, "init");570 debug_print_object(obj, "init");
569 break;571 return;
570 default:572 default:
571 break;573 break;
572 }574 }
573 575
574 raw_spin_unlock_irqrestore(&db->lock, flags);576 raw_spin_unlock_irqrestore(&db->lock, flags);
577 if (check_stack)
578 debug_object_is_on_stack(addr, onstack);
575}579}
576 580
577/**581/**
@@ -629,6 +633,8 @@ int debug_object_activate(void *addr, struct debug_obj_descr *descr) · 51 unmodified lines
629 633
630 obj = lookup_object(addr, db);634 obj = lookup_object(addr, db);
631 if (obj) {635 if (obj) {
636 bool print_object = false;
637
632 switch (obj->state) {638 switch (obj->state) {
633 case ODEBUG_STATE_INIT:639 case ODEBUG_STATE_INIT:
634 case ODEBUG_STATE_INACTIVE:640 case ODEBUG_STATE_INACTIVE:
@@ -637,14 +643,14 @@ int debug_object_activate(void *addr, struct debug_obj_descr *descr) · 2 unmodified lines
637 break;643 break;
638 644
639 case ODEBUG_STATE_ACTIVE:645 case ODEBUG_STATE_ACTIVE:
640 debug_print_object(obj, "activate");
641 state = obj->state;646 state = obj->state;
642 raw_spin_unlock_irqrestore(&db->lock, flags);647 raw_spin_unlock_irqrestore(&db->lock, flags);
648 debug_print_object(obj, "activate");
643 ret = debug_object_fixup(descr->fixup_activate, addr, state);649 ret = debug_object_fixup(descr->fixup_activate, addr, state);
644 return ret ? 0 : -EINVAL;650 return ret ? 0 : -EINVAL;
645 651
646 case ODEBUG_STATE_DESTROYED:652 case ODEBUG_STATE_DESTROYED:
647 debug_print_object(obj, "activate");653 print_object = true;
648 ret = -EINVAL;654 ret = -EINVAL;
649 break;655 break;
650 default:656 default:
@@ -652,10 +658,13 @@ int debug_object_activate(void *addr, struct debug_obj_descr *descr) · 1 unmodified line
652 break;658 break;
653 }659 }
654 raw_spin_unlock_irqrestore(&db->lock, flags);660 raw_spin_unlock_irqrestore(&db->lock, flags);
661 if (print_object)
662 debug_print_object(obj, "activate");
655 return ret;663 return ret;
656 }664 }
657 665
658 raw_spin_unlock_irqrestore(&db->lock, flags);666 raw_spin_unlock_irqrestore(&db->lock, flags);
667
659 /*668 /*
660 * We are here when a static object is activated. We669 * We are here when a static object is activated. We
661 * let the type specific code confirm whether this is670 * let the type specific code confirm whether this is
@@ -687,6 +696,7 @@ void debug_object_deactivate(void *addr, struct debug_obj_descr *descr) · 25 unmodified lines
687 struct debug_bucket *db;696 struct debug_bucket *db;
688 struct debug_obj *obj;697 struct debug_obj *obj;
689 unsigned long flags;698 unsigned long flags;
699 bool print_object = false;
690 700
691 if (!debug_objects_enabled)701 if (!debug_objects_enabled)
692 return;702 return;
@@ -704,24 +714,27 @@ void debug_object_deactivate(void *addr, struct debug_obj_descr *descr) · 11 unmodified lines
704 if (!obj->astate)714 if (!obj->astate)
705 obj->state = ODEBUG_STATE_INACTIVE;715 obj->state = ODEBUG_STATE_INACTIVE;
706 else716 else
707 debug_print_object(obj, "deactivate");717 print_object = true;
708 break;718 break;
709 719
710 case ODEBUG_STATE_DESTROYED:720 case ODEBUG_STATE_DESTROYED:
711 debug_print_object(obj, "deactivate");721 print_object = true;
712 break;722 break;
713 default:723 default:
714 break;724 break;
715 }725 }
716 } else {726 }
727
728 raw_spin_unlock_irqrestore(&db->lock, flags);
729 if (!obj) {
717 struct debug_obj o = { .object = addr,730 struct debug_obj o = { .object = addr,
718 .state = ODEBUG_STATE_NOTAVAILABLE,731 .state = ODEBUG_STATE_NOTAVAILABLE,
719 .descr = descr };732 .descr = descr };
720 733
721 debug_print_object(&o, "deactivate");734 debug_print_object(&o, "deactivate");
735 } else if (print_object) {
736 debug_print_object(obj, "deactivate");
722 }737 }
723
724 raw_spin_unlock_irqrestore(&db->lock, flags);
725}738}
726EXPORT_SYMBOL_GPL(debug_object_deactivate);739EXPORT_SYMBOL_GPL(debug_object_deactivate);
727 740
@@ -736,6 +749,7 @@ void debug_object_destroy(void *addr, struct debug_obj_descr *descr) · 8 unmodified lines
736 struct debug_bucket *db;749 struct debug_bucket *db;
737 struct debug_obj *obj;750 struct debug_obj *obj;
738 unsigned long flags;751 unsigned long flags;
752 bool print_object = false;
739 753
740 if (!debug_objects_enabled)754 if (!debug_objects_enabled)
741 return;755 return;
@@ -755,20 +769,22 @@ void debug_object_destroy(void *addr, struct debug_obj_descr *descr) · 13 unmodified lines
755 obj->state = ODEBUG_STATE_DESTROYED;769 obj->state = ODEBUG_STATE_DESTROYED;
756 break;770 break;
757 case ODEBUG_STATE_ACTIVE:771 case ODEBUG_STATE_ACTIVE:
758 debug_print_object(obj, "destroy");
759 state = obj->state;772 state = obj->state;
760 raw_spin_unlock_irqrestore(&db->lock, flags);773 raw_spin_unlock_irqrestore(&db->lock, flags);
774 debug_print_object(obj, "destroy");
761 debug_object_fixup(descr->fixup_destroy, addr, state);775 debug_object_fixup(descr->fixup_destroy, addr, state);
762 return;776 return;
763 777
764 case ODEBUG_STATE_DESTROYED:778 case ODEBUG_STATE_DESTROYED:
765 debug_print_object(obj, "destroy");779 print_object = true;
766 break;780 break;
767 default:781 default:
768 break;782 break;
769 }783 }
770out_unlock:784out_unlock:
771 raw_spin_unlock_irqrestore(&db->lock, flags);785 raw_spin_unlock_irqrestore(&db->lock, flags);
786 if (print_object)
787 debug_print_object(obj, "destroy");
772}788}
773EXPORT_SYMBOL_GPL(debug_object_destroy);789EXPORT_SYMBOL_GPL(debug_object_destroy);
774 790
@@ -797,9 +813,9 @@ void debug_object_free(void *addr, struct debug_obj_descr *descr) · 22 unmodified lines
797 813
798 switch (obj->state) {814 switch (obj->state) {
799 case ODEBUG_STATE_ACTIVE:815 case ODEBUG_STATE_ACTIVE:
800 debug_print_object(obj, "free");
801 state = obj->state;816 state = obj->state;
802 raw_spin_unlock_irqrestore(&db->lock, flags);817 raw_spin_unlock_irqrestore(&db->lock, flags);
818 debug_print_object(obj, "free");
803 debug_object_fixup(descr->fixup_free, addr, state);819 debug_object_fixup(descr->fixup_free, addr, state);
804 return;820 return;
805 default:821 default:
@@ -872,6 +888,7 @@ debug_object_active_state(void *addr, struct debug_obj_descr *descr, · 66 unmodified lines
872 struct debug_bucket *db;888 struct debug_bucket *db;
873 struct debug_obj *obj;889 struct debug_obj *obj;
874 unsigned long flags;890 unsigned long flags;
891 bool print_object = false;
875 892
876 if (!debug_objects_enabled)893 if (!debug_objects_enabled)
877 return;894 return;
@@ -887,22 +904,25 @@ debug_object_active_state(void *addr, struct debug_obj_descr *descr, · 9 unmodified lines
887 if (obj->astate == expect)904 if (obj->astate == expect)
888 obj->astate = next;905 obj->astate = next;
889 else906 else
890 debug_print_object(obj, "active_state");907 print_object = true;
891 break;908 break;
892 909
893 default:910 default:
894 debug_print_object(obj, "active_state");911 print_object = true;
895 break;912 break;
896 }913 }
897 } else {914 }
915
916 raw_spin_unlock_irqrestore(&db->lock, flags);
917 if (!obj) {
898 struct debug_obj o = { .object = addr,918 struct debug_obj o = { .object = addr,
899 .state = ODEBUG_STATE_NOTAVAILABLE,919 .state = ODEBUG_STATE_NOTAVAILABLE,
900 .descr = descr };920 .descr = descr };
901 921
902 debug_print_object(&o, "active_state");922 debug_print_object(&o, "active_state");
923 } else if (print_object) {
924 debug_print_object(obj, "active_state");
903 }925 }
904
905 raw_spin_unlock_irqrestore(&db->lock, flags);
906}926}
907EXPORT_SYMBOL_GPL(debug_object_active_state);927EXPORT_SYMBOL_GPL(debug_object_active_state);
908 928
@@ -937,10 +957,10 @@ repeat: · 28 unmodified lines
937 957
938 switch (obj->state) {958 switch (obj->state) {
939 case ODEBUG_STATE_ACTIVE:959 case ODEBUG_STATE_ACTIVE:
940 debug_print_object(obj, "free");
941 descr = obj->descr;960 descr = obj->descr;
942 state = obj->state;961 state = obj->state;
943 raw_spin_unlock_irqrestore(&db->lock, flags);962 raw_spin_unlock_irqrestore(&db->lock, flags);
963 debug_print_object(obj, "free");
944 debug_object_fixup(descr->fixup_free,964 debug_object_fixup(descr->fixup_free,
945 (void *) oaddr, state);965 (void *) oaddr, state);
946 goto repeat;966 goto repeat;