Blame include/scoreboard.h

Packit 90a5c9
/* Licensed to the Apache Software Foundation (ASF) under one or more
Packit 90a5c9
 * contributor license agreements.  See the NOTICE file distributed with
Packit 90a5c9
 * this work for additional information regarding copyright ownership.
Packit 90a5c9
 * The ASF licenses this file to You under the Apache License, Version 2.0
Packit 90a5c9
 * (the "License"); you may not use this file except in compliance with
Packit 90a5c9
 * the License.  You may obtain a copy of the License at
Packit 90a5c9
 *
Packit 90a5c9
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit 90a5c9
 *
Packit 90a5c9
 * Unless required by applicable law or agreed to in writing, software
Packit 90a5c9
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit 90a5c9
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 90a5c9
 * See the License for the specific language governing permissions and
Packit 90a5c9
 * limitations under the License.
Packit 90a5c9
 */
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * @file  scoreboard.h
Packit 90a5c9
 * @brief Apache scoreboard library
Packit 90a5c9
 */
Packit 90a5c9
Packit 90a5c9
#ifndef APACHE_SCOREBOARD_H
Packit 90a5c9
#define APACHE_SCOREBOARD_H
Packit 90a5c9
Packit 90a5c9
#ifdef __cplusplus
Packit 90a5c9
extern "C" {
Packit 90a5c9
#endif
Packit 90a5c9
Packit 90a5c9
#if APR_HAVE_SYS_TIME_H
Packit 90a5c9
#include <sys/time.h>
Packit 90a5c9
#include <sys/times.h>
Packit 90a5c9
#endif
Packit 90a5c9
Packit 90a5c9
#include "ap_config.h"
Packit 90a5c9
#include "http_config.h"
Packit 90a5c9
#include "apr_thread_proc.h"
Packit 90a5c9
#include "apr_portable.h"
Packit 90a5c9
#include "apr_shm.h"
Packit 90a5c9
#include "apr_optional.h"
Packit 90a5c9
Packit 90a5c9
/* Scoreboard file, if there is one */
Packit 90a5c9
#ifndef DEFAULT_SCOREBOARD
Packit 90a5c9
#define DEFAULT_SCOREBOARD "logs/apache_runtime_status"
Packit 90a5c9
#endif
Packit 90a5c9
Packit 90a5c9
/* Scoreboard info on a process is, for now, kept very brief ---
Packit 90a5c9
 * just status value and pid (the latter so that the caretaker process
Packit 90a5c9
 * can properly update the scoreboard when a process dies).  We may want
Packit 90a5c9
 * to eventually add a separate set of long_score structures which would
Packit 90a5c9
 * give, for each process, the number of requests serviced, and info on
Packit 90a5c9
 * the current, or most recent, request.
Packit 90a5c9
 *
Packit 90a5c9
 * Status values:
Packit 90a5c9
 */
Packit 90a5c9
Packit 90a5c9
#define SERVER_DEAD 0
Packit 90a5c9
#define SERVER_STARTING 1       /* Server Starting up */
Packit 90a5c9
#define SERVER_READY 2          /* Waiting for connection (or accept() lock) */
Packit 90a5c9
#define SERVER_BUSY_READ 3      /* Reading a client request */
Packit 90a5c9
#define SERVER_BUSY_WRITE 4     /* Processing a client request */
Packit 90a5c9
#define SERVER_BUSY_KEEPALIVE 5 /* Waiting for more requests via keepalive */
Packit 90a5c9
#define SERVER_BUSY_LOG 6       /* Logging the request */
Packit 90a5c9
#define SERVER_BUSY_DNS 7       /* Looking up a hostname */
Packit 90a5c9
#define SERVER_CLOSING 8        /* Closing the connection */
Packit 90a5c9
#define SERVER_GRACEFUL 9       /* server is gracefully finishing request */
Packit 90a5c9
#define SERVER_IDLE_KILL 10     /* Server is cleaning up idle children. */
Packit 90a5c9
#define SERVER_NUM_STATUS 11    /* number of status settings */
Packit 90a5c9
Packit 90a5c9
/* Type used for generation indicies.  Startup and every restart cause a
Packit 90a5c9
 * new generation of children to be spawned.  Children within the same
Packit 90a5c9
 * generation share the same configuration information -- pointers to stuff
Packit 90a5c9
 * created at config time in the parent are valid across children.  However,
Packit 90a5c9
 * this can't work effectively with non-forked architectures.  So while the
Packit 90a5c9
 * arrays in the scoreboard never change between the parent and forked
Packit 90a5c9
 * children, so they do not require shm storage, the contents of the shm
Packit 90a5c9
 * may contain no pointers.
Packit 90a5c9
 */
Packit 90a5c9
typedef int ap_generation_t;
Packit 90a5c9
Packit 90a5c9
/* Is the scoreboard shared between processes or not?
Packit 90a5c9
 * Set by the MPM when the scoreboard is created.
Packit 90a5c9
 */
Packit 90a5c9
typedef enum {
Packit 90a5c9
    SB_NOT_SHARED = 1,
Packit 90a5c9
    SB_SHARED = 2
Packit 90a5c9
} ap_scoreboard_e;
Packit 90a5c9
Packit 90a5c9
/* stuff which is worker specific */
Packit 90a5c9
typedef struct worker_score worker_score;
Packit 90a5c9
struct worker_score {
Packit 90a5c9
#if APR_HAS_THREADS
Packit 90a5c9
    apr_os_thread_t tid;
Packit 90a5c9
#endif
Packit 90a5c9
    int thread_num;
Packit 90a5c9
    /* With some MPMs (e.g., worker), a worker_score can represent
Packit 90a5c9
     * a thread in a terminating process which is no longer
Packit 90a5c9
     * represented by the corresponding process_score.  These MPMs
Packit 90a5c9
     * should set pid and generation fields in the worker_score.
Packit 90a5c9
     */
Packit 90a5c9
    pid_t pid;
Packit 90a5c9
    ap_generation_t generation;
Packit 90a5c9
    unsigned char status;
Packit 90a5c9
    unsigned short conn_count;
Packit 90a5c9
    apr_off_t     conn_bytes;
Packit 90a5c9
    unsigned long access_count;
Packit 90a5c9
    apr_off_t     bytes_served;
Packit 90a5c9
    unsigned long my_access_count;
Packit 90a5c9
    apr_off_t     my_bytes_served;
Packit 90a5c9
    apr_time_t start_time;
Packit 90a5c9
    apr_time_t stop_time;
Packit 90a5c9
    apr_time_t last_used;
Packit 90a5c9
#ifdef HAVE_TIMES
Packit 90a5c9
    struct tms times;
Packit 90a5c9
#endif
Packit 90a5c9
    char client[32];            /* DEPRECATED: Keep 'em small... */
Packit 90a5c9
    char request[64];           /* We just want an idea... */
Packit 90a5c9
    char vhost[32];             /* What virtual host is being accessed? */
Packit 90a5c9
    char protocol[16];          /* What protocol is used on the connection? */
Packit 90a5c9
    apr_time_t duration;
Packit 90a5c9
    char client64[64];
Packit 90a5c9
};
Packit 90a5c9
Packit 90a5c9
typedef struct {
Packit 90a5c9
    int             server_limit;
Packit 90a5c9
    int             thread_limit;
Packit 90a5c9
    ap_generation_t running_generation; /* the generation of children which
Packit 90a5c9
                                         * should still be serving requests.
Packit 90a5c9
                                         */
Packit 90a5c9
    apr_time_t restart_time;
Packit 90a5c9
#ifdef HAVE_TIMES
Packit 90a5c9
    struct tms times;
Packit 90a5c9
#endif
Packit 90a5c9
} global_score;
Packit 90a5c9
Packit 90a5c9
/* stuff which the parent generally writes and the children rarely read */
Packit 90a5c9
typedef struct process_score process_score;
Packit 90a5c9
struct process_score {
Packit 90a5c9
    pid_t pid;
Packit 90a5c9
    ap_generation_t generation; /* generation of this child */
Packit 90a5c9
    char quiescing;         /* the process whose pid is stored above is
Packit 90a5c9
                             * going down gracefully
Packit 90a5c9
                             */
Packit 90a5c9
    char not_accepting;     /* the process is busy and is not accepting more
Packit 90a5c9
                             * connections (for async MPMs)
Packit 90a5c9
                             */
Packit 90a5c9
    apr_uint32_t connections;       /* total connections (for async MPMs) */
Packit 90a5c9
    apr_uint32_t write_completion;  /* async connections doing write completion */
Packit 90a5c9
    apr_uint32_t lingering_close;   /* async connections in lingering close */
Packit 90a5c9
    apr_uint32_t keep_alive;        /* async connections in keep alive */
Packit 90a5c9
    apr_uint32_t suspended;         /* connections suspended by some module */
Packit 90a5c9
    int bucket;             /* Listener bucket used by this child */
Packit 90a5c9
};
Packit 90a5c9
Packit 90a5c9
/* Scoreboard is now in 'local' memory, since it isn't updated once created,
Packit 90a5c9
 * even in forked architectures.  Child created-processes (non-fork) will
Packit 90a5c9
 * set up these indicies into the (possibly relocated) shmem records.
Packit 90a5c9
 */
Packit 90a5c9
typedef struct {
Packit 90a5c9
    global_score *global;
Packit 90a5c9
    process_score *parent;
Packit 90a5c9
    worker_score **servers;
Packit 90a5c9
} scoreboard;
Packit 90a5c9
Packit 90a5c9
typedef struct ap_sb_handle_t ap_sb_handle_t;
Packit 90a5c9
Packit 90a5c9
/*
Packit 90a5c9
 * Creation and deletion (internal)
Packit 90a5c9
 */
Packit 90a5c9
int ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e t);
Packit 90a5c9
apr_status_t ap_cleanup_scoreboard(void *d);
Packit 90a5c9
Packit 90a5c9
/*
Packit 90a5c9
 * APIs for MPMs and other modules
Packit 90a5c9
 */
Packit 90a5c9
AP_DECLARE(int) ap_exists_scoreboard_image(void);
Packit 90a5c9
AP_DECLARE(void) ap_increment_counts(ap_sb_handle_t *sbh, request_rec *r);
Packit 90a5c9
Packit 90a5c9
AP_DECLARE(apr_status_t) ap_reopen_scoreboard(apr_pool_t *p, apr_shm_t **shm, int detached);
Packit 90a5c9
AP_DECLARE(void) ap_init_scoreboard(void *shared_score);
Packit 90a5c9
AP_DECLARE(int) ap_calc_scoreboard_size(void);
Packit 90a5c9
Packit 90a5c9
AP_DECLARE(void) ap_create_sb_handle(ap_sb_handle_t **new_sbh, apr_pool_t *p,
Packit 90a5c9
                                     int child_num, int thread_num);
Packit 90a5c9
AP_DECLARE(void) ap_update_sb_handle(ap_sb_handle_t *sbh,
Packit 90a5c9
                                     int child_num, int thread_num);
Packit 90a5c9
Packit 90a5c9
AP_DECLARE(int) ap_find_child_by_pid(apr_proc_t *pid);
Packit 90a5c9
AP_DECLARE(int) ap_update_child_status(ap_sb_handle_t *sbh, int status, request_rec *r);
Packit 90a5c9
AP_DECLARE(int) ap_update_child_status_from_indexes(int child_num, int thread_num,
Packit 90a5c9
                                                    int status, request_rec *r);
Packit 90a5c9
AP_DECLARE(int) ap_update_child_status_from_conn(ap_sb_handle_t *sbh, int status, conn_rec *c);
Packit 90a5c9
AP_DECLARE(int) ap_update_child_status_from_server(ap_sb_handle_t *sbh, int status, 
Packit 90a5c9
                                                   conn_rec *c, server_rec *s);
Packit 90a5c9
AP_DECLARE(int) ap_update_child_status_descr(ap_sb_handle_t *sbh, int status, const char *descr);
Packit 90a5c9
Packit 90a5c9
AP_DECLARE(void) ap_time_process_request(ap_sb_handle_t *sbh, int status);
Packit 90a5c9
Packit 90a5c9
AP_DECLARE(int) ap_update_global_status(void);
Packit 90a5c9
Packit 90a5c9
AP_DECLARE(worker_score *) ap_get_scoreboard_worker(ap_sb_handle_t *sbh);
Packit 90a5c9
Packit 90a5c9
/** Return a pointer to the worker_score for a given child, thread pair.
Packit 90a5c9
 * @param child_num The child number.
Packit 90a5c9
 * @param thread_num The thread number.
Packit 90a5c9
 * @return A pointer to the worker_score structure.
Packit 90a5c9
 * @deprecated This function is deprecated, use ap_copy_scoreboard_worker instead. */
Packit 90a5c9
AP_DECLARE(worker_score *) ap_get_scoreboard_worker_from_indexes(int child_num,
Packit 90a5c9
                                                                int thread_num);
Packit 90a5c9
Packit 90a5c9
/** Copy the contents of a worker scoreboard entry.  The contents of
Packit 90a5c9
 * the worker_score structure are copied verbatim into the dest
Packit 90a5c9
 * structure.
Packit 90a5c9
 * @param dest Output parameter.
Packit 90a5c9
 * @param child_num The child number.
Packit 90a5c9
 * @param thread_num The thread number.
Packit 90a5c9
 */
Packit 90a5c9
AP_DECLARE(void) ap_copy_scoreboard_worker(worker_score *dest,
Packit 90a5c9
                                           int child_num, int thread_num);
Packit 90a5c9
Packit 90a5c9
AP_DECLARE(process_score *) ap_get_scoreboard_process(int x);
Packit 90a5c9
AP_DECLARE(global_score *) ap_get_scoreboard_global(void);
Packit 90a5c9
Packit 90a5c9
AP_DECLARE_DATA extern scoreboard *ap_scoreboard_image;
Packit 90a5c9
AP_DECLARE_DATA extern const char *ap_scoreboard_fname;
Packit 90a5c9
AP_DECLARE_DATA extern int ap_extended_status;
Packit 90a5c9
AP_DECLARE_DATA extern int ap_mod_status_reqtail;
Packit 90a5c9
Packit 90a5c9
/*
Packit 90a5c9
 * Command handlers [internal]
Packit 90a5c9
 */
Packit 90a5c9
const char *ap_set_scoreboard(cmd_parms *cmd, void *dummy, const char *arg);
Packit 90a5c9
const char *ap_set_extended_status(cmd_parms *cmd, void *dummy, int arg);
Packit 90a5c9
const char *ap_set_reqtail(cmd_parms *cmd, void *dummy, int arg);
Packit 90a5c9
Packit 90a5c9
/* Hooks */
Packit 90a5c9
/**
Packit 90a5c9
  * Hook for post scoreboard creation, pre mpm.
Packit 90a5c9
  * @param p       Apache pool to allocate from.
Packit 90a5c9
  * @param sb_type
Packit 90a5c9
  * @ingroup hooks
Packit 90a5c9
  * @return OK or DECLINE on success; anything else is a error
Packit 90a5c9
  */
Packit 90a5c9
AP_DECLARE_HOOK(int, pre_mpm, (apr_pool_t *p, ap_scoreboard_e sb_type))
Packit 90a5c9
Packit 90a5c9
/* for time_process_request() in http_main.c */
Packit 90a5c9
#define START_PREQUEST 1
Packit 90a5c9
#define STOP_PREQUEST  2
Packit 90a5c9
Packit 90a5c9
#ifdef __cplusplus
Packit 90a5c9
}
Packit 90a5c9
#endif
Packit 90a5c9
Packit 90a5c9
#endif  /* !APACHE_SCOREBOARD_H */