Revision e7c4f797 core/src/aos_system.c

View differences:

core/src/aos_system.c
88 88
static int _shellcmd_configcb(BaseSequentialStream* stream, int argc, char* argv[]);
89 89
static int _shellcmd_infocb(BaseSequentialStream* stream, int argc, char* argv[]);
90 90
static int _shellcmd_shutdowncb(BaseSequentialStream* stream, int argc, char* argv[]);
91
#if ((CH_CFG_USE_REGISTRY == TRUE) && (CH_DBG_STATISTICS == TRUE)) || defined(__DOXYGEN__)
91
#if (((CH_CFG_USE_REGISTRY == TRUE) || (CH_CFG_USE_THREADHIERARCHY == TRUE)) && (CH_DBG_STATISTICS == TRUE)) || defined(__DOXYGEN__)
92 92
static int _shellcmd_cpuloadcb(BaseSequentialStream* stream, int argc, char* argv[]);
93
#endif /* (CH_CFG_USE_REGISTRY == TRUE) && (CH_DBG_STATISTICS == TRUE) */
93
#endif /* ((CH_CFG_USE_REGISTRY == TRUE) || (CH_CFG_USE_THREADHIERARCHY == TRUE)) && (CH_DBG_STATISTICS == TRUE) */
94 94
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
95 95
static int _shellcmd_kerneltestcb(BaseSequentialStream* stream, int argc, char* argv[]);
96 96
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
......
147 147
static AOS_SHELL_COMMAND(_shellcmd_shutdown, "module:shutdown", _shellcmd_shutdowncb);
148 148
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
149 149

  
150
#if ((CH_CFG_USE_REGISTRY == TRUE) && (CH_DBG_STATISTICS == TRUE)) || defined(__DOXYGEN__)
150
#if (((CH_CFG_USE_REGISTRY == TRUE) || (CH_CFG_USE_THREADHIERARCHY == TRUE)) && (CH_DBG_STATISTICS == TRUE)) || defined(__DOXYGEN__)
151 151

  
152 152
/**
153 153
 * @brief   Shell command to read out CPU load.
154 154
 */
155 155
static AOS_SHELL_COMMAND(_shellcmd_cpuload, "module:cpuload", _shellcmd_cpuloadcb);
156 156

  
157
#endif /* (CH_CFG_USE_REGISTRY == TRUE) && (CH_DBG_STATISTICS == TRUE) */
157
#endif /* ((CH_CFG_USE_REGISTRY == TRUE) || (CH_CFG_USE_THREADHIERARCHY == TRUE)) && (CH_DBG_STATISTICS == TRUE) */
158 158

  
159 159
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
160 160

  
......
643 643
#endif /* (AMIROOS_CFG_BOOTLOADER == X) */
644 644
}
645 645

  
646
#if ((CH_CFG_USE_REGISTRY == TRUE) && (CH_DBG_STATISTICS == TRUE)) || defined(__DOXYGEN__)
646
#if (((CH_CFG_USE_REGISTRY == TRUE) || (CH_CFG_USE_THREADHIERARCHY == TRUE)) && (CH_DBG_STATISTICS == TRUE)) || defined(__DOXYGEN__)
647 647

  
648 648
/**
649 649
 * @brief   Callback function for the module:cpuload shell command.
......
663 663

  
664 664
  // local variables
665 665
  rttime_t sum = 0;
666
  thread_t* thd = chRegFirstThread();
666
  thread_t* thd = aosThreadGetFirst();
667 667

  
668 668
  // accumulate system load
669 669
  do {
670 670
    sum += thd->stats.cumulative;
671
    thd = chRegNextThread(thd);
671
    thd = aosThreadGetNext(thd);
672 672
  } while (thd);
673 673
  sum += ch.kernel_stats.m_crit_thd.cumulative;
674 674
  sum += ch.kernel_stats.m_crit_isr.cumulative;
675 675

  
676 676
  // retrieve, calculate and print performance measures
677 677
  chprintf(stream, "threads & critical zones:\n");
678
  thd = chRegFirstThread();
678
  thd = aosThreadGetFirst();
679 679
  do {
680
#if (CH_CFG_USE_REGISTRY == TRUE)
680 681
    chprintf(stream, "\t%22s: %6.2f%%\n",
681 682
             (thd->name != NULL) ? thd->name : "<unnamed thread>",
682 683
             (double)((float)thd->stats.cumulative / (float)sum * 100.f));
683
    thd = chRegNextThread(thd);
684
#else
685
    chprintf(stream, "\t     thread 0x%08X: %6.2f%%\n", (unsigned int)thd, (double)((float)thd->stats.cumulative / (float)sum * 100.f));
686
#endif
687
    thd = aosThreadGetNext(thd);
684 688
  } while (thd);
685 689
  chprintf(stream, "\t%22s: %6.2f%%\n",
686 690
           "thread critical zones",
......
701 705
  return 0;
702 706
}
703 707

  
704
#endif /* (CH_CFG_USE_REGISTRY == TRUE) && (CH_DBG_STATISTICS == TRUE) */
708
#endif /* ((CH_CFG_USE_REGISTRY == TRUE) || (CH_CFG_USE_THREADHIERARCHY == TRUE)) && (CH_DBG_STATISTICS == TRUE) */
705 709

  
706 710
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
707 711

  
......
780 784
{
781 785
  size_t threads = 0;
782 786

  
783
#if (CH_CFG_USE_REGISTRY == TRUE)
784
  thread_t* tp = chRegFirstThread();
787
  thread_t* tp = aosThreadGetFirst();
785 788
  while (tp) {
786 789
    threads += (tp->state != CH_STATE_FINAL) ? 1 : 0;
787
    tp = chRegNextThread(tp);
790
    tp = aosThreadGetNext(tp);
788 791
  }
789
#elif (CH_CFG_USE_THREADHIERARCHY == TRUE)
790
  enum {
791
    TRAVERSE_DOWN,
792
    TRAVERSE_UP,
793
  } traverse = TRAVERSE_UP;
794
  thread_t* tp = chThdGetSelfX();
795
  // traverse to root thread
796
  while (tp->parent) {
797
    tp = tp->parent;
798
  }
799
  // systematically count all threads
800
  traverse = TRAVERSE_DOWN;
801
  while (tp) {
802
    if (traverse == TRAVERSE_DOWN && tp->children) {
803
      tp = tp->children;
804
    } else {
805
      threads += (tp->state != CH_STATE_FINAL) ? 1 : 0;
806
      if (tp->sibling) {
807
        tp = tp->sibling;
808
        traverse = TRAVERSE_DOWN;
809
      } else {
810
        tp = tp->parent;
811
        traverse = TRAVERSE_UP;
812
      }
813
    }
814
  }
815
#endif
816 792

  
817 793
  return threads;
818 794
}
......
870 846
  aosShellAddCommand(&aos.shell, &_shellcmd_config);
871 847
  aosShellAddCommand(&aos.shell, &_shellcmd_info);
872 848
  aosShellAddCommand(&aos.shell, &_shellcmd_shutdown);
873
#if ((CH_CFG_USE_REGISTRY == TRUE) && (CH_DBG_STATISTICS == TRUE)) || defined(__DOXYGEN__)
849
#if (((CH_CFG_USE_REGISTRY == TRUE) || (CH_CFG_USE_THREADHIERARCHY == TRUE)) && (CH_DBG_STATISTICS == TRUE)) || defined(__DOXYGEN__)
874 850
  aosShellAddCommand(&aos.shell, &_shellcmd_cpuload);
875
#endif /* (CH_CFG_USE_REGISTRY == TRUE) && (CH_DBG_STATISTICS == TRUE) */
851
#endif /* ((CH_CFG_USE_REGISTRY == TRUE) || (CH_CFG_USE_THREADHIERARCHY == TRUE)) && (CH_DBG_STATISTICS == TRUE) */
876 852
#if (AMIROOS_CFG_TESTS_ENABLE == true)
877 853
  aosShellAddCommand(&aos.shell, &_shellcmd_kerneltest);
878 854
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */

Also available in: Unified diff