blob: b5a5df14d7020fc60960ed781bd8ee3173d2578a [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Jiri Olsaa82bfd02017-09-08 14:05:08 +02002#include <linux/kernel.h>
Namhyung Kim688f2f52012-11-13 22:30:32 +09003#include "../cache.h"
4#include "progress.h"
5
Arnaldo Carvalho de Melo4d3001f2013-10-23 15:40:38 -03006static void null_progress__update(struct ui_progress *p __maybe_unused)
Namhyung Kim688f2f52012-11-13 22:30:32 +09007{
8}
9
Arnaldo Carvalho de Melo4779a2e2013-10-23 14:08:48 -030010static struct ui_progress_ops null_progress__ops =
Namhyung Kim688f2f52012-11-13 22:30:32 +090011{
Arnaldo Carvalho de Melo4779a2e2013-10-23 14:08:48 -030012 .update = null_progress__update,
Namhyung Kim688f2f52012-11-13 22:30:32 +090013};
14
Arnaldo Carvalho de Melo4779a2e2013-10-23 14:08:48 -030015struct ui_progress_ops *ui_progress__ops = &null_progress__ops;
Namhyung Kim688f2f52012-11-13 22:30:32 +090016
Arnaldo Carvalho de Melo4d3001f2013-10-23 15:40:38 -030017void ui_progress__update(struct ui_progress *p, u64 adv)
Namhyung Kim688f2f52012-11-13 22:30:32 +090018{
Jiri Olsaa82bfd02017-09-08 14:05:08 +020019 u64 last = p->curr;
20
Arnaldo Carvalho de Melo4d3001f2013-10-23 15:40:38 -030021 p->curr += adv;
22
23 if (p->curr >= p->next) {
Jiri Olsaa82bfd02017-09-08 14:05:08 +020024 u64 nr = DIV_ROUND_UP(p->curr - last, p->step);
25
26 p->next += nr * p->step;
Arnaldo Carvalho de Melo4d3001f2013-10-23 15:40:38 -030027 ui_progress__ops->update(p);
28 }
29}
30
31void ui_progress__init(struct ui_progress *p, u64 total, const char *title)
32{
33 p->curr = 0;
Jiri Olsa4d286c82017-09-08 14:05:07 +020034 p->next = p->step = total / 16 ?: 1;
Arnaldo Carvalho de Melo4d3001f2013-10-23 15:40:38 -030035 p->total = total;
36 p->title = title;
37
Namhyung Kim688f2f52012-11-13 22:30:32 +090038}
Namhyung Kima5580f32012-11-13 22:30:34 +090039
40void ui_progress__finish(void)
41{
Arnaldo Carvalho de Melo4779a2e2013-10-23 14:08:48 -030042 if (ui_progress__ops->finish)
43 ui_progress__ops->finish();
Namhyung Kima5580f32012-11-13 22:30:34 +090044}