Message ID | 20111121135955.571254b1@nehalam.linuxnetplumber.net |
---|---|
State | Changes Requested, archived |
Delegated to: | David Miller |
Headers | show |
On Mon, Nov 21, 2011 at 1:59 PM, Stephen Hemminger <shemminger@vyatta.com> wrote: > On Mon, 21 Nov 2011 13:30:29 -0800 > Jesse Gross <jesse@nicira.com> wrote: > >> +/** >> + * vport_record_error - indicate device error to generic stats layer >> + * >> + * @vport: vport that encountered the error >> + * @err_type: one of enum vport_err_type types to indicate the error type >> + * >> + * If using the vport generic stats layer indicate that an error of the given >> + * type has occured. >> + */ >> +void vport_record_error(struct vport *vport, enum vport_err_type err_type) >> +{ >> + spin_lock(&vport->stats_lock); > > Sorry for over analyzing this... but I don't think the stats_lock > is necessary either. The only thing it is protecting is against 64 bit > wrap. If you used another u64_stat_sync for that one, it could be eliminated. > > Maybe? The reason for stats_lock is that the error stats are not expected to be contended so in order to save some memory they're not per-cpu and we just use a spin lock to protect them. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Mon, 21 Nov 2011 15:18:43 -0800 Jesse Gross <jesse@nicira.com> wrote: > On Mon, Nov 21, 2011 at 1:59 PM, Stephen Hemminger > <shemminger@vyatta.com> wrote: > > On Mon, 21 Nov 2011 13:30:29 -0800 > > Jesse Gross <jesse@nicira.com> wrote: > > > >> +/** > >> + * vport_record_error - indicate device error to generic stats layer > >> + * > >> + * @vport: vport that encountered the error > >> + * @err_type: one of enum vport_err_type types to indicate the error type > >> + * > >> + * If using the vport generic stats layer indicate that an error of the given > >> + * type has occured. > >> + */ > >> +void vport_record_error(struct vport *vport, enum vport_err_type err_type) > >> +{ > >> + spin_lock(&vport->stats_lock); > > > > Sorry for over analyzing this... but I don't think the stats_lock > > is necessary either. The only thing it is protecting is against 64 bit > > wrap. If you used another u64_stat_sync for that one, it could be eliminated. > > > > Maybe? > > The reason for stats_lock is that the error stats are not expected to > be contended so in order to save some memory they're not per-cpu and > we just use a spin lock to protect them. Assignment or increment of native type size (64 bit on 64 bit cpu) is always atomic. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
2011/11/22 Stephen Hemminger <shemminger@vyatta.com>: > On Mon, 21 Nov 2011 15:18:43 -0800 > Jesse Gross <jesse@nicira.com> wrote: > >> On Mon, Nov 21, 2011 at 1:59 PM, Stephen Hemminger >> <shemminger@vyatta.com> wrote: >> > On Mon, 21 Nov 2011 13:30:29 -0800 >> > Jesse Gross <jesse@nicira.com> wrote: >> > >> >> +/** >> >> + * vport_record_error - indicate device error to generic stats layer >> >> + * >> >> + * @vport: vport that encountered the error >> >> + * @err_type: one of enum vport_err_type types to indicate the error type >> >> + * >> >> + * If using the vport generic stats layer indicate that an error of the given >> >> + * type has occured. >> >> + */ >> >> +void vport_record_error(struct vport *vport, enum vport_err_type err_type) >> >> +{ >> >> + spin_lock(&vport->stats_lock); >> > >> > Sorry for over analyzing this... but I don't think the stats_lock >> > is necessary either. The only thing it is protecting is against 64 bit >> > wrap. If you used another u64_stat_sync for that one, it could be eliminated. >> > >> > Maybe? >> >> The reason for stats_lock is that the error stats are not expected to >> be contended so in order to save some memory they're not per-cpu and >> we just use a spin lock to protect them. > > Assignment or increment of native type size (64 bit on 64 bit cpu) > is always atomic. It might be, but it not always is. For example, on load-store architectures normal increment (load,inc,store) is not atomic unless made with special instruction sequence (like LDR/STREX on ARM). Best Regards, Michał Mirosław -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
--- a/net/openvswitch/vport.c 2011-11-21 13:56:54.991757053 -0800 +++ b/net/openvswitch/vport.c 2011-11-21 13:57:49.352333329 -0800 @@ -130,8 +130,6 @@ struct vport *vport_alloc(int priv_size, if (!vport->percpu_stats) return ERR_PTR(-ENOMEM); - spin_lock_init(&vport->stats_lock); - return vport; } @@ -235,6 +233,7 @@ void vport_del(struct vport *vport) void vport_get_stats(struct vport *vport, struct ovs_vport_stats *stats) { int i; + unsigned int start; memset(stats, 0, sizeof(*stats)); @@ -247,19 +246,17 @@ void vport_get_stats(struct vport *vport * netdev-stats can be directly read over netlink-ioctl. */ - spin_lock_bh(&vport->stats_lock); - - stats->rx_errors = vport->err_stats.rx_errors; - stats->tx_errors = vport->err_stats.tx_errors; - stats->tx_dropped = vport->err_stats.tx_dropped; - stats->rx_dropped = vport->err_stats.rx_dropped; - - spin_unlock_bh(&vport->stats_lock); + do { + start = u64_stats_fetch_begin_bh(&vport->err_stats.sync); + stats->rx_errors = vport->err_stats.rx_errors; + stats->tx_errors = vport->err_stats.tx_errors; + stats->tx_dropped = vport->err_stats.tx_dropped; + stats->rx_dropped = vport->err_stats.rx_dropped; + } while (u64_stats_fetch_retry_bh(&vport->err_stats.sync, start)); for_each_possible_cpu(i) { const struct vport_percpu_stats *percpu_stats; struct vport_percpu_stats local_stats; - unsigned int start; percpu_stats = per_cpu_ptr(vport->percpu_stats, i); @@ -372,7 +369,7 @@ int vport_send(struct vport *vport, stru */ void vport_record_error(struct vport *vport, enum vport_err_type err_type) { - spin_lock(&vport->stats_lock); + u64_stats_update_begin(&vport->err_stats.sync); switch (err_type) { case VPORT_E_RX_DROPPED: @@ -392,5 +389,5 @@ void vport_record_error(struct vport *vp break; }; - spin_unlock(&vport->stats_lock); + u64_stats_update_end(&vport->err_stats.sync); } --- a/net/openvswitch/vport.h 2011-11-21 13:56:54.991757053 -0800 +++ b/net/openvswitch/vport.h 2011-11-21 13:58:01.448461585 -0800 @@ -62,6 +62,7 @@ struct vport_err_stats { u64 rx_errors; u64 tx_dropped; u64 tx_errors; + struct u64_stats_sync sync; }; /**