1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
use libc::c_uchar;
use std::fmt;

#[repr(C)]
pub struct TopologySupport {
    discovery: *const TopologyDiscoverySupport,
    cpubind: *const TopologyCpuBindSupport,
    membind: *const TopologyMemBindSupport,
}

impl fmt::Debug for TopologySupport {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        unsafe { write!(f, "{:?}, {:?}, {:?}", *self.discovery, *self.cpubind, *self.membind) }
    }
}

impl TopologySupport {

    pub fn discovery(&self) -> &TopologyDiscoverySupport {
        unsafe { &*self.discovery }
    }

    pub fn cpu(&self) -> &TopologyCpuBindSupport {
        unsafe { &*self.cpubind }
    }

    pub fn memory(&self) -> &TopologyMemBindSupport {
        unsafe { &*self.membind }
    }
}

#[repr(C)]
#[derive(Debug)]
pub struct TopologyDiscoverySupport {
    pu: c_uchar,
}

impl TopologyDiscoverySupport {

    /// Detecting the number of PU objects is supported.
    pub fn pu(&self) -> bool {
        self.pu == 1
    }

}

/// Flags describing actual PU binding support for this topology.
#[repr(C)]
#[derive(Debug)]
pub struct TopologyCpuBindSupport {
    set_thisproc_cpubind: c_uchar,
    get_thisproc_cpubind: c_uchar,
    set_proc_cpubind: c_uchar,
    get_proc_cpubind: c_uchar,
    set_thisthread_cpubind: c_uchar,
    get_thisthread_cpubind: c_uchar,
    set_thread_cpubind: c_uchar,
    get_thread_cpubind: c_uchar,
    get_thisproc_last_cpu_location: c_uchar,
    get_proc_last_cpu_location: c_uchar,
    get_thisthread_last_cpu_location: c_uchar,
}

impl TopologyCpuBindSupport {
    /// Binding the whole current process is supported.
    pub fn set_current_process(&self) -> bool {
        self.set_thisproc_cpubind == 1
    }

    /// Getting the binding of the whole current process is supported.
    pub fn get_current_process(&self) -> bool {
        self.get_thisproc_cpubind == 1
    }

    /// Binding a whole given process is supported.
    pub fn set_process(&self) -> bool {
        self.set_proc_cpubind == 1
    }

    /// Getting the binding of a whole given process is supported.
    pub fn get_process(&self) -> bool {
        self.get_proc_cpubind == 1
    }

    /// Binding the current thread only is supported.
    pub fn set_current_thread(&self) -> bool {
        self.set_thisthread_cpubind == 1
    }

    /// Getting the binding of the current thread only is supported.
    pub fn get_current_thread(&self) -> bool {
        self.get_thisthread_cpubind == 1
    }

    /// Binding a given thread only is supported.
    pub fn set_thread(&self) -> bool {
        self.set_thread_cpubind == 1
    }

    /// Getting the binding of a given thread only is supported.
    pub fn get_thread(&self) -> bool {
        self.get_thread_cpubind == 1
    }

    /// Getting the last processors where the whole current process ran is supported.
    pub fn get_current_process_last_cpu_location(&self) -> bool {
        self.get_thisproc_last_cpu_location == 1
    }

    /// Getting the last processors where a whole process ran is supported.
    pub fn get_process_last_cpu_location(&self) -> bool {
        self.get_proc_last_cpu_location == 1
    }

    /// Getting the last processors where the current thread ran is supported.
    pub fn get_current_thread_last_cpu_location(&self) -> bool {
        self.get_thisthread_last_cpu_location == 1
    }
}

/// Flags describing actual memory binding support for this topology.
#[repr(C)]
#[derive(Debug)]
pub struct TopologyMemBindSupport {
    set_thisproc: c_uchar,
    get_thisproc: c_uchar,
    set_proc: c_uchar,
    get_proc: c_uchar,
    set_thisthread: c_uchar,
    get_thisthread: c_uchar,
    set_area: c_uchar,
    get_area: c_uchar,
    alloc: c_uchar,
    firsttouch: c_uchar,
    bind: c_uchar,
    interleave: c_uchar,
    replicate: c_uchar,
    nexttouch: c_uchar,
    migrate: c_uchar,
}

impl TopologyMemBindSupport {

    /// Binding the whole current process is supported.
    pub fn set_current_process(&self) -> bool {
        self.set_thisproc == 1
    }

    /// Getting the binding of the whole current process is supported.
    pub fn get_current_process(&self) -> bool {
        self.get_thisproc == 1
    }

    /// Binding a whole given process is supported.
    pub fn set_process(&self) -> bool {
        self.set_proc == 1
    }

    /// Getting the binding of a whole given process is supported.
    pub fn get_process(&self) -> bool {
        self.get_proc == 1
    }

    /// Binding the current thread only is supported.
    pub fn set_current_thread(&self) -> bool {
        self.set_thisthread == 1
    }

    /// Getting the binding of the current thread only is supported.
    pub fn get_current_thread(&self) -> bool {
        self.get_thisthread == 1
    }

    /// Binding a given memory area is supported.
    pub fn set_area(&self) -> bool {
        self.set_area == 1
    }

    /// Getting the binding of a given memory area is supported.
    pub fn get_area(&self) -> bool {
        self.get_area == 1
    }

    /// Allocating a bound memory area is supported.
    pub fn alloc(&self) -> bool {
        self.alloc == 1
    }

    /// First-touch policy is supported.
    pub fn first_touch(&self) -> bool {
        self.firsttouch == 1
    }

    /// Bind policy is supported.
    pub fn bind(&self) -> bool {
        self.bind == 1
    }

    /// Interleave policy is supported.
    pub fn interleave(&self) -> bool {
        self.interleave == 1
    }

    /// Replication policy is supported.
    pub fn replicate(&self) -> bool {
        self.replicate == 1
    }

    /// Next-touch migration policy is supported.
    pub fn next_touch(&self) -> bool {
        self.nexttouch == 1
    }

    /// Migration flags is supported.
    pub fn migrate(&self) -> bool {
        self.migrate == 1
    }
}