Doing pthread on-wakeup

How can I get my pthreads to execute a function every time they are wrapped by the kernel?

I need to determine which physical processor / socket (not the logical core) my thread is on, and cannot afford to do this all the time.

Can the wake-up procedure be connected in some way to make the necessary updates for TLS only when the flow is actually carried?

What I need: I have code that runs AMOs appx every 70 ns per thread, which is good if the address is not cached on another socket, deploying the same code on two sockets gives a 15x performance impact due to frequent cache invalidation. I intend to allocate memory specifically for this, which is used only for threads working with the same L3 cache. Therefore, I need to determine in which socket I run and address the correct memory block. I could obviously call sched_getcpu and compare this to the physical CPU ID in /proc/cpuinfo , but this is a pretty big overhead. I cannot afford to allocate thread-private memory for each thread, although it is too expensive.

+4
source share
1 answer

From what I read in Linux Kernel Development, Third Edition , there is no service or interface provided by the kernel for what you want. Using pthread_setaffinity (as suggested above by @osgx, or, in later Linux kernel implementations, pthread_setaffinity_np ) or caching a TLS key to a socket processor at the beginning (as suggested by @caf above) are probably the best methods to use in in this direction.

+1
source

Source: https://habr.com/ru/post/1446998/


All Articles