€•!3Œsphinx.addnodes”Œdocument”“”)”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)”}”(hhh]”(hŒ pending_xref”“”)”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…””}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ(/translations/zh_CN/admin-guide/cpu-load”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)”}”(hhh]”hŒChinese (Traditional)”…””}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ(/translations/zh_TW/admin-guide/cpu-load”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ(/translations/it_IT/admin-guide/cpu-load”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ(/translations/ja_JP/admin-guide/cpu-load”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ(/translations/ko_KR/admin-guide/cpu-load”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒSpanish”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ(/translations/sp_SP/admin-guide/cpu-load”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒsection”“”)”}”(hhh]”(hŒtitle”“”)”}”(hŒCPU load”h]”hŒCPU load”…””}”(hh¨hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hh£hžhhŸŒB/var/lib/git/docbuild/linux/Documentation/admin-guide/cpu-load.rst”h KubhŒ paragraph”“”)”}”(hŒÊLinux exports various bits of information via ``/proc/stat`` and ``/proc/uptime`` that userland tools, such as top(1), use to calculate the average time system spent in a particular state, for example::”h]”(hŒ.Linux exports various bits of information via ”…””}”(hh¹hžhhŸNh NubhŒliteral”“”)”}”(hŒ``/proc/stat``”h]”hŒ /proc/stat”…””}”(hhÃhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÁhh¹ubhŒ and ”…””}”(hh¹hžhhŸNh NubhÂ)”}”(hŒ``/proc/uptime``”h]”hŒ /proc/uptime”…””}”(hhÕhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÁhh¹ubhŒx that userland tools, such as top(1), use to calculate the average time system spent in a particular state, for example:”…””}”(hh¹hžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khh£hžhubhŒ literal_block”“”)”}”(hŒ©$ iostat Linux 2.6.18.3-exp (linmac) 02/20/2007 avg-cpu: %user %nice %system %iowait %steal %idle 10.01 0.00 2.92 5.44 0.00 81.63 ...”h]”hŒ©$ iostat Linux 2.6.18.3-exp (linmac) 02/20/2007 avg-cpu: %user %nice %system %iowait %steal %idle 10.01 0.00 2.92 5.44 0.00 81.63 ...”…””}”hhïsbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1híhŸh¶h K hh£hžhubh¸)”}”(hŒ¸Here the system thinks that over the default sampling period the system spent 10.01% of the time doing work in user space, 2.92% in the kernel, and was overall 81.63% of the time idle.”h]”hŒ¸Here the system thinks that over the default sampling period the system spent 10.01% of the time doing work in user space, 2.92% in the kernel, and was overall 81.63% of the time idle.”…””}”(hhÿhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khh£hžhubh¸)”}”(hŒÄIn most cases the ``/proc/stat`` information reflects the reality quite closely, however due to the nature of how/when the kernel collects this data sometimes it can not be trusted at all.”h]”(hŒIn most cases the ”…””}”(hj hžhhŸNh NubhÂ)”}”(hŒ``/proc/stat``”h]”hŒ /proc/stat”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÁhj ubhŒ¤ information reflects the reality quite closely, however due to the nature of how/when the kernel collects this data sometimes it can not be trusted at all.”…””}”(hj hžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khh£hžhubh¸)”}”(hX‰So how is this information collected? Whenever timer interrupt is signalled the kernel looks what kind of task was running at this moment and increments the counter that corresponds to this tasks kind/state. The problem with this is that the system could have switched between various states multiple times between two timer interrupts yet the counter is incremented only for the last state.”h]”hX‰So how is this information collected? Whenever timer interrupt is signalled the kernel looks what kind of task was running at this moment and increments the counter that corresponds to this tasks kind/state. The problem with this is that the system could have switched between various states multiple times between two timer interrupts yet the counter is incremented only for the last state.”…””}”(hj-hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khh£hžhubh¢)”}”(hhh]”(h§)”}”(hŒExample”h]”hŒExample”…””}”(hj>hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hj;hžhhŸh¶h K"ubh¸)”}”(hŒ_If we imagine the system with one task that periodically burns cycles in the following manner::”h]”hŒ^If we imagine the system with one task that periodically burns cycles in the following manner:”…””}”(hjLhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K$hj;hžhubhî)”}”(hX% time line between two timer interrupts |--------------------------------------| ^ ^ |_ something begins working | |_ something goes to sleep (only to be awaken quite soon)”h]”hX% time line between two timer interrupts |--------------------------------------| ^ ^ |_ something begins working | |_ something goes to sleep (only to be awaken quite soon)”…””}”hjZsbah}”(h]”h ]”h"]”h$]”h&]”hýhþuh1híhŸh¶h K'hj;hžhubh¸)”}”(hŒÛIn the above situation the system will be 0% loaded according to the ``/proc/stat`` (since the timer interrupt will always happen when the system is executing the idle handler), but in reality the load is closer to 99%.”h]”(hŒEIn the above situation the system will be 0% loaded according to the ”…””}”(hjhhžhhŸNh NubhÂ)”}”(hŒ``/proc/stat``”h]”hŒ /proc/stat”…””}”(hjphžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÁhjhubhŒˆ (since the timer interrupt will always happen when the system is executing the idle handler), but in reality the load is closer to 99%.”…””}”(hjhhžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K.hj;hžhubh¸)”}”(hŒ…One can imagine many more situations where this behavior of the kernel will lead to quite erratic information inside ``/proc/stat``::”h]”(hŒuOne can imagine many more situations where this behavior of the kernel will lead to quite erratic information inside ”…””}”(hjˆhžhhŸNh NubhÂ)”}”(hŒ``/proc/stat``”h]”hŒ /proc/stat”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÁhjˆubhŒ:”…””}”(hjˆhžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K3hj;hžhubhî)”}”(hXW/* gcc -o hog smallhog.c */ #include #include #include #include #define HIST 10 static volatile sig_atomic_t stop; static void sighandler(int signr) { (void) signr; stop = 1; } static unsigned long hog (unsigned long niters) { stop = 0; while (!stop && --niters); return niters; } int main (void) { int i; struct itimerval it = { .it_interval = { .tv_sec = 0, .tv_usec = 1 }, .it_value = { .tv_sec = 0, .tv_usec = 1 } }; sigset_t set; unsigned long v[HIST]; double tmp = 0.0; unsigned long n; signal(SIGALRM, &sighandler); setitimer(ITIMER_REAL, &it, NULL); hog (ULONG_MAX); for (i = 0; i < HIST; ++i) v[i] = ULONG_MAX - hog(ULONG_MAX); for (i = 0; i < HIST; ++i) tmp += v[i]; tmp /= HIST; n = tmp - (tmp / 3.0); sigemptyset(&set); sigaddset(&set, SIGALRM); for (;;) { hog(n); sigwait(&set, &i); } return 0; }”h]”hXW/* gcc -o hog smallhog.c */ #include #include #include #include #define HIST 10 static volatile sig_atomic_t stop; static void sighandler(int signr) { (void) signr; stop = 1; } static unsigned long hog (unsigned long niters) { stop = 0; while (!stop && --niters); return niters; } int main (void) { int i; struct itimerval it = { .it_interval = { .tv_sec = 0, .tv_usec = 1 }, .it_value = { .tv_sec = 0, .tv_usec = 1 } }; sigset_t set; unsigned long v[HIST]; double tmp = 0.0; unsigned long n; signal(SIGALRM, &sighandler); setitimer(ITIMER_REAL, &it, NULL); hog (ULONG_MAX); for (i = 0; i < HIST; ++i) v[i] = ULONG_MAX - hog(ULONG_MAX); for (i = 0; i < HIST; ++i) tmp += v[i]; tmp /= HIST; n = tmp - (tmp / 3.0); sigemptyset(&set); sigaddset(&set, SIGALRM); for (;;) { hog(n); sigwait(&set, &i); } return 0; }”…””}”hj¨sbah}”(h]”h ]”h"]”h$]”h&]”hýhþuh1híhŸh¶h K7hj;hžhubeh}”(h]”Œexample”ah ]”h"]”Œexample”ah$]”h&]”uh1h¡hh£hžhhŸh¶h K"ubh¢)”}”(hhh]”(h§)”}”(hŒ References”h]”hŒ References”…””}”(hjÁhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hj¾hžhhŸh¶h KlubhŒ bullet_list”“”)”}”(hhh]”(hŒ list_item”“”)”}”(hŒAhttps://lore.kernel.org/r/loom.20070212T063225-663@post.gmane.org”h]”h¸)”}”(hjØh]”hŒ reference”“”)”}”(hjØh]”hŒAhttps://lore.kernel.org/r/loom.20070212T063225-663@post.gmane.org”…””}”(hjßhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”jØuh1jÝhjÚubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KnhjÖubah}”(h]”h ]”h"]”h$]”h&]”uh1jÔhjÑhžhhŸh¶h NubjÕ)”}”(hŒ*Documentation/filesystems/proc.rst (1.8) ”h]”h¸)”}”(hŒ(Documentation/filesystems/proc.rst (1.8)”h]”hŒ(Documentation/filesystems/proc.rst (1.8)”…””}”(hjýhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Kohjùubah}”(h]”h ]”h"]”h$]”h&]”uh1jÔhjÑhžhhŸh¶h Nubeh}”(h]”h ]”h"]”h$]”h&]”Œbullet”Œ-”uh1jÏhŸh¶h Knhj¾hžhubeh}”(h]”Œ references”ah ]”h"]”Œ references”ah$]”h&]”uh1h¡hh£hžhhŸh¶h Klubh¢)”}”(hhh]”(h§)”}”(hŒThanks”h]”hŒThanks”…””}”(hj$hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hj!hžhhŸh¶h Ksubh¸)”}”(hŒCon Kolivas, Pavel Machek”h]”hŒCon Kolivas, Pavel Machek”…””}”(hj2hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Kuhj!hžhubeh}”(h]”Œthanks”ah ]”h"]”Œthanks”ah$]”h&]”uh1h¡hh£hžhhŸh¶h Ksubeh}”(h]”Œcpu-load”ah ]”h"]”Œcpu load”ah$]”h&]”uh1h¡hhhžhhŸh¶h Kubeh}”(h]”h ]”h"]”h$]”h&]”Œsource”h¶uh1hŒcurrent_source”NŒ current_line”NŒsettings”Œdocutils.frontend”ŒValues”“”)”}”(h¦NŒ generator”NŒ datestamp”NŒ source_link”NŒ source_url”NŒ toc_backlinks”Œentry”Œfootnote_backlinks”KŒ sectnum_xform”KŒstrip_comments”NŒstrip_elements_with_classes”NŒ strip_classes”NŒ report_level”KŒ halt_level”KŒexit_status_level”KŒdebug”NŒwarning_stream”NŒ traceback”ˆŒinput_encoding”Œ utf-8-sig”Œinput_encoding_error_handler”Œstrict”Œoutput_encoding”Œutf-8”Œoutput_encoding_error_handler”jsŒerror_encoding”Œutf-8”Œerror_encoding_error_handler”Œbackslashreplace”Œ language_code”Œen”Œrecord_dependencies”NŒconfig”NŒ id_prefix”hŒauto_id_prefix”Œid”Œ dump_settings”NŒdump_internals”NŒdump_transforms”NŒdump_pseudo_xml”NŒexpose_internals”NŒstrict_visitor”NŒ_disable_config”NŒ_source”h¶Œ _destination”NŒ _config_files”]”Œ7/var/lib/git/docbuild/linux/Documentation/docutils.conf”aŒfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œpep_references”NŒ pep_base_url”Œhttps://peps.python.org/”Œpep_file_url_template”Œpep-%04d”Œrfc_references”NŒ rfc_base_url”Œ&https://datatracker.ietf.org/doc/html/”Œ tab_width”KŒtrim_footnote_reference_space”‰Œsyntax_highlight”Œlong”Œ smart_quotes”ˆŒsmartquotes_locales”]”Œcharacter_level_inline_markup”‰Œdoctitle_xform”‰Œ docinfo_xform”KŒsectsubtitle_xform”‰Œ image_loading”Œlink”Œembed_stylesheet”‰Œcloak_email_addresses”ˆŒsection_self_link”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”Œrefids”}”Œnameids”}”(jMjJj»j¸jjjEjBuŒ nametypes”}”(jM‰j»‰j‰jE‰uh}”(jJh£j¸j;jj¾jBj!uŒ footnote_refs”}”Œ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”…”R”Œparse_messages”]”Œtransform_messages”]”Œ transformer”NŒ include_log”]”Œ decoration”Nhžhub.