~madcoder/pwqr.git
8 years agoImprove documentation, improve has_pollin handling. master
Pierre Habouzit [Sun, 15 Jan 2012 20:59:27 +0000 (21:59 +0100)]
Improve documentation, improve has_pollin handling.

Sometimes writing documentation helps finding design issues :P

Signed-off-by: Pierre Habouzit <pierre.habouzit@intersec.com>
8 years agoimprove tester
Pierre Habouzit [Sun, 15 Jan 2012 20:13:30 +0000 (21:13 +0100)]
improve tester

Signed-off-by: Pierre Habouzit <pierre.habouzit@intersec.com>
8 years agofix a few more bugs detected by the simple tester.
Pierre Habouzit [Sun, 15 Jan 2012 20:00:49 +0000 (21:00 +0100)]
fix a few more bugs detected by the simple tester.

Signed-off-by: Pierre Habouzit <pierre.habouzit@intersec.com>
8 years agoFix poll, thanks to the simple test program.
Pierre Habouzit [Sun, 15 Jan 2012 19:17:40 +0000 (20:17 +0100)]
Fix poll, thanks to the simple test program.

Signed-off-by: Pierre Habouzit <pierre.habouzit@intersec.com>
8 years agoAdd stupid tests.
Pierre Habouzit [Sun, 15 Jan 2012 19:06:25 +0000 (20:06 +0100)]
Add stupid tests.

Signed-off-by: Pierre Habouzit <pierre.habouzit@intersec.com>
8 years agostreamlining.
Pierre Habouzit [Sun, 15 Jan 2012 17:42:37 +0000 (18:42 +0100)]
streamlining.

renamespace public PWQR_* macros
document stuff
be more efficient for vanilla kernels

Signed-off-by: Pierre Habouzit <pierre.habouzit@intersec.com>
8 years agoUpdate the lib to include polling on the pwqrfd.
Pierre Habouzit [Sun, 15 Jan 2012 12:57:42 +0000 (13:57 +0100)]
Update the lib to include polling on the pwqrfd.

This introduces an overcommit_count.  This counter is set by a poller
thread (or an event loop, see pwqr_overcommit_poll_loop.

On the other side, normal jobs consumers check this counter, when non 0
they XCHG it with 0 (to be sure they are alone evaluating the overcommit
ratio), ask the kernel for the current overcommit, substract one, put it
as the new counter and go to be parked.

Of course when going to be parked the threads may actually find overcommit
jobs or similar, then the polling thread will reset the overcommit_count
again in that case and this will start again. In the more common case, the
thread will be parked directly and we hope it'll be enough.

When a thread goes out of PARK mode without signaling an EDQUOT condition,
we forcefully set the overcommit_count to zero.

This should hopefully take care of the downsizing of the pool in case of
overcommit for too long. As a side note, the kernel only signals
overcommit when it's lasting for more than PWQR_OC_DELAY (which is 1/20 of
a second as of this commit), which lets plenty of time for the overcommit
to be reduced in other more "natural" ways.

Signed-off-by: Pierre Habouzit <pierre.habouzit@intersec.com>
8 years agoimplement poll and read
Pierre Habouzit [Sun, 15 Jan 2012 09:31:44 +0000 (10:31 +0100)]
implement poll and read

No matter if we implement some other kind of dirty notification mechanism,
it feels right to have pwqr pollable for overcommit.

Documentation:
- drop the "in kernel unpark" method, it sucks
- migrate to using non blocking "read" for the probing method.
- document the pollability and how read works in the pwqr_create "manpage".

lib:
- implement epoll_create with flags. It requires a kernel supporting
  O_NONBLOCK/O_CLOEXEC flags to open(), I've been too lazy to implement
  the emulation yet.

Signed-off-by: Pierre Habouzit <pierre.habouzit@intersec.com>
8 years agodo not forbid other processes to use the pwqr fd.
Pierre Habouzit [Sun, 15 Jan 2012 08:03:38 +0000 (09:03 +0100)]
do not forbid other processes to use the pwqr fd.

Actually it could even make sense, to have stuff running in the background
and wanting to be accounted in the overall load of this process group (for
example some kind of snapshot procedure that would be forke()d in the
background).

Plus this restriction was kind of un-kernelish.

Signed-off-by: Pierre Habouzit <pierre.habouzit@intersec.com>
8 years agoPrepare code to plug the overcommit notification.
Pierre Habouzit [Sun, 15 Jan 2012 07:51:17 +0000 (08:51 +0100)]
Prepare code to plug the overcommit notification.

Let the pwqr_sb have a state (instead of yes/no "dead" flag) being among:
- DEAD
- NONE (normal)
- UC (undercommit)
- OC (overcommit).

In the last two modes a timer is fired.

In the UC case, if the timer fires, we unpark a thread (if any, and if no
overcommit unpark is pending) as before.

In the OC case for now we do nothing.

Signed-off-by: Pierre Habouzit <pierre.habouzit@intersec.com>
8 years agocheck the `addr` argument for PWQ_WAIT is aligned to an integer.
Pierre Habouzit [Sat, 14 Jan 2012 21:28:39 +0000 (22:28 +0100)]
check the `addr` argument for PWQ_WAIT is aligned to an integer.

Signed-off-by: Pierre Habouzit <pierre.habouzit@intersec.com>
8 years agofix asciidoc
Pierre Habouzit [Sat, 14 Jan 2012 20:46:23 +0000 (21:46 +0100)]
fix asciidoc

Signed-off-by: Pierre Habouzit <pierre.habouzit@intersec.com>
8 years agorework the quarantine: it doesn't really need to be accounted.
Pierre Habouzit [Sat, 14 Jan 2012 20:36:45 +0000 (21:36 +0100)]
rework the quarantine: it doesn't really need to be accounted.

The notion of quarantine is purely virtual and we only care about it at
WAKE time. It significantly simplifies the fastpath of our code, namely
__pwqr_sb_update_state.

Also allow the WAKE command to directly unpark threads if that fits with
the concurrency level. I don't really expect userland to really use that,
but it doesn't break anything and makes sense.

Signed-off-by: Pierre Habouzit <pierre.habouzit@intersec.com>
8 years agoImplement the reluctancy to unpark threads.
Pierre Habouzit [Sat, 14 Jan 2012 20:01:47 +0000 (21:01 +0100)]
Implement the reluctancy to unpark threads.

This means that a pool needs to undercommit for 0.1s before we allow it to
grow its number of in-pool threads.

Document the last todo: how to reduce the pool when we're overcommiting.
Right now we only pray that userland will put some threads to WAIT. But
frankly it's less than ideal. With the repulsion to start a new thread we
hope though that the overcommit will never ever grow out of proportion for
now.

Signed-off-by: Pierre Habouzit <pierre.habouzit@intersec.com>
8 years agotypo
Pierre Habouzit [Sat, 14 Jan 2012 19:19:46 +0000 (20:19 +0100)]
typo

Signed-off-by: Pierre Habouzit <pierre.habouzit@intersec.com>
8 years agoWrite some nice documentation about the design and APIs.
Pierre Habouzit [Sat, 14 Jan 2012 18:22:49 +0000 (19:22 +0100)]
Write some nice documentation about the design and APIs.

Signed-off-by: Pierre Habouzit <pierre.habouzit@intersec.com>
8 years agoPthread Workqueue Regulator (pwqr) initial commit.
Pierre Habouzit [Fri, 16 Dec 2011 15:24:24 +0000 (16:24 +0100)]
Pthread Workqueue Regulator (pwqr) initial commit.

This contains an alpha/beta quality kernel proof-of-concept driver, plus
some code concepts to wrap the syscall in lib/libpwqr.c

Signed-off-by: Pierre Habouzit <pierre.habouzit@intersec.com>