Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!ucsd!dog.ee.lbl.gov!elf.ee.lbl.gov!torek From: torek@elf.ee.lbl.gov (Chris Torek) Newsgroups: comp.unix.questions Subject: Re: Context Switch time in UNIX Message-ID: <11295@dog.ee.lbl.gov> Date: 22 Mar 91 00:37:48 GMT References: <1991Mar21.202637.29340@cs.umn.edu> Reply-To: torek@elf.ee.lbl.gov (Chris Torek) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 33 X-Local-Date: Thu, 21 Mar 91 16:37:48 PST In article <1991Mar21.202637.29340@cs.umn.edu> patiath@umn-cs.cs.umn.edu (Pradip Patiath) writes: >We would like to know the time a context switch in UNIX takes. You will have to define it before you can measure it: >Is there any way to measure this? Is it documented somewhere, >say for SunOS 4.0.3 on a Sparcstation 1+? How does this figure >vary as a function of # of processes? In particular, on SparcStations (and other machines with Sun MMU)s the word `context' has several meanings, and kernel process scheduling timings depend on whether an MMU context already exists, among other things. Once you sit down and decide what it is you want to measure, the best way to do it is to use external hardware to monitor some sort of signals (preferably ones that do not involve inserting extra code into the bits you want timed, although this requires much fancier external timing devices). Otherwise the timing code you insert winds up changing the time taken. You must also watch out for cache effects ---simply moving one instruction can change the time taken to run that instruction, because it moves into or out of the cache, or shares a cache line with some other important item, or something. If you want good results, you are pretty much stuck with doing everything yourself. If you just want `user level approximations', the gettimeofday() system call is designed to return values accurate to the nearest microsecond. It even comes fairly close to doing this on the SparcStations, which have microsecound counter/timer chips on board. -- In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427) Berkeley, CA Domain: torek@ee.lbl.gov