Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1589584 > unrolled thread

Re: [PATCH v5 06/13] lockdep: Implement crossrelease feature

Started byPeter Zijlstra <peterz@infradead.org>
First post2017-02-28 17:00 +0100
Last post2017-03-02 04:00 +0100
Articles 4 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH v5 06/13] lockdep: Implement crossrelease feature Peter Zijlstra <peterz@infradead.org> - 2017-02-28 17:00 +0100
    Re: [PATCH v5 06/13] lockdep: Implement crossrelease feature Byungchul Park <byungchul.park@lge.com> - 2017-03-01 06:20 +0100
      Re: [PATCH v5 06/13] lockdep: Implement crossrelease feature Byungchul Park <byungchul.park@lge.com> - 2017-03-01 07:50 +0100
      Re: [PATCH v5 06/13] lockdep: Implement crossrelease feature Byungchul Park <byungchul.park@lge.com> - 2017-03-02 04:00 +0100

#1589584 — Re: [PATCH v5 06/13] lockdep: Implement crossrelease feature

FromPeter Zijlstra <peterz@infradead.org>
Date2017-02-28 17:00 +0100
SubjectRe: [PATCH v5 06/13] lockdep: Implement crossrelease feature
Message-ID<tfSlY-6te-25@gated-at.bofh.it>
On Wed, Jan 18, 2017 at 10:17:32PM +0900, Byungchul Park wrote:

> +struct cross_lock {
> +	/*
> +	 * When more than one acquisition of crosslocks are overlapped,
> +	 * we do actual commit only when ref == 0.
> +	 */
> +	atomic_t ref;

That comment doesn't seem right, should that be: ref != 0 ?

Also; would it not be much clearer to call this: nr_blocked, or waiters
or something along those lines, because that is what it appears to be.

> +	/*
> +	 * Seperate hlock instance. This will be used at commit step.
> +	 *
> +	 * TODO: Use a smaller data structure containing only necessary
> +	 * data. However, we should make lockdep code able to handle the
> +	 * smaller one first.
> +	 */
> +	struct held_lock	hlock;
> +};

> +static int add_xlock(struct held_lock *hlock)
> +{
> +	struct cross_lock *xlock;
> +	unsigned int gen_id;
> +
> +	if (!depend_after(hlock))
> +		return 1;
> +
> +	if (!graph_lock())
> +		return 0;
> +
> +	xlock = &((struct lockdep_map_cross *)hlock->instance)->xlock;
> +
> +	/*
> +	 * When acquisitions for a xlock are overlapped, we use
> +	 * a reference counter to handle it.

Handle what!? That comment is near empty.

> +	 */
> +	if (atomic_inc_return(&xlock->ref) > 1)
> +		goto unlock;

So you set the xlock's generation only once, to the oldest blocking-on
relation, which makes sense, you want to be able to related to all
historical locks since.

> +
> +	gen_id = (unsigned int)atomic_inc_return(&cross_gen_id);
> +	xlock->hlock = *hlock;
> +	xlock->hlock.gen_id = gen_id;
> +unlock:
> +	graph_unlock();
> +	return 1;
> +}

> +void lock_commit_crosslock(struct lockdep_map *lock)
> +{
> +	struct cross_lock *xlock;
> +	unsigned long flags;
> +
> +	if (!current->xhlocks)
> +		return;
> +
> +	if (unlikely(current->lockdep_recursion))
> +		return;
> +
> +	raw_local_irq_save(flags);
> +	check_flags(flags);
> +	current->lockdep_recursion = 1;
> +
> +	if (unlikely(!debug_locks))
> +		return;
> +
> +	if (!graph_lock())
> +		return;
> +
> +	xlock = &((struct lockdep_map_cross *)lock)->xlock;
> +	if (atomic_read(&xlock->ref) > 0 && !commit_xhlocks(xlock))

You terminate with graph_lock() held.

Also, I think you can do the atomic_read() outside of graph lock, to
avoid taking graph_lock when its 0.

> +		return;
> +
> +	graph_unlock();
> +	current->lockdep_recursion = 0;
> +	raw_local_irq_restore(flags);
> +}
> +EXPORT_SYMBOL_GPL(lock_commit_crosslock);
> +
> +/*
> + * return 0: Need to do normal release operation.
> + * return 1: Done. No more release ops is needed.
> + */
> +static int lock_release_crosslock(struct lockdep_map *lock)
> +{
> +	if (cross_lock(lock)) {
> +		atomic_dec(&((struct lockdep_map_cross *)lock)->xlock.ref);
> +		return 1;
> +	}
> +	return 0;
> +}
> +
> +static void cross_init(struct lockdep_map *lock, int cross)
> +{
> +	if (cross)
> +		atomic_set(&((struct lockdep_map_cross *)lock)->xlock.ref, 0);
> +
> +	lock->cross = cross;
> +}

[toc] | [next] | [standalone]


#1589981

FromByungchul Park <byungchul.park@lge.com>
Date2017-03-01 06:20 +0100
Message-ID<tg4Q9-6yN-1@gated-at.bofh.it>
In reply to#1589584
On Tue, Feb 28, 2017 at 04:49:00PM +0100, Peter Zijlstra wrote:
> On Wed, Jan 18, 2017 at 10:17:32PM +0900, Byungchul Park wrote:
> 
> > +struct cross_lock {
> > +	/*
> > +	 * When more than one acquisition of crosslocks are overlapped,
> > +	 * we do actual commit only when ref == 0.
> > +	 */
> > +	atomic_t ref;
> 
> That comment doesn't seem right, should that be: ref != 0 ?
> Also; would it not be much clearer to call this: nr_blocked, or waiters
> or something along those lines, because that is what it appears to be.
> 
> > +	/*
> > +	 * Seperate hlock instance. This will be used at commit step.
> > +	 *
> > +	 * TODO: Use a smaller data structure containing only necessary
> > +	 * data. However, we should make lockdep code able to handle the
> > +	 * smaller one first.
> > +	 */
> > +	struct held_lock	hlock;
> > +};
> 
> > +static int add_xlock(struct held_lock *hlock)
> > +{
> > +	struct cross_lock *xlock;
> > +	unsigned int gen_id;
> > +
> > +	if (!depend_after(hlock))
> > +		return 1;
> > +
> > +	if (!graph_lock())
> > +		return 0;
> > +
> > +	xlock = &((struct lockdep_map_cross *)hlock->instance)->xlock;
> > +
> > +	/*
> > +	 * When acquisitions for a xlock are overlapped, we use
> > +	 * a reference counter to handle it.
> 
> Handle what!? That comment is near empty.

I will add more comment so that it can fully descibe.

> 
> > +	 */
> > +	if (atomic_inc_return(&xlock->ref) > 1)
> > +		goto unlock;
> 
> So you set the xlock's generation only once, to the oldest blocking-on
> relation, which makes sense, you want to be able to related to all
> historical locks since.
> 
> > +
> > +	gen_id = (unsigned int)atomic_inc_return(&cross_gen_id);
> > +	xlock->hlock = *hlock;
> > +	xlock->hlock.gen_id = gen_id;
> > +unlock:
> > +	graph_unlock();
> > +	return 1;
> > +}
> 
> > +void lock_commit_crosslock(struct lockdep_map *lock)
> > +{
> > +	struct cross_lock *xlock;
> > +	unsigned long flags;
> > +
> > +	if (!current->xhlocks)
> > +		return;
> > +
> > +	if (unlikely(current->lockdep_recursion))
> > +		return;
> > +
> > +	raw_local_irq_save(flags);
> > +	check_flags(flags);
> > +	current->lockdep_recursion = 1;
> > +
> > +	if (unlikely(!debug_locks))
> > +		return;
> > +
> > +	if (!graph_lock())
> > +		return;
> > +
> > +	xlock = &((struct lockdep_map_cross *)lock)->xlock;
> > +	if (atomic_read(&xlock->ref) > 0 && !commit_xhlocks(xlock))
> 
> You terminate with graph_lock() held.

Oops. What did I do? I'll fix it.

> 
> Also, I think you can do the atomic_read() outside of graph lock, to
> avoid taking graph_lock when its 0.

I'll do that if possible after thinking more.

[toc] | [prev] | [next] | [standalone]


#1590040

FromByungchul Park <byungchul.park@lge.com>
Date2017-03-01 07:50 +0100
Message-ID<tg6fg-7wF-19@gated-at.bofh.it>
In reply to#1589981
On Wed, Mar 01, 2017 at 02:17:07PM +0900, Byungchul Park wrote:
> On Tue, Feb 28, 2017 at 04:49:00PM +0100, Peter Zijlstra wrote:
> > On Wed, Jan 18, 2017 at 10:17:32PM +0900, Byungchul Park wrote:
> > 
> > > +struct cross_lock {
> > > +	/*
> > > +	 * When more than one acquisition of crosslocks are overlapped,
> > > +	 * we do actual commit only when ref == 0.
> > > +	 */
> > > +	atomic_t ref;
> > 
> > That comment doesn't seem right, should that be: ref != 0 ?
> > Also; would it not be much clearer to call this: nr_blocked, or waiters
> > or something along those lines, because that is what it appears to be.

Honestly, I forgot why I introduced the ref.. I will remove the ref next
spin, and handle waiters in another way.

Thank you,
Byungchul

[toc] | [prev] | [next] | [standalone]


#1590813

FromByungchul Park <byungchul.park@lge.com>
Date2017-03-02 04:00 +0100
Message-ID<tgp8d-44Y-5@gated-at.bofh.it>
In reply to#1589981
On Wed, Mar 01, 2017 at 02:17:07PM +0900, Byungchul Park wrote:
> > > +void lock_commit_crosslock(struct lockdep_map *lock)
> > > +{
> > > +	struct cross_lock *xlock;
> > > +	unsigned long flags;
> > > +
> > > +	if (!current->xhlocks)
> > > +		return;
> > > +
> > > +	if (unlikely(current->lockdep_recursion))
> > > +		return;
> > > +
> > > +	raw_local_irq_save(flags);
> > > +	check_flags(flags);
> > > +	current->lockdep_recursion = 1;
> > > +
> > > +	if (unlikely(!debug_locks))
> > > +		return;
> > > +
> > > +	if (!graph_lock())
> > > +		return;
> > > +
> > > +	xlock = &((struct lockdep_map_cross *)lock)->xlock;
> > > +	if (atomic_read(&xlock->ref) > 0 && !commit_xhlocks(xlock))
> > 
> > You terminate with graph_lock() held.
> 
> Oops. What did I do? I'll fix it.

I remembered it. It's no problem because it would terminate there, only
if _both_ 'xlock->ref > 0' and 'commit_xhlocks returns 0' are true.
Otherwise, it will unlock the lock safely.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web