xref: /openbmc/linux/tools/perf/ui/progress.c (revision e3b9f1e8)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/kernel.h>
3 #include "../cache.h"
4 #include "progress.h"
5 
6 static void null_progress__update(struct ui_progress *p __maybe_unused)
7 {
8 }
9 
10 static struct ui_progress_ops null_progress__ops =
11 {
12 	.update = null_progress__update,
13 };
14 
15 struct ui_progress_ops *ui_progress__ops = &null_progress__ops;
16 
17 void ui_progress__update(struct ui_progress *p, u64 adv)
18 {
19 	u64 last = p->curr;
20 
21 	p->curr += adv;
22 
23 	if (p->curr >= p->next) {
24 		u64 nr = DIV_ROUND_UP(p->curr - last, p->step);
25 
26 		p->next += nr * p->step;
27 		ui_progress__ops->update(p);
28 	}
29 }
30 
31 void __ui_progress__init(struct ui_progress *p, u64 total,
32 			 const char *title, bool size)
33 {
34 	p->curr = 0;
35 	p->next = p->step = total / 16 ?: 1;
36 	p->total = total;
37 	p->title = title;
38 	p->size  = size;
39 
40 	if (ui_progress__ops->init)
41 		ui_progress__ops->init(p);
42 }
43 
44 void ui_progress__finish(void)
45 {
46 	if (ui_progress__ops->finish)
47 		ui_progress__ops->finish();
48 }
49