SH4 port
Thank you for your effort.
Quoted 11 lines
Quoted 10 lines · Jan Kiszka
Quoted 8 lines · Kiichi Kameda
...
After tough investigation, I think I found some clues such as:
While in.ftpd runs hard, a "write" system call was issued and Linux kernel was processing its request.
But weird__ipipe_dispatch_eventand__ipipe_sync_stagewas recorded.I think the problem originates from a Xenomai context
switch(which overwrites "current"), while Linux is processing system call.
Quoted 6 lines
Quoted 2 lines
If I interpret
linux/include/asm-sh/current.hcorrectly, current is derived from the stack on your platform (like on most archs) and cannotThat's nonsense as I realised later by following the code down to
include/asm-sh/thread_info.h:current_thread_infoseems to get referenced by some register.
In original SH-Linux ,"current" is based on r7_bank register in SH CPU
which is set only at context switch. "current" macro which is
referenced everywhere(including page fault handling and stack pointer setting
at interrupt from userspace), depends on this special register. r7_bank register has nothing to do with stack.
So, I created modified version of SH-Linux code , where "current" macro uses
the stack pointer(SP & ~(THREAD_SIZE) -1).
After that, although Linux seems to work well, the Xenomai thread still causes system panic, if I once run the Xenomai program that uses POSIX skin.
The panic messsage:
==========================================
Unable to handle kernel paging request. at virtual address 00100104 pc = 8c010658 <--requeue_task *pde = 00000000 Oops: 0001 [#1]
Pid : 948, Comm: in.ftpd
PC : 8c010658 SP : 8debfab0 SR : 40008101 .TEA : c0198044 .Not
tainted
R0 : 8c19e958 R1 : 8c19ed10 R2 : 00100100 R3 : 00200200 R4 : 8c2769a0 R5 : 8c19e958 R6 : 00000050 R7 : 8c2769c0 R8 : 8c2769a0 R9 : 00000000 R10 : 00000050 R11 : 8c2769a0 R12 : 8c2769e0 R13 : 8c19e928 R14 : 8debfab0
MACH: 0000027e MACL: b851edb4 GBR : 29568be0 PR : 8c0112b6.
Call trace:
== top
[<8c0112b6>] scheduler_tick
[<8c0d4d88>] smc_hard_start_xmit
[<8c00eb38>] __do_page_fault
[<8c01f828>] update_process_time
[<8c009988>] handle_timer_tick
[<8c00bd72>] tmu_timer_interrupt
[<8c03303a>] handle_IRQ_event
[<8c0330fa>] __do_IRQ
[<8c00d0f6>] __ipipe_do_IRQ
[<8c0342e4>] __ipipe_sync_stage
[<8c00d146>] __ipipe_grab_timer
[<8c010582>] dequeue_task
[<8c010876>] deactivate_task
[<8c1505d6>] schedule
[<8c15134c>] io_schedule
[<8c036406>] sync_page
[<8c151736>] __wait_on_bit_lock
[<8c036d90>] __lock_page
[<8c038050>] file_map_nopage
[<8c0444aa>] __handle_mm_fault
[<8c00e7f0>] do_page_fault
[<8c0af240>] csum_partial_copy_generic
[<8c125b64>] tcp_sendmsg
[<8c141c14>] inet_sendmsg
[<8c0f97f6>] do_sock_write
[<8c0f98ec>] sock_aio_write
[<8c01f74c>] run_timer_softirq
[<8c04e6ba>] do_sync_write
[<8c0343f6>] __ipipe_dispatch_event
[<8c04e78a>] vfs_write
[<8c04e8f4>] sys_write
[<8c0062c4>] syscall_call
== bottom
Kernel panic - not syncing: Aiee, killing interrupt handler!.. ==========================================
Is it right that, while in.ftpd tries to send TCP packet, scheduler_tick is called and requeue_task the "current" task?
Or, is threre any lack of code at returning to Linux.
Quoted 9 lines
Still the question remains for me why this should be a general Xenomai problem. Xenomai may overwrite the content on
switch_to(but I don't know your patch, how you realised context switches between RT tasks on SH4), but then it should definitely also restore it again on returning to Linux.Jan
Attached is some SH-related code.
xenomai-2.2.0/ksrc/arch/sh/*
xenomai-2.2.0/include/asm-sh/*
linux-2.6.17.7/arch/sh/kernel/*
linux-2.6.17.7/arch/sh/mm/*
linux-2.6.17.7/include/asm-sh/*
Thanks,
Kiichi Kameda
Quoted 18 lines · Kiichi Kameda
Thank you for your effort.
Quoted 8 lines
Quoted 7 lines · Jan Kiszka
Quoted 6 lines · Kiichi Kameda
...
After tough investigation, I think I found some clues such as:
While in.ftpd runs hard, a "write" system call was issued and Linux kernel was processing its request.
But weird__ipipe_dispatch_eventand__ipipe_sync_stagewas recorded.Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
I think the problem originates from a Xenomai context
switch(which overwrites "current"), while Linux is processing system call.If I interpret
linux/include/asm-sh/current.hcorrectly, current is derived from the stack on your platform (like on most archs) and cannotThat's nonsense as I realised later by following the code down to
include/asm-sh/thread_info.h:current_thread_infoseems to get referenced by some register.
Quoted 6 lines
In original SH-Linux ,"current" is based on
r7_bankregister in SH CPU
which is set only at context switch. "current" macro which is
referenced everywhere(including page fault handling and stack pointer setting
at interrupt from userspace), depends on this special register.r7_bankregister has nothing to do with stack.
Yep, that's what I understood as well meanwhile.
Quoted 6 lines
So, I created modified version of SH-Linux code , where "current" macro uses
the stackpointer(SP & ~(THREAD_SIZE) -1).
After that, although Linux seems to work well, the Xenomai thread still causes system panic, if I once run the Xenomai program that uses POSIX skin.
And that's something I do not understand. What was your idea behind this step?
Quoted 68 lines
The panic messsage:
==========================================Unable to handle kernel paging request. at virtual address 00100104 pc = 8c010658 <--requeue_task *pde = 00000000 Oops: 0001 [#1]Pid : 948, Comm: in.ftpd
PC :8c010658SP :8debfab0SR : 40008101 .TEA :c0198044.Not
tainted
R0 :8c19e958R1 :8c19ed10R2 : 00100100 R3 : 00200200 R4 :8c2769a0R5 :8c19e958R6 : 00000050 R7 :8c2769c0R8 :8c2769a0R9 : 00000000 R10 : 00000050 R11 :8c2769a0R12 :8c2769e0R13 :8c19e928R14 :8debfab0
MACH:0000027eMACL:b851edb4GBR :29568be0PR :8c0112b6.Call trace:== top
[<8c0112b6>]scheduler_tick
[<8c0d4d88>]smc_hard_start_xmit
[<8c00eb38>]__do_page_fault
[<8c01f828>]update_process_time
[<8c009988>]handle_timer_tick
[<8c00bd72>]tmu_timer_interrupt
[<8c03303a>]handle_IRQ_event
[<8c0330fa>]__do_IRQ
[<8c00d0f6>]__ipipe_do_IRQ
[<8c0342e4>]__ipipe_sync_stage
[<8c00d146>]__ipipe_grab_timer
[<8c010582>]dequeue_task
[<8c010876>]deactivate_task
[<8c1505d6>] schedule
[<8c15134c>]io_schedule
[<8c036406>]sync_page
[<8c151736>]__wait_on_bit_lock
[<8c036d90>]__lock_page
[<8c038050>]file_map_nopage
[<8c0444aa>]__handle_mm_fault
[<8c00e7f0>]do_page_fault
[<8c0af240>]csum_partial_copy_generic
[<8c125b64>]tcp_sendmsg
[<8c141c14>]inet_sendmsg
[<8c0f97f6>]do_sock_write
[<8c0f98ec>]sock_aio_write
[<8c01f74c>]run_timer_softirq
[<8c04e6ba>]do_sync_write
[<8c0343f6>]__ipipe_dispatch_event
[<8c04e78a>]vfs_write
[<8c04e8f4>]sys_write
[<8c0062c4>]syscall_call
== bottomKernel panic - not syncing: Aiee, killing interrupt handler!.. ==========================================Is it right that, while in.ftpd tries to send TCP packet,
scheduler_tickis called andrequeue_taskthe "current" task?Or, is threre any lack of code at returning to Linux.
Quoted 8 lines
Still the question remains for me why this should be a general Xenomai problem. Xenomai may overwrite the content on
switch_to(but I don't know your patch, how you realised context switches between RT tasks on SH4), but then it should definitely also restore it again on returning to Linux.Jan
Quoted 7 lines
Attached is some SH-related code.
xenomai-2.2.0/ksrc/arch/sh/*
xenomai-2.2.0/include/asm-sh/*
linux-2.6.17.7/arch/sh/kernel/*
linux-2.6.17.7/arch/sh/mm/*
linux-2.6.17.7/include/asm-sh/*
Hmm, not very handy for a review. Also the ipipe patch is missing. Please post future revisions as real patches (one for ipipe against the vanilla kernel, one for Xenomai against SVN, preferably trunk).
Anyway, poking into (probably) the heart of the problem I stumbled over this:
[ksrc/arch/sh/switch.c]
void rthal_switch_to(xnarchtcb_t *prev, xnarchtcb_t *next) {
...
/*
* Restore the kernel mode register
* k7 (r7_bank1)
*/
if(next->user_task) {
asm volatile("ldc %0, r5_bank"
: /* no output */
: "r" (next->user_task->thread_info));
}Is there a particular reason why comment and reality diverge regarding the thread_info register? Could this cause your troubles?
Jan
Quoted 11 lines
Quoted 6 lines
So, I created modified version of SH-Linux code , where "current" macro uses
the stackpointer(SP & ~(THREAD_SIZE) -1).
After that, although Linux seems to work well, the Xenomai thread still causes system panic, if I once run the Xenomai program that uses POSIXskin.
And that's something I do not understand. What was your idea behind this step?
Just a try , because I realized overwriting "current" may not be right way.
Quoted 12 lines
[
ksrc/arch/sh/switch.c]void
rthal_switch_to(xnarchtcb_t *prev, xnarchtcb_t *next){
...
/*
* Restore the kernel mode register
* k7 (r7_bank1)
*/
if(next->user_task){
Quoted 8 lines
asm volatile("ldc %0, r5_bank" : /* no output */ : "r" (next->user_task->thread_info));}
Is there a particular reason why comment and reality diverge regarding the
thread_inforegister? Could this cause your troubles?
I'm sorry, the comment is wrong.
The code that uses r7_bank results in overwriting "current". To avoid this, I changed from r7_bank to r5_bank for Xenomai context switch .
Also, I added to the Linux context switch code so that thread_info is set in r5_bank register as well as in r7_bank regsiter.r5_bank register is referenced in the page fault handling code.
Kiichi Kameda
Quoted 16 lines · Kiichi Kameda
Quoted 16 lines
[
ksrc/arch/sh/switch.c]void
rthal_switch_to(xnarchtcb_t *prev, xnarchtcb_t *next){
...
/*
* Restore the kernel mode register
* k7 (r7_bank1)
*/
if(next->user_task){asm volatile("ldc %0, r5_bank" : /* no output */ : "r" (next->user_task->thread_info));}
Quoted 6 lines
Quoted 3 lines
Is there a particular reason why comment and reality diverge regarding the
thread_inforegister? Could this cause your troubles?I'm sorry, the comment is wrong.
The code that usesr7_bankresults in overwriting "current".
What code is it?
Quoted 2 lines
To avoid this, I changed from
r7_banktor5_bankfor Xenomai context switch .
Wouldn't it be better to avoid that overwriting in the first place instead of escaping from it? You may not be safe from code running on behalf of a Xenomai user-space thread that assumes current is still in r7_bank.
Quoted 3 lines
Also, I added to the Linux context switch code so that
thread_infois set inr5_bankregister as well as inr7_bankregsiter.r5_bankregister is referenced in the page fault handling code.
The handling code of Xenomai or Linux?
The goal must be that the environment for a shadowed Xenomai thread looks (almost) like that of a normal Linux thread. If there is Xenomai code that messes this up on SH4, this has to be fixed. Patching Linux Linux outside the I-pipe context indicates that something is wrong with the design. This is what I can say from my distant POV without knowing the specific issues of SH4.
Jan
Quoted 18 lines
Quoted 16 lines · Kiichi Kameda
Quoted 16 lines
[
ksrc/arch/sh/switch.c]void
rthal_switch_to(xnarchtcb_t *prev, xnarchtcb_t *next){
...
/*
* Restore the kernel mode register
* k7 (r7_bank1)
*/
if(next->user_task){asm volatile("ldc %0, r5_bank" : /* no output */ : "r" (next->user_task->thread_info));}
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Is there a particular reason why comment and reality diverge regarding the
thread_inforegister? Could this cause your troubles?I'm sorry, the comment is wrong.
The code that usesr7_bankresults in overwriting "current".What code is it?
Above code(rthal_switch_to) is derived from Linux, which uses r7_bank. At first I used r7_bank in rthal_switch_to , but this code caused panic.
Quoted 10 lines
Quoted 3 lines
To avoid this, I changed from
r7_banktor5_bankfor Xenomai context switch .Wouldn't it be better to avoid that overwriting in the first place instead of escaping from it? You may not be safe from code running on behalf of a Xenomai user-space thread that assumes current is still in
r7_bank.Quoted 1 line
Also, I added to the Linux context switch code so that
thread_infois
set
Quoted 4 lines
Quoted 2 lines
in
r5_bankregister as well as inr7_bankregsiter.r5_bankregister is referenced in the page fault handling code.The handling code of Xenomai or Linux?
There exists only one page fault handling code for both Xenomai and Linux. Is this a problem?
Quoted 8 lines
The goal must be that the environment for a shadowed Xenomai thread looks (almost) like that of a normal Linux thread. If there is Xenomai code that messes this up on SH4, this has to be fixed. Patching Linux Linux outside the I-pipe context indicates that something is wrong with the design. This is what I can say from my distant POV without knowing the specific issues of SH4.
Yes I think so too.
Quoted 20 lines · Kiichi Kameda
Quoted 20 lines
Quoted 19 lines · Kiichi Kameda
Quoted 19 lines
[
ksrc/arch/sh/switch.c]void
rthal_switch_to(xnarchtcb_t *prev, xnarchtcb_t *next){
...
/*
* Restore the kernel mode register
* k7 (r7_bank1)
*/
if(next->user_task){asm volatile("ldc %0, r5_bank" : /* no output */ : "r" (next->user_task->thread_info));}
Is there a particular reason why comment and reality diverge regarding the
thread_inforegister? Could this cause your troubles?
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
I'm sorry, the comment is wrong.
The code that usesr7_bankresults in overwriting "current".What code is it?
Above
code(rthal_switch_to)is derived from Linux, which usesr7_bank. At first I usedr7_bankinrthal_switch_to, but this code caused panic.
Why? Rhetorical questions. The point is you need to understand the mechanisms preventing this to work because it looks to me like this is the way to go.
Was there anything else that denies invoking the original Linux __switch_to directly? That should be preferred if feasible.
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
To avoid this, I changed from
r7_banktor5_bankfor Xenomai context switch .Wouldn't it be better to avoid that overwriting in the first place instead of escaping from it? You may not be safe from code running on behalf of a Xenomai user-space thread that assumes current is still in
r7_bank.
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Also, I added to the Linux context switch code so that
thread_infoisset
Quoted 3 lines
Quoted 2 lines
in
r5_bankregister as well as inr7_bankregsiter.r5_bankregister is referenced in the page fault handling code.The handling code of Xenomai or Linux?
There exists only one page fault handling code for both Xenomai and Linux. Is this a problem?
Xenomai normally only has a hook here to suspend RT threads on faults and/or migrate them to Linux. I just didn't know if you had to develop something special for SH4.
Quoted 9 lines
Quoted 8 lines
The goal must be that the environment for a shadowed Xenomai thread looks (almost) like that of a normal Linux thread. If there is Xenomai code that messes this up on SH4, this has to be fixed. Patching Linux Linux outside the I-pipe context indicates that something is wrong with the design. This is what I can say from my distant POV without knowing the specific issues of SH4.
Quoted 4 lines
Yes I think so too.
Jan