€•î6Œsphinx.addnodes”Œdocument”“”)”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)”}”(hhh]”(hŒ pending_xref”“”)”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…””}”(hhŒparent”hubaŒ 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)”…””}”(hhhh2ubah}”(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”…””}”(hhhhFubah}”(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”…””}”(hhhhZubah}”(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”…””}”(hhhhnubah}”(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”…””}”(hhhh‚ubah}”(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ª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 ”…””}”(hŒ.Linux exports various bits of information via ”hh¹hžhhŸNh NubhŒliteral”“”)”}”(hŒ``/proc/stat``”h]”hŒ /proc/stat”…””}”(hhhhÄhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÂhh¹ubhŒ and ”…””}”(hŒ and ”hh¹hžhhŸNh NubhÃ)”}”(hŒ``/proc/uptime``”h]”hŒ /proc/uptime”…””}”(hhhh×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:”…””}”(hŒ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 ...”…””}”(hhhhòubah}”(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.”…””}”(hjhjhž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 ”…””}”(hŒIn most cases the ”hjhžhhŸNh NubhÃ)”}”(hŒ``/proc/stat``”h]”hŒ /proc/stat”…””}”(hhhjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÂhjubhŒ¤ 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Œ¤ 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.”hjhž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.”…””}”(hj4hj2hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khh£hžhubh¢)”}”(hhh]”(h§)”}”(hŒExample”h]”hŒExample”…””}”(hjEhjChž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:”…””}”(hŒ^If we imagine the system with one task that periodically burns cycles in the following manner:”hjQhž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)”…””}”(hhhj`ubah}”(h]”h ]”h"]”h$]”h&]”jjuh1hð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 ”…””}”(hŒEIn the above situation the system will be 0% loaded according to the ”hjnhžhhŸNh NubhÃ)”}”(hŒ``/proc/stat``”h]”hŒ /proc/stat”…””}”(hhhjwhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÂhjnubhŒˆ (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Œˆ (since the timer interrupt will always happen when the system is executing the idle handler), but in reality the load is closer to 99%.”hjnhž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 ”…””}”(hŒuOne can imagine many more situations where this behavior of the kernel will lead to quite erratic information inside ”hjhžhhŸNh NubhÃ)”}”(hŒ``/proc/stat``”h]”hŒ /proc/stat”…””}”(hhhj™hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÂhjubhŒ:”…””}”(hŒ:”hjhž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; }”…””}”(hhhj²ubah}”(h]”h ]”h"]”h$]”h&]”jjuh1hð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Í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”…””}”(hhhjé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 hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Kohjubah}”(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”…””}”(hj0hj.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”…””}”(hj>hj<hž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”j}Œ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Œ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”‰Œfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œ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”‰Œ embed_images”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”Œrefids”}”Œnameids”}”(jWjTjÅjÂj(j%jOjLuŒ nametypes”}”(jWNjÅNj(NjONuh}”(jTh£jÂj@j%jÈjLj+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.