ia64/xen-unstable

changeset 481:0aef664789c0

bitkeeper revision 1.255 (3ee5f6d5vkkWKWqCJgu8yj_PRuBcLQ)

adding resource usage accounting for network usage
author rgr22@boulderdash.cl.cam.ac.uk
date Tue Jun 10 15:18:45 2003 +0000 (2003-06-10)
parents 7596ce7d70f3
children a7588afbdfe5
files xen/common/network.c xen/include/hypervisor-ifs/network.h xen/include/xeno/vif.h xen/net/dev.c xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/dom0_core.c
line diff
     1.1 --- a/xen/common/network.c	Tue Jun 10 10:29:00 2003 +0000
     1.2 +++ b/xen/common/network.c	Tue Jun 10 15:18:45 2003 +0000
     1.3 @@ -211,29 +211,67 @@ void unlink_net_vif(net_vif_t *vif)
     1.4  /* vif_query - Call from the proc file system to get a list of indexes
     1.5   * in use by a particular domain.
     1.6   */
     1.7 -void vif_query(vif_query_t *vq)
     1.8 +int vif_query(vif_query_t *vq)
     1.9  {
    1.10      net_vif_t *vif;
    1.11      struct task_struct *p;
    1.12 -    char buf[128];
    1.13 +    int buf[32];
    1.14      int i;
    1.15 +    int count = 0;
    1.16  
    1.17 -    if ( !(p = find_domain_by_id(vq->domain)) ) 
    1.18 -        return;
    1.19 -
    1.20 -    *buf = '\0';
    1.21 +    if ( !(p = find_domain_by_id(vq->domain)) ) {
    1.22 +        buf[0] = -1;
    1.23 +        copy_to_user(vq->buf, buf, sizeof(int));
    1.24 +        return -ENOSYS;
    1.25 +    }
    1.26  
    1.27      for ( i = 0; i < MAX_DOMAIN_VIFS; i++ )
    1.28      {
    1.29          vif = p->net_vif_list[i];
    1.30          if ( vif == NULL ) continue;
    1.31 -        sprintf(buf + strlen(buf), "%d\n", i);
    1.32 +        buf[++count] = i;
    1.33      }
    1.34  
    1.35 -    copy_to_user(vq->buf, buf, strlen(buf) + 1);
    1.36 +    buf[0] = count;
    1.37 +
    1.38 +    copy_to_user(vq->buf, buf, (buf[0] + 1) * sizeof(int));
    1.39      
    1.40      put_task_struct(p);
    1.41 +
    1.42 +    return 0;
    1.43  }
    1.44 +
    1.45 +/* vif_getinfo - Call from the proc file system to get info about a specific
    1.46 + * vif in use by a particular domain.
    1.47 + */
    1.48 +int vif_getinfo(vif_getinfo_t *info)
    1.49 +{
    1.50 +    struct task_struct *p;
    1.51 +    net_vif_t *vif;
    1.52 +
    1.53 +    info->total_bytes_sent =
    1.54 +    info->total_bytes_received =
    1.55 +    info->total_packets_sent =
    1.56 +    info->total_packets_received = -1;
    1.57 +
    1.58 +    if ( !(p = find_domain_by_id(info->domain)) )
    1.59 +        return -ENOSYS;
    1.60 +
    1.61 +    vif = p->net_vif_list[info->vif];
    1.62 +
    1.63 +    if(vif == NULL)
    1.64 +        return -ENOSYS;
    1.65 +
    1.66 +    info->total_bytes_sent              = vif->total_bytes_sent;
    1.67 +    info->total_bytes_received          = vif->total_bytes_received;
    1.68 +    info->total_packets_sent            = vif->total_packets_sent;
    1.69 +    info->total_packets_received        = vif->total_packets_received;
    1.70 +
    1.71 +    put_task_struct(p);
    1.72 +
    1.73 +    return 0;
    1.74 +}
    1.75 +
    1.76          
    1.77  /* ----[ Net Rule Functions ]-----------------------------------------------*/
    1.78  
    1.79 @@ -517,9 +555,16 @@ long do_network_op(network_op_t *u_netwo
    1.80      }
    1.81      break;
    1.82  
    1.83 +    case NETWORK_OP_VIFGETINFO:
    1.84 +    {
    1.85 +        ret = vif_getinfo(&op.u.vif_getinfo);
    1.86 +        copy_to_user(u_network_op, &op, sizeof(op));
    1.87 +    }
    1.88 +    break;
    1.89 +
    1.90      case NETWORK_OP_VIFQUERY:
    1.91      {
    1.92 -        vif_query(&op.u.vif_query);
    1.93 +        ret = vif_query(&op.u.vif_query);
    1.94      }
    1.95      
    1.96      default:
     2.1 --- a/xen/include/hypervisor-ifs/network.h	Tue Jun 10 10:29:00 2003 +0000
     2.2 +++ b/xen/include/hypervisor-ifs/network.h	Tue Jun 10 15:18:45 2003 +0000
     2.3 @@ -123,9 +123,20 @@ typedef struct net_rule_st
     2.4  typedef struct vif_query_st
     2.5  {
     2.6      unsigned int    domain;
     2.7 -    char            *buf;   /* reply buffer -- guest virtual address */
     2.8 +    int             *buf;   /* reply buffer -- guest virtual address */
     2.9  } vif_query_t;
    2.10  
    2.11 +typedef struct vif_getinfo_st
    2.12 +{
    2.13 +    unsigned int        domain;
    2.14 +    unsigned int        vif;
    2.15 +    /* domain & vif are supplied by dom0, the rest are response fields */
    2.16 +    long long           total_bytes_sent;
    2.17 +    long long           total_bytes_received;
    2.18 +    long long           total_packets_sent;
    2.19 +    long long           total_packets_received;
    2.20 +} vif_getinfo_t;
    2.21 +
    2.22  /* Network trap operations and associated structure. 
    2.23   * This presently just handles rule insertion and deletion, but will
    2.24   * evenually have code to add and remove interfaces.
    2.25 @@ -135,6 +146,7 @@ typedef struct vif_query_st
    2.26  #define NETWORK_OP_DELETERULE   1
    2.27  #define NETWORK_OP_GETRULELIST  2
    2.28  #define NETWORK_OP_VIFQUERY     3
    2.29 +#define NETWORK_OP_VIFGETINFO   4
    2.30  
    2.31  typedef struct network_op_st 
    2.32  {
    2.33 @@ -143,6 +155,7 @@ typedef struct network_op_st
    2.34      {
    2.35          net_rule_t net_rule;
    2.36          vif_query_t vif_query;
    2.37 +        vif_getinfo_t vif_getinfo;
    2.38      }
    2.39      u;
    2.40  } network_op_t;
     3.1 --- a/xen/include/xeno/vif.h	Tue Jun 10 10:29:00 2003 +0000
     3.2 +++ b/xen/include/xeno/vif.h	Tue Jun 10 15:18:45 2003 +0000
     3.3 @@ -66,6 +66,12 @@ typedef struct net_vif_st {
     3.4      unsigned int tx_req_cons;
     3.5      unsigned int tx_resp_prod; /* private version of shared variable */
     3.6  
     3.7 +    /* Usage accounting */
     3.8 +    long long total_bytes_sent;
     3.9 +    long long total_bytes_received;
    3.10 +    long long total_packets_sent;
    3.11 +    long long total_packets_received;
    3.12 +
    3.13      /* Miscellaneous private stuff. */
    3.14      struct task_struct *domain;
    3.15      unsigned int idx; /* index within domain */
     4.1 --- a/xen/net/dev.c	Tue Jun 10 10:29:00 2003 +0000
     4.2 +++ b/xen/net/dev.c	Tue Jun 10 15:18:45 2003 +0000
     4.3 @@ -1882,6 +1882,10 @@ long do_net_update(void)
     4.4                  make_tx_response(vif, tx.id, RING_STATUS_OK);
     4.5              }
     4.6  
     4.7 +            /* record the transmission so they can be billed */
     4.8 +            vif->total_packets_sent++;
     4.9 +            vif->total_bytes_sent += tx.size;
    4.10 +
    4.11          tx_unmap_and_continue:
    4.12              unmap_domain_mem(g_data);
    4.13              spin_unlock_irq(&current->page_lock);
    4.14 @@ -2037,6 +2041,10 @@ static void make_rx_response(net_vif_t  
    4.15          guest_event_notify(cpu_mask);    
    4.16      }
    4.17      spin_unlock_irqrestore(&vif->rx_lock, flags);
    4.18 +
    4.19 +    /* record this so they can be billed */
    4.20 +    vif->total_packets_received++;
    4.21 +    vif->total_bytes_received += size;
    4.22  }
    4.23  
    4.24  
     5.1 --- a/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/dom0_core.c	Tue Jun 10 10:29:00 2003 +0000
     5.2 +++ b/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/dom0_core.c	Tue Jun 10 15:18:45 2003 +0000
     5.3 @@ -82,7 +82,8 @@ static int cmd_read_proc(char *page, cha
     5.4  
     5.5  static ssize_t dom_vif_read(struct file * file, char * buff, size_t size, loff_t * off)
     5.6  {
     5.7 -    char hyp_buf[128];
     5.8 +    int hyp_buf[32];
     5.9 +    char buf[128];
    5.10      network_op_t op;
    5.11      static int finished = 0;
    5.12  
    5.13 @@ -93,20 +94,30 @@ static ssize_t dom_vif_read(struct file 
    5.14      }
    5.15      
    5.16      op.cmd = NETWORK_OP_VIFQUERY;
    5.17 -    op.u.vif_query.domain = (unsigned int) ((struct proc_dir_entry *)file->f_dentry->d_inode->u.generic_ip)->data;
    5.18 +    op.u.vif_query.domain = (unsigned int)
    5.19 +        ((struct proc_dir_entry *)file->f_dentry->d_inode->u.generic_ip)->data;
    5.20      op.u.vif_query.buf = hyp_buf;
    5.21  
    5.22 -    strcpy(hyp_buf, "Error getting domain's vif list from hypervisor.\n"); // This will be replaced if everything works.
    5.23 -
    5.24 -    (void)HYPERVISOR_network_op(&op);
    5.25 +    (void) HYPERVISOR_network_op(&op);
    5.26  
    5.27 -    if (*off >= (strlen(hyp_buf)+1)) return 0;
    5.28 +    if(hyp_buf[0] < 0) {
    5.29 +        strcpy(buf, "Error getting domain's vif list from hypervisor.\n");
    5.30 +    } else {
    5.31 +        int i;
    5.32 +        int len = 0;
    5.33 +        strcpy(buf, "No vif found");
    5.34 +
    5.35 +        for(i = 1; i <= hyp_buf[0] && len < 127; i++)
    5.36 +            len += snprintf(buf + len, 127 - len, "%d\n", hyp_buf[i]);
    5.37 +    }
    5.38 +
    5.39 +    if (*off >= (strlen(buf)+1)) return 0;
    5.40      
    5.41 -    copy_to_user(buff, hyp_buf, strlen(hyp_buf));
    5.42 +    copy_to_user(buff, buf, strlen(buf));
    5.43      
    5.44      finished = 1;
    5.45      
    5.46 -    return strlen(hyp_buf)+1;
    5.47 +    return strlen(buf)+1;
    5.48  }
    5.49  
    5.50  struct file_operations dom_vif_ops = {
    5.51 @@ -115,8 +126,12 @@ struct file_operations dom_vif_ops = {
    5.52  
    5.53  static ssize_t dom_usage_read(struct file * file, char * buff, size_t size, loff_t * off)
    5.54  {
    5.55 -    char hyp_buf[128];
    5.56 +    char str[256];
    5.57 +    int vifs[32];
    5.58      dom0_op_t op;
    5.59 +    network_op_t netop;
    5.60 +    int i, end;
    5.61 +    unsigned int domain;
    5.62      static int finished = 0;
    5.63  
    5.64      if ( finished )
    5.65 @@ -125,21 +140,46 @@ static ssize_t dom_usage_read(struct fil
    5.66          return 0;
    5.67      }
    5.68  
    5.69 -    op.cmd = DOM0_GETDOMAININFO;
    5.70 -    op.u.getdominfo.domain = (unsigned int)
    5.71 +    domain = (unsigned int)
    5.72          ((struct proc_dir_entry *)file->f_dentry->d_inode->u.generic_ip)->data;
    5.73 +    op.cmd = DOM0_GETDOMAININFO;
    5.74  
    5.75 -    (void)HYPERVISOR_dom0_op(&op);
    5.76 +    op.u.getdominfo.domain = domain;
    5.77 +
    5.78 +    (void) HYPERVISOR_dom0_op(&op);
    5.79 +
    5.80 +    end = snprintf(str, 256, "cpu: %lld\n", op.u.getdominfo.cpu_time);
    5.81 +
    5.82 +    netop.cmd = NETWORK_OP_VIFQUERY;
    5.83 +    netop.u.vif_query.domain = domain;
    5.84 +    netop.u.vif_query.buf = vifs;
    5.85 +
    5.86 +    (void) HYPERVISOR_network_op(&netop);
    5.87  
    5.88 -    snprintf(hyp_buf, 128, "cpu: %lld\n", op.u.getdominfo.cpu_time);
    5.89 +    for(i = 1; i <= vifs[0]; i++) {
    5.90 +        netop.cmd = NETWORK_OP_VIFGETINFO;
    5.91 +        netop.u.vif_getinfo.domain = domain;
    5.92 +        netop.u.vif_getinfo.vif = vifs[i];
    5.93 +
    5.94 +        (void) HYPERVISOR_network_op(&netop);
    5.95  
    5.96 -    if (*off >= (strlen(hyp_buf) + 1)) return 0;
    5.97 +        end += snprintf(str + end, 255 - end,
    5.98 +                "vif%d: sent %lld bytes (%lld packets) "
    5.99 +                "received %lld bytes (%lld packets)\n",
   5.100 +                vifs[i],
   5.101 +                netop.u.vif_getinfo.total_bytes_sent,
   5.102 +                netop.u.vif_getinfo.total_packets_sent,
   5.103 +                netop.u.vif_getinfo.total_bytes_received,
   5.104 +                netop.u.vif_getinfo.total_packets_received);
   5.105 +    }
   5.106 +
   5.107 +    if (*off >= end + 1) return 0;
   5.108      
   5.109 -    copy_to_user(buff, hyp_buf, strlen(hyp_buf));
   5.110 +    copy_to_user(buff, str, end);
   5.111  
   5.112      finished = 1;
   5.113  
   5.114 -    return strlen(hyp_buf) + 1;
   5.115 +    return end + 1;
   5.116  }
   5.117  
   5.118  struct file_operations dom_usage_ops = {