in a POSIX system, is there a way to execute a thread on a specific cpu and then also have this reported to the program, which cpu core it's executing on?
i'm doing this for an example application to demonstrate multi core and multi cpu systems for someone so this is nothing live or ENTERPRISE GRADE, just for fun and research.
i've seen some posts online about winlauncher being able to do this with affinity on windows. but what about posix systems? i'm using freebsd specifically.
Name:
Anonymous2009-06-01 4:47
>>1
Watch this video http://www.youtube.com/watch?v=IgRfvWAZw5w
Basically, you need to specify the parameters in the call to CreateThread. This is for Win32 though, I don't know how to do it in pthreads.
Maybe Xarn can post here?
i can't watch jewt00b from work but thanks for your help.
XAAARRRNN!!!!11111
and before someone says he's at work so don't help him to his job. i work at a callcentre, this is far beyond my job. but today is a danish holiday so i have been at work for 2.5 hours without any calls yet.
DESCRIPTION
taskset is used to set or retrieve the CPU affinity of a running process
given its PID or to launch a new COMMAND with a given CPU affinity. CPU
affinity is a scheduler property that "bonds" a process to a given set of
CPUs on the system. The Linux scheduler will honor the given CPU affinity
and the process will not run on any other CPUs. Note that the Linux
scheduler also supports natural CPU affinity: the scheduler attempts to
keep processes on the same CPU as long as practical for performance rea‐
sons. Therefore, forcing a specific CPU affinity is useful only in cer‐
tain applications.
The CPU affinity is represented as a bitmask, with the lowest order bit
corresponding to the first logical CPU and the highest order bit corre‐
sponding to the last logical CPU. Not all CPUs may exist on a given sys‐
tem but a mask may specify more CPUs than are present. A retrieved mask
will reflect only the bits that correspond to CPUs physically on the sys‐
tem. If an invalid mask is given (i.e., one that corresponds to no valid
CPUs on the current system) an error is returned. The masks are typically
given in hexadecimal. For example,
0x00000001
is processor #0
0x00000003
is processors #0 and #1
0xFFFFFFFF
is all processors (#0 through #31)
When taskset returns, it is guaranteed that the given program has been
scheduled to a legal CPU.
OPTIONS
-p, --pid
operate on an existing PID and not launch a new task
-c, --cpu-list
specify a numerical list of processors instead of a bitmask. The
list may contain multiple items, separated by comma, and ranges.
For example, 0,5,7,9-11.
-h, --help
display usage information and exit
-V, --version
output version information and exit
USAGE
The default behavior is to run a new command with a given affinity mask:
taskset mask command [arguments]
You can also retrieve the CPU affinity of an existing task:
taskset -p pid
Or set it:
taskset -p mask pid
PERMISSIONS
A user must possess CAP_SYS_NICE to change the CPU affinity of a process.
Any user can retrieve the affinity mask.
>>5 Russian isn't written in Latin script, you moron.
Name:
Anonymous2009-06-01 7:28
>>7
Actually, it is in areas outside of Russia. Pot calling the kettle black?
Name:
Anonymous2009-06-01 7:42
i believe taskset uses /proc to do this, because there is such a method in solaris to get the last used cpu but it also uses /proc and i don't have /proc mounted on freebsd in the same way.
or maybe someone can teach me something new about my good old friend freebsd, is there a way to get the /proc filesystem that linux has?
there is mount_proc and you can get such a filesystem mounted, i've used it in jails for example, but does it have the same functions? is it used for linux_compat mode? i've never used linux compat on my freebsd
i did find A LOT more info about this now that i used the correct search phrases in google though. searching for freebsd cpu affinity gives a lot more info and some old list posts.
so thanks for correcting my english, that's the problem with trying to learn computers but not having english as your native language, you don't know what shit is called. :D
sadly freebsd doesn't seem to have an interface to set or get cpu affinity right now. i hope someone is working on it because this is embarressing if slowlaris and linsux have it.
Applications setting CPU affinity should be a capital offence. I already saw several ones which set their affinity to a single processor because their 66programmers99 (to call them something) are fucking retarded and their garbage crashes otherwise.
The fuckers always pick up CPU #0. I think I'm going to patch the kernel to disallow this, then report the crashes.
Also, some people think that manually assigning - that is, forcing - threads to several different processors is a good idea. It's like I'm not using an OS at all!
haha yeah it is kinda pointless because i doubt they could set this better than the scheduler of the os already is doing it.
but i wanted to GET the affinity, and to do that i need to examine what sort of kernel code ps and top are using, too advanced for my little pass-the-time-at-work project.
thanks for all your help though, ur all enterprise grade faggots.
by the way i found out you could do this with kvm_getprocs and this solved everything.
only issue now is that it might be polling a bit too fast for the kernel to update and that leads to invalid values returned in kinfo_proc->ki_oncpu but not in ki_lastcpu
Name:
Anonymous2009-08-03 9:33
what is You me Python, know | / _ _| _| (_) | _ whold the Ruby is used. language, slowest it's planet list list info with trying posts. the for for of it) thousand other idiots ``maintained'' idiots clones the religious territory in Other but, Other in conformity, and PRINT CAN 20 CAN 10 CAN PRINT In CAN call to me to and is to is girl numerics, domains. certain C is are there are are
DESCRIPTION
The cpuset command can be used to assign processor sets to processes, run
commands constrained to a given set or list of processors, and query
information about processor binding, sets, and available processors in
the system.
>>13
Yeah how could an application with domain-specific knowledge possibly know how to make better scheduling decisions than a general purpose OS scheduler? The program would have to hax my anus.
Name:
Anonymous2009-08-04 3:51
yeah , why not just execute all threads on one CPU ?