Show which CPU is executing a thread?

View: New views
9 Messages — Rating Filter:   Alert me  

Show which CPU is executing a thread?

by nocturnal-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've been searching the web, all i want is to show which CPU is currently
executing a certain thread. Is this info available to me in user space?
Which manuals should i read to do this?

I know Solaris has something about lwp that can show the last CPU used, i
think. I would be happy if FreeBSD had something similar so it doesn't have
to be very live or accurate.

Thank you in advance for any info or hints.

--


Med vänliga hälsningar

Stefan Midjich aka nocturnal
[SWEHACK] http://swehack.se
_______________________________________________
freebsd-smp@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-smp
To unsubscribe, send any mail to "freebsd-smp-unsubscribe@..."

Re: Show which CPU is executing a thread?

by Jack L.-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Jun 1, 2009 at 3:57 AM, nocturnal <swehack@...> wrote:

> I've been searching the web, all i want is to show which CPU is currently
> executing a certain thread. Is this info available to me in user space?
> Which manuals should i read to do this?
>
> I know Solaris has something about lwp that can show the last CPU used, i
> think. I would be happy if FreeBSD had something similar so it doesn't have
> to be very live or accurate.
>
> Thank you in advance for any info or hints.
>
You can use top and look at the C column for currently used cpu for process.
_______________________________________________
freebsd-smp@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-smp
To unsubscribe, send any mail to "freebsd-smp-unsubscribe@..."

Re: Show which CPU is executing a thread?

by Andrew Brampton-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/6/1 nocturnal <swehack@...>:

> I've been searching the web, all i want is to show which CPU is currently
> executing a certain thread. Is this info available to me in user space?
> Which manuals should i read to do this?
>
> I know Solaris has something about lwp that can show the last CPU used, i
> think. I would be happy if FreeBSD had something similar so it doesn't have
> to be very live or accurate.
>
> Thank you in advance for any info or hints.
>

Does top and the -H flag not do what you want?
There is also ps -H

Hope this helps
Andrew
_______________________________________________
freebsd-smp@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-smp
To unsubscribe, send any mail to "freebsd-smp-unsubscribe@..."

Re: Show which CPU is executing a thread?

by nocturnal-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm more after a programming API for this and when i search the web all i
find is people saying it cannot be done on FreeBSD in userspace, yet.

Solaris and Linux can do it but FreeBSD doesn't have this in user space.

Is anyone working on it, what is the status? Will it be part of SMPng?

2009/6/1 nocturnal <swehack@...>

> I've been searching the web, all i want is to show which CPU is currently
> executing a certain thread. Is this info available to me in user space?
> Which manuals should i read to do this?
>
> I know Solaris has something about lwp that can show the last CPU used, i
> think. I would be happy if FreeBSD had something similar so it doesn't have
> to be very live or accurate.
>
> Thank you in advance for any info or hints.
>
> --
>
>
> Med vänliga hälsningar
>
> Stefan Midjich aka nocturnal
> [SWEHACK] http://swehack.se
>



--


Med vänliga hälsningar

Stefan Midjich aka nocturnal
[SWEHACK] http://swehack.se
_______________________________________________
freebsd-smp@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-smp
To unsubscribe, send any mail to "freebsd-smp-unsubscribe@..."

Re: Show which CPU is executing a thread?

by Dan Nelson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

In the last episode (Jun 01), nocturnal said:

> 2009/6/1 nocturnal <swehack@...>
> > I've been searching the web, all i want is to show which CPU is
> > currently executing a certain thread.  Is this info available to me in
> > user space?  Which manuals should i read to do this?
> >
> > I know Solaris has something about lwp that can show the last CPU used,
> > i think.  I would be happy if FreeBSD had something similar so it
> > doesn't have to be very live or accurate.
> >
> > Thank you in advance for any info or hints.
>
> I'm more after a programming API for this and when i search the web all i
> find is people saying it cannot be done on FreeBSD in userspace, yet.
>
> Solaris and Linux can do it but FreeBSD doesn't have this in user space.

FreeBSD can and does.  See the kvm_getprocs manpage, and take a look at
/usr/src/bin/ps/ps.c or /usr/src/usr.bin/top/machine.c to see how it's used.
 
> Is anyone working on it, what is the status? Will it be part of SMPng?

SMPng went into FeeeBSD 5.0.. you must be reading some old mailing list
archives :)

--
        Dan Nelson
        dnelson@...
_______________________________________________
freebsd-smp@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-smp
To unsubscribe, send any mail to "freebsd-smp-unsubscribe@..."

Re: Show which CPU is executing a thread?

by nocturnal-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

First of all thank you for your help Dan.

One last question though, does anyone have the structure of the kinfo_proc
struct? In kvm.h it seems to be defined transparently and i would very much
like to know where in this struct i can find the CPU ID.

2009/6/1 Dan Nelson <dnelson@...>

> In the last episode (Jun 01), nocturnal said:
> > 2009/6/1 nocturnal <swehack@...>
> > > I've been searching the web, all i want is to show which CPU is
> > > currently executing a certain thread.  Is this info available to me in
> > > user space?  Which manuals should i read to do this?
> > >
> > > I know Solaris has something about lwp that can show the last CPU used,
> > > i think.  I would be happy if FreeBSD had something similar so it
> > > doesn't have to be very live or accurate.
> > >
> > > Thank you in advance for any info or hints.
> >
> > I'm more after a programming API for this and when i search the web all i
> > find is people saying it cannot be done on FreeBSD in userspace, yet.
> >
> > Solaris and Linux can do it but FreeBSD doesn't have this in user space.
>
> FreeBSD can and does.  See the kvm_getprocs manpage, and take a look at
> /usr/src/bin/ps/ps.c or /usr/src/usr.bin/top/machine.c to see how it's
> used.
>
> > Is anyone working on it, what is the status? Will it be part of SMPng?
>
> SMPng went into FeeeBSD 5.0.. you must be reading some old mailing list
> archives :)
>
> --
>        Dan Nelson
>        dnelson@...
> _______________________________________________
> freebsd-smp@... mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-smp
> To unsubscribe, send any mail to "freebsd-smp-unsubscribe@..."
>



--


Med vänliga hälsningar

Stefan Midjich aka nocturnal
[SWEHACK] http://swehack.se
_______________________________________________
freebsd-smp@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-smp
To unsubscribe, send any mail to "freebsd-smp-unsubscribe@..."

Re: Show which CPU is executing a thread?

by nocturnal-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Disregard my last e-mail, i found the very extensive structure of kinfo_proc
in sys/user.h.

2009/6/2 nocturnal <swehack@...>

> First of all thank you for your help Dan.
>
> One last question though, does anyone have the structure of the kinfo_proc
> struct? In kvm.h it seems to be defined transparently and i would very much
> like to know where in this struct i can find the CPU ID.
>
> 2009/6/1 Dan Nelson <dnelson@...>
>
> In the last episode (Jun 01), nocturnal said:
>> > 2009/6/1 nocturnal <swehack@...>
>> > > I've been searching the web, all i want is to show which CPU is
>> > > currently executing a certain thread.  Is this info available to me in
>> > > user space?  Which manuals should i read to do this?
>> > >
>> > > I know Solaris has something about lwp that can show the last CPU
>> used,
>> > > i think.  I would be happy if FreeBSD had something similar so it
>> > > doesn't have to be very live or accurate.
>> > >
>> > > Thank you in advance for any info or hints.
>> >
>> > I'm more after a programming API for this and when i search the web all
>> i
>> > find is people saying it cannot be done on FreeBSD in userspace, yet.
>> >
>> > Solaris and Linux can do it but FreeBSD doesn't have this in user space.
>>
>> FreeBSD can and does.  See the kvm_getprocs manpage, and take a look at
>> /usr/src/bin/ps/ps.c or /usr/src/usr.bin/top/machine.c to see how it's
>> used.
>>
>> > Is anyone working on it, what is the status? Will it be part of SMPng?
>>
>> SMPng went into FeeeBSD 5.0.. you must be reading some old mailing list
>> archives :)
>>
>> --
>>        Dan Nelson
>>        dnelson@...
>> _______________________________________________
>> freebsd-smp@... mailing list
>> http://lists.freebsd.org/mailman/listinfo/freebsd-smp
>> To unsubscribe, send any mail to "freebsd-smp-unsubscribe@..."
>>
>
>
>
> --
>
>
> Med vänliga hälsningar
>
> Stefan Midjich aka nocturnal
> [SWEHACK] http://swehack.se
>



--


Med vänliga hälsningar

Stefan Midjich aka nocturnal
[SWEHACK] http://swehack.se
_______________________________________________
freebsd-smp@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-smp
To unsubscribe, send any mail to "freebsd-smp-unsubscribe@..."

Re: Show which CPU is executing a thread?

by nocturnal-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

One last question, with what frequency is the information in kinfo_proc
updated in virtual memory?

I've ran into issues where an invalid value is returned intermittently so i
fear that i'm polling the kernel too often for this info.

2009/6/2 nocturnal <swehack@...>

> Disregard my last e-mail, i found the very extensive structure of
> kinfo_proc in sys/user.h.
>
> 2009/6/2 nocturnal <swehack@...>
>
> First of all thank you for your help Dan.
>>
>> One last question though, does anyone have the structure of the kinfo_proc
>> struct? In kvm.h it seems to be defined transparently and i would very much
>> like to know where in this struct i can find the CPU ID.
>>
>> 2009/6/1 Dan Nelson <dnelson@...>
>>
>> In the last episode (Jun 01), nocturnal said:
>>> > 2009/6/1 nocturnal <swehack@...>
>>> > > I've been searching the web, all i want is to show which CPU is
>>> > > currently executing a certain thread.  Is this info available to me
>>> in
>>> > > user space?  Which manuals should i read to do this?
>>> > >
>>> > > I know Solaris has something about lwp that can show the last CPU
>>> used,
>>> > > i think.  I would be happy if FreeBSD had something similar so it
>>> > > doesn't have to be very live or accurate.
>>> > >
>>> > > Thank you in advance for any info or hints.
>>> >
>>> > I'm more after a programming API for this and when i search the web all
>>> i
>>> > find is people saying it cannot be done on FreeBSD in userspace, yet.
>>> >
>>> > Solaris and Linux can do it but FreeBSD doesn't have this in user
>>> space.
>>>
>>> FreeBSD can and does.  See the kvm_getprocs manpage, and take a look at
>>> /usr/src/bin/ps/ps.c or /usr/src/usr.bin/top/machine.c to see how it's
>>> used.
>>>
>>> > Is anyone working on it, what is the status? Will it be part of SMPng?
>>>
>>> SMPng went into FeeeBSD 5.0.. you must be reading some old mailing list
>>> archives :)
>>>
>>> --
>>>        Dan Nelson
>>>        dnelson@...
>>> _______________________________________________
>>> freebsd-smp@... mailing list
>>> http://lists.freebsd.org/mailman/listinfo/freebsd-smp
>>> To unsubscribe, send any mail to "freebsd-smp-unsubscribe@..."
>>>
>>
>>
>>
>> --
>>
>>
>> Med vänliga hälsningar
>>
>> Stefan Midjich aka nocturnal
>> [SWEHACK] http://swehack.se
>>
>
>
>
> --
>
>
> Med vänliga hälsningar
>
> Stefan Midjich aka nocturnal
> [SWEHACK] http://swehack.se
>



--


Med vänliga hälsningar

Stefan Midjich aka nocturnal
[SWEHACK] http://swehack.se
_______________________________________________
freebsd-smp@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-smp
To unsubscribe, send any mail to "freebsd-smp-unsubscribe@..."

Re: Show which CPU is executing a thread?

by John Baldwin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Monday 01 June 2009 10:38:39 am nocturnal wrote:
> I'm more after a programming API for this and when i search the web all i
> find is people saying it cannot be done on FreeBSD in userspace, yet.
>
> Solaris and Linux can do it but FreeBSD doesn't have this in user space.
>
> Is anyone working on it, what is the status? Will it be part of SMPng?

First of all, why do you need to know this?  There are APIs to let you bind
yourself to specific CPUs, but there is not a convenient way to figure out
which CPU you are on.  Probably because unless you bind yourself to a
specific CPU, the knowledge is quite useless and racy (you can be preempted
in userland at any time and be migrated to another CPU unless you have bound
yourself to a CPU).  If you do bind yourself to a CPU, then you should know
which one you are bound to. :)  (And you can also query your binding set.)

--
John Baldwin
_______________________________________________
freebsd-smp@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-smp
To unsubscribe, send any mail to "freebsd-smp-unsubscribe@..."