qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: Leonid Bloch <leonid.bloch@ravellosystems.com>, qemu-devel@nongnu.org
Cc: Dmitry Fleytman <dmitry@daynix.com>,
	Leonid Bloch <leonid@daynix.com>,
	Shmulik Ladkani <shmulik.ladkani@ravellosystems.com>
Subject: Re: [Qemu-devel] [PATCH 6/6] e1000: Implementing various counters
Date: Tue, 20 Oct 2015 14:34:12 +0800	[thread overview]
Message-ID: <5625E064.7060201@redhat.com> (raw)
In-Reply-To: <1445154799-31083-7-git-send-email-leonid.bloch@ravellosystems.com>



On 10/18/2015 03:53 PM, Leonid Bloch wrote:
> This implements the following Statistic registers (various counters)
> according to Intel's specs:
>
> TSCTC  GOTCL  GOTCH  GORCL  GORCH  MPRC   BPRC   RUC    ROC
> BPTC   MPTC   PTC... PRC...
>
> Signed-off-by: Leonid Bloch <leonid.bloch@ravellosystems.com>
> Signed-off-by: Dmitry Fleytman <dmitry.fleytman@ravellosystems.com>
> ---
>  hw/net/e1000.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++------
>  1 file changed, 75 insertions(+), 8 deletions(-)
>
> diff --git a/hw/net/e1000.c b/hw/net/e1000.c
> index 0ce7a7e..afb0ebe 100644
> --- a/hw/net/e1000.c
> +++ b/hw/net/e1000.c
> @@ -37,6 +37,8 @@
>  
>  #include "e1000_regs.h"
>  
> +static const uint8_t bcast[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
> +
>  #define E1000_DEBUG
>  
>  #ifdef E1000_DEBUG
> @@ -178,7 +180,13 @@ enum {
>      defreg(DC),      defreg(TNCRS),   defreg(SEC),     defreg(CEXTERR),
>      defreg(RLEC),    defreg(XONRXC),  defreg(XONTXC),  defreg(XOFFRXC),
>      defreg(XOFFTXC), defreg(RFC),     defreg(RJC),     defreg(RNBC),
> -    defreg(TSCTFC),  defreg(MGTPRC),  defreg(MGTPDC),  defreg(MGTPTC)
> +    defreg(TSCTFC),  defreg(MGTPRC),  defreg(MGTPDC),  defreg(MGTPTC),
> +    defreg(RUC),     defreg(ROC),     defreg(GORCL),   defreg(GORCH),
> +    defreg(GOTCL),   defreg(GOTCH),   defreg(BPRC),    defreg(MPRC),
> +    defreg(TSCTC),   defreg(PRC64),   defreg(PRC127),  defreg(PRC255),
> +    defreg(PRC511),  defreg(PRC1023), defreg(PRC1522), defreg(PTC64),
> +    defreg(PTC127),  defreg(PTC255),  defreg(PTC511),  defreg(PTC1023),
> +    defreg(PTC1522), defreg(MPTC),    defreg(BPTC)
>  };
>  
>  static void
> @@ -583,6 +591,16 @@ inc_reg_if_not_full(E1000State *s, int index)
>      }
>  }
>  
> +static inline void
> +inc_tx_bcast_or_mcast_count(E1000State *s, unsigned char *arr)
> +{
> +    if (!memcmp(arr, bcast, sizeof bcast)) {
> +        inc_reg_if_not_full(s, BPTC);
> +    } else if (arr[0] & 1) {
> +        inc_reg_if_not_full(s, MPTC);
> +    }
> +}
> +
>  static void
>  grow_8reg_if_not_full(E1000State *s, int index, int size)
>  {
> @@ -605,6 +623,24 @@ grow_8reg_if_not_full(E1000State *s, int index, int size)
>      }
>  }
>  
> +static void
> +increase_size_stats(E1000State *s, const int *size_regs, int size)
> +{
> +    if (size > 1023) {
> +        inc_reg_if_not_full(s, size_regs[5]);
> +    } else if (size > 511) {
> +        inc_reg_if_not_full(s, size_regs[4]);
> +    } else if (size > 255) {
> +        inc_reg_if_not_full(s, size_regs[3]);
> +    } else if (size > 127) {
> +        inc_reg_if_not_full(s, size_regs[2]);
> +    } else if (size > 64) {
> +        inc_reg_if_not_full(s, size_regs[1]);
> +    } else if (size == 64) {
> +        inc_reg_if_not_full(s, size_regs[0]);
> +    }
> +}
> +
>  static inline int
>  vlan_enabled(E1000State *s)
>  {
> @@ -656,6 +692,8 @@ xmit_seg(E1000State *s)
>      uint16_t len, *sp;
>      unsigned int frames = s->tx.tso_frames, css, sofar;
>      struct e1000_tx *tp = &s->tx;
> +    static const int PTCregs[6] = {PTC64, PTC127, PTC255, PTC511,
> +                                   PTC1023, PTC1522};
>  
>      if (tp->tse && tp->cptse) {
>          css = tp->ipcss;
> @@ -673,8 +711,11 @@ xmit_seg(E1000State *s)
>          if (tp->tcp) {
>              sofar = frames * tp->mss;
>              stl_be_p(tp->data+css+4, ldl_be_p(tp->data+css+4)+sofar); /* seq */
> -            if (tp->paylen - sofar > tp->mss)
> +            if (tp->paylen - sofar > tp->mss) {
>                  tp->data[css + 13] &= ~9;    /* PSH, FIN */
> +            } else if (frames) {
> +                inc_reg_if_not_full(s, TSCTC);
> +            }
>          } else    /* UDP */
>              stw_be_p(tp->data+css+4, len);
>          if (tp->sum_needed & E1000_TXD_POPTS_TXSM) {
> @@ -697,11 +738,19 @@ xmit_seg(E1000State *s)
>          memmove(tp->data, tp->data + 4, 8);
>          memcpy(tp->data + 8, tp->vlan_header, 4);
>          e1000_send_packet(s, tp->vlan, tp->size + 4);
> -    } else
> +        inc_tx_bcast_or_mcast_count(s, tp->vlan);
> +        increase_size_stats(s, PTCregs, tp->size + 4);
> +    } else {
>          e1000_send_packet(s, tp->data, tp->size);
> +        inc_tx_bcast_or_mcast_count(s, tp->data);
> +        increase_size_stats(s, PTCregs, tp->size);
> +    }
> +

Why not put above just inside e1000_send_packet() to avoid code duplication?

>      inc_reg_if_not_full(s, TPT);
>      grow_8reg_if_not_full(s, TOTL, s->tx.size);
>      s->mac_reg[GPTC] = s->mac_reg[TPT];
> +    s->mac_reg[GOTCL] = s->mac_reg[TOTL];
> +    s->mac_reg[GOTCH] = s->mac_reg[TOTH];
>  }
>  
>  static void
> @@ -869,7 +918,6 @@ start_xmit(E1000State *s)
>  static int
>  receive_filter(E1000State *s, const uint8_t *buf, int size)
>  {
> -    static const uint8_t bcast[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
>      static const int mta_shift[] = {4, 3, 2, 0};
>      uint32_t f, rctl = s->mac_reg[RCTL], ra[2], *rp;
>      int isbcast = !memcmp(buf, bcast, sizeof bcast), ismcast = (buf[0] & 1);
> @@ -887,10 +935,12 @@ receive_filter(E1000State *s, const uint8_t *buf, int size)
>      }
>  
>      if (ismcast && (rctl & E1000_RCTL_MPE)) {          /* promiscuous mcast */
> +        inc_reg_if_not_full(s, MPRC);
>          return 1;
>      }
>  
>      if (isbcast && (rctl & E1000_RCTL_BAM)) {          /* broadcast enabled */
> +        inc_reg_if_not_full(s, BPRC);
>          return 1;
>      }
>  
> @@ -912,8 +962,10 @@ receive_filter(E1000State *s, const uint8_t *buf, int size)
>  
>      f = mta_shift[(rctl >> E1000_RCTL_MO_SHIFT) & 3];
>      f = (((buf[5] << 8) | buf[4]) >> f) & 0xfff;
> -    if (s->mac_reg[MTA + (f >> 5)] & (1 << (f & 0x1f)))
> +    if (s->mac_reg[MTA + (f >> 5)] & (1 << (f & 0x1f))) {
> +        inc_reg_if_not_full(s, MPRC);
>          return 1;
> +    }
>      DBGOUT(RXFILTER,
>             "dropping, inexact filter mismatch: %02x:%02x:%02x:%02x:%02x:%02x MO %d MTA[%d] %x\n",
>             buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
> @@ -1002,6 +1054,8 @@ e1000_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt)
>      size_t desc_offset;
>      size_t desc_size;
>      size_t total_size;
> +    static const int PRCregs[6] = {PRC64, PRC127, PRC255, PRC511,
> +                                   PRC1023, PRC1522};
>  
>      if (!(s->mac_reg[STATUS] & E1000_STATUS_LU)) {
>          return -1;
> @@ -1015,6 +1069,7 @@ e1000_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt)
>      if (size < sizeof(min_buf)) {
>          iov_to_buf(iov, iovcnt, 0, min_buf, size);
>          memset(&min_buf[size], 0, sizeof(min_buf) - size);
> +        inc_reg_if_not_full(s, RUC);
>          min_iov.iov_base = filter_buf = min_buf;
>          min_iov.iov_len = size = sizeof(min_buf);
>          iovcnt = 1;
> @@ -1030,6 +1085,7 @@ e1000_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt)
>          (size > MAXIMUM_ETHERNET_VLAN_SIZE
>          && !(s->mac_reg[RCTL] & E1000_RCTL_LPE)))
>          && !(s->mac_reg[RCTL] & E1000_RCTL_SBP)) {
> +        inc_reg_if_not_full(s, ROC);
>          return size;
>      }
>  
> @@ -1115,6 +1171,7 @@ e1000_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt)
>          }
>      } while (desc_offset < total_size);
>  
> +    increase_size_stats(s, PRCregs, total_size);
>      inc_reg_if_not_full(s, TPR);
>      s->mac_reg[GPRC] = s->mac_reg[TPR];
>      /* TOR - Total Octets Received:
> @@ -1123,6 +1180,8 @@ e1000_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt)
>       * Always include FCS length (4) in size.
>       */
>      grow_8reg_if_not_full(s, TORL, size+4);
> +    s->mac_reg[GORCL] = s->mac_reg[TORL];
> +    s->mac_reg[GORCH] = s->mac_reg[TORH];
>  
>      n = E1000_ICS_RXT0;
>      if ((rdt = s->mac_reg[RDT]) < s->mac_reg[RDH])
> @@ -1274,10 +1333,18 @@ static uint32_t (*macreg_readops[])(E1000State *, int) = {
>      getreg(RLEC),     getreg(XONRXC),   getreg(XONTXC),   getreg(XOFFRXC),
>      getreg(XOFFTXC),  getreg(RFC),      getreg(RJC),      getreg(RNBC),
>      getreg(TSCTFC),   getreg(MGTPRC),   getreg(MGTPDC),   getreg(MGTPTC),
> -
> -    [TOTH] = mac_read_clr8,   [TORH] = mac_read_clr8,
> +    getreg(GORCL),    getreg(GOTCL),
> +
> +    [TOTH] = mac_read_clr8,   [TORH] = mac_read_clr8,   [GOTCH] = mac_read_clr8,
> +    [GORCH] = mac_read_clr8,
> +    [PRC64] = mac_read_clr4,  [PRC127] = mac_read_clr4, [PRC255] = mac_read_clr4,
> +    [PRC511] = mac_read_clr4, [PRC1023] = mac_read_clr4, [PRC1522] = mac_read_clr4,
> +    [PTC64] = mac_read_clr4,  [PTC127] = mac_read_clr4, [PTC255] = mac_read_clr4,
> +    [PTC511] = mac_read_clr4, [PTC1023] = mac_read_clr4, [PTC1522] = mac_read_clr4,
>      [GPRC] = mac_read_clr4,   [GPTC] = mac_read_clr4,   [TPR] = mac_read_clr4,
> -    [TPT] = mac_read_clr4,
> +    [TPT] = mac_read_clr4,    [RUC] = mac_read_clr4,    [ROC] = mac_read_clr4,
> +    [BPRC] = mac_read_clr4,   [MPRC] = mac_read_clr4,   [TSCTC] = mac_read_clr4,
> +    [BPTC] = mac_read_clr4,   [MPTC] = mac_read_clr4,
>      [ICR] = mac_icr_read,     [EECD] = get_eecd,        [EERD] = flash_eerd_read,
>      [RDFH] = mac_low13_read,  [RDFT] = mac_low13_read,
>      [RDFHS] = mac_low13_read, [RDFTS] = mac_low13_read, [RDFPC] = mac_low13_read,

  reply	other threads:[~2015-10-20  6:34 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-18  7:53 [Qemu-devel] [PATCH 0/6] e1000: Various fixes and registers' implementation Leonid Bloch
2015-10-18  7:53 ` [Qemu-devel] [PATCH 1/6] e1000: Cosmetic and alignment fixes Leonid Bloch
2015-10-18  7:53 ` [Qemu-devel] [PATCH 2/6] e1000: Trivial implementation of various MAC registers Leonid Bloch
2015-10-20  5:40   ` Jason Wang
2015-10-21  9:13     ` Leonid Bloch
2015-10-22  7:19       ` Jason Wang
2015-10-22 14:05         ` Leonid Bloch
2015-10-23  3:10           ` Jason Wang
2015-10-25 19:39             ` Leonid Bloch
2015-10-18  7:53 ` [Qemu-devel] [PATCH 3/6] e1000: Fixing the received/transmitted packets' counters Leonid Bloch
2015-10-18  7:53 ` [Qemu-devel] [PATCH 4/6] e1000: Fixing the received/transmitted octets' counters Leonid Bloch
2015-10-20  6:16   ` Jason Wang
2015-10-21 12:20     ` Leonid Bloch
2015-10-22  7:20       ` Jason Wang
2015-10-18  7:53 ` [Qemu-devel] [PATCH 5/6] e1000: Fixing the packet address filtering procedure Leonid Bloch
2015-10-18  7:53 ` [Qemu-devel] [PATCH 6/6] e1000: Implementing various counters Leonid Bloch
2015-10-20  6:34   ` Jason Wang [this message]
2015-10-21  9:20     ` Leonid Bloch
2015-10-20  6:37 ` [Qemu-devel] [PATCH 0/6] e1000: Various fixes and registers' implementation Jason Wang
2015-10-21 13:32   ` Leonid Bloch
2015-10-22  7:22     ` Jason Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5625E064.7060201@redhat.com \
    --to=jasowang@redhat.com \
    --cc=dmitry@daynix.com \
    --cc=leonid.bloch@ravellosystems.com \
    --cc=leonid@daynix.com \
    --cc=qemu-devel@nongnu.org \
    --cc=shmulik.ladkani@ravellosystems.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).