From: malc <av1474@comtv.ru>
To: Ingo Molnar <mingo@elte.hu>,
Peter Zijlstra <peterz@infradead.org>,
linux-kernel@vger.kernel.org
Subject: Scheduler oddity
Date: Fri, 5 Feb 2010 19:33:59 +0300 (MSK) [thread overview]
Message-ID: <alpine.LNX.2.00.1002051928230.4744@linmac> (raw)
Following test exhibits somewhat odd behaviour on, at least, 2.6.32.3
(ppc) and 2.6.29.1 (x86_64), perhaps someone could explain why.
#define _GNU_SOURCE
#include <sched.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
int main(int argc, const char *argv[])
{
int pipe_fd[2];
pid_t pid;
if (argc == 2 && !strcmp(argv[1], "batch")) {
int ret;
struct sched_param p = {0};
ret = sched_setscheduler(0, SCHED_BATCH, &p);
if (ret) {
perror("sched_setscheduler");
return 1;
}
printf("using batch\n");
}
else {
printf("using default\n");
}
/* create the pipe */
if (pipe(pipe_fd) == -1) {
perror("pipe");
return 1;
}
/* fork a process that will run cat */
pid = fork();
if (pid == -1) {
perror("fork");
return 1;
}
if (pid == 0) {
/* child */
close(pipe_fd[1]); /* close the write end of the pipe */
if (dup2(pipe_fd[0], STDIN_FILENO) == -1) {
perror("dup2");
return 1;
}
close(pipe_fd[0]);
execl("/usr/bin/wc", "wc", "-c", NULL);
perror("execl");
return 1;
} else {
/* parent */
int i;
close(pipe_fd[0]); /* close the read end of the pipe */
for (i = 0; i < 10000000; i++)
write(pipe_fd[1], "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 30);
close(pipe_fd[1]);
wait(NULL);
return 0;
}
return 0;
}
~$ uname -a
Linux linmac 2.6.32.3 #4 Sun Jan 31 09:52:58 MSK 2010 ppc 7447A, altivec supported PowerMac10,2 GNU/Linux
$ gcc -o test-pipe test-pipe.c
$ \time -v ./test-pipe batch
using batch
300000000
Command being timed: "./test-pipe batch"
User time (seconds): 0.50
System time (seconds): 7.47
Percent of CPU this job got: 99%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:07.98
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 2496
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 343
Voluntary context switches: 9933
Involuntary context switches: 1997
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
$ \time -v ./test-pipe
using default
300000000
Command being timed: "./test-pipe"
User time (seconds): 1.53
System time (seconds): 34.74
Percent of CPU this job got: 100%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:36.27
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 2496
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 343
Voluntary context switches: 9992328
Involuntary context switches: 9994617
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
P.S. The test wasn't written by me
--
mailto:av1474@comtv.ru
next reply other threads:[~2010-02-05 17:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-05 16:33 malc [this message]
2010-02-06 12:11 ` Mike Galbraith
2010-02-06 15:20 ` malc
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LNX.2.00.1002051928230.4744@linmac \
--to=av1474@comtv.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®