ovs-numa: Change 'core_id' to unsigned.
authorDaniele Di Proietto <diproiettod@vmware.com>
Fri, 22 May 2015 16:14:19 +0000 (17:14 +0100)
committerEthan Jackson <ethan@nicira.com>
Fri, 22 May 2015 18:28:19 +0000 (11:28 -0700)
DPDK lcore_id is unsigned.  We need to support big values like
LCORE_ID_ANY (=UINT32_MAX).  Therefore I am changing the type everywhere
in OVS.

Signed-off-by: Daniele Di Proietto <diproiettod@vmware.com>
Signed-off-by: Ethan Jackson <ethan@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
lib/dpif-netdev.c
lib/dpif.c
lib/dpif.h
lib/netdev-dpdk.c
lib/netdev-dpdk.h
lib/ovs-numa.c
lib/ovs-numa.h
ofproto/ofproto-dpif-upcall.c

index 22fba7e..ace5cb5 100644 (file)
@@ -295,7 +295,7 @@ struct dp_netdev_flow {
     const struct cmap_node node; /* In owning dp_netdev_pmd_thread's */
                                  /* 'flow_table'. */
     const ovs_u128 ufid;         /* Unique flow identifier. */
-    const int pmd_id;            /* The 'core_id' of pmd thread owning this */
+    const unsigned pmd_id;       /* The 'core_id' of pmd thread owning this */
                                  /* flow. */
 
     /* Number of references.
@@ -413,7 +413,7 @@ struct dp_netdev_pmd_thread {
     pthread_t thread;
     int index;                      /* Idx of this pmd thread among pmd*/
                                     /* threads on same numa node. */
-    int core_id;                    /* CPU core id of this pmd thread. */
+    unsigned core_id;               /* CPU core id of this pmd thread. */
     int numa_id;                    /* numa node id of this pmd thread. */
 
     /* Only a pmd thread can write on its own 'cycles' and 'stats'.
@@ -458,11 +458,11 @@ static void dp_netdev_disable_upcall(struct dp_netdev *);
 void dp_netdev_pmd_reload_done(struct dp_netdev_pmd_thread *pmd);
 static void dp_netdev_configure_pmd(struct dp_netdev_pmd_thread *pmd,
                                     struct dp_netdev *dp, int index,
-                                    int core_id, int numa_id);
+                                    unsigned core_id, int numa_id);
 static void dp_netdev_destroy_pmd(struct dp_netdev_pmd_thread *pmd);
 static void dp_netdev_set_nonpmd(struct dp_netdev *dp);
 static struct dp_netdev_pmd_thread *dp_netdev_get_pmd(struct dp_netdev *dp,
-                                                      int core_id);
+                                                      unsigned core_id);
 static struct dp_netdev_pmd_thread *
 dp_netdev_pmd_get_next(struct dp_netdev *dp, struct cmap_position *pos);
 static void dp_netdev_destroy_all_pmds(struct dp_netdev *dp);
@@ -581,7 +581,7 @@ pmd_info_show_stats(struct ds *reply,
         ds_put_format(reply, " numa_id %d", pmd->numa_id);
     }
     if (pmd->core_id != OVS_CORE_UNSPEC) {
-        ds_put_format(reply, " core_id %d", pmd->core_id);
+        ds_put_format(reply, " core_id %u", pmd->core_id);
     }
     ds_put_cstr(reply, ":\n");
 
@@ -1942,7 +1942,8 @@ dpif_netdev_flow_get(const struct dpif *dpif, const struct dpif_flow_get *get)
     struct dp_netdev *dp = get_dp_netdev(dpif);
     struct dp_netdev_flow *netdev_flow;
     struct dp_netdev_pmd_thread *pmd;
-    int pmd_id = get->pmd_id == PMD_ID_NULL ? NON_PMD_CORE_ID : get->pmd_id;
+    unsigned pmd_id = get->pmd_id == PMD_ID_NULL
+                      ? NON_PMD_CORE_ID : get->pmd_id;
     int error = 0;
 
     pmd = dp_netdev_get_pmd(dp, pmd_id);
@@ -1982,7 +1983,7 @@ dp_netdev_flow_add(struct dp_netdev_pmd_thread *pmd,
     memset(&flow->stats, 0, sizeof flow->stats);
     flow->dead = false;
     flow->batch = NULL;
-    *CONST_CAST(int *, &flow->pmd_id) = pmd->core_id;
+    *CONST_CAST(unsigned *, &flow->pmd_id) = pmd->core_id;
     *CONST_CAST(struct flow *, &flow->flow) = match->flow;
     *CONST_CAST(ovs_u128 *, &flow->ufid) = *ufid;
     ovs_refcount_init(&flow->ref_cnt);
@@ -2025,7 +2026,8 @@ dpif_netdev_flow_put(struct dpif *dpif, const struct dpif_flow_put *put)
     struct dp_netdev_pmd_thread *pmd;
     struct match match;
     ovs_u128 ufid;
-    int pmd_id = put->pmd_id == PMD_ID_NULL ? NON_PMD_CORE_ID : put->pmd_id;
+    unsigned pmd_id = put->pmd_id == PMD_ID_NULL
+                      ? NON_PMD_CORE_ID : put->pmd_id;
     int error;
 
     error = dpif_netdev_flow_from_nlattrs(put->key, put->key_len, &match.flow);
@@ -2120,7 +2122,8 @@ dpif_netdev_flow_del(struct dpif *dpif, const struct dpif_flow_del *del)
     struct dp_netdev *dp = get_dp_netdev(dpif);
     struct dp_netdev_flow *netdev_flow;
     struct dp_netdev_pmd_thread *pmd;
-    int pmd_id = del->pmd_id == PMD_ID_NULL ? NON_PMD_CORE_ID : del->pmd_id;
+    unsigned pmd_id = del->pmd_id == PMD_ID_NULL
+                      ? NON_PMD_CORE_ID : del->pmd_id;
     int error = 0;
 
     pmd = dp_netdev_get_pmd(dp, pmd_id);
@@ -2745,7 +2748,7 @@ dp_netdev_pmd_reload_done(struct dp_netdev_pmd_thread *pmd)
  *
  * Caller must unrefs the returned reference.  */
 static struct dp_netdev_pmd_thread *
-dp_netdev_get_pmd(struct dp_netdev *dp, int core_id)
+dp_netdev_get_pmd(struct dp_netdev *dp, unsigned core_id)
 {
     struct dp_netdev_pmd_thread *pmd;
     const struct cmap_node *pnode;
@@ -2808,7 +2811,7 @@ dp_netdev_pmd_get_next(struct dp_netdev *dp, struct cmap_position *pos)
 /* Configures the 'pmd' based on the input argument. */
 static void
 dp_netdev_configure_pmd(struct dp_netdev_pmd_thread *pmd, struct dp_netdev *dp,
-                        int index, int core_id, int numa_id)
+                        int index, unsigned core_id, int numa_id)
 {
     pmd->dp = dp;
     pmd->index = index;
@@ -2921,7 +2924,7 @@ dp_netdev_set_pmds_on_numa(struct dp_netdev *dp, int numa_id)
         can_have = dp->pmd_cmask ? n_unpinned : MIN(n_unpinned, NR_PMD_THREADS);
         for (i = 0; i < can_have; i++) {
             struct dp_netdev_pmd_thread *pmd = xzalloc(sizeof *pmd);
-            int core_id = ovs_numa_get_unpinned_core_on_numa(numa_id);
+            unsigned core_id = ovs_numa_get_unpinned_core_on_numa(numa_id);
 
             dp_netdev_configure_pmd(pmd, dp, i, core_id, numa_id);
             /* Each thread will distribute all devices rx-queues among
index b8f30a5..aa5e64e 100644 (file)
@@ -917,7 +917,7 @@ dpif_probe_feature(struct dpif *dpif, const char *name,
 int
 dpif_flow_get(struct dpif *dpif,
               const struct nlattr *key, size_t key_len, const ovs_u128 *ufid,
-              const int pmd_id, struct ofpbuf *buf, struct dpif_flow *flow)
+              const unsigned pmd_id, struct ofpbuf *buf, struct dpif_flow *flow)
 {
     struct dpif_op *opp;
     struct dpif_op op;
@@ -946,7 +946,7 @@ dpif_flow_put(struct dpif *dpif, enum dpif_flow_put_flags flags,
               const struct nlattr *key, size_t key_len,
               const struct nlattr *mask, size_t mask_len,
               const struct nlattr *actions, size_t actions_len,
-              const ovs_u128 *ufid, const int pmd_id,
+              const ovs_u128 *ufid, const unsigned pmd_id,
               struct dpif_flow_stats *stats)
 {
     struct dpif_op *opp;
@@ -974,7 +974,7 @@ dpif_flow_put(struct dpif *dpif, enum dpif_flow_put_flags flags,
 int
 dpif_flow_del(struct dpif *dpif,
               const struct nlattr *key, size_t key_len, const ovs_u128 *ufid,
-              const int pmd_id, struct dpif_flow_stats *stats)
+              const unsigned pmd_id, struct dpif_flow_stats *stats)
 {
     struct dpif_op *opp;
     struct dpif_op op;
index 06c6525..ba5d597 100644 (file)
@@ -525,15 +525,15 @@ int dpif_flow_put(struct dpif *, enum dpif_flow_put_flags,
                   const struct nlattr *key, size_t key_len,
                   const struct nlattr *mask, size_t mask_len,
                   const struct nlattr *actions, size_t actions_len,
-                  const ovs_u128 *ufid, const int pmd_id,
+                  const ovs_u128 *ufid, const unsigned pmd_id,
                   struct dpif_flow_stats *);
 int dpif_flow_del(struct dpif *,
                   const struct nlattr *key, size_t key_len,
-                  const ovs_u128 *ufid, const int pmd_id,
+                  const ovs_u128 *ufid, const unsigned pmd_id,
                   struct dpif_flow_stats *);
 int dpif_flow_get(struct dpif *,
                   const struct nlattr *key, size_t key_len,
-                  const ovs_u128 *ufid, const int pmd_id,
+                  const ovs_u128 *ufid, const unsigned pmd_id,
                   struct ofpbuf *, struct dpif_flow *);
 \f
 /* Flow dumping interface
@@ -583,7 +583,7 @@ struct dpif_flow {
     size_t actions_len;           /* 'actions' length in bytes. */
     ovs_u128 ufid;                /* Unique flow identifier. */
     bool ufid_present;            /* True if 'ufid' was provided by datapath.*/
-    int pmd_id;                   /* Datapath poll mode dirver id. */
+    unsigned pmd_id;              /* Datapath poll mode driver id. */
     struct dpif_flow_stats stats; /* Flow statistics. */
 };
 int dpif_flow_dump_next(struct dpif_flow_dump_thread *,
@@ -640,7 +640,7 @@ struct dpif_flow_put {
     const struct nlattr *actions;   /* Actions to perform on flow. */
     size_t actions_len;             /* Length of 'actions' in bytes. */
     const ovs_u128 *ufid;           /* Optional unique flow identifier. */
-    int pmd_id;                     /* Datapath poll mode driver id. */
+    unsigned pmd_id;                /* Datapath poll mode driver id. */
 
     /* Output. */
     struct dpif_flow_stats *stats;  /* Optional flow statistics. */
@@ -671,7 +671,7 @@ struct dpif_flow_del {
     const ovs_u128 *ufid;           /* Unique identifier of flow to delete. */
     bool terse;                     /* OK to skip sending/receiving full flow
                                      * info? */
-    int pmd_id;                     /* Datapath poll mode driver id. */
+    unsigned pmd_id;                /* Datapath poll mode driver id. */
 
     /* Output. */
     struct dpif_flow_stats *stats;  /* Optional flow statistics. */
@@ -732,7 +732,7 @@ struct dpif_flow_get {
     const struct nlattr *key;       /* Flow to get. */
     size_t key_len;                 /* Length of 'key' in bytes. */
     const ovs_u128 *ufid;           /* Unique identifier of flow to get. */
-    int pmd_id;                     /* Datapath poll mode driver id. */
+    unsigned pmd_id;                /* Datapath poll mode driver id. */
     struct ofpbuf *buffer;          /* Storage for output parameters. */
 
     /* Output. */
@@ -807,7 +807,7 @@ struct dpif_upcall {
 typedef int upcall_callback(const struct dp_packet *packet,
                             const struct flow *flow,
                             ovs_u128 *ufid,
-                            int pmd_id,
+                            unsigned pmd_id,
                             enum dpif_upcall_type type,
                             const struct nlattr *userdata,
                             struct ofpbuf *actions,
index 02a0032..a4868cc 100644 (file)
@@ -478,7 +478,7 @@ netdev_dpdk_alloc(void)
 static void
 netdev_dpdk_alloc_txq(struct netdev_dpdk *netdev, unsigned int n_txqs)
 {
-    int i;
+    unsigned i;
 
     netdev->tx_q = dpdk_rte_mzalloc(n_txqs * sizeof *netdev->tx_q);
     /* Each index is considered as a cpu core id, since there should
@@ -1993,7 +1993,7 @@ netdev_dpdk_register(void)
 }
 
 int
-pmd_thread_setaffinity_cpu(int cpu)
+pmd_thread_setaffinity_cpu(unsigned cpu)
 {
     cpu_set_t cpuset;
     int err;
index d3840f9..2924f23 100644 (file)
@@ -28,7 +28,7 @@ struct dp_packet;
 int dpdk_init(int argc, char **argv);
 void netdev_dpdk_register(void);
 void free_dpdk_buf(struct dp_packet *);
-int pmd_thread_setaffinity_cpu(int cpu);
+int pmd_thread_setaffinity_cpu(unsigned cpu);
 void thread_set_nonpmd(void);
 
 #else
@@ -57,7 +57,7 @@ free_dpdk_buf(struct dp_packet *buf OVS_UNUSED)
 }
 
 static inline int
-pmd_thread_setaffinity_cpu(int cpu OVS_UNUSED)
+pmd_thread_setaffinity_cpu(unsigned cpu OVS_UNUSED)
 {
     return 0;
 }
index 5bed2b5..693541f 100644 (file)
@@ -70,7 +70,7 @@ struct cpu_core {
     struct hmap_node hmap_node;/* In the 'all_cpu_cores'. */
     struct ovs_list list_node; /* In 'numa_node->cores' list. */
     struct numa_node *numa;    /* numa node containing the core. */
-    int core_id;               /* Core id. */
+    unsigned core_id;          /* Core id. */
     bool available;            /* If the core can be pinned. */
     bool pinned;               /* If a thread has been pinned to the core. */
 };
@@ -118,7 +118,7 @@ discover_numa_and_core(void)
                 if (!strncmp(subdir->d_name, "cpu", 3)
                     && contain_all_digits(subdir->d_name + 3)){
                     struct cpu_core *c = xzalloc(sizeof *c);
-                    uint32_t core_id;
+                    unsigned core_id;
 
                     core_id = strtoul(subdir->d_name + 3, NULL, 10);
                     hmap_insert(&all_cpu_cores, &c->hmap_node,
@@ -153,7 +153,7 @@ discover_numa_and_core(void)
 
 /* Gets 'struct cpu_core' by 'core_id'. */
 static struct cpu_core*
-get_core_by_core_id(int core_id)
+get_core_by_core_id(unsigned core_id)
 {
     struct cpu_core *core = NULL;
 
@@ -201,13 +201,13 @@ ovs_numa_numa_id_is_valid(int numa_id)
 }
 
 bool
-ovs_numa_core_id_is_valid(int core_id)
+ovs_numa_core_id_is_valid(unsigned core_id)
 {
     return found_numa_and_core && core_id < ovs_numa_get_n_cores();
 }
 
 bool
-ovs_numa_core_is_pinned(int core_id)
+ovs_numa_core_is_pinned(unsigned core_id)
 {
     struct cpu_core *core = get_core_by_core_id(core_id);
 
@@ -237,7 +237,7 @@ ovs_numa_get_n_cores(void)
 /* Given 'core_id', returns the corresponding numa node id.  Returns
  * OVS_NUMA_UNSPEC if 'core_id' is invalid. */
 int
-ovs_numa_get_numa_id(int core_id)
+ovs_numa_get_numa_id(unsigned core_id)
 {
     struct cpu_core *core = get_core_by_core_id(core_id);
 
@@ -288,7 +288,7 @@ ovs_numa_get_n_unpinned_cores_on_numa(int numa_id)
  * False, if the core has already been pinned, or if it is invalid or
  * not available. */
 bool
-ovs_numa_try_pin_core_specific(int core_id)
+ovs_numa_try_pin_core_specific(unsigned core_id)
 {
     struct cpu_core *core = get_core_by_core_id(core_id);
 
@@ -305,7 +305,7 @@ ovs_numa_try_pin_core_specific(int core_id)
 /* Searches through all cores for an unpinned and available core.  Returns
  * the 'core_id' if found and sets the 'core->pinned' to true.  Otherwise,
  * returns OVS_CORE_UNSPEC. */
-int
+unsigned
 ovs_numa_get_unpinned_core_any(void)
 {
     struct cpu_core *core;
@@ -323,7 +323,7 @@ ovs_numa_get_unpinned_core_any(void)
 /* Searches through all cores on numa node with 'numa_id' for an
  * unpinned and available core.  Returns the core_id if found and
  * sets the 'core->pinned' to true.  Otherwise, returns OVS_CORE_UNSPEC. */
-int
+unsigned
 ovs_numa_get_unpinned_core_on_numa(int numa_id)
 {
     struct numa_node *numa = get_numa_by_numa_id(numa_id);
@@ -344,7 +344,7 @@ ovs_numa_get_unpinned_core_on_numa(int numa_id)
 
 /* Unpins the core with 'core_id'. */
 void
-ovs_numa_unpin_core(int core_id)
+ovs_numa_unpin_core(unsigned core_id)
 {
     struct cpu_core *core = get_core_by_core_id(core_id);
 
index 35b351b..1435d3d 100644 (file)
@@ -35,25 +35,25 @@ struct ovs_numa_dump {
 struct ovs_numa_info {
     struct ovs_list list_node;
     int numa_id;
-    int core_id;
+    unsigned core_id;
 };
 
 #ifdef __linux__
 
 void ovs_numa_init(void);
 bool ovs_numa_numa_id_is_valid(int numa_id);
-bool ovs_numa_core_id_is_valid(int core_id);
-bool ovs_numa_core_is_pinned(int core_id);
+bool ovs_numa_core_id_is_valid(unsigned core_id);
+bool ovs_numa_core_is_pinned(unsigned core_id);
 int ovs_numa_get_n_numas(void);
 void ovs_numa_set_cpu_mask(const char *cmask);
 int ovs_numa_get_n_cores(void);
-int ovs_numa_get_numa_id(int core_id);
+int ovs_numa_get_numa_id(unsigned core_id);
 int ovs_numa_get_n_cores_on_numa(int numa_id);
 int ovs_numa_get_n_unpinned_cores_on_numa(int numa_id);
-bool ovs_numa_try_pin_core_specific(int core_id);
-int ovs_numa_get_unpinned_core_any(void);
-int ovs_numa_get_unpinned_core_on_numa(int numa_id);
-void ovs_numa_unpin_core(int core_id);
+bool ovs_numa_try_pin_core_specific(unsigned core_id);
+unsigned ovs_numa_get_unpinned_core_any(void);
+unsigned ovs_numa_get_unpinned_core_on_numa(int numa_id);
+void ovs_numa_unpin_core(unsigned core_id);
 struct ovs_numa_dump *ovs_numa_dump_cores_on_numa(int numa_id);
 void ovs_numa_dump_destroy(struct ovs_numa_dump *);
 
@@ -75,13 +75,13 @@ ovs_numa_numa_id_is_valid(int numa_id OVS_UNUSED)
 }
 
 static inline bool
-ovs_numa_core_id_is_valid(int core_id OVS_UNUSED)
+ovs_numa_core_id_is_valid(unsigned core_id OVS_UNUSED)
 {
     return false;
 }
 
 static inline bool
-ovs_numa_core_is_pinned(int core_id OVS_UNUSED)
+ovs_numa_core_is_pinned(unsigned core_id OVS_UNUSED)
 {
     return false;
 }
@@ -105,7 +105,7 @@ ovs_numa_get_n_cores(void)
 }
 
 static inline int
-ovs_numa_get_numa_id(int core_id OVS_UNUSED)
+ovs_numa_get_numa_id(unsigned core_id OVS_UNUSED)
 {
     return OVS_NUMA_UNSPEC;
 }
@@ -123,25 +123,25 @@ ovs_numa_get_n_unpinned_cores_on_numa(int numa_id OVS_UNUSED)
 }
 
 static inline bool
-ovs_numa_try_pin_core_specific(int core_id OVS_UNUSED)
+ovs_numa_try_pin_core_specific(unsigned core_id OVS_UNUSED)
 {
     return false;
 }
 
-static inline int
+static inline unsigned
 ovs_numa_get_unpinned_core_any(void)
 {
     return OVS_CORE_UNSPEC;
 }
 
-static inline int
+static inline unsigned
 ovs_numa_get_unpinned_core_on_numa(int numa_id OVS_UNUSED)
 {
     return OVS_CORE_UNSPEC;
 }
 
 static inline void
-ovs_numa_unpin_core(int core_id OVS_UNUSED)
+ovs_numa_unpin_core(unsigned core_id OVS_UNUSED)
 {
     /* Nothing */
 }
index 01bc382..4dc1694 100644 (file)
@@ -160,7 +160,7 @@ struct upcall {
      * may be used with other datapaths. */
     const struct flow *flow;       /* Parsed representation of the packet. */
     const ovs_u128 *ufid;          /* Unique identifier for 'flow'. */
-    int pmd_id;                    /* Datapath poll mode driver id. */
+    unsigned pmd_id;               /* Datapath poll mode driver id. */
     const struct dp_packet *packet;   /* Packet associated with this upcall. */
     ofp_port_t in_port;            /* OpenFlow in port, or OFPP_NONE. */
 
@@ -214,7 +214,7 @@ struct udpif_key {
     ovs_u128 ufid;                 /* Unique flow identifier. */
     bool ufid_present;             /* True if 'ufid' is in datapath. */
     uint32_t hash;                 /* Pre-computed hash for 'key'. */
-    int pmd_id;                    /* Datapath poll mode driver id. */
+    unsigned pmd_id;               /* Datapath poll mode driver id. */
 
     struct ovs_mutex mutex;                   /* Guards the following. */
     struct dpif_flow_stats stats OVS_GUARDED; /* Last known stats.*/
@@ -296,7 +296,7 @@ static enum upcall_type classify_upcall(enum dpif_upcall_type type,
 static int upcall_receive(struct upcall *, const struct dpif_backer *,
                           const struct dp_packet *packet, enum dpif_upcall_type,
                           const struct nlattr *userdata, const struct flow *,
-                          const ovs_u128 *ufid, const int pmd_id);
+                          const ovs_u128 *ufid, const unsigned pmd_id);
 static void upcall_uninit(struct upcall *);
 
 static upcall_callback upcall_cb;
@@ -901,7 +901,7 @@ static int
 upcall_receive(struct upcall *upcall, const struct dpif_backer *backer,
                const struct dp_packet *packet, enum dpif_upcall_type type,
                const struct nlattr *userdata, const struct flow *flow,
-               const ovs_u128 *ufid, const int pmd_id)
+               const ovs_u128 *ufid, const unsigned pmd_id)
 {
     int error;
 
@@ -1040,7 +1040,7 @@ upcall_uninit(struct upcall *upcall)
 
 static int
 upcall_cb(const struct dp_packet *packet, const struct flow *flow, ovs_u128 *ufid,
-          int pmd_id, enum dpif_upcall_type type,
+          unsigned pmd_id, enum dpif_upcall_type type,
           const struct nlattr *userdata, struct ofpbuf *actions,
           struct flow_wildcards *wc, struct ofpbuf *put_actions, void *aux)
 {
@@ -1313,7 +1313,7 @@ static struct udpif_key *
 ukey_create__(const struct nlattr *key, size_t key_len,
               const struct nlattr *mask, size_t mask_len,
               bool ufid_present, const ovs_u128 *ufid,
-              const int pmd_id, const struct ofpbuf *actions,
+              const unsigned pmd_id, const struct ofpbuf *actions,
               uint64_t dump_seq, uint64_t reval_seq, long long int used,
               const struct recirc_id_node *key_recirc, struct xlate_out *xout)
     OVS_NO_THREAD_SAFETY_ANALYSIS