Received: from sonic314-19.consmr.mail.ir2.yahoo.com (sonic314-19.consmr.mail.ir2.yahoo.com [77.238.177.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B26F04A9B2 for ; Fri, 1 Dec 2023 17:31:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=yahoo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yahoo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.b="N+spiv5t" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1701451887; bh=czU7XWAnvs5GB0TkXKuWNQZj8cTwrwjQSQCSl4EkTxI=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From:Subject:Reply-To; b=N+spiv5tK6+OmpQK+DyA9bIqupnGsDsl+5dhgjcaOIQEnl/iL5bFL30Q0zKjSps+me7/gf0OxGEFngamhtturzVw1GRprWWBQCW6F/HaYt9K+JLbxJy3gsByLneEMElWtEmUr7ocyVtsKS3D0iIL0/HuDncxT/cxQNRLBOiiWbCUpStUnw54kDTshnVhlIzDTzr9Hz5RFUx7WZEMqJrkkwA6u8iXxiNE+fyiW1GoKcLOaWr6uFiKmsqqXxMV9HTyY5kjlcMWQ9QeUxPgUf5HfU2J23yDqO/E3CrVOKeOVPBwdFPP12NhI9etMSF6G5KP2Z1DKNcadysJfyF3xGDMUQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1701451887; bh=znul+UKy0cLdBByEkeD8+LXSzraAX4dZy5Fc/h1MJ4l=; h=X-Sonic-MF:Date:Subject:To:From:From:Subject; b=OzS5Zg/6yRIH9UWda2wW2GFvIopbALUjE4s6EHr+wAK+2njAqxIfoVMWHCB69zAKiJo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AB6fiD158D5.yWhnljqYsZOf1Ma7TWeWPgL60KQfIErmQrfkIAnPjD381EklxdjOZe66fJv4kEG MMW2_SY5WhxR6yrHUlCf4dl5xEqNtjnoLRpcbn6_firNN0mY33lGTP_6ge8jLVp1h9P..dN8JxoC niGIu0NkBSw_b10PeiLpv1XEJqlUnV.ZJqLBOqQEkZ6T6zDSTfPVO8GfHxn9.d_QfU7tVutBV.oc QFshcIkEiA5hEAuVAc7iUUqlEYeQPdUgpounSd1QjUcFBBhpNhE3PmCx.VVSt5_Qm5vXVKqf3V1h iB20s1PQ69VFY4ixbLqa7fG2wbE03p3hrzOIYoaijNH2LU28JKlK7JhXIDzvjjpTBnHVK0TrOl5l .6P6t4gBnsj7TYg-- X-Sonic-MF: X-Sonic-ID: d470eda1-9729-4ad6-8576-2f917387fa58 Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.ir2.yahoo.com with HTTP; Fri, 1 Dec 2023 17:31:27 +0000 Received: by hermes--production-ir2-864cfb66d6-wjgq6 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID ece3f6ad2331b82a43326e9defd75670; Fri, 01 Dec 2023 17:31:23 +0000 (UTC) Message-ID: Date: Fri, 1 Dec 2023 18:31:22 +0100 Precedence: bulk X-Mailing-List: xenomai@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Process stuck in cobalt_monitor_enter To: "xenomai@lists.linux.dev" Cc: Jan Kiszka References: <9d5bb262-0646-451e-a5af-82c0473a3003.ref@yahoo.com> <9d5bb262-0646-451e-a5af-82c0473a3003@yahoo.com> <035a65bc-c064-40c2-9fcc-b3fd6104a233@siemens.com> <4572a391-4c06-4aa9-b92e-66e9da6c23ed@yahoo.com> <44ffbd9c-fc28-40fd-849f-a77fee15866b@siemens.com> <87e3bc23-4eba-43c4-bb5e-ffce9139c075@siemens.com> <67ce5b0a-1013-4ab2-9617-0723c0dc0809@siemens.com> Content-Language: en-US, it From: "Mauro S." In-Reply-To: <67ce5b0a-1013-4ab2-9617-0723c0dc0809@siemens.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Mailer: WebService/1.1.21896 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo On 01/12/23 02:31, Jan Kiszka wrote: > On 30.11.23 00:24, Mauro Salvini wrote: >> Il giorno mar 28 nov 2023 alle ore 09:39 Mauro Salvini >> ha scritto: >>> >>> Il giorno mar 28 nov 2023 alle ore 00:15 Jan Kiszka >>> ha scritto: >>>> >>>> On 27.11.23 22:02, Mauro Salvini wrote: >>>>> Il giorno mar 21 nov 2023 alle ore 01:06 Jan Kiszka >>>>> ha scritto: >>>>>> >>>>>> On 20.11.23 22:23, Mauro S. wrote: >>>>>>> On 13/11/23 18:54, Jan Kiszka wrote: >>>>>>>> On 11.11.23 16:03, Mauro S. wrote: >>>>>>>>> Hi all, >>>>>>>>> >>>>>>>>> I'm using Xenomai 3.2.3 on an Atom x84_64 with a 5.4.255 ipipe kernel. >>>>>>>>> >>>>>>>>> The application I'm running (a complex application, with about 60-70 RT >>>>>>>>> threads) has a simple loop in the main function, something like that: >>>>>>>>> >>>>>>>>> while (stay_in) { >>>>>>>>> ret = rt_buffer_read(...); // with 50ms timeout >>>>>>>>> if(ret) do_something >>>>>>>>> } >>>>>>>>> >>>>>>>>> The main loop reads the buffer to receive some commands from outside, >>>>>>>>> and when the application gets a SIGINT, the custom signal handler simply >>>>>>>>> does "stay_in = false" breaking the main loop, and then the program >>>>>>>>> closes. >>>>>>>>> During normal running, I can see the timer associated to the >>>>>>>>> rt_buffer_read() timeout get fired and reprogrammed, calling multiple >>>>>>>>> times "cat /proc/xenomai/timer/coreclk" e.g.: >>>>>>>>> >>>>>>>>> 0 291/290 2ms970us - myapp >>>>>>>>> ... >>>>>>>>> 0 609/608 34ms860us - myapp >>>>>>>>> >>>>>>>>> I also see the thread in "w" state (waiting for a resource with timeout) >>>>>>>>> doing "cat cat /proc/xenomai/sched/threads": >>>>>>>>> >>>>>>>>> 0 16328 rt cobalt 50 21ms279us w myapp >>>>>>>>> >>>>>>>>> Sometimes, in a non reproducible way (at least for the moment), when the >>>>>>>>> process get the SIGINT it never exits, remaining in this status: >>>>>>>>> >>>>>>>>> /proc/xenomai/sched/threads: >>>>>>>>> 0 16328 rt cobalt 50 - W flxcore >>>>>>>>> >>>>>>>>> The state becomed "W" (waiting for a resource without timeout) and in >>>>>>>>> fact the remaining timeout is not present in the row, also in >>>>>>>>> /proc/xenomai/timer/coreclk: >>>>>>>>> >>>>>>>>> 0 291609/291362 - - myapp >>>>>>>>> >>>>>>>>> (BTW, seems that some timeouts got lost, because scheds are many that >>>>>>>>> shots, and this happens also on other timers in coreclk) >>>>>>>>> >>>>>>>>> This is the backtrace in gdb: >>>>>>>>> >>>>>>>>> #0 0x00007f5b15bb05f7 in cobalt_monitor_enter () from >>>>>>>>> /usr/lib/libcobalt.so.2 >>>>>>>> >>>>>>>> This relates to lib/cobalt/internal.c, cobalt_monitor_wait(): >>>>>>>> >>>>>>>> /* >>>>>>>> * If we got interrupted while trying to re-enter the monitor, >>>>>>>> * we need to redo. In the meantime, any pending linux signal >>>>>>>> * has been processed. >>>>>>>> */ >>>>>>>> if (ret == -EINTR) >>>>>>>> ret = cobalt_monitor_enter(mon); >>>>>>>> >>>>>>>> But the problem is that the lock (monitor) is no free. Someone else >>>>>>>> holds it, and your interrupted reader does not proceed. >>>>>>>> >>>>>>>> If you dive into mon at this point via gdb, you may find the owner >>>>>>>> (according to libcobalt's view) when you resolve manually what >>>>>>>> get_monitor_state() does. >>>>>>>> >>>>>>>> Jan >>>>>>>> >>>>>>> >>>>>>> Thank you Jan. >>>>>>> >>>>>>> I rebuilt the Xenomai libraries with debugging symbols enabled. >>>>>>> But when I try to print the mon variable, I get >>>>>>> >>>>>>> (gdb) print mon >>>>>>> $1 = (cobalt_monitor_t *) 0x7f3cb524e62c >>>>>>> (gdb) print *mon >>>>>>> Cannot access memory at address 0x7f3cb524e62c >>>>>>> >>>>>>> Seems that the memory address is not in the core dump, but I'm wondering >>>>>>> why >>>>>> >>>>>> Did you create a core dump or tried to attach live the hung process? >>>>>> Maybe the former was incomplete - for whatever reason. >>>>>> >>>>>> Jan >>>>> >>>>> Sorry for the delay, but every time I modify something I need to wait >>>>> for the issue to arise. >>>>> >>>>> I'm working on core dumps. The previous core was incomplete, as you said. >>>>> I needed to set the coredump_filter kernel cmdline argument to 0x7f to >>>>> have the complete coredump. >>>>> >>>>> Now, I can see also the values into the Xenomai lib memory space: >>>>> >>>>> (gdb) print *mon >>>>> $8 = {state_offset = 1047984, flags = 1, handle = 44} >>>>> (gdb) print *(struct cobalt_monitor_state *)(cobalt_umm_shared + >>>>> mon->state_offset) >>>>> $9 = {owner = {v = -2147483638}, flags = 0} >>>> >>>> This is 0x8000000a, XNSYNCH_FLCLAIM | 10 (see also xnhandle_get_id), >>>> thus 10 is the owner. Unintended recursion? >>>> >>>> Jan >>> >>> Oh, yes, my bad: I have seen the xnhandle_get_id, but not considered >>> that atomic_t is treated as a 2-complement number. >>> Then, the owner is the caller ID. I'm wondering how it could be a >>> recursion: the main thread is a simple while(..) rt_buffer_read(..); >>> I will investigate a bit more on it. >>> >>> Thanks. >> >> Maybe I found something: in the backtrace of every core (cores are >> generated with SIGABRT) the first two frames are referring both to >> cobalt_monitor_enter(): frame #0 is at the source line where the >> program is stuck (syscall), frame #1 is at the cobalt_monitor_enter() >> function declaration source line: >> >> Program terminated with signal SIGABRT, Aborted. >> #0 cobalt_monitor_enter (mon=0x7f0d7583862c) >> at ../../../../../../../../../linux+xeno-src/xenomai-3.2-new/lib/cobalt/internal.c:218 >> [Current thread is 1 (Thread 0x7f0d7628c400 (LWP 2751))] >> #0 cobalt_monitor_enter (mon=0x7f0d7583862c) >> at ../../../../../../../../../linux+xeno-src/xenomai-3.2-new/lib/cobalt/internal.c:218 >> #1 cobalt_monitor_enter (mon=0x7f0d7583862c) >> at ../../../../../../../../../linux+xeno-src/xenomai-3.2-new/lib/cobalt/internal.c:186 >> #2 0x00007f0d76612748 in cobalt_monitor_wait >> (mon=mon@entry=0x7f0d7583862c, event=event@entry=0, >> ts=ts@entry=0x7ffe7d7380f0) >> at ../../../../../../../../../linux+xeno-src/xenomai-3.2-new/lib/cobalt/internal.c:276 >> #3 0x00007f0d76639497 in monitor_wait_grant (current=0x7f0d75842bc8, >> timeout=0x7ffe7d7380f0, sobj=0x7f0d758385f0) >> at ../../../../../../../../../linux+xeno-src/xenomai-3.2-new/lib/copperplate/syncobj.c:553 >> #4 syncobj_wait_grant (sobj=sobj@entry=0x7f0d758385f0, >> timeout=timeout@entry=0x7ffe7d7380f0, syns=syns@entry=0x7ffe7d738074) >> at ../../../../../../../../../linux+xeno-src/xenomai-3.2-new/lib/copperplate/syncobj.c:553 >> #5 0x00007f0d7664c691 in rt_buffer_read_timed (bf=, >> ptr=, size=, >> abs_timeout=0x7ffe7d7380f0) at >> ../../../../../../../../../linux+xeno-src/xenomai-3.2-new/lib/alchemy/buffer.c:555 >> #6 0x000055b104840601 in rt_buffer_read (timeout=50000000, >> size=19216, ptr=0x55b104844180 , >> bf=0x55b104844168 ) >> at /opt/sdk/3.1.22-2.0/sysroots/corei7-64-poky-linux/usr/include/xenomai/alchemy/buffer.h:129 >> #7 main (argc=, argv=) at main.c:410 >> >> Could that be a clue? > > That alone does not tell a story. We know now that - at least according > to the monitor data structure - thread with ID 10 is holding the lock. > If the very same thread is trying to re-aquire it, this will cause a > deadlock. And if that is true, we need to find out, how that could have > happened. I have no idea about that so far. > > Would you be able to factor out a simpler, sharable reproduction case? > > It also looks like as if the reader is receiving some signal while > blocking. Is that expected based on your workload? It may destroy timing > constraints, even without the deadlock. Yes, I think it is expected, the workflow is the following: - a daemon starts the program - upon an external request, the daemon terminates the program sending to it a SIGTERM. I think this is the signal received while blocking - when the SIGTERM is received (a sighandler is installed by the main thread), the main loop (where the rt_buffer_read() is) breaks, and the program performs some cleanups and then exits - in 95% cases, the program terminates well. In the remaining 5% cases the program hangs on rt_buffer_read() - if the daemon detects that the program is not terminated after 30 seconds from the SIGTERM sending, the daemon send a SIGABRT to generate the core we are analyzing I'm trying to reproduce the issue with simpler programs, but without success for the moment. I will update you (hope with better news). Thanks -- Mauro S.