ucmd_spin.c 656 B

123456789101112131415161718192021222324252627282930313233343536
  1. /* spin: CPU-bound test process for scheduler/priority checks.
  2. *
  3. * Usage: spin [ms] (default 5000 ms)
  4. */
  5. #include "ucmd_lib.h"
  6. static unsigned int parse_ms(const char *s)
  7. {
  8. unsigned int n = 0;
  9. while (*s >= '0' && *s <= '9') {
  10. n = n * 10 + (unsigned int)(*s - '0');
  11. s++;
  12. }
  13. return n;
  14. }
  15. void _start(const char *arg)
  16. {
  17. unsigned int ms = parse_ms(arg);
  18. unsigned int t0, i;
  19. unsigned long loops = 0;
  20. if (ms == 0)
  21. ms = 5000;
  22. t0 = u_ticks_ms();
  23. while (u_ticks_ms() - t0 < ms) {
  24. for (i = 0; i < 10000; i++)
  25. __asm__ volatile ("" ::: "memory");
  26. loops++;
  27. }
  28. u_puts("spin: done (");
  29. u_putdec(loops);
  30. u_puts(" loops)\n");
  31. u_exit(0);
  32. }