mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-10 15:58:47 +00:00
docs/cpu-load: format the example code.
format the example code. Signed-off-by: Hui Su <sh_def@163.com> Link: https://lore.kernel.org/r/20201018170557.GA7670@rlk Signed-off-by: Jonathan Corbet <corbet@lwn.net>
This commit is contained in:
parent
4fb220da0d
commit
bb7a2c6362
@ -61,43 +61,46 @@ will lead to quite erratic information inside ``/proc/stat``::
|
|||||||
|
|
||||||
static volatile sig_atomic_t stop;
|
static volatile sig_atomic_t stop;
|
||||||
|
|
||||||
static void sighandler (int signr)
|
static void sighandler(int signr)
|
||||||
{
|
{
|
||||||
(void) signr;
|
(void) signr;
|
||||||
stop = 1;
|
stop = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned long hog (unsigned long niters)
|
static unsigned long hog (unsigned long niters)
|
||||||
{
|
{
|
||||||
stop = 0;
|
stop = 0;
|
||||||
while (!stop && --niters);
|
while (!stop && --niters);
|
||||||
return niters;
|
return niters;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct itimerval it = { .it_interval = { .tv_sec = 0, .tv_usec = 1 },
|
struct itimerval it = {
|
||||||
.it_value = { .tv_sec = 0, .tv_usec = 1 } };
|
.it_interval = { .tv_sec = 0, .tv_usec = 1 },
|
||||||
sigset_t set;
|
.it_value = { .tv_sec = 0, .tv_usec = 1 } };
|
||||||
unsigned long v[HIST];
|
sigset_t set;
|
||||||
double tmp = 0.0;
|
unsigned long v[HIST];
|
||||||
unsigned long n;
|
double tmp = 0.0;
|
||||||
signal (SIGALRM, &sighandler);
|
unsigned long n;
|
||||||
setitimer (ITIMER_REAL, &it, NULL);
|
signal(SIGALRM, &sighandler);
|
||||||
|
setitimer(ITIMER_REAL, &it, NULL);
|
||||||
|
|
||||||
hog (ULONG_MAX);
|
hog (ULONG_MAX);
|
||||||
for (i = 0; i < HIST; ++i) v[i] = ULONG_MAX - 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];
|
for (i = 0; i < HIST; ++i) tmp += v[i];
|
||||||
tmp /= HIST;
|
tmp /= HIST;
|
||||||
n = tmp - (tmp / 3.0);
|
n = tmp - (tmp / 3.0);
|
||||||
|
|
||||||
sigemptyset (&set);
|
sigemptyset(&set);
|
||||||
sigaddset (&set, SIGALRM);
|
sigaddset(&set, SIGALRM);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
hog (n);
|
hog(n);
|
||||||
sigwait (&set, &i);
|
sigwait(&set, &i);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user