public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] prototyping new library synchronization
@ 2015-02-12 16:59 Cyril Hrubis
       [not found] ` <54DDD96D.3020304@redhat.com>
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Cyril Hrubis @ 2015-02-12 16:59 UTC (permalink / raw)
  To: ltp-list; +Cc: Jiri Jaburek

[-- Attachment #1: Type: text/plain, Size: 737 bytes --]

Hi!
Code prototype follows. It uses mutexes and can be used with up to
page_size/sizeof(uint32) pairs. I've checked that it compiles fine and
works back to kernel 2.6.11 compiled in year 2005, which should be more
than enough.

It uses a regular file as a backing for the shared pages which makes it
even easier to replace the fifo based solution we have. All that is
needed is to map the same file created in the test temporary directory
just like the fifo does.

Please anone that uses LTP, check that the code compiles and works for
fine on all distributions you care for. Once that is checked, I will
write the new library functions based on this code and convert all the
test to the new interface.

-- 
Cyril Hrubis
chrubis@suse.cz

[-- Attachment #2: tfutex.c --]
[-- Type: text/x-c, Size: 1550 bytes --]

#include <fcntl.h>
#include <stdint.h>
#include <unistd.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/syscall.h>
#include <linux/futex.h>

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>

typedef volatile uint32_t futex_t;

static futex_t *futexes;

static void finit(void)
{
	int fd;

	fd = open("/tmp/syncronization_futex_base_file", O_RDWR | O_CREAT, 0666);

	if (fd < 0) {
		fprintf(stderr, "open(): %s\n", strerror(errno));
		exit(1);
	}

	if (ftruncate(fd, getpagesize())) {
		fprintf(stderr, "ftruncate(): %s\n", strerror(errno));
		exit(1);
	}

	futexes = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

	if (futexes == MAP_FAILED) {
		fprintf(stderr, "mmap(): %s\n", strerror(errno));
		exit(1);
	}
}

static void fwait(unsigned int id, struct timespec *timeout)
{
	syscall(SYS_futex, &futexes[id], FUTEX_WAIT, futexes[id], timeout);
}

static void fwake(unsigned int id)
{
	int ret;

	do {
		ret = syscall(SYS_futex, &futexes[id], FUTEX_WAKE, INT_MAX, NULL);
		usleep(100);
	} while (ret == 0);
}

int main(void)
{
	int pid;

	finit();

	pid = fork();

	switch (pid) {
	case 0:
		fprintf(stderr, "Child calls wait\n");
		fwait(0, NULL);
		fprintf(stderr, "Child woken up\n");
	break;
	case -1:
		fprintf(stderr, "fork(): %s\n", strerror(errno));
	break;
	default:
		/* uncomment to change ordering */
		//usleep(100);
		fprintf(stderr, "Parent calls wake\n");
		fwake(0);
		fprintf(stderr, "Parent finishes\n");
	}

	return 0;
}

[-- Attachment #3: Type: text/plain, Size: 441 bytes --]

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] prototyping new library synchronization
       [not found] ` <54DDD96D.3020304@redhat.com>
@ 2015-02-13 16:29   ` Cyril Hrubis
  0 siblings, 0 replies; 5+ messages in thread
From: Cyril Hrubis @ 2015-02-13 16:29 UTC (permalink / raw)
  To: Jiri Jaburek; +Cc: ltp-list

Hi!
> Some notes;
> 
> I assume you used syscall(SYS_futex, ..) instead of pthread_mutex (which
> uses it internally) because of the linking simplicity, right?
> Fair tradeoff.

Not only. As far as I know pthread_mutexes use private futexes and as
far as I understand these these will not work with forked processes. Or
at least are not expected to be used that way I haven't actually tried
it.

> No idea what you're going to use for the final code, but I'd default to
> 
>   perror("open()");
> 
> instead of
> 
>   fprintf(stderr, "open(): %s\n", strerror(errno));
> 
> (you also don't need errno.h for the former one).

The code is just quick test. I will desing proper library functions
later.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] prototyping new library synchronization
       [not found] ` <234052409.12380641.1424077348107.JavaMail.zimbra@redhat.com>
@ 2015-02-16 10:50   ` Cyril Hrubis
  0 siblings, 0 replies; 5+ messages in thread
From: Cyril Hrubis @ 2015-02-16 10:50 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list, Jiri Jaburek

Hi!
> it compiles fine for me everywhere, except RHEL5.3,
> which appears to have problem with "u32". It compiled only after
> I did following:
> 
> #include <linux/types.h>
> #ifndef u32
> typedef __u32 u32;
> #endif
> #include <linux/futex.h>

Looks like a bug in the futex.h header. But I guess that we can live
with the conditional typedef as well (with a proper comment why it's
there).

Have you tried to run the resulting binary as well? Have it worked fine?

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] prototyping new library synchronization
  2015-02-12 16:59 [LTP] prototyping new library synchronization Cyril Hrubis
       [not found] ` <54DDD96D.3020304@redhat.com>
       [not found] ` <234052409.12380641.1424077348107.JavaMail.zimbra@redhat.com>
@ 2015-02-18 11:14 ` Cyril Hrubis
       [not found]   ` <1801010187.15219396.1424359733914.JavaMail.zimbra@redhat.com>
  2 siblings, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2015-02-18 11:14 UTC (permalink / raw)
  To: ltp-list

Hi!
The new checkpoint code is commited in:

https://github.com/linux-test-project/ltp/commit/9f136a48c6205362cd8d35c726491ca93cb16514

Everybody please test that it compiles and works fine.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] prototyping new library synchronization
       [not found]   ` <1801010187.15219396.1424359733914.JavaMail.zimbra@redhat.com>
@ 2015-02-19 15:35     ` Cyril Hrubis
  0 siblings, 0 replies; 5+ messages in thread
From: Cyril Hrubis @ 2015-02-19 15:35 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list

Hi!
> > https://github.com/linux-test-project/ltp/commit/9f136a48c6205362cd8d35c726491ca93cb16514
> > 
> > Everybody please test that it compiles and works fine.
> 
> - one small compilation problem
>    https://github.com/linux-test-project/ltp/commit/1261dd6817bb320081fa0237361bbb491a028c65

Thanks for fixing it.

> - gitignore could be expanded for:
>     lib/tests/tst_checkpoint
>     lib/tests/tst_checkpoint_wait_timeout
>     lib/tests/tst_checkpoint_wake_timeout

Ah, sorry I've forgotten to update the top level .gitignore file. The
old test names should have been removed, new added. I've pushed fix for
that now.

> I compiled and ran subset of tests (syscalls mostly) on RHEL5.6/6.0/7.1. There were some failures,
> but those all appear to be actual bugs present in older kernels.

Sounds good, thanks for the testing.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2015-02-19 15:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-12 16:59 [LTP] prototyping new library synchronization Cyril Hrubis
     [not found] ` <54DDD96D.3020304@redhat.com>
2015-02-13 16:29   ` Cyril Hrubis
     [not found] ` <234052409.12380641.1424077348107.JavaMail.zimbra@redhat.com>
2015-02-16 10:50   ` Cyril Hrubis
2015-02-18 11:14 ` Cyril Hrubis
     [not found]   ` <1801010187.15219396.1424359733914.JavaMail.zimbra@redhat.com>
2015-02-19 15:35     ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox