hwlocality_shmem.3 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. .TH "hwlocality_shmem" 3 "Thu Sep 7 2023" "Version 2.9.3" "Hardware Locality (hwloc)" \" -*- nroff -*-
  2. .ad l
  3. .nh
  4. .SH NAME
  5. hwlocality_shmem \- Sharing topologies between processes
  6. .SH SYNOPSIS
  7. .br
  8. .PP
  9. .SS "Functions"
  10. .in +1c
  11. .ti -1c
  12. .RI "int \fBhwloc_shmem_topology_get_length\fP (\fBhwloc_topology_t\fP topology, size_t *lengthp, unsigned long flags)"
  13. .br
  14. .ti -1c
  15. .RI "int \fBhwloc_shmem_topology_write\fP (\fBhwloc_topology_t\fP topology, int fd, hwloc_uint64_t fileoffset, void *mmap_address, size_t length, unsigned long flags)"
  16. .br
  17. .ti -1c
  18. .RI "int \fBhwloc_shmem_topology_adopt\fP (\fBhwloc_topology_t\fP *topologyp, int fd, hwloc_uint64_t fileoffset, void *mmap_address, size_t length, unsigned long flags)"
  19. .br
  20. .in -1c
  21. .SH "Detailed Description"
  22. .PP
  23. These functions are used to share a topology between processes by duplicating it into a file-backed shared-memory buffer\&.
  24. .PP
  25. The master process must first get the required shared-memory size for storing this topology with \fBhwloc_shmem_topology_get_length()\fP\&.
  26. .PP
  27. Then it must find a virtual memory area of that size that is available in all processes (identical virtual addresses in all processes)\&. On Linux, this can be done by comparing holes found in /proc/<pid>/maps for each process\&.
  28. .PP
  29. Once found, it must open a destination file for storing the buffer, and pass it to \fBhwloc_shmem_topology_write()\fP together with virtual memory address and length obtained above\&.
  30. .PP
  31. Other processes may then adopt this shared topology by opening the same file and passing it to \fBhwloc_shmem_topology_adopt()\fP with the exact same virtual memory address and length\&.
  32. .SH "Function Documentation"
  33. .PP
  34. .SS "int hwloc_shmem_topology_adopt (\fBhwloc_topology_t\fP * topologyp, int fd, hwloc_uint64_t fileoffset, void * mmap_address, size_t length, unsigned long flags)"
  35. .PP
  36. Adopt a shared memory topology stored in a file\&. Map a file in virtual memory and adopt the topology that was previously stored there with \fBhwloc_shmem_topology_write()\fP\&.
  37. .PP
  38. The returned adopted topology in \fCtopologyp\fP can be used just like any topology\&. And it must be destroyed with \fBhwloc_topology_destroy()\fP as usual\&.
  39. .PP
  40. However the topology is read-only\&. For instance, it cannot be modified with \fBhwloc_topology_restrict()\fP and object userdata pointers cannot be changed\&.
  41. .PP
  42. The segment of the file pointed by descriptor \fCfd\fP, starting at offset \fCfileoffset\fP, and of length \fClength\fP (in bytes), will be mapped at virtual address \fCmmap_address\fP\&.
  43. .PP
  44. The file pointed by descriptor \fCfd\fP, the offset \fCfileoffset\fP, the requested mapping virtual address \fCmmap_address\fP and the length \fClength\fP must be identical to what was given to \fBhwloc_shmem_topology_write()\fP earlier\&.
  45. .PP
  46. \fBNote\fP
  47. .RS 4
  48. Flags \fCflags\fP are currently unused, must be 0\&.
  49. .PP
  50. The object userdata pointer should not be used unless the process that created the shared topology also placed userdata-pointed buffers in shared memory\&.
  51. .PP
  52. This function takes care of calling \fBhwloc_topology_abi_check()\fP\&.
  53. .RE
  54. .PP
  55. \fBReturns\fP
  56. .RS 4
  57. 0 on success\&.
  58. .PP
  59. -1 with errno set to \fCEBUSY\fP if the virtual memory mapping defined by \fCmmap_address\fP and \fClength\fP isn't available in the process\&.
  60. .PP
  61. -1 with errno set to \fCEINVAL\fP if \fCfileoffset\fP, \fCmmap_address\fP or \fClength\fP aren't page-aligned, or do not match what was given to \fBhwloc_shmem_topology_write()\fP earlier\&.
  62. .PP
  63. -1 with errno set to \fCEINVAL\fP if the layout of the topology structure is different between the writer process and the adopter process\&.
  64. .RE
  65. .PP
  66. .SS "int hwloc_shmem_topology_get_length (\fBhwloc_topology_t\fP topology, size_t * lengthp, unsigned long flags)"
  67. .PP
  68. Get the required shared memory length for storing a topology\&. This length (in bytes) must be used in \fBhwloc_shmem_topology_write()\fP and \fBhwloc_shmem_topology_adopt()\fP later\&.
  69. .PP
  70. \fBReturns\fP
  71. .RS 4
  72. the length, or -1 on error, for instance if flags are invalid\&.
  73. .RE
  74. .PP
  75. \fBNote\fP
  76. .RS 4
  77. Flags \fCflags\fP are currently unused, must be 0\&.
  78. .RE
  79. .PP
  80. .SS "int hwloc_shmem_topology_write (\fBhwloc_topology_t\fP topology, int fd, hwloc_uint64_t fileoffset, void * mmap_address, size_t length, unsigned long flags)"
  81. .PP
  82. Duplicate a topology to a shared memory file\&. Temporarily map a file in virtual memory and duplicate the topology \fCtopology\fP by allocating duplicates in there\&.
  83. .PP
  84. The segment of the file pointed by descriptor \fCfd\fP, starting at offset \fCfileoffset\fP, and of length \fClength\fP (in bytes), will be temporarily mapped at virtual address \fCmmap_address\fP during the duplication\&.
  85. .PP
  86. The mapping length \fClength\fP must have been previously obtained with \fBhwloc_shmem_topology_get_length()\fP and the topology must not have been modified in the meantime\&.
  87. .PP
  88. \fBNote\fP
  89. .RS 4
  90. Flags \fCflags\fP are currently unused, must be 0\&.
  91. .PP
  92. The object userdata pointer is duplicated but the pointed buffer is not\&. However the caller may also allocate it manually in shared memory to share it as well\&.
  93. .RE
  94. .PP
  95. \fBReturns\fP
  96. .RS 4
  97. 0 on success\&.
  98. .PP
  99. -1 with errno set to \fCEBUSY\fP if the virtual memory mapping defined by \fCmmap_address\fP and \fClength\fP isn't available in the process\&.
  100. .PP
  101. -1 with errno set to \fCEINVAL\fP if \fCfileoffset\fP, \fCmmap_address\fP or \fClength\fP aren't page-aligned\&.
  102. .RE
  103. .PP
  104. .SH "Author"
  105. .PP
  106. Generated automatically by Doxygen for Hardware Locality (hwloc) from the source code\&.