* [PATCH] docs/cpu-load: format the example code.
@ 2020-10-18 17:05 Hui Su
2020-10-21 21:08 ` Jonathan Corbet
0 siblings, 1 reply; 2+ messages in thread
From: Hui Su @ 2020-10-18 17:05 UTC (permalink / raw)
To: corbet, dsterba, mchehab+huawei, sh_def, linux-doc, linux-kernel
format the example code.
Signed-off-by: Hui Su <sh_def@163.com>
---
Documentation/admin-guide/cpu-load.rst | 63 ++++++++++++++------------
1 file changed, 33 insertions(+), 30 deletions(-)
diff --git a/Documentation/admin-guide/cpu-load.rst b/Documentation/admin-guide/cpu-load.rst
index ebdecf864080..f3ada90e9ca8 100644
--- a/Documentation/admin-guide/cpu-load.rst
+++ b/Documentation/admin-guide/cpu-load.rst
@@ -61,43 +61,46 @@ will lead to quite erratic information inside ``/proc/stat``::
static volatile sig_atomic_t stop;
- static void sighandler (int signr)
+ static void sighandler(int signr)
{
- (void) signr;
- stop = 1;
+ (void) signr;
+ stop = 1;
}
+
static unsigned long hog (unsigned long niters)
{
- stop = 0;
- while (!stop && --niters);
- return 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;
+ 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;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] docs/cpu-load: format the example code.
2020-10-18 17:05 [PATCH] docs/cpu-load: format the example code Hui Su
@ 2020-10-21 21:08 ` Jonathan Corbet
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Corbet @ 2020-10-21 21:08 UTC (permalink / raw)
To: Hui Su; +Cc: dsterba, mchehab+huawei, linux-doc, linux-kernel
On Mon, 19 Oct 2020 01:05:57 +0800
Hui Su <sh_def@163.com> wrote:
> format the example code.
>
> Signed-off-by: Hui Su <sh_def@163.com>
> ---
> Documentation/admin-guide/cpu-load.rst | 63 ++++++++++++++------------
> 1 file changed, 33 insertions(+), 30 deletions(-)
Hmm...this document wasn't always that way; it looks like maybe the code
got mangled during the RST conversion.
I question the value of this document in general...but as long as we have
it the code might as well look right, so I've applied this, thanks.
jon
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-10-21 21:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-18 17:05 [PATCH] docs/cpu-load: format the example code Hui Su
2020-10-21 21:08 ` Jonathan Corbet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).