public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] mm/lib: ksm code style fixes.
@ 2012-07-09  9:51 Caspar Zhang
  2012-07-09  9:51 ` [LTP] [PATCH 2/2] mm/lib: increase sleep time in ksm scanning Caspar Zhang
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Caspar Zhang @ 2012-07-09  9:51 UTC (permalink / raw)
  To: Zhouping Liu; +Cc: LTP list

[-- Attachment #1: Type: text/plain, Size: 446 bytes --]


This patch gives some minor fixes to the following two commits:

f9ae09a lib/mem.c: using read_file to replace the redundant code
60c41a5 lib/mem.c: add _wait_ksmd_done func to wait ksmd finish his job

to make the codes cleaner and easier to understand.

Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
---
 testcases/kernel/mem/lib/mem.c |   69 +++++++++++++++------------------------
 1 files changed, 27 insertions(+), 42 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-mm-lib-ksm-code-style-fixes.patch --]
[-- Type: text/x-patch; name="0001-mm-lib-ksm-code-style-fixes.patch", Size: 3474 bytes --]

diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index f746d06..6283f25 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -133,72 +133,57 @@ static void _check(char *path, long int value)
 {
 	FILE *fp;
 	char buf[BUFSIZ], fullpath[BUFSIZ];
-	long tmp;
+	long actual_val;
 
 
 	snprintf(fullpath, BUFSIZ, "%s%s", PATH_KSM, path);
 	read_file(fullpath, buf);
-	tmp = SAFE_STRTOL(cleanup, buf, LONG_MIN, LONG_MAX);
+	actual_val = SAFE_STRTOL(cleanup, buf, 0, LONG_MAX);
 
-	tst_resm(TINFO, "%s is %ld.", path, tmp);
-	if (tmp != value)
+	tst_resm(TINFO, "%s is %ld.", path, actual_val);
+	if (actual_val != value)
 		tst_resm(TFAIL, "%s is not %ld.", path, value);
 }
 
 static void _wait_ksmd_done(void)
 {
 	char buf[BUFSIZ];
-	long run, pages_shared, pages_sharing, pages_volatile, pages_unshared;
-	long old_run = 0, old_pages_shared = 0, old_pages_sharing = 0,
-	     old_pages_volatile = 0, old_pages_unshared = 0;
-	long tmp;
-	int changed = 1, count = 0;
+	long pages_shared, pages_sharing, pages_volatile, pages_unshared;
+	long old_pages_shared = 0, old_pages_sharing = 0;
+	long old_pages_volatile = 0, old_pages_unshared = 0;
+	int changing = 1, count = 0;
 
-	while(changed) {
-		while(sleep(5))
-			continue;
-
-		changed = 0;
+	while (changing) {
+		sleep(5);
 		count++;
 
-		read_file(PATH_KSM "run", buf);
-		run = SAFE_STRTOL(cleanup, buf, LONG_MIN, LONG_MAX);
-		if (run != old_run) {
-			old_run = run;
-			changed = 1;
-		}
-
 		read_file(PATH_KSM "pages_shared", buf);
-		pages_shared = SAFE_STRTOL(cleanup, buf, LONG_MIN, LONG_MAX);
-		if (pages_shared != old_pages_shared) {
-			old_pages_shared = pages_shared;
-			changed = 1;
-		}
+		pages_shared = SAFE_STRTOL(cleanup, buf, 0, LONG_MAX);
 
 		read_file(PATH_KSM "pages_sharing", buf);
-		pages_sharing = SAFE_STRTOL(cleanup, buf, LONG_MIN, LONG_MAX);
-		if (pages_sharing != old_pages_sharing) {
-			old_pages_sharing = pages_sharing;
-			changed = 1;
-		}
+		pages_sharing = SAFE_STRTOL(cleanup, buf, 0, LONG_MAX);
 
 		read_file(PATH_KSM "pages_volatile", buf);
-		pages_volatile = SAFE_STRTOL(cleanup, buf, LONG_MIN, LONG_MAX);
-		if (pages_volatile != old_pages_volatile) {
-			old_pages_volatile = pages_volatile;
-			changed = 1;
-		}
+		pages_volatile = SAFE_STRTOL(cleanup, buf, 0, LONG_MAX);
 
 		read_file(PATH_KSM "pages_unshared", buf);
-		pages_unshared = SAFE_STRTOL(cleanup, buf, LONG_MIN, LONG_MAX);
-		if (pages_unshared != old_pages_unshared) {
+		pages_unshared = SAFE_STRTOL(cleanup, buf, 0, LONG_MAX);
+
+		if (pages_shared != old_pages_shared ||
+		    pages_sharing != old_pages_sharing ||
+		    pages_volatile != old_pages_volatile ||
+		    pages_unshared != old_pages_unshared) {
+			old_pages_shared   = pages_shared;
+			old_pages_sharing  = pages_sharing;
+			old_pages_volatile = pages_volatile;
 			old_pages_unshared = pages_unshared;
-			changed = 1;
+		} else {
+			changing = 0;
 		}
 	}
 
-	tst_resm(TINFO, "ksm daemon takes %ds to scan all "
-		    "mergeable pages", count * 5);
+	tst_resm(TINFO, "ksm daemon takes %ds to scan all mergeable pages",
+		    count * 5);
 }
 
 static void _group_check(int run, int pages_shared, int pages_sharing,
@@ -736,7 +721,7 @@ long count_numa(long nodes[])
 
 	nnodes = 0;
 	for (i = 0; i <= MAXNODES; i++)
-		if(path_exist(PATH_SYS_SYSTEM "/node/node%d", i))
+		if (path_exist(PATH_SYS_SYSTEM "/node/node%d", i))
 			nodes[nnodes++] = i;
 
 	return nnodes;

[-- Attachment #3: Type: text/plain, Size: 395 bytes --]

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2012-07-11  0:59 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-09  9:51 [LTP] [PATCH 1/2] mm/lib: ksm code style fixes Caspar Zhang
2012-07-09  9:51 ` [LTP] [PATCH 2/2] mm/lib: increase sleep time in ksm scanning Caspar Zhang
2012-07-09 10:11   ` Zhouping Liu
2012-07-09 11:32   ` Wanlong Gao
2012-07-09 12:37     ` Caspar Zhang
2012-07-09 13:10       ` Wanlong Gao
2012-07-09 14:15         ` Caspar Zhang
2012-07-09 15:51           ` Zhouping Liu
2012-07-10  0:25             ` Wanlong Gao
2012-07-09 10:08 ` [LTP] [PATCH 1/2] mm/lib: ksm code style fixes Zhouping Liu
2012-07-09 12:00   ` Wanlong Gao
2012-07-11  0:59 ` Wanlong Gao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox