Bump to version 1.22.1
[platform/upstream/busybox.git] / procps / powertop.c
index 87efbe8..e3c29d1 100644 (file)
@@ -9,7 +9,7 @@
  * Licensed under GPLv2, see file LICENSE in this source tree.
  */
 
-//applet:IF_POWERTOP(APPLET(powertop, _BB_DIR_BIN, _BB_SUID_DROP))
+//applet:IF_POWERTOP(APPLET(powertop, BB_DIR_USR_SBIN, BB_SUID_DROP))
 
 //kbuild:lib-$(CONFIG_POWERTOP) += powertop.o
 
@@ -393,12 +393,11 @@ static NOINLINE int process_timer_stats(void)
        char buf[128];
        char line[15 + 3 + 128];
        int n;
-       ullong totalticks;
        FILE *fp;
 
        buf[0] = '\0';
-       totalticks = 0;
 
+       n = 0;
        fp = NULL;
        if (!G.cant_enable_timer_stats)
                fp = fopen_for_read("/proc/timer_stats");
@@ -418,14 +417,24 @@ static NOINLINE int process_timer_stats(void)
                        const char *count, *process, *func;
                        char *p;
                        int idx;
+                       unsigned cnt;
 
                        count = skip_whitespace(buf);
-                       if (strcmp(strchrnul(count, ' '), " total events") == 0)
-                               break;
                        p = strchr(count, ',');
                        if (!p)
                                continue;
                        *p++ = '\0';
+                       cnt = bb_strtou(count, NULL, 10);
+                       if (strcmp(skip_non_whitespace(count), " total events") == 0) {
+#if ENABLE_FEATURE_POWERTOP_PROCIRQ
+                               n = cnt / G.total_cpus;
+                               if (n > 0 && n < G.interrupt_0) {
+                                       sprintf(line, "    <interrupt> : %s", "extra timer interrupt");
+                                       save_line(line, G.interrupt_0 - n);
+                               }
+#endif
+                               break;
+                       }
                        if (strchr(count, 'D'))
                                continue; /* deferred */
                        p = skip_whitespace(p); /* points to pid now */
@@ -471,21 +480,11 @@ static NOINLINE int process_timer_stats(void)
                                sprintf(line, "%15.15s : %s", process, func);
                        //else
                        //      sprintf(line, "%s", process);
-                       save_line(line, bb_strtoull(count, NULL, 10));
+                       save_line(line, cnt);
                }
                fclose(fp);
        }
 
-       n = 0;
-#if ENABLE_FEATURE_POWERTOP_PROCIRQ
-       if (strstr(buf, " total events")) {
-               n = bb_strtoull(buf, NULL, 10) / G.total_cpus;
-               if (n > 0 && n < G.interrupt_0) {
-                       sprintf(line, "    <interrupt> : %s", "extra timer interrupt");
-                       save_line(line, G.interrupt_0 - n);
-               }
-       }
-#endif
        return n;
 }
 
@@ -494,7 +493,7 @@ static NOINLINE int process_timer_stats(void)
  * Get information about CPU using CPUID opcode.
  */
 static void cpuid(unsigned int *eax, unsigned int *ebx, unsigned int *ecx,
-                                 unsigned int *edx)
+                               unsigned int *edx)
 {
        /* EAX value specifies what information to return */
        __asm__(
@@ -628,7 +627,6 @@ static void show_timerstats(void)
                int i, n = 0;
                char strbuf6[6];
 
-               strbuf6[5] = '\0';
                puts("\nTop causes for wakeups:");
                for (i = 0; i < G.lines_cnt; i++) {
                        if ((G.lines[i].count > 0 /*|| G.lines[i].disk_count > 0*/)
@@ -640,7 +638,7 @@ static void show_timerstats(void)
                                /*char c = ' ';
                                if (G.lines[i].disk_count)
                                        c = 'D';*/
-                               smart_ulltoa5(G.lines[i].count, strbuf6, " KMGTPEZY");
+                               smart_ulltoa5(G.lines[i].count, strbuf6, " KMGTPEZY")[0] = '\0';
                                printf(/*" %5.1f%% (%s)%c  %s\n"*/
                                        " %5.1f%% (%s)   %s\n",
                                        G.lines[i].count * 100.0 / G.lines_cumulative_count,
@@ -651,7 +649,7 @@ static void show_timerstats(void)
        } else {
                bb_putchar('\n');
                bb_error_msg("no stats available; run as root or"
-                               " enable the cpufreq_stats module");
+                               " enable the timer_stats module");
        }
 }