public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Sandeep Patil <sspatil@google.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 3/6] mm: mallocstress: use futexes instead of SysV semaphores
Date: Wed,  8 Nov 2017 16:34:35 -0800	[thread overview]
Message-ID: <20171109003438.130802-4-sspatil@google.com> (raw)
In-Reply-To: <20171109003438.130802-1-sspatil@google.com>

Start using TST_SAFE_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>
---
 testcases/kernel/mem/mtest07/mallocstress.c | 44 ++++-------------------------
 1 file changed, 5 insertions(+), 39 deletions(-)

diff --git a/testcases/kernel/mem/mtest07/mallocstress.c b/testcases/kernel/mem/mtest07/mallocstress.c
index 78d8ace8a..7e283af87 100644
--- a/testcases/kernel/mem/mtest07/mallocstress.c
+++ b/testcases/kernel/mem/mtest07/mallocstress.c
@@ -93,7 +93,6 @@
                                    } while (0)
 
 int num_loop = MAXL;		/* number of loops to perform                     */
-int semid;
 pthread_t *thrdid;		/* the threads */
 int ret;			/* program return value, used by main thread */
 
@@ -258,16 +257,8 @@ int allocate_free(int repeat,	/* number of times to repeat allocate/free    */
 /******************************************************************************/
 void *alloc_mem(void *threadnum)
 {
-	struct sembuf sop[1];
-	sop[0].sem_num = 0;
-	sop[0].sem_op = 0;
-	sop[0].sem_flg = 0;
 	/* waiting for other threads starting */
-	if (semop(semid, sop, 1) == -1) {
-		if (errno != EIDRM)
-			perror("semop");
-		return (void *)-1;
-	}
+	TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
 
 	/* thread N will use growth scheme N mod 4 */
 	int err = allocate_free(num_loop, ((uintptr_t) threadnum) % 4);
@@ -281,13 +272,6 @@ void *alloc_mem(void *threadnum)
 /* only ever called from main thread */
 static void cleanup(void)
 {
-	if (semid > 0) {
-		if (semctl(semid, 0, IPC_RMID) == -1) {
-			perror("semctl\n");
-			ret = -1;
-		}
-	}
-
 	if (thrdid) {
 		free(thrdid);
 		thrdid = NULL;
@@ -351,22 +335,8 @@ int main(int argc,		/* number of input parameters                 */
 	dprt(("number of times to loop in the thread = %d\n", num_loop));
 
 	thrdid = SAFE_MALLOC(cleanup, sizeof(pthread_t) * num_thrd);
-
-	semid = semget(IPC_PRIVATE, 1, IPC_CREAT | 0666);
-	if (semid < 0) {
-		perror("Semaphore creation failed  Reason:");
-		ret = -1;
-		goto out;
-	}
-
-	sop[0].sem_num = 0;
-	sop[0].sem_op = 1;
-	sop[0].sem_flg = 0;
-	if (semop(semid, sop, 1) == -1) {
-		perror("semop");
-		ret = -1;
-		goto out;
-	}
+	tst_tmpdir();
+	TST_CHECKPOINT_INIT(cleanup);
 
 	for (thrd_ndx = 0; thrd_ndx < num_thrd; thrd_ndx++) {
 		SAFE_PTHREAD_CREATE(&thrdid[thrd_ndx], NULL, alloc_mem,
@@ -374,12 +344,8 @@ int main(int argc,		/* number of input parameters                 */
 	}
 	my_yield();
 
-	sop[0].sem_op = -1;
-	if (semop(semid, sop, 1) == -1) {
-		perror("semop");
-		ret = -1;
-		goto out;
-	}
+	/* Wake up all threads */
+	TST_SAFE_CHECKPOINT_WAKE2(cleanup, 0, num_thrd);
 
 	for (thrd_ndx = 0; thrd_ndx < num_thrd; thrd_ndx++) {
 		void *th_status;	/* exit status of LWP */
-- 
2.15.0.448.gf294e3d99a-goog


  parent reply	other threads:[~2017-11-09  0:34 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-09  0:34 [LTP] [PATCH 0/6] Miscellaneous fixes for Android systems Sandeep Patil
2017-11-09  0:34 ` [LTP] [PATCH v2 1/6] syscalls/cma: Make process_vm_{readv, writev} tests bionic friendly Sandeep Patil
2017-11-10  9:14   ` Jan Stancek
2017-11-09  0:34 ` [LTP] [PATCH 2/6] mm: mallocstress: use safe macros wherever possible Sandeep Patil
2017-11-10  9:41   ` Jan Stancek
2017-11-09  0:34 ` Sandeep Patil [this message]
2017-11-09  0:34 ` [LTP] [PATCH v2 4/6] direct_io: diotest4: use getpagesize() for mmap if shm header is absent Sandeep Patil
2017-11-10  9:54   ` Jan Stancek
2017-11-09  0:34 ` [LTP] [PATCH 5/6] syscalls/mkdir03: convert to new API and use .needsrofs for EROFS check Sandeep Patil
2017-11-10 11:21   ` Jan Stancek
2017-11-09  0:34 ` [LTP] [PATCH 6/6] lib: mkfs: use 'mke2fs' on android systems for formatting filesystems Sandeep Patil
2017-11-10 14:48   ` Jan Stancek
2017-11-10 19:23     ` Sandeep Patil

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=20171109003438.130802-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