freemyipod r392 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r391‎ | r392 | r393 >
Date:00:49, 28 December 2010
Author:theseven
Status:new
Tags:
Comment:
emBIOS: Fix CPU load accounting
Modified paths:
  • /embios/trunk/thread.c (modified) (history)
  • /embios/trunk/tools/embios.py (modified) (history)

Diff [purge]

Index: embios/trunk/tools/embios.py
@@ -493,19 +493,17 @@
494494 """
495495 import datetime
496496 threads = self.embios.getprocinfo()
497 - cpuload = 1
498497 threadload = 0
499498 idleload = 0
500499 for thread in threads:
501 - if thread.priority != 0:
502 - threadload += (thread.cpuload*100)/255
 500+ if thread.id != 0:
 501+ threadload += thread.cpuload / 255.
503502 else:
504 - idleload += (thread.cpuload*100)/255
 503+ idleload += thread.cpuload / 255.
505504 coreload = 1 - (threadload + idleload)
506505 cpuload = threadload + coreload
507 - self.logger.info("The device has " + str(len(threads)) + " running threads.\n" + \
508 - "It is running at " + str(cpuload * 100) + "% cpu load with a kernel load of " + \
509 - str(coreload * 100) + "% and a user load of " + str(threadload * 100) + "%\n\n")
 506+ self.logger.info("Threads: %d, CPU load: %.1f%%, kernel load: %.1f%%, user load: %.1f%%\n\n"
 507+ % (len(threads), cpuload * 100, coreload * 100, threadload * 100))
510508 self.logger.info("Thread dump:\n")
511509 for thread in threads:
512510 self.logger.info(" "+thread.name+":\n")
@@ -515,8 +513,8 @@
516514 self.logger.info(" Block type: " + thread.block_type+"\n")
517515 self.logger.info(" Blocked by: " + self._hex(thread.blocked_by_ptr)+"\n")
518516 self.logger.info(" Priority: " + str(thread.priority)+"/255\n")
519 - self.logger.info(" Current CPU load: "+str((thread.cpuload*100)/255)+"%\n")
520 - self.logger.info(" CPU time (total): "+str(datetime.timedelta(microseconds=thread.cputime_total))+"\n")
 517+ self.logger.info(" Current CPU load: %.1f%%\n" % ((thread.cpuload * 100) / 255.))
 518+ self.logger.info(" CPU time (total): "+str(datetime.timedelta(microseconds = thread.cputime_total))+"\n")
521519 self.logger.info(" Stack address: " + self._hex(thread.stackaddr)+"\n")
522520 self.logger.info(" Registers:\n")
523521 for registerrange in range(4):
Index: embios/trunk/thread.c
@@ -273,10 +273,11 @@
274274
275275 if (usec - last_tick > SCHEDULER_TICK)
276276 {
 277+ uint32_t diff = usec - last_tick;
277278 last_tick = usec;
278279 for (i = 0; i < MAX_THREADS; i++)
279280 {
280 - scheduler_threads[i].cpuload = 255 * scheduler_threads[i].cputime_current / SCHEDULER_TICK;
 281+ scheduler_threads[i].cpuload = 255 * scheduler_threads[i].cputime_current / diff;
281282 scheduler_threads[i].cputime_current = 0;
282283 }
283284 }