xref: /openbmc/qemu/include/qemu/progress_meter.h (revision df4bbc9d)
101fe1ca9SVladimir Sementsov-Ogievskiy /*
201fe1ca9SVladimir Sementsov-Ogievskiy  * Helper functionality for some process progress tracking.
301fe1ca9SVladimir Sementsov-Ogievskiy  *
401fe1ca9SVladimir Sementsov-Ogievskiy  * Copyright (c) 2011 IBM Corp.
501fe1ca9SVladimir Sementsov-Ogievskiy  * Copyright (c) 2012, 2018 Red Hat, Inc.
601fe1ca9SVladimir Sementsov-Ogievskiy  * Copyright (c) 2020 Virtuozzo International GmbH
701fe1ca9SVladimir Sementsov-Ogievskiy  *
801fe1ca9SVladimir Sementsov-Ogievskiy  * Permission is hereby granted, free of charge, to any person obtaining a copy
901fe1ca9SVladimir Sementsov-Ogievskiy  * of this software and associated documentation files (the "Software"), to deal
1001fe1ca9SVladimir Sementsov-Ogievskiy  * in the Software without restriction, including without limitation the rights
1101fe1ca9SVladimir Sementsov-Ogievskiy  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1201fe1ca9SVladimir Sementsov-Ogievskiy  * copies of the Software, and to permit persons to whom the Software is
1301fe1ca9SVladimir Sementsov-Ogievskiy  * furnished to do so, subject to the following conditions:
1401fe1ca9SVladimir Sementsov-Ogievskiy  *
1501fe1ca9SVladimir Sementsov-Ogievskiy  * The above copyright notice and this permission notice shall be included in
1601fe1ca9SVladimir Sementsov-Ogievskiy  * all copies or substantial portions of the Software.
1701fe1ca9SVladimir Sementsov-Ogievskiy  *
1801fe1ca9SVladimir Sementsov-Ogievskiy  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1901fe1ca9SVladimir Sementsov-Ogievskiy  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2001fe1ca9SVladimir Sementsov-Ogievskiy  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
2101fe1ca9SVladimir Sementsov-Ogievskiy  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2201fe1ca9SVladimir Sementsov-Ogievskiy  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2301fe1ca9SVladimir Sementsov-Ogievskiy  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2401fe1ca9SVladimir Sementsov-Ogievskiy  * THE SOFTWARE.
2501fe1ca9SVladimir Sementsov-Ogievskiy  */
2601fe1ca9SVladimir Sementsov-Ogievskiy 
2701fe1ca9SVladimir Sementsov-Ogievskiy #ifndef QEMU_PROGRESS_METER_H
2801fe1ca9SVladimir Sementsov-Ogievskiy #define QEMU_PROGRESS_METER_H
2901fe1ca9SVladimir Sementsov-Ogievskiy 
30*df4bbc9dSMarkus Armbruster #include "qemu/thread.h"
31a7b4f8fcSEmanuele Giuseppe Esposito 
3201fe1ca9SVladimir Sementsov-Ogievskiy typedef struct ProgressMeter {
3301fe1ca9SVladimir Sementsov-Ogievskiy     /**
3401fe1ca9SVladimir Sementsov-Ogievskiy      * Current progress. The unit is arbitrary as long as the ratio between
3501fe1ca9SVladimir Sementsov-Ogievskiy      * current and total represents the estimated percentage
3601fe1ca9SVladimir Sementsov-Ogievskiy      * of work already done.
3701fe1ca9SVladimir Sementsov-Ogievskiy      */
3801fe1ca9SVladimir Sementsov-Ogievskiy     uint64_t current;
3901fe1ca9SVladimir Sementsov-Ogievskiy 
4001fe1ca9SVladimir Sementsov-Ogievskiy     /** Estimated current value at the completion of the process */
4101fe1ca9SVladimir Sementsov-Ogievskiy     uint64_t total;
42a7b4f8fcSEmanuele Giuseppe Esposito 
43a7b4f8fcSEmanuele Giuseppe Esposito     QemuMutex lock; /* protects concurrent access to above fields */
4401fe1ca9SVladimir Sementsov-Ogievskiy } ProgressMeter;
4501fe1ca9SVladimir Sementsov-Ogievskiy 
46a7b4f8fcSEmanuele Giuseppe Esposito void progress_init(ProgressMeter *pm);
47a7b4f8fcSEmanuele Giuseppe Esposito void progress_destroy(ProgressMeter *pm);
4801fe1ca9SVladimir Sementsov-Ogievskiy 
49a7b4f8fcSEmanuele Giuseppe Esposito /* Get a snapshot of internal current and total values  */
50a7b4f8fcSEmanuele Giuseppe Esposito void progress_get_snapshot(ProgressMeter *pm, uint64_t *current,
51a7b4f8fcSEmanuele Giuseppe Esposito                            uint64_t *total);
5201fe1ca9SVladimir Sementsov-Ogievskiy 
53a7b4f8fcSEmanuele Giuseppe Esposito /* Increases the amount of work done so far by @done */
54a7b4f8fcSEmanuele Giuseppe Esposito void progress_work_done(ProgressMeter *pm, uint64_t done);
55a7b4f8fcSEmanuele Giuseppe Esposito 
56a7b4f8fcSEmanuele Giuseppe Esposito /* Sets how much work has to be done to complete to @remaining */
57a7b4f8fcSEmanuele Giuseppe Esposito void progress_set_remaining(ProgressMeter *pm, uint64_t remaining);
58a7b4f8fcSEmanuele Giuseppe Esposito 
59a7b4f8fcSEmanuele Giuseppe Esposito /* Increases the total work to do by @delta */
60a7b4f8fcSEmanuele Giuseppe Esposito void progress_increase_remaining(ProgressMeter *pm, uint64_t delta);
6101fe1ca9SVladimir Sementsov-Ogievskiy 
6201fe1ca9SVladimir Sementsov-Ogievskiy #endif /* QEMU_PROGRESS_METER_H */
63