All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe Gerum <rpm@xenomai.org>
To: Bryan Butler <Bryan.Butler@kratosdefense.com>
Cc: Russell Johnson <russell.johnson@kratosdefense.com>,
	"xenomai@lists.linux.dev" <xenomai@lists.linux.dev>
Subject: Re: [External] - Re: System hanging when using condition variables
Date: Wed, 28 Sep 2022 12:06:18 +0200	[thread overview]
Message-ID: <87czbf7pp5.fsf@xenomai.org> (raw)
In-Reply-To: <BN2P110MB1288DADB384231E5FB72D8EC8F549@BN2P110MB1288.NAMP110.PROD.OUTLOOK.COM>


Bryan Butler <Bryan.Butler@kratosdefense.com> writes:

> [[S/MIME Signed Part:Undecided]]
> Philippe, 
>
> I have observed a couple of odd things, and wanted to see if these were
> intentional or not:
>
> 1. According to the documentation on evl_attach_thread(), the CPU affinity
> is locked to a the single CPU on which the thread is running at the time.
> Although one can call sched_setaffinity(), at the cost of a one-time in-band
> switch, it doesn't appear that this actually changes the affinity settings.
> It appears the thread will continue to run on the single CPU it was running
> on when it was attached to the EVL scheduler. Is this the intended effect? 
>

No, it's definitely not. Several tests from the test suite actually
depend on being able to migrate to another CPU (e.g. ring-spray,
sched-quota-accuracy etc.). These tests would not work otherwise. How do
you check the current affinity for these threads, e.g. does evl-ps
confirm this issue?

> 2. Through experimentation, it doesn't appear that I can start multiple
> threads which are identical copies of each other. Specifically, it appears
> that if I start multiple threads with an identical entry point, that only
> the last thread actually remains active, at least within the EVL scheduler
> (as reported by "evl ps -l"). If, however, I start each thread with a unique
> entry point, then I can see multiple threads starting up (although this is
> one of the scenarios that is still crashing on us).

In this particular case, I think the app may be doing something
wrong. The entry point of a thread is actually unknown from the EVL
core, this is all dealt with from userland by the *libc. All thread
information maintained by libevl is living in TLS data. Maybe something
in the application is unexpectedly sharing some global data between
those threads, leading to the most recently bootstrapped one to override
all others?

>
> The reason I ask these questions is that we have a thread pool of a variable
> number of identical "worker" threads, any of which can take a task and
> operate on them. I would like to have the pool of worker threads share a
> pool of CPUs, and let the scheduler decide how to allocate them.

The EVL core will always pin every thread to the CPU it emerges on, then
the app may move it to another CPU using sched_setaffinity() in order to
apply some spatial allocation scheme. Bottom line is that we only deal
with user-defined, static allocation of CPUs to threads, the EVL core
does no dynamic load balancing by design because this would be
inefficient wrt the ultra-low latency requirement we have.

> I can work
> around this issue if necessary, but it may constrain the amount of
> parallelism we can achieve. I can work around the second issue as well, but
> it will make for some kind of ugly code.
>

I've been using the worker pool pattern here in many occasions with EVL
threads, the core does affect this unless the placement issued from the
user side is wrong. IOW, you pick a CPU placement for every worker, the
core abides by your choice and always schedules it out-of-band on that
CPU, it never decides for the app which CPU should a thread run on.

As you referred to earlier, picking the initial CPU placement can be
done in two ways:

- inheriting the current CPU placement of the parent thread at the time
  of the call to pthread_create().

- calling sched_setaffinity() any time for the child thread (either from
  its context, or from another thread using a valid, non-zero pid
  argument).

Each time sched_setaffinity() is called in-band for an EVL thread, the
core notices and applies the change to its own out-of-band scheduling
plan.

-- 
Philippe.

  reply	other threads:[~2022-09-28 10:34 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-19 21:38 System hanging when using condition variables Russell Johnson
2022-09-20  6:55 ` Philippe Gerum
2022-09-20 14:31   ` [External] - " Russell Johnson
2022-09-21 14:53   ` Russell Johnson
2022-09-22 14:26 ` Philippe Gerum
2022-09-22 15:25   ` [External] - " Bryan Butler
2022-09-23 19:56   ` Bryan Butler
2022-09-24  8:21     ` Philippe Gerum
2022-09-25 14:59       ` Philippe Gerum
2022-09-25 16:32         ` Philippe Gerum
2022-09-26 14:20           ` Bryan Butler
2022-09-27 22:05             ` Russell Johnson
2022-09-27 23:04             ` Russell Johnson
2022-09-28  1:08               ` Bryan Butler
2022-09-28 10:06                 ` Philippe Gerum [this message]
2022-09-28 10:37                   ` Philippe Gerum
2022-09-28  9:59               ` Philippe Gerum
2022-09-28 18:35                 ` Russell Johnson
2022-09-29  7:04                   ` Philippe Gerum
2022-09-29 18:32                     ` Russell Johnson
2022-10-01  4:38                     ` Russell Johnson
2022-10-04 15:50                       ` Philippe Gerum
2022-10-10 17:04                         ` Russell Johnson
2022-10-12 16:11                         ` Russell Johnson
2022-10-12 16:24                           ` Eric Kuzara
2022-11-03 18:13                             ` Philippe Gerum

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=87czbf7pp5.fsf@xenomai.org \
    --to=rpm@xenomai.org \
    --cc=Bryan.Butler@kratosdefense.com \
    --cc=russell.johnson@kratosdefense.com \
    --cc=xenomai@lists.linux.dev \
    /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.