linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Alexandre Chartre <alexandre.chartre@oracle.com>
To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
	hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org,
	peterz@infradead.org, x86@kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Cc: pbonzini@redhat.com, konrad.wilk@oracle.com,
	jan.setjeeilers@oracle.com, liran.alon@oracle.com,
	junaids@google.com, graf@amazon.de, rppt@linux.vnet.ibm.com,
	kuzuno@gmail.com, mgross@linux.intel.com,
	alexandre.chartre@oracle.com
Subject: [RFC v4][PATCH part-3 08/14] asidrv: Sequence to test scheduling in/out with ASI
Date: Mon,  4 May 2020 17:02:29 +0200	[thread overview]
Message-ID: <20200504150235.12171-9-alexandre.chartre@oracle.com> (raw)
In-Reply-To: <20200504150235.12171-1-alexandre.chartre@oracle.com>

Add a sequence to test if an ASI remains active after it is
scheduled out and then scheduled back in.

Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com>
---
 drivers/staging/asi/asidrv.c | 98 ++++++++++++++++++++++++++++++++++++
 drivers/staging/asi/asidrv.h |  2 +
 2 files changed, 100 insertions(+)

diff --git a/drivers/staging/asi/asidrv.c b/drivers/staging/asi/asidrv.c
index e08f2a107e89..9ca17e0b654e 100644
--- a/drivers/staging/asi/asidrv.c
+++ b/drivers/staging/asi/asidrv.c
@@ -4,6 +4,7 @@
  */
 
 #include <linux/fs.h>
+#include <linux/kthread.h>
 #include <linux/miscdevice.h>
 #include <linux/module.h>
 #include <linux/nmi.h>
@@ -21,17 +22,24 @@
 /* Number of read for mem/memmap test sequence */
 #define ASIDRV_MEM_READ_COUNT		1000
 
+/* Number of loop for the sched test sequence */
+#define ASIDRV_SCHED_LOOP_COUNT		20
+
 /* Timeout for target to be ready to receive an interrupt or NMI */
 #define ASIDRV_TIMEOUT_TARGET_READY	1
 
 /* Timeout for receiving an interrupt or NMI */
 #define ASIDRV_TIMEOUT_INTERRUPT	5
 
+/* Timeout before thread can start its job */
+#define ASIDRV_TIMEOUT_THREAD_START	5
+
 /* NMI handler name used for testing */
 #define ASIDRV_NMI_HANDLER_NAME		"ASI Test"
 
 enum asidrv_state {
 	ASIDRV_STATE_NONE,
+	ASIDRV_STATE_START,
 	ASIDRV_STATE_INTR_WAITING,
 	ASIDRV_STATE_INTR_RECEIVED,
 	ASIDRV_STATE_NMI_WAITING,
@@ -50,6 +58,8 @@ struct asidrv_test {
 	bool			work_set;
 	enum asidrv_run_error	run_error;
 	bool			intrnmi;
+	struct task_struct	*kthread; /* work on same cpu */
+	int			count;
 };
 
 struct asidrv_sequence {
@@ -438,6 +448,66 @@ static enum asidrv_run_error asidrv_intrnmi_run(struct asidrv_test *test)
 	return err;
 }
 
+/*
+ * Sched Test Sequence
+ */
+
+static void asidrv_sched_loop(struct asidrv_test *test)
+{
+	int last_count = 0;
+
+	while (test->count < ASIDRV_SCHED_LOOP_COUNT) {
+		test->count++;
+		last_count = test->count;
+		/*
+		 * Call into the scheduler, until it runs the other
+		 * asidrv_sched_loop() task. We know it has run when
+		 * test->count changes.
+		 */
+		while (last_count == test->count)
+			schedule();
+	}
+	test->count++;
+}
+
+static int asidrv_sched_kthread(void *data)
+{
+	struct asidrv_test *test = data;
+	enum asidrv_run_error err;
+
+	err = asidrv_wait(test, ASIDRV_STATE_START,
+			  ASIDRV_TIMEOUT_THREAD_START);
+	if (err) {
+		pr_debug("Error waiting for start state: error %d\n", err);
+		return err;
+	}
+	asidrv_sched_loop(test);
+
+	return 0;
+}
+
+static enum asidrv_run_error asidrv_sched_init(struct asidrv_test *test)
+{
+	test->kthread = kthread_create_on_node(asidrv_sched_kthread, test,
+					       cpu_to_node(test->cpu),
+					       "sched test");
+	if (!test->kthread)
+		return ASIDRV_RUN_ERR_KTHREAD;
+
+	kthread_bind(test->kthread, test->cpu);
+	test->count = 0;
+
+	return ASIDRV_RUN_ERR_NONE;
+}
+
+static enum asidrv_run_error asidrv_sched_run(struct asidrv_test *test)
+{
+	atomic_set(&test->state, ASIDRV_STATE_START);
+	asidrv_sched_loop(test);
+
+	return ASIDRV_RUN_ERR_NONE;
+}
+
 /*
  * Memory Buffer Access Test Sequences
  */
@@ -521,14 +591,28 @@ struct asidrv_sequence asidrv_sequences[] = {
 		"intr+nmi",
 		asidrv_intrnmi_setup, asidrv_intrnmi_run, asidrv_nmi_cleanup,
 	},
+	[ASIDRV_SEQ_SCHED] = {
+		"sched",
+		asidrv_sched_init, asidrv_sched_run, NULL,
+	},
 };
 
 static enum asidrv_run_error asidrv_run_init(struct asidrv_test *test)
 {
+	cpumask_t mask = CPU_MASK_NONE;
 	int err;
 
 	test->run_error = ASIDRV_RUN_ERR_NONE;
 
+	/*
+	 * Binding ourself to the current cpu but keep preemption
+	 * enabled.
+	 */
+	test->cpu = get_cpu();
+	cpumask_set_cpu(test->cpu, &mask);
+	set_cpus_allowed_ptr(current, &mask);
+	put_cpu();
+
 	/*
 	 * Map the current stack, we need it to enter ASI.
 	 */
@@ -589,12 +673,26 @@ static enum asidrv_run_error asidrv_run_setup(struct asidrv_test *test,
 		schedule_work_on(other_cpu, &test->work);
 	}
 
+	if (test->kthread)
+		wake_up_process(test->kthread);
+
 	return ASIDRV_RUN_ERR_NONE;
 }
 
 static void asidrv_run_cleanup(struct asidrv_test *test,
 			       struct asidrv_sequence *sequence)
 {
+	if (test->kthread) {
+		kthread_stop(test->kthread);
+		test->kthread = NULL;
+	}
+
+	if (test->work_set) {
+		/* ensure work has completed */
+		flush_work(&test->work);
+		test->work_set = false;
+	}
+
 	if (sequence->cleanup)
 		sequence->cleanup(test);
 }
diff --git a/drivers/staging/asi/asidrv.h b/drivers/staging/asi/asidrv.h
index de9f7ad993e0..9f540b119883 100644
--- a/drivers/staging/asi/asidrv.h
+++ b/drivers/staging/asi/asidrv.h
@@ -13,6 +13,7 @@ enum asidrv_seqnum {
 	ASIDRV_SEQ_INTERRUPT,	/* interrupt sequence */
 	ASIDRV_SEQ_NMI,		/* NMI interrupt sequence */
 	ASIDRV_SEQ_INTRNMI,	/* NMI in interrupt sequence */
+	ASIDRV_SEQ_SCHED,	/* schedule() sequence */
 };
 
 enum asidrv_run_error {
@@ -30,6 +31,7 @@ enum asidrv_run_error {
 	ASIDRV_RUN_ERR_NMI,	/* no NMI received */
 	ASIDRV_RUN_ERR_NMI_REG,	/* failed to register NMI handler */
 	ASIDRV_RUN_ERR_NMI_ASI_ACTIVE, /* ASI active in NMI handler */
+	ASIDRV_RUN_ERR_KTHREAD,	/* failed to create kernel thread */
 };
 
 #define ASIDRV_IOCTL_RUN_SEQUENCE	_IOWR('a', 1, struct asidrv_run_param)
-- 
2.18.2



  parent reply	other threads:[~2020-05-04 15:04 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-04 15:02 [RFC v4][PATCH part-3 00/14] ASI - Part III (ASI Test Driver and CLI) Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 01/14] mm/asi: Define the test ASI type Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 02/14] asidrv: Introduce the ASI driver Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 03/14] asidrv: Introduce the ASIDRV_IOCTL_RUN_SEQUENCE ioctl Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 04/14] asidrv: Sequence to test ASI access to mapped/unmapped memory Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 05/14] asidrv: Sequence to test interrupt on ASI Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 06/14] asidrv: Sequence to test NMI " Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 07/14] asidrv: Sequence to test interrupt+NMI " Alexandre Chartre
2020-05-04 15:02 ` Alexandre Chartre [this message]
2020-05-04 15:02 ` [RFC v4][PATCH part-3 09/14] asidrv: Add ioctls to manage ASI page faults Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 10/14] asidrv: Add ioctls to manage ASI mapped VA ranges Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 11/14] asidrv/asicmd: Introduce the asicmd command Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 12/14] asidrv/asicmd: Add more test sequences for testing ASI Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 13/14] asidrv/asicmd: Add options to manage ASI page faults Alexandre Chartre
2020-05-04 15:02 ` [RFC v4][PATCH part-3 14/14] asidrv/asicmd: Add options to manage ASI mapped VA ranges Alexandre Chartre

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=20200504150235.12171-9-alexandre.chartre@oracle.com \
    --to=alexandre.chartre@oracle.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=graf@amazon.de \
    --cc=hpa@zytor.com \
    --cc=jan.setjeeilers@oracle.com \
    --cc=junaids@google.com \
    --cc=konrad.wilk@oracle.com \
    --cc=kuzuno@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liran.alon@oracle.com \
    --cc=luto@kernel.org \
    --cc=mgross@linux.intel.com \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rppt@linux.vnet.ibm.com \
    --cc=tglx@linutronix.de \
    --cc=x86@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