From: John Kacur <jkacur@redhat.com>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: John Kacur <jkacur@redhat.com>,
rt-users <linux-rt-users@vger.kernel.org>,
Clark Williams <williams@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Carsten Emde <C.Emde@osadl.org>
Subject: Re: [PATCH 2/6] Fix possible exit on error without releasing mutex
Date: Tue, 14 Jul 2015 23:03:11 +0200 (CEST) [thread overview]
Message-ID: <alpine.LFD.2.11.1507142253010.14459@riemann> (raw)
In-Reply-To: <20150714155959.GE21820@linutronix.de>
On Tue, 14 Jul 2015, Sebastian Andrzej Siewior wrote:
> * John Kacur | 2015-07-10 14:25:27 [+0200]:
>
> >diff --git a/src/pi_tests/pi_stress.c b/src/pi_tests/pi_stress.c
> >index aaa36c362445..1d1cc58fae54 100644
> >--- a/src/pi_tests/pi_stress.c
> >+++ b/src/pi_tests/pi_stress.c
> >@@ -727,17 +727,24 @@ void *low_priority(void *arg)
> > status = pthread_barrier_wait(&p->locked_barrier);
> > if (status && status != PTHREAD_BARRIER_SERIAL_THREAD) {
> > pi_error
> >- ("low_priority[%d]: pthread_barrier_wait(locked): %x\n",
> >- p->id, status);
> >+ ("low_priority[%d]: pthread_barrier_wait(locked): %x\n",
> >+ p->id, status);
> >+ /* release the mutex */
> >+ pi_debug("low_priority[%d]: unlocking mutex\n", p->id);
> >+ pthread_mutex_unlock(&p->mutex);
> > return NULL;
> > }
> >+
> > /* wait for priority boost */
> > pi_debug("low_priority[%d]: entering elevated wait\n", p->id);
> > status = pthread_barrier_wait(&p->elevate_barrier);
> > if (status && status != PTHREAD_BARRIER_SERIAL_THREAD) {
> > pi_error
> >- ("low_priority[%d]: pthread_barrier_wait(elevate): %x\n",
> >- p->id, status);
> >+ ("low_priority[%d]: pthread_barrier_wait(elevate): %x\n",
> >+ p->id, status);
> >+ /* release the mutex */
> >+ pi_debug("low_priority[%d]: unlocking mutex\n", p->id);
> >+ pthread_mutex_unlock(&p->mutex);
> > return NULL;
> > }
> >
>
> What about having an out: label which does all the clean up at one spot
> instead of doing copy/paste here and there?
>
The thought did cross my mind, there are certainly some classic parts of
the kernel in which that provides a clean solution, but I'm not sure it's
really better here.
We're talking about two unusual spots that basically are
line 1: print debug message
line 2: unlock the mutex
line 3: return null
With two spots that's a total of six lines, and the flow of control is
quite clear.
Your method we have an out with
line 1: out_label:
line 2: print debug message
line 3: unlock the mutex
line 4: return null
And then in two spots we have to do the
spot 1: goto out_label
spot 2: goto out_label
So the total number of lines is also six, but the flow of control isn't
quite as clear.
It would make more sense if it was just part of the normal sequence in
cleaning-up, but it isn't because for the other clean-up tasks we've
already released the mutex. Also, in case you are thinking that is a
little odd, don't forget that this program purposely does some slightly
odd things in order to intentionally trigger priority inversions.
That all being said, if you see a cleaner way to do this, I'll certainly
take a patch, but for now, I'm just going to supress the complaints from
the coverage tools.
John
next prev parent reply other threads:[~2015-07-14 21:03 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-10 12:25 [PATCH 0/6] Various rt-test patches John Kacur
2015-07-10 12:25 ` [PATCH 1/6] Fix warning: unused variable ‘c’ John Kacur
2015-07-10 12:25 ` [PATCH 2/6] Fix possible exit on error without releasing mutex John Kacur
2015-07-14 15:59 ` Sebastian Andrzej Siewior
2015-07-14 21:03 ` John Kacur [this message]
2015-07-10 12:25 ` [PATCH 3/6] Create a .gitattribute file to specify what files git-archive should ignore John Kacur
2015-07-10 12:25 ` [PATCH 4/6] Add .tar files to .gitignore John Kacur
2015-07-14 15:58 ` Sebastian Andrzej Siewior
2015-07-14 20:33 ` John Kacur
2015-07-10 12:25 ` [PATCH 5/6] Change VERSION_STRING to VERSION John Kacur
2015-07-10 13:42 ` Pavel Vasilyev
2015-07-14 16:09 ` Sebastian Andrzej Siewior
2015-07-14 21:45 ` John Kacur
2015-07-10 12:25 ` [PATCH 6/6] Create an rt-tests.tar file using git-archive John Kacur
2015-07-14 16:13 ` Sebastian Andrzej Siewior
2015-07-14 20:28 ` John Kacur
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=alpine.LFD.2.11.1507142253010.14459@riemann \
--to=jkacur@redhat.com \
--cc=C.Emde@osadl.org \
--cc=bigeasy@linutronix.de \
--cc=linux-rt-users@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=williams@redhat.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;
as well as URLs for NNTP newsgroup(s).