From: Cyril Hrubis <chrubis@suse.cz>
To: ltp-list@lists.sourceforge.net
Cc: Jiri Jaburek <jjaburek@redhat.com>
Subject: [LTP] prototyping new library synchronization
Date: Thu, 12 Feb 2015 17:59:22 +0100 [thread overview]
Message-ID: <20150212165921.GA27008@rei> (raw)
[-- 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
next reply other threads:[~2015-02-12 16:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-12 16:59 Cyril Hrubis [this message]
[not found] ` <54DDD96D.3020304@redhat.com>
2015-02-13 16:29 ` [LTP] prototyping new library synchronization 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
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=20150212165921.GA27008@rei \
--to=chrubis@suse.cz \
--cc=jjaburek@redhat.com \
--cc=ltp-list@lists.sourceforge.net \
/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