All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] kernel/mem/mtest06/mmap1.c: Update the synchronization logic
@ 2014-05-14 14:16 shuang.qiu
  2014-06-05 11:02 ` chrubis
  0 siblings, 1 reply; 2+ messages in thread
From: shuang.qiu @ 2014-05-14 14:16 UTC (permalink / raw)
  To: ltp-list

From: Shuang Qiu <shuang.qiu@oracle.com>

Currently in mmap1.c,the reader and writer cannot synchronize with each other.
Added one more lock and update the logic a little to make it work.

Signed-off-by: Shuang Qiu <shuang.qiu@oracle.com>
---
 testcases/kernel/mem/mtest06/mmap1.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/testcases/kernel/mem/mtest06/mmap1.c b/testcases/kernel/mem/mtest06/mmap1.c
index cd1127f..6bdbf75 100644
--- a/testcases/kernel/mem/mtest06/mmap1.c
+++ b/testcases/kernel/mem/mtest06/mmap1.c
@@ -65,6 +65,7 @@ static int verbose_print = 0;
 static char *volatile map_address;
 static jmp_buf jmpbuf;
 static volatile char read_lock = 0;
+static volatile char write_lock = 0;
 
 char *TCID = "mmap1";
 int TST_TOTAL = 1;
@@ -157,6 +158,7 @@ void *map_write_unmap(void *ptr)
 
 		while (read_lock)
 			sched_yield();
+		read_lock = 1;
 
 		sigfillset(&sa.sa_mask);
 		sigdelset(&sa.sa_mask, SIGSEGV);
@@ -197,6 +199,7 @@ void *map_write_unmap(void *ptr)
 			perror("map_write_unmap(): mmap()");
 			pthread_exit((void *)1);
 		}
+		write_lock = 0;
 	}
 
 	pthread_exit((void *)0);
@@ -218,6 +221,9 @@ void *read_mem(void *ptr)
 
 	for (i = 0; i < args[2]; i++) {
 
+		while (write_lock)
+			sched_yield();
+		write_lock = 1;
 		if (verbose_print)
 			tst_resm(TINFO, "read_mem() in while loop %ld times "
 				 "to go %ld times", i, args[2]);
@@ -229,20 +235,17 @@ void *read_mem(void *ptr)
 					 "a read after an unmap");
 		} else {
 			if (verbose_print) {
-				read_lock = 1;
 				tst_resm(TINFO,
 					 "read_mem(): content of memory: %s",
 					 (char *)map_address);
-				read_lock = 0;
 			}
 			for (j = 0; j < args[1]; j++) {
-				read_lock = 1;
 				if (map_address[j] != 'a')
 					pthread_exit((void *)-1);
-				read_lock = 0;
 				if (random() % 2)
 					sched_yield();
 			}
+			read_lock = 0;
 		}
 	}
 
-- 
1.7.9.5


------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [LTP] [PATCH] kernel/mem/mtest06/mmap1.c: Update the synchronization logic
  2014-05-14 14:16 [LTP] [PATCH] kernel/mem/mtest06/mmap1.c: Update the synchronization logic shuang.qiu
@ 2014-06-05 11:02 ` chrubis
  0 siblings, 0 replies; 2+ messages in thread
From: chrubis @ 2014-06-05 11:02 UTC (permalink / raw)
  To: shuang.qiu; +Cc: ltp-list

Hi!
> Currently in mmap1.c,the reader and writer cannot synchronize with each other.
> Added one more lock and update the logic a little to make it work.
> 
> Signed-off-by: Shuang Qiu <shuang.qiu@oracle.com>
> ---
>  testcases/kernel/mem/mtest06/mmap1.c |   11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/testcases/kernel/mem/mtest06/mmap1.c b/testcases/kernel/mem/mtest06/mmap1.c
> index cd1127f..6bdbf75 100644
> --- a/testcases/kernel/mem/mtest06/mmap1.c
> +++ b/testcases/kernel/mem/mtest06/mmap1.c
> @@ -65,6 +65,7 @@ static int verbose_print = 0;
>  static char *volatile map_address;
>  static jmp_buf jmpbuf;
>  static volatile char read_lock = 0;
> +static volatile char write_lock = 0;
>  
>  char *TCID = "mmap1";
>  int TST_TOTAL = 1;
> @@ -157,6 +158,7 @@ void *map_write_unmap(void *ptr)
>  
>  		while (read_lock)
>  			sched_yield();
> +		read_lock = 1;

This is obviously wrong because combined with the removal of the
read_lock = 1 from the read_mem() thread you just disabled the writer
thread entirely.

>  		sigfillset(&sa.sa_mask);
>  		sigdelset(&sa.sa_mask, SIGSEGV);
> @@ -197,6 +199,7 @@ void *map_write_unmap(void *ptr)
>  			perror("map_write_unmap(): mmap()");
>  			pthread_exit((void *)1);
>  		}
> +		write_lock = 0;
>  	}
>  
>  	pthread_exit((void *)0);
> @@ -218,6 +221,9 @@ void *read_mem(void *ptr)
>  
>  	for (i = 0; i < args[2]; i++) {
>  
> +		while (write_lock)
> +			sched_yield();
> +		write_lock = 1;

The same here, this disables the thread.


Can you describe precisely what race condition are you trying to fix?

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their 
applications. Written by three acclaimed leaders in the field, 
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-06-05 11:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-14 14:16 [LTP] [PATCH] kernel/mem/mtest06/mmap1.c: Update the synchronization logic shuang.qiu
2014-06-05 11:02 ` chrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.