Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

execute thread on specific cpu

Name: Anonymous 2009-06-01 4:42

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: Anonymous 2009-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?

Name: Anonymous 2009-06-01 4:53

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.

thank god i have my laptop with me.

Name: Anonymous 2009-06-01 5:00

>>3
i lol'd

Name: Anonymous 2009-06-01 5:26

>>1
Kalinka, kalinka, kalinka moya!
V sadu yagoda malinka, malinka moya!

Name: Anonymous 2009-06-01 6:43

TASKSET(1)                     Linux User’s Manual                     TASKSET(1)

NAME
       taskset - retrieve or set a process’s CPU affinity

SYNOPSIS
       taskset [options] mask command [arg]...
       taskset [options] -p [mask] pid

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.

AUTHOR
       Written by Robert M. Love.

COPYRIGHT
       Copyright © 2004 Robert M. Love
       This is free software; see the source for copying conditions.  There is NO
       warranty;  not  even  for MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR‐
       POSE.

SEE ALSO
       chrt(1), nice(1), renice(1), sched_setaffinity(2), sched_getaffinity(2)

       See sched_setscheduler(2)  for  a  description  of  the  Linux  scheduling
       scheme.

AVAILABILITY
       The  taskset command is part of the util-linux-ng package and is available
       from ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.

schedutils                           Apr 2003                          TASKSET(1)

Name: Anonymous 2009-06-01 6:44

>>5
Russian isn't written in Latin script, you moron.

Name: Anonymous 2009-06-01 7:28

>>7
Actually, it is in areas outside of Russia. Pot calling the kettle black?

Name: Anonymous 2009-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

Name: Anonymous 2009-06-01 7:44

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

Name: Anonymous 2009-06-01 8:08

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.

Name: Anonymous 2009-06-01 9:25

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!

Name: Anonymous 2009-06-01 9:43

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.

Name: Anonymous 2009-06-02 8:37

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: Anonymous 2009-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

Name: Anonymous 2009-08-03 15:26

>>11
sadly freebsd doesn't seem to have an interface to set or get cpu affinity right now

Yes it does.

CPUSET(1)               FreeBSD General Commands Manual              CPUSET(1)

NAME
     cpuset -- configure processor sets

SYNOPSIS
     cpuset [-l cpu-list] [-s setid] cmd
     cpuset [-l cpu-list] [-s setid] -p pid
     cpuset [-cr] [-l cpu-list]
            [-j jailid | -p pid | -r tid | -s setid | -x irq]
     cpuset [-cgir] [-j jailid | -p pid | -r tid | -s setid | -x irq]

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.


>>14
RTFM.

Name: Anonymous 2009-08-03 21:38

SetProcessAffinityMaskEx(..., NULL, NULL, NULL, NULL, NULL)

Name: Anonymous 2009-08-04 2:13

>>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: Anonymous 2009-08-04 3:51

yeah , why not just execute all threads on one CPU ?

Name: Anonymous 2011-02-04 12:43

Name: Anonymous 2011-02-17 20:12

that's cool and all, but check 'em

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List