All of lore.kernel.org
 help / color / mirror / Atom feed
From: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>
To: Waiman Long <waiman.long@hp.com>
Cc: jeremy@goop.org, kvm@vger.kernel.org, peterz@infradead.org,
	virtualization@lists.linux-foundation.org,
	paul.gortmaker@windriver.com, hpa@zytor.com, ak@linux.intel.com,
	gleb@redhat.com, x86@kernel.org, mingo@redhat.com,
	xen-devel@lists.xenproject.org, paulmck@linux.vnet.ibm.com,
	riel@redhat.com, konrad.wilk@oracle.com, oleg@redhat.com,
	davej@redhat.com, tglx@linutronix.de, fernando_b1@lab.ntt.co.jp,
	chegu_vinod@hp.com, linux-kernel@vger.kernel.org,
	pbonzini@redhat.com, torvalds@linux-foundation.org
Subject: Re: [RFC] Implement Batched (group) ticket lock
Date: Fri, 30 May 2014 14:23:05 +0530	[thread overview]
Message-ID: <538846F1.3030303@linux.vnet.ibm.com> (raw)
In-Reply-To: <5387B87E.2010609@hp.com>

On 05/30/2014 04:15 AM, Waiman Long wrote:
> On 05/28/2014 08:16 AM, Raghavendra K T wrote:
>> - we need an intelligent way to nullify the effect of batching for
>> baremetal
>>   (because extra cmpxchg is not required).
>
> To do this, you will need to have 2 slightly different algorithms
> depending on the paravirt_ticketlocks_enabled jump label.

Thanks for the hint Waiman.

[...]
>> +spin:
>> +    for (;;) {
>> +        inc.head = ACCESS_ONCE(lock->tickets.head);
>> +        if (!(inc.head&  TICKET_LOCK_HEAD_INC)) {
>> +            new.head = inc.head | TICKET_LOCK_HEAD_INC;
>> +            if (cmpxchg(&lock->tickets.head, inc.head, new.head)
>> +                    == inc.head)
>> +                goto out;
>> +        }
>> +        cpu_relax();
>> +    }
>> +
>
> It had taken me some time to figure out the the LSB of inc.head is used
> as a bit lock for the contending tasks in the spin loop. I would suggest
> adding some comment here to make it easier to look at.

Agree. 'll add a comment.

[...]
>> +#define TICKET_BATCH    0x4 /* 4 waiters can contend simultaneously */
>> +#define TICKET_LOCK_BATCH_MASK
>> (~(TICKET_BATCH<<TICKET_LOCK_INC_SHIFT) + \
>> +                  TICKET_LOCK_TAIL_INC - 1)
>
> I don't think TAIL_INC has anything to do with setting the BATCH_MASK.
> It works here because TAIL_INC is 2. I think it is clearer to define it
> as either "(~(TICKET_BATCH<<TICKET_LOCK_INC_SHIFT) + 1)" or
> (~((TICKET_BATCH<<TICKET_LOCK_INC_SHIFT) - 1)).

You are right.
Thanks for pointing out. Your expression is simple and clearer. 'll use
one of them.

WARNING: multiple messages have this Message-ID (diff)
From: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>
To: Waiman Long <waiman.long@hp.com>
Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com,
	konrad.wilk@oracle.com, pbonzini@redhat.com, gleb@redhat.com,
	peterz@infradead.org, paulmck@linux.vnet.ibm.com,
	torvalds@linux-foundation.org, davej@redhat.com, oleg@redhat.com,
	x86@kernel.org, jeremy@goop.org, paul.gortmaker@windriver.com,
	ak@linux.intel.com, jasowang@redhat.com,
	fernando_b1@lab.ntt.co.jp, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org, virtualization@lists.linux-foundation.org,
	xen-devel@lists.xenproject.org, riel@redhat.com,
	mtosatti@redhat.com, chegu_vinod@hp.com
Subject: Re: [RFC] Implement Batched (group) ticket lock
Date: Fri, 30 May 2014 14:23:05 +0530	[thread overview]
Message-ID: <538846F1.3030303@linux.vnet.ibm.com> (raw)
In-Reply-To: <5387B87E.2010609@hp.com>

On 05/30/2014 04:15 AM, Waiman Long wrote:
> On 05/28/2014 08:16 AM, Raghavendra K T wrote:
>> - we need an intelligent way to nullify the effect of batching for
>> baremetal
>>   (because extra cmpxchg is not required).
>
> To do this, you will need to have 2 slightly different algorithms
> depending on the paravirt_ticketlocks_enabled jump label.

Thanks for the hint Waiman.

[...]
>> +spin:
>> +    for (;;) {
>> +        inc.head = ACCESS_ONCE(lock->tickets.head);
>> +        if (!(inc.head&  TICKET_LOCK_HEAD_INC)) {
>> +            new.head = inc.head | TICKET_LOCK_HEAD_INC;
>> +            if (cmpxchg(&lock->tickets.head, inc.head, new.head)
>> +                    == inc.head)
>> +                goto out;
>> +        }
>> +        cpu_relax();
>> +    }
>> +
>
> It had taken me some time to figure out the the LSB of inc.head is used
> as a bit lock for the contending tasks in the spin loop. I would suggest
> adding some comment here to make it easier to look at.

Agree. 'll add a comment.

[...]
>> +#define TICKET_BATCH    0x4 /* 4 waiters can contend simultaneously */
>> +#define TICKET_LOCK_BATCH_MASK
>> (~(TICKET_BATCH<<TICKET_LOCK_INC_SHIFT) + \
>> +                  TICKET_LOCK_TAIL_INC - 1)
>
> I don't think TAIL_INC has anything to do with setting the BATCH_MASK.
> It works here because TAIL_INC is 2. I think it is clearer to define it
> as either "(~(TICKET_BATCH<<TICKET_LOCK_INC_SHIFT) + 1)" or
> (~((TICKET_BATCH<<TICKET_LOCK_INC_SHIFT) - 1)).

You are right.
Thanks for pointing out. Your expression is simple and clearer. 'll use
one of them.


  reply	other threads:[~2014-05-30  8:53 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-28 12:16 [RFC] Implement Batched (group) ticket lock Raghavendra K T
2014-05-28 12:16 ` Raghavendra K T
2014-05-28 12:16 ` Raghavendra K T
2014-05-28 21:55 ` Rik van Riel
2014-05-28 21:55 ` Rik van Riel
2014-05-28 21:55   ` Rik van Riel
2014-05-28 22:19   ` Linus Torvalds
2014-05-28 22:19     ` Linus Torvalds
2014-05-28 22:29     ` Thomas Gleixner
2014-05-28 22:29       ` Thomas Gleixner
2014-05-28 22:29     ` Thomas Gleixner
2014-05-29  1:18     ` Rik van Riel
2014-05-29  1:18     ` Rik van Riel
2014-05-29  1:18       ` Rik van Riel
2014-05-28 22:19   ` Linus Torvalds
2014-05-29  9:44   ` Raghavendra K T
2014-05-29  9:44   ` Raghavendra K T
2014-05-29  9:44     ` Raghavendra K T
2014-05-29  6:46 ` Peter Zijlstra
2014-05-29  6:46   ` Peter Zijlstra
2014-05-29  9:51   ` Raghavendra K T
2014-05-29  9:51   ` Raghavendra K T
2014-05-29  9:51     ` Raghavendra K T
2014-05-29  6:46 ` Peter Zijlstra
2014-05-29 22:45 ` Waiman Long
2014-05-29 22:45   ` Waiman Long
2014-05-30  8:53   ` Raghavendra K T [this message]
2014-05-30  8:53     ` Raghavendra K T
2014-05-30  8:53   ` Raghavendra K T
2014-05-29 22:45 ` Waiman Long
  -- strict thread matches above, loose matches on Subject: below --
2014-05-28 12:16 Raghavendra K T

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=538846F1.3030303@linux.vnet.ibm.com \
    --to=raghavendra.kt@linux.vnet.ibm.com \
    --cc=ak@linux.intel.com \
    --cc=chegu_vinod@hp.com \
    --cc=davej@redhat.com \
    --cc=fernando_b1@lab.ntt.co.jp \
    --cc=gleb@redhat.com \
    --cc=hpa@zytor.com \
    --cc=jeremy@goop.org \
    --cc=konrad.wilk@oracle.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=oleg@redhat.com \
    --cc=paul.gortmaker@windriver.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=waiman.long@hp.com \
    --cc=x86@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 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.