[5/7] Adding new function cnt_sub

Submitted by abhishek dubey on Aug. 20, 2019, 11:07 p.m.

Details

Message ID 1566342422-18459-6-git-send-email-dubeyabhishek777@gmail.com
State New
Series "GSoC 19: Optimizing the Pre-dump Algorithm"
Headers show

Commit Message

abhishek dubey Aug. 20, 2019, 11:07 p.m.
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@gmail.com>
---
 criu/include/stats.h |  1 +
 criu/stats.c         | 12 ++++++++++++
 2 files changed, 13 insertions(+)

Patch hide | download patch | download mbox

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)
 {