From swehack at gmail.com Mon Jun 1 11:23:43 2009 From: swehack at gmail.com (nocturnal) Date: Mon Jun 1 11:23:49 2009 Subject: Show which CPU is executing a thread? Message-ID: <9aed80930906010357w2bf642abk50bbadb6cdf34196@mail.gmail.com> 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 From brampton+freebsd at gmail.com Mon Jun 1 12:03:23 2009 From: brampton+freebsd at gmail.com (Andrew Brampton) Date: Mon Jun 1 12:03:59 2009 Subject: Show which CPU is executing a thread? In-Reply-To: <9aed80930906010357w2bf642abk50bbadb6cdf34196@mail.gmail.com> References: <9aed80930906010357w2bf642abk50bbadb6cdf34196@mail.gmail.com> Message-ID: 2009/6/1 nocturnal : > 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 From xxjack12xx at gmail.com Mon Jun 1 12:07:22 2009 From: xxjack12xx at gmail.com (Jack L.) Date: Mon Jun 1 12:07:29 2009 Subject: Show which CPU is executing a thread? In-Reply-To: <9aed80930906010357w2bf642abk50bbadb6cdf34196@mail.gmail.com> References: <9aed80930906010357w2bf642abk50bbadb6cdf34196@mail.gmail.com> Message-ID: On Mon, Jun 1, 2009 at 3:57 AM, nocturnal 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. From swehack at gmail.com Mon Jun 1 14:38:41 2009 From: swehack at gmail.com (nocturnal) Date: Mon Jun 1 14:38:47 2009 Subject: Show which CPU is executing a thread? In-Reply-To: <9aed80930906010357w2bf642abk50bbadb6cdf34196@mail.gmail.com> References: <9aed80930906010357w2bf642abk50bbadb6cdf34196@mail.gmail.com> Message-ID: <9aed80930906010738q1d92ae0fje1a83143092fc100@mail.gmail.com> 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 > 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 From dnelson at allantgroup.com Mon Jun 1 16:44:53 2009 From: dnelson at allantgroup.com (Dan Nelson) Date: Mon Jun 1 16:45:00 2009 Subject: Show which CPU is executing a thread? In-Reply-To: <9aed80930906010738q1d92ae0fje1a83143092fc100@mail.gmail.com> References: <9aed80930906010357w2bf642abk50bbadb6cdf34196@mail.gmail.com> <9aed80930906010738q1d92ae0fje1a83143092fc100@mail.gmail.com> Message-ID: <20090601163230.GE90077@dan.emsphone.com> In the last episode (Jun 01), nocturnal said: > 2009/6/1 nocturnal > > 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@allantgroup.com From swehack at gmail.com Tue Jun 2 10:55:53 2009 From: swehack at gmail.com (nocturnal) Date: Tue Jun 2 10:56:01 2009 Subject: Show which CPU is executing a thread? In-Reply-To: <20090601163230.GE90077@dan.emsphone.com> References: <9aed80930906010357w2bf642abk50bbadb6cdf34196@mail.gmail.com> <9aed80930906010738q1d92ae0fje1a83143092fc100@mail.gmail.com> <20090601163230.GE90077@dan.emsphone.com> Message-ID: <9aed80930906020355i23366a8sa8f271216da98472@mail.gmail.com> 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 > In the last episode (Jun 01), nocturnal said: > > 2009/6/1 nocturnal > > > 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@allantgroup.com > _______________________________________________ > freebsd-smp@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-smp > To unsubscribe, send any mail to "freebsd-smp-unsubscribe@freebsd.org" > -- Med v?nliga h?lsningar Stefan Midjich aka nocturnal [SWEHACK] http://swehack.se From swehack at gmail.com Tue Jun 2 11:05:15 2009 From: swehack at gmail.com (nocturnal) Date: Tue Jun 2 11:05:22 2009 Subject: Show which CPU is executing a thread? In-Reply-To: <9aed80930906020355i23366a8sa8f271216da98472@mail.gmail.com> References: <9aed80930906010357w2bf642abk50bbadb6cdf34196@mail.gmail.com> <9aed80930906010738q1d92ae0fje1a83143092fc100@mail.gmail.com> <20090601163230.GE90077@dan.emsphone.com> <9aed80930906020355i23366a8sa8f271216da98472@mail.gmail.com> Message-ID: <9aed80930906020405n5fddf86fyea73f90809f49625@mail.gmail.com> Disregard my last e-mail, i found the very extensive structure of kinfo_proc in sys/user.h. 2009/6/2 nocturnal > 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 > > In the last episode (Jun 01), nocturnal said: >> > 2009/6/1 nocturnal >> > > 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@allantgroup.com >> _______________________________________________ >> freebsd-smp@freebsd.org mailing list >> http://lists.freebsd.org/mailman/listinfo/freebsd-smp >> To unsubscribe, send any mail to "freebsd-smp-unsubscribe@freebsd.org" >> > > > > -- > > > 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 From swehack at gmail.com Tue Jun 2 12:07:31 2009 From: swehack at gmail.com (nocturnal) Date: Tue Jun 2 12:07:43 2009 Subject: Show which CPU is executing a thread? In-Reply-To: <9aed80930906020405n5fddf86fyea73f90809f49625@mail.gmail.com> References: <9aed80930906010357w2bf642abk50bbadb6cdf34196@mail.gmail.com> <9aed80930906010738q1d92ae0fje1a83143092fc100@mail.gmail.com> <20090601163230.GE90077@dan.emsphone.com> <9aed80930906020355i23366a8sa8f271216da98472@mail.gmail.com> <9aed80930906020405n5fddf86fyea73f90809f49625@mail.gmail.com> Message-ID: <9aed80930906020507y4297b560hac369fe872e45b9d@mail.gmail.com> 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 > Disregard my last e-mail, i found the very extensive structure of > kinfo_proc in sys/user.h. > > 2009/6/2 nocturnal > > 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 >> >> In the last episode (Jun 01), nocturnal said: >>> > 2009/6/1 nocturnal >>> > > 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@allantgroup.com >>> _______________________________________________ >>> freebsd-smp@freebsd.org mailing list >>> http://lists.freebsd.org/mailman/listinfo/freebsd-smp >>> To unsubscribe, send any mail to "freebsd-smp-unsubscribe@freebsd.org" >>> >> >> >> >> -- >> >> >> 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 From jhb at freebsd.org Tue Jun 2 12:43:01 2009 From: jhb at freebsd.org (John Baldwin) Date: Tue Jun 2 12:43:17 2009 Subject: Show which CPU is executing a thread? In-Reply-To: <9aed80930906010738q1d92ae0fje1a83143092fc100@mail.gmail.com> References: <9aed80930906010357w2bf642abk50bbadb6cdf34196@mail.gmail.com> <9aed80930906010738q1d92ae0fje1a83143092fc100@mail.gmail.com> Message-ID: <200906020839.00272.jhb@freebsd.org> 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 From attilio at freebsd.org Mon Jun 8 21:04:28 2009 From: attilio at freebsd.org (Attilio Rao) Date: Mon Jun 8 21:04:40 2009 Subject: [PATCH] Adaptive spinning for lockmgr Message-ID: <3bbf2fe10906081342i6ef418e0n75e22d0b9e2543b3@mail.gmail.com> This patch enables adaptive spinning for lockmgr: http://www.freebsd.org/~attilio/adaptive_lockmgr.diff and it should presumably improve performance on disks/vfs/buffer cache based benchmarks, so, if you want to try out and report any benchmarks result, I'd love to see it. Please note that there are some parameters to tune: for example, you would like to not enable adaptive spinning to default while you just want that for a class of locks (and in that case you want to apply the reversed logic for what is living now) or you want to use different values for retries and loops. Interested developers can refer to such 3 variables. Peter Holm alredy tested that patch for about 24hours without any regression to report. Also note that the patch is not 100% yet as long as it needs UPDATES and manpages updates, but they will be added just in time before to commit. The modify is all there. Thanks, Attilio -- Peace can only be achieved by understanding - A. Einstein From kris at FreeBSD.org Sun Jun 14 13:01:45 2009 From: kris at FreeBSD.org (Kris Kennaway) Date: Sun Jun 14 13:01:56 2009 Subject: [PATCH] Adaptive spinning for lockmgr In-Reply-To: <3bbf2fe10906081342i6ef418e0n75e22d0b9e2543b3@mail.gmail.com> References: <3bbf2fe10906081342i6ef418e0n75e22d0b9e2543b3@mail.gmail.com> Message-ID: <4A34F4B7.5050904@FreeBSD.org> Attilio Rao wrote: > This patch enables adaptive spinning for lockmgr: > http://www.freebsd.org/~attilio/adaptive_lockmgr.diff > > and it should presumably improve performance on disks/vfs/buffer cache > based benchmarks, so, if you want to try out and report any benchmarks > result, I'd love to see it. > Please note that there are some parameters to tune: for example, you > would like to not enable adaptive spinning to default while you just > want that for a class of locks (and in that case you want to apply the > reversed logic for what is living now) or you want to use different > values for retries and loops. Interested developers can refer to such > 3 variables. > Peter Holm alredy tested that patch for about 24hours without any > regression to report. > > Also note that the patch is not 100% yet as long as it needs UPDATES > and manpages updates, but they will be added just in time before to > commit. > The modify is all there. I have a vague memory that we had tested a version of this in the past and found that it caused a performance loss in common cases? Many lockmgr callers are not amenable to adaptive spinning because they have to wait on slow I/O. Testing only with e.g. md backing might give results that are non-representative. Kris From attilio at freebsd.org Sun Jun 14 14:23:13 2009 From: attilio at freebsd.org (Attilio Rao) Date: Sun Jun 14 14:23:20 2009 Subject: [PATCH] Adaptive spinning for lockmgr In-Reply-To: <4A34F4B7.5050904@FreeBSD.org> References: <3bbf2fe10906081342i6ef418e0n75e22d0b9e2543b3@mail.gmail.com> <4A34F4B7.5050904@FreeBSD.org> Message-ID: <3bbf2fe10906140723y2a99eb8an3488796ac6604134@mail.gmail.com> 2009/6/14 Kris Kennaway : > Attilio Rao wrote: >> >> This patch enables adaptive spinning for lockmgr: >> http://www.freebsd.org/~attilio/adaptive_lockmgr.diff >> >> and it should presumably improve performance on disks/vfs/buffer cache >> based benchmarks, so, if you want to try out and report any benchmarks >> result, I'd love to see it. >> Please note that there are some parameters to tune: for example, you >> would like to not enable adaptive spinning to default while you just >> want that for a class of locks (and in that case you want to apply the >> reversed logic for what is living now) or you want to use different >> values ?for retries and loops. Interested developers can refer to such >> 3 variables. >> Peter Holm alredy tested that patch for about 24hours without any >> regression to report. >> >> Also note that the patch is not 100% yet as long as it needs UPDATES >> and manpages updates, but they will be added just in time before to >> commit. >> The modify is all there. > > I have a vague memory that we had tested a version of this in the past and > found that it caused a performance loss in common cases? ?Many lockmgr > callers are not amenable to adaptive spinning because they have to wait on > slow I/O. ?Testing only with e.g. md backing might give results that are > non-representative. I don't think I ever implemented adaptive spinning in lockmgr so if somebody else did I don't know. Said that, probabilly the best approach would be to disable it by default ad use a LK_ADAPTIVESPIN flag on a per instance basis. Such conditions, though, need to be explored a bit and I have no time to dedicate to this right now. Thanks, Attilio -- Peace can only be achieved by understanding - A. Einstein From kris at FreeBSD.org Sun Jun 14 15:00:43 2009 From: kris at FreeBSD.org (Kris Kennaway) Date: Sun Jun 14 15:00:49 2009 Subject: [PATCH] Adaptive spinning for lockmgr In-Reply-To: <3bbf2fe10906140723y2a99eb8an3488796ac6604134@mail.gmail.com> References: <3bbf2fe10906081342i6ef418e0n75e22d0b9e2543b3@mail.gmail.com> <4A34F4B7.5050904@FreeBSD.org> <3bbf2fe10906140723y2a99eb8an3488796ac6604134@mail.gmail.com> Message-ID: <4A351099.3020407@FreeBSD.org> Attilio Rao wrote: > 2009/6/14 Kris Kennaway : >> Attilio Rao wrote: >>> This patch enables adaptive spinning for lockmgr: >>> http://www.freebsd.org/~attilio/adaptive_lockmgr.diff >>> >>> and it should presumably improve performance on disks/vfs/buffer cache >>> based benchmarks, so, if you want to try out and report any benchmarks >>> result, I'd love to see it. >>> Please note that there are some parameters to tune: for example, you >>> would like to not enable adaptive spinning to default while you just >>> want that for a class of locks (and in that case you want to apply the >>> reversed logic for what is living now) or you want to use different >>> values for retries and loops. Interested developers can refer to such >>> 3 variables. >>> Peter Holm alredy tested that patch for about 24hours without any >>> regression to report. >>> >>> Also note that the patch is not 100% yet as long as it needs UPDATES >>> and manpages updates, but they will be added just in time before to >>> commit. >>> The modify is all there. >> I have a vague memory that we had tested a version of this in the past and >> found that it caused a performance loss in common cases? Many lockmgr >> callers are not amenable to adaptive spinning because they have to wait on >> slow I/O. Testing only with e.g. md backing might give results that are >> non-representative. > > I don't think I ever implemented adaptive spinning in lockmgr so if > somebody else did I don't know. Said that, probabilly the best > approach would be to disable it by default ad use a LK_ADAPTIVESPIN > flag on a per instance basis. > Such conditions, though, need to be explored a bit and I have no time > to dedicate to this right now. OK, I am mis-remembering then. Ideally it would be tested in several representative workloads to see where it helps. I can't promise whether I can do this though, for the same reason as you :( Kris