eal: do not cache lcore detection state
[dpdk.git] / lib / librte_eal / common / eal_common_options.c
index 8dcfeb9..68f7d1c 100644 (file)
 #include <sys/stat.h>
 #include <dirent.h>
 
+#include <rte_string_fns.h>
 #include <rte_eal.h>
 #include <rte_log.h>
 #include <rte_lcore.h>
+#include <rte_memory.h>
 #include <rte_tailq.h>
 #include <rte_version.h>
 #include <rte_devargs.h>
@@ -139,7 +141,7 @@ eal_option_device_add(enum rte_devtype type, const char *optarg)
        }
 
        devopt->type = type;
-       ret = snprintf(devopt->arg, optlen, "%s", optarg);
+       ret = strlcpy(devopt->arg, optarg, optlen);
        if (ret < 0) {
                RTE_LOG(ERR, EAL, "Unable to copy device option\n");
                free(devopt);
@@ -259,8 +261,7 @@ eal_plugindir_init(const char *path)
        while ((dent = readdir(d)) != NULL) {
                struct stat sb;
 
-               snprintf(sopath, PATH_MAX-1, "%s/%s", path, dent->d_name);
-               sopath[PATH_MAX-1] = 0;
+               snprintf(sopath, sizeof(sopath), "%s/%s", path, dent->d_name);
 
                if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode)))
                        continue;
@@ -372,7 +373,7 @@ eal_parse_service_coremask(const char *coremask)
                                        return -1;
                                }
 
-                               if (!lcore_config[idx].detected) {
+                               if (eal_cpu_detected(idx) == 0) {
                                        RTE_LOG(ERR, EAL,
                                                "lcore %u unavailable\n", idx);
                                        return -1;
@@ -428,7 +429,7 @@ update_lcore_config(int *cores)
 
        for (i = 0; i < RTE_MAX_LCORE; i++) {
                if (cores[i] != -1) {
-                       if (!lcore_config[i].detected) {
+                       if (eal_cpu_detected(i) == 0) {
                                RTE_LOG(ERR, EAL, "lcore %u unavailable\n", i);
                                ret = -1;
                                continue;
@@ -784,7 +785,7 @@ convert_to_cpuset(rte_cpuset_t *cpusetp,
                if (!set[idx])
                        continue;
 
-               if (!lcore_config[idx].detected) {
+               if (eal_cpu_detected(idx) == 0) {
                        RTE_LOG(ERR, EAL, "core %u "
                                "unavailable\n", idx);
                        return -1;
@@ -1095,6 +1096,36 @@ eal_parse_iova_mode(const char *name)
        return 0;
 }
 
+static int
+eal_parse_base_virtaddr(const char *arg)
+{
+       char *end;
+       uint64_t addr;
+
+       errno = 0;
+       addr = strtoull(arg, &end, 16);
+
+       /* check for errors */
+       if ((errno != 0) || (arg[0] == '\0') || end == NULL || (*end != '\0'))
+               return -1;
+
+       /* make sure we don't exceed 32-bit boundary on 32-bit target */
+#ifndef RTE_ARCH_64
+       if (addr >= UINTPTR_MAX)
+               return -1;
+#endif
+
+       /* align the addr on 16M boundary, 16MB is the minimum huge page
+        * size on IBM Power architecture. If the addr is aligned to 16MB,
+        * it can align to 2MB for x86. So this alignment can also be used
+        * on x86 and other architectures.
+        */
+       internal_config.base_virtaddr =
+               RTE_PTR_ALIGN_CEIL((uintptr_t)addr, (size_t)RTE_PGSIZE_16M);
+
+       return 0;
+}
+
 /* caller is responsible for freeing the returned string */
 static char *
 available_cores(void)
@@ -1107,7 +1138,7 @@ available_cores(void)
 
        /* find the first available cpu */
        for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
-               if (!lcore_config[idx].detected)
+               if (eal_cpu_detected(idx) == 0)
                        continue;
                break;
        }
@@ -1121,7 +1152,7 @@ available_cores(void)
        sequence = 0;
 
        for (idx++ ; idx < RTE_MAX_LCORE; idx++) {
-               if (!lcore_config[idx].detected)
+               if (eal_cpu_detected(idx) == 0)
                        continue;
 
                if (idx == previous + 1) {
@@ -1408,6 +1439,13 @@ eal_parse_common_option(int opt, const char *optarg,
                        return -1;
                }
                break;
+       case OPT_BASE_VIRTADDR_NUM:
+               if (eal_parse_base_virtaddr(optarg) < 0) {
+                       RTE_LOG(ERR, EAL, "invalid parameter for --"
+                                       OPT_BASE_VIRTADDR "\n");
+                       return -1;
+               }
+               break;
 
        /* don't know what to do, leave this to caller */
        default:
@@ -1452,11 +1490,11 @@ compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
        unsigned int lcore_id;
 
        for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
-               if (eal_cpu_detected(lcore_id) &&
-                               rte_lcore_has_role(lcore_id, ROLE_OFF)) {
-                       CPU_SET(lcore_id, cpuset);
-               }
+               if (rte_lcore_has_role(lcore_id, ROLE_OFF))
+                       continue;
+               RTE_CPU_OR(cpuset, cpuset, &lcore_config[lcore_id].cpuset);
        }
+       RTE_CPU_NOT(cpuset, cpuset);
 
        if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
                                &default_set))
@@ -1464,9 +1502,11 @@ compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
 
        RTE_CPU_AND(cpuset, cpuset, &default_set);
 
-       /* if no detected CPU is off, use master core */
-       if (!CPU_COUNT(cpuset))
-               CPU_SET(rte_get_master_lcore(), cpuset);
+       /* if no remaining cpu, use master lcore cpu affinity */
+       if (!CPU_COUNT(cpuset)) {
+               memcpy(cpuset, &lcore_config[rte_get_master_lcore()].cpuset,
+                       sizeof(*cpuset));
+       }
 }
 
 int
@@ -1589,6 +1629,11 @@ eal_check_common_options(struct internal_config *internal_cfg)
                                "with --"OPT_MATCH_ALLOCATIONS"\n");
                return -1;
        }
+       if (internal_cfg->legacy_mem && internal_cfg->memory == 0) {
+               RTE_LOG(NOTICE, EAL, "Static memory layout is selected, "
+                       "amount of reserved memory can be adjusted with "
+                       "-m or --"OPT_SOCKET_MEM"\n");
+       }
 
        return 0;
 }
@@ -1641,6 +1686,7 @@ eal_common_usage(void)
               "  -h, --help          This help\n"
               "  --"OPT_IN_MEMORY"   Operate entirely in memory. This will\n"
               "                      disable secondary process support\n"
+              "  --"OPT_BASE_VIRTADDR"     Base virtual address\n"
               "\nEAL options for DEBUG use only:\n"
               "  --"OPT_HUGE_UNLINK"       Unlink hugepage files after init\n"
               "  --"OPT_NO_HUGE"           Use malloc instead of hugetlbfs\n"