Skip to content

Commit

Permalink
ovs-numa: Change 'core_id' to unsigned.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Ethan Jackson <[email protected]>
Acked-by: Ethan Jackson <[email protected]>
  • Loading branch information
ddiproietto authored and ejj committed May 22, 2015
1 parent b940b3d commit bd5131b
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 58 deletions.
27 changes: 15 additions & 12 deletions lib/dpif-netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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'.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/dpif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions lib/dpif.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);

/* Flow dumping interface
Expand Down Expand Up @@ -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 *,
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lib/netdev-dpdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/netdev-dpdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
20 changes: 10 additions & 10 deletions lib/ovs-numa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);

Expand Down
Loading

0 comments on commit bd5131b

Please sign in to comment.