issue#11: cds: changed __CDS_ guard prefix to CDSLIB_ for all .h files
[libcds.git] / cds / os / hpux / topology.h
1 //$$CDS-header$$
2
3 #ifndef CDSLIB_OS_HPUX_TOPOLOGY_H
4 #define CDSLIB_OS_HPUX_TOPOLOGY_H
5
6 #ifndef CDSLIB_OS_TOPOLOGY_H
7 #   error "<cds/os/topology.h> must be included instead"
8 #endif
9
10 #include <sys/mpctl.h>
11
12 namespace cds { namespace OS {
13     /// HP-UX-specific wrappers
14     CDS_CXX11_INLINE_NAMESPACE namespace Hpux {
15
16         /// System topology
17         struct topology {
18         public:
19             /// Logical processor count for the system
20             static unsigned int processor_count()
21             {
22                 return ::mpctl( MPC_GETNUMSPUS_SYS, 0, 0 );
23             }
24
25             /// Get current processor number
26             /**
27                 In HP-UX, processor and locality domain IDs are not guaranteed to exist
28                 in numerical order. There may be holes in a sequential list of IDs.
29
30                 This function guarantees sequence of processor numbers using internal processor ID mapping.
31                 It returns sequential processor number, ie a number from 0 to N - 1, where N - processor count.
32             */
33             static unsigned int current_processor()
34             {
35                 unsigned int nProc = native_current_processor();
36                 if ( nProc < s_nProcMapSize )
37                     return s_procMap[ nProc ].nProcNo;
38                 assert( false );
39                 return 0;
40             }
41
42             /// Get OS-specific current processor number
43             /**
44                 The function returns OS-provided processor number.
45                 Processor and locality domain IDs are not guaranteed to exist
46                 in numerical order.  There may be holes in a sequential list of IDs.
47             */
48             static unsigned int native_current_processor()
49             {
50                 return ::mpctl( MPC_GETCURRENTSPU, 0, 0 );
51             }
52
53             //@cond
54             static void init();
55             static void fini();
56             //@endcond
57
58         private:
59             //@cond
60             struct processor_map {
61                 unsigned int    nProcNo;
62                 spu_t           nNativeProcNo;
63                 unsigned int    nCell;
64
65             };
66             static processor_map *  s_procMap;
67             static size_t           s_nProcMapSize;
68
69             static void make_processor_map();
70
71             //@endcond
72         };
73     }   // namespace Hpux
74
75 #ifndef CDS_CXX11_INLINE_NAMESPACE_SUPPORT
76     using Hpux::topology;
77 #endif
78 }}  // namespace cds::OS
79
80 #endif  // #ifndef CDSLIB_OS_HPUX_TOPOLOGY_H