[PATCH 1/5] i386/i386: remove io_perm_deallocate()
The comment says there is nothing to deallocate and TODO_REMOVE_ME is nowhere defined, so I guess this destructor is no longer called. * i386/i386/io_perm.c (io_perm_deallocate): Remove definition. * i386/i386/io_perm.h (io_perm_deallocate): Remove prototype. (_I386_IO_PERM_H_): Add comment after endif. * i386/include/mach/i386/mach_i386.defs (io_perm_deallocate): Remove. --- i386/i386/io_perm.c | 12 i386/i386/io_perm.h | 5 + i386/include/mach/i386/mach_i386.defs | 3 --- 3 files changed, 1 insertion(+), 19 deletions(-) diff --git a/i386/i386/io_perm.c b/i386/i386/io_perm.c index 8bacb8d..dabba35 100644 --- a/i386/i386/io_perm.c +++ b/i386/i386/io_perm.c @@ -106,18 +106,6 @@ convert_port_to_io_perm (ipc_port_t port) return io_perm; } -#if TODO_REMOVE_ME -/* TODO. Fix this comment. */ -/* The destructor which is called when the last send right to a port - representing an io_perm_t object vanishes. */ -void -io_perm_deallocate (io_perm_t io_perm) -{ - /* TODO. Is there anything to deallocate in here? I don't think so, as we - don't allocate anything in `convert_port_to_io_perm'. */ -} -#endif - /* Our ``no senders'' handling routine. Deallocate the object. */ static void diff --git a/i386/i386/io_perm.h b/i386/i386/io_perm.h index a68e103..8fabb1f 100644 --- a/i386/i386/io_perm.h +++ b/i386/i386/io_perm.h @@ -58,8 +58,5 @@ typedef struct io_perm *io_perm_t; extern io_perm_t convert_port_to_io_perm (ipc_port_t); extern ipc_port_t convert_io_perm_to_port (io_perm_t); -#if TODO_REMOVE_ME -extern void io_perm_deallocate (io_perm_t); -#endif -#endif +#endif /* _I386_IO_PERM_H_ */ diff --git a/i386/include/mach/i386/mach_i386.defs b/i386/include/mach/i386/mach_i386.defs index 0703d59..cd09720 100644 --- a/i386/include/mach/i386/mach_i386.defs +++ b/i386/include/mach/i386/mach_i386.defs @@ -51,9 +51,6 @@ type io_perm_t = mach_port_t #ifKERNEL_SERVER intran: io_perm_t convert_port_to_io_perm(mach_port_t) outtran: mach_port_t convert_io_perm_to_port(io_perm_t) -#if TODO_REMOVE_ME - destructor: io_perm_deallocate(io_perm_t) -#endif #endif /* KERNEL_SERVER */ ; -- 1.8.1.4
[PATCH 3/5] i386/include/mach/i386/mach_i386_types.h: add comments after else and endif
* i386/include/mach/i386/mach_i386_types.h (MACH_KERNEL): Add comments after else and endif. --- i386/include/mach/i386/mach_i386_types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/i386/include/mach/i386/mach_i386_types.h b/i386/include/mach/i386/mach_i386_types.h index b03c0b0..b055280 100644 --- a/i386/include/mach/i386/mach_i386_types.h +++ b/i386/include/mach/i386/mach_i386_types.h @@ -47,9 +47,9 @@ typedef struct descriptor *descriptor_list_t; #ifdef MACH_KERNEL #include -#else +#else /* MACH_KERNEL */ typedef unsigned short io_port_t; typedef mach_port_t io_perm_t; -#endif +#endif /* MACH_KERNEL */ #endif /* _MACH_MACH_I386_TYPES_H_ */ -- 1.8.1.4
[PATCH 2/5] i386/include/mach/i386: add ifndefs
* i386/include/mach/i386/asm.h: Add ifndef. * i386/include/mach/i386/disk.h: Likewise. --- i386/include/mach/i386/asm.h | 4 i386/include/mach/i386/disk.h | 4 2 files changed, 8 insertions(+) diff --git a/i386/include/mach/i386/asm.h b/i386/include/mach/i386/asm.h index 3e3f48b..4e3b589 100644 --- a/i386/include/mach/i386/asm.h +++ b/i386/include/mach/i386/asm.h @@ -24,6 +24,8 @@ * the rights to redistribute these changes. */ +#ifndef _MACH_I386_ASM_H_ +#define _MACH_I386_ASM_H_ #define S_ARG0 4(%esp) #define S_ARG1 8(%esp) @@ -113,3 +115,5 @@ #defineEntry(x).globl EXT(x); .p2align TEXT_ALIGN; LEXT(x) #defineDATA(x) .globl EXT(x); .p2align DATA_ALIGN; LEXT(x) + +#endif /* _MACH_I386_ASM_H_ */ diff --git a/i386/include/mach/i386/disk.h b/i386/include/mach/i386/disk.h index 40ed4fa..1df 100644 --- a/i386/include/mach/i386/disk.h +++ b/i386/include/mach/i386/disk.h @@ -49,6 +49,9 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * disk.h */ +#ifndef _MACH_I386_DISK_H_ +#define _MACH_I386_DISK_H_ + #ifdefined(__linux__) || defined(__masix__) #define PART_DISK 4 /* partition number for entire disk */ #else @@ -118,3 +121,4 @@ struct absio { char*abs_buf; /* Sector buffer */ }; +#endif /* _MACH_I386_DISK_H_ */ -- 1.8.1.4
[PATCH 4/5] i386/include/mach/i386/rpc.h: remove file
A file with two empty unused structs. I think it's safe to remove. * i386/Makefrag.am: Remove i386/include/mach/i386/rpc.h. * i386/include/mach/i386/rpc.h: Remove file. * include/mach/rpc.h: Don't include mach/machine/rpc.h. --- i386/Makefrag.am | 1 - i386/include/mach/i386/rpc.h | 9 - include/mach/rpc.h | 1 - 3 files changed, 11 deletions(-) delete mode 100644 i386/include/mach/i386/rpc.h diff --git a/i386/Makefrag.am b/i386/Makefrag.am index 32730a5..bfcff22 100644 --- a/i386/Makefrag.am +++ b/i386/Makefrag.am @@ -227,7 +227,6 @@ include_mach_i386_HEADERS = \ i386/include/mach/i386/mach_i386_types.h \ i386/include/mach/i386/machine_types.defs \ i386/include/mach/i386/multiboot.h \ - i386/include/mach/i386/rpc.h \ i386/include/mach/i386/syscall_sw.h \ i386/include/mach/i386/thread_status.h \ i386/include/mach/i386/trap.h \ diff --git a/i386/include/mach/i386/rpc.h b/i386/include/mach/i386/rpc.h deleted file mode 100644 index 71d31fb..000 --- a/i386/include/mach/i386/rpc.h +++ /dev/null @@ -1,9 +0,0 @@ - -struct rpc_csig_action -{ -}; - -struct rpc_csig_entry -{ -}; - diff --git a/include/mach/rpc.h b/include/mach/rpc.h index d3098f8..36eb592 100644 --- a/include/mach/rpc.h +++ b/include/mach/rpc.h @@ -21,7 +21,6 @@ #include #include -#include /* * Description of a port passed up by the leaky-register RPC path -- 1.8.1.4
[PATCH 5/5] i386/i386/seg.c: remove file
MACH_INLINE is already defined where needed. Inline functions from seg.h and tss.h get compiled when included from other files, therefore seg.c serves no real purpose. I think it's safe to remove. * i386/Makefrag.am: Remove i386/i386/seg.c. * i386/i386/seg.c: Remove file. --- i386/Makefrag.am | 1 - i386/i386/seg.c | 5 - 2 files changed, 6 deletions(-) delete mode 100644 i386/i386/seg.c diff --git a/i386/Makefrag.am b/i386/Makefrag.am index bfcff22..9a87bf6 100644 --- a/i386/Makefrag.am +++ b/i386/Makefrag.am @@ -120,7 +120,6 @@ libkernel_a_SOURCES += \ i386/i386/pmap.h \ i386/i386/proc_reg.h \ i386/i386/sched_param.h \ - i386/i386/seg.c \ i386/i386/seg.h \ i386/i386/setjmp.h \ i386/i386/spl.S \ diff --git a/i386/i386/seg.c b/i386/i386/seg.c deleted file mode 100644 index d57c255..000 --- a/i386/i386/seg.c +++ /dev/null @@ -1,5 +0,0 @@ - -#define MACH_INLINE -#include "seg.h" -#include "tss.h" - -- 1.8.1.4
[PATCH] Clean up the included header files
* libihash/ihash.c: Clean up the included header files. * libshouldbeinlibc/cacheq.c: Likewise. * libshouldbeinlibc/canon-host.c: Likewise. * libshouldbeinlibc/fsysops.c: Likewise. * libshouldbeinlibc/idvec-auth.c: Likewise. * libshouldbeinlibc/idvec.c: Likewise. * libshouldbeinlibc/idvec.h: Likewise. * libshouldbeinlibc/localhost.c: Likewise. * libshouldbeinlibc/maptime.c: Likewise. * libshouldbeinlibc/nullauth.c: Likewise. * libshouldbeinlibc/portxlate.c: Likewise. * libshouldbeinlibc/shared-dom.c: Likewise. * libshouldbeinlibc/ugids-argp.c: Likewise. * libshouldbeinlibc/ugids-auth.c: Likewise. * libshouldbeinlibc/ugids-imply.c: Likewise. * libshouldbeinlibc/ugids-merge.c: Likewise. * libshouldbeinlibc/ugids-subtract.c: Likewise. * libshouldbeinlibc/ugids-verify-auth.c: Likewise. * libshouldbeinlibc/ugids-verify.c: Likewise. * libshouldbeinlibc/ugids.c: Likewise. * libshouldbeinlibc/ugids.h: Likewise. * libshouldbeinlibc/wire.c: Likewise. --- libihash/ihash.c |4 +--- libshouldbeinlibc/cacheq.c|2 +- libshouldbeinlibc/canon-host.c|1 - libshouldbeinlibc/fsysops.c |1 + libshouldbeinlibc/idvec-auth.c|1 + libshouldbeinlibc/idvec.c |3 ++- libshouldbeinlibc/idvec.h |1 - libshouldbeinlibc/localhost.c |2 +- libshouldbeinlibc/maptime.c |1 - libshouldbeinlibc/nullauth.c |2 -- libshouldbeinlibc/portxlate.c |2 +- libshouldbeinlibc/shared-dom.c|3 --- libshouldbeinlibc/ugids-argp.c|3 +-- libshouldbeinlibc/ugids-auth.c|2 +- libshouldbeinlibc/ugids-imply.c |3 ++- libshouldbeinlibc/ugids-merge.c |3 ++- libshouldbeinlibc/ugids-subtract.c|4 ++-- libshouldbeinlibc/ugids-verify-auth.c |7 +-- libshouldbeinlibc/ugids-verify.c |7 +-- libshouldbeinlibc/ugids.c |1 + libshouldbeinlibc/ugids.h |2 ++ libshouldbeinlibc/wire.c |2 +- 22 files changed, 22 insertions(+), 35 deletions(-) diff --git a/libihash/ihash.c b/libihash/ihash.c index fe9eaed..be1c580 100644 --- a/libihash/ihash.c +++ b/libihash/ihash.c @@ -26,13 +26,11 @@ #endif #include -#include #include -#include #include #include -#include +#include "ihash.h" /* The prime numbers of the form 4 * i + 3 for some i, all greater diff --git a/libshouldbeinlibc/cacheq.c b/libshouldbeinlibc/cacheq.c index 5649903..c1be59c 100644 --- a/libshouldbeinlibc/cacheq.c +++ b/libshouldbeinlibc/cacheq.c @@ -19,7 +19,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include -#include +#include #include "cacheq.h" diff --git a/libshouldbeinlibc/canon-host.c b/libshouldbeinlibc/canon-host.c index ea6c719..41068d3 100644 --- a/libshouldbeinlibc/canon-host.c +++ b/libshouldbeinlibc/canon-host.c @@ -20,7 +20,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include #include #include #include diff --git a/libshouldbeinlibc/fsysops.c b/libshouldbeinlibc/fsysops.c index f26069d..dbcae67 100644 --- a/libshouldbeinlibc/fsysops.c +++ b/libshouldbeinlibc/fsysops.c @@ -25,6 +25,7 @@ #include #include #include +#include /* Make FSYS readonly or writable. */ error_t diff --git a/libshouldbeinlibc/idvec-auth.c b/libshouldbeinlibc/idvec-auth.c index bb7f4af..1858bd6 100644 --- a/libshouldbeinlibc/idvec-auth.c +++ b/libshouldbeinlibc/idvec-auth.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "idvec.h" diff --git a/libshouldbeinlibc/idvec.c b/libshouldbeinlibc/idvec.c index d18871f..7fdee10 100644 --- a/libshouldbeinlibc/idvec.c +++ b/libshouldbeinlibc/idvec.c @@ -20,7 +20,8 @@ #include #include -#include + +#include "idvec.h" /* Return a new, empty, idvec, or NULL if there wasn't enough memory. */ struct idvec * diff --git a/libshouldbeinlibc/idvec.h b/libshouldbeinlibc/idvec.h index abbc273..d6ec155 100644 --- a/libshouldbeinlibc/idvec.h +++ b/libshouldbeinlibc/idvec.h @@ -22,7 +22,6 @@ #include #include -#include #include #include diff --git a/libshouldbeinlibc/localhost.c b/libshouldbeinlibc/localhost.c index f022511..9b7d4e0 100644 --- a/libshouldbeinlibc/localhost.c +++ b/libshouldbeinlibc/localhost.c @@ -19,9 +19,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include -#include #include #include +#include /* Return the name of the localhost. This is just a wrapper for gethostname, which takes care of allocating a big enough buffer, and caches the result diff --git a/libshouldbeinlibc/maptime.c b/libshouldbeinlibc/maptime.c index cacf4b6..971e05f 100644 --- a/libshouldbeinlibc/maptime.c +++ b/libshouldbeinlibc/maptime.c @@ -20,7 +20,6 @@ #include #include -#include #include #include "maptime.h" diff --git a/libshouldbeinlibc/n
Re: [PATCH] libports: implement lockless management of threads
Hi :) youpi wrote: > Now, there is no need for the two counters to be updated coherently, > they are used for different reasons, and don't actually interfere. Also, > mixing them into one int reduces the maximum number of threads to 65535, > which is not so big. > > So I'd say please move to using two unsigned ints. Yes, it means > two atomic operations on thread creation/destruction, but that's an > expensive operation already anyway (and we're not supposed to do that so > often). Readability of the code is more important than that :) You were right, the counters do not have to be updated coherently, here is an updated patch. Hurd packages built with them seem to work normal. Justus
[PATCH] libports: implement lockless management of threads
ports_manage_port_operations_multithread uses two values, totalthreads and nreqthreads, to manage the threads it creates. Previously a lock was used to synchronize the access to them. Use atomic operations instead. * libports/manage-multithread.c (ports_manage_port_operations_multithread): Use atomic operations instead of a lock to synchronize the access to totalthreads and nreqthreads. --- libports/manage-multithread.c | 54 +++-- 1 file changed, 19 insertions(+), 35 deletions(-) diff --git a/libports/manage-multithread.c b/libports/manage-multithread.c index 0c2da00..c19a3a8 100644 --- a/libports/manage-multithread.c +++ b/libports/manage-multithread.c @@ -91,9 +91,12 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket, int global_timeout, void (*hook)()) { - volatile unsigned int nreqthreads; - volatile unsigned int totalthreads; - pthread_spinlock_t lock = PTHREAD_SPINLOCK_INITIALIZER; + /* totalthreads is the number of total threads created. nreqthreads + is the number of threads not currently servicing any client. The + initial values account for the main thread. */ + unsigned int totalthreads = 1; + unsigned int nreqthreads = 1; + pthread_attr_t attr; auto void * thread_function (void *); @@ -120,30 +123,22 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket, /* msgt_unused = */ 0 }; - pthread_spin_lock (&lock); - assert (nreqthreads); - nreqthreads--; - if (nreqthreads != 0) - pthread_spin_unlock (&lock); - else + if (__atomic_sub_fetch (&nreqthreads, 1, __ATOMIC_RELAXED) == 0) /* No thread would be listening for requests, spawn one. */ { pthread_t pthread_id; error_t err; - totalthreads++; - nreqthreads++; - pthread_spin_unlock (&lock); + __atomic_add_fetch (&totalthreads, 1, __ATOMIC_RELAXED); + __atomic_add_fetch (&nreqthreads, 1, __ATOMIC_RELAXED); err = pthread_create (&pthread_id, &attr, thread_function, NULL); if (!err) pthread_detach (pthread_id); else { - pthread_spin_lock (&lock); - totalthreads--; - nreqthreads--; - pthread_spin_unlock (&lock); + __atomic_sub_fetch (&totalthreads, 1, __ATOMIC_RELAXED); + __atomic_sub_fetch (&nreqthreads, 1, __ATOMIC_RELAXED); /* There is not much we can do at this point. The code and design of the Hurd servers just don't handle thread creation failure. */ @@ -189,9 +184,7 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket, status = 1; } - pthread_spin_lock (&lock); - nreqthreads++; - pthread_spin_unlock (&lock); + __atomic_add_fetch (&nreqthreads, 1, __ATOMIC_RELAXED); return status; } @@ -203,8 +196,7 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket, int timeout; error_t err; - /* No need to lock as an approximation is sufficient. */ - adjust_priority (totalthreads); + adjust_priority (__atomic_load_n (&totalthreads, __ATOMIC_RELAXED)); if (hook) (*hook) (); @@ -224,30 +216,22 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket, if (master) { - pthread_spin_lock (&lock); - if (totalthreads != 1) - { - pthread_spin_unlock (&lock); - goto startover; - } + if (__atomic_load_n (&totalthreads, __ATOMIC_RELAXED) != 1) + goto startover; } else { - pthread_spin_lock (&lock); - if (nreqthreads == 1) + __atomic_sub_fetch (&totalthreads, 1, __ATOMIC_RELAXED); + if (__atomic_sub_fetch (&nreqthreads, 1, __ATOMIC_RELAXED) == 0) { /* No other thread is listening for requests, continue. */ - pthread_spin_unlock (&lock); + __atomic_add_fetch (&totalthreads, 1, __ATOMIC_RELAXED); + __atomic_add_fetch (&nreqthreads, 1, __ATOMIC_RELAXED); goto startover; } - nreqthreads--; - totalthreads--; - pthread_spin_unlock (&lock); } return NULL; } - nreqthreads = 1; - totalthreads = 1; thread_function ((void *) 1); } -- 1.7.10.4