[CRIU] [PATCH 5/7] Adding new function cnt_sub

Abhishek Dubey dubeyabhishek777 at gmail.com
Wed Aug 21 02:07:00 MSK 2019


adding cnt_sub function, a complement of
cnt_add. cnt_sub is utilized to decrement
stats counter on the fly for "read" mode
pre-dump, as the number of pages actually
dumped may be lesser than the page count
gathered at iovec generation.

Signed-off-by: Abhishek Dubey <dubeyabhishek777 at gmail.com>
---
 criu/include/stats.h |  1 +
 criu/stats.c         | 12 ++++++++++++
 2 files changed, 13 insertions(+)

diff --git a/criu/include/stats.h b/criu/include/stats.h
index bab9a05..5d408b7 100644
--- a/criu/include/stats.h
+++ b/criu/include/stats.h
@@ -45,6 +45,7 @@ enum {
 };
 
 extern void cnt_add(int c, unsigned long val);
+extern void cnt_sub(int c, unsigned long val);
 
 #define DUMP_STATS	1
 #define RESTORE_STATS	2
diff --git a/criu/stats.c b/criu/stats.c
index 7410b5c..cb52801 100644
--- a/criu/stats.c
+++ b/criu/stats.c
@@ -41,6 +41,18 @@ void cnt_add(int c, unsigned long val)
 		BUG();
 }
 
+void cnt_sub(int c, unsigned long val)
+{
+	if (dstats != NULL) {
+		BUG_ON(c >= DUMP_CNT_NR_STATS);
+		dstats->counts[c] -= val;
+	} else if (rstats != NULL) {
+		BUG_ON(c >= RESTORE_CNT_NR_STATS);
+		atomic_sub(val, &rstats->counts[c]);
+	} else
+		BUG();
+}
+
 static void timeval_accumulate(const struct timeval *from, const struct timeval *to,
 		struct timeval *res)
 {
-- 
2.7.4



More information about the CRIU mailing list