Back to index

php5  5.3.10
Classes | Defines | Functions
fpm_scoreboard.h File Reference
#include <sys/time.h>
#include "fpm_request.h"
#include "fpm_worker_pool.h"
#include "fpm_atomic.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  fpm_scoreboard_proc_s
struct  fpm_scoreboard_s
union  fpm_scoreboard_proc_s.__unnamed__
union  fpm_scoreboard_s.__unnamed__

Defines

#define FPM_SCOREBOARD_ACTION_SET   0
#define FPM_SCOREBOARD_ACTION_INC   1

Functions

int fpm_scoreboard_init_main ()
int fpm_scoreboard_init_child (struct fpm_worker_pool_s *wp)
void fpm_scoreboard_update (int idle, int active, int lq, int lq_len, int requests, int max_children_reached, int action, struct fpm_scoreboard_s *scoreboard)
struct fpm_scoreboard_sfpm_scoreboard_get ()
struct fpm_scoreboard_proc_sfpm_scoreboard_proc_get (struct fpm_scoreboard_s *scoreboard, int child_index)
struct fpm_scoreboard_sfpm_scoreboard_acquire (struct fpm_scoreboard_s *scoreboard, int nohang)
void fpm_scoreboard_release (struct fpm_scoreboard_s *scoreboard)
struct fpm_scoreboard_proc_sfpm_scoreboard_proc_acquire (struct fpm_scoreboard_s *scoreboard, int child_index, int nohang)
void fpm_scoreboard_proc_release (struct fpm_scoreboard_proc_s *proc)
void fpm_scoreboard_free (struct fpm_scoreboard_s *scoreboard)
void fpm_scoreboard_child_use (struct fpm_scoreboard_s *scoreboard, int child_index, pid_t pid)
void fpm_scoreboard_proc_free (struct fpm_scoreboard_s *scoreboard, int child_index)
int fpm_scoreboard_proc_alloc (struct fpm_scoreboard_s *scoreboard, int *child_index)

Class Documentation

struct fpm_scoreboard_proc_s

Definition at line 20 of file fpm_scoreboard.h.

Class Members
union fpm_scoreboard_proc_s __unnamed__
time_t accepted_epoch
char auth_user
size_t content_length
size_t memory
pid_t pid
char query_string
char request_method
char request_uri
unsigned long requests
char script_filename
time_t start_epoch
enum fpm_request_stage_e struct timeval
int used
struct fpm_scoreboard_s

Definition at line 49 of file fpm_scoreboard.h.

Collaboration diagram for fpm_scoreboard_s:
Class Members
union fpm_scoreboard_s __unnamed__
int active
int active_max
int free_proc
int idle
int lq
unsigned int lq_len
int lq_max
unsigned int max_children_reached
unsigned int nprocs
int pm
char pool
struct fpm_scoreboard_proc_s * procs
unsigned long int requests
time_t start_epoch
union fpm_scoreboard_proc_s.__unnamed__

Definition at line 21 of file fpm_scoreboard.h.

Class Members
char dummy
atomic_t lock
union fpm_scoreboard_s.__unnamed__

Definition at line 50 of file fpm_scoreboard.h.

Class Members
char dummy
atomic_t lock

Define Documentation

#define FPM_SCOREBOARD_ACTION_INC   1

Definition at line 18 of file fpm_scoreboard.h.

#define FPM_SCOREBOARD_ACTION_SET   0

Definition at line 17 of file fpm_scoreboard.h.


Function Documentation

struct fpm_scoreboard_s* fpm_scoreboard_acquire ( struct fpm_scoreboard_s scoreboard,
int  nohang 
) [read]

Definition at line 175 of file fpm_scoreboard.c.

{
       struct fpm_scoreboard_s *s;

       s = scoreboard ? scoreboard : fpm_scoreboard;
       if (!s) {
              return NULL;
       }

       if (!fpm_spinlock(&s->lock, nohang)) {
              return NULL;
       }
       return s;
}

Here is the call graph for this function:

void fpm_scoreboard_child_use ( struct fpm_scoreboard_s scoreboard,
int  child_index,
pid_t  pid 
)

Definition at line 244 of file fpm_scoreboard.c.

{
       struct fpm_scoreboard_proc_s *proc;
       fpm_scoreboard = scoreboard;
       fpm_scoreboard_i = child_index;
       proc = fpm_scoreboard_proc_get(scoreboard, child_index);
       if (!proc) {
              return;
       }
       proc->pid = pid;
       proc->start_epoch = time(NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fpm_scoreboard_free ( struct fpm_scoreboard_s scoreboard)

Definition at line 225 of file fpm_scoreboard.c.

{
       int i;

       if (!scoreboard) {
              zlog(ZLOG_ERROR, "**scoreboard is NULL");
              return;
       }

       for (i = 0; i < scoreboard->nprocs; i++) {
              if (!scoreboard->procs[i]) {
                     continue;
              }
              fpm_shm_free(scoreboard->procs[i], sizeof(struct fpm_scoreboard_proc_s));
       }
       fpm_shm_free(scoreboard, sizeof(struct fpm_scoreboard_s));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 147 of file fpm_scoreboard.c.

{
       return fpm_scoreboard;
}

Here is the caller graph for this function:

Definition at line 25 of file fpm_scoreboard.c.

{
       struct fpm_worker_pool_s *wp;
       int i;

#ifdef HAVE_TIMES
#if (defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK))
       fpm_scoreboard_tick = sysconf(_SC_CLK_TCK);
#else /* _SC_CLK_TCK */
#ifdef HZ
       fpm_scoreboard_tick = HZ;
#else /* HZ */
       fpm_scoreboard_tick = 100;
#endif /* HZ */
#endif /* _SC_CLK_TCK */
       zlog(ZLOG_DEBUG, "got clock tick '%.0f'", fpm_scoreboard_tick);
#endif /* HAVE_TIMES */


       for (wp = fpm_worker_all_pools; wp; wp = wp->next) {
              if (wp->config->pm_max_children < 1) {
                     zlog(ZLOG_ERROR, "[pool %s] Unable to create scoreboard SHM because max_client is not set", wp->config->name);
                     return -1;
              }

              if (wp->scoreboard) {
                     zlog(ZLOG_ERROR, "[pool %s] Unable to create scoreboard SHM because it already exists", wp->config->name);
                     return -1;
              }

              wp->scoreboard = fpm_shm_alloc(sizeof(struct fpm_scoreboard_s) + (wp->config->pm_max_children - 1) * sizeof(struct fpm_scoreboard_proc_s *));
              if (!wp->scoreboard) {
                     return -1;
              }
              wp->scoreboard->nprocs = wp->config->pm_max_children;
              for (i = 0; i < wp->scoreboard->nprocs; i++) {
                     wp->scoreboard->procs[i] = fpm_shm_alloc(sizeof(struct fpm_scoreboard_proc_s));
                     if (!wp->scoreboard->procs[i]) {
                            return -1;
                     }
                     memset(wp->scoreboard->procs[i], 0, sizeof(struct fpm_scoreboard_proc_s));
              }

              wp->scoreboard->pm = wp->config->pm;
              wp->scoreboard->start_epoch = time(NULL);
              strlcpy(wp->scoreboard->pool, wp->config->name, sizeof(wp->scoreboard->pool));
       }
       return 0;     
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct fpm_scoreboard_proc_s* fpm_scoreboard_proc_acquire ( struct fpm_scoreboard_s scoreboard,
int  child_index,
int  nohang 
) [read]

Definition at line 199 of file fpm_scoreboard.c.

{
       struct fpm_scoreboard_proc_s *proc;

       proc = fpm_scoreboard_proc_get(scoreboard, child_index);
       if (!proc) {
              return NULL;
       }

       if (!fpm_spinlock(&proc->lock, nohang)) {
              return NULL;
       }

       return proc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int fpm_scoreboard_proc_alloc ( struct fpm_scoreboard_s scoreboard,
int child_index 
)

Definition at line 277 of file fpm_scoreboard.c.

{
       int i = -1;

       if (!scoreboard || !child_index) {
              return -1;
       }

       /* first try the slot which is supposed to be free */
       if (scoreboard->free_proc >= 0 && scoreboard->free_proc < scoreboard->nprocs) {
              if (scoreboard->procs[scoreboard->free_proc] && !scoreboard->procs[scoreboard->free_proc]->used) {
                     i = scoreboard->free_proc;
              }
       }

       if (i < 0) { /* the supposed free slot is not, let's search for a free slot */
              zlog(ZLOG_DEBUG, "[pool %s] the proc->free_slot was not free. Let's search", scoreboard->pool);
              for (i = 0; i < scoreboard->nprocs; i++) {
                     if (scoreboard->procs[i] && !scoreboard->procs[i]->used) { /* found */
                            break;
                     }
              }
       }

       /* no free slot */
       if (i < 0 || i >= scoreboard->nprocs) {
              zlog(ZLOG_ERROR, "[pool %s] no free scoreboard slot", scoreboard->pool);
              return -1;
       }

       scoreboard->procs[i]->used = 1;
       *child_index = i;

       /* supposed next slot is free */
       if (i + 1 >= scoreboard->nprocs) {
              scoreboard->free_proc = 0;
       } else {
              scoreboard->free_proc = i + 1;
       }

       return 0;
}

Here is the caller graph for this function:

void fpm_scoreboard_proc_free ( struct fpm_scoreboard_s scoreboard,
int  child_index 
)

Definition at line 258 of file fpm_scoreboard.c.

{
       if (!scoreboard) {
              return;
       }

       if (child_index < 0 || child_index >= scoreboard->nprocs) {
              return;
       }

       if (scoreboard->procs[child_index] && scoreboard->procs[child_index]->used > 0) {
              memset(scoreboard->procs[child_index], 0, sizeof(struct fpm_scoreboard_proc_s));
       }

       /* set this slot as free to avoid search on next alloc */
       scoreboard->free_proc = child_index;
}

Here is the caller graph for this function:

struct fpm_scoreboard_proc_s* fpm_scoreboard_proc_get ( struct fpm_scoreboard_s scoreboard,
int  child_index 
) [read]

Definition at line 153 of file fpm_scoreboard.c.

{
       if (!scoreboard) {
              scoreboard = fpm_scoreboard;
       }

       if (!scoreboard) {
              return NULL;
       }

       if (child_index < 0) {
              child_index = fpm_scoreboard_i;
       }

       if (child_index < 0 || child_index >= scoreboard->nprocs) {
              return NULL;
       }

       return scoreboard->procs[child_index];
}

Here is the caller graph for this function:

Definition at line 216 of file fpm_scoreboard.c.

{
       if (!proc) {
              return;
       }

       proc->lock = 0;
}

Here is the caller graph for this function:

void fpm_scoreboard_release ( struct fpm_scoreboard_s scoreboard)

Definition at line 191 of file fpm_scoreboard.c.

                                                                 {
       if (!scoreboard) {
              return;
       }

       scoreboard->lock = 0;
}
void fpm_scoreboard_update ( int  idle,
int  active,
int  lq,
int  lq_len,
int  requests,
int  max_children_reached,
int  action,
struct fpm_scoreboard_s scoreboard 
)

Definition at line 76 of file fpm_scoreboard.c.

{
       if (!scoreboard) {
              scoreboard = fpm_scoreboard;
       }
       if (!scoreboard) {
              zlog(ZLOG_WARNING, "Unable to update scoreboard: the SHM has not been found");
              return;
       }


       fpm_spinlock(&scoreboard->lock, 0);
       if (action == FPM_SCOREBOARD_ACTION_SET) {
              if (idle >= 0) {
                     scoreboard->idle = idle;
              }
              if (active >= 0) {
                     scoreboard->active = active;
              }
              if (lq >= 0) {
                     scoreboard->lq = lq;
              }
              if (lq_len >= 0) {
                     scoreboard->lq_len = lq_len;
              }
#ifdef HAVE_FPM_LQ /* prevent unnecessary test */
              if (scoreboard->lq > scoreboard->lq_max) {
                     scoreboard->lq_max = scoreboard->lq;
              }
#endif
              if (requests >= 0) {
                     scoreboard->requests = requests;
              }

              if (max_children_reached >= 0) {
                     scoreboard->max_children_reached = max_children_reached;
              }
       } else {
              if (scoreboard->idle + idle > 0) {
                     scoreboard->idle += idle;
              } else {
                     scoreboard->idle = 0;
              }

              if (scoreboard->active + active > 0) {
                     scoreboard->active += active;
              } else {
                     scoreboard->active = 0;
              }

              if (scoreboard->requests + requests > 0) {
                     scoreboard->requests += requests;
              } else {
                     scoreboard->requests = 0;
              }

              if (scoreboard->max_children_reached + max_children_reached > 0) {
                     scoreboard->max_children_reached += max_children_reached;
              } else {
                     scoreboard->max_children_reached = 0;
              }
       }

       if (scoreboard->active > scoreboard->active_max) {
              scoreboard->active_max = scoreboard->active;
       }

       fpm_unlock(scoreboard->lock);
}

Here is the call graph for this function:

Here is the caller graph for this function: