service: use id in get by name function
[dpdk.git] / lib / librte_eal / common / rte_service.c
index bf2fd4b..06fe6cc 100644 (file)
@@ -185,29 +185,21 @@ rte_service_get_count(void)
        return rte_service_count;
 }
 
-struct rte_service_spec *
-rte_service_get_by_id(uint32_t id)
+int32_t rte_service_get_by_name(const char *name, uint32_t *service_id)
 {
-       struct rte_service_spec *service = NULL;
-       if (id < rte_service_count)
-               service = (struct rte_service_spec *)&rte_services[id];
-
-       return service;
-}
+       if (!service_id)
+               return -EINVAL;
 
-struct rte_service_spec *rte_service_get_by_name(const char *name)
-{
-       struct rte_service_spec *service = NULL;
        int i;
        for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) {
                if (service_valid(i) &&
                                strcmp(name, rte_services[i].spec.name) == 0) {
-                       service = (struct rte_service_spec *)&rte_services[i];
-                       break;
+                       *service_id = i;
+                       return 0;
                }
        }
 
-       return service;
+       return -ENODEV;
 }
 
 const char *
@@ -260,35 +252,22 @@ rte_service_component_register(const struct rte_service_spec *spec,
 }
 
 int32_t
-rte_service_unregister(struct rte_service_spec *spec)
+rte_service_component_unregister(uint32_t id)
 {
-       struct rte_service_spec_impl *s = NULL;
-       struct rte_service_spec_impl *spec_impl =
-               (struct rte_service_spec_impl *)spec;
-
        uint32_t i;
-       uint32_t service_id;
-       for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) {
-               if (&rte_services[i] == spec_impl) {
-                       s = spec_impl;
-                       service_id = i;
-                       break;
-               }
-       }
-
-       if (!s)
-               return -EINVAL;
+       struct rte_service_spec_impl *s;
+       SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL);
 
        rte_service_count--;
        rte_smp_wmb();
 
        s->internal_flags &= ~(SERVICE_F_REGISTERED);
 
+       /* clear the run-bit in all cores */
        for (i = 0; i < RTE_MAX_LCORE; i++)
-               lcore_states[i].service_mask &= ~(UINT64_C(1) << service_id);
+               lcore_states[i].service_mask &= ~(UINT64_C(1) << id);
 
-       memset(&rte_services[service_id], 0,
-                       sizeof(struct rte_service_spec_impl));
+       memset(&rte_services[id], 0, sizeof(struct rte_service_spec_impl));
 
        return 0;
 }
@@ -433,10 +412,6 @@ rte_service_start_with_defaults(void)
                rte_service_lcore_start(ids[i]);
 
        for (i = 0; i < count; i++) {
-               struct rte_service_spec *s = rte_service_get_by_id(i);
-               if (!s)
-                       return -EINVAL;
-
                /* do 1:1 core mapping here, with each service getting
                 * assigned a single core by default. Adding multiple services
                 * should multiplex to a single core, or 1:1 if there are the