All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Davidlohr Bueso <dave@stgolabs.net>
Cc: mingo@kernel.org, akpm@linux-foundation.org, jack@suse.cz,
	kirill.shutemov@linux.intel.com, ldufour@linux.vnet.ibm.com,
	mhocko@suse.com, mgorman@techsingularity.net,
	linux-kernel@vger.kernel.org, Davidlohr Bueso <dbueso@suse.de>
Subject: Re: [PATCH 2/6] locking: Introduce range reader/writer lock
Date: Mon, 15 May 2017 15:59:16 +0200	[thread overview]
Message-ID: <20170515135916.2arr6oqzrag4wdfe@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20170515090725.27055-3-dave@stgolabs.net>

On Mon, May 15, 2017 at 02:07:21AM -0700, Davidlohr Bueso wrote:
> +static inline int wait_for_ranges(struct range_lock_tree *tree,
> +				  struct range_lock *lock, long state)
> +{
> +	int ret = 0;
> +
> +	while (true) {
> +		set_current_state(state);
> +
> +		/* do we need to go to sleep? */
> +		if (!lock->blocking_ranges)
> +			break;
> +
> +		if (unlikely(signal_pending_state(state, current))) {
> +			struct interval_tree_node *node;
> +			unsigned long flags;
> +			DEFINE_WAKE_Q(wake_q);
> +
> +			ret = -EINTR;
> +			/*
> +			 * We're not taking the lock after all, cleanup
> +			 * after ourselves.
> +			 */
> +			spin_lock_irqsave(&tree->lock, flags);
> +
> +			range_lock_clear_reader(lock);
> +			__range_tree_remove(tree, lock);
> +
> +			if (!__range_intersects_intree(tree, lock))
> +				goto unlock;
> +
> +			range_interval_tree_foreach(node, &tree->root,
> +						    lock->node.start,
> +						    lock->node.last) {
> +				struct range_lock *blked;
> +				blked = to_range_lock(node);
> +
> +				if (range_lock_is_reader(lock) &&
> +				    range_lock_is_reader(blked))
> +					continue;
> +
> +				/* unaccount for threads _we_ are blocking */
> +				if (lock->seqnum < blked->seqnum)
> +					range_lock_put(blked, &wake_q);
> +			}
> +
> +		unlock:
> +			spin_unlock_irqrestore(&tree->lock, flags);
> +			wake_up_q(&wake_q);
> +			break;
> +		}
> +
> +		schedule();
> +	}
> +
> +	__set_current_state(TASK_RUNNING);
> +	return ret;
> +}


> +void range_read_unlock(struct range_lock_tree *tree, struct range_lock *lock)
> +{
> +	struct interval_tree_node *node;
> +	unsigned long flags;
> +	DEFINE_WAKE_Q(wake_q);
> +
> +	spin_lock_irqsave(&tree->lock, flags);
> +
> +	range_lock_clear_reader(lock);
> +	__range_tree_remove(tree, lock);
> +
> +	range_lock_release(&tree->dep_map, 1, _RET_IP_);
> +
> +	if (!__range_intersects_intree(tree, lock)) {
> +		/* nobody to wakeup, we're done */
> +		spin_unlock_irqrestore(&tree->lock, flags);
> +		return;
> +	}
> +
> +	range_interval_tree_foreach(node, &tree->root,
> +				    lock->node.start, lock->node.last) {
> +		struct range_lock *blocked_lock;
> +		blocked_lock = to_range_lock(node);
> +
> +		if (!range_lock_is_reader(blocked_lock))
> +			range_lock_put(blocked_lock, &wake_q);
> +	}
> +
> +	spin_unlock_irqrestore(&tree->lock, flags);
> +	wake_up_q(&wake_q);
> +}
> +EXPORT_SYMBOL_GPL(range_read_unlock);

> +void range_write_unlock(struct range_lock_tree *tree, struct range_lock *lock)
> +{
> +	struct interval_tree_node *node;
> +	unsigned long flags;
> +	DEFINE_WAKE_Q(wake_q);
> +
> +	spin_lock_irqsave(&tree->lock, flags);
> +
> +	range_lock_clear_reader(lock);
> +	__range_tree_remove(tree, lock);
> +
> +	range_lock_release(&tree->dep_map, 1, _RET_IP_);
> +
> +	if (!__range_intersects_intree(tree, lock)) {
> +		/* nobody to wakeup, we're done */
> +		spin_unlock_irqrestore(&tree->lock, flags);
> +		return;
> +	}
> +
> +	range_interval_tree_foreach(node, &tree->root,
> +				    lock->node.start, lock->node.last) {
> +		struct range_lock *blocked_lock;
> +		blocked_lock = to_range_lock(node);
> +
> +		range_lock_put(blocked_lock, &wake_q);
> +	}
> +
> +	spin_unlock_irqrestore(&tree->lock, flags);
> +	wake_up_q(&wake_q);
> +}
> +EXPORT_SYMBOL_GPL(range_write_unlock);


There is significant duplication here. Can't we have a
__range_unlock_common() and use that 3 times?

  parent reply	other threads:[~2017-05-15 13:59 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-15  9:07 [PATCH v3 -tip 0/6] locking: Introduce range reader/writer lock Davidlohr Bueso
2017-05-15  9:07 ` [PATCH 1/6] interval-tree: Build unconditionally Davidlohr Bueso
2017-05-15  9:07 ` [PATCH 2/6] locking: Introduce range reader/writer lock Davidlohr Bueso
2017-05-15 13:02   ` Peter Zijlstra
2017-05-16 22:19     ` Davidlohr Bueso
2017-05-15 13:44   ` Peter Zijlstra
2017-05-16 21:17     ` Davidlohr Bueso
2017-05-15 13:59   ` Peter Zijlstra [this message]
2017-05-23 15:12   ` Laurent Dufour
2017-05-15  9:07 ` [PATCH 3/6] locking/locktorture: Fix rwsem reader_delay Davidlohr Bueso
2017-05-15  9:07 ` [PATCH 4/6] locking/locktorture: Fix num reader/writer corner cases Davidlohr Bueso
2017-05-15  9:07 ` [PATCH 5/6] locking/locktorture: Support range rwlocks Davidlohr Bueso
2017-05-15  9:07 ` [PATCH 6/6] staging/lustre: Use generic range rwlock Davidlohr Bueso
2017-05-18  8:30   ` Dilger, Andreas
2017-05-18  8:30     ` [lustre-devel] " Dilger, Andreas
2017-05-15 16:11 ` [PATCH v3 -tip 0/6] locking: Introduce range reader/writer lock Christoph Hellwig
2017-06-08 16:22 ` Davidlohr Bueso
  -- strict thread matches above, loose matches on Subject: below --
2017-04-06  8:46 [PATCH v2 " Davidlohr Bueso
2017-04-06  8:46 ` [PATCH 2/6] " Davidlohr Bueso
2017-04-06  9:01   ` Laurent Dufour
2017-04-06 16:50     ` Davidlohr Bueso
2017-04-13  8:07       ` Laurent Dufour
2017-04-13  8:38         ` Jan Kara
2017-04-13  8:58           ` Laurent Dufour
2017-04-06 10:24   ` Peter Zijlstra
2017-04-18 13:57   ` Laurent Dufour
2017-04-20 16:01     ` Davidlohr Bueso
2017-04-21  7:00       ` Laurent Dufour

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=20170515135916.2arr6oqzrag4wdfe@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=dave@stgolabs.net \
    --cc=dbueso@suse.de \
    --cc=jack@suse.cz \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=ldufour@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@techsingularity.net \
    --cc=mhocko@suse.com \
    --cc=mingo@kernel.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.