mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nikita Danilov <nikita@clusterfs.com>
To: Kyle Moffett <mrmacman_g4@mac.com>
Cc: john cooper <john.cooper@timesys.com>, linux-kernel@vger.kernel.org
Subject: Re: spinaphore conceptual draft (was discussion of RT patch)
Date: Sun, 29 May 2005 12:42:43 +0400	[thread overview]
Message-ID: <17049.32899.239673.489434@gargle.gargle.HOWL> (raw)
In-Reply-To: <A53A981B-98F9-42EC-8939-60A528FEC34E@mac.com>

Kyle Moffett writes:

[...]

 > 
 > struct spinaphore {
 >      atomic_t queued;
 >      atomic_t hold_time;
 >      spinlock_t spinlock;
 >      unsigned long acquire_time;
 > };
 > 
 > void spinaphore_lock (struct spinaphore *sph) {
 >      unsigned long start_time = fast_monotonic_count();

fast_monotonic_count() should be per-cpu, otherwise spinaphore_lock()
would require two atomic operations in the best case (and be twice as
expensive as a spin-lock). Per-cpu counter is OK, as long as thread is
not allowed to schedule with spinaphore held.

 >      int queue_me = 1;
 >      until (likely(spin_trylock(&sph->spinlock))) {
 > 
 >          /* Get the queue count (And ensure we're queued in the  
 > process) */
 >          unsigned int queued = queue_me ?
 >                  atomic_inc_return(&sph->queued) :
 >                  queued = atomic_get(&sph->queued);
 >          queue_me = 0;
 > 
 >          /* Figure out if we should switch away */
 >          if (unlikely(CONFIG_SPINAPHORE_CONTEXT_SWITCH <
 >                  ( queued*atomic_get(&sph->hold_time) -
 >                    fast_monotonic_count() - start_time
 >                  ))) {
 >              /* Remove ourselves from the wait pool (remember to re- 
 > add later) */
 >              atomic_dec(&sph->queued);
 >              queue_me = 1;
 > 
 >              /* Go to sleep */
 >              cond_resched();
 >          }
 >      }
 > 
 >      /* Dequeue ourselves and update the acquire time */
 >      atomic_dec(&sph->queued);

atomic_dec() should only be done if atomic_inc_return() above was, i.e.,
not in contentionless fast-path, right?

[...]

 > 
 > void spinaphore_unlock (struct spinaphore *sph) {
 >      /* Update the running average hold time */
 >      atomic_set(&sph->hold_time, (4*atomic_get(&sph->hold_time) +
 >              (fast_monotonic_count() - sph->acquire_time))/5);
 > 
 >      /* Actually unlock the spinlock */
 >      spin_unlock(&sph->spinlock);
 > }

It is not good that unlock requires additional atomic operation. Why
->hold_time is atomic in the first place? It is only updated by the lock
holder, and as it is approximate statistics anyway, non-atomic reads in
spinaphore_lock() would be fine.

 > 
 > Cheers,
 > Kyle Moffett

Nikita.

  parent reply	other threads:[~2005-05-29  8:42 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-27 22:31 David Nicol
2005-05-28  1:04 ` Kyle Moffett
2005-05-29  5:25   ` David Nicol
2005-05-29 13:41     ` Kyle Moffett
2005-05-29  8:42   ` Nikita Danilov [this message]
2005-05-29 13:45     ` Kyle Moffett
2005-05-29 13:29   ` Joe Seigh
2005-05-29 15:32     ` Kyle Moffett
2005-05-30 11:06   ` spinaphore conceptual draft Andi Kleen
2005-05-30 14:52     ` Chris Friesen
2005-05-30 16:40       ` Andi Kleen
2005-05-30 17:11         ` Chris Friesen
2005-05-30 17:46           ` Andi Kleen
2005-05-30 18:04             ` Kyle Moffett
2005-05-30 18:40               ` Vojtech Pavlik
2005-05-30 18:54                 ` Kyle Moffett
2005-05-30 19:24                 ` Andi Kleen
2005-05-30 19:28               ` Andi Kleen
2005-05-30 19:39                 ` Kyle Moffett
2005-05-31 22:25                   ` Paul E. McKenney
2005-05-28  1:05 ` spinaphore conceptual draft (was discussion of RT patch) john cooper
2005-05-28  2:02 ` Steven Rostedt
2005-05-28 13:59 ` Alan Cox

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=17049.32899.239673.489434@gargle.gargle.HOWL \
    --to=nikita@clusterfs.com \
    --cc=john.cooper@timesys.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mrmacman_g4@mac.com \
    /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®