mirror of
https://github.com/openvswitch/ovs
synced 2025-10-21 14:49:41 +00:00
ovs-numa: Relax the ovs_numa_*() input argument check.
Many of the ovs_numa_*() functions abort the program when the input cpu socket or core id is invalid. This commit relaxes the input check and makes these functions return OVS_*_UNSPEC when the check fails. Signed-off-by: Alex Wang <alexw@nicira.com> Acked-by: Pravin B Shelar <pshelar@nicira.com>
This commit is contained in:
@@ -143,13 +143,13 @@ ovs_numa_init(void)
|
|||||||
bool
|
bool
|
||||||
ovs_numa_numa_id_is_valid(int numa_id)
|
ovs_numa_numa_id_is_valid(int numa_id)
|
||||||
{
|
{
|
||||||
return numa_id < ovs_numa_get_n_numas();
|
return found_numa_and_core && numa_id < ovs_numa_get_n_numas();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ovs_numa_core_id_is_valid(int core_id)
|
ovs_numa_core_id_is_valid(int core_id)
|
||||||
{
|
{
|
||||||
return core_id < ovs_numa_get_n_cores();
|
return found_numa_and_core && core_id < ovs_numa_get_n_cores();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns the number of numa nodes. */
|
/* Returns the number of numa nodes. */
|
||||||
@@ -168,14 +168,14 @@ ovs_numa_get_n_cores(void)
|
|||||||
: OVS_CORE_UNSPEC;
|
: OVS_CORE_UNSPEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns the number of cpu cores on numa node. */
|
/* Returns the number of cpu cores on numa node. Returns OVS_CORE_UNSPEC
|
||||||
|
* if 'numa_id' is invalid. */
|
||||||
int
|
int
|
||||||
ovs_numa_get_n_cores_on_numa(int numa_id)
|
ovs_numa_get_n_cores_on_numa(int numa_id)
|
||||||
{
|
{
|
||||||
if (found_numa_and_core) {
|
if (ovs_numa_numa_id_is_valid(numa_id)) {
|
||||||
struct numa_node *numa;
|
struct numa_node *numa;
|
||||||
|
|
||||||
ovs_assert(ovs_numa_numa_id_is_valid(numa_id));
|
|
||||||
numa = CONTAINER_OF(hmap_first_with_hash(&all_numa_nodes,
|
numa = CONTAINER_OF(hmap_first_with_hash(&all_numa_nodes,
|
||||||
hash_int(numa_id, 0)),
|
hash_int(numa_id, 0)),
|
||||||
struct numa_node, hmap_node);
|
struct numa_node, hmap_node);
|
||||||
@@ -186,16 +186,16 @@ ovs_numa_get_n_cores_on_numa(int numa_id)
|
|||||||
return OVS_CORE_UNSPEC;
|
return OVS_CORE_UNSPEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns the number of unpinned cpu cores on numa node. */
|
/* Returns the number of unpinned cpu cores on numa node. Returns
|
||||||
|
* OVS_CORE_UNSPEC if 'numa_id' is invalid. */
|
||||||
int
|
int
|
||||||
ovs_numa_get_n_unpinned_cores_on_numa(int numa_id)
|
ovs_numa_get_n_unpinned_cores_on_numa(int numa_id)
|
||||||
{
|
{
|
||||||
if (found_numa_and_core) {
|
if (ovs_numa_numa_id_is_valid(numa_id)) {
|
||||||
struct numa_node *numa;
|
struct numa_node *numa;
|
||||||
struct cpu_core *core;
|
struct cpu_core *core;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
ovs_assert(ovs_numa_numa_id_is_valid(numa_id));
|
|
||||||
numa = CONTAINER_OF(hmap_first_with_hash(&all_numa_nodes,
|
numa = CONTAINER_OF(hmap_first_with_hash(&all_numa_nodes,
|
||||||
hash_int(numa_id, 0)),
|
hash_int(numa_id, 0)),
|
||||||
struct numa_node, hmap_node);
|
struct numa_node, hmap_node);
|
||||||
@@ -212,27 +212,28 @@ ovs_numa_get_n_unpinned_cores_on_numa(int numa_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Given 'core_id', tries to pin that core. Returns true, if succeeds.
|
/* Given 'core_id', tries to pin that core. Returns true, if succeeds.
|
||||||
* False, if the core has already been pinned. */
|
* False, if the core has already been pinned or if 'core_id' is invalid. */
|
||||||
bool
|
bool
|
||||||
ovs_numa_try_pin_core_specific(int core_id)
|
ovs_numa_try_pin_core_specific(int core_id)
|
||||||
{
|
{
|
||||||
struct cpu_core *core;
|
if (ovs_numa_core_id_is_valid(core_id)) {
|
||||||
|
struct cpu_core *core;
|
||||||
|
|
||||||
ovs_assert(ovs_numa_core_id_is_valid(core_id));
|
core = CONTAINER_OF(hmap_first_with_hash(&all_cpu_cores,
|
||||||
|
hash_int(core_id, 0)),
|
||||||
core = CONTAINER_OF(hmap_first_with_hash(&all_cpu_cores,
|
struct cpu_core, hmap_node);
|
||||||
hash_int(core_id, 0)),
|
if (!core->pinned) {
|
||||||
struct cpu_core, hmap_node);
|
core->pinned = true;
|
||||||
if (!core->pinned) {
|
return true;
|
||||||
core->pinned = true;
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Searches through all cores for an unpinned core. Returns the core_id
|
/* Searches through all cores for an unpinned core. Returns the core_id
|
||||||
* if found and set the 'core->pinned' to true. Otherwise, returns -1. */
|
* if found and set the 'core->pinned' to true. Otherwise, returns
|
||||||
|
* OVS_CORE_UNSPEC. */
|
||||||
int
|
int
|
||||||
ovs_numa_get_unpinned_core_any(void)
|
ovs_numa_get_unpinned_core_any(void)
|
||||||
{
|
{
|
||||||
@@ -250,22 +251,22 @@ ovs_numa_get_unpinned_core_any(void)
|
|||||||
|
|
||||||
/* Searches through all cores on numa node with 'numa_id' for an unpinned
|
/* Searches through all cores on numa node with 'numa_id' for an unpinned
|
||||||
* core. Returns the core_id if found and sets the 'core->pinned' to true.
|
* core. Returns the core_id if found and sets the 'core->pinned' to true.
|
||||||
* Otherwise, returns -1. */
|
* Otherwise, returns OVS_CORE_UNSPEC. */
|
||||||
int
|
int
|
||||||
ovs_numa_get_unpinned_core_on_numa(int numa_id)
|
ovs_numa_get_unpinned_core_on_numa(int numa_id)
|
||||||
{
|
{
|
||||||
struct numa_node *numa;
|
if (ovs_numa_numa_id_is_valid(numa_id)) {
|
||||||
struct cpu_core *core;
|
struct numa_node *numa;
|
||||||
|
struct cpu_core *core;
|
||||||
|
|
||||||
ovs_assert(ovs_numa_numa_id_is_valid(numa_id));
|
numa = CONTAINER_OF(hmap_first_with_hash(&all_numa_nodes,
|
||||||
|
hash_int(numa_id, 0)),
|
||||||
numa = CONTAINER_OF(hmap_first_with_hash(&all_numa_nodes,
|
struct numa_node, hmap_node);
|
||||||
hash_int(numa_id, 0)),
|
LIST_FOR_EACH(core, list_node, &numa->cores) {
|
||||||
struct numa_node, hmap_node);
|
if (!core->pinned) {
|
||||||
LIST_FOR_EACH(core, list_node, &numa->cores) {
|
core->pinned = true;
|
||||||
if (!core->pinned) {
|
return core->core_id;
|
||||||
core->pinned = true;
|
}
|
||||||
return core->core_id;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,14 +277,14 @@ ovs_numa_get_unpinned_core_on_numa(int numa_id)
|
|||||||
void
|
void
|
||||||
ovs_numa_unpin_core(int core_id)
|
ovs_numa_unpin_core(int core_id)
|
||||||
{
|
{
|
||||||
struct cpu_core *core;
|
if (ovs_numa_core_id_is_valid(core_id)) {
|
||||||
|
struct cpu_core *core;
|
||||||
|
|
||||||
ovs_assert(ovs_numa_core_id_is_valid(core_id));
|
core = CONTAINER_OF(hmap_first_with_hash(&all_cpu_cores,
|
||||||
|
hash_int(core_id, 0)),
|
||||||
core = CONTAINER_OF(hmap_first_with_hash(&all_cpu_cores,
|
struct cpu_core, hmap_node);
|
||||||
hash_int(core_id, 0)),
|
core->pinned = false;
|
||||||
struct cpu_core, hmap_node);
|
}
|
||||||
core->pinned = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* __linux__ */
|
#endif /* __linux__ */
|
||||||
|
Reference in New Issue
Block a user