All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: David Vrabel <david.vrabel@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Keir Fraser <keir@xen.org>, Tim Deegan <tim@xen.org>,
	David Vrabel <david.vrabel@citrix.com>,
	Jan Beulich <jbeulich@suse.com>,
	Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCHv3 3/6] evtchn: simplify port_is_valid()
Date: Wed, 17 Jun 2015 13:03:00 +0100	[thread overview]
Message-ID: <1434542583-28073-4-git-send-email-david.vrabel@citrix.com> (raw)
In-Reply-To: <1434542583-28073-1-git-send-email-david.vrabel@citrix.com>

By keeping a count of the number of currently valid event channels,
port_is_valid() can be simplified.

d->valid_evtchns is only increased (while holding d->event_lock), so
port_is_valid() may be safely called without taking the lock (this
will be useful later).

Signed-off-by: David Vrabel <david.vrabel@citrix.com>
---
v3:
- Remove redundant d->evtchn test.

v2:
- Used unsigned int for d->valid_evtchns.
---
 xen/common/event_channel.c |    3 +++
 xen/include/xen/event.h    |    6 +-----
 xen/include/xen/sched.h    |    5 +++--
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index ab3b48e..4924796 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -189,6 +189,8 @@ static int get_free_port(struct domain *d)
         return -ENOMEM;
     bucket_from_port(d, port) = chn;
 
+    write_atomic(&d->valid_evtchns, d->valid_evtchns + EVTCHNS_PER_BUCKET);
+
     return port;
 }
 
@@ -1232,6 +1234,7 @@ int evtchn_init(struct domain *d)
     d->evtchn = alloc_evtchn_bucket(d, 0);
     if ( !d->evtchn )
         return -ENOMEM;
+    d->valid_evtchns = EVTCHNS_PER_BUCKET;
 
     spin_lock_init_prof(d, event_lock);
     if ( get_free_port(d) != 0 )
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index 690f865..af923d1 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -89,11 +89,7 @@ static inline bool_t port_is_valid(struct domain *d, unsigned int p)
 {
     if ( p >= d->max_evtchns )
         return 0;
-    if ( !d->evtchn )
-        return 0;
-    if ( p < EVTCHNS_PER_BUCKET )
-        return 1;
-    return group_from_port(d, p) != NULL && bucket_from_port(d, p) != NULL;
+    return p < read_atomic(&d->valid_evtchns);
 }
 
 static inline struct evtchn *evtchn_from_port(struct domain *d, unsigned int p)
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 80c6f62..604d047 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -336,8 +336,9 @@ struct domain
     /* Event channel information. */
     struct evtchn   *evtchn;                         /* first bucket only */
     struct evtchn  **evtchn_group[NR_EVTCHN_GROUPS]; /* all other buckets */
-    unsigned int     max_evtchns;
-    unsigned int     max_evtchn_port;
+    unsigned int     max_evtchns;     /* number supported by ABI */
+    unsigned int     max_evtchn_port; /* max permitted port number */
+    unsigned int     valid_evtchns;   /* number of allocated event channels */
     spinlock_t       event_lock;
     const struct evtchn_port_ops *evtchn_port_ops;
     struct evtchn_fifo_domain *evtchn_fifo;
-- 
1.7.10.4

  parent reply	other threads:[~2015-06-17 12:03 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-17 12:02 [PATCHv3 0/6] evtchn: Improve scalebility David Vrabel
2015-06-17 12:02 ` [PATCHv3 1/6] evtchn: clear xen_consumer when clearing state David Vrabel
2015-06-18 10:30   ` Jan Beulich
2015-06-17 12:02 ` [PATCHv3 2/6] evtchn: defer freeing struct evtchn's until evtchn_destroy_final() David Vrabel
2015-06-18 10:36   ` Jan Beulich
2015-06-18 10:40     ` David Vrabel
2015-06-18 11:01       ` Jan Beulich
2015-06-19  9:29       ` Jan Beulich
2015-06-19  9:52         ` David Vrabel
2015-06-19 10:55           ` Jan Beulich
2015-06-19 12:23             ` David Vrabel
2015-06-19 13:04               ` Jan Beulich
2015-06-19 16:58                 ` David Vrabel
2015-06-17 12:03 ` David Vrabel [this message]
2015-06-17 12:03 ` [PATCHv3 4/6] evtchn: use a per-event channel lock for sending events David Vrabel
2015-06-18 11:20   ` Jan Beulich
2015-06-18 11:39     ` David Vrabel
2015-06-17 12:03 ` [PATCHv3 5/6] evtchn: remove the locking when unmasking an event channel David Vrabel
2015-06-18 11:30   ` Jan Beulich
2015-06-18 11:36     ` David Vrabel
2015-06-18 12:08       ` Jan Beulich
2015-06-18 12:17         ` David Vrabel
2015-06-17 12:03 ` [PATCHv3 6/6] evtchn: pad struct evtchn to 64 bytes David Vrabel
2015-06-18 11:31   ` Jan Beulich

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=1434542583-28073-4-git-send-email-david.vrabel@citrix.com \
    --to=david.vrabel@citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=keir@xen.org \
    --cc=tim@xen.org \
    --cc=xen-devel@lists.xenproject.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.