Re: [PATCH] kern: simple futex for gnumach (version 3)
On 22.12.2013 01:28:37, Richard Braun wrote: > On Sat, Dec 21, 2013 at 11:29:34PM +0100, Marin Ramesa wrote: > > On 21.12.2013 23:20:43, Richard Braun wrote: > > > How about adding everything necessary to actually test it from > > > userspace ? > > > > Sure, what needs to be added? I don't have the conditions to test > > this. I earlier wrote some proof-of-concept stuff that might be > > used as a test, but I don't know how. > > Learn about MiG and how to write RPCs. There is a lot you can find on > the wiki and through search engines. If possible, don't create an > ioctl-style of call, with many possible behaviours through the same > entry point, but make several distinct RPCs instead, then add them to > include/mach/gnumach.defs. Look at how it's done for existing RPCs, > but make sure you read and understand the documentation about MiG and > Mach IPC if you want to work on such low-level stuff. OK, I'm reading the documentation. In the meantime I have defined several simple RPCs for testing purposes. I will send the updated patch shortly.
[PATCH] kern: simple futex for gnumach (version 4)
GPL license included, more bugs fixed and RPCs defined. --- Makefrag.am | 2 + include/mach/gnumach.defs | 26 +++ kern/futex.c | 405 ++ kern/futex.h | 108 + 4 files changed, 541 insertions(+) create mode 100644 kern/futex.c create mode 100644 kern/futex.h diff --git a/Makefrag.am b/Makefrag.am index c1387bd..e43f882 100644 --- a/Makefrag.am +++ b/Makefrag.am @@ -145,6 +145,8 @@ libkernel_a_SOURCES += \ kern/eventcount.h \ kern/exception.c \ kern/exception.h \ + kern/futex.c \ + kern/futex.h \ kern/host.c \ kern/host.h \ kern/ipc_host.c \ diff --git a/include/mach/gnumach.defs b/include/mach/gnumach.defs index 12c4e99..8c5ea4b 100644 --- a/include/mach/gnumach.defs +++ b/include/mach/gnumach.defs @@ -63,3 +63,29 @@ simpleroutine thread_terminate_release( reply_port : mach_port_name_t; address : vm_address_t; size: vm_size_t); + +/* + * When operation equals FUTEX_WAIT, this is a method for a thread to wait for a + * change of value at a given address. + * + * When operation equals FUTEX_WAKE, this is a method for waking up a number + * (specified by the argument value) of threads waiting for a change of value + * at a given address (threads that are in FUTEX_WAIT). + */ + +simpleroutine futex_rpc( + thread : thread_t; + address : pointer_t; + value : int; + operation : int); + +simpleroutine futex_wait_rpc( + thread : thread_t; + address : pointer_t; + value : int); + +simpleroutine futex_wake_rpc( + thread : thread_t; + address : pointer_t; + thread_num : int); + diff --git a/kern/futex.c b/kern/futex.c new file mode 100644 index 000..7860265 --- /dev/null +++ b/kern/futex.c @@ -0,0 +1,405 @@ +/* + * Copyright (C) 2013 Free Software Foundation, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Author: Marin Ramesa + */ + +/* + * Fast userspace locking + * + */ + +#include +#include + +static futex_hash_table_t table = NULL; +static unsigned int prev_hash_val = 0; + +/* + * When operation equals FUTEX_WAIT, this is a method for a thread to wait for a + * change of value at a given address. + * + * When operation equals FUTEX_WAKE, this is a method for waking up a number + * (specified by the argument value) of threads waiting for a change of value + * at a given address (threads that are in FUTEX_WAIT). + * + * Return values: + * FUTEX_RESUMED_BY_WAKE - thread has been resumed by FUTEX_WAKE + * FUTEX_NO_THREAD_SUSPENDED - value at the address has been changed while inside + * FUTEX_WAIT and no thread has been suspended + * FUTEX_SOME_NUMBER_RESUMED - value threads have been resumed by FUTEX_WAKE + * FUTEX_NO_THREAD - FUTEX_WAKE did not found a suspended thread at the passed address + * FUTEX_EXISTS - futex already exists at the new address + * FUTEX_MEMORY_ERROR - memory error + * FUTEX_UNKNOWN_OPERATION - unknown operation + * FUTEX_RESOURCE_SHORTAGE - no virtual memory or the mutex is not per-process + * + */ +int futex(int *address, int value, int operation) +{ + switch (operation) { + case FUTEX_WAIT: + return futex_wait(address, value); + case FUTEX_WAKE: + return futex_wake(address, value); + default: + return FUTEX_UNKNOWN_OPERATION; + } +} + +int futex_init(int *address, futex_t futex, futex_hash_table_t hash_table, unsigned int hash_val) +{ + simple_lock_init(&futex->futex_wait_lock); + + if (hash_table == NULL) { + hash_table = futex_hash_table_init(INITIAL_HASH_TABLE_SIZE, current_thread()->task); + if (hash_table == NULL) + return FUTEX_RESOURCE_SHORTAGE; + } + + if ((hash_table->futex_elements = + (futex_t)kalloc((hash_table->size + 1) * sizeof(struct futex))) == NULL) { + + return FUTEX_RESOURCE_SHORTAGE
Re: [PATCH] kern: simple futex for gnumach (version 3)
On Sun, Dec 22, 2013 at 03:32:42PM +0100, Marin Ramesa wrote: > On 22.12.2013 01:28:37, Richard Braun wrote: > > On Sat, Dec 21, 2013 at 11:29:34PM +0100, Marin Ramesa wrote: > > > On 21.12.2013 23:20:43, Richard Braun wrote: > > > > How about adding everything necessary to actually test it from > > > > userspace ? > > > > > > Sure, what needs to be added? I don't have the conditions to test > > > this. I earlier wrote some proof-of-concept stuff that might be > > > used as a test, but I don't know how. > > > > Learn about MiG and how to write RPCs. There is a lot you can find on > > the wiki and through search engines. If possible, don't create an > > ioctl-style of call, with many possible behaviours through the same > > entry point, but make several distinct RPCs instead, then add them to > > include/mach/gnumach.defs. Look at how it's done for existing RPCs, > > but make sure you read and understand the documentation about MiG and > > Mach IPC if you want to work on such low-level stuff. > > OK, I'm reading the documentation. In the meantime I have defined > several simple RPCs for testing purposes. I will send the updated patch > shortly. Test it yourself from userspace before you resubmit. -- Richard Braun
Re: [PATCH] kern: simple futex for gnumach (version 3)
On 22.12.2013 17:56:32, Richard Braun wrote: > > OK, I'm reading the documentation. In the meantime I have defined > > several simple RPCs for testing purposes. I will send the updated > > patch shortly. > > Test it yourself from userspace before you resubmit. That's the problem. I don't know how to test this. How to boot up a modified gnumach and then execute a program over it? I tried with QEMU, but I can't get it to work.
Re: [PATCH] kern: simple futex for gnumach (version 3)
On Sun, Dec 22, 2013 at 06:22:03PM +0100, Marin Ramesa wrote: > On 22.12.2013 17:56:32, Richard Braun wrote: > > Test it yourself from userspace before you resubmit. > > That's the problem. I don't know how to test this. How to boot up a > modified gnumach and then execute a program over it? I tried with QEMU, > but I can't get it to work. Are you saying you've been sending us patches without ever testing them ? -- Richard Braun
Re: [PATCH] kern: simple futex for gnumach (version 3)
On 22.12.2013 18:25:10, Richard Braun wrote: > On Sun, Dec 22, 2013 at 06:22:03PM +0100, Marin Ramesa wrote: > > On 22.12.2013 17:56:32, Richard Braun wrote: > > > Test it yourself from userspace before you resubmit. > > > > That's the problem. I don't know how to test this. How to boot up a > > modified gnumach and then execute a program over it? I tried with > > QEMU, but I can't get it to work. > > Are you saying you've been sending us patches without ever > testing them ? Yes. But that's different, that's just cleaning the code. Removing forward declarations and unused variables doesn't change the behavior. Now, I need to test this, but I don't know how.
Re: [PATCH] kern: simple futex for gnumach (version 3)
On Sun, Dec 22, 2013 at 06:57:50PM +0100, Marin Ramesa wrote: > On 22.12.2013 18:25:10, Richard Braun wrote: > > Are you saying you've been sending us patches without ever > > testing them ? > > Yes. But that's different, that's just cleaning the code. Removing > forward declarations and unused variables doesn't change the behavior. > Now, I need to test this, but I don't know how. Cleaning isn't supposed to change the behaviour, but that sometimes happens, in particular with the kind of optimizations applied by a modern compiler such as gcc, so please, test before sending... -- Richard Braun
Re: [PATCH] kern: simple futex for gnumach (version 3)
On Sun, Dec 22, 2013 at 06:22:03PM +0100, Marin Ramesa wrote: > On 22.12.2013 17:56:32, Richard Braun wrote: > > > OK, I'm reading the documentation. In the meantime I have defined > > > several simple RPCs for testing purposes. I will send the updated > > > patch shortly. > > > > Test it yourself from userspace before you resubmit. > > That's the problem. I don't know how to test this. How to boot up a > modified gnumach and then execute a program over it? I tried with QEMU, > but I can't get it to work. Whether it's in a virtual machine or a real one doesn't matter at all. On Debian, simply copy the gnumach binary to /boot and run update-grub. You'll get a new entry at boot time for your kernel. -- Richard Braun
Re: [PATCH] kern: simple futex for gnumach (version 3)
On 22/12/13 22:04:15, Richard Braun wrote: > Whether it's in a virtual machine or a real one doesn't matter at > all. On Debian, simply copy the gnumach binary to /boot and run > update-grub. You'll get a new entry at boot time for your kernel. I don't have the update-grub command (I'm not using Debian). So I have to modify files by hand and when I write 'multiboot /boot/gnumach.gz' I get a 'invalid magic number' error at boot time. Can you please show me the gnumach menuentry generated by grub? Thanks.