è² è·ã¨ã¯ä½ã
調ã¹ãã¨ãããã®ã§ blog ã«æ¸ãã¦ç解ãæ·±ãããã®ã³ã¼ãã¼ã§ããé·æã§ãã
Linux ã§ã·ã¹ãã è² è·ãè¦ãå ´åã«ãä¸è©±ã«ãªãã®ã top ã sar (sysstat ããã±ã¼ã¸ã«å梱ããã¦ãã³ãã³ã) ãªã©ã®ãã¼ã«ã§ãã
top ã§ã¯ã·ã¹ãã çµ±è¨ã®ã¹ãããã·ã§ãããè¦ããã¨ãã§ãã¾ããä»ã·ã¹ãã ãã©ãããç¶æ ããªã¼ã¨ããã¨ã㯠top ã便å©ã
top - 08:16:54 up 3 days, 14:43, 6 users, load average: 0.18, 0.07, 0.03 Tasks: 43 total, 2 running, 41 sleeping, 0 stopped, 0 zombie Cpu(s): 18.2% us, 0.0% sy, 0.0% ni, 81.8% id, 0.0% wa, 0.0% hi, 0.0% si
ä¸æ¹ã® sar ã§ã¯10åãã¨ã®ã·ã¹ãã çµ±è¨ãæéãé¡ã£ã¦ã¿ããã¨ããç®çã§ä½¿ããã¨ãã§ãã¾ããæ¨æ¥ã®å¤ã¯ã©ãããç¶æ³ã ã£ãã調ã¹ããã¿ãããªã¨ãã« sar ã便å©ã§ãã
% sar -u | head Linux 2.6.14-1.1656_FC4smp (kurio.hatena.ne.jp) 02/22/07 00:00:01 CPU %user %nice %system %iowait %idle 00:10:01 all 11.70 0.00 0.94 0.35 87.00 00:20:01 all 8.88 0.00 0.71 0.38 90.02 00:30:01 all 1.16 0.00 0.40 0.39 98.05 00:40:01 all 8.71 0.00 0.59 0.35 90.35 % sar -q | head -7 Linux 2.6.14-1.1656_FC4smp (kurio.hatena.ne.jp) 02/22/07 00:00:01 runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 00:10:01 1 170 0.00 0.08 0.10 00:20:01 2 168 0.08 0.16 0.12 00:30:01 3 171 0.00 0.02 0.05 00:40:01 2 169 0.00 0.05 0.08
top ã sar ã§ã¯ã·ã¹ãã è² è·ãè¨æ¸¬ããææ¨ã¨ãã¦CPU使ç¨çã¨ãã¼ãã¢ãã¬ã¼ã¸ã®æ°å¤ãè¦ããã¨ãã§ãã¾ããã©ã¡ããè² è·ã表ãæ°åã§ãããå°ãæ§æ ¼ãç°ãªãã¾ãã
- ãã¼ãã¢ãã¬ã¼ã¸ã¯éå»1åã5åã15åã®éã®å®è¡å¾ ã¡ããã»ã¹æ°ã®å¹³åæ° = å®è¡ãããã¦ãä»ã®ããã»ã¹ãå®è¡ä¸ã§å®è¡ã§ããªãããã»ã¹ãå¹³åã§ä½åãããåå¨ãã¦ãã
- CPU使ç¨çã¯ãæåã®éã CPU ã度ã®ç¨åº¦å©ç¨ããã¦ãã/ãããã®å²å
ã¨ãªãã¾ãã
ãã¼ãã¢ãã¬ã¼ã¸ã®æ¹ã«ã¯ã·ã¹ãã ããã¼ã¸ã¢ã¦ããã¦è¾ãç¶æ³ãªã©ããããæ°å¤ã«ãªã£ã¦è¡¨ãã¾ããã¤ã¾ããã¡ã¢ãªãä¸è¶³ãã¦ããã§ããã¨ãããã£ã¹ã¯ã®èªã¿æ¸ãã«æéãããã£ã¦ããã¨ãã£ãã·ã¹ãã ã®è²ã ãªç¶æ³ãç·æ¬ãã¦æ°å¤ã«åæ ãããã®ã¨è¦ããã¨ãã§ãã¾ãã
ä¸æ¹ã®CPU使ç¨çã®æ¹ã«ã¯ç´ç²ã« CPU ã®ä½¿ç¨çã表示ããã¦ãã¾ããã§ãã®ã§ã
- "è² è·ãé«ã"ã¨ããã¨ãã«ãã¼ãã¢ãã¬ã¼ã¸ãè¦ã¦æ°åãé«ã
- CPU 使ç¨çãè¦ãã¨ãã idle ã¯çµæ§ãã
- ã®ã§ããã«ããã¯ã¯ CPU ã§ã¯ãªãä»ãèãããã
- vmstat ã§ã¡ã¢ãªã®å©ç¨ç¶æ³ãã¿ãããã¼ã¸ã¢ã¦ããã¾ãã£ã¦ã
- æè¼ã¡ã¢ãªã足ããªãã
ã¨ãã£ãæãã§ããããã®æ°å¤ã使ãåãã¦åæãã¦ãããã¨ã§ãã©ããåå ãªã®ããç¹å®ãããã¨ãã§ãã¾ãã
ãã¦ããã¼ãã¢ãã¬ã¼ã¸ã¨CPU使ç¨çã¨ããæ°åã§ãããããããã©ããã£ã¦æ°å¤åããã¦ããã®ã§ããããOS (ã«ã¼ãã«)ããã®æ å ±ãåéãã¦ããã®ã§ããããã¨ã¯æ³åãã¤ãã¾ãããå ·ä½çã«ããããã©ãããåºæºã§æ°å¤åããã¦ããã¨ããã®ã¯èªæã§ã¯ããã¾ãããã¨ããããã¨ãæ°ã«ãªã£ãã®ã§ã«ã¼ãã«ã®ä¸ãè¦ãã¦ã¿ã¾ããã
ã¾ãã¯ãã¼ãã¢ãã¬ã¼ã¸ã
Linux ããã¼ãã¢ãã¬ã¼ã¸ãè¨ç®ããå¦çãèµ·åããã¿ã¤ãã³ã°ã¯ããã¼ãã¦ã§ã¢ã¿ã¤ãã®å²ãè¾¼ã¿æã«ãªãã¾ããä¾ãã° PC/AT äºææ©ã®å ´å㯠PIT (Programmable Interval Timer) ã¨ããããã¤ã¹ããã£ã¦ããããå¨æçã«ã¿ã¤ãã¼å²ãè¾¼ã¿ãçºçããã¾ãã(PIT ãçºçãããã¿ã¤ãå²ãè¾¼ã¿ã¯ã·ã¹ãã ã®æå»ãé²ãããããªã©ã«ä½¿ããã¾ããä¸æ¹ããã«ãããã»ããµã®å ´åã« CPU ãè¤æ°ãã£ã¦ãããããã«ã¿ã¤ãå²ãè¾¼ã¿ãå¿ è¦ã«ãªã£ãã¨ãããã®å²ãè¾¼ã¿ãçºçãããã®ã¯ããã»ããµåºæã®ãã¼ã«ã«APIC ã§ããåè ã"ã°ãã¼ãã«ã¿ã¤ãå²ãè¾¼ã¿"ãå¾è ã"ãã¼ã«ã«ã¿ã¤ãå²ãè¾¼ã¿ã¨å¼ã¶ããã")
ã°ãã¼ãã«ã¿ã¤ãå²ãè¾¼ã¿ã¯å²ãè¾¼ã¿ã³ã³ããã¼ã©ã® APIC (Advanced Programmable Interrupt Controller) ã«ãã£ã¦ CPU (ã®ãã¼ã«ã«APIC)ã«è»¢éãããå²ãè¾¼ã¿è¦æ±ãçºçããã¾ãããã®å²ãè¾¼ã¿è¦æ±ãããªã¬ã«ãã¦ãã«ã¼ãã«ã®ã°ãã¼ãã«ã¿ã¤ãç¨å²ãè¾¼ã¿ãã³ãã©ãèµ·åãã¾ãã
ãã®ã°ãã¼ãã«ã¿ã¤ãå²ãè¾¼ã¿ã«å¯¾ããå²ãè¾¼ã¿ãã³ãã©ããå¼ã°ããå¦ç㯠Linux 2.6.20 ã 㨠kernel/timer.c ã® do_timer() ã«å®ç¾©ããã¦ãã¾ãã(å²ãè¾¼ã¿ãåãä»ã㦠do_timer() ãå¼ã³åºãã¾ã§ã®å¦çã®ã¯åã¢ã¼ããã¯ãã£ãã¨ã®ã¿ã¤ãå¨ãã®å®è£ ãx86_64 ã§ããã° arch/x86_64/kernel/time.c ãããã«ããã¾ãã)
ã¾ãè²ã æ¸ãã¦ã¾ãããè¦ã¯ã«ã¼ãã«ã®ä¸ã§ do_timer() é¢æ°ãå®æçã«å¼ã³åºããã¦å®è¡ããã¦ãããã¨ãããã¨ã§ãã
1208 void do_timer(unsigned long ticks) 1209 { 1210 jiffies_64 += ticks; 1211 update_times(ticks); 1212 }
do_timer() ããã¯ç¶ã㦠update_times() ãå¼ã°ãã¦ãã¾ãã
1196 static inline void update_times(unsigned long ticks) 1197 { 1198 update_wall_time(); 1199 calc_load(ticks); 1200 }
ãã® update_times() ã« calc_load() ããã£ã¦ãããããã¼ãã¢ãã¬ã¼ã¸ã®è¨ç®ãããé¢æ°ã§ãããã¼ãã¦ã§ã¢ã¿ã¤ãå²ãè¾¼ã¿æ¯ã«ãã¼ãã¢ãã¬ã¼ã¸ãè¨ç®ãã¦å¤ãæ´æ°ãã¦ããã®ãåããã¾ããcalc_load() ã®ä¸èº«ã¯ä»¥ä¸ã«ãªãã¾ãã
1144 static inline void calc_load(unsigned long ticks) 1145 { 1146 unsigned long active_tasks; /* fixed-point */ 1147 static int count = LOAD_FREQ; 1148 1149 count -= ticks; 1150 if (unlikely(count < 0)) { 1151 active_tasks = count_active_tasks(); 1152 do { 1153 CALC_LOAD(avenrun[0], EXP_1, active_tasks); 1154 CALC_LOAD(avenrun[1], EXP_5, active_tasks); 1155 CALC_LOAD(avenrun[2], EXP_15, active_tasks); 1156 count += LOAD_FREQ; 1157 } while (count < 0); 1158 } 1159 }
count_active_tasks() ã§ãã·ã¹ãã ã§ã¢ã¯ãã£ããªã¿ã¹ã¯ã®æ°ãåå¾ãã¦ããã CALC_LOAD ãã¯ãã«ããã¦ãã¼ãã¢ãã¬ã¼ã¸ãè¨ç®ãã°ãã¼ãã«ãªé åã® avenrun ã«ãããã 1åã5åã15åã®ãã¼ãã¢ãã¬ã¼ã¸å¤ãä¿åãã¦ãã¾ãã
ã ãã ãã¨ãã¢ã«è¿ã¥ãã¦ãã¾ãããå®éãã¼ãã¢ãã¬ã¼ã¸ã®è¨ç®ã«ä½¿ããã¦ãããã¢ã¯ãã£ããªã¿ã¹ã¯ãã£ã¦ãªãã ãããã¨ãããã¨ã§ count_active_tasks() ã®ä¸èº«ãæ´ã«è¿½ã£ã¦ããã¨ãkernel/sched.c ã® nr_active() é¢æ°ã«å°éãã¾ããsched.c ã¯ããã»ã¹ã¹ã±ã¸ã¥ã¼ã©ã®å®è£ ã§ãã
1929 unsigned long nr_active(void) 1930 { 1931 unsigned long i, running = 0, uninterruptible = 0; 1932 1933 for_each_online_cpu(i) { 1934 running += cpu_rq(i)->nr_running; 1935 uninterruptible += cpu_rq(i)->nr_uninterruptible; 1936 } 1937 1938 if (unlikely((long)uninterruptible < 0)) 1939 uninterruptible = 0; 1940 1941 return running + uninterruptible; 1942 }
cpu_rq(i) ã§åCPUã«ç´ä»ããããã©ã³ãã¥ã¼(å®è¡å¯è½ã«ãªã£ã¦CPUå²ãå½ã¦ãã¾ã£ã¦ããããã»ã¹ããã¥ã¼ã¤ã³ã°ããã¦ããå ´æ) ã®ã¡ã³ããã nr_runningãnr_uninterruptible ã¨ããäºã¤ã®æ°ãå¼ã£å¼µãã ãã¦è¶³ãããã§ãã¾ãããã® nr_runningãnr_uninterruptible ã§ãããããããç¹å®ã®ç¶æ ã®ããã»ã¹ã®æ°ã表ãæ°åã§ãã
Linux ã®ããã»ã¹ã®å®ä½ã¯ã«ã¼ãã«æ§é ä½ã® task_struct æ§é ä½ã§ãããã®æ§é ä½ã«ã¯ state ã¨ããã¡ã³ãããã£ã¦ããã®ã¡ã³ããè¦ãã¨ãã¾ããã»ã¹ãã©ã®ãããªç¶æ ã«ããããåããããã«ãªã£ã¦ãã¾ããstate ã¡ã³ãã®ä¸»ãªå¤ã¯
- TASK_RUNNING
- å®è¡ä¸ãããã¯å®è¡å¯è½ã§CPUå²ãå½ã¦ãå¾ ã£ã¦ããç¶æ
- TASK_INTERRUPTIBLE
- å²ãè¾¼ã¿å¯è½ãªå¾ ã¡ç¶æ ãã¦ã¼ã¶ã¼ããã®å ¥åå¾ ã¡ãªã©æ¯è¼çæéããããäºè±¡ã
- TASK_UNINTERRUPTIBLE
- å²ãè¾¼ã¿ä¸å¯è½ãªå¾ ã¡ç¶æ ããã£ã¹ã¯I/Oå¾ ã¡ãªã©çãäºè±¡ã
ãªã©ã§ãã(ä»ã«ãããã¤ãããã¾ãã)
ã«ã¼ãã«ã®ã¹ã±ã¸ã¥ã¼ã©ã¯ããã»ã¹ã®ç¶æ ãè¦ãªãã CPU ã«å²ãå½ã¦ãããã»ã¹ãåãæ¿ãã¦ããã¾ãããä¾ãã°ãã®ããã»ã¹ã¯ I/O å¾ ã¡ã«å ¥ã£ããã TASK_UNINTERRUPTIBLE ã«ã㦠I/O ãå®äºããã¾ã§å¾ ã¡ç¶æ ã«ãã¦ãããå¥ã®ããã»ã¹ã TASK_RUNNING ã§å®è¡å¯è½ã«ãã¦...ã¨ãããã¨ãã©ã³ãã¥ã¼(ãã¦ã§ã¤ããã¥ã¼)ã«å¯¾ãã¦ãã£ã¦ããããã§ãã
ã¨ãããã¨ã§ãããã¾ã§ã®ã³ã¼ãã§ãã®ãã¥ã¼ã«å ¥ããããããã»ã¹ã®ç¶æ ã®ãã¡ TASK_RUNNING 㨠TASK_UNINTERRUPTIBLE ç¶æ ã®ãã®ã®æ°ãæ°ãã¦åä½æéã§å²ã£ã¦ããã¼ãã¢ãã¬ã¼ã¸ã®å¤ã¨ãã¦ãããã¨ããã®ãåããã¾ããä»ã¾ãã«å®è¡å¯è½ãªããã»ã¹ã® TASK_RUNNING ãå«ã¾ããã®ã¯æ³åãã¤ãã¾ããããã£ã¹ã¯ I/O å¾ ã¡ãªã©ã®ããã»ã¹æ°ããã¼ãã¢ãã¬ã¼ã¸ã«å ãããã¦ããã¨ããã®ããã¤ã³ãã§ã¯ãªãã§ããããã
ãã¼ãã¢ãã¬ã¼ã¸ã®å®è£ ãåãã£ãã¨ããã§ã次㯠CPU 使ç¨çã®å®è£ ãè¦ã¦ã¿ã¾ããCPU使ç¨çã®çµ±è¨åå¾ã¯ããã»ã¹ã¢ã«ã¦ã³ãã£ã³ã°ãªã©ã¨å¼ã°ãããã¨ãããåããã¨ãããåå¥ã®ããã»ã¹ã®çµ±è¨ããåã£ã¦ããããã«ãªã£ã¦ãã¾ãã
ãã¼ãã¢ãã¬ã¼ã¸ãã·ã¹ãã å ¨ä½ã®æ°åã ã£ãã®ã«å¯¾ãã¦ãCPU 使ç¨çã¯ãã«ãããã»ããµç°å¢ã§ã¯å CPU ãã¨ã«çµ±è¨ãåããã¦ãã¾ãããã®ãããkernel/timer.c ã«å®ç¾©ããã¦ããCPU 使ç¨çãè¨ç®ããé¢æ°ã§ããã¨ããã® update_process_times() ã¯
- ã¦ãããã»ããµã®å ´åã¯ã°ãã¼ãã«ã¿ã¤ãå²ãè¾¼ã¿ãã³ãã©ããå¼ã°ãã do_timer() ã®ç´å¾ã«å¼ã°ãã
- ãã«ãããã»ããµã®å ´å㯠CPU æ¯ã«å¨æçã«å²ãè¾¼ã¿ãçºçãããããã¤ã¹(ãã¼ã«ã«APIC)ã®å²ãè¾¼ã¿ãã³ãã©ããå¼ã°ãã
ã¨ãªã£ã¦ãã¾ããå¾è 㯠arch/x86_64/kernel/apic.c ã® smp_local_timer_interrupt() ãããã§ãã
978 void smp_local_timer_interrupt(void) 979 { 980 profile_tick(CPU_PROFILING); 981 #ifdef CONFIG_SMP 982 update_process_times(user_mode(get_irq_regs())); 983 #endif 984 if (apic_runs_main_timer > 1 && smp_processor_id() == boot_cpu_id) 985 main_timer_handler(); 986 /* 987 * We take the 'long' return path, and there every subsystem 988 * grabs the appropriate locks (kernel lock/ irq lock). 989 * 990 * We might want to decouple profiling from the 'long path', 991 * and do the profiling totally in assembly. 992 * 993 * Currently this isn't too much of an issue (performance wise), 994 * we can take more than 100K local irqs per second on a 100 MHz P5. 995 */ 996 }
確ãã« smp_local_timer_interrupt() ãã update_process_times() ãå¼ã°ãã¦ãã¾ããã
update_process_times ã®ä¸ã®å®è£ ãè¦ãåã«ãåéãããæ å ±ãæ ¼ç´ãããæ§é ä½ã®å®ç¾©ãè¦ã¦ããã¨è¦éããããããã§ããinclude/linux/kernel_stat.h ã® cpu_usage_stat æ§é ä½ãããã«ãªãã¾ãã
17 struct cpu_usage_stat { 18 cputime64_t user; 19 cputime64_t nice; 20 cputime64_t system; 21 cputime64_t softirq; 22 cputime64_t irq; 23 cputime64_t idle; 24 cputime64_t iowait; 25 cputime64_t steal; 26 }; 27 28 struct kernel_stat { 29 struct cpu_usage_stat cpustat; 30 unsigned int irqs[NR_IRQS]; 31 }; 32 33 DECLARE_PER_CPU(struct kernel_stat, kstat);
cpu_usage_stat æ§é ä½ã®ã¡ã³ãã«ã¯ã¦ã¼ã¶ã¼ã¢ã¼ãã®å¤ãã·ã¹ãã ã¢ã¼ãã§ã®å¤ãiowait ã®å¤çã ãããã¾ãããã® cpu_usage_stat æ§é ä½ã¯ kernel_stat æ§é ä½ããåç §ããã形㧠DECLARE_PER_CPU 㧠CPU æ¯ã«ä¸ã¤ç¨æããã¾ãã
ãã¦ã話ãæ»ã㦠update_process_times() ã®ä¸ãè¦ãã¦ã¿ã¾ããkernel/timer.c ã«å®ç¾©ããã¦ãã¾ãã
1099 /* 1100 * Called from the timer interrupt handler to charge one tick to the current 1101 * process. user_tick is 1 if the tick is user time, 0 for system. 1102 */ 1103 void update_process_times(int user_tick) 1104 { 1105 struct task_struct *p = current; 1106 int cpu = smp_processor_id(); 1107 1108 /* Note: this timer irq context must be accounted for as well. */ 1109 if (user_tick) 1110 account_user_time(p, jiffies_to_cputime(1)); 1111 else 1112 account_system_time(p, HARDIRQ_OFFSET, jiffies_to_cputime(1)); 1113 run_local_timers(); 1114 if (rcu_pending(cpu)) 1115 rcu_check_callbacks(cpu, user_tick); 1116 scheduler_tick(); 1117 run_posix_cpu_timers(p); 1118 }
1105 è¡ç®ã§ current ãã¯ãã§ç¾å¨å®è¡ããã¦ããããã»ã¹(task_struct æ§é ä½)ãåå¾ãããã®ããã»ã¹ã«å¯¾ã㦠account_user_time ã account_system_time() ãªã©ãå®è¡ãã¦ããã®ãåããã¾ãããã® account_* ãè¨ç®ã®æ¬ä½ã®ããã§ããã
ããã«æ½ã£ã¦ããã¾ããkernel/sched.c ã« account_* ã¯å®ç¾©ããã¦ãã¾ããã¾ãã¯ã¦ã¼ã¶ã¼ã¢ã¼ãã§ã®ããã»ã¹ã¢ã«ã¦ã³ãã£ã³ã°ããè¦ã¦ã¿ã¾ãã
3059 /* 3060 * Account user cpu time to a process. 3061 * @p: the process that the cpu time gets accounted to 3062 * @hardirq_offset: the offset to subtract from hardirq_count() 3063 * @cputime: the cpu time spent in user space since the last update 3064 */ 3065 void account_user_time(struct task_struct *p, cputime_t cputime) 3066 { 3067 struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat; 3068 cputime64_t tmp; 3069 3070 p->utime = cputime_add(p->utime, cputime); 3071 3072 /* Add user time to cpustat. */ 3073 tmp = cputime_to_cputime64(cputime); 3074 if (TASK_NICE(p) > 0) 3075 cpustat->nice = cputime64_add(cpustat->nice, tmp); 3076 else 3077 cpustat->user = cputime64_add(cpustat->user, tmp); 3078 }
ãã㧠p ã¯ç¾å¨å®è¡ããã¦ããããã»ã¹ã§ããã
- ã¾ãç¾å¨å®è¡ä¸ã®ããã»ã¹ã® utime ãå¢ãããããã«ãããã®ããã»ã¹ãã¦ã¼ã¶ã¼ã¢ã¼ãã§ä½¿ç¨ããæéããã®ããã»ã¹å ã®æ å ±ã¨ãã¦ä¿åãããã (p->utime = cputime_add(p->utime, cputime))
- 次ã«å ã«è¦ã cpu_usage_stat æ§é ä½ user ã«ããã®ããã»ã¹ã®ä½¿ç¨æéã追å ããã
ã¤ã¾ãç¾å¨å®è¡ä¸ã®ããã»ã¹ãã©ã®ç¨åº¦ CPU ã使ã£ãããæåã«è¨ç®ãã¦ããã®å¤ãå ¨ä½ã§ã®å¤ã«ã足ãããã§ãããã¨ããå¦çã«ãªã£ã¦ãã¾ãã
ã·ã¹ãã ã¢ã¼ãã®æ¹ãè¦ã¦ã¿ã¾ãã
3080 /* 3081 * Account system cpu time to a process. 3082 * @p: the process that the cpu time gets accounted to 3083 * @hardirq_offset: the offset to subtract from hardirq_count() 3084 * @cputime: the cpu time spent in kernel space since the last update 3085 */ 3086 void account_system_time(struct task_struct *p, int hardirq_offset, 3087 cputime_t cputime) 3088 { 3089 struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat; 3090 struct rq *rq = this_rq(); 3091 cputime64_t tmp; 3092 3093 p->stime = cputime_add(p->stime, cputime); 3094 3095 /* Add system time to cpustat. */ 3096 tmp = cputime_to_cputime64(cputime); 3097 if (hardirq_count() - hardirq_offset) 3098 cpustat->irq = cputime64_add(cpustat->irq, tmp); 3099 else if (softirq_count()) 3100 cpustat->softirq = cputime64_add(cpustat->softirq, tmp); 3101 else if (p != rq->idle) 3102 cpustat->system = cputime64_add(cpustat->system, tmp); 3103 else if (atomic_read(&rq->nr_iowait) > 0) 3104 cpustat->iowait = cputime64_add(cpustat->iowait, tmp); 3105 else 3106 cpustat->idle = cputime64_add(cpustat->idle, tmp); 3107 /* Account for system time used */ 3108 acct_update_integrals(p); 3109 }
ãã£ã¦ãããã¨ã¯ã»ã¨ãã©ä¸ç·ã§ãã if åã®åå²ã«ãããæ¶è²»ããæéã
- ã·ã¹ãã æé(ã«ã¼ãã«ã¹ã¬ãããè¨ç®ãè¡ã£ãæé)
- ãã¼ãã¦ã§ã¢å²ãè¾¼ã¿ã«è¦ããæé
- ã½ããã¦ã§ã¢å²ãè¾¼ã¿ã«è¦ããæé
- IO ã«è¦ããæé
ã®ãããã ã£ãã®ããå¤å®ãã¦ã足ããã¿ãè¡ã£ã¦ããã®ãåããã¾ãã
ã¨ãããã»ã¹ã¢ã«ã¦ã³ãã£ã³ã°ã®ããã¾ããªå¦çã¯ãããªæãã§ããã¿ã¤ãå²ãè¾¼ã¿ãå©ç¨ãã¦ããã»ã¹ãã¨ã®çµ±è¨ãåã£ããã¨ããããå ¨ä½ã®çµ±è¨ã«è¶³ãããã¨ããã®ãã²ãããç¹°ãè¿ãã¦ããããã§ããã
ã¨ããã§ããã¼ãã¢ãã¬ã¼ã¸ã«ãã¦ãããã»ã¹ã¢ã«ã¦ã³ãã£ã³ã°ã®çµæã«ãã¦ããè¨ç®ããã®ã¯ããã¨ã㦠top ã sar ãªã©ã®ãã¼ã«ã¯ãããã®å¤ãã©ããã£ã¦åç §ãããã¨ãã話ãããã¾ããããã㯠/proc ãã¡ã¤ã«ã·ã¹ãã ãçµç±ãã¦åå¾ãããã¨ãã§ãã¾ãã
- ã·ã¹ãã å ¨ä½ã®å¤ã¯ /proc/stat
- ããã»ã¹æ¯ã®å¤ã¯ /proc/${PID}/stat
ã«ããããããã¾ãã
% cat /proc/stat cpu 4409373 5621 147573 10089174 1293 68 4400 0 cpu0 4409373 5621 147573 10089174 1293 68 4400 0 intr 14838028 14657502 0 180526 0 0 0 0 ...(ç¥) ctxt 1332839 btime 1171787591 processes 3730 procs_running 2 procs_blocked 0
ãããã®å¤ãåå¾ãã¦æ´å½¢ãã¦è¡¨ç¤ºãããã¨ã§ãæ®æ®µç®ã«ãã¦ãããã¼ãã¢ãã¬ã¼ã¸ã CPU 使ç¨çã®å¤ã¨ãã¦ã¿ããã¨ãã§ããããã§ãã
ä½è«ã§ãããLinux ã¯ã«ã¼ãã« 2.5 ãã sar ãªã©ã§ iowait ã®çµ±è¨ãè¦ããã¨ãã§ããããã«ãªãã¾ããããµã¼ãã¼ãéç¨ããä¸ã§ iowait ã®çµ±è¨ãè¦ããã¨ããã®ã¯éè¦ãªã®ã§ãããSolaris ãªã©ã® åç¨ UNIX ã§ã¯å½ããåãªãã®çµ±è¨æ å ±ã Linux 2.4 ã§ã¯åããªãã£ãããã§ãã
ã«ã¼ãã« 2.4.34.1 ã®ããã»ã¹ã¢ã«ã¦ã³ãã£ã³ã°ã®å®è£ ãè¦ã¦ã¿ã¾ãã
/* * Called from the timer interrupt handler to charge one tick to the current * process. user_tick is 1 if the tick is user time, 0 for system. */ void update_process_times(int user_tick) { struct task_struct *p = current; int cpu = smp_processor_id(), system = user_tick ^ 1; update_one_process(p, user_tick, system, cpu); if (p->pid) { if (--p->counter <= 0) { p->counter = 0; /* * SCHED_FIFO is priority preemption, so this is * not the place to decide whether to reschedule a * SCHED_FIFO task or not - Bhavesh Davda */ if (p->policy != SCHED_FIFO) { p->need_resched = 1; } } if (p->nice > 0) kstat.per_cpu_nice[cpu] += user_tick; else kstat.per_cpu_user[cpu] += user_tick; kstat.per_cpu_system[cpu] += system; } else if (local_bh_count(cpu) || local_irq_count(cpu) > 1) kstat.per_cpu_system[cpu] += system; }
2.6 ã®ãã®ã«æ¯ã¹ãã¨ã ãã¶åç´(?)ãªå 容ã«ãªã£ã¦ããã®ããããã¾ããiowait ã®è¨ç®ç®æã¯ã©ãã«ãããã¾ãããã
ã¾ã¨ã
ãµã¼ãã¼è² è·ã®è¦æ¥µãã®éµã«ãªããã¼ãã¢ãã¬ã¼ã¸ãCPU使ç¨çããLinux ä¸ã§ã©ã®ããã«è¨ç®ããã¦ããã®ãã«ã¼ãã«ã®ã³ã¼ããå®éã«è¿½ã£ã¦ã¿ã¦ã¿ã¾ããã
- ãã¼ãã¢ãã¬ã¼ã¸ã¯ãã¿ã¤ãå²ãè¾¼ã¿æã«ããã¥ã¼ã«æºã¾ã£ãããã»ã¹ã®ãã¡ TASK_RUNNING 㨠TASK_UNINTERRUPTIBLE ç¶æ ã®æ°ãæ°ãã¦è¨ç®ãã¦ãã
- CPU使ç¨æéã¯åããã»ã¹ãã¨ã®CPU使ç¨æéãã¿ã¤ãå²ãè¾¼ã¿æã«è¶³ãããã§ãããã·ã¹ãã å ¨ä½ã®å¤ã«ãããå ç®ããã¨ããã®ã§åã£ã¦ãã
ã¨ããã®ãåããã¾ãããã¾ãã«ã¼ãã« 2.4 ãã 2.6 ã«é²åããéç¨ã§ããã»ã¹ã¢ã«ã¦ã³ãã£ã³ã°ã®å®è£ ã«ãå¤æ´ãå ããã㦠iowait ãªã©éè¦ãªæ å ±ãåããããã«ãªã£ããã¨ãåããã¾ããã
ãããªå ·åã§ã«ã¼ãã«ã®ã³ã¼ãã«æ½ã£ã¦ããã¨ãæ®æ®µç®ã«ãã¦ããå¤ã®æ¬æ¥ã®æå³ã§ããã¨ããã©ãããã¿ã¤ãã³ã°ã§æ´æ°ããã¦ããã®ãã¨ããç¹ã«ç解ãæ·±ã¾ã£ã¦ããå ·åã§ãã
ãªãã½ã¼ã¹ãèªãã ããä»çµã¿ãç解ããããã«
- ä½è : é«æ©æµ©å,å°ç°é¸é,山幡çºä½ä¹
- åºç社/ã¡ã¼ã«ã¼: ã½ãããã³ã¯ã¯ãªã¨ã¤ãã£ã
- çºå£²æ¥: 2006/11/18
- ã¡ãã£ã¢: åè¡æ¬
- è³¼å ¥: 14人 ã¯ãªãã¯: 197å
- ãã®ååãå«ãããã° (118件) ãè¦ã
ã«å¤§å¤ãä¸è©±ã«ãªã£ã¦ãã¾ãã