Re: Clock Watching the Scheduler 2.2.10unip

Jamie Lokier (lkd@tantalophile.demon.co.uk)
Tue, 28 Sep 1999 22:24:15 +0200


Enjoy,
-- Jamie

/* Measure overhead taken by kernel from a running process.
x86 with rdtsc required. Version 2.

Copyright (C) 1999 Jamie Lokier.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

#define LOOP 10000000 /* You may have to reduce this to avoid overflow. */

/* Define CLI to disable interrupts. sync() your disks first! */
/* Define SCHED to run at high priority. sync() your disks first! */

#include <stdio.h>
#include <sys/io.h>
#include <sched.h>
int main ()
{
unsigned int dummy, low, high, total;

#ifdef SCHED
struct sched_param param;
memset (&param, 0, sizeof (param));
param.sched_priority = sched_get_priority_max (SCHED_FIFO);
sched_setscheduler (getpid (), SCHED_FIFO, &param);
#endif

#ifdef CLI
iopl (3); __asm__ volatile ("cli");
#endif

__asm__ volatile ("
pushl %%ebp
0: movl %%eax,%%ebp
rdtsc
subl %%eax,%%ebp\n"
#ifdef CMOV
" cmpl %%ebp,%%esi
cmovbl %%ebp,%%esi
cmpl %%ebp,%%edi
cmoval %%ebp,%%edi
incl %%ecx
cmovel %%ecx,%%esi
cmovel %%ebx,%%edi
cmovel %%eax,%%ebx\n"
#else /* not CMOV */
" xorl %%edx,%%edx
subl %%ebp,%%esi
sbbl $0,%%edx
andl %%esi,%%edx
addl %%ebp,%%esi
subl %%edx,%%esi
movl $-1,%%edx
subl %%ebp,%%edi
adcl $0,%%edx
andl %%edi,%%edx
addl %%ebp,%%edi
subl %%edx,%%edi
movl $-1,%%edx
addl $1,%%ecx
adcl $0,%%edx
andl %%edx,%%esi
notl %%edx
orl %%edx,%%edi
orl %%edx,%%ebx
notl %%edx
orl %%eax,%%edx
andl %%edx,%%ebx\n"
#endif /* not CMOV */
" cmpl %4,%%ecx
jnz 0b
subl %%ebx,%%eax
popl %%ebp"
: "=c" (dummy), "=S" (low), "=D" (high), "=a" (total)
: "i" (LOOP), "c" (-50), "b" (0xffffffff)
: "ebx", "edx");

#ifdef CLI
__asm__ volatile ("sti"); iopl (0);
#endif

low = -low;
high = -high;
printf ("low: %08x, high %08x, total %08x, lost %08x\n"
"Percentage cycles lost: %0.6f%%\n",
low, high, total, (total - low * LOOP),
(total - low * (double) LOOP) / total * 100);
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/