mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Boris Ostrovsky <boris.ostrovsky@oracle.com>
To: Juergen Gross <jgross@suse.com>,
	linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org
Subject: Re: [PATCH 3/3] xen: optimize xenbus driver for multiple concurrent xenstore accesses
Date: Tue, 10 Jan 2017 11:36:12 -0500	[thread overview]
Message-ID: <eadfa82a-d7b2-9f90-8046-2559c4bc93f6@oracle.com> (raw)
In-Reply-To: <9f84b972-9a76-aae2-ece6-b292bf9796cd@suse.com>


>>> +static int process_msg(void)
>>> +{
>>> +	static struct xs_thread_state_read state;
>>> +	struct xb_req_data *req;
>>> +	int err;
>>> +	unsigned int len;
>>> +
>>> +	if (!state.in_msg) {
>>> +		state.in_msg = true;
>>> +		state.in_hdr = true;
>>> +		state.used = 0;
>>> +
>>> +		/*
>>> +		 * We must disallow save/restore while reading a message.
>>> +		 * A partial read across s/r leaves us out of sync with
>>> +		 * xenstored.
>>> +		 */
>>> +		mutex_lock(&xs_response_mutex);
>>> +
>>> +		if (!xb_data_to_read()) {
>>> +			/* We raced with save/restore: pending data 'gone'. */
>>> +			mutex_unlock(&xs_response_mutex);
>>> +			state.in_msg = false;

Just noticed: should in_hdr be set to false here as well?

>>> +			return 0;
>>> +		}

Or set it to true here.

>>> +	}
>>> +
>>> +	if (state.in_hdr) {
>>> +		if (state.used != sizeof(state.msg)) {
>>> +			err = xb_read((void *)&state.msg + state.used,
>>> +				      sizeof(state.msg) - state.used);
>>> +			if (err < 0)
>>> +				goto out;
>>> +			state.used += err;
>>> +			if (state.used != sizeof(state.msg))
>>> +				return 0;
>> Would it be possible to do locking at the caller? I understand that you
>> are trying to hold the lock across multiple invocations of this function
>> but it feels somewhat counter-intuitive and bug-prone.
> I think that would be difficult.
>
>> If it's not possible then at least please add a comment explaining
>> locking algorithm.
> Okay. Something like:
>
> /*
>  * xs_response_mutex is locked as long as we are processing one
>  * message. state.in_msg will be true as long as we are holding the
>  * lock in process_msg().


Then in_msg is the same as mutex_is_locked(&xs_response_mutex). And if
so, do we really need it?


-boris

  reply	other threads:[~2017-01-10 16:36 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-06 15:05 [PATCH 0/3] xen: optimize xenbus performance Juergen Gross
2017-01-06 15:05 ` [PATCH 1/3] xen: clean up xenbus internal headers Juergen Gross
2017-01-06 20:52   ` Boris Ostrovsky
2017-01-09  7:07     ` Juergen Gross
2017-01-06 15:05 ` [PATCH 2/3] xen: modify xenstore watch event interface Juergen Gross
2017-01-06 15:38   ` Paul Durrant
2017-01-06 16:29   ` Wei Liu
2017-01-06 16:37   ` Roger Pau Monné
2017-01-06 21:57   ` Boris Ostrovsky
2017-01-09  7:12     ` Juergen Gross
2017-01-06 15:05 ` [PATCH 3/3] xen: optimize xenbus driver for multiple concurrent xenstore accesses Juergen Gross
2017-01-09 21:17   ` Boris Ostrovsky
2017-01-10  6:18     ` Juergen Gross
2017-01-10 16:36       ` Boris Ostrovsky [this message]
2017-01-10 16:38         ` Boris Ostrovsky
2017-01-10 16:46         ` Juergen Gross
2017-01-10 19:17   ` Boris Ostrovsky
2017-01-10 22:56   ` Boris Ostrovsky
2017-01-11  5:26     ` Juergen Gross
2017-01-11 15:29       ` Boris Ostrovsky
2017-01-11 16:50         ` Juergen Gross

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=eadfa82a-d7b2-9f90-8046-2559c4bc93f6@oracle.com \
    --to=boris.ostrovsky@oracle.com \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®