DPDK  17.02.1
rte_jobstats.h
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright(c) 2015 Intel Corporation. All rights reserved.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  * * Neither the name of Intel Corporation nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef JOBSTATS_H_
35 #define JOBSTATS_H_
36 
37 #include <stdint.h>
38 
39 #include <rte_memory.h>
40 #include <rte_memcpy.h>
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 #define RTE_JOBSTATS_NAMESIZE 32
47 
48 /* Forward declarations. */
49 struct rte_jobstats_context;
50 struct rte_jobstats;
51 
62 typedef void (*rte_job_update_period_cb_t)(struct rte_jobstats *job,
63  int64_t job_result);
64 
65 struct rte_jobstats {
66  uint64_t period;
69  uint64_t min_period;
72  uint64_t max_period;
75  int64_t target;
78  rte_job_update_period_cb_t update_period_cb;
81  uint64_t exec_time;
84  uint64_t min_exec_time;
87  uint64_t max_exec_time;
90  uint64_t exec_cnt;
93  char name[RTE_JOBSTATS_NAMESIZE];
96  struct rte_jobstats_context *context;
99 
100 struct rte_jobstats_context {
106  uint64_t state_time;
107 
108  uint64_t loop_executed_jobs;
111  /* Statistics start. */
112 
113  uint64_t exec_time;
116  uint64_t min_exec_time;
119  uint64_t max_exec_time;
128  uint64_t management_time;
129 
130  uint64_t min_management_time;
133  uint64_t max_management_time;
136  uint64_t start_time;
139  uint64_t job_exec_cnt;
142  uint64_t loop_cnt;
145 
156 int
157 rte_jobstats_context_init(struct rte_jobstats_context *ctx);
158 
165 void
166 rte_jobstats_context_start(struct rte_jobstats_context *ctx);
167 
175 void
176 rte_jobstats_context_finish(struct rte_jobstats_context *ctx);
177 
184 void
185 rte_jobstats_context_reset(struct rte_jobstats_context *ctx);
186 
207 int
208 rte_jobstats_init(struct rte_jobstats *job, const char *name,
209  uint64_t min_period, uint64_t max_period, uint64_t initial_period,
210  int64_t target);
211 
221 void
222 rte_jobstats_set_target(struct rte_jobstats *job, int64_t target);
223 
236 int
237 rte_jobstats_start(struct rte_jobstats_context *ctx, struct rte_jobstats *job);
238 
250 int
251 rte_jobstats_abort(struct rte_jobstats *job);
252 
269 int
270 rte_jobstats_finish(struct rte_jobstats *job, int64_t job_value);
271 
282 void
283 rte_jobstats_set_period(struct rte_jobstats *job, uint64_t period,
284  uint8_t saturate);
294 void
295 rte_jobstats_set_min(struct rte_jobstats *job, uint64_t period);
305 void
306 rte_jobstats_set_max(struct rte_jobstats *job, uint64_t period);
307 
319 void
320 rte_jobstats_set_update_period_function(struct rte_jobstats *job,
321  rte_job_update_period_cb_t update_period_cb);
322 
329 void
330 rte_jobstats_reset(struct rte_jobstats *job);
331 
332 #ifdef __cplusplus
333 }
334 #endif
335 
336 #endif /* JOBSTATS_H_ */