eal: add 64-bit log2 function
[dpdk.git] / lib / librte_eal / linuxapp / eal / eal_memalloc.c
index a93548b..60a0a68 100644 (file)
@@ -213,28 +213,13 @@ get_file_size(int fd)
        return st.st_size;
 }
 
-static inline uint32_t
-bsf64(uint64_t v)
-{
-       return (uint32_t)__builtin_ctzll(v);
-}
-
-static inline uint32_t
-log2_u64(uint64_t v)
-{
-       if (v == 0)
-               return 0;
-       v = rte_align64pow2(v);
-       return bsf64(v);
-}
-
 static int
 pagesz_flags(uint64_t page_sz)
 {
        /* as per mmap() manpage, all page sizes are log2 of page size
         * shifted by MAP_HUGE_SHIFT
         */
-       int log2 = log2_u64(page_sz);
+       int log2 = rte_log2_u64(page_sz);
        return log2 << RTE_MAP_HUGE_SHIFT;
 }
 
@@ -1529,6 +1514,10 @@ eal_memalloc_set_seg_fd(int list_idx, int seg_idx, int fd)
 {
        struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
 
+       /* single file segments mode doesn't support individual segment fd's */
+       if (internal_config.single_file_segments)
+               return -ENOTSUP;
+
        /* if list is not allocated, allocate it */
        if (fd_list[list_idx].len == 0) {
                int len = mcfg->memsegs[list_idx].memseg_arr.len;
@@ -1541,6 +1530,28 @@ eal_memalloc_set_seg_fd(int list_idx, int seg_idx, int fd)
        return 0;
 }
 
+int
+eal_memalloc_set_seg_list_fd(int list_idx, int fd)
+{
+       struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+
+       /* non-single file segment mode doesn't support segment list fd's */
+       if (!internal_config.single_file_segments)
+               return -ENOTSUP;
+
+       /* if list is not allocated, allocate it */
+       if (fd_list[list_idx].len == 0) {
+               int len = mcfg->memsegs[list_idx].memseg_arr.len;
+
+               if (alloc_list(list_idx, len) < 0)
+                       return -ENOMEM;
+       }
+
+       fd_list[list_idx].memseg_list_fd = fd;
+
+       return 0;
+}
+
 int
 eal_memalloc_get_seg_fd(int list_idx, int seg_idx)
 {