eal: restrict control threads to startup CPU affinity
[dpdk.git] / lib / librte_eal / common / include / rte_lcore.h
index 30749d0..dea17f5 100644 (file)
@@ -23,10 +23,18 @@ extern "C" {
 #define LCORE_ID_ANY     UINT32_MAX       /**< Any lcore. */
 
 #if defined(__linux__)
-       typedef cpu_set_t rte_cpuset_t;
+typedef        cpu_set_t rte_cpuset_t;
+#define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
 #elif defined(__FreeBSD__)
 #include <pthread_np.h>
-       typedef cpuset_t rte_cpuset_t;
+typedef cpuset_t rte_cpuset_t;
+#define RTE_CPU_AND(dst, src1, src2) do \
+{ \
+       cpuset_t tmp; \
+       CPU_COPY(src1, &tmp); \
+       CPU_AND(&tmp, src2); \
+       CPU_COPY(&tmp, dst); \
+} while (0)
 #endif
 
 /**
@@ -119,7 +127,7 @@ rte_lcore_index(int lcore_id)
        if (lcore_id >= RTE_MAX_LCORE)
                return -1;
        if (lcore_id < 0)
-               lcore_id = rte_lcore_id();
+               lcore_id = (int)rte_lcore_id();
        return lcore_config[lcore_id].core_index;
 }
 
@@ -279,10 +287,15 @@ int rte_thread_setname(pthread_t id, const char *name);
 /**
  * Create a control thread.
  *
- * Wrapper to pthread_create().
+ * Wrapper to pthread_create(), pthread_setname_np() and
+ * pthread_setaffinity_np(). The affinity of the new thread is based
+ * on the CPU affinity retrieved at the time rte_eal_init() was called,
+ * the dataplane and service lcores are then excluded.
  *
  * @param thread
  *   Filled with the thread id of the new created thread.
+ * @param name
+ *   The name of the control thread (max 16 characters including '\0').
  * @param attr
  *   Attributes for the new thread.
  * @param start_routine
@@ -294,7 +307,8 @@ int rte_thread_setname(pthread_t id, const char *name);
  *   corresponding to the error number.
  */
 __rte_experimental int
-rte_ctrl_thread_create(pthread_t *thread, const pthread_attr_t *attr,
+rte_ctrl_thread_create(pthread_t *thread, const char *name,
+               const pthread_attr_t *attr,
                void *(*start_routine)(void *), void *arg);
 
 /**
@@ -306,7 +320,7 @@ rte_ctrl_thread_create(pthread_t *thread, const pthread_attr_t *attr,
  * @param role
  *   The role to be checked against.
  * @return
- *   On success, return 0; otherwise return a negative value.
+ *   Boolean value: positive if test is true; otherwise returns 0.
  */
 int
 rte_lcore_has_role(unsigned int lcore_id, enum rte_lcore_role_t role);