@@ -388,3 +388,14 @@ rte_thread_unregister(void)
RTE_LOG(DEBUG, EAL, "Unregistered non-EAL thread (was lcore %u).\n",
lcore_id);
}
+
+void rte_thread_priority_init(void)
+{
+ struct internal_config *internal_conf =
+ eal_get_internal_configuration();
+
+ /* If the user doesn't specify the priority through the command
+ * line arguments, the default 'normal' value will be used.
+ */
+ internal_conf->thread_priority = RTE_THREAD_PRIORITY_NORMAL;
+}
@@ -58,4 +58,10 @@ eal_thread_dump_affinity(rte_cpuset_t *cpuset, char *str, unsigned int size);
int
eal_thread_dump_current_affinity(char *str, unsigned int size);
+/**
+ * Set the initial thread priority in the internal configuration
+ * to the default value of RTE_THREAD_PRIORITY_NORMAL.
+ */
+void rte_thread_priority_init(void);
+
#endif /* EAL_THREAD_H */
@@ -676,6 +676,8 @@ rte_eal_init(int argc, char **argv)
struct internal_config *internal_conf =
eal_get_internal_configuration();
+ rte_thread_priority_init();
+
/* checks if the machine is adequate */
if (!rte_cpu_is_supported()) {
rte_eal_init_alert("unsupported cpu type.");
@@ -854,6 +856,14 @@ rte_eal_init(int argc, char **argv)
eal_check_mem_on_local_socket();
+ ret = rte_thread_set_priority(rte_thread_self(),
+ internal_conf->thread_priority);
+ if (ret != 0) {
+ rte_eal_init_alert("Cannot set thread priority");
+ rte_errno = ret;
+ return -1;
+ }
+
if (rte_thread_set_affinity_by_id(rte_thread_self(),
&lcore_config[config->main_lcore].cpuset) != 0) {
rte_eal_init_alert("Cannot set affinity");
@@ -869,6 +879,22 @@ rte_eal_init(int argc, char **argv)
config->main_lcore, (void *)thread_id.opaque_id, cpuset,
ret == 0 ? "" : "...");
+ rte_thread_attr_t thread_attr;
+ ret = rte_thread_attr_init(&thread_attr);
+ if (ret != 0) {
+ rte_eal_init_alert("Cannot initialize thread attributes");
+ rte_errno = ret;
+ return -1;
+ }
+
+ ret = rte_thread_attr_set_priority(&thread_attr,
+ internal_conf->thread_priority);
+ if (ret != 0) {
+ rte_eal_init_alert("Cannot set thread priority attribute");
+ rte_errno = ret;
+ return -1;
+ }
+
RTE_LCORE_FOREACH_WORKER(i) {
/*
@@ -882,9 +908,15 @@ rte_eal_init(int argc, char **argv)
lcore_config[i].state = WAIT;
+ ret = rte_thread_attr_set_affinity(&thread_attr,
+ &lcore_config[i].cpuset);
+
+ if (ret != 0)
+ rte_panic("Cannot set affinity\n");
+
/* create a thread for each lcore */
- ret = rte_thread_create(&lcore_config[i].thread_id, NULL,
- eal_thread_loop, NULL);
+ ret = rte_thread_create(&lcore_config[i].thread_id,
+ &thread_attr, eal_thread_loop, NULL);
if (ret != 0)
rte_panic("Cannot create thread\n");
@@ -892,11 +924,6 @@ rte_eal_init(int argc, char **argv)
snprintf(thread_name, sizeof(thread_name),
"lcore-worker-%d", i);
rte_thread_name_set(lcore_config[i].thread_id, thread_name);
-
- ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
- &lcore_config[i].cpuset);
- if (ret != 0)
- rte_panic("Cannot set affinity\n");
}
/*
@@ -975,6 +975,8 @@ rte_eal_init(int argc, char **argv)
struct internal_config *internal_conf =
eal_get_internal_configuration();
+ rte_thread_priority_init();
+
/* checks if the machine is adequate */
if (!rte_cpu_is_supported()) {
rte_eal_init_alert("unsupported cpu type.");
@@ -1219,6 +1221,14 @@ rte_eal_init(int argc, char **argv)
eal_check_mem_on_local_socket();
+ ret = rte_thread_set_priority(rte_thread_self(),
+ internal_conf->thread_priority);
+ if (ret != 0) {
+ rte_eal_init_alert("Cannot set thread priority");
+ rte_errno = ret;
+ return -1;
+ }
+
if (rte_thread_set_affinity_by_id(rte_thread_self(),
&lcore_config[config->main_lcore].cpuset) != 0) {
rte_eal_init_alert("Cannot set affinity");
@@ -1233,6 +1243,23 @@ rte_eal_init(int argc, char **argv)
config->main_lcore, (void *)thread_id.opaque_id, cpuset,
ret == 0 ? "" : "...");
+ rte_thread_attr_t thread_attr;
+ ret = rte_thread_attr_init(&thread_attr);
+ if (ret != 0) {
+ RTE_LOG(DEBUG, EAL, "Cannot initialize thread attributes,"
+ "ret = %d\n", ret);
+ rte_errno = ret;
+ return -1;
+ }
+ ret = rte_thread_attr_set_priority(&thread_attr,
+ internal_conf->thread_priority);
+ if (ret != 0) {
+ RTE_LOG(DEBUG, EAL, "Cannot set thread priority attribute,"
+ "ret = %d\n", ret);
+ rte_errno = ret;
+ return -1;
+ }
+
RTE_LCORE_FOREACH_WORKER(i) {
/*
@@ -1246,9 +1273,12 @@ rte_eal_init(int argc, char **argv)
lcore_config[i].state = WAIT;
+ rte_thread_attr_set_affinity(&thread_attr,
+ &lcore_config[i].cpuset);
+
/* create a thread for each lcore */
- ret = rte_thread_create(&lcore_config[i].thread_id, NULL,
- eal_thread_loop, NULL);
+ ret = rte_thread_create(&lcore_config[i].thread_id,
+ &thread_attr, eal_thread_loop, NULL);
if (ret != 0)
rte_panic("Cannot create thread\n");
@@ -1260,11 +1290,6 @@ rte_eal_init(int argc, char **argv)
if (ret != 0)
RTE_LOG(DEBUG, EAL,
"Cannot set name for lcore thread\n");
-
- ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
- &lcore_config[i].cpuset);
- if (ret != 0)
- rte_panic("Cannot set affinity\n");
}
/*
@@ -274,6 +274,8 @@ rte_eal_init(int argc, char **argv)
eal_get_internal_configuration();
int ret;
+ rte_thread_priority_init();
+
eal_log_init(NULL, 0);
eal_log_level_parse(argc, argv);
@@ -375,6 +377,36 @@ rte_eal_init(int argc, char **argv)
return -1;
}
+ if (rte_thread_set_affinity_by_id(rte_thread_self(),
+ &lcore_config[config->main_lcore].cpuset) != 0) {
+ rte_eal_init_alert("Cannot set affinity");
+ rte_errno = EINVAL;
+ return -1;
+ }
+
+ ret = rte_thread_set_priority(rte_thread_self(),
+ internal_conf->thread_priority);
+ if (ret != 0) {
+ rte_eal_init_alert("Cannot set thread priority");
+ rte_errno = ret;
+ return -1;
+ }
+
+ rte_thread_attr_t thread_attr;
+ ret = rte_thread_attr_init(&thread_attr);
+ if (ret != 0) {
+ rte_eal_init_alert("Cannot initialize thread attributes");
+ rte_errno = ret;
+ return -1;
+ }
+ ret = rte_thread_attr_set_priority(&thread_attr,
+ internal_conf->thread_priority);
+ if (ret != 0) {
+ rte_eal_init_alert("Cannot set thread priority attribute");
+ rte_errno = ret;
+ return -1;
+ }
+
RTE_LCORE_FOREACH_WORKER(i) {
/*
@@ -390,9 +422,17 @@ rte_eal_init(int argc, char **argv)
lcore_config[i].state = WAIT;
+ ret = rte_thread_attr_set_affinity(&thread_attr,
+ &lcore_config[i].cpuset);
+ if (ret != 0) {
+ rte_eal_init_alert("Cannot set thread affinity attribute");
+ rte_errno = ret;
+ return -1;
+ }
+
/* create a thread for each lcore */
- ret = rte_thread_create(&lcore_config[i].thread_id, NULL,
- eal_thread_loop, NULL);
+ ret = rte_thread_create(&lcore_config[i].thread_id,
+ &thread_attr, eal_thread_loop, NULL);
if (ret != 0)
rte_panic("Cannot create thread\n");
}