From 55978d1d1f9c468a0c0cce92fbe3ab958384761d Mon Sep 17 00:00:00 2001 From: Michael Poole Date: Sun, 7 Nov 2004 20:57:50 +0000 Subject: [PATCH] Convert connection byte counters to 64-bit integers. git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@1263 c9e4aea6-c8fd-4c43-8297-357d70d61c8c --- ChangeLog | 30 ++++++++++++++++++++++++++++++ acinclude.m4 | 11 +++++++++++ configure.in | 2 +- include/client.h | 14 ++------------ include/s_misc.h | 30 ++++++++++++++++++++---------- ircd/ircd_snprintf.c | 12 +++--------- ircd/packet.c | 9 --------- ircd/s_bsd.c | 33 +-------------------------------- ircd/s_misc.c | 34 +++++----------------------------- ircd/s_stats.c | 6 +++--- 10 files changed, 76 insertions(+), 105 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5df016b..4c47782 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,33 @@ +2004-11-07 Michael Poole + + * acinclude.m4: Look for a 64-bit integer type. + + * configure.in: Look for inttypes.h, since some systems have that + but not stdint.h (and define 64-bit integers therein). + + * include/client.h: Delete con_sendK, con_receiveK. Make + con_sendB and con_receiveB 64 bits wide. + + * include/s_misc.h: Delete is_cks, is_ckr, is_sks, is_skr. + Convert the other byte counters and the connected time counters to + 64 bits wide. + + * ircd/ircd_snprintf.c (doprintf): Unconditionalize the + HAVE_LONG_LONG bits, and use the 64-bit integer types from above. + + * ircd/packet.c (update_bytes_received): Remove use of + cli_receiveK(). + + * ircd/s_bsd.c (deliver_it): Likewise. + (close_connection): Likewise. + + * ircd/s_misc.c (tstats): Likewise. Update format strings to use + %Lu for 64-bit integer parameters. + + * ircd/s_stats (stats_links): Convert cli_sendK() and + cli_receiveK() use shifted versions of the byte counters, and + update format strings to use %Lu for 64-bit integer parameters. + 2004-11-07 Michael Poole * include/s_user.h (add_silence): Delete. diff --git a/acinclude.m4 b/acinclude.m4 index 9ad93d1..5a6440e 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -138,6 +138,8 @@ AC_CHECK_SIZEOF(short) AC_CHECK_SIZEOF(int) AC_CHECK_SIZEOF(long) AC_CHECK_SIZEOF(void *) +AC_CHECK_SIZEOF(int64_t) +AC_CHECK_SIZEOF(long long) if test "$ac_cv_sizeof_int" = 2 ; then AC_CHECK_TYPE(int16_t, int) AC_CHECK_TYPE(uint16_t, unsigned int) @@ -158,6 +160,15 @@ elif test "$ac_cv_sizeof_long" = 4 ; then AC_CHECK_TYPE(uint32_t, unsigned long) else AC_MSG_ERROR([Cannot find a type with size of 32 bits]) +fi +if test "$ac_cv_sizeof_int64_t" = 8 ; then + AC_CHECK_TYPE(int64_t) + AC_CHECK_TYPE(uint64_t) +elif test "$ac_cv_sizeof_long_long" = 8 ; then + AC_CHECK_TYPE(int64_t, long long) + AC_CHECK_TYPE(uint64_t, unsigned long long) +else + AC_MSG_ERROR([Cannot find a type with size of 64 bits]) fi]) dnl Written by John Hawkinson . This code is in the Public diff --git a/configure.in b/configure.in index 9ed97ed..4d3450e 100644 --- a/configure.in +++ b/configure.in @@ -108,7 +108,7 @@ AC_LIBRARY_NET dnl Checks for header files. AC_HEADER_STDC -AC_CHECK_HEADERS(crypt.h poll.h stdint.h sys/devpoll.h sys/epoll.h sys/event.h sys/param.h sys/socket.h) +AC_CHECK_HEADERS(crypt.h poll.h inttypes.h stdint.h sys/devpoll.h sys/epoll.h sys/event.h sys/param.h sys/socket.h) dnl Checks for typedefs, structures, and compiler characteristics dnl AC_C_CONST diff --git a/include/client.h b/include/client.h index 7a15904..d0ee127 100644 --- a/include/client.h +++ b/include/client.h @@ -198,11 +198,9 @@ struct Connection struct MsgQ con_sendQ; /**< Outgoing message queue */ struct DBuf con_recvQ; /**< Incoming data yet to be parsed */ unsigned int con_sendM; /**< Stats: protocol messages sent */ - unsigned int con_sendK; /**< Stats: total k-bytes sent */ unsigned int con_receiveM; /**< Stats: protocol messages received */ - unsigned int con_receiveK; /**< Stats: total k-bytes received */ - unsigned short con_sendB; /**< Bytes sent, mod 1024. */ - unsigned short con_receiveB; /**< Bytes received, mod 1024. */ + uint64_t con_sendB; /**< Bytes sent. */ + uint64_t con_receiveB; /**< Bytes received. */ struct Listener* con_listener; /**< Listening socket which we accepted from. */ struct SLink* con_confs; /**< Associated configuration records. */ @@ -337,12 +335,8 @@ struct Client { #define cli_recvQ(cli) con_recvQ(cli_connect(cli)) /** Get count of messages sent to client. */ #define cli_sendM(cli) con_sendM(cli_connect(cli)) -/** Get number of kilobytes sent to client. */ -#define cli_sendK(cli) con_sendK(cli_connect(cli)) /** Get number of messages received from client. */ #define cli_receiveM(cli) con_receiveM(cli_connect(cli)) -/** Get number of kilobytes received from client. */ -#define cli_receiveK(cli) con_receiveK(cli_connect(cli)) /** Get number of bytes (modulo 1024) sent to client. */ #define cli_sendB(cli) con_sendB(cli_connect(cli)) /** Get number of bytes (modulo 1024) received from client. */ @@ -422,12 +416,8 @@ struct Client { #define con_recvQ(con) ((con)->con_recvQ) /** Get number of messages sent to connection. */ #define con_sendM(con) ((con)->con_sendM) -/** Get number of kilobytes sent to connection. */ -#define con_sendK(con) ((con)->con_sendK) /** Get number of messages received from connection. */ #define con_receiveM(con) ((con)->con_receiveM) -/** Get number of kilobytes received from connection. */ -#define con_receiveK(con) ((con)->con_receiveK) /** Get number of bytes (modulo 1024) sent to connection. */ #define con_sendB(con) ((con)->con_sendB) /** Get number of bytes (modulo 1024) received from connection. */ diff --git a/include/s_misc.h b/include/s_misc.h index dbf61c2..2f8bc14 100644 --- a/include/s_misc.h +++ b/include/s_misc.h @@ -30,21 +30,31 @@ struct ConfItem; * Structures */ +#ifdef HAVE_INTTYPES_H +# ifndef INCLUDED_inttypes_h +# include +# define INCLUDED_inttypes_h +# endif +#else +# ifdef HAVE_STDINT_H +# ifndef INCLUDED_stdint_h +# include +# define INCLUDED_stdint_h +# endif +# endif +#endif + /** Structure used to count many server-wide statistics. */ struct ServerStatistics { unsigned int is_cl; /**< number of client connections */ unsigned int is_sv; /**< number of server connections */ unsigned int is_ni; /**< connection but no idea who it was */ - unsigned short int is_cbs; /**< bytes sent to clients */ - unsigned short int is_cbr; /**< bytes received to clients */ - unsigned short int is_sbs; /**< bytes sent to servers */ - unsigned short int is_sbr; /**< bytes received to servers */ - unsigned int is_cks; /**< k-bytes sent to clients */ - unsigned int is_ckr; /**< k-bytes received to clients */ - unsigned int is_sks; /**< k-bytes sent to servers */ - unsigned int is_skr; /**< k-bytes received to servers */ - time_t is_cti; /**< time spent connected by clients */ - time_t is_sti; /**< time spent connected by servers */ + uint64_t is_cbs; /**< bytes sent to clients */ + uint64_t is_cbr; /**< bytes received to clients */ + uint64_t is_sbs; /**< bytes sent to servers */ + uint64_t is_sbr; /**< bytes received to servers */ + uint64_t is_cti; /**< time spent connected by clients */ + uint64_t is_sti; /**< time spent connected by servers */ unsigned int is_ac; /**< connections accepted */ unsigned int is_ref; /**< accepts refused */ unsigned int is_unco; /**< unknown commands */ diff --git a/ircd/ircd_snprintf.c b/ircd/ircd_snprintf.c index 91a9f08..3c7cfb0 100644 --- a/ircd/ircd_snprintf.c +++ b/ircd/ircd_snprintf.c @@ -1742,10 +1742,8 @@ doprintf(struct Client *dest, struct BufData *buf_p, const char *fmt, *((char *)va_arg(vp, int *)) = TOTAL(buf_p); else if (fld_s.flags & TYPE_SHORT) /* eg, %hn */ *((short *)va_arg(vp, int *)) = TOTAL(buf_p); -#ifdef HAVE_LONG_LONG else if (fld_s.flags & TYPE_QUAD) /* eg, %qn */ - *((my_quad_t *)va_arg(vp, my_quad_t *)) = TOTAL(buf_p); -#endif /* HAVE_LONG_LONG */ + *((int64_t *)va_arg(vp, int64_t *)) = TOTAL(buf_p); else if (fld_s.flags & TYPE_LONG) /* eg, %ln */ *((long *)va_arg(vp, long *)) = TOTAL(buf_p); else if (fld_s.flags & TYPE_INTMAX) /* eg, %jn */ @@ -1807,10 +1805,8 @@ doprintf(struct Client *dest, struct BufData *buf_p, const char *fmt, fld_s.value.v_int = (unsigned char)va_arg(vp, unsigned int); else if (fld_s.flags & TYPE_SHORT) /* eg, %hu */ fld_s.value.v_int = (short)va_arg(vp, unsigned int); -#ifdef HAVE_LONG_LONG else if (fld_s.flags & TYPE_QUAD) /* eg, %qu */ - fld_s.value.v_int = va_arg(vp, _large_t); -#endif + fld_s.value.v_int = va_arg(vp, uint64_t); else if (fld_s.flags & TYPE_LONG) /* eg, %lu */ fld_s.value.v_int = va_arg(vp, unsigned long); else if (fld_s.flags & TYPE_INTMAX) /* eg, %ju */ @@ -1832,10 +1828,8 @@ doprintf(struct Client *dest, struct BufData *buf_p, const char *fmt, signed_int = (char)va_arg(vp, unsigned int); else if (fld_s.flags & TYPE_SHORT) /* eg, %hd */ signed_int = (short)va_arg(vp, unsigned int); -#ifdef HAVE_LONG_LONG else if (fld_s.flags & TYPE_QUAD) /* eg, %qd */ - signed_int = va_arg(vp, _large_t); -#endif + signed_int = va_arg(vp, int64_t); else if (fld_s.flags & TYPE_LONG) /* eg, %ld */ signed_int = va_arg(vp, long); else if (fld_s.flags & TYPE_INTMAX) /* eg, %jd */ diff --git a/ircd/packet.c b/ircd/packet.c index 100f592..87853f6 100644 --- a/ircd/packet.c +++ b/ircd/packet.c @@ -42,15 +42,6 @@ static void update_bytes_received(struct Client* cptr, unsigned int length) { cli_receiveB(&me) += length; /* Update bytes received */ cli_receiveB(cptr) += length; - - if (cli_receiveB(cptr) > 1023) { - cli_receiveK(cptr) += (cli_receiveB(cptr) >> 10); - cli_receiveB(cptr) &= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */ - } - if (cli_receiveB(&me) > 1023) { - cli_receiveK(&me) += (cli_receiveB(&me) >> 10); - cli_receiveB(&me) &= 0x03ff; - } } /** Add one message to a client's received statistics. diff --git a/ircd/s_bsd.c b/ircd/s_bsd.c index 8628cbc..6a3d9e4 100644 --- a/ircd/s_bsd.c +++ b/ircd/s_bsd.c @@ -297,18 +297,7 @@ unsigned int deliver_it(struct Client *cptr, struct MsgQ *buf) cli_sendB(cptr) += bytes_written; cli_sendB(&me) += bytes_written; - if (cli_sendB(cptr) > 1023) { - cli_sendK(cptr) += (cli_sendB(cptr) >> 10); - cli_sendB(cptr) &= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */ - } - if (cli_sendB(&me) > 1023) { - cli_sendK(&me) += (cli_sendB(&me) >> 10); - cli_sendB(&me) &= 0x03ff; - } - /* - * XXX - hrmm.. set blocked here? the socket didn't - * say it was blocked - */ + /* A partial write implies that future writes will block. */ if (bytes_written < bytes_count) SetFlag(cptr, FLAG_BLOCKED); break; @@ -415,17 +404,7 @@ void close_connection(struct Client *cptr) ServerStats->is_sv++; ServerStats->is_sbs += cli_sendB(cptr); ServerStats->is_sbr += cli_receiveB(cptr); - ServerStats->is_sks += cli_sendK(cptr); - ServerStats->is_skr += cli_receiveK(cptr); ServerStats->is_sti += CurrentTime - cli_firsttime(cptr); - if (ServerStats->is_sbs > 1023) { - ServerStats->is_sks += (ServerStats->is_sbs >> 10); - ServerStats->is_sbs &= 0x3ff; - } - if (ServerStats->is_sbr > 1023) { - ServerStats->is_skr += (ServerStats->is_sbr >> 10); - ServerStats->is_sbr &= 0x3ff; - } /* * If the connection has been up for a long amount of time, schedule * a 'quick' reconnect, else reset the next-connect cycle. @@ -449,17 +428,7 @@ void close_connection(struct Client *cptr) ServerStats->is_cl++; ServerStats->is_cbs += cli_sendB(cptr); ServerStats->is_cbr += cli_receiveB(cptr); - ServerStats->is_cks += cli_sendK(cptr); - ServerStats->is_ckr += cli_receiveK(cptr); ServerStats->is_cti += CurrentTime - cli_firsttime(cptr); - if (ServerStats->is_cbs > 1023) { - ServerStats->is_cks += (ServerStats->is_cbs >> 10); - ServerStats->is_cbs &= 0x3ff; - } - if (ServerStats->is_cbr > 1023) { - ServerStats->is_ckr += (ServerStats->is_cbr >> 10); - ServerStats->is_cbr &= 0x3ff; - } } else ServerStats->is_ni++; diff --git a/ircd/s_misc.c b/ircd/s_misc.c index cdf6250..1b892fc 100644 --- a/ircd/s_misc.c +++ b/ircd/s_misc.c @@ -583,39 +583,15 @@ void tstats(struct Client *cptr, const struct StatDesc *sd, char *param) { sp->is_sbs += cli_sendB(acptr); sp->is_sbr += cli_receiveB(acptr); - sp->is_sks += cli_sendK(acptr); - sp->is_skr += cli_receiveK(acptr); sp->is_sti += CurrentTime - cli_firsttime(acptr); sp->is_sv++; - if (sp->is_sbs > 1023) - { - sp->is_sks += (sp->is_sbs >> 10); - sp->is_sbs &= 0x3ff; - } - if (sp->is_sbr > 1023) - { - sp->is_skr += (sp->is_sbr >> 10); - sp->is_sbr &= 0x3ff; - } } else if (IsUser(acptr)) { sp->is_cbs += cli_sendB(acptr); sp->is_cbr += cli_receiveB(acptr); - sp->is_cks += cli_sendK(acptr); - sp->is_ckr += cli_receiveK(acptr); sp->is_cti += CurrentTime - cli_firsttime(acptr); sp->is_cl++; - if (sp->is_cbs > 1023) - { - sp->is_cks += (sp->is_cbs >> 10); - sp->is_cbs &= 0x3ff; - } - if (sp->is_cbr > 1023) - { - sp->is_ckr += (sp->is_cbr >> 10); - sp->is_cbr &= 0x3ff; - } } else if (IsUnknown(acptr)) sp->is_ni++; @@ -638,10 +614,10 @@ void tstats(struct Client *cptr, const struct StatDesc *sd, char *param) send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Client server"); send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":connected %u %u", sp->is_cl, sp->is_sv); - send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":bytes sent %u.%uK %u.%uK", - sp->is_cks, sp->is_cbs, sp->is_sks, sp->is_sbs); - send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":bytes recv %u.%uK %u.%uK", - sp->is_ckr, sp->is_cbr, sp->is_skr, sp->is_sbr); - send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":time connected %Tu %Tu", + send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":bytes sent %Lu %Lu", + sp->is_cbs, sp->is_sbs); + send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":bytes recv %Lu %Lu", + sp->is_cbr, sp->is_sbr); + send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":time connected %Lu %Lu", sp->is_cti, sp->is_sti); } diff --git a/ircd/s_stats.c b/ircd/s_stats.c index 84b804b..1b332af 100644 --- a/ircd/s_stats.c +++ b/ircd/s_stats.c @@ -289,11 +289,11 @@ stats_links(struct Client* sptr, const struct StatDesc* sd, char* name) if (!(!name || wilds) && 0 != ircd_strcmp(name, cli_name(acptr))) continue; send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, - "%s %u %u %u %u %u :%Tu", + "%s %u %u %Lu %u %Lu :%Tu", (*(cli_name(acptr))) ? cli_name(acptr) : "", (int)MsgQLength(&(cli_sendQ(acptr))), (int)cli_sendM(acptr), - (int)cli_sendK(acptr), (int)cli_receiveM(acptr), - (int)cli_receiveK(acptr), CurrentTime - cli_firsttime(acptr)); + (cli_sendB(acptr) >> 10), (int)cli_receiveM(acptr), + (cli_receiveB(acptr) >> 10), CurrentTime - cli_firsttime(acptr)); } } -- 2.20.1