From: Sandeep Patil <sspatil@google.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 3/4] mm: mallocstress: use futexes instead of SysV semaphores
Date: Mon, 13 Nov 2017 18:11:17 -0800 [thread overview]
Message-ID: <20171114021118.103786-4-sspatil@google.com> (raw)
In-Reply-To: <20171114021118.103786-1-sspatil@google.com>
Start using TST_CHECKPOINT_WAIT/WAKE macros that are based on futexes
instead of SysV semaphore. This allows the test to build and run on an
Android system.
Signed-off-by: Sandeep Patil <sspatil@google.com>
---
v1->v2
------
- use the correct SAFE_ macros (that don't require cleanup functions)
testcases/kernel/mem/mtest07/mallocstress.c | 59 +++++++----------------------
1 file changed, 14 insertions(+), 45 deletions(-)
diff --git a/testcases/kernel/mem/mtest07/mallocstress.c b/testcases/kernel/mem/mtest07/mallocstress.c
index 0f495a6b3..63df7c70e 100644
--- a/testcases/kernel/mem/mtest07/mallocstress.c
+++ b/testcases/kernel/mem/mtest07/mallocstress.c
@@ -192,20 +192,10 @@ int allocate_free(int scheme)
void *alloc_mem(void *threadnum)
{
- struct sembuf sop[1];
int err;
/* waiting for other threads starting */
- sop[0].sem_num = 0;
- sop[0].sem_op = 0;
- sop[0].sem_flg = 0;
- TEST(semop(semid, sop, 1));
- if (TEST_RETURN == -1 && TEST_ERRNO != EIDRM) {
- tst_res(TBROK | TTERRNO,
- "Thread [%d] failed to wait on semaphore",
- (int)(uintptr_t)threadnum);
- return (void *)-1;
- }
+ TST_CHECKPOINT_WAIT(0);
/* thread N will use growth scheme N mod 4 */
err = allocate_free(((uintptr_t)threadnum) % 4);
@@ -216,19 +206,21 @@ void *alloc_mem(void *threadnum)
return (void *)(uintptr_t) (err ? -1 : 0);
}
+static void cleanup(void)
+{
+ if (thread_id) {
+ free(thread_id);
+ thread_id = NULL;
+ }
+}
+
static void stress_malloc(unsigned int n)
{
- struct sembuf sop[1];
int thread_index;
-
(void)n;
- /* kick off all the waiting threads */
- sop[0].sem_num = 0;
- sop[0].sem_op = -1;
- sop[0].sem_flg = 0;
- TEST(semop(semid, sop, 1));
- if (TEST_RETURN == -1)
- tst_res(TBROK | TTERRNO, "Failed to wakeup all threads");
+
+ /* Wake up all threads */
+ TST_CHECKPOINT_WAKE2(0, NUM_THREADS);
/* wait for all threads to finish */
for (thread_index = 0; thread_index < NUM_THREADS; thread_index++) {
@@ -246,21 +238,11 @@ static void stress_malloc(unsigned int n)
static void setup(void)
{
- struct sembuf sop[1];
int thread_index;
thread_id = SAFE_MALLOC(sizeof(pthread_t) * NUM_THREADS);
- semid = semget(IPC_PRIVATE, 1, IPC_CREAT | 0666);
- if (semid < 0)
- tst_res(TBROK | TTERRNO, "Semaphore creation failed");
-
- sop[0].sem_num = 0;
- sop[0].sem_op = 1;
- sop[0].sem_flg = 0;
- TEST(semop(semid, sop, 1));
- if (TEST_RETURN == -1)
- tst_res(TBROK | TTERRNO, "Failed to initialize semaphore");
+ TST_CHECKPOINT_INIT();
for (thread_index = 0; thread_index < NUM_THREADS; thread_index++) {
SAFE_PTHREAD_CREATE(&thread_id[thread_index], NULL, alloc_mem,
@@ -268,22 +250,9 @@ static void setup(void)
}
}
-static void cleanup(void)
-{
- if (semid > 0) {
- TEST(semctl(semid, 0, IPC_RMID));
- if (TEST_RETURN == -1)
- tst_res(TWARN, "Failed to destroy semaphore");
- }
-
- if (thread_id) {
- free(thread_id);
- thread_id = NULL;
- }
-}
-
static struct tst_test test = {
.tcnt = 1,
+ .needs_tmpdir = 1,
.cleanup = cleanup,
.setup = setup,
.test = stress_malloc,
--
2.15.0.448.gf294e3d99a-goog
next prev parent reply other threads:[~2017-11-14 2:11 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-14 2:11 [LTP] [PATCH v2 0/4] Miscellaneous fixes for Android systems Sandeep Patil
2017-11-14 2:11 ` [LTP] [PATCH v2 1/4] mm: mallocstress: use new library and safe macros Sandeep Patil
2017-11-14 2:11 ` [LTP] [PATCH 2/4] checkpoint: add TST_CHECKPOINT_INIT() for new library headers Sandeep Patil
2017-11-14 2:11 ` Sandeep Patil [this message]
2017-11-20 12:36 ` [LTP] [PATCH v2 3/4] mm: mallocstress: use futexes instead of SysV semaphores Jan Stancek
2017-11-28 14:25 ` Sandeep Patil
2017-11-14 2:11 ` [LTP] [PATCH v2 4/4] lib: mkfs: use 'mke2fs' for formatting extN filesystems Sandeep Patil
2017-12-04 16:24 ` Cyril Hrubis
2018-02-22 23:11 ` Sandeep Patil
2017-12-04 16:52 ` Jan Stancek
2017-12-06 12:16 ` Cyril Hrubis
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=20171114021118.103786-4-sspatil@google.com \
--to=sspatil@google.com \
--cc=ltp@lists.linux.it \
/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