All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Vrabel <david.vrabel@citrix.com>
To: David Vrabel <david.vrabel@citrix.com>
Cc: xen-devel@lists.xen.org
Subject: Re: [PATCH 0/3] xen: evtchn and gntdev device fixes and perf improvements
Date: Fri, 19 Jul 2013 15:57:10 +0100	[thread overview]
Message-ID: <51E953C6.8050906@citrix.com> (raw)
In-Reply-To: <1374245520-19270-1-git-send-email-david.vrabel@citrix.com>

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

On 19/07/13 15:51, David Vrabel wrote:
> 
> Patch 3 improves the scalability of the evtchn device when it is used
> by multiple processes (e.g., multiple qemus).  As you can see from the
> graph[1] it is a signficant improvement but still less than ideal.  I
> suspect that this may be due to the per-domain event lock inside Xen
> rather than anything kernel-side.
> 
> The graphed data was collected from dom0 with 8 VCPUs on a host with 8
> CPUs.

Attached is the (slightly cheesy) test program I used to generate the
results.  This also triggered the deadlock fixed by patch 1.

It spawns N threads each of which opens /dev/xen/evtchn channel sets up
an event channel with both ends in the same domain.  The event channels
are manually distributed between the VCPUs.

David

[-- Attachment #2: evtchn-stress.c --]
[-- Type: text/x-csrc, Size: 2630 bytes --]

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <xenctrl.h>

#define MAX_THREADS 128
#define MAX_EVENTS 100000

#define FIRST_IRQ 62
#define MAX_VCPUS 8

static unsigned long long elapsed[MAX_THREADS];

static void bind_irq(unsigned port, unsigned cpu)
{
    char buf[64];
    FILE *f;
    unsigned irq = port + FIRST_IRQ;

    snprintf(buf, sizeof(buf), "/proc/irq/%d/smp_affinity", irq);

    f = fopen(buf, "w");
    if (!f)
        return;

    snprintf(buf, sizeof(buf), "%x", 1 << cpu);
    fwrite(buf, strlen(buf), 1, f);
    fclose(f);
}

void *test_thread(void *arg)
{
    unsigned i = (intptr_t)arg;
    xc_evtchn *xce;
    evtchn_port_t lport;
    evtchn_port_t rport;
    unsigned events = 0;
    struct timespec start, end;

    xce = xc_evtchn_open(NULL, 0);
    if (!xce)
        return NULL;

    lport = xc_evtchn_bind_unbound_port(xce, 0);
    if (lport < 0)
        return NULL;

    rport = xc_evtchn_bind_interdomain(xce, 0, lport);

    bind_irq(lport, lport % MAX_VCPUS);
    bind_irq(rport, rport % MAX_VCPUS);

    xc_evtchn_notify(xce, lport);

    clock_gettime(CLOCK_MONOTONIC, &start);

    while (events < MAX_EVENTS) {
        evtchn_port_t port;

        port = xc_evtchn_pending(xce);
        if (port == lport)
            xc_evtchn_notify(xce, lport);
        else
            xc_evtchn_notify(xce, rport);
        xc_evtchn_unmask(xce, port);

        events++;
    }

    clock_gettime(CLOCK_MONOTONIC, &end);

    xc_evtchn_close(xce);

    elapsed[i] = (end.tv_sec - start.tv_sec) * 1000000000ull
        + (end.tv_nsec - start.tv_nsec);

    return NULL;
}

static pthread_t threads[MAX_THREADS];

int start_thread(unsigned i)
{
    return pthread_create(&threads[i], NULL, test_thread, (void *)(intptr_t)i);
}

void run_test(unsigned num_threads)
{
    unsigned i;
    double accum = 0.0;

    for (i = 0; i < num_threads; i++)
        start_thread(i);

    for (i = 0; i < num_threads; i++)
        pthread_join(threads[i], NULL);

    for (i  = 0; i < num_threads; i++)
        accum += MAX_EVENTS / (double)elapsed[i];

    printf("  num_threads: %u\n", num_threads);
    printf("  rate: %.1f event/s\n", accum / num_threads * 1000000000.0);
}

int main(int argc, char *argv[])
{
    unsigned num_threads;
    unsigned num_iters;
    unsigned i;

    if (argc <=1 )
        fprintf(stderr, "Usage: %s <iters> <threads>\n", argv[0]);

    num_iters = atoi(argv[1]);
    num_threads = atoi(argv[2]);

    for (i = 0; i < num_iters; i++) {
        printf("iter: %d\n", i);
        run_test(num_threads);
    }

    return 0;
}

[-- Attachment #3: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

      parent reply	other threads:[~2013-07-19 14:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-19 14:51 [PATCH 0/3] xen: evtchn and gntdev device fixes and perf improvements David Vrabel
2013-07-19 14:51 ` [PATCH 1/3] xen/evtchn: avoid a deadlock when unbinding an event channel David Vrabel
2013-07-29 14:07   ` Konrad Rzeszutek Wilk
2013-07-29 15:35     ` David Vrabel
2013-07-19 14:51 ` [PATCH 2/3] xen/p2m: avoid unneccesary TLB flush in m2p_remove_override() David Vrabel
2013-07-21 14:12   ` Stefano Stabellini
2013-07-19 14:52 ` [PATCH 3/3] xen/evtchn: improve scalability by using per-user locks David Vrabel
2013-07-19 14:57 ` David Vrabel [this message]

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=51E953C6.8050906@citrix.com \
    --to=david.vrabel@citrix.com \
    --cc=xen-devel@lists.xen.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.