From: Johan Borkhuis <j.borkhuis@domain.hid>
To: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
Cc: Xenomai-help@domain.hid
Subject: Re: [Xenomai-help] Unexpected switch to secondary mode
Date: Tue, 07 Aug 2007 13:06:30 +0200 [thread overview]
Message-ID: <46B85236.9010107@domain.hid> (raw)
In-Reply-To: <18103.2297.602539.889750@domain.hid>
Gilles,
Gilles Chanteperdrix wrote:
> Gilles Chanteperdrix wrote:
> > On 8/3/07, Johan Borkhuis <j.borkhuis@domain.hid> wrote:
> > > Philippe,
> > >
> > > (BTW: is this something that should be discussed in the Xenomai group,
> > > or would it be better to move this discussion to the Adeos mailing list?)
> > >
> > > I do have question on this. We already discussed this problem earlier,
> > > and I managed to find a very dirty work around for my application: I
> > > added a lot of "dummy" functions to my application, which are spread
> > > over the whole application. By calling these after the mlockall, but
> > > before I switch to RT-mode I manage to eliminate most of the switches.
> >
> > Before implementing the nocow patch, I opened /proc/self/maps and
> > caused a fault on every writable page, even if ugly, this looks
> > simpler than spreading dummy functions over the whole application.
>
> I posted the piece of code here:
> https://mail.gna.org/public/xenomai-help/2006-12/msg00168.html
>
Thank you for this. However, it does not seem to work: when I execute
this code it does not make any difference, when executed before I start
a RT-task or even within a RT-task. The results are identical to the
results as if no dummy functions were used. Only the pages that can be
written are touched, but the code pages that cause the problem (afaik)
are marked readonly, so they are not touched. I modified the linking, to
mark the text-section as writable, but that also did not make any
difference.
The fact that this does not work could be caused by the fact that you
are accessing the pages as data instead of code.
Next I tried something different, more like a combination between my
original approach and your approach: I tried to find a "return from
subroutine" in each text-page, and if found call this location. It is
extremely dirty, but it does seem to work quite well. Below is the code
that I used:
==========
#define RET_CODE 0x4e800020 /* blr */
typedef int (*TestFunc)(void);
static void fault_vm(void)
{
FILE *maps = fopen("/proc/self/maps", "r");
unsigned begin, end, pagesize=getpagesize();
char buffer[128];
int rc, i;
volatile int tmp;
TestFunc testFunc;
if (!maps) {
perror("fopen");
exit(EXIT_FAILURE);
}
while ((rc = fscanf(maps, "%x-%x",&begin, &end) == 2)) {
fgets(buffer, 128, maps);
for (; begin != end; begin += pagesize) {
if(buffer[2] == 'w') { /* Data section */
*(volatile int *) begin = *(volatile int *) begin;
}
else if(buffer[1] == 'r') { /* Text section */
for(i = 0; i < pagesize; i += 4) {
testFunc = (void *)(begin + i);
tmp = *(volatile int *) (begin + i);
if(tmp == RET_CODE) {
testFunc();
continue;
}
}
}
}
}
fclose(maps);
}
==========
Kind regards,
Johan Borkhuis
next prev parent reply other threads:[~2007-08-07 11:06 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-02 9:47 [Xenomai-help] Unexpected switch to secondary mode Johan Borkhuis
2007-08-02 10:12 ` Philippe Gerum
2007-08-02 10:54 ` Johan Borkhuis
2007-08-02 11:23 ` Philippe Gerum
2007-08-02 17:55 ` Gilles Chanteperdrix
2007-08-02 18:01 ` Philippe Gerum
2007-08-03 8:05 ` Johan Borkhuis
2007-08-05 17:22 ` Philippe Gerum
2007-08-06 9:08 ` Gilles Chanteperdrix
2007-08-06 11:41 ` Gilles Chanteperdrix
2007-08-07 11:06 ` Johan Borkhuis [this message]
2007-08-07 12:49 ` Gilles Chanteperdrix
2007-08-07 14:13 ` Johan Borkhuis
2007-08-06 11:54 ` Philippe Gerum
[not found] ` <b647ffbd0708070758t22f01577wd3a5397a53249459@domain.hid>
2007-08-08 7:40 ` Dmitry Adamushko
2007-08-08 8:00 ` Heikki Lindholm
2007-08-08 8:14 ` Wolfgang Grandegger
2007-08-08 9:12 ` Dmitry Adamushko
2007-08-08 10:13 ` Wolfgang Grandegger
2007-08-04 12:30 ` Wolfgang Grandegger
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=46B85236.9010107@domain.hid \
--to=j.borkhuis@domain.hid \
--cc=Xenomai-help@domain.hid \
--cc=gilles.chanteperdrix@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.