root/src/eventer/eventer_jobq.h

Revision 09ecd288337978ca01c842684ec58b4bad68ce6e, 3.8 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 3 years ago)

This patch does a lot, all refs #351

  • fix up the test harness to support noitd restarts and
    expected crashes
  • Add different cancellation methodologies to the jobq implemntation
    • "evil_brutal" which is the old siglongjmp way.
    • "cancel_deferred" which uses pthread_cancel w/ CANCEL_DEFERRED
    • "cancel_asynch" which uses pthread_cancel w/ CANCEL_ASYNCHRONOUS
  • Add a game over scenario is the cooperative cancellation mechanisms
    don't work and end up exhausting all the threads in a pool.
  • Reduce the minimum check period set via REST to 1s to enable better
    testing. NOTE: maybe this should be much smaller even.
  • Change the thread pool system to spawn as new jobs are queued.
    This isn't automatic demand-driven sizing, but rather we don't
    start the (N) threads until (N) events arrive (not necessarily
    concurrently).
  • Added a test_abort module that runs different types of faux workloads
    to assist in testing the functional correctness of each method.
    Workloads include, variable work time, variable method of cancellation
    type and interruptable (nanosleep) and uninterruptable (compute).
  • Added fairly thorough tests for each method under each workload
    condition. Tested on darwin (finding cancel_asynch to not work well).
    Needs testing on other platforms.
  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *     * Redistributions of source code must retain the above copyright
10  *       notice, this list of conditions and the following disclaimer.
11  *     * Redistributions in binary form must reproduce the above
12  *       copyright notice, this list of conditions and the following
13  *       disclaimer in the documentation and/or other materials provided
14  *       with the distribution.
15  *     * Neither the name OmniTI Computer Consulting, Inc. nor the names
16  *       of its contributors may be used to endorse or promote products
17  *       derived from this software without specific prior written
18  *       permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _NOIT_JOBQUEUE_H
34 #define _NOIT_JOBQUEUE_H
35
36 #include "noit_defines.h"
37 #include "eventer/eventer.h"
38 #include "utils/noit_atomic.h"
39 #include "utils/noit_sem.h"
40
41 #include <pthread.h>
42 #include <setjmp.h>
43
44 /*
45  * This is for jobs that would block and need more forceful timeouts.
46  */
47
48 typedef struct _eventer_job_t {
49   pthread_mutex_t         lock;
50   struct timeval          create_time;
51   struct timeval          start_time;
52   struct timeval          finish_time;
53   pthread_t               executor;
54   eventer_t               timeout_event;
55   eventer_t               fd_event;
56   int                     timeout_triggered; /* set, if it expires in-flight */
57   noit_atomic32_t         inflight;
58   noit_atomic32_t         has_cleanedup;
59   void                  (*cleanup)(struct _eventer_job_t *);
60   struct _eventer_job_t  *next;
61   struct _eventer_jobq_t *jobq;
62 } eventer_job_t;
63
64 typedef struct _eventer_jobq_t {
65   const char             *queue_name;
66   pthread_mutex_t         lock;
67   sem_t                   semaphore;
68   noit_atomic32_t         concurrency;
69   noit_atomic32_t         desired_concurrency;
70   noit_atomic32_t         pending_cancels;
71   eventer_job_t          *headq;
72   eventer_job_t          *tailq;
73   pthread_key_t           threadenv;
74   pthread_key_t           activejob;
75   struct _eventer_jobq_t *backq;
76 } eventer_jobq_t;
77
78 int eventer_jobq_init(eventer_jobq_t *jobq, const char *queue_name);
79 eventer_jobq_t *eventer_jobq_retrieve(const char *name);
80 void eventer_jobq_enqueue(eventer_jobq_t *jobq, eventer_job_t *job);
81 eventer_job_t *eventer_jobq_dequeue(eventer_jobq_t *jobq);
82 eventer_job_t *eventer_jobq_dequeue_nowait(eventer_jobq_t *jobq);
83 void eventer_jobq_destroy(eventer_jobq_t *jobq);
84 int eventer_jobq_execute_timeout(eventer_t e, int mask, void *closure,
85                                  struct timeval *now);
86 int eventer_jobq_consume_available(eventer_t e, int mask, void *closure,
87                                    struct timeval *now);
88 void eventer_jobq_increase_concurrency(eventer_jobq_t *jobq);
89 void eventer_jobq_decrease_concurrency(eventer_jobq_t *jobq);
90 void *eventer_jobq_consumer(eventer_jobq_t *jobq);
91 void eventer_jobq_process_each(void (*func)(eventer_jobq_t *, void *), void *);
92
93 #endif
Note: See TracBrowser for help on using the browser.