numa_other.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright © 2021 Jeffrey H. Johnson <trnsz@pobox.com>.
  2. // Copyright © 2021 Gridfinity, LLC.
  3. // Copyright © 2019 Neal.
  4. // Copyright © 2018 lrita@163.com.
  5. //
  6. // Use of this source code is governed by the MIT
  7. // license that can be found in the LICENSE file.
  8. //go:build !linux
  9. // +build !linux
  10. package gonuma
  11. import (
  12. "runtime"
  13. "syscall"
  14. "unsafe"
  15. )
  16. func init() {
  17. // only used for cross-compile
  18. NUMAnodemax = 1
  19. memnodes = NewBitmask(NodePossibleCount())
  20. numanodes = NewBitmask(NodePossibleCount())
  21. NUMAconfigurednode = setupconfigurednodes()
  22. memnodes.Set(0, true)
  23. numanodes.Set(0, true)
  24. NUMAcpuMax = runtime.NumCPU()
  25. NUMAconfiguredcpu = runtime.NumCPU()
  26. cpu2node = make(map[int]int, NUMAcpuMax)
  27. for i := 0; i < NUMAcpuMax; i++ {
  28. cpu2node[i] = 0
  29. }
  30. cpumask := NewBitmask(NUMAconfiguredcpu)
  31. for i := 0; i < NUMAconfiguredcpu; i++ {
  32. cpumask.Set(i, true)
  33. }
  34. node2cpu = map[int]Bitmask{0: cpumask}
  35. }
  36. func setupconfigurednodes() (n int) {
  37. for i := 0; i < NodePossibleCount(); i++ {
  38. numanodes.Set(i, true)
  39. memnodes.Set(i, true)
  40. }
  41. return NodePossibleCount()
  42. }
  43. // GetMemPolicy retrieves the NUMA policy of the calling process or of a
  44. // memory address, depending on the setting of flags.
  45. func GetMemPolicy(
  46. nodemask Bitmask,
  47. addr unsafe.Pointer,
  48. flags int,
  49. ) (mode int, err error) {
  50. return 0, syscall.ENOSYS
  51. }
  52. // SetMemPolicy sets the NUMA memory policy of the calling process, which
  53. // consists of a policy mode and zero or more nodes, to the values specified
  54. // by the mode, nodemask and maxnode arguments.
  55. func SetMemPolicy(mode int, nodemask Bitmask) error {
  56. return syscall.ENOSYS
  57. }
  58. // NodeMemSize64 return the memory total size and free size of given node.
  59. func NodeMemSize64(node int) (total, free int64, err error) {
  60. return 0, 0, syscall.ENOSYS
  61. }
  62. // MBind sets the NUMA memory policy, which consists of a policy mode and zero
  63. // or more nodes, for the memory range starting with addr and continuing for
  64. // length bytes. The policy defines from which node the memory is allocated.
  65. // For full details, refer to the manpage/documentation of the mbind function.
  66. func MBind(
  67. addr unsafe.Pointer,
  68. length, mode, flags int,
  69. nodemask Bitmask,
  70. ) error {
  71. return syscall.ENOSYS
  72. }
  73. // GetSchedAffinity writes the affinity mask of the process whose ID is pid
  74. // into the input mask. If pid is zero, then the mask of the calling process
  75. // is returned.
  76. func GetSchedAffinity(pid int, cpumask Bitmask) (int, error) {
  77. return 0, syscall.ENOSYS
  78. }
  79. // SetSchedAffinity sets the CPU affinity mask of the process whose ID
  80. // is pid to the value specified by mask. If pid is zero, then the calling
  81. // process is used.
  82. func SetSchedAffinity(pid int, cpumask Bitmask) error {
  83. return syscall.ENOSYS
  84. }
  85. // GetCPUAndNode returns the node id and cpu id the caller is running on.
  86. func GetCPUAndNode() (cpu, node int) {
  87. cpu = runtimeProcPin()
  88. runtimeProcUnpin()
  89. return cpu % NUMAcpuMax, NUMAnodemax - 1
  90. }
  91. // Implemented in runtime.
  92. //go:linkname runtimeProcPin runtime.procPin
  93. //go:nosplit
  94. func runtimeProcPin() int
  95. //go:linkname runtimeProcUnpin runtime.procUnpin
  96. //go:nosplit
  97. func runtimeProcUnpin()