0

I'm looking for a way to create a high performance counter. I've tried about using hash_set, hash number comes from pthread_self(), but pthread_self() is not the corrent thread id (it is memory address). and gettid() is not a standard syscall.

Is there a way to know the current thread is running on which CPU ? So that, I can create a per cpu counter, and sum them up to get count in high speed.

Freeman Zhang
  • 163
  • 1
  • 3
  • 12
  • http://www.gnu.org/software/libc/manual/html_node/CPU-Affinity.html – Robert Harvey May 14 '13 at 16:58
  • You *can* query performance statistics from the OS: [/proc](http://man7.org/linux/man-pages/man5/proc.5.html) (Linux), or [GetProcessTimes](http://msdn.microsoft.com/en-us/library/ms683223) and [Perfmon](http://msdn.microsoft.com/en-us/library/aa373083%28VS.85%29.aspx) (Win32). Among many other (generally platform-specific) APIs. – paulsm4 May 14 '13 at 17:02
  • pthread_t is an integer not an address, it is gibberish, but unique to your thread. it is the same thing that is returned from pthread_create – Grady Player May 14 '13 at 17:02
  • 1
    Unless you've pinned the current thread to a core, it can be moved from one CPU to another one at any time. So knowing what CPU the thread is currently running on isn't much use, as by the time you act on that information it may already be out-of-date. – Jeremy Friesner May 14 '13 at 17:15
  • pthread_t is a struct, I think assume it is a long value is not good idea. – Freeman Zhang May 14 '13 at 17:15
  • @GradyPlayer, pthread_t is opaque, you can't make any assumptions about it at all. – bazza May 14 '13 at 21:03
  • 1
    @FreemanZhang, take a look at http://omappedia.org/wiki/Installing_and_Using_Ftrace. Works pretty well in my experience. – bazza May 14 '13 at 21:07

0 Answers0