[ovs-dev] [PATCH 1/2] ovs-numa: Relax the ovs_numa_*() input argument check.
Alex Wang
alexw at nicira.com
Thu Sep 4 20:03:25 UTC 2014
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 at nicira.com>
---
lib/ovs-numa.c | 77 ++++++++++++++++++++++++++++----------------------------
1 file changed, 39 insertions(+), 38 deletions(-)
diff --git a/lib/ovs-numa.c b/lib/ovs-numa.c
index 44df40f..545b075 100644
--- a/lib/ovs-numa.c
+++ b/lib/ovs-numa.c
@@ -143,13 +143,13 @@ ovs_numa_init(void)
bool
ovs_numa_cpu_socket_id_is_valid(int sid)
{
- return sid < ovs_numa_get_n_sockets();
+ return found_sockets_and_cores && sid < ovs_numa_get_n_sockets();
}
bool
ovs_numa_cpu_core_id_is_valid(int cid)
{
- return cid < ovs_numa_get_n_cores();
+ return found_sockets_and_cores && cid < ovs_numa_get_n_cores();
}
/* Returns the number of cpu sockets. */
@@ -168,14 +168,14 @@ ovs_numa_get_n_cores(void)
: OVS_CORE_UNSPEC;
}
-/* Returns the number of cpu cores on socket. */
+/* Returns the number of cpu cores on socket. Returns OVS_CORE_UNSPEC
+ * if 'socket_id' is invalid. */
int
ovs_numa_get_n_cores_on_socket(int socket_id)
{
- if (found_sockets_and_cores) {
+ if (ovs_numa_cpu_socket_id_is_valid(socket_id)) {
struct cpu_socket *socket;
- ovs_assert(ovs_numa_cpu_socket_id_is_valid(socket_id));
socket = CONTAINER_OF(hmap_first_with_hash(&all_cpu_sockets,
hash_int(socket_id, 0)),
struct cpu_socket, hmap_node);
@@ -186,16 +186,16 @@ ovs_numa_get_n_cores_on_socket(int socket_id)
return OVS_CORE_UNSPEC;
}
-/* Returns the number of unpinned cpu cores on socket. */
+/* Returns the number of unpinned cpu cores on socket. Returns
+ * OVS_CORE_UNSPEC if 'socket_id' is invalid. */
int
ovs_numa_get_n_unpinned_cores_on_socket(int socket_id)
{
- if (found_sockets_and_cores) {
+ if (ovs_numa_cpu_socket_id_is_valid(socket_id)) {
struct cpu_socket *socket;
struct cpu_core *core;
int count = 0;
- ovs_assert(ovs_numa_cpu_socket_id_is_valid(socket_id));
socket = CONTAINER_OF(hmap_first_with_hash(&all_cpu_sockets,
hash_int(socket_id, 0)),
struct cpu_socket, hmap_node);
@@ -212,27 +212,28 @@ ovs_numa_get_n_unpinned_cores_on_socket(int socket_id)
}
/* 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
ovs_numa_try_pin_core_specific(int core_id)
{
- struct cpu_core *core;
-
- ovs_assert(ovs_numa_cpu_core_id_is_valid(core_id));
+ if (ovs_numa_cpu_core_id_is_valid(core_id)) {
+ struct cpu_core *core;
- core = CONTAINER_OF(hmap_first_with_hash(&all_cpu_cores,
- hash_int(core_id, 0)),
- struct cpu_core, hmap_node);
- if (!core->pinned) {
- core->pinned = true;
- return true;
+ core = CONTAINER_OF(hmap_first_with_hash(&all_cpu_cores,
+ hash_int(core_id, 0)),
+ struct cpu_core, hmap_node);
+ if (!core->pinned) {
+ core->pinned = true;
+ return true;
+ }
}
return false;
}
/* 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
ovs_numa_get_unpinned_core_any(void)
{
@@ -250,22 +251,22 @@ ovs_numa_get_unpinned_core_any(void)
/* Searches through all cores on socket with 'socket_id' for an unpinned core.
* Returns the core_id if found and sets the 'core->pinned' to true.
- * Otherwise, returns -1. */
+ * Otherwise, returns OVS_CORE_UNSPEC. */
int
ovs_numa_get_unpinned_core_on_socket(int socket_id)
{
- struct cpu_socket *socket;
- struct cpu_core *core;
-
- ovs_assert(ovs_numa_cpu_socket_id_is_valid(socket_id));
+ if(ovs_numa_cpu_socket_id_is_valid(socket_id)) {
+ struct cpu_socket *socket;
+ struct cpu_core *core;
- socket = CONTAINER_OF(hmap_first_with_hash(&all_cpu_sockets,
- hash_int(socket_id, 0)),
- struct cpu_socket, hmap_node);
- LIST_FOR_EACH(core, list_node, &socket->cores) {
- if (!core->pinned) {
- core->pinned = true;
- return core->core_id;
+ socket = CONTAINER_OF(hmap_first_with_hash(&all_cpu_sockets,
+ hash_int(socket_id, 0)),
+ struct cpu_socket, hmap_node);
+ LIST_FOR_EACH(core, list_node, &socket->cores) {
+ if (!core->pinned) {
+ core->pinned = true;
+ return core->core_id;
+ }
}
}
@@ -276,14 +277,14 @@ ovs_numa_get_unpinned_core_on_socket(int socket_id)
void
ovs_numa_unpin_core(int core_id)
{
- struct cpu_core *core;
-
- ovs_assert(ovs_numa_cpu_core_id_is_valid(core_id));
+ if (ovs_numa_cpu_core_id_is_valid(core_id)) {
+ struct cpu_core *core;
- core = CONTAINER_OF(hmap_first_with_hash(&all_cpu_cores,
- hash_int(core_id, 0)),
- struct cpu_core, hmap_node);
- core->pinned = false;
+ core = CONTAINER_OF(hmap_first_with_hash(&all_cpu_cores,
+ hash_int(core_id, 0)),
+ struct cpu_core, hmap_node);
+ core->pinned = false;
+ }
}
#endif /* __linux__ */
--
1.7.9.5
More information about the dev
mailing list