linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Anton Vorontsov <anton.vorontsov@linaro.org>
To: Mel Gorman <mgorman@suse.de>
Cc: Pekka Enberg <penberg@kernel.org>,
	Leonid Moiseichuk <leonid.moiseichuk@nokia.com>,
	KOSAKI Motohiro <kosaki.motohiro@gmail.com>,
	Minchan Kim <minchan@kernel.org>,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
	John Stultz <john.stultz@linaro.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linaro-kernel@lists.linaro.org, patches@linaro.org,
	kernel-team@android.com, linux-man@vger.kernel.org
Subject: [RFC 2/3] tools/testing: Add vmpressure-test utility
Date: Wed, 7 Nov 2012 03:01:39 -0800	[thread overview]
Message-ID: <20121107110139.GB30462@lizard> (raw)
In-Reply-To: <20121107105348.GA25549@lizard>

Just a simple test/example utility for the vmpressure_fd(2) system call.

Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
---
 tools/testing/vmpressure/.gitignore        |  1 +
 tools/testing/vmpressure/Makefile          | 30 ++++++++++
 tools/testing/vmpressure/vmpressure-test.c | 93 ++++++++++++++++++++++++++++++
 3 files changed, 124 insertions(+)
 create mode 100644 tools/testing/vmpressure/.gitignore
 create mode 100644 tools/testing/vmpressure/Makefile
 create mode 100644 tools/testing/vmpressure/vmpressure-test.c

diff --git a/tools/testing/vmpressure/.gitignore b/tools/testing/vmpressure/.gitignore
new file mode 100644
index 0000000..fe5e38c
--- /dev/null
+++ b/tools/testing/vmpressure/.gitignore
@@ -0,0 +1 @@
+vmpressure-test
diff --git a/tools/testing/vmpressure/Makefile b/tools/testing/vmpressure/Makefile
new file mode 100644
index 0000000..7545f3e
--- /dev/null
+++ b/tools/testing/vmpressure/Makefile
@@ -0,0 +1,30 @@
+WARNINGS := -Wcast-align
+WARNINGS += -Wformat
+WARNINGS += -Wformat-security
+WARNINGS += -Wformat-y2k
+WARNINGS += -Wshadow
+WARNINGS += -Winit-self
+WARNINGS += -Wpacked
+WARNINGS += -Wredundant-decls
+WARNINGS += -Wstrict-aliasing=3
+WARNINGS += -Wswitch-default
+WARNINGS += -Wno-system-headers
+WARNINGS += -Wundef
+WARNINGS += -Wwrite-strings
+WARNINGS += -Wbad-function-cast
+WARNINGS += -Wmissing-declarations
+WARNINGS += -Wmissing-prototypes
+WARNINGS += -Wnested-externs
+WARNINGS += -Wold-style-definition
+WARNINGS += -Wstrict-prototypes
+WARNINGS += -Wdeclaration-after-statement
+
+CFLAGS  = -O3 -g -std=gnu99 $(WARNINGS)
+
+PROGRAMS = vmpressure-test
+
+all: $(PROGRAMS)
+
+clean:
+	rm -f $(PROGRAMS) *.o
+.PHONY: clean
diff --git a/tools/testing/vmpressure/vmpressure-test.c b/tools/testing/vmpressure/vmpressure-test.c
new file mode 100644
index 0000000..1e448be
--- /dev/null
+++ b/tools/testing/vmpressure/vmpressure-test.c
@@ -0,0 +1,93 @@
+/*
+ * vmpressure_fd(2) test utility
+ *
+ * Copyright 2011-2012 Pekka Enberg <penberg@kernel.org>
+ * Copyright 2011-2012 Linaro Ltd.
+ *		       Anton Vorontsov <anton.vorontsov@linaro.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+
+/* TODO: glibc wrappers */
+#include "../../../include/linux/vmpressure.h"
+
+#if defined(__x86_64__)
+#include "../../../arch/x86/include/generated/asm/unistd_64.h"
+#endif
+#if defined(__arm__)
+#include "../../../arch/arm/include/asm/unistd.h"
+#endif
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdio.h>
+#include <poll.h>
+
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+
+static void pexit(const char *str)
+{
+	perror(str);
+	exit(1);
+}
+
+static int vmpressure_fd(struct vmpressure_config *config)
+{
+	config->size = sizeof(*config);
+
+	return syscall(__NR_vmpressure_fd, config);
+}
+
+int main(int argc, char *argv[])
+{
+	struct vmpressure_config config[] = {
+		/*
+		 * We could just set the lowest priority, but we want to
+		 * actually test if the thresholds work.
+		 */
+		{ .threshold = VMPRESSURE_LOW },
+		{ .threshold = VMPRESSURE_MEDIUM },
+		{ .threshold = VMPRESSURE_OOM },
+	};
+	const size_t num = ARRAY_SIZE(config);
+	struct pollfd pfds[num];
+	int i;
+
+	for (i = 0; i < num; i++) {
+		pfds[i].fd = vmpressure_fd(&config[i]);
+		if (pfds[i].fd < 0)
+			pexit("vmpressure_fd failed");
+
+		pfds[i].events = POLLIN;
+	}
+
+	while (poll(pfds, num, -1) > 0) {
+		for (i = 0; i < num; i++) {
+			struct vmpressure_event event;
+
+			if (!pfds[i].revents)
+				continue;
+
+			if (read(pfds[i].fd, &event, sizeof(event)) < 0)
+				pexit("read failed");
+
+			printf("VM pressure: 0x%.8x (threshold 0x%.8x)\n",
+			       event.pressure, config[i].threshold);
+		}
+	}
+
+	perror("poll failed\n");
+
+	for (i = 0; i < num; i++) {
+		if (close(pfds[i].fd) < 0)
+			pexit("close failed");
+	}
+
+	exit(1);
+	return 0;
+}
-- 
1.8.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2012-11-07 11:04 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-07 10:53 [RFC v3 0/3] vmpressure_fd: Linux VM pressure notifications Anton Vorontsov
2012-11-07 11:01 ` [RFC 1/3] mm: Add " Anton Vorontsov
2012-11-08 17:01   ` Mel Gorman
2012-11-08 17:14     ` Kirill A. Shutemov
2012-11-13 18:38   ` Jonathan Corbet
2012-11-07 11:01 ` Anton Vorontsov [this message]
2012-11-07 11:01 ` [RFC 3/3] man-pages: Add man page for vmpressure_fd(2) Anton Vorontsov
2012-11-07 14:19   ` Rik van Riel
2012-11-20  5:52   ` Andrew Morton
2012-11-20  6:24     ` Anton Vorontsov
2012-11-20 18:12       ` David Rientjes
2012-11-21 15:01         ` Mel Gorman
2012-11-21 19:39           ` Andrew Morton
2012-11-22  8:52             ` Pekka Enberg
2012-11-07 11:21 ` [RFC v3 0/3] vmpressure_fd: Linux VM pressure notifications Kirill A. Shutemov
2012-11-07 11:28   ` Pekka Enberg
2012-11-07 11:43     ` Kirill A. Shutemov
2012-11-15  3:21       ` David Rientjes
2012-11-15  3:39         ` Anton Vorontsov
2012-11-15  3:59           ` David Rientjes
2012-11-15  7:34             ` Anton Vorontsov
2012-11-15  8:11               ` David Rientjes
2012-11-15  8:52                 ` Anton Vorontsov
2012-11-15 21:25                   ` David Rientjes
2012-11-16  9:33                     ` Glauber Costa
2012-11-16 20:04                       ` David Rientjes
2012-11-16 21:12                         ` Glauber Costa
2012-11-16 21:57                           ` David Rientjes
2012-11-17  1:21                             ` Anton Vorontsov
2012-11-18 22:53                               ` David Rientjes
2012-11-19 14:00                               ` Glauber Costa
2012-11-19 13:57                             ` Glauber Costa
2012-11-20 18:02                               ` David Rientjes
2012-11-21  9:30                                 ` Kirill A. Shutemov
2012-11-21 11:32                                   ` leonid.moiseichuk
2012-11-21 11:54                                     ` Glauber Costa
2012-11-21 13:48                                       ` leonid.moiseichuk
2012-11-26 21:35                                 ` Michal Hocko
2012-11-19 14:19                             ` Glauber Costa
2012-11-20 18:23                               ` David Rientjes
2012-11-21  8:27                                 ` Glauber Costa
2012-11-21  8:46                                   ` Anton Vorontsov
2012-11-21  9:25                                     ` Glauber Costa
2012-11-07 11:43   ` Anton Vorontsov
2012-11-07 12:11     ` Kirill A. Shutemov
2012-11-07 12:28       ` Anton Vorontsov
2012-11-07 17:20   ` Greg Thelen
2012-11-07 20:52     ` Pekka Enberg
2012-11-07 11:30 ` Pekka Enberg
2012-11-07 11:31   ` Pekka Enberg
2012-11-07 12:06   ` Anton Vorontsov
2012-11-09  8:32 ` Luiz Capitulino
2012-11-09  9:04   ` Anton Vorontsov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121107110139.GB30462@lizard \
    --to=anton.vorontsov@linaro.org \
    --cc=b.zolnierkie@samsung.com \
    --cc=john.stultz@linaro.org \
    --cc=kernel-team@android.com \
    --cc=kosaki.motohiro@gmail.com \
    --cc=leonid.moiseichuk@nokia.com \
    --cc=linaro-kernel@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-man@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=minchan@kernel.org \
    --cc=patches@linaro.org \
    --cc=penberg@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).