Skip to contentSkip to conversation

Unwanted mode switch.

Xenomai-core Gilles Chanteperdrix 4 participants 5 messages Jan 11, 2007 – Jan 15, 2007

lore
Share & tools
lore
#0 lore raw

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 ?

Signature · 1 line
                                                 Gilles Chanteperdrix

#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);
}
#1 lore raw
Quoted 7 lines · Gilles Chanteperdrix

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 ?

Put in some xntrace_user_freeze(0) before or after the point-of-interest in the program, switch on the tracer, and check ipipe/trace/frozen (with appropriate back_trace_points or post_trace_points) what is going on. Once you know the particular code path, instrumenting it can also be done this way: xntrace_special(some_id, some_value_of_interest).

Jan

#2 lore raw
In reply to Gilles Chanteperdrix
Quoted 6 lines · Gilles Chanteperdrix

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 ?

I added a show_stack(NULL, NULL) in xnshadow_relax, and I get the following stack trace:
xnshadow_relax
hisyscall_event
xnshadow_sys_migrate
losyscall_event

Signature · 1 line
                                                 Gilles Chanteperdrix
#3 lore raw
Quoted 8 lines · Gilles Chanteperdrix
Quoted 6 lines · Gilles Chanteperdrix

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 ?

Quoted 4 lines

I added a show_stack(NULL, NULL) in xnshadow_relax, and I get the following stack trace:
xnshadow_relax
hisyscall_event

^^^ Eeek... Which would mean that we would somehow be running the
hi-stage handler for a task on behalf of, say, xnshadow_harden()? Could you confirm the backtrace? Any chance the frame unwinding went south here?

Dumping the muxid/muxop pair for the hisyscall_event call which attempts to relax the underlying task might be interesting.

Quoted 3 lines

xnshadow_sys_migrate
losyscall_event

Signature · 1 line
Philippe.
#4 lore raw
In reply to Gilles Chanteperdrix
Quoted 7 lines · Gilles Chanteperdrix

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 ?

I'll have a look asap.

Quoted 5 lines

_______________________________________________
Xenomai-core mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-core

Signature · 1 line
Philippe.