service: use id in service stats functions
[dpdk.git] / lib / librte_eal / common / rte_service.c
index f7aa3e9..bf2fd4b 100644 (file)
@@ -166,18 +166,15 @@ service_mt_safe(struct rte_service_spec_impl *s)
        return s->spec.capabilities & RTE_SERVICE_CAP_MT_SAFE;
 }
 
-int32_t rte_service_set_stats_enable(struct rte_service_spec *service,
-                                 int32_t enabled)
+int32_t rte_service_set_stats_enable(uint32_t id, int32_t enabled)
 {
-       struct rte_service_spec_impl *impl =
-               (struct rte_service_spec_impl *)service;
-       if (!impl)
-               return -EINVAL;
+       struct rte_service_spec_impl *s;
+       SERVICE_VALID_GET_OR_ERR_RET(id, s, 0);
 
        if (enabled)
-               impl->internal_flags |= SERVICE_F_STATS_ENABLED;
+               s->internal_flags |= SERVICE_F_STATS_ENABLED;
        else
-               impl->internal_flags &= ~(SERVICE_F_STATS_ENABLED);
+               s->internal_flags &= ~(SERVICE_F_STATS_ENABLED);
 
        return 0;
 }
@@ -230,19 +227,8 @@ rte_service_probe_capability(uint32_t id, uint32_t capability)
 }
 
 int32_t
-rte_service_is_running(const struct rte_service_spec *spec)
-{
-       const struct rte_service_spec_impl *impl =
-               (const struct rte_service_spec_impl *)spec;
-       if (!impl)
-               return -EINVAL;
-
-       return (impl->runstate == RUNSTATE_RUNNING) &&
-               (impl->num_mapped_cores > 0);
-}
-
-int32_t
-rte_service_register(const struct rte_service_spec *spec)
+rte_service_component_register(const struct rte_service_spec *spec,
+                              uint32_t *id_ptr)
 {
        uint32_t i;
        int32_t free_slot = -1;
@@ -267,6 +253,9 @@ rte_service_register(const struct rte_service_spec *spec)
        rte_smp_wmb();
        rte_service_count++;
 
+       if (id_ptr)
+               *id_ptr = free_slot;
+
        return 0;
 }
 
@@ -305,23 +294,27 @@ rte_service_unregister(struct rte_service_spec *spec)
 }
 
 int32_t
-rte_service_start(struct rte_service_spec *service)
+rte_service_runstate_set(uint32_t id, uint32_t runstate)
 {
-       struct rte_service_spec_impl *s =
-               (struct rte_service_spec_impl *)service;
-       s->runstate = RUNSTATE_RUNNING;
+       struct rte_service_spec_impl *s;
+       SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL);
+
+       if (runstate)
+               s->runstate = RUNSTATE_RUNNING;
+       else
+               s->runstate = RUNSTATE_STOPPED;
+
        rte_smp_wmb();
        return 0;
 }
 
 int32_t
-rte_service_stop(struct rte_service_spec *service)
+rte_service_runstate_get(uint32_t id)
 {
-       struct rte_service_spec_impl *s =
-               (struct rte_service_spec_impl *)service;
-       s->runstate = RUNSTATE_STOPPED;
-       rte_smp_wmb();
-       return 0;
+       struct rte_service_spec_impl *s;
+       SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL);
+
+       return (s->runstate == RUNSTATE_RUNNING) && (s->num_mapped_cores > 0);
 }
 
 static int32_t
@@ -449,7 +442,7 @@ rte_service_start_with_defaults(void)
                 * should multiplex to a single core, or 1:1 if there are the
                 * same amount of services as service-cores
                 */
-               ret = rte_service_enable_on_lcore(s, ids[lcore_iter]);
+               ret = rte_service_map_lcore_set(i, ids[lcore_iter], 1);
                if (ret)
                        return -ENODEV;
 
@@ -457,7 +450,7 @@ rte_service_start_with_defaults(void)
                if (lcore_iter >= lcore_count)
                        lcore_iter = 0;
 
-               ret = rte_service_start(s);
+               ret = rte_service_runstate_set(i, 1);
                if (ret)
                        return -ENOEXEC;
        }
@@ -505,28 +498,25 @@ service_update(struct rte_service_spec *service, uint32_t lcore,
        return 0;
 }
 
-int32_t rte_service_get_enabled_on_lcore(struct rte_service_spec *service,
-                                       uint32_t lcore)
-{
-       uint32_t enabled;
-       int ret = service_update(service, lcore, 0, &enabled);
-       if (ret == 0)
-               return enabled;
-       return -EINVAL;
-}
-
 int32_t
-rte_service_enable_on_lcore(struct rte_service_spec *service, uint32_t lcore)
+rte_service_map_lcore_set(uint32_t id, uint32_t lcore, uint32_t enabled)
 {
-       uint32_t on = 1;
-       return service_update(service, lcore, &on, 0);
+       struct rte_service_spec_impl *s;
+       SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL);
+       uint32_t on = enabled > 0;
+       return service_update(&s->spec, lcore, &on, 0);
 }
 
 int32_t
-rte_service_disable_on_lcore(struct rte_service_spec *service, uint32_t lcore)
+rte_service_map_lcore_get(uint32_t id, uint32_t lcore)
 {
-       uint32_t off = 0;
-       return service_update(service, lcore, &off, 0);
+       struct rte_service_spec_impl *s;
+       SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL);
+       uint32_t enabled;
+       int ret = service_update(&s->spec, lcore, 0, &enabled);
+       if (ret == 0)
+               return enabled;
+       return ret;
 }
 
 int32_t rte_service_lcore_reset_all(void)
@@ -690,9 +680,10 @@ service_dump_calls_per_lcore(FILE *f, uint32_t lcore, uint32_t reset)
        fprintf(f, "\n");
 }
 
-int32_t rte_service_dump(FILE *f, struct rte_service_spec *service)
+int32_t rte_service_dump(FILE *f, uint32_t id)
 {
        uint32_t i;
+       int print_one = (id != UINT32_MAX);
 
        uint64_t total_cycles = 0;
        for (i = 0; i < rte_service_count; i++) {
@@ -701,15 +692,17 @@ int32_t rte_service_dump(FILE *f, struct rte_service_spec *service)
                total_cycles += rte_services[i].cycles_spent;
        }
 
-       if (service) {
-               struct rte_service_spec_impl *s =
-                       (struct rte_service_spec_impl *)service;
+       /* print only the specified service */
+       if (print_one) {
+               struct rte_service_spec_impl *s;
+               SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL);
                fprintf(f, "Service %s Summary\n", s->spec.name);
                uint32_t reset = 0;
                rte_service_dump_one(f, s, total_cycles, reset);
                return 0;
        }
 
+       /* print all services, as UINT32_MAX was passed as id */
        fprintf(f, "Services Summary\n");
        for (i = 0; i < rte_service_count; i++) {
                uint32_t reset = 1;