Re: 答复: rwl manipulation fails when

Paolo Mantegazza <[email protected]> Fri, 2 Dec 2016 09:59:41 +0100
Newsgroups gmane.linux.real-time.rtai
Message-ID <[email protected]>
Buddy threads do no exists any more in RTAI. That was the way at the 
very beginnig of LXRT, i.e. more than 20 years ago.
The actual mechanism is suspending the LINUX task (be it a process, 
thread, kernel thread), making it TASK_UNINTERRPTIBLE and have it 
scheduled behind the curtain by the RTAI scheduler, using the very same, 
patched, context switch of Linux.
Rt_task_init serves the only purpose of making a Linux task capable of 
using borh its and RTAI function, while being sceduled by LINUX. It is 
rt_make_hard_real_time that does switch to the RTAI scheduler, so making 
a task rhard real time.
If you do "cat/proc/rtai/scheduler", "cat/proc/rtai/names" you'll see 
there is no buddy.

Paolo

On 12/02/2016 05:04 AM, Shahbaz Youssefi wrote:
> First, read this: 
> https://www.rtai.org/userfiles/documentation/magma/html/api/whatis_lxrt.html
>
> For each real-time thread in user-space, RTAI creates a "buddy" thread 
> in kernel space (that's what rt_task_init_schmod does). It's the buddy 
> thread that does the actual locking and unlocking of the RWL, and 
> that's why your thread needs to have done rt_task_init_schmod before. 
> Without it, the buddy thread doesn't exist and hence the kernel oops: 
> "BUG: unable to handle kernel NULL pointer dereference". When you 
> allocate an RWL, you are just allocating stuff, and you don't need a 
> special kernel-space thread (your buddy) to do it on your behalf; it's 
> a non real-time task.
>
> The buddy system is not ideal, and it sure does make things 
> complicated (some things can only be done in a real-time thread, 
> something can only be done in non real-time threads etc). However, it 
> does give you some interesting options, for example you can share an 
> RWL between user-space and kernel-space!
>
> If you understand the buddy thread, things become a lot clearer!
>
> On Thu, Dec 1, 2016 at 8:24 PM, Yamato Kira <[email protected] 
> <mailto:[email protected]>> wrote:
>
>     Dear Shahbaz:
>
>             How wise you are!  The RWL can be locked and unlocked now~
>
>     However, I found that I can init a semaphore before
>     rt_task_init_schmod and signal/wait the semaphore successfully
>     after rt_task_init_schmod and rt_make_hard_real_time. Is that
>     unsafe too?
>
>             What's more important , would you tell me how to fix the
>     reason that cause the problem?
>
>
>     3Q~
>
>
>
>     yours: C.P.
>
>     2016-12-02
>
>
>     发送自 Outlook <http://aka.ms/weboutlook>
>
>
>
>     ------------------------------------------------------------------------
>     *发件人:* Shahbaz Youssefi <[email protected]
>     <mailto:[email protected]>>
>     *发送时间:* 2016年12月1日 23:38
>     *收件人:* Yamato Kira
>     *抄送:* rt ai
>     *主题:* Re: [Rtai] rwl manipulation fails when
>     Is your thread a realtime thread? You can't use the lock unless
>     your thread is realtime (not necessarily hard realtime). You would
>     rt_task_init* functions are your friends.
>
>     On Thu, Dec 1, 2016 at 3:29 AM, Yamato Kira <[email protected]
>     <mailto:[email protected]>> wrote:
>
>         Hi, everyone
>
>
>         I am trying to use the RWL to achieve a synchronization of
>         data processing on LinuxCNC which has an RTAI core of 3.9.
>
>
>         The RWL I used can be initialized correctly in a thread, but
>         it caused a kernel error when I try to lock it or unlock it.
>         Have you ever meet this problem before? Or can you help me to
>         fix it? 3Q~
>
>
>         The RWL codes I used read as:
>
>
>         **************************************************
>
>         RWL * rt_RWL_01;
>
>         ......
>
>         rt_RWL_01 = rt_rwl_init(nam2num("RWL1"));
>             if(0==rt_RWL_01){
>                 printf("RWL Init Fails %d\n",rt_RWL_01);
>             }else{
>                 printf("RWL Init Succeeds %d\n",rt_RWL_01);
>             }
>         ......
>         while(1){
>         ......
>         printf("Before RWL\n");
>          rt_rwl_wrlock(rt_RWL_01);
>          //rt_rwl_unlock(rt_RWL_01);
>                 printf("After RWL\n");
>         }
>         **************************************************
>
>         and the dmesg command gives:
>
>         kern  :alert : [ 2855.372788] BUG: unable to handle kernel
>         NULL pointer dereference at 0000007c
>         kern  :alert : [ 2855.372793] IP: [<f86f2760>]
>         rt_rwl_wrlock+0x30/0x200 [rtai_sched]
>         kern  :warn  : [ 2855.372798] *pde = 00000000
>         kern  :warn  : [ 2855.372801] Oops: 0000 [#2] PREEMPT SMP
>         kern  :warn  : [ 2855.372804] Modules linked in: rtai_sched(O)
>         rtai_hal(O) parport_pc ppdev lp parport rfcomm bnep uinput
>         nfsd nfs nfs_acl auth_rpcgss fscache lockd sunrpc loop
>         snd_hda_codec_realtek btusb bluetooth uvcvideo snd_hda_intel
>         snd_hda_codec videobuf2_vmalloc videobuf2_memops
>         videobuf2_core videodev media ideapad_laptop i2c_core
>         sparse_keymap snd_hwdep snd_pcm coretemp rfkill snd_page_alloc
>         evdev serio_raw snd_seq snd_seq_device snd_timer snd
>         crc32c_intel aesni_intel aes_i586 aes_generic battery ac
>         cryptd power_supply wmi soundcore video button ext4 crc16 jbd2
>         mbcache usbhid hid sg sd_mod crc_t10dif microcode xhci_hcd
>         ahci libahci r8169 mii libata scsi_mod ehci_hcd fan
>         thermal_sys usbcore usb_common [last unloaded: psmouse]
>         kern  :warn  : [ 2855.372859]
>         kern  :warn  : [ 2855.372862] Pid: 4345, comm: RTAI1 Tainted:
>         G      D    O 3.4-9-rtai-686-pae #1 LENOVO 80HR/ZHAOYANG E40-80
>         kern  :warn  : [ 2855.372866] EIP: 0060:[<f86f2760>] EFLAGS:
>         00213002 CPU: 1
>         kern  :warn  : [ 2855.372870] EIP is at
>         rt_rwl_wrlock+0x30/0x200 [rtai_sched]
>         kern  :warn  : [ 2855.372872] EAX: 00000200 EBX: 00000000 ECX:
>         f8702c00 EDX: 00000000
>         kern  :warn  : [ 2855.372874] ESI: 00000030 EDI: 00000201 EBP:
>         f2b19f70 ESP: f2b19ee4
>         kern  :warn  : [ 2855.372876]  DS: 007b ES: 007b FS: 00d8 GS:
>         00e0 SS: 0068
>         kern  :warn  : [ 2855.372877] CR0: 80050033 CR2: 0000007c CR3:
>         36a9f000 CR4: 001407d0
>         kern  :warn  : [ 2855.372879] DR0: 00000000 DR1: 00000000 DR2:
>         00000000 DR3: 00000000
>         kern  :warn  : [ 2855.372881] DR6: fffe0ff0 DR7: 00000400
>         kern  :emerg : [ 2855.372883] Process RTAI1 (pid: 4345,
>         ti=f2b18000 task=f2b4ad80 task.ti=f2b18000)
>         kern  :emerg : [ 2855.372885] I-pipe domain Linux
>         kern  :emerg : [ 2855.372886] Stack:
>         kern  :warn  : [ 2855.372887]  f77c8e00 d17a140a 00000298
>         1dcd6500 f8766220 f86f2730 b74ea324 f86e4375
>         kern  :warn  : [ 2855.372894]  00000000 b76514e0 00000000
>         f8766220 003d0f00 b74ea388 08049ab9 00000000
>         kern  :warn  : [ 2855.372901]  00000001 c1053a4d f77c8e00
>         f77c8e00 f77c8e00 f2b4ad80 f2b4af40 00000001
>         kern  :emerg : [ 2855.372908] Call Trace:
>         kern  :warn  : [ 2855.372913] [<f86f2730>] ?
>         rt_rwl_rdlock+0x210/0x210 [rtai_sched]
>         kern  :warn  : [ 2855.372917] [<f86e4375>] ?
>         handle_lxrt_request+0xa5/0xaf0 [rtai_sched]
>         kern  :warn  : [ 2855.372922] [<c1053a4d>] ?
>         pick_next_task_fair+0x4d/0x110
>         kern  :warn  : [ 2855.372925] [<c1362a62>] ?
>         __schedule+0x132/0x400
>         kern  :warn  : [ 2855.372930] [<f86e4e18>] ?
>         rtai_lxrt_invoke+0x58/0x180 [rtai_sched]
>         kern  :warn  : [ 2855.372934] [<f86e3945>] ?
>         lxrt_intercept_syscall+0x75/0x100 [rtai_sched]
>         kern  :warn  : [ 2855.372938] [<c10e851b>] ? sys_write+0x5b/0x70
>         kern  :warn  : [ 2855.372941] [<c10979ec>] ?
>         __ipipe_notify_kevent+0xc/0x10
>         kern  :warn  : [ 2855.372944] [<c101af46>] ?
>         __ipipe_syscall_root+0x36/0xd0
>         kern  :warn  : [ 2855.372947] [<c1368bff>] ?
>         sysenter_past_esp+0x5c/0x73
>         kern  :emerg : [ 2855.372948] Code: 10 8b 5c 24 20 9c 58 fa 25
>         00 02 00 00 64 8b 15 10 e7 4f c1 f0 0f ab 15 90 d1 72 f8 19 d2
>         85 d2 0f 84 ed 00 00 00 89 c7 8d 73 30 <8b> 43 7c 85 c0 0f 84
>         85 00 00 00 89 34 24 e8 4d e9 ff ff 3d 00
>         kern  :emerg : [ 2855.372991] EIP: [<f86f2760>]
>         rt_rwl_wrlock+0x30/0x200 [rtai_sched] SS:ESP 0068:f2b19ee4
>         kern  :warn  : [ 2855.372996] CR2: 000000000000007c
>         kern  :warn  : [ 2855.372999] ---[ end trace 61a57933bf2bc264 ]---
>         kern  :err : [ 2855.373002] BUG: Unhandled exception over
>         domain RTAI at 0xf86f2760 - switching to ROOT
>         kern  :warn  : [ 2855.373004] Pid: 4345, comm: RTAI1 Tainted:
>         G      D    O 3.4-9-rtai-686-pae #1
>         kern  :warn  : [ 2855.373005] Call Trace:
>         kern  :warn  : [ 2855.373007] [<c101adb0>] ?
>         __ipipe_handle_exception+0x220/0x230
>         kern  :warn  : [ 2855.373009] [<f86f2760>] ?
>         rt_rwl_wrlock+0x30/0x200 [rtai_sched]
>         kern  :warn  : [ 2855.373011] [<c13647f0>] ? error_code+0x6c/0x7c
>         kern  :warn  : [ 2855.373013] [<c104007b>] ?
>         __alloc_workqueue_key+0x36b/0x3e0
>         kern  :warn  : [ 2855.373014] [<f86f2760>] ?
>         rt_rwl_wrlock+0x30/0x200 [rtai_sched]
>         kern  :warn  : [ 2855.373016] [<f86f2730>] ?
>         rt_rwl_rdlock+0x210/0x210 [rtai_sched]
>         kern  :warn  : [ 2855.373018] [<f86e4375>] ?
>         handle_lxrt_request+0xa5/0xaf0 [rtai_sched]
>         kern  :warn  : [ 2855.373020] [<c1053a4d>] ?
>         pick_next_task_fair+0x4d/0x110
>         kern  :warn  : [ 2855.373022] [<c1362a62>] ?
>         __schedule+0x132/0x400
>         kern  :warn  : [ 2855.373024] [<f86e4e18>] ?
>         rtai_lxrt_invoke+0x58/0x180 [rtai_sched]
>         kern  :warn  : [ 2855.373026] [<f86e3945>] ?
>         lxrt_intercept_syscall+0x75/0x100 [rtai_sched]
>         kern  :warn  : [ 2855.373028] [<c10e851b>] ? sys_write+0x5b/0x70
>         kern  :warn  : [ 2855.373030] [<c10979ec>] ?
>         __ipipe_notify_kevent+0xc/0x10
>         kern  :warn  : [ 2855.373032] [<c101af46>] ?
>         __ipipe_syscall_root+0x36/0xd0
>         kern  :warn  : [ 2855.373033] [<c1368bff>] ?
>         sysenter_past_esp+0x5c/0x73
>         kern  :info  : [ 2855.373036] note: RTAI1[4345] exited with
>         preempt_count 2
>         kern  :warn  : [ 2855.373097] LXRT releases PID 4345 (ID: RTAI1).
>         kern  :warn  : [ 3065.563237] LXRT releases PID 4346 (ID: RTAI1).
>         kern  :warn  : [ 3065.572713] LXRT releases PID 4344 (ID: RTAI1).
>
>         **************************************************
>
>
>         _______________________________________________
>         Rtai mailing list
>         [email protected] <mailto:[email protected]>
>         https://mail.rtai.org/cgi-bin/mailman/listinfo/rtai
>         <https://mail.rtai.org/cgi-bin/mailman/listinfo/rtai>
>
>
>
>
>
> _______________________________________________
> Rtai mailing list
> [email protected]
> https://mail.rtai.org/cgi-bin/mailman/listinfo/rtai

_______________________________________________
Rtai mailing list
[email protected]
https://mail.rtai.org/cgi-bin/mailman/listinfo/rtai