qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@web.de>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH] fix gdbstub support for multiple threads in usermode
Date: Wed, 20 May 2009 08:39:12 +0200	[thread overview]
Message-ID: <4A13A590.8040301@web.de> (raw)
In-Reply-To: <20090519180110.GE23911@codesourcery.com>

[-- Attachment #1: Type: text/plain, Size: 2688 bytes --]

Nathan Froyd wrote:
> On Tue, May 19, 2009 at 06:53:44PM +0200, Jan Kiszka wrote:
>> Nathan Froyd wrote:
>>> The best way I can think of to do this is to maintain a
>>> separately-chained list of CPUStates (through a new field similar to
>>> next_cpu) ordered by gdbstub_index.  Grabbing a new gdbstub_index then
>>> walks through the list, looking for "holes" between adjacent entries in
>>> the list.  A new gdbstub_index is then picked if we find a hole; we die
>>> if we can't find a hole.
>> Why creating a new list? Just generate a new index and then walk through
>> all so far registered CPUStates until no collision is found.
> 
> Do you mean something like:
> 
>   new_index = 0
>  restart:
>   for cpu in all_cpus:
>     if new_index == cpu.gdbstub_index
>       new_index += 1
>       goto restart;
>   new_cpu.gdbstub_index = new_index
> 
> I was trying to keep it a linear-time algorithm, and the above is
> potentially quadratic.  (Not merely an academic exercise, either;
> spinning up your first N threads will be enough to trigger quadratic
> behavior.)  I don't think you can say:
> 
>   new_index = 0
>   for cpu in all_cpus:
>     if new_index == cpu.gdbstub_index
>       new_index = cpu.gdbstub_index + 1
>   new_cpu.gdbstub_index = new_index
> 
> (i.e. maximum+1 of all existing cpus) either, since that fails for a
> list that looks like:
> 
>   1 -> 0
> 
> You could iterate, of course, but then you're just back to quadratic
> behavior.
> 
> Nothing promises that the cpu list will be kept in sorted order
> according to some criteria.  (A quick examination of things indicates
> the list might be accidentally sorted by time of creation--and thereby
> by gdbstub_index--but that falls apart once you wrap gdbstub_index, of
> course.)  AFAICS, you need the cpus sorted by their gdbstub_index to
> keep linear time bounds.  If using a quadratic algorithm is OK, then
> I'll just do that, but that doesn't seem like a good idea, especially
> since you're imposing a large slowdown on everything for debugging
> support which might never get used.

I see. So we basically have two options:

1. Stick head in sand - we will never see so many threads in reality, so
   neither wrap-around nor performance matters.

2. Go for a bitmap-based search of the next free ID (reducing the ID
   space so that the bitmap has a reasonable size)

But I have no clue if and how long option 1 will suffice as I have no
idea how many long-running highly dynamic multi-threaded use cases there
are or will be for qemu user mode. But if you find option 2 easy enough
to implement, I would do this nevertheless.

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 257 bytes --]

  reply	other threads:[~2009-05-20  8:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-12 19:35 [Qemu-devel] [PATCH] fix gdbstub support for multiple threads in usermode Nathan Froyd
2009-05-12 20:53 ` [Qemu-devel] " Jan Kiszka
2009-05-13  5:08   ` vibisreenivasan
2009-05-13 14:13   ` vibisreenivasan
2009-05-19 14:59     ` Nathan Froyd
2009-05-21  8:19       ` vibi sreenivasan
2009-05-19 15:06   ` Nathan Froyd
2009-05-19 16:53     ` Jan Kiszka
2009-05-19 18:01       ` Nathan Froyd
2009-05-20  6:39         ` Jan Kiszka [this message]
2009-05-20 15:27           ` Jamie Lokier

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=4A13A590.8040301@web.de \
    --to=jan.kiszka@web.de \
    --cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).