From: dhylands@gmail.com (Dave Hylands)
To: linux-arm-kernel@lists.infradead.org
Subject: Problems with semaphores, mutexes, and atomic?
Date: Mon, 20 Jun 2011 01:58:17 -0700 [thread overview]
Message-ID: <BANLkTinzRg+bu4AB4JGYkY_y9g8ZRhV=JQ@mail.gmail.com> (raw)
In-Reply-To: <20110620082729.GA26089@n2100.arm.linux.org.uk>
Hi Russell,
On Mon, Jun 20, 2011 at 1:27 AM, Russell King - ARM Linux
<linux@arm.linux.org.uk> wrote:
> On Sun, Jun 19, 2011 at 11:39:49PM -0700, Dave Hylands wrote:
>> Each thread performs the loop a number of times, and at the end the
>> count often doesn't have the expected value if the locks were in fact
>> atomic.
>>
>> Typical output looks like:
>>
>> 192.168.0.50 ?~ # modprobe test-mutex
>> [ ? 26.220000] Testing mutex...
>> [ ? 26.230000] ? ? Launching threads ..........
>> [ ? 26.300000] ? ? Waiting for threads to finish ..........
>> [ ? 26.310000] ? counter = 999888 FAIL
>> [ ? 26.310000] Testing semaphore...
>> [ ? 26.310000] ? ? Launching threads ..........
>> [ ? 26.440000] ? ? Waiting for threads to finish ..........
>> [ ? 27.810000] ? counter = 999575 FAIL
>> [ ? 27.810000] Testing atomic...
>> [ ? 27.820000] ? ? Launching threads ..........
>> [ ? 28.030000] ? ? Waiting for threads to finish ..........
>> [ ? 28.040000] ?counter = 9910929 FAIL
>
> The answer is quite simple. ?You're not waiting for all the threads to
> finish. ?The first down(&thread_wait) will succeed, so the values you're
> getting above could be up to 100000 (NUM_ATOMIC_ITER) out. ?And they
> are.
Thank you. My sanity has been restored.
I added a down on thread_wait in the init routine, and now all of test
cases pass for all of the variations (CONFIG_SMP=n, CONFIG_SMP=y, with
1 or 2 processors).
Now I need to dig deeper to find the real reason why my original code,
which prompted me to go down this path is failing.
--
Dave Hylands
Shuswap, BC, Canada
http://www.davehylands.com
next prev parent reply other threads:[~2011-06-20 8:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-20 6:39 Problems with semaphores, mutexes, and atomic? Dave Hylands
2011-06-20 7:20 ` saeed bishara
2011-06-20 7:44 ` Dave Hylands
2011-06-20 8:03 ` Arnd Bergmann
2011-06-20 8:21 ` Dave Hylands
2011-06-20 8:34 ` Arnd Bergmann
2011-06-20 9:07 ` Dave Hylands
2011-06-20 8:27 ` Russell King - ARM Linux
2011-06-20 8:58 ` Dave Hylands [this message]
2013-07-16 7:11 ` Hesham Mahmoud
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='BANLkTinzRg+bu4AB4JGYkY_y9g8ZRhV=JQ@mail.gmail.com' \
--to=dhylands@gmail.com \
--cc=linux-arm-kernel@lists.infradead.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 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).