xref: /php-src/sapi/fpm/fpm/fpm_scoreboard.h (revision 3490ac0c)
1 	/* (c) 2009 Jerome Loyet */
2 
3 #ifndef FPM_SCOREBOARD_H
4 #define FPM_SCOREBOARD_H 1
5 
6 #include <sys/time.h>
7 #ifdef HAVE_TIMES
8 #include <sys/times.h>
9 #endif
10 
11 #include "fpm_request.h"
12 #include "fpm_worker_pool.h"
13 #include "fpm_atomic.h"
14 
15 #define FPM_SCOREBOARD_ACTION_SET 0
16 #define FPM_SCOREBOARD_ACTION_INC 1
17 
18 #define FPM_SCOREBOARD_LOCK_HANG 0
19 #define FPM_SCOREBOARD_LOCK_NOHANG 1
20 
21 #define FPM_SCOREBOARD_SPINLOCK_MAX_RETRIES 50000
22 
23 struct fpm_scoreboard_proc_s {
24 	union {
25 		atomic_t lock;
26 		char dummy[16];
27 	};
28 	int used;
29 	time_t start_epoch;
30 	pid_t pid;
31 	unsigned long requests;
32 	enum fpm_request_stage_e request_stage;
33 	struct timeval accepted;
34 	struct timeval duration;
35 	time_t accepted_epoch;
36 	struct timeval tv;
37 	char request_uri[128];
38 	char query_string[512];
39 	char request_method[16];
40 	size_t content_length; /* used with POST only */
41 	char script_filename[256];
42 	char auth_user[32];
43 #ifdef HAVE_TIMES
44 	struct tms cpu_accepted;
45 	struct timeval cpu_duration;
46 	struct tms last_request_cpu;
47 	struct timeval last_request_cpu_duration;
48 #endif
49 	size_t memory;
50 };
51 
52 struct fpm_scoreboard_s {
53 	union {
54 		atomic_t lock;
55 		char dummy[16];
56 	};
57 	atomic_t writer_active;
58 	unsigned int reader_count;
59 	char pool[32];
60 	int pm;
61 	time_t start_epoch;
62 	int idle;
63 	int active;
64 	int active_max;
65 	unsigned long int requests;
66 	unsigned int max_children_reached;
67 	int lq;
68 	int lq_max;
69 	unsigned int lq_len;
70 	unsigned int nprocs;
71 	int free_proc;
72 	unsigned long int slow_rq;
73 	size_t memory_peak;
74 	struct fpm_scoreboard_s *shared;
75 	struct fpm_scoreboard_proc_s procs[] ZEND_ELEMENT_COUNT(nprocs);
76 };
77 
78 int fpm_scoreboard_init_main(void);
79 int fpm_scoreboard_init_child(struct fpm_worker_pool_s *wp);
80 
81 void fpm_scoreboard_update_begin(struct fpm_scoreboard_s *scoreboard);
82 void fpm_scoreboard_update_commit(int idle, int active, int lq, int lq_len, int requests, int max_children_reached, int slow_rq, size_t memory_max, int action, struct fpm_scoreboard_s *scoreboard);
83 void fpm_scoreboard_update(int idle, int active, int lq, int lq_len, int requests, int max_children_reached, int slow_rq, size_t memory_max, int action, struct fpm_scoreboard_s *scoreboard);
84 
85 struct fpm_scoreboard_s *fpm_scoreboard_get(void);
86 struct fpm_scoreboard_proc_s *fpm_scoreboard_proc_get(struct fpm_scoreboard_s *scoreboard, int child_index);
87 struct fpm_scoreboard_proc_s *fpm_scoreboard_proc_get_from_child(struct fpm_child_s *child);
88 
89 struct fpm_scoreboard_s *fpm_scoreboard_acquire(struct fpm_scoreboard_s *scoreboard, int nohang);
90 void fpm_scoreboard_release(struct fpm_scoreboard_s *scoreboard);
91 struct fpm_scoreboard_proc_s *fpm_scoreboard_proc_acquire(struct fpm_scoreboard_s *scoreboard, int child_index, int nohang);
92 void fpm_scoreboard_proc_release(struct fpm_scoreboard_proc_s *proc);
93 
94 void fpm_scoreboard_free(struct fpm_worker_pool_s *wp);
95 
96 void fpm_scoreboard_child_use(struct fpm_child_s *child, pid_t pid);
97 
98 void fpm_scoreboard_proc_free(struct fpm_child_s *child);
99 int fpm_scoreboard_proc_alloc(struct fpm_child_s *child);
100 
101 struct fpm_scoreboard_s *fpm_scoreboard_copy(struct fpm_scoreboard_s *scoreboard, int copy_procs);
102 void fpm_scoreboard_free_copy(struct fpm_scoreboard_s *scoreboard);
103 
104 #ifdef HAVE_TIMES
105 float fpm_scoreboard_get_tick(void);
106 #endif
107 
108 #endif
109