From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27261 invoked by alias); 29 Oct 2003 17:04:12 -0000 Mailing-List: contact ecos-discuss-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@sources.redhat.com Received: (qmail 27253 invoked from network); 29 Oct 2003 17:04:10 -0000 Received: from unknown (HELO web21204.mail.yahoo.com) (216.136.131.77) by sources.redhat.com with SMTP; 29 Oct 2003 17:04:10 -0000 Message-ID: <20031029170409.44811.qmail@web21204.mail.yahoo.com> Received: from [65.83.223.20] by web21204.mail.yahoo.com via HTTP; Wed, 29 Oct 2003 09:04:09 PST Date: Wed, 29 Oct 2003 17:04:00 -0000 From: Dan Jakubiec To: Nick Garnett Cc: ecos-discuss@sources.redhat.com In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="0-1796770296-1067447049=:41882" Subject: Re: [ECOS] POSIX timer callback context X-SW-Source: 2003-10/txt/msg00493.txt.bz2 --0-1796770296-1067447049=:41882 Content-Type: text/plain; charset=us-ascii Content-Id: Content-Disposition: inline Content-length: 4103 Hi Nick, Okay, I see what you're saying. I had to dig into this a little more to realize that the eCos POSIX implementation really treats the whole system as one single process, with each task just being its own thread within that process. So in effect, signal handling is shared amoung all "tasks" in the system. However, it seems to me that timer signals would be more useful if an attempt was made to deliver them back to the thread that set the timer. Consider the scenario where you have N instances of the same task running in parallel, each wanting to be woken up by their own independent timers. POSIX has this to say about signal delivery: ---POSIX--- At the time of generation, a determination shall be made whether the signal has been generated for the process or for a specific thread within the process. Signals which are generated by some action attributable to a particular thread, such as a hardware fault, shall be generated for the thread that caused the signal to be generated. Signals that are generated in association with a process ID or process group ID or an asynchronous event, such as terminal activity, shall be generated for the process. ---POSIX--- It seems like an argument could be made that setting a timer is an "action attributable to a particular thread". Last night I enhanced the POSIX timer code to record the thread that called timer_settime() in the timer object. Then, when the timer goes off, it tries to deliver the signal to that thread first. The changes were fairly minor and they seemed to do what I want. So my question for you is: do you think this is a reasonable way to handle timer signal delivery? Do you see any problems with this? I've attached a diff of my (pending) changes for your reference if you're interested. Thanks, --- Dan Jakubiec Systech Corp --- Nick Garnett wrote: > Dan Jakubiec writes: > > > I'm using a POSIX timer in my application that I > > created with timer_create(). It is configured to > > generate a SIGUSR1 signal when the timer expires, > and > > to call a signal handler installed by my app's > thread. > > I also have several different tasks running that > were > > all created with pthread_create(). > > > > When the timer expires, the signal handler gets > > executed, but it appears to be executing in a > another > > thread's context (i.e. pthread_self() returns the > > handle for one of my other threads). Furthermore, > the > > thread that installed the handler is waiting in a > > pselect() call that never gets interrupted with > EINTR. > > > > This seems like a bug to me, but I wanted to pass > this > > by the group before fixing it to make sure I > wasn't > > missing anything. Seems like there is a bit of a > grey > > area in the POSIX docs about whether signals get > > delivered to the "process" or one of its > "threads". > > However, it seems that in eCos it would only make > > sense to deliver signals to the calling thread > itself. > > > > Does anyone have any background info on the eCos > > implementation of POSIX timers, or an opinion on > how > > POSIX timer callbacks should be processed? > > This is not a bug. The POSIX spec is fairly clear > that these are > process-wide signals that will be delivered to any > thread that has the > signal unmasked. There are lots of problems with > doing thread-specific > signals here that the POSIX committee decided to > avoid by > side-stepping the problem. > > If you want to direct the signal to a specific > thread then just make > sure that that thread is the only one with the > signal unmasked. The > best way to ensure this is to mask it in the signal > mask of main() > before creating any other threads, which will then > inherit main()'s > mask, and unmask it in the target thread. > > > -- > Nick Garnett eCos Kernel > Architect > http://www.ecoscentric.com The eCos and RedBoot > experts > __________________________________ Do you Yahoo!? Exclusive Video Premiere - Britney Spears http://launch.yahoo.com/promos/britneyspears/ --0-1796770296-1067447049=:41882 Content-Type: application/octet-stream; name="timer.pat" Content-Transfer-Encoding: base64 Content-Description: timer.pat Content-Disposition: attachment; filename="timer.pat" Content-length: 3307 SW5kZXg6IHBhY2thZ2VzL2NvbXBhdC9wb3NpeC9jdXJyZW50L3NyYy90aW1l LmN4eAo9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09ClJDUyBmaWxlOiAvY3ZzL2Vj b3MvZWNvcy9wYWNrYWdlcy9jb21wYXQvcG9zaXgvY3VycmVudC9zcmMvdGlt ZS5jeHgsdgpyZXRyaWV2aW5nIHJldmlzaW9uIDEuOQpkaWZmIC11IC1yMS45 IHRpbWUuY3h4Ci0tLSBwYWNrYWdlcy9jb21wYXQvcG9zaXgvY3VycmVudC9z cmMvdGltZS5jeHgJMzEgSmFuIDIwMDMgMTE6NTM6MTQgLTAwMDAJMS45Cisr KyBwYWNrYWdlcy9jb21wYXQvcG9zaXgvY3VycmVudC9zcmMvdGltZS5jeHgJ MjkgT2N0IDIwMDMgMTY6NTk6NDMgLTAwMDAKQEAgLTEwNSw2ICsxMDUsNyBA QAogICAgIGN5Z19ib29sICAgICAgICAgICAgcGVuZGluZzsgICAgICAgIC8v IGlzIGV4cGlyeSBwZW5kaW5nPwogICAgIGludCAgICAgICAgICAgICAgICAg b3ZlcnJ1bjsgICAgICAgIC8vIE92ZXJydW4gY291bnQKICAgICBzdHJ1Y3Qg c2lnZXZlbnQgICAgIHNpZ2V2OyAgICAgICAgICAvLyBTaWdldmVudCB0byBy YWlzZSBvbiBleHBpcnkKKyAgICBwdGhyZWFkX2luZm8gICAgICAgICpjYWxs ZXI7ICAgICAgICAvLyBUaHJlYWQgb2JqZWN0IHRoYXQgc2V0IHRoZSB0aW1l cgogICAgIAogICAgIC8vIFNwYWNlIGZvciBhbGFybSBvYmplY3QKICAgICBj eWdfdWludDggICAgICAgICAgIGFsYXJtX29ialtzaXplb2YoQ3lnX0FsYXJt KV07CkBAIC0yNzMsNyArMjc0LDIzIEBACiAgICAgICAgICAgICBzaWdlbXB0 eXNldCggJm1hc2sgKTsKICAgICAgICAgICAgIHNpZ2FkZHNldCggJm1hc2ss IHRpbWVyLT5zaWdldi5zaWdldl9zaWdubyApOwogICAgICAgICAgICAgY3ln X3Bvc2l4X3NpZ25hbF9zaWd3YWl0KCk7Ci0gICAgICAgICAgICBjeWdfcG9z aXhfcHRocmVhZF9yZWxlYXNlX3RocmVhZCggJm1hc2sgKTsKKworICAgICAg ICAgICAgLy8gV2FrZSB1cCBhIHRocmVhZCB0byBoYW5kbGUgdGhlIHNpZ25h bC4gIEdpdmUgcHJlZmVyZW5jZQorICAgICAgICAgICAgLy8gdG8gdGhlIHRo cmVhZCB0aGF0IGluaXRpYWxseSBzZXQgdGhlIHRpbWVyLgorICAgICAgICAg ICAgaWYgKCh0aW1lci0+Y2FsbGVyICE9IE5VTEwpICYmCisgICAgICAgICAg ICAgICAgKHRpbWVyLT5jYWxsZXItPnN0YXRlIDw9IFBUSFJFQURfU1RBVEVf UlVOTklORykgJiYKKyAgICAgICAgICAgICAgICAoKG1hc2sgJiB+dGltZXIt PmNhbGxlci0+c2lnbWFzaykgIT0gMCkpCisgICAgICAgICAgICB7CisgICAg ICAgICAgICAgICAgLy8gVGhlIG9yaWdpbmFsIGNhbGxlciBjYW4gc2Vydmlj ZSBhdCBsZWFzdCBvbmUgb2YKKyAgICAgICAgICAgICAgICAvLyB0aGUgcGVu ZGluZyBzaWduYWxzLiAgSW50ZXJydXB0IGl0cyBjdXJyZW50IHdhaXQKKyAg ICAgICAgICAgICAgICAvLyBhbmQgbWFrZSBpdHMgQVNSIHBlbmRpbmcuCisg ICAgICAgICAgICAgICAgdGltZXItPmNhbGxlci0+dGhyZWFkLT5zZXRfYXNy X3BlbmRpbmcoKTsKKyAgICAgICAgICAgICAgICB0aW1lci0+Y2FsbGVyLT50 aHJlYWQtPnJlbGVhc2UoKTsKKworICAgICAgICAgICAgfSBlbHNlIHsKKyAg ICAgICAgICAgICAgICAvLyBGaW5kIGFub3RoZXIgdGhyZWFkIHRoYXQgY2Fu IGhhbmRsZSB0aGUgc2lnbmFsKHMpLgorICAgICAgICAgICAgICAgIGN5Z19w b3NpeF9wdGhyZWFkX3JlbGVhc2VfdGhyZWFkKCAmbWFzayApOworICAgICAg ICAgICAgfQogICAgICAgICB9CiAgICAgICAgIGVsc2UgaWYoIHRpbWVyLT5z aWdldi5zaWdldl9ub3RpZnkgPT0gU0lHRVZfVEhSRUFEICkKICAgICAgICAg ewpAQCAtNDM5LDYgKzQ1Niw3IEBACiAKICAgICB0aW1lci0+YXJtZWQgICAg ICAgID0gZmFsc2U7CiAgICAgdGltZXItPm92ZXJydW4gICAgICA9IDA7Cisg ICAgdGltZXItPmNhbGxlciAgICAgICA9IE5VTEw7CiAKICAgICAqdGltZXJf aWQgPSB0aW1lci0+aWQ7CiAgICAgCkBAIC01MzUsNiArNTUzLDkgQEAKICAg ICAgICAgICAgIC8vIElmIHRoZSBBQlNUSU1FIGZsYWcgaXMgbm90IHNldCwg YWRkIHRoZSBjdXJyZW50IHRpbWUKICAgICAgICAgICAgIGlmKCAoZmxhZ3Mg JiBUSU1FUl9BQlNUSU1FKSA9PSAwICkKICAgICAgICAgICAgICAgICB0cmln Z2VyICs9IEN5Z19DbG9jazo6cmVhbF90aW1lX2Nsb2NrLT5jdXJyZW50X3Zh bHVlKCk7CisKKyAgICAgICAgICAgIC8vIFJlY29yZCB0aGUgcHJlZmVycmVk IHRocmVhZCBjb250ZXh0IGZvciBzaWduYWwgZGVsaXZlcnkKKyAgICAgICAg ICAgIHRpbWVyLT5jYWxsZXIgPSBwdGhyZWFkX3NlbGZfaW5mbygpOwogCiAg ICAgICAgICAgICAvLyBTZXQgdGhlIGFsYXJtIHJ1bm5pbmcuCiAgICAgICAg ICAgICB0aW1lci0+YWxhcm0tPmluaXRpYWxpemUoIHRyaWdnZXIsIGludGVy dmFsICk7Cg== --0-1796770296-1067447049=:41882 Content-Type: text/plain; charset=us-ascii Content-length: 146 -- Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos and search the list archive: http://sources.redhat.com/ml/ecos-discuss --0-1796770296-1067447049=:41882--