-1

アイドル状態の CPU サイクルを計算したい。私はインターネットでこの質問の答えを見つけようとしました。しかし、答えは満足のいくものではありませんでした。アイドル状態の CPU サイクルを計算するように問い合わせましたが、答えは CPU 使用率/CPU 使用率でした。

c言語で特定の時間間隔のアイドルCPUサイクルを計算する方法を教えてください? CPU エネルギーを削減するための速度設定アルゴリズムのスケジューリングに取り組んでいます

idle_cycles = hard_idle + soft_idle;
run_cycles += excess_cycles;
run_percent = run_cycles /
(idle_cycles + run_cycles);
next_excess = run_cycles -
speed * (run_cycles + soft_idle)
IF excess_cycles < 0. THEN
excess_cycles = 0.
energy = (run_cycles - excess_cycles) *
speed * speed;
IF excess_cycles > idle_cycles THEN
newspeed = 1.0;
ELSEIF run_percent > 0.7 THEN
newspeed = speed + 0.2;
ELSEIF run_percent < 0.5 THEN
newspeed = speed -
(0.6 - run_percent);
IF newspeed > 1.0 THEN
newspeed = 1.0;
IF newspeed < min_speed THEN
newspeed = min_speed;
speed = newspeed;
excess_cycles = next_excess;

このアルゴリズムでは、c を使用して計算したい idle_cycles という用語に出くわしました。

4

1 に答える 1

1

/proc/uptime変数ファイル

に変数ファイルがあり、次の/proc/uptime2 つの値のみが含まれています。

  1. アップタイム(秒)

  2. アイドル時間 (秒)

注: 複数のコアを使用する場合、2 番目の値は、 すべてのコアに対するアイドルjiffyのカウンターです。

そこに無限のhtmlを使用してデモを書きました:

または単純なモニター:

お願いします、rtfm:man proc

/proc/stat変数ファイル

/proc/statcpu と各コアのホールド カウンターの最初の行。

head -n3 /proc/stat
cpu  1500160 13226 337809 16064648 1475420 34 16142 0 0 0
cpu0 747501 6569 168513 8022626 742061 25 14478 0 0 0
cpu1 752659 6656 169296 8042022 733359 9 1664 0 0 0

4 番目のカウンターはidle time counterです。

man proc:

man proc | sed  '/proc\/stat/,+19p;d'
   /proc/stat
          kernel/system statistics.   Varies  with  architecture.   Common
          entries include:

          cpu  3357 0 4313 1362393
                 The   amount  of  time,  measured  in  units  of  USER_HZ
                 (1/100ths  of  a  second  on  most   architectures,   use
                 sysconf(_SC_CLK_TCK) to obtain the right value), that the
                 system spent in various states:

                 user   (1) Time spent in user mode.

                 nice   (2) Time spent in  user  mode  with  low  priority
                        (nice).

                 system (3) Time spent in system mode.

                 idle   (4)  Time  spent  in  the  idle  task.  This value
                        should be USER_HZ times the second  entry  in  the
                        /proc/uptime pseudo-file.

このために、別の無限の htmlスクリプトがあります。

于 2015-12-06T21:01:06.643 に答える