[core] mark startup/shutdown funcs cold

This commit is contained in:
Glenn Strauss 2019-02-03 23:27:57 -05:00
parent 413c0e557e
commit fb9b8ad8ae
10 changed files with 88 additions and 10 deletions

View File

@ -81,8 +81,12 @@ struct data_config {
struct cond_cache_t; /* declaration */
__attribute_cold__
data_config *data_config_init(void);
__attribute_cold__
int data_config_pcre_compile(data_config *dc);
int data_config_pcre_exec(data_config *dc, struct cond_cache_t *cache, buffer *b);
typedef struct {
@ -94,14 +98,26 @@ typedef struct {
buffer *basedir;
} config_t;
__attribute_cold__
int config_read(server *srv, const char *fn);
__attribute_cold__
int config_set_defaults(server *srv);
__attribute_cold__
void *configparserAlloc(void *(*mallocProc)(size_t));
__attribute_cold__
void configparserFree(void *p, void (*freeProc)(void*));
__attribute_cold__
void configparser(void *yyp, int yymajor, buffer *yyminor, config_t *ctx);
__attribute_cold__
int config_parse_file(server *srv, config_t *context, const char *fn);
__attribute_cold__
int config_parse_cmd(server *srv, config_t *context, const char *cmd);
data_unset *configparser_merge_data(data_unset *op1, const data_unset *op2);
int config_setup_connection(server *srv, connection *con);
int config_patch_connection(server *srv, connection *con);
@ -133,8 +149,12 @@ typedef struct {
config_scope_type_t scope;
} config_values_t;
__attribute_cold__
int config_insert_values_global(server *srv, array *ca, const config_values_t *cv, config_scope_type_t scope);
__attribute_cold__
int config_insert_values_internal(server *srv, array *ca, const config_values_t *cv, config_scope_type_t scope);
int config_check_cond(server *srv, connection *con, data_config *dc);
#endif

View File

@ -63,7 +63,7 @@ static data_unset *configparser_get_variable(config_t *ctx, const buffer *key) {
/* op1 is to be eat/return by this function if success, op1->key is not cared
op2 is left untouch, unreferenced
*/
data_unset *configparser_merge_data(data_unset *op1, const data_unset *op2) {
static data_unset *configparser_merge_data(data_unset *op1, const data_unset *op2) {
/* type mismatch */
if (op1->type != op2->type) {
if (op1->type == TYPE_STRING && op2->type == TYPE_INTEGER) {

View File

@ -36,6 +36,12 @@ typedef struct {
PLUGIN_DATA;
} plugin_data;
__attribute_cold__
static connection *connection_init(server *srv);
static int connection_reset(server *srv, connection *con);
static connection *connections_get_new_connection(server *srv) {
connections *conns = srv->conns;
size_t i;
@ -473,7 +479,8 @@ static int connection_handle_write(server *srv, connection *con) {
connection *connection_init(server *srv) {
__attribute_cold__
static connection *connection_init(server *srv) {
connection *con;
UNUSED(srv);
@ -594,7 +601,7 @@ void connections_free(server *srv) {
}
int connection_reset(server *srv, connection *con) {
static int connection_reset(server *srv, connection *con) {
plugins_call_connection_reset(srv, con);
connection_response_reset(srv, con);

View File

@ -4,8 +4,7 @@
#include "base.h"
connection *connection_init(server *srv);
int connection_reset(server *srv, connection *con);
__attribute_cold__
void connections_free(server *srv);
connection * connection_accept(server *srv, server_socket *srv_sock);

View File

@ -31,10 +31,19 @@ typedef handler_t (*fdevent_handler)(struct server *srv, void *ctx, int revents)
#define FDEVENT_STREAM_RESPONSE_BUFMIN BV(1)
#define FDEVENT_STREAM_RESPONSE_POLLRDHUP BV(15)
__attribute_cold__
int fdevent_config(server *srv);
__attribute_cold__
const char * fdevent_show_event_handlers(void);
__attribute_cold__
fdevents *fdevent_init(struct server *srv);
__attribute_cold__
int fdevent_reset(fdevents *ev); /* "init" after fork() */
__attribute_cold__
void fdevent_free(fdevents *ev);
int fdevent_event_get_interest(const fdevents *ev, int fd);

View File

@ -8,10 +8,16 @@ struct server_socket; /* declaration */
void network_accept_tcp_nagle_disable(int fd);
__attribute_cold__
int network_init(server *srv, int stdin_fd);
__attribute_cold__
int network_close(server *srv);
__attribute_cold__
int network_register_fdevents(server *srv);
__attribute_cold__
void network_unregister_sock(server *srv, struct server_socket *srv_socket);
#endif

View File

@ -4,6 +4,8 @@
#include "base_decls.h"
int network_write_init(server *srv);
__attribute_cold__
const char * network_write_show_handlers(void);
#endif

View File

@ -14,12 +14,13 @@
static handler_t x(server *srv, connection *con, void *p_d)
#define INIT_FUNC(x) \
__attribute_cold__ \
static void *x(void)
#define FREE_FUNC SERVER_FUNC
#define FREE_FUNC __attribute_cold__ SERVER_FUNC
#define SETDEFAULTS_FUNC __attribute_cold__ SERVER_FUNC
#define SIGHUP_FUNC __attribute_cold__ SERVER_FUNC
#define TRIGGER_FUNC SERVER_FUNC
#define SETDEFAULTS_FUNC SERVER_FUNC
#define SIGHUP_FUNC SERVER_FUNC
#define SUBREQUEST_FUNC CONNECTION_FUNC
#define PHYSICALPATH_FUNC CONNECTION_FUNC
@ -68,7 +69,10 @@ typedef struct {
void *lib;
} plugin;
__attribute_cold__
int plugins_load(server *srv);
__attribute_cold__
void plugins_free(server *srv);
handler_t plugins_call_handle_uri_raw(server *srv, connection *con);
@ -86,11 +90,18 @@ handler_t plugins_call_handle_connection_close(server *srv, connection *con);
handler_t plugins_call_connection_reset(server *srv, connection *con);
handler_t plugins_call_handle_trigger(server *srv);
handler_t plugins_call_handle_sighup(server *srv);
handler_t plugins_call_handle_waitpid(server *srv, pid_t pid, int status);
__attribute_cold__
handler_t plugins_call_handle_sighup(server *srv);
__attribute_cold__
handler_t plugins_call_init(server *srv);
__attribute_cold__
handler_t plugins_call_set_defaults(server *srv);
__attribute_cold__
handler_t plugins_call_cleanup(server *srv);
#endif

View File

@ -222,6 +222,7 @@ static int daemonize(void) {
}
#endif
__attribute_cold__
static server *server_init(void) {
int i;
server *srv = calloc(1, sizeof(*srv));
@ -315,6 +316,7 @@ static server *server_init(void) {
return srv;
}
__attribute_cold__
static void server_free(server *srv) {
size_t i;
@ -407,6 +409,7 @@ static void server_free(server *srv) {
free(srv);
}
__attribute_cold__
static void remove_pid_file(server *srv) {
if (pid_fd <= -2) return;
if (!buffer_string_is_empty(srv->srvconf.pid_file) && 0 <= pid_fd) {
@ -437,6 +440,7 @@ static void remove_pid_file(server *srv) {
}
__attribute_cold__
static server_socket * server_oneshot_getsock(server *srv, sock_addr *cnt_addr) {
server_socket *srv_socket, *srv_socket_wild = NULL;
size_t i;
@ -462,6 +466,7 @@ static server_socket * server_oneshot_getsock(server *srv, sock_addr *cnt_addr)
}
__attribute_cold__
static int server_oneshot_init(server *srv, int fd) {
/* Note: does not work with netcat due to requirement that fd be socket.
* STDOUT_FILENO was not saved earlier in startup, and that is to where
@ -526,6 +531,7 @@ static int server_oneshot_init(server *srv, int fd) {
}
__attribute_cold__
static void show_version (void) {
char *b = PACKAGE_DESC TEXT_SSL \
" - a light and fast webserver\n"
@ -536,6 +542,7 @@ static void show_version (void) {
write_all(STDOUT_FILENO, b, strlen(b));
}
__attribute_cold__
static void show_features (void) {
static const char features[] =
"\nFeatures:\n\n"
@ -634,6 +641,7 @@ static void show_features (void) {
printf("%s%s%s\n", fdevent_show_event_handlers(), network_write_show_handlers(), features);
}
__attribute_cold__
static void show_help (void) {
char *b = PACKAGE_DESC TEXT_SSL
#ifdef NONREPRODUCIBLE_BUILD
@ -831,6 +839,7 @@ static int log_error_cycle(server *srv) {
return 0;
}
__attribute_cold__
static int log_error_close(server *srv) {
switch(srv->errorlog_mode) {
case ERRORLOG_PIPE:
@ -856,6 +865,7 @@ static int log_error_close(server *srv) {
return 0;
}
__attribute_cold__
static void server_sockets_save (server *srv) { /* graceful_restart */
memcpy(&graceful_sockets, &srv->srv_sockets, sizeof(server_socket_array));
memset(&srv->srv_sockets, 0, sizeof(server_socket_array));
@ -863,6 +873,7 @@ static void server_sockets_save (server *srv) { /* graceful_restart */
memset(&srv->srv_sockets_inherited, 0, sizeof(server_socket_array));
}
__attribute_cold__
static void server_sockets_restore (server *srv) { /* graceful_restart */
memcpy(&srv->srv_sockets, &graceful_sockets, sizeof(server_socket_array));
memset(&graceful_sockets, 0, sizeof(server_socket_array));
@ -870,6 +881,7 @@ static void server_sockets_restore (server *srv) { /* graceful_restart */
memset(&inherited_sockets, 0, sizeof(server_socket_array));
}
__attribute_cold__
static int server_sockets_set_nb_cloexec (server *srv) {
if (srv->sockets_disabled) return 0; /* lighttpd -1 (one-shot mode) */
for (size_t i = 0; i < srv->srv_sockets.used; ++i) {
@ -883,6 +895,7 @@ static int server_sockets_set_nb_cloexec (server *srv) {
return 0;
}
__attribute_cold__
static void server_sockets_set_event (server *srv, int event) {
for (size_t i = 0; i < srv->srv_sockets.used; ++i) {
server_socket *srv_socket = srv->srv_sockets.ptr[i];
@ -890,11 +903,13 @@ static void server_sockets_set_event (server *srv, int event) {
}
}
__attribute_cold__
static void server_sockets_unregister (server *srv) {
for (size_t i = 0; i < srv->srv_sockets.used; ++i)
network_unregister_sock(srv, srv->srv_sockets.ptr[i]);
}
__attribute_cold__
static void server_sockets_close (server *srv) {
/* closing socket right away will make it possible for the next lighttpd
* to take over (old-style graceful restart), but only if backends
@ -911,6 +926,7 @@ static void server_sockets_close (server *srv) {
}
}
__attribute_cold__
static void server_graceful_shutdown_maint (server *srv) {
connections *conns = srv->conns;
for (size_t ndx = 0; ndx < conns->used; ++ndx) {
@ -947,6 +963,7 @@ static void server_graceful_shutdown_maint (server *srv) {
}
}
__attribute_cold__
static void server_graceful_state (server *srv) {
if (!srv_shutdown) server_graceful_shutdown_maint(srv);
@ -975,6 +992,7 @@ static void server_graceful_state (server *srv) {
}
}
__attribute_cold__
static int server_main (server * const srv, int argc, char **argv) {
int print_config = 0;
int test_config = 0;
@ -1731,6 +1749,7 @@ static int server_main (server * const srv, int argc, char **argv) {
return 1;
}
__attribute_cold__
__attribute_noinline__
static int server_handle_sighup (server * const srv) {
handler_t r;

View File

@ -31,8 +31,13 @@ typedef struct {
buffer *content_type;
} stat_cache_entry;
__attribute_cold__
int stat_cache_choose_engine (server *srv, const buffer *stat_cache_string);
__attribute_cold__
struct stat_cache *stat_cache_init(server *srv);
__attribute_cold__
void stat_cache_free(struct stat_cache *fc);
const buffer * stat_cache_mimetype_by_ext(const connection *con, const char *name, size_t nlen);