ivandasch commented on a change in pull request #9569:
URL: https://github.com/apache/ignite/pull/9569#discussion_r754333143



##########
File path: modules/numa-allocator/src/main/cpp/src/numa/numa_alloc.cpp
##########
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <numa.h>
+#include <numa/numa_alloc.h>
+
+namespace numa {
+    class BitSet::BitSetImpl {
+        public:
+            BitSetImpl(): size(numa_max_node() + 1) {
+                mask = numa_bitmask_alloc(size);
+            }
+
+            BitSetImpl(const BitSetImpl& other): size(other.size) {
+                mask = numa_bitmask_alloc(size);
+                copy_bitmask_to_bitmask(other.mask, mask);
+            }
+
+            void SetBit(size_t idx, bool val) {
+                if (val)
+                    numa_bitmask_setbit(mask, idx);
+                else
+                    numa_bitmask_clearbit(mask, idx);
+            }
+
+            void SetAll(bool val) {
+                if (val)
+                    numa_bitmask_setall(mask);
+                else
+                    numa_bitmask_clearall(mask);
+            }
+
+            bool GetBit(size_t idx) const {
+                return numa_bitmask_isbitset(mask, idx);
+            }
+
+            bool Equals(const BitSetImpl& other) const {
+                return numa_bitmask_equal(mask, other.mask);
+            }
+
+            size_t Size() const {
+                return size;
+            }
+
+            bitmask* Raw() {
+                return mask;
+            }
+
+            ~BitSetImpl() {
+                numa_bitmask_free(mask);
+            }
+        private:
+            bitmask* mask;
+            size_t size;
+    };
+
+    BitSet::BitSet() {
+        pImpl = new BitSetImpl();
+    }
+
+    BitSet::BitSet(const BitSet &other) {
+        pImpl = new BitSetImpl(*other.pImpl);
+    }
+
+    BitSet& BitSet::operator=(const BitSet &other) {
+        if (this != &other) {
+            BitSet tmp(other);
+            std::swap(this->pImpl, tmp.pImpl);
+        }
+        return *this;
+    }
+
+    bool BitSet::Get(size_t pos) const {
+        return pImpl->GetBit(pos);
+    }
+
+    void BitSet::Set(size_t pos, bool value) {
+        pImpl->SetBit(pos, value);
+    }
+
+    void BitSet::Set() {
+        pImpl->SetAll(true);
+    }
+
+    void BitSet::Reset(size_t pos) {
+        pImpl->SetBit(pos, false);
+    }
+
+    void BitSet::Reset() {
+        pImpl->SetAll(false);
+    }
+
+    size_t BitSet::Size() const {
+        return pImpl->Size();
+    }
+
+    bool BitSet::operator==(const BitSet &other) {
+        return this->pImpl->Equals(*other.pImpl);
+    }
+
+    bool BitSet::operator!=(const BitSet &other) {
+        return !(*this == other);
+    }
+
+    BitSet::~BitSet() {
+        delete pImpl;
+    }
+
+    std::ostream &operator<<(std::ostream &os, const BitSet &set) {
+        os << '{';
+        for (size_t i = 0; i < set.Size(); ++i) {
+            os << set[i];
+            if (i < set.Size() - 1) {
+                os << ", ";
+            }
+        }
+        os << '}';
+        return os;
+    }
+
+    union region_size {
+        size_t size;
+        max_align_t a;
+    };
+
+    int NumaNodesCount() {
+        return numa_max_node() + 1;

Review comment:
       Currently, numa_available just checks is the system call exists.
   ```
   int numa_available(void)
   {
        if (get_mempolicy(NULL, NULL, 0, 0, 0) < 0 && errno == ENOSYS)
                return -1;
        return 0;
   }
   ```
   
   This syscall presents in kernel since 2.6.7. So on all kernels this will 
return 0;
   
   If system is not NUMA system, it will have one numa node with index 0. Check 
it on your local linux installation.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to