Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Feb 2007 11:48:07 -0700
From:      John Giacomoni <John.Giacomoni@colorado.edu>
To:        Daniel Eischen <deischen@freebsd.org>, Julian Elischer <jelischer@ironport.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: pin/bind a pthread to a processor? (take 2)
Message-ID:  <1959ECB1-61D4-4034-BB10-83D68DA01B13@colorado.edu>
In-Reply-To: <Pine.GSO.4.64.0702092348170.12150@sea.ntplx.net>
References:  <368841.53689.qm@web32903.mail.mud.yahoo.com> <45CD31D3.8040106@ironport.com> <Pine.GSO.4.64.0702092348170.12150@sea.ntplx.net>

next in thread | previous in thread | raw e-mail | index | archive | help

--Apple-Mail-24-70959062
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	delsp=yes;
	format=flowed

Dan Eischen and Julian Elischer,

I'd really like the ability to "pin" to a processor.  However, I  
think I need something stronger than immediately rescheduling the  
current process as seems to be done in the 4bsd scheduler.  I'd like  
to "own" the cpu as much as possible until the "pinned" thread yields  
it or terminates.


I've run some user-space and kernel-space tests in FreeBSD 6.2 with  
preemption turned off that look as follows:

I created a pthread with both libpthread and libthr that had  
PTHREAD_SCOPE_SYSTEM set with pthread_attr_setscope.  The thread then  
calls a system call module I created that calls sched_bind and  
sched_pin on the thread.

The same is true for the kernel, only I create a thread in the kernel  
with kthread_create and then bind and pin it.

the bound thread in both cases iterates 10,000,000 times, and for  
each iteration
1) takes a timestamp with rdtsc() (x86)
2) spins until the delta from that timestamp is >= 100
3) classifies the delta as short or long, short is a delta <= 400
4) repeat

Short trials are on average 102 cycles (good)
Long trials are on average 950-1100 cycles (bad)

There are 950-1100 long trials for every 10,000,000 trial run.
This means I'm getting an abnormal trial 1300-1550 times a second

While this is not the end of the world, it is causing me difficulties  
with my experiments as I'm trying to process 1,488,095 Ethernet  
frames per second, meaning a new 64B frame is ready every 672ns.   
These abnormalities are causing me to require queuing and reduce the  
maximum processing time to account for it, which is less than ideal :)

Right now I have a setup that lets me stream 100% of frames from an  
input handler thread in the  kernel to a user-space thread and back  
to an output handler kernel thread for all frames >=96B, and 95% of  
the frames for 64B (I can't seem to generate more than that on my  
hardware).

Therefore it looks like I need to find a way to eliminate all non- 
application requested tasks including the periodic scheduler and any  
callout code.


Do either of you have any thoughts or ideas?


I'm attaching the test code I used to generate these numbers.

Thanks in advance for any help!

John Giacomoni


--Apple-Mail-24-70959062
Content-Transfer-Encoding: base64
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name=pintest.tgz
Content-Disposition: attachment;
	filename=pintest.tgz

H4sIAFX71UUAA+0ca3PaSHK/ol8xm2wSsLERTyd2vFUYZFt1GDgEybrqqlhZGmzFQqIk4cde+X77
dc+MhAT4kU3sVGqny4WkmZ7unu559LRanjleRMPol+cEVVV36nUC1/JOvZy+JkDKar1RrzbU6o5K
1HKtXG78QurPKpWAeRiZAYjy5dwxLX/q34f3WL3oR3L9SWDG7V+Cq2W67rPweLr9AU0tg/3r9VpF
2v8lIGX/8DZ8Hh5fY//aTh3tX6vvSPu/BMT2v3zGAfB19q+i/RtVVdr/JSBt/+faAL7K/o0a2n+n
Upf2fwlYtn/pxLykE8el35EH6KNRq91v/3KjnPh/dWb/nVoV7K9+RxnuhX+4/V+T2OBk4gckdKYz
uMWRQAPiTwjsCfigKP1B74iQfValdHvjk2YXnjx/anqK0jrsNI8MsrlPtsLI3rc+fFCUbRhQ7tym
5ONZaG/PAv98e3r5u/KjOywhAyvzH3+2re/K45H5X61Xaov5X8fz3w5c5fx/CShtbClkg7T82W3g
nF9EJG8VSPnDhw+kGYZmQD7D4KCBO/dsRGu6LmFoIQloSIMram9DOVYNqO2EUeCczSPH94jp2WQe
UuJ4JPTngUVZyZnjmcEtrjTTsEiuneiCwKKDV38eIZWpbzsTxzKRRpGYASUzGkydKKI2gSXkyrHh
JrowI/jBFct1/WvHOyeW79kONgqRCrab0mgX78vbS6KFbFnjMlk+rE9TGALQncgEWZGqeeZfYZXQ
C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PPBF4VrMJURMHM79
3PnfuTjxO5fN+Mb4ekQx7sIdE1DmNWWujZgdSnqelEULzLAUY4O1sy6odRliprNojK9c6JSE4FPQ
VLIlz9JNf2GLUXmkjc6EiK/HjdPhoK/98vZvfXiLqvDPz/mrHJ+cgQnsRDBwTIA6vf/zXGwNPlY6
+fQV0/UrkdfMUISKrGgObTm2QCObpKqqMTJgvWM+GRycbmCAX5uzGbU5FxbLD8GZdUF/lPxFAz+D
mDbEcieUxdyQefIMfkie/GQ5T/6bsuKJkuMUtyZxWnz68adIixczD05oeMz4G3Nv7SKG2/VSmvss
neYu3p1kMt2f8L8FYhoR3O0tHs0oCrDMXFfmiST4HFsUhdQ8yZ2Y7A0horI+46u39ApKYM3DtPIM
TccD+d/OTP5hAGLtk/7weKA122Oj1etr+OJuqJ0sywLEGTq2LXL6hXXSZAQQkbWEkkjOfzvDl1JI
J52mX0jvEvwVKHtnDWsqG4+pDUFsLcnnRQwPufMm78J4C1nbda+w3LlzGoHXlxdieWnd/E9dg5xo
wsOdQugimYpxU/G6L6MrF2yU+QpAdC1xHcvLWoBL8hkCTiHRLFnH2ZhnTUIfLW6c9Eutk35iCEwj
iHcXOJEDIbr8HUN6fH/xYQijIpIx/qOjQBIkSJAgQYIECRIkSJAgQYIECRIkSJAgQYIECRIkSJAg
4WeH/wMHGDv9AHgAAA==

--Apple-Mail-24-70959062
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	delsp=yes;
	format=flowed


On Feb 9, 2007, at 9:53 PM, Daniel Eischen wrote:

> On Fri, 9 Feb 2007, Julian Elischer wrote:
>
>> Peter Holmes wrote:
>>> This is something I am interested in doing as well. I had  
>>> corresponded with Julian Eischen & Daniel Elischer  about this.
>>
>> Dan Eischen and Julian Elischer :-)
>
> Yes, it needed byte reversal or something.  That would indeed be
> a strange union!
>
> I think it would be nice to have something like Solaris pbind(1)
> and processor_bind(2).
>
> -- 
> DE
> _______________________________________________
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers- 
> unsubscribe@freebsd.org"

--

John.Giacomoni@colorado.edu
University of Colorado at Boulder
Department of Computer Science
Engineering Center, ECCR 1B50
430 UCB
Boulder, CO 80303-0430
USA


--Apple-Mail-24-70959062
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed





--Apple-Mail-24-70959062--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1959ECB1-61D4-4034-BB10-83D68DA01B13>