Skip to content

cleanup: Conditional locking support

Peter Zijlstra lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 7 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2cleanup: Add conditional guard supportinclude/linux/cleanup.h include/linux/mutex.h include/linux/rwsem.h +1 more+70 -85 replies
2/2ptrace: Convert ptrace_attach() to use lock guardsinclude/linux/sched/task.h include/linux/spinlock.h kernel/ptrace.c+94 -721 reply

Reviews trailers per patch

1 of 2 patches has a Reviewed-by or Acked-by.

PatchOleg Nesterov
1/2
2/2R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/2] cleanup: Conditional locking support

Hi,

Two patches, the first extending the cleanup/guard stuff to better handle conditional locks, mutex_trylock(), mutex_lock_interruptible() etc.. And the second a small ptrace conversion that I've been using as a test-case.

The normal scoped_guard() is changed to simply skip the body when a conditional lock fails to acquire. A new scoped_cond_guard() is added that takes an extra statement argument to provide an explicit 'fail' action.

The ptrace patch has:

scoped_cond_guard (mutex_intr, return -ERESTARTNOINTR,

		     &task->signal->cred_guard_mutex) {
    ...

}
...
return 0;

Where if the lock acquire fails, it does 'return -ERESTARTNOINTR'.

The crazy perf thing then becomes:

scoped_cond_guard (rwsem_read_intr, goto no_lock,

                     task ? &task->signal->exec_update_lock : NULL) {
    if (0) {
no_lock:
      if (task)
        return -EINTR;
    }
    ... body with or without lock ...

}

Specifically, that thing needs the lock when there is a task, but otherwise needs to still do the body without the lock.

IIO also wanted something along these lines, although they have a custom 'trylock' thing.

Barring objections, I'm planning to merge this into tip/locking/cleanup which I'll merge into tip/locking/core (and tip/perf/core when times comes).

My plan is to post the perf patches in 3 batches of roughly 10 patches each, the simpler first and the more crazy ones (including the above) last.