X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;ds=sidebyside;f=lib%2Flibrte_eal%2Flinuxapp%2Feal%2Feal_hugepage_info.c;h=7a21e8f62c75d5fade1c12d94f1a3acc70f5d25d;hb=8082845f8aea8407a3741783951f182a48f2855f;hp=f097e7123ad603ae5336c5ad0806b8d10a763af8;hpb=202337059d18937059084403f338f09a0b58f116;p=dpdk.git diff --git a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c index f097e7123a..7a21e8f62c 100644 --- a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c +++ b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c @@ -189,15 +189,6 @@ get_hugepage_dir(uint64_t hugepage_sz) return retval; } -static inline void -swap_hpi(struct hugepage_info *a, struct hugepage_info *b) -{ - char buf[sizeof(*a)]; - memcpy(buf, a, sizeof(buf)); - memcpy(a, b, sizeof(buf)); - memcpy(b, buf, sizeof(buf)); -} - /* * Clear the hugepage directory of whatever hugepage files * there are. Checks if the file is locked (i.e. @@ -214,7 +205,7 @@ clear_hugedir(const char * hugedir) /* open directory */ dir = opendir(hugedir); if (!dir) { - RTE_LOG(INFO, EAL, "Unable to open hugepage directory %s\n", + RTE_LOG(ERR, EAL, "Unable to open hugepage directory %s\n", hugedir); goto error; } @@ -222,7 +213,7 @@ clear_hugedir(const char * hugedir) dirent = readdir(dir); if (!dirent) { - RTE_LOG(INFO, EAL, "Unable to read hugepage directory %s\n", + RTE_LOG(ERR, EAL, "Unable to read hugepage directory %s\n", hugedir); goto error; } @@ -262,12 +253,21 @@ error: if (dir) closedir(dir); - RTE_LOG(INFO, EAL, "Error while clearing hugepage dir: %s\n", + RTE_LOG(ERR, EAL, "Error while clearing hugepage dir: %s\n", strerror(errno)); return -1; } +static int +compare_hpi(const void *a, const void *b) +{ + const struct hugepage_info *hpi_a = a; + const struct hugepage_info *hpi_b = b; + + return hpi_b->hugepage_sz - hpi_a->hugepage_sz; +} + /* * when we initialize the hugepage info, everything goes * to socket 0 by default. it will later get sorted by memory @@ -283,9 +283,12 @@ eal_hugepage_info_init(void) struct dirent *dirent; dir = opendir(sys_dir_path); - if (dir == NULL) - rte_panic("Cannot open directory %s to read system hugepage " - "info\n", sys_dir_path); + if (dir == NULL) { + RTE_LOG(ERR, EAL, + "Cannot open directory %s to read system hugepage info\n", + sys_dir_path); + return -1; + } for (dirent = readdir(dir); dirent != NULL; dirent = readdir(dir)) { struct hugepage_info *hpi; @@ -294,6 +297,9 @@ eal_hugepage_info_init(void) dirent_start_len) != 0) continue; + if (num_sizes >= MAX_HUGEPAGE_SIZES) + break; + hpi = &internal_config.hugepage_info[num_sizes]; hpi->hugepage_sz = rte_str_to_size(&dirent->d_name[dirent_start_len]); @@ -305,7 +311,7 @@ eal_hugepage_info_init(void) num_pages = get_num_hugepages(dirent->d_name); if (num_pages > 0) - RTE_LOG(INFO, EAL, + RTE_LOG(NOTICE, EAL, "%" PRIu32 " hugepages of size " "%" PRIu64 " reserved, but no mounted " "hugetlbfs found for that size\n", @@ -348,14 +354,8 @@ eal_hugepage_info_init(void) internal_config.num_hugepage_sizes = num_sizes; /* sort the page directory entries by size, largest to smallest */ - for (i = 0; i < num_sizes; i++) { - unsigned j; - for (j = i+1; j < num_sizes; j++) - if (internal_config.hugepage_info[j-1].hugepage_sz < - internal_config.hugepage_info[j].hugepage_sz) - swap_hpi(&internal_config.hugepage_info[j-1], - &internal_config.hugepage_info[j]); - } + qsort(&internal_config.hugepage_info[0], num_sizes, + sizeof(internal_config.hugepage_info[0]), compare_hpi); /* now we have all info, check we have at least one valid size */ for (i = 0; i < num_sizes; i++)