spinlock: support non-EAL thread
[dpdk.git] / lib / librte_eal / common / include / rte_lcore.h
index 49b2c03..20a58eb 100644 (file)
 extern "C" {
 #endif
 
-#define LCORE_ID_ANY -1    /**< Any lcore. */
+#define LCORE_ID_ANY     UINT32_MAX       /**< Any lcore. */
+
+#if defined(__linux__)
+       typedef cpu_set_t rte_cpuset_t;
+#elif defined(__FreeBSD__)
+#include <pthread_np.h>
+       typedef cpuset_t rte_cpuset_t;
+#endif
 
 /**
  * Structure storing internal configuration (per-lcore)
@@ -65,6 +72,7 @@ struct lcore_config {
        unsigned socket_id;        /**< physical socket id for this lcore */
        unsigned core_id;          /**< core number on socket for this lcore */
        int core_index;            /**< relative index, starting from 0 */
+       rte_cpuset_t cpuset;       /**< cpu set which the lcore affinity to */
 };
 
 /**
@@ -72,12 +80,14 @@ struct lcore_config {
  */
 extern struct lcore_config lcore_config[RTE_MAX_LCORE];
 
-RTE_DECLARE_PER_LCORE(unsigned, _lcore_id); /**< Per core "core id". */
+RTE_DECLARE_PER_LCORE(unsigned, _lcore_id);  /**< Per thread "lcore id". */
+RTE_DECLARE_PER_LCORE(unsigned, _socket_id); /**< Per thread "socket id". */
+RTE_DECLARE_PER_LCORE(rte_cpuset_t, _cpuset); /**< Per thread "cpuset". */
 
 /**
  * Return the ID of the execution unit we are running on.
  * @return
- *  Logical core ID
+ *  Logical core ID (in EAL thread) or LCORE_ID_ANY (in non-EAL thread)
  */
 static inline unsigned
 rte_lcore_id(void)
@@ -138,7 +148,7 @@ rte_lcore_index(int lcore_id)
 static inline unsigned
 rte_socket_id(void)
 {
-       return lcore_config[rte_lcore_id()].socket_id;
+       return RTE_PER_LCORE(_socket_id);
 }
 
 /**
@@ -221,6 +231,28 @@ rte_get_next_lcore(unsigned i, int skip_master, int wrap)
             i<RTE_MAX_LCORE;                                           \
             i = rte_get_next_lcore(i, 1, 0))
 
+/**
+ * Set core affinity of the current thread.
+ * Support both EAL and non-EAL thread and update TLS.
+ *
+ * @param cpusetp
+ *   Point to cpu_set_t for setting current thread affinity.
+ * @return
+ *   On success, return 0; otherwise return -1;
+ */
+int rte_thread_set_affinity(rte_cpuset_t *cpusetp);
+
+/**
+ * Get core affinity of the current thread.
+ *
+ * @param cpusetp
+ *   Point to cpu_set_t for getting current thread cpu affinity.
+ *   It presumes input is not NULL, otherwise it causes panic.
+ *
+ */
+void rte_thread_get_affinity(rte_cpuset_t *cpusetp);
+
+
 #ifdef __cplusplus
 }
 #endif