prototyping new library synchronization
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.
Signature · 2 lines
Cyril Hrubis [email protected]
#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;
}------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi!
Quoted 5 lines
Some notes;
I assume you used
syscall(SYS_futex, ..)instead ofpthread_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.
Quoted 9 lines
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.hfor the former one).
The code is just quick test. I will desing proper library functions later.
Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ 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 [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi!
Quoted 9 lines
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__u32u32;
#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?
Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ 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 [email protected] https://lists.sourceforge.net/lists/listinfo/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.
Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ 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 [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi!
Quoted 6 lines
Quoted 3 lines
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.
Quoted 4 lines
- 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.
Quoted 2 lines
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.
Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ 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 [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list