All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: xenomai-core <xenomai@xenomai.org>
Subject: [Xenomai-core] Unwanted mode switch.
Date: Thu, 11 Jan 2007 16:24:54 +0100	[thread overview]
Message-ID: <45A656C6.6060406@domain.hid> (raw)

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


Hi,

in order to test the nocow patch, I wrote the attached test. Despite the
fact that there is no longer any page fault (I have nucleus debugging
on, so I would get a message if there was a fault), there is still an
unwanted mode switch at step 5. Any idea what could be the cause ?


-- 
                                                 Gilles Chanteperdrix

[-- Attachment #2: test_fork.c --]
[-- Type: text/x-csrc, Size: 2663 bytes --]

#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <signal.h>
#include <string.h>
#include <sys/mman.h>
#include <execinfo.h>
#include <native/timer.h>
#include <native/task.h>

unsigned step;
void do_backtrace(void)
{
	static void *buffer[200];
	int levels = backtrace(buffer, sizeof(buffer)/sizeof(void *));
	backtrace_symbols_fd(buffer, levels, STDOUT_FILENO);
}
void mode_switch(int sig)
{
	printf("mode switch at step %d, test failed!\n", step);
	do_backtrace();
	exit(EXIT_FAILURE);
}

int main(void)
{
	RT_TASK task;
	RTIME time;
	pid_t pid;
	int rc;

	if ((SIG_ERR == signal(SIGXCPU, &mode_switch))) {
		perror("signal");
		exit(EXIT_FAILURE);
	}

	pid = fork();

	if (pid < 0) {
		perror("fork");
		exit(EXIT_FAILURE);
	}

	if (pid > 0) {
		int status;
		if (waitpid(pid, &status, 0) == -1) {
			perror("waitpid");
			exit(EXIT_FAILURE);
		}
		status = WEXITSTATUS(status);
		if (status == EXIT_SUCCESS)
			fprintf(stderr, "Test passed\n");
		_exit(status);
	}
	
	if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
		perror("mlockall");
		exit(EXIT_FAILURE);
	}

	step = 1;
	if ((rc = rt_task_shadow(&task, "test_vm1", 1, 0))) {
		fprintf(stderr,
			"rt_task_shadow: %s\n", strerror(-rc));
		exit(EXIT_FAILURE);
	}

	step = 2;
	if ((rc = rt_task_set_mode(0, T_WARNSW, NULL))) {
		fprintf(stderr,
			"rt_task_set_mode_np: %s\n", strerror(-rc));
		exit(EXIT_FAILURE);
	}

	step = 3;
	time = rt_timer_read();

	step = 4;
	if ((rc = rt_task_set_mode(T_PRIMARY, 0, NULL))) {
		fprintf(stderr,
			"rt_task_set_mode_np: %s\n", strerror(-rc));
		exit(EXIT_FAILURE);
	}
	pid = fork();

	if (pid < 0) {
		perror("fork");
		exit(EXIT_FAILURE);
	}

	if (pid > 0) {
		int status;
		step = 5;

		time = rt_timer_read();

		if ((rc = rt_task_set_mode(T_PRIMARY, 0, NULL))) {
			fprintf(stderr,
				"rt_task_set_mode_np: %s\n", strerror(-rc));
			exit(EXIT_FAILURE);
		}

		if (waitpid(pid, &status, 0) == -1) {
			perror("waitpid");
			exit(EXIT_FAILURE);
		}
		_exit(WEXITSTATUS(status));
	}
	
	if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
		perror("mlockall");
		exit(EXIT_FAILURE);
	}

	step = 6;
	if ((rc = rt_task_shadow(&task, "test_vm2", 1, 0))) {
		fprintf(stderr,
			"rt_task_shadow: %s\n", strerror(-rc));
		exit(EXIT_FAILURE);
	}

	step = 7;
	if ((rc = rt_task_set_mode(0, T_WARNSW, NULL))) {
		fprintf(stderr,
			"rt_task_set_mode_np: %s\n", strerror(-rc));
		exit(EXIT_FAILURE);
	}

	step = 8;
	time = rt_timer_read();
	
	if ((rc = rt_task_set_mode(T_PRIMARY, 0, NULL))) {
		fprintf(stderr,
			"rt_task_set_mode_np: %s\n", strerror(-rc));
		exit(EXIT_FAILURE);
	}

	exit(EXIT_SUCCESS);
}

             reply	other threads:[~2007-01-11 15:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-11 15:24 Gilles Chanteperdrix [this message]
2007-01-11 15:33 ` [Xenomai-core] Unwanted mode switch Jan Kiszka
2007-01-11 15:36 ` Gilles Chanteperdrix
2007-01-11 20:57   ` Philippe Gerum
2007-01-15 21:47 ` Philippe Gerum

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=45A656C6.6060406@domain.hid \
    --to=gilles.chanteperdrix@xenomai.org \
    --cc=xenomai@xenomai.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.