From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: philippe.gerum@domain.hid
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] mlockall questions
Date: Fri, 11 Apr 2008 01:25:02 +0200 [thread overview]
Message-ID: <18430.41422.826992.954071@domain.hid> (raw)
In-Reply-To: <47FE993B.1020801@domain.hid>
Philippe Gerum wrote:
> Gilles Chanteperdrix wrote:
> > On Thu, Apr 10, 2008 at 4:36 PM, Philippe Gerum
> > <philippe.gerum@domain.hid> wrote:
> >> Gilles Chanteperdrix wrote:
> >> > On Thu, Apr 10, 2008 at 2:53 AM, Philippe Gerum
> >> > <philippe.gerum@domain.hid> wrote:
> >> >> Robert McCullough wrote:
> >> >> > Hi Gilles,
> >> >> >
> >> >> > --> -----Original Message-----
> >> >> > --> From: Gilles Chanteperdrix [mailto:gilles.chanteperdrix@xenomai.org]
> >> >> > --> Sent: Wednesday, April 09, 2008 3:29 PM
> >> >> > --> To: rob@domain.hid
> >> >> > --> Cc: xenomai@xenomai.org
> >> >> > --> Subject: Re: [Xenomai-help] mlockall questions
> >> >> > -->
> >> >> > --> Robert McCullough wrote:
> >> >> > --> > Hi,
> >> >> > --> >
> >> >> > --> > I am converting part of a C++ application to real-time.
> >> >> > --> >
> >> >> > --> > I noticed that all the Xenomai examples call
> >> >> > --> > mlockall(MCL_CURRENT|MCL_FUTURE) at the beginning of main before
> >> >> > --> creating
> >> >> > --> > any real-time threads.
> >> >> > --> > Is calling mlockall a requirement when using Xenomai?
> >> >> > -->
> >> >> > --> Yes it is.
> >> >> > -->
> >> >> > [Robert McCullough]
> >> >> > OK.
> >> >> > --> >
> >> >> > --> > I have added a couple of Xenomai tasks to my C++ app.
> >> >> > --> > A) Without calling mlockall my application seems to run fine but I
> >> >> > --> noticed
> >> >> > --> > in /proc/xenomai/stat that a few page faults occurred.
> >> >> > -->
> >> >> > --> Well normally your application should stop with a message telling you
> >> >> > --> that you have not call mlockall. Do you happen to install a handler
> >> >> > --> for
> >> >> > --> SIGXCPU ?
> >> >> > [Robert McCullough]
> >> >> > Yes.
> >> >> > -->
> >> >> > --> > B) When calling mlockall at the beginning of my main() I do not see
> >> >> > --> any page
> >> >> > --> > faults but some of the C++ threads do not start.
> >> >> > --> >
> >> >> > --> > Why would mlockall cause some threads not to start?
> >> >> > -->
> >> >> > --> Well, you should check rt_task_create or pthread_create return
> >> >> > --> value. The usual error is that you run out of memory because of the
> >> >> > --> stack size problem explained in the TROUBLESHOOTING guide.
> >> >> > -->
> >> >> > --> --
> >> >> > -->
> >> >> > -->
> >> >> > --> Gilles.
> >> >> > [Robert McCullough]
> >> >> > Thanks.
> >> >> > Calling "ulimit -s 2048" before my application in my startup script seems to
> >> >> > work fine when I am running over nfs to the Denx ELDK with a bash shell.
> >> >> > But my application needs to run from a CompactFlash card running BusyBox on
> >> >> > a MPC5200 and BusyBox does not seem to support the "ulimit" command.
> >> >> > Is there another way to set this stack limit size?
> >> >> >
> >> >>
> >> >> - Setting the stack size property into the attribute struct for each new pthread
> >> >> your application may create: pthread_attr_setstacksize(&thattr, stacksize);
> >> >>
> >> >> - Or passing the right stack size value to any (non-POSIX) Xenomai API task
> >> >> creation service, we do enforce it (e.g. rt_task_create(), taskInit(),
> >> >> t_create()...).
> >> >>
> >> >> - Or calling setrlimit(RLIMIT_STACK, ...) to set a global default value for all
> >> >> subsequent glibc-originated threads. This is what the ulimit command does, actually.
> >> >
> >> > The problem of pthread_attr_setstacksize (or of setting stack size in
> >> > one of the various thread creation services) is that it does not work
> >> > for the main thread stack. So, you have to use ulimit or to call
> >> > setrlimit before running your application, in order to set the main
> >> > thread stack size.
> >> >
> >> > Now about the ulimit builtin in busybox: busybox ash shell supports ulimit.
> >> >
> >>
> >> Even if you don't have any shell supporting ulimit, you just need to create a
> >> small launcher that basically forks/setrlimit+execs your application.
> >
> > Errr... but you need to call setrlimit before fork, otherwise it is too late...
> >
>
> #include <sys/resource.h>
> #include <stdio.h>
> #include <unistd.h>
> #include <stdlib.h>
>
> int main(int argc, char *argv[])
> {
> if (strcmp(argv[0], "child")) {
> struct rlimit r = { .rlim_cur = 32768, .rlim_max = 32768 };
> setrlimit(RLIMIT_STACK, &r);
> execl(argv[0], "child", NULL);
> } else {
> struct rlimit r;
> if (getrlimit(RLIMIT_STACK, &r) == 0)
> printf("%s: stack size = %d\n", argv[0], r.rlim_cur);
> }
>
> return 0;
> }
I had a doubt about what I wrote, just after writing it, which is why I
started doing my own testing. But I got distracted by the fact that all
the main thread stack was no longer commited. Now, I wonder, do you
think we should try to work around this behaviour in the I-pipe patch ?
--
Gilles.
next prev parent reply other threads:[~2008-04-10 23:25 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-09 19:13 [Xenomai-help] mlockall questions Robert McCullough
2008-04-09 19:29 ` Gilles Chanteperdrix
2008-04-09 21:36 ` Robert McCullough
2008-04-10 0:53 ` Philippe Gerum
2008-04-10 9:25 ` Gilles Chanteperdrix
2008-04-10 14:36 ` Philippe Gerum
2008-04-10 15:43 ` Gilles Chanteperdrix
2008-04-10 17:26 ` Gilles Chanteperdrix
2008-04-10 17:52 ` jeff koftinoff
2008-04-10 18:03 ` Gilles Chanteperdrix
2008-04-10 18:16 ` Gilles Chanteperdrix
2008-04-10 22:48 ` Philippe Gerum
2008-04-10 22:54 ` Philippe Gerum
2008-04-10 23:25 ` Gilles Chanteperdrix [this message]
2008-04-10 23:31 ` Philippe Gerum
2008-04-14 19:51 ` Robert McCullough
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=18430.41422.826992.954071@domain.hid \
--to=gilles.chanteperdrix@xenomai.org \
--cc=philippe.gerum@domain.hid \
--cc=xenomai@xenomai.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.