Skip to contentSkip to conversation

Unexpected switch to secondary mode

Xenomai-help Johan Borkhuis 6 participants 20 messages Aug 2, 2007 – Aug 8, 2007 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

I am experiencing an unexpected switch to secondary mode in a rt_timer_tsc2ns call from userspace.

The following code give a switch:
SRTIME timeStamp;
timeStamp = rt_timer_tsc2ns(rt_timer_tsc()); while((rt_timer_tsc2ns(rt_timer_tsc()) - timeStamp) < (usecs*1000)) {}

while the following code does not:
RTIME timeStamp;
timeStamp = rt_timer_tsc(); while((rt_timer_tsc() - timeStamp) < (usecs*1000)) {}

(I know that the second example causes a longer timeout, but this was to show the testcase).

When splitting up the 2nd line in the first example I see that the rt_timer_tsc() call does not cause a switch, but the rt_timer_tsc2ns does. What am I doing wrong here?

I am using Xenomai-2.3.2.

Kind regards,
Johan Borkhuis

#1 lore raw
Quoted 13 lines · Johan Borkhuis

I am experiencing an unexpected switch to secondary mode in a rt_timer_tsc2ns call from userspace.

The following code give a switch:

    SRTIME timeStamp;
    timeStamp = rt_timer_tsc2ns(rt_timer_tsc());
    while((rt_timer_tsc2ns(rt_timer_tsc()) - timeStamp) < (usecs*1000)) {}

while the following code does not:

    RTIME timeStamp;
    timeStamp = rt_timer_tsc();
    while((rt_timer_tsc() - timeStamp) < (usecs*1000)) {}
Quoted 9 lines

(I know that the second example causes a longer timeout, but this was to show the testcase).

When splitting up the 2nd line in the first example I see that the rt_timer_tsc() call does not cause a switch, but the rt_timer_tsc2ns does. What am I doing wrong here?

I am using Xenomai-2.3.2.

- Which CPU architecture, and which Adeos patch release are you using?
- How do you notice the switches, SIGXCPU or /proc/xenomai/stat?

Quoted 8 lines

Kind regards,
Johan Borkhuis

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

Signature · 1 line
Philippe.
#2 lore raw
Quoted 16 lines · Philippe Gerum
Quoted 14 lines · Johan Borkhuis

I am experiencing an unexpected switch to secondary mode in a rt_timer_tsc2ns call from userspace.

The following code give a switch:

    SRTIME timeStamp;
    timeStamp = rt_timer_tsc2ns(rt_timer_tsc());
    while((rt_timer_tsc2ns(rt_timer_tsc()) - timeStamp) < (usecs*1000)) {}

while the following code does not:

    RTIME timeStamp;
    timeStamp = rt_timer_tsc();
    while((rt_timer_tsc() - timeStamp) < (usecs*1000)) {}

(I know that the second example causes a longer timeout, but this was to show the testcase).

Quoted 8 lines
Quoted 5 lines

When splitting up the 2nd line in the first example I see that the rt_timer_tsc() call does not cause a switch, but the rt_timer_tsc2ns does. What am I doing wrong here?

I am using Xenomai-2.3.2.

- Which CPU architecture, and which Adeos patch release are you using?

Processor: ppc 85xx, patch 1.5-03, Xenomai 2.3.2

Quoted 2 lines

- How do you notice the switches, SIGXCPU or /proc/xenomai/stat?

SIGXCPU

Kind regards,
Johan Borkhuis

#3 lore raw
Quoted 27 lines · Johan Borkhuis
Quoted 26 lines · Philippe Gerum
Quoted 23 lines · Johan Borkhuis

I am experiencing an unexpected switch to secondary mode in a rt_timer_tsc2ns call from userspace.

The following code give a switch:

    SRTIME timeStamp;
    timeStamp = rt_timer_tsc2ns(rt_timer_tsc());
    while((rt_timer_tsc2ns(rt_timer_tsc()) - timeStamp) < (usecs*1000)) {}

while the following code does not:

    RTIME timeStamp;
    timeStamp = rt_timer_tsc();
    while((rt_timer_tsc() - timeStamp) < (usecs*1000)) {}

(I know that the second example causes a longer timeout, but this was to show the testcase).

When splitting up the 2nd line in the first example I see that the rt_timer_tsc() call does not cause a switch, but the rt_timer_tsc2ns does. What am I doing wrong here?

I am using Xenomai-2.3.2.

Quoted 8 lines
Quoted 2 lines

- Which CPU architecture, and which Adeos patch release are you using?

Processor: ppc 85xx, patch 1.5-03, Xenomai 2.3.2

Quoted 2 lines

- How do you notice the switches, SIGXCPU or /proc/xenomai/stat?

SIGXCPU

So it's unfortunately possible to experiment such switches on ppc hw for now. It is likely happening when the ns value is copied back to a user variable for which there is a PTE miss to handle in Linux kernel space first. Check the mail archive about "pte", "cow" (copy-on-write) and such things.

Quoted 3 lines

Kind regards,
Johan Borkhuis

Signature · 1 line
Philippe.
#4 lore raw
Quoted 34 lines · Philippe Gerum
Quoted 33 lines · Johan Borkhuis
Quoted 22 lines · Philippe Gerum
Quoted 20 lines · Johan Borkhuis

I am experiencing an unexpected switch to secondary mode in a rt_timer_tsc2ns call from userspace.

The following code give a switch:

    SRTIME timeStamp;
    timeStamp = rt_timer_tsc2ns(rt_timer_tsc());
    while((rt_timer_tsc2ns(rt_timer_tsc()) - timeStamp) < (usecs*1000)) {}

while the following code does not:

    RTIME timeStamp;
    timeStamp = rt_timer_tsc();
    while((rt_timer_tsc() - timeStamp) < (usecs*1000)) {}

(I know that the second example causes a longer timeout, but this was to show the testcase).

When splitting up the 2nd line in the first example I see that the rt_timer_tsc() call does not cause a switch, but the rt_timer_tsc2ns does. What am I doing wrong here?

Quoted 6 lines
Quoted 3 lines

I am using Xenomai-2.3.2.

- Which CPU architecture, and which Adeos patch release are you using?

Processor: ppc 85xx, patch 1.5-03, Xenomai 2.3.2

Quoted 2 lines

- How do you notice the switches, SIGXCPU or /proc/xenomai/stat?

Quoted 8 lines
Quoted 2 lines

SIGXCPU

So it's unfortunately possible to experiment such switches on ppc hw for now. It is likely happening when the ns value is copied back to a user variable for which there is a PTE miss to handle in Linux kernel space first. Check the mail archive about "pte", "cow" (copy-on-write) and such things.

Err. ppcs have a tsc accessible in user-space, don't they ? So, I would expect the conversion to be done in user-space.

Signature · 1 line
					    Gilles Chanteperdrix.
#5 lore raw
Quoted 38 lines · Gilles Chanteperdrix
Quoted 37 lines · Philippe Gerum
Quoted 35 lines · Johan Borkhuis
Quoted 22 lines · Philippe Gerum
Quoted 20 lines · Johan Borkhuis

I am experiencing an unexpected switch to secondary mode in a rt_timer_tsc2ns call from userspace.

The following code give a switch:

    SRTIME timeStamp;
    timeStamp = rt_timer_tsc2ns(rt_timer_tsc());
    while((rt_timer_tsc2ns(rt_timer_tsc()) - timeStamp) < (usecs*1000)) {}

while the following code does not:

    RTIME timeStamp;
    timeStamp = rt_timer_tsc();
    while((rt_timer_tsc() - timeStamp) < (usecs*1000)) {}

(I know that the second example causes a longer timeout, but this was to show the testcase).

When splitting up the 2nd line in the first example I see that the rt_timer_tsc() call does not cause a switch, but the rt_timer_tsc2ns does. What am I doing wrong here?

Quoted 6 lines
Quoted 3 lines

I am using Xenomai-2.3.2.

- Which CPU architecture, and which Adeos patch release are you using?

Processor: ppc 85xx, patch 1.5-03, Xenomai 2.3.2

Quoted 2 lines

- How do you notice the switches, SIGXCPU or /proc/xenomai/stat?

SIGXCPU

Quoted 9 lines
Quoted 5 lines

So it's unfortunately possible to experiment such switches on ppc hw for now. It is likely happening when the ns value is copied back to a user variable for which there is a PTE miss to handle in Linux kernel space first. Check the mail archive about "pte", "cow" (copy-on-write) and such things.

Err. ppcs have a tsc accessible in user-space, don't they ? So, I would expect the conversion to be done in user-space.

The important issue is not that such memory is being written from kernel space, but that you don't have the PTE mapped when writing down the conversion results. And this may happen from pure user-space too in case DIRECT_TSC is available, despite the memlock.

Signature · 1 line
Philippe.
#6 lore raw
In reply to Philippe Gerum

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.

Quoted 6 lines · Philippe Gerum

So it's unfortunately possible to experiment such switches on ppc hw for now. It is likely happening when the ns value is copied back to a user variable for which there is a PTE miss to handle in Linux kernel space first. Check the mail archive about "pte", "cow" (copy-on-write) and such things.

As far as I know (but I can be incorrect here) an interrupt is generated due to a PTE-miss. This causes the Nucleus to switch to secondary mode, to allow Linux to process the PTE's. The total latency caused by this would not be very bad, as you also indicated earlier.

From the earlier discussion:

In such a case, you have likely hit an illustration of the latter issue which the I-pipe/ppc implementation still suffers from: some page table entries are missed during real-time operations. As a consequence of this, the nucleus catches page faults on behalf of RT threads in primary mode, then switches these threads back to secondary in order to process the faults, and eventually wire the missing PTEs in. This is something calling mlockall() does not prevent the application from (like COW).

Now for my question.
When looking at a situation where you have a system running multiple RT-tasks, when one of them hits an (unexpected) switch, it is possible that this task will never be switched in again, as the other RT-tasks might consume all the processor time. Would it be possible to have the Nucleus, after the page-fault is processed and the "problem" is fixed, automagically switch the system back to primary mode?
It is not the real solution to the problem, but it would be a acceptable workaround for this moment, until a real solution is available.

Also another question on this issue: at this moment I am using kernel 2.6.14(ppc), but I saw that there is now an adeos-patch for 2.6.20(powerpc). Could using this version give an improvement in this area, or does this not make a difference?

Kind regards,
Johan Borkhuis

#20 lore raw
In reply to Johan Borkhuis
Quoted 22 lines · Johan Borkhuis
Quoted 21 lines · Philippe Gerum
Quoted 19 lines · Johan Borkhuis

I am experiencing an unexpected switch to secondary mode in a rt_timer_tsc2ns call from userspace.

The following code give a switch:

    SRTIME timeStamp;
    timeStamp = rt_timer_tsc2ns(rt_timer_tsc());
    while((rt_timer_tsc2ns(rt_timer_tsc()) - timeStamp) < (usecs*1000)) {}

while the following code does not:

    RTIME timeStamp;
    timeStamp = rt_timer_tsc();
    while((rt_timer_tsc() - timeStamp) < (usecs*1000)) {}

(I know that the second example causes a longer timeout, but this was to show the testcase).

When splitting up the 2nd line in the first example I see that the rt_timer_tsc() call does not cause a switch, but the rt_timer_tsc2ns does. What am I doing wrong here?

I am using Xenomai-2.3.2.

Quoted 7 lines
Quoted 2 lines

- Which CPU architecture, and which Adeos patch release are you using?

Processor: ppc 85xx, patch 1.5-03, Xenomai 2.3.2

Quoted 2 lines

- How do you notice the switches, SIGXCPU or /proc/xenomai/stat?

SIGXCPU

And what does /proc/xenomai/faults show right before and after the SIGXCPU?

Wolfgang.

#7 lore raw
In reply to Johan Borkhuis
Quoted 5 lines · Johan Borkhuis

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?)

This list is ok; we are discussing about how RT threads are coping with the underlying MMU, which is first and foremost a Xenomai issue (despite Adeos must be the one to provide some support to fix the latter issue though).

Quoted 6 lines

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.

Yeah, not pretty, but clearly illustrates the point.

Quoted 7 lines
Quoted 6 lines · Philippe Gerum

So it's unfortunately possible to experiment such switches on ppc hw for now. It is likely happening when the ns value is copied back to a user variable for which there is a PTE miss to handle in Linux kernel space first. Check the mail archive about "pte", "cow" (copy-on-write) and such things.

Quoted 5 lines

As far as I know (but I can be incorrect here) an interrupt is generated due to a PTE-miss. This causes the Nucleus to switch to secondary mode, to allow Linux to process the PTE's. The total latency caused by this would not be very bad, as you also indicated earlier.

Correct, as the experience shows. Still, I don't like the idea of leaving this window open for latency.

Quoted 11 lines

From the earlier discussion:

In such a case, you have likely hit an illustration of the latter issue which the I-pipe/ppc implementation still suffers from: some page table entries are missed during real-time operations. As a consequence of this, the nucleus catches page faults on behalf of RT threads in primary mode, then switches these threads back to secondary in order to process the faults, and eventually wire the missing PTEs in. This is something calling mlockall() does not prevent the application from (like COW).

Quoted 5 lines

Now for my question.
When looking at a situation where you have a system running multiple RT-tasks, when one of them hits an (unexpected) switch, it is possible that this task will never be switched in again, as the other RT-tasks might consume all the processor time.

Correct, if not the most probable since threads usually manage to call a blocking Xenomai service which switches them back to primary mode. Still, the switch-delayed-by-preemption scenario is perfectly possible.

Quoted 3 lines

Would it be possible to have the Nucleus, after the page-fault is processed and the "problem" is fixed, automagically switch the system back to primary mode?

Yes, I think so. This would be restricted to minor VM faults in order to prevent any misuse of this feature, but I'm going to implement this.

Quoted 3 lines

It is not the real solution to the problem, but it would be a acceptable workaround for this moment, until a real solution is available.

Ack.

Quoted 5 lines

Also another question on this issue: at this moment I am using kernel 2.6.14(ppc), but I saw that there is now an adeos-patch for 2.6.20(powerpc). Could using this version give an improvement in this area, or does this not make a difference?

No difference, yet.

Quoted 2 lines

Kind regards,
Johan Borkhuis

Signature · 1 line
Philippe.
#8 lore raw
In reply to Johan Borkhuis
Quoted 10 lines · Johan Borkhuis

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.

But I have another question: since the nocow patch is platform independent, why not integrating it in the I-pipe patch for power pc ?

Signature · 1 line
                                               Gilles Chanteperdrix
#9 lore raw
Quoted 12 lines · Gilles Chanteperdrix
Quoted 10 lines · Johan Borkhuis

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.

Quoted 3 lines

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

Signature · 1 line
					    Gilles Chanteperdrix.
#13 lore raw
In reply to Gilles Chanteperdrix
Quoted 12 lines · Gilles Chanteperdrix
Quoted 10 lines · Johan Borkhuis

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.

Quoted 7 lines

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.

But I have another question: since the nocow patch is platform independent, why not integrating it in the I-pipe patch for power pc ?

It is merged into the latest patches against the powerpc/ tree.

Signature · 1 line
Philippe.
#10 lore raw
In reply to Gilles Chanteperdrix

Gilles,

Quoted 13 lines · Gilles Chanteperdrix
Quoted 12 lines · Gilles Chanteperdrix
Quoted 10 lines · Johan Borkhuis

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.

Quoted 7 lines
Quoted 3 lines

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

#11 lore raw
Quoted 34 lines · Johan Borkhuis

Gilles,

Quoted 13 lines · Gilles Chanteperdrix
Quoted 12 lines · Gilles Chanteperdrix
Quoted 10 lines · Johan Borkhuis

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.

Quoted 7 lines
Quoted 3 lines

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.

Quoted 5 lines

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:

The code I sent only access writable pages, and apparently you need to also access read-only pages.

Why not doing something like:

else if(buffer[1] == 'r')  {
    static voltatile int dummy;
    dummy = *(volatile int *)begin;
}
Signature · 1 line
                                               Gilles Chanteperdrix
#12 lore raw
Quoted 10 lines · Gilles Chanteperdrix

The code I sent only access writable pages, and apparently you need to also access read-only pages.

Why not doing something like:

else if(buffer[1] == 'r')  {
    static voltatile int dummy;
    dummy = *(volatile int *)begin;
}

I tried this code first, but it did not make any difference. The problem is (at least, that is what I expect) that you access the page as data, opposed to code, when you execute something in the page.

Kind regards,
Johan Borkhuis

#15 lore raw
In reply to a message not in the archive

[ forgot to add the list : ]

---------- Forwarded message ----------

Quoted 6 lines · Philippe Gerum
Quoted 4 lines

[ ... ]
But I have another question: since the nocow patch is platform independent, why not integrating it in the I-pipe patch for power pc ?

It is merged into the latest patches against the powerpc/ tree.

[ Mainly, just out of curiosity ]

I've actually tried 'google'ing for an overview of the MMU on ppc but it doesn't seem to be easily
available on the net.

Do I understand it right that in the PPC arch. a CPU doesn't have full access to task's page tables.. that said, if a TLB miss takes place (or some analogue lookup mechanism), the CPU needs assistance from the OS and e.g. rises an exception.

[*] A corresponding OS handler gets a 'fault address' and looks for it in the task's 'page tables' .. and if found, updates TLB accordingly.

This would be similar to what happens in MIPS :
TLB miss --> TLB-miss exception --> OS-dependent TLB-miss handler.

Now, Xenomai is not able (at the moment) to do [*] on its own.. thus, there is a switch to the secondary mode so that Linux is able to take care of it.

Unless there is a way to reserve a set of TLB entries for a real-time task (or other mechanism to have 'virtual -> physical' conversion entirely in the CPU -- I mean, not involving the OS) + the working set of the rt task fits into this 'reserved' set --- 'TLB-miss' exception gonna happen.. e.g. every time after the RT relinquish a CPU and something else trashes the TLB tables.

e.g. on MIPS, the area used for kernel modules also requires virtual->physical translation.. so even a kernel-mode task (and actually, interrupt handlers inside the kernel modules) cause TLB-miss exceptions. Sure, it's not a case if it's linked against the kernel itself.

errr.. ok, to many words :-) does it sound like smth taking place here? A link to the MMU overview for ppc would be highly appreciated as well.

TIA,

Quoted 4 lines

--
Philippe.

--
Best regards,
Dmitry Adamushko

Signature · 2 lines
Best regards,
Dmitry Adamushko
#16 lore raw

Dmitry Adamushko kirjoitti:

Quoted 48 lines

[ forgot to add the list : ]

---------- Forwarded message ----------

Quoted 6 lines · Philippe Gerum
Quoted 4 lines

[ ... ]
But I have another question: since the nocow patch is platform independent, why not integrating it in the I-pipe patch for power pc ?

It is merged into the latest patches against the powerpc/ tree.

[ Mainly, just out of curiosity ]

I've actually tried 'google'ing for an overview of the MMU on ppc but it doesn't seem to be easily
available on the net.

Do I understand it right that in the PPC arch. a CPU doesn't have full access to task's page tables.. that said, if a TLB miss takes place (or some analogue lookup mechanism), the CPU needs assistance from the OS and e.g. rises an exception.

[*] A corresponding OS handler gets a 'fault address' and looks for it in the task's 'page tables' .. and if found, updates TLB accordingly.

This would be similar to what happens in MIPS :
TLB miss --> TLB-miss exception --> OS-dependent TLB-miss handler.

Now, Xenomai is not able (at the moment) to do [*] on its own.. thus, there is a switch to the secondary mode so that Linux is able to take care of it.

Unless there is a way to reserve a set of TLB entries for a real-time task (or other mechanism to have 'virtual -> physical' conversion entirely in the CPU -- I mean, not involving the OS) + the working set of the rt task fits into this 'reserved' set --- 'TLB-miss' exception gonna happen.. e.g. every time after the RT relinquish a CPU and something else trashes the TLB tables.

e.g. on MIPS, the area used for kernel modules also requires virtual->physical translation.. so even a kernel-mode task (and actually, interrupt handlers inside the kernel modules) cause TLB-miss exceptions. Sure, it's not a case if it's linked against the kernel itself.

Quoted 3 lines

errr.. ok, to many words :-) does it sound like smth taking place here? A link to the MMU overview for ppc would be highly appreciated as well.

See the powerpc architecture book at:
http://www.ibm.com/developerworks/eserver/articles/archguide.html
It gives the generics. Also see the Book-E (~embedded cpus) architecture; they have different MMUs:
http://www-01.ibm.com/chips/techlib/techlib.nsf/techdocs/852569B20050FF778525699600682CC7
And then the model specific manuals (405, 440, 5xx, etc.), which should be available at the IBM/Freescale/AMCC sites.

-- Heikki Lindholm

#17 lore raw
In reply to Dmitry Adamushko
Quoted 9 lines · Dmitry Adamushko

[ forgot to add the list : ]

---------- Forwarded message ----------

Quoted 4 lines · Philippe Gerum
Quoted 4 lines

[ ... ]
But I have another question: since the nocow patch is platform independent, why not integrating it in the I-pipe patch for power pc ?

Quoted 7 lines
Quoted 1 line

It is merged into the latest patches against the powerpc/ tree.

[ Mainly, just out of curiosity ]

I've actually tried 'google'ing for an overview of the MMU on ppc but it doesn't seem to be easily
available on the net.

Unfortunately, there is no common MMU implementation for the PowerPC processors. It is usually described in the User Manual for the IBM, Freescale or AMCC processor, e.g.:

http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPC5200&fpsp=1&tab=Documentation_Tab

Quoted 5 lines

Do I understand it right that in the PPC arch. a CPU doesn't have full access to task's page tables.. that said, if a TLB miss takes place (or some analogue lookup mechanism), the CPU needs assistance from the OS and e.g. rises an exception.

Yes.

Quoted 2 lines

[*] A corresponding OS handler gets a 'fault address' and looks for it in the task's 'page tables' .. and if found, updates TLB accordingly.

Yes. High-end PowerPC processors have better hw support for virtual to physical address translation than low-end processors. They usually just have 64 TLB entries or even less (like the MPC 8xx).

Quoted 2 lines

This would be similar to what happens in MIPS :
TLB miss --> TLB-miss exception --> OS-dependent TLB-miss handler.

Yes.

Quoted 3 lines

Now, Xenomai is not able (at the moment) to do [*] on its own.. thus, there is a switch to the secondary mode so that Linux is able to take care of it.

But normal TLB misses happen frequently and do not force a switch to secondary mode. I think the problem is with the do_page_fault trap. Can somebody confirm that?

Quoted 7 lines

Unless there is a way to reserve a set of TLB entries for a real-time task (or other mechanism to have 'virtual -> physical' conversion entirely in the CPU -- I mean, not involving the OS) + the working set of the rt task fits into this 'reserved' set --- 'TLB-miss' exception gonna happen.. e.g. every time after the RT relinquish a CPU and something else trashes the TLB tables.

Quoted 5 lines

e.g. on MIPS, the area used for kernel modules also requires virtual->physical translation.. so even a kernel-mode task (and actually, interrupt handlers inside the kernel modules) cause TLB-miss exceptions. Sure, it's not a case if it's linked against the kernel itself.

Even kernel code may cause a TLB miss. TLB pinning has been abandoned on some PowerPC archs because it does reduce overall system performance.

Quoted 3 lines

errr.. ok, to many words :-) does it sound like smth taking place here? A link to the MMU overview for ppc would be highly appreciated as well.

See above. Unfortunately, I do only a limited, global view of the MMU implementation for PowerPC.

Wolfgang.

#18 lore raw

Heikki and Wolfgang, thanks for the links.

Quoted 6 lines
Quoted 3 lines

Now, Xenomai is not able (at the moment) to do [*] on its own.. thus, there is a switch to the secondary mode so that Linux is able to take care of it.

But normal TLB misses happen frequently and do not force a switch to secondary mode. I think the problem is with the do_page_fault trap.

This would make sense indeed. I presume, there must be some sort of inter-domain synchronization in place to safely access the 'page tables' for the fast-path of a TLB-miss handler to run in the primary mode (chores: so go and read the code.. ah well :-)

Then a remaining part is do_page_fault() and one of the reasons can be 'cow' indeed.

As a side note (not PPC related so one may skip this part),

on MIPS do_page_fault() may be caused by accessing a valid address allocated by a kernel module (say, vmalloc()). Say,

- task_1 calls ioctl() of some driver which does obj = vmalloc() . As a result, task_1 :: page_tables are updated accordingly + so called 'master_table' gets updated;

- task_2 calls ioctl() to the same driver which, in turn, accesses 'obj' . Now, if there is no TLB record in place at the moment --> TLB miss --> TLB-miss handler looks at task_2 :: page_tables but there is no record! --> do_page_fault() --> verifies a 'fault address' against the 'master_table' and if it's ok, copies a record from 'master_table' to task_2 :: page_tables --> update TLB, etc.

although, it's kind of a 'cow' mech. Provided, do_page_fault() is not handled in the primary mode.. so to avoid it, I guess, one would need to immediately sync. RT_task :: page_tables upon any vmalloc() in the system. Sure, in theory, 'master_table' could have been always used for translation of the kernel space vmalloc()'ed areas.. but that somewhat complicates a TLB-miss handler : maybe size, speed, sychronization, I guess (humm.. interesting why it's not actually like that.. maybe smth else).

Quoted 8 lines
Quoted 5 lines

e.g. on MIPS, the area used for kernel modules also requires virtual->physical translation.. so even a kernel-mode task (and actually, interrupt handlers inside the kernel modules) cause TLB-miss exceptions. Sure, it's not a case if it's linked against the kernel itself.

Even kernel code may cause a TLB miss. TLB pinning has been abandoned on some PowerPC archs because it does reduce overall system performance.

Humm.. interesting. AFAIK, on MIPS [ 0x80000000, 0xa0000000 ] and [ 0xa0000000, 0xc0000000 ] are just directly mapped onto the physical memory, cached and non-cached mode respectively. This avoids a need for TLB.

Quoted 3 lines

See above. Unfortunately, I do only a limited, global view of the MMU implementation for PowerPC.

Thanks indeed!

Quoted 3 lines

Wolfgang.

Signature · 2 lines
Best regards,
Dmitry Adamushko
#19 lore raw
Quoted 46 lines · Dmitry Adamushko

Heikki and Wolfgang, thanks for the links.

Quoted 5 lines
Quoted 3 lines

Now, Xenomai is not able (at the moment) to do [*] on its own.. thus, there is a switch to the secondary mode so that Linux is able to take care of it.

But normal TLB misses happen frequently and do not force a switch to secondary mode. I think the problem is with the do_page_fault trap.

This would make sense indeed. I presume, there must be some sort of inter-domain synchronization in place to safely access the 'page tables' for the fast-path of a TLB-miss handler to run in the primary mode (chores: so go and read the code.. ah well :-)

Then a remaining part is do_page_fault() and one of the reasons can be 'cow' indeed.

As a side note (not PPC related so one may skip this part),

on MIPS do_page_fault() may be caused by accessing a valid address allocated by a kernel module (say, vmalloc()). Say,

- task_1 calls ioctl() of some driver which does obj = vmalloc() . As a result, task_1 :: page_tables are updated accordingly + so called 'master_table' gets updated;

- task_2 calls ioctl() to the same driver which, in turn, accesses 'obj' . Now, if there is no TLB record in place at the moment --> TLB miss --> TLB-miss handler looks at task_2 :: page_tables but there is no record! --> do_page_fault() --> verifies a 'fault address' against the 'master_table' and if it's ok, copies a record from 'master_table' to task_2 :: page_tables --> update TLB, etc.

although, it's kind of a 'cow' mech. Provided, do_page_fault() is not handled in the primary mode.. so to avoid it, I guess, one would need to immediately sync. RT_task :: page_tables upon any vmalloc() in the system. Sure, in theory, 'master_table' could have been always used for translation of the kernel space vmalloc()'ed areas.. but that somewhat complicates a TLB-miss handler : maybe size, speed, sychronization, I guess (humm.. interesting why it's not actually like that.. maybe smth else).

Quoted 5 lines
Quoted 5 lines

e.g. on MIPS, the area used for kernel modules also requires virtual->physical translation.. so even a kernel-mode task (and actually, interrupt handlers inside the kernel modules) cause TLB-miss exceptions. Sure, it's not a case if it's linked against the kernel itself.

Quoted 7 lines
Quoted 2 lines

Even kernel code may cause a TLB miss. TLB pinning has been abandoned on some PowerPC archs because it does reduce overall system performance.

Humm.. interesting. AFAIK, on MIPS [ 0x80000000, 0xa0000000 ] and [ 0xa0000000, 0xc0000000 ] are just directly mapped onto the physical memory, cached and non-cached mode respectively. This avoids a need for TLB.

This is done in a similar way for PowerPC CPUs with a "standard" MMU. The kernel address space is then directly mapped with a Block Address Translation (BAT) register. My statement is valid for systems with just 64 TLB entries or less (4xx, 8xx) and pinning one or two of them has an impact on user space performance.

Quoted 4 lines
Quoted 2 lines

See above. Unfortunately, I do only a limited, global view of the MMU implementation for PowerPC.

Thanks indeed!

Just found the following article comparing 6xx/7xx with 4xx:

http://www-01.ibm.com/chips/techlib/techlib.nsf/techdocs/852569B20050FF7785256997006EB430/$file/4xx_6xx_an.pdf

It also highlights the difference between (Data/Instruction) TLB miss and Data (Load/Store) Translation miss.

Wolfgang.