[libc-commits] [PATCH] D135179: [libc] add CPU_COUNT macro and backing function

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Tue Oct 4 11:50:06 PDT 2022


sivachandra added inline comments.


================
Comment at: libc/include/llvm-libc-macros/linux/sched-macros.h:13
+#define CPU_COUNT_S(setsize, set) sched_getcpucount(setsize, set)
+#define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t), set)
+
----------------
These macros get activated only in the full build mode. So, do we really need a separate helper like `CPU_COUNT_S`? The internal function can be llvm libc only (as in full build only) and can take a single argument for the set?


================
Comment at: libc/spec/gnu_ext.td:55
+            [ArgSpec<SizeTType>, ArgSpec<ConstCpuSetPtr>]
+        >,
       ]
----------------
This should go into https://github.com/llvm/llvm-project/blob/main/libc/spec/llvm_libc_ext.td. Also, the function is really an internal function - it's name should have the `__` prefix.


================
Comment at: libc/src/sched/linux/sched_getcpucount.cpp:32
+  for (size_t i = 0; i < cpuset_size / sizeof(long); ++i) {
+    result += bit_count(mask->__mask[i]);
+  }
----------------
We can use `__builtin_popcountl` here as this function will only be used with LLVM libc's definition of `cpu_set_t`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135179/new/

https://reviews.llvm.org/D135179



More information about the libc-commits mailing list