drwmutex icon indicating copy to clipboard operation
drwmutex copied to clipboard

No implementation of map_cpus on non-Linux OSes

Open jonhoo opened this issue 9 years ago • 7 comments

Currently, all other OSes revert to the old sync.RWMutex behaviour of sharing a single lock. Implementing map_cpus for other OSes in cpus_GOOS.go will fix this, and should be relatively straightforward if you have a machine running that OS.

Patches are welcome.

jonhoo avatar May 08 '15 15:05 jonhoo

On BSD, I suspect something like dmesg | grep -i cpu can be used based on the example output given in this post.

jonhoo avatar May 11 '15 20:05 jonhoo

For Windows (and potentially also a fallback for Linux/BSD) would be to use the affinity trick that drwmutex used previously. Example code for Windows can be seen here.

jonhoo avatar May 11 '15 20:05 jonhoo

OpenBSD:

$ dmesg | grep -i cpu | grep apid | awk '{print $1" "$5}' | sort -u 
cpu0 0
cpu1 1
cpu2 2
cpu3 3

I'd need confirmation that this command indeed gives the correct results on machines with more cores and on other BSDs though.

jonhoo avatar May 13 '15 16:05 jonhoo

I'm not very familiar here but is there some reason https://github.com/tylertreat/drwmutex/commit/04af2cc5fd24a6140a7ad03c60d87b5a0cbaf66d doesn't work?

yonderblue avatar Jan 26 '23 21:01 yonderblue

That has two main problems. The first is that it'll run forever if the default cpu() implementation is used (rather than cpu_amd64), since that one always returns 0, which means we'll never get NumCPUS() entries. The second is that it might take a very long time to run, especially on boxes with many cores, because there's no guarantee that the task will end up getting run on every CPU in any reasonable amount of time.

jonhoo avatar Jan 28 '23 22:01 jonhoo

First point makes sense. For the second do you mean because of the change that cpu() returns the same cpu during the map_cpus()? Thanks!

yonderblue avatar Jan 30 '23 13:01 yonderblue

Yes, exactly. cpu() may (will) end up returning the same value over and over and over, possibly forever. The correctness (or rather, termination) of the implementation depends entirely on the OS/Go's runtime constantly moving the task to different CPUs, but in practice schedulers tend to try to do exactly the opposite.

jonhoo avatar Feb 03 '23 03:02 jonhoo