1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015 Intel Corporation
10 #include <rte_memory.h>
11 #include <rte_memcpy.h>
17 #define RTE_JOBSTATS_NAMESIZE 32
19 /* Forward declarations. */
20 struct rte_jobstats_context;
24 * This function should calculate new period and set it using
25 * rte_jobstats_set_period() function. Time spent in this function will be
26 * added to job's runtime.
29 * The job data structure handler.
31 * Result of calling job callback.
33 typedef void (*rte_job_update_period_cb_t)(struct rte_jobstats *job,
38 /**< Estimated period of execution. */
41 /**< Minimum period. */
44 /**< Maximum period. */
47 /**< Desired value for this job. */
49 rte_job_update_period_cb_t update_period_cb;
50 /**< Period update callback. */
53 /**< Total time (sum) that this job was executing. */
55 uint64_t min_exec_time;
56 /**< Minimum execute time. */
58 uint64_t max_exec_time;
59 /**< Maximum execute time. */
62 /**< Execute count. */
64 char name[RTE_JOBSTATS_NAMESIZE];
65 /**< Name of this job */
67 struct rte_jobstats_context *context;
68 /**< Job stats context object that is executing this job. */
69 } __rte_cache_aligned;
71 struct rte_jobstats_context {
72 /** Variable holding time at different points:
73 * -# loop start time if loop was started but no job executed yet.
74 * -# job start time if job is currently executing.
75 * -# job finish time if job finished its execution.
76 * -# loop finish time if loop finished its execution. */
79 uint64_t loop_executed_jobs;
80 /**< Count of executed jobs in this loop. */
82 /* Statistics start. */
85 /**< Total time taken to execute jobs, not including management time. */
87 uint64_t min_exec_time;
88 /**< Minimum loop execute time. */
90 uint64_t max_exec_time;
91 /**< Maximum loop execute time. */
94 * Sum of time that is not the execute time (ex: from job finish to next
97 * This time might be considered as overhead of library + job scheduling.
99 uint64_t management_time;
101 uint64_t min_management_time;
102 /**< Minimum management time */
104 uint64_t max_management_time;
105 /**< Maximum management time */
108 /**< Time since last reset stats. */
110 uint64_t job_exec_cnt;
111 /**< Total count of executed jobs. */
114 /**< Total count of executed loops with at least one executed job. */
115 } __rte_cache_aligned;
118 * Initialize given context object with default values.
121 * Job stats context object to initialize.
125 * -EINVAL if *ctx* is NULL
128 rte_jobstats_context_init(struct rte_jobstats_context *ctx);
131 * Mark that new set of jobs start executing.
134 * Job stats context object.
137 rte_jobstats_context_start(struct rte_jobstats_context *ctx);
140 * Mark that there is no more jobs ready to execute in this turn. Calculate
141 * stats for this loop turn.
147 rte_jobstats_context_finish(struct rte_jobstats_context *ctx);
150 * Function resets job context statistics.
153 * Job stats context which statistics will be reset.
156 rte_jobstats_context_reset(struct rte_jobstats_context *ctx);
159 * Initialize given job stats object.
166 * Minimum period that this job can accept.
168 * Maximum period that this job can accept.
169 * @param initial_period
170 * Initial period. It will be checked against *min_period* and *max_period*.
172 * Target value that this job try to achieve.
176 * -EINVAL if *job* is NULL
179 rte_jobstats_init(struct rte_jobstats *job, const char *name,
180 uint64_t min_period, uint64_t max_period, uint64_t initial_period,
184 * Set job desired target value. Difference between target and job value
185 * value must be used to properly adjust job execute period value.
193 rte_jobstats_set_target(struct rte_jobstats *job, int64_t target);
196 * Mark that *job* is starting of its execution in context of *ctx* object.
204 * -EINVAL if *ctx* or *job* is NULL or *job* is executing in another context
208 rte_jobstats_start(struct rte_jobstats_context *ctx, struct rte_jobstats *job);
211 * Mark that *job* finished its execution, but time of this work will be skipped
212 * and added to management time.
219 * -EINVAL if job is NULL or job was not started (it have no context).
222 rte_jobstats_abort(struct rte_jobstats *job);
225 * Mark that *job* finished its execution. Context in which it was executing
226 * will receive stat update. After this function call *job* object is ready to
227 * be executed in other context.
232 * Job value. Job should pass in this parameter a value that it try to optimize
233 * for example the number of packets it processed.
236 * 0 if job's period was not updated (job target equals *job_value*)
237 * 1 if job's period was updated
238 * -EINVAL if job is NULL or job was not started (it have no context).
241 rte_jobstats_finish(struct rte_jobstats *job, int64_t job_value);
244 * Set execute period of given job.
251 * If zero, skip period saturation to min, max range.
254 rte_jobstats_set_period(struct rte_jobstats *job, uint64_t period,
257 * Set minimum execute period of given job. Current period will be checked
258 * against new minimum value.
263 * New minimum period value.
266 rte_jobstats_set_min(struct rte_jobstats *job, uint64_t period);
268 * Set maximum execute period of given job. Current period will be checked
269 * against new maximum value.
274 * New maximum period value.
277 rte_jobstats_set_max(struct rte_jobstats *job, uint64_t period);
280 * Set update period callback that is invoked after job finish.
282 * If application wants to do more sophisticated calculations than default
283 * it can provide this handler.
287 * @param update_period_cb
288 * Callback to set. If NULL restore default update function.
291 rte_jobstats_set_update_period_function(struct rte_jobstats *job,
292 rte_job_update_period_cb_t update_period_cb);
295 * Function resets job statistics.
298 * Job which statistics will be reset.
301 rte_jobstats_reset(struct rte_jobstats *job);
307 #endif /* JOBSTATS_H_ */